[lld] r234378 - Allow undefined symbols in shared library by default.

Ed Maste emaste at freebsd.org
Wed Apr 8 06:10:46 PDT 2015


On 8 April 2015 at 05:58, Joerg Sonnenberger <joerg at britannica.bec.de> wrote:
> On Wed, Apr 08, 2015 at 01:00:19AM -0000, Davide Italiano wrote:
>> Author: davide
>> Date: Tue Apr  7 20:00:19 2015
>> New Revision: 234378
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=234378&view=rev
>> Log:
>> Allow undefined symbols in shared library by default.
>
> Are you sure this is correct? There are two different cases here:
> (1) The undefined symbol is in a dependency. While it is sometimes nice
> to see a warning, it should not be an error. GNU ld gets this wrong.

This case was an error prior to r234378, and after is silently
ignored. It's also ignored with GNU ld 2.17.50 in the FreeBSD default
toolchain.

There's a demo in PR23035. The link command line from that PR ends up as:

"/usr/bin/ld" --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1
--hash-style=both --enable-new-dtags -o main /usr/lib/crt1.o
/usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib -rpath . main.o lib1.so
-lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s
--no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o

> (2) The undefined symbol is defined in a dependency. I think we get this
> wrong right now for indirect dependencies, e.g. we link against libfoo,
> which links against libbar and the symbol is defined by libbar. We
> certainly *do* want to complain by default here.

Unless I'm misunderstanding the case you describe here, it still
works. If I use the demo from PR 23035 but try to use a symbol from
the indirect dependency lib2.so from main.c I get:

GNU ld 2.17.50:

% clang -Wall -g -rpath . -o main main.o lib1.so
/usr/bin/ld: undefined reference to symbol `fn2' (try adding -l2)
././lib2.so: could not read symbols: Bad value
clang: error: linker command failed with exit code 1 (use -v to see invocation)

lld:

% clang -B. -Wall -g -rpath . -o main main.o lib1.so
Undefined symbol: main.o: fn2
symbol(s) not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)



More information about the llvm-commits mailing list