diff options
-rw-r--r-- | rts/Linker.c | 4 | ||||
-rw-r--r-- | rts/linker/MachO.c | 226 | ||||
-rw-r--r-- | rts/linker/MachO.h | 4 | ||||
-rw-r--r-- | rts/linker/MachOTypes.h | 5 |
4 files changed, 8 insertions, 231 deletions
diff --git a/rts/Linker.c b/rts/Linker.c index b6f1de9be6..06b36ca88e 100644 --- a/rts/Linker.c +++ b/rts/Linker.c @@ -447,9 +447,7 @@ initLinker_ (int retain_cafs) } IF_DEBUG(linker, debugBelch("initLinker: inserting rts symbol %s, %p\n", sym->lbl, sym->addr)); } -# if defined(OBJFORMAT_MACHO) && defined(powerpc_HOST_ARCH) - machoInitSymbolsWithoutUnderscore(); -# endif + /* GCC defines a special symbol __dso_handle which is resolved to NULL if referenced from a statically linked module. We need to mimic this, but we cannot use NULL because we use it to mean nonexistent symbols. So we diff --git a/rts/linker/MachO.c b/rts/linker/MachO.c index ca5befca77..adcfcc7c40 100644 --- a/rts/linker/MachO.c +++ b/rts/linker/MachO.c @@ -29,10 +29,6 @@ # include <sys/mman.h> #endif -#if defined(powerpc_HOST_ARCH) -# include <mach-o/ppc/reloc.h> -#endif - #if defined(x86_64_HOST_ARCH) # include <mach-o/x86_64/reloc.h> #endif @@ -218,7 +214,6 @@ ocVerifyImage_MachO(ObjectCode * oc) IF_DEBUG(linker, debugBelch("ocVerifyImage_MachO: start\n")); -#if defined(x86_64_HOST_ARCH) || defined(aarch64_HOST_ARCH) if(header->magic != MH_MAGIC_64) { errorBelch("Could not load image %s: bad magic!\n" " Expected %08x (64bit), got %08x%s\n", @@ -226,15 +221,6 @@ ocVerifyImage_MachO(ObjectCode * oc) header->magic == MH_MAGIC ? " (32bit)." : "."); return 0; } -#else - if(header->magic != MH_MAGIC) { - errorBelch("Could not load image %s: bad magic!\n" - " Expected %08x (32bit), got %08x%s\n", - oc->fileName, MH_MAGIC, header->magic, - header->magic == MH_MAGIC_64 ? " (64bit)." : "."); - return 0; - } -#endif // FIXME: do some more verifying here IF_DEBUG(linker, debugBelch("ocVerifyImage_MachO: done\n")); @@ -251,17 +237,6 @@ resolveImports( IF_DEBUG(linker, debugBelch("resolveImports: start\n")); -#if defined(i386_HOST_ARCH) - int isJumpTable = 0; - - if (strcmp(sect->sectname,"__jump_table") == 0) { - isJumpTable = 1; - itemSize = 5; - ASSERT(sect->reserved2 == itemSize); - } - -#endif - for(unsigned i = 0; i * itemSize < sect->size; i++) { // according to otool, reserved1 contains the first index into the @@ -289,22 +264,10 @@ resolveImports( } ASSERT(addr); -#if defined(i386_HOST_ARCH) - if (isJumpTable) { - checkProddableBlock(oc,oc->image + sect->offset + i*itemSize, 5); - - *(oc->image + sect->offset + i * itemSize) = 0xe9; // jmp opcode - *(unsigned*)(oc->image + sect->offset + i*itemSize + 1) - = (SymbolAddr*)addr - (oc->image + sect->offset + i*itemSize + 5); - } - else -#endif - { - checkProddableBlock(oc, - ((void**)(oc->image + sect->offset)) + i, - sizeof(void *)); - ((void**)(oc->image + sect->offset))[i] = addr; - } + checkProddableBlock(oc, + ((void**)(oc->image + sect->offset)) + i, + sizeof(void *)); + ((void**)(oc->image + sect->offset))[i] = addr; } IF_DEBUG(linker, debugBelch("resolveImports: done\n")); @@ -717,7 +680,6 @@ relocateSectionAarch64(ObjectCode * oc, Section * section) } return 1; } - #else /* non aarch64_HOST_ARCH branch -- aarch64 doesn't use relocateAddress */ /* @@ -751,7 +713,7 @@ relocateAddress( #endif /* aarch64_HOST_ARCH */ -#if !defined(aarch64_HOST_ARCH) +#if defined(x86_64_HOST_ARCH) static int relocateSection( ObjectCode* oc, @@ -780,7 +742,6 @@ relocateSection( for(i = 0; i < n; i++) { -#if defined(x86_64_HOST_ARCH) MachORelocationInfo *reloc = &relocs[i]; char *thingPtr = image + sect->offset + reloc->r_address; @@ -974,178 +935,12 @@ relocateSection( *(uint64_t*)thingPtr = thing; break; } -#else /* x86_64_HOST_ARCH */ - if(relocs[i].r_address & R_SCATTERED) - { - MachOScatteredRelocationInfo *scat = - (MachOScatteredRelocationInfo*) &relocs[i]; - - if(!scat->r_pcrel) - { - if(scat->r_length == 2) - { - unsigned long word = 0; - unsigned long* wordPtr = (unsigned long*) (image + sect->offset + scat->r_address); - - /* In this check we assume that sizeof(unsigned long) = 2 * sizeof(unsigned short) - on powerpc_HOST_ARCH */ - checkProddableBlock(oc,wordPtr,sizeof(unsigned long)); - - // Note on relocation types: - // i386 uses the GENERIC_RELOC_* types, - // while ppc uses special PPC_RELOC_* types. - // *_RELOC_VANILLA and *_RELOC_PAIR have the same value - // in both cases, all others are different. - // Therefore, we use GENERIC_RELOC_VANILLA - // and GENERIC_RELOC_PAIR instead of the PPC variants, - // and use #ifdefs for the other types. - - // Step 1: Figure out what the relocated value should be - if (scat->r_type == GENERIC_RELOC_VANILLA) { - word = *wordPtr - + (unsigned long) relocateAddress(oc, - nSections, - sections, - scat->r_value) - - scat->r_value; - } - else if(scat->r_type == GENERIC_RELOC_SECTDIFF - || scat->r_type == GENERIC_RELOC_LOCAL_SECTDIFF) - { - MachOScatteredRelocationInfo *pair = - (MachOScatteredRelocationInfo*) &relocs[i+1]; - - if (!pair->r_scattered || pair->r_type != GENERIC_RELOC_PAIR) { - barf("Invalid Mach-O file: " - "RELOC_*_SECTDIFF not followed by RELOC_PAIR"); - } - - word = (unsigned long) - (relocateAddress(oc, nSections, sections, scat->r_value) - - relocateAddress(oc, nSections, sections, pair->r_value)); - i++; - } - else { - barf ("Don't know how to handle this Mach-O " - "scattered relocation entry: " - "object file %s; entry type %ld; " - "address %#lx\n", - OC_INFORMATIVE_FILENAME(oc), - scat->r_type, - scat->r_address); - return 0; - } - - if(scat->r_type == GENERIC_RELOC_VANILLA - || scat->r_type == GENERIC_RELOC_SECTDIFF - || scat->r_type == GENERIC_RELOC_LOCAL_SECTDIFF) - { - *wordPtr = word; - } - } - else - { - barf("Can't handle Mach-O scattered relocation entry " - "with this r_length tag: " - "object file %s; entry type %ld; " - "r_length tag %ld; address %#lx\n", - OC_INFORMATIVE_FILENAME(oc), - scat->r_type, - scat->r_length, - scat->r_address); - return 0; - } - } - else /* scat->r_pcrel */ - { - barf("Don't know how to handle *PC-relative* Mach-O " - "scattered relocation entry: " - "object file %s; entry type %ld; address %#lx\n", - OC_INFORMATIVE_FILENAME(oc), - scat->r_type, - scat->r_address); - return 0; - } - - } - else /* !(relocs[i].r_address & R_SCATTERED) */ - { - MachORelocationInfo *reloc = &relocs[i]; - if (reloc->r_pcrel && !reloc->r_extern) { - IF_DEBUG(linker, debugBelch("relocateSection: pc relative but not external, skipping\n")); - continue; - } - - if (reloc->r_length == 2) { - unsigned long word = 0; - unsigned long* wordPtr = (unsigned long*) (image + sect->offset + reloc->r_address); - - checkProddableBlock(oc,wordPtr, sizeof(unsigned long)); - - if (reloc->r_type == GENERIC_RELOC_VANILLA) { - word = *wordPtr; - } - else { - barf("Can't handle this Mach-O relocation entry " - "(not scattered): " - "object file %s; entry type %ld; address %#lx\n", - OC_INFORMATIVE_FILENAME(oc), - reloc->r_type, - reloc->r_address); - return 0; - } - - if (!reloc->r_extern) { - long delta = sections[reloc->r_symbolnum-1].offset - - sections[reloc->r_symbolnum-1].addr - + ((long) image); - - word += delta; - } - else { - MachONList *symbol = &nlist[reloc->r_symbolnum]; - char *nm = image + symLC->stroff + symbol->n_un.n_strx; - void *symbolAddress = lookupSymbol_(nm); - - if (!symbolAddress) { - errorBelch("\nunknown symbol `%s'", nm); - return 0; - } - - if (reloc->r_pcrel) { - word += (unsigned long) symbolAddress - - (((long)image) + sect->offset - sect->addr); - } - else { - word += (unsigned long) symbolAddress; - } - } - - if (reloc->r_type == GENERIC_RELOC_VANILLA) { - *wordPtr = word; - continue; - } - } - else - { - barf("Can't handle Mach-O relocation entry (not scattered) " - "with this r_length tag: " - "object file %s; entry type %ld; " - "r_length tag %ld; address %#lx\n", - OC_INFORMATIVE_FILENAME(oc), - reloc->r_type, - reloc->r_length, - reloc->r_address); - return 0; - } - } -#endif /* x86_64_HOST_ARCH */ } IF_DEBUG(linker, debugBelch("relocateSection: done\n")); return 1; } -#endif /* aarch64_HOST_ARCH */ +#endif /* x86_64_HOST_ARCH */ /* Note [mmap r+w+x] * ~~~~~~~~~~~~~~~~~ @@ -1678,17 +1473,10 @@ machoGetMisalignment( FILE * f ) } fseek(f, -sizeof(header), SEEK_CUR); -#if defined(x86_64_HOST_ARCH) || defined(aarch64_HOST_ARCH) if(header.magic != MH_MAGIC_64) { barf("Bad magic. Expected: %08x, got: %08x.", MH_MAGIC_64, header.magic); } -#else - if(header.magic != MH_MAGIC) { - barf("Bad magic. Expected: %08x, got: %08x.", - MH_MAGIC, header.magic); - } -#endif misalignment = (header.sizeofcmds + sizeof(header)) & 0xF; @@ -1696,4 +1484,4 @@ machoGetMisalignment( FILE * f ) return misalignment ? (16 - misalignment) : 0; } -#endif /* darwin_HOST_OS, ios_HOST_OS */ +#endif /* darwin_HOST_OS || ios_HOST_OS */ diff --git a/rts/linker/MachO.h b/rts/linker/MachO.h index 4fb58e8668..5e00e2a8d2 100644 --- a/rts/linker/MachO.h +++ b/rts/linker/MachO.h @@ -15,8 +15,4 @@ int ocRunInit_MachO ( ObjectCode* oc ); int machoGetMisalignment( FILE * ); int ocAllocateExtras_MachO ( ObjectCode* oc ); -#if defined(powerpc_HOST_ARCH) -void machoInitSymbolsWithoutUnderscore( void ); -#endif - #include "EndPrivate.h" diff --git a/rts/linker/MachOTypes.h b/rts/linker/MachOTypes.h index dcea906021..c5923b441f 100644 --- a/rts/linker/MachOTypes.h +++ b/rts/linker/MachOTypes.h @@ -12,11 +12,6 @@ typedef struct mach_header_64 MachOHeader; typedef struct segment_command_64 MachOSegmentCommand; typedef struct section_64 MachOSection; typedef struct nlist_64 MachONList; -#elif defined(i386_HOST_ARCH) || defined(arm_HOST_ARCH) -typedef struct mach_header MachOHeader; -typedef struct segment_command MachOSegmentCommand; -typedef struct section MachOSection; -typedef struct nlist MachONList; #else #error Unknown Darwin architecture #endif |