Commit | Line | Data |
---|---|---|
1136f72d | 1 | /* |
80f25b52 | 2 | * $Id: symbol.c,v 1.2 1993/11/09 04:19:04 paul Exp $ - symbol table routines |
1136f72d PR |
3 | */ |
4 | ||
5 | /* Create the symbol table entries for `etext', `edata' and `end'. */ | |
6 | ||
7 | #include <sys/param.h> | |
8 | #include <stdio.h> | |
9 | #include <stdlib.h> | |
10 | #include <sys/types.h> | |
11 | #include <fcntl.h> | |
12 | #include <a.out.h> | |
13 | #include <stab.h> | |
14 | #include <string.h> | |
15 | ||
16 | #include "ld.h" | |
17 | ||
18 | void | |
19 | symtab_init (relocatable_output) | |
20 | int relocatable_output; | |
21 | { | |
22 | /* | |
23 | * Put linker reserved symbols into symbol table. | |
24 | */ | |
25 | ||
26 | dynamic_symbol = getsym ("__DYNAMIC"); | |
27 | dynamic_symbol->defined = relocatable_output?N_UNDF:(N_DATA | N_EXT); | |
28 | dynamic_symbol->referenced = 0; | |
29 | dynamic_symbol->value = 0; | |
30 | ||
31 | got_symbol = getsym ("__GLOBAL_OFFSET_TABLE_"); | |
32 | got_symbol->defined = N_DATA | N_EXT; | |
33 | got_symbol->referenced = 0; | |
34 | got_symbol->value = 0; | |
35 | ||
36 | if (relocatable_output) | |
37 | return; | |
38 | ||
39 | #ifndef nounderscore | |
40 | edata_symbol = getsym ("_edata"); | |
41 | etext_symbol = getsym ("_etext"); | |
42 | end_symbol = getsym ("_end"); | |
43 | #else | |
44 | edata_symbol = getsym ("edata"); | |
45 | etext_symbol = getsym ("etext"); | |
46 | end_symbol = getsym ("end"); | |
47 | #endif | |
48 | edata_symbol->defined = N_DATA | N_EXT; | |
49 | etext_symbol->defined = N_TEXT | N_EXT; | |
50 | end_symbol->defined = N_BSS | N_EXT; | |
51 | ||
52 | edata_symbol->referenced = 1; | |
53 | etext_symbol->referenced = 1; | |
54 | end_symbol->referenced = 1; | |
55 | } | |
56 | ||
57 | /* Compute the hash code for symbol name KEY. */ | |
58 | ||
59 | int | |
60 | hash_string (key) | |
61 | char *key; | |
62 | { | |
63 | register char *cp; | |
64 | register int k; | |
65 | ||
66 | cp = key; | |
67 | k = 0; | |
68 | while (*cp) | |
69 | k = (((k << 1) + (k >> 14)) ^ (*cp++)) & 0x3fff; | |
70 | ||
71 | return k; | |
72 | } | |
73 | ||
74 | /* Get the symbol table entry for the global symbol named KEY. | |
75 | Create one if there is none. */ | |
76 | ||
77 | symbol * | |
78 | getsym(key) | |
79 | char *key; | |
80 | { | |
81 | register int hashval; | |
82 | register symbol *bp; | |
83 | ||
84 | /* Determine the proper bucket. */ | |
85 | hashval = hash_string (key) % TABSIZE; | |
86 | ||
87 | /* Search the bucket. */ | |
88 | for (bp = symtab[hashval]; bp; bp = bp->link) | |
89 | if (! strcmp (key, bp->name)) | |
90 | return bp; | |
91 | ||
92 | /* Nothing was found; create a new symbol table entry. */ | |
93 | bp = (symbol *) xmalloc (sizeof (symbol)); | |
94 | bp->refs = 0; | |
95 | bp->name = (char *) xmalloc (strlen (key) + 1); | |
96 | strcpy (bp->name, key); | |
97 | bp->defined = 0; | |
98 | bp->referenced = 0; | |
99 | bp->trace = 0; | |
100 | bp->value = 0; | |
101 | bp->max_common_size = 0; | |
102 | bp->warning = 0; | |
103 | bp->undef_refs = 0; | |
104 | bp->multiply_defined = 0; | |
105 | bp->alias = 0; | |
106 | bp->setv_count = 0; | |
80f25b52 JH |
107 | bp->symbolnum = 0; |
108 | bp->rrs_symbolnum = 0; | |
1136f72d PR |
109 | |
110 | bp->size = 0; | |
80f25b52 | 111 | bp->aux = 0; |
1136f72d PR |
112 | bp->sorefs = 0; |
113 | bp->so_defined = 0; | |
114 | bp->def_nlist = 0; | |
115 | bp->jmpslot_offset = -1; | |
116 | bp->gotslot_offset = -1; | |
117 | bp->jmpslot_claimed = 0; | |
118 | bp->gotslot_claimed = 0; | |
119 | bp->cpyreloc_reserved = 0; | |
120 | bp->cpyreloc_claimed = 0; | |
121 | ||
122 | /* Add the entry to the bucket. */ | |
123 | bp->link = symtab[hashval]; | |
124 | symtab[hashval] = bp; | |
125 | ||
126 | ++num_hash_tab_syms; | |
127 | ||
128 | return bp; | |
129 | } | |
130 | ||
131 | /* Like `getsym' but return 0 if the symbol is not already known. */ | |
132 | ||
133 | symbol * | |
134 | getsym_soft (key) | |
135 | char *key; | |
136 | { | |
137 | register int hashval; | |
138 | register symbol *bp; | |
139 | ||
140 | /* Determine which bucket. */ | |
141 | ||
142 | hashval = hash_string (key) % TABSIZE; | |
143 | ||
144 | /* Search the bucket. */ | |
145 | ||
146 | for (bp = symtab[hashval]; bp; bp = bp->link) | |
147 | if (! strcmp (key, bp->name)) | |
148 | return bp; | |
149 | ||
150 | return 0; | |
151 | } |