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]

3.0.1 PATCH: Don't pass elided switches to COLLECT_GCC_OPTIONS


As discovered in

	http://gcc.gnu.org/ml/java-patches/2001-q3/msg00114.html

all java compilations with --main break on alpha-dec-osf* since the
gcj-only option -fencoding=UTF-8 is passed to cc1 by collect2.

This happens because very early in gcc.c (main) all switches are stored in
the COLLECT_GCC_OPTIONS environment variable and passed to collect2,
ignoring all %{<S} components in the specs used.  The patch below fixes
this by constructing COLLECT_GCC_OPTIONS every time a program is to be
executed in do_spec1.  It consists primarily of moving the code currently
used to construct the environment variable into a separate function and
ignoring switches elided by the %{<S} construct.

With this patch and two others

	http://gcc.gnu.org/ml/java-patches/2001-q3/msg00127.html
	http://gcc.gnu.org/ml/gcc-patches/2001-07/msg01381.html

gcc 3.0.1 20010719 bootstraps without regressions on alpha-dec-osf5.1 and
passes all libjava compilation tests that failed before due to the bug
above.

The execution tests still fail, though, with an /sbin/loader (the Tru64
UNIX runtime linker) error:

69995:/vol/gcc/obj/gcc-3.0.1-20010719/5.1-cc-java/alpha-dec-osf5.1/libjava/testsuite/.libs/lt-pr133: /sbin/loader: Error: libgcj.so: symbol "JNI_OnLoad" unresolved

This happens because Tru64 UNIX doesn't support weak definitions like the
one used in libjava/gnu/gcj/runtime/natFirstThread.cc:

/* This will be non-NULL if the user has preloaded a JNI library, or
   linked one into the executable.  */
extern "C"
{
#pragma weak JNI_OnLoad
  extern jint JNI_OnLoad (JavaVM *, void *) __attribute__((weak));
}

On all other platforms supporting weak symbols (like Solaris 2, IRIX 5/6),
if a pragma like the one above is the only definition of a symbol, the
runtime linker takes this as a definition with value 0, so user code can
test this and invoke the function conditionally:

	if (JNI_OnLoad != NULL)
	  JNI_OnLoad (...);

I'll investigate what to do about this.

Ok for branch and mainline?

	Rainer

-----------------------------------------------------------------------------
Rainer Orth, Faculty of Technology, Bielefeld University

Email: ro@TechFak.Uni-Bielefeld.DE


Thu Jul 19 22:05:27 2001  Rainer Orth  <ro@TechFak.Uni-Bielefeld.DE>

	* gcc.c (set_collect_gcc_options): New function, split out from
	main.
	Ignore elided switches.
	(do_spec_1): Invoke before executing command.

===================================================================
RCS file: gcc/RCS/gcc.c,v
retrieving revision 1.1
diff -up -r1.1 gcc/gcc.c
--- gcc/gcc.c	2001/06/10 00:30:43	1.1
+++ gcc/gcc.c	2001/06/09 22:30:43
@@ -243,6 +243,7 @@ static void clear_failure_queue PARAMS (
 static int check_live_switch	PARAMS ((int, int));
 static const char *handle_braces PARAMS ((const char *));
 static char *save_string	PARAMS ((const char *, int));
+static void set_collect_gcc_options PARAMS ((void));
 static int do_spec_1		PARAMS ((const char *, int, const char *));
 static const char *find_file	PARAMS ((const char *));
 static int is_directory		PARAMS ((const char *, const char *, int));
@@ -3869,6 +3870,63 @@ process_command (argc, argv)
   switches[n_switches].part1 = 0;
   infiles[n_infiles].name = 0;
 }
+
+/* Store switches not filtered out but %{<S} in spec in COLLECT_GCC_OPTIONS
+   and place that in the environment.  */
+
+static void
+set_collect_gcc_options ()
+{
+  int i;
+  int first_time;
+
+  /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
+     the compiler.  */
+  obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
+		sizeof ("COLLECT_GCC_OPTIONS=") - 1);
+
+  first_time = TRUE;
+  for (i = 0; (int) i < n_switches; i++)
+    {
+      const char *const *args;
+      const char *p, *q;
+      if (!first_time)
+	obstack_grow (&collect_obstack, " ", 1);
+
+      first_time = FALSE;
+
+      /* Ignore elided switches.  */
+      if (switches[i].live_cond == SWITCH_IGNORE)
+	continue;
+
+      obstack_grow (&collect_obstack, "'-", 2);
+      q = switches[i].part1;
+      while ((p = strchr (q, '\'')))
+	{
+	  obstack_grow (&collect_obstack, q, p - q);
+	  obstack_grow (&collect_obstack, "'\\''", 4);
+	  q = ++p;
+	}
+      obstack_grow (&collect_obstack, q, strlen (q));
+      obstack_grow (&collect_obstack, "'", 1);
+
+      for (args = switches[i].args; args && *args; args++)
+	{
+	  obstack_grow (&collect_obstack, " '", 2);
+	  q = *args;
+	  while ((p = strchr (q, '\'')))
+	    {
+	      obstack_grow (&collect_obstack, q, p - q);
+	      obstack_grow (&collect_obstack, "'\\''", 4);
+	      q = ++p;
+	    }
+	  obstack_grow (&collect_obstack, q, strlen (q));
+	  obstack_grow (&collect_obstack, "'", 1);
+	}
+    }
+  obstack_grow (&collect_obstack, "\0", 1);
+  putenv (obstack_finish (&collect_obstack));
+}
 
 /* Process a spec string, accumulating and running commands.  */
 
@@ -4012,6 +4070,8 @@ do_spec_1 (spec, inswitch, soft_matched_
 	      argbuf_index--;
 	  }
 
+	set_collect_gcc_options ();
+
 	if (argbuf_index > 0)
 	  {
 	    value = execute ();
@@ -5568,52 +5628,6 @@ main (argc, argv)
 
   process_command (argc, argv);
 
-  {
-    int first_time;
-
-    /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
-       the compiler.  */
-    obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
-		  sizeof ("COLLECT_GCC_OPTIONS=") - 1);
-
-    first_time = TRUE;
-    for (i = 0; (int) i < n_switches; i++)
-      {
-	const char *const *args;
-	const char *p, *q;
-	if (!first_time)
-	  obstack_grow (&collect_obstack, " ", 1);
-
-	first_time = FALSE;
-	obstack_grow (&collect_obstack, "'-", 2);
-	q = switches[i].part1;
-	while ((p = strchr (q, '\'')))
-	  {
-	    obstack_grow (&collect_obstack, q, p - q);
-	    obstack_grow (&collect_obstack, "'\\''", 4);
-	    q = ++p;
-	  }
-	obstack_grow (&collect_obstack, q, strlen (q));
-	obstack_grow (&collect_obstack, "'", 1);
-
-	for (args = switches[i].args; args && *args; args++)
-	  {
-	    obstack_grow (&collect_obstack, " '", 2);
-	    q = *args;
-	    while ((p = strchr (q, '\'')))
-	      {
-		obstack_grow (&collect_obstack, q, p - q);
-		obstack_grow (&collect_obstack, "'\\''", 4);
-		q = ++p;
-	      }
-	    obstack_grow (&collect_obstack, q, strlen (q));
-	    obstack_grow (&collect_obstack, "'", 1);
-	  }
-      }
-    obstack_grow (&collect_obstack, "\0", 1);
-    putenv (obstack_finish (&collect_obstack));
-  }
-
   /* Initialize the vector of specs to just the default.
      This means one element containing 0s, as a terminator.  */
 


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