Is mmap a built-in function?

I know that mmap is a system call, but there must be some kind of shell in glibc that calls the system call. However, when I try to use gdb to execute the mmap function in my program, gdb ignores it because it cannot find any source file for it (note that I will compile my own glibc from the source code). I can perform other functions of the glibc library, such as printf and malloc, but not mmap. I also use the -fno-builtin flag so that gcc does not use built-in functions. Any help on this would be greatly appreciated.

+3
source share
1 answer

I do not know what the problem is. This works great for me.

libc.so.6 :

// mmap.c
#include <sys/mman.h>

int main()
{
  void *p = mmap(0, 4096, PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
  return 0;
}

gcc -g mmap.c


$ gdb -q a.out
Reading symbols from /tmp/a.out...done.
(gdb) start
Temporary breakpoint 1 at 0x40052c: file mmap.c, line 5.

Temporary breakpoint 1, main () at mmap.c:5
5         void *p = mmap(0, 4096, PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
(gdb) step
mmap64 () at ../sysdeps/unix/syscall-template.S:82
82      ../sysdeps/unix/syscall-template.S: No such file or directory.
(gdb) 
mmap64 () at ../sysdeps/unix/syscall-template.S:83
83      in ../sysdeps/unix/syscall-template.S
(gdb) 
main () at mmap.c:6
6         return 0;
(gdb) q

glibc:

gdb -q a.out
Reading symbols from /tmp/a.out...done.
(gdb) start
Temporary breakpoint 1 at 0x40056c: file mmap.c, line 5.
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?

Temporary breakpoint 1, main () at mmap.c:5
5         void *p = mmap(0, 4096, PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
(gdb) step
mmap64 () at ../sysdeps/unix/syscall-template.S:81
81      T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS)
(gdb) 
mmap64 () at ../sysdeps/unix/syscall-template.S:82
82              ret
(gdb) 
main () at mmap.c:6
6         return 0;
(gdb) q
+4

All Articles