[OE-core] Changing between gold and bfd linker (was: [PATCH 1/4] kernel.bbclass, module-base.bbclass: Use CC to form KERNEL_CC)

Enrico Scholz enrico.scholz at sigma-chemnitz.de
Thu Jan 24 12:13:05 UTC 2013


Khem Raj <raj.khem-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> writes:

>>> +KERNEL_LD = "${LD} ${HOST_LD_KERNEL_ARCH}"
>>> ...
>>> -KERNEL_LD = "${HOST_PREFIX}ld${KERNEL_LDSUFFIX} ${HOST_LD_KERNEL_ARCH}${TOOLCHAIN_OPTIONS}"
>>
>> that's bad... gold linker has serious problems to compile stuff like
>> kernel or bootloaders and setting 'KERNEL_LDSUFFIX = .bfd' was a good
>> way to workaround these problems.
>>
>
> This was not the intended use of KERNEL_LD IMO.

ok; then I abused it for this purpose and stuff failed more or less
silently with recent oe ;)

Me wonders whether we should implement a more generic way to select
between .bfd and .gold linker.  Overriding LD works well when LD is used
by the build system, but when it is called through gcc -> collect there
is no way to select the linker.

For grub2 I use

------
PATH_prepend = "${S}/.bin:"
CC_prepend = "env COMPILER_PATH=${S}/.bin/gcc "

do_configure_prepend() {
    mkdir -p .bin/gcc
    { echo "#!/bin/sh"
      echo 'exec ${TARGET_PREFIX}ld.bfd "$@"'
    } > .bin/${TARGET_PREFIX}ld
    chmod +x .bin/${TARGET_PREFIX}ld
    ln -s ../${TARGET_PREFIX}ld .bin/gcc/ld
}
------

which might go into a more general .bbclass.

Modifying binutils or gcc to select the wanted linker is probably the
2nd best solution (after fixing gold linker). E.g. for binutils, the
'arm-linux-gnueabi-ld' binary (or however it is called) which is a copy
of .bfd or .gold atm can be replaced by a oe specific program which
calls the corresponding linker depending on an environment variable.

Changing gcc seems to be more difficultly because name of ld is determined
at multiple locations.

So we have to following options:

1. keep things as is; when problems with gold arise[1], people have to turn
   it of globally

2. create a 'custom-ld.bbclass' which is inherited on demand

3. create custom 'ld' program evaluating '${OE_LDSUFFIX}' which is set
   on demand

4. patch gcc/collect to call a linker specified by environment


I favor 3; what do you think?



Enrico

Footnotes: 
[1]  I am aware of
     * kernel (--> '--march=all' object file mismatch)
     * barebox (--> optimizing away constructors with '--gc-shared')
     * grub2 (--> disfunctional with gold; no further details)

-- 
SIGMA Chemnitz GmbH       Registergericht:   Amtsgericht Chemnitz HRB 1750
Am Erlenwald 13           Geschaeftsfuehrer: Grit Freitag, Frank Pyritz
09128 Chemnitz




More information about the Openembedded-core mailing list