Skip to content

LLD emits corrupt version for weak symbol when using version script #49259

@aaronpuchert

Description

@aaronpuchert
Bugzilla Link 49915
Resolution FIXED
Resolved on May 12, 2021 09:40
Version unspecified
OS Linux
Blocks #48661
CC @h0tc0d3,@MaskRay,@nikic,@smithp35,@tstellar
Fixed by commit(s) 1c00530 6912082

Extended Description

When linking against a lld-linked libLLVM.so with ld.bfd I got the following error:

/usr/bin/ld: /usr/lib64/libLLVM.so: __morestack: invalid needed version 2
/usr/bin/ld: /usr/lib64/libLLVM.so: error adding symbols: bad value
clang-12.0: error: linker command failed with exit code 1 (use -v to see invocation)

Indeed:

readelf --wide --dyn-syms /usr/lib64/libLLVM.so.12 | grep morestack
332: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __morestack@@

This is coming from llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp. I've managed to build a small reproducer that should work with 12.0.0rc5:

cat morestack.cpp
extern "C" attribute((weak)) void __morestack();

unsigned long f() {
return (unsigned long)&__morestack;
}

cat script.map
LLVM_13 { global: *; };
clang -c -fPIC -g morestack.cpp
clang -fuse-ld=lld -shared -o test.so -Wl,--version-script,script.map morestack.o
readelf --wide --dyn-syms test.so | grep __morestack
5: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __morestack@@

Without -fuse-ld=lld, i.e. with ld.bfd I get

 2: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __morestack

Now lld itself seems to fine with the corrupt version, so maybe binutils are just overly sensitive? I don't know.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions