I need need to call some functions from different C libraries in my nasm program.
Libraries:
<sys/ptrace.h>
<sys/wait.h>
... and functions like ptrace, execl, wait, etc.
There are generally two ways to use C/or any other HLL function from assembly program:
Static linking - if you are using linker, you can link your program together with the needed HLL generated .obj or .lib file and
Dynamic linking - your program links to the needed functions during the loading, not the compilation. There are two possible implementations:
2.1. Manually load dynamic libraries and get the addresses of the needed functions. You have to use OS provided services for this. For example in Linux this is sys_uselib (pretty obsolete) or to load the library yourself and parse the ELF file for the function addresses;
2.2. Build import table containing list of libraries and functions you want to use. Then the OS loader will automatically provide addresses of the functions in a placeholder variables from where you can call them indirectly.
All these methods are highly OS and assembler dependent, so I can provide example only for the assembler I use :
Import macros for FreshLib that build import tables for Linux.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.