-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[lld-link] Spourious duplicate symbol error #31950
Comments
I was aware that the LLD's symbol resolution order might be different from the MSVC linker, but in most cases it just works fine. What program are you trying to link? |
This problem showed up when compiling the spec2k6/namd benchmark. |
Yes, if possible. |
Changing the build system is not always possible for us. This commit https://reviews.llvm.org/D32317 solves a similar problem. Would this be ok for you ? |
Sorting input files is probably OK, as I don't think of any failure scenario. Do you want to write a patch? |
Yes, I can do that. |
Seeing this when trying to link with a Microsoft C library (libcmt) with lld-link 8.0.0: lld-link: error: duplicate symbol: __aenvptr in libcmt.lib(crt0.obj) and in libcmt.lib(wincrt0.obj) In this case, the object files are all within the same .lib file, therefore there is no workaround available such as reordering object files. Of course, MS link.exe does not exhibit this problem. |
"/force:multiple" allows working around the above situation. |
Duplicate symbol error test case for lld-link gcc:
clang:
msvc (on Windows):
clangcl (on Windows):
oj] |
I'm encountering this problem when using https://github.com/https://github.com/nabijaczleweli/rust-embed-resource to have two different resources, one for tests and one for release. I can somewhat work around it by using In my case, I can't reorder the arguments since it's cargo and rustc that orders them |
Using @CyberShadow's response and adding |
Extended Description
We have noticed an inconsistency between the link.exe and lld-link.exe
Consider this example:
foo1.ll defines a function foo
foo2.ll defines a function foo
main.ll contains main that calls foo
foo1.ll is assembled into an object file and then into a library
foo2.ll is assembled into an object file
The following command currently fails:
lld-link.exe foo1.lib main.obj foo2.obj
The error is: duplicate symbol: foo
While the same invocation works with link.exe
This is because link processes all .obj files in input first and resorts to .lib inputs only if there are unresolved symbols.
Since the symbol foo is found in the .obj the library is ignored and no error is reported.
A reproducer for this bug is attached in the format of an LLVM test.
The same diff file contains a possible fix.
The text was updated successfully, but these errors were encountered: