This is an archive of the discontinued LLVM Phabricator instance.

Use the DWARF form DW_FORM_sec_offset or DW_FORM_data4 depending on the Dwarf version being generated
ClosedPublic

Authored by keith.walker.arm on Nov 14 2013, 8:28 AM.

Details

Reviewers
echristo
Summary

In Dwarf 3 (and Dwarf 2) attributes whose value are offsets into a section use the form DW_FORM_data4 whilst in Dwarf 4 and later they use the form DW_FORM_sec_offset.

This patch updates the places where such attributes are generated to use the appropriate form depending on the Dwarf version. The DIE entries affected have the following tags:
DW_AT_stmt_list, DW_AT_ranges, DW_AT_location, DW_AT_GNU_pubnames, DW_AT_GNU_pubtypes, DW_AT_GNU_addr_base, DW_AT_GNU_ranges_base

It also adds a hidden command line option "--dwarf-version=<uint>" to llc which allows the version of Dwarf to be generated to override what is specified in the metadata; this makes it possible to update existing tests to check the debugging information generated for both Dwarf 4 (the default) and Dwarf 3 using the same metadata.

Diff Detail

Event Timeline

echristo accepted this revision.Nov 14 2013, 1:52 PM

LGTM. Do you need someone to commit for you?

+; RUN: llc -split-dwarf=Enable -O0 %s -mtriple=x86_64-unknown-linux-gnu -filetype=obj -o %t -dwarf-version=3

This seems weird, fission with DWARF 3... but of course 4 doesn't
have it either, so it's no less weird than what we have today.

It's good to have the forms more consistent with the target version
but eventually we might want to be more picky about mix-n-match.
--paulr

-----Original Message-----
From: llvm-commits-bounces@cs.uiuc.edu [mailto:llvm-commits-
bounces@cs.uiuc.edu] On Behalf Of Keith Walker
Sent: Thursday, November 14, 2013 8:29 AM
To: echristo@gmail.com; kwalker@arm.com
Cc: llvm-commits@cs.uiuc.edu
Subject: [PATCH] Use the DWARF form DW_FORM_sec_offset or DW_FORM_data4
depending on the Dwarf version being generated

Hi echristo,

In Dwarf 3 (and Dwarf 2) attributes whose value are offsets into a
section use the form DW_FORM_data4 whilst in Dwarf 4 and later they use
the form DW_FORM_sec_offset.

This patch updates the places where such attributes are generated to use
the appropriate form depending on the Dwarf version. The DIE entries
affected have the following tags:
DW_AT_stmt_list, DW_AT_ranges, DW_AT_location, DW_AT_GNU_pubnames,
DW_AT_GNU_pubtypes, DW_AT_GNU_addr_base, DW_AT_GNU_ranges_base

It also adds a hidden command line option "--dwarf-version=<uint>" to
llc which allows the version of Dwarf to be generated to override what
is specified in the metadata; this makes it possible to update existing
tests to check the debugging information generated for both Dwarf 4 (the
default) and Dwarf 3 using the same metadata.

http://llvm-reviews.chandlerc.com/D2180

Files:

lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
lib/CodeGen/AsmPrinter/DIE.cpp
lib/CodeGen/AsmPrinter/DwarfDebug.cpp
test/DebugInfo/X86/op_deref.ll
test/DebugInfo/X86/block-capture.ll
test/DebugInfo/X86/DW_AT_stmt_list_sec_offset.ll
test/DebugInfo/X86/gnu-public-names.ll
test/DebugInfo/X86/fission-cu.ll
test/DebugInfo/X86/stmt-list-multiple-compile-units.ll
keith.walker.arm updated this revision to Unknown Object (????).Nov 18 2013, 6:05 AM

Updated to remove DWARF 3 checks in fission test.

Eric if there are no further issues with this patch could you please commit it on my behalf.

echristo added inline comments.Nov 18 2013, 6:12 PM
lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
234

I do apologize for the lateness of this comment, but rather than bringing this into addLabel I'd prefer we have a "getSectionOffset()" function that will return the proper form that can be used at the call site. Either that or make these function something like "addSectionOffset". Probably prefer the latter, but I'd want that patch to be more uniform across all of the additions.

Make sense? That possible in the time you have?

keith.walker.arm updated this revision to Unknown Object (????).Nov 20 2013, 5:49 PM

From: Eric Christopher [mailto:echristo@gmail.com]
Comment at: lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp:234
@@ +233,3 @@
+ const MCSymbol *Label) {
+ if (DD->getDwarfVersion() >= 4)

+ addLabel(Die, Attribute, dwarf::DW_FORM_sec_offset, Label);

I do apologize for the lateness of this comment, but rather than bringing this
into addLabel I'd prefer we have a "getSectionOffset()" function that will return
the proper form that can be used at the call site. Either that or make these
function something like "addSectionOffset". Probably prefer the latter, but I'd
want that patch to be more uniform across all of the additions.

Make sense? That possible in the time you have?

I have updated the patch such that methods that use DW_FORM_sec_offset/DW_FORM_data4 are renames as follows:

addLabel() -> addSectionLabel()
addOffset() -> addSectionOffset()
addDelta() -> addSectionDelta()

Hopefully these changes are along the lines that make the usage clearer.

[I am on vacation this week so I am also bit slow responding :-) ]

I've gone ahead and applied this thusly (slightly modified):

M test/DebugInfo/X86/DW_AT_stmt_list_sec_offset.ll
M test/DebugInfo/X86/gnu-public-names.ll
M test/DebugInfo/X86/stmt-list-multiple-compile-units.ll
M test/DebugInfo/X86/op_deref.ll
M test/DebugInfo/X86/block-capture.ll
M lib/CodeGen/AsmPrinter/DIE.cpp
M lib/CodeGen/AsmPrinter/DwarfDebug.cpp
M lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
M lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
r195391 = 9e22df523d65f5200399bfe2dcdeeb900f75a054 (refs/remotes/origin/master)

FWIW llvm-dwarfdump does support dumping some locations but you'd have
to look at the actual debug_loc section to see if the right one
exists. Probably just need to fix the relocation handling and get the
addend in the relocation for DW_AT_location. It would be nice if that
was fixed for sure.

-eric

echristo closed this revision.Feb 25 2014, 3:44 PM

According to the comments I committed this.