| Issue |
239537
|
| Summary |
[lld][COFF] lld-link leaves an invalid section name Expected unchecked for an empty section declaration
|
| 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.
An empty section declaration is an `IMAGE_SYM_CLASS_SECTION` symbol with section number 0, as used in import library objects. For such a symbol, `ObjFile::createDefined` synthesizes a `coff_section` and copies the symbol's 8-byte name into it. If that name starts with `/`, `COFFObjectFile::getSectionName` treats it as a string-table reference and returns `invalid section name`. The `SectionChunk` constructor only handles the success case, so the `Expected` is destroyed unchecked. With `LLVM_ENABLE_ABI_BREAKING_CHECKS` (the default with assertions), `lld-link` aborts. Without it, the error is dropped and the section gets an empty name.
**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
```sh
cat > secdecl.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: C3
symbols:
- Name: f
Value: 0
SectionNumber: 1
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_FUNCTION
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
- Name: '/idata$4'
Value: 0
SectionNumber: 0
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_SECTION
YAML
yaml2obj secdecl.yaml -o secdecl.obj
lld-link /dll /noentry /machine:x64 /out:secdecl.dll secdecl.obj
```
The second symbol is exactly 8 bytes, so it is stored inline and copied unchanged into the synthesized header. With the name `.idata$4`, the same command links (status 0).
### Observed
```
Expected<T> must be checked before access or destruction.
Unchecked Expected<T> contained error:
invalid section name
```
```
llvm::Expected<llvm::StringRef>::fatalUncheckedExpected() const
lld::coff::SectionChunk::SectionChunk(lld::coff::ObjFile*, llvm::object::coff_section const*, lld::coff::Chunk::Kind)
lld::coff::ObjFile::createDefined(llvm::object::COFFSymbolRef, ...)
lld::coff::ObjFile::initializeSymbols()
lld::coff::ObjFile::parse()
```
### Expected
`error: secdecl.obj: invalid section name` (or similar), instead of an abort or a silently empty section name.
### Analysis
`createDefined` builds the header from the symbol name:
https://github.com/llvm/llvm-project/blob/46ca55573ce669e89f3c452a745d4f471b74f20c/lld/COFF/InputFiles.cpp#L868-L887
A leading `/` makes `getSectionName` parse the rest as a string-table offset, which fails here:
https://github.com/llvm/llvm-project/blob/46ca55573ce669e89f3c452a745d4f471b74f20c/llvm/lib/Object/COFFObjectFile.cpp#L1261-L1275
The `SectionChunk` constructor has no `else` for the error:
https://github.com/llvm/llvm-project/blob/46ca55573ce669e89f3c452a745d4f471b74f20c/lld/COFF/Chunks.cpp#L41-L46
Sections read from the section table don't reach this, because `readSection` already reports a `getSectionName` failure as a fatal error before it creates the chunk:
https://github.com/llvm/llvm-project/blob/46ca55573ce669e89f3c452a745d4f471b74f20c/lld/COFF/InputFiles.cpp#L395-L400
Only the synthesized header (added in #122806) skips that check. One fix is to report the error, or consume it, in the constructor. Another is to have `createDefined` reject an empty section declaration whose name starts with `/` (or to use the symbol name directly instead of round-tripping it through `getSectionName`).
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