summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/InputSection.cpp12
-rw-r--r--lld/ELF/InputSection.h2
-rw-r--r--lld/ELF/OutputSections.cpp4
-rw-r--r--lld/ELF/SyntheticSections.cpp2
-rw-r--r--lld/test/ELF/section-metadata-err.s15
5 files changed, 28 insertions, 7 deletions
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 466656efbf0..979369b26db 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -181,9 +181,15 @@ uint64_t SectionBase::getOffset(const DefinedRegular &Sym) const {
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;
}
diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h
index 4ef4328e8a5..42ae0a796c8 100644
--- a/lld/ELF/InputSection.h
+++ b/lld/ELF/InputSection.h
@@ -158,7 +158,7 @@ public:
return getFile<ELFT>()->getObj();
}
- InputSectionBase *getLinkOrderDep() const;
+ InputSection *getLinkOrderDep() const;
void uncompress();
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 9f70155ed6f..00514f16604 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -76,8 +76,8 @@ static bool compareByFilePosition(InputSection *A, InputSection *B) {
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)
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 797401008b1..304968ad0bc 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -2200,7 +2200,7 @@ void ARMExidxSentinelSection::writeTo(uint8_t *Buf) {
});
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);
diff --git a/lld/test/ELF/section-metadata-err.s b/lld/test/ELF/section-metadata-err.s
new file mode 100644
index 00000000000..f3b5842945c
--- /dev/null
+++ b/lld/test/ELF/section-metadata-err.s
@@ -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",@progbits,8
+.quad 0
+
+.section bar,"ao",@progbits,.foo
OpenPOWER on IntegriCloud