Skip to content

[LLD] Undefined symbol __gxx_personality_v0 when linking with lld #54701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Kmeakin opened this issue Apr 1, 2022 · 5 comments
Closed

[LLD] Undefined symbol __gxx_personality_v0 when linking with lld #54701

Kmeakin opened this issue Apr 1, 2022 · 5 comments
Labels
invalid Resolved as invalid, i.e. not a bug lld:ELF

Comments

@Kmeakin
Copy link
Contributor

Kmeakin commented Apr 1, 2022

lld reports an undefined symbol, while ld is able to link this without issue:

main.c:

int main() {}

foo.cpp:

inline void f() {}

class Class1 {
public:
  virtual ~Class1() {}
};

class Class2 : Class1 {
public:
  Class2();
};

Class2::Class2() { f(); }
clang++ -O0 -c foo.cpp -o foo.o
clang -O0 -c main.c -o main.o
clang main.o foo.o -Wl,--gc-sections -fuse-ld=lld

produces

ld.lld: error: undefined symbol: __gxx_personality_v0
>>> referenced by foo.cpp
>>>               foo.o:(DW.ref.__gxx_personality_v0)
clang: error: linker command failed with exit code 1 (use -v to see invocation)

but removing -fuse-ld=lld produces no issues.

clang --version:

Ubuntu clang version 15.0.0-++20220321012320+9aa52ba574ad-1~exp1~20220321012418.363
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

ld.lld --version:

Ubuntu LLD 15.0.0 (compatible with GNU linkers)
@Kmeakin Kmeakin added the lld:ELF label Apr 1, 2022
@llvmbot
Copy link
Member

llvmbot commented Apr 1, 2022

@llvm/issue-subscribers-lld-elf

@MaskRay
Copy link
Member

MaskRay commented Apr 1, 2022

Usage error. You need to link with clang++ instead of clang. The only difference for the link action is whether the C++ standard library (libstdc++ or libc++/libc++abi) is linked. __gxx_personality_v0 is defined in libsupc++ in libstdc++, and libc++abi.

but removing -fuse-ld=lld produces no issues.

I cannot reproduce.

% clang main.o foo.o -Wl,--gc-sections -fuse-ld=bfd
/usr/bin/ld.bfd: foo.o:(.eh_frame+0xeb): undefined reference to `__gxx_personality_v0'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
% clang++ main.o foo.o -Wl,--gc-sections -fuse-ld=bfd

If that happens, it may be a bug in GNU ld.

@MaskRay MaskRay closed this as completed Apr 1, 2022
@MaskRay MaskRay added the invalid Resolved as invalid, i.e. not a bug label Apr 1, 2022
@Kmeakin
Copy link
Contributor Author

Kmeakin commented Apr 1, 2022

I believe this should be considered a bug. lld is described as "a drop in replacement for bfd and gold". This implies that it should be possible to append -fuse-ld=lld to a compiler invocation and get the same behavior.

@MaskRay
Copy link
Member

MaskRay commented Apr 1, 2022

https://maskray.me/blog/2020-12-19-lld-and-gnu-linker-incompatibilities See the first few paragraphs around "Piotr Kubaj said that this is a probably more of a marketing term than a technical term, the term tries to lure existing users into thinking "it's the same you know, but better!". "

As I mentioned, clang -fuse-ld=bfd failed for me. The case that it does not fail for you may be a bug, or could be a Ubuntu specific bug. This is not such a widespread thing that we should seek for bug-for-bug compatibility.

@smithp35
Copy link
Collaborator

smithp35 commented Apr 1, 2022

FWIW I can't reproduce either on Ubuntu18.04 with a recent clang (rebuilt a few days ago), and GNU ld (GNU Binutils for Ubuntu) 2.30
foo.o:(.eh_frame+0x13): undefined reference to `__gxx_personality_v0'
Nor with an AArch64 GCC toolchain with GNU ld (fsf-10.39) 2.34.0.20200629

I agree with MaskRay that this is within the tolerances of incompatibilities between linkers, especially as linking with clang++ is the way to get the linker driver to put the right libraries on the command line directly. The only things that I can think of are:

  • In your ld.bfd the garbage collection is somehow removing the section that references the personality routine. It is questionable whether relying on garbage collection for correctness of output is fair game. For example gold seems to give undefined symbol errors for the parts not removed by gc-sections.
  • You may have a library selection difference based on LLD supporting back-references. For example in ld.bfd a later object in a library may be getting searched. The output of the linker option --verbose and --print-map could be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid Resolved as invalid, i.e. not a bug lld:ELF
Projects
None yet
Development

No branches or pull requests

4 participants