Possibility to use GCC "--enable-frame-pointer" for 64bit targets - c++

I'd like to ensure that a large set projects are build with the -fno-omit-frame-pointer flag for easier debugging with tools like ebpf.
One way of course would be to modify the build scripts of each of these projects, but that is a lot of work.
I've come across the possibility to configure gcc with --enable-frame-pointer which restores the old default from the early gcc4.x days of using -fno-omit-frame-pointer.
I've built gcc from source like that and confirmed:
❯ ./bin/gcc -m32 -O3 -Q --help=optimizers | grep omit
-fomit-frame-pointer [disabled]
❯ ./bin/gcc -m64 -O3 -Q --help=optimizers | grep omit
-fomit-frame-pointer [enabled]
Is anyone aware of a possibility to extend the effect of --enable-frame-pointer to the 64bit targets?

I believe you are using an older version of GCC because support of this flag on x64 has been enabled some time ago (see e.g. this commit).

Related

Getting Arduino IDE to compile for C++14

I've been looking to modify the build flags under Arduino's IDE 1.x, or even the Arduino CLI (which I haven't used but am willing to adopt) such that I can undefine -std=gnu++11 and instead define -std=gnu++14
I found a question related to this which gives me almost what I need:
Arduino 1.0.6: How to change compiler flag?
But it only shows how to add flags, not to remove them. I found another related post about changing arduino to GNU C++17 but the answer was it's not possible.
In this case, I know it's possible, as I do it in Platform IO in order to use the htcw_gfx library. It works great on most platforms that will run GFX reasonably anyway.
But I just don't know how to fiddle with Arduino to get it to dance the way I need to.
Any help would be greatly appreciated.
You can modify the default compile flags in the hardware/arduino/avr/platform.txt file.
$ grep -n "std" hardware/arduino/avr/platform.txt
23:compiler.c.flags=-c -g -Os {compiler.warning_flags} -std=gnu11 -ffunction-sections -fdata-sections -MMD -flto -fno-fat-lto-objects
28:compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto
For some linux systems the following would work to automatically do this:
dirname $(realpath $(which arduino)) | xargs -I{} sed -i "s/\(std=gnu++1\)1/\14/" {}/hardware/arduino/avr/platform.txt
But this is not very portable, and will not work if the user has installed Arduino with Snap (as snap has these files mounted RO).
Sources:
https://stackoverflow.com/a/28047811/6946577
https://stackoverflow.com/a/55254754/6946577

gcc-7: error: unrecognized command line option ‘-m64’

I'm trying to compile C code on a Jetson Nano and I get this error during compiling. I tried removing any occurrence of 'm -64' but it seems like its added automatically. This is the cmd where it fails: /usr/bin/gcc-7 -Wall -Wextra -Wconversion -pedantic -Wshadow -m64 -Wfatal-errors -O0 -g -o CMakeFiles/dir/testCCompiler.c.o -c /home/user/dir/CMakeFiles/CMakeTmp/testCCompiler.c
uname -a: Linux jetson-nano 4.9.140-tegra aarch64 aarch64 aarch64 GNU/Linux
gcc-7 -v: Using built-in specs.
COLLECT_GCC=gcc-7
COLLECT_LTO_WRAPPER=/usr/lib/gcc/aarch64-linux-gnu/7/lto-wrapper
Target: aarch64-linux-gnu
gcc version 7.4.0 (Ubuntu/Linaro 7.4.0-1ubuntu1~18.04.1)
CMAKE_C_COMPILER = gcc-7
CMAKE_CXX_COMPILER = g++-7
CXX_COMPILE_FLAGS = "-Wall -Werror -Wextra -Wnon-virtual-dtor -Wconversion -Wold-style-cast -pedantic -Wshadow"
C_COMPILE_FLAGS = "-Wall -Wextra -Wconversion -pedantic -Wshadow"
gcc-7: error: unrecognized command line option ‘-m64’
error: unrecognized command line option ‘-m64’
I believe you are looking for -march=armv8-a (and friends), and not -m64. The GCC arm64 options are available at 3.18.1 AArch64 Options in the manual.
Aarch64 includes ASIMD in the base specification, so there are no extra gyrations needed for it. ASIMD is "Advanced SIMD instructions", and it is what ARM calls NEON on the Aarch32 and Aarch64 architectures.
If you want to enable extensions, like CRC or Crypto, then the option would look like -march=armv8.1-a+crc or -march=armv8.1-a+crypto or -march=armv8.1-a+crc+crypto.
The equivalent x86 options would be the following. Obviously, the ARM port of GCC does not use the same model as x86. It is confusing for new users (or it was confusing for me).
-march=armv8-a → -msse2
-march=armv8.1-a+crc → -msse2 -msse4.1
-march=armv8.1-a+crypto → -msse2 -mpclmul -maes
-march=armv8.1-a+crc+crypto → -msse2 -msse4.1 -mpclmul -maes
ARM instruction set includes SHA in crypto, so the x86 options should probably include -msha. The problem is, x86 SHA did not arrive until about 8 years after carryless multiplies and AES.
Also, GCC ARM compilers usually don't understand -march=native. On older GCC compilers, the compiler will just crash. On mid-ranged GCC it is simply ignored. I believe the latest GCC compilers honor it.
This error often happens when cross-compiling with Rust/Cargo, because Cargo isn't smart enough to find cross-build tools by itself.
You need to set appropriate env vars. In the example replace x86_64_unknown_linux_gnu with your target, and paths to your cross-build paths (the example is for Debian). Watch out the env vars are case-sensitive and inconsistently named!
# for the cc crate
export HOST_CC=gcc
export CC_x86_64_unknown_linux_gnu=/usr/bin/x86_64-linux-gnu-gcc
# for Cargo
export CARGO_TARGET_X86_64-UNKNOWN-LINUX-GNU_LINKER=/usr/bin/x86_64-linux-gnu-gcc

g++: Will -fno-omit-frame-pointer be effective if specified before -O2 or -O3?

We have a complex hierarchical make file system where the CXXFLAGS is appended in several places (several separate makefiles of individual libraries).
There's one master file that seems to be getting included in every other make file. So I specified the -fno-omit-frame-pointer flag there.
When I compile, I see the above flag and after that I see -O2. My question is, if the -O2 flag sets -fomit-frame-pointer, will the latest setting take effect?
With gcc/g++ you can use the -Q --help=optimizers flags to find out the exact set of optimizations that are enabled.
With my version of gcc I get:
$ gcc -Q --help=optimizers -O2 | fgrep omit-frame-pointer
-fomit-frame-pointer [enabled]
and
$ gcc -Q --help=optimizers -fno-omit-frame-pointer -O2 | fgrep omit-frame-pointer
-fomit-frame-pointer [disabled]
So -O2 doesn't seem to overwrite the previous -fno-omit-frame-pointer.
Anyway check your environment.

Does gcc 4.8.1 enable sse by default?

I experienced crashes running an old code of mine on a system which doesn't support SSE4.1, I debugged a bit and found SSE instructions in the glibc, is that possible? Why isn't this reported in gcc 4.8.1 release notes?
You can see what optimizations are used by GCC with the following command:
$ gcc -Q --help=target
For instance, on my machine, GCC does not enable sse4.1 by default:
$ gcc -Q --help=target | grep msse4.1
-msse4.1 [disabled]
However, it is supported because it appears in /proc/cpuinfo. And indeed, if I ask GCC to optimize the generated code for my machine, it enables sse4.1:
$ gcc -Q --help=target -march=native | grep msse4.1
-msse4.1 [enabled]

gcc 4.3.3 compiler options enabled by default

I have moved from gcc version 4.0.3 to 4.3.3 and realized that -mfpmath was set to sse by default in gcc 4.3.3. This actually caused errors in my application.
In 4.0.3 the -mfpmath was 387.
I want to know how I can get all the default options enabled by gcc for a given version.
How can I dump set of all options used by gcc while compiling.
This enables me to compare version 4.0.3 vs 4.3.3.
In general it will be great if I can know a comprehensive list of things need to be checked before going for a version change in gcc .(As this has effect on performance and functionality.)
gcc -Q -v
With just a basic tiny c or cpp file as an input file. Should give you a big list of all the options passed to gcc by default, one of those might be causing sse fp math to be enabled.
In addition to compiling a specific file -Q -v, which outputs the list of passed and enabled options, as well as a lots of other version, configuration, and timing information, you can also use gcc -Q --help=target to just list default target-specific compiler options:
$ gcc --version | head -1
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
$ gcc -Q --help=target
The following options are target specific:
-m128bit-long-double [disabled]
-m32 [disabled]
-m3dnow [disabled]
-m3dnowa [disabled]
-m64 [enabled]
-m80387 [enabled]
-m8bit-idiv [disabled]
-m96bit-long-double [enabled]
-mabi=
-mabm [disabled]
-maccumulate-outgoing-args [disabled]
-maes [disabled]
-malign-double [disabled]
-malign-functions=
-malign-jumps=
-malign-loops=
-malign-stringops [enabled]
-mandroid [disabled]
-march= x86-64
...
To also include a list of target-specific assembler and linker options (but not currently their default settings), use --target-help instead of --help=target.
In addition to -Q --help=target for target-specific options, you can use -Q -O<n> --help=optimize to display which optimizer passes are on or off at a given optimization level. -Q also appears to work by itself with other --help=<blah> arguments as well.
The version I've here of gcc 4.3.3 hasn't the behavior you are complaining about. I compiled it myself so I'm pretty sure that there must be another reason for the change you are seeing than just the gcc version (like compiling for 64 bit which has always used sse AFAIR).
gcc has release notes which notifies of behavior changes. They are packaged with gcc source distribution and are available on the web. For gcc 4.3 see http://gcc.gnu.org/gcc-4.3/changes.html.