From 2db41020963905ee09fa4303f9783f7bc419e747 Mon Sep 17 00:00:00 2001 From: Julian Seward Date: Sat, 21 Jun 2014 09:34:22 +0000 Subject: [PATCH] Redirect strchr in dyld (the dynamic linker) on OS X 10.9, for the usual reason. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14070 --- coregrind/m_redir.c | 4 ++++ coregrind/m_trampoline.S | 23 +++++++++++++++++++++++ coregrind/pub_core_trampoline.h | 3 +++ 3 files changed, 30 insertions(+) diff --git a/coregrind/m_redir.c b/coregrind/m_redir.c index e5dc248931..b13b3fba4d 100644 --- a/coregrind/m_redir.c +++ b/coregrind/m_redir.c @@ -1387,6 +1387,10 @@ void VG_(redir_initialise) ( void ) // DDD: #warning fixme rdar://6166275 add_hardwired_spec("dyld", "arc4random", (Addr)&VG_(amd64_darwin_REDIR_FOR_arc4random), NULL); +# if DARWIN_VERS == DARWIN_10_9 + add_hardwired_spec("dyld", "strchr", + (Addr)&VG_(amd64_darwin_REDIR_FOR_strchr), NULL); +# endif } # elif defined(VGP_s390x_linux) diff --git a/coregrind/m_trampoline.S b/coregrind/m_trampoline.S index a1c4dec411..5dd362c402 100644 --- a/coregrind/m_trampoline.S +++ b/coregrind/m_trampoline.S @@ -1081,6 +1081,29 @@ VG_(amd64_darwin_REDIR_FOR_arc4random): movq $0x76616c6772696e64, %rax ret +.globl VG_(amd64_darwin_REDIR_FOR_strchr) +VG_(amd64_darwin_REDIR_FOR_strchr): + pushq %rbp + movq %rsp, %rbp + movb (%rdi), %cl + cmpb %sil, %cl + jne 1f + movq %rdi, %rax + popq %rbp + ret +1: + testb %cl, %cl + movl $0, %eax + je 2f + movb 1(%rdi), %cl + incq %rdi + cmpb %sil, %cl + movq %rdi, %rax + jne 1b +2: + popq %rbp + ret + .globl VG_(trampoline_stuff_end) VG_(trampoline_stuff_end): diff --git a/coregrind/pub_core_trampoline.h b/coregrind/pub_core_trampoline.h index 755f8b90b2..96710fe8d0 100644 --- a/coregrind/pub_core_trampoline.h +++ b/coregrind/pub_core_trampoline.h @@ -129,6 +129,9 @@ extern char* VG_(amd64_darwin_REDIR_FOR_strcpy)( char *s1, char *s2 ); extern SizeT VG_(amd64_darwin_REDIR_FOR_strlcat)( char *s1, const char *s2, SizeT size ); extern UInt VG_(amd64_darwin_REDIR_FOR_arc4random)( void ); +# if DARWIN_VERS == DARWIN_10_9 + extern char* VG_(amd64_darwin_REDIR_FOR_strchr)( const char*, int ); +# endif #endif #if defined(VGP_s390x_linux) -- 2.47.3