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

Commit 7ce4a66

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 7afffb9 commit 7ce4a66

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/Support/CodeGen.h"
2020
#include "llvm/Support/VersionTuple.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())
@@ -227,9 +232,12 @@ void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
227232
DwarfInfoSection =
228233
Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
229234
SectionKind::getMetadata(), "section_info");
230-
DwarfLineSection =
231-
Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
232-
SectionKind::getMetadata(), "section_line");
235+
DwarfLineSection = Ctx->getMachOSection(
236+
"__DWARF", "__debug_line",
237+
// LDC-specific
238+
ldc::emitMachODwarfLineAsRegularSection ? MachO::S_REGULAR
239+
: MachO::S_ATTR_DEBUG,
240+
SectionKind::getMetadata(), "section_line");
233241
DwarfLineStrSection =
234242
Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG,
235243
SectionKind::getMetadata(), "section_line_str");

0 commit comments

Comments
 (0)