[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAKwvOdkWkBMzFmYdLtdJswXdL2U7ycteVvmZLwk8AUvtrAy6gQ@mail.gmail.com>
Date: Wed, 27 Jan 2021 14:37:57 -0800
From: Nick Desaulniers <ndesaulniers@...gle.com>
To: Fangrui Song <maskray@...gle.com>, Borislav Petkov <bp@...en8.de>
Cc: Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>,
"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" <x86@...nel.org>,
LKML <linux-kernel@...r.kernel.org>,
clang-built-linux <clang-built-linux@...glegroups.com>,
Michael Matz <matz@...e.de>, Arnd Bergmann <arnd@...db.de>,
Nathan Chancellor <natechancellor@...il.com>
Subject: Re: [PATCH v4] x86: Treat R_386_PLT32 as R_386_PC32
On Wed, Jan 27, 2021 at 12:56 PM Fangrui Song <maskray@...gle.com> 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@...` 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 <strikethrough>alcohol</strikethrough>coffee
less to have one less fire.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/1210
> Reported-by: Arnd Bergmann <arnd@...db.de>
> Signed-off-by: Fangrui Song <maskray@...gle.com>
> Reviewed-by: Nick Desaulniers <ndesaulniers@...gle.com>
> Reviewed-by: Nathan Chancellor <natechancellor@...il.com>
> Tested-by: Nick Desaulniers <ndesaulniers@...gle.com>
> Tested-by: Nathan Chancellor <natechancellor@...il.com>
>
> ---
> 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
Powered by blists - more mailing lists