Drop support for i386 and PowerPC in MachO linker
authorArtem Pyanykh <artempyanykh@gmail.com>
Mon, 11 Feb 2019 11:05:23 +0000 (14:05 +0300)
committerMarge Bot <ben+marge-bot@smart-cactus.org>
Sat, 23 Feb 2019 04:47:32 +0000 (23:47 -0500)
Some code is broken, there are no CI targets (so not obvious how to
test), and no one seems to have built GHC for any of the above
platforms in years.

rts/Linker.c
rts/linker/MachO.c
rts/linker/MachO.h
rts/linker/MachOTypes.h

index b6f1de9..06b36ca 100644 (file)
@@ -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
index ca5befc..adcfcc7 100644 (file)
 #  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 */
index 4fb58e8..5e00e2a 100644 (file)
@@ -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"
index dcea906..c5923b4 100644 (file)
@@ -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