source: trunk/src/binutils/include/bfdlink.h@ 239

Last change on this file since 239 was 10, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 22.1 KB
RevLine 
[10]1/* bfdlink.h -- header file for BFD link routines
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
3 Free Software Foundation, Inc.
4 Written by Steve Chamberlain and Ian Lance Taylor, Cygnus Support.
5
6This file is part of BFD, the Binary File Descriptor library.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21
22#ifndef BFDLINK_H
23#define BFDLINK_H
24
25/* Which symbols to strip during a link. */
26enum bfd_link_strip
27{
28 strip_none, /* Don't strip any symbols. */
29 strip_debugger, /* Strip debugging symbols. */
30 strip_some, /* keep_hash is the list of symbols to keep. */
31 strip_all /* Strip all symbols. */
32};
33
34/* Which local symbols to discard during a link. This is irrelevant
35 if strip_all is used. */
36enum bfd_link_discard
37{
38 discard_none, /* Don't discard any locals. */
39 discard_l, /* Discard local temporary symbols. */
40 discard_all /* Discard all locals. */
41};
42
43
44/* These are the possible types of an entry in the BFD link hash
45 table. */
46
47enum bfd_link_hash_type
48{
49 bfd_link_hash_new, /* Symbol is new. */
50 bfd_link_hash_undefined, /* Symbol seen before, but undefined. */
51 bfd_link_hash_undefweak, /* Symbol is weak and undefined. */
52 bfd_link_hash_defined, /* Symbol is defined. */
53 bfd_link_hash_defweak, /* Symbol is weak and defined. */
54 bfd_link_hash_common, /* Symbol is common. */
55 bfd_link_hash_indirect, /* Symbol is an indirect link. */
56 bfd_link_hash_warning /* Like indirect, but warn if referenced. */
57};
58
59/* The linking routines use a hash table which uses this structure for
60 its elements. */
61
62struct bfd_link_hash_entry
63{
64 /* Base hash table entry structure. */
65 struct bfd_hash_entry root;
66 /* Type of this entry. */
67 enum bfd_link_hash_type type;
68
69 /* Undefined and common symbols are kept in a linked list through
70 this field. This field is not in the union because that would
71 force us to remove entries from the list when we changed their
72 type, which would force the list to be doubly linked, which would
73 waste more memory. When an undefined or common symbol is
74 created, it should be added to this list, the head of which is in
75 the link hash table itself. As symbols are defined, they need
76 not be removed from the list; anything which reads the list must
77 doublecheck the symbol type.
78
79 Weak symbols are not kept on this list.
80
81 Defined and defweak symbols use this field as a reference marker.
82 If the field is not NULL, or this structure is the tail of the
83 undefined symbol list, the symbol has been referenced. If the
84 symbol is undefined and becomes defined, this field will
85 automatically be non-NULL since the symbol will have been on the
86 undefined symbol list. */
87 struct bfd_link_hash_entry *next;
88 /* A union of information depending upon the type. */
89 union
90 {
91 /* Nothing is kept for bfd_hash_new. */
92 /* bfd_link_hash_undefined, bfd_link_hash_undefweak. */
93 struct
94 {
95 bfd *abfd; /* BFD symbol was found in. */
96 } undef;
97 /* bfd_link_hash_defined, bfd_link_hash_defweak. */
98 struct
99 {
100 bfd_vma value; /* Symbol value. */
101 asection *section; /* Symbol section. */
102 } def;
103 /* bfd_link_hash_indirect, bfd_link_hash_warning. */
104 struct
105 {
106 struct bfd_link_hash_entry *link; /* Real symbol. */
107 const char *warning; /* Warning (bfd_link_hash_warning only). */
108 } i;
109 /* bfd_link_hash_common. */
110 struct
111 {
112 /* The linker needs to know three things about common
113 symbols: the size, the alignment, and the section in
114 which the symbol should be placed. We store the size
115 here, and we allocate a small structure to hold the
116 section and the alignment. The alignment is stored as a
117 power of two. We don't store all the information
118 directly because we don't want to increase the size of
119 the union; this structure is a major space user in the
120 linker. */
121 bfd_size_type size; /* Common symbol size. */
122 struct bfd_link_hash_common_entry
123 {
124 unsigned int alignment_power; /* Alignment. */
125 asection *section; /* Symbol section. */
126 } *p;
127 } c;
128 } u;
129};
130
131/* This is the link hash table. It is a derived class of
132 bfd_hash_table. */
133
134struct bfd_link_hash_table
135{
136 /* The hash table itself. */
137 struct bfd_hash_table table;
138 /* The back end which created this hash table. This indicates the
139 type of the entries in the hash table, which is sometimes
140 important information when linking object files of different
141 types together. */
142 const bfd_target *creator;
143 /* A linked list of undefined and common symbols, linked through the
144 next field in the bfd_link_hash_entry structure. */
145 struct bfd_link_hash_entry *undefs;
146 /* Entries are added to the tail of the undefs list. */
147 struct bfd_link_hash_entry *undefs_tail;
148};
149
150/* Look up an entry in a link hash table. If FOLLOW is true, this
151 follows bfd_link_hash_indirect and bfd_link_hash_warning links to
152 the real symbol. */
153extern struct bfd_link_hash_entry *bfd_link_hash_lookup
154 PARAMS ((struct bfd_link_hash_table *, const char *, boolean create,
155 boolean copy, boolean follow));
156
157/* Look up an entry in the main linker hash table if the symbol might
158 be wrapped. This should only be used for references to an
159 undefined symbol, not for definitions of a symbol. */
160
161extern struct bfd_link_hash_entry *bfd_wrapped_link_hash_lookup
162 PARAMS ((bfd *, struct bfd_link_info *, const char *, boolean, boolean,
163 boolean));
164
165/* Traverse a link hash table. */
166extern void bfd_link_hash_traverse
167 PARAMS ((struct bfd_link_hash_table *,
168 boolean (*) (struct bfd_link_hash_entry *, PTR),
169 PTR));
170
171/* Add an entry to the undefs list. */
172extern void bfd_link_add_undef
173 PARAMS ((struct bfd_link_hash_table *, struct bfd_link_hash_entry *));
174
175
176/* This structure holds all the information needed to communicate
177 between BFD and the linker when doing a link. */
178
179struct bfd_link_info
180{
181 /* Function callbacks. */
182 const struct bfd_link_callbacks *callbacks;
183 /* true if BFD should generate a relocateable object file. */
184 boolean relocateable;
185 /* true if BFD should generate relocation information in the final executable. */
186 boolean emitrelocations;
187 /* true if BFD should generate a "task linked" object file,
188 similar to relocatable but also with globals converted to statics. */
189 boolean task_link;
190 /* true if BFD should generate a shared object. */
191 boolean shared;
192 /* true if BFD should pre-bind symbols in a shared object. */
193 boolean symbolic;
194 /* true if shared objects should be linked directly, not shared. */
195 boolean static_link;
196 /* true if the output file should be in a traditional format. This
197 is equivalent to the setting of the BFD_TRADITIONAL_FORMAT flag
198 on the output file, but may be checked when reading the input
199 files. */
200 boolean traditional_format;
201 /* true if we want to produced optimized output files. This might
202 need much more time and therefore must be explicitly selected. */
203 boolean optimize;
204 /* true if BFD should generate errors for undefined symbols
205 even if generating a shared object. */
206 boolean no_undefined;
207 /* true if BFD should allow undefined symbols in shared objects even
208 when no_undefined is set to disallow undefined symbols. The net
209 result will be that undefined symbols in regular objects will
210 still trigger an error, but undefined symbols in shared objects
211 will be ignored. The implementation of no_undefined makes the
212 assumption that the runtime linker will choke on undefined
213 symbols. However there is at least one system (BeOS) where
214 undefined symbols in shared libraries is normal since the kernel
215 patches them at load time to select which function is most
216 appropriate for the current architecture. I.E. dynamically
217 select an appropriate memset function. Apparently it is also
218 normal for HPPA shared libraries to have undefined symbols. */
219 boolean allow_shlib_undefined;
220 /* Which symbols to strip. */
221 enum bfd_link_strip strip;
222 /* Which local symbols to discard. */
223 enum bfd_link_discard discard;
224 /* true if symbols should be retained in memory, false if they
225 should be freed and reread. */
226 boolean keep_memory;
227 /* The list of input BFD's involved in the link. These are chained
228 together via the link_next field. */
229 bfd *input_bfds;
230 /* If a symbol should be created for each input BFD, this is section
231 where those symbols should be placed. It must be a section in
232 the output BFD. It may be NULL, in which case no such symbols
233 will be created. This is to support CREATE_OBJECT_SYMBOLS in the
234 linker command language. */
235 asection *create_object_symbols_section;
236 /* Hash table handled by BFD. */
237 struct bfd_link_hash_table *hash;
238 /* Hash table of symbols to keep. This is NULL unless strip is
239 strip_some. */
240 struct bfd_hash_table *keep_hash;
241 /* true if every symbol should be reported back via the notice
242 callback. */
243 boolean notice_all;
244 /* Hash table of symbols to report back via the notice callback. If
245 this is NULL, and notice_all is false, then no symbols are
246 reported back. */
247 struct bfd_hash_table *notice_hash;
248 /* Hash table of symbols which are being wrapped (the --wrap linker
249 option). If this is NULL, no symbols are being wrapped. */
250 struct bfd_hash_table *wrap_hash;
251 /* If a base output file is wanted, then this points to it */
252 PTR base_file;
253
254 /* If non-zero, specifies that branches which are problematic for the
255 MPC860 C0 (or earlier) should be checked for and modified. It gives the
256 number of bytes that should be checked at the end of each text page. */
257 int mpc860c0;
258
259 /* The function to call when the executable or shared object is
260 loaded. */
261 const char *init_function;
262 /* The function to call when the executable or shared object is
263 unloaded. */
264 const char *fini_function;
265
266 /* true if the new ELF dynamic tags are enabled. */
267 boolean new_dtags;
268
269 /* May be used to set DT_FLAGS for ELF. */
270 bfd_vma flags;
271
272 /* May be used to set DT_FLAGS_1 for ELF. */
273 bfd_vma flags_1;
274};
275
276/* This structures holds a set of callback functions. These are
277 called by the BFD linker routines. The first argument to each
278 callback function is the bfd_link_info structure being used. Each
279 function returns a boolean value. If the function returns false,
280 then the BFD function which called it will return with a failure
281 indication. */
282
283struct bfd_link_callbacks
284{
285 /* A function which is called when an object is added from an
286 archive. ABFD is the archive element being added. NAME is the
287 name of the symbol which caused the archive element to be pulled
288 in. */
289 boolean (*add_archive_element) PARAMS ((struct bfd_link_info *,
290 bfd *abfd,
291 const char *name));
292 /* A function which is called when a symbol is found with multiple
293 definitions. NAME is the symbol which is defined multiple times.
294 OBFD is the old BFD, OSEC is the old section, OVAL is the old
295 value, NBFD is the new BFD, NSEC is the new section, and NVAL is
296 the new value. OBFD may be NULL. OSEC and NSEC may be
297 bfd_com_section or bfd_ind_section. */
298 boolean (*multiple_definition) PARAMS ((struct bfd_link_info *,
299 const char *name,
300 bfd *obfd,
301 asection *osec,
302 bfd_vma oval,