flat assembler
Message board for the users of flat assembler.

Index > Linux > .o for linking with gcc?

Author
Thread Post new topic Reply to topic
roxaz



Joined: 27 Jul 2008
Posts: 25
roxaz 10 Jul 2015, 12:44
Can fasm produce .o for linking it with gcc on linux? I am not sure how COFF is different from MS COFF but neither works. Im writing hoping i missed something in docs.
Post 10 Jul 2015, 12:44
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20421
Location: In your JS exploiting you and your system
revolution 10 Jul 2015, 12:51
I expect you need ELF format, not COFF.
Post 10 Jul 2015, 12:51
View user's profile Send private message Visit poster's website Reply with quote
alkap



Joined: 18 Feb 2015
Posts: 44
Location: Dnipro, Ukraine
alkap 10 Jul 2015, 16:25
roxaz wrote:
Can fasm produce .o for linking it with gcc on linux? I am not sure how COFF is different from MS COFF but neither works. Im writing hoping i missed something in docs.


The 'examples/elfobj' directory of the fasm distribution has instructions on how to generate '.o' files:
Code:
/path/to/fasm/examples/elfobj/msgdemo.asm:4,7
; compile the program using commands like:
;   fasm msgdemo.asm msgdemo.o
;   fasm writemsg.asm writemsg.o
;   ld msgdemo.o writemsg.o -o msgdemo
    
Post 10 Jul 2015, 16:25
View user's profile Send private message Send e-mail Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 10 Jul 2015, 20:23
Without more information, it's tricky to determine the cause. In addition to above, you may need to match your architecture if the default is 64bit by using "format ELF64". There's also the issue of linking: C style is basically just name matching but C++ style requires a matching prototype "hash", which you will have to adapt according to your particular compilation. i.e.
Code:
public my_function    
is fine for C regardless of the prototype but for C++ you might need:
Code:
public my_function as '?my_fuction1@@YAXPAD@Z'    
This hash can be obtained by doing a readelf on intermediate object of your C/C++ code.

Agner Fog's volume 5 here: http://www.agner.org/optimize/ details both the hashing and general ABI (if you were seeing run time failures it could suggest a calling mismatch)
Post 10 Jul 2015, 20:23
View user's profile Send private message Reply with quote
redsock



Joined: 09 Oct 2009
Posts: 434
Location: Australia
redsock 10 Jul 2015, 21:40
I just did a recent post about integrating my fasm library with gcc, with x86_64 at least, all that is required is
Code:
format ELF64
section '.text' executable align 16
public somesymbol
somesymbol:
    


See https://2ton.com.au/rants_and_musings/gcc_integration.html for working examples of this.

Cheers
Post 10 Jul 2015, 21:40
View user's profile Send private message Reply with quote
roxaz



Joined: 27 Jul 2008
Posts: 25
roxaz 11 Jul 2015, 06:52
indeed "format ELF64 " is exactly what i needed. i got confused thinking ELF64 must be .so while ELF64 executable must be.. executable.

thank you!
Post 11 Jul 2015, 06:52
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.