From fbf6836aec9f7a8de06df59b09dad718fc2bcb80 Mon Sep 17 00:00:00 2001 From: Julian Seward Date: Sun, 20 Nov 2005 19:37:54 +0000 Subject: [PATCH] As with ppc it's necessary to have an initial redirect for index(strchr) on x86 glibc-2.3.5. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@5223 --- coregrind/m_redir.c | 14 ++++++++++- coregrind/m_trampoline.S | 44 ++++++++++++++++++++++++++++++++- coregrind/pub_core_trampoline.h | 1 + 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/coregrind/m_redir.c b/coregrind/m_redir.c index 5d8056dd17..56a89e499d 100644 --- a/coregrind/m_redir.c +++ b/coregrind/m_redir.c @@ -160,7 +160,11 @@ static void add_redir_to_resolved_list(CodeRedirect *redir, Bool need_discard) TRACE_REDIR(" redir %s:%s:%p->%p duplicated\n", redir->from_lib, redir->from_sym, redir->from_addr, redir->to_addr); - VG_(arena_free)(VG_AR_SYMTAB, redir); + // jrs 20 Nov 05: causes this: m_mallocfree.c:170 + // (mk_plain_bszB): Assertion 'bszB != 0' failed. + // Perhaps it is an invalid free? Disable for now + // XXX leak? + //VG_(arena_free)(VG_AR_SYMTAB, redir); } break; } @@ -362,6 +366,14 @@ void VG_(setup_code_redirect_table) ( void ) "soname:ld-linux.so.2", "_dl_sysinfo_int80", (Addr)&VG_(x86_linux_REDIR_FOR__dl_sysinfo_int80) ); + /* If we're using memcheck, use this intercept right from the + start, otherwise ld.so (glibc-2.3.5) makes a lot of noise. */ + if (0==VG_(strcmp)("Memcheck", VG_(details).name)) { + add_redirect_sym_to_addr( + "soname:ld-linux.so.2", "index", + (Addr)&VG_(x86_linux_REDIR_FOR_index) + ); + } #elif defined(VGP_amd64_linux) diff --git a/coregrind/m_trampoline.S b/coregrind/m_trampoline.S index 54a6a76d6a..e4930f9702 100644 --- a/coregrind/m_trampoline.S +++ b/coregrind/m_trampoline.S @@ -73,7 +73,49 @@ VG_(x86_linux_REDIR_FOR__dl_sysinfo_int80): /* We can point our sysinfo stuff here */ int $0x80 ret - + +/* There's no particular reason that this needs to be handwritten + assembly, but since that's what this file contains, here's a + simple index implementation (written in C and compiled by gcc.) + + unsigned char* REDIR_FOR_index ( const char* s, int c ) + { + unsigned char ch = (unsigned char)((unsigned int)c); + unsigned char* p = (unsigned char*)s; + unsigned char* last = 0; + while (1) { + if (*p == ch) last = p; + if (*p == 0) return last; + p++; + } + } +*/ +.global VG_(x86_linux_REDIR_FOR_index) +.type VG_(x86_linux_REDIR_FOR_index), @function +VG_(x86_linux_REDIR_FOR_index): + pushl %ebp + movl %esp, %ebp + pushl %ebx + movb 12(%ebp), %al + movl 8(%ebp), %ecx + movl $0, %ebx +.L2: + movb (%ecx), %dl + cmpb %dl, %al + jne .L3 + movl %ecx, %ebx +.L3: + testb %dl, %dl + je .L8 + addl $1, %ecx + jmp .L2 +.L8: + movl %ebx, %eax + popl %ebx + popl %ebp + ret +.size VG_(x86_linux_REDIR_FOR_index), .-VG_(x86_linux_REDIR_FOR_index) + .global VG_(trampoline_stuff_end) VG_(trampoline_stuff_end): diff --git a/coregrind/pub_core_trampoline.h b/coregrind/pub_core_trampoline.h index 95f58d4bff..68e1f7a3d3 100644 --- a/coregrind/pub_core_trampoline.h +++ b/coregrind/pub_core_trampoline.h @@ -51,6 +51,7 @@ extern void VG_(trampoline_stuff_end); extern void VG_(x86_linux_SUBST_FOR_sigreturn); extern void VG_(x86_linux_SUBST_FOR_rt_sigreturn); extern void VG_(x86_linux_REDIR_FOR__dl_sysinfo_int80); +extern Char* VG_(x86_linux_REDIR_FOR_index) ( const Char*, Int ); #endif #if defined(VGP_amd64_linux) -- 2.47.2