https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70419

            Bug ID: 70419
           Summary: descriptions of -fpic/-fPIC and -fpic/-fPIE aren't
                    clear and contain syntax error
           Product: gcc
           Version: 5.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: driver
          Assignee: unassigned at gcc dot gnu.org
          Reporter: britton.kerin at gmail dot com
  Target Milestone: ---

It's not clear if -fPIC can be used when compiling files which are going to be
linked into executables, or not.  The description of -fpic states that the
generated code is suitable for use in a shared library.  It doesn't say it
can't be used to link into an executable.  I believe that it can be and that
this is defined behavior.  However, because the -fpie/-fPIE options also exist,
the impression is created that -fpic/-fPIC cannot be used for executables.

I think the -fpic description should begin like this:

    Generate position-independent code (PIC) suitable for use in a shared
    library or executable, ...

I think the -fPIC option description should begin like this:

    If supported for the target machine, emit position-independent code,
    suitable for dynamic linking into executables or shared libraries, and
    avoiding any limit...

The description of -fPIE contains a small syntax error.  The sentence

    These options are similar to -fpic and -fPIC, but generated position
    independent code can be only linked into executables.

is incorrect and should read:

    These options are similar to -fpic and -fPIC, but generated position
    independent code can only be linked into executables.


Here is how the -fpic/-fPIC and -fpic/-fPIE option descriptions currently read:

-fpic
    Generate position-independent code (PIC) suitable for use in a shared
library, if supported for the target machine. Such code accesses all constant
addresses through a global offset table (GOT). The dynamic loader resolves the
GOT entries when the program starts (the dynamic loader is not part of GCC; it
is part of the operating system). If the GOT size for the linked executable
exceeds a machine-specific maximum size, you get an error message from the
linker indicating that -fpic does not work; in that case, recompile with -fPIC
instead. (These maximums are 8k on the SPARC and 32k on the m68k and RS/6000.
The x86 has no such limit.)

    Position-independent code requires special support, and therefore works
only on certain machines. For the x86, GCC supports PIC for System V but not
for the Sun 386i. Code generated for the IBM RS/6000 is always
position-independent.

    When this flag is set, the macros __pic__ and __PIC__ are defined to 1.
-fPIC
    If supported for the target machine, emit position-independent code,
suitable for dynamic linking and avoiding any limit on the size of the global
offset table. This option makes a difference on the m68k, PowerPC and SPARC.

    Position-independent code requires special support, and therefore works
only on certain machines.

    When this flag is set, the macros __pic__ and __PIC__ are defined to 2.
-fpie
-fPIE
    These options are similar to -fpic and -fPIC, but generated position
independent code can be only linked into executables. Usually these options are
used when -pie GCC option is used during linking.

    -fpie and -fPIE both define the macros __pie__ and __PIE__. The macros have
the value 1 for -fpie and 2 for -fPIE.

Reply via email to