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

I have a project where I was given several Makefiles wich also do Precompiler-Work with Pro*C. They have to be migrated from HP-Unix to a linux system. No problem so far, but in some ways I can't figure out (or still haven't found the right google keywords) what some given options / flags in the gcc call are doing.

Consider following for example:

FLAGS_C=-Ae -v
FLAGS_PROC=-g +Z -Ae +M2

I have not found anything in the man page regarding -Ae or +Z +M2, but just calling them on the shell shows me that they exist - but not what they will do or are awaiting.

From the output of make I can only see that +Z or +M2 seem to await a directory which is not present.

$ gcc +Z 
gcc: +Z: No such file or directory 
gcc: no input files

The output is then followed by:

<command-line>: error: missing '(' after predicate

Because of some more Makesfiles I have not yet seen I was wondering if there is any good resource out there that can help me figure out what unknown options / flags are.

gcc (SUSE Linux) 4.3.4 [gcc-4_3-branch revision 152973]

Edit: As others have mentiond +Z +M2 may definetely be no gcc option. So maybe possible that my interpretation of the gcc +Z call is just wrong understanding.



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1