https://sourceware.org/bugzilla/show_bug.cgi?id=26551
--- Comment #7 from Fangrui Song <i at maskray dot me> ---
(In reply to H.J. Lu from comment #6)
> (In reply to Fangrui Song from comment #5)
> > ld.bfd a.o --as-needed b.so
> >
> > Let a.o define a function which will be called by b.so via dlopen. In this
> > case, ld should export the function. This justification may look weak but I
> > think it is moving toward the right direction if we consider that GNU ld
> > from binutils 2.22 defaulted to --no-copy-dt-needed-entries (doing less
> > shared object traversal for more proper dependency tracking and avoiding
> > unneeded work).
>
> LD creates dynamic section only if dynamic relocation is needed.
> For this test, since no dynamic relocation is needed, there is no
> dynamic section. Since there is no dynamic section, there is no
> dynamic symbol table.
>a.c <<e cat
#include <dlfcn.h>
int foo() { return 42; }
int main() {
void *h = dlopen("./b.so", RTLD_LAZY);
int (*bar)(void) = dlsym(h, "bar");
return bar();
}
e
>b.c <<e cat
int foo();
int bar() { return foo(); }
e
cc -fuse-ld=bfd -shared -fPIC b.c -ldl -o b.so
cc -fuse-ld=bfd -pie -fPIE a.c -Wl,--push-state -Wl,--as-needed ./b.so
-Wl,--pop-state -ldl
./a.out => symbol lookup error: ./b.so: undefined symbol: foo
-fuse-ld=gold or -fuse-ld=lld is good.
--
You are receiving this mail because:
You are on the CC list for the bug.