LD_PRELOAD not working for printf
Asked Answered
K

1

5

i am using LD_PRELOAD to capture write() system call in linux . I am successfully able to do this for write system call and make it work.

But when i call printf() that time it does not work. If we observe printf stack trace using strace i found that, at the end printf calls write() system call to write to console, but at that time my write() system call is not called before actually calling the the write() system call.

Anybody have any idea why is this happening ?

Knowitall answered 22/3, 2011 at 18:7 Comment(2)
Post some code snippets so we can see what's happening.Snowden
This might also be related.Didynamous
K
12

Function calls made from one library to another or from the executable to a dynamically loaded library go through the PLT (Procedure Linkage Table) and are able to be redirected by the use of LD_PRELOAD. However, function calls within a library can be resolved at compile time and do not go through the PLT. Therefore they are unable to be redirected by LD_PRELOAD. Since printf and write are both compiled into libc.so.6, the call to write from printf never goes through the PLT to look for a possible redirection, but when you call write directly from your application (or from another shared library) it does.

Kuhlman answered 22/3, 2011 at 18:40 Comment(1)
is this tribal knowledge? Where can I read more about this?Stjohn

© 2022 - 2024 — McMap. All rights reserved.