Ticket #7287: link-hack.patch

File link-hack.patch, 4.7 KB (added by joshuadavidson@…, 10 years ago)

Patch provided by Luke Elliot to support linking in MinGW

  • libs\context\src\asm\fcontext_i386_ms_pe_masm.asm

     
    4040;  | fc_mxcsr|fc_x87_cw|                                        |
    4141;  --------------------------------------------------------------
    4242
    4343.386
    4444.XMM
    4545.model flat, c
    46 _exit PROTO, value:SDWORD
     46_exit PROTO, value:SDWORD
    4747align_stack PROTO, vp:DWORD
    4848seh_fcontext PROTO, except:DWORD, frame:DWORD, context:DWORD, dispatch:DWORD
    4949.code
    5050
    51 jump_fcontext PROC EXPORT
     51jump_fcontext_impl PROC
    5252    mov     ecx,         [esp+04h]  ; load address of the first fcontext_t arg
    5353    mov     [ecx],       edi        ; save EDI
    5454    mov     [ecx+04h],   esi        ; save ESI
    5555    mov     [ecx+08h],   ebx        ; save EBX
    5656    mov     [ecx+0ch],   ebp        ; save EBP
    5757
     
    104104
    105105    mov     esp,        [ecx+010h]  ; restore ESP
    106106    mov     [esp+04h],  eax         ; use third arg as first arg in context function
    107107    mov     ecx,        [ecx+014h]  ; fetch the address to return to
    108108
    109109    jmp     ecx                     ; indirect jump to context
    110 jump_fcontext ENDP
     110jump_fcontext_impl ENDP
    111111
    112 make_fcontext PROC EXPORT
     112make_fcontext_impl PROC
    113113    mov  eax,         [esp+04h]     ; load address of the fcontext_t arg0
    114114    mov  [eax],       eax           ; save the address of passed context
    115115    mov  ecx,         [esp+08h]     ; load the address of the context function
    116116    mov  [eax+014h],  ecx           ; save the address of the context function
    117117    mov  edx,         [eax+018h]    ; load the stack base
    118118
     
    144144
    145145finish:
    146146    xor   eax,        eax
    147147    push  eax                       ; exit code is zero
    148148    call  _exit                     ; exit application
    149149    hlt
    150 make_fcontext ENDP
     150make_fcontext_impl ENDP
    151151END
  • libs\context\src\asm\fcontext_x86_64_ms_pe_masm.asm

     
    8484
    8585EXTERN  _exit:PROC            ; standard C library function
    8686EXTERN  align_stack:PROC      ; stack alignment
    8787EXTERN  seh_fcontext:PROC     ; exception handler
    8888.code
    8989
    90 jump_fcontext PROC EXPORT FRAME:seh_fcontext
     90jump_fcontext_impl PROC FRAME:seh_fcontext
    9191    .endprolog
    9292
    9393    mov     [rcx],       r12        ; save R12
    9494    mov     [rcx+08h],   r13        ; save R13
    9595    mov     [rcx+010h],  r14        ; save R14
    9696    mov     [rcx+018h],  r15        ; save R15
     
    165165    mov     r10,        [rdx+048h]  ; fetch the address to returned to
    166166
    167167    mov     rax,        r8          ; use third arg as return value after jump
    168168    mov     rcx,        r8          ; use third arg as first arg in context function
    169169
    170170    jmp     r10                     ; indirect jump to caller
    171 jump_fcontext ENDP
     171jump_fcontext_impl ENDP
    172172
    173 make_fcontext PROC EXPORT FRAME  ; generate function table entry in .pdata and unwind information in    E
     173make_fcontext_impl PROC FRAME    ; generate function table entry in .pdata and unwind information in    E
    174174    .endprolog                   ; .xdata for a function's structured exception handling unwind behavior
    175175
    176176    mov  [rcx],      rcx         ; store the address of current context
    177177    mov  [rcx+048h], rdx         ; save the address of the function supposed to run
    178178    mov  rdx,        [rcx+050h]  ; load the address where the context stack beginns
    179179
     
    200200
    201201finish:
    202202    xor   rcx,        rcx
    203203    mov   [rsp+08h],  rcx
    204204    call  _exit                  ; exit application
    205205    hlt
    206 make_fcontext ENDP
     206make_fcontext_impl ENDP
    207207END
  • libs\context\src\fcontext.cpp

     
    2626        base = ( char * ) ( ( ( ( uintptr_t) base) - 15) & ~0x0F);
    2727    return base;
    2828}
    2929
    3030}
    3131
     32// HACK: GNU linker doesn't understand masm's EXPORT directive.
     33extern "C"
     34intptr_t BOOST_CONTEXT_CALLDECL jump_fcontext_impl( fcontext_t * ofc, fcontext_t const* nfc, intptr_t vp, bool preserve_fpu);
     35extern "C"
     36void BOOST_CONTEXT_CALLDECL make_fcontext_impl( fcontext_t * fc, void (* fn)( intptr_t) );
     37
     38extern "C" BOOST_CONTEXT_DECL
     39intptr_t BOOST_CONTEXT_CALLDECL jump_fcontext( fcontext_t * ofc, fcontext_t const* nfc, intptr_t vp, bool preserve_fpu)
     40{
     41        return jump_fcontext_impl(ofc, nfc, vp, preserve_fpu);
     42}
     43
     44extern "C" BOOST_CONTEXT_DECL
     45void BOOST_CONTEXT_CALLDECL make_fcontext( fcontext_t * fc, void (* fn)( intptr_t) )
     46{
     47        make_fcontext_impl(fc, fn);
     48}
     49
    3250}}
    3351
    3452#ifdef BOOST_HAS_ABI_HEADERS
    3553#  include BOOST_ABI_SUFFIX
    3654#endif