flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
jorido
Say, I want to use this http://man7.org/linux/man-pages/man3/socket.3p.html or this http://man7.org/linux/man-pages/man3/getaliasent_r.3.html function or both:
Code: extrn socket extrn getaliasent_r How should I compile and link a source assembly file in this case? And how do I know where those functions are defined so that I'll be able to link those files to my assembly file? |
|||
![]() |
|
zhak
There's an example included in fasm package: libcdemo or elfexe/dynamic
|
|||
![]() |
|
jorido
This?
Code: interpreter '/lib64/ld-linux-x86-64.so.2' needed 'libc.so.6' import printf,exit But where is "extrn"? And what if my file format isn't "executable 3" either? |
|||
![]() |
|
system error
I've read your other posts and I take it that you come from NASM background. Well, this is one area where NASM is not familiar with - dynamic linking. Get used to it and welcome to FASM.
|
|||
![]() |
|
jorido
Thanks, how about static linking?
|
|||
![]() |
|
system error
For static linking, the step is the same as with NASM. If you're looking for source comparison, here's the static version
Code: format ELF64 public main extrn printf section '.data' writeable hello db 'hello world',0ah,0 section '.code' executable main: mov rdi,hello call printf ret ;link against: gcc -m64 yourfile.o -o yourfile I didn't test this bcoz I don't have linux at this moment, but the code should work. Even if it doesn't, just pay attention to the structural differences (section, format, public etc) |
|||
![]() |
|
jorido
Why not ld for linking?
Is this a correct way? Code: ld hello.o -dynamic-linker /lib64/ld-linux-x86-64.so.2 -lc -melf_x86_64 |
|||
![]() |
|
system error
jorido
if you're linking to dynamic library, just use the first example. if you're linking to static library, you can use pretty much anything you know of using. asking people about static and extrn thingies and yet using --dynamic-linker switch is not obviously smart from source structure point of view, because dynamic and static sources are different at the source code level. (segment vs section, ELF64 vs ELF64 executable 3, public vs entry etc). If you trying to force NASM's way of doing things upon FASM, then you'll not learn anything new today. |
|||
![]() |
|
jorido
So why not ld?
|
|||
![]() |
|
system error
@jorido
If I use ld, then I cannot use "format ELF64 executable 3". I don't need "ld" to create an executable directly via FASM to access "libc.so.6". Why should I? |
|||
![]() |
|
jorido
Alright.
What if there were other "so" library, would you still be able to use gcc? Also: include 'import64.inc' error: file not found. Where should I get it? |
|||
![]() |
|
system error
import64.inc is in the /examples/elfexe/dynamic/
you'd probably need "elf.inc" as well. Just make sure you have these two available in a the same path every time you're compiling. In the examples folder, there are also examples of using both ld and gcc if you wished to perform static linking instead (like you always do in NASM). Good luck |
|||
![]() |
|
jorido
thanks.
|
|||
![]() |
|
moveax41h
I got a question here for Linux. I'm getting an error from fasm saying this is not a legal instruction:
Code: interpreter '/lib64/ld-linux-x86-64.so.2' needed 'libc.so.6' On Windows, I used to do something like Code: library 'kernel32.dll', import 'printf', \ 'scanf' etc I want to dynamically link those libc functions in on Linux. |
|||
![]() |
|
revolution
"interpreter" and "needed" are macros, not instructions or directives. You will need to have some other macro file included to process those two lines.
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.