From: <sy...@us...> - 2005-04-20 20:05:36
|
Hi, I am trying to memcheck with valgrind a python script using the ctypes 0.9.6 module: --------------------------------------------------------------------------- $ valgrind --tool=memcheck --log-file=log --trace-syscalls=yes \ python -c 'import ctypes' Traceback (most recent call last): File "<string>", line 1, in ? File "ctypes/__init__.py", line 13, in ? from _ctypes import Union, Structure, Array ImportError: ./_ctypes.so: cannot enable executable stack as shared object requires: Invalid argument --------------------------------------------------------------------------- I tried with valgrind 2.2, valgrind 2.4, and valgrin 2.4 from CVS (just extracted it Wed Apr 20 15:43:31 EDT 2005 -- I could not run valgrind 3.0 from subversion, because I ran into a unrelated 'Illegal Instruction in /lib/ld-2.3.4.so' no matter how I configured it). All three versions report the same problem[1]. Looking at `_ctypes.so`, I coudn't see any blattant error with stack permission either[2]. Of course, the same script: # python -c 'import ctypes' run without problem by itself. I have nothing special, like PaX, installed or running on my linux 2.6.11 system, running glibc 2.3.4 (nptl only) on a x86 (athlon-tbird)... Any idea? -- Sylvain Fourmanoit <sy...@us...> Simulations are like miniskirts, they show a lot and hide the essentials. -- Hubert Kirrman [1] http://adesklets.sf.net/verbatim/log.pid16866 [2] http://adesklets.sf.net/verbatim/objdump.log |
From: John R. <jr...@Bi...> - 2005-04-20 22:47:30
|
> $ valgrind --tool=memcheck --log-file=log --trace-syscalls=yes \ > python -c 'import ctypes' > > Traceback (most recent call last): > File "<string>", line 1, in ? > File "ctypes/__init__.py", line 13, in ? > from _ctypes import Union, Structure, Array > ImportError: ./_ctypes.so: cannot enable executable stack as shared > object requires: Invalid argument $ execstack --query ./_ctypes.so $( which valgrind ) Note that _ctypes.so probably says '?' ["don't know"] and valgrind probably says '-' ["executable stack not required"]. $ readelf --program-headers ./_ctypes.so $ readelf --program-headers $( which valgrind ) Look at the GNU_STACK line. _ctypes.so probably has none at all, while valrind probably has one that says "RW-" ["executable stack not required" because no 'X' is present]. So, valgrind forgot to put "-W,-z,execstack" in its static link command so as to be usable when an old .so is invoked on a new system where dlopen [and ld-linux.so.2, both of which are components of glibc] and the Linux kernel enforce non-executable stacks. Also, _ctype.so forgot to put "-W,-z,noexecstack" in its static link command, so as to be usable on systems that prefer to enforce non- executable stacks. It might be possible to achieve a "quick fix" via $ execstack --clear-execstack ./_ctype.so [above is preferable] _or_ via [below is last resort] $ execstack --set-execstack $( which valgrind ) assuming you have the necessary filesystem permissions. -- John Reiser, jr...@Bi... |
From: John R. <jr...@Bi...> - 2005-04-20 22:50:19
|
There is an 'l' missing: > So, valgrind forgot to put "-W,-z,execstack" in its static link command -Wl,-z,execstack > Also, _ctype.so forgot to put "-W,-z,noexecstack" in its static link -Wl,-z,noexecstack -- |
From: <sy...@us...> - 2005-04-21 01:52:07
|
Thanks for the quick answer, John Reiser... I never heard of execstack before: thanks for the pointer. $ export ELF="`find $HOME -name '_ctypes.so'` `which valgrind`" && \ execstack --query $ELF && \ readelf -l $ELF | grep GNU_STACK X /home/sylvain/python/lib/python2.4/site-packages/_ctypes.so - /home/sylvain/bin/valgrind GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RWE 0x4 GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4 Just as you described. I added the linker parameter `-z noexecflag' while compiling the ctypes module, and everything is working fine now. A subsidiary question though: I also attempted to link valgrind 2.4.0 from CVS passing '-z execflag' to ld (by the way: right now, the autoconf script completely ignore command-line settings for CFLAGS). Final valgrind just threw back these 'cannot enable executable stack as shared object requires' at startup on everything dynamically linked on the system, regardless of the stack permission in the ELF headers of valgrind'ed programs... I tried this too on a test machine without any kind of stack protection (no PIE, no SSP, no specialized kernel-enforcement of non-executable stack of any sort either: linux 2.6.11, gcc 2.95, glibc 2.3.4 compiled against 2.6.11 headers with previous compile), same result... But just ignore this if this is not of any use to you: you put me right on track to investigate things myself. ;-) Thanks again, -- Sylvain <sy...@us...> The trouble with computers is that they do what you tell them, not what you want. -- D. Cohen |
From: Nicholas N. <nj...@cs...> - 2005-04-21 22:42:50
|
On Wed, 20 Apr 2005 sy...@us... wrote: > I am trying to memcheck with valgrind a python script using the ctypes 0.9.6 > module: A somewhat-related question: why are you running Memcheck on a Python program? N |
From: Benjamin L. <ben...@us...> - 2005-04-23 03:00:03
|
On Friday, 2005-04-22 at 08:42:41 AM, Nicholas Nethercote scribbled: > On Wed, 20 Apr 2005 sy...@us... wrote: > > >I am trying to memcheck with valgrind a python script using the ctypes > >0.9.6 module: > > A somewhat-related question: why are you running Memcheck on a Python > program? For what it's worth... Valgrind works great on Perl modules written in C too. ;-) I'm having deja vu. I may have mentioned this before on the list. ;-P -- Benjamin Lee mailto:ben...@re... Melbourne, Australia http://www.realthought.net Linux / BSD / GNU tel:+61.4.16.BEN.LEE Open Source "... invest in YOUR company, not HIS company..." "... invest in the WORLD, not a COUNTRY..." __________________________________________________________________________ Clarke's Conclusion: Never let your sense of morals interfere with doing the right thing. |
From: <sy...@us...> - 2005-04-21 23:03:30
|
Nicholas, I am working on Python bindings to Evas[1] using the ctypes module[2], which is itself basically a wrapping around the very good libffi[3]. With the garbade collection from my code, it get random segfaults, and the public interface to Python's garbage collector is not enough for such an abuse of the language, as I did not even knew precicely where the problem lied. With valgrind, it took me less than an hour to figure things out... Thanks for this software, it is a real time saver. Regards, -- Sylvain <sy...@us...> [1] http://www.enlightenment.org/index.php?id=25 [2] http://starship.python.net/crew/theller/ctypes/ [3] http://sources.redhat.com/libffi/ |