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 50BB6CDB47E for ; Wed, 18 Oct 2023 05:36:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DF8108D0137; Wed, 18 Oct 2023 01:36:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DA8568D0016; Wed, 18 Oct 2023 01:36:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C70CC8D0137; Wed, 18 Oct 2023 01:36:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B4CC58D0016 for ; Wed, 18 Oct 2023 01:36:13 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8A361161201 for ; Wed, 18 Oct 2023 05:36:13 +0000 (UTC) X-FDA: 81357471426.13.95A6507 Received: from mail-oi1-f178.google.com (mail-oi1-f178.google.com [209.85.167.178]) by imf28.hostedemail.com (Postfix) with ESMTP id BE8A5C000F for ; Wed, 18 Oct 2023 05:36:11 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="oYTGAaC/"; spf=pass (imf28.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.167.178 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697607371; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=RVGEVK2oqiimD1UCwBActT2L4ZyISAIQqtoBz0C3gOM=; b=3UOkxoRwou4gLVHkszgzwRBPGd4/DftlNkoQBtAq/cQg1BSt163UlJpcOdxwfcx0xhqU3R h1vn8qH7gqKjVJA1gqPzo22DErt2GT8FSdPiwwc45tpBh94CYJ5HTc7XDi9YaeXZy2JA21 IyCHzMLpo+PbTV7veQgEvXLoEtiZgOg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697607371; a=rsa-sha256; cv=none; b=gD2rduYDAglVBF3Hk+USthwpXX0tva6WNT1L3aqVs4ydEwZlcKVChLHS5OcKZpDFA5ijkj R0DlgHdKFrQUwOXgSj1x/TT4Rx+mTimZAQ2XVWNeIRJOMGUbmjnsaW5eygOYZsqWsY8g97 VsOznSKsPwfvlCLKGCofIheK6ql7XOQ= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="oYTGAaC/"; spf=pass (imf28.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.167.178 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none Received: by mail-oi1-f178.google.com with SMTP id 5614622812f47-3b2e22a4004so651561b6e.3 for ; Tue, 17 Oct 2023 22:36:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1697607371; x=1698212171; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=RVGEVK2oqiimD1UCwBActT2L4ZyISAIQqtoBz0C3gOM=; b=oYTGAaC/8Vwp2uDkHL5aTlTzdAkps5kExUlurMKCXevdBkCwVN/A5FqTBH4+JeY/PL sjNoLpvCxfV7De3ePxtONaIM4TkhQbU6n1YIWq5W1wk+mq1MjrTxRHu7iVIATfg+q98K w7/3FWe5Si2/BjZzqZ9WalM7JycKPd46PSEH9RJrFQMWBY5DygTRKoFD6gUiWAuui3He 0lS5rPOQCfwiBk1KxVYbUdD3x2aB7hycouMrsjsJL+ran4A5w/g9Ven1gYbbGhYYK+bW ShAT7er/lEDZ71L/09q6jX1m+NVGKvW68vKWPxAqCUMcmGvJbuq5yAL1oyAnFPFJxcLH Oh9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697607371; x=1698212171; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=RVGEVK2oqiimD1UCwBActT2L4ZyISAIQqtoBz0C3gOM=; b=MP32VleHqknFSDLshUaR2Zr2eqx8giw+FiugID+FbTYRQv8YwztNb6zuGUlhOa6zqI RXfPh3yOQOfbI0/qW5Jym1G+R2U26tLZUYkZdJ9lM+A2l8zbJehaIizmygs4smRqOFQE nPWsQ40j17pwuTM0xUcpEgK5/gfSS72pSniq5k9Hdceve3ncNRyXO8dJZW1ty8HAimwm BQnSNAxr/WAtIdNP0CRF5uoudJe5Ph0XBOg4GyEK2HgChdUGbFZz8HBbTqsBJ7CdLnKq i2MxbP//CHWIEXThUrZOilpYYc036JLcaKVxuaXmzdrO9HMpMaWbaM8psBFMb607rLG1 qVFg== X-Gm-Message-State: AOJu0Yw1PIQFIfT3k6BYD/cRJZowqDnW7dLo6CLO5pburgtPaT6Tn2bx WnbhZxj/deDtIuz96X6f8q0yZw== X-Google-Smtp-Source: AGHT+IEvzLb3C4KqeMCgyh/WDl3C4rY51QFTJJan1ICRIFhgomvelxVfP2gaAQYax7svEYG3H7Gdxg== X-Received: by 2002:a54:4399:0:b0:3a9:ba39:6d70 with SMTP id u25-20020a544399000000b003a9ba396d70mr4750526oiv.23.1697607370952; Tue, 17 Oct 2023 22:36:10 -0700 (PDT) Received: from ghost ([2601:647:5700:6860:f063:a395:7fed:1020]) by smtp.gmail.com with ESMTPSA id bp18-20020a056808239200b003af644e6e81sm533544oib.45.2023.10.17.22.36.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 22:36:10 -0700 (PDT) Date: Tue, 17 Oct 2023 22:36:07 -0700 From: Charlie Jenkins To: Conor Dooley Cc: linux-riscv@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Eric Biederman , Kees Cook , Paul Walmsley , Palmer Dabbelt , Albert Ou Subject: Re: [PATCH v3 1/2] riscv: Add remaining module relocations Message-ID: References: <20231016-module_relocations-v3-0-a667fd6071e9@rivosinc.com> <20231016-module_relocations-v3-1-a667fd6071e9@rivosinc.com> <20231017-heaviness-husked-f3b81d5ecdfb@spud> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231017-heaviness-husked-f3b81d5ecdfb@spud> X-Rspamd-Queue-Id: BE8A5C000F X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 4gadk6fenk9gf7jrxfpjryitzxn8wa5w X-HE-Tag: 1697607371-492554 X-HE-Meta: U2FsdGVkX19R6OmIkdMkRaSr0P8gH38hEnIPM3+gUaxP7p3/WtVnBy3Txsbef9GHnhJa2f/nuK6tu2xmTWR07G9bED7RfIj1furtD3agBTOK9pFMYgpLffULAC60bcPDNOIw7yXv8f/cPZ2oyBNT7+zOHvD2uOv5m0larINbYQ0z23MoKz3zz6+NZsxH2VQE9O+rlFclDXF248gJJtg3kma8KoMZsViyF/68MAErclsyg1uQtll02SuK6PuPr97ZyGiziejJn3nDtTcK6rPpp0ERgtMNeqV+kH2eYB9W2rXlAd9H6ZaF83kJsDXV1Ok58jepugWYU1u8QTobF4qrRhbeCuogJ2aOZvW8gftqv/RBoj0IJ2uy115dE1a1M+G5Bs6T0Su4NOSLUMfWlyeyWcpAqhlUPTYfxh+6tpR+JbZbLviFbcDdG4kLUe5xvbGwEkUtJycgG4u623nZjzwmNLaZpIsLJ1/Glo+lcaTW+GjWVZVFMAHm4RR+ykr/oUXdO5CaOM+aofVFPoyfkHaHhr2Vkah7WNFV/Ly1RARN3LnbBhJn7Gnebc6NCUIpHqKCHFIvm1V14H4sPFT/M/e142EnKKj5jPAZqauCAUcHoCFzDOKzy0kUvm5P6j67zj9QVkIHp0KGq0XJqePa9bL74HQAKk64kHZfB66JxMgDVHowSpA4Dx70lNZ1RSi96WCquO5TDFkRNe+49DnPtDTcIojYHL0CleYmVZLE/Q3vcvUy+7epRgEk91SfyLx+sJIRVyM7+VGeZUlR1k4I4mNGrsr1y/56iYO3Cjd/hOpz22xOu+E4/8YrJ6d0Js9xoQrq1jA3M+8Uf8jGTotXzQmFF+Ndt+CcEre6HK5+0cFtYD/nmDRnp7ekhFswLi+YsrNs3QFluPCuJZrjo7Cfbhg49b1jr+Bb7VDIp5fFqCMnukHDiWIfHQgCuJMzAK4aHHOZi/5RXi5o1ltDNQ2tYN4 qDqzVl4L RkbT0fceC2VdbDCHoGqPo3eVxBk/KklTuQnMgP6pcrPQSgr62ibpJ5uHEfAuoAm0YBAGYdd7h5cqSTuNzf0RVJ5ZIm5zPJEq1F2o/li1U1GspvhqE4VDNrklEotvYNK8v0QjOA3GO721IPWK76UVOzRjN8PjFcuv5aH4SmiF3X1xwwgUqSUxrk7bjPjyvooqEpPvrrRMtnadUbRe6wj7a9prMDVMp3r9ECH2FZlD2b8VdqmDm71PMnv5U0w5LnENpn90M4d5imtrn4oG8NynMB3xGzQkRsikl4iSZ2EB1eYVwZZoyeoN0FxfrfNs77BwD27WcEE27ZlU2GaPOPPnuz/yhUF1IuReq2T29W/Zn8GCkfaGwFeye4/6S/sgkYaIAv72HGQKu7D8NSXoSEPzlIUNqOgDw6wap+UOgfTymrVmTn+jAuFxY+XxB1T9YQvP2euAoz/UALQPih6sK3CRCGql2Ug== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Oct 17, 2023 at 08:08:26AM +0100, Conor Dooley wrote: > On Mon, Oct 16, 2023 at 10:36:09AM -0700, Charlie Jenkins wrote: > > Add all final module relocations and add error logs explaining the ones > > that are not supported. > > In the patchwork automation's clang/llvm allmodconfig: > ../arch/riscv/kernel/tests/module_test/test_uleb128.S:18:17: error: unknown relocation name > ../arch/riscv/kernel/tests/module_test/test_uleb128.S:19:17: error: unknown relocation name > > (llvm-17 iirc) > > Cheers, > Conor. Thank you, that slipped my mind that I needed to conditionally build the uleb128 tests. I will send an updated version. - Charlie > > > > > Signed-off-by: Charlie Jenkins > > --- > > arch/riscv/include/uapi/asm/elf.h | 6 +- > > arch/riscv/kernel/module.c | 207 +++++++++++++++++++++++++++++++++----- > > 2 files changed, 187 insertions(+), 26 deletions(-) > > > > diff --git a/arch/riscv/include/uapi/asm/elf.h b/arch/riscv/include/uapi/asm/elf.h > > index d696d6610231..a9307a1c9ceb 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,7 @@ 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_RVC_LUI 46 > > #define R_RISCV_GPREL_I 47 > > #define R_RISCV_GPREL_S 48 > > #define R_RISCV_TPREL_I 49 > > @@ -93,6 +94,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..73f47de538d2 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 -= (u8)v & 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; > > + return 0; > > +} > > + > > +static int apply_r_riscv_32_pcrel_rela(struct module *me, u32 *location, > > + Elf_Addr v) > > +{ > > + *(u32 *)location = (u32)v; > > + return 0; > > +} > > + > > +static int apply_r_riscv_plt32_rela(struct module *me, u32 *location, > > + Elf_Addr v) > > +{ > > + *(u32 *)location = (u32)v; > > + 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; > > + > > > > 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; > > + } 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); > > > > -- > > 2.42.0 > >