Skip to content

Commit e3d0359

Browse files
hjl-toolsIngo Molnar
authored andcommitted
x86/build/64: Force the linker to use 2MB page size
Binutils 2.31 will enable -z separate-code by default for x86 to avoid mixing code pages with data to improve cache performance as well as security. To reduce x86-64 executable and shared object sizes, the maximum page size is reduced from 2MB to 4KB. But x86-64 kernel must be aligned to 2MB. Pass -z max-page-size=0x200000 to linker to force 2MB page size regardless of the default page size used by linker. Tested with Linux kernel 4.15.6 on x86-64. Signed-off-by: H.J. Lu <[email protected]> Cc: Andy Shevchenko <[email protected]> Cc: Eric Biederman <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Juergen Gross <[email protected]> Cc: Kees Cook <[email protected]> Cc: Kirill A. Shutemov <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/CAMe9rOp4_%[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 4b0b37d commit e3d0359

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

arch/x86/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,15 @@ KBUILD_CFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr)
223223

224224
LDFLAGS := -m elf_$(UTS_MACHINE)
225225

226+
#
227+
# The 64-bit kernel must be aligned to 2MB. Pass -z max-page-size=0x200000 to
228+
# the linker to force 2MB page size regardless of the default page size used
229+
# by the linker.
230+
#
231+
ifdef CONFIG_X86_64
232+
LDFLAGS += $(call ld-option, -z max-page-size=0x200000)
233+
endif
234+
226235
# Speed up the build
227236
KBUILD_CFLAGS += -pipe
228237
# Workaround for a gcc prelease that unfortunately was shipped in a suse release

0 commit comments

Comments
 (0)