[llvm-dev] llvm-objcopy --keep-symbols performance

49 views
Skip to first unread message

Brian Cain via llvm-dev

unread,
May 18, 2021, 12:11:44 AM5/18/21
to llvm...@lists.llvm.org

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.

 

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.

 

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.

 

~~~

#!/bin/bash

 

set -euo pipefail

 

echo creating init file

echo <<EOF > input.S

.section .text

EOF

echo '' > keep_syms.txt

for i in $(seq 0 100000)

do

    echo -e "sym_${i}:\nnop\n" >> input.S

    if [[ ${i} -lt 30000 ]]; then

        echo "sym_${i}" >> keep_syms.txt

    fi

done

echo <<EOF >> input.S

.section .ballast

nop

EOF

echo creating obj file

llvm-mc -triple arm-linux-androideabi -filetype=obj input.S -o out.o

echo creating shared obj file

ld.lld  -shared out.o -o libtestcase.so

 

echo performing llvm objcopy

\time llvm-objcopy -S --remove-section .ballast  \

    --keep-symbols=keep_syms.txt \

    libtestcase.so libtestcase_smaller.so

 

echo performing GNU objcopy

\time arm-linux-androideabi-objcopy -S --remove-section .ballast  \

    --keep-symbols=keep_syms.txt \

    libtestcase.so libtestcase_smaller.so

~~~

 

Here’s the output I get when I run it on ToT-within-last-week-or-so:

 

$ PATH=$PWD/bin:$PATH ../../tmp/qt66370/32/objcopy_perf.sh

creating init file

creating obj file

creating shared obj file

ld.lld: warning: lld uses blx instruction, no object with architecture supporting feature detected

performing llvm objcopy

12.34user 0.00system 0:12.35elapsed 99%CPU (0avgtext+0avgdata 20228maxresident)k

0inputs+2288outputs (0major+3815minor)pagefaults 0swaps

performing GNU objcopy

0.03user 0.00system 0:00.04elapsed 97%CPU (0avgtext+0avgdata 20396maxresident)k

0inputs+2288outputs (0major+5895minor)pagefaults 0swaps

 

 

Alternate access to the script above:

https://gist.github.com/androm3da/83560d92f3fe637b58aa115ba6b68456

 

-Brian

Justin Cady via llvm-dev

unread,
May 21, 2021, 10:25:00 AM5/21/21
to Brian Cain, llvm...@lists.llvm.org
Unfortunately I do not have an answer or workaround, but I want to add that I am also hitting this issue. The performance of --keep-symbols with a large list of symbols is quite slow.

Have you filed a bug to track this?

(For other reasons in my specific case I cannot fall back to GNU objcopy, so this performance penalty must be paid today.)

Thanks,

Justin

_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

Brian Cain via llvm-dev

unread,
May 21, 2021, 11:24:38 AM5/21/21
to Justin Cady, llvm...@lists.llvm.org
Reply all
Reply to author
Forward
0 new messages