<p dir="ltr"><br>
On Jul 3, 2013 5:35 PM, "Eric Christopher" <<a href="mailto:echristo@gmail.com">echristo@gmail.com</a>> wrote:<br>
><br>
> On Wed, Jul 3, 2013 at 5:29 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
> ><br>
> > On Jul 2, 2013 7:06 PM, "Manman Ren" <<a href="mailto:mren@apple.com">mren@apple.com</a>> wrote:<br>
> >><br>
> >> Author: mren<br>
> >> Date: Tue Jul 2 18:40:10 2013<br>
> >> New Revision: 185484<br>
> >><br>
> >> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=185484&view=rev">http://llvm.org/viewvc/llvm-project?rev=185484&view=rev</a><br>
> >> Log:<br>
> >> Debug Info: use module flag to set up Dwarf version.<br>
> >><br>
> >> Correctly handles ref_addr depending on the Dwarf version. Emit Dwarf with<br>
> >> version from module flag.<br>
> >><br>
> >> TODO: turn on/off features depending on the Dwarf version.<br>
> >><br>
> >> Added:<br>
> >> llvm/trunk/test/DebugInfo/version.ll<br>
> >> Modified:<br>
> >> llvm/trunk/include/llvm/CodeGen/AsmPrinter.h<br>
> >> llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp<br>
> >> llvm/trunk/lib/CodeGen/AsmPrinter/DIE.h<br>
> >> llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp<br>
> >> llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h<br>
> >><br>
> >> Modified: llvm/trunk/include/llvm/CodeGen/AsmPrinter.h<br>
> >> URL:<br>
> >> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=185484&r1=185483&r2=185484&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=185484&r1=185483&r2=185484&view=diff</a><br>
> >><br>
> >> ==============================================================================<br>
> >> --- llvm/trunk/include/llvm/CodeGen/AsmPrinter.h (original)<br>
> >> +++ llvm/trunk/include/llvm/CodeGen/AsmPrinter.h Tue Jul 2 18:40:10 2013<br>
> >> @@ -121,6 +121,8 @@ namespace llvm {<br>
> >> public:<br>
> >> virtual ~AsmPrinter();<br>
> >><br>
> >> + const DwarfDebug *getDwarfDebug() const { return DD; }<br>
> >> +<br>
> >> /// isVerbose - Return true if assembly output should contain<br>
> >> comments.<br>
> >> ///<br>
> >> bool isVerbose() const { return VerboseAsm; }<br>
> >><br>
> >> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp<br>
> >> URL:<br>
> >> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp?rev=185484&r1=185483&r2=185484&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp?rev=185484&r1=185483&r2=185484&view=diff</a><br>
> >><br>
> >> ==============================================================================<br>
> >> --- llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp (original)<br>
> >> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp Tue Jul 2 18:40:10 2013<br>
> >> @@ -12,6 +12,7 @@<br>
> >><br>
> >> //===----------------------------------------------------------------------===//<br>
> >><br>
> >> #include "DIE.h"<br>
> >> +#include "DwarfDebug.h"<br>
> >> #include "llvm/ADT/Twine.h"<br>
> >> #include "llvm/CodeGen/AsmPrinter.h"<br>
> >> #include "llvm/IR/DataLayout.h"<br>
> >> @@ -331,6 +332,16 @@ void DIEEntry::EmitValue(AsmPrinter *AP,<br>
> >> AP->EmitInt32(Entry->getOffset());<br>
> >> }<br>
> >><br>
> >> +unsigned DIEEntry::getRefAddrSize(AsmPrinter *AP) {<br>
> >> + // DWARF4: References that use the attribute form DW_FORM_ref_addr are<br>
> >> + // specified to be four bytes in the DWARF 32-bit format and eight<br>
> >> bytes<br>
> >> + // in the DWARF 64-bit format, while DWARF Version 2 specifies that<br>
> >> such<br>
> >> + // references have the same size as an address on the target system.<br>
> >> + if (AP->getDwarfDebug()->getDwarfVersion() == 2)<br>
> >> + return AP->getDataLayout().getPointerSize();<br>
> >> + return sizeof(int32_t);<br>
> >> +}<br>
> ><br>
> > This seems like a slightly strange place for this function - it also doesn't<br>
> > need any access to private members of DIEEntry. As it's a generic debug info<br>
> > utility function, could it go somewhere more central than DIEEntry? (If its<br>
> > needed from other places, which it seems to be)<br>
> ><br>
> >> +<br>
> >> #ifndef NDEBUG<br>
> >> void DIEEntry::print(raw_ostream &O) const {<br>
> >> O << format("Die: 0x%lx", (long)(intptr_t)Entry);<br>
> >><br>
> >> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DIE.h<br>
> >> URL:<br>
> >> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DIE.h?rev=185484&r1=185483&r2=185484&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DIE.h?rev=185484&r1=185483&r2=185484&view=diff</a><br>
> >><br>
> >> ==============================================================================<br>
> >> --- llvm/trunk/lib/CodeGen/AsmPrinter/DIE.h (original)<br>
> >> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DIE.h Tue Jul 2 18:40:10 2013<br>
> >> @@ -365,9 +365,13 @@ namespace llvm {<br>
> >> /// SizeOf - Determine size of debug information entry in bytes.<br>
> >> ///<br>
> >> virtual unsigned SizeOf(AsmPrinter *AP, unsigned Form) const {<br>
> >> - return sizeof(int32_t);<br>
> >> + return Form == dwarf::DW_FORM_ref_addr ? getRefAddrSize(AP) :<br>
> >> + sizeof(int32_t);<br>
> >> }<br>
> >><br>
> >> + /// Returns size of a ref_addr entry.<br>
> >> + static unsigned getRefAddrSize(AsmPrinter *AP);<br>
> >> +<br>
> >> // Implement isa/cast/dyncast.<br>
> >> static bool classof(const DIEValue *E) { return E->getType() ==<br>
> >> isEntry; }<br>
> >><br>
> >><br>
> >> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp<br>
> >> URL:<br>
> >> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=185484&r1=185483&r2=185484&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=185484&r1=185483&r2=185484&view=diff</a><br>
> >><br>
> >> ==============================================================================<br>
> >> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)<br>
> >> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Tue Jul 2 18:40:10<br>
> >> 2013<br>
> >> @@ -162,6 +162,21 @@ DIType DbgVariable::getType() const {<br>
> >><br>
> >> } // end llvm namespace<br>
> >><br>
> >> +/// Return Dwarf Version by checking module flags.<br>
> >> +static unsigned getDwarfVersionFromModule(const Module *M) {<br>
> >> + SmallVector<Module::ModuleFlagEntry, 8> ModuleFlags;<br>
> >> + M->getModuleFlagsMetadata(ModuleFlags);<br>
> >> + for (unsigned I = 0, E = ModuleFlags.size(); I < E; ++I) {<br>
> >> + const Module::ModuleFlagEntry &MFE = ModuleFlags[I];<br>
> >> + StringRef Key = MFE.Key->getString();<br>
> >> + Value *Val = MFE.Val;<br>
> >> +<br>
> >> + if (Key == "Dwarf Version")<br>
> >> + return cast<ConstantInt>(Val)->getZExtValue();<br>
> >> + }<br>
> >> + return dwarf::DWARF_VERSION;<br>
> ><br>
> > Do we not have a better way to query module flags? Perhaps we should add<br>
> > one?<br>
> ><br>
> > Is there any need to support debug info generation for modules that lack<br>
> > this flag? Seems we could just consider that to be invalid?<br>
> ><br>
><br>
> Icky. Either we need to autoupgrade modules that come in to specify a<br>
> dwarf version or leave this sort of thing around. Admittedly if we<br>
> stored it in the CU we could call it an incompatible debug info change<br>
> :)</p>
<p dir="ltr">I think we could still make that claim even if its a module flag. If you have debug info metadata and no flag: invalid. If you don't have any debug info metadata, we shouldn't care what the flag value is,</p>
<p dir="ltr">><br>
> -eric<br>
><br>
> >> +}<br>
> >> +<br>
> >> DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)<br>
> >> : Asm(A), MMI(Asm->MMI), FirstCU(0),<br>
> >> AbbreviationsSet(InitAbbreviationsSetSize),<br>
> >> @@ -204,6 +219,8 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Mo<br>
> >> else<br>
> >> HasSplitDwarf = SplitDwarf == Enable ? true : false;<br>
> >><br>
> >> + DwarfVersion = getDwarfVersionFromModule(MMI->getModule());<br>
> >> +<br>
> >> {<br>
> >> NamedRegionTimer T(DbgTimerName, DWARFGroupName,<br>
> >> TimePassesIsEnabled);<br>
> >> beginModule();<br>
> >> @@ -1900,7 +1917,8 @@ void DwarfDebug::emitDIE(DIE *Die, std::<br>
> >> DwarfUnits &Holder = useSplitDwarf() ? SkeletonHolder :<br>
> >> InfoHolder;<br>
> >> Addr += Holder.getCUOffset(Origin->getCompileUnit());<br>
> >> }<br>
> >> - Asm->EmitInt32(Addr);<br>
> >> + Asm->OutStreamer.EmitIntValue(Addr,<br>
> >> + Form == dwarf::DW_FORM_ref_addr ? DIEEntry::getRefAddrSize(Asm)<br>
> >> : 4);<br>
> >> break;<br>
> >> }<br>
> >> case dwarf::DW_AT_ranges: {<br>
> >> @@ -1984,7 +2002,7 @@ void DwarfUnits::emitUnits(DwarfDebug *D<br>
> >> Asm->OutStreamer.AddComment("Length of Compilation Unit Info");<br>
> >> Asm->EmitInt32(ContentSize);<br>
> >> Asm->OutStreamer.AddComment("DWARF version number");<br>
> >> - Asm->EmitInt16(dwarf::DWARF_VERSION);<br>
> >> + Asm->EmitInt16(DD->getDwarfVersion());<br>
> >> Asm->OutStreamer.AddComment("Offset Into Abbrev. Section");<br>
> >><br>
> >> Asm->EmitSectionOffset(Asm->GetTempSymbol(ASection->getLabelBeginName()),<br>
> >> ASectionSym);<br>
> >> @@ -2225,7 +2243,7 @@ void DwarfDebug::emitDebugPubnames() {<br>
> >> Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubnames_begin", ID));<br>
> >><br>
> >> Asm->OutStreamer.AddComment("DWARF Version");<br>
> >> - Asm->EmitInt16(dwarf::DWARF_VERSION);<br>
> >> + Asm->EmitInt16(DwarfVersion);<br>
> >><br>
> >> Asm->OutStreamer.AddComment("Offset of Compilation Unit Info");<br>
> >> Asm->EmitSectionOffset(Asm->GetTempSymbol(ISec->getLabelBeginName(),<br>
> >> ID),<br>
> >> @@ -2272,7 +2290,7 @@ void DwarfDebug::emitDebugPubTypes() {<br>
> >> TheCU->getUniqueID()));<br>
> >><br>
> >> if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DWARF Version");<br>
> >> - Asm->EmitInt16(dwarf::DWARF_VERSION);<br>
> >> + Asm->EmitInt16(DwarfVersion);<br>
> >><br>
> >> Asm->OutStreamer.AddComment("Offset of Compilation Unit Info");<br>
> >> const MCSection *ISec =<br>
> >> Asm->getObjFileLowering().getDwarfInfoSection();<br>
> >> @@ -2553,7 +2571,7 @@ void DwarfDebug::emitDebugInlineInfo() {<br>
> >> Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_inlined_begin",<br>
> >> 1));<br>
> >><br>
> >> Asm->OutStreamer.AddComment("Dwarf Version");<br>
> >> - Asm->EmitInt16(dwarf::DWARF_VERSION);<br>
> >> + Asm->EmitInt16(DwarfVersion);<br>
> >> Asm->OutStreamer.AddComment("Address Size (in bytes)");<br>
> >> Asm->EmitInt8(Asm->getDataLayout().getPointerSize());<br>
> >><br>
> >><br>
> >> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h<br>
> >> URL:<br>
> >> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=185484&r1=185483&r2=185484&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=185484&r1=185483&r2=185484&view=diff</a><br>
> >><br>
> >> ==============================================================================<br>
> >> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)<br>
> >> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Tue Jul 2 18:40:10<br>
> >> 2013<br>
> >> @@ -407,6 +407,8 @@ class DwarfDebug {<br>
> >> bool HasDwarfAccelTables;<br>
> >> bool HasSplitDwarf;<br>
> >><br>
> >> + unsigned DwarfVersion;<br>
> >> +<br>
> >> // Separated Dwarf Variables<br>
> >> // In general these will all be for bits that are left in the<br>
> >> // original object file, rather than things that are meant<br>
> >> @@ -650,6 +652,9 @@ public:<br>
> >> /// \brief Returns whether or not to change the current debug info for<br>
> >> the<br>
> >> /// split dwarf proposal support.<br>
> >> bool useSplitDwarf() { return HasSplitDwarf; }<br>
> >> +<br>
> >> + /// Returns the Dwarf Version.<br>
> >> + unsigned getDwarfVersion() const { return DwarfVersion; }<br>
> >> };<br>
> >> } // End of namespace llvm<br>
> >><br>
> >><br>
> >> Added: llvm/trunk/test/DebugInfo/version.ll<br>
> >> URL:<br>
> >> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/version.ll?rev=185484&view=auto">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/version.ll?rev=185484&view=auto</a><br>
> >><br>
> >> ==============================================================================<br>
> >> --- llvm/trunk/test/DebugInfo/version.ll (added)<br>
> >> +++ llvm/trunk/test/DebugInfo/version.ll Tue Jul 2 18:40:10 2013<br>
> >> @@ -0,0 +1,27 @@<br>
> >> +; RUN: llc -O0 < %s | FileCheck %s<br>
> >> +; Make sure we are generating DWARF version 3 when module flag says so.<br>
> >> +; CHECK: .short 3 ## DWARF version number<br>
> >> +<br>
> >> +define i32 @main() #0 {<br>
> >> +entry:<br>
> >> + %retval = alloca i32, align 4<br>
> >> + store i32 0, i32* %retval<br>
> >> + ret i32 0, !dbg !10<br>
> >> +}<br>
> >> +<br>
> >> +attributes #0 = { nounwind uwtable "less-precise-fpmad"="false"<br>
> >> "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"="true"<br>
> >> "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false"<br>
> >> "use-soft-float"="false" }<br>
> >> +<br>
> >> +!<a href="http://llvm.dbg.cu">llvm.dbg.cu</a> = !{!0}<br>
> >> +!llvm.module.flags = !{!9}<br>
> >> +<br>
> >> +!0 = metadata !{i32 786449, metadata !1, i32 12, metadata !"clang version<br>
> >> 3.4 (trunk 185475)", i1 false, metadata !"", i32 0, metadata !2, metadata<br>
> >> !2, metadata !3, metadata !2, metadata !2, metadata !""} ; [<br>
> >> DW_TAG_compile_unit ]<br>
> >> +!1 = metadata !{metadata !"CodeGen/dwarf-version.c", metadata !"test"}<br>
> >> +!2 = metadata !{i32 0}<br>
> >> +!3 = metadata !{metadata !4}<br>
> >> +!4 = metadata !{i32 786478, metadata !1, metadata !5, metadata !"main",<br>
> >> metadata !"main", metadata !"", i32 6, metadata !6, i1 false, i1 true, i32<br>
> >> 0, i32 0, null, i32 256, i1 false, i32 ()* @main, null, null, metadata !2,<br>
> >> i32 6} ; [ DW_TAG_subprogram ] [line 6] [def] [main]<br>
> >> +!5 = metadata !{i32 786473, metadata !1} ; [ DW_TAG_file_type ]<br>
> >> +!6 = metadata !{i32 786453, i32 0, i32 0, metadata !"", i32 0, i64 0, i64<br>
> >> 0, i64 0, i32 0, null, metadata !7, i32 0, i32 0} ; [ DW_TAG_subroutine_type<br>
> >> ] [line 0, size 0, align 0, offset 0] [from ]<br>
> >> +!7 = metadata !{metadata !8}<br>
> >> +!8 = metadata !{i32 786468, null, null, metadata !"int", i32 0, i64 32,<br>
> >> i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ] [int] [line 0, size 32,<br>
> >> align 32, offset 0, enc DW_ATE_signed]<br>
> >> +!9 = metadata !{i32 2, metadata !"Dwarf Version", i32 3}<br>
> >> +!10 = metadata !{i32 7, i32 0, metadata !4, null}<br>
> >><br>
> >><br>
> >> _______________________________________________<br>
> >> llvm-commits mailing list<br>
> >> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> >> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
> ><br>
> ><br>
> > _______________________________________________<br>
> > llvm-commits mailing list<br>
> > <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
> ><br>
</p>