diff options
Diffstat (limited to 'rts/linker/MachO.c')
| -rw-r--r-- | rts/linker/MachO.c | 267 |
1 files changed, 3 insertions, 264 deletions
diff --git a/rts/linker/MachO.c b/rts/linker/MachO.c index 10e9629e9d..c6a6c28440 100644 --- a/rts/linker/MachO.c +++ b/rts/linker/MachO.c @@ -179,47 +179,7 @@ resolveImports( unsigned long *indirectSyms); #if NEED_SYMBOL_EXTRAS -#if defined(powerpc_HOST_ARCH) -int -ocAllocateSymbolExtras_MachO(ObjectCode* oc) -{ - - IF_DEBUG(linker, debugBelch("ocAllocateSymbolExtras_MachO: start\n")); - - // Find out the first and last undefined external - // symbol, so we don't have to allocate too many - // jump islands/GOT entries. - - unsigned min = oc->info->symCmd->nsyms, max = 0; - - for (unsigned i = 0; i < oc->info->symCmd->nsyms; i++) { - - if (oc->info->nlist[i].n_type & N_STAB) { - ; - } else if (oc->info->nlist[i].n_type & N_EXT) { - - if((oc->info->nlist[i].n_type & N_TYPE) == N_UNDF - && (oc->info->nlist[i].n_value == 0)) { - - if (i < min) { - min = i; - } - - if (i > max) { - max = i; - } - } - } - } - - if (max >= min) { - return ocAllocateSymbolExtras(oc, max - min + 1, min); - } - - return ocAllocateSymbolExtras(oc,0,0); -} - -#elif defined(x86_64_HOST_ARCH) || defined(aarch64_HOST_ARCH) +#if defined(x86_64_HOST_ARCH) || defined(aarch64_HOST_ARCH) int ocAllocateSymbolExtras_MachO(ObjectCode* oc) @@ -250,8 +210,7 @@ ocVerifyImage_MachO(ObjectCode * oc) IF_DEBUG(linker, debugBelch("ocVerifyImage_MachO: start\n")); -#if defined(x86_64_HOST_ARCH) || defined(powerpc64_HOST_ARCH) \ - || defined(aarch64_HOST_ARCH) +#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", @@ -1042,16 +1001,8 @@ relocateSection( scat->r_value) - scat->r_value; } -#if defined(powerpc_HOST_ARCH) - else if(scat->r_type == PPC_RELOC_SECTDIFF - || scat->r_type == PPC_RELOC_LO16_SECTDIFF - || scat->r_type == PPC_RELOC_HI16_SECTDIFF - || scat->r_type == PPC_RELOC_HA16_SECTDIFF - || scat->r_type == PPC_RELOC_LOCAL_SECTDIFF) -#else /* powerpc_HOST_ARCH */ else if(scat->r_type == GENERIC_RELOC_SECTDIFF || scat->r_type == GENERIC_RELOC_LOCAL_SECTDIFF) -#endif /* powerpc_HOST_ARCH */ { MachOScatteredRelocationInfo *pair = (MachOScatteredRelocationInfo*) &relocs[i+1]; @@ -1066,48 +1017,6 @@ relocateSection( - relocateAddress(oc, nSections, sections, pair->r_value)); i++; } -#if defined(powerpc_HOST_ARCH) - else if(scat->r_type == PPC_RELOC_HI16 - || scat->r_type == PPC_RELOC_LO16 - || scat->r_type == PPC_RELOC_HA16 - || scat->r_type == PPC_RELOC_LO14) - { // these are generated by label+offset things - MachORelocationInfo *pair = &relocs[i+1]; - - if ((pair->r_address & R_SCATTERED) || pair->r_type != PPC_RELOC_PAIR) { - barf("Invalid Mach-O file: " - "PPC_RELOC_* not followed by PPC_RELOC_PAIR"); - } - - if(scat->r_type == PPC_RELOC_LO16) - { - word = ((unsigned short*) wordPtr)[1]; - word |= ((unsigned long) relocs[i+1].r_address & 0xFFFF) << 16; - } - else if(scat->r_type == PPC_RELOC_LO14) - { - barf("Unsupported Relocation: PPC_RELOC_LO14"); - word = ((unsigned short*) wordPtr)[1] & 0xFFFC; - word |= ((unsigned long) relocs[i+1].r_address & 0xFFFF) << 16; - } - else if(scat->r_type == PPC_RELOC_HI16) - { - word = ((unsigned short*) wordPtr)[1] << 16; - word |= ((unsigned long) relocs[i+1].r_address & 0xFFFF); - } - else if(scat->r_type == PPC_RELOC_HA16) - { - word = ((unsigned short*) wordPtr)[1] << 16; - word += ((short)relocs[i+1].r_address & (short)0xFFFF); - } - - - word += (unsigned long) relocateAddress(oc, nSections, sections, scat->r_value) - - scat->r_value; - - i++; - } -#endif /* powerpc_HOST_ARCH */ else { barf ("Don't know how to handle this Mach-O " "scattered relocation entry: " @@ -1119,35 +1028,12 @@ relocateSection( return 0; } -#if defined(powerpc_HOST_ARCH) - if(scat->r_type == GENERIC_RELOC_VANILLA - || scat->r_type == PPC_RELOC_SECTDIFF) -#else /* powerpc_HOST_ARCH */ if(scat->r_type == GENERIC_RELOC_VANILLA || scat->r_type == GENERIC_RELOC_SECTDIFF || scat->r_type == GENERIC_RELOC_LOCAL_SECTDIFF) -#endif /* powerpc_HOST_ARCH */ { *wordPtr = word; } -#if defined(powerpc_HOST_ARCH) - else if (scat->r_type == PPC_RELOC_LO16_SECTDIFF - || scat->r_type == PPC_RELOC_LO16) - { - ((unsigned short*) wordPtr)[1] = word & 0xFFFF; - } - else if (scat->r_type == PPC_RELOC_HI16_SECTDIFF - || scat->r_type == PPC_RELOC_HI16) - { - ((unsigned short*) wordPtr)[1] = (word >> 16) & 0xFFFF; - } - else if (scat->r_type == PPC_RELOC_HA16_SECTDIFF - || scat->r_type == PPC_RELOC_HA16) - { - ((unsigned short*) wordPtr)[1] = ((word >> 16) & 0xFFFF) - + ((word & (1<<15)) ? 1 : 0); - } -#endif /* powerpc_HOST_ARCH */ } else { @@ -1184,40 +1070,13 @@ relocateSection( if (reloc->r_length == 2) { unsigned long word = 0; -#if defined(powerpc_HOST_ARCH) - unsigned long jumpIsland = 0; - long offsetToJumpIsland = 0xBADBAD42; // initialise to bad value - // to avoid warning and to catch - // bugs. -#endif /* powerpc_HOST_ARCH */ - unsigned long* wordPtr = (unsigned long*) (image + sect->offset + reloc->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)); if (reloc->r_type == GENERIC_RELOC_VANILLA) { word = *wordPtr; } -#if defined(powerpc_HOST_ARCH) - else if (reloc->r_type == PPC_RELOC_LO16) { - word = ((unsigned short*) wordPtr)[1]; - word |= ((unsigned long) relocs[i+1].r_address & 0xFFFF) << 16; - } - else if (reloc->r_type == PPC_RELOC_HI16) { - word = ((unsigned short*) wordPtr)[1] << 16; - word |= ((unsigned long) relocs[i+1].r_address & 0xFFFF); - } - else if (reloc->r_type == PPC_RELOC_HA16) { - word = ((unsigned short*) wordPtr)[1] << 16; - word += ((short)relocs[i+1].r_address & (short)0xFFFF); - } - else if (reloc->r_type == PPC_RELOC_BR24) { - word = *wordPtr; - word = (word & 0x03FFFFFC) | ((word & 0x02000000) ? 0xFC000000 : 0); - } -#endif /* powerpc_HOST_ARCH */ else { barf("Can't handle this Mach-O relocation entry " "(not scattered): " @@ -1246,20 +1105,6 @@ relocateSection( } if (reloc->r_pcrel) { -#if defined(powerpc_HOST_ARCH) - // In the .o file, this should be a relative jump to NULL - // and we'll change it to a relative jump to the symbol - ASSERT(word + reloc->r_address == 0); - jumpIsland = (unsigned long) - &makeSymbolExtra(oc, - reloc->r_symbolnum, - (unsigned long) symbolAddress) - -> jumpIsland; - if (jumpIsland != 0) { - offsetToJumpIsland = word + jumpIsland - - (((long)image) + sect->offset - sect->addr); - } -#endif /* powerpc_HOST_ARCH */ word += (unsigned long) symbolAddress - (((long)image) + sect->offset - sect->addr); } @@ -1272,60 +1117,6 @@ relocateSection( *wordPtr = word; continue; } -#if defined(powerpc_HOST_ARCH) - else if(reloc->r_type == PPC_RELOC_LO16) - { - ((unsigned short*) wordPtr)[1] = word & 0xFFFF; - i++; - continue; - } - else if(reloc->r_type == PPC_RELOC_HI16) - { - ((unsigned short*) wordPtr)[1] = (word >> 16) & 0xFFFF; - i++; - continue; - } - else if(reloc->r_type == PPC_RELOC_HA16) - { - ((unsigned short*) wordPtr)[1] = ((word >> 16) & 0xFFFF) - + ((word & (1<<15)) ? 1 : 0); - i++; - continue; - } - else if(reloc->r_type == PPC_RELOC_BR24) - { - if ((word & 0x03) != 0) { - barf("%s: unconditional relative branch with a displacement " - "which isn't a multiple of 4 bytes: %#lx", - OC_INFORMATIVE_FILENAME(oc), - word); - } - - if((word & 0xFE000000) != 0xFE000000 && - (word & 0xFE000000) != 0x00000000) { - // The branch offset is too large. - // Therefore, we try to use a jump island. - if (jumpIsland == 0) { - barf("%s: unconditional relative branch out of range: " - "no jump island available: %#lx", - OC_INFORMATIVE_FILENAME(oc), - word); - } - - word = offsetToJumpIsland; - - if((word & 0xFE000000) != 0xFE000000 && - (word & 0xFE000000) != 0x00000000) { - barf("%s: unconditional relative branch out of range: " - "jump island out of range: %#lx", - OC_INFORMATIVE_FILENAME(oc), - word); - } - } - *wordPtr = (*wordPtr & 0xFC000003) | (word & 0x03FFFFFC); - continue; - } -#endif /* powerpc_HOST_ARCH */ } else { @@ -1822,10 +1613,6 @@ ocResolve_MachO(ObjectCode* oc) return 0; #endif -#if defined (powerpc_HOST_ARCH) - ocFlushInstructionCache( oc ); -#endif - return 1; } @@ -1865,53 +1652,6 @@ ocRunInit_MachO ( ObjectCode *oc ) return 1; } -#if defined(powerpc_HOST_ARCH) -/* - * The Mach-O object format uses leading underscores. But not everywhere. - * There is a small number of runtime support functions defined in - * libcc_dynamic.a whose name does not have a leading underscore. - * As a consequence, we can't get their address from C code. - * We have to use inline assembler just to take the address of a function. - * Yuck. - */ - -extern void* symbolsWithoutUnderscore[]; - -void -machoInitSymbolsWithoutUnderscore(void) -{ - void **p = symbolsWithoutUnderscore; - __asm__ volatile(".globl _symbolsWithoutUnderscore\n.data\n_symbolsWithoutUnderscore:"); - -#undef SymI_NeedsProto -#undef SymI_NeedsDataProto - -#define SymI_NeedsProto(x) \ - __asm__ volatile(".long " # x); - -#define SymI_NeedsDataProto(x) \ - SymI_NeedsProto(x) - - RTS_MACHO_NOUNDERLINE_SYMBOLS - - __asm__ volatile(".text"); - -#undef SymI_NeedsProto -#undef SymI_NeedsDataProto - -#define SymI_NeedsProto(x) \ - ghciInsertSymbolTable("(GHCi built-in symbols)", symhash, #x, *p++, HS_BOOL_FALSE, NULL); - -#define SymI_NeedsDataProto(x) \ - SymI_NeedsProto(x) - - RTS_MACHO_NOUNDERLINE_SYMBOLS - -#undef SymI_NeedsProto -#undef SymI_NeedsDataProto -} -#endif - /* * Figure out by how much to shift the entire Mach-O file in memory * when loading so that its single segment ends up 16-byte-aligned @@ -1930,8 +1670,7 @@ machoGetMisalignment( FILE * f ) } fseek(f, -sizeof(header), SEEK_CUR); -#if defined(x86_64_HOST_ARCH) || defined(powerpc64_HOST_ARCH) \ - || defined(aarch64_HOST_ARCH) +#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); |
