[lld] [LLD] [COFF] Fix crashes for cfguard with undefined weak symbols (PR #79063)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 23 05:30:23 PST 2024


mstorsjo wrote:

> Do you have an example stack trace of the codepath that triggers the error? I wonder if `maybeAddAddressTakenFunction` is supposed to prevent this from happening in the first place. If the problematic codepath bypasses this function and calls `addSymbolToRVASet` directly, then maybe it shouldn't...

Yes, the callstack doesn't pass through `maybeAddAddressTakenFunction` here, we have this call stack:
```
#10 0x0000aaaab3da976c addSymbolToRVASet(llvm::DenseSet<lld::coff::ChunkAndOffset, llvm::DenseMapInfo<lld::coff::ChunkAndOffset, void>>&, lld::coff::Defined*) /home/martin/code/llvm-project/llvm/tools/lld/COFF/Writer.cpp:1805:40
#11 0x0000aaaab3daa500 (anonymous namespace)::Writer::markSymbolsForRVATable(lld::coff::ObjFile*, llvm::ArrayRef<lld::coff::SectionChunk*>, llvm::DenseSet<lld::coff::ChunkAndOffset, llvm::DenseMapInfo<lld::coff::ChunkAndOffset, void>>&) /home/martin/code/llvm-project/llvm/tools/lld/COFF/Writer.cpp:2016:20
#12 0x0000aaaab3da9c44 (anonymous namespace)::Writer::createGuardCFTables() /home/martin/code/llvm-project/llvm/tools/lld/COFF/Writer.cpp:1903:29
```
The reason is that we're not running linker heuristics to add these, but we're compiled with cfguard enabled, and those tables says that the address of this symbol is taken. We just don't know at compile time whether the symbol will evaluate to a non-null value or not.

https://github.com/llvm/llvm-project/pull/79063


More information about the llvm-commits mailing list