Skip to content

Commit 2b6713d

Browse files
authored
[lld/coff] Fix assert on /start-lib foo.obj /end-lib during eager loads (#120292)
If foo.obj is eagerly loaded (due to a prior undef referencing one if its symbols) and has more than one symbol, we used to assert: SymbolTable::addLazyObject() for the first symbol would set `lazy` to false and load all symbols from the file, but the outer ObjFile::parseLazy() loop would continue to run and call addLazyObject() for the second symbol, which would assert. Instead, just stop adding lazy symbols if the file got loaded for real while adding a symbol. (The ELF port has a similar early exit in `ObjFile<ELFT>::parseLazy()`.)
1 parent 4039a79 commit 2b6713d

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

lld/COFF/InputFiles.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ void ObjFile::parseLazy() {
193193
if (coffSym.isAbsolute() && ignoredSymbolName(name))
194194
continue;
195195
symtab.addLazyObject(this, name);
196+
if (!lazy)
197+
return;
196198
i += coffSym.getNumberOfAuxSymbols();
197199
}
198200
}
@@ -1292,8 +1294,11 @@ void BitcodeFile::parse() {
12921294

12931295
void BitcodeFile::parseLazy() {
12941296
for (const lto::InputFile::Symbol &sym : obj->symbols())
1295-
if (!sym.isUndefined())
1297+
if (!sym.isUndefined()) {
12961298
symtab.addLazyObject(this, sym.getName());
1299+
if (!lazy)
1300+
return;
1301+
}
12971302
}
12981303

12991304
MachineTypes BitcodeFile::getMachineType() const {

lld/test/COFF/start-lib.ll

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,37 @@
66
; RUN: llc -filetype=obj %t.dir/main.ll -o %t.obj
77
; RUN: llc -filetype=obj %t.dir/start-lib1.ll -o %t1.obj
88
; RUN: llc -filetype=obj %t.dir/start-lib2.ll -o %t2.obj
9+
; RUN: llc -filetype=obj %t.dir/eager.ll -o %t-eager.obj
910
; RUN: opt -thinlto-bc %t.dir/main.ll -o %t.bc
1011
; RUN: opt -thinlto-bc %t.dir/start-lib1.ll -o %t1.bc
1112
; RUN: opt -thinlto-bc %t.dir/start-lib2.ll -o %t2.bc
13+
; RUN: opt -thinlto-bc %t.dir/eager.ll -o %t-eager.bc
1214
;
1315
; RUN: lld-link -out:%t1.exe -entry:main -opt:noref -lldmap:%t1.map \
14-
; RUN: %t.obj %t1.obj %t2.obj
16+
; RUN: %t.obj %t1.obj %t2.obj %t-eager.obj
1517
; RUN: FileCheck --check-prefix=TEST1 %s < %t1.map
1618
; RUN: lld-link -out:%t1.exe -entry:main -opt:noref -lldmap:%t1.thinlto.map \
17-
; RUN: %t.bc %t1.bc %t2.bc
19+
; RUN: %t.bc %t1.bc %t2.bc %t-eager.bc
1820
; RUN: FileCheck --check-prefix=TEST1 %s < %t1.thinlto.map
1921
; TEST1: foo
2022
; TEST1: bar
2123
;
2224
; RUN: lld-link -out:%t2.exe -entry:main -opt:noref -lldmap:%t2.map \
23-
; RUN: %t.obj -start-lib %t1.obj -end-lib %t2.obj
25+
; RUN: %t.obj -start-lib %t1.obj %t-eager.obj -end-lib %t2.obj
2426
; RUN: FileCheck --check-prefix=TEST2 %s < %t2.map
2527
; RUN: lld-link -out:%t2.exe -entry:main -opt:noref -lldmap:%t2.thinlto.map \
26-
; RUN: %t.bc -start-lib %t1.bc -end-lib %t2.bc
28+
; RUN: %t.bc -start-lib %t1.bc %t-eager.bc -end-lib %t2.bc
2729
; RUN: FileCheck --check-prefix=TEST2 %s < %t2.thinlto.map
2830
; TEST2: Address Size Align Out In Symbol
2931
; TEST2-NOT: {{ }}foo{{$}}
3032
; TEST2: {{ }}bar{{$}}
3133
; TEST2-NOT: {{ }}foo{{$}}
3234
;
3335
; RUN: lld-link -out:%t3.exe -entry:main -opt:noref -lldmap:%t3.map \
34-
; RUN: %t.obj -start-lib %t1.obj %t2.obj
36+
; RUN: %t.obj -start-lib %t1.obj %t2.obj %t-eager.obj
3537
; RUN: FileCheck --check-prefix=TEST3 %s < %t3.map
3638
; RUN: lld-link -out:%t3.exe -entry:main -opt:noref -lldmap:%t3.thinlto.map \
37-
; RUN: %t.bc -start-lib %t1.bc %t2.bc
39+
; RUN: %t.bc -start-lib %t1.bc %t2.bc %t-eager.bc
3840
; RUN: FileCheck --check-prefix=TEST3 %s < %t3.thinlto.map
3941
; TEST3: Address Size Align Out In Symbol
4042
; TEST3-NOT: {{ }}foo{{$}}
@@ -46,7 +48,10 @@
4648
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
4749
target triple = "x86_64-pc-windows-msvc"
4850

51+
declare void @eager()
52+
4953
define void @main() {
54+
call void @eager()
5055
ret void
5156
}
5257

@@ -79,3 +84,16 @@ define i32 @bar() {
7984

8085
!llvm.linker.options = !{!0}
8186
!0 = !{!"/INCLUDE:bar"}
87+
88+
#--- eager.ll
89+
90+
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
91+
target triple = "x86_64-pc-windows-msvc"
92+
93+
define void @eager() {
94+
ret void
95+
}
96+
97+
define i32 @ogre() {
98+
ret i32 1
99+
}

0 commit comments

Comments
 (0)