site  contact  subhomenews

gcc fixed by recompiling in running EasyOS

October 16, 2020 — BarryK

Yesterday I posted about gcc having pretty awful default commandline parameters:

That was compiled in the Dunfell release of OpenEmbedded (OE), and I had much more sane parameters a couple years ago with the OE Pyro port. The problem, we discovered, was that gcc was compiling packages and using extra CPU instructions that are not in a Core2 or Nocona CPU.

I looked at the gcc recipe in OE, and it is very complicated. I could probably fix it in time, but then I thought, why not go for a quick fix and recompile gcc in a running EasyOS 0.92. This has the gcc compiled in OE and it does work, apart from the undesired CPU instructions.

Thanks to the LFS guys, for instructions:

I compiled gcc, and going straight to the end result:

# echo "" | cc -v -E - 2>&1 | grep cc1
/usr/libexec/gcc/x86_64-poky-linux/9.3.0/cc1 -E -quiet -v - -mtune=generic -march=nocona

Oh yes! Um, I think so anyway, presume that "-mtune=generic" is OK. Guys with in-depth experience configuring gcc, such as jamesbond and technosaurus, would be able to tell me if this looks good.

Actually, it is odd, because I supplied it with "-mtune=nocona". Here are my notes:

Firstly, finding out the configure options used to compile the gcc in OE:

# gcc -v
Using built-in specs.
Target: x86_64-poky-linux
Configured with: ../../../../../../work-shared/gcc-9.3.0-r0/gcc-9.3.0/configure --build=x86_64-linux \
--host=x86_64-poky-linux --target=x86_64-poky-linux --prefix=/usr --exec_prefix=/usr \
--bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/libexec --datadir=/usr/share \
--sysconfdir=/etc --sharedstatedir=/com --localstatedir=/var --libdir=/usr/lib \
--includedir=/usr/include --oldincludedir=/usr/include --infodir=/usr/share/info \
--mandir=/usr/share/man --disable-silent-rules --disable-dependency-tracking \
--with-libtool-sysroot=/ --with-gnu-ld --enable-shared --enable-languages=c,c++ \
--enable-threads=posix --enable-multilib --enable-default-pie --enable-c99 --enable-long-long \
--enable-symvers=gnu --enable-libstdcxx-pch --program-prefix=x86_64-poky-linux- \
--without-local-prefix --disable-install-libiberty --enable-lto --disable-libssp --enable-libitm \
--disable-bootstrap --disable-libmudflap --with-system-zlib --with-linker-hash-style=gnu \
--enable-linker-build-id --with-ppl=no --with-cloog=no --enable-checking=release \
--enable-cheaders=c_global --without-isl --with-build-sysroot=/ --disable-static --enable-nls \
--with-glibc-version=2.28 --enable-initfini-array --enable-__cxa_atexit --with-arch=native
Thread model: posix
gcc version 9.3.0 (GCC)

I used this as a starting point.

A point to make right now: EasyOS 0.92 has /lib/x86_64-linux-gnu and /usr/lib/x86_64-linux-gnu symlinks to ".", for compatibility in the future if ever want to install a package from Debian or Ubuntu. I had to remove them, as they forced gcc to configure as "multilib" even though I had explicitly disabled multilib.

I also applied some fixes as recommended by LFS, and exported some variables:

required for x86_64, coz we are only using lib not lib64:
# sed -e '/m64=/s/lib64/lib/' -i.orig gcc/config/i386/t-linux64
dunfell has glibc 2.31, requires this fix;
# sed -e '1161 s|^|//|' -i libsanitizer/sanitizer_common/
# export SED='sed'

# export CFLAGS='-march=nocona -mtune=nocona'

I modified and removed some of the configure options. For example, "--disable-dependency-tracking" causes compile fail, which would require a patch, but I just removed it. Here we go:

# mkdir build
# cd build
# ../configure --build=x86_64-poky-linux --prefix=/usr --exec_prefix=/usr --bindir=/usr/bin \
--sbindir=/usr/sbin --libexecdir=/usr/libexec --datadir=/usr/share --sysconfdir=/etc \
--sharedstatedir=/com --localstatedir=/var --libdir=/usr/lib --includedir=/usr/include \
--oldincludedir=/usr/include --infodir=/usr/share/info --mandir=/usr/share/man \
--disable-silent-rules --with-libtool-sysroot=/ --with-gnu-ld --enable-shared \
--enable-languages=c,c++ --enable-threads=posix --disable-multilib --enable-default-pie \
--enable-c99 --enable-long-long --enable-symvers=gnu --enable-libstdcxx-pch \
--program-prefix=x86_64-poky-linux- --without-local-prefix --disable-install-libiberty \
--enable-lto --disable-libssp --enable-libitm --disable-bootstrap --disable-libmudflap \
--with-system-zlib --with-linker-hash-style=gnu --enable-linker-build-id --with-ppl=no \
--with-cloog=no --enable-checking=release --enable-cheaders=c_global --without-isl \
--with-build-sysroot=/ --disable-static --enable-nls --with-glibc-version=2.28 \
--enable-initfini-array --enable-__cxa_atexit --with-arch=nocona
# make
# new2dir make install

After that, LFS has a lot of post-install fixes and tests. Passed all the tests, except for one odd thing:

Now make sure that we're setup to use the correct start files:
# grep -o '/usr/lib.*/crt[1in].*succeeded' dummy.log
The output of the last command should be:
/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../lib/crt1.o succeeded
/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../lib/crti.o succeeded
/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../lib/crtn.o succeeded
hmmm, in my case, has returned:
/usr/lib/gcc/x86_64-poky-linux/9.3.0/../../../../lib/crti.o succeeded
/usr/lib/gcc/x86_64-poky-linux/9.3.0/../../../../lib/crtn.o succeeded

However, crt1.o does exist! Hmmm. Finally, I compiled "Hello World":

and hello world:
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
# gcc hello.c -o hello
# ./hello
Hello, World!#
# file hello
hello: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter \
/lib64/, BuildID[sha1]=bcf9f98c2befa38a457812857dc570270ec25bf0, \
for GNU/Linux 3.2.0, with debug_info, not stripped

Looks OK, so I have rebuilt 0.92 with this new gcc package in the 'devx' SFS. I will give it a quick sanity test and upload it soon. 

Tags: easy