- -Wl,-segaddr,__INITPT,0xffffff8000100000 \
- -Wl,-segaddr,__INITGDT,0xffffff8000106000 \
- -Wl,-segaddr,__SLEEP,0xffffff8000107000 \
- -Wl,-segaddr,__HIB,0xffffff8000108000 \
- -Wl,-image_base,0xffffff8000200000 \
- -Wl,-seg_page_size,__TEXT,0x200000
-
-export LDFLAGS_KERNEL_DEBUGX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
-export LDFLAGS_KERNEL_DEVELOPMENTX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
-export LDFLAGS_KERNEL_PROFILEX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
-
-export LDFLAGS_KERNEL_ARM = \
- -Wl,-new_linker \
- -Wl,-pagezero_size,0x0 \
- -Wl,-segaddr,__HIB,0xC0000000 \
- -Wl,-image_base,0xC0008000
-
-
-export LDFLAGS_KERNEL = $(LDFLAGS_KERNEL_GEN) \
- $($(addsuffix $(MACHINE_CONFIG),MACHINE_FLAGS_)) \
- $($(addsuffix $(ARCH_CONFIG),ARCH_FLAGS_)) \
- $($(addsuffix $(ARCH_CONFIG),LDFLAGS_KERNEL_)) \
- $($(addsuffix $(KERNEL_CONFIG),LDFLAGS_KERNEL_)) \
- $($(addsuffix $(ARCH_CONFIG), $(addsuffix $(KERNEL_CONFIG),LDFLAGS_KERNEL_))) \
-
+ -Wl,-version_load_command \
+ -Wl,-function_starts \
+ -Wl,-headerpad,152
+
+LDFLAGS_KERNEL_RELEASE =
+LDFLAGS_KERNEL_DEVELOPMENT =
+LDFLAGS_KERNEL_DEBUG =
+LDFLAGS_KERNEL_PROFILE =
+
+# KASLR static slide config:
+ifndef SLIDE
+SLIDE=0x00
+endif
+KERNEL_MIN_ADDRESS = 0xffffff8000000000
+KERNEL_BASE_OFFSET = 0x100000
+KERNEL_STATIC_SLIDE = $(shell printf "0x%016x" \
+ $$[ $(SLIDE) << 21 ])
+KERNEL_STATIC_BASE = $(shell printf "0x%016x" \
+ $$[ $(KERNEL_MIN_ADDRESS) + $(KERNEL_BASE_OFFSET) ])
+KERNEL_HIB_SECTION_BASE = $(shell printf "0x%016x" \
+ $$[ $(KERNEL_STATIC_BASE) + $(KERNEL_STATIC_SLIDE) ])
+KERNEL_TEXT_BASE = $(shell printf "0x%016x" \
+ $$[ $(KERNEL_HIB_SECTION_BASE) + 0x100000 ])
+
+LDFLAGS_KERNEL_RELEASEX86_64 = \
+ -Wl,-pie \
+ -Wl,-segaddr,__HIB,$(KERNEL_HIB_SECTION_BASE) \
+ -Wl,-image_base,$(KERNEL_TEXT_BASE) \
+ -Wl,-seg_page_size,__TEXT,0x200000 \
+ -Wl,-sectalign,__DATA,__const,0x1000 \
+ -Wl,-sectalign,__DATA,__sysctl_set,0x1000 \
+ -Wl,-sectalign,__HIB,__bootPT,0x1000 \
+ -Wl,-sectalign,__HIB,__desc,0x1000 \
+ -Wl,-sectalign,__HIB,__data,0x1000 \
+ -Wl,-sectalign,__HIB,__text,0x1000 \
+ -Wl,-sectalign,__HIB,__const,0x1000 \
+ -Wl,-sectalign,__HIB,__bss,0x1000 \
+ -Wl,-sectalign,__HIB,__common,0x1000 \
+ $(LDFLAGS_NOSTRIP_FLAG)
+
+# Define KERNEL_BASE_OFFSET so known at compile time:
+CFLAGS_X86_64 += -DKERNEL_BASE_OFFSET=$(KERNEL_BASE_OFFSET)
+
+LDFLAGS_KERNEL_DEBUGX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
+LDFLAGS_KERNEL_DEVELOPMENTX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
+LDFLAGS_KERNEL_PROFILEX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
+
+
+LDFLAGS_KERNEL = $(LDFLAGS_KERNEL_GEN) \
+ $($(addsuffix $(CURRENT_ARCH_CONFIG),ARCH_FLAGS_)) \
+ $($(addsuffix $(CURRENT_ARCH_CONFIG),LDFLAGS_KERNEL_)) \
+ $($(addsuffix $(CURRENT_KERNEL_CONFIG),LDFLAGS_KERNEL_)) \
+ $($(addsuffix $(CURRENT_ARCH_CONFIG), $(addsuffix $(CURRENT_KERNEL_CONFIG),LDFLAGS_KERNEL_))) \
+ $(DEPLOYMENT_TARGET_FLAGS)