[lld] r304327 - Fix a crash.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed May 31 12:09:53 PDT 2017
Author: rafael
Date: Wed May 31 14:09:52 2017
New Revision: 304327
URL: http://llvm.org/viewvc/llvm-project?rev=304327&view=rev
Log:
Fix a crash.
We would crash if a SHF_LINK_ORDER section pointed to a non
InputSection section. Since those sections are not merged in order,
SHF_LINK_ORDER is pretty meaningless and we can error on that case.
Added:
lld/trunk/test/ELF/section-metadata-err.s
Modified:
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/InputSection.h
lld/trunk/ELF/OutputSections.cpp
lld/trunk/ELF/SyntheticSections.cpp
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=304327&r1=304326&r2=304327&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Wed May 31 14:09:52 2017
@@ -181,9 +181,15 @@ uint64_t SectionBase::getOffset(const De
return getOffset(Sym.Value);
}
-InputSectionBase *InputSectionBase::getLinkOrderDep() const {
- if ((Flags & SHF_LINK_ORDER) && Link != 0)
- return File->getSections()[Link];
+InputSection *InputSectionBase::getLinkOrderDep() const {
+ if ((Flags & SHF_LINK_ORDER) && Link != 0) {
+ InputSectionBase *L = File->getSections()[Link];
+ if (auto *IS = dyn_cast<InputSection>(L))
+ return IS;
+ error(
+ "Merge and .eh_frame sections are not supported with SHF_LINK_ORDER " +
+ toString(L));
+ }
return nullptr;
}
Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=304327&r1=304326&r2=304327&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Wed May 31 14:09:52 2017
@@ -158,7 +158,7 @@ public:
return getFile<ELFT>()->getObj();
}
- InputSectionBase *getLinkOrderDep() const;
+ InputSection *getLinkOrderDep() const;
void uncompress();
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=304327&r1=304326&r2=304327&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Wed May 31 14:09:52 2017
@@ -76,8 +76,8 @@ static bool compareByFilePosition(InputS
if (A->kind() == InputSectionBase::Synthetic ||
B->kind() == InputSectionBase::Synthetic)
return false;
- auto *LA = cast<InputSection>(A->getLinkOrderDep());
- auto *LB = cast<InputSection>(B->getLinkOrderDep());
+ InputSection *LA = A->getLinkOrderDep();
+ InputSection *LB = B->getLinkOrderDep();
OutputSection *AOut = LA->OutSec;
OutputSection *BOut = LB->OutSec;
if (AOut != BOut)
Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=304327&r1=304326&r2=304327&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Wed May 31 14:09:52 2017
@@ -2200,7 +2200,7 @@ void ARMExidxSentinelSection::writeTo(ui
});
auto L = cast<InputSectionDescription>(*ISD);
InputSection *Highest = L->Sections[L->Sections.size() - 2];
- InputSection *LS = cast<InputSection>(Highest->getLinkOrderDep());
+ InputSection *LS = Highest->getLinkOrderDep();
uint64_t S = LS->OutSec->Addr + LS->getOffset(LS->getSize());
uint64_t P = getVA();
Target->relocateOne(Buf, R_ARM_PREL31, S - P);
Added: lld/trunk/test/ELF/section-metadata-err.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/section-metadata-err.s?rev=304327&view=auto
==============================================================================
--- lld/trunk/test/ELF/section-metadata-err.s (added)
+++ lld/trunk/test/ELF/section-metadata-err.s Wed May 31 14:09:52 2017
@@ -0,0 +1,15 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck %s
+
+# CHECK: error: Merge and .eh_frame sections are not supported with SHF_LINK_ORDER {{.*}}section-metadata-err.s.tmp.o:(.foo)
+
+.global _start
+_start:
+.quad .foo
+
+.section .foo,"aM", at progbits,8
+.quad 0
+
+.section bar,"ao", at progbits,.foo
More information about the llvm-commits
mailing list