Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp628094pxb; Wed, 27 Jan 2021 17:16:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJyh/5RMcuUR8ur8uCHFBgrfS2STzKfhdzbbskXxlRO7/FrclgPthDqg4Kr6a35EA2RmjdUy X-Received: by 2002:a17:906:f246:: with SMTP id gy6mr8590108ejb.264.1611796611330; Wed, 27 Jan 2021 17:16:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611796611; cv=none; d=google.com; s=arc-20160816; b=CofMPjaxMIdivJ6NADxi/FUQ4M5I32QSpOfy9bBIeC2SLoSeeZGCSdiRKGeCeF1d8W gKmu98pg8VjQetpHg2sM1frOmbhV5AEDNGXJW1D0AH7O9JfPjK5VWXAMylRBiaVLAzUN LORiext8qJ2F8DPViyZtVFyqDj0O6wfZ2r/moQC5gfg/34SDLCfaWUVdOIL8nATlSGUu EUd3GWPgEICTUE2JMx5E0yv2SLKwLd3lfLe7cDW/+LUW//cTHFNCNHh/Rz/sy388rBnp KR1CCLCxep/AzRfeH+Xx44gwogabhfdXPArZf4pcMRgWIrvDOwX+iTfR1eIruD405msk t6Pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:reply-to :in-reply-to:references:mime-version:dkim-signature; bh=v+u1DiVrW3O+pldsYbx0PikwzegMHzk/tjgfkZuCvGg=; b=fm+3ii+rJDQjtY9+sRQ+/pk86Sm7tQPmeJOeB59bqFF9Rl7TOkInOnj5efVRhev9UT +I4Hb89dkUMGytazQ05gQ44Z6AW2IPp1iLo32bn0ReHDqzitrk/Edtdl8vC9mECXJatM Dt7RVRfgZKE9+yWGSJrE4+lEzohvS+FDkaPCjOaMIu/yBn5LwP2B5JCPhOlluwKYIGlx aLy7J/i0TBn9+vfgwHiihVNNXTu5ToCOA02tkEiy9mwoGtdo5M+hbtb7XW0gCvHolrAY OwuegrCCbXI2BZZVviPsNfp/rus2vN02yeMVBNiKv5kn5s3LYUdp6McxhB3Kerq7y/22 uh3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="pI/cGUyN"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kd11si1506334ejc.330.2021.01.27.17.16.27; Wed, 27 Jan 2021 17:16:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="pI/cGUyN"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231564AbhA1BNf (ORCPT + 99 others); Wed, 27 Jan 2021 20:13:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231656AbhA1BLP (ORCPT ); Wed, 27 Jan 2021 20:11:15 -0500 Received: from mail-il1-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94AE0C06174A for ; Wed, 27 Jan 2021 17:10:35 -0800 (PST) Received: by mail-il1-x134.google.com with SMTP id d6so3731476ilo.6 for ; Wed, 27 Jan 2021 17:10:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:reply-to:from:date:message-id :subject:to:cc; bh=v+u1DiVrW3O+pldsYbx0PikwzegMHzk/tjgfkZuCvGg=; b=pI/cGUyNW+neaOvEcVmBjKcIhXcIDz9dj5cGJuj36sCqj04fRmMzT0CtZW60lccJpW yob4Gjy/p3kpf24dpBShsMUWLCUx7PB+0AS7amQ9UEkBcwJ1VJQIGV/bs6UwcbCm7PVF M9DEVf9N1cqMpAgIWVtRVSUJ1L8LtGYORXMEeOhFRyZH2XgbK1zWCFEX3LV/3muLitUF HGYaRLTVgw4dmQUdt+b0XpstSNEgiqhj1T3H8KoGs0fbiHrAsxbDdKixWBkQRCtjqsPo 1AfDjrKFo0ZMeNqHBnG+8s2ZCbU2Nzkz3TDJ8dXMnIEXEU4XulD1vx/E5csmT6WQhbFJ 4MwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:reply-to :from:date:message-id:subject:to:cc; bh=v+u1DiVrW3O+pldsYbx0PikwzegMHzk/tjgfkZuCvGg=; b=Tu3NJysyTwURm4ReQUOc8AXx8ZYIvXzVKRCnjDjxcZ9YAOeClTVcxd/l09stiUZNvl tbkNbU7zqSYjpkBwQBX7HTZYexF8j+zxhxnvbgqW/vRPIIJwFCjWid5Uo/D6FWLRMCtJ iJ8D+2TGZMyOvMCA4LdTTk0WuD4kKkB8H3b/HGnxNT07fVRPuxdY+wTTOoA9/xnyZGco xz9hr7hsOixm4mgpq57xHBlQSvfA0KU41tFOfqgIvda1udXJugkaPiZeAvqkZ+i31GI2 m88kRqDdKtM87hxp/7i74azORzEMc+T55D+oxinWQQCCJUjZ0xKRaWyH8lY/H3YzugiF K/vA== X-Gm-Message-State: AOAM532mo47GDvD4fVzLZUx/MmZxH4UP/wdOU5koAO9df79f+3sulvWo i+ciWu2YyfxcrFhgScZj5MFXV/Jt7b6WlLoV854= X-Received: by 2002:a05:6e02:e94:: with SMTP id t20mr11016518ilj.10.1611796234823; Wed, 27 Jan 2021 17:10:34 -0800 (PST) MIME-Version: 1.0 References: <20210125172956.j2prlchhqwfcgzuc@google.com> <20210127205600.1227437-1-maskray@google.com> In-Reply-To: <20210127205600.1227437-1-maskray@google.com> Reply-To: sedat.dilek@gmail.com From: Sedat Dilek Date: Thu, 28 Jan 2021 02:10:23 +0100 Message-ID: Subject: Re: [PATCH v4] x86: Treat R_386_PLT32 as R_386_PC32 To: Fangrui Song Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, linux-kernel@vger.kernel.org, Clang-Built-Linux ML , Michael Matz , Arnd Bergmann , Nick Desaulniers , Nathan Chancellor Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 27, 2021 at 9:56 PM 'Fangrui Song' via Clang Built Linux wrote: > > This is similar to commit b21ebf2fb4cd ("x86: Treat R_X86_64_PLT32 as > R_X86_64_PC32"), but for i386. As far as Linux kernel is concerned, > R_386_PLT32 can be treated the same as R_386_PC32. > > R_386_PLT32/R_X86_64_PLT32 are PC-relative relocation types which can > only be used by branches. If the referenced symbol is defined > externally, a PLT will be used. > R_386_PC32/R_X86_64_PC32 are PC-relative relocation types which can be > used by address taking operations and branches. If the referenced symbol > is defined externally, a copy relocation/canonical PLT entry will be > created in the executable. > > On x86-64, there is no PIC vs non-PIC PLT distinction and an > R_X86_64_PLT32 relocation is produced for both `call/jmp foo` and > `call/jmp foo@PLT` with newer (2018) GNU as/LLVM integrated assembler. > This avoids canonical PLT entries (st_shndx=0, st_value!=0). > > On i386, there are 2 types of PLTs, PIC and non-PIC. Currently the > GCC/GNU as convention is to use R_386_PC32 for non-PIC PLT and > R_386_PLT32 for PIC PLT. Copy relocations/canonical PLT entries are > possible ABI issues but GCC/GNU as will likely keep the status quo > because (1) the ABI is legacy (2) the change will drop a GNU ld > diagnostic for non-default visibility ifunc in shared objects. > https://sourceware.org/bugzilla/show_bug.cgi?id=27169 > > clang-12 -fno-pic (since > https://github.com/llvm/llvm-project/commit/a084c0388e2a59b9556f2de0083333232da3f1d6) > can emit R_386_PLT32 for compiler generated function declarations, > because preventing canonical PLT entries is weighed over the rare ifunc > diagnostic. > > Link: https://github.com/ClangBuiltLinux/linux/issues/1210 > Reported-by: Arnd Bergmann > Signed-off-by: Fangrui Song > Reviewed-by: Nick Desaulniers > Reviewed-by: Nathan Chancellor > Tested-by: Nick Desaulniers > Tested-by: Nathan Chancellor > Tested-by: Sedat Dilek # v3 - Sedat - > --- > Change in v2: > * Improve commit message > --- > Change in v3: > * Change the GCC link to the more relevant GNU as link. > * Fix the relevant llvm-project commit. > --- > Change in v4: > * Improve comments and commit message > --- > arch/x86/kernel/module.c | 1 + > arch/x86/tools/relocs.c | 12 ++++++++---- > 2 files changed, 9 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c > index 34b153cbd4ac..5e9a34b5bd74 100644 > --- a/arch/x86/kernel/module.c > +++ b/arch/x86/kernel/module.c > @@ -114,6 +114,7 @@ int apply_relocate(Elf32_Shdr *sechdrs, > *location += sym->st_value; > break; > case R_386_PC32: > + case R_386_PLT32: > /* Add the value, subtract its position */ > *location += sym->st_value - (uint32_t)location; > break; > diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c > index ce7188cbdae5..1c3a1962cade 100644 > --- a/arch/x86/tools/relocs.c > +++ b/arch/x86/tools/relocs.c > @@ -867,9 +867,11 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym, > case R_386_PC32: > case R_386_PC16: > case R_386_PC8: > + case R_386_PLT32: > /* > - * NONE can be ignored and PC relative relocations don't > - * need to be adjusted. > + * NONE can be ignored and PC relative relocations don't need > + * to be adjusted. Because sym must be defined, R_386_PLT32 can > + * be treated the same way as R_386_PC32. > */ > break; > > @@ -910,9 +912,11 @@ static int do_reloc_real(struct section *sec, Elf_Rel *rel, Elf_Sym *sym, > case R_386_PC32: > case R_386_PC16: > case R_386_PC8: > + case R_386_PLT32: > /* > - * NONE can be ignored and PC relative relocations don't > - * need to be adjusted. > + * NONE can be ignored and PC relative relocations don't need > + * to be adjusted. Because sym must be defined, R_386_PLT32 can > + * be treated the same way as R_386_PC32. > */ > break; > > -- > 2.30.0.280.ga3ce27912f-goog > > -- > You received this message because you are subscribed to the Google Groups "Clang Built Linux" group. > To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-linux+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20210127205600.1227437-1-maskray%40google.com.