Forgot half of the changes for CPUSTATES and DK_NDRIVE, sorry.
[unix-history] / gnu / usr.bin / ld / ld.h
CommitLineData
80f25b52 1/* $Id: ld.h,v 1.3 1993/11/18 20:52:34 jkh Exp $ */
1136f72d
PR
2/*-
3 * This code is derived from software copyrighted by the Free Software
4 * Foundation.
5 *
6 * Modified 1991 by Donn Seeley at UUNET Technologies, Inc.
7 */
8
9#define SUN_COMPAT
10
11#ifndef N_SIZE
12#define N_SIZE 0xc
13#endif
14
15#ifndef min
16#define min(a,b) ((a) < (b) ? (a) : (b))
17#endif
18
19#ifndef __P
20#ifndef __STDC__
21#define __P(a) ()
22#else
23#define __P(a) a
24#endif
25#endif
26
27/* If compiled with GNU C, use the built-in alloca */
28#if defined(__GNUC__) || defined(sparc)
29#define alloca __builtin_alloca
30#endif
31
32#include "md.h"
33#include "link.h"
34
35/* Macro to control the number of undefined references printed */
36#define MAX_UREFS_PRINTED 10
37
38/* Align to power-of-two boundary */
39#define PALIGN(x,p) (((x) + (u_long)(p) - 1) & (-(u_long)(p)))
40
41/* Align to machine dependent boundary */
42#define MALIGN(x) PALIGN(x,MAX_ALIGNMENT)
43
44/* Size of a page; obtained from the operating system. */
45
46int page_size;
47
48/* Name this program was invoked by. */
49
50char *progname;
51\f
52/* System dependencies */
53
54/* Define this to specify the default executable format. */
55
56#ifndef DEFAULT_MAGIC
57#define DEFAULT_MAGIC ZMAGIC
58#endif
59
60#ifdef QMAGIC
61int oldmagic;
62#endif
63
64
65/*
66 * Ok. Following are the relocation information macros. If your
67 * system should not be able to use the default set (below), you must
68 * define the following:
69
70 * relocation_info: This must be typedef'd (or #define'd) to the type
71 * of structure that is stored in the relocation info section of your
72 * a.out files. Often this is defined in the a.out.h for your system.
73 *
74 * RELOC_ADDRESS (rval): Offset into the current section of the
75 * <whatever> to be relocated. *Must be an lvalue*.
76 *
77 * RELOC_EXTERN_P (rval): Is this relocation entry based on an
78 * external symbol (1), or was it fully resolved upon entering the
79 * loader (0) in which case some combination of the value in memory
80 * (if RELOC_MEMORY_ADD_P) and the extra (if RELOC_ADD_EXTRA) contains
81 * what the value of the relocation actually was. *Must be an lvalue*.
82 *
83 * RELOC_TYPE (rval): If this entry was fully resolved upon
84 * entering the loader, what type should it be relocated as?
85 *
86 * RELOC_SYMBOL (rval): If this entry was not fully resolved upon
87 * entering the loader, what is the index of it's symbol in the symbol
88 * table? *Must be a lvalue*.
89 *
90 * RELOC_MEMORY_ADD_P (rval): This should return true if the final
91 * relocation value output here should be added to memory, or if the
92 * section of memory described should simply be set to the relocation
93 * value.
94 *
95 * RELOC_ADD_EXTRA (rval): (Optional) This macro, if defined, gives
96 * an extra value to be added to the relocation value based on the
97 * individual relocation entry. *Must be an lvalue if defined*.
98 *
99 * RELOC_PCREL_P (rval): True if the relocation value described is
100 * pc relative.
101 *
102 * RELOC_VALUE_RIGHTSHIFT (rval): Number of bits right to shift the
103 * final relocation value before putting it where it belongs.
104 *
105 * RELOC_TARGET_SIZE (rval): log to the base 2 of the number of
106 * bytes of size this relocation entry describes; 1 byte == 0; 2 bytes
107 * == 1; 4 bytes == 2, and etc. This is somewhat redundant (we could
108 * do everything in terms of the bit operators below), but having this
109 * macro could end up producing better code on machines without fancy
110 * bit twiddling. Also, it's easier to understand/code big/little
111 * endian distinctions with this macro.
112 *
113 * RELOC_TARGET_BITPOS (rval): The starting bit position within the
114 * object described in RELOC_TARGET_SIZE in which the relocation value
115 * will go.
116 *
117 * RELOC_TARGET_BITSIZE (rval): How many bits are to be replaced
118 * with the bits of the relocation value. It may be assumed by the
119 * code that the relocation value will fit into this many bits. This
120 * may be larger than RELOC_TARGET_SIZE if such be useful.
121 *
122 *
123 * Things I haven't implemented
124 * ----------------------------
125 *
126 * Values for RELOC_TARGET_SIZE other than 0, 1, or 2.
127 *
128 * Pc relative relocation for External references.
129 *
130 *
131 */
132
133
134/* Default macros */
135#ifndef RELOC_ADDRESS
136
137#define RELOC_ADDRESS(r) ((r)->r_address)
138#define RELOC_EXTERN_P(r) ((r)->r_extern)
139#define RELOC_TYPE(r) ((r)->r_symbolnum)
140#define RELOC_SYMBOL(r) ((r)->r_symbolnum)
141#define RELOC_MEMORY_SUB_P(r) 0
142#define RELOC_MEMORY_ADD_P(r) 1
143#undef RELOC_ADD_EXTRA
144#define RELOC_PCREL_P(r) ((r)->r_pcrel)
145#define RELOC_VALUE_RIGHTSHIFT(r) 0
146#if defined(RTLD) && defined(SUN_COMPAT)
147#define RELOC_TARGET_SIZE(r) (2) /* !!!!! Sun BUG compatible */
148#else
149#define RELOC_TARGET_SIZE(r) ((r)->r_length)
150#endif
151#define RELOC_TARGET_BITPOS(r) 0
152#define RELOC_TARGET_BITSIZE(r) 32
153
154#define RELOC_JMPTAB_P(r) ((r)->r_jmptable)
155#define RELOC_BASEREL_P(r) ((r)->r_baserel)
156#define RELOC_RELATIVE_P(r) ((r)->r_relative)
157#define RELOC_COPY_P(r) ((r)->r_copy)
158#define RELOC_LAZY_P(r) ((r)->r_jmptable)
159
160#define CHECK_GOT_RELOC(r) ((r)->r_pcrel)
161
162#endif
163
164/*
165 * Internal representation of relocation types
166 */
167#define RELTYPE_EXTERN 1
168#define RELTYPE_JMPSLOT 2
169#define RELTYPE_BASEREL 4
170#define RELTYPE_RELATIVE 8
171#define RELTYPE_COPY 16
172
173#ifdef nounderscore
174#define LPREFIX '.'
175#else
176#define LPREFIX 'L'
177#endif
178
179#ifndef TEXT_START
180#define TEXT_START(x) N_TXTADDR(x)
181#endif
182
183#ifndef DATA_START
184#define DATA_START(x) N_DATADDR(x)
185#endif
186\f
187/* If a this type of symbol is encountered, its name is a warning
188 message to print each time the symbol referenced by the next symbol
189 table entry is referenced.
190
191 This feature may be used to allow backwards compatibility with
192 certain functions (eg. gets) but to discourage programmers from
193 their use.
194
195 So if, for example, you wanted to have ld print a warning whenever
196 the function "gets" was used in their C program, you would add the
197 following to the assembler file in which gets is defined:
198
199 .stabs "Obsolete function \"gets\" referenced",30,0,0,0
200 .stabs "_gets",1,0,0,0
201
202 These .stabs do not necessarily have to be in the same file as the
203 gets function, they simply must exist somewhere in the compilation. */
204
205#ifndef N_WARNING
206#define N_WARNING 0x1E /* Warning message to print if symbol
207 included */
208#endif /* This is input to ld */
209
210/* Special global symbol types understood by GNU LD. */
211
212/* The following type indicates the definition of a symbol as being
213 an indirect reference to another symbol. The other symbol
214 appears as an undefined reference, immediately following this symbol.
215
216 Indirection is asymmetrical. The other symbol's value will be used
217 to satisfy requests for the indirect symbol, but not vice versa.
218 If the other symbol does not have a definition, libraries will
219 be searched to find a definition.
220
221 So, for example, the following two lines placed in an assembler
222 input file would result in an object file which would direct gnu ld
223 to resolve all references to symbol "foo" as references to symbol
224 "bar".
225
226 .stabs "_foo",11,0,0,0
227 .stabs "_bar",1,0,0,0
228
229 Note that (11 == (N_INDR | N_EXT)) and (1 == (N_UNDF | N_EXT)). */
230
231#ifndef N_INDR
232#define N_INDR 0xa
233#endif
234
235/* The following symbols refer to set elements. These are expected
236 only in input to the loader; they should not appear in loader
237 output (unless relocatable output is requested). To be recognized
238 by the loader, the input symbols must have their N_EXT bit set.
239 All the N_SET[ATDB] symbols with the same name form one set. The
240 loader collects all of these elements at load time and outputs a
241 vector for each name.
242 Space (an array of 32 bit words) is allocated for the set in the
243 data section, and the n_value field of each set element value is
244 stored into one word of the array.
245 The first word of the array is the length of the set (number of
246 elements). The last word of the vector is set to zero for possible
247 use by incremental loaders. The array is ordered by the linkage
248 order; the first symbols which the linker encounters will be first
249 in the array.
250
251 In C syntax this looks like:
252
253 struct set_vector {
254 unsigned int length;
255 unsigned int vector[length];
256 unsigned int always_zero;
257 };
258
259 Before being placed into the array, each element is relocated
260 according to its type. This allows the loader to create an array
261 of pointers to objects automatically. N_SETA type symbols will not
262 be relocated.
263
264 The address of the set is made into an N_SETV symbol
265 whose name is the same as the name of the set.
266 This symbol acts like a N_DATA global symbol
267 in that it can satisfy undefined external references.
268
269 For the purposes of determining whether or not to load in a library
270 file, set element definitions are not considered "real
271 definitions"; they will not cause the loading of a library
272 member.
273
274 If relocatable output is requested, none of this processing is
275 done. The symbols are simply relocated and passed through to the
276 output file.
277
278 So, for example, the following three lines of assembler code
279 (whether in one file or scattered between several different ones)
280 will produce a three element vector (total length is five words;
281 see above), referenced by the symbol "_xyzzy", which will have the
282 addresses of the routines _init1, _init2, and _init3.
283
284 *NOTE*: If symbolic addresses are used in the n_value field of the
285 defining .stabs, those symbols must be defined in the same file as
286 that containing the .stabs.
287
288 .stabs "_xyzzy",23,0,0,_init1
289 .stabs "_xyzzy",23,0,0,_init2
290 .stabs "_xyzzy",23,0,0,_init3
291
292 Note that (23 == (N_SETT | N_EXT)). */
293
294#ifndef N_SETA
295#define N_SETA 0x14 /* Absolute set element symbol */
296#endif /* This is input to LD, in a .o file. */
297
298#ifndef N_SETT
299#define N_SETT 0x16 /* Text set element symbol */
300#endif /* This is input to LD, in a .o file. */
301
302#ifndef N_SETD
303#define N_SETD 0x18 /* Data set element symbol */
304#endif /* This is input to LD, in a .o file. */
305
306#ifndef N_SETB
307#define N_SETB 0x1A /* Bss set element symbol */
308#endif /* This is input to LD, in a .o file. */
309
310/* Macros dealing with the set element symbols defined in a.out.h */
311#define SET_ELEMENT_P(x) ((x) >= N_SETA && (x) <= (N_SETB|N_EXT))
312#define TYPE_OF_SET_ELEMENT(x) ((x) - N_SETA + N_ABS)
313
314#ifndef N_SETV
315#define N_SETV 0x1C /* Pointer to set vector in data area. */
316#endif /* This is output from LD. */
317
318
319#ifndef __GNU_STAB__
320
321/* Line number for the data section. This is to be used to describe
322 the source location of a variable declaration. */
323#ifndef N_DSLINE
324#define N_DSLINE (N_SLINE+N_DATA-N_TEXT)
325#endif
326
327/* Line number for the bss section. This is to be used to describe
328 the source location of a variable declaration. */
329#ifndef N_BSLINE
330#define N_BSLINE (N_SLINE+N_BSS-N_TEXT)
331#endif
332
333#endif /* not __GNU_STAB__ */
334\f
335/* Symbol table */
336
337/*
338 * Global symbol data is recorded in these structures, one for each global
339 * symbol. They are found via hashing in 'symtab', which points to a vector
340 * of buckets. Each bucket is a chain of these structures through the link
341 * field.
342 */
343
344typedef struct glosym {
345 /* Pointer to next symbol in this symbol's hash bucket. */
80f25b52 346 struct glosym *link;
1136f72d 347 /* Name of this symbol. */
80f25b52 348 char *name;
1136f72d 349 /* Value of this symbol as a global symbol. */
80f25b52 350 long value;
1136f72d
PR
351 /*
352 * Chain of external 'nlist's in files for this symbol, both defs and
353 * refs.
354 */
355 struct localsymbol *refs;
356 /*
357 * Any warning message that might be associated with this symbol from
358 * an N_WARNING symbol encountered.
359 */
80f25b52 360 char *warning;
1136f72d
PR
361 /*
362 * Nonzero means definitions of this symbol as common have been seen,
363 * and the value here is the largest size specified by any of them.
364 */
80f25b52 365 int max_common_size;
1136f72d
PR
366 /*
367 * For relocatable_output, records the index of this global sym in
368 * the symbol table to be written, with the first global sym given
369 * index 0.
370 */
80f25b52 371 int symbolnum;
1136f72d
PR
372 /*
373 * For dynamically linked output, records the index in the RRS
374 * symbol table.
375 */
80f25b52 376 int rrs_symbolnum;
1136f72d
PR
377 /*
378 * Nonzero means a definition of this global symbol is known to
379 * exist. Library members should not be loaded on its account.
380 */
80f25b52 381 char defined;
1136f72d
PR
382 /*
383 * Nonzero means a reference to this global symbol has been seen in a
384 * file that is surely being loaded. A value higher than 1 is the
385 * n_type code for the symbol's definition.
386 */
80f25b52 387 char referenced;
1136f72d
PR
388 /*
389 * A count of the number of undefined references printed for a
390 * specific symbol. If a symbol is unresolved at the end of
391 * digest_symbols (and the loading run is supposed to produce
392 * relocatable output) do_file_warnings keeps track of how many
393 * unresolved reference error messages have been printed for each
394 * symbol here. When the number hits MAX_UREFS_PRINTED, messages
395 * stop.
396 */
80f25b52 397 unsigned char undef_refs;
1136f72d
PR
398 /*
399 * 1 means that this symbol has multiple definitions. 2 means that
400 * it has multiple definitions, and some of them are set elements,
401 * one of which has been printed out already.
402 */
80f25b52 403 unsigned char multiply_defined;
1136f72d 404 /* Nonzero means print a message at all refs or defs of this symbol */
80f25b52 405 char trace;
1136f72d
PR
406
407 /*
408 * For symbols of type N_INDR, this points at the real symbol.
409 */
410 struct glosym *alias;
411
412 /*
413 * Count number of elements in set vector if symbol is of type N_SETV
414 */
415 int setv_count;
416
417 /* Dynamic lib support */
418
419 /*
420 * Nonzero means a definition of this global symbol has been found
421 * in a shared object. These symbols do not go into the symbol
422 * section of the resulting a.out file. They *do* go into the
423 * dynamic link information segment.
424 */
80f25b52 425 char so_defined;
1136f72d 426
80f25b52
JH
427 /* Size of symbol as determined by N_SIZE symbols in object files */
428 int size;
1136f72d 429
c62b29f8
JH
430 /* Auxialiary info to put in the `nz_other' field of the
431 * RRS symbol table. Used by the run-time linker to resolve
432 * references to function addresses from within shared objects.
433 */
434 int aux;
435#define RRS_FUNC 2
436
1136f72d
PR
437 /*
438 * Chain of external 'nlist's in shared objects for this symbol, both
439 * defs and refs.
440 */
441 struct localsymbol *sorefs;
442
443 /* The offset into one of the RRS tables, -1 if not used */
444 long jmpslot_offset;
445 char jmpslot_claimed;
446
447 long gotslot_offset;
448 char gotslot_claimed;
449
450 char cpyreloc_reserved;
451 char cpyreloc_claimed;
452
453 /* The local symbol that gave this global symbol its definition */
454 struct nlist *def_nlist;
455} symbol;
456
457/* Number of buckets in symbol hash table */
458#define TABSIZE 1009
459
460/* The symbol hash table: a vector of TABSIZE pointers to struct glosym. */
461symbol *symtab[TABSIZE];
462#define FOR_EACH_SYMBOL(i,sp) { \
463 int i; \
464 for (i = 0; i < TABSIZE; i++) { \
465 register symbol *sp; \
466 for (sp = symtab[i]; sp; sp = sp->link)
467
468#define END_EACH_SYMBOL }}
469
470/* Number of symbols in symbol hash table. */
471int num_hash_tab_syms;
472
473/* Count the number of nlist entries that are for local symbols.
474 This count and the three following counts
475 are incremented as as symbols are entered in the symbol table. */
476int local_sym_count;
477
478/* Count number of nlist entries that are for local symbols
479 whose names don't start with L. */
480int non_L_local_sym_count;
481
482/* Count the number of nlist entries for debugger info. */
483int debugger_sym_count;
484
485/* Count the number of global symbols referenced and not defined. */
486int undefined_global_sym_count;
487
488/* Count the number of symbols referenced from shared objects and not defined */
489int undefined_shobj_sym_count;
490
491/* Count the number of global symbols multiply defined. */
492int multiple_def_count;
493
494/* Count the number of defined global symbols.
495 Each symbol is counted only once
496 regardless of how many different nlist entries refer to it,
497 since the output file will need only one nlist entry for it.
498 This count is computed by `digest_symbols';
499 it is undefined while symbols are being loaded. */
500int defined_global_sym_count;
501
502/* Count the number of symbols defined through common declarations.
503 This count is kept in symdef_library, linear_library, and
504 enter_global_ref. It is incremented when the defined flag is set
505 in a symbol because of a common definition, and decremented when
506 the symbol is defined "for real" (ie. by something besides a common
507 definition). */
508int common_defined_global_count;
509
510/* Count the number of linker defined symbols.
511 XXX - Currently, only __DYNAMIC and _G_O_T_ go here if required,
512 perhaps _etext, _edata and _end should go here too */
513int special_sym_count;
514
515/* Count number of aliased symbols */
516int global_alias_count;
517
518/* Count number of set element type symbols and the number of separate
519 vectors which these symbols will fit into */
520int set_symbol_count;
521int set_vector_count;
522
523/* Define a linked list of strings which define symbols which should
524 be treated as set elements even though they aren't. Any symbol
525 with a prefix matching one of these should be treated as a set
526 element.
527
528 This is to make up for deficiencies in many assemblers which aren't
529 willing to pass any stabs through to the loader which they don't
530 understand. */
531struct string_list_element {
532 char *str;
533 struct string_list_element *next;
534};
535
536struct string_list_element *set_element_prefixes;
537
538/* Count the number of warning symbols encountered. */
539int warning_count;
540
541/* 1 => write load map. */
542int write_map;
543
544/* 1 => write relocation into output file so can re-input it later. */
545int relocatable_output;
546
547/* Nonzero means ptr to symbol entry for symbol to use as start addr.
548 -e sets this. */
549symbol *entry_symbol;
550
551symbol *edata_symbol; /* the symbol _edata */
552symbol *etext_symbol; /* the symbol _etext */
553symbol *end_symbol; /* the symbol _end */
554symbol *got_symbol; /* the symbol __GLOBAL_OFFSET_TABLE_ */
555symbol *dynamic_symbol; /* the symbol __DYNAMIC */
556
557\f
558/*
559 * Each input file, and each library member ("subfile") being loaded, has a
560 * `file_entry' structure for it.
561 *
562 * For files specified by command args, these are contained in the vector which
563 * `file_table' points to.
564 *
565 * For library members, they are dynamically allocated, and chained through the
566 * `chain' field. The chain is found in the `subfiles' field of the
567 * `file_entry'. The `file_entry' objects for the members have `superfile'
568 * fields pointing to the one for the library.
569 */
570
571struct file_entry {
572 /* Name of this file. */
573 char *filename;
574
575 /*
576 * Name to use for the symbol giving address of text start Usually
577 * the same as filename, but for a file spec'd with -l this is the -l
578 * switch itself rather than the filename.
579 */
580 char *local_sym_name;
581
582 /* Describe the layout of the contents of the file */
583
584 /* The file's a.out header. */
585 struct exec header;
586 /* Offset in file of GDB symbol segment, or 0 if there is none. */
587 int symseg_offset;
588
589 /* Describe data from the file loaded into core */
590
591 /*
592 * Symbol table of the file.
593 * We need access to the global symbol early, ie. before
594 * symbols are asssigned there final values. gotslot_offset is
595 * here because GOT entries may be generated for local symbols.
596 */
597 struct localsymbol {
598 struct nzlist nzlist;
599 struct glosym *symbol;
600 struct localsymbol *next;
601 long gotslot_offset;
602 char gotslot_claimed;
80f25b52
JH
603 char rename;
604 int symbolnum;
1136f72d
PR
605 } *symbols;
606
607 /* Number of symbols in above array. */
608 int nsymbols;
609
610 /* Size in bytes of string table. */
611 int string_size;
612
613 /*
614 * Pointer to the string table. The string table is not kept in core
615 * all the time, but when it is in core, its address is here.
616 */
617 char *strings;
618
619 /* Offset of string table (normally N_STROFF() + 4) */
620 int strings_offset;
621
622 /* Next two used only if `relocatable_output' or if needed for */
623 /* output of undefined reference line numbers. */
624
625 /* Text reloc info saved by `write_text' for `coptxtrel'. */
626 struct relocation_info *textrel;
627 int ntextrel;
628
629 /* Data reloc info saved by `write_data' for `copdatrel'. */
630 struct relocation_info *datarel;
631 int ndatarel;
632
633 /* Relation of this file's segments to the output file */
634
635 /* Start of this file's text seg in the output file core image. */
636 int text_start_address;
637
638 /* Start of this file's data seg in the output file core image. */
639 int data_start_address;
640
641 /* Start of this file's bss seg in the output file core image. */
642 int bss_start_address;
643 /*
644 * Offset in bytes in the output file symbol table of the first local
645 * symbol for this file. Set by `write_file_symbols'.
646 */
647 int local_syms_offset;
648
649 /* For library members only */
650
651 /* For a library, points to chain of entries for the library members. */
652 struct file_entry *subfiles;
653
654 /*
655 * For a library member, offset of the member within the archive.
656 * Zero for files that are not library members.
657 */
658 int starting_offset;
659
660 /* Size of contents of this file, if library member. */
661 int total_size;
662
663 /* For library member, points to the library's own entry. */
664 struct file_entry *superfile;
665
666 /* For library member, points to next entry for next member. */
667 struct file_entry *chain;
668
669 /* 1 if file is a library. */
670 char library_flag;
671
672 /* 1 if file's header has been read into this structure. */
673 char header_read_flag;
674
675 /* 1 means search a set of directories for this file. */
676 char search_dirs_flag;
677
678 /*
679 * 1 means this is base file of incremental load. Do not load this
680 * file's text or data. Also default text_start to after this file's
681 * bss.
682 */
683 char just_syms_flag;
684
685 /* 1 means search for dynamic libraries (dependent on -B switch) */
686 char search_dynamic_flag;
687
688 /* version numbers of selected shared library */
689 int lib_major, lib_minor;
690
691 /* This entry is a shared object */
692 char is_dynamic;
80f25b52
JH
693
694 /* 1 if this entry is not a major player anymore */
695 char scrapped;
1136f72d
PR
696};
697
698typedef struct localsymbol localsymbol_t;
699
700/* Vector of entries for input files specified by arguments.
701 These are all the input files except for members of specified libraries. */
702struct file_entry *file_table;
703
704/* Length of that vector. */
705int number_of_files;
706
707/* Current link mode */
708#define DYNAMIC 1 /* Consider shared libraries */
709#define SYMBOLIC 2 /* Force symbolic resolution */
710#define FORCEARCHIVE 4 /* Force inclusion of all members
711 of archives */
712#define SHAREABLE 8 /* Build a shared object */
713int link_mode;
714
715/*
716 * Runtime Relocation Section (RRS).
717 * This describes the data structures that go into the output text and data
718 * segments to support the run-time linker. The RRS can be empty (plain old
719 * static linking), or can just exist of GOT and PLT entries (in case of
720 * statically linked PIC code).
721 */
722
723int rrs_section_type;
724#define RRS_NONE 0
725#define RRS_PARTIAL 1
726#define RRS_FULL 2
727
728int rrs_text_size;
729int rrs_data_size;
730int rrs_text_start;
731int rrs_data_start;
732
733/* Version number to put in __DYNAMIC (set by -V) */
734int soversion;
735
736/* When loading the text and data, we can avoid doing a close
737 and another open between members of the same library.
738
739 These two variables remember the file that is currently open.
740 Both are zero if no file is open.
741
742 See `each_file' and `file_close'. */
743
744struct file_entry *input_file;
745int input_desc;
746
747/* The name of the file to write; "a.out" by default. */
748
749char *output_filename;
750
751/* Descriptor for writing that file with `mywrite'. */
752
753int outdesc;
754
755/* Header for that file (filled in by `write_header'). */
756
757struct exec outheader;
758
759/* The following are computed by `digest_symbols'. */
760
761int text_size; /* total size of text of all input files. */
762int data_size; /* total size of data of all input files. */
763int bss_size; /* total size of bss of all input files. */
764int text_reloc_size; /* total size of text relocation of all input files. */
765int data_reloc_size; /* total size of data relocation of all input files. */
766
767/* Relocation offsets set by perform_relocation(). Defined globaly here
768 because some of the RRS routines need access to them */
769int text_relocation;
770int data_relocation;
771int bss_relocation;
772int pc_relocation;
773
774/* Specifications of start and length of the area reserved at the end
775 of the data segment for the set vectors. Computed in 'digest_symbols' */
776int set_sect_start;
777int set_sect_size;
778
779/* Amount of cleared space to leave between the text and data segments. */
780int text_pad;
781
782/* Amount of bss segment to include as part of the data segment. */
783int data_pad;
784
785
786/* Record most of the command options. */
787
788/* Address we assume the text section will be loaded at.
789 We relocate symbols and text and data for this, but we do not
790 write any padding in the output file for it. */
791int text_start;
792
793/* Offset of default entry-pc within the text section. */
794int entry_offset;
795
796/* Address we decide the data section will be loaded at. */
797int data_start;
798int bss_start;
799
800/* Keep a list of any symbols referenced from the command line (so
801 that error messages for these guys can be generated). This list is
802 zero terminated. */
803struct glosym **cmdline_references;
804int cl_refs_allocated;
805
806/*
807 * Actual vector of directories to search; this contains those specified with
808 * -L plus the standard ones.
809 */
810char **search_dirs;
811
812/* Length of the vector `search_dirs'. */
813int n_search_dirs;
814
815void digest_symbols __P((void));
816void load_symbols __P((void));
817void decode_command __P((int, char **));
818void read_header __P((int, struct file_entry *));
819void read_entry_symbols __P((int, struct file_entry *));
820void read_entry_strings __P((int, struct file_entry *));
821void read_entry_relocation __P((int, struct file_entry *));
822void write_output __P((void));
823void write_header __P((void));
824void write_text __P((void));
825void write_data __P((void));
826void write_rel __P((void));
827void write_syms __P((void));
828void write_symsegs __P((void));
829void mywrite ();
830
831/* In warnings.c: */
832void perror_name __P((char *));
833void perror_file __P((struct file_entry *));
834void fatal_with_file __P((char *, struct file_entry *, ...));
835void print_symbols __P((FILE *));
836char *get_file_name __P((struct file_entry *));
837void print_file_name __P((struct file_entry *, FILE *));
838void prline_file_name __P((struct file_entry *, FILE *));
839int do_warnings __P((FILE *));
840
841/* In etc.c: */
842void *xmalloc __P((int));
843void *xrealloc __P((void *, int));
844void fatal __P((char *, ...));
845void error __P((char *, ...));
846void padfile __P((int,int));
847char *concat __P((char *, char *, char *));
848int parse __P((char *, char *, char *));
849
850/* In symbol.c: */
851void symtab_init __P((int));
852symbol *getsym __P((char *)), *getsym_soft __P((char *));
853
854/* In lib.c: */
855void search_library __P((int, struct file_entry *));
856void read_shared_object __P((int, struct file_entry *));
857int findlib __P((struct file_entry *));
858
859/* In shlib.c: */
860char *findshlib __P((char *, int *, int *));
861void add_search_dir __P((char *));
862void std_search_dirs __P((char *));
863
864/* In rrs.c: */
865void init_rrs __P((void));
80f25b52 866int rrs_add_shobj __P((struct file_entry *));
1136f72d
PR
867void alloc_rrs_reloc __P((symbol *));
868void alloc_rrs_segment_reloc __P((struct relocation_info *));
869void alloc_rrs_jmpslot __P((symbol *));
870void alloc_rrs_gotslot __P((struct relocation_info *, localsymbol_t *));
871void alloc_rrs_copy_reloc __P((symbol *));
872
873/* In <md>.c */
874void md_init_header __P((struct exec *, int, int));
875long md_get_addend __P((struct relocation_info *, unsigned char *));
876void md_relocate __P((struct relocation_info *, long, unsigned char *, int));
877void md_make_jmpslot __P((jmpslot_t *, long, long));
878void md_fix_jmpslot __P((jmpslot_t *, long, u_long));
879int md_make_reloc __P((struct relocation_info *, struct relocation_info *, int));
880void md_make_jmpreloc __P((struct relocation_info *, struct relocation_info *, int));
881void md_make_gotreloc __P((struct relocation_info *, struct relocation_info *, int));
882void md_make_copyreloc __P((struct relocation_info *, struct relocation_info *));
883
884#ifdef NEED_SWAP
885void md_swapin_exec_hdr __P((struct exec *));
886void md_swapout_exec_hdr __P((struct exec *));
887void md_swapin_reloc __P((struct relocation_info *, int));
888void md_swapout_reloc __P((struct relocation_info *, int));
889void md_swapout_jmpslot __P((jmpslot_t *, int));
890
891/* In xbits.c: */
892void swap_longs __P((long *, int));
893void swap_symbols __P((struct nlist *, int));
894void swap_zsymbols __P((struct nzlist *, int));
895void swap_ranlib_hdr __P((struct ranlib *, int));
896void swap_link_dynamic __P((struct link_dynamic *));
897void swap_link_dynamic_2 __P((struct link_dynamic_2 *));
898void swap_ld_debug __P((struct ld_debug *));
899void swapin_link_object __P((struct link_object *, int));
900void swapout_link_object __P((struct link_object *, int));
901void swapout_fshash __P((struct fshash *, int));
902#endif