flat assembler
Message board for the users of flat assembler.

Index > Linux > linking fasm prog to libc using ld?

Author
Thread Post new topic Reply to topic
ProphetOfDoom



Joined: 08 Aug 2008
Posts: 120
Location: UK
ProphetOfDoom
Hi,

I want to write a fasm program that uses libc, and link it with ld. When I try to do this, the linker outputs a binary, but it's impossible to run it. It just says something like 'Bash: no such file or directory'.

I noticed someone had a similar problem ( http://board.flatassembler.net/topic.php?t=9456 ) but no-one posted a satisfactory solution as far as i can see.

I just want to use printf etc, in my fasm program, and link it with ld. It's a linker, it should link, right?

If you can help me you will be my god. Well, almost.

Thanks
Post 17 Aug 2009, 22:36
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
What do you get with "readelf {executable file} -l"?

I got this working on a 32-bit Debian:
Code:
; compile the source with commands like:
;   fasm printf.asm
;   ld printf.o -dynamic-linker /lib/ld-linux.so.2 -lc


format ELF

section '.text' executable

 public _start
 extrn printf
 extrn getpid
 extrn _exit

_start:
        call    getpid
        push    eax
        push    msg
        call    printf
        push    0
        call    _exit

section '.data' writeable
 msg db "Current process ID is %d.", 0xA,0    
(It is the libcdemo example modified to not need gcc to link).
Post 17 Aug 2009, 22:57
View user's profile Send private message Reply with quote
ProphetOfDoom



Joined: 08 Aug 2008
Posts: 120
Location: UK
ProphetOfDoom
thanks soooo much Loco! your example worked first time. Smile
Post 17 Aug 2009, 23: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-2020, Tomasz Grysztar.

Powered by rwasa.