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

            Bug ID: 116957
           Summary: Creation of pre-compiled header (-x c-header, -x
                    c++-header) confused by linker options (eg -Wl,-g)
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: driver
          Assignee: unassigned at gcc dot gnu.org
          Reporter: earl_chew at yahoo dot com
  Target Milestone: ---

Precompiled headers are created from C headers, or C++ headers. For example:

$ gcc -x c-header /dev/null -o /tmp/test.gch && echo Ok
Ok

Surprisingly, passing any option to the linker via -Wl, triggers an attempt to
link the precompiled header file:

$ gcc -x c-header /dev/null -o /tmp/test.gch -Wl,-g && echo Ok
/usr/bin/ld:
/usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/Scrt1.o: in function
`_start':
(.text+0x17): undefined reference to `main'
collect2: error: ld returned 1 exit status

In comparison, object files are created from C source, and passing any option
to the linker via -Wl, does not trigger an attempt to link. For example:

$ gcc -x c /dev/null -c -o /tmp/test.o && echo Ok
Ok

$ gcc -x c /dev/null -c -o /tmp/test.o -Wl,-g && echo Ok
Ok

$ gcc -x c /dev/null -c -o /tmp/test.o -Wl,bar.o && echo Ok
Ok


Options to address this issue include:

* Do nothing, and accept the inconsistency
* Any -Wl option only applies when the linker is run
* All -Wl options that do not specify a linker option (-Wl,-option or
-Wl,--option, for example -Wl,bar.o) will force the linker to run
* Ignore -Wl for -x c-header and -x c++-header
* Something else

Reply via email to