alistair23-linux/arch/x86/boot
H.J. Lu 6d92bc9d48 x86/build: Build compressed x86 kernels as PIE
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>
2016-03-29 12:51:12 +02:00
..
compressed x86/build: Build compressed x86 kernels as PIE 2016-03-29 12:51:12 +02:00
tools x86/boot: Remove unused 'is_big_kernel' variable 2016-02-16 09:16:58 +01:00
.gitignore x86: remove offsets.h from .gitignore and dontdiff 2012-11-19 14:10:53 +01:00
a20.c x86, setup: "glove box" BIOS interrupts in the core boot code 2009-04-09 16:08:11 -07:00
apm.c x86, setup: "glove box" BIOS interrupts in the APM code 2009-04-09 16:08:11 -07:00
bioscall.S x86, boot: Move intcall() to the .inittext section 2014-01-04 14:29:08 -08:00
bitops.h x86: remove pointless comments 2008-04-19 19:19:54 +02:00
boot.h x86/mm: Fix regression with huge pages on PAE 2015-12-04 09:14:27 +01:00
cmdline.c x86, boot: Pass cmd_line_ptr with unsigned long instead 2013-01-29 15:26:09 -08:00
code16gcc.h x86, build: Change code16gcc.h from a C header to an assembly header 2014-06-04 13:16:48 -07:00
copy.S x86, boot: Use .code16 instead of .code16gcc 2014-01-04 13:59:06 -08:00
cpu.c x86: Support compiling out human-friendly processor feature names 2014-08-17 15:54:00 -07:00
cpucheck.c Merge branch 'x86/boot' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2014-04-02 12:23:49 -07:00
cpuflags.c x86, boot: Fix word-size assumptions in has_eflag() inline asm 2014-01-30 08:04:32 -08:00
cpuflags.h x86/cpufeature: Carve out X86_FEATURE_* 2016-01-30 11:22:17 +01:00
ctype.h x86, setup: Rename BOOT_ISDIGIT_H to BOOT_CTYPE_H 2015-01-13 11:59:04 +01:00
early_serial_console.c x86, early_serial_console: Remove unnecessary check 2015-01-13 12:14:44 +01:00
edd.c x86, boot: Create a separate string.h file to provide standard string functions 2014-03-19 15:43:45 -07:00
header.S Merge branch 'x86/urgent' into core/efi, to pick up a pending EFI fix 2015-10-14 16:05:18 +02:00
install.sh kbuild: use INSTALLKERNEL to select customized installkernel script 2009-09-20 12:18:14 +02:00
main.c x86/boot: Obsolete the MCA sys_desc_table 2015-07-21 10:55:11 +02:00
Makefile kernel: add kcov code coverage 2016-03-22 15:36:02 -07:00
memory.c x86, setup: When probing memory with e801, use ax/bx as a pair 2011-04-25 14:52:37 -07:00
mkcpustr.c x86/cpufeature: Carve out X86_FEATURE_* 2016-01-30 11:22:17 +01:00
mtools.conf.in i386: move boot 2007-10-11 11:16:45 +02:00
pm.c x86: remove zImage support 2009-03-11 11:00:00 -07:00
pmjump.S x86, setup: move 32-bit code to .text32 2009-03-17 15:26:06 -07:00
printf.c x86/boot: Fix a sanity check in printf.c 2013-08-14 11:48:41 +02:00
regs.c x86, boot: Create a separate string.h file to provide standard string functions 2014-03-19 15:43:45 -07:00
setup.ld x86, boot: Define the 2.12 bzImage boot protocol 2013-01-27 15:56:37 -08:00
string.c x86/boot: Standardize strcmp() 2015-03-23 10:24:12 +01:00
string.h x86, boot: Move memcmp() into string.h and string.c 2014-03-19 15:44:04 -07:00
tty.c x86, setup: reorganize the early console setup 2010-08-02 15:51:56 -07:00
version.c kbuild: move utsrelease.h to include/generated 2009-12-12 13:08:15 +01:00
vesa.h x86-boot: don't request VBE2 information 2008-03-07 16:39:14 +01:00
video-bios.c x86: fix usage of bios intcall() 2009-07-04 12:56:32 -07:00
video-mode.c x86/mm: Fix regression with huge pages on PAE 2015-12-04 09:14:27 +01:00
video-vesa.c x86, boot: Create a separate string.h file to provide standard string functions 2014-03-19 15:43:45 -07:00
video-vga.c x86, setup: Set ax register in boot vga query 2010-06-10 15:24:29 -07:00
video.c x86/mm: Fix regression with huge pages on PAE 2015-12-04 09:14:27 +01:00
video.h x86/boot/video: Move the 'video_segment' variable to video.c 2015-02-19 00:25:05 +01:00