Skip to content

Commit de3d950

Browse files
committed
[LDC] Mach-O: 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 69748f0 commit de3d950

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

llvm/include/llvm/MC/MCObjectFileInfo.h

+11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@
2020
#include "llvm/Support/CodeGen.h"
2121
#include "llvm/Support/VersionTuple.h"
2222

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

llvm/lib/MC/MCObjectFileInfo.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424

2525
using namespace llvm;
2626

27+
// LDC-specific
28+
namespace ldc {
29+
bool emitMachODwarfLineAsRegularSection = false;
30+
} // end namespace ldc
31+
2732
static bool useCompactUnwind(const Triple &T) {
2833
// Only on darwin.
2934
if (!T.isOSDarwin())
@@ -229,9 +234,12 @@ void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
229234
DwarfInfoSection =
230235
Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
231236
SectionKind::getMetadata(), "section_info");
232-
DwarfLineSection =
233-
Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
234-
SectionKind::getMetadata(), "section_line");
237+
DwarfLineSection = Ctx->getMachOSection(
238+
"__DWARF", "__debug_line",
239+
// LDC-specific
240+
ldc::emitMachODwarfLineAsRegularSection ? MachO::S_REGULAR
241+
: MachO::S_ATTR_DEBUG,
242+
SectionKind::getMetadata(), "section_line");
235243
DwarfLineStrSection =
236244
Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG,
237245
SectionKind::getMetadata(), "section_line_str");

0 commit comments

Comments
 (0)