How to tell gcc to stop using built-in functions?

I use my own modified glibc. I saw in the compiled code that the compiler did not use many of the standard library functions from my glibc when I linked to it. Then I set the flag -fno-builtin. Everything became better, and I saw that now many functions were taken from there that were not taken from glibc, for example malloc.

However, for many functions, such as mmap, the compiler uses some built-in code. Now, how can I ask the compiler to use exclusively code from glibc and not use its built-in functions?

In my x86-64 function, if I execute the objdump of compiled glibc, the next is the generated mmap function. I cannot find equivalent code in glibc source.

0000000000000000 <__mmap>:
   0:   49 89 ca                mov    %rcx,%r10
   3:   b8 09 00 00 00          mov    $0x9,%eax
   8:   0f 05                   syscall 
   a:   48 3d 01 f0 ff ff       cmp    $0xfffffffffffff001,%rax
  10:   0f 83 00 00 00 00       jae    16 <__mmap+0x16>
  16:   c3                      retq  
+5
source share
2 answers

The wrapper that you parse above comes from the macro INLINE_SYSCALL in sysdeps / Unix / SysV / Linux / x86_64 / our header file sysdep.h. This macro is the “magic glue” used to incorporate a regular function call into a system call.

As part of the glibc build process, for every specific system call foothat is not on the list of special exceptions for this architecture, it generates a function __foothat contains only one macro INLINE_SYSCALL, is mmapnot on the list of exceptions for x86_64 (in sysdeps / unix / sysv / linux / x86_64 /syscalls.list), so he gets the general treatment.

+5
source

This is what the call mmapcompiles into my system:

movl    $1048837, 20(%esp)
movl    $1048836, 16(%esp)
movl    $1048835, 12(%esp)
movl    $1048834, 8(%esp)
movl    $1048833, 4(%esp)
movl    $1048832, (%esp)
call    mmap

0x100100 (1048832) mmap, .

, .

mmap . , i386 Linux sysdeps/unix/sysv/linux/i386/mmap.S (, ).

0

All Articles