| Issue |
239529
|
| Summary |
[lld][COFF] lld-link asserts on duplicate CodeView subsections while printing a diagnostic
|
| Labels |
lld:COFF,
crash
|
| Assignees |
|
| Reporter |
AnantaSrikar
|
I'm Ananta Srikar Puranam, a PhD student at Washington State University. I'm reporting this bug on behalf of my team.
When `lld-link` prints a source location for a diagnostic, such as `>>> referenced by a.c:1` on an undefined symbol, `findLineTable` walks the object's `.debug$S` subsections. It asserts that there is only one string table, only one checksum table and only one line table for the function. These counts come straight from the input. An object that repeats one of these subsections aborts an assertions build while LLD is reporting an ordinary error. Release builds print the normal diagnostic, using the first table.
**Version**: main at 46ca55573ce6 (2026-11-06), built from the Git repository with `-DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PROJECTS=lld`, on x86_64 Linux.
### Reproducer
`f` calls an undefined `g`, and `.debug$S` has a line table for `f` and two copies of the FileChecksums subsection:
```sh
cat > dupcks.yaml <<'YAML'
--- !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: E800000000C3
Relocations:
- VirtualAddress: 1
SymbolName: g
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:
- !Lines
CodeSize: 6
Flags: [ ]
RelocOffset: 0
RelocSegment: 0
Blocks:
- FileName: 'a.c'
Lines:
- Offset: 0
LineStart: 1
IsStatement: false
EndDelta: 0
Columns: []
- !FileChecksums
Checksums:
- FileName: 'a.c'
Kind: None
Checksum: ''
- !FileChecksums
Checksums:
- FileName: 'a.c'
Kind: None
Checksum: ''
- !StringTable
Strings:
- 'a.c'
Relocations:
- VirtualAddress: 12
SymbolName: f
Type: IMAGE_REL_AMD64_SECREL
symbols:
- Name: f
Value: 0
SectionNumber: 1
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_FUNCTION
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
- Name: g
Value: 0
SectionNumber: 0
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_FUNCTION
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
YAML
yaml2obj dupcks.yaml -o dupcks.obj
lld-link /dll /noentry /machine:x64 /out:dupcks.dll dupcks.obj
```
With one FileChecksums subsection, the same command reports `error: undefined symbol: g` / `>>> referenced by a.c:1` (status 1).
The other two assertions are reached the same way:
- Two StringTable subsections, both placed before the Lines subsection (with the SECREL relocation moved to offset 44), fail `Encountered multiple string table subsections!`. They have to come first, because `findLineTable` returns as soon as it has one of each table.
- A second copy of the Lines subsection with its own SECREL relocation to `f` at offset 52 fails `Encountered multiple line tables for function!`.
### Observed
```
lld-link: lld/COFF/PDB.cpp:1781: bool findLineTable(const SectionChunk *, uint32_t, DebugStringTableSubsectionRef &, DebugChecksumsSubsectionRef &, DebugLinesSubsectionRef &, uint32_t &): Assertion `!checksums.valid() && "Encountered multiple checksum subsections!"' failed.
```
```
lld::coff::getFileLineCodeView(lld::coff::SectionChunk const*, unsigned int)
lld::coff::getFileLine(lld::coff::SectionChunk const*, unsigned int)
lld::coff::SymbolTable::reportUndefinedSymbol(lld::coff::UndefinedDiag const&)
lld::coff::SymbolTable::reportProblemSymbols(...)
lld::coff::SymbolTable::resolveRemainingUndefines(...)
lld::coff::LinkerDriver::linkerMain(llvm::ArrayRef<char const*>)
```
### Expected
The undefined-symbol error with its source location, as release builds print. Duplicate subsections could be ignored (keeping the first one) or reported as a warning.
### Analysis
All three assertions are in the subsection loop of `findLineTable`:
https://github.com/llvm/llvm-project/blob/46ca55573ce669e89f3c452a745d4f471b74f20c/lld/COFF/PDB.cpp#L1771-L1814
It is reached from `getFileLineCodeView`, which every diagnostic that prints a source location uses:
https://github.com/llvm/llvm-project/blob/46ca55573ce669e89f3c452a745d4f471b74f20c/lld/COFF/PDB.cpp#L1824-L1832
The duplicates are properties of the input, not internal invariants. Replacing the asserts with "keep the first one" checks, so that release and assertions builds behave the same, would fix all three.
This report was drafted with help from an AI assistant (Claude); I reviewed it and reproduced it myself.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs