* $Id: symbol.c,v 1.4 1994/02/13 20:41:46 jkh Exp $ - symbol table routines
/* Create the symbol table entries for `etext', `edata' and `end'. */
symbol
*symtab
[SYMTABSIZE
]; /* The symbol table. */
int num_hash_tab_syms
; /* Number of symbols in symbol hash table. */
symbol
*edata_symbol
; /* the symbol _edata */
symbol
*etext_symbol
; /* the symbol _etext */
symbol
*end_symbol
; /* the symbol _end */
symbol
*got_symbol
; /* the symbol __GLOBAL_OFFSET_TABLE_ */
symbol
*dynamic_symbol
; /* the symbol __DYNAMIC */
symtab_init(relocatable_output
)
* Put linker reserved symbols into symbol table.
#define ETEXT_SYM "_etext"
#define EDATA_SYM "_edata"
#define DYN_SYM "__DYNAMIC"
#define GOT_SYM "__GLOBAL_OFFSET_TABLE_"
#define ETEXT_SYM "etext"
#define EDATA_SYM "edata"
#define DYN_SYM "_DYNAMIC"
#define GOT_SYM "_GLOBAL_OFFSET_TABLE_"
dynamic_symbol
= getsym(DYN_SYM
);
dynamic_symbol
->defined
= relocatable_output
?N_UNDF
:(N_DATA
| N_EXT
);
got_symbol
= getsym(GOT_SYM
);
got_symbol
->defined
= N_DATA
| N_EXT
;
etext_symbol
= getsym(ETEXT_SYM
);
edata_symbol
= getsym(EDATA_SYM
);
end_symbol
= getsym(END_SYM
);
etext_symbol
->defined
= N_TEXT
| N_EXT
;
edata_symbol
->defined
= N_DATA
| N_EXT
;
end_symbol
->defined
= N_BSS
| N_EXT
;
etext_symbol
->flags
|= GS_REFERENCED
;
edata_symbol
->flags
|= GS_REFERENCED
;
end_symbol
->flags
|= GS_REFERENCED
;
* Compute the hash code for symbol name KEY.
k
= (((k
<< 1) + (k
>> 14)) ^ (*cp
++)) & 0x3fff;
* Get the symbol table entry for the global symbol named KEY.
* Create one if there is none.
/* Determine the proper bucket. */
hashval
= hash_string(key
) % SYMTABSIZE
;
for (bp
= symtab
[hashval
]; bp
; bp
= bp
->link
)
if (strcmp(key
, bp
->name
) == 0)
/* Nothing was found; create a new symbol table entry. */
bp
= (symbol
*)xmalloc(sizeof(symbol
));
bp
->name
= (char *)xmalloc(strlen(key
) + 1);
/* Add the entry to the bucket. */
bp
->link
= symtab
[hashval
];
/* Like `getsym' but return 0 if the symbol is not already known. */
/* Determine which bucket. */
hashval
= hash_string(key
) % SYMTABSIZE
;
for (bp
= symtab
[hashval
]; bp
; bp
= bp
->link
)
if (strcmp(key
, bp
->name
) == 0)