Gcc -Fpic Option

What does gcc -E mean?

It tells GCC to stop after the preprocessing stage. Details in the link.

https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html#Overall-Options

gcc -g0 and without the -g option

If you go to the GCC manual, you will find that it says:

-glevel

Request debugging information and also use level to specify how much information. The default level is 2.

Level 0 produces no debug information at all. Thus, -g0 negates -g.

So, don't use -g0 if you want debug information. If you do want debug information, remember to use the -g option both when creating the object files (-c) and when linking the program.

And compiling without -g at all and compiling with -g0 are equivalent and there is no debugging information in the resulting binaries — as you found by experimentation.

What is the -z option for in this gcc compiler command?

In your case is -z execstack

-z is passed directly to the linker along with the keyword execstack.

Source: https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html#index-z

About the execstack

Linux has in the past allowed execution of instructions on the stack and there are lots of binaries and shared libraries assuming this behaviour. Furthermore, GCC trampoline code for e.g. nested functions requires executable stack on many architectures. To avoid breaking binaries and shared libraries which need executable stack, ELF binaries and shared libraries now can be marked as requiring executable stack or not requiring it. This marking is done through the p_flags field in the PT_GNU_STACK program header entry. If the marking is missing, kernel or dynamic linker need to assume it might need executable stack. The marking is done automatically by recent GCC versions (objects using trampolines on the stack are marked as requiring executable stack, all other newly built objects are marked as not requiring it) and linker collects these markings into marking of the whole binary or shared library. The user can override this at assembly time (through --execstack or --noexecstack assembler options), at link time (through -z execstack or -z noexecstack linker options) and using the execstack tool also on an already linker binary or shared library. This tool is especially useful for third party shared libraries where it is known that they don't need executable stack or testing proves it.

Source: http://linux.die.net/man/8/execstack

Hope this helps.

How do I enable all Intel Intrinsic options in GCC?

You want to use -march=native if you want to use all the instrinsic of your local CPU.

  • option -march=cpu-type

Generate instructions for the machine type cpu-type. In contrast to
-mtune=cpu-type, which merely tunes the generated code for the specified cpu-type, -march=cpu-type allows GCC to generate code that
may not run at all on processors other than the one indicated.
Specifying -march=cpu-type implies -mtune=cpu-type, except where noted
otherwise.

  • if cpu-type is native

This selects the CPU to generate code for at compilation time by
determining the processor type of the compiling machine. Using
-march=native enables all instruction subsets supported by the local machine
(hence the result might not run on different machines).
Using -mtune=native produces code optimized for the local machine
under the constraints of the selected instruction set.

If you are targeting other CPUs, you want to target the smallest subset of intrinsics. But the instrinsic set is not always growing in the following architectures. For instance, not all instructions in tigerlake are in alderlake, and reciprocally:

Intel Tigerlake CPU with 64-bit extensions, MOVBE, MMX, SSE, SSE2,
SSE3, SSSE3, SSE4.1, SSE4.2, POPCNT, PKU, AVX, AVX2, AES, PCLMUL,
FSGSBASE, RDRND, FMA, BMI, BMI2, F16C, RDSEED, ADCX, PREFETCHW,
CLFLUSHOPT, XSAVEC, XSAVES, AVX512F, AVX512VL, AVX512BW, AVX512DQ,
AVX512CD, AVX512VBMI, AVX512IFMA, SHA, CLWB, UMIP, RDPID, GFNI,
AVX512VBMI2, AVX512VPOPCNTDQ, AVX512BITALG, AVX512VNNI, VPCLMULQDQ,
VAES, PCONFIG, WBNOINVD, MOVDIRI, MOVDIR64B, AVX512VP2INTERSECT and
KEYLOCKER instruction set support.

Intel Alderlake CPU with 64-bit extensions, MOVBE, MMX, SSE, SSE2,
SSE3, SSSE3, SSE4.1, SSE4.2, POPCNT, AES, PREFETCHW, PCLMUL, RDRND,
XSAVE, XSAVEC, XSAVES, XSAVEOPT, FSGSBASE, PTWRITE, RDPID, SGX, UMIP,
GFNI-SSE, CLWB, MOVDIRI, MOVDIR64B, CLDEMOTE, WAITPKG, ADCX, AVX,
AVX2, BMI, BMI2, F16C, FMA, LZCNT, PCONFIG, PKU, VAES, VPCLMULQDQ,
SERIALIZE, HRESET, KL, WIDEKL and AVX-VNNI instruction set support.

Reference:

https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html

Are default gcc compiler options gcc version specific or OS specific or both?

Yes, you can generally expect the default flags to be quite different. Fortunately, you don't need to know what the flags are, and you don't need to set them.

Ubuntu and Debian are pretty similar, since Ubuntu is so closely based on Debian. But you will see a variety of different options, since the actual options that GCC uses are fairly technical. You can see them by running the following:

gcc -Q -v -x c -c /dev/null

This asks GCC to compile /dev/null as a C program (-x c -c /dev/null) and print out a bunch of developer info (-Q -v). I ran this with GCC 4.4, 4.6, and 4.8 and got different results. Here are the differences between the options for 4.4 and 4.6 on my machine:

< -falign-loops
< -fargument-alias
> -fdelete-null-pointer-checks
> -fprefetch-loop-arrays
> -fsched-critical-path-heuristic
> -fsched-dep-count-heuristic
> -fsched-group-heuristic
> -fsched-last-insn-heuristic
> -fsched-rank-heuristic
> -fsched-spec-insn-heuristic
> -fshow-column
> -fstrict-volatile-bitfields
> -ftree-forwprop
> -ftree-loop-if-convert
> -ftree-phiprop
> -ftree-pta
> -ftree-slp-vectorize
> -fvar-tracking-assignments
< -mfused-madd

Here are the diffs from version 4.6 to 4.8 on my machine:

> -faggressive-loop-optimizations
> -fgnu-runtime
> -fgnu-unique
< -finline-functions-called-once
> -finline-atomics
> -fira-hoist-pressure
> -fsync-libcalls
> -ftree-coalesce-vars
< -fvect-cost-model
> -mfxsr
> -mlong-double-80

On my machine, GCC uses 80 different options by default when compiling C! The options will also change when you compile C++ or compile on different platforms.

But that's okay. You can basically ignore all of these options and just focus on the most important ones, which are the various -W warning flags, -O optimization flags (which are really just shortcuts for a ton of preselected -f flags and a few -m—on my computer, -O2 enables 63 additional flags!), and the -g debug data flag.

And of course, the basic flags, like -std=, -c, -o, -l, -I, etc.

I mean, do you really need to know what -fbranch-count-reg does? Not really.

arm-none-eabi-gcc: error: unrecognized command line option '--cref'; did you mean '--xref'?

--cref is an option for the GNU binutils linker, ld, but it is not an option of gcc

You can direct gcc to pass such options through to ld when it invokes the linker by using the the
gcc option -Wl, which has the usage:

-Wl,<ld-option>[,<ld-option>...]

So, instead of --cref, pass -Wl,--cref in your gcc commandline.

By itself, this will make the linker print the cross-reference table on the standard output. If you
would prefer to have it in a mapfile, then request a mapfile from the linker as well and the cross-reference
table will be appended to it: -Wl,--cref,-Map=mapfile

(--xref was an option for gcc long ago. It is not longer one, but the commandline
parser will still suggest it as one that you might have meant when it parses an unknown
option.)



Related Topics



Leave a reply



Submit