summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsewardj <unknown>2001-09-12 14:53:39 +0000
committersewardj <unknown>2001-09-12 14:53:39 +0000
commit2db150e82af6cb9802006227cffb8414d99261f3 (patch)
tree686c747472e6afe3860b7164cc30c64c8e2fac95
parent5d5ed99933e1f4388b2d0c999f9f5789e36c2518 (diff)
downloadhaskell-2db150e82af6cb9802006227cffb8414d99261f3.tar.gz
[project @ 2001-09-12 14:53:39 by sewardj]
Redo half-arsed hacks to do with BSS symbols on ELF. Hopefully get it right this time. MERGE TO STABLE
-rw-r--r--ghc/rts/Linker.c61
1 files changed, 44 insertions, 17 deletions
diff --git a/ghc/rts/Linker.c b/ghc/rts/Linker.c
index a6e92c16b7..d733257d1f 100644
--- a/ghc/rts/Linker.c
+++ b/ghc/rts/Linker.c
@@ -1,5 +1,5 @@
/* -----------------------------------------------------------------------------
- * $Id: Linker.c,v 1.66 2001/09/07 16:08:31 sewardj Exp $
+ * $Id: Linker.c,v 1.67 2001/09/12 14:53:39 sewardj Exp $
*
* (c) The GHC Team, 2000, 2001
*
@@ -1717,12 +1717,12 @@ ocGetNames_ELF ( ObjectCode* oc )
it, and set its .sh_offset field such that
ehdrC + .sh_offset == addr_of_zeroed_space. */
char* zspace = stgCallocBytes(1, shdr[i].sh_size,
- "ocGetNames_ELF(anonymous bss)");
+ "ocGetNames_ELF(BSS)");
shdr[i].sh_offset = ((char*)zspace) - ((char*)ehdrC);
- /*
+ /*
fprintf(stderr, "BSS section at 0x%x, size %d\n",
zspace, shdr[i].sh_size);
- */
+ */
}
/* fill in the section info */
@@ -1742,6 +1742,26 @@ ocGetNames_ELF ( ObjectCode* oc )
"ocGetNames_ELF(oc->symbols)");
for (j = 0; j < nent; j++) {
+
+ char isLocal = FALSE; /* avoids uninit-var warning */
+ char* ad = NULL;
+ char* nm = strtab + stab[j].st_name;
+ int secno = stab[j].st_shndx;
+
+ /* Figure out if we want to add it; if so, set ad to its
+ address. Otherwise leave ad == NULL. */
+
+ if (secno == SHN_COMMON) {
+ isLocal = FALSE;
+ ad = stgCallocBytes(1, stab[j].st_size, "ocGetNames_ELF(COMMON)");
+ /*
+ fprintf(stderr, "COMMON symbol, size %d name %s\n",
+ stab[j].st_size, nm);
+ */
+ /* Pointless to do addProddableBlock() for this area,
+ since the linker should never poke around in it. */
+ }
+ else
if ( ( ELF32_ST_BIND(stab[j].st_info)==STB_GLOBAL
|| ELF32_ST_BIND(stab[j].st_info)==STB_LOCAL
)
@@ -1756,33 +1776,39 @@ ocGetNames_ELF ( ObjectCode* oc )
ELF32_ST_TYPE(stab[j].st_info)==STT_NOTYPE
)
) {
- char* nm;
- char* ad;
- int secno = stab[j].st_shndx;
/* Section 0 is the undefined section, hence > and not >=. */
ASSERT(secno > 0 && secno < ehdr->e_shnum);
- nm = strtab + stab[j].st_name;
- /*
+ /*
if (shdr[secno].sh_type == SHT_NOBITS) {
- fprintf(stderr, "bss symbol, size %d off %d name %s\n",
- stab[j].st_size, stab[j].st_value, nm);
+ fprintf(stderr, " BSS symbol, size %d off %d name %s\n",
+ stab[j].st_size, stab[j].st_value, nm);
}
*/
ad = ehdrC + shdr[ secno ].sh_offset + stab[j].st_value;
- ASSERT(nm != NULL);
- ASSERT(ad != NULL);
- oc->symbols[j] = nm;
if (ELF32_ST_BIND(stab[j].st_info)==STB_LOCAL) {
IF_DEBUG(linker,belch( "addOTabName(LOCL): %10p %s %s",
ad, oc->fileName, nm ));
- insertStrHashTable(oc->lochash, nm, ad);
+ isLocal = TRUE;
} else {
IF_DEBUG(linker,belch( "addOTabName(GLOB): %10p %s %s",
ad, oc->fileName, nm ));
- insertStrHashTable(symhash, nm, ad);
+ isLocal = FALSE;
}
}
- else {
+
+ /* And the decision is ... */
+
+ if (ad != NULL) {
+ ASSERT(nm != NULL);
+ oc->symbols[j] = nm;
+ /* Acquire! */
+ if (isLocal) {
+ insertStrHashTable(oc->lochash, nm, ad);
+ } else {
+ insertStrHashTable(symhash, nm, ad);
+ }
+ } else {
+ /* Skip. */
IF_DEBUG(linker,belch( "skipping `%s'",
strtab + stab[j].st_name ));
/*
@@ -1796,6 +1822,7 @@ ocGetNames_ELF ( ObjectCode* oc )
*/
oc->symbols[j] = NULL;
}
+
}
}