Why printf prints with ld when a new line is present?

I am trying to intercept calls on printfusing a parameter ld -wrap. I have two files:

main.c:

#include <stdio.h>

int main(void) {
    printf("printing\n");
    printf("printing");
}

printf_wrapper.c:

int __real_printf(const char *format, ...);

int __wrap_printf(const char *format, ...) {
    (void)format;
    return __real_printf("WRAPPED\n");
}

And I compile the following command:

gcc -Wl,-wrap,printf *.c

When I run the resulting binary a.out, I get this output:

printing
WRAPPED

Why does the wrapper fail if there is a new line in the line? I checked the system stdio.h, and printf is not a macro. This is with gcc 5.3.0

+4
source share
1 answer

-fno-builtin, gcc . , -fno-builtin-printf, . , , . . gcc. https://gcc.gnu.org/onlinedocs/gcc-4.2.2/gcc/C-Dialect-Options.html

+2

All Articles