-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[LLD][COFF] Fix handling of weak aliases referencing lazy symbols #112243
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -340,7 +340,10 @@ class Undefined : public Symbol { | |
| // If this symbol is external weak, try to resolve it to a defined | ||
| // symbol by searching the chain of fallback symbols. Returns the symbol if | ||
| // successful, otherwise returns null. | ||
| Defined *getWeakAlias(); | ||
| Symbol *getWeakAlias(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In trying to read the diff and the effects of it - I see that a number of callers are switched from Because any caller that is switched to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The remaining callers use In the test example from this PR, using |
||
| Defined *getDefinedWeakAlias() { | ||
| return dyn_cast_or_null<Defined>(getWeakAlias()); | ||
| } | ||
|
|
||
| // If this symbol is external weak, replace this object with aliased symbol. | ||
| bool resolveWeakAlias(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # REQUIRES: x86 | ||
|
|
||
| # RUN: llvm-mc -filetype=obj -triple=i686-windows %s -o %t.obj | ||
| # RUN: llvm-lib -machine:x86 -out:%t-func.lib %t.obj | ||
|
|
||
| # -export:func creates a weak alias to a lazy symbol. Make sure we can handle that when processing -export:func2=func. | ||
| # RUN: lld-link -dll -noentry -machine:x86 -out:%t.dll %t-func.lib -export:func -export:func2=func | ||
|
|
||
| .text | ||
| .def @feat.00; | ||
| .scl 3; | ||
| .type 0; | ||
| .endef | ||
| .globl @feat.00 | ||
| .set @feat.00, 1 | ||
| .globl _func@0 | ||
| _func@0: | ||
| retl |
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.
So... previously, this
cast<Undefined>(a)was broken (invoking UB etc), if we had a weak alias which pointed at something which wasn't eitherUndefinedorDefined?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.
Yes.
The assumption that a symbol is either
UndefinedorDefinedis true for some callers, but not all. See the other comment for details.