diff --git a/coregrind/m_main.c b/coregrind/m_main.c index 63e5e1448..4500c222a 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -2398,8 +2398,12 @@ Int main(Int argc, HChar **argv, HChar **envp) // p: aspacem //-------------------------------------------------------------- { Bool change_ownership_v_c_OK; - Addr co_start = VG_PGROUNDDN( (Addr)&VG_(trampoline_stuff_start) ); - Addr co_endPlus = VG_PGROUNDUP( (Addr)&VG_(trampoline_stuff_end) ); + Addr co_start = VG_PGROUNDDN( + (Addr)VG_(fnptr_to_fnentry)( + &VG_(trampoline_stuff_start) ) ); + Addr co_endPlus = VG_PGROUNDUP( + (Addr)VG_(fnptr_to_fnentry)( + &VG_(trampoline_stuff_end) ) ); VG_(debugLog)(1,"redir", "transfer ownership V -> C of 0x%llx .. 0x%llx\n", (ULong)co_start, (ULong)co_endPlus-1 ); diff --git a/coregrind/m_redir.c b/coregrind/m_redir.c index 153998003..53b0dddd2 100644 --- a/coregrind/m_redir.c +++ b/coregrind/m_redir.c @@ -43,6 +43,7 @@ #include "pub_core_trampoline.h" #include "pub_core_transtab.h" #include "pub_core_tooliface.h" // VG_(needs).malloc_replacement +#include "pub_tool_machine.h" // VG_(fnptr_to_fnentry) /*------------------------------------------------------------*/ @@ -406,7 +407,16 @@ void VG_(setup_code_redirect_table) ( void ) #elif defined(VGP_ppc64_linux) - // we'll have to stick some godawful hacks in here, no doubt + /* If we're using memcheck, use these intercepts right from + the start, otherwise ld.so makes a lot of noise. */ + if (0==VG_(strcmp)("Memcheck", VG_(details).name)) { + + add_redirect_sym_to_addr( + "soname:ld64.so.1", "strlen", + (Addr)VG_(fnptr_to_fnentry)( &VG_(ppc64_linux_REDIR_FOR_strlen) ) + ); + + } #else # error Unknown platform diff --git a/coregrind/m_trampoline.S b/coregrind/m_trampoline.S index 1da47dde6..f2e0c8a32 100644 --- a/coregrind/m_trampoline.S +++ b/coregrind/m_trampoline.S @@ -277,6 +277,9 @@ VG_(ppc32_linux_REDIR_FOR_strchr): .global VG_(trampoline_stuff_end) VG_(trampoline_stuff_end): + /* and a trailing page of unexecutable code */ + UD2_PAGE + # undef UD2_16 # undef UD2_64 # undef UD2_256 @@ -306,7 +309,32 @@ VG_(trampoline_stuff_start): .type .VG_(trampoline_stuff_start),@function .global .VG_(trampoline_stuff_start) .VG_(trampoline_stuff_start): - + +.align 2 +.globl VG_(ppc64_linux_REDIR_FOR_strlen) +.section ".opd","aw" +.align 3 +VG_(ppc64_linux_REDIR_FOR_strlen): +.quad .L.VG_(ppc64_linux_REDIR_FOR_strlen),.TOC.@tocbase +.previous +.type VG_(ppc64_linux_REDIR_FOR_strlen), @function +.L.VG_(ppc64_linux_REDIR_FOR_strlen): + mr 9,3 + lbz 0,0(3) + li 3,0 + cmpwi 7,0,0 + beqlr 7 + li 3,0 +.L5: + addi 0,3,1 + extsw 3,0 + lbzx 0,9,3 + cmpwi 7,0,0 + bne 7,.L5 + blr + .long 0 + .byte 0,0,0,0,0,0,0,0 + .size VG_(ppc64_linux_REDIR_FOR_strlen),.-.L.VG_(ppc64_linux_REDIR_FOR_strlen) .align 2 .global VG_(trampoline_stuff_end) @@ -319,6 +347,9 @@ VG_(trampoline_stuff_end): .global .VG_(trampoline_stuff_end) .VG_(trampoline_stuff_end): + /* and a trailing page of unexecutable code */ + UD2_PAGE + # undef UD2_16 # undef UD2_64 # undef UD2_256 diff --git a/coregrind/pub_core_trampoline.h b/coregrind/pub_core_trampoline.h index 68e1f7a3d..0113fa70c 100644 --- a/coregrind/pub_core_trampoline.h +++ b/coregrind/pub_core_trampoline.h @@ -65,6 +65,10 @@ extern UInt VG_(ppc32_linux_REDIR_FOR_strlen)( void* ); extern UInt VG_(ppc32_linux_REDIR_FOR_strcmp)( void*, void* ); extern void* VG_(ppc32_linux_REDIR_FOR_strchr)( void*, Int ); #endif + +#if defined(VGP_ppc64_linux) +extern UInt VG_(ppc64_linux_REDIR_FOR_strlen)( void* ); +#endif #endif // __PUB_CORE_TRAMPOLINE_H