Bug 338615

Summary: Intercept glibc 2.20 optimized strcmp implementation for ARMv7
Product: [Developer tools] valgrind Reporter: Mark Wielaard <mark>
Component: generalAssignee: Julian Seward <jseward>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: Suppress glibc 2.20 optimized strcmp implementation for ARMv7.

Description Mark Wielaard 2014-08-28 08:00:31 UTC
The newly introduced optimized strcmp implementation for ARMv7 in glibc 2.20 seems to confuse memcheck a lot. Just running /bin/true under valgrind gives:

==7193== Invalid write of size 4
==7193==    at 0x401BC9C: strcmp (in /usr/lib/ld-2.19.90.so)
==7193==  Address 0xbd9c5e30 is just below the stack ptr.  To suppress, use: --w
orkaround-gcc296-bugs=yes
==7193== 
==7193== Use of uninitialised value of size 4
==7193==    at 0x4012774: _dl_name_match_p (in /usr/lib/ld-2.19.90.so)
==7193==    by 0x4009743: _dl_map_object (in /usr/lib/ld-2.19.90.so)
==7193==    by 0x4000E27: map_doit (in /usr/lib/ld-2.19.90.so)
==7193==    by 0x4011683: _dl_catch_error (in /usr/lib/ld-2.19.90.so)
==7193==    by 0x4000893: do_preload (in /usr/lib/ld-2.19.90.so)
==7193==    by 0x4003563: dl_main (in /usr/lib/ld-2.19.90.so)
==7193==  Uninitialised value was created by a stack allocation
==7193==    at 0x401BC9C: strcmp (in /usr/lib/ld-2.19.90.so)
==7193== 
==7193== Use of uninitialised value of size 4
==7193==    at 0x401BC90: ??? (in /usr/lib/ld-2.19.90.so)
==7193==  Uninitialised value was created by a stack allocation
==7193==    at 0x401BC9C: strcmp (in /usr/lib/ld-2.19.90.so)
==7193== 
==7193== Conditional jump or move depends on uninitialised value(s)
==7193==    at 0x401BCB0: strcmp (in /usr/lib/ld-2.19.90.so)
==7193==  Uninitialised value was created by a stack allocation
==7193==    at 0x401BC9C: strcmp (in /usr/lib/ld-2.19.90.so)
==7193== 
[... lots more ...]

See https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/arm/armv7/strcmp.S;hb=HEAD for the implementation.
Comment 1 Mark Wielaard 2014-08-28 08:08:13 UTC
Created attachment 88464 [details]
Suppress glibc 2.20 optimized strcmp implementation for ARMv7.

Proposed patch.

    Add an add_hardwired_spec for strcmp in VG_(redir_initialise) for
    ld-linux.so.3 and ld-linux-armhf.so.3 to use a simple strcmp
    implementation in m_trampoline.S (compiled from the trivial .c code
    to asm with gcc like the other implementations in that file).
Comment 2 Mark Wielaard 2014-08-28 15:03:26 UTC
Apologies. I committed my proposed fix by accident as valgrind svn r14374 while working on something else. I had wanted someone to review it first.

I think it is the correct way to handle this situation, but please yell and scream if it is not an appropriate fix and I'll revert it.
Comment 3 Julian Seward 2014-08-30 10:03:11 UTC
Sounds exactly right to me.