Linking FreeBSD with lld: -dc option missing

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 16 09:05:30 PST 2016


On 16 November 2016 at 11:57, Ed Maste via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> I'm now looking in more detail at the final two issues preventing us
> from fully using lld for building FreeBSD userland and kernel. The
> issues have been discussed in sub-threads in the past, but as we're
> very close to building FreeBSD with lld "out of the box" I'm focusing
> on final resolutions for them. I need to either have lld gain the last
> pieces of missing functionality, or commit to a permanent change in
> FreeBSD.

Thanks!

>  * crunchide.c - tiptoes through a symbol table, hiding all defined
>  *      global symbols.  Allows the user to supply a "keep list" of symbols
>  *      that are not to be hidden.  This program relies on the use of the
>  *      linker's -dc flag to actually put global bss data into the file's
>  *      bss segment (rather than leaving it as undefined "common" data).
>  *
>  *      The point of all this is to allow multiple programs to be linked
>  *      together without getting multiple-defined errors.
>  *
>  *      For example, consider a program "foo.c".  It can be linked with a
>  *      small stub routine, called "foostub.c", eg:
>  *          int foo_main(int argc, char **argv){ return main(argc, argv); }
>  *      like so:
>  *          cc -c foo.c foostub.c
>  *          ld -dc -r foo.o foostub.o -o foo.combined.o
>  *          crunchide -k _foo_main foo.combined.o
>  *      at this point, foo.combined.o can be linked with another program
>  *      and invoked with "foo_main(argc, argv)".  foo's main() and any
>  *      other globals are hidden and will not conflict with other symbols.

And it doesn't know how to hide common symbols, so it depends on they
being pre allocated to .bss.

> In order to make this work with lld I need to do one of three things:
>
> 1) compile the object files with -fno-common
> 2) give crunchide some simple linking ability, so that it can convert
> common symbols into allocated .bss symbols
> 3) add -dc support to lld
>
> Rafael previously suggested #1. It's feasible, but makes the crunch
> build system slightly less portable (in that it couldn't be used with
> other software that relies on common symbol behaviour). It also
> requires that we build a second set of objects for the rescue build,
> if -fno-common isn't applied to the "normal" build of the tools.

So, right now if a foo.o is in both /bin/sh and the rescue system you
only compile it once? I would assume that the one in the rescue system
was a special minimal version. If the size is not an issue, why do you
"concatenate" multiple program into one? Why not just have static
versions of sh, ls, etc?

> Rafael/Rui, do you think it's reasonable to add -dc to lld?

Now that we use synthetic input sections it should not be too
horrible. I would just like to understand what is the need a bit
better.

Cheers,
Rafael


More information about the llvm-commits mailing list