Index: lld/COFF/Chunks.h =================================================================== --- lld/COFF/Chunks.h +++ lld/COFF/Chunks.h @@ -177,6 +177,10 @@ // redundant when GC is enabled, as all comdat sections will start out dead. void markDiscarded() { Discarded = true; } + // True if this is a codeview debug info chunk. These will not be laid out in + // the image. Instead they will end up in the PDB, if one is requested. + bool isCodeView() const { return IsCodeViewDebug; } + // Allow iteration over the bodies of this chunk's relocated symbols. llvm::iterator_range symbols() const { return llvm::make_range(symbol_iterator(File, Relocs.begin()), @@ -213,6 +217,8 @@ // Used by the garbage collector. bool Live; + bool IsCodeViewDebug; + // Used for ICF (Identical COMDAT Folding) void replace(SectionChunk *Other); uint32_t Class[2] = {0, 0}; Index: lld/COFF/Chunks.cpp =================================================================== --- lld/COFF/Chunks.cpp +++ lld/COFF/Chunks.cpp @@ -45,6 +45,9 @@ // files will be built with -ffunction-sections or /Gy, so most things worth // stripping will be in a comdat. Live = !Config->DoGC || !isCOMDAT(); + + IsCodeViewDebug = + SectionName == ".debug" || SectionName.startswith(".debug$"); } static void add16(uint8_t *P, int16_t V) { write16le(P, read16le(P) + V); } Index: lld/COFF/InputFiles.cpp =================================================================== --- lld/COFF/InputFiles.cpp +++ lld/COFF/InputFiles.cpp @@ -132,17 +132,17 @@ if (!Config->Debug && Name.startswith(".debug")) continue; - // CodeView sections are stored to a different vector because they are - // not linked in the regular manner. - if (Name == ".debug" || Name.startswith(".debug$")) { - DebugChunks.push_back(make(this, Sec)); - continue; - } - if (Sec->Characteristics & llvm::COFF::IMAGE_SCN_LNK_REMOVE) continue; auto *C = make(this, Sec); - Chunks.push_back(C); + + // CodeView sections are stored to a different vector because they are not + // linked in the regular manner. + if (C->isCodeView()) + DebugChunks.push_back(C); + else + Chunks.push_back(C); + SparseChunks[I] = C; } } Index: lld/COFF/PDB.cpp =================================================================== --- lld/COFF/PDB.cpp +++ lld/COFF/PDB.cpp @@ -164,10 +164,7 @@ // Now do all line info. for (SectionChunk *DebugChunk : File->getDebugChunks()) { - // FIXME: Debug chunks do not have a correct isLive() bit. - // FIXME: When linker GC is off we need to ignore debug info whose - // associated symbol was discarded. - if (DebugChunk->getSectionName() != ".debug$S") + if (!DebugChunk->isLive() || DebugChunk->getSectionName() != ".debug$S") continue; ArrayRef RelocatedDebugContents = Index: lld/COFF/Writer.cpp =================================================================== --- lld/COFF/Writer.cpp +++ lld/COFF/Writer.cpp @@ -445,9 +445,12 @@ if (isa(Def)) return None; - if (auto *D = dyn_cast(Def)) - if (!D->getChunk()->isLive()) + if (auto *D = dyn_cast(Def)) { + // Don't write dead symbols or symbols in codeview sections to the symbol + // table. + if (!D->getChunk()->isLive() || D->getChunk()->isCodeView()) return None; + } if (auto *Sym = dyn_cast(Def)) if (!Sym->File->Live) Index: lld/test/COFF/Inputs/pdb_comdat_bar.yaml =================================================================== --- /dev/null +++ lld/test/COFF/Inputs/pdb_comdat_bar.yaml @@ -0,0 +1,455 @@ +--- !COFF +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [ ] +sections: + - Name: .drectve + Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ] + Alignment: 1 + SectionData: 2020202F44454641554C544C49423A224C4942434D5422202F44454641554C544C49423A224F4C444E414D45532220 + - Name: '.debug$S' + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] + Alignment: 1 + SectionData: 04000000F1000000710000003300011100000000433A5C7372635C6C6C766D2D70726F6A6563745C6275696C645C7064625F636F6D6461745F6261722E6F626A003A003C1100600000D00013000000975E010013000000975E01004D6963726F736F667420285229204F7074696D697A696E6720436F6D70696C657200000000F10000004D000000290047110000000000000000000000000E00000004000000090000000610000000000000000000626172001C001210280000000000000000000000000000000000000000000042110002004F11000000F20000003000000000000000000000000E000000000000000300000024000000000000000300008004000000040000800900000005000080F10000001500000013000D1174000000000000000000676C6F62616C00000000F400000030000000010000001001365279DB4FCBEDD721BBFC3B14A953C200002C0000001001D74D834EFAC3AE2B45E606A8320B1D5C0000F30000004C00000000633A5C7372635C6C6C766D2D70726F6A6563745C6275696C645C7064625F636F6D6461745F6261722E6300633A5C7372635C6C6C766D2D70726F6A6563745C6275696C645C666F6F2E6800F10000000800000006004C110E100000 + Subsections: + - !Symbols + Records: + - Kind: S_OBJNAME + ObjNameSym: + Signature: 0 + ObjectName: 'C:\src\llvm-project\build\pdb_comdat_bar.obj' + - Kind: S_COMPILE3 + Compile3Sym: + Flags: [ SecurityChecks, HotPatch ] + Machine: X64 + FrontendMajor: 19 + FrontendMinor: 0 + FrontendBuild: 24215 + FrontendQFE: 1 + BackendMajor: 19 + BackendMinor: 0 + BackendBuild: 24215 + BackendQFE: 1 + Version: 'Microsoft (R) Optimizing Compiler' + - !Symbols + Records: + - Kind: S_GPROC32_ID + ProcSym: + PtrParent: 0 + PtrEnd: 0 + PtrNext: 0 + CodeSize: 14 + DbgStart: 4 + DbgEnd: 9 + FunctionType: 4102 + Segment: 0 + Flags: [ ] + DisplayName: bar + - Kind: S_FRAMEPROC + FrameProcSym: + TotalFrameBytes: 40 + PaddingFrameBytes: 0 + OffsetToPadding: 0 + BytesOfCalleeSavedRegisters: 0 + OffsetOfExceptionHandler: 0 + SectionIdOfExceptionHandler: 0 + Flags: [ AsynchronousExceptionHandling, OptimizedForSpeed ] + - Kind: S_PROC_ID_END + ScopeEndSym: + - !Lines + CodeSize: 14 + Flags: [ ] + RelocOffset: 0 + RelocSegment: 0 + Blocks: + - FileName: 'c:\src\llvm-project\build\pdb_comdat_bar.c' + Lines: + - Offset: 0 + LineStart: 3 + IsStatement: true + EndDelta: 0 + - Offset: 4 + LineStart: 4 + IsStatement: true + EndDelta: 0 + - Offset: 9 + LineStart: 5 + IsStatement: true + EndDelta: 0 + Columns: + - !Symbols + Records: + - Kind: S_GDATA32 + DataSym: + Type: 116 + DisplayName: global + - !FileChecksums + Checksums: + - FileName: 'c:\src\llvm-project\build\pdb_comdat_bar.c' + Kind: MD5 + Checksum: 365279DB4FCBEDD721BBFC3B14A953C2 + - FileName: 'c:\src\llvm-project\build\foo.h' + Kind: MD5 + Checksum: D74D834EFAC3AE2B45E606A8320B1D5C + - !StringTable + Strings: + - 'c:\src\llvm-project\build\pdb_comdat_bar.c' + - 'c:\src\llvm-project\build\foo.h' + - !Symbols + Records: + - Kind: S_BUILDINFO + BuildInfoSym: + BuildId: 4110 + Relocations: + - VirtualAddress: 168 + SymbolName: bar + Type: IMAGE_REL_AMD64_SECREL + - VirtualAddress: 172 + SymbolName: bar + Type: IMAGE_REL_AMD64_SECTION + - VirtualAddress: 224 + SymbolName: bar + Type: IMAGE_REL_AMD64_SECREL + - VirtualAddress: 228 + SymbolName: bar + Type: IMAGE_REL_AMD64_SECTION + - VirtualAddress: 288 + SymbolName: global + Type: IMAGE_REL_AMD64_SECREL + - VirtualAddress: 292 + SymbolName: global + Type: IMAGE_REL_AMD64_SECTION + - Name: '.debug$T' + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] + Alignment: 1 + SectionData: 040000000A00011201000000000000000E0008100300000000000000001000000A000210011000000C0001000E0001160000000001100000666F6F0006000112000000000E0008100300000000000000041000000E0001160000000005100000626172002200051600000000433A5C7372635C6C6C766D2D70726F6A6563745C6275696C6400F2F13200051600000000433A5C50524F4752417E325C4D4943524F537E312E305C56435C42696E5C616D6436345C636C2E65786500F1FE000516000000002D63202D5A37202D4D54202D49433A5C50524F4752417E325C4D4943524F537E312E305C56435C696E636C756465202D49433A5C50524F4752417E325C4D4943524F537E312E305C56435C61746C6D66635C696E636C756465202D49433A5C50524F4752417E325C5749334346327E315C31305C696E636C7564655C31302E302E31343339332E305C75637274202D49433A5C50524F4752417E325C5749334346327E315C31305C696E636C7564655C31302E302E31343339332E305C736861726564202D49433A5C50524F4752417E325C5749334346327E315C31305C696E636C7564655C31302E302E31343339332E305C756D00F2F10A0004160100000009100000460005160A100000202D49433A5C50524F4752417E325C5749334346327E315C31305C696E636C7564655C31302E302E31343339332E305C77696E7274202D5443202D5800F3F2F11A000516000000007064625F636F6D6461745F6261722E6300F3F2F12A00051600000000433A5C7372635C6C6C766D2D70726F6A6563745C6275696C645C76633134302E706462001A000316050007100000081000000C1000000D1000000B100000F2F1 + Types: + - Kind: LF_ARGLIST + ArgList: + ArgIndices: [ 0 ] + - Kind: LF_PROCEDURE + Procedure: + ReturnType: 3 + CallConv: NearC + Options: [ None ] + ParameterCount: 0 + ArgumentList: 4096 + - Kind: LF_POINTER + Pointer: + ReferentType: 4097 + Attrs: 65548 + - Kind: LF_FUNC_ID + FuncId: + ParentScope: 0 + FunctionType: 4097 + Name: foo + - Kind: LF_ARGLIST + ArgList: + ArgIndices: [ ] + - Kind: LF_PROCEDURE + Procedure: + ReturnType: 3 + CallConv: NearC + Options: [ None ] + ParameterCount: 0 + ArgumentList: 4100 + - Kind: LF_FUNC_ID + FuncId: + ParentScope: 0 + FunctionType: 4101 + Name: bar + - Kind: LF_STRING_ID + StringId: + Id: 0 + String: 'C:\src\llvm-project\build' + - Kind: LF_STRING_ID + StringId: + Id: 0 + String: 'C:\PROGRA~2\MICROS~1.0\VC\Bin\amd64\cl.exe' + - Kind: LF_STRING_ID + StringId: + Id: 0 + String: '-c -Z7 -MT -IC:\PROGRA~2\MICROS~1.0\VC\include -IC:\PROGRA~2\MICROS~1.0\VC\atlmfc\include -IC:\PROGRA~2\WI3CF2~1\10\include\10.0.14393.0\ucrt -IC:\PROGRA~2\WI3CF2~1\10\include\10.0.14393.0\shared -IC:\PROGRA~2\WI3CF2~1\10\include\10.0.14393.0\um' + - Kind: LF_SUBSTR_LIST + StringList: + StringIndices: [ 4105 ] + - Kind: LF_STRING_ID + StringId: + Id: 4106 + String: ' -IC:\PROGRA~2\WI3CF2~1\10\include\10.0.14393.0\winrt -TC -X' + - Kind: LF_STRING_ID + StringId: + Id: 0 + String: pdb_comdat_bar.c + - Kind: LF_STRING_ID + StringId: + Id: 0 + String: 'C:\src\llvm-project\build\vc140.pdb' + - Kind: LF_BUILDINFO + BuildInfo: + ArgIndices: [ 4103, 4104, 4108, 4109, 4107 ] + - Name: .bss + Characteristics: [ IMAGE_SCN_CNT_UNINITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: '' + - Name: '.text$mn' + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: 4883EC28E8000000004883C428C3 + Relocations: + - VirtualAddress: 5 + SymbolName: foo + Type: IMAGE_REL_AMD64_REL32 + - Name: '.text$mn' + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: 8B0500000000FFC0890500000000C3 + Relocations: + - VirtualAddress: 2 + SymbolName: global + Type: IMAGE_REL_AMD64_REL32 + - VirtualAddress: 10 + SymbolName: global + Type: IMAGE_REL_AMD64_REL32 + - Name: '.debug$S' + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] + Alignment: 1 + SectionData: 04000000F10000004D000000290047110000000000000000000000000F000000000000000E0000000310000000000000000000666F6F001C001210000000000000000000000000000000000000000000002042110002004F11000000F20000003000000000000000000000000F000000180000000300000024000000000000000200008000000000030000800E00000004000080 + Subsections: + - !Symbols + Records: + - Kind: S_GPROC32_ID + ProcSym: + PtrParent: 0 + PtrEnd: 0 + PtrNext: 0 + CodeSize: 15 + DbgStart: 0 + DbgEnd: 14 + FunctionType: 4099 + Segment: 0 + Flags: [ ] + DisplayName: foo + - Kind: S_FRAMEPROC + FrameProcSym: + TotalFrameBytes: 0 + PaddingFrameBytes: 0 + OffsetToPadding: 0 + BytesOfCalleeSavedRegisters: 0 + OffsetOfExceptionHandler: 0 + SectionIdOfExceptionHandler: 0 + Flags: [ MarkedInline, AsynchronousExceptionHandling, OptimizedForSpeed ] + - Kind: S_PROC_ID_END + ScopeEndSym: + - !Lines + CodeSize: 15 + Flags: [ ] + RelocOffset: 0 + RelocSegment: 0 + Blocks: + - FileName: 'c:\src\llvm-project\build\foo.h' + Lines: + - Offset: 0 + LineStart: 2 + IsStatement: true + EndDelta: 0 + - Offset: 0 + LineStart: 3 + IsStatement: true + EndDelta: 0 + - Offset: 14 + LineStart: 4 + IsStatement: true + EndDelta: 0 + Columns: + Relocations: + - VirtualAddress: 44 + SymbolName: foo + Type: IMAGE_REL_AMD64_SECREL + - VirtualAddress: 48 + SymbolName: foo + Type: IMAGE_REL_AMD64_SECTION + - VirtualAddress: 100 + SymbolName: foo + Type: IMAGE_REL_AMD64_SECREL + - VirtualAddress: 104 + SymbolName: foo + Type: IMAGE_REL_AMD64_SECTION + - Name: .xdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: '0104010004420000' + - Name: .pdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: '000000000E00000000000000' + Relocations: + - VirtualAddress: 0 + SymbolName: '$LN3' + Type: IMAGE_REL_AMD64_ADDR32NB + - VirtualAddress: 4 + SymbolName: '$LN3' + Type: IMAGE_REL_AMD64_ADDR32NB + - VirtualAddress: 8 + SymbolName: '$unwind$bar' + Type: IMAGE_REL_AMD64_ADDR32NB +symbols: + - Name: '@comp.id' + Value: 17063575 + SectionNumber: -1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: '@feat.00' + Value: 2147484048 + SectionNumber: -1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .drectve + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 47 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: '.debug$S' + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 460 + NumberOfRelocations: 6 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: '.debug$T' + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 628 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: .bss + Value: 0 + SectionNumber: 4 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 4 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: global + Value: 0 + SectionNumber: 4 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: '.text$mn' + Value: 0 + SectionNumber: 5 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 14 + NumberOfRelocations: 1 + NumberOfLinenumbers: 0 + CheckSum: 1682752513 + Number: 0 + - Name: '.text$mn' + Value: 0 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 15 + NumberOfRelocations: 2 + NumberOfLinenumbers: 0 + CheckSum: 1746394828 + Number: 0 + Selection: IMAGE_COMDAT_SELECT_ANY + - Name: '.debug$S' + Value: 0 + SectionNumber: 7 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 148 + NumberOfRelocations: 4 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 6 + Selection: IMAGE_COMDAT_SELECT_ASSOCIATIVE + - Name: foo + Value: 0 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: bar + Value: 0 + SectionNumber: 5 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: '$LN3' + Value: 0 + SectionNumber: 5 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_LABEL + - Name: .xdata + Value: 0 + SectionNumber: 8 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 8 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 264583633 + Number: 0 + - Name: '$unwind$bar' + Value: 0 + SectionNumber: 8 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .pdata + Value: 0 + SectionNumber: 9 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 12 + NumberOfRelocations: 3 + NumberOfLinenumbers: 0 + CheckSum: 361370162 + Number: 0 + - Name: '$pdata$bar' + Value: 0 + SectionNumber: 9 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC +... Index: lld/test/COFF/Inputs/pdb_comdat_main.yaml =================================================================== --- /dev/null +++ lld/test/COFF/Inputs/pdb_comdat_main.yaml @@ -0,0 +1,461 @@ +--- !COFF +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [ ] +sections: + - Name: .drectve + Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ] + Alignment: 1 + SectionData: 2020202F44454641554C544C49423A224C4942434D5422202F44454641554C544C49423A224F4C444E414D45532220 + - Name: '.debug$S' + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] + Alignment: 1 + SectionData: 04000000F1000000720000003400011100000000433A5C7372635C6C6C766D2D70726F6A6563745C6275696C645C7064625F636F6D6461745F6D61696E2E6F626A003A003C1100600000D00013000000975E010013000000975E01004D6963726F736F667420285229204F7074696D697A696E6720436F6D70696C6572000000F10000004E0000002A00471100000000000000000000000018000000040000001300000006100000000000000000006D61696E001C001210280000000000000000000000000000000000000000000042110002004F110000F2000000400000000000000000000000180000000000000005000000340000000000000002000080040000000300008009000000040000800E000000050000801300000006000080F10000001500000013000D1174000000000000000000676C6F62616C00000000F400000030000000010000001001F969E51BBE373436D81492EB61387F3600002D0000001001D74D834EFAC3AE2B45E606A8320B1D5C0000F30000004D00000000633A5C7372635C6C6C766D2D70726F6A6563745C6275696C645C7064625F636F6D6461745F6D61696E2E6300633A5C7372635C6C6C766D2D70726F6A6563745C6275696C645C666F6F2E6800000000F10000000800000006004C110F100000 + Subsections: + - !Symbols + Records: + - Kind: S_OBJNAME + ObjNameSym: + Signature: 0 + ObjectName: 'C:\src\llvm-project\build\pdb_comdat_main.obj' + - Kind: S_COMPILE3 + Compile3Sym: + Flags: [ SecurityChecks, HotPatch ] + Machine: X64 + FrontendMajor: 19 + FrontendMinor: 0 + FrontendBuild: 24215 + FrontendQFE: 1 + BackendMajor: 19 + BackendMinor: 0 + BackendBuild: 24215 + BackendQFE: 1 + Version: 'Microsoft (R) Optimizing Compiler' + - !Symbols + Records: + - Kind: S_GPROC32_ID + ProcSym: + PtrParent: 0 + PtrEnd: 0 + PtrNext: 0 + CodeSize: 24 + DbgStart: 4 + DbgEnd: 19 + FunctionType: 4102 + Segment: 0 + Flags: [ ] + DisplayName: main + - Kind: S_FRAMEPROC + FrameProcSym: + TotalFrameBytes: 40 + PaddingFrameBytes: 0 + OffsetToPadding: 0 + BytesOfCalleeSavedRegisters: 0 + OffsetOfExceptionHandler: 0 + SectionIdOfExceptionHandler: 0 + Flags: [ AsynchronousExceptionHandling, OptimizedForSpeed ] + - Kind: S_PROC_ID_END + ScopeEndSym: + - !Lines + CodeSize: 24 + Flags: [ ] + RelocOffset: 0 + RelocSegment: 0 + Blocks: + - FileName: 'c:\src\llvm-project\build\pdb_comdat_main.c' + Lines: + - Offset: 0 + LineStart: 2 + IsStatement: true + EndDelta: 0 + - Offset: 4 + LineStart: 3 + IsStatement: true + EndDelta: 0 + - Offset: 9 + LineStart: 4 + IsStatement: true + EndDelta: 0 + - Offset: 14 + LineStart: 5 + IsStatement: true + EndDelta: 0 + - Offset: 19 + LineStart: 6 + IsStatement: true + EndDelta: 0 + Columns: + - !Symbols + Records: + - Kind: S_GDATA32 + DataSym: + Type: 116 + DisplayName: global + - !FileChecksums + Checksums: + - FileName: 'c:\src\llvm-project\build\pdb_comdat_main.c' + Kind: MD5 + Checksum: F969E51BBE373436D81492EB61387F36 + - FileName: 'c:\src\llvm-project\build\foo.h' + Kind: MD5 + Checksum: D74D834EFAC3AE2B45E606A8320B1D5C + - !StringTable + Strings: + - 'c:\src\llvm-project\build\pdb_comdat_main.c' + - 'c:\src\llvm-project\build\foo.h' + - !Symbols + Records: + - Kind: S_BUILDINFO + BuildInfoSym: + BuildId: 4111 + Relocations: + - VirtualAddress: 168 + SymbolName: main + Type: IMAGE_REL_AMD64_SECREL + - VirtualAddress: 172 + SymbolName: main + Type: IMAGE_REL_AMD64_SECTION + - VirtualAddress: 224 + SymbolName: main + Type: IMAGE_REL_AMD64_SECREL + - VirtualAddress: 228 + SymbolName: main + Type: IMAGE_REL_AMD64_SECTION + - VirtualAddress: 304 + SymbolName: global + Type: IMAGE_REL_AMD64_SECREL + - VirtualAddress: 308 + SymbolName: global + Type: IMAGE_REL_AMD64_SECTION + - Name: '.debug$T' + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] + Alignment: 1 + SectionData: 040000000A00011201000000000000000E0008100300000000000000001000000A000210011000000C0001000E0001160000000001100000666F6F0006000112000000000E0008107400000000000000041000001200011600000000051000006D61696E00F3F2F10E0001160000000001100000626172002200051600000000433A5C7372635C6C6C766D2D70726F6A6563745C6275696C6400F2F13200051600000000433A5C50524F4752417E325C4D4943524F537E312E305C56435C42696E5C616D6436345C636C2E65786500F1FE000516000000002D63202D5A37202D4D54202D49433A5C50524F4752417E325C4D4943524F537E312E305C56435C696E636C756465202D49433A5C50524F4752417E325C4D4943524F537E312E305C56435C61746C6D66635C696E636C756465202D49433A5C50524F4752417E325C5749334346327E315C31305C696E636C7564655C31302E302E31343339332E305C75637274202D49433A5C50524F4752417E325C5749334346327E315C31305C696E636C7564655C31302E302E31343339332E305C736861726564202D49433A5C50524F4752417E325C5749334346327E315C31305C696E636C7564655C31302E302E31343339332E305C756D00F2F10A000416010000000A100000460005160B100000202D49433A5C50524F4752417E325C5749334346327E315C31305C696E636C7564655C31302E302E31343339332E305C77696E7274202D5443202D5800F3F2F11A000516000000007064625F636F6D6461745F6D61696E2E6300F2F12A00051600000000433A5C7372635C6C6C766D2D70726F6A6563745C6275696C645C76633134302E706462001A000316050008100000091000000D1000000E1000000C100000F2F1 + Types: + - Kind: LF_ARGLIST + ArgList: + ArgIndices: [ 0 ] + - Kind: LF_PROCEDURE + Procedure: + ReturnType: 3 + CallConv: NearC + Options: [ None ] + ParameterCount: 0 + ArgumentList: 4096 + - Kind: LF_POINTER + Pointer: + ReferentType: 4097 + Attrs: 65548 + - Kind: LF_FUNC_ID + FuncId: + ParentScope: 0 + FunctionType: 4097 + Name: foo + - Kind: LF_ARGLIST + ArgList: + ArgIndices: [ ] + - Kind: LF_PROCEDURE + Procedure: + ReturnType: 116 + CallConv: NearC + Options: [ None ] + ParameterCount: 0 + ArgumentList: 4100 + - Kind: LF_FUNC_ID + FuncId: + ParentScope: 0 + FunctionType: 4101 + Name: main + - Kind: LF_FUNC_ID + FuncId: + ParentScope: 0 + FunctionType: 4097 + Name: bar + - Kind: LF_STRING_ID + StringId: + Id: 0 + String: 'C:\src\llvm-project\build' + - Kind: LF_STRING_ID + StringId: + Id: 0 + String: 'C:\PROGRA~2\MICROS~1.0\VC\Bin\amd64\cl.exe' + - Kind: LF_STRING_ID + StringId: + Id: 0 + String: '-c -Z7 -MT -IC:\PROGRA~2\MICROS~1.0\VC\include -IC:\PROGRA~2\MICROS~1.0\VC\atlmfc\include -IC:\PROGRA~2\WI3CF2~1\10\include\10.0.14393.0\ucrt -IC:\PROGRA~2\WI3CF2~1\10\include\10.0.14393.0\shared -IC:\PROGRA~2\WI3CF2~1\10\include\10.0.14393.0\um' + - Kind: LF_SUBSTR_LIST + StringList: + StringIndices: [ 4106 ] + - Kind: LF_STRING_ID + StringId: + Id: 4107 + String: ' -IC:\PROGRA~2\WI3CF2~1\10\include\10.0.14393.0\winrt -TC -X' + - Kind: LF_STRING_ID + StringId: + Id: 0 + String: pdb_comdat_main.c + - Kind: LF_STRING_ID + StringId: + Id: 0 + String: 'C:\src\llvm-project\build\vc140.pdb' + - Kind: LF_BUILDINFO + BuildInfo: + ArgIndices: [ 4104, 4105, 4109, 4110, 4108 ] + - Name: '.text$mn' + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: 4883EC28E800000000E800000000B82A0000004883C428C3 + Relocations: + - VirtualAddress: 5 + SymbolName: foo + Type: IMAGE_REL_AMD64_REL32 + - VirtualAddress: 10 + SymbolName: bar + Type: IMAGE_REL_AMD64_REL32 + - Name: '.text$mn' + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: 8B0500000000FFC0890500000000C3 + Relocations: + - VirtualAddress: 2 + SymbolName: global + Type: IMAGE_REL_AMD64_REL32 + - VirtualAddress: 10 + SymbolName: global + Type: IMAGE_REL_AMD64_REL32 + - Name: '.debug$S' + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] + Alignment: 1 + SectionData: 04000000F10000004D000000290047110000000000000000000000000F000000000000000E0000000310000000000000000000666F6F001C001210000000000000000000000000000000000000000000002042110002004F11000000F20000003000000000000000000000000F000000180000000300000024000000000000000200008000000000030000800E00000004000080 + Subsections: + - !Symbols + Records: + - Kind: S_GPROC32_ID + ProcSym: + PtrParent: 0 + PtrEnd: 0 + PtrNext: 0 + CodeSize: 15 + DbgStart: 0 + DbgEnd: 14 + FunctionType: 4099 + Segment: 0 + Flags: [ ] + DisplayName: foo + - Kind: S_FRAMEPROC + FrameProcSym: + TotalFrameBytes: 0 + PaddingFrameBytes: 0 + OffsetToPadding: 0 + BytesOfCalleeSavedRegisters: 0 + OffsetOfExceptionHandler: 0 + SectionIdOfExceptionHandler: 0 + Flags: [ MarkedInline, AsynchronousExceptionHandling, OptimizedForSpeed ] + - Kind: S_PROC_ID_END + ScopeEndSym: + - !Lines + CodeSize: 15 + Flags: [ ] + RelocOffset: 0 + RelocSegment: 0 + Blocks: + - FileName: 'c:\src\llvm-project\build\foo.h' + Lines: + - Offset: 0 + LineStart: 2 + IsStatement: true + EndDelta: 0 + - Offset: 0 + LineStart: 3 + IsStatement: true + EndDelta: 0 + - Offset: 14 + LineStart: 4 + IsStatement: true + EndDelta: 0 + Columns: + Relocations: + - VirtualAddress: 44 + SymbolName: foo + Type: IMAGE_REL_AMD64_SECREL + - VirtualAddress: 48 + SymbolName: foo + Type: IMAGE_REL_AMD64_SECTION + - VirtualAddress: 100 + SymbolName: foo + Type: IMAGE_REL_AMD64_SECREL + - VirtualAddress: 104 + SymbolName: foo + Type: IMAGE_REL_AMD64_SECTION + - Name: .xdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: '0104010004420000' + - Name: .pdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: '000000001800000000000000' + Relocations: + - VirtualAddress: 0 + SymbolName: '$LN3' + Type: IMAGE_REL_AMD64_ADDR32NB + - VirtualAddress: 4 + SymbolName: '$LN3' + Type: IMAGE_REL_AMD64_ADDR32NB + - VirtualAddress: 8 + SymbolName: '$unwind$main' + Type: IMAGE_REL_AMD64_ADDR32NB +symbols: + - Name: '@comp.id' + Value: 17063575 + SectionNumber: -1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: '@feat.00' + Value: 2147484048 + SectionNumber: -1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .drectve + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 47 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: '.debug$S' + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 480 + NumberOfRelocations: 6 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: '.debug$T' + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 648 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: '.text$mn' + Value: 0 + SectionNumber: 4 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 24 + NumberOfRelocations: 2 + NumberOfLinenumbers: 0 + CheckSum: 492663294 + Number: 0 + - Name: '.text$mn' + Value: 0 + SectionNumber: 5 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 15 + NumberOfRelocations: 2 + NumberOfLinenumbers: 0 + CheckSum: 1746394828 + Number: 0 + Selection: IMAGE_COMDAT_SELECT_ANY + - Name: '.debug$S' + Value: 0 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 148 + NumberOfRelocations: 4 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 5 + Selection: IMAGE_COMDAT_SELECT_ASSOCIATIVE + - Name: foo + Value: 0 + SectionNumber: 5 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: bar + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: main + Value: 0 + SectionNumber: 4 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: '$LN3' + Value: 0 + SectionNumber: 4 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_LABEL + - Name: .xdata + Value: 0 + SectionNumber: 7 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 8 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 264583633 + Number: 0 + - Name: '$unwind$main' + Value: 0 + SectionNumber: 7 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .pdata + Value: 0 + SectionNumber: 8 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 12 + NumberOfRelocations: 3 + NumberOfLinenumbers: 0 + CheckSum: 2942184094 + Number: 0 + - Name: '$pdata$main' + Value: 0 + SectionNumber: 8 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: global + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... Index: lld/test/COFF/pdb-comdat.test =================================================================== --- /dev/null +++ lld/test/COFF/pdb-comdat.test @@ -0,0 +1,52 @@ +Consider this example program with an inline function "foo": + +==> foo.h <== +extern int global; +__inline void foo() { + ++global; +} +void bar(); +==> pdb_comdat_main.c <== +#include "foo.h" +int main(void) { + foo(); + bar(); + return 42; +} +==> pdb_comdat_bar.c <== +#include "foo.h" +void bar(void) { + foo(); +} + +Both object files will contain debug info for foo, but only the debug info from +pdb_comdat_main.obj should be included in the PDB. + +RUN: rm -rf %t && mkdir -p %t && cd %t +RUN: yaml2obj %S/Inputs/pdb_comdat_main.yaml -o pdb_comdat_main.obj +RUN: yaml2obj %S/Inputs/pdb_comdat_bar.yaml -o pdb_comdat_bar.obj +RUN: lld-link pdb_comdat_main.obj pdb_comdat_bar.obj -out:t.exe -debug -pdb:t.pdb -nodefaultlib -entry:main +RUN: llvm-pdbutil raw -l t.pdb | FileCheck %s + +CHECK: Lines +CHECK: ============================================================ +CHECK-LABEL: Mod 0000 | `{{.*}}pdb_comdat_main.obj`: +CHECK: c:\src\llvm-project\build\pdb_comdat_main.c (MD5: F969E51BBE373436D81492EB61387F36) +CHECK: c:\src\llvm-project\build\foo.h (MD5: D74D834EFAC3AE2B45E606A8320B1D5C) +CHECK-LABEL: Mod 0001 | `{{.*}}pdb_comdat_bar.obj`: +CHECK: c:\src\llvm-project\build\pdb_comdat_bar.c (MD5: 365279DB4FCBEDD721BBFC3B14A953C2) +CHECK-NOT: c:\src\llvm-project\build\foo.h +CHECK-LABEL: Mod 0002 | `* Linker *`: + +Reorder the object files and verify that the other table is selected. + +RUN: lld-link pdb_comdat_bar.obj pdb_comdat_main.obj -out:t.exe -debug -pdb:t.pdb -nodefaultlib -entry:main +RUN: llvm-pdbutil raw -l t.pdb | FileCheck %s --check-prefix=REORDER + +REORDER-LABEL: Mod 0000 | `{{.*}}pdb_comdat_bar.obj`: +REORDER: c:\src\llvm-project\build\pdb_comdat_bar.c (MD5: 365279DB4FCBEDD721BBFC3B14A953C2) +REORDER: c:\src\llvm-project\build\foo.h (MD5: D74D834EFAC3AE2B45E606A8320B1D5C) +REORDER-LABEL: Mod 0001 | `{{.*}}pdb_comdat_main.obj`: +REORDER: c:\src\llvm-project\build\pdb_comdat_main.c +REORDER-NOT: c:\src\llvm-project\build\foo.h +REORDER-LABEL: Mod 0002 | `* Linker *`: