2 /* Copyright (C) 1991 Free Software Foundation, Inc.
4 This file is part of GLD, the Gnu Linker.
6 GLD is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
11 GLD is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GLD; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
27 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;
47 extern boolean option_v;
54 typedef struct search_dirs_struct
57 struct search_dirs_struct *next;
60 static search_dirs_type *search_head;
61 static search_dirs_type **search_tail_ptr = &search_head;
63 typedef struct search_arch_struct
66 struct search_arch_struct *next;
69 static search_arch_type *search_arch_head;
70 static search_arch_type **search_arch_tail_ptr = &search_arch_head;
75 ldfile_add_library_path(name)
78 search_dirs_type *new =
79 (search_dirs_type *)ldmalloc(sizeof(search_dirs_type));
81 new->next = (search_dirs_type*)NULL;
82 *search_tail_ptr = new;
83 search_tail_ptr = &new->next;
88 cached_bfd_openr(attempt,entry)
90 lang_input_statement_type *entry;
92 entry->the_bfd = bfd_openr(attempt, entry->target);
93 if (option_v == true ) {
94 info("attempt to open %s %s\n", attempt,
95 (entry->the_bfd == (bfd *)NULL) ? "failed" : "succeeded" );
97 return entry->the_bfd;
101 open_a(arch, entry, lib, suffix)
103 lang_input_statement_type *entry;
108 search_dirs_type *search ;
109 for (search = search_head;
110 search != (search_dirs_type *)NULL;
111 search = search->next)
115 if (entry->is_archive == true) {
120 entry->filename, arch, suffix);
123 if (entry->filename[0] == '/' || entry->filename[0] == '.') {
124 strcpy(buffer, entry->filename);
126 sprintf(buffer,"%s/%s",search->name, entry->filename);
129 string = buystring(buffer);
130 desc = cached_bfd_openr (string, entry);
133 entry->filename = string;
134 entry->search_dirs_flag = false;
135 entry->the_bfd = desc;
143 /* Open the input file specified by 'entry', and return a descriptor.
144 The open file is remembered; if the same file is opened twice in a row,
145 a new open is not actually done. */
148 ldfile_open_file (entry)
149 lang_input_statement_type *entry;
152 if (entry->superfile)
153 ldfile_open_file (entry->superfile);
155 if (entry->search_dirs_flag)
157 search_arch_type *arch;
158 /* Try to open <filename><suffix> or lib<filename><suffix>.a */
160 for (arch = search_arch_head;
161 arch != (search_arch_type *)NULL;
163 if (open_a(arch->name,entry,"","") != (bfd *)NULL) {
166 if (open_a(arch->name,entry,"lib",".a") != (bfd *)NULL) {
175 entry->the_bfd = cached_bfd_openr (entry->filename, entry);
178 if (!entry->the_bfd) info("%F%P: %E %I\n", entry);
188 try_open(name, exten)
194 result = fopen(name, "r");
195 if (option_v == true) {
196 if (result == (FILE *)NULL) {
203 sprintf(buff, "%s%s", name, exten);
204 result = fopen(buff, "r");
206 if (option_v == true) {
207 if (result == (FILE *)NULL) {
215 find_a_name(name, extend)
219 search_dirs_type *search;
222 /* First try raw name */
223 result = try_open(name,"");
224 if (result == (FILE *)NULL) {
225 /* Try now prefixes */
226 for (search = search_head;
227 search != (search_dirs_type *)NULL;
228 search = search->next) {
229 sprintf(buffer,"%s/%s", search->name, name);
230 result = try_open(buffer, extend);
237 void ldfile_open_command_file(name)
240 extern FILE *ldlex_input_stack;
241 ldlex_input_stack = find_a_name(name, ".ld");
243 if (ldlex_input_stack == (FILE *)NULL) {
244 info("%P%F cannot open load script file %s\n",name);
246 ldfile_input_filename = name;
257 gnu960_map_archname( name )
260 struct tabentry { char *cmd_switch; char *arch; };
261 static struct tabentry arch_tab[] = {
265 "KC", "mc", /* Synonym for MC */
268 "SA", "ka", /* Functionally equivalent to KA */
269 "SB", "kb", /* Functionally equivalent to KB */
275 for ( tp = arch_tab; tp->cmd_switch != NULL; tp++ ){
276 if ( !strcmp(name,tp->cmd_switch) ){
281 if ( tp->cmd_switch == NULL ){
282 info("%P%F: unknown architecture: %s\n",name);
290 ldfile_add_arch(name)
293 search_arch_type *new =
294 (search_arch_type *)ldmalloc(sizeof(search_arch_type));
298 if (ldfile_output_machine_name[0] != '\0') {
299 info("%P%F: target architecture respecified\n");
302 ldfile_output_machine_name = name;
305 new->next = (search_arch_type*)NULL;
306 new->name = gnu960_map_archname( name );
307 *search_arch_tail_ptr = new;
308 search_arch_tail_ptr = &new->next;
312 #else /* not GNU960 */
316 DEFUN(ldfile_add_arch,(in_name),
317 CONST char * in_name)
319 char *name = buystring(in_name);
320 search_arch_type *new =
321 (search_arch_type *)ldmalloc(sizeof(search_arch_type));
323 ldfile_output_machine_name = in_name;
326 new->next = (search_arch_type*)NULL;
328 if (isupper(*name)) *name = tolower(*name);
331 *search_arch_tail_ptr = new;
332 search_arch_tail_ptr = &new->next;
337 /* Set the output architecture */
339 DEFUN(ldfile_set_output_arch,(string),
342 enum bfd_architecture arch;
343 unsigned long machine;
344 if (bfd_scan_arch_mach(string, &arch, &machine) == true) {
345 ldfile_output_architecture = arch;
346 ldfile_output_machine = machine;
347 ldfile_output_machine_name = string;
350 info("%P%F: Can't represent machine `%s'\n", string);