<div dir="ltr">For kernel PGO, you will probably need to invoke the buffer API to dump the profile data: __llvm_profile_write_buffer. Before that call, try to get the buffer size with __llvm_profile_get_size_for_buffer() and allocate memory with that size.<div><br></div><div>Note the buffer API will ignore value profile data, so you should also disable value profiling in build with --mllvm -disable-vp option to avoid the unsats at link time.</div><div><br></div><div>David</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 28, 2020 at 9:24 PM <<a href="mailto:mayi.rjpt@vivo.com">mayi.rjpt@vivo.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="ZH-CN"><div class="gmail-m_3152894027798263182WordSection1"><p class="MsoNormal"><span lang="EN-US" style="font-size:10.5pt;font-family:等线">Hi David, <u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10.5pt;font-family:等线"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10.5pt;font-family:等线">Thank you for replying! I have checked the symbol of libclang_rt.profile-<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10.5pt;font-family:等线">aarch64-android.a file. This archive library contains InstrProfilingValue.o <u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10.5pt;font-family:等线">as well as the symbol of '__llvm_profile_instrument_target' that i need(see <u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10.5pt;font-family:等线"><a href="https://pastebin.com/7LqpFtkP" target="_blank">https://pastebin.com/7LqpFtkP</a> ). So I have tried to add this archive <u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10.5pt;font-family:等线">library as a link-time library when building the Android kernel. But the <u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10.5pt;font-family:等线">error still remains. I think the Android kernel may not be able to call <u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10.5pt;font-family:等线">libraries outside the kernel source tree when linking and running. So I'm <u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10.5pt;font-family:等线">porting pgo-related files (compiler-rt/lib/profile/) from compiler-rt to <u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10.5pt;font-family:等线">Android kernel source tree. Is this the right and feasible way? <u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10.5pt;font-family:等线"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10.5pt;font-family:等线">Yi Ma</span><span lang="EN-US" style="font-size:10.5pt;font-family:Calibri,sans-serif"><u></u><u></u></span></p><div style="border-top:none;border-right:none;border-bottom:none;border-left:1.5pt solid blue;padding:0cm 0cm 0cm 4pt"><div><div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 0cm 0cm"><p class="MsoNormal"><b><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif">From:</span></b><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif"> Xinliang David Li <<a href="mailto:xinliangli@gmail.com" target="_blank">xinliangli@gmail.com</a>> <br><b>Sent:</b> Wednesday, April 29, 2020 1:09 AM<br><b>To:</b> Yi Ma <<a href="mailto:mayi.rjpt@vivo.com" target="_blank">mayi.rjpt@vivo.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] Android kernel PGO with LLVM<u></u><u></u></span></p></div></div><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><div><p class="MsoNormal"><span lang="EN-US">The entry point  is for value profiling and should be defined in InstrProfilingValue.o in the archive library. Can you check the symbol table of the .a file?<u></u><u></u></span></p><div><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US">David<u></u><u></u></span></p></div></div><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><div><div><p class="MsoNormal"><span lang="EN-US">On Tue, Apr 28, 2020 at 4:25 AM Yi Ma via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<u></u><u></u></span></p></div><blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin:5pt 0cm 5pt 4.8pt"><p class="MsoNormal"><span lang="EN-US">Hello, <br><br>I'm working on Android kernel profile-guided optimization to figure out <br>whether pgo can improve the performance of Android kernel. I have tried <br>to added '-fprofile-generate' option to build Android kernel(msm-4.19). <br>But error occurs during building: "undefined reference to <br>'__llvm_profile_instrument_target'". <br>I have tried to add libclang_rt.profile-aarch64-android.a as a library <br>when building Android kernel, but the error still shows up. I think the <br>kernel may not be able to call libraries outside the kernel source tree, <br>so I was porting pgo-related files(compiler-rt/lib/profile/) from <br>compiler-rt to Android kernel source tree. <br><br>Do you know why did this error occurs? And am I doing the right thing? <br>Is it possible to improve the performance of Android kernel with llvm <br>pgo mechanism?<br><br>Thanks,<br>Yi Ma<br><br>_______________________________________________<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="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><u></u><u></u></span></p></blockquote></div></div></div></div></blockquote></div>