Skip to content

Commit 39f3528

Browse files
committed
[lld/COFF] Fix -start-lib / -end-lib after reviews.llvm.org/D116434
That change forgot to set `lazy` to false before calling `addFile()` in `forceLazy()` which caused `addFile()` to parse the file we want to force a load for to be added as a lazy object again instead of adding the file to `ctx.objFileInstances`. This is caught by a pretty simple test (included).
1 parent cde996c commit 39f3528

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

lld/COFF/SymbolTable.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ static void forceLazy(Symbol *s) {
116116
}
117117
case Symbol::Kind::LazyObjectKind: {
118118
InputFile *file = cast<LazyObject>(s)->file;
119+
file->lazy = false;
119120
file->symtab.addFile(file);
120121
break;
121122
}

lld/test/COFF/start-lib.ll

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,78 @@ define i32 @bar() {
7979

8080
!llvm.linker.options = !{!0}
8181
!0 = !{!"/INCLUDE:bar"}
82+
83+
84+
; Check that lazy object files trigger loads correctly.
85+
; If the links succeed, that's enough, no additional tests needed.
86+
87+
; RUN: llc -filetype=obj %t.dir/main2.ll -o %t-main2.obj
88+
; RUN: llc -filetype=obj %t.dir/foo.ll -o %t-foo.obj
89+
; RUN: llc -filetype=obj %t.dir/bar.ll -o %t-bar.obj
90+
; RUN: llc -filetype=obj %t.dir/baz.ll -o %t-baz.obj
91+
; RUN: opt -thinlto-bc %t.dir/main2.ll -o %t-main2.bc
92+
; RUN: opt -thinlto-bc %t.dir/foo.ll -o %t-foo.bc
93+
; RUN: opt -thinlto-bc %t.dir/bar.ll -o %t-bar.bc
94+
; RUN: opt -thinlto-bc %t.dir/baz.ll -o %t-baz.bc
95+
96+
; RUN: lld-link -out:%t2.exe -entry:main \
97+
; RUN: %t-main2.obj %t-foo.obj %t-bar.obj %t-baz.obj
98+
; RUN: lld-link -out:%t2.exe -entry:main \
99+
; RUN: %t-main2.obj /start-lib %t-foo.obj %t-bar.obj %t-baz.obj /end-lib
100+
; RUN: lld-link -out:%t2.exe -entry:main \
101+
; RUN: /start-lib %t-foo.obj %t-bar.obj %t-baz.obj /end-lib %t-main2.obj
102+
103+
; RUN: lld-link -out:%t2.exe -entry:main \
104+
; RUN: %t-main2.bc %t-foo.bc %t-bar.bc %t-baz.bc
105+
; RUN: lld-link -out:%t2.exe -entry:main \
106+
; RUN: %t-main2.bc /start-lib %t-foo.bc %t-bar.bc %t-baz.bc /end-lib
107+
; RUN: lld-link -out:%t2.exe -entry:main \
108+
; RUN: /start-lib %t-foo.bc %t-bar.bc %t-baz.bc /end-lib %t-main2.bc
109+
110+
#--- main2.ll
111+
112+
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
113+
target triple = "x86_64-pc-windows-msvc"
114+
115+
declare void @bar()
116+
117+
define void @main() {
118+
call void () @bar()
119+
ret void
120+
}
121+
122+
123+
#--- foo.ll
124+
125+
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
126+
target triple = "x86_64-pc-windows-msvc"
127+
128+
define void @foo() {
129+
ret void
130+
}
131+
132+
133+
#--- bar.ll
134+
135+
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
136+
target triple = "x86_64-pc-windows-msvc"
137+
138+
; One undef from the lazy obj file before it, one from the one after it.
139+
declare void @foo()
140+
declare void @baz()
141+
142+
define void @bar() {
143+
call void () @foo()
144+
call void () @baz()
145+
ret void
146+
}
147+
148+
149+
#--- baz.ll
150+
151+
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
152+
target triple = "x86_64-pc-windows-msvc"
153+
154+
define void @baz() {
155+
ret void
156+
}

0 commit comments

Comments
 (0)