Why I call the strcmp, but function stack show that the strcat is  
called not the strcmp, but the file is belong to the function strcmp
             Can you show the how to replace the strcmp with 
“STRCMP(VG_Z_LIBC_SONAME,          strcmp)”, and then  I can follow the code to 
find out why.

             I can find the code you set the LD_PRELOAD ,  but symbol name  is 
not match,  I do not know how you replace the strcmp with 
STRCMP(VG_Z_LIBC_SONAME,          strcmp).
             Can  you help to point out the function do the job replace the 
strcmp with STRCMP(VG_Z_LIBC_SONAME,          strcmp)”,

Valgrind 3.12.
CPU:arm

#include <errno.h>
#include <limits.h>
#include <stdatomic.h>
#include <string.h>
#include <sys/cdefs.h>
#include <sys/mman.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

_Atomic(unsigned int ) g_status;

#define __unused /*empty*/
#define __predict_true /*empty*/

int main(int argc __unused , char ** argv __unused ) {
        unsigned int init = 1;
        int flag = 1;
        unsigned int expect = random();
        unsigned int value = 2;
        atomic_init(&g_status, init);

        if (__predict_true(atomic_compare_exchange_strong_explicit(&g_status, 
&expect,
                             value, memory_order_acquire, 
memory_order_relaxed))) {
            flag = 0;
        }

        printf("Done  flag:%d cmp:%d \n", flag, strcmp("aaaa", "cccc") );
        return  1;
}


The compiler name and version were not specified.  I used:
        gcc (GCC) 8.0.1 20180324 (Red Hat 8.0.1-0.20)
As shown, I had to #define the symbols __unused and __predict_true.


Valgrind show me output :
==30141== Invalid write of size 4
==30141== at 0x4C27CAE: strcat(strcmp.c:3)
==30141==    by 0x108871: main (testClang.c:27)
==30141==  Address 0xfeb445bc is on thread 1's stack
==30141==  12 bytes below stack pointer

Using valgrind-3.13 on Fedora 28 beta for armv7l (armhfp; 32-bit ARM):
$ valgrind ./predict
==2012== Memcheck, a memory error detector
==2012== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==2012== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==2012== Command: ./predict
==2012==
Done  flag:1 cmp:-1
==2012==
==2012== HEAP SUMMARY:
==2012==     in use at exit: 0 bytes in 0 blocks
==2012==   total heap usage: 1 allocs, 1 frees, 1,024 bytes allocated
==2012==
==2012== All heap blocks were freed -- no leaks are possible
==2012==
==2012== For counts of detected and suppressed errors, rerun with: -v
==2012== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to