Bug#998687: Acknowledgement (lld: --no-allow-shlib-undefined: Doesn't check recursively)
Alejandro Colomar (man-pages)
alx.manpages at gmail.com
Sat Nov 6 13:09:47 GMT 2021
Sorry, I copied the wrong log (the one for ld.gold).
Here goes the one for ld.lld (which is almost identical (basically
s/gold/lld/, and also the different error message format from lld than
gold):
$ ll
total 20
-rw-r--r-- 1 user user 29 Oct 28 11:47 bar.c
-rw-r--r-- 1 user user 60 Oct 28 13:47 foobar.c
-rw-r--r-- 1 user user 83 Oct 28 11:46 foo.c
-rw-r--r-- 1 user user 52 Oct 28 13:47 foovar.c
-rw-r--r-- 1 user user 56 Oct 28 13:31 main.c
$
$ cat bar.c
int bar(void)
{
return 1;
}
$ cat foo.c
int bar(void);
int foo(void)
{
return 1;
}
int foo_bar(void)
{
return bar();
}
$ cat foobar.c
int foo_bar(void);
int foobar(void)
{
return foo_bar();
}
$ cat foovar.c
int foo(void);
int foobar(void)
{
return foo();
}
$ cat main.c
int foobar(void);
int main(void)
{
return foobar();
}
$
$ cc -c -fpic -Wall -Wextra -Werror main.c foo.c bar.c foobar.c foovar.c
$
$ cc -shared -Wl,--no-undefined -Wl,--no-allow-shlib-undefined
-Wl,--as-needed -Wl,--no-copy-dt-needed-entries -o libbar.so bar.o
-fuse-ld=bfd
$ cc -shared -Wl,--no-undefined -Wl,--no-allow-shlib-undefined
-Wl,--as-needed -Wl,--no-copy-dt-needed-entries -o libbar.so bar.o
-fuse-ld=lld
$
$ cc -shared -Wl,--no-undefined -Wl,--no-allow-shlib-undefined
-Wl,--as-needed -Wl,--no-copy-dt-needed-entries -o libfoo.so foo.o
-fuse-ld=bfd
/usr/bin/ld.bfd: foo.o: in function `foo_bar':
foo.c:(.text+0x10): undefined reference to `bar'
collect2: error: ld returned 1 exit status
$ cc -shared -Wl,--no-undefined -Wl,--no-allow-shlib-undefined
-Wl,--as-needed -Wl,--no-copy-dt-needed-entries -o libfoo.so foo.o
-fuse-ld=lld
ld.lld: error: undefined symbol: bar
>>> referenced by foo.c
>>> foo.o:(foo_bar)
collect2: error: ld returned 1 exit status
$
$ cc -shared -Wl,--no-allow-shlib-undefined -Wl,--as-needed
-Wl,--no-copy-dt-needed-entries -o libfoo.so foo.o -fuse-ld=bfd
$ cc -shared -Wl,--no-allow-shlib-undefined -Wl,--as-needed
-Wl,--no-copy-dt-needed-entries -o libfoo.so foo.o -fuse-ld=lld
$
$ cc -shared -Wl,--no-undefined -Wl,--no-allow-shlib-undefined
-Wl,--as-needed -Wl,--no-copy-dt-needed-entries -o libfoobar.so foobar.o
-L. -lfoo -fuse-ld=bfd
/usr/bin/ld.bfd: ./libfoo.so: undefined reference to `bar'
collect2: error: ld returned 1 exit status
$ cc -shared -Wl,--no-undefined -Wl,--no-allow-shlib-undefined
-Wl,--as-needed -Wl,--no-copy-dt-needed-entries -o libfoobar.so foobar.o
-L. -lfoo -fuse-ld=lld
ld.lld: error: ./libfoo.so: undefined reference to bar
[--no-allow-shlib-undefined]
collect2: error: ld returned 1 exit status
$
$ cc -shared -Wl,--no-undefined -Wl,--as-needed
-Wl,--no-copy-dt-needed-entries -o libfoobar.so foobar.o -L. -lfoo
-fuse-ld=bfd
$ cc -shared -Wl,--no-undefined -Wl,--as-needed
-Wl,--no-copy-dt-needed-entries -o libfoobar.so foobar.o -L. -lfoo
-fuse-ld=lld
$
$ cc -shared -Wl,--no-undefined -Wl,--no-allow-shlib-undefined
-Wl,--as-needed -Wl,--no-copy-dt-needed-entries -o libfoovar.so foovar.o
-L. -lfoo -fuse-ld=bfd
/usr/bin/ld.bfd: ./libfoo.so: undefined reference to `bar'
collect2: error: ld returned 1 exit status
$ cc -shared -Wl,--no-undefined -Wl,--no-allow-shlib-undefined
-Wl,--as-needed -Wl,--no-copy-dt-needed-entries -o libfoovar.so foovar.o
-L. -lfoo -fuse-ld=lld
ld.lld: error: ./libfoo.so: undefined reference to bar
[--no-allow-shlib-undefined]
collect2: error: ld returned 1 exit status
$
$ cc -shared -Wl,--no-undefined -Wl,--as-needed
-Wl,--no-copy-dt-needed-entries -o libfoovar.so foovar.o -L. -lfoo
-fuse-ld=bfd
$ cc -shared -Wl,--no-undefined -Wl,--as-needed
-Wl,--no-copy-dt-needed-entries -o libfoovar.so foovar.o -L. -lfoo
-fuse-ld=lld
$
$ # NOTE: bfd and lld behave differently here!
$ # lld will produce a buggy binary!!
$ cc -Wl,--no-undefined -Wl,--no-allow-shlib-undefined -Wl,--as-needed
-Wl,--no-copy-dt-needed-entries -o foobar -Wl,-rpath=. main.o -L.
-lfoobar -fuse-ld=bfd
/usr/bin/ld.bfd: ./libfoo.so: undefined reference to `bar'
collect2: error: ld returned 1 exit status
$ cc -Wl,--no-undefined -Wl,--no-allow-shlib-undefined -Wl,--as-needed
-Wl,--no-copy-dt-needed-entries -o foobar -Wl,-rpath=. main.o -L.
-lfoobar -fuse-ld=lld
$
$ LD_LIBRARY_PATH=. ./foobar
./foobar: symbol lookup error: ./libfoo.so: undefined symbol: bar
$
$ # NOTE: bfd and lld behave differently here!
$ # lld will produce a binary that luckily works here,
$ # but might break inadvertently if a future libfoovar starts using
foo_bar()!
$ cc -Wl,--no-undefined -Wl,--no-allow-shlib-undefined -Wl,--as-needed
-Wl,--no-copy-dt-needed-entries -o foovar -Wl,-rpath=. main.o -L.
-lfoovar -fuse-ld=bfd
/usr/bin/ld.bfd: ./libfoo.so: undefined reference to `bar'
collect2: error: ld returned 1 exit status
$ cc -Wl,--no-undefined -Wl,--no-allow-shlib-undefined -Wl,--as-needed
-Wl,--no-copy-dt-needed-entries -o foovar -Wl,-rpath=. main.o -L.
-lfoovar -fuse-ld=lld
$
$ LD_LIBRARY_PATH=. ./foovar
$
--
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/
More information about the Pkg-llvm-team
mailing list