This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[7/8] Don't compile collect2 init and fini routines with -fwhole-program


As Dave explained in:

    http://gcc.gnu.org/ml/gcc-patches/2008-09/msg00573.html

collect2 should not pass -fwhole-program to gcc when compiling the
init and fini functions, because the option causes the functions
to be optimised away.  The easiest way of handling this is to
stop -fwhole-program being added to the COLLECT_GCC_OPTIONS
environment variable.

I don't think there's anything target-specific here, so I'd like
to handle it in gcc.c rather than the target files.  I'm also a bit
wary of using %<fwhole-program, because -fwhole-program seems like
the kind of option that future specs might conceivably care about.
In other words, %< is really for hiding options from other _specs_,
so it doesn't seem like a good idea to hide an option for purely
non-spec reasons.  (COLLECT_GCC_OPTIONS doesn't use the specs mechanism.)

So, while I can see it makes sense for COLLECT_GCC_OPTIONS to ignore
options that have been removed by %< (as the current code does),
I'm not sure it makes sense to use %< to remove options purely
for the sake of COLLECT_GCC_OPTIONS.

Tested on powerpc-ibm-aix6.1 and x86_64-linux-gnu.  OK to install?

Richard


gcc/
	* config/pa/pa-hpux.h (LINK_SPEC): Remove "%<fwhole-program".
	* config/pa/pa-hpux10.h (LINK_SPEC): Likewise.
	* config/pa/pa-hpux11.h (LINK_SPEC): Likewise.
	* gcc.c (set_collect_gcc_options): Don't add -fwhole-program
	to COLLECT_GCC_OPTIONS.

Index: gcc/config/pa/pa-hpux.h
===================================================================
--- gcc/config/pa/pa-hpux.h	2009-06-02 13:05:35.000000000 +0100
+++ gcc/config/pa/pa-hpux.h	2009-06-02 13:06:09.000000000 +0100
@@ -95,12 +95,10 @@ #define LIB_SPEC "%{!shared:%{!p:%{!pg:-
 #undef LINK_SPEC
 #if ((TARGET_DEFAULT | TARGET_CPU_DEFAULT) & MASK_PA_11)
 #define LINK_SPEC \
-  "%<fwhole-program\
-   %{!mpa-risc-1-0:%{!march=1.0:%{static:-L/lib/pa1.1 -L/usr/lib/pa1.1 }}}%{mlinker-opt:-O} %{!shared:-u main} %{static:-a archive} %{g*:-a archive} %{shared:-b}"
+  "%{!mpa-risc-1-0:%{!march=1.0:%{static:-L/lib/pa1.1 -L/usr/lib/pa1.1 }}}%{mlinker-opt:-O} %{!shared:-u main} %{static:-a archive} %{g*:-a archive} %{shared:-b}"
 #else
 #define LINK_SPEC \
-  "%<fwhole-program\
-   %{mlinker-opt:-O} %{!shared:-u main} %{static:-a archive} %{g*:-a archive} %{shared:-b}"
+  "%{mlinker-opt:-O} %{!shared:-u main} %{static:-a archive} %{g*:-a archive} %{shared:-b}"
 #endif
 
 /* hpux8 and later have C++ compatible include files, so do not
Index: gcc/config/pa/pa-hpux10.h
===================================================================
--- gcc/config/pa/pa-hpux10.h	2009-06-02 13:05:35.000000000 +0100
+++ gcc/config/pa/pa-hpux10.h	2009-06-02 13:06:09.000000000 +0100
@@ -82,8 +82,7 @@ #define CPP_SPEC "%{threads: -D_REENTRAN
 #undef LINK_SPEC
 #if ((TARGET_DEFAULT | TARGET_CPU_DEFAULT) & MASK_PA_11)
 #define LINK_SPEC \
-  "%<fwhole-program\
-   %{!mpa-risc-1-0:%{!march=1.0:%{static:-L/lib/pa1.1 -L/usr/lib/pa1.1 }}}\
+  "%{!mpa-risc-1-0:%{!march=1.0:%{static:-L/lib/pa1.1 -L/usr/lib/pa1.1 }}}\
    %{!shared:%{p:-L/lib/libp %{!static:\
      %nWarning: consider linking with `-static' as system libraries with\n\
      %n  profiling support are only provided in archive format}}}\
@@ -94,8 +93,7 @@ #define LINK_SPEC \
    %{static:-a archive} %{shared:-b}"
 #else
 #define LINK_SPEC \
-  "%<fwhole-program\
-   %{!shared:%{p:-L/lib/libp %{!static:\
+  "%{!shared:%{p:-L/lib/libp %{!static:\
      %nWarning: consider linking with `-static' as system libraries with\n\
      %n  profiling support are only provided in archive format}}}\
    %{!shared:%{pg:-L/lib/libp %{!static:\
Index: gcc/config/pa/pa-hpux11.h
===================================================================
--- gcc/config/pa/pa-hpux11.h	2009-06-02 13:05:35.000000000 +0100
+++ gcc/config/pa/pa-hpux11.h	2009-06-02 13:06:09.000000000 +0100
@@ -104,8 +104,7 @@ #define CPP_SPEC \
    want dereferencing of a NULL pointer to cause a SEGV.  */
 #undef LINK_SPEC
 #define LINK_SPEC \
-  "%<fwhole-program\
-   %{!shared:%{p:-L/lib/libp -L/usr/lib/libp %{!static:\
+  "%{!shared:%{p:-L/lib/libp -L/usr/lib/libp %{!static:\
      %nWarning: consider linking with `-static' as system libraries with\n\
      %n  profiling support are only provided in archive format}}}\
    %{!shared:%{pg:-L/lib/libp -L/usr/lib/libp %{!static:\
Index: gcc/gcc.c
===================================================================
--- gcc/gcc.c	2009-06-02 13:05:35.000000000 +0100
+++ gcc/gcc.c	2009-06-02 13:26:45.000000000 +0100
@@ -4429,6 +4429,11 @@ set_collect_gcc_options (void)
       if ((switches[i].live_cond & SWITCH_IGNORE) != 0)
 	continue;
 
+      /* Don't use -fwhole-program when compiling the init and fini routines,
+	 since we'd wrongly assume that the routines aren't needed.  */
+      if (strcmp (switches[i].part1, "fwhole-program") == 0)
+	continue;
+
       obstack_grow (&collect_obstack, "'-", 2);
       q = switches[i].part1;
       while ((p = strchr (q, '\'')))


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]