Mac OS X:
Bypass the dlfcn compatibility layer in lookupSymbol, use Apple's
NSModule functions directly instead. This protects us from differences
between different implementations of the dlcompat library (regarding
treatment of prefixed underscores).
Note that the compatibility layer is still used in addDLL (it's needed by
the POSIX library anyway).
Also, add a little more sanity checking (checkProddableBlock) to the Mach-O
linker itself.
MERGE TO STABLE
/* -----------------------------------------------------------------------------
/* -----------------------------------------------------------------------------
- * $Id: Linker.c,v 1.128 2003/09/10 14:45:25 simonmar Exp $
+ * $Id: Linker.c,v 1.129 2003/09/11 15:12:25 wolfgang Exp $
*
* (c) The GHC Team, 2000-2003
*
*
* (c) The GHC Team, 2000-2003
*
# include <mach-o/loader.h>
# include <mach-o/nlist.h>
# include <mach-o/reloc.h>
# include <mach-o/loader.h>
# include <mach-o/nlist.h>
# include <mach-o/reloc.h>
+# include <mach-o/dyld.h>
#endif
/* Hash table mapping symbol names to Symbol */
#endif
/* Hash table mapping symbol names to Symbol */
val = lookupStrHashTable(symhash, lbl);
if (val == NULL) {
val = lookupStrHashTable(symhash, lbl);
if (val == NULL) {
-# if defined(OBJFORMAT_ELF) || defined(OBJFORMAT_MACHO)
+# if defined(OBJFORMAT_ELF)
return dlsym(dl_prog_handle, lbl);
return dlsym(dl_prog_handle, lbl);
+# elif defined(OBJFORMAT_MACHO)
+ if(NSIsSymbolNameDefined(lbl)) {
+ NSSymbol symbol = NSLookupAndBindSymbol(lbl);
+ return NSAddressOfSymbol(symbol);
+ } else {
+ return NULL;
+ }
# elif defined(OBJFORMAT_PEi386)
OpenedDLL* o_dll;
void* sym;
# elif defined(OBJFORMAT_PEi386)
OpenedDLL* o_dll;
void* sym;
return 0;
}
ASSERT(addr);
return 0;
}
ASSERT(addr);
+ checkProddableBlock(oc,((void**)(image + sect->offset)) + i);
((void**)(image + sect->offset))[i] = addr;
}
return 1;
}
((void**)(image + sect->offset))[i] = addr;
}
return 1;
}
-static int relocateSection(char *image,
+static int relocateSection(
+ ObjectCode* oc,
+ char *image,
struct symtab_command *symLC, struct nlist *nlist,
struct section* sections, struct section *sect)
{
struct symtab_command *symLC, struct nlist *nlist,
struct section* sections, struct section *sect)
{
{
unsigned long* word = (unsigned long*) (image + sect->offset + scat->r_address);
{
unsigned long* word = (unsigned long*) (image + sect->offset + scat->r_address);
+ checkProddableBlock(oc,word);
*word = scat->r_value + sect->offset + ((long) image);
}
}
*word = scat->r_value + sect->offset + ((long) image);
}
}
unsigned long word = 0;
unsigned long* wordPtr = (unsigned long*) (image + sect->offset + reloc->r_address);
unsigned long word = 0;
unsigned long* wordPtr = (unsigned long*) (image + sect->offset + reloc->r_address);
+ checkProddableBlock(oc,wordPtr);
if(reloc->r_type == GENERIC_RELOC_VANILLA)
{
if(reloc->r_type == GENERIC_RELOC_VANILLA)
{
addSection(oc, SECTIONKIND_RWDATA,
(void*) (image + sections[i].offset),
(void*) (image + sections[i].offset + sections[i].size));
addSection(oc, SECTIONKIND_RWDATA,
(void*) (image + sections[i].offset),
(void*) (image + sections[i].offset + sections[i].size));
+
+ if(sections[i].size > 0) // size 0 segments do exist
+ addProddableBlock(oc, (void*) (image + sections[i].offset),
+ sections[i].size);
}
// count external symbols defined here
}
// count external symbols defined here
for(i=0;i<segLC->nsects;i++)
{
for(i=0;i<segLC->nsects;i++)
{
- if(!relocateSection(image,symLC,nlist,sections,§ions[i]))
+ if(!relocateSection(oc,image,symLC,nlist,sections,§ions[i]))