flat assembler
Message board for the users of flat assembler.

Index > Windows > Linking FASM MS64 COFF static object with GCC

Author
Thread Post new topic Reply to topic
system error



Joined: 01 Sep 2013
Posts: 670
system error 09 Apr 2016, 06:49
Never used MS COFF/MS64 COFF before in my life but last night I managed to link the 32-bit version, but no such luck with MS64 COFF. I used this;

Code:
 gcc test.obj -o test.exe    


It emits "File format not recognized" or something like that

The code;

Code:
;test.asm
format MS64 COFF

public main ;as 'main'
extrn printf

section '.data' data readable writeable align 16
align 16
x dq -0.1756522
fmt db '%f',0
msg db 'Hello World',0ah,0

section '.code' code readable executable align 16
align 16
main:
        sub     rsp,32
        mov     rcx,msg
        call    printf
        movq    xmm0,[x]
        mov     rcx,fmt
        call    printf
        add     rsp,32
        ret    


What did I miss?

EDIT: test.obj, not test.o
Post 09 Apr 2016, 06:49
View user's profile Send private message Reply with quote
system error



Joined: 01 Sep 2013
Posts: 670
system error 09 Apr 2016, 07:27
For comparison. this is the 32-bit version that works

Code:
;gcc test.obj -o test.exe
format MS COFF

public main as '_main'
extrn _printf

main:
        push    ebp
        mov     ebp,esp
        push    msg
        call    _printf
        add     esp,4
        sub     esp,8
        push    [x]
        fld     dword[x]
        fstp    qword[esp]
        push    fmt
        call    _printf
        add     esp,12
        mov     esp,ebp
        pop     ebp
        ret

x dd -0.1756522
fmt db '%f',0
msg db 'Hello World LOL LOL',0ah,0    
Post 09 Apr 2016, 07:27
View user's profile Send private message Reply with quote
eeikel



Joined: 17 Jun 2013
Posts: 7
Location: NL
eeikel 14 Apr 2016, 09:32
in c: void aFunction();

Code:
 
     format MS64 COFF 
     public aFunction
     section '.data' data readable writeable align 16
     the_x dq -0.1756522 
     fmt db '%f',0 
     msg db 'Hello World',0ah,0 
     section '.code' code readable executable ;align 16
     extrn 'printf' as _printf
                                        aFunction:

                                                  sub     rsp,32
                                                  mov     rcx,msg 
                                                  call    _printf
                                                  movq    xmm0, [the_x] 
                                                  mov     rcx, fmt ; rcx returned value
                                                  call    _printf
                                                  add     rsp,32 
                                                  ret              
    
Post 14 Apr 2016, 09:32
View user's profile Send private message Reply with quote
system error



Joined: 01 Sep 2013
Posts: 670
system error 15 Apr 2016, 07:35
thanks man. But when I use GCC, shouldn't I comply to the C structure (main, _main, WinMain@xyxyxyxyxyxyzz, mainCRTStartup and stuff)?
Post 15 Apr 2016, 07:35
View user's profile Send private message Reply with quote
eeikel



Joined: 17 Jun 2013
Posts: 7
Location: NL
eeikel 15 Apr 2016, 08:11
No you just do in c:
Code:
void aFunction();

int main(){
                 aFunction();

return 0;
}
    


link the file test.OBJ
in eclipse project -> properties -> c/c++ build -> tab: tool settings -> mingWC linker -> Miscellanious -> other objects
Post 15 Apr 2016, 08:11
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.