On 12/05/2019 06:24, Ken Moffat via lfs-dev wrote:
> As people probably know, I usually set my own CFLAGS when building
> LFS (at a minimum, -O2 to get rid of most debug symbols).  But I'm
> now trying to compare the build times and the size of the
> executables for "I did it my way" against using the default CFLAGS
> from the individual packages (or from BLFS, or using releease builds
> for cmake and meson).
> 
> Got through chapter 5 ok, time was not a lot greater but the space
> used by /tools was a lot bigger (2.4 GB instead of 851MB).  But in
> chapter 6 glibc was not happy:
> 
>  # error "glibc cannot be compiled without optimization"
> 
> Looking on google, and trying to follow a link to the FAQ
> specifically for this (apparently failed, but left me at hte FAQ)
> all I can find is the old advice from Seth: if you use CFLAGS and
> the build fails, people will suggest you  try without those CFLAGS.
> 
> Fine, and I remember suggestions to use -O3 for glibc from Greg
> Schafer.  So, I've added CFLAGS='-O2' for glibc if my own CFLAGS are
> not set (and I had a similar fix which became ineffective when I
> reworked how I set/pass my CFLAGS, at that time it was labelled as
> being needed for at least x86_32).
> 
> But unless I'm looking in the wrong place, I can't see any CFLAGS in
> the book ?  So, how do you all build glibc in chroot ?
> 
> I'm guessing that --enable-stack-protector=strong might be what
> enforces this requirement.
> 
> Or have I somehow diverged too far from the book, and will shortly be
> "not waving, but drowning" ?
> 

jhalfs default, which I use, and I guess others too, is to have CFLAGS unset.
Note the defaults CFLAGS for glibc come frome Makeconfig:
----------------------------
override CFLAGS = -std=gnu11 -fgnu89-inline $(config-extra-cflags) \
               $(filter-out %frame-pointer,$(+cflags)) $(+gccwarn-c) \
               $(+extra-math-flags) \
               $(sysdep-CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(<F)) \
               $(CFLAGS-$(@F)) $(tls-model) \
               $(foreach lib,$(libof-$(basename $(@F))) \
                             $(libof-$(<F)) $(libof-$(@F)),$(CFLAGS-$(lib)))
--------------------------
and "+cflags" contains either what has been passed as CFLAGS, or "-g -O2".

The #error you are seeing comes from file include/libc-symbols.h. It flags the
error if __OPTIMIZE__ is not defined when compiling. From gcc doc,
__OPTIMIZE__ is defined to 1 whenever optimization is enabled (even -Os).

From my glibc logs, almost all the calls to gcc have "-g -O2" in their command
line. Ah, and they have also "-include ../include/libc-symbols.h".

So, IIUC, if you pass a CFLAGS without -Osomething (explicit or implied), the
error is triggered. BTW, I've been pulling my hair several times in my life
for using -02 (zero two), instead of -O2 (letter O two)...

Pierre
-- 
http://lists.linuxfromscratch.org/listinfo/lfs-dev
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page

Reply via email to