[RFC PATCH] powerpc/Makefile: Add option to build with gold

Subsystems: linux for powerpc (32-bit and 64-bit), the rest

STALE3653d

2 messages, 2 authors, 2016-08-12 · open the first message on its own page

[RFC PATCH] powerpc/Makefile: Add option to build with gold

From: Michael Ellerman <mpe@ellerman.id.au>
Date: 2016-08-12 11:30:24

This adds a Kconfig option which can be turned on to enable use of the
gold linker. It depends on DEBUG_KERNEL to hopefully hide it from users
who don't really care about it, and also !COMPILE_TEST so that it will
be turned off for allyes/modconfig builds.

In the wrapper script we currently always use ${CROSS}ld, so instead
make that the default if ${LD} isn't already set. When we're called as
part of a normal build ${LD} will be set, but if the wrapper is called
separately we will fall back to ${CROSS}ld as before.

With this enabled I have successfully built a ppc64[le]_defconfig using
a toolchain which only has ld.gold.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 arch/powerpc/Kconfig.debug | 7 +++++++
 arch/powerpc/Makefile      | 4 ++++
 arch/powerpc/boot/wrapper  | 4 +++-
 3 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug
index 63292f64b25a..c63ec2bb08ae 100644
--- a/arch/powerpc/Kconfig.debug
+++ b/arch/powerpc/Kconfig.debug
@@ -19,6 +19,13 @@ config PPC_WERROR
 	depends on !PPC_DISABLE_WERROR
 	default y
 
+config PPC_USE_GOLD
+	bool "Build with the gold linker"
+	depends on DEBUG_KERNEL && !COMPILE_TEST
+	default n
+	  Build the kernel with the ld.gold linker, rather than ld.bfd.
+	  If you don't know what this means say N.
+
 config PRINT_STACK_DEPTH
 	int "Stack depth to print" if DEBUG_KERNEL
 	default 64
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 1934707bf321..005c63fd8be1 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -65,6 +65,10 @@ endif
 
 UTS_MACHINE := $(OLDARCH)
 
+ifdef CONFIG_PPC_USE_GOLD
+LD := $(LD).gold
+endif
+
 ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y)
 override LD	+= -EL
 override CROSS32AS += -mlittle-endian
diff --git a/arch/powerpc/boot/wrapper b/arch/powerpc/boot/wrapper
index 6681ec3625c9..00f13d18fd6f 100755
--- a/arch/powerpc/boot/wrapper
+++ b/arch/powerpc/boot/wrapper
@@ -140,6 +140,8 @@ while [ "$#" -gt 0 ]; do
     shift
 done
 
+LD=${LD:-${CROSS}ld}
+
 if [ -n "$dts" ]; then
     if [ ! -r "$dts" -a -r "$object/dts/$dts" ]; then
 	dts="$object/dts/$dts"
@@ -417,7 +419,7 @@ if [ "$platform" != "miboot" ]; then
     if [ -n "$link_address" ] ; then
         text_start="-Ttext $link_address"
     fi
-    ${CROSS}ld -m $format -T $lds $text_start $pie -o "$ofile" \
+    ${LD} -m $format -T $lds $text_start $pie -o "$ofile" \
 	$platformo $tmp $object/wrapper.a
     rm $tmp
 fi
-- 
2.7.4

Re: [RFC PATCH] powerpc/Makefile: Add option to build with gold

From: Nicholas Piggin <npiggin@gmail.com>
Date: 2016-08-12 14:30:22

On Fri, 12 Aug 2016 21:30:21 +1000
Michael Ellerman [off-list ref] wrote:
This adds a Kconfig option which can be turned on to enable use of the
gold linker. It depends on DEBUG_KERNEL to hopefully hide it from users
who don't really care about it, and also !COMPILE_TEST so that it will
be turned off for allyes/modconfig builds.

In the wrapper script we currently always use ${CROSS}ld, so instead
make that the default if ${LD} isn't already set. When we're called as
part of a normal build ${LD} will be set, but if the wrapper is called
separately we will fall back to ${CROSS}ld as before.

With this enabled I have successfully built a ppc64[le]_defconfig using
a toolchain which only has ld.gold.
Nice. Out of curiosity, I ran some testing.

On allyesconfig with sfr's thin archives patch and --gc-sections,
ld.gold is about 10% faster than ld.bfd. About 11 seconds vs 12. A lot
of that is in utf8 conversions from "fnmatch" it's using to match
section names though. Setting LANG=C brings it down to 8 seconds and
helps ld.bfd a tiny bit but not much. So that's a pretty good win.
Threading still has some crashes.

ld.gold creates a larger executable though. It seems to be creating a
lot more branch stubs (19000 vs 6500 for ld.bfd). 

I should keep in mind we link the kernel about 4 times every build
before complain too much about linker performance to the binutils guys.
I wonder if we couldn't objcopy the kallsyms onto the end of the image
to avoid that relinking.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help