1 /* Copyright (C) 1991, 92, 93, 94 Free Software Foundation, Inc.
3 This file is part of GLD, the Gnu Linker.
5 GLD is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 1, or (at your option)
10 GLD is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GLD; see the file COPYING. If not, write to
17 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 look after all the file stuff
41 const char *ldfile_input_filename
;
42 boolean ldfile_assumed_script
= false;
43 const char *ldfile_output_machine_name
= "";
44 unsigned long ldfile_output_machine
;
45 enum bfd_architecture ldfile_output_architecture
;
46 search_dirs_type
*search_head
;
55 /* The MPW path char is a colon. */
61 static search_dirs_type
**search_tail_ptr
= &search_head
;
63 typedef struct search_arch
66 struct search_arch
*next
;
69 static search_arch_type
*search_arch_head
;
70 static search_arch_type
**search_arch_tail_ptr
= &search_arch_head
;
72 static boolean ldfile_open_file_search
73 PARAMS ((const char *arch
, lang_input_statement_type
*,
74 const char *lib
, const char *suffix
));
75 static FILE *try_open
PARAMS ((const char *name
, const char *exten
));
78 ldfile_add_library_path (name
, cmdline
)
82 search_dirs_type
*new;
84 new = (search_dirs_type
*) xmalloc (sizeof (search_dirs_type
));
87 new->cmdline
= cmdline
;
88 *search_tail_ptr
= new;
89 search_tail_ptr
= &new->next
;
92 /* Try to open a BFD for a lang_input_statement. */
95 ldfile_try_open_bfd (attempt
, entry
)
97 lang_input_statement_type
*entry
;
99 entry
->the_bfd
= bfd_openr (attempt
, entry
->target
);
101 if (trace_file_tries
)
102 info_msg ("attempt to open %s %s\n", attempt
,
103 entry
->the_bfd
== NULL
? "failed" : "succeeded");
105 if (entry
->the_bfd
!= NULL
)
111 /* Search for and open the file specified by ENTRY. If it is an
112 archive, use ARCH, LIB and SUFFIX to modify the file name. */
115 ldfile_open_file_search (arch
, entry
, lib
, suffix
)
117 lang_input_statement_type
*entry
;
121 search_dirs_type
*search
;
123 /* If this is not an archive, try to open it in the current
125 if (! entry
->is_archive
)
127 if (ldfile_try_open_bfd (entry
->filename
, entry
))
131 for (search
= search_head
;
132 search
!= (search_dirs_type
*)NULL
;
133 search
= search
->next
)
137 if (entry
->dynamic
&& ! link_info
.relocateable
)
139 if (ldemul_open_dynamic_archive (arch
, search
, entry
))
143 string
= (char *) xmalloc (strlen (search
->name
)
146 + strlen (entry
->filename
)
151 if (entry
->is_archive
)
152 sprintf (string
, "%s%s%s%s%s%s", search
->name
, slash
,
153 lib
, entry
->filename
, arch
, suffix
);
154 else if (entry
->filename
[0] == '/' || entry
->filename
[0] == '.')
155 strcpy (string
, entry
->filename
);
157 sprintf (string
, "%s%s%s", search
->name
, slash
, entry
->filename
);
159 if (ldfile_try_open_bfd (string
, entry
))
161 entry
->filename
= string
;
171 /* Open the input file specified by ENTRY. */
174 ldfile_open_file (entry
)
175 lang_input_statement_type
*entry
;
177 if (entry
->the_bfd
!= NULL
)
180 if (! entry
->search_dirs_flag
)
182 if (ldfile_try_open_bfd (entry
->filename
, entry
))
187 search_arch_type
*arch
;
189 /* Try to open <filename><suffix> or lib<filename><suffix>.a */
190 for (arch
= search_arch_head
;
191 arch
!= (search_arch_type
*) NULL
;
194 if (ldfile_open_file_search (arch
->name
, entry
, "lib", ".a"))
197 if (ldfile_open_file_search (arch
->name
, entry
, ":lib", ".a"))
203 einfo("%F%P: cannot open %s: %E\n", entry
->local_sym_name
);
206 /* Try to open NAME; if that fails, try NAME with EXTEN appended to it. */
209 try_open (name
, exten
)
216 result
= fopen (name
, "r");
217 if (trace_file_tries
)
220 info_msg ("cannot find script file ");
222 info_msg ("opened script file ");
223 info_msg ("%s\n",name
);
231 sprintf (buff
, "%s%s", name
, exten
);
232 result
= fopen (buff
, "r");
233 if (trace_file_tries
)
236 info_msg ("cannot find script file ");
238 info_msg ("opened script file ");
239 info_msg ("%s\n", buff
);
246 /* Try to open NAME; if that fails, look for it in any directories
247 specified with -L, without and with EXTEND apppended. */
250 ldfile_find_command_file (name
, extend
)
254 search_dirs_type
*search
;
258 /* First try raw name */
259 result
= try_open(name
,"");
260 if (result
== (FILE *)NULL
) {
261 /* Try now prefixes */
262 for (search
= search_head
;
263 search
!= (search_dirs_type
*)NULL
;
264 search
= search
->next
) {
265 sprintf(buffer
,"%s/%s", search
->name
, name
);
266 result
= try_open(buffer
, extend
);
274 ldfile_open_command_file (name
)
277 FILE *ldlex_input_stack
;
278 ldlex_input_stack
= ldfile_find_command_file(name
, "");
280 if (ldlex_input_stack
== (FILE *)NULL
) {
281 bfd_set_error (bfd_error_system_call
);
282 einfo("%P%F: cannot open linker script file %s: %E\n",name
);
284 lex_push_file(ldlex_input_stack
, name
);
286 ldfile_input_filename
= name
;
298 gnu960_map_archname( name
)
301 struct tabentry
{ char *cmd_switch
; char *arch
; };
302 static struct tabentry arch_tab
[] = {
306 "KC", "mc", /* Synonym for MC */
309 "SA", "ka", /* Functionally equivalent to KA */
310 "SB", "kb", /* Functionally equivalent to KB */
316 for ( tp
= arch_tab
; tp
->cmd_switch
!= NULL
; tp
++ ){
317 if ( !strcmp(name
,tp
->cmd_switch
) ){
322 if ( tp
->cmd_switch
== NULL
){
323 einfo("%P%F: unknown architecture: %s\n",name
);
331 ldfile_add_arch(name
)
334 search_arch_type
*new =
335 (search_arch_type
*)xmalloc((bfd_size_type
)(sizeof(search_arch_type
)));
339 if (ldfile_output_machine_name
[0] != '\0') {
340 einfo("%P%F: target architecture respecified\n");
343 ldfile_output_machine_name
= name
;
346 new->next
= (search_arch_type
*)NULL
;
347 new->name
= gnu960_map_archname( name
);
348 *search_arch_tail_ptr
= new;
349 search_arch_tail_ptr
= &new->next
;
353 #else /* not GNU960 */
357 ldfile_add_arch (in_name
)
358 CONST
char * in_name
;
360 char *name
= buystring(in_name
);
361 search_arch_type
*new =
362 (search_arch_type
*)xmalloc((bfd_size_type
)(sizeof(search_arch_type
)));
364 ldfile_output_machine_name
= in_name
;
367 new->next
= (search_arch_type
*)NULL
;
369 if (isupper(*name
)) *name
= tolower(*name
);
372 *search_arch_tail_ptr
= new;
373 search_arch_tail_ptr
= &new->next
;
378 /* Set the output architecture */
380 ldfile_set_output_arch (string
)
383 bfd_arch_info_type
*arch
= bfd_scan_arch(string
);
386 ldfile_output_architecture
= arch
->arch
;
387 ldfile_output_machine
= arch
->mach
;
388 ldfile_output_machine_name
= arch
->printable_name
;
391 einfo("%P%F: cannot represent machine `%s'\n", string
);