diff options
author | George Rimar <grimar@accesssoftek.com> | 2018-12-05 10:43:58 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2018-12-05 10:43:58 +0000 |
commit | 79ace92fcd19c357d51a414109fb1121014c0173 (patch) | |
tree | 48871d86a77ec5beca99c974a5f56bd3f7f4e78b /llvm/lib/MC/ELFObjectWriter.cpp | |
parent | d24730cdda57d76f980980085a17b041edc0df35 (diff) | |
download | bcm5719-llvm-79ace92fcd19c357d51a414109fb1121014c0173.tar.gz bcm5719-llvm-79ace92fcd19c357d51a414109fb1121014c0173.zip |
Recommit r348243 - "[llvm-mc] - Do not crash when referencing undefined debug sections."
The patch triggered an unrelated msan issue: LayoutOrder variable was not initialized.
(http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/26794/steps/check-llvm%20msan/logs/stdio)
It was fixed.
Original commit message:
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
----
Modified : /llvm/trunk/lib/MC/ELFObjectWriter.cpp
Added : /llvm/trunk/test/MC/ELF/undefined-debug.s
llvm-svn: 348349
Diffstat (limited to 'llvm/lib/MC/ELFObjectWriter.cpp')
-rw-r--r-- | llvm/lib/MC/ELFObjectWriter.cpp | 14 |
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); |