|
From: Yeshurun, M. <mei...@in...> - 2005-08-17 11:38:56
|
It's possible that printf is a small inline function or a template function (which then turns around and calls fprintf) that is compiled into your program, not one of the so's. You need to find a way to leave the code for printf out of your program, so your program will have to call the code for printf that is in one of the so's.=20 Regards, Meir -----Original Message----- From: val...@li... [mailto:val...@li...] On Behalf Of Rob Holland Sent: Wednesday, August 17, 2005 2:02 PM To: valgrind-users Subject: [Valgrind-users] Replacing printf Hi, As part of the format check code I need to replace printf with our own version which runs some sanity checks. I've happily managed to replace fprintf and some others, but not printf. Anyone know what's special about printf and why I can't replace it with VG_REPLACE_FUNCTION like I can the others? The output of 'valgrind --tool=3Dformatcheck --trace-redirs=3Dyes = /tmp/test' looks the same whether I try to replace fprintf or printf (save the different function name obviously), but when trying to redirect the printf function my replacement isn't actually called :/ It's not helped that I don't quite understand the syntax of the trace-redirs report. It says it's loaded vg_preload_core.so and then lists some REDIRS including the (f)printf one which is in my preload library which it hasn't loaded yet, then it says it's loaded my preload, but there is no mention of the (f)printf redir which is there. If I remove the VG_REPLACE_FUNCTION from my code, it doesn't mention any (f)printf redirections, so I'm assuming there is no printf redirection in the core valgrind. Example: <header snipped> --30136-- Just loaded /tmp/a.out (soname=3D(null)), --30136-- resolving any unresolved redirs with it --30136-- Finished resolving --30136-- Just loaded /lib64/ld-2.3.5.so = (soname=3Dld-linux-x86-64.so.2), --30136-- resolving any unresolved redirs with it --30136-- Finished resolving --30136-- REDIRECT addr to addr: 0xFFFFFFFFFF600000 to 0x7002B2DB --30136-- redir resolved ((null):(null)=3D0xFFFFFFFFFF600000 -> 0x7002B2DB) --30136-- Discarding translation due to redirect of already loaded function --30136-- (null):(null)(0xFFFFFFFFFF600000) -> 0x7002B2DB) --30136-- REDIRECT addr to addr: 0xFFFFFFFFFF600400 to 0x7002B2E5 --30136-- redir resolved ((null):(null)=3D0xFFFFFFFFFF600400 -> 0x7002B2E5) --30136-- Discarding translation due to redirect of already loaded function --30136-- (null):(null)(0xFFFFFFFFFF600400) -> 0x7002B2E5) =3D=3D30136=3D=3D For more details, rerun with: -v =3D=3D30136=3D=3D=20 --30136-- Just loaded /usr/local/lib64/valgrind/vg_preload_core.so (soname=3Dvg_preload_core.so), --30136-- resolving any unresolved redirs with it --30136-- Finished resolving --30136-- REDIR sym to addr: soname:libc.so.6:_Znwm to 0x25719C0F --30136-- REDIR sym to addr: soname:libstdc++*:builtin_new to 0x25719840 --30136-- REDIR sym to addr: soname:libc.so.6:__builtin_vec_delete to 0x2571A821 --30136-- REDIR sym to addr: soname:libstdc++*:_ZnamRKSt9nothrow_t to 0x2571A124 --30136-- REDIR sym to addr: soname:libstdc++*:__builtin_vec_new to 0x25719E18 --30136-- REDIR sym to addr: soname:libc.so.6:_ZnamRKSt9nothrow_t to 0x2571A1C7 --30136-- REDIR sym to addr: soname:libc.so.6:__builtin_new to 0x25719A89 --30136-- REDIR sym to addr: soname:libc.so.6:_ZdlPvRKSt9nothrow_t to 0x2571A717 --30136-- REDIR sym to addr: soname:libc.so.6:_ZdlPv to 0x2571A60D --30136-- REDIR sym to addr: soname:libstdc++*:_ZnwmRKSt9nothrow_t to 0x25719CD2 --30136-- REDIR sym to addr: soname:libc.so.6:memalign to 0x2571AC4E --30136-- REDIR sym to addr: soname:libc.so.6:_ZnwmRKSt9nothrow_t to 0x25719D75 --30136-- REDIR sym to addr: soname:libc.so.6:realloc to 0x2571AB63 --30136-- REDIR sym to addr: soname:libc.so.6:_ZdaPv to 0x2571A92B --30136-- REDIR sym to addr: soname:libc.so.6:malloc_trim to 0x2571AE72 --30136-- REDIR sym to addr: soname:libc.so.6:free to 0x2571A2EF --30136-- REDIR sym to addr: soname:libstdc++*:malloc to 0x257196FA --30136-- REDIR sym to addr: soname:libc.so.6:mallopt to 0x2571AD2C --30136-- REDIR sym to addr: soname:libstdc++*:_Znam to 0x25719F9E --30136-- REDIR sym to addr: soname:libc.so.6:malloc_set_state to 0x2571AE96 --30136-- REDIR sym to addr: soname:libstdc++*:_ZdlPvRKSt9nothrow_t to 0x2571A692 --30136-- REDIR sym to addr: soname:libc.so.6:cfree to 0x2571A3F9 --30136-- REDIR sym to addr: soname:libc.so.6:__builtin_delete to 0x2571A503 --30136-- REDIR sym to addr: soname:libstdc++*:free to 0x2571A26A --30136-- REDIR sym to addr: soname:libc.so.6:__builtin_vec_new to 0x25719EDB --30136-- REDIR sym to addr: soname:libc.so.6:valloc to 0x2571AD19 --30136-- REDIR sym to addr: soname:libc.so.6:malloc to 0x2571979D --30136-- REDIR sym to addr: soname:libc.so.6:mallinfo to 0x2571AEA8 --30136-- REDIR sym to addr: soname:libstdc++*:_ZdlPv to 0x2571A588 --30136-- REDIR sym to addr: soname:libstdc++*:__builtin_new to 0x257199C6 --30136-- REDIR sym to addr: soname:libc.so.6:pvalloc to 0x2571AE4E --30136-- REDIR sym to addr: soname:libc.so.6:builtin_new to 0x25719903 --30136-- REDIR sym to addr: soname:libstdc++*:__builtin_delete to 0x2571A47E --30136-- REDIR sym to addr: soname:libc.so.6:printf to 0x2571AF50 --30136-- REDIR sym to addr: soname:libc.so.6:calloc to 0x2571AABA --30136-- REDIR sym to addr: soname:libstdc++*:_Znwm to 0x25719B4C --30136-- REDIR sym to addr: soname:libc.so.6:malloc_stats to 0x2571AE60 --30136-- REDIR sym to addr: soname:libstdc++*:cfree to 0x2571A374 --30136-- REDIR sym to addr: soname:libc.so.6:malloc_get_state to 0x2571AE84 --30136-- REDIR sym to addr: soname:libc.so.6:posix_memalign to 0x2571AD37 --30136-- REDIR sym to addr: soname:libstdc++*:__builtin_vec_delete to 0x2571A79C --30136-- REDIR sym to addr: soname:libc.so.6:malloc_usable_size to 0x2571AD80 --30136-- REDIR sym to addr: soname:libc.so.6:_ZdaPvRKSt9nothrow_t to 0x2571AA35 --30136-- REDIR sym to addr: soname:libstdc++*:_ZdaPvRKSt9nothrow_t to 0x2571A9B0 --30136-- REDIR sym to addr: soname:libstdc++*:_ZdaPv to 0x2571A8A6 --30136-- REDIR sym to addr: soname:libc.so.6:_Znam to 0x2571A061 --30136-- Just loaded /usr/local/lib64/valgrind/vgpreload_formatcheck.so (soname=3D(null)), --30136-- resolving any unresolved redirs with it --30136-- Finished resolving --30136-- Just loaded /lib64/tls/libc-2.3.5.so (soname=3Dlibc.so.6), --30136-- resolving any unresolved redirs with it --30136-- redir resolved (soname:libc.so.6:malloc_usable_size=3D0x2588FAC0 -> 0x2571AD80) --30136-- redir resolved (soname:libc.so.6:posix_memalign=3D0x25893CA0 -> 0x2571AD37) --30136-- redir resolved = (soname:libc.so.6:malloc_get_state=3D0x258926A0 -> 0x2571AE84) --30136-- redir resolved (soname:libc.so.6:malloc_stats=3D0x25893170 = -> 0x2571AE60) --30136-- redir resolved (soname:libc.so.6:calloc=3D0x25891EE0 -> 0x2571AABA) --30136-- redir resolved (soname:libc.so.6:printf=3D0x2586FE60 -> 0x2571AF50) --30136-- redir resolved (soname:libc.so.6:pvalloc=3D0x25893330 -> 0x2571AE4E) --30136-- redir resolved (soname:libc.so.6:mallinfo=3D0x258930B0 -> 0x2571AEA8) --30136-- redir resolved (soname:libc.so.6:malloc=3D0x25892210 -> 0x2571979D) --30136-- redir resolved (soname:libc.so.6:valloc=3D0x25893430 -> 0x2571AD19) --30136-- redir resolved = (soname:libc.so.6:malloc_set_state=3D0x25893520 -> 0x2571AE96) --30136-- redir resolved (soname:libc.so.6:mallopt=3D0x25893010 -> 0x2571AD2C) --30136-- redir resolved (soname:libc.so.6:free=3D0x25890630 -> 0x2571A2EF) --30136-- redir resolved (soname:libc.so.6:malloc_trim=3D0x2588FE70 -> 0x2571AE72) --30136-- redir resolved (soname:libc.so.6:realloc=3D0x25892860 -> 0x2571AB63) --30136-- redir resolved (soname:libc.so.6:memalign=3D0x258924B0 -> 0x2571AC4E) --30136-- Finished resolving --30136-- Just loaded /lib64/libdl-2.3.5.so (soname=3Dlibdl.so.2), --30136-- resolving any unresolved redirs with it --30136-- Finished resolving foo =3D=3D30136=3D=3D The code is of course available should anyone feel it would be helpful, but as it works fine for fprintf I'm assuming the code is ok and that printf is "special" in some way I'm unaware of. Thanks, Rob --=20 - Rob Holland [ Gentoo Audit Team ] |