gcc
- Disable bootstrap; stage1 is good enough
- Use a different
libexecdir bootstrap-ltobuild configuration adjustsCFLAGSandLDFLAGS--with-build-config=bootstrap-lto-leanhas to be used withmake profiledbootstrap- Personal testing showed negligible differences between
disable-bootstrapandbootstrap-lean, with notable differences againstbootstrap-native(latter is~5%smaller):
bootstrap-native disable-bootstrap diff %lto-dump 40,730,072 42,812,208 +2,082,136 +5.11%g++ 1,094,704 1,098,840 +4,136 +0.38%gcc 1,094,704 1,094,744 +40 +0.00%gcov 358,904 358,944 +40 +0.01%gcc-ar 26,424 30,544 +4,120 +15.59%
cc1plus 44,880,264 46,822,920 +1,942,656 +4.33%cc1 42,226,152 44,263,176 +2,037,024 +4.82%lto1 40,730,072 42,812,272 +2,082,200 +5.11%libgcc.a 8,233,264 8,253,544 +20,280 +0.25%lto-wrapper 866,808 862,744 -4,064 -0.47%libgcov.a 378,410 381,562 +3,152 +0.83%collect2 313,848 309,784 -4,064 -1.29%liblto_plugin.so 67,192 75,536 +8,344 +12.42%g++-mapper-server 55,040 51,112 -3,928 -7.14%
libstdc++.so.6.0.33 2,427,408 2,501,200 +73,792 +3.04%libgcc_s.so.1 169,904 826,832 +656,928 +386.65%libquadmath.so.0.0.0 296,488 296,632 +144 +0.05%libgomp.so.1.0.0 277,064 277,120 +56 +0.02%libitm.so.1.0.0 71,456 79,704 +8,248 +11.54%libatomic.so.1.2.0 22,056 22,120 +64 +0.29%bootstrap-debug-leanis slower and bigger compared tobootstrap-debugBOOT_CFLAGS,BOOT_LDFLAGSand--with-boot-ldflagsonly make sense when bootstrapping gcc; applies to stages 2 and 3LD_FOR_TARGET,STAGE1_CFLAGSandSTAGE1_LDFLAGSapply to stage 1--enable-link-mutexhas been deprecated, use--enable-link-serialization=1instead: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109310 (=1is sane, any higher value might thrash the system)cc1depends onmpcat run time- Depends on
tarfor themaketargetinstall-headers-tar - As of 14.1, new configure options
--enable-host-pie, to build the compiler executables as PIE; and--enable-host-bind-now, to link the compiler executables with-Wl,-z,nowto enable additional hardening --enable-host-sharedhas a performance penalty ongcc- Might need a lex/flex library
libfl.a:
checking for lex library... not foundconfigure: WARNING: required lex library not found; giving up on touch lex.yy.cBOOT_CXXFLAGShas been deprecatedCFLAGS,CXXFLAGS,CFLAGS_FOR_TARGETandCXXFLAGS_FOR_TARGETare being picked up from the environment; the latter two are automatically assigned to the former two- Check
clocaleto use forlibstdc++;genericvs--disable-clocale? libgcc_s.so.1size dramatically reduced when using stage1 flags (from ~ 830k to ~ 170k)otoolis for mach os, and is part of LLVM; theotoolnot found error is normal forgcc- Move cpp from lib to bin?
- The following (ignored) errors occur when building
libstdc++-v3(in all stages):
libstdc++-v3.log:945:make[1]: [Makefile:1831: x86_64-glaucus-linux-musl/bits/largefile-config.h] Error 1 (ignored)libstdc++-v3.log:946:make[1]: [Makefile:1832: x86_64-glaucus-linux-musl/bits/largefile-config.h] Error 1 (ignored)According to tmp/gcc/gcc-14.2.0/build/x86_64-glaucus-linux-musl/libstdc++-v3/include/Makefile:
...# This header is not installed, it's only used to build libstdc++ itself.${host_builddir}/largefile-config.h: ${CONFIG_HEADER} stamp-${host_alias} @rm -f $@.tmp @-grep 'define _DARWIN_USE_64_BIT_INODE' ${CONFIG_HEADER} >> $@.tmp @-grep 'define _FILE_OFFSET_BITS' ${CONFIG_HEADER} >> $@.tmp @-grep 'define _LARGE_FILES' ${CONFIG_HEADER} >> $@.tmp @mv $@.tmp $@...and indeed if we check tmp/gcc/gcc-14.2.0/build/x86_64-glaucus-linux-musl/libstdc++-v3/include/x86_64-glaucus-linux-musl/bits/largefile-config.h:
# define _DARWIN_USE_64_BIT_INODE 1which means that the first @-grep is working, while the latter two are not causing these two Error 1 (ignored) messages; and no this is not related to a race condition and it does not go away neither with -j 1 nor with --disable-largefile
- No need to fix headers or includes on glaucus
libsupc++is the ABI library and it is a subset oflibstdc++- Alpine sets
libat_cv_have_ifunc=nobefore gcc configure; related to libatomic, and Alpaquita are providing ifunc and are not setting this variable - Alpine uses
gcc-goto bootstrap go -fstack-protector-strongis the default; no need to lowerssp-buffer-sizefrom the default8to4, but glaucus still does it- Disable
libsanitizerforgccwith musl (only ASan works), and preferclangandcompiler-rtfor sanitizers - Do we need to remove
usr/lib/gcc/x86_64-glaucus-linux-musl/$ver/install-tools/(andinclude-fixed/)? - Patching
gccto linklibatomicto everything is not needed onx86_64(Alpine enables it forriscv64) - If you are not building a C library in the same source tree as GCC, you should also provide the target libraries and headers before configuring GCC, specifying the directories with —with-sysroot or —with-headers and —with-libs. Many targets also require “start files” such as crt0.o and crtn.o which are linked into each executable. There may be several alternatives for crt0.o, for use with profiling or other compilation options. Check your target’s definition of STARTFILE_SPEC to find out what start files it uses.
- No need to perform this maneuver from LFS thanks to our toolchain design:
cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \ `dirname $($target-gcc -print-libgcc-file-name)`/include/limits.h--enable-gnu-indirect-function(ifunc) is only available for glibc and is enabled by default on glibc systems; it won’t hurt to explicitly disable it on musllibat_cv_have_ifunc=noexplicitly disablesifuncforlibatomic:- creates conflicts on ARM as it
-march/-mcpuexpect it (Alpine) - ifunc attributes detection is broken in configure scripts which makes sense to force disable it for non-glibc systems (it is used extensively by the Go language) (Alpine)
- creates conflicts on ARM as it
- For bootstrap builds we hardcode
sysrootbecause it is split from thetoolchainand located in its own directory outside of thetoolchaindirectory; this does not change withbuild-sysrootbecausebuild-sysrootcontrols where gcc finds its libaries, headers and stuff during its build, whilesysrootcontrols where it finds them after the build when building stuff, in a sense this makes the toolchain not so relocatable (well it will still look undersysroot(which iscrossin our condition) for stuff regardless of what thetoolchaindirectory is named or located, meaning if we movedglaucus/toolchainover to/tmp/someOtherDirit will still look for stuff underglaucus/crosswherever that is, so that’s a minor win), but it is not meant to be, this is because we want to keepcross(basically oursysroot) separate from thetoolchainso we can populate it later on with stage 2 stuff and turn it into a bootable image; this is notmusselafter all --with-libstdcxx-lock-policy=atomicuses less memory and is simpler thanmutex--enable-linker-build-idisoffby default- Disable transactional memory (Intel TSX)
--disable-tm-clone-registryas it is obsolete nowadays (see-fgnu-tm) -Qnis an old obsolete synonym for-fno-ident-mmuslis the default on*-*-linux-*musl*targets-fomit-frame-pointeris used by default with-Os(and-O2)- From
ldmanual:
Note that the location of the compiler originated plugins is different from the place where the ar, nm and ranlib programs search for their plugins. In order for those commands to make use of a compiler based plugin it must first be copied into the ${libdir}/bfd-plugins directory. All gcc based linker plugins are backward compatible, so it is sufficient to just copy in the newest one.- Graphite is no longer being developed/maintained as it used to be
- Baseline gcc optimizes performs better loop optimizations without graphite (isl, and cloog/ppl previously) than with it
- Installing the linker plugin into $libdir/bfd-plugins has the same effect as usage of the command wrappers (gcc-ar, gcc-nm and gcc-ranlib)
--with-cross-hostis deprecated (according to aFIXMEcomment inconfigure)- Configure
libstdc++-v3with--enable-libstdcxx-timeasmuslhasclock_gettime mudflapremoved since4.9(musldoes not supportlibmudflaganyways)- intel
mpxandsfiare unmaintained and were dropped from both the kernel andgcc(musldoes not supportlibmpxanyways as it lackssecure_getenvandstruct _libc_fpstate) libcilkrtsremoved since 2017- a custom tuple like
x86_64-glaucus-linux-muslis good for cross-compilation otherwise it is bad because it assumes the compiler is failing for many tests; it is better to havex86_64-pc-linux-muslas the final target config.guessandconfig.subpreferx86_64-pctox86_64-unknown(or not specifying anything though formuslit is sufficient)- Uses
~2GBof memory permakejob - test suite takes a lot of time (several hours)
- LTO is not a default language, but is built by default because
--enable-ltois enabled by default --disable-libstdcxx-pchprevents the precompiled headers from being built (which is the default behavior); we don’t use these headers and they take up space--disable-libstdcxx-visibilitycauses missing symbols fromlibstdc++when linking and running programs that depend on itmusl-gcc-crosspatches from Rich Felker were added to upstreamgccas of10.2.0+bootstrap-O3might cause regressions
Not Relocatable
Section titled “Not Relocatable”Relocatable:
Section titled “Relocatable:”- http://musl.cc/
- https://github.com/firasuke/mussel
- https://github.com/richfelker/musl-cross-make
- https://skarnet.org/toolchains/
References
Section titled “References”- https://dl.acm.org/doi/full/10.1145/3674735
- https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100537
- https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106162
- https://gcc.gnu.org/install/build.html
- https://gcc.gnu.org/install/configure.html
- https://gcc.gnu.org/install/specific.html
- https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html
- https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
- https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html
- https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html
- https://gcc.gnu.org/onlinedocs/libstdc++/manual/configure.html
- https://github.com/archlinux/svntogit-packages/commit/9c2de9ba1494f1dfd94e65e8814409814840618b
- https://github.com/dslm4515/Musl-LFS/issues/74
- https://lists.reproducible-builds.org/pipermail/rb-general/2018-June/001068.html
- https://wiki.osdev.org/Building_GCC