Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/build: Build compressed x86 kernels as PIE when !CONFIG_RELOCATABLE as well

Since the bootloader may load the compressed x86 kernel at any address,
it should always be built as PIE, not just when CONFIG_RELOCATABLE=y.

Otherwise, linker in binutils 2.27 will optimize GOT load into the
absolute address when building the compressed x86 kernel as a non-PIE
executable.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Cc: Andy Lutomirski <luto@kernel.org>
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: Josh Poimboeuf <jpoimboe@redhat.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
[ Small wording changes. ]
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

H.J. Lu and committed by
Ingo Molnar
a980ce35 8c5c86fb

+2 -3
+2 -3
arch/x86/boot/compressed/Makefile
··· 40 40 UBSAN_SANITIZE :=n 41 41 42 42 LDFLAGS := -m elf_$(UTS_MACHINE) 43 - ifeq ($(CONFIG_RELOCATABLE),y) 44 - # If kernel is relocatable, build compressed kernel as PIE. 43 + # Compressed kernel should be built as PIE since it may be loaded at any 44 + # address by the bootloader. 45 45 ifeq ($(CONFIG_X86_32),y) 46 46 LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker) 47 47 else ··· 50 50 # command-line option, -z noreloc-overflow. 51 51 LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \ 52 52 && echo "-z noreloc-overflow -pie --no-dynamic-linker") 53 - endif 54 53 endif 55 54 LDFLAGS_vmlinux := -T 56 55