[dsymutil] Accept line tables up to DWARFv5.
authorJonas Devlieghere <jonas@devlieghere.com>
Tue, 12 Dec 2017 11:32:21 +0000 (11:32 +0000)
committerJonas Devlieghere <jonas@devlieghere.com>
Tue, 12 Dec 2017 11:32:21 +0000 (11:32 +0000)
This patch removes the hard-coded check for DWARFv2 line tables. Now
dsymutil accepts line tables for DWARF versions 2 to 5 (inclusive).

Differential revision: https://reviews.llvm.org/D41084

rdar://35968319

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320469 91177308-0d34-0410-b5e6-96231b3b80d8

test/tools/dsymutil/Inputs/dwarf4.o [new file with mode: 0644]
test/tools/dsymutil/Inputs/dwarf5.o [new file with mode: 0644]
test/tools/dsymutil/X86/dwarf4-linetable.test [new file with mode: 0644]
test/tools/dsymutil/X86/dwarf5-linetable.test [new file with mode: 0644]
tools/dsymutil/DwarfLinker.cpp

diff --git a/test/tools/dsymutil/Inputs/dwarf4.o b/test/tools/dsymutil/Inputs/dwarf4.o
new file mode 100644 (file)
index 0000000..0c6487a
Binary files /dev/null and b/test/tools/dsymutil/Inputs/dwarf4.o differ
diff --git a/test/tools/dsymutil/Inputs/dwarf5.o b/test/tools/dsymutil/Inputs/dwarf5.o
new file mode 100644 (file)
index 0000000..a9767f6
Binary files /dev/null and b/test/tools/dsymutil/Inputs/dwarf5.o differ
diff --git a/test/tools/dsymutil/X86/dwarf4-linetable.test b/test/tools/dsymutil/X86/dwarf4-linetable.test
new file mode 100644 (file)
index 0000000..39de076
--- /dev/null
@@ -0,0 +1,23 @@
+# RUN: llvm-dsymutil -f -oso-prepend-path=%p/../Inputs/ -y %s -o - | llvm-dwarfdump -debug-line - | FileCheck %s
+
+# Source:
+#   int main() {
+#     return 0;
+#   }
+# Compile with:
+#   clang -gdwarf-4 dwarf4.c -c -o dwarf4.o
+
+---
+triple:          'x86_64-apple-darwin'
+objects:
+  - filename:        dwarf4.o
+    timestamp:       1513021112
+    symbols:
+      - { sym: _main, objAddr: 0x0000000000000000, binAddr: 0x0000000100000FA0, size: 0x0000000F }
+...
+
+# CHECK: .debug_line contents:
+# CHECK: debug_line
+# CHECK: Line table prologue:
+# CHECK: total_length:
+# CHECK: version: 4
diff --git a/test/tools/dsymutil/X86/dwarf5-linetable.test b/test/tools/dsymutil/X86/dwarf5-linetable.test
new file mode 100644 (file)
index 0000000..8622c37
--- /dev/null
@@ -0,0 +1,23 @@
+# RUN: llvm-dsymutil -f -oso-prepend-path=%p/../Inputs/ -y %s -o - | llvm-dwarfdump -debug-line - | FileCheck %s
+
+# Source:
+#   int main() {
+#     return 0;
+#   }
+# Compile with:
+#   clang -gdwarf-5 dwarf5.c -c -o dwarf5.o
+
+---
+triple:          'x86_64-apple-darwin'
+objects:
+  - filename:        dwarf5.o
+    timestamp:       1513021112
+    symbols:
+      - { sym: _main, objAddr: 0x0000000000000000, binAddr: 0x0000000100000FA0, size: 0x0000000F }
+...
+
+# CHECK: .debug_line contents:
+# CHECK: debug_line
+# CHECK: Line table prologue:
+# CHECK: total_length:
+# CHECK: version: 5
index 68f1505de1c454aa7ede48496c799c8de91aa8b1..50ffc69dfaa05a1bc703a594a28502b304842573 100644 (file)
@@ -3232,16 +3232,21 @@ void DwarfLinker::patchLineTableForUnit(CompileUnit &Unit,
   }
 
   // Finished extracting, now emit the line tables.
-  uint32_t PrologueEnd = *StmtList + 10 + LineTable.Prologue.PrologueLength;
-  // FIXME: LLVM hardcodes it's prologue values. We just copy the
+  // FIXME: LLVM hardcodes its prologue values. We just copy the
   // prologue over and that works because we act as both producer and
   // consumer. It would be nicer to have a real configurable line
   // table emitter.
-  if (LineTable.Prologue.getVersion() != 2 ||
+  if (LineTable.Prologue.getVersion() < 2 ||
+      LineTable.Prologue.getVersion() > 5 ||
       LineTable.Prologue.DefaultIsStmt != DWARF2_LINE_DEFAULT_IS_STMT ||
       LineTable.Prologue.OpcodeBase > 13)
     reportWarning("line table parameters mismatch. Cannot emit.");
   else {
+    uint32_t PrologueEnd = *StmtList + 10 + LineTable.Prologue.PrologueLength;
+    // DWARFv5 has an extra 2 bytes of information before the header_length
+    // field.
+    if (LineTable.Prologue.getVersion() == 5)
+      PrologueEnd += 2;
     StringRef LineData = OrigDwarf.getDWARFObj().getLineSection().Data;
     MCDwarfLineTableParams Params;
     Params.DWARF2LineOpcodeBase = LineTable.Prologue.OpcodeBase;