[lld] 50d33c6 - [LLD] [COFF] Fix crashes for cfguard with undefined weak symbols (#79063)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 23 10:37:06 PST 2024
Author: Martin Storsjö
Date: 2024-01-23T20:37:03+02:00
New Revision: 50d33c62ad8786400a712b01150f6decaf070782
URL: https://github.com/llvm/llvm-project/commit/50d33c62ad8786400a712b01150f6decaf070782
DIFF: https://github.com/llvm/llvm-project/commit/50d33c62ad8786400a712b01150f6decaf070782.diff
LOG: [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 https://github.com/llvm/llvm-project/issues/78619.
Added:
lld/test/COFF/cfguard-weak-undef.s
Modified:
lld/COFF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index 2e34a6c5cfa2c0..9c20bbb83d86d1 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -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);
diff --git a/lld/test/COFF/cfguard-weak-undef.s b/lld/test/COFF/cfguard-weak-undef.s
new file mode 100644
index 00000000000000..fd4121ac27dfcc
--- /dev/null
+++ b/lld/test/COFF/cfguard-weak-undef.s
@@ -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
More information about the llvm-commits
mailing list