Alternative fix for reloc tareting discarded section

r283984 introduced a problem of too many warning messages being shown
when -ffunction-sections and -fdata-sections were used in conjunction 
with --gc-sections linker flag and debugging information present. This
happens because lot of relocations from .debug_line section may become
invalid in such case. The newer fix doesn't show any warning message but
zeroes OutSec pointer in createInputSectionList() to avoid crash, when
relocations are written

llvm-svn: 284010
This commit is contained in:
Eugene Leviant 2016-10-12 12:31:34 +00:00
parent c7d16f4e05
commit cc1ba8c7d0
3 changed files with 7 additions and 13 deletions

View File

@ -239,6 +239,12 @@ LinkerScript<ELFT>::createInputSectionList(OutputSectionCommand &OutCmd) {
Ret.push_back(static_cast<InputSectionBase<ELFT> *>(S));
}
// After we created final list we should now set OutSec pointer to null,
// instead of -1. Otherwise we may get a crash when writing relocs, in
// case section is discarded by linker script
for (InputSectionBase<ELFT> *S : Ret)
S->OutSec = nullptr;
return Ret;
}

View File

@ -24,12 +24,6 @@ using namespace llvm::ELF;
using namespace lld;
using namespace lld::elf;
template <class ELFT>
static std::string getSectionName(InputSectionBase<ELFT> *S) {
StringRef Filename = S->getFile()->getName();
return (sys::path::filename(Filename) + "(" + S->Name + ")").str();
}
template <class ELFT>
static typename ELFT::uint getSymVA(const SymbolBody &Body,
typename ELFT::uint &Addend) {
@ -60,11 +54,6 @@ static typename ELFT::uint getSymVA(const SymbolBody &Body,
if (!SC)
return D.Value;
if (!SC->Live) {
warn("relocation refers to discarded section '" + getSectionName(SC) + "'");
return 0;
}
uintX_t Offset = D.Value;
if (D.isSection()) {
Offset += Addend;

View File

@ -1,10 +1,9 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: echo "SECTIONS { /DISCARD/ : { *(.aaa*) } }" > %t.script
# RUN: ld.lld -o %t1 --script %t.script %t 2>&1 | FileCheck --check-prefix=WARN %s
# RUN: ld.lld -o %t1 --script %t.script %t
# RUN: llvm-objdump -section-headers %t1 | FileCheck %s
# WARN: relocation refers to discarded section {{.+}}(.aaa)
# CHECK-NOT: .aaa
.section .aaa,"a"