flat assembler
Message board for the users of flat assembler.

flat assembler > Linux > ELF executable + library calls?

Author
Thread Post new topic Reply to topic
AMD64



Joined: 19 Sep 2003
Posts: 8
When an executable ELF module is assembled, the extrn directive isn't functional, this is also stated in the docs. But, shouldn't there be a way to call external library functions from all those ".so" libraries...? Sure I could create a non-executable ELF-object with FAsm, use extrn, and link the module with gcc (ld),.. but would be nice to be able to code it all with one tool. Just like windows PE-exes can be very nicely crafted with just using FAsm.

Not sure if I'm missing something, but shouldn't the Linux library-import system work just like the thing with non-executable linkable objects..? But just using dynamic linking... or would I need to call some kernel functions myself through int 80h to load the library and do some dark magic trickery to find the function addresses... I don't think (or at least hope) so... Wink
Sorry, this is prolly a very silly question, but I'm a n00b in Linux asm coding. Some experinced guy come and help me out, please... Wink
Post 08 May 2008, 10:30
View user's profile Send private message Reply with quote
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
The dlopen(), dlysm() and dlclose() functions are the ones you're after if you are building an Executable ELF directly and wish to load *.so's at runtime (eg if you're using a plug-in architecture when you don't know in advance what *.so's you're linking to)...

http://www.opengroup.org/onlinepubs/009695399/functions/dlopen.html

Or otherwise build you're asm file as an Object ELF file (and hence the extern is available), and link to the *.so's using either gcc or ld to create your executable.

eg
Code:
> fasm myfile.asm myfile.o
> gcc -lGL -lDSL -lm -o myfile myfile.o
> ldd -r main
   libc.so.1 =>     /usr/lib/libc.so.1
   libelf.so.1 =>   /usr/lib/libelf.so.1
   libm.so =>       /usr/lib/libm.so
   libGL.so =>      /usr/X11R6/lib/libGL.so
   libSDL.so =>     /usr/lib/libSDL.so    


(The -lGL denotes to link to libGL.so)...
Post 09 May 2008, 03:26
View user's profile Send private message Visit poster's website Reply with quote
Endre



Joined: 29 Dec 2003
Posts: 212
Location: Budapest, Hungary
Post 09 May 2008, 07:34
View user's profile Send private message Reply with quote
AMD64



Joined: 19 Sep 2003
Posts: 8
Thank you for your help fellows.
I get it now. Wink
Just lately abandoned Windows and switched to Linux completely... time has come for it. Not going back. Ever Wink
Internal support for extrn + executable elf in fasm would be nice, but no problem... just wanted to hyper-optimize a little proggy Wink Well, dunno how much fluff does using ld bring in the program... shouldn't be much, as it should just create the import stuff needed and nothing else, if calling gcc with -nostdlib switch.

Thanks again... and may the future be filled with penguins... Wink
Post 10 May 2008, 15:30
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-2018, Tomasz Grysztar.

Powered by rwasa.