I"m tracking down an issue where I get different result depending on whether I use -O2 or -O1. Bisecting the compile options enabled by -O2 and not -O1, shows that I need to add -ftree-pre to -O1 to get the same results as using -O2. The gfortran documentation states that:
-ftree-pre
Perform partial redundancy elimination (PRE) on trees. This flag is enabled by default at -O2 and -O3.
gfortran 9.2 documentation
Can someone explain what this means? And if possible, what kind of code (for instance OO, pointers, arrays etc or something else) might be affected by this? This is for gfortran v9.2.0
Related
For example, when compiling a simple program
clang hello_world.c
Does the clang add any options by default? Like link library, include search path or optimization flags -O0 or exploit-mitigation flags like -mlvi-cfi?
If so, how to get a full list of default options?
Yes, Clang has default options. The document is here
I am evaluating Keil Microvision IDE on STM32H753.
I am doing compiler comparison between ARMCC5 and AC6 in the different optimisation levels. AC6 is based on Clang.
My code is not using memcpy and I have unchecked "Use MicroLIB" in the project settings , However a basic byte per byte copy loop in my code is replaced by a memcpy with AC6 (only in "high" optimisation levels). It doesn't happen with ARMCC5.
I tried using compilation options to avoid that, as described here: -ffreestanding and -disable-simplify-libcalls, at both compiler and linker levels but it didn't change (for the second option, I get an error message saying that the option is not supported).
In the ARMCLANG reference guide i've found the options -nostdlib -nostdlibinc that prevent (??) the compiler to use any function of a standard lib.
However I still need the math.h function.
Do you know how to prevent clang to use functions from the Standard C Lib that are not explicitely called in the code ?
EDIT: here is a quick and dirty reproduceable example:
https://godbolt.org/z/AX8_WV
Please do not discuss the quality of this example, I know it is dumb !!, I know about memset, etc... It is just to understand the issue
gcc know a lot about the memcpy, memset and similar functions and even they are called "the builtin functions". If you do not want those functions to be used by default just use the command line option -fno-builtin
https://godbolt.org/z/a42m4j
Why is bazel still using -std=c++0x when I explicitly passed something else?
Linkopts are options given to the linker: https://docs.bazel.build/versions/master/be/c-cpp.html#cc_binary.linkopts
Have a look at this duplicate answer: https://stackoverflow.com/a/43388168/461597
For single executables you can use copts.
I monitor a process on a PowerPC system in order to extract performance information.
How I can load the debug symbols of this process?
I use the following command
perf record -g dwarf -p 4591
and I take an error that the "dwarf cannot be found (no such file or directory)"
Could you please give me a hint how to load debug information about the functions that have been called when the report is generated?
You are using an old version of perf which do not support -g dwarf but only -g (without argument) i.e. it does not support DWARF unwinding.
perf record -g dwarf -p 4591
These days the correct option to chose a method is --call-graph whereas -g is only a flag to enable call stacks with it's default method fp.
from man perf-record.
-g
Enables call-graph (stack chain/backtrace) recording.
--call-graph
Setup and enable call-graph (stack chain/backtrace) recording,
implies -g. Default is "fp".
Allows specifying "fp" (frame pointer) or "dwarf"
(DWARF's CFI - Call Frame Information) or "lbr"
(Hardware Last Branch Record facility) as the method to collect
the information used to show the call graphs.
In some systems, where binaries are build with gcc
--fomit-frame-pointer, using the "fp" method will produce bogus
call graphs, using "dwarf", if available (perf tools linked to
the libunwind or libdw library) should be used instead.
Using the "lbr" method doesn't require any compiler options. It
will produce call graphs from the hardware LBR registers. The
main limitation is that it is only available on new Intel
platforms, such as Haswell. It can only get user call chain. It
doesn't work with branch stack sampling at the same time.
When "dwarf" recording is used, perf also records (user) stack dump
when sampled. Default size of the stack dump is 8192 (bytes).
User can change the size by passing the size after comma like
"--call-graph dwarf,4096".
By the way, try fp first - it's much more efficient, but doesn't work well with optimized binaries (e.g. --fomit-frame-pointer). Also this has very little to do with debug information. If you do not need to know the stack trace, you needn't add -g.
When Homebrew compiles libgcrypt on OS X, it patches it to use clang and add -std=gnu89 and -fheinous-gnu-extensions to the CFLAG Makefile var. What does the latter do?
https://clang.llvm.org/doxygen/SemaStmtAsm_8cpp.html says:
GNU C has an extremely ugly extension whereby they silently ignore "noop" casts in places where an lvalue is required by an inline asm. We emulate this behavior when -fheinous-gnu-extensions is specified, but provide a strong guidance to not use it.
No, I haven’t used it; I don’t know why Homebrew needed it.