-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[lld][WebAssembly] Fix bitcode LTO order in archive parsing #73095
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d79b51c
[lld][WebAssembly] Fix bitcode LTO order in archive parsing
aheejin 90af3eb
Add comment with the PR link
aheejin f880bfc
Paste source C++ code as comments
aheejin 1943722
add :
aheejin 72804e9
Add `CHECK-NOT` to make sure we don't have duplicate defs
aheejin a559108
Rename tests
aheejin c21e792
Missing ;
aheejin 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,42 @@ | ||
target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128" | ||
target triple = "wasm32-unknown-unknown" | ||
|
||
; Generated from this C++ code and simplified manually: | ||
; | ||
; int foo(); | ||
; inline int unused = foo(); | ||
; | ||
; int main() { | ||
; return foo(); | ||
; } | ||
|
||
$unused = comdat any | ||
|
||
@unused = linkonce_odr global i32 0, comdat, align 4 | ||
@_ZGV6unused = linkonce_odr global i32 0, comdat($unused), align 4 | ||
@llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init, ptr @unused }] | ||
|
||
define internal void @__cxx_global_var_init() comdat($unused) { | ||
entry: | ||
%0 = load i8, ptr @_ZGV6unused, align 4 | ||
%1 = and i8 %0, 1 | ||
%guard.uninitialized = icmp eq i8 %1, 0 | ||
br i1 %guard.uninitialized, label %init.check, label %init.end | ||
|
||
init.check: ; preds = %entry | ||
store i8 1, ptr @_ZGV6unused, align 4 | ||
%call = call i32 @foo() | ||
store i32 %call, ptr @unused, align 4 | ||
br label %init.end | ||
|
||
init.end: ; preds = %init.check, %entry | ||
ret void | ||
} | ||
|
||
declare i32 @foo() | ||
|
||
define i32 @main() { | ||
entry: | ||
%call = call i32 @foo() | ||
ret i32 %call | ||
} |
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,39 @@ | ||
target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128" | ||
target triple = "wasm32-unknown-unknown" | ||
|
||
; Generated from this C++ code and simplified manually: | ||
; | ||
; int foo(); | ||
; inline int unused = foo(); | ||
; | ||
; int foo() { | ||
; return 42; | ||
; } | ||
|
||
$unused = comdat any | ||
|
||
@unused = linkonce_odr global i32 0, comdat, align 4 | ||
@_ZGV6unused = linkonce_odr global i32 0, comdat($unused), align 4 | ||
@llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init, ptr @unused }] | ||
|
||
define internal void @__cxx_global_var_init() comdat($unused) { | ||
entry: | ||
%0 = load i8, ptr @_ZGV6unused, align 4 | ||
%1 = and i8 %0, 1 | ||
%guard.uninitialized = icmp eq i8 %1, 0 | ||
br i1 %guard.uninitialized, label %init.check, label %init.end | ||
|
||
init.check: ; preds = %entry | ||
store i8 1, ptr @_ZGV6unused, align 4 | ||
%call = call i32 @foo() | ||
store i32 %call, ptr @unused, align 4 | ||
br label %init.end | ||
|
||
init.end: ; preds = %init.check, %entry | ||
ret void | ||
} | ||
|
||
define i32 @foo() { | ||
entry: | ||
ret i32 42 | ||
} |
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,19 @@ | ||
; Check if we handle a variable (here __cxx_global_var_init) in different LTO | ||
; bitcode modules sharing a comdat. | ||
|
||
; RUN: llvm-as %S/Inputs/comdat_ordering1.ll -o %t1.o | ||
; RUN: llvm-as %S/Inputs/comdat_ordering2.ll -o %t2.o | ||
; RUN: llvm-ar rcs %t1.a %t1.o | ||
; RUN: llvm-ar rcs %t2.a %t2.o | ||
; RUN: wasm-ld %t1.a %t2.a -o %t.wasm --no-entry --export=main --export=__wasm_call_ctors | ||
; RUN: obj2yaml %t.wasm | FileCheck %s | ||
|
||
; CHECK: - Type: CUSTOM | ||
; CHECK-NEXT: Name: name | ||
; CHECK-NEXT: FunctionNames: | ||
; CHECK-NEXT: - Index: 0 | ||
; CHECK-NEXT: Name: __wasm_call_ctors | ||
; CHECK-NEXT: - Index: 1 | ||
; CHECK-NEXT: Name: __cxx_global_var_init | ||
|
||
; CHECK-NOT: Name: __cxx_global_var_init.2 |
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
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.
This looks like a good change to me. The fact that ELF does it this way makes me even more confident this is correct:
llvm-project/lld/ELF/InputFiles.cpp
Lines 314 to 315 in 3a6f02a