Ticket #2013: linker-freebsd-amd64.patch

File linker-freebsd-amd64.patch, 4.0 KB (added by mboes, 6 years ago)
  • rts/Linker.c

    old new  
    5959#include <sys/wait.h> 
    6060#endif 
    6161 
    62 #if defined(ia64_HOST_ARCH) || defined(openbsd_HOST_OS) || defined(linux_HOST_OS) || defined(freebsd_HOST_OS) 
     62#if defined(ia64_HOST_ARCH) || defined(linux_HOST_OS) || defined(freebsd_HOST_OS) || defined(netbsd_HOST_OS) || defined(openbsd_HOST_OS) 
    6363#define USE_MMAP 
    6464#include <fcntl.h> 
    6565#include <sys/mman.h> 
    6666 
    67 #if defined(openbsd_HOST_OS) || defined(linux_HOST_OS) || defined(freebsd_HOST_OS) 
     67#if defined(linux_HOST_OS) || defined(freebsd_HOST_OS) || defined(netbsd_HOST_OS) || defined(openbsd_HOST_OS) 
    6868#ifdef HAVE_UNISTD_H 
    6969#include <unistd.h> 
    7070#endif 
     
    11991199   struct stat st; 
    12001200   int r, n; 
    12011201#ifdef USE_MMAP 
     1202   /* In the absence of a MAP_32BIT flag to mmap() we map objects one 
     1203    * after the other starting from a fixed location in memory. */ 
    12021204   int fd, pagesize; 
    1203    void *map_addr = NULL; 
     1205   static void *map_addr = (void *)0x40000000L; 
    12041206#else 
    12051207   FILE *f; 
    12061208#endif 
     
    12621264 
    12631265#ifdef USE_MMAP 
    12641266#define ROUND_UP(x,size) ((x + size - 1) & ~(size - 1)) 
     1267#define ROUND_DOWN(x,size) (x & ~(size - 1)) 
    12651268 
    12661269   /* On many architectures malloc'd memory isn't executable, so we need to use mmap. */ 
    12671270 
     
    12781281#ifdef ia64_HOST_ARCH 
    12791282   /* The PLT needs to be right before the object */ 
    12801283   n = ROUND_UP(PLTSize(), pagesize); 
    1281    oc->plt = mmap(NULL, n, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); 
     1284   oc->plt = mmap(map_addr, n, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); 
    12821285   if (oc->plt == MAP_FAILED) 
    12831286      barf("loadObj: can't allocate PLT"); 
    12841287 
     
    12971300#if defined(x86_64_HOST_ARCH) && defined(MAP_32BIT) 
    12981301#define EXTRA_MAP_FLAGS MAP_32BIT 
    12991302#else 
    1300 #define EXTRA_MAP_FLAGS 0 
     1303#define EXTRA_MAP_FLAGS MAP_FIXED 
    13011304#endif 
    13021305 
    13031306   /* MAP_ANONYMOUS is MAP_ANON on some systems, e.g. OpenBSD */ 
     
    13091312                    MAP_PRIVATE|EXTRA_MAP_FLAGS, fd, 0); 
    13101313   if (oc->image == MAP_FAILED) 
    13111314      barf("loadObj: can't map `%s'", path); 
     1315   map_addr += n; 
    13121316 
    13131317   close(fd); 
    13141318 
     
    25962600#define Elf_Sym     Elf64_Sym 
    25972601#define Elf_Rel     Elf64_Rel 
    25982602#define Elf_Rela    Elf64_Rela 
     2603#if !defined(freebsd_HOST_OS) 
    25992604#define ELF_ST_TYPE ELF64_ST_TYPE 
    26002605#define ELF_ST_BIND ELF64_ST_BIND 
    26012606#define ELF_R_TYPE  ELF64_R_TYPE 
    26022607#define ELF_R_SYM   ELF64_R_SYM 
     2608#endif 
    26032609#else 
    26042610#define ELFCLASS    ELFCLASS32 
    26052611#define Elf_Addr    Elf32_Addr 
     
    27722778x86_64_high_symbol( char *lbl, void *addr ) 
    27732779{ 
    27742780    x86_64_bounce *bounce; 
     2781    int pagesize; 
     2782 
     2783    pagesize = getpagesize(); 
    27752784 
    2776     if ( x86_64_bounce_buffer == NULL ||  
     2785    if ( x86_64_bounce_buffer == NULL || 
    27772786         x86_64_bb_next_off >= X86_64_BB_SIZE ) { 
    2778         x86_64_bounce_buffer =  
    2779             mmap(NULL, X86_64_BB_SIZE * sizeof(x86_64_bounce),  
    2780                  PROT_EXEC|PROT_READ|PROT_WRITE,  
    2781                  MAP_PRIVATE|EXTRA_MAP_FLAGS|MAP_ANONYMOUS, -1, 0); 
     2787#ifdef MAP_32BIT 
     2788            x86_64_bounce_buffer = 
     2789                mmap(NULL, X86_64_BB_SIZE * sizeof(x86_64_bounce), 
     2790                     PROT_EXEC|PROT_READ|PROT_WRITE, 
     2791                     MAP_PRIVATE|EXTRA_MAP_FLAGS|MAP_ANONYMOUS, -1, 0); 
     2792#else 
     2793#define X86_64_BOUNCE_BUFFER_TOP 0x80000000L; 
     2794            x86_64_bounce *map_addr; 
     2795 
     2796            x86_64_bounce_buffer = x86_64_bounce_buffer ? 
     2797                    x86_64_bounce_buffer : (x86_64_bounce *)X86_64_BOUNCE_BUFFER_TOP; 
     2798            map_addr = x86_64_bounce_buffer - X86_64_BB_SIZE; 
     2799            map_addr = ROUND_DOWN((int)map_addr, pagesize); 
     2800            /* In the absence of MAP_32BIT we allocate the bounce 
     2801             * buffers at a fixed address, one after the other, 
     2802             * starting from the top and growing downwards. */ 
     2803            x86_64_bounce_buffer = 
     2804                mmap(map_addr, X86_64_BB_SIZE * sizeof(x86_64_bounce), 
     2805                     PROT_EXEC|PROT_READ|PROT_WRITE, 
     2806                     MAP_PRIVATE|EXTRA_MAP_FLAGS|MAP_ANONYMOUS, -1, 0); 
     2807#endif 
    27822808        if (x86_64_bounce_buffer == MAP_FAILED) { 
    2783             barf("x86_64_high_symbol: mmap failed"); 
     2809            barf("x86_64_high_symbol: mmap failed at %p", x86_64_bounce_buffer); 
    27842810        } 
    27852811        x86_64_bb_next_off = 0; 
    27862812    }