Skip to content
This repository was archived by the owner on Dec 20, 2019. It is now read-only.

Commit 7f88194

Browse files
committed
[Mach-O] LDC: Support emitting the DWARF __debug_info section as non-debug section
Which the linker preserves when linking the executable, so that druntime can display file/line infos in backtraces. See dlang/dmd@2bf7d0d.
1 parent 66a0a02 commit 7f88194

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

include/llvm/MC/MCObjectFileInfo.h

+11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@
1919
#include "llvm/MC/MCSymbol.h"
2020
#include "llvm/Support/CodeGen.h"
2121

22+
// LDC-specific
23+
#define LDC_LLVM_SUPPORTS_MACHO_DWARF_LINE_AS_REGULAR_SECTION
24+
namespace ldc {
25+
// Mach-O: emit __debug_line section in __DWARF segment as regular section
26+
// (S_REGULAR) instead of default S_ATTR_DEBUG, like DMD?
27+
// druntime's rt.backtrace attempts to read that section from the executable,
28+
// and debug sections are stripped by the linker. See
29+
// https://github.com/dlang/dmd/commit/2bf7d0db29416eacbb01a91e6502140e354ee0ef.
30+
extern bool emitMachODwarfLineAsRegularSection; // defaults to false
31+
} // end namespace ldc
32+
2233
namespace llvm {
2334
class MCContext;
2435
class MCSection;

lib/MC/MCObjectFileInfo.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222

2323
using namespace llvm;
2424

25+
// LDC-specific
26+
namespace ldc {
27+
bool emitMachODwarfLineAsRegularSection = false;
28+
} // end namespace ldc
29+
2530
static bool useCompactUnwind(const Triple &T) {
2631
// Only on darwin.
2732
if (!T.isOSDarwin())
@@ -231,9 +236,12 @@ void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
231236
DwarfInfoSection =
232237
Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
233238
SectionKind::getMetadata(), "section_info");
234-
DwarfLineSection =
235-
Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
236-
SectionKind::getMetadata(), "section_line");
239+
DwarfLineSection = Ctx->getMachOSection(
240+
"__DWARF", "__debug_line",
241+
// LDC-specific
242+
ldc::emitMachODwarfLineAsRegularSection ? MachO::S_REGULAR
243+
: MachO::S_ATTR_DEBUG,
244+
SectionKind::getMetadata(), "section_line");
237245
DwarfLineStrSection =
238246
Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG,
239247
SectionKind::getMetadata(), "section_line_str");

0 commit comments

Comments
 (0)