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 int do_collecting
= 1;
135 int do_collecting
= 0;
138 /* Nonzero if we should suppress the automatic demangling of identifiers
139 in linker error messages. Set from COLLECT_NO_DEMANGLE. */
142 /* Linked lists of constructor and destructor names. */
158 /* Enumeration giving which pass this is for scanning the program file. */
161 PASS_FIRST
, /* without constructors */
162 PASS_OBJ
, /* individual objects */
163 PASS_LIB
, /* looking for shared libraries */
164 PASS_SECOND
/* with constructors linked in */
167 int vflag
; /* true if -v */
168 static int rflag
; /* true if -r */
169 static int strip_flag
; /* true if -s */
170 static const char *demangle_flag
;
171 #ifdef COLLECT_EXPORT_LIST
172 static int export_flag
; /* true if -bE */
173 static int aix64_flag
; /* true if -b64 */
174 static int aixrtl_flag
; /* true if -brtl */
177 int debug
; /* true if -debug */
179 static int shared_obj
; /* true if -shared */
181 static const char *c_file
; /* <xxx>.c for constructor/destructor list. */
182 static const char *o_file
; /* <xxx>.o for constructor/destructor list. */
183 #ifdef COLLECT_EXPORT_LIST
184 static const char *export_file
; /* <xxx>.x for AIX export list. */
186 const char *ldout
; /* File for ld stdout. */
187 const char *lderrout
; /* File for ld stderr. */
188 static const char *output_file
; /* Output file for ld. */
189 static const char *nm_file_name
; /* pathname of nm */
191 static const char *ldd_file_name
; /* pathname of ldd (or equivalent) */
193 static const char *strip_file_name
; /* pathname of strip */
194 const char *c_file_name
; /* pathname of gcc */
195 static char *initname
, *fininame
; /* names of init and fini funcs */
197 static struct head constructors
; /* list of constructors found */
198 static struct head destructors
; /* list of destructors found */
199 #ifdef COLLECT_EXPORT_LIST
200 static struct head exports
; /* list of exported symbols */
202 static struct head frame_tables
; /* list of frame unwind info tables */
204 static bool at_file_supplied
; /* Whether to use @file arguments */
205 static char *response_file
; /* Name of any current response file */
207 struct obstack temporary_obstack
;
208 char * temporary_firstobj
;
210 /* Structure to hold all the directories in which to search for files to
215 const char *prefix
; /* String to prepend to the path. */
216 struct prefix_list
*next
; /* Next in linked list. */
221 struct prefix_list
*plist
; /* List of prefixes to try */
222 int max_len
; /* Max length of a prefix in PLIST */
223 const char *name
; /* Name of this list (used in config stuff) */
226 #ifdef COLLECT_EXPORT_LIST
227 /* Lists to keep libraries to be scanned for global constructors/destructors. */
228 static struct head libs
; /* list of libraries */
229 static struct path_prefix cmdline_lib_dirs
; /* directories specified with -L */
230 static struct path_prefix libpath_lib_dirs
; /* directories in LIBPATH */
231 static struct path_prefix
*libpaths
[3] = {&cmdline_lib_dirs
,
232 &libpath_lib_dirs
, NULL
};
235 static void handler (int);
236 static int is_ctor_dtor (const char *);
237 static char *find_a_file (struct path_prefix
*, const char *);
238 static void add_prefix (struct path_prefix
*, const char *);
239 static void prefix_from_env (const char *, struct path_prefix
*);
240 static void prefix_from_string (const char *, struct path_prefix
*);
241 static void do_wait (const char *, struct pex_obj
*);
242 static void fork_execute (const char *, char **);
243 static void maybe_unlink (const char *);
244 static void add_to_list (struct head
*, const char *);
245 static int extract_init_priority (const char *);
246 static void sort_ids (struct head
*);
247 static void write_list (FILE *, const char *, struct id
*);
248 #ifdef COLLECT_EXPORT_LIST
249 static void dump_list (FILE *, const char *, struct id
*);
252 static void dump_prefix_list (FILE *, const char *, struct prefix_list
*);
254 static void write_list_with_asm (FILE *, const char *, struct id
*);
255 static void write_c_file (FILE *, const char *);
256 static void write_c_file_stat (FILE *, const char *);
257 #ifndef LD_INIT_SWITCH
258 static void write_c_file_glob (FILE *, const char *);
260 static void scan_prog_file (const char *, enum pass
);
261 #ifdef SCAN_LIBRARIES
262 static void scan_libraries (const char *);
264 #if LINK_ELIMINATE_DUPLICATE_LDIRECTORIES
265 static int is_in_args (const char *, const char **, const char **);
267 #ifdef COLLECT_EXPORT_LIST
269 static int is_in_list (const char *, struct id
*);
271 static void write_aix_file (FILE *, struct id
*);
272 static char *resolve_lib_name (const char *);
274 static char *extract_string (const char **);
276 /* Delete tempfiles and exit function. */
279 collect_exit (int status
)
281 if (c_file
!= 0 && c_file
[0])
282 maybe_unlink (c_file
);
284 if (o_file
!= 0 && o_file
[0])
285 maybe_unlink (o_file
);
287 #ifdef COLLECT_EXPORT_LIST
288 if (export_file
!= 0 && export_file
[0])
289 maybe_unlink (export_file
);
292 if (ldout
!= 0 && ldout
[0])
294 dump_file (ldout
, stdout
);
295 maybe_unlink (ldout
);
298 if (lderrout
!= 0 && lderrout
[0])
300 dump_file (lderrout
, stderr
);
301 maybe_unlink (lderrout
);
304 if (status
!= 0 && output_file
!= 0 && output_file
[0])
305 maybe_unlink (output_file
);
308 maybe_unlink (response_file
);
314 /* Notify user of a non-error. */
316 notice (const char *cmsgid
, ...)
320 va_start (ap
, cmsgid
);
321 vfprintf (stderr
, _(cmsgid
), ap
);
325 /* Die when sys call fails. */
328 fatal_perror (const char * cmsgid
, ...)
333 va_start (ap
, cmsgid
);
334 fprintf (stderr
, "collect2: ");
335 vfprintf (stderr
, _(cmsgid
), ap
);
336 fprintf (stderr
, ": %s\n", xstrerror (e
));
339 collect_exit (FATAL_EXIT_CODE
);
345 fatal (const char * cmsgid
, ...)
349 va_start (ap
, cmsgid
);
350 fprintf (stderr
, "collect2: ");
351 vfprintf (stderr
, _(cmsgid
), ap
);
352 fprintf (stderr
, "\n");
355 collect_exit (FATAL_EXIT_CODE
);
358 /* Write error message. */
361 error (const char * gmsgid
, ...)
365 va_start (ap
, gmsgid
);
366 fprintf (stderr
, "collect2: ");
367 vfprintf (stderr
, _(gmsgid
), ap
);
368 fprintf (stderr
, "\n");
372 /* In case obstack is linked in, and abort is defined to fancy_abort,
373 provide a default entry. */
376 fancy_abort (const char *file
, int line
, const char *func
)
378 fatal ("internal gcc abort in %s, at %s:%d", func
, file
, line
);
384 if (c_file
!= 0 && c_file
[0])
385 maybe_unlink (c_file
);
387 if (o_file
!= 0 && o_file
[0])
388 maybe_unlink (o_file
);
390 if (ldout
!= 0 && ldout
[0])
391 maybe_unlink (ldout
);
393 if (lderrout
!= 0 && lderrout
[0])
394 maybe_unlink (lderrout
);
396 #ifdef COLLECT_EXPORT_LIST
397 if (export_file
!= 0 && export_file
[0])
398 maybe_unlink (export_file
);
402 maybe_unlink (response_file
);
404 signal (signo
, SIG_DFL
);
410 file_exists (const char *name
)
412 return access (name
, R_OK
) == 0;
415 /* Parse a reasonable subset of shell quoting syntax. */
418 extract_string (const char **pp
)
431 obstack_1grow (&temporary_obstack
, c
);
432 else if (! inside
&& c
== ' ')
434 else if (! inside
&& c
== '\\')
439 obstack_1grow (&temporary_obstack
, c
);
442 obstack_1grow (&temporary_obstack
, '\0');
444 return XOBFINISH (&temporary_obstack
, char *);
448 dump_file (const char *name
, FILE *to
)
450 FILE *stream
= fopen (name
, "r");
457 while (c
= getc (stream
),
458 c
!= EOF
&& (ISIDNUM (c
) || c
== '$' || c
== '.'))
459 obstack_1grow (&temporary_obstack
, c
);
460 if (obstack_object_size (&temporary_obstack
) > 0)
462 const char *word
, *p
;
464 obstack_1grow (&temporary_obstack
, '\0');
465 word
= XOBFINISH (&temporary_obstack
, const char *);
468 ++word
, putc ('.', to
);
470 if (!strncmp (p
, USER_LABEL_PREFIX
, strlen (USER_LABEL_PREFIX
)))
471 p
+= strlen (USER_LABEL_PREFIX
);
473 #ifdef HAVE_LD_DEMANGLE
479 result
= cplus_demangle (p
, DMGL_PARAMS
| DMGL_ANSI
| DMGL_VERBOSE
);
487 diff
= strlen (word
) - strlen (result
);
488 while (diff
> 0 && c
== ' ')
489 --diff
, putc (' ', to
);
490 if (diff
< 0 && c
== ' ')
492 while (diff
< 0 && c
== ' ')
493 ++diff
, c
= getc (stream
);
496 /* Make sure we output at least one space, or
497 the demangled symbol name will run into
498 whatever text follows. */
509 obstack_free (&temporary_obstack
, temporary_firstobj
);
518 /* Decide whether the given symbol is: a constructor (1), a destructor
519 (2), a routine in a shared object that calls all the constructors
520 (3) or destructors (4), a DWARF exception-handling table (5), or
521 nothing special (0). */
524 is_ctor_dtor (const char *s
)
526 struct names
{ const char *const name
; const int len
; const int ret
;
527 const int two_underscores
; };
529 const struct names
*p
;
531 const char *orig_s
= s
;
533 static const struct names special
[] = {
534 #ifndef NO_DOLLAR_IN_LABEL
535 { "GLOBAL__I$", sizeof ("GLOBAL__I$")-1, 1, 0 },
536 { "GLOBAL__D$", sizeof ("GLOBAL__D$")-1, 2, 0 },
538 #ifndef NO_DOT_IN_LABEL
539 { "GLOBAL__I.", sizeof ("GLOBAL__I.")-1, 1, 0 },
540 { "GLOBAL__D.", sizeof ("GLOBAL__D.")-1, 2, 0 },
541 #endif /* NO_DOT_IN_LABEL */
542 #endif /* NO_DOLLAR_IN_LABEL */
543 { "GLOBAL__I_", sizeof ("GLOBAL__I_")-1, 1, 0 },
544 { "GLOBAL__D_", sizeof ("GLOBAL__D_")-1, 2, 0 },
545 { "GLOBAL__F_", sizeof ("GLOBAL__F_")-1, 5, 0 },
546 { "GLOBAL__FI_", sizeof ("GLOBAL__FI_")-1, 3, 0 },
547 { "GLOBAL__FD_", sizeof ("GLOBAL__FD_")-1, 4, 0 },
551 while ((ch
= *s
) == '_')
557 for (p
= &special
[0]; p
->len
> 0; p
++)
560 && (!p
->two_underscores
|| ((s
- orig_s
) >= 2))
561 && strncmp(s
, p
->name
, p
->len
) == 0)
569 /* We maintain two prefix lists: one from COMPILER_PATH environment variable
570 and one from the PATH variable. */
572 static struct path_prefix cpath
, path
;
574 #ifdef CROSS_DIRECTORY_STRUCTURE
575 /* This is the name of the target machine. We use it to form the name
576 of the files to execute. */
578 static const char *const target_machine
= TARGET_MACHINE
;
581 /* Search for NAME using prefix list PPREFIX. We only look for executable
584 Return 0 if not found, otherwise return its name, allocated with malloc. */
587 find_a_file (struct path_prefix
*pprefix
, const char *name
)
590 struct prefix_list
*pl
;
591 int len
= pprefix
->max_len
+ strlen (name
) + 1;
594 fprintf (stderr
, "Looking for '%s'\n", name
);
596 #ifdef HOST_EXECUTABLE_SUFFIX
597 len
+= strlen (HOST_EXECUTABLE_SUFFIX
);
600 temp
= XNEWVEC (char, len
);
602 /* Determine the filename to execute (special case for absolute paths). */
605 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
606 || (*name
&& name
[1] == ':')
610 if (access (name
, X_OK
) == 0)
615 fprintf (stderr
, " - found: absolute path\n");
620 #ifdef HOST_EXECUTABLE_SUFFIX
621 /* Some systems have a suffix for executable files.
622 So try appending that. */
624 strcat (temp
, HOST_EXECUTABLE_SUFFIX
);
626 if (access (temp
, X_OK
) == 0)
631 fprintf (stderr
, " - failed to locate using absolute path\n");
634 for (pl
= pprefix
->plist
; pl
; pl
= pl
->next
)
638 strcpy (temp
, pl
->prefix
);
641 if (stat (temp
, &st
) >= 0
642 && ! S_ISDIR (st
.st_mode
)
643 && access (temp
, X_OK
) == 0)
646 #ifdef HOST_EXECUTABLE_SUFFIX
647 /* Some systems have a suffix for executable files.
648 So try appending that. */
649 strcat (temp
, HOST_EXECUTABLE_SUFFIX
);
651 if (stat (temp
, &st
) >= 0
652 && ! S_ISDIR (st
.st_mode
)
653 && access (temp
, X_OK
) == 0)
658 if (debug
&& pprefix
->plist
== NULL
)
659 fprintf (stderr
, " - failed: no entries in prefix list\n");
665 /* Add an entry for PREFIX to prefix list PPREFIX. */
668 add_prefix (struct path_prefix
*pprefix
, const char *prefix
)
670 struct prefix_list
*pl
, **prev
;
675 for (pl
= pprefix
->plist
; pl
->next
; pl
= pl
->next
)
680 prev
= &pprefix
->plist
;
682 /* Keep track of the longest prefix. */
684 len
= strlen (prefix
);
685 if (len
> pprefix
->max_len
)
686 pprefix
->max_len
= len
;
688 pl
= XNEW (struct prefix_list
);
689 pl
->prefix
= xstrdup (prefix
);
694 pl
->next
= (struct prefix_list
*) 0;
698 /* Take the value of the environment variable ENV, break it into a path, and
699 add of the entries to PPREFIX. */
702 prefix_from_env (const char *env
, struct path_prefix
*pprefix
)
705 GET_ENVIRONMENT (p
, env
);
708 prefix_from_string (p
, pprefix
);
712 prefix_from_string (const char *p
, struct path_prefix
*pprefix
)
714 const char *startp
, *endp
;
715 char *nstore
= XNEWVEC (char, strlen (p
) + 3);
718 fprintf (stderr
, "Convert string '%s' into prefixes, separator = '%c'\n", p
, PATH_SEPARATOR
);
723 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
725 strncpy (nstore
, startp
, endp
-startp
);
728 strcpy (nstore
, "./");
730 else if (! IS_DIR_SEPARATOR (endp
[-1]))
732 nstore
[endp
-startp
] = DIR_SEPARATOR
;
733 nstore
[endp
-startp
+1] = 0;
736 nstore
[endp
-startp
] = 0;
739 fprintf (stderr
, " - add prefix: %s\n", nstore
);
741 add_prefix (pprefix
, nstore
);
744 endp
= startp
= endp
+ 1;
755 main (int argc
, char **argv
)
757 static const char *const ld_suffix
= "ld";
758 static const char *const real_ld_suffix
= "real-ld";
759 static const char *const collect_ld_suffix
= "collect-ld";
760 static const char *const nm_suffix
= "nm";
761 static const char *const gnm_suffix
= "gnm";
763 static const char *const ldd_suffix
= LDD_SUFFIX
;
765 static const char *const strip_suffix
= "strip";
766 static const char *const gstrip_suffix
= "gstrip";
768 #ifdef CROSS_DIRECTORY_STRUCTURE
769 /* If we look for a program in the compiler directories, we just use
770 the short name, since these directories are already system-specific.
771 But it we look for a program in the system directories, we need to
772 qualify the program name with the target machine. */
774 const char *const full_ld_suffix
=
775 concat(target_machine
, "-", ld_suffix
, NULL
);
776 const char *const full_nm_suffix
=
777 concat (target_machine
, "-", nm_suffix
, NULL
);
778 const char *const full_gnm_suffix
=
779 concat (target_machine
, "-", gnm_suffix
, NULL
);
781 const char *const full_ldd_suffix
=
782 concat (target_machine
, "-", ldd_suffix
, NULL
);
784 const char *const full_strip_suffix
=
785 concat (target_machine
, "-", strip_suffix
, NULL
);
786 const char *const full_gstrip_suffix
=
787 concat (target_machine
, "-", gstrip_suffix
, NULL
);
789 const char *const full_ld_suffix
= ld_suffix
;
790 const char *const full_nm_suffix
= nm_suffix
;
791 const char *const full_gnm_suffix
= gnm_suffix
;
793 const char *const full_ldd_suffix
= ldd_suffix
;
795 const char *const full_strip_suffix
= strip_suffix
;
796 const char *const full_gstrip_suffix
= gstrip_suffix
;
797 #endif /* CROSS_DIRECTORY_STRUCTURE */
801 #ifdef COLLECT_EXPORT_LIST
804 const char *ld_file_name
;
819 expandargv (&argc
, &argv
);
820 if (argv
!= old_argv
)
821 at_file_supplied
= 1;
823 num_c_args
= argc
+ 9;
825 no_demangle
= !! getenv ("COLLECT_NO_DEMANGLE");
827 /* Suppress demangling by the real linker, which may be broken. */
828 putenv (xstrdup ("COLLECT_NO_DEMANGLE="));
830 #if defined (COLLECT2_HOST_INITIALIZATION)
831 /* Perform system dependent initialization, if necessary. */
832 COLLECT2_HOST_INITIALIZATION
;
836 /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
837 receive the signal. A different setting is inheritable */
838 signal (SIGCHLD
, SIG_DFL
);
841 /* Unlock the stdio streams. */
842 unlock_std_streams ();
846 /* Do not invoke xcalloc before this point, since locale needs to be
847 set first, in case a diagnostic is issued. */
849 ld1
= (const char **)(ld1_argv
= xcalloc(sizeof (char *), argc
+4));
850 ld2
= (const char **)(ld2_argv
= xcalloc(sizeof (char *), argc
+11));
851 object
= (const char **)(object_lst
= xcalloc(sizeof (char *), argc
));
857 /* Parse command line early for instances of -debug. This allows
858 the debug flag to be set before functions like find_a_file()
863 for (i
= 1; argv
[i
] != NULL
; i
++)
865 if (! strcmp (argv
[i
], "-debug"))
871 #ifndef DEFAULT_A_OUT_NAME
872 output_file
= "a.out";
874 output_file
= DEFAULT_A_OUT_NAME
;
877 obstack_begin (&temporary_obstack
, 0);
878 temporary_firstobj
= obstack_alloc (&temporary_obstack
, 0);
880 #ifndef HAVE_LD_DEMANGLE
881 current_demangling_style
= auto_demangling
;
883 p
= getenv ("COLLECT_GCC_OPTIONS");
886 const char *q
= extract_string (&p
);
887 if (*q
== '-' && (q
[1] == 'm' || q
[1] == 'f'))
890 obstack_free (&temporary_obstack
, temporary_firstobj
);
892 /* -fno-profile-arcs -fno-test-coverage -fno-branch-probabilities
893 -fno-exceptions -w */
896 c_ptr
= (const char **) (c_argv
= xcalloc (sizeof (char *), num_c_args
));
899 fatal ("no arguments");
902 if (signal (SIGQUIT
, SIG_IGN
) != SIG_IGN
)
903 signal (SIGQUIT
, handler
);
905 if (signal (SIGINT
, SIG_IGN
) != SIG_IGN
)
906 signal (SIGINT
, handler
);
908 if (signal (SIGALRM
, SIG_IGN
) != SIG_IGN
)
909 signal (SIGALRM
, handler
);
912 if (signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
913 signal (SIGHUP
, handler
);
915 if (signal (SIGSEGV
, SIG_IGN
) != SIG_IGN
)
916 signal (SIGSEGV
, handler
);
918 if (signal (SIGBUS
, SIG_IGN
) != SIG_IGN
)
919 signal (SIGBUS
, handler
);
922 /* Extract COMPILER_PATH and PATH into our prefix list. */
923 prefix_from_env ("COMPILER_PATH", &cpath
);
924 prefix_from_env ("PATH", &path
);
926 /* Try to discover a valid linker/nm/strip to use. */
928 /* Maybe we know the right file to use (if not cross). */
930 #ifdef DEFAULT_LINKER
931 if (access (DEFAULT_LINKER
, X_OK
) == 0)
932 ld_file_name
= DEFAULT_LINKER
;
933 if (ld_file_name
== 0)
935 #ifdef REAL_LD_FILE_NAME
936 ld_file_name
= find_a_file (&path
, REAL_LD_FILE_NAME
);
937 if (ld_file_name
== 0)
939 /* Search the (target-specific) compiler dirs for ld'. */
940 ld_file_name
= find_a_file (&cpath
, real_ld_suffix
);
941 /* Likewise for `collect-ld'. */
942 if (ld_file_name
== 0)
943 ld_file_name
= find_a_file (&cpath
, collect_ld_suffix
);
944 /* Search the compiler directories for `ld'. We have protection against
945 recursive calls in find_a_file. */
946 if (ld_file_name
== 0)
947 ld_file_name
= find_a_file (&cpath
, ld_suffix
);
948 /* Search the ordinary system bin directories
949 for `ld' (if native linking) or `TARGET-ld' (if cross). */
950 if (ld_file_name
== 0)
951 ld_file_name
= find_a_file (&path
, full_ld_suffix
);
953 #ifdef REAL_NM_FILE_NAME
954 nm_file_name
= find_a_file (&path
, REAL_NM_FILE_NAME
);
955 if (nm_file_name
== 0)
957 nm_file_name
= find_a_file (&cpath
, gnm_suffix
);
958 if (nm_file_name
== 0)
959 nm_file_name
= find_a_file (&path
, full_gnm_suffix
);
960 if (nm_file_name
== 0)
961 nm_file_name
= find_a_file (&cpath
, nm_suffix
);
962 if (nm_file_name
== 0)
963 nm_file_name
= find_a_file (&path
, full_nm_suffix
);
966 ldd_file_name
= find_a_file (&cpath
, ldd_suffix
);
967 if (ldd_file_name
== 0)
968 ldd_file_name
= find_a_file (&path
, full_ldd_suffix
);
971 #ifdef REAL_STRIP_FILE_NAME
972 strip_file_name
= find_a_file (&path
, REAL_STRIP_FILE_NAME
);
973 if (strip_file_name
== 0)
975 strip_file_name
= find_a_file (&cpath
, gstrip_suffix
);
976 if (strip_file_name
== 0)
977 strip_file_name
= find_a_file (&path
, full_gstrip_suffix
);
978 if (strip_file_name
== 0)
979 strip_file_name
= find_a_file (&cpath
, strip_suffix
);
980 if (strip_file_name
== 0)
981 strip_file_name
= find_a_file (&path
, full_strip_suffix
);
983 /* Determine the full path name of the C compiler to use. */
984 c_file_name
= getenv ("COLLECT_GCC");
985 if (c_file_name
== 0)
987 #ifdef CROSS_DIRECTORY_STRUCTURE
988 c_file_name
= concat (target_machine
, "-gcc", NULL
);
994 p
= find_a_file (&cpath
, c_file_name
);
996 /* Here it should be safe to use the system search path since we should have
997 already qualified the name of the compiler when it is needed. */
999 p
= find_a_file (&path
, c_file_name
);
1004 *ld1
++ = *ld2
++ = ld_file_name
;
1006 /* Make temp file names. */
1007 c_file
= make_temp_file (".c");
1008 o_file
= make_temp_file (".o");
1009 #ifdef COLLECT_EXPORT_LIST
1010 export_file
= make_temp_file (".x");
1012 ldout
= make_temp_file (".ld");
1013 lderrout
= make_temp_file (".le");
1014 *c_ptr
++ = c_file_name
;
1021 #ifdef COLLECT_EXPORT_LIST
1022 /* Generate a list of directories from LIBPATH. */
1023 prefix_from_env ("LIBPATH", &libpath_lib_dirs
);
1024 /* Add to this list also two standard directories where
1025 AIX loader always searches for libraries. */
1026 add_prefix (&libpath_lib_dirs
, "/lib");
1027 add_prefix (&libpath_lib_dirs
, "/usr/lib");
1030 /* Get any options that the upper GCC wants to pass to the sub-GCC.
1032 AIX support needs to know if -shared has been specified before
1033 parsing commandline arguments. */
1035 p
= getenv ("COLLECT_GCC_OPTIONS");
1038 const char *q
= extract_string (&p
);
1039 if (*q
== '-' && (q
[1] == 'm' || q
[1] == 'f'))
1040 *c_ptr
++ = xstrdup (q
);
1041 if (strcmp (q
, "-EL") == 0 || strcmp (q
, "-EB") == 0)
1042 *c_ptr
++ = xstrdup (q
);
1043 if (strcmp (q
, "-shared") == 0)
1045 if (*q
== '-' && q
[1] == 'B')
1047 *c_ptr
++ = xstrdup (q
);
1050 q
= extract_string (&p
);
1051 *c_ptr
++ = xstrdup (q
);
1055 obstack_free (&temporary_obstack
, temporary_firstobj
);
1056 *c_ptr
++ = "-fno-profile-arcs";
1057 *c_ptr
++ = "-fno-test-coverage";
1058 *c_ptr
++ = "-fno-branch-probabilities";
1059 *c_ptr
++ = "-fno-exceptions";
1062 /* !!! When GCC calls collect2,
1063 it does not know whether it is calling collect2 or ld.
1064 So collect2 cannot meaningfully understand any options
1065 except those ld understands.
1066 If you propose to make GCC pass some other option,
1067 just imagine what will happen if ld is really ld!!! */
1069 /* Parse arguments. Remember output file spec, pass the rest to ld. */
1070 /* After the first file, put in the c++ rt0. */
1073 #ifdef HAVE_LD_DEMANGLE
1074 if (!demangle_flag
&& !no_demangle
)
1075 demangle_flag
= "--demangle";
1077 *ld1
++ = *ld2
++ = demangle_flag
;
1079 while ((arg
= *++argv
) != (char *) 0)
1081 *ld1
++ = *ld2
++ = arg
;
1087 #ifdef COLLECT_EXPORT_LIST
1088 /* We want to disable automatic exports on AIX when user
1089 explicitly puts an export list in command line */
1091 if (arg
[2] == 'E' || strncmp (&arg
[2], "export", 6) == 0)
1093 else if (arg
[2] == '6' && arg
[3] == '4')
1095 else if (arg
[2] == 'r' && arg
[3] == 't' && arg
[4] == 'l')
1101 if (!strcmp (arg
, "-debug"))
1103 /* Already parsed. */
1107 if (!strcmp (arg
, "-dynamic-linker") && argv
[1])
1110 *ld1
++ = *ld2
++ = *argv
;
1117 /* place o_file BEFORE this argument! */
1123 #ifdef COLLECT_EXPORT_LIST
1125 /* Resolving full library name. */
1126 const char *s
= resolve_lib_name (arg
+2);
1128 /* Saving a full library name. */
1129 add_to_list (&libs
, s
);
1134 #ifdef COLLECT_EXPORT_LIST
1135 /* Saving directories where to search for libraries. */
1137 add_prefix (&cmdline_lib_dirs
, arg
+2);
1140 #if LINK_ELIMINATE_DUPLICATE_LDIRECTORIES
1142 if (is_in_args (arg
, (const char **) ld1_argv
, ld1
-1))
1145 #endif /* LINK_ELIMINATE_DUPLICATE_LDIRECTORIES */
1150 output_file
= *ld1
++ = *ld2
++ = *++argv
;
1152 #ifdef SWITCHES_NEED_SPACES
1153 && ! strchr (SWITCHES_NEED_SPACES
, arg
[1])
1157 output_file
= &arg
[2];
1166 if (arg
[2] == '\0' && do_collecting
)
1168 /* We must strip after the nm run, otherwise C++ linking
1169 will not work. Thus we strip in the second ld run, or
1170 else with strip if there is no second ld run. */
1182 if (strcmp (arg
, "--no-demangle") == 0)
1184 demangle_flag
= arg
;
1189 else if (strncmp (arg
, "--demangle", 10) == 0)
1191 demangle_flag
= arg
;
1193 #ifndef HAVE_LD_DEMANGLE
1196 enum demangling_styles style
1197 = cplus_demangle_name_to_style (arg
+11);
1198 if (style
== unknown_demangling
)
1199 error ("unknown demangling style '%s'", arg
+11);
1201 current_demangling_style
= style
;
1210 else if ((p
= strrchr (arg
, '.')) != (char *) 0
1211 && (strcmp (p
, ".o") == 0 || strcmp (p
, ".a") == 0
1212 || strcmp (p
, ".so") == 0 || strcmp (p
, ".lo") == 0
1213 || strcmp (p
, ".obj") == 0))
1222 /* place o_file BEFORE this argument! */
1228 if (p
[1] == 'o' || p
[1] == 'l')
1230 #ifdef COLLECT_EXPORT_LIST
1231 /* libraries can be specified directly, i.e. without -l flag. */
1234 /* Saving a full library name. */
1235 add_to_list (&libs
, arg
);
1241 #ifdef COLLECT_EXPORT_LIST
1242 /* This is added only for debugging purposes. */
1245 fprintf (stderr
, "List of libraries:\n");
1246 dump_list (stderr
, "\t", libs
.first
);
1249 /* The AIX linker will discard static constructors in object files if
1250 nothing else in the file is referenced, so look at them first. */
1252 const char **export_object_lst
= (const char **)object_lst
;
1254 while (export_object_lst
< object
)
1255 scan_prog_file (*export_object_lst
++, PASS_OBJ
);
1258 struct id
*list
= libs
.first
;
1260 for (; list
; list
= list
->next
)
1261 scan_prog_file (list
->name
, PASS_FIRST
);
1266 char *buf
= concat ("-bE:", export_file
, NULL
);
1271 exportf
= fopen (export_file
, "w");
1272 if (exportf
== (FILE *) 0)
1273 fatal_perror ("fopen %s", export_file
);
1274 write_aix_file (exportf
, exports
.first
);
1275 if (fclose (exportf
))
1276 fatal_perror ("fclose %s", export_file
);
1281 *c_ptr
= *ld1
= *object
= (char *) 0;
1285 notice ("collect2 version %s", version_string
);
1286 #ifdef TARGET_VERSION
1289 fprintf (stderr
, "\n");
1295 fprintf (stderr
, "ld_file_name = %s\n",
1296 (ld_file_name
? ld_file_name
: "not found"));
1297 fprintf (stderr
, "c_file_name = %s\n",
1298 (c_file_name
? c_file_name
: "not found"));
1299 fprintf (stderr
, "nm_file_name = %s\n",
1300 (nm_file_name
? nm_file_name
: "not found"));
1302 fprintf (stderr
, "ldd_file_name = %s\n",
1303 (ldd_file_name
? ldd_file_name
: "not found"));
1305 fprintf (stderr
, "strip_file_name = %s\n",
1306 (strip_file_name
? strip_file_name
: "not found"));
1307 fprintf (stderr
, "c_file = %s\n",
1308 (c_file
? c_file
: "not found"));
1309 fprintf (stderr
, "o_file = %s\n",
1310 (o_file
? o_file
: "not found"));
1312 ptr
= getenv ("COLLECT_GCC_OPTIONS");
1314 fprintf (stderr
, "COLLECT_GCC_OPTIONS = %s\n", ptr
);
1316 ptr
= getenv ("COLLECT_GCC");
1318 fprintf (stderr
, "COLLECT_GCC = %s\n", ptr
);
1320 ptr
= getenv ("COMPILER_PATH");
1322 fprintf (stderr
, "COMPILER_PATH = %s\n", ptr
);
1324 ptr
= getenv (LIBRARY_PATH_ENV
);
1326 fprintf (stderr
, "%-20s= %s\n", LIBRARY_PATH_ENV
, ptr
);
1328 fprintf (stderr
, "\n");
1331 /* Load the program, searching all libraries and attempting to provide
1332 undefined symbols from repository information. */
1334 /* On AIX we do this later. */
1335 #ifndef COLLECT_EXPORT_LIST
1336 do_tlink (ld1_argv
, object_lst
);
1339 /* If -r or they will be run via some other method, do not build the
1340 constructor or destructor list, just return now. */
1342 #ifndef COLLECT_EXPORT_LIST
1347 #ifdef COLLECT_EXPORT_LIST
1348 /* Do the link we avoided above if we are exiting. */
1349 do_tlink (ld1_argv
, object_lst
);
1351 /* But make sure we delete the export file we may have created. */
1352 if (export_file
!= 0 && export_file
[0])
1353 maybe_unlink (export_file
);
1355 maybe_unlink (c_file
);
1356 maybe_unlink (o_file
);
1360 /* Examine the namelist with nm and search it for static constructors
1361 and destructors to call.
1362 Write the constructor and destructor tables to a .s file and reload. */
1364 /* On AIX we already scanned for global constructors/destructors. */
1365 #ifndef COLLECT_EXPORT_LIST
1366 scan_prog_file (output_file
, PASS_FIRST
);
1369 #ifdef SCAN_LIBRARIES
1370 scan_libraries (output_file
);
1375 notice ("%d constructor(s) found\n", constructors
.number
);
1376 notice ("%d destructor(s) found\n", destructors
.number
);
1377 notice ("%d frame table(s) found\n", frame_tables
.number
);
1380 if (constructors
.number
== 0 && destructors
.number
== 0
1381 && frame_tables
.number
== 0
1382 #if defined (SCAN_LIBRARIES) || defined (COLLECT_EXPORT_LIST)
1383 /* If we will be running these functions ourselves, we want to emit
1384 stubs into the shared library so that we do not have to relink
1385 dependent programs when we add static objects. */
1390 #ifdef COLLECT_EXPORT_LIST
1391 /* Do tlink without additional code generation. */
1392 do_tlink (ld1_argv
, object_lst
);
1394 /* Strip now if it was requested on the command line. */
1397 char **real_strip_argv
= XCNEWVEC (char *, 3);
1398 const char ** strip_argv
= (const char **) real_strip_argv
;
1400 strip_argv
[0] = strip_file_name
;
1401 strip_argv
[1] = output_file
;
1402 strip_argv
[2] = (char *) 0;
1403 fork_execute ("strip", real_strip_argv
);
1406 #ifdef COLLECT_EXPORT_LIST
1407 maybe_unlink (export_file
);
1409 maybe_unlink (c_file
);
1410 maybe_unlink (o_file
);
1414 /* Sort ctor and dtor lists by priority. */
1415 sort_ids (&constructors
);
1416 sort_ids (&destructors
);
1418 maybe_unlink(output_file
);
1419 outf
= fopen (c_file
, "w");
1420 if (outf
== (FILE *) 0)
1421 fatal_perror ("fopen %s", c_file
);
1423 write_c_file (outf
, c_file
);
1426 fatal_perror ("fclose %s", c_file
);
1428 /* Tell the linker that we have initializer and finalizer functions. */
1429 #ifdef LD_INIT_SWITCH
1430 #ifdef COLLECT_EXPORT_LIST
1431 *ld2
++ = concat (LD_INIT_SWITCH
, ":", initname
, ":", fininame
, NULL
);
1433 *ld2
++ = LD_INIT_SWITCH
;
1435 *ld2
++ = LD_FINI_SWITCH
;
1440 #ifdef COLLECT_EXPORT_LIST
1443 /* If we did not add export flag to link arguments before, add it to
1444 second link phase now. No new exports should have been added. */
1445 if (! exports
.first
)
1446 *ld2
++ = concat ("-bE:", export_file
, NULL
);
1448 #ifndef LD_INIT_SWITCH
1449 add_to_list (&exports
, initname
);
1450 add_to_list (&exports
, fininame
);
1451 add_to_list (&exports
, "_GLOBAL__DI");
1452 add_to_list (&exports
, "_GLOBAL__DD");
1454 exportf
= fopen (export_file
, "w");
1455 if (exportf
== (FILE *) 0)
1456 fatal_perror ("fopen %s", export_file
);
1457 write_aix_file (exportf
, exports
.first
);
1458 if (fclose (exportf
))
1459 fatal_perror ("fclose %s", export_file
);
1463 /* End of arguments to second link phase. */
1468 fprintf (stderr
, "\n========== output_file = %s, c_file = %s\n",
1469 output_file
, c_file
);
1470 write_c_file (stderr
, "stderr");
1471 fprintf (stderr
, "========== end of c_file\n\n");
1472 #ifdef COLLECT_EXPORT_LIST
1473 fprintf (stderr
, "\n========== export_file = %s\n", export_file
);
1474 write_aix_file (stderr
, exports
.first
);
1475 fprintf (stderr
, "========== end of export_file\n\n");
1479 /* Assemble the constructor and destructor tables.
1480 Link the tables in with the rest of the program. */
1482 fork_execute ("gcc", c_argv
);
1483 #ifdef COLLECT_EXPORT_LIST
1484 /* On AIX we must call tlink because of possible templates resolution. */
1485 do_tlink (ld2_argv
, object_lst
);
1487 /* Otherwise, simply call ld because tlink is already done. */
1488 fork_execute ("ld", ld2_argv
);
1490 /* Let scan_prog_file do any final mods (OSF/rose needs this for
1491 constructors/destructors in shared libraries. */
1492 scan_prog_file (output_file
, PASS_SECOND
);
1495 maybe_unlink (c_file
);
1496 maybe_unlink (o_file
);
1498 #ifdef COLLECT_EXPORT_LIST
1499 maybe_unlink (export_file
);
1506 /* Wait for a process to finish, and exit if a nonzero status is found. */
1509 collect_wait (const char *prog
, struct pex_obj
*pex
)
1513 if (!pex_get_status (pex
, 1, &status
))
1514 fatal_perror ("can't get program status");
1519 if (WIFSIGNALED (status
))
1521 int sig
= WTERMSIG (status
);
1522 error ("%s terminated with signal %d [%s]%s",
1523 prog
, sig
, strsignal(sig
),
1524 WCOREDUMP(status
) ? ", core dumped" : "");
1525 collect_exit (FATAL_EXIT_CODE
);
1528 if (WIFEXITED (status
))
1529 return WEXITSTATUS (status
);
1535 do_wait (const char *prog
, struct pex_obj
*pex
)
1537 int ret
= collect_wait (prog
, pex
);
1540 error ("%s returned %d exit status", prog
, ret
);
1546 unlink (response_file
);
1547 response_file
= NULL
;
1552 /* Execute a program, and wait for the reply. */
1555 collect_execute (const char *prog
, char **argv
, const char *outname
,
1556 const char *errname
)
1558 struct pex_obj
*pex
;
1561 char *response_arg
= NULL
;
1562 char *response_argv
[3] ATTRIBUTE_UNUSED
;
1564 if (HAVE_GNU_LD
&& at_file_supplied
&& argv
[0] != NULL
)
1566 /* If using @file arguments, create a temporary file and put the
1567 contents of argv into it. Then change argv to an array corresponding
1568 to a single argument @FILE, where FILE is the temporary filename. */
1570 char **current_argv
= argv
+ 1;
1571 char *argv0
= argv
[0];
1575 /* Note: we assume argv contains at least one element; this is
1578 response_file
= make_temp_file ("");
1580 f
= fopen (response_file
, "w");
1583 fatal ("could not open response file %s", response_file
);
1585 status
= writeargv (current_argv
, f
);
1588 fatal ("could not write to response file %s", response_file
);
1590 status
= fclose (f
);
1593 fatal ("could not close response file %s", response_file
);
1595 response_arg
= concat ("@", response_file
, NULL
);
1596 response_argv
[0] = argv0
;
1597 response_argv
[1] = response_arg
;
1598 response_argv
[2] = NULL
;
1600 argv
= response_argv
;
1609 fprintf (stderr
, "%s", argv
[0]);
1611 notice ("[cannot find %s]", prog
);
1613 for (p_argv
= &argv
[1]; (str
= *p_argv
) != (char *) 0; p_argv
++)
1614 fprintf (stderr
, " %s", str
);
1616 fprintf (stderr
, "\n");
1622 /* If we cannot find a program we need, complain error. Do this here
1623 since we might not end up needing something that we could not find. */
1626 fatal ("cannot find '%s'", prog
);
1628 pex
= pex_init (0, "collect2", NULL
);
1630 fatal_perror ("pex_init failed");
1632 errmsg
= pex_run (pex
, PEX_LAST
| PEX_SEARCH
, argv
[0], argv
, outname
,
1639 fatal_perror (errmsg
);
1646 free (response_arg
);
1652 fork_execute (const char *prog
, char **argv
)
1654 struct pex_obj
*pex
;
1656 pex
= collect_execute (prog
, argv
, NULL
, NULL
);
1657 do_wait (prog
, pex
);
1660 /* Unlink a file unless we are debugging. */
1663 maybe_unlink (const char *file
)
1666 unlink_if_ordinary (file
);
1668 notice ("[Leaving %s]\n", file
);
1672 static long sequence_number
= 0;
1674 /* Add a name to a linked list. */
1677 add_to_list (struct head
*head_ptr
, const char *name
)
1679 struct id
*newid
= xcalloc (sizeof (struct id
) + strlen (name
), 1);
1681 strcpy (newid
->name
, name
);
1683 if (head_ptr
->first
)
1684 head_ptr
->last
->next
= newid
;
1686 head_ptr
->first
= newid
;
1688 /* Check for duplicate symbols. */
1689 for (p
= head_ptr
->first
;
1690 strcmp (name
, p
->name
) != 0;
1695 head_ptr
->last
->next
= 0;
1700 newid
->sequence
= ++sequence_number
;
1701 head_ptr
->last
= newid
;
1705 /* Grab the init priority number from an init function name that
1706 looks like "_GLOBAL_.I.12345.foo". */
1709 extract_init_priority (const char *name
)
1713 while (name
[pos
] == '_')
1715 pos
+= 10; /* strlen ("GLOBAL__X_") */
1717 /* Extract init_p number from ctor/dtor name. */
1718 pri
= atoi (name
+ pos
);
1719 return pri
? pri
: DEFAULT_INIT_PRIORITY
;
1722 /* Insertion sort the ids from ctor/dtor list HEAD_PTR in descending order.
1723 ctors will be run from right to left, dtors from left to right. */
1726 sort_ids (struct head
*head_ptr
)
1728 /* id holds the current element to insert. id_next holds the next
1729 element to insert. id_ptr iterates through the already sorted elements
1730 looking for the place to insert id. */
1731 struct id
*id
, *id_next
, **id_ptr
;
1733 id
= head_ptr
->first
;
1735 /* We don't have any sorted elements yet. */
1736 head_ptr
->first
= NULL
;
1738 for (; id
; id
= id_next
)
1741 id
->sequence
= extract_init_priority (id
->name
);
1743 for (id_ptr
= &(head_ptr
->first
); ; id_ptr
= &((*id_ptr
)->next
))
1745 /* If the sequence numbers are the same, we put the id from the
1746 file later on the command line later in the list. */
1747 || id
->sequence
> (*id_ptr
)->sequence
1748 /* Hack: do lexical compare, too.
1749 || (id->sequence == (*id_ptr)->sequence
1750 && strcmp (id->name, (*id_ptr)->name) > 0) */
1759 /* Now set the sequence numbers properly so write_c_file works. */
1760 for (id
= head_ptr
->first
; id
; id
= id
->next
)
1761 id
->sequence
= ++sequence_number
;
1764 /* Write: `prefix', the names on list LIST, `suffix'. */
1767 write_list (FILE *stream
, const char *prefix
, struct id
*list
)
1771 fprintf (stream
, "%sx%d,\n", prefix
, list
->sequence
);
1776 #if LINK_ELIMINATE_DUPLICATE_LDIRECTORIES
1777 /* Given a STRING, return nonzero if it occurs in the list in range
1778 [ARGS_BEGIN,ARGS_END). */
1781 is_in_args (const char *string
, const char **args_begin
,
1782 const char **args_end
)
1784 const char **args_pointer
;
1785 for (args_pointer
= args_begin
; args_pointer
!= args_end
; ++args_pointer
)
1786 if (strcmp (string
, *args_pointer
) == 0)
1790 #endif /* LINK_ELIMINATE_DUPLICATE_LDIRECTORIES */
1792 #ifdef COLLECT_EXPORT_LIST
1793 /* This function is really used only on AIX, but may be useful. */
1796 is_in_list (const char *prefix
, struct id
*list
)
1800 if (!strcmp (prefix
, list
->name
)) return 1;
1806 #endif /* COLLECT_EXPORT_LIST */
1808 /* Added for debugging purpose. */
1809 #ifdef COLLECT_EXPORT_LIST
1811 dump_list (FILE *stream
, const char *prefix
, struct id
*list
)
1815 fprintf (stream
, "%s%s,\n", prefix
, list
->name
);
1823 dump_prefix_list (FILE *stream
, const char *prefix
, struct prefix_list
*list
)
1827 fprintf (stream
, "%s%s,\n", prefix
, list
->prefix
);
1834 write_list_with_asm (FILE *stream
, const char *prefix
, struct id
*list
)
1838 fprintf (stream
, "%sx%d __asm__ (\"%s\");\n",
1839 prefix
, list
->sequence
, list
->name
);
1844 /* Write out the constructor and destructor tables statically (for a shared
1845 object), along with the functions to execute them. */
1848 write_c_file_stat (FILE *stream
, const char *name ATTRIBUTE_UNUSED
)
1852 int frames
= (frame_tables
.number
> 0);
1854 /* Figure out name of output_file, stripping off .so version. */
1855 p
= strrchr (output_file
, '/');
1871 if (strncmp (q
, ".so", 3) == 0)
1880 /* q points to null at end of the string (or . of the .so version) */
1881 prefix
= XNEWVEC (char, q
- p
+ 1);
1882 strncpy (prefix
, p
, q
- p
);
1884 for (r
= prefix
; *r
; r
++)
1885 if (!ISALNUM ((unsigned char)*r
))
1888 notice ("\nwrite_c_file - output name is %s, prefix is %s\n",
1889 output_file
, prefix
);
1891 initname
= concat ("_GLOBAL__FI_", prefix
, NULL
);
1892 fininame
= concat ("_GLOBAL__FD_", prefix
, NULL
);
1896 /* Write the tables as C code. */
1898 fprintf (stream
, "static int count;\n");
1899 fprintf (stream
, "typedef void entry_pt();\n");
1900 write_list_with_asm (stream
, "extern entry_pt ", constructors
.first
);
1904 write_list_with_asm (stream
, "extern void *", frame_tables
.first
);
1906 fprintf (stream
, "\tstatic void *frame_table[] = {\n");
1907 write_list (stream
, "\t\t&", frame_tables
.first
);
1908 fprintf (stream
, "\t0\n};\n");
1910 /* This must match what's in frame.h. */
1911 fprintf (stream
, "struct object {\n");
1912 fprintf (stream
, " void *pc_begin;\n");
1913 fprintf (stream
, " void *pc_end;\n");
1914 fprintf (stream
, " void *fde_begin;\n");
1915 fprintf (stream
, " void *fde_array;\n");
1916 fprintf (stream
, " __SIZE_TYPE__ count;\n");
1917 fprintf (stream
, " struct object *next;\n");
1918 fprintf (stream
, "};\n");
1920 fprintf (stream
, "extern void __register_frame_info_table (void *, struct object *);\n");
1921 fprintf (stream
, "extern void *__deregister_frame_info (void *);\n");
1923 fprintf (stream
, "static void reg_frame () {\n");
1924 fprintf (stream
, "\tstatic struct object ob;\n");
1925 fprintf (stream
, "\t__register_frame_info_table (frame_table, &ob);\n");
1926 fprintf (stream
, "\t}\n");
1928 fprintf (stream
, "static void dereg_frame () {\n");
1929 fprintf (stream
, "\t__deregister_frame_info (frame_table);\n");
1930 fprintf (stream
, "\t}\n");
1933 fprintf (stream
, "void %s() {\n", initname
);
1934 if (constructors
.number
> 0 || frames
)
1936 fprintf (stream
, "\tstatic entry_pt *ctors[] = {\n");
1937 write_list (stream
, "\t\t", constructors
.first
);
1939 fprintf (stream
, "\treg_frame,\n");
1940 fprintf (stream
, "\t};\n");
1941 fprintf (stream
, "\tentry_pt **p;\n");
1942 fprintf (stream
, "\tif (count++ != 0) return;\n");
1943 fprintf (stream
, "\tp = ctors + %d;\n", constructors
.number
+ frames
);
1944 fprintf (stream
, "\twhile (p > ctors) (*--p)();\n");
1947 fprintf (stream
, "\t++count;\n");
1948 fprintf (stream
, "}\n");
1949 write_list_with_asm (stream
, "extern entry_pt ", destructors
.first
);
1950 fprintf (stream
, "void %s() {\n", fininame
);
1951 if (destructors
.number
> 0 || frames
)
1953 fprintf (stream
, "\tstatic entry_pt *dtors[] = {\n");
1954 write_list (stream
, "\t\t", destructors
.first
);
1956 fprintf (stream
, "\tdereg_frame,\n");
1957 fprintf (stream
, "\t};\n");
1958 fprintf (stream
, "\tentry_pt **p;\n");
1959 fprintf (stream
, "\tif (--count != 0) return;\n");
1960 fprintf (stream
, "\tp = dtors;\n");
1961 fprintf (stream
, "\twhile (p < dtors + %d) (*p++)();\n",
1962 destructors
.number
+ frames
);
1964 fprintf (stream
, "}\n");
1968 COLLECT_SHARED_INIT_FUNC(stream
, initname
);
1969 COLLECT_SHARED_FINI_FUNC(stream
, fininame
);
1973 /* Write the constructor/destructor tables. */
1975 #ifndef LD_INIT_SWITCH
1977 write_c_file_glob (FILE *stream
, const char *name ATTRIBUTE_UNUSED
)
1979 /* Write the tables as C code. */
1981 int frames
= (frame_tables
.number
> 0);
1983 fprintf (stream
, "typedef void entry_pt();\n\n");
1985 write_list_with_asm (stream
, "extern entry_pt ", constructors
.first
);
1989 write_list_with_asm (stream
, "extern void *", frame_tables
.first
);
1991 fprintf (stream
, "\tstatic void *frame_table[] = {\n");
1992 write_list (stream
, "\t\t&", frame_tables
.first
);
1993 fprintf (stream
, "\t0\n};\n");
1995 /* This must match what's in frame.h. */
1996 fprintf (stream
, "struct object {\n");
1997 fprintf (stream
, " void *pc_begin;\n");
1998 fprintf (stream
, " void *pc_end;\n");
1999 fprintf (stream
, " void *fde_begin;\n");
2000 fprintf (stream
, " void *fde_array;\n");
2001 fprintf (stream
, " __SIZE_TYPE__ count;\n");
2002 fprintf (stream
, " struct object *next;\n");
2003 fprintf (stream
, "};\n");
2005 fprintf (stream
, "extern void __register_frame_info_table (void *, struct object *);\n");
2006 fprintf (stream
, "extern void *__deregister_frame_info (void *);\n");
2008 fprintf (stream
, "static void reg_frame () {\n");
2009 fprintf (stream
, "\tstatic struct object ob;\n");
2010 fprintf (stream
, "\t__register_frame_info_table (frame_table, &ob);\n");
2011 fprintf (stream
, "\t}\n");
2013 fprintf (stream
, "static void dereg_frame () {\n");
2014 fprintf (stream
, "\t__deregister_frame_info (frame_table);\n");
2015 fprintf (stream
, "\t}\n");
2018 fprintf (stream
, "\nentry_pt * __CTOR_LIST__[] = {\n");
2019 fprintf (stream
, "\t(entry_pt *) %d,\n", constructors
.number
+ frames
);
2020 write_list (stream
, "\t", constructors
.first
);
2022 fprintf (stream
, "\treg_frame,\n");
2023 fprintf (stream
, "\t0\n};\n\n");
2025 write_list_with_asm (stream
, "extern entry_pt ", destructors
.first
);
2027 fprintf (stream
, "\nentry_pt * __DTOR_LIST__[] = {\n");
2028 fprintf (stream
, "\t(entry_pt *) %d,\n", destructors
.number
+ frames
);
2029 write_list (stream
, "\t", destructors
.first
);
2031 fprintf (stream
, "\tdereg_frame,\n");
2032 fprintf (stream
, "\t0\n};\n\n");
2034 fprintf (stream
, "extern entry_pt %s;\n", NAME__MAIN
);
2035 fprintf (stream
, "entry_pt *__main_reference = %s;\n\n", NAME__MAIN
);
2037 #endif /* ! LD_INIT_SWITCH */
2040 write_c_file (FILE *stream
, const char *name
)
2042 fprintf (stream
, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n");
2043 #ifndef LD_INIT_SWITCH
2045 write_c_file_glob (stream
, name
);
2048 write_c_file_stat (stream
, name
);
2049 fprintf (stream
, "#ifdef __cplusplus\n}\n#endif\n");
2052 #ifdef COLLECT_EXPORT_LIST
2054 write_aix_file (FILE *stream
, struct id
*list
)
2056 for (; list
; list
= list
->next
)
2058 fputs (list
->name
, stream
);
2059 putc ('\n', stream
);
2064 #ifdef OBJECT_FORMAT_NONE
2066 /* Generic version to scan the name list of the loaded program for
2067 the symbols g++ uses for static constructors and destructors.
2069 The constructor table begins at __CTOR_LIST__ and contains a count
2070 of the number of pointers (or -1 if the constructors are built in a
2071 separate section by the linker), followed by the pointers to the
2072 constructor functions, terminated with a null pointer. The
2073 destructor table has the same format, and begins at __DTOR_LIST__. */
2076 scan_prog_file (const char *prog_name
, enum pass which_pass
)
2078 void (*int_handler
) (int);
2080 void (*quit_handler
) (int);
2082 char *real_nm_argv
[4];
2083 const char **nm_argv
= (const char **) real_nm_argv
;
2085 struct pex_obj
*pex
;
2091 if (which_pass
== PASS_SECOND
)
2094 /* If we do not have an `nm', complain. */
2095 if (nm_file_name
== 0)
2096 fatal ("cannot find 'nm'");
2098 nm_argv
[argc
++] = nm_file_name
;
2099 if (NM_FLAGS
[0] != '\0')
2100 nm_argv
[argc
++] = NM_FLAGS
;
2102 nm_argv
[argc
++] = prog_name
;
2103 nm_argv
[argc
++] = (char *) 0;
2105 /* Trace if needed. */
2108 const char **p_argv
;
2111 for (p_argv
= &nm_argv
[0]; (str
= *p_argv
) != (char *) 0; p_argv
++)
2112 fprintf (stderr
, " %s", str
);
2114 fprintf (stderr
, "\n");
2120 pex
= pex_init (PEX_USE_PIPES
, "collect2", NULL
);
2122 fatal_perror ("pex_init failed");
2124 errmsg
= pex_run (pex
, 0, nm_file_name
, real_nm_argv
, NULL
, NULL
, &err
);
2130 fatal_perror (errmsg
);
2136 int_handler
= (void (*) (int)) signal (SIGINT
, SIG_IGN
);
2138 quit_handler
= (void (*) (int)) signal (SIGQUIT
, SIG_IGN
);
2141 inf
= pex_read_output (pex
, 0);
2143 fatal_perror ("can't open nm output");
2146 fprintf (stderr
, "\nnm output with constructors/destructors.\n");
2148 /* Read each line of nm output. */
2149 while (fgets (buf
, sizeof buf
, inf
) != (char *) 0)
2154 /* If it contains a constructor or destructor name, add the name
2155 to the appropriate list. */
2157 for (p
= buf
; (ch
= *p
) != '\0' && ch
!= '\n' && ch
!= '_'; p
++)
2158 if (ch
== ' ' && p
[1] == 'U' && p
[2] == ' ')
2165 /* Find the end of the symbol name.
2166 Do not include `|', because Encore nm can tack that on the end. */
2167 for (end
= p
; (ch2
= *end
) != '\0' && !ISSPACE (ch2
) && ch2
!= '|';
2173 switch (is_ctor_dtor (name
))
2176 if (which_pass
!= PASS_LIB
)
2177 add_to_list (&constructors
, name
);
2181 if (which_pass
!= PASS_LIB
)
2182 add_to_list (&destructors
, name
);
2186 if (which_pass
!= PASS_LIB
)
2187 fatal ("init function found in object %s", prog_name
);
2188 #ifndef LD_INIT_SWITCH
2189 add_to_list (&constructors
, name
);
2194 if (which_pass
!= PASS_LIB
)
2195 fatal ("fini function found in object %s", prog_name
);
2196 #ifndef LD_FINI_SWITCH
2197 add_to_list (&destructors
, name
);
2202 if (which_pass
!= PASS_LIB
)
2203 add_to_list (&frame_tables
, name
);
2206 default: /* not a constructor or destructor */
2211 fprintf (stderr
, "\t%s\n", buf
);
2215 fprintf (stderr
, "\n");
2217 do_wait (nm_file_name
, pex
);
2219 signal (SIGINT
, int_handler
);
2221 signal (SIGQUIT
, quit_handler
);
2227 /* Use the List Dynamic Dependencies program to find shared libraries that
2228 the output file depends upon and their initialization/finalization
2229 routines, if any. */
2232 scan_libraries (const char *prog_name
)
2234 static struct head libraries
; /* list of shared libraries found */
2236 void (*int_handler
) (int);
2238 void (*quit_handler
) (int);
2240 char *real_ldd_argv
[4];
2241 const char **ldd_argv
= (const char **) real_ldd_argv
;
2243 struct pex_obj
*pex
;
2249 /* If we do not have an `ldd', complain. */
2250 if (ldd_file_name
== 0)
2252 error ("cannot find 'ldd'");
2256 ldd_argv
[argc
++] = ldd_file_name
;
2257 ldd_argv
[argc
++] = prog_name
;
2258 ldd_argv
[argc
++] = (char *) 0;
2260 /* Trace if needed. */
2263 const char **p_argv
;
2266 for (p_argv
= &ldd_argv
[0]; (str
= *p_argv
) != (char *) 0; p_argv
++)
2267 fprintf (stderr
, " %s", str
);
2269 fprintf (stderr
, "\n");
2275 pex
= pex_init (PEX_USE_PIPES
, "collect2", NULL
);
2277 fatal_perror ("pex_init failed");
2279 errmsg
= pex_run (pex
, 0, ldd_file_name
, real_ldd_argv
, NULL
, NULL
, &err
);
2285 fatal_perror (errmsg
);
2291 int_handler
= (void (*) (int)) signal (SIGINT
, SIG_IGN
);
2293 quit_handler
= (void (*) (int)) signal (SIGQUIT
, SIG_IGN
);
2296 inf
= pex_read_output (pex
, 0);
2298 fatal_perror ("can't open ldd output");
2301 notice ("\nldd output with constructors/destructors.\n");
2303 /* Read each line of ldd output. */
2304 while (fgets (buf
, sizeof buf
, inf
) != (char *) 0)
2307 char *name
, *end
, *p
= buf
;
2309 /* Extract names of libraries and add to list. */
2310 PARSE_LDD_OUTPUT (p
);
2315 if (strncmp (name
, "not found", sizeof ("not found") - 1) == 0)
2316 fatal ("dynamic dependency %s not found", buf
);
2318 /* Find the end of the symbol name. */
2320 (ch2
= *end
) != '\0' && ch2
!= '\n' && !ISSPACE (ch2
) && ch2
!= '|';
2325 if (access (name
, R_OK
) == 0)
2326 add_to_list (&libraries
, name
);
2328 fatal ("unable to open dynamic dependency '%s'", buf
);
2331 fprintf (stderr
, "\t%s\n", buf
);
2334 fprintf (stderr
, "\n");
2336 do_wait (ldd_file_name
, pex
);
2338 signal (SIGINT
, int_handler
);
2340 signal (SIGQUIT
, quit_handler
);
2343 /* Now iterate through the library list adding their symbols to
2345 for (list
= libraries
.first
; list
; list
= list
->next
)
2346 scan_prog_file (list
->name
, PASS_LIB
);
2349 #endif /* LDD_SUFFIX */
2351 #endif /* OBJECT_FORMAT_NONE */
2355 * COFF specific stuff.
2358 #ifdef OBJECT_FORMAT_COFF
2360 #if defined (EXTENDED_COFF)
2362 # define GCC_SYMBOLS(X) (SYMHEADER(X).isymMax + SYMHEADER(X).iextMax)
2363 # define GCC_SYMENT SYMR
2364 # define GCC_OK_SYMBOL(X) ((X).st == stProc || (X).st == stGlobal)
2365 # define GCC_SYMINC(X) (1)
2366 # define GCC_SYMZERO(X) (SYMHEADER(X).isymMax)
2367 # define GCC_CHECK_HDR(X) (PSYMTAB(X) != 0)
2371 # define GCC_SYMBOLS(X) (HEADER(ldptr).f_nsyms)
2372 # define GCC_SYMENT SYMENT
2373 # if defined (C_WEAKEXT)
2374 # define GCC_OK_SYMBOL(X) \
2375 (((X).n_sclass == C_EXT || (X).n_sclass == C_WEAKEXT) && \
2376 ((X).n_scnum > N_UNDEF) && \
2378 || (((X).n_type & N_TMASK) == (DT_NON << N_BTSHFT) \
2379 || ((X).n_type & N_TMASK) == (DT_FCN << N_BTSHFT))))
2380 # define GCC_UNDEF_SYMBOL(X) \
2381 (((X).n_sclass == C_EXT || (X).n_sclass == C_WEAKEXT) && \
2382 ((X).n_scnum == N_UNDEF))
2384 # define GCC_OK_SYMBOL(X) \
2385 (((X).n_sclass == C_EXT) && \
2386 ((X).n_scnum > N_UNDEF) && \
2388 || (((X).n_type & N_TMASK) == (DT_NON << N_BTSHFT) \
2389 || ((X).n_type & N_TMASK) == (DT_FCN << N_BTSHFT))))
2390 # define GCC_UNDEF_SYMBOL(X) \
2391 (((X).n_sclass == C_EXT) && ((X).n_scnum == N_UNDEF))
2393 # define GCC_SYMINC(X) ((X).n_numaux+1)
2394 # define GCC_SYMZERO(X) 0
2396 /* 0757 = U803XTOCMAGIC (AIX 4.3) and 0767 = U64_TOCMAGIC (AIX V5) */
2398 # define GCC_CHECK_HDR(X) \
2399 ((HEADER (X).f_magic == U802TOCMAGIC && ! aix64_flag) \
2400 || (HEADER (X).f_magic == 0767 && aix64_flag))
2402 # define GCC_CHECK_HDR(X) \
2403 ((HEADER (X).f_magic == U802TOCMAGIC && ! aix64_flag) \
2404 || (HEADER (X).f_magic == 0757 && aix64_flag))
2409 #ifdef COLLECT_EXPORT_LIST
2410 /* Array of standard AIX libraries which should not
2411 be scanned for ctors/dtors. */
2412 static const char *const aix_std_libs
[] = {
2420 "/usr/lib/libc_r.a",
2421 "/usr/lib/libm_r.a",
2422 "/usr/lib/threads/libc.a",
2423 "/usr/ccs/lib/libc.a",
2424 "/usr/ccs/lib/libm.a",
2425 "/usr/ccs/lib/libc_r.a",
2426 "/usr/ccs/lib/libm_r.a",
2430 /* This function checks the filename and returns 1
2431 if this name matches the location of a standard AIX library. */
2432 static int ignore_library (const char *);
2434 ignore_library (const char *name
)
2436 const char *const *p
= &aix_std_libs
[0];
2437 while (*p
++ != NULL
)
2438 if (! strcmp (name
, *p
)) return 1;
2441 #endif /* COLLECT_EXPORT_LIST */
2443 #if defined (HAVE_DECL_LDGETNAME) && !HAVE_DECL_LDGETNAME
2444 extern char *ldgetname (LDFILE
*, GCC_SYMENT
*);
2447 /* COFF version to scan the name list of the loaded program for
2448 the symbols g++ uses for static constructors and destructors.
2450 The constructor table begins at __CTOR_LIST__ and contains a count
2451 of the number of pointers (or -1 if the constructors are built in a
2452 separate section by the linker), followed by the pointers to the
2453 constructor functions, terminated with a null pointer. The
2454 destructor table has the same format, and begins at __DTOR_LIST__. */
2457 scan_prog_file (const char *prog_name
, enum pass which_pass
)
2459 LDFILE
*ldptr
= NULL
;
2460 int sym_index
, sym_count
;
2463 if (which_pass
!= PASS_FIRST
&& which_pass
!= PASS_OBJ
)
2466 #ifdef COLLECT_EXPORT_LIST
2467 /* We do not need scanning for some standard C libraries. */
2468 if (which_pass
== PASS_FIRST
&& ignore_library (prog_name
))
2471 /* On AIX we have a loop, because there is not much difference
2472 between an object and an archive. This trick allows us to
2473 eliminate scan_libraries() function. */
2477 /* Some platforms (e.g. OSF4) declare ldopen as taking a
2478 non-const char * filename parameter, even though it will not
2479 modify that string. So we must cast away const-ness here,
2480 which will cause -Wcast-qual to burp. */
2481 if ((ldptr
= ldopen ((char *)prog_name
, ldptr
)) != NULL
)
2483 if (! MY_ISCOFF (HEADER (ldptr
).f_magic
))
2484 fatal ("%s: not a COFF file", prog_name
);
2486 if (GCC_CHECK_HDR (ldptr
))
2488 sym_count
= GCC_SYMBOLS (ldptr
);
2489 sym_index
= GCC_SYMZERO (ldptr
);
2491 #ifdef COLLECT_EXPORT_LIST
2492 /* Is current archive member a shared object? */
2493 is_shared
= HEADER (ldptr
).f_flags
& F_SHROBJ
;
2496 while (sym_index
< sym_count
)
2500 if (ldtbread (ldptr
, sym_index
, &symbol
) <= 0)
2502 sym_index
+= GCC_SYMINC (symbol
);
2504 if (GCC_OK_SYMBOL (symbol
))
2508 if ((name
= ldgetname (ldptr
, &symbol
)) == NULL
)
2509 continue; /* Should never happen. */
2511 #ifdef XCOFF_DEBUGGING_INFO
2512 /* All AIX function names have a duplicate entry
2513 beginning with a dot. */
2518 switch (is_ctor_dtor (name
))
2522 add_to_list (&constructors
, name
);
2523 #if defined (COLLECT_EXPORT_LIST) && !defined (LD_INIT_SWITCH)
2524 if (which_pass
== PASS_OBJ
)
2525 add_to_list (&exports
, name
);
2531 add_to_list (&destructors
, name
);
2532 #if defined (COLLECT_EXPORT_LIST) && !defined (LD_INIT_SWITCH)
2533 if (which_pass
== PASS_OBJ
)
2534 add_to_list (&exports
, name
);
2538 #ifdef COLLECT_EXPORT_LIST
2540 #ifndef LD_INIT_SWITCH
2542 add_to_list (&constructors
, name
);
2547 #ifndef LD_INIT_SWITCH
2549 add_to_list (&destructors
, name
);
2556 add_to_list (&frame_tables
, name
);
2557 #if defined (COLLECT_EXPORT_LIST) && !defined (LD_INIT_SWITCH)
2558 if (which_pass
== PASS_OBJ
)
2559 add_to_list (&exports
, name
);
2563 default: /* not a constructor or destructor */
2564 #ifdef COLLECT_EXPORT_LIST
2565 /* Explicitly export all global symbols when
2566 building a shared object on AIX, but do not
2567 re-export symbols from another shared object
2568 and do not export symbols if the user
2569 provides an explicit export list. */
2570 if (shared_obj
&& !is_shared
2571 && which_pass
== PASS_OBJ
&& !export_flag
)
2572 add_to_list (&exports
, name
);
2578 #if !defined(EXTENDED_COFF)
2579 fprintf (stderr
, "\tsec=%d class=%d type=%s%o %s\n",
2580 symbol
.n_scnum
, symbol
.n_sclass
,
2581 (symbol
.n_type
? "0" : ""), symbol
.n_type
,
2585 "\tiss = %5d, value = %5ld, index = %5d, name = %s\n",
2586 symbol
.iss
, (long) symbol
.value
, symbol
.index
, name
);
2591 #ifdef COLLECT_EXPORT_LIST
2594 /* If archive contains both 32-bit and 64-bit objects,
2595 we want to skip objects in other mode so mismatch normal. */
2597 fprintf (stderr
, "%s : magic=%o aix64=%d mismatch\n",
2598 prog_name
, HEADER (ldptr
).f_magic
, aix64_flag
);
2604 fatal ("%s: cannot open as COFF file", prog_name
);
2606 #ifdef COLLECT_EXPORT_LIST
2607 /* On AIX loop continues while there are more members in archive. */
2609 while (ldclose (ldptr
) == FAILURE
);
2611 /* Otherwise we simply close ldptr. */
2612 (void) ldclose(ldptr
);
2615 #endif /* OBJECT_FORMAT_COFF */
2617 #ifdef COLLECT_EXPORT_LIST
2618 /* Given a library name without "lib" prefix, this function
2619 returns a full library name including a path. */
2621 resolve_lib_name (const char *name
)
2625 /* Library extensions for AIX dynamic linking. */
2626 const char * const libexts
[2] = {"a", "so"};
2628 for (i
= 0; libpaths
[i
]; i
++)
2629 if (libpaths
[i
]->max_len
> l
)
2630 l
= libpaths
[i
]->max_len
;
2632 lib_buf
= xmalloc (l
+ strlen(name
) + 10);
2634 for (i
= 0; libpaths
[i
]; i
++)
2636 struct prefix_list
*list
= libpaths
[i
]->plist
;
2637 for (; list
; list
= list
->next
)
2639 /* The following lines are needed because path_prefix list
2640 may contain directories both with trailing '/' and
2643 if (list
->prefix
[strlen(list
->prefix
)-1] != '/')
2645 for (j
= 0; j
< 2; j
++)
2647 sprintf (lib_buf
, "%s%slib%s.%s",
2648 list
->prefix
, p
, name
,
2649 libexts
[(j
+ aixrtl_flag
) % 2]);
2650 if (debug
) fprintf (stderr
, "searching for: %s\n", lib_buf
);
2651 if (file_exists (lib_buf
))
2653 if (debug
) fprintf (stderr
, "found: %s\n", lib_buf
);
2660 fprintf (stderr
, "not found\n");
2662 fatal ("library lib%s not found", name
);
2665 #endif /* COLLECT_EXPORT_LIST */