llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.96k stars 11.54k forks source link

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

Open davidstone opened 1 month ago

davidstone commented 1 month ago

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 commented 1 month ago

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.