diff --git a/include/llvm/MC/MCContext.h b/include/llvm/MC/MCContext.h index b1fa8e7a1d0..3f106c697b0 100644 --- a/include/llvm/MC/MCContext.h +++ b/include/llvm/MC/MCContext.h @@ -185,6 +185,9 @@ namespace llvm { /// The maximum version of dwarf that we should emit. uint16_t DwarfVersion = 4; + /// The format of dwarf that we emit. + dwarf::DwarfFormat DwarfFormat = dwarf::DWARF32; + /// Honor temporary labels, this is useful for debugging semantic /// differences between temporary and non-temporary labels (primarily on /// Darwin). @@ -694,10 +697,8 @@ namespace llvm { void setDwarfDebugProducer(StringRef S) { DwarfDebugProducer = S; } StringRef getDwarfDebugProducer() { return DwarfDebugProducer; } - dwarf::DwarfFormat getDwarfFormat() const { - // TODO: Support DWARF64 - return dwarf::DWARF32; - } + void setDwarfFormat(dwarf::DwarfFormat f) { DwarfFormat = f; } + dwarf::DwarfFormat getDwarfFormat() const { return DwarfFormat; } void setDwarfVersion(uint16_t v) { DwarfVersion = v; } uint16_t getDwarfVersion() const { return DwarfVersion; } diff --git a/include/llvm/MC/MCTargetOptions.h b/include/llvm/MC/MCTargetOptions.h index 018c3374af3..f20af1ab30c 100644 --- a/include/llvm/MC/MCTargetOptions.h +++ b/include/llvm/MC/MCTargetOptions.h @@ -53,6 +53,7 @@ public: /// Preserve Comments in Assembly. bool PreserveAsmComments : 1; + bool Dwarf64 : 1; int DwarfVersion = 0; std::string ABIName; diff --git a/include/llvm/MC/MCTargetOptionsCommandFlags.h b/include/llvm/MC/MCTargetOptionsCommandFlags.h index 8d9e5af448e..6d3c477e4b7 100644 --- a/include/llvm/MC/MCTargetOptionsCommandFlags.h +++ b/include/llvm/MC/MCTargetOptionsCommandFlags.h @@ -30,6 +30,8 @@ bool getIncrementalLinkerCompatible(); int getDwarfVersion(); +bool getDwarf64(); + bool getShowMCInst(); bool getFatalWarnings(); diff --git a/lib/MC/MCTargetOptions.cpp b/lib/MC/MCTargetOptions.cpp index 0a5d0cefedd..d35ef942d2d 100644 --- a/lib/MC/MCTargetOptions.cpp +++ b/lib/MC/MCTargetOptions.cpp @@ -16,7 +16,7 @@ MCTargetOptions::MCTargetOptions() MCNoWarn(false), MCNoDeprecatedWarn(false), MCSaveTempLabels(false), MCUseDwarfDirectory(false), MCIncrementalLinkerCompatible(false), ShowMCEncoding(false), ShowMCInst(false), AsmVerbose(false), - PreserveAsmComments(true) {} + PreserveAsmComments(true), Dwarf64(false) {} StringRef MCTargetOptions::getABIName() const { return ABIName; diff --git a/lib/MC/MCTargetOptionsCommandFlags.cpp b/lib/MC/MCTargetOptionsCommandFlags.cpp index 34dd759c894..38996f90006 100644 --- a/lib/MC/MCTargetOptionsCommandFlags.cpp +++ b/lib/MC/MCTargetOptionsCommandFlags.cpp @@ -38,6 +38,7 @@ using namespace llvm; MCOPT_EXP(bool, RelaxAll) MCOPT(bool, IncrementalLinkerCompatible) MCOPT(int, DwarfVersion) +MCOPT(bool, Dwarf64) MCOPT(bool, ShowMCInst) MCOPT(bool, FatalWarnings) MCOPT(bool, NoWarn) @@ -66,6 +67,11 @@ llvm::mc::RegisterMCTargetOptionsFlags::RegisterMCTargetOptionsFlags() { cl::init(0)); MCBINDOPT(DwarfVersion); + static cl::opt Dwarf64( + "dwarf64", + cl::desc("Generate debugging info in the 64-bit DWARF format")); + MCBINDOPT(Dwarf64); + static cl::opt ShowMCInst( "asm-show-inst", cl::desc("Emit internal instruction representation to assembly file")); @@ -97,6 +103,7 @@ MCTargetOptions llvm::mc::InitMCTargetOptionsFromFlags() { MCTargetOptions Options; Options.MCRelaxAll = getRelaxAll(); Options.MCIncrementalLinkerCompatible = getIncrementalLinkerCompatible(); + Options.Dwarf64 = getDwarf64(); Options.DwarfVersion = getDwarfVersion(); Options.ShowMCInst = getShowMCInst(); Options.ABIName = getABIName(); diff --git a/test/MC/COFF/dwarf64-err.s b/test/MC/COFF/dwarf64-err.s new file mode 100644 index 00000000000..52704dab7d5 --- /dev/null +++ b/test/MC/COFF/dwarf64-err.s @@ -0,0 +1,3 @@ +# RUN: not llvm-mc -dwarf64 -triple x86_64-unknown-windows-gnu %s -o - 2>&1 | FileCheck %s + +# CHECK: the 64-bit DWARF format is not supported for x86_64-unknown-windows-gnu diff --git a/test/MC/ELF/dwarf64-err.s b/test/MC/ELF/dwarf64-err.s new file mode 100644 index 00000000000..dd514068cf6 --- /dev/null +++ b/test/MC/ELF/dwarf64-err.s @@ -0,0 +1,5 @@ +# RUN: not llvm-mc -g -dwarf-version 2 -dwarf64 -triple x86_64 %s -o - 2>&1 | FileCheck --check-prefix=DWARF2 %s +# RUN: not llvm-mc -g -dwarf-version 5 -dwarf64 -triple i686 %s -o - 2>&1 | FileCheck --check-prefix=I686 %s + +# DWARF2: the 64-bit DWARF format is not supported for DWARF versions prior to 3 +# I686: the 64-bit DWARF format is only supported for 64-bit targets diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index eee51a5179e..66b55abc489 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -387,6 +387,31 @@ int main(int argc, char **argv) { return 1; } Ctx.setDwarfVersion(DwarfVersion); + if (MCOptions.Dwarf64) { + // The 64-bit DWARF format was introduced in DWARFv3. + if (DwarfVersion < 3) { + errs() << ProgName + << ": the 64-bit DWARF format is not supported for DWARF versions " + "prior to 3\n"; + return 1; + } + // 32-bit targets don't support DWARF64, which requires 64-bit relocations. + if (MAI->getCodePointerSize() < 8) { + errs() << ProgName + << ": the 64-bit DWARF format is only supported for 64-bit " + "targets\n"; + return 1; + } + // If needsDwarfSectionOffsetDirective is true, we would eventually call + // MCStreamer::emitSymbolValue() with IsSectionRelative = true, but that + // is supported only for 4-byte long references. + if (MAI->needsDwarfSectionOffsetDirective()) { + errs() << ProgName << ": the 64-bit DWARF format is not supported for " + << TheTriple.normalize() << "\n"; + return 1; + } + Ctx.setDwarfFormat(dwarf::DWARF64); + } if (!DwarfDebugFlags.empty()) Ctx.setDwarfDebugFlags(StringRef(DwarfDebugFlags)); if (!DwarfDebugProducer.empty())