Author: Tom Stellard Date: 2020-12-09T14:12:58-05:00 New Revision: b091768e60e6807ae3806acaba1cbc9b1c96b388
URL: https://github.com/llvm/llvm-project/commit/b091768e60e6807ae3806acaba1cbc9b1c96b388 DIFF: https://github.com/llvm/llvm-project/commit/b091768e60e6807ae3806acaba1cbc9b1c96b388.diff LOG: [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 4140f0744fb2deccb74e77282e23ff731f67821b) Added: lld/test/COFF/Inputs/precomp2-a.yaml lld/test/COFF/Inputs/precomp2.yaml lld/test/COFF/precomp-summary-fail.test Modified: lld/COFF/DebugTypes.cpp Removed: ################################################################################ diff --git a/lld/COFF/DebugTypes.cpp b/lld/COFF/DebugTypes.cpp index 4790b0166799..abe3bb9eef5b 100644 --- a/lld/COFF/DebugTypes.cpp +++ b/lld/COFF/DebugTypes.cpp @@ -202,6 +202,9 @@ Expected<const CVIndexMap *> TpiSource::mergeDebugT(TypeMerger *m, BinaryStreamReader reader(file->debugTypes, support::little); cantFail(reader.readArray(types, reader.getLength())); + // When dealing with PCH.OBJ, some indices were already merged. + unsigned nbHeadIndices = indexMap->tpiMap.size(); + if (config->debugGHashes) { ArrayRef<GloballyHashedType> hashes; std::vector<GloballyHashedType> ownedHashes; @@ -232,7 +235,7 @@ Expected<const CVIndexMap *> TpiSource::mergeDebugT(TypeMerger *m, // 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 = indexMap->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 index 000000000000..a9d497ba10a3 --- /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 index 000000000000..7a4ec2f25af4 --- /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 index 000000000000..6c48ba5f0c45 --- /dev/null +++ b/lld/test/COFF/precomp-summary-fail.test @@ -0,0 +1,21 @@ + +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: 5 Merged TPI 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 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits