+export LDFLAGS_KERNEL_RELEASEI386 = \
+ -Wl,-segaddr,__INITPT,0x00100000 \
+ -Wl,-segaddr,__INITGDT,0x00106000 \
+ -Wl,-segaddr,__SLEEP,0x00107000 \
+ -Wl,-segaddr,__HIB,0x00108000 \
+ -Wl,-image_base,0x200000 \
+ -Wl,-seg_page_size,__TEXT,0x200000
+
+export LDFLAGS_KERNEL_DEBUGI386 = $(LDFLAGS_KERNEL_RELEASEI386)
+export LDFLAGS_KERNEL_DEVELOPMENTI386 = $(LDFLAGS_KERNEL_RELEASEI386)
+export LDFLAGS_KERNEL_PROFILEI386 = $(LDFLAGS_KERNEL_RELEASEI386)
+
+# 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 ])
+
+export 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 \
+
+# Define KERNEL_BASE_OFFSET so known at compile time:
+export CFLAGS_X86_64 += -DKERNEL_BASE_OFFSET=$(KERNEL_BASE_OFFSET)
+
+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_RELEASEARM = \
+ -Wl,-pie \
+ -Wl,-static \
+ -Wl,-image_base,0x80001000 \
+ -Wl,-exported_symbols_list,$(TARGET)/kernel-kpi.exp
+
+export LDFLAGS_KERNEL_DEVELOPMENTARM = \
+ -Wl,-pie \
+ -Wl,-static \
+ -Wl,-image_base,0x80001000
+
+export LDFLAGS_KERNEL_DEBUGARM = $(LDFLAGS_KERNEL_DEVELOPMENTARM)
+
+# Offset image base by page to have iBoot load kernel TEXT correctly.
+# First page is used for various purposes : sleep token, reset vector.