summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC/ELFObjectWriter.cpp
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2018-12-04 10:10:50 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2018-12-04 10:10:50 +0000
commit026cc2ff9552fa372bd5a38397fd0866d69fd96d (patch)
treec271418de0c24890d04eb89e9bb022ef8f83fdce /llvm/lib/MC/ELFObjectWriter.cpp
parent7e981f330b2f204b3ec4b3b7af90ea3f950af822 (diff)
downloadbcm5719-llvm-026cc2ff9552fa372bd5a38397fd0866d69fd96d.tar.gz
bcm5719-llvm-026cc2ff9552fa372bd5a38397fd0866d69fd96d.zip
[llvm-mc] - Do not crash when referencing undefined debug sections.
MC has code that pre-creates few debug sections: https://github.com/llvm-mirror/llvm/blob/master/lib/MC/MCObjectFileInfo.cpp#L396 If users code has a reference to such section but does not redefine it, MC code currently asserts, because still thinks they are normally defined. The patch fixes the issue. Differential revision: https://reviews.llvm.org/D55173 llvm-svn: 348243
Diffstat (limited to 'llvm/lib/MC/ELFObjectWriter.cpp')
-rw-r--r--llvm/lib/MC/ELFObjectWriter.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 5b8b013ad08..89f3b30cddd 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -669,6 +669,20 @@ void ELFWriter::computeSymbolTable(
} else {
const MCSectionELF &Section =
static_cast<const MCSectionELF &>(Symbol.getSection());
+
+ // We may end up with a situation when section symbol is technically
+ // defined, but should not be. That happens because we explicitly
+ // pre-create few .debug_* sections to have accessors.
+ // And if these sections were not really defined in the code, but were
+ // referenced, we simply error out.
+ if (!Section.isRegistered()) {
+ assert(static_cast<const MCSymbolELF &>(Symbol).getType() ==
+ ELF::STT_SECTION);
+ Ctx.reportError(SMLoc(),
+ "Undefined section reference: " + Symbol.getName());
+ continue;
+ }
+
if (Mode == NonDwoOnly && isDwoSection(Section))
continue;
MSD.SectionIndex = SectionIndexMap.lookup(&Section);
OpenPOWER on IntegriCloud