-
Notifications
You must be signed in to change notification settings - Fork 12.1k
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
[llvm] spurious multiple definition errors when linking with gcc #62270
Comments
The commit explicitly makes the
I don’t quite understand how that happens, LLVM uses One interesting thing in the error message: Edit:
|
A simple workaround would be to make the templates non constant only for MSVC ? What about the other template:
Isn't it highly dangerous that the static char is not const anymore ? PS: I haven't used C++ in years. |
The value of
I would prefer something that can be the same code for all compilers. Can you try if initializing the template <typename T> char Any::TypeId<T>::Id = 1; This should force the value to always land in the I don’t understand how they end up in different sections, the flag |
Will try that.
llvm and rust are both compiled with gcc in our case. |
Actually LLVM is built with Clang (and linked with ld.bfd) since msys2/MINGW-packages#12866 because GCC cannot build LLVM library with all targets because of the symbols limit. |
Changing to |
Thank you for testing it! I put a patch with this change into https://reviews.llvm.org/D148953. |
Thanks for the fix! |
Citing the comment in the source: Define the type id and initialize with a non-zero value. Initializing with a zero value means the variab can end up in either the .data or the .bss section. This can lead to multiple definition linker errors when some object files are compiled with a compiler that puts the variable into .data but they are linked to object files from a different compiler that put the variable into .bss. To prevent this issue from happening, initialize the variable with a non-zero value, which forces it to land in .data (because .bss is zero-initialized). Fixes llvm/llvm-project#62270 A regression of D139974. Differential Revision: https://reviews.llvm.org/D148953
I am one of the maintainers of the MSYS2 build of Rust.
Since upgrading to LLVM 16.0 the GCC build of Rust fails with the following error.
Shorter version :
multiple definition of `llvm::Any::TypeId<llvm::Function const*>::Id';
They are defined in
PassBuilder.cpp.obj
andPassWrapper.o
.I have traced the cause of the error to this change: 95b27b2
Rerverting it fixes the build issue.
In a nutshell, Rust builds it own C++ wrappers around some LLVM classes.
It happens that both Rust and LLVM end up instantiating the same "static template".
Apparently having these instances "constant" allows GCC to merge them (?).
If they are not constant, GCC fails with
multiple definition
errors.Note that the Clang build is fine.
The text was updated successfully, but these errors were encountered: