diff --git a/lld/COFF/DebugTypes.cpp b/lld/COFF/DebugTypes.cpp --- a/lld/COFF/DebugTypes.cpp +++ b/lld/COFF/DebugTypes.cpp @@ -319,6 +319,9 @@ BinaryStreamReader reader(file->debugTypes, support::little); cantFail(reader.readArray(types, reader.getLength())); + // When dealing with PCH.OBJ, some indices were already merged. + unsigned nbHeadIndices = indexMapStorage.size(); + if (auto err = mergeTypeAndIdRecords( m->idTable, m->typeTable, indexMapStorage, types, file->pchSignature)) fatal("codeview::mergeTypeAndIdRecords failed: " + @@ -335,7 +338,7 @@ // collecting statistics. m->tpiCounts.resize(m->getTypeTable().size()); m->ipiCounts.resize(m->getIDTable().size()); - uint32_t srcIdx = 0; + uint32_t srcIdx = nbHeadIndices; for (CVType &ty : types) { TypeIndex dstIdx = tpiMap[srcIdx++]; // Type merging may fail, so a complex source type may become the simple diff --git a/lld/test/COFF/Inputs/precomp2-a.yaml b/lld/test/COFF/Inputs/precomp2-a.yaml new file mode 100644 --- /dev/null +++ b/lld/test/COFF/Inputs/precomp2-a.yaml @@ -0,0 +1,84 @@ +--- !COFF +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [ ] +sections: + - Name: '.debug$S' + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] + Alignment: 1 + Subsections: + - !Symbols + Records: + - Kind: S_OBJNAME + ObjNameSym: + Signature: 545589255 + ObjectName: 'D:\llvm-project\lld\test\COFF\Inputs\precomp2-a.obj' + - Kind: S_COMPILE3 + Compile3Sym: + Flags: [ SecurityChecks, HotPatch ] + Machine: X64 + FrontendMajor: 19 + FrontendMinor: 13 + FrontendBuild: 26131 + FrontendQFE: 1 + BackendMajor: 19 + BackendMinor: 13 + BackendBuild: 26131 + BackendQFE: 1 + Version: 'Microsoft (R) Optimizing Compiler' + - !StringTable + Strings: + - 'D:\llvm-project\lld\test\COFF\precomp\precomp.pch' + - 'D:\llvm-project\lld\test\COFF\precomp\precomp.h' + - 'D:\llvm-project\lld\test\COFF\precomp\a.cpp' + - Name: '.debug$T' + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] + Alignment: 1 + Types: + - Kind: LF_PRECOMP + Precomp: + StartTypeIndex: 4096 + TypesCount: 3 + Signature: 545589255 + PrecompFilePath: 'D:\llvm-project\lld\test\COFF\Inputs\precomp2.obj' + - Kind: LF_STRING_ID + StringId: + Id: 0 + String: 'test test test test test' + - Kind: LF_STRING_ID + StringId: + Id: 0 + String: 'test test test test test' + - Kind: LF_STRING_ID + StringId: + Id: 0 + String: 'test test test test test' + - Kind: LF_BUILDINFO + BuildInfo: + ArgIndices: [ 4101, 4101, 4101, 4101, 4101 ] +symbols: + - Name: '.debug$S' + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 0 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: '.debug$T' + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 0 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 +... diff --git a/lld/test/COFF/Inputs/precomp2.yaml b/lld/test/COFF/Inputs/precomp2.yaml new file mode 100644 --- /dev/null +++ b/lld/test/COFF/Inputs/precomp2.yaml @@ -0,0 +1,82 @@ +--- !COFF +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [ ] +sections: + - Name: '.debug$S' + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] + Alignment: 1 + Subsections: + - !Symbols + Records: + - Kind: S_OBJNAME + ObjNameSym: + Signature: 545589255 + ObjectName: 'D:\llvm-project\lld\test\COFF\Inputs\precomp2.obj' + - Kind: S_COMPILE3 + Compile3Sym: + Flags: [ SecurityChecks, HotPatch ] + Machine: X64 + FrontendMajor: 19 + FrontendMinor: 13 + FrontendBuild: 26131 + FrontendQFE: 1 + BackendMajor: 19 + BackendMinor: 13 + BackendBuild: 26131 + BackendQFE: 1 + Version: 'Microsoft (R) Optimizing Compiler' + - !StringTable + Strings: + - 'D:\llvm-project\lld\test\COFF\precomp\precomp.pch' + - Name: '.debug$P' + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] + Alignment: 1 + PrecompTypes: + - Kind: LF_STRUCTURE + Class: + MemberCount: 0 + Options: [ None, ForwardReference, HasUniqueName ] + FieldList: 0 + Name: _s__CatchableType + UniqueName: '.?AU_s__CatchableType@@' + DerivationList: 0 + VTableShape: 0 + Size: 0 + - Kind: LF_MODIFIER + Modifier: + ModifiedType: 4096 + Modifiers: [ None, Const ] + - Kind: LF_POINTER + Pointer: + ReferentType: 4096 + Attrs: 65548 + - Kind: LF_ENDPRECOMP + EndPrecomp: + Signature: 545589255 +symbols: + - Name: '.debug$S' + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 0 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: '.debug$P' + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 0 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 +... diff --git a/lld/test/COFF/precomp-summary-fail.test b/lld/test/COFF/precomp-summary-fail.test new file mode 100644 --- /dev/null +++ b/lld/test/COFF/precomp-summary-fail.test @@ -0,0 +1,22 @@ + +The input files were tailored so that we end up with a resulting IPI stream +smaller than the TPI stream, which would previously trigger a crash with +/summary. + +RUN: rm -rf %t && mkdir %t +RUN: yaml2obj < %S/Inputs/precomp2.yaml -o %t\precomp2.obj +RUN: yaml2obj < %S/Inputs/precomp2-a.yaml -o %t\precomp2-a.obj +RUN: lld-link %t\precomp2-a.obj %t\precomp2.obj /nodefaultlib /noentry \ +RUN: /dll /out:%t.dll /debug /summary | FileCheck %s -check-prefix SUMMARY + +SUMMARY: Summary +SUMMARY-NEXT: -------------------------------------------------------------------------------- +SUMMARY-NEXT: 2 Input OBJ files (expanded from all cmd-line inputs) +SUMMARY-NEXT: 0 PDB type server dependencies +SUMMARY-NEXT: 1 Precomp OBJ dependencies +SUMMARY-NEXT: 3 Merged TPI records +SUMMARY-NEXT: 2 Merged IPI records +SUMMARY-NEXT: 1 Output PDB strings +SUMMARY-NEXT: 0 Global symbol records +SUMMARY-NEXT: 4 Module symbol records +SUMMARY-NEXT: 0 Public symbol records