<div dir="ltr">The order of those sections in memory does not matter. What needed is a way to tell the profile runtime where to find the start and end of the sections. On Linux, the linker defines symbols __start_<section_name> and __stop_<section_name>. If your linker does not do that, you can use linker script to provide the start and end:<div><br></div><div><div>  __start___llvm_prf_data = ADDR(__llvm_prf_data);</div><div>  __start___llvm_prf_data = ADDR(__llvm_prf_data) + SIZEOF(__llvm_prf_data);</div><div>...</div></div><div><br></div><div>David</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jul 25, 2017 at 1:04 AM, Martin J. O'Riordan <span dir="ltr"><<a href="mailto:MartinO@theheart.ie" target="_blank">MartinO@theheart.ie</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-IE" link="blue" vlink="purple"><div class="m_5060004228053837857WordSection1"><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black">Hi David,<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black">When I use CMake to configure, ‘</span><span style="font-family:"Courier New";color:black">zlib</span><span style="font-family:"Book Antiqua",serif;color:black">’ and its header are detected - I build on CentOS 6.5 or CentOS 7.  Since I run CMake from the command-line, I tried added ‘</span><span style="font-family:"Courier New";color:black">-DLLVM_ENABLE_ZLIB=0</span><span style="font-family:"Book Antiqua",serif;color:black">’ and ‘</span><span style="font-family:"Courier New";color:black">-DLLVM_ENABLE_ZLIB=1</span><span style="font-family:"Book Antiqua",serif;color:black">’ (using ‘</span><span style="font-family:"Courier New";color:black">-DLLVM_ENABLE_ZLIB=ON</span><span style="font-family:"Book Antiqua",serif;color:black">’ does not seem to work).  Both ‘</span><span style="font-family:"Courier New";color:black">clang</span><span style="font-family:"Book Antiqua",serif;color:black">’ and ‘</span><span style="font-family:"Courier New";color:black">llvm-profdata</span><span style="font-family:"Book Antiqua",serif;color:black">’ (and all other tools and utilities) are configured and built together, in any event, they are both built with ‘</span><span style="font-family:"Courier New";color:black">zlib</span><span style="font-family:"Book Antiqua",serif;color:black">’ enabled or ‘</span><span style="font-family:"Courier New";color:black">zlib</span><span style="font-family:"Book Antiqua",serif;color:black">’ disabled.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black">On Windows with VS2015 there is no ‘</span><span style="font-family:"Courier New";color:black">zlib</span><span style="font-family:"Book Antiqua",serif;color:black">’.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black">But I think that there is something different causing the problem, possibly in the linking.  When profiling instrumentation is enabled, there are 4 new sections introduced:<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">__llvm_prf_cnts<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">__llvm_prf_data<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">__llvm_prf_names<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">__llvm_prf_vnds<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black">Since our target is an heterogeneous multi-core embedded system, it requires the use of some elaborate linking techniques, and the LD scripts are carefully crafted for this purpose.  We use ‘</span><span style="font-family:"Courier New";color:black">ld</span><span style="font-family:"Book Antiqua",serif;color:black">’ from Binutils v2.28.  However, I do not know what these new sections mean to ‘</span><span style="font-family:"Courier New";color:black">llvm-profdata</span><span style="font-family:"Book Antiqua",serif;color:black">’ or how they should be laid out.  I cannot find any reference to these sections in any of the in-tree targets for Binutils or for LLVM-LLD, so there is no guidance or examples on how they should be collated and ordered, or how they should be placed in the memory-map.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black">What I did is added a very simple line to my existing LD script’s rule for collating ‘</span><span style="font-family:"Courier New";color:black">.data</span><span style="font-family:"Book Antiqua",serif;color:black">’ as:<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">SECTIONS<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">{<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">  ...<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">  .data:<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">    {<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">      ...<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">      *(__llvm_prf_*)<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">      ...<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">    }<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">  ...<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">}<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black">I’m guessing that this is too naïve and simplistic, and that something else is required, but I can’t find any sample LD scripts in either the LLD (v5.0) or Binutils (v2.28) sources.  I was considering replacing the line:<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">*(__llvm_prf_*)</span><span style="font-family:"Book Antiqua",serif;color:black"><u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black">with:<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">*(__llvm_prf_cnts)<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">*(__llvm_prf_data)<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">*(__llvm_prf_names)<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">*(__llvm_prf_vnds)</span><span style="font-family:"Book Antiqua",serif;color:black"><u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black">but without knowing what is required, this is still just a wild guess.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black">Any thoughts or recommendations on how these sections should be linked, and whether they need any special “</span><span style="font-family:"Courier New";color:black">PROVIDE</span><span style="font-family:"Book Antiqua",serif;color:black">” declarations?  Or “</span><span style="font-family:"Courier New";color:black">SORT</span><span style="font-family:"Book Antiqua",serif;color:black">” clauses?<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black">Thanks,<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black">            MartinO<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"><u></u> <u></u></span></p><div><div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0cm 0cm 0cm"><p class="MsoNormal"><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Martin J. O'Riordan [mailto:<a href="mailto:MartinO@theheart.ie" target="_blank">MartinO@theheart.ie</a>] <br><b>Sent:</b> 19 July 2017 15:56<br><b>To:</b> Xinliang David Li <<a href="mailto:xinliangli@gmail.com" target="_blank">xinliangli@gmail.com</a>><br><b>Cc:</b> llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br><b>Subject:</b> RE: [llvm-dev] PGO, zlib and 'default.profraw'<u></u><u></u></span></p></div></div><div><div class="h5"><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif">Thanks.  Yes, I build ‘clang’ and all the other tools and utilities together, so I am surprised that ‘clang’ would have ‘zlib’ enabled but not ‘llvm-profdata’.  I will get back to this when I return on Monday, and I have a suspicion I may be doing something else wrong that I will formulate and ask next week.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif">Thanks for your help,<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif">            MartinO<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif"><u></u> <u></u></span></p><p class="MsoNormal"><a name="m_5060004228053837857______replyseparator"></a><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> llvm-dev [<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">mailto:llvm-dev-bounces@<wbr>lists.llvm.org</a>] <b>On Behalf Of </b>Xinliang David Li via llvm-dev<br><b>Sent:</b> Tuesday, July 18, 2017 10:41 PM<br><b>To:</b> Martin J. O'Riordan <<a href="mailto:MartinO@theheart.ie" target="_blank">MartinO@theheart.ie</a>><br><b>Cc:</b> LLVM Developers <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br><b>Subject:</b> Re: [llvm-dev] PGO, zlib and 'default.profraw'<u></u><u></u></span></p><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal">set LLVM_ENABLE_ZLIB=ON with cmake invocation.  zlib should be installed and zlib.h header file needs to be in the header search path.<u></u><u></u></p><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">Is your llvm-profdata tool built together with clang? <u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">David<u></u><u></u></p></div></div><div><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal">On Tue, Jul 18, 2017 at 1:04 PM, Martin J. O'Riordan via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<u></u><u></u></p><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt"><p class="MsoNormal" style="margin-bottom:12.0pt">How can I build the profile reader with ZLIB support enabled?  I configure and build all the tools together with 'clang', so I would have expected that all or none support ZLIB, or is this a cross-compiler configuration specific issue?<br><br>Thanks,<br><br>        MartinO<br><br><span class="m_5060004228053837857im">-----Original Message-----</span><br><span class="m_5060004228053837857im">From: llvm-dev [mailto:<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@<wbr>lists.llvm.org</a>] On Behalf Of Justin Bogner via llvm-dev</span><br><span class="m_5060004228053837857im">Sent: 18 July 2017 19:37</span><br><span class="m_5060004228053837857im">To: Xinliang David Li via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span><br><span class="m_5060004228053837857im">Subject: Re: [llvm-dev] PGO, zlib and 'default.profraw'</span><u></u><u></u></p><div><div><p class="MsoNormal">Can we improve the error message here? We should be able to check zlib::isAvailable and give an error like "profile uses zlib compression but the profile reader was built without zlib support" or so in this case.<br><br>Xinliang David Li via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> writes:<br>> The __llvm_prf_names section is compressed but your llvm-profdata tool<br>> is probably not built with zlib enabled.<br>><br>> To disable compression, use option -mllvm<span style="color:#943634"> </span>-enable-name-compression=false<span style="color:#943634"><u></u><u></u></span></p><p class="MsoNormal"><span style="color:black">> </span>in your instrumentation build.<br>><br>> David<br>><br>> On Tue, Jul 18, 2017 at 7:05 AM, ORiordan, Martin via llvm-dev <<br>> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>><br>>> We are trying to get PGO working for our embedded out-of-tree target,<br>>> but the utility ‘llvm-profdata’ does not like the data we are giving it.<br>>><br>>><br>>><br>>> Because this is not a hosted environment, we have to off-chip the<br>>> profiling data ourselves, and although the data looks okay, ‘llvm-profdata’<br>>> reports the following error:<br>>><br>>><br>>><br>>> *llvm-profdata show -all-functions -counts -detailed-summary -text<br>>> -static-func-full-module-<wbr>prefix ~/Downloads/default.profraw*<br>>><br>>> error: ~/Downloads/default.profraw: Failed to uncompress data (zlib)<br>>><br>>><br>>><br>>> But even for a hosted system, it is not clear to me where ‘zlib’ gets<br>>> involved in compressing the data.  The start of our data looks like:<br>>><br>>><br>>><br>>> *hexdump -C default.profraw*<br>>><br>>> 00000000  81 52 66 6f 72 70 6c ff  04 00 00 00 00 00 00<br>>><br>>> 00  |.Rforpl.........|<br>>><br>>> 00000010  3c 00 00 00 00 00 00 00  28 01 00 00 00 00 00<br>>><br>>> 00  |<.......(.......|<br>>><br>>><br>>><br>>> Which looks valid for Little-Endian, 32-bit and LLVM v4.0.<br>>><br>>><br>>><br>>> What do we need to do to prepare this raw data from the device into<br>>> the form that ‘llvm-profdata’ needs to see?<br>>><br>>><br>>><br>>> Thanks,<br>>><br>>><br>>><br>>>             MartinO<br>>><br>>><br>>><br>>><br>>><br>>> ------------------------------<wbr>------------------------------<wbr>--<br>>> Intel Research and Development Ireland Limited Registered in Ireland<br>>> Registered Office: Collinstown Industrial Park, Leixlip, County<br>>> Kildare Registered Number: 308263<br>>><br>>> This e-mail and any attachments may contain confidential material for<br>>> the sole use of the intended recipient(s). Any review or distribution<br>>> by others is strictly prohibited. If you are not the intended<br>>> recipient, please contact the sender and delete all copies.<br>>><br>>><br>>> ______________________________<wbr>_________________<br>>> LLVM Developers mailing list<br>>> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>>><br>>><br>> ______________________________<wbr>_________________<br>> LLVM Developers mailing list<br>> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>______________________________<wbr>_________________<br>LLVM Developers mailing list<br><a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br><br>______________________________<wbr>_________________<br>LLVM Developers mailing list<br><a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><u></u><u></u></p></div></div></blockquote></div><p class="MsoNormal"><u></u> <u></u></p></div><p>------------------------------<wbr>------------------------------<wbr>--<br>Intel Research and Development Ireland Limited<br>Registered in Ireland<br>Registered Office: Collinstown Industrial Park, Leixlip, County Kildare<br>Registered Number: 308263<u></u><u></u></p><p>This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.<u></u><u></u></p></div></div></div></div></blockquote></div><br></div>