Find out what a given gcc Option/Flag is doing?

GCC docs have an overview page for all of the few hundred options it has: https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html

  • -Ae is probably the -A preprocessor option with predicate name e

-A predicate=answer

Make an assertion with the predicate predicate and answer answer. This form is preferred to the older form -A predicate(answer), which is still supported, because it does not use shell special characters.

FLAGS_PROC do not seem to be gcc options. I never heard of any option like +Z or +M2 and my GCC rejects them.

They might be HPUX linker options... ?

You didn't say which version of HPUX you are using, which may be of interest. The +z/+Z options AFAIK are relevant to HPUX only, not to gcc or binutils. If your gcc is set up the usual way, using gnu as, only the HPUX linker is used from the standard HPUX set of tools. You could check 'man ld' to see if those options are relevant to HPUX ld. Sorry, I am no longer employed where I had access to HPUX.

https://groups.google.com/d/msg/gnu.gcc.help/iWt83RMbt-8/rsAQ14_r-jgJ


I spent some time trying to compile git-1-8.5.3 from the source package at hpux.connect.org.uk (The HP-UX Porting and Archive Center) using gcc instead of the bundled HP C compiler (cc) on HP-UX 11.11 (yes, in 2021)

After much digging, the following two things became apparent:

  1. Command-lines passed to gcc or cc may be options for the compiler itself (gcc or cc) the linker (ld in my case) the assembler (as in my case), or the pre-processor (cpp in my case).
  2. +Z is a linker specific option. You can get doc on this (and other things) in the HP-UX Linker and Libraries user's guide (relevant section inserted here) @ https://support.hpe.com/hpesc/public/docDisplay?docId=c05074198&docLocale=en_US

Creating Position-Independent Code (PIC)
In PA-32 mode, the first step in creating a shared library is to create object files containing position-independent code (PIC). There are two ways to create PIC object files:

  • Compile source files with the +z or +Z compiler option, described below.
  • Write assembly language programs that use appropriate addressing modes, described in “Writing and Generating Position-Independent Code” (page 188).

In PA-32 mode, the +z and +Z options force the compiler to generate PIC object files. In PA-64 and IPF mode, the +Z option is the default.
Example Using +z
Suppose you have some C functions, stored in length.c, that convert between English and Metric length units. To compile these routines and create PIC object files with the C compiler, you can use this command:
$ cc -Aa -c +z length.c The +z option creates PIC.
You can then link it with other PIC object files to create a shared library, as discussed in “Creating the Shared Library with ld” (page 101) .
Comparing +z and +Z
In PA-32 mode, the +z and +Z options are essentially the same. Normally, you compile with +z.
However, in some instances - when the number of referenced symbols per shared library exceeds a predetermined limit - you must recompile with the +Z option instead. In this situation, the linker displays an error message and tells you to recompile the library with +Z.
In PA-64 and IPF mode, +Z is the default and the compilers ignore the options and generate PIC code.
Compiler Support for +z and +Z
In PA-32 mode, the C, C++, FORTRAN, and Pascal compilers support the +z and +Z options.
In PA-64 and IPF mode, +Z is the default for the C and C++ compilers.

Part of the challenge of discovering this is that on my system, 'man cc' returned 'no manual entry for cc'. Scanning around in /usr/share/man (find /usr/share/man -name "*cc*") it turned out that the man page was named "bundled_cc". At the bottom of bundled_cc is this line:

SEE ALSO

  System Tools

    as(1)             Translate assembly code to machine code.

Reading 'man as' provides the following:

      +z,+Z            Both of these options are used in the building
                       of shared libraries.  For a more complete
                       discussion regarding these options, see the
                       manual HP-UX Linker and Libraries User's Guide.

TL;DR: The specific answer for +Z is that +z and +Z are assembler options that create Position Independent Code (PIC). I believe the appropriate replacement in GCC is -fPIC, though I have not been successful yet in my endeavor, so it may not be the whole story.

Update: I have since completed this successfully (or at least apparently successfully) and using -fPIC seems to be the correct answer.