Mail archive

Re: [alpine-devel] force compile flag for musl?

From: Przemysław Pawełczyk <>
Date: Wed, 25 Oct 2017 17:38:57 +0200

---- On Wed, 25 Oct 2017 16:46:14 +0200 Natanael Copa <> wrote ----
> I wonder what you think about overriding the -Os compile flag for musl,
> and hardcode it to -O2.

I would be very careful with such changes.

There is misconception that the higher optimization level, the faster
code is generated. That is the general -Olevel idea, but not what is
seen in practice. Gains (or losses) from higher optimization levels
vary between archs and obviously depend on the code that is being

Smaller code, beside being smaller, is also more cache-friendly, so -Os
can be faster than -O2 and often is. OTOH higher optimization levels
for x86-64 usually tend to give better results than on other archs.

There is no rule. It all depends on:
- source code,
- compiler,
- platform.

> I think this makes sense since the functions in libc are so often used
> that we want trade better performance at the cost of slightly bigger
> binary.

This makes sense if we really get better performance with -O2 on all
platforms AL supports. And to be able to confirm that, it has te be

> This means that we override whatever user as set CFLAGS to
> in /etc/abuild.conf
> We already do this with zlib.

zlib is a different beast, because it's computational software. It's
much more natural to see gains from higher -Olevel in that kind of apps.

> What do you think?

There were similar changes in aports for various applications over
recent months, but I haven't seen even one proof behind them.

Performance improvements are imporant, and they may come from simply
bumping optimization level, but it should be verified, not blindly


> diff --git a/main/musl/APKBUILD b/main/musl/APKBUILD
> index 1938bbb3ca..193002186d 100644
> --- a/main/musl/APKBUILD
> +++ b/main/musl/APKBUILD
> _at_@ -54,6 +54,8 @@ build() {
> fi
> # note: not autotools
> + # force -O2 compile flag for better performance
> + CFLAGS="-O2" \
> LDFLAGS="$LDFLAGS -Wl,-soname,libc.musl-${CARCH}.so.1" \
> ./configure \
> --build=$CBUILD \
> -nc

Received on Wed Oct 25 2017 - 17:38:57 UTC