<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Oct 4, 2013 at 9:41 AM, Eric Christopher <span dir="ltr"><<a href="mailto:echristo@gmail.com" target="_blank">echristo@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi Manman,<br>
<br>
In reviewing this code I've found a few problems with how you're<br>
emitting the debug info for ref_addr. It needs to be a relocatable<br>
value from the beginning of the section and while it's a reasonably<br>
straightforward change it is going to require some work to plumb I<br>
think. With this and the design discussions we've been going through<br>
with it I'm going to revert the patch for now and get you a testcase.<br></blockquote><div><br></div><div>To expound on this further we saw crashes in GDB. Here's a worked example demonstrating the problem:<br><br>
hdr.h:<br><font face="courier new, monospace">  struct foo {</font></div><div><font face="courier new, monospace">  }</font></div><div><br>tu1.cpp<br><font face="courier new, monospace">  #include "hdr.h"<br>  foo f;</font><br>
<br>tu2.cpp<br><font face="courier new, monospace">  #include "hdr.h"<br>  foo g;</font><br><br>tu3.cpp<br><font face="courier new, monospace">  int main() {<br>  }</font><br><br><font face="courier new, monospace">$ clang++ tu1.cpp tu2.cpp -g -emit-llvm -c<br>
$ llvm-link tu1.bc tu2.bc -o tu12.bc -S<br>$ llc -filetype=obj tu12.bc<br>$ clang++ tu3.cpp -g -c<br>$ clang++ tu3.o tu12.o<br>$ llvm-dwarfdump a.out<br></font><div><font face="courier new, monospace">.debug_info contents:</font></div>
<div><font face="courier new, monospace">0x00000000: Compile Unit: length = 0x00000047 version = 0x0004 abbr_offset = 0x0000 addr_size = 0x08 (next unit at 0x0000004b)</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace">0x0000000b: DW_TAG_compile_unit [1] *</font></div><div><font face="courier new, monospace">              DW_AT_producer [DW_FORM_strp]     ( .debug_str[0x00000000] = "clang version 3.4 ")</font></div>
<div><font face="courier new, monospace">              DW_AT_language [DW_FORM_data2]    (0x0004)</font></div><div><font face="courier new, monospace">              DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000013] = "tu3.cpp")</font></div>
<div><font face="courier new, monospace">              DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)</font></div><div><font face="courier new, monospace">              DW_AT_stmt_list [DW_FORM_sec_offset]      (0x00000000)</font></div>
<div><font face="courier new, monospace">              DW_AT_comp_dir [DW_FORM_strp]     ( .debug_str[0x0000001b] = "/tmp/dbginfo")</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span style="background-color:rgb(255,255,0)">0x00000026</span>:   DW_TAG_subprogram [2]  </font></div>
<div><font face="courier new, monospace">                DW_AT_name [DW_FORM_strp]       ( .debug_str[0x00000028] = "main")</font></div><div><font face="courier new, monospace">                DW_AT_decl_file [DW_FORM_data1] (0x01)</font></div>
<div><font face="courier new, monospace">                DW_AT_decl_line [DW_FORM_data1] (0x01)</font></div><div><font face="courier new, monospace">                DW_AT_type [DW_FORM_ref4]       (cu + 0x0043 => {0x00000043})</font></div>
<div><font face="courier new, monospace">                DW_AT_external [DW_FORM_flag_present]   (true)</font></div><div><font face="courier new, monospace">                DW_AT_low_pc [DW_FORM_addr]     (0x0000000000400590)</font></div>
<div><font face="courier new, monospace">                DW_AT_high_pc [DW_FORM_addr]    (0x000000000040059b)</font></div><div><font face="courier new, monospace">                DW_AT_frame_base [DW_FORM_block1]       (<0x01> 56 )</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">0x00000043:   DW_TAG_base_type [3]  </font></div><div><font face="courier new, monospace">                DW_AT_name [DW_FORM_strp]       ( .debug_str[0x0000002d] = "int")</font></div>
<div><font face="courier new, monospace">                DW_AT_encoding [DW_FORM_data1]  (0x05)</font></div><div><font face="courier new, monospace">                DW_AT_byte_size [DW_FORM_data1] (0x04)</font></div><div>
<font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">0x0000004a:   NULL</font></div><div><font face="courier new, monospace">0x0000004b: Compile Unit: length = 0x00000040 version = 0x0004 abbr_offset = 0x0032 addr_size = 0x08 (next unit at 0x0000008f)</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">0x00000056: DW_TAG_compile_unit [1] *</font></div><div><font face="courier new, monospace">              DW_AT_producer [DW_FORM_strp]     ( .debug_str[0x00000000] = "clang version 3.4 ")</font></div>
<div><font face="courier new, monospace">              DW_AT_language [DW_FORM_data2]    (0x0004)</font></div><div><font face="courier new, monospace">              DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000031] = "tu1.cpp")</font></div>
<div><font face="courier new, monospace">              DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)</font></div><div><font face="courier new, monospace">              DW_AT_stmt_list [DW_FORM_sec_offset]      (0x0000003b)</font></div>
<div><font face="courier new, monospace">              DW_AT_comp_dir [DW_FORM_strp]     ( .debug_str[0x0000001b] = "/tmp/dbginfo")</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">0x00000071:   DW_TAG_structure_type [2]  </font></div>
<div><font face="courier new, monospace">                DW_AT_name [DW_FORM_strp]       ( .debug_str[0x0000003b] = "foo")</font></div><div><font face="courier new, monospace">                DW_AT_byte_size [DW_FORM_data1] (0x01)</font></div>
<div><font face="courier new, monospace">                DW_AT_decl_file [DW_FORM_data1] (0x02)</font></div><div><font face="courier new, monospace">                DW_AT_decl_line [DW_FORM_data1] (0x01)</font></div><div>
<font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">0x00000079:   DW_TAG_variable [3]  </font></div><div><font face="courier new, monospace">                DW_AT_name [DW_FORM_strp]       ( .debug_str[0x00000039] = "f")</font></div>
<div><font face="courier new, monospace">                DW_AT_type [DW_FORM_ref4]       (cu + 0x0026 => {0x00000071})</font></div><div><font face="courier new, monospace">                DW_AT_external [DW_FORM_flag_present]   (true)</font></div>
<div><font face="courier new, monospace">                DW_AT_decl_file [DW_FORM_data1] (0x01)</font></div><div><font face="courier new, monospace">                DW_AT_decl_line [DW_FORM_data1] (0x02)</font></div><div>
<font face="courier new, monospace">                DW_AT_location [DW_FORM_block1] (<0x09> 03 2c 20 40 00 00 00 00 00 )</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">0x0000008e:   NULL</font></div>
<div><font face="courier new, monospace">0x0000008f: Compile Unit: length = 0x00000038 version = 0x0004 abbr_offset = 0x0032 addr_size = 0x08 (next unit at 0x000000cb)</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace">0x0000009a: DW_TAG_compile_unit [1] *</font></div><div><font face="courier new, monospace">              DW_AT_producer [DW_FORM_strp]     ( .debug_str[0x00000000] = "clang version 3.4 ")</font></div>
<div><font face="courier new, monospace">              DW_AT_language [DW_FORM_data2]    (0x0004)</font></div><div><font face="courier new, monospace">              DW_AT_name [DW_FORM_strp] ( .debug_str[0x0000003f] = "tu2.cpp")</font></div>
<div><font face="courier new, monospace">              DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)</font></div><div><font face="courier new, monospace">              DW_AT_stmt_list [DW_FORM_sec_offset]      (0x0000003b)</font></div>
<div><font face="courier new, monospace">              DW_AT_comp_dir [DW_FORM_strp]     ( .debug_str[0x0000001b] = "/tmp/dbginfo")</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">0x000000b5:   DW_TAG_variable [4]  </font></div>
<div><font face="courier new, monospace">                DW_AT_name [DW_FORM_strp]       ( .debug_str[0x00000047] = "g")</font></div><div><font face="courier new, monospace">                DW_AT_external [DW_FORM_flag_present]   (true)</font></div>
<div><font face="courier new, monospace">                DW_AT_decl_file [DW_FORM_data1] (0x03)</font></div><div><font face="courier new, monospace">                DW_AT_decl_line [DW_FORM_data1] (0x02)</font></div><div>
<font face="courier new, monospace">                DW_AT_location [DW_FORM_block1] (<0x09> 03 2d 20 40 00 00 00 00 00 )</font></div><div><font face="courier new, monospace">                DW_AT_type [DW_FORM_ref_addr]   (<span style="background-color:rgb(255,255,0)">0x0000000000000026</span>)</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">0x000000ca:   NULL</font></div><br>So, while the type of the variable 'g' in tu2.cpp should be 'foo' (offset 0x71) it instead refers to the DIE for the main function in tu3.cpp. (this gets even worse, of course, once the DIEs don't line up - and the offset might not even point to the start of a DIE, but instead to some attribute or portion of an attribute).<br>
<br>Does this help/make sense?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
This is a good idea for work and is something I definitely want us to<br>
pursue in the long run (or immediate term depending on your<br>
priorities) so don't look at this as anything more than me needing to<br>
revert due to a bug.<br>
<br>
Thanks!<br>
<span class=""><font color="#888888"><br>
-eric<br>
</font></span><div class=""><div class="h5"><br>
<br>
On Thu, Oct 3, 2013 at 8:50 PM, Manman Ren <<a href="mailto:manman.ren@gmail.com">manman.ren@gmail.com</a>> wrote:<br>
><br>
><br>
><br>
> On Thu, Oct 3, 2013 at 4:24 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
>><br>
>><br>
>><br>
>><br>
>> On Thu, Oct 3, 2013 at 4:10 PM, Manman Ren <<a href="mailto:manman.ren@gmail.com">manman.ren@gmail.com</a>> wrote:<br>
>>><br>
>>><br>
>>><br>
>>><br>
>>> On Thu, Oct 3, 2013 at 2:06 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
>>>><br>
>>>><br>
>>>>>> 3GB memory reduction for xalan built with lto -g (without removing DIE<br>
>>>>>> duplication, the memory usage is 7GB)<br>
>>>>><br>
>>>>><br>
>>>>> OK, so you're looking at memory usage during LTO, not the size of the<br>
>>>>> resulting debug info? (that's fine, just trying to understand exactly what<br>
>>>>> metrics you're targeting)<br>
>>>><br>
>>>><br>
>>>> One thought I had (and just discussed with Eric - he seemed to think it<br>
>>>> was plausible, at least):<br>
>>>><br>
>>>> If you're interested in reducing peak memory usage of LLVM during LTO,<br>
>>>> have you considered modifying debug info generation not to cache all the<br>
>>>> compile_units before emitting them? If we emitted one CU at a time as they<br>
>>>> were created I imagine the memory footprint would be much lower.<br>
>>><br>
>>><br>
>>> Yes, that is on my todo list after type uniquing is done.<br>
>><br>
>><br>
>> So, as I said, I think it might be better to do that work first. It may<br>
>> have a substantial impact on cross-CU references. (see below)<br>
>><br>
>>><br>
>>> Right now, we don't release any memory and we have layers of memory usage<br>
>>> related to debug info: MDNodes, DIEs and some data in MC layer.<br>
>>>  All these layers exist for the whole program with LTO.<br>
>>><br>
>>>><br>
>>>> (and we could still, potentially, add the type cross-referencing by just<br>
>>>> caching the section offsets or labels, etc, of the types emitted in prior<br>
>>>> units - though that wouldn't be perfect for types that contain some members<br>
>>>> (implicit special members) in one CU and a different set of members in<br>
>>>> another CU (and it'll be a bit trickier for type units - we'd need to cache<br>
>>>> any subgraph of potentially self-referencing type units until all the<br>
>>>> signatures are resolved, then they could all be emitted))<br>
>>>><br>
>>>> This isn't necessarily a place you should start with - I can appreciate<br>
>>>> that your current approach is probably higher value to you for lower<br>
>>>> engineering cost (and thus gets you closer sooner) but if it's still not<br>
>>>> going to be sufficient for your needs, especially if you're going to have to<br>
>>>> implement something like emit-CU-at-a-time as I describe above anyway, it<br>
>>>> might be more valuable to lay that foundation first.<br>
>>><br>
>>><br>
>>> Even if we emit one CU at a time, it is still good to share the types<br>
>>> across-CU so we don't waist time constructing the type DIEs for each CU, and<br>
>>> this approach (remove DIE duplication) also reduces the raw DWARF size.<br>
>><br>
>><br>
>> I agree, from an output size perspective we'll still want to share DIEs<br>
>> across CUs - but I think you might see bigger memory footprint (since that's<br>
>> the stat you're aiming at at the moment) wins from this change, but more<br>
>> importantly - I think a change like that will have a significant impact on a<br>
>> feature like the cross-CU DIE referencing you're doing here.<br>
>><br>
>> If we emit one CU at a time, cross-CU DIE references will look very<br>
>> different - it won't be simply a matter of getting a DIE from the cross-CU<br>
>> map anymore. Likely we'll want to store a much more minimal form of the DIE<br>
>> (just it's section offset or label) in a table once the prior CU has been<br>
>> emitted. Then when a future CU is emitted and wants to reference that, we<br>
>> can lookup that remnant in the table - the whole DIE won't exist anymore.<br>
><br>
><br>
> With "emit-a-CU-at-a-time", we can still keep the type DIEs around since<br>
> they are going to be shared across CUs.<br>
> We can also store a minimal form of the type DIEs to further reduce the<br>
> memory footprint.<br>
><br>
> I agree that we have to change the cross-CU references when we only store a<br>
> minimal form of the type DIEs. But the change should<br>
> not be complicated, we now store a map from MDNode to DIE, and that can be<br>
> changed to map from MDNode to MinimalDIE.<br>
><br>
> "emit-a-CU-at-a-time" is a known solution to reduce memory footprint, but I<br>
> don't have a time line for when I will work on it.<br>
><br>
>><br>
>><br>
>> It seems like the bigger change should go first so we don't avoid<br>
>> discussing a lot of this design only to have to rework it substantially when<br>
>> we emit a CU-at-a-time.<br>
><br>
> Since we already did a lot of discussion about this design and it is not<br>
> complicated (about 30 to 40 lines of code), let's discuss<br>
> "emit-a-CU-at-a-time" when it is somebody's immediate task.<br>
><br>
> Thanks,<br>
> Manman<br>
><br>
>><br>
>>><br>
>>><br>
>>>><br>
>>>><br>
>>>> If not, I'd still probably like to discuss the design of the cross-CU<br>
>>>> referencing work you have here to decide on the right design in a normal<br>
>>>> patch review process rather than trying to think about how the current code<br>
>>>> can be morphed into a better design.<br>
>>><br>
>>><br>
>>> What other designs do you have in mind?<br>
>><br>
>><br>
>> Just some of the stuff we've already been discussing such as merging the<br>
>> maps and simplifying the DwarfDebug entry points. But if you're already<br>
>> planning to do CU-at-a-time, I wonder whether it's worth discussing the<br>
>> design of cross-CU references before we do CU-at-a-time - it seems to me<br>
>> like the implementation would change quite significantly.<br>
>><br>
>>><br>
>>><br>
>>> Manman<br>
>>>><br>
>>>><br>
>>>><br>
>>>> - David<br>
>>><br>
>>><br>
>><br>
><br>
</div></div></blockquote></div><br></div></div>