Skip to content

Commit 50d33c6

Browse files
authored
[LLD] [COFF] Fix crashes for cfguard with undefined weak symbols (#79063)
When marking symbols as having their address taken, we can have the sitaution where we have the address taken of a weak symbol. If there's no strong definition of the symbol, the symbol ends up as an absolute symbol with the value null. In those cases, we don't have any Chunk. Skip such symbols from the cfguard tables. This fixes #78619.
1 parent bb8a877 commit 50d33c6

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lld/COFF/Writer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,8 @@ void Writer::createSEHTable() {
18021802
// symbol's offset into that Chunk.
18031803
static void addSymbolToRVASet(SymbolRVASet &rvaSet, Defined *s) {
18041804
Chunk *c = s->getChunk();
1805+
if (!c)
1806+
return;
18051807
if (auto *sc = dyn_cast<SectionChunk>(c))
18061808
c = sc->repl; // Look through ICF replacement.
18071809
uint32_t off = s->getRVA() - (c ? c->getRVA() : 0);

lld/test/COFF/cfguard-weak-undef.s

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# REQUIRES: x86
2+
# RUN: llvm-mc -triple=x86_64-windows-gnu -filetype=obj -o %t.obj %s
3+
# RUN: lld-link %t.obj /out:%t.exe /entry:entry /subsystem:console /guard:cf
4+
5+
.def @feat.00;
6+
.scl 3;
7+
.type 0;
8+
.endef
9+
.globl @feat.00
10+
.set @feat.00, 2048
11+
12+
.globl entry
13+
entry:
14+
retq
15+
16+
.data
17+
.globl funcs
18+
funcs:
19+
.quad weakfunc
20+
21+
.section .gfids$y,"dr"
22+
.symidx weakfunc
23+
.section .giats$y,"dr"
24+
.section .gljmp$y,"dr"
25+
.weak weakfunc
26+
.addrsig
27+
.addrsig_sym weakfunc

0 commit comments

Comments
 (0)