<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 8, 2015 at 1:10 PM, Frédéric Riss <span dir="ltr"><<a href="mailto:friss@apple.com" target="_blank">friss@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class=""><blockquote type="cite"><div>On Sep 8, 2015, at 12:24 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:</div><br><div><br><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div class="gmail_quote" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">On Mon, Aug 31, 2015 at 11:10 AM, Frédéric Riss<span> </span><span dir="ltr"><<a href="mailto:friss@apple.com" target="_blank">friss@apple.com</a>></span><span> </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"><div style="word-wrap:break-word"><br><div><span><blockquote type="cite"><div>On Aug 31, 2015, at 9:07 AM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:</div><br><div><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 31, 2015 at 9:05 AM, David Blaikie<span> </span><span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span><span> </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"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>On Sun, Aug 30, 2015 at 6:43 PM, Frederic Riss via llvm-commits<span> </span><span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span><span> </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">Author: friss<br>Date: Sun Aug 30 20:43:14 2015<br>New Revision: 246406<br><br>URL:<span> </span><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D246406-26view-3Drev&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=_sX2G1Du1KZyzi5BD4_ddw&m=FkrVlXa3-EdUHEUklJrpTIxLR2zDdr3ysgnj0hyNiNc&s=-yp_b9w-sonxhFICg6npPkz6_FLOw29qR_X8EIzjwWY&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=246406&view=rev</a><br>Log:<br>[dsymutil] Fix handling of inlined_subprogram low_pcs<br><br>The value of an inlined subprogram low_pc attribute should not<br>get relocated, but it can happen that it matches the enclosing<br>function's start address and thus gets the generic treatment.<br>Special case it to avoid applying the PC offset twice.<br></blockquote></span><div><br>I'm a tad confused - do you store the low_pcs as offsets relative to the function<br></div></div></div></div></blockquote><div><br>(sorry, bouncy shuttle to work & accidentally sent before I finished that sentence...)<br><br>do you store the low_pcs as offsets relative to the function's low_pc? That's interesting - and perhaps something we should standardize/generalize to reduce relocations in all our DWARF output (but I don't think there's any standard for it yet in DWARF), but I'm not sure why that would require special casing the case where the two low_pcs are equal - wouldn't that just mean the low_pc of the inlined subroutine would be at zero offset from the subprogram's low_pc? (& still not relocated)</div></div></div></div></div></blockquote><div><br></div></span><div>dsymutil takes the debug map as input that only contains the function (and variables) start addresses. That’s the only thing we can count on being exact. We then do a pass over all the debug_info relocations to find the ones that correspond to those addresses (and the DIEs where we find the ‘interesting’ relocations are the ones that define which part of the DIE tree we keep). Then — once we decided what to keep — we go over the kept DIEs and we clone them, applying the relocations in the process. But note that the relocations we’ve chosen are only for the entry points, thus we need to have the code around to handle the lexical_block/inlined_subroutine, and this code doesn’t use the relocations (it applies an offset that we computed when handling the subprogram DIE).</div><div><br></div><div>What  happened here is that the generic code that applied the relocations would also patch the inlined_subroutine low_pc because the relocation was the same as the entry point. And then the code handling the low_pc attributes for the inlined_subroutine would apply the offset a second time.</div></div></div></blockquote><div><br></div><div>OK - what I'm wondering is whether it would work better/as well to generalize this code, rather than two distinct passes/processes. </div></div></div></blockquote><div><br></div></span><div>I don’t think there’s a way to generalize this code. But I agree that storing the low_/high_pcs as offsets from their enclosing function low_pc would save quite a few relocations.</div></div></div></blockquote><div><br>Sorry, that wasn't what I was trying to describe, but it's certainly something we've discussed before (actually I made a silly prototype of using dwarf expressions and debug address pool indicies to do reloc sharing (using one reloc per section (macho would use one reloc per function, due to the implied function-sections like behavior) - never did get around to running good numbers on it, though)).<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div> Note that there is precedent for something like this: the ranges are encoded as offsets from the *CU* low_pc. Maybe it would be more natural to use that then?</div></div></div></blockquote><div><br></div><div>If we had a (probably/preferably compact) encoding to describe this, it would probably be ideal.<br><br>DWARF4 already has this /sort/ of thing for high_pc (where it can be encoded as a static offset relative to the low_pc - so it's not another relocation). That could possibly be generalized further to allow high_pcs to be a static offset relative to their enclosing high_pc (if one exists, otherwise it would be an unacceptable encoding (this could occur for functions - if the CU isn't a contiguous PC range (non-CU functions in between CU functions, functions in other sections, etc) or if a function itself is discontiguous (hot/cold code splitting)).<br><br>Eric & I have bandied that around now & then, which lead to the aforementioned prototype I played around with, but didn't go any further than that - my improvements to Clang's debug info emission had already brought it down to half the size of GCC's, so we didn't have any particular need to push further at the time.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><span class=""><br><blockquote type="cite"><div><div class="gmail_quote" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div>low_pc should just be a zero-offset relocation, right?<br></div></div></div></blockquote><div><br></div></span><div>Not on mach-o. Most relocations will be of the form __text+offset. That’s why there is no way for me to differentiate a __text+offset references the end of a range from the exact same relocation that references the beginning of another one (and as the linker can tear apart sections, that distinction is fundamental).</div></div></div></blockquote><div><br></div><div>OK, so you search through looking for a subprogram that has a subprogram low_pc at __text+offset? then assume all the other low/high pcs (and ranges) are relative to that function starting point? (this is how you remove the ambiguity of the start/end?)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><span class=""><br><blockquote type="cite"><div><div class="gmail_quote" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div>Maybe I'm not understanding/explaining very well, though.</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"><div style="word-wrap:break-word"><div><div>We might be able to completely remove any specific handling and just ‘promote’ all the relocations that fall inside a linked function as interesting. At the point we do that triaging relocs, we are not exploring the DIE tree though, just looking at the relocation list, so it would require us to trust the size field of the debug map, and I’m not sure we can do that 100% of the time (I know that this field is not accurate, it’s usually too big because it factors in alignment, but that might not be an issue if nothing gets allocated in the alignment padding).<br></div></div></div></blockquote><div><br></div><div>Hmm - not sure I follow this. You're suggesting that if a non-debug-aware tool applied the relocations in the object file/debug info, it would mangle/damage the debug info?<br></div></div></div></blockquote><div><br></div></span><div>Basically yes. As I explain above a relocation based off the __text section with a constant offset could be replaced by different values depending on the context. I already said that, but I guess the message is hard to get through: dsymutil uses the object file relocations to know what to link, but it doesn’t do relocation processing in the usual sense, because this simply wouldn’t work (More precisely, it tries to do as much standard relocation processing as possible, but it needs some code to workaround the cases where that logic gives the wrong result).</div></div></div></blockquote><div><br>It's slowly sinking in, I appreciate your patience in (repeatedly) explaining it to me.<br><br>- Dave<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><br></div>Fred</div><div><div class="h5"><div><br><blockquote type="cite"><div><div class="gmail_quote" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div>- David</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"><div style="word-wrap:break-word"><div><div></div><div><br></div><div>Fred </div><div><div><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><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"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </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>Added:<br>   <span> </span>llvm/trunk/test/tools/dsymutil/ARM/dummy-debug-map-amr64.map<br>   <span> </span>llvm/trunk/test/tools/dsymutil/ARM/inlined-low_pc.c<br>   <span> </span>llvm/trunk/test/tools/dsymutil/Inputs/inlined-low_pc/<br>   <span> </span>llvm/trunk/test/tools/dsymutil/Inputs/inlined-low_pc/1.o<br>Modified:<br>   <span> </span>llvm/trunk/test/tools/dsymutil/ARM/lit.local.cfg<br>   <span> </span>llvm/trunk/tools/dsymutil/DwarfLinker.cpp<br><br>Added: llvm/trunk/test/tools/dsymutil/ARM/dummy-debug-map-amr64.map<br>URL:<span> </span><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_test_tools_dsymutil_ARM_dummy-2Ddebug-2Dmap-2Damr64.map-3Frev-3D246406-26view-3Dauto&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=_sX2G1Du1KZyzi5BD4_ddw&m=FkrVlXa3-EdUHEUklJrpTIxLR2zDdr3ysgnj0hyNiNc&s=Za5qJ6LsFqNTEnS7lR9nOUQu3xiakQs49dpO89XaJg0&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/ARM/dummy-debug-map-amr64.map?rev=246406&view=auto</a><br>==============================================================================<br>--- llvm/trunk/test/tools/dsymutil/ARM/dummy-debug-map-amr64.map (added)<br>+++ llvm/trunk/test/tools/dsymutil/ARM/dummy-debug-map-amr64.map Sun Aug 30 20:43:14 2015<br>@@ -0,0 +1,15 @@<br>+# This is a dummy debug map used for some tests where the contents of the<br>+# map are just an implementation detail. The tests wanting to use that file<br>+# should put all there object files in an explicitely named sub-directory<br>+# of Inputs, and they should be named 1.o, 2.o, ...<br>+# As not finding an object file or symbols isn't a fatal error for dsymutil,<br>+# you can extend this file with as much object files and symbols as needed.<br>+<br>+---<br>+triple:          'arm64-apple-darwin'<br>+objects:<br>+  - filename: 1.o<br>+    symbols:<br>+      - { sym: _bar, objAddr: 0x0, binAddr: 0x10000, size: 0x10 }<br>+...<br>+<br><br>Added: llvm/trunk/test/tools/dsymutil/ARM/inlined-low_pc.c<br>URL:<span> </span><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_test_tools_dsymutil_ARM_inlined-2Dlow-5Fpc.c-3Frev-3D246406-26view-3Dauto&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=_sX2G1Du1KZyzi5BD4_ddw&m=FkrVlXa3-EdUHEUklJrpTIxLR2zDdr3ysgnj0hyNiNc&s=Q8OeSlNX91218xjgr3aIrN1U1Bssvnu-Nu8WzoX_nlI&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/ARM/inlined-low_pc.c?rev=246406&view=auto</a><br>==============================================================================<br>--- llvm/trunk/test/tools/dsymutil/ARM/inlined-low_pc.c (added)<br>+++ llvm/trunk/test/tools/dsymutil/ARM/inlined-low_pc.c Sun Aug 30 20:43:14 2015<br>@@ -0,0 +1,15 @@<br>+/* Compiled with: clang -arch=arm64 -O2 -g -c inlined_low_pc.c */<br>+<br>+static int foo(int i) { return 42 + i; }<br>+int bar(int a) { return foo(a); }<br>+<br>+// RUN: llvm-dsymutil -f -y %p/dummy-debug-map-amr64.map -oso-prepend-path %p/../Inputs/inlined-low_pc -o - | llvm-dwarfdump - | FileCheck %s<br>+<br>+// CHECK: DW_TAG_subprogram<br>+// CHECK: DW_AT_low_pc{{.*}}0x0000000000010000<br>+// CHECK: DW_AT_name{{.*}}"bar"<br>+// CHECK-NOT: NULL<br>+// CHECK: DW_TAG_inlined_subroutine<br>+// CHECK-NEXT: DW_AT_abstract_origin{{.*}}"foo"<br>+// CHECK-NEXT: DW_AT_low_pc{{.*}}0x0000000000010000<br>+<br><br>Modified: llvm/trunk/test/tools/dsymutil/ARM/lit.local.cfg<br>URL:<span> </span><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_test_tools_dsymutil_ARM_lit.local.cfg-3Frev-3D246406-26r1-3D246405-26r2-3D246406-26view-3Ddiff&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=_sX2G1Du1KZyzi5BD4_ddw&m=FkrVlXa3-EdUHEUklJrpTIxLR2zDdr3ysgnj0hyNiNc&s=zEAxxhhWFPrzEd5HWOml9qsDlLRCwN45LHyqj9f5wUc&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/ARM/lit.local.cfg?rev=246406&r1=246405&r2=246406&view=diff</a><br>==============================================================================<br>--- llvm/trunk/test/tools/dsymutil/ARM/lit.local.cfg (original)<br>+++ llvm/trunk/test/tools/dsymutil/ARM/lit.local.cfg Sun Aug 30 20:43:14 2015<br>@@ -2,3 +2,6 @@ if not 'ARM' in config.root.targets:<br>     config.unsupported = True<br> if not 'AArch64' in config.root.targets:<br>     config.unsupported = True<br>+<br>+config.suffixes = ['.test', '.cpp', '.c']<br>+<br><br>Added: llvm/trunk/test/tools/dsymutil/Inputs/inlined-low_pc/1.o<br>URL:<span> </span><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_test_tools_dsymutil_Inputs_inlined-2Dlow-5Fpc_1.o-3Frev-3D246406-26view-3Dauto&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=_sX2G1Du1KZyzi5BD4_ddw&m=FkrVlXa3-EdUHEUklJrpTIxLR2zDdr3ysgnj0hyNiNc&s=lY2aOkTZ45aHfHwE3xL8Amnff5hUDIrveaBrWrrNdnI&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/Inputs/inlined-low_pc/1.o?rev=246406&view=auto</a><br>==============================================================================<br>Binary files llvm/trunk/test/tools/dsymutil/Inputs/inlined-low_pc/1.o (added) and llvm/trunk/test/tools/dsymutil/Inputs/inlined-low_pc/1.o Sun Aug 30 20:43:14 2015 differ<br><br>Modified: llvm/trunk/tools/dsymutil/DwarfLinker.cpp<br>URL:<span> </span><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_tools_dsymutil_DwarfLinker.cpp-3Frev-3D246406-26r1-3D246405-26r2-3D246406-26view-3Ddiff&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=_sX2G1Du1KZyzi5BD4_ddw&m=FkrVlXa3-EdUHEUklJrpTIxLR2zDdr3ysgnj0hyNiNc&s=6xjIRngxynhJS54wLMKfMmHyjNR49UDteCNLX-SlUxI&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DwarfLinker.cpp?rev=246406&r1=246405&r2=246406&view=diff</a><br>==============================================================================<br>--- llvm/trunk/tools/dsymutil/DwarfLinker.cpp (original)<br>+++ llvm/trunk/tools/dsymutil/DwarfLinker.cpp Sun Aug 30 20:43:14 2015<br>@@ -1206,6 +1206,7 @@ private:<br>     const char *Name, *MangledName;         ///< Names.<br>     uint32_t NameOffset, MangledNameOffset; ///< Offsets in the string pool.<br><br>+    uint64_t OrigLowPc;  ///< Value of AT_low_pc in the input DIE<br>     uint64_t OrigHighPc; ///< Value of AT_high_pc in the input DIE<br>     int64_t PCOffset;    ///< Offset to apply to PC addresses inside a function.<br><br>@@ -1214,8 +1215,8 @@ private:<br><br>     AttributesInfo()<br>         : Name(nullptr), MangledName(nullptr), NameOffset(0),<br>-          MangledNameOffset(0), OrigHighPc(0), PCOffset(0), HasLowPc(false),<br>-          IsDeclaration(false) {}<br>+          MangledNameOffset(0), OrigLowPc(UINT64_MAX), OrigHighPc(0),<br>+          PCOffset(0), HasLowPc(false), IsDeclaration(false) {}<br>   };<br><br>   /// \brief Helper for cloneDIE.<br>@@ -2274,7 +2275,12 @@ unsigned DwarfLinker::cloneAddressAttrib<br>   if (AttrSpec.Attr == dwarf::DW_AT_low_pc) {<br>     if (Die.getTag() == dwarf::DW_TAG_inlined_subroutine ||<br>         Die.getTag() == dwarf::DW_TAG_lexical_block)<br>-      Addr += Info.PCOffset;<br>+      // The low_pc of a block or inline subroutine might get<br>+      // relocated because it happens to match the low_pc of the<br>+      // enclosing subprogram. To prevent issues with that, always use<br>+      // the low_pc from the input DIE if relocations have been applied.<br>+      Addr = (Info.OrigLowPc != UINT64_MAX ? Info.OrigLowPc : Addr) +<br>+             Info.PCOffset;<br>     else if (Die.getTag() == dwarf::DW_TAG_compile_unit) {<br>       Addr = Unit.getLowPc();<br>       if (Addr == UINT64_MAX)<br>@@ -2522,6 +2528,11 @@ DIE *DwarfLinker::cloneDIE(const DWARFDe<br>     // high_pc value is done in cloneAddressAttribute().<br>     AttrInfo.OrigHighPc =<br>         InputDIE.getAttributeValueAsAddress(&U, dwarf::DW_AT_high_pc, 0);<br>+    // Also store the low_pc. It might get relocated in an<br>+    // inline_subprogram that happens at the beginning of its<br>+    // inlining function.<br>+    AttrInfo.OrigLowPc =<br>+        InputDIE.getAttributeValueAsAddress(&U, dwarf::DW_AT_low_pc, UINT64_MAX);<br>   }<br><br>   // Reset the Offset to 0 as we will be working on the local copy of<br><br><br>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_llvm-2Dcommits&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=_sX2G1Du1KZyzi5BD4_ddw&m=FkrVlXa3-EdUHEUklJrpTIxLR2zDdr3ysgnj0hyNiNc&s=pIHV3NLou6W4R8NtF6A-1IkCPvKIdG-XzjtGugnY6Ts&e=" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a></blockquote></div></div></div></div></div></blockquote></div></div></div></div></blockquote></div></div></div></div></blockquote></div></div></blockquote></div><br></div></div></div></blockquote></div><br></div></div>