[assembler + debuginfo] interaction with .file directive and debuginfo

[ I discussed this briefly with Paul off list and he suggested it would be better here. ]

Among the changes in 7.0.0 are some that were added to support DWARFv5’s .debug_line.

The presence of “.file” mutes debug info generated by the assembler as of r328208 – logic in AsmParser::enabledGenDwarfForAssembly().

The comment there states: “If we haven’t encountered any .file directives (which would imply that the assembler source was produced with debug info already) then emit one describing the assembler source file itself.”

Does .file imply that the assembly source was already produced with debug info? Perhaps not in all cases. If you wanted to emit an ELF::STT_FILE into your object, for example, you might add .file "foo.s".

I think we should change this behavior to the previous – check for “-g” but ignore “.file” directives. Or maybe there’s a compromise to be found among the different versions of “.file” with various args? Thoughts?

-Brian

There are two forms of the .file directive. One is simply

.file “path”

and the other is

.file [ “dir”] “path” [ …. other stuff ]

The latter is sometimes referred to as the “DWARF” form of the .file directive. I don’t know the history about the different forms. I have certainly messed with the latter form to accommodate the needs of DWARF v5.

I think it’s pretty certain that the DWARF form of .file means that the .s file was generated with debug info, and therefore the correct behavior of “clang –g foo.s” in that case is to ignore the –g and assume the assembler source has all the right stuff.

If the older form of .file can mean nothing more than “emit a file symbol” and not imply that the assembler source file itself already contains debug info, then seeing that form should not cause the assembler to ignore –g. But as I said, I don’t know the history and I don’t understand how the first form is generally used.

I’m quite willing to believe I did not understand the (largely unstated) specification for the non-DWARF form of .file, and if others agree that it should not imply that debug info already exists, then reporting that as a bug is appropriate. I can’t say I’d be able to find time to try to fix it before October, as I’m already over-committed, but I’d anticipate getting to it around that time.

–paulr

What does gcc do?

gcc as of 4.2.4 generates the debuginfo even with “.file” (as did clang 6.0.0). I’ll check a modern gcc.

gcc as of 8.1 still behaves the same as clang 6.

$ cat file_.S

//.file 1 “file.S”

.file “file_other.S”

.text

f1:

nop

.size f1, .-f1

$ /local/mnt/workspace/install/gcc-8.1/bin/gcc-8.1 -g -o out.o -c file_.S ; objdump -t out.o

out.o: file format elf64-x86-64

SYMBOL TABLE:

0000000000000000 l df ABS 0000000000000000 file_other.S

0000000000000000 l d .text 0000000000000000 .text

0000000000000000 l d .data 0000000000000000 .data

0000000000000000 l d .bss 0000000000000000 .bss

0000000000000000 l .text 0000000000000001 f1

0000000000000000 l d .debug_info 0000000000000000 .debug_info

0000000000000000 l d .debug_abbrev 0000000000000000 .debug_abbrev

0000000000000000 l d .debug_line 0000000000000000 .debug_line

0000000000000000 l d .debug_aranges 0000000000000000 .debug_aranges

$ /local/mnt/workspace/install/clang_nightly_2018_Jul27/bin/clang -g -o out.o -c file_.S ; objdump -t out.o

out.o: file format elf64-x86-64

SYMBOL TABLE:

0000000000000000 l df ABS 0000000000000000 file_other.S

0000000000000000 l .text 0000000000000001 f1

Awesome, couldn’t have a clearer example. Can you file a bug for this? Product: libraries, component: MC.

Feel free to have a run at it yourself, if you don’t want to wait a couple months.

Thanks!

–paulr

Done. PR38695.

I’ll give it a try and reach out if I need help.

-Brian

https://reviews.llvm.org/D51315