Using libmudflap to test a program that uses libxml2, I found that if
a program access a constant pointer in a non-instrumented library,
mudflap thinks that a read violation has occurred.

A simple test that illustrates this is:

a.c:
-----------------------------
char *p = "abc";
-----------------------------

b.c:
----------------------------
#include <stdio.h>
extern char *p;

int main() {
        char a = p[0];
        printf("%c\n",a);
        return 0;
}
----------------------------

compile and link with
gcc -shared -fPIC a.c -o liba.so
gcc  -fmudflap -lmudflap b.c -la -L. -o b

When b is run, mudflap prints:
--------------------------------
*******
mudflap violation 1 (check/read): time=1142875338.034838 ptr=0xb7e2a521 size=1
pc=0xb7e34317 location=`b.c:5 (main)'
      /usr/lib/libmudflap.so.0(__mf_check+0x37) [0xb7e34317]
      ./b(main+0x7a) [0x80487f2]
      /usr/lib/libmudflap.so.0(__wrap_main+0x176) [0xb7e34ed6]
number of nearby objects: 0
---------------------------------

Given how mudflap works, it would be very hard to avoid this false
positive. It would be nice if this limitation was documented.

Thanks,
Rafael

Reply via email to