Skip to content
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

Assertion failure with link-time optimization and link command that duplicates static library #104243

Open
davidstone opened this issue Aug 14, 2024 · 3 comments
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] LTO Link time optimization (regular/full LTO or ThinLTO)

Comments

@davidstone
Copy link
Contributor

Given the following two translation units:

a.c:

b.c:

int main() {}

And compiling with

clang -flto=thin -c a.c
clang -flto=thin -c b.c
llvm-ar qc c.a a.o
clang -fuse-ld=mold -flto=thin b.o -o /dev/null c.a c.a

Causes a crash with

ld.mold: /home/david/llvm/llvm/tools/gold/gold-plugin.cpp:1069: std::vector<std::pair<SmallString<128>, bool>> runLTO(): Assertion `ObjFilename.second' failed.
clang: error: unable to execute command: Aborted (core dumped)
clang: error: linker command failed due to signal (use -v to see invocation)

I'm not sure if the bug is in llvm's gold-plugin code or mold calls that plugin incorrectly or if clang's compiler driver calls mold incorrectly.

@davidstone
Copy link
Contributor Author

As a note, the same crash occurs if b.c is empty, but I added the int main() {} to make this a crash on valid instead of crash on invalid.

@benjamasu
Copy link

The corresponding issue in the mold repository: rui314/mold#1356.
The problem occurs not only with static libraries, but also with object files.

@rui314
Copy link
Member

rui314 commented Oct 10, 2024

I think this is LLVMgold's bug. It is easy to deduplicate given filenames, but doing it is a bit odd from the linker's perspective, as a user explicitly pass the same file twice to the linker, and the most straightforward for the linker to do in that situation is just process them normally. In other words, the plugin should be prepared for the situation in which the same file is given more than once.

@EugeneZelenko EugeneZelenko added crash Prefer [crash-on-valid] or [crash-on-invalid] LTO Link time optimization (regular/full LTO or ThinLTO) and removed new issue labels Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] LTO Link time optimization (regular/full LTO or ThinLTO)
Projects
None yet
Development

No branches or pull requests

4 participants