Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3991159rdg; Wed, 18 Oct 2023 11:29:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFKJpiUKjtkqHm7PAfy/d5gBj7JG1uk3CutMZxpn21xJws7wnt79LvcvgKSr8zK5nxuyh9U X-Received: by 2002:a17:902:d48c:b0:1c6:d70:144d with SMTP id c12-20020a170902d48c00b001c60d70144dmr199807plg.34.1697653764059; Wed, 18 Oct 2023 11:29:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697653764; cv=none; d=google.com; s=arc-20160816; b=CUC2VIa+ZP4oSe9VevKQhb9sGkj+BuQ171sznNYBwNrdlZ/7mA9IT4suLn0PXjduRg PljLellENwKWxHV9nT+mnbLD7/Yz53TosRYCgfwTITtU1Br+LtI4LrDUFYirKf/zRUmA eDIbONMv9+OidRzHVKJeRTQIqHXzdi1Ro3EIAtGercghNwX84oKtn+OElUIuI7K3ZohP Gf0SY5yozFTh0m//ZRxZHK3tmJcfaPlT3AkmLnenflCO5DDcxtJszVOc8QJMbMaDkOCz x5PwytN3lr0ehH5OC6YCnBs7h0eddlqtv1gx8zWcd5ergkgy9Nu5BzPyOKV0bPhQgh2o ROTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=vUcw5okN5wncPu5Duait9qP75YEDXN830LWrskfnUHs=; fh=LkFjRCZOaDT+qbdzTtIK/eHCZ6OfWDrCMV4pK6unMOo=; b=fWhoycJY026DDuw6KetGRL32Z2wVmvsWlKxm8iDY53GRojYuOe14YCBfVv6xXVmHmy vaZtjBbU7Xwiw72ii34SXf+38ubUWNxIlPcWH6P9/itFmK1DMygAbmsw4N60Z5ilplHo 8bXL1iuVA8262v4d0auVmzEwTpWULM2XoS3rgOsfagzbyo1QelBudgWABZzmi1bI4cgI jIC0x8adbvWMUcDNn0hYPODZv/rWqlF0exPBFPtKDwGOmnfW8gOjkpkleiFqazXTLH43 GdG2o+AqLsSnO5AoN7pxUNZ9ZK5PuBDOVbWqrD+oyXNZvJUL5vHieMeIcNgS4eMWdPbk o4mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=L6X9HTPS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id a5-20020a170902ecc500b001b811261289si444328plh.482.2023.10.18.11.29.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 11:29:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=L6X9HTPS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id C4BCE8027033; Wed, 18 Oct 2023 11:29:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231354AbjJRS2v (ORCPT + 99 others); Wed, 18 Oct 2023 14:28:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230396AbjJRS2u (ORCPT ); Wed, 18 Oct 2023 14:28:50 -0400 Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01F72F7 for ; Wed, 18 Oct 2023 11:28:48 -0700 (PDT) Received: by mail-qt1-x831.google.com with SMTP id d75a77b69052e-419b628e990so48048701cf.0 for ; Wed, 18 Oct 2023 11:28:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1697653727; x=1698258527; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=vUcw5okN5wncPu5Duait9qP75YEDXN830LWrskfnUHs=; b=L6X9HTPSbPQ7lNSlDWQJ74+5aw+vI6PKDx/HXYZf5pSKRAplyrLIRsL8nVAt0egic1 q0L0EOU4+/cKJ+9uzp/yj3VfpxN45kc46plrcntXxlliFGEVdxYytrhcjrPntuEEEZdg jq71qbTiF0r5qiVKOdQVgJXYEuaIQt4U9fVzmZCzl927xa5PWnJo8SQImW4a4iU2vQkY /dWK8V2cWCug7cdLCiIxUIUSELTcmbVX1VRNJOIaZ+yCL6onvseBmpk24aY/Re7+g7pV fwv0tQukv6EMU2gzTfgWs/Mxk3e1YciGbQlmR8dU+QVF3Dkv4B5GAYVf2pEEzObPtvE3 hdxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697653727; x=1698258527; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vUcw5okN5wncPu5Duait9qP75YEDXN830LWrskfnUHs=; b=PoXv5kEIGGcCCz1qt+x/2RZtCBX1GupnMX9jGSjkFFaTmvdQwEp63K/xhoCgJ384TU sskVFwvBjjwCRopR0ngmprPNrVbZIPZYpvD1rP5yeFEPpVpZJ2thj6t49mNMeeC3LeaY K2/2gvZm67TH8C+AuUmfmy6GbLLKKgRZqUDRbNuG5oTkZKoHAa9i5eLpFxbKs4p5rC4s MJ8FIF/ISvv49ZQP5fpMccZdMeIVKvoHvVVzEs0s05/qcd/18Sp7d5H3WKpst/DrBQCB WmT51rCUP90bI+1qhfPHabKLgVi41PKO2tbOURD/RKDxXWAgAd5hRrdGdXTFX5BOOMgJ FbTQ== X-Gm-Message-State: AOJu0YycFL51UIo8I9ZtSwbD6RVn6rcGakLBOAzxVA3ZMwmXT/BaWwMG /Xy4MAZnvzDMzVcSM7cIYZoqSQ== X-Received: by 2002:a05:622a:1a87:b0:418:804:340d with SMTP id s7-20020a05622a1a8700b004180804340dmr75023qtc.48.1697653727055; Wed, 18 Oct 2023 11:28:47 -0700 (PDT) Received: from ?IPV6:2600:1700:2000:b002:f59c:efa7:80ec:8da0? ([2600:1700:2000:b002:f59c:efa7:80ec:8da0]) by smtp.gmail.com with ESMTPSA id fp7-20020a05622a508700b00405502aaf76sm144270qtb.57.2023.10.18.11.28.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Oct 2023 11:28:46 -0700 (PDT) Message-ID: <2fea6698-7446-443b-9026-c4b082a9f809@sifive.com> Date: Wed, 18 Oct 2023 13:28:45 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 1/2] riscv: Add remaining module relocations Content-Language: en-US To: Charlie Jenkins Cc: Eric Biederman , Kees Cook , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20231017-module_relocations-v4-0-937f5ef316f0@rivosinc.com> <20231017-module_relocations-v4-1-937f5ef316f0@rivosinc.com> From: Samuel Holland In-Reply-To: <20231017-module_relocations-v4-1-937f5ef316f0@rivosinc.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 18 Oct 2023 11:29:17 -0700 (PDT) On 2023-10-18 12:34 AM, Charlie Jenkins wrote: > Add all final module relocations and add error logs explaining the ones > that are not supported. > > Signed-off-by: Charlie Jenkins > --- > arch/riscv/include/uapi/asm/elf.h | 5 +- > arch/riscv/kernel/module.c | 207 +++++++++++++++++++++++++++++++++----- > 2 files changed, 186 insertions(+), 26 deletions(-) > > diff --git a/arch/riscv/include/uapi/asm/elf.h b/arch/riscv/include/uapi/asm/elf.h > index d696d6610231..11a71b8533d5 100644 > --- a/arch/riscv/include/uapi/asm/elf.h > +++ b/arch/riscv/include/uapi/asm/elf.h > @@ -49,6 +49,7 @@ typedef union __riscv_fp_state elf_fpregset_t; > #define R_RISCV_TLS_DTPREL64 9 > #define R_RISCV_TLS_TPREL32 10 > #define R_RISCV_TLS_TPREL64 11 > +#define R_RISCV_IRELATIVE 58 > > /* Relocation types not used by the dynamic linker */ > #define R_RISCV_BRANCH 16 > @@ -81,7 +82,6 @@ typedef union __riscv_fp_state elf_fpregset_t; > #define R_RISCV_ALIGN 43 > #define R_RISCV_RVC_BRANCH 44 > #define R_RISCV_RVC_JUMP 45 > -#define R_RISCV_LUI 46 > #define R_RISCV_GPREL_I 47 > #define R_RISCV_GPREL_S 48 > #define R_RISCV_TPREL_I 49 > @@ -93,6 +93,9 @@ typedef union __riscv_fp_state elf_fpregset_t; > #define R_RISCV_SET16 55 > #define R_RISCV_SET32 56 > #define R_RISCV_32_PCREL 57 > +#define R_RISCV_PLT32 59 > +#define R_RISCV_SET_ULEB128 60 > +#define R_RISCV_SUB_ULEB128 61 > > > #endif /* _UAPI_ASM_RISCV_ELF_H */ > diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c > index 7c651d55fcbd..e860726352ac 100644 > --- a/arch/riscv/kernel/module.c > +++ b/arch/riscv/kernel/module.c > @@ -7,6 +7,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -268,6 +269,12 @@ static int apply_r_riscv_align_rela(struct module *me, u32 *location, > return -EINVAL; > } > > +static int apply_r_riscv_add8_rela(struct module *me, u32 *location, Elf_Addr v) > +{ > + *(u8 *)location += (u8)v; > + return 0; > +} > + > static int apply_r_riscv_add16_rela(struct module *me, u32 *location, > Elf_Addr v) > { > @@ -289,6 +296,12 @@ static int apply_r_riscv_add64_rela(struct module *me, u32 *location, > return 0; > } > > +static int apply_r_riscv_sub8_rela(struct module *me, u32 *location, Elf_Addr v) > +{ > + *(u8 *)location -= (u8)v; > + return 0; > +} > + > static int apply_r_riscv_sub16_rela(struct module *me, u32 *location, > Elf_Addr v) > { > @@ -310,31 +323,149 @@ static int apply_r_riscv_sub64_rela(struct module *me, u32 *location, > return 0; > } > > -static int (*reloc_handlers_rela[]) (struct module *me, u32 *location, > - Elf_Addr v) = { > - [R_RISCV_32] = apply_r_riscv_32_rela, > - [R_RISCV_64] = apply_r_riscv_64_rela, > - [R_RISCV_BRANCH] = apply_r_riscv_branch_rela, > - [R_RISCV_JAL] = apply_r_riscv_jal_rela, > - [R_RISCV_RVC_BRANCH] = apply_r_riscv_rvc_branch_rela, > - [R_RISCV_RVC_JUMP] = apply_r_riscv_rvc_jump_rela, > - [R_RISCV_PCREL_HI20] = apply_r_riscv_pcrel_hi20_rela, > - [R_RISCV_PCREL_LO12_I] = apply_r_riscv_pcrel_lo12_i_rela, > - [R_RISCV_PCREL_LO12_S] = apply_r_riscv_pcrel_lo12_s_rela, > - [R_RISCV_HI20] = apply_r_riscv_hi20_rela, > - [R_RISCV_LO12_I] = apply_r_riscv_lo12_i_rela, > - [R_RISCV_LO12_S] = apply_r_riscv_lo12_s_rela, > - [R_RISCV_GOT_HI20] = apply_r_riscv_got_hi20_rela, > - [R_RISCV_CALL_PLT] = apply_r_riscv_call_plt_rela, > - [R_RISCV_CALL] = apply_r_riscv_call_rela, > - [R_RISCV_RELAX] = apply_r_riscv_relax_rela, > - [R_RISCV_ALIGN] = apply_r_riscv_align_rela, > - [R_RISCV_ADD16] = apply_r_riscv_add16_rela, > - [R_RISCV_ADD32] = apply_r_riscv_add32_rela, > - [R_RISCV_ADD64] = apply_r_riscv_add64_rela, > - [R_RISCV_SUB16] = apply_r_riscv_sub16_rela, > - [R_RISCV_SUB32] = apply_r_riscv_sub32_rela, > - [R_RISCV_SUB64] = apply_r_riscv_sub64_rela, > +static int dynamic_linking_not_supported(struct module *me, u32 *location, > + Elf_Addr v) > +{ > + pr_err("%s: Dynamic linking not supported in kernel modules PC = %p\n", > + me->name, location); > + return -EINVAL; > +} > + > +static int tls_not_supported(struct module *me, u32 *location, Elf_Addr v) > +{ > + pr_err("%s: Thread local storage not supported in kernel modules PC = %p\n", > + me->name, location); > + return -EINVAL; > +} > + > +static int apply_r_riscv_sub6_rela(struct module *me, u32 *location, Elf_Addr v) > +{ > + *(u8 *)location = (*location - ((u8)v & 0x3F)) & 0x3F; > + return 0; > +} > + > +static int apply_r_riscv_set6_rela(struct module *me, u32 *location, Elf_Addr v) > +{ > + *(u8 *)location = (*(u8 *)location & 0xc0) | ((u8)v & 0x3F); > + return 0; > +} > + > +static int apply_r_riscv_set8_rela(struct module *me, u32 *location, Elf_Addr v) > +{ > + *(u8 *)location = (u8)v; > + return 0; > +} > + > +static int apply_r_riscv_set16_rela(struct module *me, u32 *location, > + Elf_Addr v) > +{ > + *(u16 *)location = (u16)v; > + return 0; > +} > + > +static int apply_r_riscv_set32_rela(struct module *me, u32 *location, > + Elf_Addr v) > +{ > + *(u32 *)location = (u32)v; You don't need to cast the pointer, since it's already a `u32 *`. > + return 0; > +} > + > +static int apply_r_riscv_32_pcrel_rela(struct module *me, u32 *location, > + Elf_Addr v) > +{ > + *(u32 *)location = (u32)v; This expression should be: *location = v - location; matching the other PC-relative relocations. (BTW, recent clang generates these relocations for module alternatives.) > + return 0; > +} > + > +static int apply_r_riscv_plt32_rela(struct module *me, u32 *location, > + Elf_Addr v) > +{ > + *(u32 *)location = (u32)v; This should look like apply_r_riscv_32_pcrel_rela(), but with the PLT entry emission code from apply_r_riscv_call_plt_rela(). See the psABI commit[1]. [1]: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/commit/c3f8269c56d8a2f56c2602f2a44175362024ef9c > + return 0; > +} > + > +static int apply_r_riscv_set_uleb128(struct module *me, u32 *location, Elf_Addr v) > +{ > + /* > + * Relocation is only performed if R_RISCV_SET_ULEB128 is followed by > + * R_RISCV_SUB_ULEB128 so do computation there > + */ > + return 0; > +} > + > +static int apply_r_riscv_sub_uleb128(struct module *me, u32 *location, Elf_Addr v) > +{ > + if (v >= 128) { > + pr_err("%s: uleb128 must be in [0, 127] (not %ld) at PC = %p\n", > + me->name, (unsigned long)v, location); > + return -EINVAL; > + } > + > + *location = v; > + return 0; > +} > + > +/* > + * Relocations defined in the riscv-elf-psabi-doc. > + * This handles static linking only. > + */ > +static int (*reloc_handlers_rela[])(struct module *me, u32 *location, > + Elf_Addr v) = { > + [R_RISCV_32] = apply_r_riscv_32_rela, > + [R_RISCV_64] = apply_r_riscv_64_rela, > + [R_RISCV_RELATIVE] = dynamic_linking_not_supported, > + [R_RISCV_COPY] = dynamic_linking_not_supported, > + [R_RISCV_JUMP_SLOT] = dynamic_linking_not_supported, > + [R_RISCV_TLS_DTPMOD32] = dynamic_linking_not_supported, > + [R_RISCV_TLS_DTPMOD64] = dynamic_linking_not_supported, > + [R_RISCV_TLS_DTPREL32] = dynamic_linking_not_supported, > + [R_RISCV_TLS_DTPREL64] = dynamic_linking_not_supported, > + [R_RISCV_TLS_TPREL32] = dynamic_linking_not_supported, > + [R_RISCV_TLS_TPREL64] = dynamic_linking_not_supported, > + /* 12-15 undefined */ > + [R_RISCV_BRANCH] = apply_r_riscv_branch_rela, > + [R_RISCV_JAL] = apply_r_riscv_jal_rela, > + [R_RISCV_CALL] = apply_r_riscv_call_rela, > + [R_RISCV_CALL_PLT] = apply_r_riscv_call_plt_rela, > + [R_RISCV_GOT_HI20] = apply_r_riscv_got_hi20_rela, > + [R_RISCV_TLS_GOT_HI20] = tls_not_supported, > + [R_RISCV_TLS_GD_HI20] = tls_not_supported, > + [R_RISCV_PCREL_HI20] = apply_r_riscv_pcrel_hi20_rela, > + [R_RISCV_PCREL_LO12_I] = apply_r_riscv_pcrel_lo12_i_rela, > + [R_RISCV_PCREL_LO12_S] = apply_r_riscv_pcrel_lo12_s_rela, > + [R_RISCV_HI20] = apply_r_riscv_hi20_rela, > + [R_RISCV_LO12_I] = apply_r_riscv_lo12_i_rela, > + [R_RISCV_LO12_S] = apply_r_riscv_lo12_s_rela, > + [R_RISCV_TPREL_HI20] = tls_not_supported, > + [R_RISCV_TPREL_LO12_I] = tls_not_supported, > + [R_RISCV_TPREL_LO12_S] = tls_not_supported, > + [R_RISCV_TPREL_ADD] = tls_not_supported, > + [R_RISCV_ADD8] = apply_r_riscv_add8_rela, > + [R_RISCV_ADD16] = apply_r_riscv_add16_rela, > + [R_RISCV_ADD32] = apply_r_riscv_add32_rela, > + [R_RISCV_ADD64] = apply_r_riscv_add64_rela, > + [R_RISCV_SUB8] = apply_r_riscv_sub8_rela, > + [R_RISCV_SUB16] = apply_r_riscv_sub16_rela, > + [R_RISCV_SUB32] = apply_r_riscv_sub32_rela, > + [R_RISCV_SUB64] = apply_r_riscv_sub64_rela, > + /* 41-42 reserved for future standard use */ > + [R_RISCV_ALIGN] = apply_r_riscv_align_rela, > + [R_RISCV_RVC_BRANCH] = apply_r_riscv_rvc_branch_rela, > + [R_RISCV_RVC_JUMP] = apply_r_riscv_rvc_jump_rela, > + /* 46-50 reserved for future standard use */ > + [R_RISCV_RELAX] = apply_r_riscv_relax_rela, > + [R_RISCV_SUB6] = apply_r_riscv_sub6_rela, > + [R_RISCV_SET6] = apply_r_riscv_set6_rela, > + [R_RISCV_SET8] = apply_r_riscv_set8_rela, > + [R_RISCV_SET16] = apply_r_riscv_set16_rela, > + [R_RISCV_SET32] = apply_r_riscv_set32_rela, > + [R_RISCV_32_PCREL] = apply_r_riscv_32_pcrel_rela, > + [R_RISCV_IRELATIVE] = dynamic_linking_not_supported, > + [R_RISCV_PLT32] = apply_r_riscv_plt32_rela, > + [R_RISCV_SET_ULEB128] = apply_r_riscv_set_uleb128, > + [R_RISCV_SUB_ULEB128] = apply_r_riscv_sub_uleb128, > + /* 62-191 reserved for future standard use */ > + /* 192-255 nonstandard ABI extensions */ > }; > > int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab, > @@ -348,6 +479,10 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab, > unsigned int i, type; > Elf_Addr v; > int res; > + bool uleb128_set_exists = false; > + u32 *uleb128_set_loc; > + unsigned long uleb128_set_sym_val; > + Extra blank line. > > pr_debug("Applying relocate section %u to %u\n", relsec, > sechdrs[relsec].sh_info); > @@ -425,6 +560,28 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab, > me->name); > return -EINVAL; > } > + } else if (type == R_RISCV_SET_ULEB128) { > + if (uleb128_set_exists) { > + pr_err("%s: riscv psABI requires the next ULEB128 relocation to come after a R_RISCV_SET_ULEB128 is an R_RISCV_SUB_ULEB128, not another R_RISCV_SET_ULEB128.\n", > + me->name); > + return -EINVAL; > + } > + uleb128_set_exists = true; > + uleb128_set_loc = location; > + uleb128_set_sym_val = > + ((Elf_Sym *)sechdrs[symindex].sh_addr + > + ELF_RISCV_R_SYM(rel[i].r_info)) > + ->st_value + > + rel[i].r_addend; > + } else if (type == R_RISCV_SUB_ULEB128) { > + if (uleb128_set_exists && uleb128_set_loc == location) { > + /* Calculate set and subtraction */ > + v = uleb128_set_sym_val - v; You need to set uleb128_set_exists back to false somewhere, or you can only handle one R_RISCV_SET_ULEB128 relocation per module. Regards, Samuel > + } else { > + pr_err("%s: R_RISCV_SUB_ULEB128 must always be paired with the first R_RISCV_SET_ULEB128 that comes before it. PC = %p\n", > + me->name, location); > + return -EINVAL; > + } > } > > res = handler(me, location, v); >