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