kern build: Tweak ldscripts for gold linker
authorJohn Marino <draco@marino.st>
Thu, 23 Feb 2012 18:03:04 +0000 (19:03 +0100)
committerJohn Marino <draco@marino.st>
Fri, 24 Feb 2012 06:51:44 +0000 (07:51 +0100)
commite19c755caea4d4761617e54c6d5ae1919cbf2765
treecd54f4156af3437585d5f14d83eb9aeb07da4cb9
parent8a3051132d4376f6801cad8897fe5897be53f459
kern build: Tweak ldscripts for gold linker

The gold linker v2.21 was able to link a working kernel although its
modules were unloadable.  The gold linker v2.22 could build loadable
modules, but the kernel wouldn't boot!  It's not clear why the modules
started to work -- my guess is that the ancient ldscripts used during
the 2.21 trial were the culprit.

The gold linker changed its ELF program header handling defaults for
version 2.22, and this resulted in an extra LOAD segment reserved only
for the program headers.  The DragonFly loader wasn't expecting that
and instantly rebooted when trying to load a gold kernel.

The solution was to add a PHDRS section to the ldscripts to specify
exactly the section to segment mapping, and prevent gold from putting
the elf headers in their own load segment.  Now gold matches gnu ld
linker in having only two LOAD segments, text and data.

As a curiousity, gold sets the LOAD segment alignment value at 0x1000
for both i386 and x86_64, where gnu ld sets the segment alignment at
0x1000 for i386 and 0x200000 for x86_64.  This seems to have no impact
on the loading of the kernel.
sys/platform/pc32/conf/ldscript.i386
sys/platform/pc64/conf/ldscript.x86_64
sys/platform/vkernel/conf/ldscript.i386
sys/platform/vkernel64/conf/ldscript.x86_64