]> Git Repo - binutils.git/blame_incremental - ld/ldfile.c
checkpoint before a merge
[binutils.git] / ld / ldfile.c
... / ...
CommitLineData
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$
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
38/* EXPORT */
39char *ldfile_input_filename;
40CONST char * ldfile_output_machine_name;
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
72
73
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);
93 if (option_v == true && entry->the_bfd == (bfd *)NULL) {
94 info("attempt to open %s failed\n", attempt);
95 }
96 return entry->the_bfd;
97}
98
99static bfd *
100open_a(arch, entry, lib, suffix)
101char *arch;
102lang_input_statement_type *entry;
103char *lib;
104char *suffix;
105{
106 bfd*desc;
107 search_dirs_type *search ;
108 for (search = search_head;
109 search != (search_dirs_type *)NULL;
110 search = search->next)
111 {
112 char buffer[1000];
113 char *string;
114 if (entry->is_archive == true) {
115 sprintf(buffer,
116 "%s/%s%s%s%s",
117 search->name,
118 lib,
119 entry->filename, arch, suffix);
120 }
121 else {
122 if (entry->filename[0] == '/' || entry->filename[0] == '.') {
123 strcpy(buffer, entry->filename);
124 } else {
125 sprintf(buffer,"%s/%s",search->name, entry->filename);
126 }
127 }
128 string = buystring(buffer);
129 desc = cached_bfd_openr (string, entry);
130 if (desc)
131 {
132 entry->filename = string;
133 entry->search_dirs_flag = false;
134 entry->the_bfd = desc;
135 return desc;
136 }
137 free(string);
138 }
139 return (bfd *)NULL;
140}
141
142/* Open the input file specified by 'entry', and return a descriptor.
143 The open file is remembered; if the same file is opened twice in a row,
144 a new open is not actually done. */
145
146void
147ldfile_open_file (entry)
148lang_input_statement_type *entry;
149{
150
151 if (entry->superfile)
152 ldfile_open_file (entry->superfile);
153
154 if (entry->search_dirs_flag)
155 {
156 search_arch_type *arch;
157 /* Try to open <filename><suffix> or lib<filename><suffix>.a */
158
159 for (arch = search_arch_head;
160 arch != (search_arch_type *)NULL;
161 arch = arch->next) {
162 if (open_a(arch->name,entry,"","") != (bfd *)NULL) {
163 return;
164 }
165 if (open_a(arch->name,entry,"lib",".a") != (bfd *)NULL) {
166 return;
167 }
168
169 }
170
171
172 }
173 else {
174 entry->the_bfd = cached_bfd_openr (entry->filename, entry);
175
176 }
177 if (!entry->the_bfd) info("%F%P: %E %I\n", entry);
178
179}
180
181
182
183
184
185
186static FILE *
187try_open(name, exten)
188char *name;
189char *exten;
190{
191 FILE *result;
192 char buff[1000];
193 result = fopen(name, "r");
194 if (option_v == true) {
195 if (result == (FILE *)NULL) {
196 info("can't find ");
197 }
198 info("%s\n",name);
199
200 return result;
201 }
202 sprintf(buff, "%s%s", name, exten);
203 result = fopen(buff, "r");
204
205 if (option_v == true) {
206 if (result == (FILE *)NULL) {
207 info("can't find ");
208 }
209 info("%s\n", buff);
210 }
211 return result;
212}
213static FILE *
214find_a_name(name, extend)
215char *name;
216char *extend;
217{
218 search_dirs_type *search;
219 FILE *result;
220 char buffer[1000];
221 /* First try raw name */
222 result = try_open(name,"");
223 if (result == (FILE *)NULL) {
224 /* Try now prefixes */
225 for (search = search_head;
226 search != (search_dirs_type *)NULL;
227 search = search->next) {
228 sprintf(buffer,"%s/%s", search->name, name);
229 result = try_open(buffer, extend);
230 if (result)break;
231 }
232 }
233 return result;
234}
235
236void ldfile_open_command_file(name)
237char *name;
238{
239 extern FILE *ldlex_input_stack;
240 ldlex_input_stack = find_a_name(name, ".ld");
241
242 if (ldlex_input_stack == (FILE *)NULL) {
243 info("%P%F cannot open load script file %s\n",name);
244 }
245 ldfile_input_filename = name;
246 had_script = true;
247}
248
249
250
251
252void
253DEFUN(ldfile_add_arch,(in_name),
254 CONST char *CONST in_name)
255{
256 char *name = buystring(in_name);
257 search_arch_type *new =
258 (search_arch_type *)ldmalloc(sizeof(search_arch_type));
259
260 ldfile_output_machine_name = in_name;
261
262 new->name = name;
263 new->next = (search_arch_type*)NULL;
264 while (*name) {
265 if (isupper(*name)) *name = tolower(*name);
266 name++;
267 }
268 *search_arch_tail_ptr = new;
269 search_arch_tail_ptr = &new->next;
270
271}
This page took 0.023844 seconds and 4 git commands to generate.