Skip to contentSkip to conversation

binutils: allow distro to select gold as default cross-linker

RFC PATCH In review Phil Blundell 3 participants 13 messages Jun 14, 2011 – Jun 15, 2011

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 binutils: allow distro to select gold as default cross-linker

This is not particularly pretty but I couldn't think of any obviously better way of doing it. Any suggestions?

---
 meta/recipes-devtools/binutils/binutils-cross.inc |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
meta/recipes-devtools/binutils/binutils-cross.inc +2 -1
index 4b90972..5a41970 100644
@@ -5,7 +5,8 @@ EXTRA_OECONF = "--with-sysroot=${STAGING_DIR_TARGET} \
                 --program-prefix=${TARGET_PREFIX} \
                 --disable-install-libbfd \
                 --disable-werror \
-                --enable-poison-system-directories"
+                --enable-poison-system-directories \
+		${@base_contains('DISTRO_FEATURES', 'ld-is-gold', '--enable-gold=default', '', d)}"
 
 do_install () {
 	oe_runmake 'DESTDIR=${D}' install
Signature · 1 line
1.7.2.5
#1 lore raw

Op 14 jun 2011, om 17:30 heeft Phil Blundell het volgende geschreven:

Quoted 13 lines

This is not particularly pretty but I couldn't think of any obviously better way of doing it. Any suggestions?

---
meta/recipes-devtools/binutils/binutils-cross.inc | 3 ++-

1 files changed, 2 insertions(+), 1 deletions(-)
meta/recipes-devtools/binutils/binutils-cross.inc +0 -0
index 4b90972..5a41970 100644

meta/recipes-devtools/binutils/binutils-cross.inc EXTRA_OECONF = "--with-sysroot=${STAGING_DIR_TARGET} \ · line 9

Quoted 6 lines
meta/recipes-devtools/binutils/binutils-cross.inc +2 -1
@@ -5,7 +5,8 @@ EXTRA_OECONF = "--with-sysroot=${STAGING_DIR_TARGET} \
                --program-prefix=${TARGET_PREFIX} \
                --disable-install-libbfd \
                --disable-werror \
-                --enable-poison-system-directories"
+                --enable-poison-system-directories \
+		${@base_contains('DISTRO_FEATURES', 'ld-is-gold', '--enable-gold=default', '', d)}"

Out of curiousity, how well does gold work nowadays? Last I remember hearing of it was in its x86-only days.

regards,

Koen

#11 lore raw
In reply to Phil Blundell
Quoted 13 lines · Phil Blundell

This is not particularly pretty but I couldn't think of any obviously better way of doing it. Any suggestions?

---
  meta/recipes-devtools/binutils/binutils-cross.inc |    3 ++-
  1 files changed, 2 insertions(+), 1 deletions(-)
meta/recipes-devtools/binutils/binutils-cross.inc +0 -0
index 4b90972..5a41970 100644

meta/recipes-devtools/binutils/binutils-cross.inc EXTRA_OECONF = "--with-sysroot=${STAGING_DIR_TARGET} \ · line 12

Quoted 9 lines
meta/recipes-devtools/binutils/binutils-cross.inc +2 -1
@@ -5,7 +5,8 @@ EXTRA_OECONF = "--with-sysroot=${STAGING_DIR_TARGET} \
                  --program-prefix=${TARGET_PREFIX} \
                  --disable-install-libbfd \
                  --disable-werror \
-                --enable-poison-system-directories"
+                --enable-poison-system-directories \
+		${@base_contains('DISTRO_FEATURES', 'ld-is-gold', '--enable-gold=default', '', d)}"
 
  do_install () {
  	oe_runmake 'DESTDIR=${D}' install

I think we need to document this distro feature somewhere as well. We need the same for target binutils too.

#2 lore raw
In reply to Koen Kooi
Quoted 11 lines · Koen Kooi

Op 14 jun 2011, om 17:30 heeft Phil Blundell het volgende geschreven:

Quoted 8 lines

This is not particularly pretty but I couldn't think of any obviously better way of doing it. Any suggestions?

---
meta/recipes-devtools/binutils/binutils-cross.inc | 3 ++-

1 files changed, 2 insertions(+), 1 deletions(-)
Quoted 14 lines

meta/recipes-devtools/binutils/binutils-cross.inc EXTRA_OECONF = "--with-sysroot=${STAGING_DIR_TARGET} \ · line 9

Quoted 11 lines
meta/recipes-devtools/binutils/binutils-cross.inc +2 -1
index 4b90972..5a41970 100644
@@ -5,7 +5,8 @@ EXTRA_OECONF = "--with-sysroot=${STAGING_DIR_TARGET} \
                 --program-prefix=${TARGET_PREFIX} \
                 --disable-install-libbfd \
                 --disable-werror \
-                --enable-poison-system-directories"
+                --enable-poison-system-directories \
+		${@base_contains('DISTRO_FEATURES', 'ld-is-gold', '--enable-gold=default', '', d)}"

Out of curiousity, how well does gold work nowadays? Last I remember hearing of it was in its x86-only days.

it works well on arm in fact link times are way better on some (especially C++) applications using gold. We can try to use gold for x86, x86_64 and arm to start with.

Quoted 7 lines

regards,

Koen
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-core

#3 lore raw
In reply to Koen Kooi
Quoted 1 line · Koen Kooi

Out of curiousity, how well does gold work nowadays? Last I remember hearing of it was in its x86-only days.

It works for arm, x86 and amd64 which are the only targets that I've tried for myself. I suspect it doesn't support some of the more obscure architectures. Obviously it doesn't (and isn't intended to) support non ELF targets, though I can't think of any such in OE.

One slightly annoying thing is that (e)glibc isn't buildable with gold because the linker scripts don't work. So a little bit of patching is going to be needed to have it use ld.bfd there. There might be some other packages with similar issues but I haven't come across any yet.

p.

#12 lore raw
In reply to Khem Raj
Quoted 1 line · Khem Raj

I think we need to document this distro feature somewhere as well.

Yeah, agreed. Any suggestions for "somewhere"? Traditionally this kind of thing has been sort-of-documented in local.conf.sample{.extended} but that doesn't seem like a terribly good model for the future.

If the wiki were ever to become editable then I guess a page there might be a good place, perhaps.

Quoted 1 line

We need the same for target binutils too.

Yeah, though it wants slightly different handling in the target case. I was planning to leave that for someone who actually uses on-target binutils to sort out :-)

There's also the sdk case which I haven't looked at either. I'm not sure to what extent that needs special handling.

p.

#4 lore raw
In reply to Phil Blundell
Quoted 4 lines · Phil Blundell

One slightly annoying thing is that (e)glibc isn't buildable with gold because the linker scripts don't work. So a little bit of patching is going to be needed to have it use ld.bfd there. There might be some other packages with similar issues but I haven't come across any yet.

I think something like this is probably what's required for that.

From 48eaba1da89086b8edccaa03c27075d78635ab01 Mon Sep 17 00:00:00 2001
From: Phil Blundell <[email protected]>
Date: Wed, 15 Jun 2011 15:22:47 +0100
Subject: [PATCH] gcc-cross-intermediate: use ld.bfd if distro prefers gold

---
 .../gcc/gcc-cross-intermediate.inc                 |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
meta/recipes-devtools/gcc/gcc-cross-intermediate.inc +6 -1
index 92c3ce2..05b5dbc 100644
@@ -7,6 +7,10 @@ CROSS_TARGET_SYS_DIR_append = ".${PN}"
 
 # This is intended to be a -very- basic config
 # sysroot is needed in case we use libc-initial
+#
+# Glibc won't compile with gold, and building glibc is the whole point of
+# this recipe.   So we select ld.bfd explicitly here if gold is the distro's 
+# preferred linker.
 EXTRA_OECONF = "--with-local-prefix=${STAGING_DIR_TARGET}${target_prefix} \
 		--enable-shared \
 		--disable-multilib \
@@ -17,7 +21,8 @@ EXTRA_OECONF = "--with-local-prefix=${STAGING_DIR_TARGET}${target_prefix} \
 		--with-sysroot=${STAGING_DIR_TCBOOTSTRAP} \
 		--with-build-sysroot=${STAGING_DIR_TCBOOTSTRAP} \
 		${EXTRA_OECONF_INTERMEDIATE} \
-		${@get_gcc_fpu_setting(bb, d)}"
+		${@get_gcc_fpu_setting(bb, d)} \
+		${@base_contains('DISTRO_FEATURES', 'ld-is-gold', '--with-ld=${STAGING_BINDIR_TOOLCHAIN}/${TARGET_PREFIX}ld.bfd', '', d)}"
 
 do_populate_sysroot[sstate-inputdirs] = "${SYSROOT_DESTDIR}/${STAGING_DIR_HOST} ${SYSROOT_DESTDIR}/${STAGING_DIR_TARGET}/${target_base_libdir}"
 do_populate_sysroot[sstate-outputdirs] = "${STAGING_DIR_HOST} ${STAGING_DIR_TCBOOTSTRAP}/${target_base_libdir}"
Signature · 1 line
1.7.2.5
#5 lore raw
Quoted 35 lines · Phil Blundell
Quoted 4 lines · Phil Blundell

One slightly annoying thing is that (e)glibc isn't buildable with gold because the linker scripts don't work. So a little bit of patching is going to be needed to have it use ld.bfd there. There might be some other packages with similar issues but I haven't come across any yet.

I think something like this is probably what's required for that.

From 48eaba1da89086b8edccaa03c27075d78635ab01 Mon Sep 17 00:00:00 2001
From: Phil Blundell<[email protected]>
Date: Wed, 15 Jun 2011 15:22:47 +0100
Subject: [PATCH] gcc-cross-intermediate: use ld.bfd if distro prefers gold

---
  .../gcc/gcc-cross-intermediate.inc                 |    7 ++++++-
  1 files changed, 6 insertions(+), 1 deletions(-)
meta/recipes-devtools/gcc/gcc-cross-intermediate.inc +4 -0
index 92c3ce2..05b5dbc 100644
@@ -7,6 +7,10 @@ CROSS_TARGET_SYS_DIR_append = ".${PN}"
 
  # This is intended to be a -very- basic config
  # sysroot is needed in case we use libc-initial
+#
+# Glibc won't compile with gold, and building glibc is the whole point of
+# this recipe.   So we select ld.bfd explicitly here if gold is the distro's
+# preferred linker.
  EXTRA_OECONF = "--with-local-prefix=${STAGING_DIR_TARGET}${target_prefix} \
  		--enable-shared \
  		--disable-multilib \

meta/recipes-devtools/gcc/gcc-cross-intermediate.inc EXTRA_OECONF = "--with-local-prefix=${STAGING_DIR_TARGET}${target_prefix} \ · line 28

Quoted 9 lines
meta/recipes-devtools/gcc/gcc-cross-intermediate.inc +2 -1
@@ -17,7 +21,8 @@ EXTRA_OECONF = "--with-local-prefix=${STAGING_DIR_TARGET}${target_prefix} \
  		--with-sysroot=${STAGING_DIR_TCBOOTSTRAP} \
  		--with-build-sysroot=${STAGING_DIR_TCBOOTSTRAP} \
  		${EXTRA_OECONF_INTERMEDIATE} \
-		${@get_gcc_fpu_setting(bb, d)}"
+		${@get_gcc_fpu_setting(bb, d)} \
+		${@base_contains('DISTRO_FEATURES', 'ld-is-gold', '--with-ld=${STAGING_BINDIR_TOOLCHAIN}/${TARGET_PREFIX}ld.bfd', '', d)}"
 
  do_populate_sysroot[sstate-inputdirs] = "${SYSROOT_DESTDIR}/${STAGING_DIR_HOST} ${SYSROOT_DESTDIR}/${STAGING_DIR_TARGET}/${target_base_libdir}"
  do_populate_sysroot[sstate-outputdirs] = "${STAGING_DIR_HOST} ${STAGING_DIR_TCBOOTSTRAP}/${target_base_libdir}"

this might not work second time around when gcc-cross has been staged.

#6 lore raw
Quoted 1 line · Khem Raj

this might not work second time around when gcc-cross has been staged.

Oh, I thought that mess was fixed nowadays. Doesn't eglibc always use the -intermediate compiler from the special tcbootstrap place?

If it's just picking whatever was staged most recently then yeah, this will lose.

p.

#7 lore raw
Quoted 9 lines · Phil Blundell
Quoted 1 line · Khem Raj

this might not work second time around when gcc-cross has been staged.

Oh, I thought that mess was fixed nowadays. Doesn't eglibc always use the -intermediate compiler from the special tcbootstrap place?

If it's just picking whatever was staged most recently then yeah, this will lose.

ah I stand corrected.

STAGINGCC = "gcc-cross-intermediate"
PATH_prepend = "${STAGING_BINDIR_TOOLCHAIN}.${STAGINGCC}:"

so yes it uses gcc-cross-intermediate all the time.

This will work. Do you know what problems eglibc has linking with gold ? may be we can fix it

Quoted 8 lines

p.

_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-core

#8 lore raw
Quoted 2 lines · Khem Raj

This will work. Do you know what problems eglibc has linking with gold ? may be we can fix it

If I remember right, it relies on linker script functionality which gold just doesn't have. I suspect this would be hard to fix and, unless there is a pressing need to fight that particular battle, I would be inclined not to bother.

That said, though, I haven't checked recently and it's possible that recent versions of gold will "just work". If you wanted to give it a try then I think it'd just be a question of h4x0ring eglibc's configure script slightly to get it to accept gold as a valid linker version.

p.

#9 lore raw
Quoted 9 lines · Phil Blundell
Quoted 2 lines · Khem Raj

This will work. Do you know what problems eglibc has linking with gold ? may be we can fix it

If I remember right, it relies on linker script functionality which gold just doesn't have. I suspect this would be hard to fix and, unless there is a pressing need to fight that particular battle, I would be inclined not to bother.

Quoted 5 lines

That said, though, I haven't checked recently and it's possible that recent versions of gold will "just work". If you wanted to give it a try then I think it'd just be a question of h4x0ring eglibc's configure script slightly to get it to accept gold as a valid linker version.

I remember now. Accepting gold would be easier but changing how ld.so is built where it asks ld to spit out default linker script and then munge it before reusing it is harder part. I think status is still same. It reminds me that we probably need ld.bfd for kernel too.

Quoted 8 lines

p.

_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-core

#10 lore raw
Quoted 1 line · Khem Raj

we probably need ld.bfd for kernel too.

Yeah. That's easy though, because the kernel invokes ld directly rather than going through the compiler driver. Just need to set ${KERNEL_LD} appropriately and it should all be fine.

p.