Issue #12 new

Feature request: support x86 arch on x86_64 Linux

Anonymous created an issue

When I try to run strace.py with a 32bits program in Ubuntu Linux x64 I get the following message:

Format argument filename of function lstat() value error: [ProcessError] readBytes(0x0000000000000003, 256) error: [Errno 5] Input/output error Traceback (most recent call last): File "/the/path/python-ptrace/ptrace/func_arg.py", line 31, in getText text = self.createText() File "/the/path/python-ptrace/ptrace/syscall/syscall_argument.py", line 106, in createText return self.readCString(value) File "/the/path/python-ptrace/ptrace/syscall/syscall_argument.py", line 183, in readCString char, truncated = self.function.process.readCString(address, max_size) File "/the/path/python-ptrace/ptrace/debugger/process.py", line 637, in readCString data = self.readBytes(address, chunk_length) File "/the/path/python-ptrace/ptrace/debugger/process.py", line 566, in readBytes formatAddress(address), size, err)) ProcessError: readBytes(0x0000000000000003, 256) error: [Errno 5] Input/output error

Any idea about what is wrong? I tried to look at the source but I'm a bit lost.

Comments (13)

  1. Joxean Koret

    Hi,

    I'm the same person who created this issue. I think I'm using the development version, I just grabbed the source via:

    $ hg clone https://bitbucket.org/haypo/python-ptrace

    ...so I guess I'm using devel. Perhap I'm doing something wrong?

    BTW, just to clarify: it doesn't fail tracing x64 programs, it only fails when tracing x32 programs (using x64 version of Python).

  2. Victor Stinner repo owner

    x32 is not supported yet. You probably have to modify descriptions of syscalls. Maybe registers used for syscalls, size of parameters, or something else.

    How can I test x32 on Fedora?

  3. Joxean Koret

    You just need to trace any x32 program in your x64 environment (the Linux distro used here doesn't matter). I created a minimal test-case for you to reproduce the issue:

    #include <stdio.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <unistd.h>
    
    int main(void)
    {
        struct stat sb;
        int i = stat("/etc/hosts", &sb);
    
        printf("Hello world!\n");
        return 0;
    }
    

    Compile this code with gcc -m32 like this:

    $ gcc -m32 test.c -o test

    And try to run with strace.py, you will see the following error:

    $ python strace.py -- ./test
    execve(/the/path/python-ptrace/test, ['/the/path/python-ptrace/test'], [/* 40 vars */]) = 26154
    recvfrom(9, 0x00000000f77a1000, 0, 0, NULL, 0) = 135118848 (0x00000000080dc000)
    dup2(4, -142994956)                      = -2 (No such file or directory)
    lgetxattr(0x00000000ffffffff, 0x0000000000000022, 0x0000000000000003, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000) = 4151963648 (0x00000000f779f000)
    dup2(-142853100, -142885450)             = 0
    fstat(4152114196, 0x00000000ffca3b60)    = 3
    removexattr(0x0000000000000003, 0x00000000ffca3b60, 0x00000000f77c2ff4, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000) = 0
    Format argument filename of function lstat() value error: [ProcessError] readBytes(0x0000000000000003, 256) error: [Errno 5] Input/output error
    Traceback (most recent call last):
      File "/the/path/python-ptrace/ptrace/func_arg.py", line 31, in getText
        text = self.createText()
      File "/the/path/python-ptrace/ptrace/syscall/syscall_argument.py", line 106, in createText
        return self.readCString(value)
      File "/the/path/python-ptrace/ptrace/syscall/syscall_argument.py", line 183, in readCString
        char, truncated = self.function.process.readCString(address, max_size)
      File "/the/path/python-ptrace/ptrace/debugger/process.py", line 637, in readCString
        data = self.readBytes(address, chunk_length)
      File "/the/path/python-ptrace/ptrace/debugger/process.py", line 566, in readBytes
        formatAddress(address), size, err))
    ProcessError: readBytes(0x0000000000000003, 256) error: [Errno 5] Input/output error
    
  4. Joxean Koret

    I'm not sure as I don't have any Fedora install here but, I guess, you can execute x32 applications in Fedora x64, no matters if they don't support x32 any more as, again, I guess, this is only for the distribution itself, not for the applications they support. I don't think they removed support for x32 applications in either Fedora or RHEL (it makes no sense, there are always old applications in enterprise).

    This may help you: How to run 32 bit programs on 64 bit Fedora 17?

  5. Victor Stinner repo owner

    "I guess, you can execute x32 applications in Fedora x64"

    No you can't. You need x32 libraries, at least the libc.

    "I don't think they removed support for x32 applications in either Fedora or RHEL (it makes no sense, there are always old applications in enterprise)"

    Fedora/RHEL never supported x32, i don't see how they could "remove" support of x32.

    This may help you: How to run 32 bit programs on 64 bit Fedora 17?

    The x86 arch (Intel 32 bit) is different than x32 (use 64 bits registers for arithmetic but 32 bi types, especially pointers). Yes, you can run x86 programs on a x86_64 (Intel 64 bit) system.

    You are asking for support of a new architecture, x32. I'm not really interested, but I can review patches :-)

  6. Victor Stinner repo owner

    Oh, I misunderstood the "-m32" comand line option. It's x86 not x32, sorry.

    I tried "sudo yum install glibc-devel.i686" but "gcc -m32 x.c -o x" now fails with a different error message:

    /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.8.2/libgcc_s.so when searching for -lgcc_s
    /usr/bin/ld: cannot find -lgcc_s
    collect2: error: ld returned 1 exit status
    
  7. Log in to comment