This is an archive of the discontinued LLVM Phabricator instance.

Keep underscores in DW_AT_name of DW_TAG_labels
Needs ReviewPublic

Authored by dimitry on May 19 2018, 7:12 AM.

Details

Summary

Do not remove leading underscores from DW_AT_names of DW_TAG_labels.

Bug: https://bugs.llvm.org/show_bug.cgi?id=37470

Diff Detail

Event Timeline

dimitry created this revision.May 19 2018, 7:12 AM

This still breaks the assembler scenario @aprantl mentioned in D46878. Can we differentiate between the two in MC so we can fix PR37470 without that side-effect?

This behavior goes back to r146262:

commit 94c2e85bea1ab1b837a4c055ccc83d5cd32dd027
Author: Kevin Enderby <enderby@apple.com>
Date:   Fri Dec 9 18:09:40 2011 +0000

    The second part of support for generating dwarf for assembly source files.  
This
    generates the dwarf Compile Unit DIE and a dwarf subprogram DIE for each
    non-temporary label.
    
    The next part will be to get the clang driver to enable this when assembling
    a .s file.  rdar://9275556
    
    
    git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146262

which added

+  // The dwarf subprogram's name does not have the symbol name's leading
+  // underbar if any.
+  StringRef Name = Symbol->getName();
+  if (Name.startswith("_"))
+    Name = Name.substr(1, Name.size()-1);
+

My *guess* is that the underscore trimming was added to allow setting breakpoints by name on labels in assembler output generated by a compiler, but I'm not sure. Perhaps @echristo knows more?

(The radar doesn't mention this at all unfortunately)

My *guess* is that the underscore trimming was added to allow setting breakpoints by name on labels in assembler output generated by a compiler, but I'm not sure. Perhaps @echristo knows more?

I don't sadly. I believe the intention was to make it so that breakpoints would be for the "obvious" symbol name rather than the "mangled with an underscore" that you need for the platform. So... whatever makes that easiest? I'd probably think a linkage name would be more helpful than mangling/demangling the actual symbol name here.

Thoughts?