Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 705406 - sys-devel/gcc-9.2.0-r2 : stage2 should not be built with debug info
Summary: sys-devel/gcc-9.2.0-r2 : stage2 should not be built with debug info
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-01-14 12:06 UTC by Hans F. Nordhaug
Modified: 2020-01-16 06:22 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hans F. Nordhaug 2020-01-14 12:06:01 UTC
When compiling GCC 9.2.0 (which has failed many times for me now), I notice that stage 2 build GCC with debug info:

# cd /var/tmp/portage/sys-devel/gcc-9.2.0-r2/work/build
# file prev-gcc/xg++ gcc/xg++
prev-gcc/xg++: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, not stripped
gcc/xg++:      ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, with debug_info, not stripped

This uses a lot of extra disk space while building and probably also more CPU / time.

# du -hs *
[...]
1,4G	gcc
[...]
352M	prev-gcc

I just wonder if this is intended behavior and if so, why?

Reproducible: Always
Comment 1 Sergei Trofimovich (RETIRED) gentoo-dev 2020-01-14 20:05:04 UTC
By default gcc builds itself 3 times:
- stage1: build gcc-9.2.0 from any other system C++ compiler, usually without optmisations
- stage2: build gcc-9.2.0 using -stage1
- stage3: build gcc-9.2.0 using -gtoggle and stage2

then gcc strips stage2/stage3 and makes sure the final result is identical. Build fails if it does not.

stage2/3 are especially useful for USE="lto" and USE="pgo" phases where optimisations are performed by a version of a compiler being built.

If you use none of the above you can use EXTRA_ECONF=--disable-bootstrap. Then gcc will use stage1/stage2 only to get final result without a comparison.
Comment 2 Hans F. Nordhaug 2020-01-15 08:29:10 UTC
@Sergei: First, thank you for taking the time to answer. 

It's still unclear to me why stage2 and stage3 is compiled with debug info. Maybe it was there in your answer, but I didn't get it. (A little googling reveals that from time to time, the stage comparison fails because of debugging being enable.)

Slightly hijacking my own issue now:

My compilation of GCC 9.2.0 once again failed (on my industrial PC), this time I got all the way to the actual stage comparison and got "Bootstrap comparison failure!". So I quickly tested your suggestion to disable bootstrap:

# EXTRA_ECONF="--disable-bootstrap" emerge -av gcc:9.2.0
[...]
>>> Source configured.
>>> Compiling source in /var/tmp/portage/sys-devel/gcc-9.2.0-r2/work/gcc-9.2.0 ...
 * Compiling gcc (bootstrap-lean)...
make -j4 'LDFLAGS=-Wl,-O1 -Wl,--as-needed' STAGE1_CFLAGS= LIBPATH=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0 'BOOT_CFLAGS=-m64 -O2 -march=bonnell -mtune=generic -fno-stack-protector' bootstrap-lean 
make: *** No rule to make target 'bootstrap-lean'.  Stop.

It failed immediately. By the way, I tested this on my workstation too, and it failed there as well. Let me know if I should file a bug report for this.
Comment 3 Sergei Trofimovich (RETIRED) gentoo-dev 2020-01-15 08:38:37 UTC
(In reply to Hans F. Nordhaug from comment #2)
> @Sergei: First, thank you for taking the time to answer. 
> 
> It's still unclear to me why stage2 and stage3 is compiled with debug info.
> Maybe it was there in your answer, but I didn't get it. (A little googling
> reveals that from time to time, the stage comparison fails because of
> debugging being enable.)

Only one of two is compiler with debugging info: only stage2 or only stage3 (which of those depends on users' CFLAGS value). The reason gcc does it is to make sure gcc's code generation is stable and has no non-determinism from build to build.

> Slightly hijacking my own issue now:
> 
> My compilation of GCC 9.2.0 once again failed (on my industrial PC), this
> time I got all the way to the actual stage comparison and got "Bootstrap
> comparison failure!".

That should not happen. Please file a bug.

> So I quickly tested your suggestion to disable
> bootstrap:
> 
> # EXTRA_ECONF="--disable-bootstrap" emerge -av gcc:9.2.0
> [...]
> >>> Source configured.
> >>> Compiling source in /var/tmp/portage/sys-devel/gcc-9.2.0-r2/work/gcc-9.2.0 ...
>  * Compiling gcc (bootstrap-lean)...
> make -j4 'LDFLAGS=-Wl,-O1 -Wl,--as-needed' STAGE1_CFLAGS=
> LIBPATH=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0 'BOOT_CFLAGS=-m64 -O2
> -march=bonnell -mtune=generic -fno-stack-protector' bootstrap-lean 
> make: *** No rule to make target 'bootstrap-lean'.  Stop.
> 
> It failed immediately. By the way, I tested this on my workstation too, and
> it failed there as well. Let me know if I should file a bug report for this.

You will also need to override 'bootstrap-lean' target with GCC_MAKE_TARGET=all.
I'm using the following env file occasionally to skip some sanity checks:
  $ cat /etc/portage/env/gcc-nobootstrap.conf
  # skip unoptimised build
  EXTRA_ECONF=--disable-bootstrap
  GCC_MAKE_TARGET=all
Comment 4 Hans F. Nordhaug 2020-01-16 06:22:23 UTC
Thanks again for a very useful reply. I'm marking the issue as resolved / fixed. 

And thanks for the gcc-nobootstrap env tip. However, I didn't need it this time. The compile actually completed last night after at least 10 tries. Probably just bad hardware - running Gentoo from a SD card.