Index: include/llvm/MC/MCDwarf.h =================================================================== --- include/llvm/MC/MCDwarf.h +++ include/llvm/MC/MCDwarf.h @@ -306,6 +306,8 @@ 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. @@ -314,12 +316,13 @@ MCSymbol *Label; public: - MCGenDwarfLabelEntry(StringRef name, unsigned fileNumber, unsigned lineNumber, - MCSymbol *label) - : Name(name), FileNumber(fileNumber), LineNumber(lineNumber), + MCGenDwarfLabelEntry(StringRef name, StringRef linkageName, unsigned fileNumber, + unsigned lineNumber, MCSymbol *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; } 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,9 +945,11 @@ // 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); + // Get the dwarf file number to be used for the dwarf label. unsigned FileNumber = context.getGenDwarfFileNumber(); @@ -960,7 +967,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: 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)