-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[LLD][COFF] Don't dllimport from static libraries #134443
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
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# REQUIRES: x86 | ||
|
||
# Ensure that we don't import dllimport symbols from static (non-import) libraries | ||
# RUN: split-file %s %t.dir | ||
# RUN: llvm-mc --filetype=obj -triple=x86_64-windows-msvc %t.dir/foo.s -o %t.foo.obj | ||
# RUN: llvm-mc --filetype=obj -triple=x86_64-windows-msvc %t.dir/main.s -o %t.main.obj | ||
# RUN: llvm-lib %t.foo.obj -out:%t.foo.lib | ||
# RUN: not lld-link %t.foo.lib %t.main.obj -out:%t.dll -dll 2>&1 | FileCheck %s | ||
|
||
CHECK: error: undefined symbol: __declspec(dllimport) foo | ||
|
||
# Now do the same thing, but import the symbol from a import library. | ||
# RUN: llvm-mc --filetype=obj -triple=x86_64-windows-msvc %t.dir/foo_dll_main.s -o %t.foo_dll_main.obj | ||
# RUN: lld-link /out:%t.dll /dll %t.foo.obj %t.foo_dll_main.obj /export:foo /implib:%t.foo.imp.lib | ||
# RUN: lld-link %t.main.obj %t.foo.imp.lib -out:%t.exe -dll | ||
|
||
#--- foo.s | ||
.text | ||
.globl foo | ||
foo: | ||
ret | ||
#--- foo_dll_main.s | ||
.text | ||
.global _DllMainCRTStartup | ||
_DllMainCRTStartup: | ||
ret | ||
#--- main.s | ||
.text | ||
.global _DllMainCRTStartup | ||
_DllMainCRTStartup: | ||
call *__imp_foo(%rip) | ||
ret |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: an import library
Initially I felt confused by this message, but I think it may be the best way to phrase it. The other angle at this is, that if this wasn't a static library but object files, or members in a static library that we've already pulled in, then we'd actually link it successfully. But it's hard to suggest that in the diagnostic, and we probably don't want to push users that way anyway. So I guess this wording is fine.
I don't see this diagnostic tested though - I think it would be good to check that we do hit it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see updated version. I've added another testcase to also validate your suggestion in #131807 (comment) -- which happens to only generate a warning.