Remove rcfonts.tex after building refcard.
[deliverable/binutils-gdb.git] / ld / ldfile.c
CommitLineData
2fa0b342
DHW
1
2/* Copyright (C) 1991 Free Software Foundation, Inc.
3
4This file is part of GLD, the Gnu Linker.
5
6GLD is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 1, or (at your option)
9any later version.
10
11GLD is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GLD; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20/*
21 $Id$
2fa0b342
DHW
22*/
23
24/*
25 ldfile.c
26
27 look after all the file stuff
28
29 */
30
31#include "sysdep.h"
32#include "bfd.h"
33
34#include "ldmisc.h"
35#include "ldlang.h"
36#include "ldfile.h"
37
2fa0b342
DHW
38/* EXPORT */
39char *ldfile_input_filename;
070aa819 40CONST char * ldfile_output_machine_name ="";
2fa0b342
DHW
41unsigned long ldfile_output_machine;
42enum bfd_architecture ldfile_output_architecture;
43boolean had_script;
44
45/* IMPORT */
46
47extern boolean option_v;
48
49
50
51
52
53/* LOACL */
54typedef struct search_dirs_struct
55{
56 char *name;
57 struct search_dirs_struct *next;
58} search_dirs_type;
59
60static search_dirs_type *search_head;
61static search_dirs_type **search_tail_ptr = &search_head;
62
63typedef struct search_arch_struct
64{
65 char *name;
66 struct search_arch_struct *next;
67} search_arch_type;
68
69static search_arch_type *search_arch_head;
70static search_arch_type **search_arch_tail_ptr = &search_arch_head;
71
1418c83b
SC
72
73
2fa0b342
DHW
74void
75ldfile_add_library_path(name)
76char *name;
77{
78 search_dirs_type *new =
79 (search_dirs_type *)ldmalloc(sizeof(search_dirs_type));
80 new->name = name;
81 new->next = (search_dirs_type*)NULL;
82 *search_tail_ptr = new;
83 search_tail_ptr = &new->next;
84}
85
86
87static bfd*
88cached_bfd_openr(attempt,entry)
89char *attempt;
90lang_input_statement_type *entry;
91{
92 entry->the_bfd = bfd_openr(attempt, entry->target);
99fe4553
SC
93 if (option_v == true ) {
94 info("attempt to open %s %s\n", attempt,
95 (entry->the_bfd == (bfd *)NULL) ? "failed" : "succeeded" );
1418c83b 96 }
2fa0b342
DHW
97 return entry->the_bfd;
98}
99
100static bfd *
101open_a(arch, entry, lib, suffix)
102char *arch;
103lang_input_statement_type *entry;
104char *lib;
105char *suffix;
106{
107 bfd*desc;
108 search_dirs_type *search ;
109 for (search = search_head;
110 search != (search_dirs_type *)NULL;
111 search = search->next)
112 {
113 char buffer[1000];
114 char *string;
115 if (entry->is_archive == true) {
116 sprintf(buffer,
117 "%s/%s%s%s%s",
118 search->name,
119 lib,
120 entry->filename, arch, suffix);
121 }
122 else {
1418c83b
SC
123 if (entry->filename[0] == '/' || entry->filename[0] == '.') {
124 strcpy(buffer, entry->filename);
125 } else {
126 sprintf(buffer,"%s/%s",search->name, entry->filename);
127 }
2fa0b342
DHW
128 }
129 string = buystring(buffer);
130 desc = cached_bfd_openr (string, entry);
131 if (desc)
132 {
133 entry->filename = string;
134 entry->search_dirs_flag = false;
135 entry->the_bfd = desc;
136 return desc;
137 }
138 free(string);
139 }
140 return (bfd *)NULL;
141}
142
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. */
146
147void
148ldfile_open_file (entry)
149lang_input_statement_type *entry;
150{
151
152 if (entry->superfile)
153 ldfile_open_file (entry->superfile);
154
155 if (entry->search_dirs_flag)
156 {
157 search_arch_type *arch;
1418c83b
SC
158 /* Try to open <filename><suffix> or lib<filename><suffix>.a */
159
2fa0b342
DHW
160 for (arch = search_arch_head;
161 arch != (search_arch_type *)NULL;
162 arch = arch->next) {
163 if (open_a(arch->name,entry,"","") != (bfd *)NULL) {
164 return;
165 }
166 if (open_a(arch->name,entry,"lib",".a") != (bfd *)NULL) {
167 return;
168 }
169
170 }
171
172
173 }
174 else {
175 entry->the_bfd = cached_bfd_openr (entry->filename, entry);
176
177 }
178 if (!entry->the_bfd) info("%F%P: %E %I\n", entry);
179
180}
181
182
183
184
185
186
187static FILE *
188try_open(name, exten)
189char *name;
190char *exten;
191{
192 FILE *result;
193 char buff[1000];
194 result = fopen(name, "r");
1418c83b
SC
195 if (option_v == true) {
196 if (result == (FILE *)NULL) {
197 info("can't find ");
198 }
2fa0b342 199 info("%s\n",name);
1418c83b 200
2fa0b342
DHW
201 return result;
202 }
203 sprintf(buff, "%s%s", name, exten);
204 result = fopen(buff, "r");
205
1418c83b
SC
206 if (option_v == true) {
207 if (result == (FILE *)NULL) {
208 info("can't find ");
209 }
2fa0b342
DHW
210 info("%s\n", buff);
211 }
212 return result;
213}
214static FILE *
215find_a_name(name, extend)
216char *name;
217char *extend;
218{
219 search_dirs_type *search;
220 FILE *result;
221 char buffer[1000];
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);
231 if (result)break;
232 }
233 }
234 return result;
235}
236
237void ldfile_open_command_file(name)
238char *name;
239{
240 extern FILE *ldlex_input_stack;
241 ldlex_input_stack = find_a_name(name, ".ld");
242
243 if (ldlex_input_stack == (FILE *)NULL) {
244 info("%P%F cannot open load script file %s\n",name);
245 }
246 ldfile_input_filename = name;
247 had_script = true;
248}
249
250
251
252
99fe4553
SC
253
254#ifdef GNU960
255static
256char *
257gnu960_map_archname( name )
258char *name;
259{
260 struct tabentry { char *cmd_switch; char *arch; };
261 static struct tabentry arch_tab[] = {
262 "", "",
263 "KA", "ka",
264 "KB", "kb",
265 "KC", "mc", /* Synonym for MC */
266 "MC", "mc",
267 "CA", "ca",
268 "SA", "ka", /* Functionally equivalent to KA */
269 "SB", "kb", /* Functionally equivalent to KB */
270 NULL, ""
271 };
272 struct tabentry *tp;
273
274
275 for ( tp = arch_tab; tp->cmd_switch != NULL; tp++ ){
276 if ( !strcmp(name,tp->cmd_switch) ){
277 break;
278 }
279 }
280
281 if ( tp->cmd_switch == NULL ){
282 info("%P%F: unknown architecture: %s\n",name);
283 }
284 return tp->arch;
285}
286
287
288
289void
290ldfile_add_arch(name)
291char *name;
292{
293 search_arch_type *new =
294 (search_arch_type *)ldmalloc(sizeof(search_arch_type));
295
296
297 if (*name != '\0') {
298 if (ldfile_output_machine_name[0] != '\0') {
299 info("%P%F: target architecture respecified\n");
300 return;
301 }
302 ldfile_output_machine_name = name;
303 }
304
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;
309
310}
311
312#else /* not GNU960 */
313
314
2fa0b342 315void
1418c83b 316DEFUN(ldfile_add_arch,(in_name),
99fe4553 317 CONST char * in_name)
2fa0b342 318{
1418c83b 319 char *name = buystring(in_name);
2fa0b342
DHW
320 search_arch_type *new =
321 (search_arch_type *)ldmalloc(sizeof(search_arch_type));
1418c83b
SC
322
323 ldfile_output_machine_name = in_name;
2fa0b342
DHW
324
325 new->name = name;
326 new->next = (search_arch_type*)NULL;
327 while (*name) {
328 if (isupper(*name)) *name = tolower(*name);
329 name++;
330 }
331 *search_arch_tail_ptr = new;
332 search_arch_tail_ptr = &new->next;
333
334}
99fe4553 335#endif
a37cc0c0
SC
336
337/* Set the output architecture */
338void
339DEFUN(ldfile_set_output_arch,(string),
340CONST char *string)
341{
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;
348 }
349 else {
350 info("%P%F: Can't represent machine `%s'\n", string);
351 }
352}
This page took 0.052047 seconds and 4 git commands to generate.