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. */
24 Revision 1.1 1991/03/21 21:28:37 gumby
27 * Revision 1.2 1991/03/15 18:45:55 rich
30 * Revision 1.1 1991/03/13 00:48:18 chrisb
33 * Revision 1.4 1991/03/10 09:31:24 rich
35 * Makefile config.h ld-emul.c ld-emul.h ld-gld.c ld-gld960.c
36 * ld-lnk960.c ld.h lddigest.c ldexp.c ldexp.h ldfile.c ldfile.h
37 * ldgram.y ldinfo.h ldlang.c ldlang.h ldlex.h ldlex.l ldmain.c
38 * ldmain.h ldmisc.c ldmisc.h ldsym.c ldsym.h ldversion.c
39 * ldversion.h ldwarn.h ldwrite.c ldwrite.h y.tab.h
41 * As of this round of changes, ld now builds on all hosts of (Intel960)
42 * interest and copy passes my copy test on big endian hosts again.
44 * Revision 1.3 1991/02/22 17:15:00 sac
45 * Added RCS keywords and copyrights
52 look after all the file stuff
66 char *ldfile_input_filename
;
67 char *ldfile_output_machine_name
;
68 unsigned long ldfile_output_machine
;
69 enum bfd_architecture ldfile_output_architecture
;
74 extern boolean option_v
;
81 typedef struct search_dirs_struct
84 struct search_dirs_struct
*next
;
87 static search_dirs_type
*search_head
;
88 static search_dirs_type
**search_tail_ptr
= &search_head
;
90 typedef struct search_arch_struct
93 struct search_arch_struct
*next
;
96 static search_arch_type
*search_arch_head
;
97 static search_arch_type
**search_arch_tail_ptr
= &search_arch_head
;
100 ldfile_add_library_path(name
)
103 search_dirs_type
*new =
104 (search_dirs_type
*)ldmalloc(sizeof(search_dirs_type
));
106 new->next
= (search_dirs_type
*)NULL
;
107 *search_tail_ptr
= new;
108 search_tail_ptr
= &new->next
;
113 cached_bfd_openr(attempt
,entry
)
115 lang_input_statement_type
*entry
;
117 entry
->the_bfd
= bfd_openr(attempt
, entry
->target
);
120 return entry
->the_bfd
;
124 open_a(arch
, entry
, lib
, suffix
)
126 lang_input_statement_type
*entry
;
131 search_dirs_type
*search
;
132 for (search
= search_head
;
133 search
!= (search_dirs_type
*)NULL
;
134 search
= search
->next
)
138 if (entry
->is_archive
== true) {
143 entry
->filename
, arch
, suffix
);
146 if (entry
->filename
[0] == '/') {
147 strcpy(buffer
, entry
->filename
);
149 sprintf(buffer
,"%s/%s",search
->name
, entry
->filename
);
152 string
= buystring(buffer
);
153 desc
= cached_bfd_openr (string
, entry
);
156 entry
->filename
= string
;
157 entry
->search_dirs_flag
= false;
158 entry
->the_bfd
= desc
;
166 /* Open the input file specified by 'entry', and return a descriptor.
167 The open file is remembered; if the same file is opened twice in a row,
168 a new open is not actually done. */
171 ldfile_open_file (entry
)
172 lang_input_statement_type
*entry
;
175 if (entry
->superfile
)
176 ldfile_open_file (entry
->superfile
);
178 if (entry
->search_dirs_flag
)
180 search_arch_type
*arch
;
181 for (arch
= search_arch_head
;
182 arch
!= (search_arch_type
*)NULL
;
184 if (open_a(arch
->name
,entry
,"","") != (bfd
*)NULL
) {
187 if (open_a(arch
->name
,entry
,"lib",".a") != (bfd
*)NULL
) {
196 entry
->the_bfd
= cached_bfd_openr (entry
->filename
, entry
);
199 if (!entry
->the_bfd
) info("%F%P: %E %I\n", entry
);
209 try_open(name
, exten
)
215 result
= fopen(name
, "r");
216 if (result
&& option_v
== true) {
220 sprintf(buff
, "%s%s", name
, exten
);
221 result
= fopen(buff
, "r");
223 if (result
&& option_v
== true) {
229 find_a_name(name
, extend
)
233 search_dirs_type
*search
;
236 /* First try raw name */
237 result
= try_open(name
,"");
238 if (result
== (FILE *)NULL
) {
239 /* Try now prefixes */
240 for (search
= search_head
;
241 search
!= (search_dirs_type
*)NULL
;
242 search
= search
->next
) {
243 sprintf(buffer
,"%s/%s", search
->name
, name
);
244 result
= try_open(buffer
, extend
);
251 void ldfile_open_command_file(name
)
254 extern FILE *ldlex_input_stack
;
255 ldlex_input_stack
= find_a_name(name
, ".ld");
257 if (ldlex_input_stack
== (FILE *)NULL
) {
258 info("%P%F cannot open load script file %s\n",name
);
260 ldfile_input_filename
= name
;
268 ldfile_add_arch(name
)
271 search_arch_type
*new =
272 (search_arch_type
*)ldmalloc(sizeof(search_arch_type
));
273 ldfile_output_machine_name
= name
;
276 new->next
= (search_arch_type
*)NULL
;
278 if (isupper(*name
)) *name
= tolower(*name
);
281 *search_arch_tail_ptr
= new;
282 search_arch_tail_ptr
= &new->next
;