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, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 look after all the file stuff
39 char *ldfile_input_filename;
40 const char *ldfile_output_machine_name = "";
41 unsigned long ldfile_output_machine;
42 enum bfd_architecture ldfile_output_architecture;
43 search_dirs_type *search_head;
45 /* start-sanitize-mpw */
47 /* end-sanitize-mpw */
53 /* start-sanitize-mpw */
55 /* The MPW path char is a colon. */
58 /* end-sanitize-mpw */
62 static search_dirs_type **search_tail_ptr = &search_head;
64 typedef struct search_arch
67 struct search_arch *next;
70 static search_arch_type *search_arch_head;
71 static search_arch_type **search_arch_tail_ptr = &search_arch_head;
73 static bfd *cached_bfd_openr PARAMS ((const char *attempt,
74 lang_input_statement_type *entry));
75 static bfd *open_a PARAMS ((char *arch, lang_input_statement_type *entry,
76 char *lib, char *suffix));
77 static FILE *try_open PARAMS ((char *name, char *exten));
80 ldfile_add_library_path (name, cmdline)
84 search_dirs_type *new;
86 new = (search_dirs_type *) xmalloc (sizeof (search_dirs_type));
89 new->cmdline = cmdline;
90 *search_tail_ptr = new;
91 search_tail_ptr = &new->next;
96 cached_bfd_openr(attempt,entry)
98 lang_input_statement_type *entry;
100 entry->the_bfd = bfd_openr(attempt, entry->target);
101 if (trace_file_tries == true ) {
102 info_msg ("attempt to open %s %s\n", attempt,
103 (entry->the_bfd == (bfd *)NULL) ? "failed" : "succeeded" );
105 return entry->the_bfd;
109 open_a(arch, entry, lib, suffix)
111 lang_input_statement_type *entry;
116 search_dirs_type *search ;
117 for (search = search_head;
118 search != (search_dirs_type *)NULL;
119 search = search->next)
123 if (entry->is_archive == true) {
129 entry->filename, arch, suffix);
132 if (entry->filename[0] == '/' || entry->filename[0] == '.') {
133 strcpy(buffer, entry->filename);
135 sprintf(buffer,"%s%s%s",search->name, slash, entry->filename);
138 string = buystring(buffer);
139 desc = cached_bfd_openr (string, entry);
142 entry->filename = string;
143 entry->the_bfd = desc;
151 /* Open the input file specified by 'entry', and return a descriptor.
152 The open file is remembered; if the same file is opened twice in a row,
153 a new open is not actually done. */
156 ldfile_open_file (entry)
157 lang_input_statement_type *entry;
159 ASSERT (entry->the_bfd == NULL);
161 if (! entry->search_dirs_flag)
162 entry->the_bfd = cached_bfd_openr (entry->filename, entry);
165 search_arch_type *arch;
167 /* Try to open <filename><suffix> or lib<filename><suffix>.a */
168 for (arch = search_arch_head;
169 arch != (search_arch_type *) NULL;
172 if (config.dynamic_link)
174 /* FIXME: Perhaps we will sometimes want something other
176 if (open_a (arch->name, entry, "lib", ".so") != (bfd *) NULL)
179 if (open_a (arch->name, entry, "lib", ".a") != (bfd *) NULL)
182 if (open_a (arch->name, entry, ":lib", ".a") != (bfd *) NULL)
188 if (entry->the_bfd == NULL)
189 einfo("%F%P: cannot open %s: %E\n", entry->local_sym_name);
192 /* Try to open NAME; if that fails, try NAME with EXTEN appended to it. */
195 try_open(name, exten)
202 result = fopen(name, "r");
203 if (trace_file_tries == true) {
204 if (result == (FILE *)NULL) {
205 info_msg ("cannot find ");
207 info_msg ("%s\n",name);
209 if (result != (FILE *)NULL) {
214 sprintf(buff, "%s%s", name, exten);
215 result = fopen(buff, "r");
216 if (trace_file_tries == true) {
217 if (result == (FILE *)NULL) {
218 info_msg ("cannot find ");
220 info_msg ("%s\n", buff);
226 /* Try to open NAME; if that fails, look for it in any directories
227 specified with -L, without and with EXTEND apppended. */
230 ldfile_find_command_file(name, extend)
234 search_dirs_type *search;
238 /* First try raw name */
239 result = try_open(name,"");
240 if (result == (FILE *)NULL) {
241 /* Try now prefixes */
242 for (search = search_head;
243 search != (search_dirs_type *)NULL;
244 search = search->next) {
245 sprintf(buffer,"%s/%s", search->name, name);
246 result = try_open(buffer, extend);
254 ldfile_open_command_file(name)
257 FILE *ldlex_input_stack;
258 ldlex_input_stack = ldfile_find_command_file(name, "");
260 if (ldlex_input_stack == (FILE *)NULL) {
261 bfd_set_error (bfd_error_system_call);
262 einfo("%P%F: cannot open linker script file %s: %E\n",name);
264 lex_push_file(ldlex_input_stack, name);
266 ldfile_input_filename = name;
277 gnu960_map_archname( name )
280 struct tabentry { char *cmd_switch; char *arch; };
281 static struct tabentry arch_tab[] = {
285 "KC", "mc", /* Synonym for MC */
288 "SA", "ka", /* Functionally equivalent to KA */
289 "SB", "kb", /* Functionally equivalent to KB */
295 for ( tp = arch_tab; tp->cmd_switch != NULL; tp++ ){
296 if ( !strcmp(name,tp->cmd_switch) ){
301 if ( tp->cmd_switch == NULL ){
302 einfo("%P%F: unknown architecture: %s\n",name);
310 ldfile_add_arch(name)
313 search_arch_type *new =
314 (search_arch_type *)xmalloc((bfd_size_type)(sizeof(search_arch_type)));
318 if (ldfile_output_machine_name[0] != '\0') {
319 einfo("%P%F: target architecture respecified\n");
322 ldfile_output_machine_name = name;
325 new->next = (search_arch_type*)NULL;
326 new->name = gnu960_map_archname( name );
327 *search_arch_tail_ptr = new;
328 search_arch_tail_ptr = &new->next;
332 #else /* not GNU960 */
336 ldfile_add_arch (in_name)
337 CONST char * in_name;
339 char *name = buystring(in_name);
340 search_arch_type *new =
341 (search_arch_type *)xmalloc((bfd_size_type)(sizeof(search_arch_type)));
343 ldfile_output_machine_name = in_name;
346 new->next = (search_arch_type*)NULL;
348 if (isupper(*name)) *name = tolower(*name);
351 *search_arch_tail_ptr = new;
352 search_arch_tail_ptr = &new->next;
357 /* Set the output architecture */
359 ldfile_set_output_arch (string)
362 bfd_arch_info_type *arch = bfd_scan_arch(string);
365 ldfile_output_architecture = arch->arch;
366 ldfile_output_machine = arch->mach;
367 ldfile_output_machine_name = arch->printable_name;
370 einfo("%P%F: cannot represent machine `%s'\n", string);