[PATCH] D93367: [ELF] --emit-relocs: fix a crash if .rela.dyn is an output section description
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 15 21:34:47 PST 2020
MaskRay created this revision.
MaskRay added reviewers: grimar, psmith, ruiu.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: espindola.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Fix PR48357: If .rela.dyn appears as an output section description, its type may
be SHT_RELA (due to the empty synthetic .rela.plt) while there is no input
section. The empty .rela.dyn may be retained due to a reference in a linker
script. Don't crash.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D93367
Files:
lld/ELF/OutputSections.cpp
lld/test/ELF/linkerscript/emit-relocs-rela-dyn.s
Index: lld/test/ELF/linkerscript/emit-relocs-rela-dyn.s
===================================================================
--- /dev/null
+++ lld/test/ELF/linkerscript/emit-relocs-rela-dyn.s
@@ -0,0 +1,12 @@
+# REQUIRES: x86
+## PR48357: If .rela.dyn appears as an output section description, its type may
+## be SHT_RELA (due to the empty synthetic .rela.plt) while there is no input
+## section. The empty .rela.dyn may be retained due to a reference. Don't crash.
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64 /dev/null -o %t.o
+# RUN: ld.lld -shared --emit-relocs -T %s %t.o -o /dev/null
+
+SECTIONS {
+ .rela.dyn : { *(.rela*) }
+ __rela_offset = ABSOLUTE(ADDR(.rela.dyn));
+}
Index: lld/ELF/OutputSections.cpp
===================================================================
--- lld/ELF/OutputSections.cpp
+++ lld/ELF/OutputSections.cpp
@@ -418,7 +418,11 @@
if (!config->copyRelocs || (type != SHT_RELA && type != SHT_REL))
return;
- if (isa<SyntheticSection>(first))
+ // Skip if 'first' is synthetic, i.e. not a section created by --emit-relocs.
+ // Normally 'type' was changed by 'first' so 'first' should be non-null.
+ // However, if the output section is .rela.dyn, 'type' can be set by the empty
+ // synthetic .rela.plt and first can be null.
+ if (!first || isa<SyntheticSection>(first))
return;
link = in.symTab->getParent()->sectionIndex;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93367.312103.patch
Type: text/x-patch
Size: 1389 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201216/d8c241ad/attachment.bin>
More information about the llvm-commits
mailing list