[PATCH] D34195: [ELF] Mark symbols referenced from linker script as live
Petr Hosek via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 13 23:45:49 PDT 2017
phosek created this revision.
phosek added a project: lld.
Herald added a subscriber: emaste.
This is necessary to ensure that sections containing symbols referenced
from linker scripts (e.g. in data commands) don't get GC'd.
Repository:
rL LLVM
https://reviews.llvm.org/D34195
Files:
ELF/MarkLive.cpp
test/ELF/linkerscript/data-commands-gc.s
Index: test/ELF/linkerscript/data-commands-gc.s
===================================================================
--- /dev/null
+++ test/ELF/linkerscript/data-commands-gc.s
@@ -0,0 +1,22 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "SECTIONS \
+# RUN: { \
+# RUN: .text : { \
+# RUN: *(.text*) \
+# RUN: QUAD(bar) \
+# RUN: } \
+# RUN: }" > %t.script
+# RUN: ld.lld --gc-sections -o %t %t.o --script %t.script | FileCheck -allow-empty %s
+
+# CHECK-NOT: unable to evaluate expression: input section .rodata.bar has no output section assigned
+
+.section .rodata.bar
+.quad 0x1122334455667788
+.global bar
+bar:
+
+.section .text
+.global _start
+_start:
+ nop
Index: ELF/MarkLive.cpp
===================================================================
--- ELF/MarkLive.cpp
+++ ELF/MarkLive.cpp
@@ -230,6 +230,8 @@
MarkSymbol(Symtab<ELFT>::X->find(Config->Fini));
for (StringRef S : Config->Undefined)
MarkSymbol(Symtab<ELFT>::X->find(S));
+ for (StringRef S : Script->Opt.ReferencedSymbols)
+ MarkSymbol(Symtab<ELFT>::X->find(S));
// Preserve externally-visible symbols if the symbols defined by this
// file can interrupt other ELF file's symbols at runtime.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34195.102488.patch
Type: text/x-patch
Size: 1376 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170614/be6ac596/attachment.bin>
More information about the llvm-commits
mailing list