diff options
author | Alexandre Ganea <alexandre.ganea@ubisoft.com> | 2019-01-04 21:49:22 +0000 |
---|---|---|
committer | Alexandre Ganea <alexandre.ganea@ubisoft.com> | 2019-01-04 21:49:22 +0000 |
commit | ce4f81d7dc4f3dc9d1bc383ef680b754ac7b8b29 (patch) | |
tree | 47a13fda08121ab3443f55cd129ddc494abfdaa0 /lld | |
parent | 66940ed8e9e89752096109a3c02ff7713fdc1ccc (diff) |
[LLD][COFF] Fix file/line retrieval when a undefined symbol is to be printed
Differential Revision: https://reviews.llvm.org/D55951
Diffstat (limited to 'lld')
-rw-r--r-- | lld/COFF/PDB.cpp | 20 | ||||
-rw-r--r-- | lld/test/COFF/line-error.yaml | 160 |
2 files changed, 173 insertions, 7 deletions
diff --git a/lld/COFF/PDB.cpp b/lld/COFF/PDB.cpp index 3c99d1f8da8..ad4f39b31e3 100644 --- a/lld/COFF/PDB.cpp +++ b/lld/COFF/PDB.cpp @@ -1735,20 +1735,26 @@ std::pair<StringRef, uint32_t> coff::getFileLine(const SectionChunk *C, if (!findLineTable(C, Addr, CVStrTab, Checksums, Lines, OffsetInLinetable)) return {"", 0}; - uint32_t NameIndex; - uint32_t LineNumber; + Optional<uint32_t> NameIndex; + Optional<uint32_t> LineNumber; for (LineColumnEntry &Entry : Lines) { for (const LineNumberEntry &LN : Entry.LineNumbers) { + LineInfo LI(LN.Flags); if (LN.Offset > OffsetInLinetable) { + if (!NameIndex) { + NameIndex = Entry.NameIndex; + LineNumber = LI.getStartLine(); + } StringRef Filename = - ExitOnErr(getFileName(CVStrTab, Checksums, NameIndex)); - return {Filename, LineNumber}; + ExitOnErr(getFileName(CVStrTab, Checksums, *NameIndex)); + return {Filename, *LineNumber}; } - LineInfo LI(LN.Flags); NameIndex = Entry.NameIndex; LineNumber = LI.getStartLine(); } } - StringRef Filename = ExitOnErr(getFileName(CVStrTab, Checksums, NameIndex)); - return {Filename, LineNumber}; + if (!NameIndex) + return {"", 0}; + StringRef Filename = ExitOnErr(getFileName(CVStrTab, Checksums, *NameIndex)); + return {Filename, *LineNumber}; } diff --git a/lld/test/COFF/line-error.yaml b/lld/test/COFF/line-error.yaml new file mode 100644 index 00000000000..55fb723a6ab --- /dev/null +++ b/lld/test/COFF/line-error.yaml @@ -0,0 +1,160 @@ +# RUN: yaml2obj %s -o %t.obj
+# RUN: not lld-link %t.obj /subsystem:console 2>&1 | FileCheck %s
+
+# CHECK: lld-link: error: undefined symbol: function
+# CHECK-NEXT: >>> referenced by {{.*}}line-error.yaml.tmp.obj:(caller1)
+# CHECK-NEXT: >>> referenced by E:\file.cpp:1935
+# CHECK-NEXT: >>> {{.*}}line-error.yaml.tmp.obj:(caller22)
+
+--- !COFF
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: [ ]
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 16
+ SectionData: 488B0500000000488B51284881C2D80000004889C148FF2500000000
+ Relocations:
+ - VirtualAddress: 3
+ SymbolName: function
+ Type: IMAGE_REL_AMD64_REL32
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 16
+ SectionData: 488B0500000000488B51084881C2D80000004889C148FF2500000000
+ Relocations:
+ - VirtualAddress: 3
+ SymbolName: function
+ Type: IMAGE_REL_AMD64_REL32
+ - Name: '.debug$S'
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ Subsections:
+ - !FileChecksums
+ Checksums:
+ - FileName: 'E:\file.cpp'
+ Kind: MD5
+ Checksum: D72EDEF8B8E50C364A330F9CB3CD904B
+ - !StringTable
+ Strings:
+ - 'E:\file.cpp'
+ - Name: '.debug$S'
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ Subsections:
+ - !Lines
+ CodeSize: 28
+ Flags: [ ]
+ RelocOffset: 0
+ RelocSegment: 0
+ Blocks: []
+ Relocations:
+ - VirtualAddress: 12
+ SymbolName: caller1
+ Type: IMAGE_REL_AMD64_SECREL
+ - Name: '.debug$S'
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ Subsections:
+ - !Lines
+ CodeSize: 28
+ Flags: [ ]
+ RelocOffset: 0
+ RelocSegment: 0
+ Blocks:
+ - FileName: 'E:\file.cpp'
+ Lines:
+ - Offset: 11
+ LineStart: 1935
+ IsStatement: false
+ EndDelta: 0
+ Columns: []
+ Relocations:
+ - VirtualAddress: 12
+ SymbolName: caller22
+ Type: IMAGE_REL_AMD64_SECREL
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 28
+ NumberOfRelocations: 2
+ NumberOfLinenumbers: 0
+ CheckSum: 2430089736
+ Number: 1
+ Selection: IMAGE_COMDAT_SELECT_NODUPLICATES
+ - Name: caller1
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: .text
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 28
+ NumberOfRelocations: 2
+ NumberOfLinenumbers: 0
+ CheckSum: 3449717304
+ Number: 2
+ Selection: IMAGE_COMDAT_SELECT_NODUPLICATES
+ - Name: caller22
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: '.debug$S'
+ Value: 0
+ SectionNumber: 3
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 767204
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 4280093374
+ Number: 3
+ - Name: '.debug$S'
+ Value: 0
+ SectionNumber: 4
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 296
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 1957793731
+ Number: 1
+ Selection: IMAGE_COMDAT_SELECT_ASSOCIATIVE
+ - Name: '.debug$S'
+ Value: 0
+ SectionNumber: 5
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 276
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 1957793731
+ Number: 2
+ Selection: IMAGE_COMDAT_SELECT_ASSOCIATIVE
+ - Name: function
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
|