Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp613601pxb; Wed, 27 Jan 2021 16:48:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJyNlJu1Nr0RwgLQYRjiKmbHFIQ41ym5CPtzDiIN8CPC6G0aDIp5xBsoVOUBu6wq8hM0LvG3 X-Received: by 2002:a50:e40d:: with SMTP id d13mr8967403edm.286.1611794921220; Wed, 27 Jan 2021 16:48:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611794921; cv=none; d=google.com; s=arc-20160816; b=tLAb/UepxC7QAWrBusJ9337C2ly2eTk9lyDHWE8ALxRO7gzMW1mu69MREcPdP5MAc7 hy66k9ZKh69ut4wJRx2/ZIs+7NUUTV32sCtJdIERRRHeDz7axBqw8TlyLUfHI205/Ttp aMNw8ROLpnfkeOGtCGuzOM3r6T1GtcMKGZbv50dnI30olcEb7YLSV2q/83+jLekyWCZq qsKoR6wR7guw+klLXevZ0FgiK8ETuE5eXRSHaqI7Jd9hbyDzBooE0ehNfoH7hhyqLVhW 5D9BdptvzqBm0qed3UPmyl4HYynxPmvghIzvtNkN1w8YRlKRwN0ITglUU2HSMHM8uPtw IFPA== 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:in-reply-to :references:mime-version:dkim-signature; bh=EGTDub2HL3JRl4kOfLecB1flsjSx6VNDzS6CSE6flsM=; b=Tf/Uc9jtgQvS653lO3/zP9jugrFXy3qldZywkhly8xTCAkwN67un64/+xF+QsvinzR 5y1Nz/ZcQTX7xHugse/hkCPYYC5nKVyW8Dfni923JldtnYDvAcWsnd0dn4Fid4Byt0kV wzDzmisaDkndg2752r5anStlkUqtjrmb/vmGzgKELaGyK7k+TH9h4PinBzMQw7+mWHZi sfgjpeJXL4cUqanUu+rxXwQHXAR1nnbNOl3YwA7xdukSPUJELcqoWq1X1565U+MALdFo t0iKYYpwx4wO+0BbtiPFa2P53isd4i0rfbDhA+YagTqdrYpfg6NSJMFQ/yvsIHJyiQbc l6Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=cgoLzwUD; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j12si1515682ejt.34.2021.01.27.16.48.17; Wed, 27 Jan 2021 16:48:41 -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=@google.com header.s=20161025 header.b=cgoLzwUD; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234936AbhA0XYU (ORCPT + 99 others); Wed, 27 Jan 2021 18:24:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232548AbhA0W4v (ORCPT ); Wed, 27 Jan 2021 17:56:51 -0500 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11AFCC061793 for ; Wed, 27 Jan 2021 14:38:10 -0800 (PST) Received: by mail-pg1-x536.google.com with SMTP id i7so2676251pgc.8 for ; Wed, 27 Jan 2021 14:38:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=EGTDub2HL3JRl4kOfLecB1flsjSx6VNDzS6CSE6flsM=; b=cgoLzwUDbAVjRddaXVq2FgcSo7K3TpWHd9qMmev8D+6tJKyHW2ChVRhL/qkS0p8MHY G3zqernmCo5q35GHqR0BukiOxoZKjho9T9mqeI3K8w5tAXlXe+RQujKYv53f4ZJijsp7 2K6MhqJHLYc7MCAmnE+rqnVnEx3fp645iBZ2q240i94qju8f8g+ULdQo7/VKKWVt0GWV 2S4uvRxR4XhMmCrKWokavMQ3A24thBabISME2UreeEqOXNq5V0Vf2Mj1sAIXLd1RQoTg j4OSpn+LLM3ip8Ah9VzcQw4t+E21G82B7+dGVu2Fbaaj4Mrj/me2o+49B8otXwrkrFWD K0jQ== 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:from:date :message-id:subject:to:cc; bh=EGTDub2HL3JRl4kOfLecB1flsjSx6VNDzS6CSE6flsM=; b=LRCEOooRYGOS77emn3rDrWbHfi6wQZAaqGe6S5Wzv7P+3wUewvp5uN/ZaLnYj6eWdZ IIBR8EblZ7su+sUg6CEaD7bhfytqUPqYaCw0cG8VZsMVD/QCsUj5Z+rgqJdXag3AH1uN WhX5hNiOjsB6w4XNSSBcIGQ+mvVuCKutYO17djM8Ng1Mkf8YKskXQKsZZlt0Tv+k6qeP F+XblOgt5QI9f5ChKwCreEkzgmePx5PM9rH19xXABWdn0EaWXozkih4scb8sEPFz3sBw 8xXt9aWJSaI/1rcUVFqZhZif3prFlfaAbYZ5m0i8UZa1x5oazKp1+UsUEvKk/Ioz6k0p tf+g== X-Gm-Message-State: AOAM530cI9/MIh9fllL+EE/wXiYVu0ZhTcAc0Fp2LWVEttwyfQcjZAvC Atzqip1o/afu55NF1chkG694VYZ1ZXYcO6+TaAmp6Q== X-Received: by 2002:a62:1896:0:b029:197:491c:be38 with SMTP id 144-20020a6218960000b0290197491cbe38mr12776863pfy.15.1611787089325; Wed, 27 Jan 2021 14:38:09 -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> From: Nick Desaulniers Date: Wed, 27 Jan 2021 14:37:57 -0800 Message-ID: Subject: Re: [PATCH v4] x86: Treat R_386_PLT32 as R_386_PC32 To: Fangrui Song , Borislav Petkov Cc: Thomas Gleixner , Ingo Molnar , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , LKML , clang-built-linux , Michael Matz , Arnd Bergmann , 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 12:56 PM Fangrui Song 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. Boris, my CI is red since https://github.com/llvm/llvm-project/commit/a084c0388e2a59b9556f2de0083333232da3f1d6 landed (Dec 5) for i386. If you need a shorter (or less toolchain verbiage) commit message, please consider simply: ``` This is similar to commit b21ebf2fb4cd ("x86: Treat R_X86_64_PLT32 as R_X86_64_PC32"), but for i386. From that commit message: As far as the Linux kernel is concerned, R_386_PLT32 can be treated the same as R_386_PC32. clang-12 -fno-pic (since https://github.com/llvm/llvm-project/commit/a084c0388e2a59b9556f2de0083333232da3f1d6) can emit R_386_PLT32 for compiler generated function declarations. ``` It would help me abuse alcoholcoffee less to have one less fire. > > 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 > > --- > 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 > -- Thanks, ~Nick Desaulniers