[llvm] a8ec9de - [MC] Add --dwarf64 to generate DWARF64 debug info [1/7]
Igor Kudrin via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 16 01:51:29 PDT 2020
Author: Igor Kudrin
Date: 2020-06-16T15:50:13+07:00
New Revision: a8ec9de406ebd55b838813fc4fb1f4f770e56cdd
URL: https://github.com/llvm/llvm-project/commit/a8ec9de406ebd55b838813fc4fb1f4f770e56cdd
DIFF: https://github.com/llvm/llvm-project/commit/a8ec9de406ebd55b838813fc4fb1f4f770e56cdd.diff
LOG: [MC] Add --dwarf64 to generate DWARF64 debug info [1/7]
The patch adds an option `--dwarf64` to instruct a tool to generate
debug information in the 64-bit DWARF format. There is no real
implementation yet, only a few compatibility checks.
Differential Revision: https://reviews.llvm.org/D81143
Added:
llvm/test/MC/COFF/dwarf64-err.s
llvm/test/MC/ELF/dwarf64-err.s
Modified:
llvm/include/llvm/MC/MCContext.h
llvm/include/llvm/MC/MCTargetOptions.h
llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h
llvm/lib/MC/MCTargetOptions.cpp
llvm/lib/MC/MCTargetOptionsCommandFlags.cpp
llvm/tools/llvm-mc/llvm-mc.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h
index b1fa8e7a1d0e..3f106c697b01 100644
--- a/llvm/include/llvm/MC/MCContext.h
+++ b/llvm/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
///
diff erences 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/llvm/include/llvm/MC/MCTargetOptions.h b/llvm/include/llvm/MC/MCTargetOptions.h
index 018c3374af3d..f20af1ab30cd 100644
--- a/llvm/include/llvm/MC/MCTargetOptions.h
+++ b/llvm/include/llvm/MC/MCTargetOptions.h
@@ -53,6 +53,7 @@ class MCTargetOptions {
/// Preserve Comments in Assembly.
bool PreserveAsmComments : 1;
+ bool Dwarf64 : 1;
int DwarfVersion = 0;
std::string ABIName;
diff --git a/llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h b/llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h
index 8d9e5af448e4..6d3c477e4b73 100644
--- a/llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h
+++ b/llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h
@@ -30,6 +30,8 @@ bool getIncrementalLinkerCompatible();
int getDwarfVersion();
+bool getDwarf64();
+
bool getShowMCInst();
bool getFatalWarnings();
diff --git a/llvm/lib/MC/MCTargetOptions.cpp b/llvm/lib/MC/MCTargetOptions.cpp
index 0a5d0cefeddc..d35ef942d2db 100644
--- a/llvm/lib/MC/MCTargetOptions.cpp
+++ b/llvm/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/llvm/lib/MC/MCTargetOptionsCommandFlags.cpp b/llvm/lib/MC/MCTargetOptionsCommandFlags.cpp
index 34dd759c894e..38996f90006e 100644
--- a/llvm/lib/MC/MCTargetOptionsCommandFlags.cpp
+++ b/llvm/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<bool> Dwarf64(
+ "dwarf64",
+ cl::desc("Generate debugging info in the 64-bit DWARF format"));
+ MCBINDOPT(Dwarf64);
+
static cl::opt<bool> 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/llvm/test/MC/COFF/dwarf64-err.s b/llvm/test/MC/COFF/dwarf64-err.s
new file mode 100644
index 000000000000..52704dab7d5b
--- /dev/null
+++ b/llvm/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/llvm/test/MC/ELF/dwarf64-err.s b/llvm/test/MC/ELF/dwarf64-err.s
new file mode 100644
index 000000000000..dd514068cf61
--- /dev/null
+++ b/llvm/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/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp
index eee51a5179e9..66b55abc4898 100644
--- a/llvm/tools/llvm-mc/llvm-mc.cpp
+++ b/llvm/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())
More information about the llvm-commits
mailing list