[lld] r305452 - [ELF] Mark symbols referenced from linker script as live
Petr Hosek via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 14 22:34:31 PDT 2017
Author: phosek
Date: Thu Jun 15 00:34:31 2017
New Revision: 305452
URL: http://llvm.org/viewvc/llvm-project?rev=305452&view=rev
Log:
[ELF] Mark symbols referenced from linker script as live
This is necessary to ensure that sections containing symbols referenced
from linker scripts (e.g. in data commands) don't get GC'd.
Differential Revision: https://reviews.llvm.org/D34195
Added:
lld/trunk/test/ELF/linkerscript/data-commands-gc.s
Modified:
lld/trunk/ELF/MarkLive.cpp
Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=305452&r1=305451&r2=305452&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Thu Jun 15 00:34:31 2017
@@ -230,6 +230,8 @@ template <class ELFT> void elf::markLive
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.
Added: lld/trunk/test/ELF/linkerscript/data-commands-gc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/data-commands-gc.s?rev=305452&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/data-commands-gc.s (added)
+++ lld/trunk/test/ELF/linkerscript/data-commands-gc.s Thu Jun 15 00:34:31 2017
@@ -0,0 +1,16 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "SECTIONS { .text : { *(.text*) QUAD(bar) } }" > %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
More information about the llvm-commits
mailing list