Deleted Added
full compact
1,5c1,3
< /* Collect static initialization info into data structures
< that can be traversed by C++ initialization and finalization
< routines.
<
< Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
---
> /* Collect static initialization info into data structures that can be
> traversed by C++ initialization and finalization routines.
> Copyright (C) 1992, 93-97, 1998 Free Software Foundation, Inc.
28c26
< /* Build tables of static constructors and destructors and run ld. */
---
> /* Build tables of static constructors and destructors and run ld. */
31,34c29
< #include <sys/types.h>
< #include <stdio.h>
< #include <ctype.h>
< #include <errno.h>
---
> #include "system.h"
36d30
< #include <sys/file.h>
38,40d31
< #ifdef NO_WAIT_H
< #include <sys/wait.h>
< #endif
46,48c37,39
<
< #ifndef errno
< extern int errno;
---
> #include "gansidecl.h"
> #ifdef __CYGWIN32__
> #include <process.h>
51,61d41
< #ifndef HAVE_STRERROR
< #if defined(bsd4_4)
< extern const char *const sys_errlist[];
< #else
< extern char *sys_errlist[];
< #endif
< extern int sys_nerr;
< #else
< char *strerror();
< #endif
<
66,69d45
< #if !defined (__STDC__) && !defined (const)
< #define const
< #endif
<
74,88d49
< /* Add prototype support. */
< #ifndef PROTO
< #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
< #define PROTO(ARGS) ARGS
< #else
< #define PROTO(ARGS) ()
< #endif
< #endif
<
< #ifndef R_OK
< #define R_OK 4
< #define W_OK 2
< #define X_OK 1
< #endif
<
102,108c63
< /* On MSDOS, write temp files in current dir
< because there's no place else we can expect to use. */
< #ifdef __MSDOS__
< #ifndef P_tmpdir
< #define P_tmpdir "./"
< #endif
< #endif
---
> extern char *make_temp_file PROTO ((char *));
113c68
< the utilities aren't correct for a cross-compiler; we have to hope that
---
> the utilities are not correct for a cross-compiler; we have to hope that
126c81
< /* If we can't use a special method, use the ordinary one:
---
> /* If we cannot use a special method, use the ordinary one:
129c84
< but that isn't quite as unpleasant as special headers. */
---
> but that is not quite as unpleasant as special headers. */
161,164d115
< #ifdef XCOFF_DEBUGGING_INFO
< #define XCOFF_SCAN_LIBS
< #endif
<
203c154
< #if defined (LDD_SUFFIX) || SUNOS4_SHARED_LIBRARIES || defined(XCOFF_SCAN_LIBS)
---
> #if defined (LDD_SUFFIX) || SUNOS4_SHARED_LIBRARIES
213c164
< /* Linked lists of constructor and destructor names. */
---
> /* Linked lists of constructor and destructor names. */
239c190
< #ifndef DONT_DECLARE_SYS_SIGLIST
---
> #ifndef SYS_SIGLIST_DECLARED
247a199,202
> #ifdef COLLECT_EXPORT_LIST
> static int export_flag; /* true if -bE */
> static int aix64_flag; /* true if -b64 */
> #endif
253,257c208,213
< static int temp_filename_length; /* Length of temp_filename */
< static char *temp_filename; /* Base of temp filenames */
< static char *c_file; /* <xxx>.c for constructor/destructor list. */
< static char *o_file; /* <xxx>.o for constructor/destructor list. */
< static char *export_file; /* <xxx>.x for AIX export list. */
---
> static char *c_file; /* <xxx>.c for constructor/destructor list. */
> static char *o_file; /* <xxx>.o for constructor/destructor list. */
> #ifdef COLLECT_EXPORT_LIST
> static char *export_file; /* <xxx>.x for AIX export list. */
> static char *import_file; /* <xxx>.p for AIX import list. */
> #endif
260a217
> #ifdef LDD_SUFFIX
261a219
> #endif
267a226
> #ifdef COLLECT_EXPORT_LIST
268a228,231
> static struct head imports; /* list of imported symbols */
> static struct head undefined; /* list of undefined symbols */
> #endif
> static struct head frame_tables; /* list of frame unwind info tables */
277d239
< extern char *getenv ();
280a243,246
> #ifndef GET_ENVIRONMENT
> #define GET_ENVIRONMENT(ENV_VALUE,ENV_NAME) ENV_VALUE = getenv (ENV_NAME)
> #endif
>
286,287c252,253
< char *prefix; /* String to prepend to the path. */
< struct prefix_list *next; /* Next in linked list. */
---
> char *prefix; /* String to prepend to the path. */
> struct prefix_list *next; /* Next in linked list. */
297,299c263,273
< void collect_exit PROTO((int));
< void collect_execute PROTO((char *, char **, char *));
< void dump_file PROTO((char *));
---
> #ifdef COLLECT_EXPORT_LIST
> /* Lists to keep libraries to be scanned for global constructors/destructors. */
> static struct head libs; /* list of libraries */
> static struct path_prefix cmdline_lib_dirs; /* directories specified with -L */
> static struct path_prefix libpath_lib_dirs; /* directories in LIBPATH */
> static struct path_prefix *libpaths[3] = {&cmdline_lib_dirs,
> &libpath_lib_dirs, NULL};
> static char *libexts[3] = {"a", "so", NULL}; /* possible library extentions */
> #endif
>
> static char *my_strerror PROTO((int));
302,303d275
< static void choose_temp_base PROTO((void));
< static int is_in_prefix_list PROTO((struct path_prefix *, char *, int));
312a285,290
> #ifdef COLLECT_EXPORT_LIST
> static void dump_list PROTO((FILE *, char *, struct id *));
> #endif
> #if 0
> static void dump_prefix_list PROTO((FILE *, char *, struct prefix_list *));
> #endif
315d292
< static void write_export_file PROTO((FILE *));
316a294
> #ifdef SCAN_LIBRARIES
317a296,304
> #endif
> #ifdef COLLECT_EXPORT_LIST
> static int is_in_list PROTO((char *, struct id *));
> static void write_export_file PROTO((FILE *));
> static void write_import_file PROTO((FILE *));
> static char *resolve_lib_name PROTO((char *));
> static int use_import_list PROTO((char *));
> static int ignore_library PROTO((char *));
> #endif
322,324d308
< extern char *index ();
< extern char *rindex ();
< extern void free ();
348c332
< char *
---
> static char *
381a366
> #ifdef COLLECT_EXPORT_LIST
384a370,373
> if (import_file != 0 && import_file[0])
> maybe_unlink (import_file);
> #endif
>
398c387
< /* Die when sys call fails. */
---
> /* Die when sys call fails. */
409c398
< collect_exit (1);
---
> collect_exit (FATAL_EXIT_CODE);
412c401
< /* Just die. */
---
> /* Just die. */
421c410
< collect_exit (1);
---
> collect_exit (FATAL_EXIT_CODE);
457a447,454
> #ifdef COLLECT_EXPORT_LIST
> if (export_file != 0 && export_file[0])
> maybe_unlink (export_file);
>
> if (import_file != 0 && import_file[0])
> maybe_unlink (import_file);
> #endif
>
472c469
< return (char *)0;
---
> return (char *) 0;
484c481
< return (char *)0;
---
> return (char *) 0;
516a514,546
>
> /* Parse a reasonable subset of shell quoting syntax. */
>
> static char *
> extract_string (pp)
> char **pp;
> {
> char *p = *pp;
> int backquote = 0;
> int inside = 0;
>
> for (;;)
> {
> char c = *p;
> if (c == '\0')
> break;
> ++p;
> if (backquote)
> obstack_1grow (&temporary_obstack, c);
> else if (! inside && c == ' ')
> break;
> else if (! inside && c == '\\')
> backquote = 1;
> else if (c == '\'')
> inside = !inside;
> else
> obstack_1grow (&temporary_obstack, c);
> }
>
> obstack_1grow (&temporary_obstack, '\0');
> *pp = p;
> return obstack_finish (&temporary_obstack);
> }
531c561
< c != EOF && (isalnum (c) || c == '_' || c == '$' || c == '.'))
---
> c != EOF && (ISALNUM (c) || c == '_' || c == '$' || c == '.'))
572a603
> fclose (stream);
592a624
> { "GLOBAL__F_", sizeof ("GLOBAL__F_")-1, 5, 0 },
595a628
> { "GLOBAL_.F.", sizeof ("GLOBAL_.F.")-1, 5, 0 },
599a633
> { "GLOBAL_$F$", sizeof ("GLOBAL_$F$")-1, 5, 0 },
603c637
< #ifdef CFRONT_LOSSAGE /* Don't collect cfront initialization functions.
---
> #ifdef CFRONT_LOSSAGE /* Do not collect cfront initialization functions.
631d664
<
633,667d665
< /* Compute a string to use as the base of all temporary file names.
< It is substituted for %g. */
<
< static void
< choose_temp_base ()
< {
< char *base = getenv ("TMPDIR");
< int len;
<
< if (base == (char *)0)
< {
< #ifdef P_tmpdir
< if (access (P_tmpdir, R_OK | W_OK) == 0)
< base = P_tmpdir;
< #endif
< if (base == (char *)0)
< {
< if (access ("/usr/tmp", R_OK | W_OK) == 0)
< base = "/usr/tmp/";
< else
< base = "/tmp/";
< }
< }
<
< len = strlen (base);
< temp_filename = xmalloc (len + sizeof("/ccXXXXXX") + 1);
< strcpy (temp_filename, base);
< if (len > 0 && temp_filename[len-1] != '/')
< temp_filename[len++] = '/';
< strcpy (temp_filename + len, "ccXXXXXX");
<
< mktemp (temp_filename);
< temp_filename_length = strlen (temp_filename);
< }
<
733,774d730
< /* Names under which we were executed. Never return one of those files in our
< searches. */
<
< static struct path_prefix our_file_names;
<
< /* Determine if STRING is in PPREFIX.
<
< This utility is currently only used to look up file names. Prefix lists
< record directory names. This matters to us because the latter has a
< trailing slash, so I've added a flag to handle both. */
<
< static int
< is_in_prefix_list (pprefix, string, filep)
< struct path_prefix *pprefix;
< char *string;
< int filep;
< {
< struct prefix_list *pl;
<
< if (filep)
< {
< int len = strlen (string);
<
< for (pl = pprefix->plist; pl; pl = pl->next)
< {
< if (strncmp (pl->prefix, string, len) == 0
< && strcmp (pl->prefix + len, "/") == 0)
< return 1;
< }
< }
< else
< {
< for (pl = pprefix->plist; pl; pl = pl->next)
< {
< if (strcmp (pl->prefix, string) == 0)
< return 1;
< }
< }
<
< return 0;
< }
<
778c734
< Return 0 if not found, otherwise return its name, allocated with malloc. */
---
> Return 0 if not found, otherwise return its name, allocated with malloc. */
788a745,747
> if (debug)
> fprintf (stderr, "Looking for '%s'\n", name);
>
797c756,761
< if (*name == '/')
---
> if (*name == '/'
> #ifdef DIR_SEPARATOR
> || (DIR_SEPARATOR == '\\' && name[1] == ':'
> && (name[2] == DIR_SEPARATOR || name[2] == '/'))
> #endif
> )
801a766,769
>
> if (debug)
> fprintf (stderr, " - found: absolute path\n");
>
803a772,774
>
> if (debug)
> fprintf (stderr, " - failed to locate using absolute path\n");
810,813c781,782
< if (! is_in_prefix_list (&our_file_names, temp, 1)
< /* This is a kludge, but there seems no way around it. */
< && strcmp (temp, "./ld") != 0
< && access (temp, X_OK) == 0)
---
>
> if (access (temp, X_OK) == 0)
820,821c789,790
< if (! is_in_prefix_list (&our_file_names, temp, 1)
< && access (temp, X_OK) == 0)
---
>
> if (access (temp, X_OK) == 0)
825a795,797
> if (debug && pprefix->plist == NULL)
> fprintf (stderr, " - failed: no entries in prefix list\n");
>
873c845,846
< char *p = getenv (env);
---
> char *p;
> GET_ENVIRONMENT (p, env);
886a860,862
> if (debug)
> fprintf (stderr, "Convert string '%s' into prefixes, separator = '%c'\n", p, PATH_SEPARATOR);
>
904a881,883
> if (debug)
> fprintf (stderr, " - add prefix: %s\n", nstore);
>
915c894
< /* Main program. */
---
> /* Main program. */
925d903
< char *full_real_ld_suffix = real_ld_suffix;
940c918,922
< FILE *outf, *exportf;
---
> FILE *outf;
> #ifdef COLLECT_EXPORT_LIST
> FILE *exportf;
> FILE *importf;
> #endif
942,943d923
< char *collect_name;
< char *collect_names;
954c934
< int num_c_args = argc+7;
---
> int num_c_args = argc+9;
958d937
< vflag = 1;
960a940,952
> /* Parse command line early for instances of -debug. This allows
> the debug flag to be set before functions like find_a_file()
> are called. */
> {
> int i;
>
> for (i = 1; argv[i] != NULL; i ++)
> if (! strcmp (argv[i], "-debug"))
> debug = 1;
> vflag = debug;
> }
>
> #ifndef DEFAULT_A_OUT_NAME
961a954,956
> #else
> output_file = DEFAULT_A_OUT_NAME;
> #endif
965a961
>
966a963,971
> p = getenv ("COLLECT_GCC_OPTIONS");
> while (p && *p)
> {
> char *q = extract_string (&p);
> if (*q == '-' && (q[1] == 'm' || q[1] == 'f'))
> num_c_args++;
> }
> obstack_free (&temporary_obstack, temporary_firstobj);
> ++num_c_args;
968,1023d972
< /* We must check that we do not call ourselves in an infinite
< recursion loop. We append the name used for us to the COLLECT_NAMES
< environment variable.
<
< In practice, collect will rarely invoke itself. This can happen now
< that we are no longer called gld. A perfect example is when running
< gcc in a build directory that has been installed. When looking for
< ld's, we'll find our installed version and believe that's the real ld. */
<
< /* We must also append COLLECT_NAME to COLLECT_NAMES to watch for the
< previous version of collect (the one that used COLLECT_NAME and only
< handled two levels of recursion). If we don't we may mutually recurse
< forever. This can happen (I think) when bootstrapping the old version
< and a new one is installed (rare, but we should handle it).
< ??? Hopefully references to COLLECT_NAME can be removed at some point. */
<
< collect_name = (char *) getenv ("COLLECT_NAME");
< collect_names = (char *) getenv ("COLLECT_NAMES");
<
< p = (char *) xmalloc (strlen ("COLLECT_NAMES=")
< + (collect_name ? strlen (collect_name) + 1 : 0)
< + (collect_names ? strlen (collect_names) + 1 : 0)
< + strlen (argv[0]) + 1);
< strcpy (p, "COLLECT_NAMES=");
< if (collect_name != 0)
< sprintf (p + strlen (p), "%s%c", collect_name, PATH_SEPARATOR);
< if (collect_names != 0)
< sprintf (p + strlen (p), "%s%c", collect_names, PATH_SEPARATOR);
< strcat (p, argv[0]);
< putenv (p);
<
< prefix_from_env ("COLLECT_NAMES", &our_file_names);
<
< /* Set environment variable COLLECT_NAME to our name so the previous version
< of collect won't find us. If it does we'll mutually recurse forever.
< This can happen when bootstrapping the new version and an old version is
< installed.
< ??? Hopefully this bit of code can be removed at some point. */
<
< p = xmalloc (strlen ("COLLECT_NAME=") + strlen (argv[0]) + 1);
< sprintf (p, "COLLECT_NAME=%s", argv[0]);
< putenv (p);
<
< p = (char *) getenv ("COLLECT_GCC_OPTIONS");
< if (p)
< while (*p)
< {
< char *q = p;
< while (*q && *q != ' ') q++;
< if (*p == '-' && p[1] == 'm')
< num_c_args++;
<
< if (*q) q++;
< p = q;
< }
<
1057c1006
< But it we look for a took in the system directories, we need to
---
> But it we look for a program in the system directories, we need to
1066,1071d1014
< full_real_ld_suffix
< = xcalloc (strlen (real_ld_suffix) + strlen (target_machine) + 2, 1);
< strcpy (full_real_ld_suffix, target_machine);
< strcat (full_real_ld_suffix, "-");
< strcat (full_real_ld_suffix, real_ld_suffix);
<
1134,1145d1076
< /* If we've invoked ourselves, try again with LD_FILE_NAME. */
<
< if (collect_names != 0)
< {
< if (ld_file_name != 0)
< {
< argv[0] = ld_file_name;
< execvp (argv[0], argv);
< }
< fatal ("cannot find `ld'");
< }
<
1201,1210c1132,1139
< /* Make temp file names. */
< choose_temp_base ();
< c_file = xcalloc (temp_filename_length + sizeof (".c"), 1);
< o_file = xcalloc (temp_filename_length + sizeof (".o"), 1);
< export_file = xmalloc (temp_filename_length + sizeof (".x"));
< ldout = xmalloc (temp_filename_length + sizeof (".ld"));
< sprintf (ldout, "%s.ld", temp_filename);
< sprintf (c_file, "%s.c", temp_filename);
< sprintf (o_file, "%s.o", temp_filename);
< sprintf (export_file, "%s.x", temp_filename);
---
> /* Make temp file names. */
> c_file = make_temp_file (".c");
> o_file = make_temp_file (".o");
> #ifdef COLLECT_EXPORT_LIST
> export_file = make_temp_file (".x");
> import_file = make_temp_file (".p");
> #endif
> ldout = make_temp_file (".ld");
1211a1141,1142
> *c_ptr++ = "-x";
> *c_ptr++ = "c";
1215a1147,1172
> #ifdef COLLECT_EXPORT_LIST
> /* Generate a list of directories from LIBPATH. */
> prefix_from_env ("LIBPATH", &libpath_lib_dirs);
> /* Add to this list also two standard directories where
> AIX loader always searches for libraries. */
> add_prefix (&libpath_lib_dirs, "/lib");
> add_prefix (&libpath_lib_dirs, "/usr/lib");
> #endif
>
> /* Get any options that the upper GCC wants to pass to the sub-GCC.
>
> AIX support needs to know if -shared has been specified before
> parsing commandline arguments. */
>
> p = getenv ("COLLECT_GCC_OPTIONS");
> while (p && *p)
> {
> char *q = extract_string (&p);
> if (*q == '-' && (q[1] == 'm' || q[1] == 'f'))
> *c_ptr++ = obstack_copy0 (&permanent_obstack, q, strlen (q));
> if (strncmp (q, "-shared", sizeof ("-shared") - 1) == 0)
> shared_obj = 1;
> }
> obstack_free (&temporary_obstack, temporary_firstobj);
> *c_ptr++ = "-fno-exceptions";
>
1223c1180
< /* Parse arguments. Remember output file spec, pass the rest to ld. */
---
> /* Parse arguments. Remember output file spec, pass the rest to ld. */
1227c1184
< while ((arg = *++argv) != (char *)0)
---
> while ((arg = *++argv) != (char *) 0)
1234a1192,1202
> #ifdef COLLECT_EXPORT_LIST
> /* We want to disable automatic exports on AIX when user
> explicitly puts an export list in command line */
> case 'b':
> if (arg[2] == 'E' || strncmp (&arg[2], "export", 6) == 0)
> export_flag = 1;
> if (arg[2] == '6' && arg[3] == '4')
> aix64_flag = 1;
> break;
> #endif
>
1238,1239c1206
< debug = 1;
< vflag = 1;
---
> /* Already parsed. */
1253a1221,1237
> #ifdef COLLECT_EXPORT_LIST
> {
> /* Resolving full library name. */
> char *s = resolve_lib_name (arg+2);
>
> /* If we will use an import list for this library,
> we should exclude it from ld args. */
> if (use_import_list (s))
> {
> ld1--;
> ld2--;
> }
>
> /* Saving a full library name. */
> add_to_list (&libs, s);
> }
> #endif
1255a1240,1246
> #ifdef COLLECT_EXPORT_LIST
> /* Saving directories where to search for libraries. */
> case 'L':
> add_prefix (&cmdline_lib_dirs, arg+2);
> break;
> #endif
>
1272c1263
< won't work. Thus we strip in the second ld run, or
---
> will not work. Thus we strip in the second ld run, or
1285,1286c1276,1278
< else if ((p = rindex (arg, '.')) != (char *)0
< && (strcmp (p, ".o") == 0 || strcmp (p, ".a") == 0))
---
> else if ((p = rindex (arg, '.')) != (char *) 0
> && (strcmp (p, ".o") == 0 || strcmp (p, ".a") == 0
> || strcmp (p, ".so") == 0))
1302a1295,1310
> #ifdef COLLECT_EXPORT_LIST
> /* libraries can be specified directly, i.e. without -l flag. */
> else
> {
> /* If we will use an import list for this library,
> we should exclude it from ld args. */
> if (use_import_list (arg))
> {
> ld1--;
> ld2--;
> }
>
> /* Saving a full library name. */
> add_to_list (&libs, arg);
> }
> #endif
1306,1321d1313
< /* Get any options that the upper GCC wants to pass to the sub-GCC. */
< p = (char *) getenv ("COLLECT_GCC_OPTIONS");
< if (p)
< while (*p)
< {
< char *q = p;
< while (*q && *q != ' ') q++;
< if (*p == '-' && (p[1] == 'm' || p[1] == 'f'))
< *c_ptr++ = savestring (p, q - p);
< if (strncmp (p, "-shared", sizeof ("shared") - 1) == 0)
< shared_obj = 1;
<
< if (*q) q++;
< p = q;
< }
<
1322a1315,1321
> /* This is added only for debugging purposes. */
> if (debug)
> {
> fprintf (stderr, "List of libraries:\n");
> dump_list (stderr, "\t", libs.first);
> }
>
1325,1327d1323
< while (object_lst < object)
< scan_prog_file (*object_lst++, PASS_OBJ);
<
1329,1332c1325,1342
< char *buf = alloca (strlen (export_file) + 5);
< sprintf (buf, "-bE:%s", export_file);
< *ld1++ = buf;
< *ld2++ = buf;
---
> char **export_object_lst = object_lst;
> while (export_object_lst < object)
> scan_prog_file (*export_object_lst++, PASS_OBJ);
> }
> {
> struct id *list = libs.first;
> for (; list; list = list->next)
> scan_prog_file (list->name, PASS_FIRST);
> }
> {
> char *buf1 = alloca (strlen (export_file) + 5);
> char *buf2 = alloca (strlen (import_file) + 5);
> sprintf (buf1, "-bE:%s", export_file);
> sprintf (buf2, "-bI:%s", import_file);
> *ld1++ = buf1;
> *ld2++ = buf1;
> *ld1++ = buf2;
> *ld2++ = buf2;
1334c1344
< if (exportf == (FILE *)0)
---
> if (exportf == (FILE *) 0)
1338a1349,1354
> importf = fopen (import_file, "w");
> if (importf == (FILE *) 0)
> fatal_perror ("%s", import_file);
> write_import_file (importf);
> if (fclose (importf))
> fatal_perror ("closing %s", import_file);
1343c1359
< *object = *c_ptr = *ld1 = (char *)0;
---
> *object = *c_ptr = *ld1 = (char *) 0;
1374,1377d1389
< ptr = getenv ("COLLECT_NAMES");
< if (ptr)
< fprintf (stderr, "COLLECT_NAMES = %s\n", ptr);
<
1397c1409,1410
< /* Load the program, searching all libraries. */
---
> /* Load the program, searching all libraries and attempting to provide
> undefined symbols from repository information. */
1399,1402c1412,1415
< collect_execute ("ld", ld1_argv, ldout);
< do_wait ("ld");
< dump_file (ldout);
< unlink (ldout);
---
> /* On AIX we do this later. */
> #ifndef COLLECT_EXPORT_LIST
> do_tlink (ld1_argv, object_lst);
> #endif
1404,1407c1417,1435
< /* If -r or they'll be run via some other method, don't build the
< constructor or destructor list, just return now. */
< if (rflag || ! do_collecting)
< return 0;
---
> /* If -r or they will be run via some other method, do not build the
> constructor or destructor list, just return now. */
> if (rflag
> #ifndef COLLECT_EXPORT_LIST
> || ! do_collecting
> #endif
> )
> {
> #ifdef COLLECT_EXPORT_LIST
> /* But make sure we delete the export file we may have created. */
> if (export_file != 0 && export_file[0])
> maybe_unlink (export_file);
> if (import_file != 0 && import_file[0])
> maybe_unlink (import_file);
> #endif
> maybe_unlink (c_file);
> maybe_unlink (o_file);
> return 0;
> }
1411c1439
< Write the constructor and destructor tables to a .s file and reload. */
---
> Write the constructor and destructor tables to a .s file and reload. */
1412a1441,1442
> /* On AIX we already done scanning for global constructors/destructors. */
> #ifndef COLLECT_EXPORT_LIST
1413a1444
> #endif
1426c1457,1458
< #ifdef LDD_SUFFIX
---
> && frame_tables.number == 0
> #if defined (SCAN_LIBRARIES) || defined (COLLECT_EXPORT_LIST)
1428c1460
< stubs into the shared library so that we don't have to relink
---
> stubs into the shared library so that we do not have to relink
1433a1466,1469
> #ifdef COLLECT_EXPORT_LIST
> /* Doing tlink without additional code generation */
> do_tlink (ld1_argv, object_lst);
> #endif
1445a1482
> maybe_unlink (import_file);
1446a1484,1485
> maybe_unlink (c_file);
> maybe_unlink (o_file);
1452c1491
< if (outf == (FILE *)0)
---
> if (outf == (FILE *) 0)
1467c1506
< *ld2 = (char*)0;
---
> *ld2 = (char*) 0;
1477c1516
< if (exportf == (FILE *)0)
---
> if (exportf == (FILE *) 0)
1499c1538
< Link the tables in with the rest of the program. */
---
> Link the tables in with the rest of the program. */
1501a1541,1545
> #ifdef COLLECT_EXPORT_LIST
> /* On AIX we must call tlink because of possible templates resolution */
> do_tlink (ld2_argv, object_lst);
> #else
> /* Otherwise, simply call ld because tlink is already done */
1506a1551
> #endif
1509a1555,1556
>
> #ifdef COLLECT_EXPORT_LIST
1510a1558,1560
> maybe_unlink (import_file);
> #endif
>
1515c1565
< /* Wait for a process to finish, and exit if a non-zero status is found. */
---
> /* Wait for a process to finish, and exit if a non-zero status is found. */
1542c1592
< collect_exit (127);
---
> collect_exit (FATAL_EXIT_CODE);
1584c1634
< for (p_argv = &argv[1]; (str = *p_argv) != (char *)0; p_argv++)
---
> for (p_argv = &argv[1]; (str = *p_argv) != (char *) 0; p_argv++)
1593,1594c1643,1644
< /* If we can't find a program we need, complain error. Do this here
< since we might not end up needing something that we couldn't find. */
---
> /* If we cannot find a program we need, complain error. Do this here
> since we might not end up needing something that we could not find. */
1598a1649
> #ifndef __CYGWIN32__
1615c1666
< fatal_perror ("redirecting stdout");
---
> fatal_perror ("redirecting stdout: %s", redir);
1617c1668
< fatal_perror ("redirecting stderr");
---
> fatal_perror ("redirecting stderr: %s", redir);
1622a1674,1678
> #else
> pid = _spawnvp (_P_NOWAIT, argv[0], argv);
> if (pid == -1)
> fatal ("spawnvp failed");
> #endif
1696a1753,1770
> #ifdef COLLECT_EXPORT_LIST
> /* This function is really used only on AIX, but may be useful. */
> static int
> is_in_list (prefix, list)
> char *prefix;
> struct id *list;
> {
> while (list)
> {
> if (!strcmp (prefix, list->name)) return 1;
> list = list->next;
> }
> return 0;
> }
> #endif
>
> /* Added for debugging purpose. */
> #ifdef COLLECT_EXPORT_LIST
1697a1772,1800
> dump_list (stream, prefix, list)
> FILE *stream;
> char *prefix;
> struct id *list;
> {
> while (list)
> {
> fprintf (stream, "%s%s,\n", prefix, list->name);
> list = list->next;
> }
> }
> #endif
>
> #if 0
> static void
> dump_prefix_list (stream, prefix, list)
> FILE *stream;
> char *prefix;
> struct prefix_list *list;
> {
> while (list)
> {
> fprintf (stream, "%s%s,\n", prefix, list->prefix);
> list = list->next;
> }
> }
> #endif
>
> static void
1719a1823
> int frames = (frame_tables.number > 0);
1752c1856
< if (!isalnum (*q))
---
> if (!ISALNUM (*q))
1772a1877,1908
>
> if (frames)
> {
> write_list_with_asm (stream, "extern void *", frame_tables.first);
>
> fprintf (stream, "\tstatic void *frame_table[] = {\n");
> write_list (stream, "\t\t&", frame_tables.first);
> fprintf (stream, "\t0\n};\n");
>
> /* This must match what's in frame.h. */
> fprintf (stream, "struct object {\n");
> fprintf (stream, " void *pc_begin;\n");
> fprintf (stream, " void *pc_end;\n");
> fprintf (stream, " void *fde_begin;\n");
> fprintf (stream, " void *fde_array;\n");
> fprintf (stream, " __SIZE_TYPE__ count;\n");
> fprintf (stream, " struct object *next;\n");
> fprintf (stream, "};\n");
>
> fprintf (stream, "extern void __register_frame_info_table (void *, struct object *);\n");
> fprintf (stream, "extern void *__deregister_frame_info (void *);\n");
>
> fprintf (stream, "static void reg_frame () {\n");
> fprintf (stream, "\tstatic struct object ob;\n");
> fprintf (stream, "\t__register_frame_info_table (frame_table, &ob);\n");
> fprintf (stream, "\t}\n");
>
> fprintf (stream, "static void dereg_frame () {\n");
> fprintf (stream, "\t__deregister_frame_info (frame_table);\n");
> fprintf (stream, "\t}\n");
> }
>
1774c1910
< if (constructors.number > 0)
---
> if (constructors.number > 0 || frames)
1777a1914,1915
> if (frames)
> fprintf (stream, "\treg_frame,\n");
1781c1919
< fprintf (stream, "\tp = ctors + %d;\n", constructors.number);
---
> fprintf (stream, "\tp = ctors + %d;\n", constructors.number + frames);
1789c1927
< if (destructors.number > 0)
---
> if (destructors.number > 0 || frames)
1792a1931,1932
> if (frames)
> fprintf (stream, "\tdereg_frame,\n");
1798c1938
< destructors.number);
---
> destructors.number + frames);
1809c1949
< /* Write the constructor/destructor tables. */
---
> /* Write the constructor/destructor tables. */
1810a1951
> #ifndef LD_INIT_SWITCH
1817a1959,1960
> int frames = (frame_tables.number > 0);
>
1821c1964,1995
<
---
>
> if (frames)
> {
> write_list_with_asm (stream, "extern void *", frame_tables.first);
>
> fprintf (stream, "\tstatic void *frame_table[] = {\n");
> write_list (stream, "\t\t&", frame_tables.first);
> fprintf (stream, "\t0\n};\n");
>
> /* This must match what's in frame.h. */
> fprintf (stream, "struct object {\n");
> fprintf (stream, " void *pc_begin;\n");
> fprintf (stream, " void *pc_end;\n");
> fprintf (stream, " void *fde_begin;\n");
> fprintf (stream, " void *fde_array;\n");
> fprintf (stream, " __SIZE_TYPE__ count;\n");
> fprintf (stream, " struct object *next;\n");
> fprintf (stream, "};\n");
>
> fprintf (stream, "extern void __register_frame_info_table (void *, struct object *);\n");
> fprintf (stream, "extern void *__deregister_frame_info (void *);\n");
>
> fprintf (stream, "static void reg_frame () {\n");
> fprintf (stream, "\tstatic struct object ob;\n");
> fprintf (stream, "\t__register_frame_info_table (frame_table, &ob);\n");
> fprintf (stream, "\t}\n");
>
> fprintf (stream, "static void dereg_frame () {\n");
> fprintf (stream, "\t__deregister_frame_info (frame_table);\n");
> fprintf (stream, "\t}\n");
> }
>
1823c1997
< fprintf (stream, "\t(entry_pt *) %d,\n", constructors.number);
---
> fprintf (stream, "\t(entry_pt *) %d,\n", constructors.number + frames);
1824a1999,2000
> if (frames)
> fprintf (stream, "\treg_frame,\n");
1830c2006
< fprintf (stream, "\t(entry_pt *) %d,\n", destructors.number);
---
> fprintf (stream, "\t(entry_pt *) %d,\n", destructors.number + frames);
1831a2008,2009
> if (frames)
> fprintf (stream, "\tdereg_frame,\n");
1836a2015
> #endif /* ! LD_INIT_SWITCH */
1842a2022
> fprintf (stream, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n");
1848a2029
> fprintf (stream, "#ifdef __cplusplus\n}\n#endif\n");
1850a2032
> #ifdef COLLECT_EXPORT_LIST
1858a2041,2051
>
> static void
> write_import_file (stream)
> FILE *stream;
> {
> struct id *list = imports.first;
> fprintf (stream, "%s\n", "#! .");
> for (; list; list = list->next)
> fprintf (stream, "%s\n", list->name);
> }
> #endif
1888c2081
< /* If we don't have an `nm', complain. */
---
> /* If we do not have an `nm', complain. */
1897c2090
< nm_argv[argc++] = (char *)0;
---
> nm_argv[argc++] = (char *) 0;
1903c2096
< if (inf == (FILE *)0)
---
> if (inf == (FILE *) 0)
1912c2105
< for (p_argv = &nm_argv[0]; (str = *p_argv) != (char *)0; p_argv++)
---
> for (p_argv = &nm_argv[0]; (str = *p_argv) != (char *) 0; p_argv++)
1961c2154
< while (fgets (buf, sizeof buf, inf) != (char *)0)
---
> while (fgets (buf, sizeof buf, inf) != (char *) 0)
1967c2160
< to the appropriate list. */
---
> to the appropriate list. */
1978,1979c2171,2172
< Don't include `|', because Encore nm can tack that on the end. */
< for (end = p; (ch2 = *end) != '\0' && !isspace (ch2) && ch2 != '|';
---
> Do not include `|', because Encore nm can tack that on the end. */
> for (end = p; (ch2 = *end) != '\0' && !ISSPACE (ch2) && ch2 != '|';
2012a2206,2209
> case 5:
> if (which_pass != PASS_LIB)
> add_to_list (&frame_tables, name);
>
2046c2243
< #include <sys/unistd.h>
---
> #include <unistd.h>
2098c2295
< invalid extensions must go last in the sort, so that they won't be used. */
---
> invalid extensions must go last in the sort, so that they will not be used. */
2109c2306
< && e1[1] && isdigit (e1[1]) && e2[1] && isdigit (e2[1]))
---
> && e1[1] && ISDIGIT (e1[1]) && e2[1] && ISDIGIT (e2[1]))
2122c2319
< if (*e1 == '.' && e1[1] && isdigit (e1[1]))
---
> if (*e1 == '.' && e1[1] && ISDIGIT (e1[1]))
2131c2328
< if (*e2 == '.' && e2[1] && isdigit (e2[1]))
---
> if (*e2 == '.' && e2[1] && ISDIGIT (e2[1]))
2326c2523
< /* If we don't have an `ldd', complain. */
---
> /* If we do not have an `ldd', complain. */
2404c2601
< /* Extract names of libraries and add to list. */
---
> /* Extract names of libraries and add to list. */
2413c2610
< /* Find the end of the symbol name. */
---
> /* Find the end of the symbol name. */
2415c2612
< (ch2 = *end) != '\0' && ch2 != '\n' && !isspace (ch2) && ch2 != '|';
---
> (ch2 = *end) != '\0' && ch2 != '\n' && !ISSPACE (ch2) && ch2 != '|';
2471,2472c2668,2672
< (((X).n_type & N_TMASK) == (DT_NON << N_BTSHFT) || \
< ((X).n_type & N_TMASK) == (DT_FCN << N_BTSHFT)))
---
> ((X).n_scnum > N_UNDEF) && \
> (((X).n_type & N_TMASK) == (DT_NON << N_BTSHFT) || \
> ((X).n_type & N_TMASK) == (DT_FCN << N_BTSHFT)))
> # define GCC_UNDEF_SYMBOL(X) \
> (((X).n_sclass == C_EXT) && ((X).n_scnum == N_UNDEF))
2475c2675,2677
< # define GCC_CHECK_HDR(X) (1)
---
> # define GCC_CHECK_HDR(X) \
> ((HEADER (X).f_magic == U802TOCMAGIC && ! aix64_flag) \
> || (HEADER (X).f_magic == 0757 && aix64_flag))
2495a2698,2702
> int is_shared = 0;
> #ifdef COLLECT_EXPORT_LIST
> /* Should we generate an import list for given prog_name? */
> int import_flag = (which_pass == PASS_OBJ ? 0 : use_import_list (prog_name));
> #endif
2500,2504c2707,2710
< if ((ldptr = ldopen (prog_name, ldptr)) == NULL)
< fatal ("%s: can't open as COFF file", prog_name);
<
< if (!MY_ISCOFF (HEADER (ldptr).f_magic))
< fatal ("%s: not a COFF file", prog_name);
---
> #ifdef COLLECT_EXPORT_LIST
> /* We do not need scanning for some standard C libraries. */
> if (which_pass == PASS_FIRST && ignore_library (prog_name))
> return;
2506c2712,2715
< if (GCC_CHECK_HDR (ldptr))
---
> /* On AIX we have a loop, because there is not much difference
> between an object and an archive. This trick allows us to
> eliminate scan_libraries() function. */
> do
2508,2510c2717,2718
< sym_count = GCC_SYMBOLS (ldptr);
< sym_index = GCC_SYMZERO (ldptr);
< while (sym_index < sym_count)
---
> #endif
> if ((ldptr = ldopen (prog_name, ldptr)) != NULL)
2512c2720,2721
< GCC_SYMENT symbol;
---
> if (! MY_ISCOFF (HEADER (ldptr).f_magic))
> fatal ("%s: not a COFF file", prog_name);
2514,2518c2723
< if (ldtbread (ldptr, sym_index, &symbol) <= 0)
< break;
< sym_index += GCC_SYMINC (symbol);
<
< if (GCC_OK_SYMBOL (symbol))
---
> if (GCC_CHECK_HDR (ldptr))
2520c2725,2726
< char *name;
---
> sym_count = GCC_SYMBOLS (ldptr);
> sym_index = GCC_SYMZERO (ldptr);
2522,2523c2728,2731
< if ((name = ldgetname (ldptr, &symbol)) == NULL)
< continue; /* should never happen */
---
> #ifdef COLLECT_EXPORT_LIST
> /* Is current archive member a shared object? */
> is_shared = HEADER (ldptr).f_flags & F_SHROBJ;
> #endif
2524a2733,2747
> while (sym_index < sym_count)
> {
> GCC_SYMENT symbol;
>
> if (ldtbread (ldptr, sym_index, &symbol) <= 0)
> break;
> sym_index += GCC_SYMINC (symbol);
>
> if (GCC_OK_SYMBOL (symbol))
> {
> char *name;
>
> if ((name = ldgetname (ldptr, &symbol)) == NULL)
> continue; /* should never happen */
>
2526,2529c2749,2752
< /* All AIX function names have a duplicate entry beginning
< with a dot. */
< if (*name == '.')
< ++name;
---
> /* All AIX function names have a duplicate entry
> beginning with a dot. */
> if (*name == '.')
> ++name;
2532,2538c2755,2770
< switch (is_ctor_dtor (name))
< {
< case 1:
< add_to_list (&constructors, name);
< if (which_pass == PASS_OBJ)
< add_to_list (&exports, name);
< break;
---
> switch (is_ctor_dtor (name))
> {
> case 1:
> if (! is_shared) add_to_list (&constructors, name);
> #ifdef COLLECT_EXPORT_LIST
> if (which_pass == PASS_OBJ)
> add_to_list (&exports, name);
> /* If this symbol was undefined and we are building
> an import list, we should add a symbol to this
> list. */
> else
> if (import_flag
> && is_in_list (name, undefined.first))
> add_to_list (&imports, name);
> #endif
> break;
2540,2544c2772,2785
< case 2:
< add_to_list (&destructors, name);
< if (which_pass == PASS_OBJ)
< add_to_list (&exports, name);
< break;
---
> case 2:
> if (! is_shared) add_to_list (&destructors, name);
> #ifdef COLLECT_EXPORT_LIST
> if (which_pass == PASS_OBJ)
> add_to_list (&exports, name);
> /* If this symbol was undefined and we are building
> an import list, we should add a symbol to this
> list. */
> else
> if (import_flag
> && is_in_list (name, undefined.first))
> add_to_list (&imports, name);
> #endif
> break;
2546,2548c2787,2791
< default: /* not a constructor or destructor */
< continue;
< }
---
> #ifdef COLLECT_EXPORT_LIST
> case 3:
> if (is_shared)
> add_to_list (&constructors, name);
> break;
2549a2793,2816
> case 4:
> if (is_shared)
> add_to_list (&destructors, name);
> break;
> #endif
>
> default: /* not a constructor or destructor */
> #ifdef COLLECT_EXPORT_LIST
> /* If we are building a shared object on AIX we need
> to explicitly export all global symbols or add
> them to import list. */
> if (shared_obj)
> {
> if (which_pass == PASS_OBJ && (! export_flag))
> add_to_list (&exports, name);
> else if (! is_shared && which_pass == PASS_FIRST
> && import_flag
> && is_in_list(name, undefined.first))
> add_to_list (&imports, name);
> }
> #endif
> continue;
> }
>
2551,2555c2818,2822
< if (debug)
< fprintf (stderr, "\tsec=%d class=%d type=%s%o %s\n",
< symbol.n_scnum, symbol.n_sclass,
< (symbol.n_type ? "0" : ""), symbol.n_type,
< name);
---
> if (debug)
> fprintf (stderr, "\tsec=%d class=%d type=%s%o %s\n",
> symbol.n_scnum, symbol.n_sclass,
> (symbol.n_type ? "0" : ""), symbol.n_type,
> name);
2557,2559c2824,2827
< if (debug)
< fprintf (stderr, "\tiss = %5d, value = %5d, index = %5d, name = %s\n",
< symbol.iss, symbol.value, symbol.index, name);
---
> if (debug)
> fprintf (stderr,
> "\tiss = %5d, value = %5ld, index = %5d, name = %s\n",
> symbol.iss, (long) symbol.value, symbol.index, name);
2560a2829,2848
> }
> #ifdef COLLECT_EXPORT_LIST
> /* If we are building a shared object we should collect
> information about undefined symbols for later
> import list generation. */
> else if (shared_obj && GCC_UNDEF_SYMBOL (symbol))
> {
> char *name;
>
> if ((name = ldgetname (ldptr, &symbol)) == NULL)
> continue; /* should never happen */
>
> /* All AIX function names have a duplicate entry
> beginning with a dot. */
> if (*name == '.')
> ++name;
> add_to_list (&undefined, name);
> }
> #endif
> }
2561a2850,2859
> #ifdef COLLECT_EXPORT_LIST
> else
> {
> /* If archive contains both 32-bit and 64-bit objects,
> we want to skip objects in other mode so mismatch normal. */
> if (debug)
> fprintf (stderr, "%s : magic=%o aix64=%d mismatch\n",
> prog_name, HEADER (ldptr).f_magic, aix64_flag);
> }
> #endif
2562a2861,2866
> else
> {
> fatal ("%s: cannot open as COFF file", prog_name);
> }
> #ifdef COLLECT_EXPORT_LIST
> /* On AIX loop continues while there are more members in archive. */
2564c2868,2870
<
---
> while (ldclose (ldptr) == FAILURE);
> #else
> /* Otherwise we simply close ldptr. */
2565a2872
> #endif
2568,2576d2874
< #ifdef XCOFF_SCAN_LIBS
< /* Scan imported AIX libraries for GCC static ctors and dtors.
< FIXME: it is possible to link an executable without the actual import
< library by using an "import file" - a text file listing symbols
< exported by a library. To support this, we would have to scan
< import files as well as actual shared binaries to find GCC ctors.
< TODO: use memory mapping instead of 'ld' routines, files are already
< memory mapped, but we could eliminate the extra in-memory copies.
< Is it worth the effort? */
2578,2579c2876,2881
< static void
< scan_libraries (prog_name)
---
> #ifdef COLLECT_EXPORT_LIST
>
> /* This new function is used to decide whether we should
> generate import list for an object or to use it directly. */
> static int
> use_import_list (prog_name)
2582,2584c2884
< LDFILE *ldptr;
< SCNHDR ldsh;
< static struct path_prefix libpath; /* we should only do this once */
---
> char *p;
2586,2590c2886,2887
< if ((ldptr = ldopen (prog_name, ldptr)) == NULL)
< fatal ("%s: can't open as COFF file", prog_name);
<
< if (!MY_ISCOFF (HEADER (ldptr).f_magic))
< fatal ("%s: not a COFF file", prog_name);
---
> /* If we do not build a shared object then import list should not be used. */
> if (! shared_obj) return 0;
2592,2597c2889,2894
< /* find and read loader section */
< if (ldnshread (ldptr, _LOADER, &ldsh))
< {
< LDHDR ldh;
< char *impbuf;
< int entry;
---
> /* Currently we check only for libgcc, but this can be changed in future. */
> p = strstr (prog_name, "libgcc.a");
> if (p != 0 && (strlen (p) == sizeof ("libgcc.a") - 1))
> return 1;
> return 0;
> }
2599,2604c2896,2903
< FSEEK (ldptr, ldsh.s_scnptr, BEGINNING);
< FREAD (&ldh, sizeof (ldh), 1, ldptr);
< /* read import library list */
< impbuf = alloca (ldh.l_istlen);
< FSEEK (ldptr, ldh.l_impoff + ldsh.s_scnptr, BEGINNING);
< FREAD (impbuf, ldh.l_istlen, 1, ldptr);
---
> /* Given a library name without "lib" prefix, this function
> returns a full library name including a path. */
> static char *
> resolve_lib_name (name)
> char *name;
> {
> char *lib_buf;
> int i, j, l = 0;
2606,2608c2905,2907
< if (debug)
< fprintf (stderr, "LIBPATH=%s\n", impbuf);
< prefix_from_string (impbuf, &libpath);
---
> for (i = 0; libpaths[i]; i++)
> if (libpaths[i]->max_len > l)
> l = libpaths[i]->max_len;
2610,2622c2909
< /* skip LIBPATH and empty base and member fields */
< impbuf += strlen (impbuf) + 3;
< for (entry = 1; entry < ldh.l_nimpid; ++entry)
< {
< char *impath = impbuf;
< char *implib = impath + strlen (impath) + 1;
< char *impmem = implib + strlen (implib) + 1;
< char *soname = NULL;
< char *trial;
< int pathlen;
< LDFILE *libptr = NULL;
< struct prefix_list *pl;
< ARCHDR ah;
---
> lib_buf = xmalloc (l + strlen(name) + 10);
2624,2634c2911,2916
< impbuf = impmem + strlen (impmem) + 1;
< if (debug)
< fprintf (stderr, "PATH+BASE=%s%s\n", impath, implib);
< /* Skip AIX kernel exports */
< if (*impath == '/' && *(impath+1) == '\0'
< && strcmp (implib, "unix") == 0)
< continue;
< pathlen = strlen (impath);
< trial = alloca (MAX (pathlen + 1, libpath.max_len)
< + strlen (implib) + 1);
< if (*impath)
---
> for (i = 0; libpaths[i]; i++)
> {
> struct prefix_list *list = libpaths[i]->plist;
> for (; list; list = list->next)
> {
> for (j = 0; libexts[j]; j++)
2636,2669c2918,2927
< strcpy (trial, impath);
< if (impath[pathlen - 1] != '/')
< trial[pathlen++] = '/';
< strcpy (trial + pathlen, implib);
< if (access (trial, R_OK) == 0)
< soname = trial;
< }
< else
< for (pl = libpath.plist; pl; pl = pl->next)
< {
< strcpy (trial, pl->prefix);
< strcat (trial, implib);
< if (access (trial, R_OK) == 0)
< {
< soname = trial;
< break;
< }
< }
<
< if (! soname)
< fatal ("%s: library not found", implib);
< if (debug)
< if (*impmem)
< fprintf (stderr, "%s (%s)\n", soname, impmem);
< else
< fprintf (stderr, "%s\n", soname);
<
< do
< {
< /* scan imported shared objects for GCC GLOBAL ctors */
< short type;
< if ((libptr = ldopen (soname, libptr)) == NULL)
< fatal ("%s: can't open import library", soname);
< if (TYPE (libptr) == ARTYPE)
---
> /* The following lines are needed because path_prefix list
> may contain directories both with trailing '/' and
> without it. */
> char *p = "";
> if (list->prefix[strlen(list->prefix)-1] != '/')
> p = "/";
> sprintf (lib_buf, "%s%slib%s.%s",
> list->prefix, p, name, libexts[j]);
> if (debug) fprintf (stderr, "searching for: %s\n", lib_buf);
> if (file_exists (lib_buf))
2671,2676c2929,2930
< LDFILE *memptr;
< if (! *impmem)
< fatal ("%s: no archive member specified", soname);
< ldahread (libptr, &ah);
< if (strcmp (ah.ar_name, impmem))
< continue;
---
> if (debug) fprintf (stderr, "found: %s\n", lib_buf);
> return (lib_buf);
2678,2728d2931
< type = HEADER (libptr).f_magic;
< if (HEADER (libptr).f_flags & F_SHROBJ)
< {
< SCNHDR soldsh;
< LDHDR soldh;
< long symcnt, i;
< char *ldstrings;
< LDSYM *lsyms;
< if (!ldnshread (libptr, _LOADER, &soldsh))
< fatal ("%s: not an import library", soname);
< FSEEK (libptr, soldsh.s_scnptr, BEGINNING);
< if (FREAD (&soldh, sizeof (soldh), 1, libptr) != 1)
< fatal ("%s: can't read loader section", soname);
< /*fprintf (stderr, "\tscanning %s\n", soname);*/
< symcnt = soldh.l_nsyms;
< lsyms = (LDSYM*) alloca (symcnt * sizeof (*lsyms));
< symcnt = FREAD (lsyms, sizeof (*lsyms), symcnt, libptr);
< ldstrings = alloca (soldh.l_stlen);
< FSEEK (libptr, soldsh.s_scnptr+soldh.l_stoff, BEGINNING);
< FREAD (ldstrings, soldh.l_stlen, 1, libptr);
< for (i = 0; i < symcnt; ++i)
< {
< LDSYM *l = lsyms + i;
< if (LDR_EXPORT (*l))
< {
< char *expname = 0;
< if (l->l_zeroes)
< expname = l->l_name;
< else if (l->l_offset < soldh.l_stlen)
< expname = ldstrings + l->l_offset;
< switch (is_ctor_dtor (expname))
< {
< case 3:
< if (debug)
< fprintf (stderr, "\t%s\n", expname);
< add_to_list (&constructors, expname);
< break;
<
< case 4:
< add_to_list (&destructors, expname);
< break;
<
< default: /* not a constructor or destructor */
< continue;
< }
< }
< }
< }
< else
< fprintf (stderr, "%s: type = %04X flags = %04X\n",
< ah.ar_name, type, HEADER (libptr).f_flags);
2730,2731d2932
< while (ldclose (libptr) == FAILURE);
< /* printf (stderr, "closed %s\n", soname); */
2733a2935,2939
> if (debug)
> fprintf (stderr, "not found\n");
> else
> fatal ("Library lib%s not found", name);
> return (NULL);
2735d2940
< #endif /* XCOFF_SCAN_LIBS */
2736a2942,2969
> /* Array of standard AIX libraries which should not
> be scanned for ctors/dtors. */
> static char* aix_std_libs[] = {
> "/unix",
> "/lib/libc.a",
> "/lib/libc_r.a",
> "/usr/lib/libc.a",
> "/usr/lib/libc_r.a",
> "/usr/lib/threads/libc.a",
> "/usr/ccs/lib/libc.a",
> "/usr/ccs/lib/libc_r.a",
> NULL
> };
>
> /* This function checks the filename and returns 1
> if this name matches the location of a standard AIX library. */
> static int
> ignore_library (name)
> char *name;
> {
> char **p = &aix_std_libs[0];
> while (*p++ != NULL)
> if (! strcmp (name, *p)) return 1;
> return 0;
> }
>
> #endif
>
2790c3023
< static void print_load_command PROTO((load_union_t*, size_t, int));
---
> static void print_load_command PROTO((load_union_t *, size_t, int));
2829c3062
< fatal_perror ("can't read %s", prog_name);
---
> fatal_perror ("cannot read %s", prog_name);
2933c3166
< if (str_sect == (char *)0)
---
> if (str_sect == (char *) 0)
2936c3169
< if (load_cmd->section == (char *)0)
---
> if (load_cmd->section == (char *) 0)
3001c3234
< If we are building a program instead of a shared library, don't
---
> If we are building a program instead of a shared library, do not
3005c3238
< if (main_sym != (symbol_info_t *)0
---
> if (main_sym != (symbol_info_t *) 0
3060c3293
< bcopy ((char *)load_hdr, (char *)(obj + offset), size);
---
> bcopy ((char *) load_hdr, (char *) (obj + offset), size);
3099c3332
< load_cmd->section = (char *)0;
---
> load_cmd->section = (char *) 0;
3208c3441
< char *type_str = (char *)0;
---
> char *type_str = (char *) 0;
3233c3466
< if (type_str == (char *)0)
---
> if (type_str == (char *) 0)
3272c3505
< char *msg = (char *)0;
---
> char *msg = (char *) 0;
3284c3517
< if (msg == (char *)0)
---
> if (msg == (char *) 0)
3322c3555
< p->start = mmap ((caddr_t)0,
---
> p->start = mmap ((caddr_t) 0,
3329c3562
< if (p->start != (char *)0 && p->start != (char *)-1)
---
> if (p->start != (char *) 0 && p->start != (char *) -1)