mold
mold copied to clipboard
Hidden weak undefined symbol generates dynamic relocation in shared library
Here is a simple reproducer:
// foo.cpp
[[gnu::weak]] [[gnu::visibility("hidden")]] void foo();
int bar() {
if (foo) {
foo();
return 0;
} else {
return 1;
}
}
Then compile with
$ clang++ foo.cpp -mno-relax --target=riscv64-unknown-linux-none -Wall -c -o foo.o
and link with
$ mold foo.o -shared -o foo.so
Then we have:
$ llvm-readelf -r foo.so
Relocation section '.rela.dyn' at offset 0x290 contains 1 entries:
Offset Info Type Symbol's Value Symbol's Name + Addend
0000000000003000 0000000100000002 R_RISCV_64 0000000000000000 _Z3foov + 0
This behaviour differs to lld
and GNU ld
, e.g:
$ ld.lld foo.o -shared -o foo.so
$ llvm-readelf -r foo.so
There are no relocations in this file.
Mold version used:
$ ./mold -v
mold 1.2.1 (826bb56d59312bd8a4ad3fc1d60aa7b430cee94b; compatible with GNU ld)
Thank you for your report! It looks like this is a bug in mold. We want to fix this before the next release.
Hi, @rui314! I am trying to tackle this atm. It looks like this might be fixed if we can correctly convert hidden globals to local symbols. It might take me some time to figure this one out since I am trying to understand all implications of this change.
This one has fallen off my radar for some reason, though I wanted to get this fixed.
@rbartlensky I'll assign it to you to avoid duplicated work. Please reassign to me if you don't want to take this one.
Fixed in https://github.com/rui314/mold/commit/adde0130f5e24b6bc6551270395c79d679d80c06