1 /* Collect static initialization info into data structures that can be
2 traversed by C++ initialization and finalization routines.
3 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
5 Contributed by Chris Smith (csmith@convex.com).
6 Heavily modified by Michael Meissner (meissner@cygnus.com),
7 Per Bothner (bothner@cygnus.com), and John Gilmore (gnu@cygnus.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
26 /* Build tables of static constructors and destructors and run ld. */
30 #include "coretypes.h"
33 #if ! defined( SIGCHLD ) && defined( SIGCLD )
34 # define SIGCHLD SIGCLD
37 #ifndef LIBRARY_PATH_ENV
38 #define LIBRARY_PATH_ENV "LIBRARY_PATH"
49 /* On certain systems, we have code that works by scanning the object file
50 directly. But this code uses system-specific header files and library
51 functions, so turn it off in a cross-compiler. Likewise, the names of
52 the utilities are not correct for a cross-compiler; we have to hope that
53 cross-versions are in the proper directories. */
55 #ifdef CROSS_DIRECTORY_STRUCTURE
56 #undef OBJECT_FORMAT_COFF
58 #undef REAL_LD_FILE_NAME
59 #undef REAL_NM_FILE_NAME
60 #undef REAL_STRIP_FILE_NAME
63 /* If we cannot use a special method, use the ordinary one:
64 run nm to find what symbols are present.
65 In a cross-compiler, this means you need a cross nm,
66 but that is not quite as unpleasant as special headers. */
68 #if !defined (OBJECT_FORMAT_COFF)
69 #define OBJECT_FORMAT_NONE
72 #ifdef OBJECT_FORMAT_COFF
81 /* Many versions of ldfcn.h define these. */
89 /* Some systems have an ISCOFF macro, but others do not. In some cases
90 the macro may be wrong. MY_ISCOFF is defined in tm.h files for machines
91 that either do not have an ISCOFF macro in /usr/include or for those
95 #define MY_ISCOFF(X) ISCOFF (X)
98 #endif /* OBJECT_FORMAT_COFF */
100 #ifdef OBJECT_FORMAT_NONE
102 /* Default flags to pass to nm. */
104 #define NM_FLAGS "-n"
107 #endif /* OBJECT_FORMAT_NONE */
109 /* Some systems use __main in a way incompatible with its use in gcc, in these
110 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
111 give the same symbol without quotes for an alternative entry point. */
113 #define NAME__MAIN "__main"
116 /* This must match tree.h. */
117 #define DEFAULT_INIT_PRIORITY 65535
119 #ifndef COLLECT_SHARED_INIT_FUNC
120 #define COLLECT_SHARED_INIT_FUNC(STREAM, FUNC) \
121 fprintf ((STREAM), "void _GLOBAL__DI() {\n\t%s();\n}\n", (FUNC))
123 #ifndef COLLECT_SHARED_FINI_FUNC
124 #define COLLECT_SHARED_FINI_FUNC(STREAM, FUNC) \
125 fprintf ((STREAM), "void _GLOBAL__DD() {\n\t%s();\n}\n", (FUNC))
129 #define SCAN_LIBRARIES
133 #define SHLIB_SUFFIX ".so"
137 int do_collecting
= 1;
139 int do_collecting
= 0;
142 /* Nonzero if we should suppress the automatic demangling of identifiers
143 in linker error messages. Set from COLLECT_NO_DEMANGLE. */
146 /* Linked lists of constructor and destructor names. */
162 /* Enumeration giving which pass this is for scanning the program file. */
165 PASS_FIRST
, /* without constructors */
166 PASS_OBJ
, /* individual objects */
167 PASS_LIB
, /* looking for shared libraries */
168 PASS_SECOND
/* with constructors linked in */
171 int vflag
; /* true if -v */
172 static int rflag
; /* true if -r */
173 static int strip_flag
; /* true if -s */
174 static const char *demangle_flag
;
175 #ifdef COLLECT_EXPORT_LIST
176 static int export_flag
; /* true if -bE */
177 static int aix64_flag
; /* true if -b64 */
178 static int aixrtl_flag
; /* true if -brtl */
181 int debug
; /* true if -debug */
183 static int shared_obj
; /* true if -shared */
185 static const char *c_file
; /* <xxx>.c for constructor/destructor list. */
186 static const char *o_file
; /* <xxx>.o for constructor/destructor list. */
187 #ifdef COLLECT_EXPORT_LIST
188 static const char *export_file
; /* <xxx>.x for AIX export list. */
190 const char *ldout
; /* File for ld stdout. */
191 const char *lderrout
; /* File for ld stderr. */
192 static const char *output_file
; /* Output file for ld. */
193 static const char *nm_file_name
; /* pathname of nm */
195 static const char *ldd_file_name
; /* pathname of ldd (or equivalent) */
197 static const char *strip_file_name
; /* pathname of strip */
198 const char *c_file_name
; /* pathname of gcc */
199 static char *initname
, *fininame
; /* names of init and fini funcs */
201 static struct head constructors
; /* list of constructors found */
202 static struct head destructors
; /* list of destructors found */
203 #ifdef COLLECT_EXPORT_LIST
204 static struct head exports
; /* list of exported symbols */
206 static struct head frame_tables
; /* list of frame unwind info tables */
208 static bool at_file_supplied
; /* Whether to use @file arguments */
209 static char *response_file
; /* Name of any current response file */
211 struct obstack temporary_obstack
;
212 char * temporary_firstobj
;
214 /* Structure to hold all the directories in which to search for files to
219 const char *prefix
; /* String to prepend to the path. */
220 struct prefix_list
*next
; /* Next in linked list. */
225 struct prefix_list
*plist
; /* List of prefixes to try */
226 int max_len
; /* Max length of a prefix in PLIST */
227 const char *name
; /* Name of this list (used in config stuff) */
230 #ifdef COLLECT_EXPORT_LIST
231 /* Lists to keep libraries to be scanned for global constructors/destructors. */
232 static struct head libs
; /* list of libraries */
233 static struct path_prefix cmdline_lib_dirs
; /* directories specified with -L */
234 static struct path_prefix libpath_lib_dirs
; /* directories in LIBPATH */
235 static struct path_prefix
*libpaths
[3] = {&cmdline_lib_dirs
,
236 &libpath_lib_dirs
, NULL
};
239 static void handler (int);
240 static int is_ctor_dtor (const char *);
241 static char *find_a_file (struct path_prefix
*, const char *);
242 static void add_prefix (struct path_prefix
*, const char *);
243 static void prefix_from_env (const char *, struct path_prefix
*);
244 static void prefix_from_string (const char *, struct path_prefix
*);
245 static void do_wait (const char *, struct pex_obj
*);
246 static void fork_execute (const char *, char **);
247 static void maybe_unlink (const char *);
248 static void add_to_list (struct head
*, const char *);
249 static int extract_init_priority (const char *);
250 static void sort_ids (struct head
*);
251 static void write_list (FILE *, const char *, struct id
*);
252 #ifdef COLLECT_EXPORT_LIST
253 static void dump_list (FILE *, const char *, struct id
*);
256 static void dump_prefix_list (FILE *, const char *, struct prefix_list
*);
258 static void write_list_with_asm (FILE *, const char *, struct id
*);
259 static void write_c_file (FILE *, const char *);
260 static void write_c_file_stat (FILE *, const char *);
261 #ifndef LD_INIT_SWITCH
262 static void write_c_file_glob (FILE *, const char *);
264 static void scan_prog_file (const char *, enum pass
);
265 #ifdef SCAN_LIBRARIES
266 static void scan_libraries (const char *);
268 #if LINK_ELIMINATE_DUPLICATE_LDIRECTORIES
269 static int is_in_args (const char *, const char **, const char **);
271 #ifdef COLLECT_EXPORT_LIST
273 static int is_in_list (const char *, struct id
*);
275 static void write_aix_file (FILE *, struct id
*);
276 static char *resolve_lib_name (const char *);
278 static char *extract_string (const char **);
280 /* Delete tempfiles and exit function. */
283 collect_exit (int status
)
285 if (c_file
!= 0 && c_file
[0])
286 maybe_unlink (c_file
);
288 if (o_file
!= 0 && o_file
[0])
289 maybe_unlink (o_file
);
291 #ifdef COLLECT_EXPORT_LIST
292 if (export_file
!= 0 && export_file
[0])
293 maybe_unlink (export_file
);
296 if (ldout
!= 0 && ldout
[0])
298 dump_file (ldout
, stdout
);
299 maybe_unlink (ldout
);
302 if (lderrout
!= 0 && lderrout
[0])
304 dump_file (lderrout
, stderr
);
305 maybe_unlink (lderrout
);
308 if (status
!= 0 && output_file
!= 0 && output_file
[0])
309 maybe_unlink (output_file
);
312 maybe_unlink (response_file
);
318 /* Notify user of a non-error. */
320 notice (const char *cmsgid
, ...)
324 va_start (ap
, cmsgid
);
325 vfprintf (stderr
, _(cmsgid
), ap
);
329 /* Die when sys call fails. */
332 fatal_perror (const char * cmsgid
, ...)
337 va_start (ap
, cmsgid
);
338 fprintf (stderr
, "collect2: ");
339 vfprintf (stderr
, _(cmsgid
), ap
);
340 fprintf (stderr
, ": %s\n", xstrerror (e
));
343 collect_exit (FATAL_EXIT_CODE
);
349 fatal (const char * cmsgid
, ...)
353 va_start (ap
, cmsgid
);
354 fprintf (stderr
, "collect2: ");
355 vfprintf (stderr
, _(cmsgid
), ap
);
356 fprintf (stderr
, "\n");
359 collect_exit (FATAL_EXIT_CODE
);
362 /* Write error message. */
365 error (const char * gmsgid
, ...)
369 va_start (ap
, gmsgid
);
370 fprintf (stderr
, "collect2: ");
371 vfprintf (stderr
, _(gmsgid
), ap
);
372 fprintf (stderr
, "\n");
376 /* In case obstack is linked in, and abort is defined to fancy_abort,
377 provide a default entry. */
380 fancy_abort (const char *file
, int line
, const char *func
)
382 fatal ("internal gcc abort in %s, at %s:%d", func
, file
, line
);
388 if (c_file
!= 0 && c_file
[0])
389 maybe_unlink (c_file
);
391 if (o_file
!= 0 && o_file
[0])
392 maybe_unlink (o_file
);
394 if (ldout
!= 0 && ldout
[0])
395 maybe_unlink (ldout
);
397 if (lderrout
!= 0 && lderrout
[0])
398 maybe_unlink (lderrout
);
400 #ifdef COLLECT_EXPORT_LIST
401 if (export_file
!= 0 && export_file
[0])
402 maybe_unlink (export_file
);
406 maybe_unlink (response_file
);
408 signal (signo
, SIG_DFL
);
414 file_exists (const char *name
)
416 return access (name
, R_OK
) == 0;
419 /* Parse a reasonable subset of shell quoting syntax. */
422 extract_string (const char **pp
)
435 obstack_1grow (&temporary_obstack
, c
);
436 else if (! inside
&& c
== ' ')
438 else if (! inside
&& c
== '\\')
443 obstack_1grow (&temporary_obstack
, c
);
446 obstack_1grow (&temporary_obstack
, '\0');
448 return XOBFINISH (&temporary_obstack
, char *);
452 dump_file (const char *name
, FILE *to
)
454 FILE *stream
= fopen (name
, "r");
461 while (c
= getc (stream
),
462 c
!= EOF
&& (ISIDNUM (c
) || c
== '$' || c
== '.'))
463 obstack_1grow (&temporary_obstack
, c
);
464 if (obstack_object_size (&temporary_obstack
) > 0)
466 const char *word
, *p
;
468 obstack_1grow (&temporary_obstack
, '\0');
469 word
= XOBFINISH (&temporary_obstack
, const char *);
472 ++word
, putc ('.', to
);
474 if (!strncmp (p
, USER_LABEL_PREFIX
, strlen (USER_LABEL_PREFIX
)))
475 p
+= strlen (USER_LABEL_PREFIX
);
477 #ifdef HAVE_LD_DEMANGLE
483 result
= cplus_demangle (p
, DMGL_PARAMS
| DMGL_ANSI
| DMGL_VERBOSE
);
491 diff
= strlen (word
) - strlen (result
);
492 while (diff
> 0 && c
== ' ')
493 --diff
, putc (' ', to
);
494 if (diff
< 0 && c
== ' ')
496 while (diff
< 0 && c
== ' ')
497 ++diff
, c
= getc (stream
);
500 /* Make sure we output at least one space, or
501 the demangled symbol name will run into
502 whatever text follows. */
513 obstack_free (&temporary_obstack
, temporary_firstobj
);
522 /* Decide whether the given symbol is: a constructor (1), a destructor
523 (2), a routine in a shared object that calls all the constructors
524 (3) or destructors (4), a DWARF exception-handling table (5), or
525 nothing special (0). */
528 is_ctor_dtor (const char *s
)
530 struct names
{ const char *const name
; const int len
; const int ret
;
531 const int two_underscores
; };
533 const struct names
*p
;
535 const char *orig_s
= s
;
537 static const struct names special
[] = {
538 #ifndef NO_DOLLAR_IN_LABEL
539 { "GLOBAL__I$", sizeof ("GLOBAL__I$")-1, 1, 0 },
540 { "GLOBAL__D$", sizeof ("GLOBAL__D$")-1, 2, 0 },
542 #ifndef NO_DOT_IN_LABEL
543 { "GLOBAL__I.", sizeof ("GLOBAL__I.")-1, 1, 0 },
544 { "GLOBAL__D.", sizeof ("GLOBAL__D.")-1, 2, 0 },
545 #endif /* NO_DOT_IN_LABEL */
546 #endif /* NO_DOLLAR_IN_LABEL */
547 { "GLOBAL__I_", sizeof ("GLOBAL__I_")-1, 1, 0 },
548 { "GLOBAL__D_", sizeof ("GLOBAL__D_")-1, 2, 0 },
549 { "GLOBAL__F_", sizeof ("GLOBAL__F_")-1, 5, 0 },
550 { "GLOBAL__FI_", sizeof ("GLOBAL__FI_")-1, 3, 0 },
551 { "GLOBAL__FD_", sizeof ("GLOBAL__FD_")-1, 4, 0 },
555 while ((ch
= *s
) == '_')
561 for (p
= &special
[0]; p
->len
> 0; p
++)
564 && (!p
->two_underscores
|| ((s
- orig_s
) >= 2))
565 && strncmp(s
, p
->name
, p
->len
) == 0)
573 /* We maintain two prefix lists: one from COMPILER_PATH environment variable
574 and one from the PATH variable. */
576 static struct path_prefix cpath
, path
;
578 #ifdef CROSS_DIRECTORY_STRUCTURE
579 /* This is the name of the target machine. We use it to form the name
580 of the files to execute. */
582 static const char *const target_machine
= TARGET_MACHINE
;
585 /* Search for NAME using prefix list PPREFIX. We only look for executable
588 Return 0 if not found, otherwise return its name, allocated with malloc. */
591 find_a_file (struct path_prefix
*pprefix
, const char *name
)
594 struct prefix_list
*pl
;
595 int len
= pprefix
->max_len
+ strlen (name
) + 1;
598 fprintf (stderr
, "Looking for '%s'\n", name
);
600 #ifdef HOST_EXECUTABLE_SUFFIX
601 len
+= strlen (HOST_EXECUTABLE_SUFFIX
);
604 temp
= XNEWVEC (char, len
);
606 /* Determine the filename to execute (special case for absolute paths). */
609 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
610 || (*name
&& name
[1] == ':')
614 if (access (name
, X_OK
) == 0)
619 fprintf (stderr
, " - found: absolute path\n");
624 #ifdef HOST_EXECUTABLE_SUFFIX
625 /* Some systems have a suffix for executable files.
626 So try appending that. */
628 strcat (temp
, HOST_EXECUTABLE_SUFFIX
);
630 if (access (temp
, X_OK
) == 0)
635 fprintf (stderr
, " - failed to locate using absolute path\n");
638 for (pl
= pprefix
->plist
; pl
; pl
= pl
->next
)
642 strcpy (temp
, pl
->prefix
);
645 if (stat (temp
, &st
) >= 0
646 && ! S_ISDIR (st
.st_mode
)
647 && access (temp
, X_OK
) == 0)
650 #ifdef HOST_EXECUTABLE_SUFFIX
651 /* Some systems have a suffix for executable files.
652 So try appending that. */
653 strcat (temp
, HOST_EXECUTABLE_SUFFIX
);
655 if (stat (temp
, &st
) >= 0
656 && ! S_ISDIR (st
.st_mode
)
657 && access (temp
, X_OK
) == 0)
662 if (debug
&& pprefix
->plist
== NULL
)
663 fprintf (stderr
, " - failed: no entries in prefix list\n");
669 /* Add an entry for PREFIX to prefix list PPREFIX. */
672 add_prefix (struct path_prefix
*pprefix
, const char *prefix
)
674 struct prefix_list
*pl
, **prev
;
679 for (pl
= pprefix
->plist
; pl
->next
; pl
= pl
->next
)
684 prev
= &pprefix
->plist
;
686 /* Keep track of the longest prefix. */
688 len
= strlen (prefix
);
689 if (len
> pprefix
->max_len
)
690 pprefix
->max_len
= len
;
692 pl
= XNEW (struct prefix_list
);
693 pl
->prefix
= xstrdup (prefix
);
698 pl
->next
= (struct prefix_list
*) 0;
702 /* Take the value of the environment variable ENV, break it into a path, and
703 add of the entries to PPREFIX. */
706 prefix_from_env (const char *env
, struct path_prefix
*pprefix
)
709 GET_ENVIRONMENT (p
, env
);
712 prefix_from_string (p
, pprefix
);
716 prefix_from_string (const char *p
, struct path_prefix
*pprefix
)
718 const char *startp
, *endp
;
719 char *nstore
= XNEWVEC (char, strlen (p
) + 3);
722 fprintf (stderr
, "Convert string '%s' into prefixes, separator = '%c'\n", p
, PATH_SEPARATOR
);
727 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
729 strncpy (nstore
, startp
, endp
-startp
);
732 strcpy (nstore
, "./");
734 else if (! IS_DIR_SEPARATOR (endp
[-1]))
736 nstore
[endp
-startp
] = DIR_SEPARATOR
;
737 nstore
[endp
-startp
+1] = 0;
740 nstore
[endp
-startp
] = 0;
743 fprintf (stderr
, " - add prefix: %s\n", nstore
);
745 add_prefix (pprefix
, nstore
);
748 endp
= startp
= endp
+ 1;
759 main (int argc
, char **argv
)
761 static const char *const ld_suffix
= "ld";
762 static const char *const real_ld_suffix
= "real-ld";
763 static const char *const collect_ld_suffix
= "collect-ld";
764 static const char *const nm_suffix
= "nm";
765 static const char *const gnm_suffix
= "gnm";
767 static const char *const ldd_suffix
= LDD_SUFFIX
;
769 static const char *const strip_suffix
= "strip";
770 static const char *const gstrip_suffix
= "gstrip";
772 #ifdef CROSS_DIRECTORY_STRUCTURE
773 /* If we look for a program in the compiler directories, we just use
774 the short name, since these directories are already system-specific.
775 But it we look for a program in the system directories, we need to
776 qualify the program name with the target machine. */
778 const char *const full_ld_suffix
=
779 concat(target_machine
, "-", ld_suffix
, NULL
);
780 const char *const full_nm_suffix
=
781 concat (target_machine
, "-", nm_suffix
, NULL
);
782 const char *const full_gnm_suffix
=
783 concat (target_machine
, "-", gnm_suffix
, NULL
);
785 const char *const full_ldd_suffix
=
786 concat (target_machine
, "-", ldd_suffix
, NULL
);
788 const char *const full_strip_suffix
=
789 concat (target_machine
, "-", strip_suffix
, NULL
);
790 const char *const full_gstrip_suffix
=
791 concat (target_machine
, "-", gstrip_suffix
, NULL
);
793 const char *const full_ld_suffix
= ld_suffix
;
794 const char *const full_nm_suffix
= nm_suffix
;
795 const char *const full_gnm_suffix
= gnm_suffix
;
797 const char *const full_ldd_suffix
= ldd_suffix
;
799 const char *const full_strip_suffix
= strip_suffix
;
800 const char *const full_gstrip_suffix
= gstrip_suffix
;
801 #endif /* CROSS_DIRECTORY_STRUCTURE */
805 #ifdef COLLECT_EXPORT_LIST
808 const char *ld_file_name
;
823 expandargv (&argc
, &argv
);
824 if (argv
!= old_argv
)
825 at_file_supplied
= 1;
827 num_c_args
= argc
+ 9;
829 no_demangle
= !! getenv ("COLLECT_NO_DEMANGLE");
831 /* Suppress demangling by the real linker, which may be broken. */
832 putenv (xstrdup ("COLLECT_NO_DEMANGLE="));
834 #if defined (COLLECT2_HOST_INITIALIZATION)
835 /* Perform system dependent initialization, if necessary. */
836 COLLECT2_HOST_INITIALIZATION
;
840 /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
841 receive the signal. A different setting is inheritable */
842 signal (SIGCHLD
, SIG_DFL
);
845 /* Unlock the stdio streams. */
846 unlock_std_streams ();
850 /* Do not invoke xcalloc before this point, since locale needs to be
851 set first, in case a diagnostic is issued. */
853 ld1
= (const char **)(ld1_argv
= xcalloc(sizeof (char *), argc
+4));
854 ld2
= (const char **)(ld2_argv
= xcalloc(sizeof (char *), argc
+11));
855 object
= (const char **)(object_lst
= xcalloc(sizeof (char *), argc
));
861 /* Parse command line early for instances of -debug. This allows
862 the debug flag to be set before functions like find_a_file()
867 for (i
= 1; argv
[i
] != NULL
; i
++)
869 if (! strcmp (argv
[i
], "-debug"))
875 #ifndef DEFAULT_A_OUT_NAME
876 output_file
= "a.out";
878 output_file
= DEFAULT_A_OUT_NAME
;
881 obstack_begin (&temporary_obstack
, 0);
882 temporary_firstobj
= obstack_alloc (&temporary_obstack
, 0);
884 #ifndef HAVE_LD_DEMANGLE
885 current_demangling_style
= auto_demangling
;
887 p
= getenv ("COLLECT_GCC_OPTIONS");
890 const char *q
= extract_string (&p
);
891 if (*q
== '-' && (q
[1] == 'm' || q
[1] == 'f'))
894 obstack_free (&temporary_obstack
, temporary_firstobj
);
896 /* -fno-profile-arcs -fno-test-coverage -fno-branch-probabilities
897 -fno-exceptions -w */
900 c_ptr
= (const char **) (c_argv
= xcalloc (sizeof (char *), num_c_args
));
903 fatal ("no arguments");
906 if (signal (SIGQUIT
, SIG_IGN
) != SIG_IGN
)
907 signal (SIGQUIT
, handler
);
909 if (signal (SIGINT
, SIG_IGN
) != SIG_IGN
)
910 signal (SIGINT
, handler
);
912 if (signal (SIGALRM
, SIG_IGN
) != SIG_IGN
)
913 signal (SIGALRM
, handler
);
916 if (signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
917 signal (SIGHUP
, handler
);
919 if (signal (SIGSEGV
, SIG_IGN
) != SIG_IGN
)
920 signal (SIGSEGV
, handler
);
922 if (signal (SIGBUS
, SIG_IGN
) != SIG_IGN
)
923 signal (SIGBUS
, handler
);
926 /* Extract COMPILER_PATH and PATH into our prefix list. */
927 prefix_from_env ("COMPILER_PATH", &cpath
);
928 prefix_from_env ("PATH", &path
);
930 /* Try to discover a valid linker/nm/strip to use. */
932 /* Maybe we know the right file to use (if not cross). */
934 #ifdef DEFAULT_LINKER
935 if (access (DEFAULT_LINKER
, X_OK
) == 0)
936 ld_file_name
= DEFAULT_LINKER
;
937 if (ld_file_name
== 0)
939 #ifdef REAL_LD_FILE_NAME
940 ld_file_name
= find_a_file (&path
, REAL_LD_FILE_NAME
);
941 if (ld_file_name
== 0)
943 /* Search the (target-specific) compiler dirs for ld'. */
944 ld_file_name
= find_a_file (&cpath
, real_ld_suffix
);
945 /* Likewise for `collect-ld'. */
946 if (ld_file_name
== 0)
947 ld_file_name
= find_a_file (&cpath
, collect_ld_suffix
);
948 /* Search the compiler directories for `ld'. We have protection against
949 recursive calls in find_a_file. */
950 if (ld_file_name
== 0)
951 ld_file_name
= find_a_file (&cpath
, ld_suffix
);
952 /* Search the ordinary system bin directories
953 for `ld' (if native linking) or `TARGET-ld' (if cross). */
954 if (ld_file_name
== 0)
955 ld_file_name
= find_a_file (&path
, full_ld_suffix
);
957 #ifdef REAL_NM_FILE_NAME
958 nm_file_name
= find_a_file (&path
, REAL_NM_FILE_NAME
);
959 if (nm_file_name
== 0)
961 nm_file_name
= find_a_file (&cpath
, gnm_suffix
);
962 if (nm_file_name
== 0)
963 nm_file_name
= find_a_file (&path
, full_gnm_suffix
);
964 if (nm_file_name
== 0)
965 nm_file_name
= find_a_file (&cpath
, nm_suffix
);
966 if (nm_file_name
== 0)
967 nm_file_name
= find_a_file (&path
, full_nm_suffix
);
970 ldd_file_name
= find_a_file (&cpath
, ldd_suffix
);
971 if (ldd_file_name
== 0)
972 ldd_file_name
= find_a_file (&path
, full_ldd_suffix
);
975 #ifdef REAL_STRIP_FILE_NAME
976 strip_file_name
= find_a_file (&path
, REAL_STRIP_FILE_NAME
);
977 if (strip_file_name
== 0)
979 strip_file_name
= find_a_file (&cpath
, gstrip_suffix
);
980 if (strip_file_name
== 0)
981 strip_file_name
= find_a_file (&path
, full_gstrip_suffix
);
982 if (strip_file_name
== 0)
983 strip_file_name
= find_a_file (&cpath
, strip_suffix
);
984 if (strip_file_name
== 0)
985 strip_file_name
= find_a_file (&path
, full_strip_suffix
);
987 /* Determine the full path name of the C compiler to use. */
988 c_file_name
= getenv ("COLLECT_GCC");
989 if (c_file_name
== 0)
991 #ifdef CROSS_DIRECTORY_STRUCTURE
992 c_file_name
= concat (target_machine
, "-gcc", NULL
);
998 p
= find_a_file (&cpath
, c_file_name
);
1000 /* Here it should be safe to use the system search path since we should have
1001 already qualified the name of the compiler when it is needed. */
1003 p
= find_a_file (&path
, c_file_name
);
1008 *ld1
++ = *ld2
++ = ld_file_name
;
1010 /* Make temp file names. */
1011 c_file
= make_temp_file (".c");
1012 o_file
= make_temp_file (".o");
1013 #ifdef COLLECT_EXPORT_LIST
1014 export_file
= make_temp_file (".x");
1016 ldout
= make_temp_file (".ld");
1017 lderrout
= make_temp_file (".le");
1018 *c_ptr
++ = c_file_name
;
1025 #ifdef COLLECT_EXPORT_LIST
1026 /* Generate a list of directories from LIBPATH. */
1027 prefix_from_env ("LIBPATH", &libpath_lib_dirs
);
1028 /* Add to this list also two standard directories where
1029 AIX loader always searches for libraries. */
1030 add_prefix (&libpath_lib_dirs
, "/lib");
1031 add_prefix (&libpath_lib_dirs
, "/usr/lib");
1034 /* Get any options that the upper GCC wants to pass to the sub-GCC.
1036 AIX support needs to know if -shared has been specified before
1037 parsing commandline arguments. */
1039 p
= getenv ("COLLECT_GCC_OPTIONS");
1042 const char *q
= extract_string (&p
);
1043 if (*q
== '-' && (q
[1] == 'm' || q
[1] == 'f'))
1044 *c_ptr
++ = xstrdup (q
);
1045 if (strcmp (q
, "-EL") == 0 || strcmp (q
, "-EB") == 0)
1046 *c_ptr
++ = xstrdup (q
);
1047 if (strcmp (q
, "-shared") == 0)
1049 if (*q
== '-' && q
[1] == 'B')
1051 *c_ptr
++ = xstrdup (q
);
1054 q
= extract_string (&p
);
1055 *c_ptr
++ = xstrdup (q
);
1059 obstack_free (&temporary_obstack
, temporary_firstobj
);
1060 *c_ptr
++ = "-fno-profile-arcs";
1061 *c_ptr
++ = "-fno-test-coverage";
1062 *c_ptr
++ = "-fno-branch-probabilities";
1063 *c_ptr
++ = "-fno-exceptions";
1066 /* !!! When GCC calls collect2,
1067 it does not know whether it is calling collect2 or ld.
1068 So collect2 cannot meaningfully understand any options
1069 except those ld understands.
1070 If you propose to make GCC pass some other option,
1071 just imagine what will happen if ld is really ld!!! */
1073 /* Parse arguments. Remember output file spec, pass the rest to ld. */
1074 /* After the first file, put in the c++ rt0. */
1077 #ifdef HAVE_LD_DEMANGLE
1078 if (!demangle_flag
&& !no_demangle
)
1079 demangle_flag
= "--demangle";
1081 *ld1
++ = *ld2
++ = demangle_flag
;
1083 while ((arg
= *++argv
) != (char *) 0)
1085 *ld1
++ = *ld2
++ = arg
;
1091 #ifdef COLLECT_EXPORT_LIST
1092 /* We want to disable automatic exports on AIX when user
1093 explicitly puts an export list in command line */
1095 if (arg
[2] == 'E' || strncmp (&arg
[2], "export", 6) == 0)
1097 else if (arg
[2] == '6' && arg
[3] == '4')
1099 else if (arg
[2] == 'r' && arg
[3] == 't' && arg
[4] == 'l')
1105 if (!strcmp (arg
, "-debug"))
1107 /* Already parsed. */
1111 if (!strcmp (arg
, "-dynamic-linker") && argv
[1])
1114 *ld1
++ = *ld2
++ = *argv
;
1121 /* place o_file BEFORE this argument! */
1127 #ifdef COLLECT_EXPORT_LIST
1129 /* Resolving full library name. */
1130 const char *s
= resolve_lib_name (arg
+2);
1132 /* Saving a full library name. */
1133 add_to_list (&libs
, s
);
1138 #ifdef COLLECT_EXPORT_LIST
1139 /* Saving directories where to search for libraries. */
1141 add_prefix (&cmdline_lib_dirs
, arg
+2);
1144 #if LINK_ELIMINATE_DUPLICATE_LDIRECTORIES
1146 if (is_in_args (arg
, (const char **) ld1_argv
, ld1
-1))
1149 #endif /* LINK_ELIMINATE_DUPLICATE_LDIRECTORIES */
1154 output_file
= *ld1
++ = *ld2
++ = *++argv
;
1156 #ifdef SWITCHES_NEED_SPACES
1157 && ! strchr (SWITCHES_NEED_SPACES
, arg
[1])
1161 output_file
= &arg
[2];
1170 if (arg
[2] == '\0' && do_collecting
)
1172 /* We must strip after the nm run, otherwise C++ linking
1173 will not work. Thus we strip in the second ld run, or
1174 else with strip if there is no second ld run. */
1186 if (strcmp (arg
, "--no-demangle") == 0)
1188 demangle_flag
= arg
;
1193 else if (strncmp (arg
, "--demangle", 10) == 0)
1195 demangle_flag
= arg
;
1197 #ifndef HAVE_LD_DEMANGLE
1200 enum demangling_styles style
1201 = cplus_demangle_name_to_style (arg
+11);
1202 if (style
== unknown_demangling
)
1203 error ("unknown demangling style '%s'", arg
+11);
1205 current_demangling_style
= style
;
1214 else if ((p
= strrchr (arg
, '.')) != (char *) 0
1215 && (strcmp (p
, ".o") == 0 || strcmp (p
, ".a") == 0
1216 || strcmp (p
, ".so") == 0 || strcmp (p
, ".lo") == 0
1217 || strcmp (p
, ".obj") == 0))
1226 /* place o_file BEFORE this argument! */
1232 if (p
[1] == 'o' || p
[1] == 'l')
1234 #ifdef COLLECT_EXPORT_LIST
1235 /* libraries can be specified directly, i.e. without -l flag. */
1238 /* Saving a full library name. */
1239 add_to_list (&libs
, arg
);
1245 #ifdef COLLECT_EXPORT_LIST
1246 /* This is added only for debugging purposes. */
1249 fprintf (stderr
, "List of libraries:\n");
1250 dump_list (stderr
, "\t", libs
.first
);
1253 /* The AIX linker will discard static constructors in object files if
1254 nothing else in the file is referenced, so look at them first. */
1256 const char **export_object_lst
= (const char **)object_lst
;
1258 while (export_object_lst
< object
)
1259 scan_prog_file (*export_object_lst
++, PASS_OBJ
);
1262 struct id
*list
= libs
.first
;
1264 for (; list
; list
= list
->next
)
1265 scan_prog_file (list
->name
, PASS_FIRST
);
1270 char *buf
= concat ("-bE:", export_file
, NULL
);
1275 exportf
= fopen (export_file
, "w");
1276 if (exportf
== (FILE *) 0)
1277 fatal_perror ("fopen %s", export_file
);
1278 write_aix_file (exportf
, exports
.first
);
1279 if (fclose (exportf
))
1280 fatal_perror ("fclose %s", export_file
);
1285 *c_ptr
= *ld1
= *object
= (char *) 0;
1289 notice ("collect2 version %s", version_string
);
1290 #ifdef TARGET_VERSION
1293 fprintf (stderr
, "\n");
1299 fprintf (stderr
, "ld_file_name = %s\n",
1300 (ld_file_name
? ld_file_name
: "not found"));
1301 fprintf (stderr
, "c_file_name = %s\n",
1302 (c_file_name
? c_file_name
: "not found"));
1303 fprintf (stderr
, "nm_file_name = %s\n",
1304 (nm_file_name
? nm_file_name
: "not found"));
1306 fprintf (stderr
, "ldd_file_name = %s\n",
1307 (ldd_file_name
? ldd_file_name
: "not found"));
1309 fprintf (stderr
, "strip_file_name = %s\n",
1310 (strip_file_name
? strip_file_name
: "not found"));
1311 fprintf (stderr
, "c_file = %s\n",
1312 (c_file
? c_file
: "not found"));
1313 fprintf (stderr
, "o_file = %s\n",
1314 (o_file
? o_file
: "not found"));
1316 ptr
= getenv ("COLLECT_GCC_OPTIONS");
1318 fprintf (stderr
, "COLLECT_GCC_OPTIONS = %s\n", ptr
);
1320 ptr
= getenv ("COLLECT_GCC");
1322 fprintf (stderr
, "COLLECT_GCC = %s\n", ptr
);
1324 ptr
= getenv ("COMPILER_PATH");
1326 fprintf (stderr
, "COMPILER_PATH = %s\n", ptr
);
1328 ptr
= getenv (LIBRARY_PATH_ENV
);
1330 fprintf (stderr
, "%-20s= %s\n", LIBRARY_PATH_ENV
, ptr
);
1332 fprintf (stderr
, "\n");
1335 /* Load the program, searching all libraries and attempting to provide
1336 undefined symbols from repository information. */
1338 /* On AIX we do this later. */
1339 #ifndef COLLECT_EXPORT_LIST
1340 do_tlink (ld1_argv
, object_lst
);
1343 /* If -r or they will be run via some other method, do not build the
1344 constructor or destructor list, just return now. */
1346 #ifndef COLLECT_EXPORT_LIST
1351 #ifdef COLLECT_EXPORT_LIST
1352 /* Do the link we avoided above if we are exiting. */
1353 do_tlink (ld1_argv
, object_lst
);
1355 /* But make sure we delete the export file we may have created. */
1356 if (export_file
!= 0 && export_file
[0])
1357 maybe_unlink (export_file
);
1359 maybe_unlink (c_file
);
1360 maybe_unlink (o_file
);
1364 /* Examine the namelist with nm and search it for static constructors
1365 and destructors to call.
1366 Write the constructor and destructor tables to a .s file and reload. */
1368 /* On AIX we already scanned for global constructors/destructors. */
1369 #ifndef COLLECT_EXPORT_LIST
1370 scan_prog_file (output_file
, PASS_FIRST
);
1373 #ifdef SCAN_LIBRARIES
1374 scan_libraries (output_file
);
1379 notice ("%d constructor(s) found\n", constructors
.number
);
1380 notice ("%d destructor(s) found\n", destructors
.number
);
1381 notice ("%d frame table(s) found\n", frame_tables
.number
);
1384 if (constructors
.number
== 0 && destructors
.number
== 0
1385 && frame_tables
.number
== 0
1386 #if defined (SCAN_LIBRARIES) || defined (COLLECT_EXPORT_LIST)
1387 /* If we will be running these functions ourselves, we want to emit
1388 stubs into the shared library so that we do not have to relink
1389 dependent programs when we add static objects. */
1394 #ifdef COLLECT_EXPORT_LIST
1395 /* Do tlink without additional code generation. */
1396 do_tlink (ld1_argv
, object_lst
);
1398 /* Strip now if it was requested on the command line. */
1401 char **real_strip_argv
= XCNEWVEC (char *, 3);
1402 const char ** strip_argv
= (const char **) real_strip_argv
;
1404 strip_argv
[0] = strip_file_name
;
1405 strip_argv
[1] = output_file
;
1406 strip_argv
[2] = (char *) 0;
1407 fork_execute ("strip", real_strip_argv
);
1410 #ifdef COLLECT_EXPORT_LIST
1411 maybe_unlink (export_file
);
1413 maybe_unlink (c_file
);
1414 maybe_unlink (o_file
);
1418 /* Sort ctor and dtor lists by priority. */
1419 sort_ids (&constructors
);
1420 sort_ids (&destructors
);
1422 maybe_unlink(output_file
);
1423 outf
= fopen (c_file
, "w");
1424 if (outf
== (FILE *) 0)
1425 fatal_perror ("fopen %s", c_file
);
1427 write_c_file (outf
, c_file
);
1430 fatal_perror ("fclose %s", c_file
);
1432 /* Tell the linker that we have initializer and finalizer functions. */
1433 #ifdef LD_INIT_SWITCH
1434 #ifdef COLLECT_EXPORT_LIST
1435 *ld2
++ = concat (LD_INIT_SWITCH
, ":", initname
, ":", fininame
, NULL
);
1437 *ld2
++ = LD_INIT_SWITCH
;
1439 *ld2
++ = LD_FINI_SWITCH
;
1444 #ifdef COLLECT_EXPORT_LIST
1447 /* If we did not add export flag to link arguments before, add it to
1448 second link phase now. No new exports should have been added. */
1449 if (! exports
.first
)
1450 *ld2
++ = concat ("-bE:", export_file
, NULL
);
1452 #ifndef LD_INIT_SWITCH
1453 add_to_list (&exports
, initname
);
1454 add_to_list (&exports
, fininame
);
1455 add_to_list (&exports
, "_GLOBAL__DI");
1456 add_to_list (&exports
, "_GLOBAL__DD");
1458 exportf
= fopen (export_file
, "w");
1459 if (exportf
== (FILE *) 0)
1460 fatal_perror ("fopen %s", export_file
);
1461 write_aix_file (exportf
, exports
.first
);
1462 if (fclose (exportf
))
1463 fatal_perror ("fclose %s", export_file
);
1467 /* End of arguments to second link phase. */
1472 fprintf (stderr
, "\n========== output_file = %s, c_file = %s\n",
1473 output_file
, c_file
);
1474 write_c_file (stderr
, "stderr");
1475 fprintf (stderr
, "========== end of c_file\n\n");
1476 #ifdef COLLECT_EXPORT_LIST
1477 fprintf (stderr
, "\n========== export_file = %s\n", export_file
);
1478 write_aix_file (stderr
, exports
.first
);
1479 fprintf (stderr
, "========== end of export_file\n\n");
1483 /* Assemble the constructor and destructor tables.
1484 Link the tables in with the rest of the program. */
1486 fork_execute ("gcc", c_argv
);
1487 #ifdef COLLECT_EXPORT_LIST
1488 /* On AIX we must call tlink because of possible templates resolution. */
1489 do_tlink (ld2_argv
, object_lst
);
1491 /* Otherwise, simply call ld because tlink is already done. */
1492 fork_execute ("ld", ld2_argv
);
1494 /* Let scan_prog_file do any final mods (OSF/rose needs this for
1495 constructors/destructors in shared libraries. */
1496 scan_prog_file (output_file
, PASS_SECOND
);
1499 maybe_unlink (c_file
);
1500 maybe_unlink (o_file
);
1502 #ifdef COLLECT_EXPORT_LIST
1503 maybe_unlink (export_file
);
1510 /* Wait for a process to finish, and exit if a nonzero status is found. */
1513 collect_wait (const char *prog
, struct pex_obj
*pex
)
1517 if (!pex_get_status (pex
, 1, &status
))
1518 fatal_perror ("can't get program status");
1523 if (WIFSIGNALED (status
))
1525 int sig
= WTERMSIG (status
);
1526 error ("%s terminated with signal %d [%s]%s",
1527 prog
, sig
, strsignal(sig
),
1528 WCOREDUMP(status
) ? ", core dumped" : "");
1529 collect_exit (FATAL_EXIT_CODE
);
1532 if (WIFEXITED (status
))
1533 return WEXITSTATUS (status
);
1539 do_wait (const char *prog
, struct pex_obj
*pex
)
1541 int ret
= collect_wait (prog
, pex
);
1544 error ("%s returned %d exit status", prog
, ret
);
1550 unlink (response_file
);
1551 response_file
= NULL
;
1556 /* Execute a program, and wait for the reply. */
1559 collect_execute (const char *prog
, char **argv
, const char *outname
,
1560 const char *errname
)
1562 struct pex_obj
*pex
;
1565 char *response_arg
= NULL
;
1566 char *response_argv
[3] ATTRIBUTE_UNUSED
;
1568 if (HAVE_GNU_LD
&& at_file_supplied
&& argv
[0] != NULL
)
1570 /* If using @file arguments, create a temporary file and put the
1571 contents of argv into it. Then change argv to an array corresponding
1572 to a single argument @FILE, where FILE is the temporary filename. */
1574 char **current_argv
= argv
+ 1;
1575 char *argv0
= argv
[0];
1579 /* Note: we assume argv contains at least one element; this is
1582 response_file
= make_temp_file ("");
1584 f
= fopen (response_file
, "w");
1587 fatal ("could not open response file %s", response_file
);
1589 status
= writeargv (current_argv
, f
);
1592 fatal ("could not write to response file %s", response_file
);
1594 status
= fclose (f
);
1597 fatal ("could not close response file %s", response_file
);
1599 response_arg
= concat ("@", response_file
, NULL
);
1600 response_argv
[0] = argv0
;
1601 response_argv
[1] = response_arg
;
1602 response_argv
[2] = NULL
;
1604 argv
= response_argv
;
1613 fprintf (stderr
, "%s", argv
[0]);
1615 notice ("[cannot find %s]", prog
);
1617 for (p_argv
= &argv
[1]; (str
= *p_argv
) != (char *) 0; p_argv
++)
1618 fprintf (stderr
, " %s", str
);
1620 fprintf (stderr
, "\n");
1626 /* If we cannot find a program we need, complain error. Do this here
1627 since we might not end up needing something that we could not find. */
1630 fatal ("cannot find '%s'", prog
);
1632 pex
= pex_init (0, "collect2", NULL
);
1634 fatal_perror ("pex_init failed");
1636 errmsg
= pex_run (pex
, PEX_LAST
| PEX_SEARCH
, argv
[0], argv
, outname
,
1643 fatal_perror (errmsg
);
1650 free (response_arg
);
1656 fork_execute (const char *prog
, char **argv
)
1658 struct pex_obj
*pex
;
1660 pex
= collect_execute (prog
, argv
, NULL
, NULL
);
1661 do_wait (prog
, pex
);
1664 /* Unlink a file unless we are debugging. */
1667 maybe_unlink (const char *file
)
1670 unlink_if_ordinary (file
);
1672 notice ("[Leaving %s]\n", file
);
1676 static long sequence_number
= 0;
1678 /* Add a name to a linked list. */
1681 add_to_list (struct head
*head_ptr
, const char *name
)
1683 struct id
*newid
= xcalloc (sizeof (struct id
) + strlen (name
), 1);
1685 strcpy (newid
->name
, name
);
1687 if (head_ptr
->first
)
1688 head_ptr
->last
->next
= newid
;
1690 head_ptr
->first
= newid
;
1692 /* Check for duplicate symbols. */
1693 for (p
= head_ptr
->first
;
1694 strcmp (name
, p
->name
) != 0;
1699 head_ptr
->last
->next
= 0;
1704 newid
->sequence
= ++sequence_number
;
1705 head_ptr
->last
= newid
;
1709 /* Grab the init priority number from an init function name that
1710 looks like "_GLOBAL_.I.12345.foo". */
1713 extract_init_priority (const char *name
)
1717 while (name
[pos
] == '_')
1719 pos
+= 10; /* strlen ("GLOBAL__X_") */
1721 /* Extract init_p number from ctor/dtor name. */
1722 pri
= atoi (name
+ pos
);
1723 return pri
? pri
: DEFAULT_INIT_PRIORITY
;
1726 /* Insertion sort the ids from ctor/dtor list HEAD_PTR in descending order.
1727 ctors will be run from right to left, dtors from left to right. */
1730 sort_ids (struct head
*head_ptr
)
1732 /* id holds the current element to insert. id_next holds the next
1733 element to insert. id_ptr iterates through the already sorted elements
1734 looking for the place to insert id. */
1735 struct id
*id
, *id_next
, **id_ptr
;
1737 id
= head_ptr
->first
;
1739 /* We don't have any sorted elements yet. */
1740 head_ptr
->first
= NULL
;
1742 for (; id
; id
= id_next
)
1745 id
->sequence
= extract_init_priority (id
->name
);
1747 for (id_ptr
= &(head_ptr
->first
); ; id_ptr
= &((*id_ptr
)->next
))
1749 /* If the sequence numbers are the same, we put the id from the
1750 file later on the command line later in the list. */
1751 || id
->sequence
> (*id_ptr
)->sequence
1752 /* Hack: do lexical compare, too.
1753 || (id->sequence == (*id_ptr)->sequence
1754 && strcmp (id->name, (*id_ptr)->name) > 0) */
1763 /* Now set the sequence numbers properly so write_c_file works. */
1764 for (id
= head_ptr
->first
; id
; id
= id
->next
)
1765 id
->sequence
= ++sequence_number
;
1768 /* Write: `prefix', the names on list LIST, `suffix'. */
1771 write_list (FILE *stream
, const char *prefix
, struct id
*list
)
1775 fprintf (stream
, "%sx%d,\n", prefix
, list
->sequence
);
1780 #if LINK_ELIMINATE_DUPLICATE_LDIRECTORIES
1781 /* Given a STRING, return nonzero if it occurs in the list in range
1782 [ARGS_BEGIN,ARGS_END). */
1785 is_in_args (const char *string
, const char **args_begin
,
1786 const char **args_end
)
1788 const char **args_pointer
;
1789 for (args_pointer
= args_begin
; args_pointer
!= args_end
; ++args_pointer
)
1790 if (strcmp (string
, *args_pointer
) == 0)
1794 #endif /* LINK_ELIMINATE_DUPLICATE_LDIRECTORIES */
1796 #ifdef COLLECT_EXPORT_LIST
1797 /* This function is really used only on AIX, but may be useful. */
1800 is_in_list (const char *prefix
, struct id
*list
)
1804 if (!strcmp (prefix
, list
->name
)) return 1;
1810 #endif /* COLLECT_EXPORT_LIST */
1812 /* Added for debugging purpose. */
1813 #ifdef COLLECT_EXPORT_LIST
1815 dump_list (FILE *stream
, const char *prefix
, struct id
*list
)
1819 fprintf (stream
, "%s%s,\n", prefix
, list
->name
);
1827 dump_prefix_list (FILE *stream
, const char *prefix
, struct prefix_list
*list
)
1831 fprintf (stream
, "%s%s,\n", prefix
, list
->prefix
);
1838 write_list_with_asm (FILE *stream
, const char *prefix
, struct id
*list
)
1842 fprintf (stream
, "%sx%d __asm__ (\"%s\");\n",
1843 prefix
, list
->sequence
, list
->name
);
1848 /* Write out the constructor and destructor tables statically (for a shared
1849 object), along with the functions to execute them. */
1852 write_c_file_stat (FILE *stream
, const char *name ATTRIBUTE_UNUSED
)
1856 int frames
= (frame_tables
.number
> 0);
1858 /* Figure out name of output_file, stripping off .so version. */
1859 p
= strrchr (output_file
, '/');
1875 if (strncmp (q
, SHLIB_SUFFIX
, strlen (SHLIB_SUFFIX
)) == 0)
1877 q
+= strlen (SHLIB_SUFFIX
);
1884 /* q points to null at end of the string (or . of the .so version) */
1885 prefix
= XNEWVEC (char, q
- p
+ 1);
1886 strncpy (prefix
, p
, q
- p
);
1888 for (r
= prefix
; *r
; r
++)
1889 if (!ISALNUM ((unsigned char)*r
))
1892 notice ("\nwrite_c_file - output name is %s, prefix is %s\n",
1893 output_file
, prefix
);
1895 initname
= concat ("_GLOBAL__FI_", prefix
, NULL
);
1896 fininame
= concat ("_GLOBAL__FD_", prefix
, NULL
);
1900 /* Write the tables as C code. */
1902 fprintf (stream
, "static int count;\n");
1903 fprintf (stream
, "typedef void entry_pt();\n");
1904 write_list_with_asm (stream
, "extern entry_pt ", constructors
.first
);
1908 write_list_with_asm (stream
, "extern void *", frame_tables
.first
);
1910 fprintf (stream
, "\tstatic void *frame_table[] = {\n");
1911 write_list (stream
, "\t\t&", frame_tables
.first
);
1912 fprintf (stream
, "\t0\n};\n");
1914 /* This must match what's in frame.h. */
1915 fprintf (stream
, "struct object {\n");
1916 fprintf (stream
, " void *pc_begin;\n");
1917 fprintf (stream
, " void *pc_end;\n");
1918 fprintf (stream
, " void *fde_begin;\n");
1919 fprintf (stream
, " void *fde_array;\n");
1920 fprintf (stream
, " __SIZE_TYPE__ count;\n");
1921 fprintf (stream
, " struct object *next;\n");
1922 fprintf (stream
, "};\n");
1924 fprintf (stream
, "extern void __register_frame_info_table (void *, struct object *);\n");
1925 fprintf (stream
, "extern void *__deregister_frame_info (void *);\n");
1927 fprintf (stream
, "static void reg_frame () {\n");
1928 fprintf (stream
, "\tstatic struct object ob;\n");
1929 fprintf (stream
, "\t__register_frame_info_table (frame_table, &ob);\n");
1930 fprintf (stream
, "\t}\n");
1932 fprintf (stream
, "static void dereg_frame () {\n");
1933 fprintf (stream
, "\t__deregister_frame_info (frame_table);\n");
1934 fprintf (stream
, "\t}\n");
1937 fprintf (stream
, "void %s() {\n", initname
);
1938 if (constructors
.number
> 0 || frames
)
1940 fprintf (stream
, "\tstatic entry_pt *ctors[] = {\n");
1941 write_list (stream
, "\t\t", constructors
.first
);
1943 fprintf (stream
, "\treg_frame,\n");
1944 fprintf (stream
, "\t};\n");
1945 fprintf (stream
, "\tentry_pt **p;\n");
1946 fprintf (stream
, "\tif (count++ != 0) return;\n");
1947 fprintf (stream
, "\tp = ctors + %d;\n", constructors
.number
+ frames
);
1948 fprintf (stream
, "\twhile (p > ctors) (*--p)();\n");
1951 fprintf (stream
, "\t++count;\n");
1952 fprintf (stream
, "}\n");
1953 write_list_with_asm (stream
, "extern entry_pt ", destructors
.first
);
1954 fprintf (stream
, "void %s() {\n", fininame
);
1955 if (destructors
.number
> 0 || frames
)
1957 fprintf (stream
, "\tstatic entry_pt *dtors[] = {\n");
1958 write_list (stream
, "\t\t", destructors
.first
);
1960 fprintf (stream
, "\tdereg_frame,\n");
1961 fprintf (stream
, "\t};\n");
1962 fprintf (stream
, "\tentry_pt **p;\n");
1963 fprintf (stream
, "\tif (--count != 0) return;\n");
1964 fprintf (stream
, "\tp = dtors;\n");
1965 fprintf (stream
, "\twhile (p < dtors + %d) (*p++)();\n",
1966 destructors
.number
+ frames
);
1968 fprintf (stream
, "}\n");
1972 COLLECT_SHARED_INIT_FUNC(stream
, initname
);
1973 COLLECT_SHARED_FINI_FUNC(stream
, fininame
);
1977 /* Write the constructor/destructor tables. */
1979 #ifndef LD_INIT_SWITCH
1981 write_c_file_glob (FILE *stream
, const char *name ATTRIBUTE_UNUSED
)
1983 /* Write the tables as C code. */
1985 int frames
= (frame_tables
.number
> 0);
1987 fprintf (stream
, "typedef void entry_pt();\n\n");
1989 write_list_with_asm (stream
, "extern entry_pt ", constructors
.first
);
1993 write_list_with_asm (stream
, "extern void *", frame_tables
.first
);
1995 fprintf (stream
, "\tstatic void *frame_table[] = {\n");
1996 write_list (stream
, "\t\t&", frame_tables
.first
);
1997 fprintf (stream
, "\t0\n};\n");
1999 /* This must match what's in frame.h. */
2000 fprintf (stream
, "struct object {\n");
2001 fprintf (stream
, " void *pc_begin;\n");
2002 fprintf (stream
, " void *pc_end;\n");
2003 fprintf (stream
, " void *fde_begin;\n");
2004 fprintf (stream
, " void *fde_array;\n");
2005 fprintf (stream
, " __SIZE_TYPE__ count;\n");
2006 fprintf (stream
, " struct object *next;\n");
2007 fprintf (stream
, "};\n");
2009 fprintf (stream
, "extern void __register_frame_info_table (void *, struct object *);\n");
2010 fprintf (stream
, "extern void *__deregister_frame_info (void *);\n");
2012 fprintf (stream
, "static void reg_frame () {\n");
2013 fprintf (stream
, "\tstatic struct object ob;\n");
2014 fprintf (stream
, "\t__register_frame_info_table (frame_table, &ob);\n");
2015 fprintf (stream
, "\t}\n");
2017 fprintf (stream
, "static void dereg_frame () {\n");
2018 fprintf (stream
, "\t__deregister_frame_info (frame_table);\n");
2019 fprintf (stream
, "\t}\n");
2022 fprintf (stream
, "\nentry_pt * __CTOR_LIST__[] = {\n");
2023 fprintf (stream
, "\t(entry_pt *) %d,\n", constructors
.number
+ frames
);
2024 write_list (stream
, "\t", constructors
.first
);
2026 fprintf (stream
, "\treg_frame,\n");
2027 fprintf (stream
, "\t0\n};\n\n");
2029 write_list_with_asm (stream
, "extern entry_pt ", destructors
.first
);
2031 fprintf (stream
, "\nentry_pt * __DTOR_LIST__[] = {\n");
2032 fprintf (stream
, "\t(entry_pt *) %d,\n", destructors
.number
+ frames
);
2033 write_list (stream
, "\t", destructors
.first
);
2035 fprintf (stream
, "\tdereg_frame,\n");
2036 fprintf (stream
, "\t0\n};\n\n");
2038 fprintf (stream
, "extern entry_pt %s;\n", NAME__MAIN
);
2039 fprintf (stream
, "entry_pt *__main_reference = %s;\n\n", NAME__MAIN
);
2041 #endif /* ! LD_INIT_SWITCH */
2044 write_c_file (FILE *stream
, const char *name
)
2046 fprintf (stream
, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n");
2047 #ifndef LD_INIT_SWITCH
2049 write_c_file_glob (stream
, name
);
2052 write_c_file_stat (stream
, name
);
2053 fprintf (stream
, "#ifdef __cplusplus\n}\n#endif\n");
2056 #ifdef COLLECT_EXPORT_LIST
2058 write_aix_file (FILE *stream
, struct id
*list
)
2060 for (; list
; list
= list
->next
)
2062 fputs (list
->name
, stream
);
2063 putc ('\n', stream
);
2068 #ifdef OBJECT_FORMAT_NONE
2070 /* Generic version to scan the name list of the loaded program for
2071 the symbols g++ uses for static constructors and destructors.
2073 The constructor table begins at __CTOR_LIST__ and contains a count
2074 of the number of pointers (or -1 if the constructors are built in a
2075 separate section by the linker), followed by the pointers to the
2076 constructor functions, terminated with a null pointer. The
2077 destructor table has the same format, and begins at __DTOR_LIST__. */
2080 scan_prog_file (const char *prog_name
, enum pass which_pass
)
2082 void (*int_handler
) (int);
2084 void (*quit_handler
) (int);
2086 char *real_nm_argv
[4];
2087 const char **nm_argv
= (const char **) real_nm_argv
;
2089 struct pex_obj
*pex
;
2095 if (which_pass
== PASS_SECOND
)
2098 /* If we do not have an `nm', complain. */
2099 if (nm_file_name
== 0)
2100 fatal ("cannot find 'nm'");
2102 nm_argv
[argc
++] = nm_file_name
;
2103 if (NM_FLAGS
[0] != '\0')
2104 nm_argv
[argc
++] = NM_FLAGS
;
2106 nm_argv
[argc
++] = prog_name
;
2107 nm_argv
[argc
++] = (char *) 0;
2109 /* Trace if needed. */
2112 const char **p_argv
;
2115 for (p_argv
= &nm_argv
[0]; (str
= *p_argv
) != (char *) 0; p_argv
++)
2116 fprintf (stderr
, " %s", str
);
2118 fprintf (stderr
, "\n");
2124 pex
= pex_init (PEX_USE_PIPES
, "collect2", NULL
);
2126 fatal_perror ("pex_init failed");
2128 errmsg
= pex_run (pex
, 0, nm_file_name
, real_nm_argv
, NULL
, NULL
, &err
);
2134 fatal_perror (errmsg
);
2140 int_handler
= (void (*) (int)) signal (SIGINT
, SIG_IGN
);
2142 quit_handler
= (void (*) (int)) signal (SIGQUIT
, SIG_IGN
);
2145 inf
= pex_read_output (pex
, 0);
2147 fatal_perror ("can't open nm output");
2150 fprintf (stderr
, "\nnm output with constructors/destructors.\n");
2152 /* Read each line of nm output. */
2153 while (fgets (buf
, sizeof buf
, inf
) != (char *) 0)
2158 /* If it contains a constructor or destructor name, add the name
2159 to the appropriate list. */
2161 for (p
= buf
; (ch
= *p
) != '\0' && ch
!= '\n' && ch
!= '_'; p
++)
2162 if (ch
== ' ' && p
[1] == 'U' && p
[2] == ' ')
2169 /* Find the end of the symbol name.
2170 Do not include `|', because Encore nm can tack that on the end. */
2171 for (end
= p
; (ch2
= *end
) != '\0' && !ISSPACE (ch2
) && ch2
!= '|';
2177 switch (is_ctor_dtor (name
))
2180 if (which_pass
!= PASS_LIB
)
2181 add_to_list (&constructors
, name
);
2185 if (which_pass
!= PASS_LIB
)
2186 add_to_list (&destructors
, name
);
2190 if (which_pass
!= PASS_LIB
)
2191 fatal ("init function found in object %s", prog_name
);
2192 #ifndef LD_INIT_SWITCH
2193 add_to_list (&constructors
, name
);
2198 if (which_pass
!= PASS_LIB
)
2199 fatal ("fini function found in object %s", prog_name
);
2200 #ifndef LD_FINI_SWITCH
2201 add_to_list (&destructors
, name
);
2206 if (which_pass
!= PASS_LIB
)
2207 add_to_list (&frame_tables
, name
);
2210 default: /* not a constructor or destructor */
2215 fprintf (stderr
, "\t%s\n", buf
);
2219 fprintf (stderr
, "\n");
2221 do_wait (nm_file_name
, pex
);
2223 signal (SIGINT
, int_handler
);
2225 signal (SIGQUIT
, quit_handler
);
2231 /* Use the List Dynamic Dependencies program to find shared libraries that
2232 the output file depends upon and their initialization/finalization
2233 routines, if any. */
2236 scan_libraries (const char *prog_name
)
2238 static struct head libraries
; /* list of shared libraries found */
2240 void (*int_handler
) (int);
2242 void (*quit_handler
) (int);
2244 char *real_ldd_argv
[4];
2245 const char **ldd_argv
= (const char **) real_ldd_argv
;
2247 struct pex_obj
*pex
;
2253 /* If we do not have an `ldd', complain. */
2254 if (ldd_file_name
== 0)
2256 error ("cannot find 'ldd'");
2260 ldd_argv
[argc
++] = ldd_file_name
;
2261 ldd_argv
[argc
++] = prog_name
;
2262 ldd_argv
[argc
++] = (char *) 0;
2264 /* Trace if needed. */
2267 const char **p_argv
;
2270 for (p_argv
= &ldd_argv
[0]; (str
= *p_argv
) != (char *) 0; p_argv
++)
2271 fprintf (stderr
, " %s", str
);
2273 fprintf (stderr
, "\n");
2279 pex
= pex_init (PEX_USE_PIPES
, "collect2", NULL
);
2281 fatal_perror ("pex_init failed");
2283 errmsg
= pex_run (pex
, 0, ldd_file_name
, real_ldd_argv
, NULL
, NULL
, &err
);
2289 fatal_perror (errmsg
);
2295 int_handler
= (void (*) (int)) signal (SIGINT
, SIG_IGN
);
2297 quit_handler
= (void (*) (int)) signal (SIGQUIT
, SIG_IGN
);
2300 inf
= pex_read_output (pex
, 0);
2302 fatal_perror ("can't open ldd output");
2305 notice ("\nldd output with constructors/destructors.\n");
2307 /* Read each line of ldd output. */
2308 while (fgets (buf
, sizeof buf
, inf
) != (char *) 0)
2311 char *name
, *end
, *p
= buf
;
2313 /* Extract names of libraries and add to list. */
2314 PARSE_LDD_OUTPUT (p
);
2319 if (strncmp (name
, "not found", sizeof ("not found") - 1) == 0)
2320 fatal ("dynamic dependency %s not found", buf
);
2322 /* Find the end of the symbol name. */
2324 (ch2
= *end
) != '\0' && ch2
!= '\n' && !ISSPACE (ch2
) && ch2
!= '|';
2329 if (access (name
, R_OK
) == 0)
2330 add_to_list (&libraries
, name
);
2332 fatal ("unable to open dynamic dependency '%s'", buf
);
2335 fprintf (stderr
, "\t%s\n", buf
);
2338 fprintf (stderr
, "\n");
2340 do_wait (ldd_file_name
, pex
);
2342 signal (SIGINT
, int_handler
);
2344 signal (SIGQUIT
, quit_handler
);
2347 /* Now iterate through the library list adding their symbols to
2349 for (list
= libraries
.first
; list
; list
= list
->next
)
2350 scan_prog_file (list
->name
, PASS_LIB
);
2353 #endif /* LDD_SUFFIX */
2355 #endif /* OBJECT_FORMAT_NONE */
2359 * COFF specific stuff.
2362 #ifdef OBJECT_FORMAT_COFF
2364 #if defined (EXTENDED_COFF)
2366 # define GCC_SYMBOLS(X) (SYMHEADER(X).isymMax + SYMHEADER(X).iextMax)
2367 # define GCC_SYMENT SYMR
2368 # define GCC_OK_SYMBOL(X) ((X).st == stProc || (X).st == stGlobal)
2369 # define GCC_SYMINC(X) (1)
2370 # define GCC_SYMZERO(X) (SYMHEADER(X).isymMax)
2371 # define GCC_CHECK_HDR(X) (PSYMTAB(X) != 0)
2375 # define GCC_SYMBOLS(X) (HEADER(ldptr).f_nsyms)
2376 # define GCC_SYMENT SYMENT
2377 # if defined (C_WEAKEXT)
2378 # define GCC_OK_SYMBOL(X) \
2379 (((X).n_sclass == C_EXT || (X).n_sclass == C_WEAKEXT) && \
2380 ((X).n_scnum > N_UNDEF) && \
2382 || (((X).n_type & N_TMASK) == (DT_NON << N_BTSHFT) \
2383 || ((X).n_type & N_TMASK) == (DT_FCN << N_BTSHFT))))
2384 # define GCC_UNDEF_SYMBOL(X) \
2385 (((X).n_sclass == C_EXT || (X).n_sclass == C_WEAKEXT) && \
2386 ((X).n_scnum == N_UNDEF))
2388 # define GCC_OK_SYMBOL(X) \
2389 (((X).n_sclass == C_EXT) && \
2390 ((X).n_scnum > N_UNDEF) && \
2392 || (((X).n_type & N_TMASK) == (DT_NON << N_BTSHFT) \
2393 || ((X).n_type & N_TMASK) == (DT_FCN << N_BTSHFT))))
2394 # define GCC_UNDEF_SYMBOL(X) \
2395 (((X).n_sclass == C_EXT) && ((X).n_scnum == N_UNDEF))
2397 # define GCC_SYMINC(X) ((X).n_numaux+1)
2398 # define GCC_SYMZERO(X) 0
2400 /* 0757 = U803XTOCMAGIC (AIX 4.3) and 0767 = U64_TOCMAGIC (AIX V5) */
2402 # define GCC_CHECK_HDR(X) \
2403 ((HEADER (X).f_magic == U802TOCMAGIC && ! aix64_flag) \
2404 || (HEADER (X).f_magic == 0767 && aix64_flag))
2406 # define GCC_CHECK_HDR(X) \
2407 ((HEADER (X).f_magic == U802TOCMAGIC && ! aix64_flag) \
2408 || (HEADER (X).f_magic == 0757 && aix64_flag))
2413 #ifdef COLLECT_EXPORT_LIST
2414 /* Array of standard AIX libraries which should not
2415 be scanned for ctors/dtors. */
2416 static const char *const aix_std_libs
[] = {
2424 "/usr/lib/libc_r.a",
2425 "/usr/lib/libm_r.a",
2426 "/usr/lib/threads/libc.a",
2427 "/usr/ccs/lib/libc.a",
2428 "/usr/ccs/lib/libm.a",
2429 "/usr/ccs/lib/libc_r.a",
2430 "/usr/ccs/lib/libm_r.a",
2434 /* This function checks the filename and returns 1
2435 if this name matches the location of a standard AIX library. */
2436 static int ignore_library (const char *);
2438 ignore_library (const char *name
)
2440 const char *const *p
= &aix_std_libs
[0];
2441 while (*p
++ != NULL
)
2442 if (! strcmp (name
, *p
)) return 1;
2445 #endif /* COLLECT_EXPORT_LIST */
2447 #if defined (HAVE_DECL_LDGETNAME) && !HAVE_DECL_LDGETNAME
2448 extern char *ldgetname (LDFILE
*, GCC_SYMENT
*);
2451 /* COFF version to scan the name list of the loaded program for
2452 the symbols g++ uses for static constructors and destructors.
2454 The constructor table begins at __CTOR_LIST__ and contains a count
2455 of the number of pointers (or -1 if the constructors are built in a
2456 separate section by the linker), followed by the pointers to the
2457 constructor functions, terminated with a null pointer. The
2458 destructor table has the same format, and begins at __DTOR_LIST__. */
2461 scan_prog_file (const char *prog_name
, enum pass which_pass
)
2463 LDFILE
*ldptr
= NULL
;
2464 int sym_index
, sym_count
;
2467 if (which_pass
!= PASS_FIRST
&& which_pass
!= PASS_OBJ
)
2470 #ifdef COLLECT_EXPORT_LIST
2471 /* We do not need scanning for some standard C libraries. */
2472 if (which_pass
== PASS_FIRST
&& ignore_library (prog_name
))
2475 /* On AIX we have a loop, because there is not much difference
2476 between an object and an archive. This trick allows us to
2477 eliminate scan_libraries() function. */
2481 /* Some platforms (e.g. OSF4) declare ldopen as taking a
2482 non-const char * filename parameter, even though it will not
2483 modify that string. So we must cast away const-ness here,
2484 which will cause -Wcast-qual to burp. */
2485 if ((ldptr
= ldopen ((char *)prog_name
, ldptr
)) != NULL
)
2487 if (! MY_ISCOFF (HEADER (ldptr
).f_magic
))
2488 fatal ("%s: not a COFF file", prog_name
);
2490 if (GCC_CHECK_HDR (ldptr
))
2492 sym_count
= GCC_SYMBOLS (ldptr
);
2493 sym_index
= GCC_SYMZERO (ldptr
);
2495 #ifdef COLLECT_EXPORT_LIST
2496 /* Is current archive member a shared object? */
2497 is_shared
= HEADER (ldptr
).f_flags
& F_SHROBJ
;
2500 while (sym_index
< sym_count
)
2504 if (ldtbread (ldptr
, sym_index
, &symbol
) <= 0)
2506 sym_index
+= GCC_SYMINC (symbol
);
2508 if (GCC_OK_SYMBOL (symbol
))
2512 if ((name
= ldgetname (ldptr
, &symbol
)) == NULL
)
2513 continue; /* Should never happen. */
2515 #ifdef XCOFF_DEBUGGING_INFO
2516 /* All AIX function names have a duplicate entry
2517 beginning with a dot. */
2522 switch (is_ctor_dtor (name
))
2526 add_to_list (&constructors
, name
);
2527 #if defined (COLLECT_EXPORT_LIST) && !defined (LD_INIT_SWITCH)
2528 if (which_pass
== PASS_OBJ
)
2529 add_to_list (&exports
, name
);
2535 add_to_list (&destructors
, name
);
2536 #if defined (COLLECT_EXPORT_LIST) && !defined (LD_INIT_SWITCH)
2537 if (which_pass
== PASS_OBJ
)
2538 add_to_list (&exports
, name
);
2542 #ifdef COLLECT_EXPORT_LIST
2544 #ifndef LD_INIT_SWITCH
2546 add_to_list (&constructors
, name
);
2551 #ifndef LD_INIT_SWITCH
2553 add_to_list (&destructors
, name
);
2560 add_to_list (&frame_tables
, name
);
2561 #if defined (COLLECT_EXPORT_LIST) && !defined (LD_INIT_SWITCH)
2562 if (which_pass
== PASS_OBJ
)
2563 add_to_list (&exports
, name
);
2567 default: /* not a constructor or destructor */
2568 #ifdef COLLECT_EXPORT_LIST
2569 /* Explicitly export all global symbols when
2570 building a shared object on AIX, but do not
2571 re-export symbols from another shared object
2572 and do not export symbols if the user
2573 provides an explicit export list. */
2574 if (shared_obj
&& !is_shared
2575 && which_pass
== PASS_OBJ
&& !export_flag
)
2576 add_to_list (&exports
, name
);
2582 #if !defined(EXTENDED_COFF)
2583 fprintf (stderr
, "\tsec=%d class=%d type=%s%o %s\n",
2584 symbol
.n_scnum
, symbol
.n_sclass
,
2585 (symbol
.n_type
? "0" : ""), symbol
.n_type
,
2589 "\tiss = %5d, value = %5ld, index = %5d, name = %s\n",
2590 symbol
.iss
, (long) symbol
.value
, symbol
.index
, name
);
2595 #ifdef COLLECT_EXPORT_LIST
2598 /* If archive contains both 32-bit and 64-bit objects,
2599 we want to skip objects in other mode so mismatch normal. */
2601 fprintf (stderr
, "%s : magic=%o aix64=%d mismatch\n",
2602 prog_name
, HEADER (ldptr
).f_magic
, aix64_flag
);
2608 fatal ("%s: cannot open as COFF file", prog_name
);
2610 #ifdef COLLECT_EXPORT_LIST
2611 /* On AIX loop continues while there are more members in archive. */
2613 while (ldclose (ldptr
) == FAILURE
);
2615 /* Otherwise we simply close ldptr. */
2616 (void) ldclose(ldptr
);
2619 #endif /* OBJECT_FORMAT_COFF */
2621 #ifdef COLLECT_EXPORT_LIST
2622 /* Given a library name without "lib" prefix, this function
2623 returns a full library name including a path. */
2625 resolve_lib_name (const char *name
)
2629 /* Library extensions for AIX dynamic linking. */
2630 const char * const libexts
[2] = {"a", "so"};
2632 for (i
= 0; libpaths
[i
]; i
++)
2633 if (libpaths
[i
]->max_len
> l
)
2634 l
= libpaths
[i
]->max_len
;
2636 lib_buf
= xmalloc (l
+ strlen(name
) + 10);
2638 for (i
= 0; libpaths
[i
]; i
++)
2640 struct prefix_list
*list
= libpaths
[i
]->plist
;
2641 for (; list
; list
= list
->next
)
2643 /* The following lines are needed because path_prefix list
2644 may contain directories both with trailing '/' and
2647 if (list
->prefix
[strlen(list
->prefix
)-1] != '/')
2649 for (j
= 0; j
< 2; j
++)
2651 sprintf (lib_buf
, "%s%slib%s.%s",
2652 list
->prefix
, p
, name
,
2653 libexts
[(j
+ aixrtl_flag
) % 2]);
2654 if (debug
) fprintf (stderr
, "searching for: %s\n", lib_buf
);
2655 if (file_exists (lib_buf
))
2657 if (debug
) fprintf (stderr
, "found: %s\n", lib_buf
);
2664 fprintf (stderr
, "not found\n");
2666 fatal ("library lib%s not found", name
);
2669 #endif /* COLLECT_EXPORT_LIST */