Skip to content

Commit 356e996

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 15a392a commit 356e996

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
@@ -21,6 +21,17 @@
2121
#include <array>
2222
#include <optional>
2323

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

llvm/lib/MC/MCObjectFileInfo.cpp

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

2828
using namespace llvm;
2929

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

0 commit comments

Comments
 (0)