I’m currently coding my implementation of the malloc() function, so I’m compiling with the following flags: -m64 -fPIC -pedantic -Wall -Wextra -Werror -nostdlib -ggdb3.
For the time being, I’m compiling as an executable and not as a shared library.
For my implementation I’m using the header files stddef.h stdint.h unistd.h, for the moment I need the syscall sbrk(). The problem is that on compilation I get the following error: undefined reference to sbrk.
I assume that sbrk() and more generally unistd.h are disabled if I compile with -nostdlib but how can I compile without the glibc but with the system calls?
Thanks in advance
P.S I really need to use sbrk() I can’t use mmap(), don’t encourage me to do it.
>Solution :
In this case, don’t use -nostdlib. glibc has special support for replacing malloc()
This should enable sbrk() to work. Don’t start multiple threads or you will have a headache.
If you can’t find sbrk(), call mmap() instead. sbrk() is obsolete and doesn’t interact very well with modern system facilities.