c++gccg++gcc-warninggcc12

GCC v12.1 warning about serial compilation


I have upgraded my whole arch linux system today (12th May, 2022). gcc was also upgraded from v11.2 to v12.1. I tried compiling some of my programs with g++ (part of gcc compiler collection) by the following command:

g++ -O3 -DNDEBUG -Os -Ofast -Og -s -march=native -flto -funroll-all-loops -std=c++20 main.cc -o ./main

The program compiled perfectly and ran as excepted without any errors, but I got a warning:

lto-wrapper: warning: using serial compilation of 2 LTRANS jobs

But, when the same program was compiled using v11.2 it produces zero number of errors and warnings.

My Questions:

Here's the g++ configuration on my machine:

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/12.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-werror --with-build-config=bootstrap-lto --enable-link-serialization=1
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.1.0 (GCC) 

Solution

  • This warning is harmless. It just tells you that GCC is only using a single CPU core to do the link time optimization, which means that it will be slow.

    The warning appears due to a change in the -flto option which was introduced in GCC 11.4 by this commit. The warning is shown because the -flto option only uses parallel compilation if explicitly instructed to do so. By default, it simply uses slow serial compilation (unless you have a running job server). Also see this conversation on the GCC mailing list:

    Likewise if people just use -flto and auto-detection [of job server] finds nothing:

    warning: using serial compilation of N LTRANS jobs
    note: refer to http://.... for how to use parallel compile

    [...]

    That is, teach users rather than second-guessing and eventually blowing things up.

    Use -flto=auto to explicitly enable parallel compilation and to get rid of the warning.

    If you're using GCC on Windows via MinGW or MSYS2, then you'll likely also have to set the MAKE environment variable to mingw32-make and/or pass the -save-temps option to get rid of all warnings.

    The exact semantics and effects of the -flto is (together with the other optimization options) described in detail in the GCC manual. By the way you should not spam optimization options like you do in your command line. For example specifying multiple -O... options will only have the effect of the last one of them. Unless you know exactly what you are doing and have carefully read the manual, just stick to use -O3 and you will be fine.