Skip to content

Commit 81c5d3a

Browse files
MaskRayksacilotto
authored andcommitted
x86/build: Treat R_386_PLT32 relocation as R_386_PC32
BugLink: https://bugs.launchpad.net/bugs/1920235 [ Upstream commit bb73d07 ] This is similar to commit b21ebf2 ("x86: Treat R_X86_64_PLT32 as R_X86_64_PC32") but for i386. As far as the 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. clang-12 -fno-pic (since [1]) can emit R_386_PLT32 for compiler generated function declarations, because preventing canonical PLT entries is weighed over the rare ifunc diagnostic. Further info for the more interested: ClangBuiltLinux/linux#1210 https://sourceware.org/bugzilla/show_bug.cgi?id=27169 llvm/llvm-project@a084c03 [1] [ bp: Massage commit message. ] Reported-by: Arnd Bergmann <[email protected]> Signed-off-by: Fangrui Song <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Nick Desaulniers <[email protected]> Reviewed-by: Nathan Chancellor <[email protected]> Tested-by: Nick Desaulniers <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Tested-by: Sedat Dilek <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Kamal Mostafa <[email protected]> Signed-off-by: Kelsey Skunberg <[email protected]>
1 parent f2ed1b3 commit 81c5d3a

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

arch/x86/kernel/module.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ int apply_relocate(Elf32_Shdr *sechdrs,
114114
*location += sym->st_value;
115115
break;
116116
case R_386_PC32:
117+
case R_386_PLT32:
117118
/* Add the value, subtract its position */
118119
*location += sym->st_value - (uint32_t)location;
119120
break;

arch/x86/tools/relocs.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -867,9 +867,11 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
867867
case R_386_PC32:
868868
case R_386_PC16:
869869
case R_386_PC8:
870+
case R_386_PLT32:
870871
/*
871-
* NONE can be ignored and PC relative relocations don't
872-
* need to be adjusted.
872+
* NONE can be ignored and PC relative relocations don't need
873+
* to be adjusted. Because sym must be defined, R_386_PLT32 can
874+
* be treated the same way as R_386_PC32.
873875
*/
874876
break;
875877

@@ -910,9 +912,11 @@ static int do_reloc_real(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
910912
case R_386_PC32:
911913
case R_386_PC16:
912914
case R_386_PC8:
915+
case R_386_PLT32:
913916
/*
914-
* NONE can be ignored and PC relative relocations don't
915-
* need to be adjusted.
917+
* NONE can be ignored and PC relative relocations don't need
918+
* to be adjusted. Because sym must be defined, R_386_PLT32 can
919+
* be treated the same way as R_386_PC32.
916920
*/
917921
break;
918922

0 commit comments

Comments
 (0)