From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8717 Path: news.gmane.org!not-for-mail From: Josiah Worcester Newsgroups: gmane.linux.lib.musl.general Subject: Re: Having hard time adding to CFLAGS Date: Thu, 22 Oct 2015 23:04:49 +0000 Message-ID: References: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11c2e6ae2ad5290522b986ce X-Trace: ger.gmane.org 1445555139 28448 80.91.229.3 (22 Oct 2015 23:05:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 22 Oct 2015 23:05:39 +0000 (UTC) To: musl@lists.openwall.com, Rich Felker Original-X-From: musl-return-8730-gllmg-musl=m.gmane.org@lists.openwall.com Fri Oct 23 01:05:20 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1ZpOv3-0007iU-MT for gllmg-musl@m.gmane.org; Fri, 23 Oct 2015 01:05:13 +0200 Original-Received: (qmail 24079 invoked by uid 550); 22 Oct 2015 23:05:11 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 24054 invoked from network); 22 Oct 2015 23:05:10 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :content-type; bh=d6+0JN2T5AYpaZauZVjcIgIIcL/5CLwekQgshCACuOM=; b=U59h2UFdzuleIJ3JK28XA5fJXWC55JAj9UIq/1ogkWLsA//PXaI66NhcOCGwBPtmNE ITwB5WUQLG9cw4XWs9Au70pKCEJDd4JKB2BYq99zbtpr8LX6o6lXa2vPIH4vQHHsKFGK b7K5Qy/okTZZfa2Ii7LsIPH1OiHtzkJlnXBNBPoTfXQSkYYRf92M8rPUIkhqq+VGCqnM dBOV2hZYUmkYzy9ZJCKafJ/m+s0Du3e0jedtUMvtu3GQISMTATHlg9PLxNrGC+mmeHuc SoqUhQlaSM5wIcP3nosfpFfeSvo1b2w5QMYs97wIEIx6YfxPQqAQRDwmFuDjHSAJVNqt YD0g== X-Received: by 10.182.236.66 with SMTP id us2mr9216454obc.45.1445555098799; Thu, 22 Oct 2015 16:04:58 -0700 (PDT) In-Reply-To: Xref: news.gmane.org gmane.linux.lib.musl.general:8717 Archived-At: --001a11c2e6ae2ad5290522b986ce Content-Type: text/plain; charset=UTF-8 On Thu, Oct 22, 2015 at 3:31 PM Denys Vlasenko wrote: > Let's say I need to add a gcc option to my musl build. > > configure says: > ... > Some influential environment variables: > CC C compiler command [detected] > CFLAGS C compiler flags [-Os -pipe ...] > CROSS_COMPILE prefix for cross compiler and tools [none] > LIBCC compiler runtime library [detected > > So I try this, combining all possible ways of passing CFLAGS > (past experience is that different projects do it differently). > > CFLAGS is in environment, and on both configure and make > command lines: > > export CFLAGS="-falign-functions=1" # for example > ./configure CFLAGS="$CFLAGS" > make CFLAGS="$CFLAGS" > > It does work, but resulting libc.so is twice as big: > text data bss dec hex filename > 564099 1944 11768 577811 8d113 musl.1/lib/libc.so > 917805 2130 11736 931671 e3757 musl.2/lib/libc.so > > The cause is that gcc invocation for each .c file in both cases start > normally: > > gcc -std=c99 -nostdinc -ffreestanding -fexcess-precision=standard > -frounding-math -D_XOPEN_SOURCE=700 -I./arch/x86_64 -I./src/internal > -I./include... > > but then, build without explicit CFLAGS use this: > > ... -Os -pipe -fomit-frame-pointer -fno-unwind-tables > -fno-asynchronous-unwind-tables -Wa,--noexecstack > -Werror=implicit-function-declaration -Werror=implicit-int > -Werror=pointer-sign -Werror=pointer-arith -include vis.h -fPIC > -DSHARED -c -o src/aio/aio.lo src/aio/aio.c > > and one with CFLAGS loses these flags, in particular, it has no -Os > and no -fPIC: > > ... -falign-functions=1 -c -o src/aio/aio.o src/aio/aio.c > > Evidently, my CFLAGS replaced needed flags instead of being added at the > end. > > Can this be fixed? If user needs to use e.g. EXTRA_CFLAGS instead, > please fix configure --help. > This appears to be an issue with how you're expecting CFLAGS to work. As with almost anything with configure, all the optimization flags you want need to be in CFLAGS. Normally, a program would have nothing in there otherwise, so you'd be just getting the "-falign-functions=1" flag going to GCC. If you want to optimize it, you would actually need CFLAGS="-Os ...". As for the "no -fPIC", I believe you're looking at the build for two different objects. musl's build system builds both a static and shared library, and the line you pasted there is the one that it uses for the static library's objects. You could tell if it was intended to go into a shared object because it would have a ".lo" suffix instead. --001a11c2e6ae2ad5290522b986ce Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On Thu, Oct 22= , 2015 at 3:31 PM Denys Vlasenko <vda.linux@googlemail.com> wrote:
Let's say I need to add a gcc option to my musl build.

configure says:
...
Some influential environment variables:
=C2=A0 CC=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 C compiler command [detected]
=C2=A0 CFLAGS=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= C compiler flags [-Os -pipe ...]
=C2=A0 CROSS_COMPILE=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0prefix for cro= ss compiler and tools [none]
=C2=A0 LIBCC=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0compiler runtime library [detected

So I try this, combining all possible ways of passing CFLAGS
(past experience is that different projects do it differently).

CFLAGS is in environment, and on both configure and make
command lines:

export CFLAGS=3D"-falign-functions=3D1"=C2=A0 =C2=A0 # for exampl= e
./configure CFLAGS=3D"$CFLAGS"
make CFLAGS=3D"$CFLAGS"

It does work, but resulting libc.so is twice as big:
=C2=A0 =C2=A0text=C2=A0 =C2=A0 =C2=A0 =C2=A0data=C2=A0 =C2=A0 =C2=A0 =C2=A0= bss=C2=A0 =C2=A0 =C2=A0 =C2=A0 dec=C2=A0 =C2=A0 =C2=A0 =C2=A0 hex=C2=A0 = =C2=A0 filename
=C2=A0564099=C2=A0 =C2=A0 =C2=A0 =C2=A01944=C2=A0 =C2=A0 =C2=A0 11768=C2=A0= =C2=A0 =C2=A0577811=C2=A0 =C2=A0 =C2=A0 8d113=C2=A0 =C2=A0 musl.1/lib/libc= .so
=C2=A0917805=C2=A0 =C2=A0 =C2=A0 =C2=A02130=C2=A0 =C2=A0 =C2=A0 11736=C2=A0= =C2=A0 =C2=A0931671=C2=A0 =C2=A0 =C2=A0 e3757=C2=A0 =C2=A0 musl.2/lib/libc= .so

The cause is that gcc invocation for each .c file in both cases start norma= lly:

gcc -std=3Dc99 -nostdinc -ffreestanding -fexcess-precision=3Dstandard
-frounding-math -D_XOPEN_SOURCE=3D700 -I./arch/x86_64 -I./src/internal
-I./include...

but then, build without explicit CFLAGS use this:

... -Os -pipe -fomit-frame-pointer -fno-unwind-tables
-fno-asynchronous-unwind-tables -Wa,--noexecstack
-Werror=3Dimplicit-function-declaration -Werror=3Dimplicit-int
-Werror=3Dpointer-sign -Werror=3Dpointer-arith -include vis.h=C2=A0 -fPIC -DSHARED -c -o src/aio/aio.lo src/aio/aio.c

and one with CFLAGS loses these flags, in particular, it has no -Os
and no -fPIC:

... -falign-functions=3D1 -c -o src/aio/aio.o src/aio/aio.c

Evidently, my CFLAGS replaced needed flags instead of being added at the en= d.

Can this be fixed? If user needs to use e.g. EXTRA_CFLAGS instead,
please fix configure --help.

This appea= rs to be an issue with how you're expecting CFLAGS to work. As with alm= ost anything with configure, all the optimization flags you want need to be= in CFLAGS. Normally, a program would have nothing in there otherwise, so y= ou'd be just getting the "-falign-functions=3D1" flag going t= o GCC. If you want to optimize it, you would actually need CFLAGS=3D"-= Os ...".

As for the "no -fPIC", I b= elieve you're looking at the build for two different objects. musl'= s build system builds both a static and shared library, and the line you pa= sted there is the one that it uses for the static library's objects. Yo= u could tell if it was intended to go into a shared object because it would= have a ".lo" suffix instead.
--001a11c2e6ae2ad5290522b986ce--