Skip to content

Commit f8bcd93

Browse files
authored
[lld/COFF] Fix -start-lib / -end-lib after reviews.llvm.org/D116434 (#120452)
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 b05071d commit f8bcd93

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-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: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,79 @@ define void @eager() {
9797
define i32 @ogre() {
9898
ret i32 1
9999
}
100+
101+
102+
; Check that lazy object files trigger loads correctly.
103+
; If the links succeed, that's enough, no additional tests needed.
104+
105+
; RUN: llc -filetype=obj %t.dir/main2.ll -o %t-main2.obj
106+
; RUN: llc -filetype=obj %t.dir/foo.ll -o %t-foo.obj
107+
; RUN: llc -filetype=obj %t.dir/bar.ll -o %t-bar.obj
108+
; RUN: llc -filetype=obj %t.dir/baz.ll -o %t-baz.obj
109+
; RUN: opt -thinlto-bc %t.dir/main2.ll -o %t-main2.bc
110+
; RUN: opt -thinlto-bc %t.dir/foo.ll -o %t-foo.bc
111+
; RUN: opt -thinlto-bc %t.dir/bar.ll -o %t-bar.bc
112+
; RUN: opt -thinlto-bc %t.dir/baz.ll -o %t-baz.bc
113+
114+
; RUN: lld-link -out:%t2.exe -entry:main \
115+
; RUN: %t-main2.obj %t-foo.obj %t-bar.obj %t-baz.obj
116+
; RUN: lld-link -out:%t2.exe -entry:main \
117+
; RUN: %t-main2.obj /start-lib %t-foo.obj %t-bar.obj %t-baz.obj /end-lib
118+
; RUN: lld-link -out:%t2.exe -entry:main \
119+
; RUN: /start-lib %t-foo.obj %t-bar.obj %t-baz.obj /end-lib %t-main2.obj
120+
121+
; RUN: lld-link -out:%t2.exe -entry:main \
122+
; RUN: %t-main2.bc %t-foo.bc %t-bar.bc %t-baz.bc
123+
; RUN: lld-link -out:%t2.exe -entry:main \
124+
; RUN: %t-main2.bc /start-lib %t-foo.bc %t-bar.bc %t-baz.bc /end-lib
125+
; RUN: lld-link -out:%t2.exe -entry:main \
126+
; RUN: /start-lib %t-foo.bc %t-bar.bc %t-baz.bc /end-lib %t-main2.bc
127+
128+
#--- main2.ll
129+
130+
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
131+
target triple = "x86_64-pc-windows-msvc"
132+
133+
declare void @bar()
134+
135+
define void @main() {
136+
call void () @bar()
137+
ret void
138+
}
139+
140+
141+
#--- foo.ll
142+
143+
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
144+
target triple = "x86_64-pc-windows-msvc"
145+
146+
define void @foo() {
147+
ret void
148+
}
149+
150+
151+
#--- bar.ll
152+
153+
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
154+
target triple = "x86_64-pc-windows-msvc"
155+
156+
; One undefined symbol from the lazy obj file before it,
157+
; one from the one after it.
158+
declare void @foo()
159+
declare void @baz()
160+
161+
define void @bar() {
162+
call void () @foo()
163+
call void () @baz()
164+
ret void
165+
}
166+
167+
168+
#--- baz.ll
169+
170+
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
171+
target triple = "x86_64-pc-windows-msvc"
172+
173+
define void @baz() {
174+
ret void
175+
}

0 commit comments

Comments
 (0)