Skip to content

[LLD] [COFF] Fix crashes for cfguard with undefined weak symbols #79063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lld/COFF/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,8 @@ void Writer::createSEHTable() {
// symbol's offset into that Chunk.
static void addSymbolToRVASet(SymbolRVASet &rvaSet, Defined *s) {
Chunk *c = s->getChunk();
if (!c)
return;
if (auto *sc = dyn_cast<SectionChunk>(c))
c = sc->repl; // Look through ICF replacement.
uint32_t off = s->getRVA() - (c ? c->getRVA() : 0);
Expand Down
27 changes: 27 additions & 0 deletions lld/test/COFF/cfguard-weak-undef.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# REQUIRES: x86
# RUN: llvm-mc -triple=x86_64-windows-gnu -filetype=obj -o %t.obj %s
# RUN: lld-link %t.obj /out:%t.exe /entry:entry /subsystem:console /guard:cf

.def @feat.00;
.scl 3;
.type 0;
.endef
.globl @feat.00
.set @feat.00, 2048

.globl entry
entry:
retq

.data
.globl funcs
funcs:
.quad weakfunc

.section .gfids$y,"dr"
.symidx weakfunc
.section .giats$y,"dr"
.section .gljmp$y,"dr"
.weak weakfunc
.addrsig
.addrsig_sym weakfunc