diff options
Diffstat (limited to 'contrib/gcc/collect2.c')
| -rw-r--r-- | contrib/gcc/collect2.c | 106 |
1 files changed, 54 insertions, 52 deletions
diff --git a/contrib/gcc/collect2.c b/contrib/gcc/collect2.c index 30fb49d8e630..a74a7f069924 100644 --- a/contrib/gcc/collect2.c +++ b/contrib/gcc/collect2.c @@ -255,6 +255,7 @@ 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 int auto_export = 1; /* true if exporting everything. */ char *ldout; /* File for ld errors. */ static char *output_file; /* Output file for ld. */ static char *nm_file_name; /* pathname of nm */ @@ -1242,6 +1243,15 @@ main (argc, argv) } break; +#ifdef COLLECT_EXPORT_LIST + case 'b': + if ((!strncmp (arg, "-bE:", 4) + || !strncmp (arg, "-bexport:", 9)) + && strcmp (arg, "-bexport:/usr/lib/libg.exp")) + auto_export = 0; + break; +#endif + case 'l': if (first_file) { @@ -2544,6 +2554,8 @@ scan_prog_file (prog_name, which_pass) break; default: /* not a constructor or destructor */ + if (which_pass == PASS_OBJ && auto_export) + add_to_list (&exports, name); continue; } @@ -2594,72 +2606,62 @@ scan_libraries (prog_name) { LDHDR ldh; char *impbuf; - int entry; - + int idx; FSEEK (ldptr, ldsh.s_scnptr, BEGINNING); - FREAD (&ldh, sizeof (ldh), 1, ldptr); + 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); - + idx = strlen (impbuf) + 1; + idx += strlen (impbuf+idx) + 1; if (debug) fprintf (stderr, "LIBPATH=%s\n", impbuf); prefix_from_string (impbuf, &libpath); - - /* skip LIBPATH and empty base and member fields */ - impbuf += strlen (impbuf) + 3; - for (entry = 1; entry < ldh.l_nimpid; ++entry) + while (idx < ldh.l_istlen) { - char *impath = impbuf; - char *implib = impath + strlen (impath) + 1; + char *implib = impbuf + idx; char *impmem = implib + strlen (implib) + 1; - char *soname = NULL; - char *trial; - int pathlen; + char *soname = 0; LDFILE *libptr = NULL; struct prefix_list *pl; ARCHDR ah; - - 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) + idx += strlen (implib) + 1; + if (!implib[0]) continue; - pathlen = strlen (impath); - trial = alloca (MAX (pathlen + 1, libpath.max_len) - + strlen (implib) + 1); - if (*impath) + idx += strlen (impmem) + 1; + if (*implib == '/') { - strcpy (trial, impath); - if (impath[pathlen - 1] != '/') - trial[pathlen++] = '/'; - strcpy (trial + pathlen, implib); - if (access (trial, R_OK) == 0) - soname = trial; + if (access (soname, R_OK) == 0) + soname = implib; } 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); + { + char *temp = alloca (libpath.max_len + strlen (implib) + 1); + for (pl = libpath.plist; pl; pl = pl->next) + { + strcpy (temp, pl->prefix); + strcat (temp, implib); + if (access (temp, R_OK) == 0) + { + soname = temp; + break; + } + } + } + if (!soname) + { + fatal ("%s: library not found", implib); + continue; + } if (debug) - if (*impmem) - fprintf (stderr, "%s (%s)\n", soname, impmem); - else - fprintf (stderr, "%s\n", soname); - + { + if (impmem[0]) + fprintf (stderr, "%s (%s)\n", soname, impmem); + else + fprintf (stderr, "%s\n", soname); + } + ah.ar_name[0] = 0; do { /* scan imported shared objects for GCC GLOBAL ctors */ @@ -2669,7 +2671,7 @@ scan_libraries (prog_name) if (TYPE (libptr) == ARTYPE) { LDFILE *memptr; - if (! *impmem) + if (!impmem[0]) fatal ("%s: no archive member specified", soname); ldahread (libptr, &ah); if (strcmp (ah.ar_name, impmem)) @@ -2686,12 +2688,12 @@ scan_libraries (prog_name) 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) + 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); + 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); |
