[PATCH] D55173: [llvm-mc] - Do not crash when referencing undefined debug sections.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 2 05:06:58 PST 2018
grimar created this revision.
grimar added reviewers: pcc, dblaikie, echristo.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: espindola.
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.
https://reviews.llvm.org/D55173
Files:
lib/MC/ELFObjectWriter.cpp
test/MC/ELF/undefined-debug.s
Index: test/MC/ELF/undefined-debug.s
===================================================================
--- test/MC/ELF/undefined-debug.s
+++ test/MC/ELF/undefined-debug.s
@@ -0,0 +1,5 @@
+// RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t 2>&1 | FileCheck %s
+// CHECK: error: Undefined section reference: .debug_pubnames
+
+.section .foo,"", at progbits
+ .long .debug_pubnames
Index: lib/MC/ELFObjectWriter.cpp
===================================================================
--- lib/MC/ELFObjectWriter.cpp
+++ lib/MC/ELFObjectWriter.cpp
@@ -669,6 +669,20 @@
} 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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55173.176278.patch
Type: text/x-patch
Size: 1457 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181202/874828b7/attachment.bin>
More information about the llvm-commits
mailing list