[PATCH] D46878: Add DW_AT_linkage_name for DW_TAG_labels

Dimitry Ivanov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 16 07:00:00 PDT 2018


dimitry updated this revision to Diff 147080.
dimitry added a comment.

git clang-format --style=file


https://reviews.llvm.org/D46878

Files:
  include/llvm/MC/MCDwarf.h
  lib/MC/MCDwarf.cpp
  test/MC/MachO/gen-dwarf.s


Index: test/MC/MachO/gen-dwarf.s
===================================================================
--- test/MC/MachO/gen-dwarf.s
+++ test/MC/MachO/gen-dwarf.s
@@ -50,6 +50,7 @@
 
 // CHECK:    DW_TAG_label [2] *
 // CHECK:      DW_AT_name [DW_FORM_string]	("bar")
+// CHECK:      DW_AT_linkage_name [DW_FORM_string]	("_bar")
 // CHECK:      DW_AT_decl_file [DW_FORM_data4]	([[FILE:".*gen-dwarf.s"]])
 // CHECK:      DW_AT_decl_line [DW_FORM_data4]	(5)
 // CHECK:      DW_AT_low_pc [DW_FORM_addr]	(0x0000000000000000)
@@ -61,6 +62,7 @@
 
 // CHECK:    DW_TAG_label [2] *
 // CHECK:      DW_AT_name [DW_FORM_string]	("foo")
+// CHECK:      DW_AT_linkage_name [DW_FORM_string]	("_foo")
 // CHECK:      DW_AT_decl_file [DW_FORM_data4]	([[FILE]])
 // CHECK:      DW_AT_decl_line [DW_FORM_data4]	(9)
 // CHECK:      DW_AT_low_pc [DW_FORM_addr]	(0x0000000000000007)
@@ -72,6 +74,7 @@
 
 // CHECK:    DW_TAG_label [2] *
 // CHECK:      DW_AT_name [DW_FORM_string]	("baz")
+// CHECK:      DW_AT_linkage_name [DW_FORM_string]	("_baz")
 // CHECK:      DW_AT_decl_file [DW_FORM_data4]	([[FILE]])
 // CHECK:      DW_AT_decl_line [DW_FORM_data4]	(10)
 // CHECK:      DW_AT_low_pc [DW_FORM_addr]	(0x0000000000000007)
Index: lib/MC/MCDwarf.cpp
===================================================================
--- lib/MC/MCDwarf.cpp
+++ lib/MC/MCDwarf.cpp
@@ -559,6 +559,7 @@
   MCOS->EmitULEB128IntValue(dwarf::DW_TAG_label);
   MCOS->EmitIntValue(dwarf::DW_CHILDREN_yes, 1);
   EmitAbbrev(MCOS, dwarf::DW_AT_name, dwarf::DW_FORM_string);
+  EmitAbbrev(MCOS, dwarf::DW_AT_linkage_name, dwarf::DW_FORM_string);
   EmitAbbrev(MCOS, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data4);
   EmitAbbrev(MCOS, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data4);
   EmitAbbrev(MCOS, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr);
@@ -787,6 +788,10 @@
     MCOS->EmitBytes(Entry.getName());
     MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
 
+    // AT_linkage_name - the actual symbol name
+    MCOS->EmitBytes(Entry.getLinkageName());
+    MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
+
     // AT_decl_file, index into the file table.
     MCOS->EmitIntValue(Entry.getFileNumber(), 4);
 
@@ -940,6 +945,7 @@
   // The dwarf label's name does not have the symbol name's leading
   // underbar if any.
   StringRef Name = Symbol->getName();
+  StringRef LinkageName = Symbol->getName();
   if (Name.startswith("_"))
     Name = Name.substr(1, Name.size()-1);
 
@@ -960,7 +966,7 @@
 
   // Create and entry for the info and add it to the other entries.
   MCOS->getContext().addMCGenDwarfLabelEntry(
-      MCGenDwarfLabelEntry(Name, FileNumber, LineNumber, Label));
+      MCGenDwarfLabelEntry(Name, LinkageName, FileNumber, LineNumber, Label));
 }
 
 static int getDataAlignmentFactor(MCStreamer &streamer) {
Index: include/llvm/MC/MCDwarf.h
===================================================================
--- include/llvm/MC/MCDwarf.h
+++ include/llvm/MC/MCDwarf.h
@@ -306,20 +306,24 @@
 private:
   // Name of the symbol without a leading underbar, if any.
   StringRef Name;
+  // The original symbol name.
+  StringRef LinkageName;
   // The dwarf file number this symbol is in.
   unsigned FileNumber;
   // The line number this symbol is at.
   unsigned LineNumber;
   // The low_pc for the dwarf label is taken from this symbol.
   MCSymbol *Label;
 
 public:
-  MCGenDwarfLabelEntry(StringRef name, unsigned fileNumber, unsigned lineNumber,
+  MCGenDwarfLabelEntry(StringRef name, StringRef linkageName,
+                       unsigned fileNumber, unsigned lineNumber,
                        MCSymbol *label)
-      : Name(name), FileNumber(fileNumber), LineNumber(lineNumber),
-        Label(label) {}
+      : Name(name), LinkageName(linkageName), FileNumber(fileNumber),
+        LineNumber(lineNumber), Label(label) {}
 
   StringRef getName() const { return Name; }
+  StringRef getLinkageName() const { return LinkageName; }
   unsigned getFileNumber() const { return FileNumber; }
   unsigned getLineNumber() const { return LineNumber; }
   MCSymbol *getLabel() const { return Label; }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46878.147080.patch
Type: text/x-patch
Size: 4113 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180516/97fa6bfd/attachment.bin>


More information about the llvm-commits mailing list