Start treating .eh_frame specially.

For now, just don't follow edges leaving from it to mark other sections
live.

llvm-svn: 252493
This commit is contained in:
Rafael Espindola 2015-11-09 17:44:10 +00:00
parent 3656e3064b
commit 8ea46e00f1
3 changed files with 31 additions and 5 deletions

View File

@ -71,7 +71,7 @@ template <class ELFT> static bool isReserved(InputSectionBase<ELFT> *Sec) {
default:
StringRef S = Sec->getSectionName();
return S.startswith(".init") || S.startswith(".fini") ||
S.startswith(".jcr") || S == ".eh_frame";
S.startswith(".jcr");
}
}
@ -109,11 +109,18 @@ template <class ELFT> void lld::elf2::markLive(SymbolTable<ELFT> *Symtab) {
}
// Preserve special sections.
for (const std::unique_ptr<ObjectFile<ELFT>> &F : Symtab->getObjectFiles())
for (InputSectionBase<ELFT> *Sec : F->getSections())
if (Sec && Sec != &InputSection<ELFT>::Discarded)
for (const std::unique_ptr<ObjectFile<ELFT>> &F : Symtab->getObjectFiles()) {
for (InputSectionBase<ELFT> *Sec : F->getSections()) {
if (Sec && Sec != &InputSection<ELFT>::Discarded) {
if (isReserved(Sec))
Enqueue(Sec);
else if (Sec->getSectionName() == ".eh_frame")
// .eh_frame is special. It should be marked live so that we don't
// drop it, but it should not keep any section alive.
Sec->Live = true;
}
}
}
// Mark all reachable sections.
while (!Q.empty())

View File

@ -707,7 +707,7 @@ lld::elf2::getLocalRelTarget(const ObjectFile<ELFT> &File,
// and must be treated specially. For now we just replace the symbol with
// 0.
InputSectionBase<ELFT> *Section = File.getSection(*Sym);
if (Section == &InputSection<ELFT>::Discarded)
if (Section == &InputSection<ELFT>::Discarded || !Section->isLive())
return Addend;
uintX_t VA = Section->OutSec->getVA();

View File

@ -0,0 +1,19 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: ld.lld2 %t -o %t2 --gc-sections
# RUN: llvm-readobj -t %t2 | FileCheck %s
# CHECK-NOT: foo
.section .text,"ax",@progbits,unique,0
.globl foo
foo:
.cfi_startproc
.cfi_endproc
.section .text,"ax",@progbits,unique,1
.globl _start
_start:
.cfi_startproc
.cfi_endproc