android_kernel_oneplus_msm8998/arch
H.J. Lu 74a2862d96 x86/build: Build compressed x86 kernels as PIE
commit 6d92bc9d483aa1751755a66fee8fb39dffb088c0 upstream.

The 32-bit x86 assembler in binutils 2.26 will generate R_386_GOT32X
relocation to get the symbol address in PIC.  When the compressed x86
kernel isn't built as PIC, the linker optimizes R_386_GOT32X relocations
to their fixed symbol addresses.  However, when the compressed x86
kernel is loaded at a different address, it leads to the following
load failure:

  Failed to allocate space for phdrs

during the decompression stage.

If the compressed x86 kernel is relocatable at run-time, it should be
compiled with -fPIE, instead of -fPIC, if possible and should be built as
Position Independent Executable (PIE) so that linker won't optimize
R_386_GOT32X relocation to its fixed symbol address.

Older linkers generate R_386_32 relocations against locally defined
symbols, _bss, _ebss, _got and _egot, in PIE.  It isn't wrong, just less
optimal than R_386_RELATIVE.  But the x86 kernel fails to properly handle
R_386_32 relocations when relocating the kernel.  To generate
R_386_RELATIVE relocations, we mark _bss, _ebss, _got and _egot as
hidden in both 32-bit and 64-bit x86 kernels.

To build a 64-bit compressed x86 kernel as PIE, we need to disable the
relocation overflow check to avoid relocation overflow errors. We do
this with a new linker command-line option, -z noreloc-overflow, which
got added recently:

 commit 4c10bbaa0912742322f10d9d5bb630ba4e15dfa7
 Author: H.J. Lu <hjl.tools@gmail.com>
 Date:   Tue Mar 15 11:07:06 2016 -0700

    Add -z noreloc-overflow option to x86-64 ld

    Add -z noreloc-overflow command-line option to the x86-64 ELF linker to
    disable relocation overflow check.  This can be used to avoid relocation
    overflow check if there will be no dynamic relocation overflow at
    run-time.

The 64-bit compressed x86 kernel is built as PIE only if the linker supports
-z noreloc-overflow.  So far 64-bit relocatable compressed x86 kernel
boots fine even when it is built as a normal executable.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
[ Edited the changelog and comments. ]
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Paul Bolle <pebolle@tiscali.nl>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-10-20 10:00:47 +02:00
..
alpha alpha: fix copy_from_user() 2016-09-24 10:07:45 +02:00
arc ARC: uaccess: get_user to zero out dest in cause of fault 2016-09-24 10:07:44 +02:00
arm ARM: dts: MSM8064 remove flags from SPMI/MPP IRQs 2016-10-16 17:36:15 +02:00
arm64 arm64: debug: avoid resetting stepping state machine when TIF_SINGLESTEP 2016-10-07 15:23:42 +02:00
avr32 avr32: off by one in at32_init_pio() 2016-10-07 15:23:45 +02:00
blackfin net: smc91x: fix SMC accesses 2016-09-30 10:18:37 +02:00
c6x
cris cris: buggered copy_from_user/copy_to_user/clear_user 2016-09-24 10:07:44 +02:00
frv frv: fix clear_user() 2016-09-24 10:07:44 +02:00
h8300 h8300 update for v4.4 2015-11-12 15:26:39 -08:00
hexagon hexagon: fix strncpy_from_user() error return 2016-09-24 10:07:44 +02:00
ia64 ia64: copy_from_user() should zero the destination on access_ok() failure 2016-09-24 10:07:46 +02:00
m32r m32r: fix __get_user() 2016-09-24 10:07:43 +02:00
m68k m68k: Wire up mlock2 2015-11-22 11:35:26 +01:00
metag metag: copy_from_user() should zero the destination on access_ok() failure 2016-09-24 10:07:45 +02:00
microblaze microblaze: fix copy_from_user() 2016-09-24 10:07:43 +02:00
mips KVM: MIPS: Drop other CPU ASIDs on guest MMU changes 2016-10-16 17:36:14 +02:00
mn10300 mn10300: copy_from_user() should zero on access_ok() failure... 2016-09-24 10:07:45 +02:00
nios2 nios2: copy_from_user() should zero the tail of destination 2016-09-24 10:07:45 +02:00
openrisc openrisc: fix the fix of copy_from_user() 2016-09-24 10:07:46 +02:00
parisc parisc: fix copy_from_user() 2016-09-24 10:07:45 +02:00
powerpc KVM: PPC: BookE: Fix a sanity check 2016-10-16 17:36:15 +02:00
s390 s390: get_user() should zero on failure 2016-09-24 10:07:44 +02:00
score score: fix copy_from_user() and friends 2016-09-24 10:07:44 +02:00
sh sh: fix copy_from_user() 2016-09-24 10:07:44 +02:00
sparc sparc32: fix copy_from_user() 2016-09-24 10:07:45 +02:00
tile tile: Define AT_VECTOR_SIZE_ARCH for ARCH_DLINFO 2016-10-07 15:23:44 +02:00
um um: Don't discard .text.exit section 2016-09-07 08:32:38 +02:00
unicore32 pwm: Changes for v4.4-rc1 2015-11-11 09:16:10 -08:00
x86 x86/build: Build compressed x86 kernels as PIE 2016-10-20 10:00:47 +02:00
xtensa xtensa: clear all DBREAKC registers on start 2016-04-12 09:08:55 -07:00
.gitignore
Kconfig