Patch "x86/build: Treat R_386_PLT32 relocation as R_386_PC32" has been added to the 4.4-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    x86/build: Treat R_386_PLT32 relocation as R_386_PC32

to the 4.4-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     x86-build-treat-r_386_plt32-relocation-as-r_386_pc32.patch
and it can be found in the queue-4.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit f4eb35a321448899fc0b5c3b3e9c6ddab0478389
Author: Fangrui Song <maskray@xxxxxxxxxx>
Date:   Wed Jan 27 12:56:00 2021 -0800

    x86/build: Treat R_386_PLT32 relocation as R_386_PC32
    
    [ Upstream commit bb73d07148c405c293e576b40af37737faf23a6a ]
    
    This is similar to commit
    
      b21ebf2fb4cd ("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:
    
      https://github.com/ClangBuiltLinux/linux/issues/1210
      https://sourceware.org/bugzilla/show_bug.cgi?id=27169
      https://github.com/llvm/llvm-project/commit/a084c0388e2a59b9556f2de0083333232da3f1d6 [1]
    
     [ bp: Massage commit message. ]
    
    Reported-by: Arnd Bergmann <arnd@xxxxxxxx>
    Signed-off-by: Fangrui Song <maskray@xxxxxxxxxx>
    Signed-off-by: Borislav Petkov <bp@xxxxxxx>
    Reviewed-by: Nick Desaulniers <ndesaulniers@xxxxxxxxxx>
    Reviewed-by: Nathan Chancellor <natechancellor@xxxxxxxxx>
    Tested-by: Nick Desaulniers <ndesaulniers@xxxxxxxxxx>
    Tested-by: Nathan Chancellor <natechancellor@xxxxxxxxx>
    Tested-by: Sedat Dilek <sedat.dilek@xxxxxxxxx>
    Link: https://lkml.kernel.org/r/20210127205600.1227437-1-maskray@xxxxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
index 94779f66bf49..6f0d340594ca 100644
--- a/arch/x86/kernel/module.c
+++ b/arch/x86/kernel/module.c
@@ -124,6 +124,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 5b6c8486a0be..d1c3f82c7882 100644
--- a/arch/x86/tools/relocs.c
+++ b/arch/x86/tools/relocs.c
@@ -839,9 +839,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;
 
@@ -882,9 +884,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;
 



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux