Closed icculus closed 2 years ago
Looks like that commit has landed on LLVM months ago, so it should be in 2.0.8 definitely, unless LLVM backed it out.
Can you test to see if the error happens with plain clang as well? I'd expect it to since I think we just let LLVM do this linking stuff now. If so, it's an LLVM bug we should file there.
Does this only happen with -flto=thin
and not with -flto
?
Note that we do basically no testing with -flto=thin
either in emscripten or in upstream llvm. We should fix that.. but you might be first person to try to use in the real world, so expect issues.
Following up, this works with Clang 10.0.0 with -flto=thin ...
clang -c -flto=thin -o a.o a.c
clang -c -flto=thin -o subdir/a.o b.c
llvm-ar r a.ar a.o subdir/a.o
clang -c -flto=thin -o m.o m.c
clang -fuse-ld=lld -flto=thin -o a.out a.ar m.o
(I had to use -fuse-ld=lld because of the way this Clang was built, and it's worth noting that this could totally be what avoids this bug in the first place.)
I am absolutely unfamiliar with all these details, but the LLVM fix I linked to appears to be ELF-specific, so possibly it doesn't apply to Emscripten output?
As for -flto vs -flto=thin: using -flto works (at least, it links, I haven't tested the results further yet); this bug only reproduces with -flto=thin.
It's worth noting, however, that when you set CMAKE_INTERPROCEDURAL_OPTIMIZATION to True in a CMake project, it sets -flto=thin without any way to specify the specific option directly, which is how I came to stumble into this problem, so others will eventually hit this, too, I assume.
It's worth noting, however, that when you set CMAKE_INTERPROCEDURAL_OPTIMIZATION to True in a CMake project, it sets -flto=thin without any way to specify the specific option directly
Seems you can override it in CMake via:
set(CMAKE_CXX_COMPILE_OPTIONS_IPO "-flto")
@haraldF oh, nice, I'll try that, thanks!
Hi there, problem exists in emscripten 2.0.32 also.
This happens with -flto=thin
and not with -flto
.
LTO::addThinLTO if (!ThinLTO.ModuleMap.insert({BM.getModuleIdentifier(), BM}).second) return make_error
( "Expected at most one ThinLTO module per bitcode file", inconvertibleErrorCode());
ModuleIdentifier = "engine/libengine.aUtils.cpp.o" ModuleIdentifier = "engine/libengine.aPath.cpp.o"
It will take a few hours for this fix to show up in tot
version emsdk and then it will be in the next release (2.0.33).
Emscripten fails to link if using -flto=thin and one of the inputs is a static library (.a file) that contains two object files with the same name. This happens to me because I'm building mRuby into a library, which has two unrelated source files in different directories named "array.c" (and others, too).
This seems to be an error inherited from LLVM, based on limited results from Googling, but here's how to reproduce this (tested against 2.0.8) ...
On the last emcc command, it generates the error:
Changing one of the object names to something other than "a.o" works around this--as does linking against the .o files instead of the .a--but a proper fix would be appreciated, especially if it just needs something pulled in or adapted from LLVM: https://reviews.llvm.org/D79880