From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0A95CDB47E for ; Wed, 18 Oct 2023 18:28:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 81FCC8D0185; Wed, 18 Oct 2023 14:28:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A85E8D0016; Wed, 18 Oct 2023 14:28:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 622928D0185; Wed, 18 Oct 2023 14:28:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4AB108D0016 for ; Wed, 18 Oct 2023 14:28:50 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 17E671CB2E4 for ; Wed, 18 Oct 2023 18:28:50 +0000 (UTC) X-FDA: 81359418420.07.A86B653 Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) by imf01.hostedemail.com (Postfix) with ESMTP id 01D4740014 for ; Wed, 18 Oct 2023 18:28:47 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=HCrUPHwc; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf01.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.160.172 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697653728; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vUcw5okN5wncPu5Duait9qP75YEDXN830LWrskfnUHs=; b=52EqrpCDI2JTnSi8gjKlnXzMGpOCQ/H0i/OI9L+dqp491wo45W/vSDTg7P8JtU1EM3rw5D +tdn4fNblNWxFXdptvdp9z2C5pcF3L/SHg/KQaNsVyXN8Z+uOtcDo6Eo8q0q0iG3arux6A 2A0g/DxlQCt9y9LWSAJg8YYlFcD19ps= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=HCrUPHwc; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf01.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.160.172 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697653728; a=rsa-sha256; cv=none; b=Xf2hSX4TEGZ9wHr1OzdKSKME9LLPvWizk9MT+9S6RRy37TafqmxhZ1yxZNQgDYMsx+ha4r FINeU5Ioj8cS3wKQSEpfRCp6xHa2IW39drxW/oVUfed9qC/rzSJHoj2xtxol7dy0SvTzec 630cxO7DHaQOXTOUAMtbgTxpUBq79To= Received: by mail-qt1-f172.google.com with SMTP id d75a77b69052e-41983b83e53so47990841cf.2 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=kvack.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=HCrUPHwc9rXpuKW30C63sxKJM9vv3pFFk6Stvjz3eS0ZNnDUuJMYqvd5YXm27ZI6O8 m6yaUCjC80NF7pE/Nxk83vWdrRx0R5Z+tyQLgpw9m6AGpLOjSgqOLG3QCWrR5oDV4MVm TfkhR3I+IFPy/8y2ZbYWdEBBdx9iCRHG5LY8zGBjV2ilK3X3K8yV2JCbEPWZXEIgBHnm HMnxXc70EJTMRvh5YZVSScJveWAgrUsnj8M+ZkNiHg+3cTDWk9vXrMPtOxYqPvLUbqox tYsn7cBsuDghybjyJFN7YCnmnYoPn+bW6iveAYvTB3TuwM1ETDITAmAY9T/JR0ZpUTga ynLw== 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=pzykFnqNrAZNbN3ZvzCbCjeye3EMzKgAt0GRBLAgkig5UF2/9w1xSi5DxBCXjBjiq8 +vdTK+VE8GGZgTQJDhug96nWY2ugTw1bi34z7QU+oHBNzE7aiJD6HgGrB3/+PzTbau5J 5tchb/CNG+s58nFkFH5i7zc+YtIjNwQJcwz7pIN7HI/PFxRJoTKSoSxLsNmlv08YaUgt 9Gn9CQwpMIhCi2vuip3YfLFyJ2zgs44BpX5ei2euFJN3FljiZiHWN3N5ZD6TW+dLmIab zk5bHXUUY9H9EsOfV1SFZn77zNGXCv1tKAUb/4xFvBWxTbvtFiP218rmky4vsjhsqVvW Luwg== X-Gm-Message-State: AOJu0YxPxUkWALrJqDV50ojq+4PvGlfJ7CLo63h1eNY7/0i8k/zJyf9A 6yjPRI16QehaRzchGfb/hFejLQ== X-Google-Smtp-Source: AGHT+IF0bo1L3sO0ffxrVBI6mbDyWxNwo9HiS9a9ETu36ZowCWDy4sh/rnteUtkR0vokAZaCq6ulrg== 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-Rspamd-Queue-Id: 01D4740014 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 9wfudzpp6rn6b4rw3691wo7m5jbr6kq9 X-HE-Tag: 1697653727-516618 X-HE-Meta: U2FsdGVkX1+ZmNl1oZ/A37SOwc+j7gObaTZ2oBTpsIZUDJE7I69EmsNVCOepD0LhONk2AVwfV6H734hi/FwuA8Bco5r4UwcbiUZHO3QWrxKE9gz4pZ6wTjliPo0ropASFod4NKiqIOLjEDvoe2AHtcaOkpKQo2EE9P5g2KeLCkhBmpfDf00LjMEzKwI+1Z7cqkP4OlbtvmiDoGdauTt3zmYAoi2/AUi3Z7qRxtZJ4uRJs5fRJQ0CdetVts7mpUvJorw++oKkcHElIfYOdMtpJ9XXh/tZC8PyJC3FyaZLDwAMLp85c18q0eDjMbsra8WApRp4XFp36prs5iLN0VKA7ktANe7QyqVotLw4yxCavriO9MY1ja1b/dlyYqs9YuC5gpDrr9G0kWAznGPbLnb6sRtcvCzM4sY6zcGeSm1R4838EhKbOAjqPR4yxZUFusPkoionenti8KSNQecs3BwoDfKrSRZB3yn5nK4t6f21q4poRTjRX/ng8hmHkA8eIPsJpU6SoXAlDnB5KK9Wq6eSO7LDgIozf07CMv+8v48ZqQFRN1AChJNmTBIw7A0yWHYeO+OsqVcjrjLR0a+yvFudqFbxzpl3vG4Kjx5dZlR3ESEfLe2hJ7QFYWTEAbKnZBXJ9IQqJ0m3ASNPKKta2YB4oZYM9GrBsy8xwnNXZuTL3s/CQagtflDSVKcDQDEqz8pcYx75OuL110Y71oH48jP/neCLJcW6vfYh4KJhHR7IahYhzjsEhAWo7Eo1ykvj28WZxTc7lhWrh/z9gTG/rWESPGywXOPf6lRKz95ZyeKsp12Y6yLv10D8Y1oGe3zoc8HM/UINcunCdSrArtWsOTo1j2fSfUAhMYoh7iquPJwi/SkZKEIQm8GXmVCsVgeHAazs5zC6cmuGIZer18tW4PYKCAQB3cv1g+5vqzbj+/mDmrWbdcvag2WthY1Bb56VCQQe42lw8J7duNt/Ea+/Fj7 7mS8SCzK Q09+qf8XdOtn/uXEBjO0/bhYsc5bBy5XlpzlbaTIYMw455naLP305frJFrVNDVW/+4U0RXx/4yKzCaDja8vamhDJwZKUWlQUCgJHNYOpbbjiqnwElHnf2pZmMdUqbRMwyWmMdkUI7Bdc4VXnBP+7kND0GqlP5ZmYSRu5ANNgnyY6+fhbVH/xwX3iw3L8R3RrhqAK5tkpRKjWu62jZ1yJb2ZaidhIfRW/PcYEpfE0w0dNHe0OTg65bqv12bAmwZRJEnR0T5FOkmwTz5jZpL4JKgrW+0Klt7gC5Q8F8Rkhjv7U7nQQqFfEYIxZdLHbPqKcMfAy5Bnwbphkqhc9neANzvFKGlU3OQhFoElDZw4/tvznC9IM0y5K1T5mL6R6p4LbS08BlwLFgT6pWDKD1lWBj4pnSYYjKPny7rd5yXrcmpu6FucyffFnD/cN3eZJYwL1cjEJYe5QM8boKnj/9SYPjIiC5TWIa+4EtWOtH X-Bogosity: Ham, tests=bogofilter, spamicity=0.000079, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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); >