FS#71777 - [gcc] GCC is built with suboptimal CFLAGS / LDFLAGS
Attached to Project:
Arch Linux
Opened by Toolybird (Toolybird) - Monday, 09 August 2021, 05:57 GMT
Last edited by freswa (frederik) - Thursday, 10 February 2022, 20:02 GMT
Opened by Toolybird (Toolybird) - Monday, 09 August 2021, 05:57 GMT
Last edited by freswa (frederik) - Thursday, 10 February 2022, 20:02 GMT
|
Details
Most of the installed binaries in an Arch GCC build are not
compiled with preferred CFLAGS / LDFLAGS (from
makepkg.conf). The reason is due to a combination of
factors:
1. Arch uses the default Makefile target which performs a 3-stage bootstrap (3rd stage is what gets installed) 2. Arch doesn't employ the documented[1] BOOT_CFLAGS var, or the badly documented BOOT_LDFLAGS var. Essentially, to pass preferred FLAGS passed down into the 2nd and 3rd stages of the bootstrap, one has to utilise BOOT_*FLAGS vars. This is what other distros do e.g: Fedora[2] and Debian[3]. (Sidenote: those links demonstrate why most of us appreciate the utter simplicity of PKGBUILDs :) Now, just to complicate matters there are also *FLAGS_FOR_TARGET vars which affect how the target libraries get built. In oversimplified terms the payload of a GCC build comprises of: - compilers (gcc, g++, cpp, cc1, etc.) - target libs (libgcc, libstdc++, and friends) In the current Arch GCC build, CFLAGS are carried through to CFLAGS_FOR_TARGET. LDFLAGS are mostly lost (I say mostly because they do get used in certain less important parts of the build). BOOT_*FLAGS just get the defaults. The upshot of all this means the status quo is as follows (using current distro FLAGS from devtools): compilers: BOOT_CFLAGS="-g -O2" BOOT_LDFLAGS="" target libs: CFLAGS_FOR_TARGET="-g -march=x86-64 -mtune=generic -O2 -fno-plt" (-g is added by GCC configury, -pipe is filtered out in PKGBUILD) LDFLAGS_FOR_TARGET="" This came to light while looking into ways to improve the bootstrap of the full Arch toolchain (see Recommendations: - build GCC with `make -O' (as per - add BOOT_CFLAGS, BOOT_LDFLAGS and LDFLAGS_FOR_TARGET to the make invocation - while we're at it may as well add STAGE1_CFLAGS as per make -O STAGE1_CFLAGS="-O2" \ BOOT_CFLAGS="$CFLAGS" \ BOOT_LDFLAGS="$LDFLAGS" \ LDFLAGS_FOR_TARGET="$LDFLAGS" I've tested this in a full toolchain bootstrap using latest binutils-2.37, gcc-11.2 and glibc-2.34. The GCC testsuite results are identical as compared to when not building like above. The target libs are all now full RELRO (except for libgcc_s.so.1 but this has now been fixed on GCC trunk[4]). Overall there are less complaints from namcap. NOTE: If / when Arch changes the distro defaults in devtools to match current pacman makepkg.conf, certain CFLAGS will need to be filtered out. This is exacly what the Fedora rpm specfile does. [1] https://gcc.gnu.org/install/build.html [2] https://src.fedoraproject.org/rpms/gcc/blob/rawhide/f/gcc.spec [3] https://salsa.debian.org/toolchain-team/gcc/-/blob/master/debian/rules2 [4] https://gcc.gnu.org/pipermail/gcc-patches/2021-August/576785.html |
This task depends upon
Closed by freswa (frederik)
Thursday, 10 February 2022, 20:02 GMT
Reason for closing: Implemented
Additional comments about closing: revision 436897
Thursday, 10 February 2022, 20:02 GMT
Reason for closing: Implemented
Additional comments about closing: revision 436897
Note: I've only build-tested these and run the testsuites in the standard nspawn container. Haven't actually installed the pkgs on a "real" system then built more software. Looking around the 'net, there are some issues with latest binutils and glibc. Subsequent patches will certainly be needed (as is typical for toolchain upgrades).