<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">While investigating an issue with android build performance, I found that llvm-objcopy performance is far from parity with GNU objcopy for the “--keep-symbols” case, when the keep symbols list is very large.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I can see that llvm objcopy creates a list of NameOrPattern-s to represent the keep symbol list, but it looks like it exhaustively compares each symbol in the keep list against each symbol in the input file. Not sure what GNU objcopy does
but merging the non-pattern symbol names into a sorted list would make searching much faster.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Below is a script to reproduce the problem and its output. The test case below demonstrates a significant performance difference. The android build failure case reported had a shared obj with ~700k symbols and the keep list was ~300k
symbols and it took ~8 minutes to execute.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">~~~<o:p></o:p></p>
<p class="MsoNormal">#!/bin/bash<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">set -euo pipefail<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">echo creating init file<o:p></o:p></p>
<p class="MsoNormal">echo <<EOF > input.S<o:p></o:p></p>
<p class="MsoNormal">.section .text<o:p></o:p></p>
<p class="MsoNormal">EOF<o:p></o:p></p>
<p class="MsoNormal">echo '' > keep_syms.txt<o:p></o:p></p>
<p class="MsoNormal">for i in $(seq 0 100000)<o:p></o:p></p>
<p class="MsoNormal">do<o:p></o:p></p>
<p class="MsoNormal"> echo -e "sym_${i}:\nnop\n" >> input.S<o:p></o:p></p>
<p class="MsoNormal"> if [[ ${i} -lt 30000 ]]; then<o:p></o:p></p>
<p class="MsoNormal"> echo "sym_${i}" >> keep_syms.txt<o:p></o:p></p>
<p class="MsoNormal"> fi<o:p></o:p></p>
<p class="MsoNormal">done<o:p></o:p></p>
<p class="MsoNormal">echo <<EOF >> input.S<o:p></o:p></p>
<p class="MsoNormal">.section .ballast<o:p></o:p></p>
<p class="MsoNormal">nop<o:p></o:p></p>
<p class="MsoNormal">EOF<o:p></o:p></p>
<p class="MsoNormal">echo creating obj file<o:p></o:p></p>
<p class="MsoNormal">llvm-mc -triple arm-linux-androideabi -filetype=obj input.S -o out.o<o:p></o:p></p>
<p class="MsoNormal">echo creating shared obj file<o:p></o:p></p>
<p class="MsoNormal">ld.lld -shared out.o -o libtestcase.so<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">echo performing llvm objcopy<o:p></o:p></p>
<p class="MsoNormal">\time llvm-objcopy -S --remove-section .ballast \<o:p></o:p></p>
<p class="MsoNormal"> --keep-symbols=keep_syms.txt \<o:p></o:p></p>
<p class="MsoNormal"> libtestcase.so libtestcase_smaller.so<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">echo performing GNU objcopy<o:p></o:p></p>
<p class="MsoNormal">\time arm-linux-androideabi-objcopy -S --remove-section .ballast \<o:p></o:p></p>
<p class="MsoNormal"> --keep-symbols=keep_syms.txt \<o:p></o:p></p>
<p class="MsoNormal"> libtestcase.so libtestcase_smaller.so<o:p></o:p></p>
<p class="MsoNormal">~~~<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Here’s the output I get when I run it on ToT-within-last-week-or-so:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-left:.5in">$ PATH=$PWD/bin:$PATH ../../tmp/qt66370/32/objcopy_perf.sh
<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">creating init file<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">creating obj file<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">creating shared obj file<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">ld.lld: warning: lld uses blx instruction, no object with architecture supporting feature detected<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">performing llvm objcopy<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">12.34user 0.00system 0:12.35elapsed 99%CPU (0avgtext+0avgdata 20228maxresident)k<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">0inputs+2288outputs (0major+3815minor)pagefaults 0swaps<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">performing GNU objcopy<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">0.03user 0.00system 0:00.04elapsed 97%CPU (0avgtext+0avgdata 20396maxresident)k<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">0inputs+2288outputs (0major+5895minor)pagefaults 0swaps<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Alternate access to the script above:<o:p></o:p></p>
<p class="MsoNormal"><a href="https://gist.github.com/androm3da/83560d92f3fe637b58aa115ba6b68456">https://gist.github.com/androm3da/83560d92f3fe637b58aa115ba6b68456</a><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">-Brian<o:p></o:p></p>
</div>
</body>
</html>