-export LDFLAGS_COMPONENT_GEN = -static -r $(COMP_LDFLAGS_COMPONENT_GEN)
-
-export LDFLAGS_COMPONENT_RELEASE = $(COMP_LDFLAGS_COMPONENT_RELEASE)
-export LDFLAGS_COMPONENT_DEBUG = $(COMP_LDFLAGS_COMPONENT_DEBUG)
-export LDFLAGS_COMPONENT_PROFILE = $(COMP_LDFLAGS_COMPONENT_PROFILE)
-
-export LDFLAGS_COMPONENT_PPC = -arch ppc $(COMP_LDFLAGS_COMPONENT_PPC)
-export LDFLAGS_COMPONENT_I386 = -arch i386 $(COMP_LDFLAGS_COMPONENT_i386)
-
-export LDFLAGS_COMPONENT = $(LDFLAGS_COMPONENT_GEN) \
- $($(addsuffix $(ARCH_CONFIG),LDFLAGS_COMPONENT_)) \
- $($(addsuffix $(KERNEL_CONFIG),LDFLAGS_COMPONENT_))
-
-export LDFLAGS_KERNEL_GEN = \
- -static \
- -force_cpusubtype_ALL \
- -e __start \
- -segalign 0x1000 \
- -sectalign __TEXT __text 0x1000 \
- -sectalign __DATA __common 0x1000 \
- -sectalign __DATA __bss 0x1000 \
- -sectcreate __PRELINK __text /dev/null \
- -sectcreate __PRELINK __symtab /dev/null \
- -sectcreate __PRELINK __info /dev/null
-
-export LDFLAGS_KERNEL_RELEASE =
-# -noseglinkedit
-export LDFLAGS_KERNEL_DEBUG =
-export LDFLAGS_KERNEL_PROFILE =
-
-export LDFLAGS_KERNEL_PPC = \
- -arch ppc \
- -segaddr __VECTORS 0x0 \
- -segaddr __HIB 0x7000 \
- -segaddr __TEXT 0xe000
-
-export LDFLAGS_KERNEL_I386 = \
- -arch i386 \
- -segaddr __HIB 0xC0100000 \
- -segaddr __TEXT 0xC0111000
-
-export LDFLAGS_KERNEL = $(LDFLAGS_KERNEL_GEN) \
- $($(addsuffix $(ARCH_CONFIG),LDFLAGS_KERNEL_)) \
- $($(addsuffix $(KERNEL_CONFIG),LDFLAGS_KERNEL_))
-
+# Availability of DWARF allows DTrace CTF (compressed type format) to be constructed.
+# ctf_insert creates the CTF section. It needs reserved padding in the
+# headers for the load command segment and the CTF section structures.
+#
+LDFLAGS_KERNEL_GEN = \
+ -nostdlib \
+ -fapple-kext \
+ -Wl,-e,__start \
+ -Wl,-sectalign,__TEXT,__text,0x1000 \
+ -Wl,-sectalign,__DATA,__common,0x1000 \
+ -Wl,-sectalign,__DATA,__bss,0x1000 \
+ -Wl,-sectcreate,__PRELINK_TEXT,__text,/dev/null \
+ -Wl,-sectcreate,__PRELINK_STATE,__kernel,/dev/null \
+ -Wl,-sectcreate,__PRELINK_STATE,__kexts,/dev/null \
+ -Wl,-sectcreate,__PRELINK_INFO,__info,/dev/null \
+ -Wl,-new_linker \
+ -Wl,-pagezero_size,0x0 \
+ -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)