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]

Re: Exceptions workaround for older systems that don't USE_COLLECT2


On the egcs list, I wrote:
>> The culprit is config/nextstep.h, which defines INIT_SECTION_ASM_OP
>> and undefines INVOKE__main (since it still expects that NeXT's linker
>> will be handling constructors).  I'll post a patch for this on
>> egcs-patches once I've built egcs with my changes to nextstep.h (it
>> looks like a pretty obvious fix).

... and Jeff Law replied:
> Yup.  That's exactly what I was trying to determine [...]. Eagerly
> awaiting your patch.

I've enclosed my patch. Turned out I also needed to adjust collect2
slightly, since NeXT's linker needs -lcrt0.o as its first argument and
collect2 tries to drop the object file it creates in front of the first
`-l' argument. I created a #define conditional called COLLECT_OFILE_AFTER
(defined in nextstep.h, used in collect2.c) to handle this case.

    Melissa.

P.S. There was some slight strangeness in the build because I fixed
collect2 halfway through bootstrapping the compiler. I'm rebuilding
everything from scratch now (which takes about eight hours on a NeXT)
as a double check, but I'm pretty confident about the change -- certainly
everything appears to work now.

Enc.

--- gcc/config/nextstep.h.orig	Sat Dec  6 09:24:06 1997
+++ gcc/config/nextstep.h	Wed Sep 16 08:43:25 1998
@@ -208,46 +208,38 @@

 #undef	ASM_IDENTIFY_GCC
 #define ASM_IDENTIFY_GCC(asm_out_file)
+
+/* we need the call to __main to start all global destructors and constructors
+   correctly, so undef INIT_SECTION_ASM_OP and define INVOKE_main. The
+   NEXTSTEP linker does understand constructors and destructors, but it
+   does not understand exceptions, so we need to use collect2 to handle
+   things. */
+
 #undef	INIT_SECTION_ASM_OP
-#define INIT_SECTION_ASM_OP
-#undef	INVOKE__main
+#define INVOKE__main

-#undef	ASM_OUTPUT_CONSTRUCTOR
-#define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME)                       \
-  do { constructor_section ();                                  \
-       ASM_OUTPUT_ALIGN (FILE, 1);                              \
-       fprintf (FILE, "\t.long ");                              \
-       assemble_name (FILE, NAME);                              \
-       fprintf (FILE, "\n");                                    \
-       fprintf (FILE, ".reference .constructors_used\n");       \
-      } while (0)
+#define COLLECT_OFILE_AFTER

+/* We call the global destructors, constructors from __main */
+#undef	ASM_OUTPUT_CONSTRUCTOR
 #undef	ASM_OUTPUT_DESTRUCTOR
-#define ASM_OUTPUT_DESTRUCTOR(FILE,NAME)                        \
-  do { destructor_section ();                                   \
-       ASM_OUTPUT_ALIGN (FILE, 1);                              \
-       fprintf (FILE, "\t.long ");                              \
-       assemble_name (FILE, NAME);                              \
-       fprintf (FILE, "\n");                                    \
-       fprintf (FILE, ".reference .destructors_used\n");        \
-      } while (0)

 /* Don't output a .file directive.  That is only used by the assembler for
    error reporting.  */
 #undef	ASM_FILE_START
 #define ASM_FILE_START(FILE)

-#undef	ASM_FILE_END
+#undef ASM_FILE_END
 #define ASM_FILE_END(FILE)					\
   do {								\
     extern char *language_string;				\
     if (strcmp (language_string, "GNU C++") == 0)		\
       {								\
-	constructor_section ();					\
-	destructor_section ();					\
 	ASM_OUTPUT_ALIGN (FILE, 1);				\
       }								\
   } while (0)
+/* deleted: destructor_section ();				\ */
+/* deleted: constructor_section ();				\ */

 /* How to parse #pragma's */

--- gcc/config/nextstep21.h.orig	Mon Aug 11 08:57:15 1997
+++ gcc/config/nextstep21.h	Tue Sep 15 21:09:46 1998
@@ -30,28 +30,6 @@
 /* use this until a newer gdb for NeXTStep21 is available */
 #define DEFAULT_GDB_EXTENSIONS 0

-/* we need the call to __main to start all global destructors and constructors
-   correctly, so undef INIT_SECTION_ASM_OP, (see libgcc2.c line 1965)
-   and define INVOKE_main */
-#undef	INIT_SECTION_ASM_OP
-#define INVOKE__main
-
-/* We call the global destructors, constructors from __main */
-#undef	ASM_OUTPUT_CONSTRUCTOR
-#undef	ASM_OUTPUT_DESTRUCTOR
-
-#undef ASM_FILE_END
-#define ASM_FILE_END(FILE)					\
-  do {								\
-    extern char *language_string;				\
-      if (strcmp (language_string, "GNU C++") == 0)		\
-      {								\
-	ASM_OUTPUT_ALIGN (FILE, 1);				\
-      }								\
-  } while (0)
-/* deleted: destructor_section ();				\ */
-/* deleted: constructor_section ();				\ */
-
 /* Ensure correct alignment of bss data.  */
 /* ASM_OUTPUT_ALIGNED_LOCAL not needed */
 /* need ASM_OUTPUT_LOCAL instead for old NeXT-as */
--- gcc/collect2.c.orig	Sun Jul 12 05:11:28 1998
+++ gcc/collect2.c	Wed Sep 16 09:14:21 1998
@@ -1209,11 +1209,17 @@
 	    case 'l':
 	      if (first_file)
 		{
-		  /* place o_file BEFORE this argument! */
 		  first_file = 0;
+#ifndef COLLECT_OFILE_AFTER
+		  /* place o_file BEFORE this argument! */
 		  ld2--;
 		  *ld2++ = o_file;
 		  *ld2++ = arg;
+#else
+		  /* place o_file AFTER this argument! (some platforms need
+		   * -lcrt0.o to be the linker's first object file arg) */
+		  *ld2++ = o_file;
+#endif		
 		}
 #ifdef COLLECT_EXPORT_LIST
 	      {


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