| Issue |
243297
|
| Summary |
[lld][MachO] ld64.lld asserts in findSymbolAtOffset on an FDE whose PC-begin is outside every section
|
| Labels |
lld:MachO,
crash
|
| Assignees |
|
| Reporter |
AnantaSrikar
|
`ld64.lld` fails an assertion on an x86-64 object whose `__eh_frame` FDE has a PC-begin that isn't inside any section. The input is the existing JITLink negative test `MachO_ehframe_bad_fde_pc-begin_out-of-range.test`. `llvm-jitlink` rejects it with `No symbol or block covering address`, but `ld64.lld` aborts in `findSymbolAtOffset`.
**Version**: main at c7014922f582 (2026-11-16), built from the Git repository with `-DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PROJECTS=lld`, on x86_64 Linux.
### Reproducer
>From an llvm-project checkout:
```sh
yaml2obj llvm/test/ExecutionEngine/JITLink/x86-64/MachO_ehframe_bad_fde_pc-begin_out-of-range.test -o bad.o
ld64.lld -arch x86_64 -platform_version macos 13.0 13.0 -dylib -undefined dynamic_lookup -o bad.dylib bad.o
```
The FDE's 8-byte PC-begin field holds `0x1000000000000000`. With `0xFFFFFFFFFFFFFFD8` there instead (the PC-relative value for `_main` at address 0), the same object links (status 0).
### Observed
```
ld64.lld: lld/MachO/InputFiles.cpp:512: Defined *findSymbolAtOffset(const ConcatInputSection *, uint64_t): Assertion `d || isec->wasCoalesced' failed.
```
```
#10 lld::macho::ObjFile::registerEhFrames(lld::macho::Section&)
#11 void lld::macho::ObjFile::parse<lld::macho::LP64>()
#12 lld::macho::ObjFile::ObjFile(llvm::MemoryBufferRef, unsigned int, llvm::StringRef, bool, bool, bool, bool)
#16 lld::macho::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool)
```
### Expected
An error for the invalid FDE, like `llvm-jitlink`'s.
### Analysis
When the FDE has no relocation for its function address, `registerEhFrames` looks the address up with `findSymbolAtAddress`:
https://github.com/llvm/llvm-project/blob/c7014922f5829426952a38d079220c21b0a8ebe8/lld/MachO/InputFiles.cpp#L1645-L1648
`findContainingSection` and `findContainingSubsection` return the last section and subsection that start at or below the address, without checking that the address is inside them, so the bogus address lands in the last subsection:
https://github.com/llvm/llvm-project/blob/c7014922f5829426952a38d079220c21b0a8ebe8/lld/MachO/InputFiles.cpp#L460-L492
`findSymbolAtOffset` then finds no symbol there and asserts that the section was coalesced:
https://github.com/llvm/llvm-project/blob/c7014922f5829426952a38d079220c21b0a8ebe8/lld/MachO/InputFiles.cpp#L505-L513
Without assertions it returns null, and `registerEhFrames` drops the FDE as if its function had been coalesced, with no diagnostic. Checking in `registerEhFrames` that the PC-begin address falls inside a section, and reporting an error otherwise, would fix it.
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