diff options
| author | Petr Hosek <phosek@chromium.org> | 2017-06-15 05:34:31 +0000 |
|---|---|---|
| committer | Petr Hosek <phosek@chromium.org> | 2017-06-15 05:34:31 +0000 |
| commit | 40f2866a679c232ec5027f194dd869046059528a (patch) | |
| tree | 0aa11b46542c687e9bc24f2847d59ec6ce9ecad7 | |
| parent | b4f962cdccc7b7d9d7758e6e8c0ef436115658bd (diff) | |
| download | bcm5719-llvm-40f2866a679c232ec5027f194dd869046059528a.tar.gz bcm5719-llvm-40f2866a679c232ec5027f194dd869046059528a.zip | |
[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
llvm-svn: 305452
| -rw-r--r-- | lld/ELF/MarkLive.cpp | 2 | ||||
| -rw-r--r-- | lld/test/ELF/linkerscript/data-commands-gc.s | 16 |
2 files changed, 18 insertions, 0 deletions
diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp index b77c84ff75a..0b4a78f8da6 100644 --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -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. diff --git a/lld/test/ELF/linkerscript/data-commands-gc.s b/lld/test/ELF/linkerscript/data-commands-gc.s new file mode 100644 index 00000000000..46ce6a97cf7 --- /dev/null +++ b/lld/test/ELF/linkerscript/data-commands-gc.s @@ -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 |

