Debug Info: according to DWARF 2, FORM_ref_addr the same size as an address on
[oota-llvm.git] / lib / CodeGen / AsmPrinter / DwarfDebug.cpp
index d3cb4f9c1c0ef179c4b7896c0082a6ef22a11534..b6b0bb1237cb894ab7c5dad4a2c4f79accdff686 100644 (file)
@@ -1791,7 +1791,14 @@ void DwarfDebug::emitDIE(DIE *Die, std::vector<DIEAbbrev *> *Abbrevs) {
         DwarfUnits &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
         Addr += Holder.getCUOffset(Origin->getCompileUnit());
       }
-      Asm->EmitInt32(Addr);
+      // DWARF4: References that use the attribute form DW_FORM_ref_addr are
+      // specified to be four bytes in the DWARF 32-bit format and eight bytes
+      // in the DWARF 64-bit format, while DWARF Version 2 specifies that such
+      // references have the same size as an address on the target system.
+      // Our current version is version 2.
+      Asm->OutStreamer.EmitIntValue(Addr,
+          Form == dwarf::DW_FORM_ref_addr ?
+          Asm->getDataLayout().getPointerSize() : 4);
       break;
     }
     case dwarf::DW_AT_ranges: {