Sunday, June 04, 2023

Re: program compiled with clang from base runs 4 times slower than compiled with gcc-11.2.0p6 from ports

On Sun, Jun 04, 2023 at 05:31:34PM -0600, Todd C. Miller wrote:
> Take a look at the clang-local man page, it documents the difference
> between the OpenBSD base clang and stock llvm. You can try disabling
> some of the options to find which one (or combination of options)
> is causing the slowdown.

Thanks for the pointer, that man page is really what I missed.

>
> I would try building with -fno-stack-protector and -mno-retpoline
> first to see if either of those are the cause.

Neither of them made any difference:

henryk$ make clean
rm -f enchive src/enchive.o src/chacha.o src/curve25519-donna.o src/sha256.o enchive-cli.c
henryk$ make CFLAGS='-ansi -pedantic -Wall -Wextra -O3 -g3 -fno-stack-protector -mno-retpoline'
cc -c -ansi -pedantic -Wall -Wextra -O3 -g3 -fno-stack-protector -mno-retpoline -o src/enchive.o src/enchive.c
cc -c -ansi -pedantic -Wall -Wextra -O3 -g3 -fno-stack-protector -mno-retpoline -o src/chacha.o src/chacha.c
cc -c -ansi -pedantic -Wall -Wextra -O3 -g3 -fno-stack-protector -mno-retpoline -o src/curve25519-donna.o src/curve25519-donna.c
cc -c -ansi -pedantic -Wall -Wextra -O3 -g3 -fno-stack-protector -mno-retpoline -o src/sha256.o src/sha256.c
cc -o enchive src/enchive.o src/chacha.o src/curve25519-donna.o src/sha256.o
enchive.c:209 (src/enchive.c:209)(src/enchive.o:(load_seckey)): warning: sprintf() is often misused, please use snprintf()
henryk$ time enchive a <zero >/dev/null
0m55.07s real 0m49.69s user 0m05.47s system

Next I tried -fno-pie:

henryk$ make clean
rm -f enchive src/enchive.o src/chacha.o src/curve25519-donna.o src/sha256.o enchive-cli.c
henryk$ make CFLAGS='-ansi -pedantic -Wall -Wextra -O3 -g3 -fno-pie' LDFLAGS='-nopie'
cc -c -ansi -pedantic -Wall -Wextra -O3 -g3 -fno-pie -o src/enchive.o src/enchive.c
cc -c -ansi -pedantic -Wall -Wextra -O3 -g3 -fno-pie -o src/chacha.o src/chacha.c
cc -c -ansi -pedantic -Wall -Wextra -O3 -g3 -fno-pie -o src/curve25519-donna.o src/curve25519-donna.c
cc -c -ansi -pedantic -Wall -Wextra -O3 -g3 -fno-pie -o src/sha256.o src/sha256.c
cc -nopie -o enchive src/enchive.o src/chacha.o src/curve25519-donna.o src/sha256.o
enchive.c:209 (src/enchive.c:209)(src/enchive.o:(load_seckey)): warning: sprintf() is often misused, please use snprintf()
henryk$ time enchive a <zero >/dev/null
0m54.65s real 0m49.21s user 0m04.54s system

Still no cigar...

Next I tried -fno-fixup-gadgets, and that made a radical difference:

henryk$ make clean
rm -f enchive src/enchive.o src/chacha.o src/curve25519-donna.o src/sha256.o enchive-cli.c
henryk$ make CFLAGS='-ansi -pedantic -Wall -Wextra -O3 -g3 -fno-fixup-gadgets'
cc -c -ansi -pedantic -Wall -Wextra -O3 -g3 -fno-fixup-gadgets -o src/enchive.o src/enchive.c
cc -c -ansi -pedantic -Wall -Wextra -O3 -g3 -fno-fixup-gadgets -o src/chacha.o src/chacha.c
cc -c -ansi -pedantic -Wall -Wextra -O3 -g3 -fno-fixup-gadgets -o src/curve25519-donna.o src/curve25519-donna.c
cc -c -ansi -pedantic -Wall -Wextra -O3 -g3 -fno-fixup-gadgets -o src/sha256.o src/sha256.c
cc -o enchive src/enchive.o src/chacha.o src/curve25519-donna.o src/sha256.o
enchive.c:209 (src/enchive.c:209)(src/enchive.o:(load_seckey)): warning: sprintf() is often misused, please use snprintf()
henryk$ time enchive a <zero >/dev/null
0m16.63s real 0m14.31s user 0m02.36s system

14.31s is on par with 12.85s of gcc-compiled binary:

henryk$ make clean
rm -f enchive src/enchive.o src/chacha.o src/curve25519-donna.o src/sha256.o enchive-cli.c
henryk$ make CC=egcc
egcc -c -ansi -pedantic -Wall -Wextra -O3 -g3 -o src/enchive.o src/enchive.c
egcc -c -ansi -pedantic -Wall -Wextra -O3 -g3 -o src/chacha.o src/chacha.c
egcc -c -ansi -pedantic -Wall -Wextra -O3 -g3 -o src/curve25519-donna.o src/curve25519-donna.c
egcc -c -ansi -pedantic -Wall -Wextra -O3 -g3 -o src/sha256.o src/sha256.c
egcc -o enchive src/enchive.o src/chacha.o src/curve25519-donna.o src/sha256.o
enchive.c:209 (src/enchive.c:209)(src/enchive.o:(agent_addr)): warning: sprintf() is often misused, please use snprintf()
henryk$ time enchive a <zero >/dev/null
0m14.36s real 0m12.85s user 0m00.39s system

So to me it seems that fixup-gadgets is the culprit.

Thanks,

Kastus

No comments:

Post a Comment