-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[lld][WebAssembly] Fix spurious signature mismatch under LTO #136197
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
+47
−1
Merged
Changes from all commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
; RUN: rm -rf %t && split-file %s %t && cd %t | ||
; RUN: opt -thinlto-bc a.ll -o a.o | ||
; RUN: opt -thinlto-bc b.ll -o b.o | ||
; RUN: llvm-ar rcs b.a b.o | ||
; RUN: opt -thinlto-bc c.ll -o c.o | ||
|
||
;; Taking the address of the incorrectly declared @foo should not generate a warning. | ||
; RUN: wasm-ld --fatal-warnings --no-entry --export-all a.o b.a -o a.out \ | ||
; RUN: | FileCheck %s --implicit-check-not 'warning' --allow-empty | ||
|
||
;; But we should still warn if we call the function with the wrong signature. | ||
; RUN: not wasm-ld --fatal-warnings --no-entry --export-all a.o b.a c.o -o b.out 2>&1 \ | ||
; RUN: | FileCheck %s --check-prefix=INVALID | ||
|
||
; INVALID: error: function signature mismatch: foo | ||
; INVALID: >>> defined as () -> void | ||
; INVALID: >>> defined as () -> i32 | ||
|
||
;--- a.ll | ||
target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" | ||
target triple = "wasm32-unknown-unknown" | ||
|
||
@ptr = constant ptr @foo | ||
declare void @foo() | ||
|
||
;--- b.ll | ||
target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" | ||
target triple = "wasm32-unknown-unknown" | ||
|
||
define i32 @foo() noinline { | ||
entry: | ||
ret i32 42 | ||
} | ||
|
||
;--- c.ll | ||
target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" | ||
target triple = "wasm32-unknown-unknown" | ||
|
||
declare void @foo() | ||
|
||
define void @invalid() { | ||
entry: | ||
call void @foo() | ||
ret void | ||
} |
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
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.
I wonder if we should instead make SymbolTable.cpp assume that the null signature is a placeholder? i.e. today we do
checkSig = ud->isCalledDirectly;
but we could docheckSig = ud->isCalledDirectly && ud->signature;
?I don't feel strongly though and this approach certainly works.
Uh oh!
There was an error while loading. Please reload this page.
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.
I don't think that would fix the issue:
signatureMatches()
already returnstrue
when either function has a null signature.In the test case, after LTO, the
() -> void
reference froma.ll
is added first. The existing undefined symbol has a null signature, but this one doesn't, so we setexistingFunction->signature
to() -> void
:llvm-project/lld/wasm/SymbolTable.cpp
Lines 657 to 658 in 1db03ca
As
isCalledDirectly
is set to true, we'll report the signature mismatch when we try to add the() -> i32
definition fromb.ll
.I suppose an alternative would be to only set
existingFunction->signature
if the undefined symbol we replace it with is called directly, but that would mean we never set the signature if the function has no call sites, only its address is taken. That might cause problems later on.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.
Sounds good. LGTM as is.
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.
thanks!