1996-10-01 01:22:51 +00:00
|
|
|
/*-
|
|
|
|
* This code is derived from software copyrighted by the Free Software
|
|
|
|
* Foundation.
|
|
|
|
*
|
|
|
|
* Modified 1991 by Donn Seeley at UUNET Technologies, Inc.
|
|
|
|
*
|
|
|
|
* Modified 1993 by Paul Kranenburg, Erasmus University
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Derived from ld.c: "@(#)ld.c 6.10 (Berkeley) 5/22/91"; */
|
|
|
|
|
|
|
|
/* Linker `ld' for GNU
|
|
|
|
Copyright (C) 1988 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 1, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
|
|
|
|
|
|
|
/* Written by Richard Stallman with some help from Eric Albert.
|
|
|
|
Set, indirect, and warning symbol features added by Randy Smith. */
|
|
|
|
|
1993-11-03 23:41:59 +00:00
|
|
|
/*
|
1996-10-01 01:22:51 +00:00
|
|
|
* symbol table routines
|
|
|
|
* $Id: symbol.c,v 1.6 1994/12/23 22:30:54 nate Exp $
|
1993-11-03 23:41:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Create the symbol table entries for `etext', `edata' and `end'. */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <a.out.h>
|
|
|
|
#include <stab.h>
|
1994-06-15 22:41:19 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1993-11-03 23:41:59 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "ld.h"
|
1996-10-01 01:22:51 +00:00
|
|
|
#include "dynamic.h"
|
1993-11-03 23:41:59 +00:00
|
|
|
|
1994-02-13 20:43:13 +00:00
|
|
|
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 */
|
|
|
|
|
1993-11-03 23:41:59 +00:00
|
|
|
void
|
1994-06-15 22:41:19 +00:00
|
|
|
symtab_init(relocatable_output)
|
|
|
|
int relocatable_output;
|
1993-11-03 23:41:59 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Put linker reserved symbols into symbol table.
|
|
|
|
*/
|
1994-02-13 20:43:13 +00:00
|
|
|
#ifndef nounderscore
|
|
|
|
#define ETEXT_SYM "_etext"
|
|
|
|
#define EDATA_SYM "_edata"
|
|
|
|
#define END_SYM "_end"
|
|
|
|
#define DYN_SYM "__DYNAMIC"
|
|
|
|
#define GOT_SYM "__GLOBAL_OFFSET_TABLE_"
|
|
|
|
#else
|
|
|
|
#define ETEXT_SYM "etext"
|
|
|
|
#define EDATA_SYM "edata"
|
|
|
|
#define END_SYM "end"
|
|
|
|
#define DYN_SYM "_DYNAMIC"
|
|
|
|
#define GOT_SYM "_GLOBAL_OFFSET_TABLE_"
|
|
|
|
#endif
|
1993-11-03 23:41:59 +00:00
|
|
|
|
1994-06-15 22:41:19 +00:00
|
|
|
dynamic_symbol = getsym(DYN_SYM);
|
1993-11-03 23:41:59 +00:00
|
|
|
dynamic_symbol->defined = relocatable_output?N_UNDF:(N_DATA | N_EXT);
|
|
|
|
|
1994-06-15 22:41:19 +00:00
|
|
|
got_symbol = getsym(GOT_SYM);
|
1993-11-03 23:41:59 +00:00
|
|
|
got_symbol->defined = N_DATA | N_EXT;
|
|
|
|
|
|
|
|
if (relocatable_output)
|
|
|
|
return;
|
|
|
|
|
1994-06-15 22:41:19 +00:00
|
|
|
etext_symbol = getsym(ETEXT_SYM);
|
|
|
|
edata_symbol = getsym(EDATA_SYM);
|
|
|
|
end_symbol = getsym(END_SYM);
|
1994-02-13 20:43:13 +00:00
|
|
|
|
1993-11-03 23:41:59 +00:00
|
|
|
etext_symbol->defined = N_TEXT | N_EXT;
|
1994-02-13 20:43:13 +00:00
|
|
|
edata_symbol->defined = N_DATA | N_EXT;
|
1993-11-03 23:41:59 +00:00
|
|
|
end_symbol->defined = N_BSS | N_EXT;
|
|
|
|
|
1994-02-13 20:43:13 +00:00
|
|
|
etext_symbol->flags |= GS_REFERENCED;
|
|
|
|
edata_symbol->flags |= GS_REFERENCED;
|
|
|
|
end_symbol->flags |= GS_REFERENCED;
|
1993-11-03 23:41:59 +00:00
|
|
|
}
|
|
|
|
|
1994-06-15 22:41:19 +00:00
|
|
|
/*
|
|
|
|
* Compute the hash code for symbol name KEY.
|
|
|
|
*/
|
1993-11-03 23:41:59 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
hash_string (key)
|
|
|
|
char *key;
|
|
|
|
{
|
|
|
|
register char *cp;
|
|
|
|
register int k;
|
|
|
|
|
|
|
|
cp = key;
|
|
|
|
k = 0;
|
|
|
|
while (*cp)
|
|
|
|
k = (((k << 1) + (k >> 14)) ^ (*cp++)) & 0x3fff;
|
|
|
|
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
|
1994-06-15 22:41:19 +00:00
|
|
|
/*
|
|
|
|
* Get the symbol table entry for the global symbol named KEY.
|
|
|
|
* Create one if there is none.
|
|
|
|
*/
|
1993-11-03 23:41:59 +00:00
|
|
|
|
|
|
|
symbol *
|
|
|
|
getsym(key)
|
|
|
|
char *key;
|
|
|
|
{
|
|
|
|
register int hashval;
|
|
|
|
register symbol *bp;
|
|
|
|
|
|
|
|
/* Determine the proper bucket. */
|
1994-06-15 22:41:19 +00:00
|
|
|
hashval = hash_string(key) % SYMTABSIZE;
|
1993-11-03 23:41:59 +00:00
|
|
|
|
|
|
|
/* Search the bucket. */
|
|
|
|
for (bp = symtab[hashval]; bp; bp = bp->link)
|
1994-06-15 22:41:19 +00:00
|
|
|
if (strcmp(key, bp->name) == 0)
|
1993-11-03 23:41:59 +00:00
|
|
|
return bp;
|
|
|
|
|
|
|
|
/* Nothing was found; create a new symbol table entry. */
|
1994-06-15 22:41:19 +00:00
|
|
|
bp = (symbol *)xmalloc(sizeof(symbol));
|
|
|
|
bp->name = (char *)xmalloc(strlen(key) + 1);
|
1993-11-03 23:41:59 +00:00
|
|
|
strcpy (bp->name, key);
|
1994-02-13 20:43:13 +00:00
|
|
|
bp->refs = 0;
|
1993-11-03 23:41:59 +00:00
|
|
|
bp->defined = 0;
|
|
|
|
bp->value = 0;
|
1994-02-13 20:43:13 +00:00
|
|
|
bp->common_size = 0;
|
1993-11-03 23:41:59 +00:00
|
|
|
bp->warning = 0;
|
|
|
|
bp->undef_refs = 0;
|
1994-02-13 20:43:13 +00:00
|
|
|
bp->mult_defs = 0;
|
1993-11-03 23:41:59 +00:00
|
|
|
bp->alias = 0;
|
|
|
|
bp->setv_count = 0;
|
1993-11-22 19:05:31 +00:00
|
|
|
bp->symbolnum = 0;
|
|
|
|
bp->rrs_symbolnum = 0;
|
1993-11-03 23:41:59 +00:00
|
|
|
|
|
|
|
bp->size = 0;
|
1993-11-22 19:05:31 +00:00
|
|
|
bp->aux = 0;
|
1993-11-03 23:41:59 +00:00
|
|
|
bp->sorefs = 0;
|
|
|
|
bp->so_defined = 0;
|
1994-12-23 22:31:35 +00:00
|
|
|
bp->def_lsp = 0;
|
1993-11-03 23:41:59 +00:00
|
|
|
bp->jmpslot_offset = -1;
|
|
|
|
bp->gotslot_offset = -1;
|
1994-02-13 20:43:13 +00:00
|
|
|
bp->flags = 0;
|
1993-11-03 23:41:59 +00:00
|
|
|
|
|
|
|
/* Add the entry to the bucket. */
|
|
|
|
bp->link = symtab[hashval];
|
|
|
|
symtab[hashval] = bp;
|
|
|
|
|
|
|
|
++num_hash_tab_syms;
|
|
|
|
|
|
|
|
return bp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Like `getsym' but return 0 if the symbol is not already known. */
|
|
|
|
|
|
|
|
symbol *
|
|
|
|
getsym_soft (key)
|
1994-12-23 22:31:35 +00:00
|
|
|
char *key;
|
1993-11-03 23:41:59 +00:00
|
|
|
{
|
|
|
|
register int hashval;
|
|
|
|
register symbol *bp;
|
|
|
|
|
1994-12-23 22:31:35 +00:00
|
|
|
/* Determine which bucket. */
|
1994-06-15 22:41:19 +00:00
|
|
|
hashval = hash_string(key) % SYMTABSIZE;
|
1993-11-03 23:41:59 +00:00
|
|
|
|
1994-12-23 22:31:35 +00:00
|
|
|
/* Search the bucket. */
|
1993-11-03 23:41:59 +00:00
|
|
|
for (bp = symtab[hashval]; bp; bp = bp->link)
|
1994-06-15 22:41:19 +00:00
|
|
|
if (strcmp(key, bp->name) == 0)
|
1993-11-03 23:41:59 +00:00
|
|
|
return bp;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|