-
Notifications
You must be signed in to change notification settings - Fork 13.4k
lld-link Crash #131807
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
Comments
@llvm/issue-subscribers-lld-coff Author: Jose Santiago (jlsantiago0)
Using LLVM-20.1.0 release build from https://github.com/llvm/llvm-project/releases/download/llvmorg-20.1.0/LLVM-20.1.0-Linux-X64.tar.xz
|
Could you please provide reproducer? |
If you can pass an option like |
Oh. So i figured it out: I couldnt upload a tar file so i zipped it. |
I've managed to reproduce the crash, and reduce it to a small selfcontained testcase.
void __declspec(dllimport) other(void);
void entry(void) {
other();
}
void other(void) {
}
void __declspec(dllexport) exportedFunc(void) {
} $ clang -target x86_64-windows-msvc -c entry.c
$ clang -target x86_64-windows-msvc -c other.c
$ llvm-ar rcs other.lib other.o
$ lld-link entry.o -entry:entry -subsystem:console other.lib The problem is that we handle any This makes sure that each However in this case, we only end up pulling the other object file later, through In this case, the undefined This obviously isn't great. There's lots of ugly and kludgey ways to work around it, I'm wondering what is the best one (or least ugly). CC @rnk @aganea @nico @cjacek who are familiar with these bits of the linker. (To be clear, I'm not sure I have time to invest in trying to fix this right now, so feel totally free to pick it up.) @jlsantiago0 As a way to avoid the issue, I would recommend that your static libraries wouldn't contain dllexport attributes, and that code referencing them don't expect them to be dllimported. In this case, your |
It seems MSVC link.exe bails out with
We seem to emit
Both LLD and MSVC emit
|
That sounds reasonable - that would allow keeping the current logic of doing the importing of locally defined symbols in a late stage like we do now.
For clarity, this error message in English is:
But it does seem like MS link.exe is more strict than we are here - it looks like it doesn't pull in symbols from static libraries at all, in order to import local symbols, while we have been adding more of that behaviour (in 6a1bdd9 / #109082 - CC @glandium). |
Indeed, I think this part does not match what MSVC is doing: https://github.com/llvm/llvm-project/blob/main/lld/COFF/SymbolTable.cpp#L484-L488 Perhaps the initial problem that @glandium had was caused by our current the order of extraction of symbols inside .LIBs, which does not match was MSVC is doing, as fixed by #85290 (but I am speculating here) Indeed the test case in https://github.com/llvm/llvm-project/blob/main/lld/test/COFF/undefined_lazy.test fails with latest MSVC link.exe. With LLD:
With MSVC link.exe:
|
Which makes me think I'd be nice to optionally have a way to validate that at least |
I think we would be differing on quite a lot of cases; we have a huge amount of cases where we support things that MS link.exe doesn't. |
This reverts commit 6a1bdd9 and re-instate behavior that matches what MSVC link.exe does, that is, error out when trying to dllimport a symbol from a static library. A hint is now displayed in stdout, mentioning that we should rather dllimport the symbol from a import library. Fixes llvm/llvm-project#131807
FYI, there was another report of a similar issue, and there we found the root cause for why there were dllimport/dllexport attributes when linking static libraries - see #134843 (comment). TL;DR, known libtool issue, you may need to update the bundled libtool in source packages with one provided by msys2 which contains the necessary patches to fix this issue. |
Using LLVM-20.1.0 release build from https://github.com/llvm/llvm-project/releases/download/llvmorg-20.1.0/LLVM-20.1.0-Linux-X64.tar.xz
The text was updated successfully, but these errors were encountered: