Skip to content

Commit d4729d8

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 2f9ed32 commit d4729d8

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

llvm/include/llvm/MC/MCObjectFileInfo.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@
2222
#include <array>
2323
#include <optional>
2424

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

llvm/lib/MC/MCObjectFileInfo.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828

2929
using namespace llvm;
3030

31+
// LDC-specific
32+
namespace ldc {
33+
bool emitMachODwarfLineAsRegularSection = false;
34+
} // end namespace ldc
35+
3136
static bool useCompactUnwind(const Triple &T) {
3237
// Only on darwin.
3338
if (!T.isOSDarwin())
@@ -251,9 +256,12 @@ void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
251256
DwarfInfoSection =
252257
Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
253258
SectionKind::getMetadata(), "section_info");
254-
DwarfLineSection =
255-
Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
256-
SectionKind::getMetadata(), "section_line");
259+
DwarfLineSection = Ctx->getMachOSection(
260+
"__DWARF", "__debug_line",
261+
// LDC-specific
262+
ldc::emitMachODwarfLineAsRegularSection ? MachO::S_REGULAR
263+
: MachO::S_ATTR_DEBUG,
264+
SectionKind::getMetadata(), "section_line");
257265
DwarfLineStrSection =
258266
Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG,
259267
SectionKind::getMetadata(), "section_line_str");

0 commit comments

Comments
 (0)