More __FreeBSD__ -> __DragonFly__ translation
[dragonfly.git] / gnu / usr.bin / ld / ld.h
1 /*
2  * $FreeBSD: src/gnu/usr.bin/ld/ld.h,v 1.21 1999/08/27 23:36:01 peter Exp $
3  * $DragonFly: src/gnu/usr.bin/ld/Attic/ld.h,v 1.4 2004/02/03 19:22:59 dillon Exp $
4  */
5 /*-
6  * This code is derived from software copyrighted by the Free Software
7  * Foundation.
8  *
9  * Modified 1991 by Donn Seeley at UUNET Technologies, Inc.
10  */
11
12 #define SUN_COMPAT
13
14 #ifndef N_SIZE
15 #define N_SIZE          0xc
16 #endif
17
18 #ifndef min
19 #define min(a,b) ((a) < (b) ? (a) : (b))
20 #endif
21
22 /* If compiled with GNU C, use the built-in alloca */
23 #if defined(__GNUC__) || defined(sparc)
24 #define alloca __builtin_alloca
25 #endif
26
27 #include "md.h"
28 #include "link.h"
29
30 /* Macro to control the number of undefined references printed */
31 #define MAX_UREFS_PRINTED       10
32
33 /* Align to power-of-two boundary */
34 #define PALIGN(x,p)     (((x) +  (u_long)(p) - 1) & (-(u_long)(p)))
35
36 /* Align to machine dependent boundary */
37 #define MALIGN(x)       PALIGN(x,MAX_ALIGNMENT)
38
39 /* Define this to specify the default executable format.  */
40 #ifndef DEFAULT_MAGIC
41 #ifdef __DragonFly__
42 #define DEFAULT_MAGIC QMAGIC
43 extern int      netzmagic;
44 #else
45 #define DEFAULT_MAGIC ZMAGIC
46 #endif
47 #endif
48
49 #ifdef DEMANGLE_CPLUSPLUS
50 extern char *demangle(char*);
51 #else
52 #define demangle(name) name
53 #endif
54
55 /*
56  * Ok.  Following are the relocation information macros.  If your
57  * system should not be able to use the default set (below), you must
58  * define the following:
59
60  *   relocation_info: This must be typedef'd (or #define'd) to the type
61  * of structure that is stored in the relocation info section of your
62  * a.out files.  Often this is defined in the a.out.h for your system.
63  *
64  *   RELOC_ADDRESS (rval): Offset into the current section of the
65  * <whatever> to be relocated.  *Must be an lvalue*.
66  *
67  *   RELOC_EXTERN_P (rval):  Is this relocation entry based on an
68  * external symbol (1), or was it fully resolved upon entering the
69  * loader (0) in which case some combination of the value in memory
70  * (if RELOC_MEMORY_ADD_P) and the extra (if RELOC_ADD_EXTRA) contains
71  * what the value of the relocation actually was.  *Must be an lvalue*.
72  *
73  *   RELOC_TYPE (rval): If this entry was fully resolved upon
74  * entering the loader, what type should it be relocated as?
75  *
76  *   RELOC_SYMBOL (rval): If this entry was not fully resolved upon
77  * entering the loader, what is the index of it's symbol in the symbol
78  * table?  *Must be a lvalue*.
79  *
80  *   RELOC_MEMORY_ADD_P (rval): This should return true if the final
81  * relocation value output here should be added to memory, or if the
82  * section of memory described should simply be set to the relocation
83  * value.
84  *
85  *   RELOC_ADD_EXTRA (rval): (Optional) This macro, if defined, gives
86  * an extra value to be added to the relocation value based on the
87  * individual relocation entry.  *Must be an lvalue if defined*.
88  *
89  *   RELOC_PCREL_P (rval): True if the relocation value described is
90  * pc relative.
91  *
92  *   RELOC_VALUE_RIGHTSHIFT (rval): Number of bits right to shift the
93  * final relocation value before putting it where it belongs.
94  *
95  *   RELOC_TARGET_SIZE (rval): log to the base 2 of the number of
96  * bytes of size this relocation entry describes; 1 byte == 0; 2 bytes
97  * == 1; 4 bytes == 2, and etc.  This is somewhat redundant (we could
98  * do everything in terms of the bit operators below), but having this
99  * macro could end up producing better code on machines without fancy
100  * bit twiddling.  Also, it's easier to understand/code big/little
101  * endian distinctions with this macro.
102  *
103  *   RELOC_TARGET_BITPOS (rval): The starting bit position within the
104  * object described in RELOC_TARGET_SIZE in which the relocation value
105  * will go.
106  *
107  *   RELOC_TARGET_BITSIZE (rval): How many bits are to be replaced
108  * with the bits of the relocation value.  It may be assumed by the
109  * code that the relocation value will fit into this many bits.  This
110  * may be larger than RELOC_TARGET_SIZE if such be useful.
111  *
112  *
113  *              Things I haven't implemented
114  *              ----------------------------
115  *
116  *    Values for RELOC_TARGET_SIZE other than 0, 1, or 2.
117  *
118  *    Pc relative relocation for External references.
119  *
120  *
121  */
122
123
124 /* Default macros */
125 #ifndef RELOC_ADDRESS
126
127 #define RELOC_ADDRESS(r)                ((r)->r_address)
128 #define RELOC_EXTERN_P(r)               ((r)->r_extern)
129 #define RELOC_TYPE(r)                   ((r)->r_symbolnum)
130 #define RELOC_SYMBOL(r)                 ((r)->r_symbolnum)
131 #define RELOC_MEMORY_SUB_P(r)           0
132 #define RELOC_MEMORY_ADD_P(r)           1
133 #undef RELOC_ADD_EXTRA
134 #define RELOC_PCREL_P(r)                ((r)->r_pcrel)
135 #define RELOC_VALUE_RIGHTSHIFT(r)       0
136 #if defined(RTLD) && defined(SUN_COMPAT)
137 #define RELOC_TARGET_SIZE(r)            (2)     /* !!!!! Sun BUG compatible */
138 #else
139 #define RELOC_TARGET_SIZE(r)            ((r)->r_length)
140 #endif
141 #define RELOC_TARGET_BITPOS(r)          0
142 #define RELOC_TARGET_BITSIZE(r)         32
143
144 #endif
145
146 #ifdef nounderscore
147 #define LPREFIX '.'
148 #else
149 #define LPREFIX 'L'
150 #endif
151
152 #ifndef TEXT_START
153 #define TEXT_START(x)           N_TXTADDR(x)
154 #endif
155
156 #ifndef DATA_START
157 #define DATA_START(x)           N_DATADDR(x)
158 #endif
159
160 /* If a this type of symbol is encountered, its name is a warning
161    message to print each time the symbol referenced by the next symbol
162    table entry is referenced.
163
164    This feature may be used to allow backwards compatibility with
165    certain functions (eg. gets) but to discourage programmers from
166    their use.
167
168    So if, for example, you wanted to have ld print a warning whenever
169    the function "gets" was used in their C program, you would add the
170    following to the assembler file in which gets is defined:
171
172         .stabs "Obsolete function \"gets\" referenced",30,0,0,0
173         .stabs "_gets",1,0,0,0
174
175    These .stabs do not necessarily have to be in the same file as the
176    gets function, they simply must exist somewhere in the compilation.  */
177
178 #ifndef N_WARNING
179 #define N_WARNING 0x1E          /* Warning message to print if symbol
180                                    included */
181 #endif                          /* This is input to ld */
182
183 /* Special global symbol types understood by GNU LD.  */
184
185 /* The following type indicates the definition of a symbol as being
186    an indirect reference to another symbol.  The other symbol
187    appears as an undefined reference, immediately following this symbol.
188
189    Indirection is asymmetrical.  The other symbol's value will be used
190    to satisfy requests for the indirect symbol, but not vice versa.
191    If the other symbol does not have a definition, libraries will
192    be searched to find a definition.
193
194    So, for example, the following two lines placed in an assembler
195    input file would result in an object file which would direct gnu ld
196    to resolve all references to symbol "foo" as references to symbol
197    "bar".
198
199         .stabs "_foo",11,0,0,0
200         .stabs "_bar",1,0,0,0
201
202    Note that (11 == (N_INDR | N_EXT)) and (1 == (N_UNDF | N_EXT)).  */
203
204 #ifndef N_INDR
205 #define N_INDR 0xa
206 #endif
207
208 /* The following symbols refer to set elements.  These are expected
209    only in input to the loader; they should not appear in loader
210    output (unless relocatable output is requested).  To be recognized
211    by the loader, the input symbols must have their N_EXT bit set.
212    All the N_SET[ATDB] symbols with the same name form one set.  The
213    loader collects all of these elements at load time and outputs a
214    vector for each name.
215    Space (an array of 32 bit words) is allocated for the set in the
216    data section, and the n_value field of each set element value is
217    stored into one word of the array.
218    The first word of the array is the length of the set (number of
219    elements).  The last word of the vector is set to zero for possible
220    use by incremental loaders.  The array is ordered by the linkage
221    order; the first symbols which the linker encounters will be first
222    in the array.
223
224    In C syntax this looks like:
225
226         struct set_vector {
227           unsigned int length;
228           unsigned int vector[length];
229           unsigned int always_zero;
230         };
231
232    Before being placed into the array, each element is relocated
233    according to its type.  This allows the loader to create an array
234    of pointers to objects automatically.  N_SETA type symbols will not
235    be relocated.
236
237    The address of the set is made into an N_SETV symbol
238    whose name is the same as the name of the set.
239    This symbol acts like a N_DATA global symbol
240    in that it can satisfy undefined external references.
241
242    For the purposes of determining whether or not to load in a library
243    file, set element definitions are not considered "real
244    definitions"; they will not cause the loading of a library
245    member.
246
247    If relocatable output is requested, none of this processing is
248    done.  The symbols are simply relocated and passed through to the
249    output file.
250
251    So, for example, the following three lines of assembler code
252    (whether in one file or scattered between several different ones)
253    will produce a three element vector (total length is five words;
254    see above), referenced by the symbol "_xyzzy", which will have the
255    addresses of the routines _init1, _init2, and _init3.
256
257    *NOTE*: If symbolic addresses are used in the n_value field of the
258    defining .stabs, those symbols must be defined in the same file as
259    that containing the .stabs.
260
261         .stabs "_xyzzy",23,0,0,_init1
262         .stabs "_xyzzy",23,0,0,_init2
263         .stabs "_xyzzy",23,0,0,_init3
264
265    Note that (23 == (N_SETT | N_EXT)).  */
266
267 #ifndef N_SETA
268 #define N_SETA  0x14            /* Absolute set element symbol */
269 #endif                          /* This is input to LD, in a .o file.  */
270
271 #ifndef N_SETT
272 #define N_SETT  0x16            /* Text set element symbol */
273 #endif                          /* This is input to LD, in a .o file.  */
274
275 #ifndef N_SETD
276 #define N_SETD  0x18            /* Data set element symbol */
277 #endif                          /* This is input to LD, in a .o file. */
278
279 #ifndef N_SETB
280 #define N_SETB  0x1A            /* Bss set element symbol */
281 #endif                          /* This is input to LD, in a .o file. */
282
283 /* Macros dealing with the set element symbols defined in a.out.h */
284 #define SET_ELEMENT_P(x)        ((x) >= N_SETA && (x) <= (N_SETB|N_EXT))
285 #define TYPE_OF_SET_ELEMENT(x)  ((x) - N_SETA + N_ABS)
286
287 #ifndef N_SETV
288 #define N_SETV  0x1C            /* Pointer to set vector in data area. */
289 #endif                          /* This is output from LD. */
290
291
292 #ifndef __GNU_STAB__
293 /* Line number for the data section.  This is to be used to describe
294    the source location of a variable declaration. */
295 #ifndef N_DSLINE
296 #define N_DSLINE (N_SLINE+N_DATA-N_TEXT)
297 #endif
298
299 /* Line number for the bss section.  This is to be used to describe
300    the source location of a variable declaration.  */
301 #ifndef N_BSLINE
302 #define N_BSLINE (N_SLINE+N_BSS-N_TEXT)
303 #endif
304 #endif /* not __GNU_STAB__ */
305
306
307 /* Number of buckets in symbol hash table */
308 #define SYMTABSIZE      1009
309
310 /* # of global symbols referenced and not defined.  */
311 extern int      undefined_global_sym_count;
312
313 /* # of weak symbols referenced and not defined.  */
314 extern int      undefined_weak_sym_count;
315
316 /* # of undefined symbols referenced by shared objects */
317 extern int      undefined_shobj_sym_count;
318
319 /* # of multiply defined symbols. */
320 extern int      multiple_def_count;
321
322 /* # of common symbols. */
323 extern int      common_defined_global_count;
324
325 /* # of warning symbols encountered. */
326 extern int      warn_sym_count;
327 extern int      list_warning_symbols;
328
329 /*
330  * Define a linked list of strings which define symbols which should be
331  * treated as set elements even though they aren't.  Any symbol with a prefix
332  * matching one of these should be treated as a set element.
333  *
334  * This is to make up for deficiencies in many assemblers which aren't willing
335  * to pass any stabs through to the loader which they don't understand.
336  */
337 struct string_list_element {
338         char *str;
339         struct string_list_element *next;
340 };
341
342 struct glosym;
343 #ifndef __symbol_defined__
344 #define __symbol_defined__
345 typedef struct glosym symbol;
346 #endif
347
348 extern symbol   *entry_symbol;          /* the entry symbol, if any */
349 extern symbol   *edata_symbol;          /* the symbol _edata */
350 extern symbol   *etext_symbol;          /* the symbol _etext */
351 extern symbol   *end_symbol;            /* the symbol _end */
352
353 /*
354  * Section start addresses.
355  */
356 extern int      text_size;              /* total size of text. */
357 extern int      text_start;             /* start of text */
358 extern int      text_pad;               /* clear space between text and data */
359 extern int      data_size;              /* total size of data. */
360 extern int      data_start;             /* start of data */
361 extern int      data_pad;               /* part of bss segment within data */
362
363 extern int      bss_size;               /* total size of bss. */
364 extern int      bss_start;              /* start of bss */
365
366 extern int      text_reloc_size;        /* total size of text relocation. */
367 extern int      data_reloc_size;        /* total size of data relocation. */
368
369 extern int              magic;          /* Output file magic. */
370 extern int              relocatable_output;
371
372 /* Size of a page. */
373 extern int      page_size;
374
375 extern char     **search_dirs;  /* Directories to search for libraries. */
376 extern int      n_search_dirs;  /* Length of above. */
377
378 extern int      write_map;      /* write a load map (`-M') */
379
380 #include "dynamic.h"