Skip to content

Commit b091768

Browse files
committed
[LLD][COFF] Fix crash with /summary and PCH input files
Before this patch /summary was crashing with some .PCH.OBJ files, because tpiMap[srcIdx++] was reading at the wrong location. When the TpiSource depends on a .PCH.OBJ file, the types should be offset by the previously merged PCH.OBJ set of indices. Differential Revision: https://reviews.llvm.org/D88678 (cherry picked from commit 4140f07)
1 parent 59012b6 commit b091768

File tree

4 files changed

+191
-1
lines changed

4 files changed

+191
-1
lines changed

lld/COFF/DebugTypes.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ Expected<const CVIndexMap *> TpiSource::mergeDebugT(TypeMerger *m,
202202
BinaryStreamReader reader(file->debugTypes, support::little);
203203
cantFail(reader.readArray(types, reader.getLength()));
204204

205+
// When dealing with PCH.OBJ, some indices were already merged.
206+
unsigned nbHeadIndices = indexMap->tpiMap.size();
207+
205208
if (config->debugGHashes) {
206209
ArrayRef<GloballyHashedType> hashes;
207210
std::vector<GloballyHashedType> ownedHashes;
@@ -232,7 +235,7 @@ Expected<const CVIndexMap *> TpiSource::mergeDebugT(TypeMerger *m,
232235
// collecting statistics.
233236
m->tpiCounts.resize(m->getTypeTable().size());
234237
m->ipiCounts.resize(m->getIDTable().size());
235-
uint32_t srcIdx = 0;
238+
uint32_t srcIdx = nbHeadIndices;
236239
for (CVType &ty : types) {
237240
TypeIndex dstIdx = indexMap->tpiMap[srcIdx++];
238241
// Type merging may fail, so a complex source type may become the simple

lld/test/COFF/Inputs/precomp2-a.yaml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
--- !COFF
2+
header:
3+
Machine: IMAGE_FILE_MACHINE_AMD64
4+
Characteristics: [ ]
5+
sections:
6+
- Name: '.debug$S'
7+
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
8+
Alignment: 1
9+
Subsections:
10+
- !Symbols
11+
Records:
12+
- Kind: S_OBJNAME
13+
ObjNameSym:
14+
Signature: 545589255
15+
ObjectName: 'D:\llvm-project\lld\test\COFF\Inputs\precomp2-a.obj'
16+
- Kind: S_COMPILE3
17+
Compile3Sym:
18+
Flags: [ SecurityChecks, HotPatch ]
19+
Machine: X64
20+
FrontendMajor: 19
21+
FrontendMinor: 13
22+
FrontendBuild: 26131
23+
FrontendQFE: 1
24+
BackendMajor: 19
25+
BackendMinor: 13
26+
BackendBuild: 26131
27+
BackendQFE: 1
28+
Version: 'Microsoft (R) Optimizing Compiler'
29+
- !StringTable
30+
Strings:
31+
- 'D:\llvm-project\lld\test\COFF\precomp\precomp.pch'
32+
- 'D:\llvm-project\lld\test\COFF\precomp\precomp.h'
33+
- 'D:\llvm-project\lld\test\COFF\precomp\a.cpp'
34+
- Name: '.debug$T'
35+
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
36+
Alignment: 1
37+
Types:
38+
- Kind: LF_PRECOMP
39+
Precomp:
40+
StartTypeIndex: 4096
41+
TypesCount: 3
42+
Signature: 545589255
43+
PrecompFilePath: 'D:\llvm-project\lld\test\COFF\Inputs\precomp2.obj'
44+
- Kind: LF_STRING_ID
45+
StringId:
46+
Id: 0
47+
String: 'test test test test test'
48+
- Kind: LF_STRING_ID
49+
StringId:
50+
Id: 0
51+
String: 'test test test test test'
52+
- Kind: LF_STRING_ID
53+
StringId:
54+
Id: 0
55+
String: 'test test test test test'
56+
- Kind: LF_BUILDINFO
57+
BuildInfo:
58+
ArgIndices: [ 4101, 4101, 4101, 4101, 4101 ]
59+
symbols:
60+
- Name: '.debug$S'
61+
Value: 0
62+
SectionNumber: 1
63+
SimpleType: IMAGE_SYM_TYPE_NULL
64+
ComplexType: IMAGE_SYM_DTYPE_NULL
65+
StorageClass: IMAGE_SYM_CLASS_STATIC
66+
SectionDefinition:
67+
Length: 0
68+
NumberOfRelocations: 0
69+
NumberOfLinenumbers: 0
70+
CheckSum: 0
71+
Number: 0
72+
- Name: '.debug$T'
73+
Value: 0
74+
SectionNumber: 2
75+
SimpleType: IMAGE_SYM_TYPE_NULL
76+
ComplexType: IMAGE_SYM_DTYPE_NULL
77+
StorageClass: IMAGE_SYM_CLASS_STATIC
78+
SectionDefinition:
79+
Length: 0
80+
NumberOfRelocations: 0
81+
NumberOfLinenumbers: 0
82+
CheckSum: 0
83+
Number: 0
84+
...

lld/test/COFF/Inputs/precomp2.yaml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
--- !COFF
2+
header:
3+
Machine: IMAGE_FILE_MACHINE_AMD64
4+
Characteristics: [ ]
5+
sections:
6+
- Name: '.debug$S'
7+
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
8+
Alignment: 1
9+
Subsections:
10+
- !Symbols
11+
Records:
12+
- Kind: S_OBJNAME
13+
ObjNameSym:
14+
Signature: 545589255
15+
ObjectName: 'D:\llvm-project\lld\test\COFF\Inputs\precomp2.obj'
16+
- Kind: S_COMPILE3
17+
Compile3Sym:
18+
Flags: [ SecurityChecks, HotPatch ]
19+
Machine: X64
20+
FrontendMajor: 19
21+
FrontendMinor: 13
22+
FrontendBuild: 26131
23+
FrontendQFE: 1
24+
BackendMajor: 19
25+
BackendMinor: 13
26+
BackendBuild: 26131
27+
BackendQFE: 1
28+
Version: 'Microsoft (R) Optimizing Compiler'
29+
- !StringTable
30+
Strings:
31+
- 'D:\llvm-project\lld\test\COFF\precomp\precomp.pch'
32+
- Name: '.debug$P'
33+
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
34+
Alignment: 1
35+
PrecompTypes:
36+
- Kind: LF_STRUCTURE
37+
Class:
38+
MemberCount: 0
39+
Options: [ None, ForwardReference, HasUniqueName ]
40+
FieldList: 0
41+
Name: _s__CatchableType
42+
UniqueName: '.?AU_s__CatchableType@@'
43+
DerivationList: 0
44+
VTableShape: 0
45+
Size: 0
46+
- Kind: LF_MODIFIER
47+
Modifier:
48+
ModifiedType: 4096
49+
Modifiers: [ None, Const ]
50+
- Kind: LF_POINTER
51+
Pointer:
52+
ReferentType: 4096
53+
Attrs: 65548
54+
- Kind: LF_ENDPRECOMP
55+
EndPrecomp:
56+
Signature: 545589255
57+
symbols:
58+
- Name: '.debug$S'
59+
Value: 0
60+
SectionNumber: 1
61+
SimpleType: IMAGE_SYM_TYPE_NULL
62+
ComplexType: IMAGE_SYM_DTYPE_NULL
63+
StorageClass: IMAGE_SYM_CLASS_STATIC
64+
SectionDefinition:
65+
Length: 0
66+
NumberOfRelocations: 0
67+
NumberOfLinenumbers: 0
68+
CheckSum: 0
69+
Number: 0
70+
- Name: '.debug$P'
71+
Value: 0
72+
SectionNumber: 2
73+
SimpleType: IMAGE_SYM_TYPE_NULL
74+
ComplexType: IMAGE_SYM_DTYPE_NULL
75+
StorageClass: IMAGE_SYM_CLASS_STATIC
76+
SectionDefinition:
77+
Length: 0
78+
NumberOfRelocations: 0
79+
NumberOfLinenumbers: 0
80+
CheckSum: 0
81+
Number: 0
82+
...
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
The input files were tailored so that we end up with a resulting IPI stream
3+
smaller than the TPI stream, which would previously trigger a crash with
4+
/summary.
5+
6+
RUN: rm -rf %t && mkdir %t
7+
RUN: yaml2obj < %S/Inputs/precomp2.yaml -o %t\precomp2.obj
8+
RUN: yaml2obj < %S/Inputs/precomp2-a.yaml -o %t\precomp2-a.obj
9+
RUN: lld-link %t\precomp2-a.obj %t\precomp2.obj /nodefaultlib /noentry \
10+
RUN: /dll /out:%t.dll /debug /summary | FileCheck %s -check-prefix SUMMARY
11+
12+
SUMMARY: Summary
13+
SUMMARY-NEXT: --------------------------------------------------------------------------------
14+
SUMMARY-NEXT: 2 Input OBJ files (expanded from all cmd-line inputs)
15+
SUMMARY-NEXT: 0 PDB type server dependencies
16+
SUMMARY-NEXT: 1 Precomp OBJ dependencies
17+
SUMMARY-NEXT: 5 Merged TPI records
18+
SUMMARY-NEXT: 1 Output PDB strings
19+
SUMMARY-NEXT: 0 Global symbol records
20+
SUMMARY-NEXT: 4 Module symbol records
21+
SUMMARY-NEXT: 0 Public symbol records

0 commit comments

Comments
 (0)