Commit 603b4064 by Richard Kenner

(main): Don't turn off auto_export because of -g.

(main): Ignore the argument to -o.
(main): Place o_file after an initial .o (like crt0.o).
If we have LD_INIT_SWITCH, use init and fini functions for
executables, too.  Specify the unique function names.
(write_c_file_stat): Fix the case of destructors but no constructors.
Don't include the generic-named functions for executables.
(write_c_file): If we have LD_INIT_SWITCH, always use write_c_file_stat.
(main): Also add _GLOBAL__D? to export list.

From-SVN: r9956
parent 52f59d23
...@@ -1240,8 +1240,9 @@ main (argc, argv) ...@@ -1240,8 +1240,9 @@ main (argc, argv)
#ifdef COLLECT_EXPORT_LIST #ifdef COLLECT_EXPORT_LIST
case 'b': case 'b':
if (!strncmp (arg, "-bE:", 4) if ((!strncmp (arg, "-bE:", 4)
|| !strncmp (arg, "-bexport:", 9)) || !strncmp (arg, "-bexport:", 9))
&& strcmp (arg, "-bexport:/usr/lib/libg.exp"))
auto_export = 0; auto_export = 0;
break; break;
#endif #endif
...@@ -1258,7 +1259,10 @@ main (argc, argv) ...@@ -1258,7 +1259,10 @@ main (argc, argv)
break; break;
case 'o': case 'o':
output_file = (arg[2] == '\0') ? argv[1] : &arg[2]; if (arg[2] == '\0')
output_file = *ld1++ = *ld2++ = *++argv;
else
output_file = &arg[2];
break; break;
case 'r': case 'r':
...@@ -1289,10 +1293,15 @@ main (argc, argv) ...@@ -1289,10 +1293,15 @@ main (argc, argv)
if (first_file) if (first_file)
{ {
first_file = 0; first_file = 0;
/* place o_file BEFORE this argument! */ if (p[1] == 'o')
ld2--; *ld2++ = o_file;
*ld2++ = o_file; else
*ld2++ = arg; {
/* place o_file BEFORE this argument! */
ld2--;
*ld2++ = o_file;
*ld2++ = arg;
}
} }
if (p[1] == 'o') if (p[1] == 'o')
*object++ = arg; *object++ = arg;
...@@ -1315,19 +1324,6 @@ main (argc, argv) ...@@ -1315,19 +1324,6 @@ main (argc, argv)
p = q; p = q;
} }
/* Tell the linker that we have initializer and finalizer functions. */
if (shared_obj)
{
#ifdef LD_INIT_SWITCH
*ld2++ = LD_INIT_SWITCH;
*ld2++ = "_GLOBAL__DI";
#endif
#ifdef LD_FINI_SWITCH
*ld2++ = LD_FINI_SWITCH;
*ld2++ = "_GLOBAL__DD";
#endif
}
#ifdef COLLECT_EXPORT_LIST #ifdef COLLECT_EXPORT_LIST
/* The AIX linker will discard static constructors in object files if /* The AIX linker will discard static constructors in object files if
nothing else in the file is referenced, so look at them first. */ nothing else in the file is referenced, so look at them first. */
...@@ -1349,7 +1345,7 @@ main (argc, argv) ...@@ -1349,7 +1345,7 @@ main (argc, argv)
#endif #endif
*c_ptr++ = c_file; *c_ptr++ = c_file;
*object = *c_ptr = *ld1 = *ld2 = (char *)0; *object = *c_ptr = *ld1 = (char *)0;
if (vflag) if (vflag)
{ {
...@@ -1462,11 +1458,22 @@ main (argc, argv) ...@@ -1462,11 +1458,22 @@ main (argc, argv)
if (fclose (outf)) if (fclose (outf))
fatal_perror ("closing %s", c_file); fatal_perror ("closing %s", c_file);
/* Tell the linker that we have initializer and finalizer functions. */
#ifdef LD_INIT_SWITCH
*ld2++ = LD_INIT_SWITCH;
*ld2++ = initname;
*ld2++ = LD_FINI_SWITCH;
*ld2++ = fininame;
#endif
*ld2 = (char*)0;
#ifdef COLLECT_EXPORT_LIST #ifdef COLLECT_EXPORT_LIST
if (shared_obj) if (shared_obj)
{ {
add_to_list (&exports, initname); add_to_list (&exports, initname);
add_to_list (&exports, fininame); add_to_list (&exports, fininame);
add_to_list (&exports, "_GLOBAL__DI");
add_to_list (&exports, "_GLOBAL__DD");
exportf = fopen (export_file, "w"); exportf = fopen (export_file, "w");
if (exportf == (FILE *)0) if (exportf == (FILE *)0)
fatal_perror ("%s", export_file); fatal_perror ("%s", export_file);
...@@ -1775,6 +1782,8 @@ write_c_file_stat (stream, name) ...@@ -1775,6 +1782,8 @@ write_c_file_stat (stream, name)
fprintf (stream, "\tp = ctors + %d;\n", constructors.number); fprintf (stream, "\tp = ctors + %d;\n", constructors.number);
fprintf (stream, "\twhile (p > ctors) (*--p)();\n"); fprintf (stream, "\twhile (p > ctors) (*--p)();\n");
} }
else
fprintf (stream, "\t++count;\n");
fprintf (stream, "}\n"); fprintf (stream, "}\n");
write_list_with_asm (stream, "extern entry_pt ", destructors.first); write_list_with_asm (stream, "extern entry_pt ", destructors.first);
fprintf (stream, "void %s() {\n", fininame); fprintf (stream, "void %s() {\n", fininame);
...@@ -1791,8 +1800,11 @@ write_c_file_stat (stream, name) ...@@ -1791,8 +1800,11 @@ write_c_file_stat (stream, name)
} }
fprintf (stream, "}\n"); fprintf (stream, "}\n");
fprintf (stream, "void _GLOBAL__DI() {\n\t%s();\n}\n", initname); if (shared_obj)
fprintf (stream, "void _GLOBAL__DD() {\n\t%s();\n}\n", fininame); {
fprintf (stream, "void _GLOBAL__DI() {\n\t%s();\n}\n", initname);
fprintf (stream, "void _GLOBAL__DD() {\n\t%s();\n}\n", fininame);
}
} }
/* Write the constructor/destructor tables. */ /* Write the constructor/destructor tables. */
...@@ -1829,10 +1841,12 @@ write_c_file (stream, name) ...@@ -1829,10 +1841,12 @@ write_c_file (stream, name)
FILE *stream; FILE *stream;
char *name; char *name;
{ {
if (shared_obj) #ifndef LD_INIT_SWITCH
write_c_file_stat (stream, name); if (! shared_obj)
else
write_c_file_glob (stream, name); write_c_file_glob (stream, name);
else
#endif
write_c_file_stat (stream, name);
} }
static void static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment