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 4A618CDB47E for ; Wed, 18 Oct 2023 22:19:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D17BD8D016F; Wed, 18 Oct 2023 18:19:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CC6448D0016; Wed, 18 Oct 2023 18:19:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B8E9E8D016F; Wed, 18 Oct 2023 18:19:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A97348D0016 for ; Wed, 18 Oct 2023 18:19:18 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 751D61CB2FD for ; Wed, 18 Oct 2023 22:19:18 +0000 (UTC) X-FDA: 81359999196.18.FAD796A Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) by imf11.hostedemail.com (Postfix) with ESMTP id 7827C4001E for ; Wed, 18 Oct 2023 22:19:16 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=Iqrfkxeb; dmarc=none; spf=pass (imf11.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.219.177 as permitted sender) smtp.mailfrom=charlie@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697667556; 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=uuqTvkZsLNcN0vKiW9poC4HMQijLLBM+uo+MZO5mhQQ=; b=JDPiT+rUVS0NaVp0HGmXv95p47cl9hOXkaSHTejPctsRmJkaInvfuR3anUixhbjwDhyLgV BAATZ2mm+hHi1h10igD8NWnM6XAhOv7/ymOk8B5FedCYGVpzBlEk25Q+pk8OIW9XCmm1Tf v7vB5Vsr6qtSK2rHMRLjd/Pim/JWIHc= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=Iqrfkxeb; dmarc=none; spf=pass (imf11.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.219.177 as permitted sender) smtp.mailfrom=charlie@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697667556; a=rsa-sha256; cv=none; b=qQw3R7CqXfaJVgmndIrA4d8pIZK/CzbQmukH27hY+OvjQg/dTK/2iRrBhMyFUZDioHVhPx xPXti+ODDEjYDiiPzPhD8kEoqrMJSIW9ugIXdfmCNs84YA1BbYY7rBKJkhswEx3WqdpHf8 m7WjzQJFIZeC+d2+V+tM677IJ0oGyLg= Received: by mail-yb1-f177.google.com with SMTP id 3f1490d57ef6-d84c24a810dso8549788276.2 for ; Wed, 18 Oct 2023 15:19:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1697667555; x=1698272355; 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=uuqTvkZsLNcN0vKiW9poC4HMQijLLBM+uo+MZO5mhQQ=; b=Iqrfkxebw6doSbr6dFoBe6G840mqsRiV7ReAUwyxCOrQ2BkfYE5724Fka2Crmb4lxl g4uD9GttyapXRHUAerrqjssmnJ24crqe1TrygQUKtKDU1uZf4ilcgvEo1n1Yjlf1i/Sj akUmaYfcUv1fs0ZUdNwLiUzAp7YPw2GYSFXY0BmsaXvx8saqHXPOfs9Cn3HFIeEoxVWm dAcXAGgeLQIbHHzyrAgoBYuvsMg0Da6A+XSrRPTtA4EEFkDPPeRN8rj3kuGEPgdwPIro GgR3UTf9IhkXU9jdg5yEDhCUHT64CcqNEz3KUX3qPDSOExJEKli7zSNfpHCH91WcWKDp 1Pnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697667555; x=1698272355; 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=uuqTvkZsLNcN0vKiW9poC4HMQijLLBM+uo+MZO5mhQQ=; b=XmhvFDTD+UlykpLoN3ycVLAPXwMBSfh3JgTCMmD3Z/MNH2bTfsO2j53ID4jFYQmZRH WWHEMVkCzIhC5CkAtD1stcKrzhxldzeyh/zfevjrOQXLsr5tB/62hySaOycuW+CeXXyl nSmg1qLl/k0xBrHJGtj0LpJrAjdp+1zwGCgaFNmc/9SDIIrbyzRZaqrk7s0BxCbCJu13 ms7QmaT+0znmX6ZBSZMPiySc7kCPawcD6i2wbGwXl/hxqQ9+J5C446UreDCjRGSVV8WA OaViYyZluypC8akQtBBQJQQi8/+BGKcLIypa1YvJOIgvgDat4twWs2ODP6lkhqjY12A2 hq7g== X-Gm-Message-State: AOJu0YxdwrUqrbcngans8UHBgYQkSXRSXLVfRHHC+E8snriX2e3zENjP C8Di5VOyCksPksxMJzdMYZ3gEQ== X-Google-Smtp-Source: AGHT+IGH8wlsFfSwy2DzfGJ0wHx7SWl+MDQkarJ6/kvkpATpF9Tz7csQMF88Wxn4r1UQ/dZ1DeKpqQ== X-Received: by 2002:a25:ef48:0:b0:d9b:4f28:4f7a with SMTP id w8-20020a25ef48000000b00d9b4f284f7amr705063ybm.55.1697667555486; Wed, 18 Oct 2023 15:19:15 -0700 (PDT) Received: from ghost ([208.116.208.98]) by smtp.gmail.com with ESMTPSA id bs40-20020a05620a472800b0077892023fc5sm278376qkb.120.2023.10.18.15.19.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 15:19:15 -0700 (PDT) Date: Wed, 18 Oct 2023 15:19:11 -0700 From: Charlie Jenkins To: Samuel Holland 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 Subject: Re: [PATCH v4 1/2] riscv: Add remaining module relocations Message-ID: References: <20231017-module_relocations-v4-0-937f5ef316f0@rivosinc.com> <20231017-module_relocations-v4-1-937f5ef316f0@rivosinc.com> <2fea6698-7446-443b-9026-c4b082a9f809@sifive.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2fea6698-7446-443b-9026-c4b082a9f809@sifive.com> X-Rspamd-Queue-Id: 7827C4001E X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: gtxed5j5ugmfyatdqko8u7bj1fgyb33e X-HE-Tag: 1697667556-572305 X-HE-Meta: U2FsdGVkX199IB28ezQWwGA56rPd2AnF0Y6LrBiWmIM4sZucDeqdIIi/gsB4EpURzpcdr04x4bXCO1EPT6qwyAymn8O3PbKCd8EBtSaIRJpbCQMSuBlWt+KgEP8mMDqDDE3wVdXvZUVROs5Q1gi1l0ANVNv/tlaCjhYpJSkIKiIUZYuepiqKrT+rYVLrLp+jnWRCrWGVGggKvlebaJlltobm5CEoY+w2q63AOr5110YEXq7b7ypbYq1pjoqVwyUxrH3qmDkA69NOdiDnJb7xEjVvXeckEzeaya04zCn5RAJ+GrlFXwhwpnjjjn1ZnEVOq1UQGV4xNYMflvY1jkJDn5Zr50vhpadRQIOv6qAreRN0Jz7Qc4kUvCuU+rWsRDal9Xq3K4DUw7IBEv/+QReFAn2da7+4rVcMoOJwCcXmqW+yriA0GNgxKGos49nHUQ35+sN0ZHHQQxbb1wELutxBma4LIkX69nOEn7fVdQMYLieNZ4DaREGRY9lcqfzDL3XqGgSalKhD1p1VzSkat9CR/L3Im7m3LJCPKXna9BLhaORQf91H+1sh1h51704uSdf+pqnKhSOzdkG1sZFFI5FWkpgFtcO4Y6oKLC0qeVCWwYOeWDt2vGpg2LCUwq4MVZJ9RsJsYsFX47E+WQ3/0eWqr+gAooOrDsNm7XWxpQvoXos65OrQjJYg3iyhE5i+wYGxExWteeVxVqy01rOR7JfAGgvvAa7LJUKEV8qK81JK9VRngWpuG3/h0OfEYd3hbcwJxJQRQGS1Cd5/w0fR7Fx/PQW0id/sxNjWDTk3WUIxMXBUmegDIPZmccnEHyJQA5I+gtrOZsC+VahpaaZn1WojkrQlRqT+cS7M2twvZw4YOFY6RLCFSZRC6l3cVInKgKuhm4c2BJQvzjW75sPPLBpskLnK2mUKE31bicObXkLXUvL/Y9QOR3xz7RCBm+9BQBOlgmf2bNdPNIGVGAvc8Wn Cf8L+3NY 7+OrLfHuCBslBqp2B5vze9tJ57x5+wCcU/o2P0Z902e4Y/7Xn9FmuXdF9K/+uDnJtAUwi6lm2slOvfAMIpjQfzs23zA6zZ9CG5KVaUlBK6CIqk4PVsgURzdUONiWhlXUYdLU1aOpgUtR2mtXubfCsRKzbc1OlhNpIeQ6Pb+u+K3kZ2LxVV0CKkvqTn/VhGAFM5KPQDnTf8XGoM1IK4pZoA5KYIwWlGihT8Yxhfcl1vfrHJdUpENBWTvEUeeQmq+qD9muMVYVomDKmPVvnsWbd0yJ8o0CJCYrQHP8oYiWeKQPJi2MMy8v7qxblTsANrHHkA2YjFqOdD/7Cp/S1wDpCFSQekch505znZbOwLj0a0HwYuqt/X15PRZuNWMfhGAkpUn2t7PFYgSD+heKPYBgMOTCBiP1ZXRu5zJFVYky5tTzcFlegiLHXT68phDhbtcBe0VZwjE9wP2qQ4HoJOx5Ih+12DWWeiszTjTIY X-Bogosity: Ham, tests=bogofilter, spamicity=0.000004, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Oct 18, 2023 at 01:28:45PM -0500, Samuel Holland wrote: > 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 > Thank you for pointing out these issues. > > + 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. > I guess that never made it out of my thoughts and into the code... - Charlie > 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); > > >