== Using profile-guided optimization (PGO) == {{{#!highlight sh numbers=off gcc -O3 -march=native -pg -fprofile-generate ... # Run a benchmark or program's typical load gcc -O3 -march=native -fprofile-use ... }}} == Address sanitizers == Use GCC/clang option `-fsanitize=`, with arguments: * address * leak * thread * undefined == Performance-related options == Use `-march=native` when a binary will never leave the machine upon which it is compiled. To determine which arch will be used, run: {{{#!highlight sh numbers=off gcc -c -Q -march=native --help=target | grep march }}} You can see what other performance-related options will be set by examining the output of that gcc command. If a machine has sufficient amounts of RAM, `-pipe` can make the compilation process faster. In short: {{{#!highlight sh numbers=off export CFLAGS="-O3 -march=native -pipe" export CXXFLAGS=$CFLAGS }}} == Check compiler preprocessor defines == {{{#!highlight sh numbers=off # E.g. check for the version of OpenMP supported echo | cpp -fopenmp -dM | grep -i open #define _OPENMP 200805 }}} == Compiling gcc == Download gcc tarball, run `contrib/download_prerequisites` script to download external libraries to build as part of gcc. ./configure --prefix=/opt/gcc-custom --disable-multilib --disable-libada --enable-languages=c,c++ == Static compilation == [[http://insanecoding.blogspot.ie/2012/07/creating-portable-linux-binaries.html|Insane Coding: Creating portable Linux binaries]]. Use `-static-libgcc -static-libstdc++` to include compiler support libraries. [[http://www.pixelbeat.org/programming/linux_binary_compatibility.html|Linux distribution binary compatibility]]. Discusses glibc symbol versioning, and using the `.symver` directive to select a version of a functionl. [[https://blogs.gnome.org/tvb/2013/12/14/application-bundles-revisited/ Application Bundles Revisited – Tristan's World]]. Discusses a vala script that will create a header file targeting an older glibc. https://github.com/probonopd/AppImageKit/tree/fc6b9c5e896e4408ffd52a41dcb7a0be3149f74e/LibcWrapGenerator. Above script w/ CMake integration. == ABI == [[https://access.redhat.com/solutions/19458|What gcc versions are available in Red Hat Enterprise Linux? - Red Hat Customer Portal]]: versions of GCC available on various RHEL/CentOS versions, including the Redhat Developer Toolset. GCC 5.1 dual ABI w.r.t. std::string and std::list: https://gcc.gnu.org/onlinedocs/libstdc%2B%2B/manual/using_dual_abi.html. Can be enabled by default in GCC by using `--with-default-libstdcxx-abi=c++98` == Interesting reading == [[https://gcc.gnu.org/ml/gcc/2004-06/msg01956.html|Performance benchmarks w/ calling DSO libraries]]: compares DSOs w/ Position Independent Code (PIC) enabled, static libraries, and directly calling functions. [[https://gcc.gnu.org/projects/cxx-status.html|C++-1x/z/etc support in GCC]] [[https://gcc.gnu.org/onlinedocs/libstdc++/manual/parallel_mode_using.html|Parallel STL in gcc]] ABI tracking: https://abi-laboratory.pro/tracker/timeline/glibc/ and https://github.com/lvc/abi-tracker == New features == [[https://developers.redhat.com/blog/2020/03/26/static-analysis-in-gcc-10/|Static analysis in GCC 10]] describes the new `-fanalyzer` option. `-flto=$(nproc)` for LTO. `-fwhole-program` if program fits into a single compilation unit. ---- CategoryCheatSheet