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 $
6 * This code is derived from software copyrighted by the Free Software
9 * Modified 1991 by Donn Seeley at UUNET Technologies, Inc.
19 #define min(a,b) ((a) < (b) ? (a) : (b))
22 /* If compiled with GNU C, use the built-in alloca */
23 #if defined(__GNUC__) || defined(sparc)
24 #define alloca __builtin_alloca
30 /* Macro to control the number of undefined references printed */
31 #define MAX_UREFS_PRINTED 10
33 /* Align to power-of-two boundary */
34 #define PALIGN(x,p) (((x) + (u_long)(p) - 1) & (-(u_long)(p)))
36 /* Align to machine dependent boundary */
37 #define MALIGN(x) PALIGN(x,MAX_ALIGNMENT)
39 /* Define this to specify the default executable format. */
42 #define DEFAULT_MAGIC QMAGIC
45 #define DEFAULT_MAGIC ZMAGIC
49 #ifdef DEMANGLE_CPLUSPLUS
50 extern char *demangle(char*);
52 #define demangle(name) name
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:
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.
64 * RELOC_ADDRESS (rval): Offset into the current section of the
65 * <whatever> to be relocated. *Must be an lvalue*.
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*.
73 * RELOC_TYPE (rval): If this entry was fully resolved upon
74 * entering the loader, what type should it be relocated as?
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*.
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
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*.
89 * RELOC_PCREL_P (rval): True if the relocation value described is
92 * RELOC_VALUE_RIGHTSHIFT (rval): Number of bits right to shift the
93 * final relocation value before putting it where it belongs.
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.
103 * RELOC_TARGET_BITPOS (rval): The starting bit position within the
104 * object described in RELOC_TARGET_SIZE in which the relocation value
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.
113 * Things I haven't implemented
114 * ----------------------------
116 * Values for RELOC_TARGET_SIZE other than 0, 1, or 2.
118 * Pc relative relocation for External references.
125 #ifndef RELOC_ADDRESS
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 */
139 #define RELOC_TARGET_SIZE(r) ((r)->r_length)
141 #define RELOC_TARGET_BITPOS(r) 0
142 #define RELOC_TARGET_BITSIZE(r) 32
153 #define TEXT_START(x) N_TXTADDR(x)
157 #define DATA_START(x) N_DATADDR(x)
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.
164 This feature may be used to allow backwards compatibility with
165 certain functions (eg. gets) but to discourage programmers from
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:
172 .stabs "Obsolete function \"gets\" referenced",30,0,0,0
173 .stabs "_gets",1,0,0,0
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. */
179 #define N_WARNING 0x1E /* Warning message to print if symbol
181 #endif /* This is input to ld */
183 /* Special global symbol types understood by GNU LD. */
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.
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.
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
199 .stabs "_foo",11,0,0,0
200 .stabs "_bar",1,0,0,0
202 Note that (11 == (N_INDR | N_EXT)) and (1 == (N_UNDF | N_EXT)). */
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
224 In C syntax this looks like:
228 unsigned int vector[length];
229 unsigned int always_zero;
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
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.
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
247 If relocatable output is requested, none of this processing is
248 done. The symbols are simply relocated and passed through to the
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.
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.
261 .stabs "_xyzzy",23,0,0,_init1
262 .stabs "_xyzzy",23,0,0,_init2
263 .stabs "_xyzzy",23,0,0,_init3
265 Note that (23 == (N_SETT | N_EXT)). */
268 #define N_SETA 0x14 /* Absolute set element symbol */
269 #endif /* This is input to LD, in a .o file. */
272 #define N_SETT 0x16 /* Text set element symbol */
273 #endif /* This is input to LD, in a .o file. */
276 #define N_SETD 0x18 /* Data set element symbol */
277 #endif /* This is input to LD, in a .o file. */
280 #define N_SETB 0x1A /* Bss set element symbol */
281 #endif /* This is input to LD, in a .o file. */
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)
288 #define N_SETV 0x1C /* Pointer to set vector in data area. */
289 #endif /* This is output from LD. */
293 /* Line number for the data section. This is to be used to describe
294 the source location of a variable declaration. */
296 #define N_DSLINE (N_SLINE+N_DATA-N_TEXT)
299 /* Line number for the bss section. This is to be used to describe
300 the source location of a variable declaration. */
302 #define N_BSLINE (N_SLINE+N_BSS-N_TEXT)
304 #endif /* not __GNU_STAB__ */
307 /* Number of buckets in symbol hash table */
308 #define SYMTABSIZE 1009
310 /* # of global symbols referenced and not defined. */
311 extern int undefined_global_sym_count;
313 /* # of weak symbols referenced and not defined. */
314 extern int undefined_weak_sym_count;
316 /* # of undefined symbols referenced by shared objects */
317 extern int undefined_shobj_sym_count;
319 /* # of multiply defined symbols. */
320 extern int multiple_def_count;
322 /* # of common symbols. */
323 extern int common_defined_global_count;
325 /* # of warning symbols encountered. */
326 extern int warn_sym_count;
327 extern int list_warning_symbols;
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.
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.
337 struct string_list_element {
339 struct string_list_element *next;
343 #ifndef __symbol_defined__
344 #define __symbol_defined__
345 typedef struct glosym symbol;
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 */
354 * Section start addresses.
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 */
363 extern int bss_size; /* total size of bss. */
364 extern int bss_start; /* start of bss */
366 extern int text_reloc_size; /* total size of text relocation. */
367 extern int data_reloc_size; /* total size of data relocation. */
369 extern int magic; /* Output file magic. */
370 extern int relocatable_output;
372 /* Size of a page. */
373 extern int page_size;
375 extern char **search_dirs; /* Directories to search for libraries. */
376 extern int n_search_dirs; /* Length of above. */
378 extern int write_map; /* write a load map (`-M') */