Subject: port-amd64/36184: most programs emulated with LINUX_COMPAT crash on amd64
To: None <port-amd64-maintainer@netbsd.org, gnats-admin@netbsd.org,>
From: Loic Hoguin <essen@dev-extend.eu>
List: netbsd-bugs
Date: 04/20/2007 21:55:00
>Number:         36184
>Category:       port-amd64
>Synopsis:       most programs emulated with LINUX_COMPAT crash on amd64
>Confidential:   no
>Severity:       critical
>Priority:       low
>Responsible:    port-amd64-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Apr 20 21:55:00 +0000 2007
>Originator:     Loic Hoguin
>Release:        NetBSD 4.99.17 amd64
>Organization:
Dev:Extend 
>Environment:


System: NetBSD 4.99.17 (BLACKROSE) #9: Fri Apr 20 20:30:21 CEST 2007
	root@blackrose.dev-extend.eu:/usr/obj/sys/arch/amd64/compile/BLACKROSE



>Description:


Most programs don't work on amd64 using LINUX_COMPAT.
They crash after a call to arch_prctl with a code value of LINUX_ARCH_SET_FS.
(I added some printf to get the value.)
This call runs well, the program crash just after, according to the kdump.

Example programs crashing are date or ls from suse100_base.
Bash seems to work.

I tried using a 2.4 and 2.6 version number in sysctl.

Nicolas Joly and some others reported this problem too.
The discussion "suse100 support for NetBSD/amd64 committed" on pkgsrc-users
may contain useful informations too.

Here are gdb/kdump:

% gdb /emul/linux/bin/date
GNU gdb 6.5 
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are 
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64--netbsd"...
warning: A handler for the OS ABI "GNU/Linux" is not built into this configuration
of GDB.  Attempting to continue with the default i386:x86-64 settings.

(no debugging symbols found)

(gdb) run 
Starting program: /usr/pkg/emul/linux/bin/date 
warning: no shared library support for this OS / ABI 

Program received signal SIGSEGV, Segmentation fault.
0xfd9322eb in ?? ()
(gdb) bt
#0  0xfd9322eb in ?? ()
Cannot access memory at address 0xffffe360
(gdb) quit
The program is running.  Exit anyway? (y or n) y

% ktrace /emul/linux/bin/date
zsh: segmentation fault (core dumped)  ktrace /emul/linux/bin/date

% kdump ktrace.out
  1848      1 ktrace   EMUL  "netbsd"
  1848      1 ktrace   CALL  execve(0x7f7fffffed7f,0x7f7fffffec08,0x7f7fffffec18)
  1848      1 ktrace   NAMI  "/emul/linux/bin/date"
  1848      1 ktrace   NAMI  "/emul/linux/lib64/ld-linux-x86-64.so.2"
  1848      1 ktrace   NAMI  "/emul/linux"
  1848      1 ktrace   NAMI  "/emul/linux/lib64/ld-linux-x86-64.so.2"
  1848      1 date     EMUL  "linux"
  1848      1 date     RET   execve -1 errno -2 No such file or directory
  1848      1 date     CALL  uname(0x7f7fffffe248)
  1848      1 date     RET   uname 0
  1848      1 date     CALL  brk(0)
  1848      1 date     RET   brk 5292032/0x50c000
  1848      1 date     CALL  mmap(0,0x1000,3,0x22,0xffffffff,0)
  1848      1 date     RET   mmap 140187698982912/0x7f7ffdfff000
  1848      1 date     CALL  access(0x7f7ffde11450,4)
  1848      1 date     NAMI  "/emul/linux/etc/ld.so.preload"
  1848      1 date     NAMI  "/etc/ld.so.preload"
  1848      1 date     RET   access -1 unknown errno 2
  1848      1 date     CALL  open(0x7f7ffde131d8,0,1)
  1848      1 date     NAMI  "/emul/linux/etc/ld.so.cache"
  1848      1 date     NAMI  "/emul/linux"
  1848      1 date     NAMI  "/emul/linux/etc/ld.so.cache"
  1848      1 date     RET   open 3
  1848      1 date     CALL  fstat64(3,0x7f7fffffda38)
  1848      1 date     RET   fstat64 0
  1848      1 date     CALL  mmap(0,0xd79,1,2,3,0)
  1848      1 date     RET   mmap 140187698978816/0x7f7ffdffe000
  1848      1 date     CALL  close(3)
  1848      1 date     RET   close 0
  1848      1 date     CALL  open(0x7f7ffdffe7f8,0,0x5f0)
  1848      1 date     NAMI  "/emul/linux/lib64/librt.so.1"
  1848      1 date     NAMI  "/emul/linux"
  1848      1 date     NAMI  "/emul/linux/lib64/librt.so.1"
  1848      1 date     RET   open 3
  1848      1 date     CALL  read(3,0x7f7fffffdb90,0x280)
  1848      1 date     GIO   fd 3 read 640 bytes
       "\^?ELF\^B\^A\^A\0\0\0\0\0\0\0\0\0\^C\0>\0\^A\0\0\0\M^P)\0\0\0\0\0\0@\0\0\0\0\0\0\0\M-X\M^L\0\0\0\0\0\0\0\0\0\
        \0@\08\0
        \0@\0\"\0\^_\0\^F\0\0\0\^E\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0000\^B\0\0\0\0\0\0000\^B\0\0\0\
        \0\0\0\b\0\0\0\0\0\0\0\^C\0\0\0\^D\0\0\0\M-0l\0\0\0\0\0\0\M-0l\0\0\0\0\0\0\M-0l\0\0\0\0\0\0\^\\0\0\0\0\0\0\0\
        \^\\0\0\0\0\0\0\0\^P\0\0\0\0\0\0\0\^A\0\0\0\^E\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dw\0\0\0\
        \0\0\0dw\0\0\0\0\0\0\0\0\^P\0\0\0\0\0\^A\0\0\0\^F\0\0\08}\0\0\0\0\0\08}\^P\0\0\0\0\08}\^P\0\0\0\0\0\M-L\^E\0\
        \0\0\0\0\08\M-{\0\0\0\0\0\0\0\0\^P\0\0\0\0\0\^B\0\0\0\^F\0\0\0p}\0\0\0\0\0\0p}\^P\0\0\0\0\0p}\^P\0\0\0\0\0\
        \M-`\^A\0\0\0\0\0\0\M-`\^A\0\0\0\0\0\0\b\0\0\0\0\0\0\0\^D\0\0\0\^D\0\0\0p\^B\0\0\0\0\0\0p\^B\0\0\0\0\0\0p\^B\
        \0\0\0\0\0\0 \0\0\0\0\0\0\0 \0\0\0\0\0\0\0\^D\0\0\0\0\0\0\0\^D\0\0\0\^D\0\0\0\M^P\^B\0\0\0\0\0\0\M^P\^B\0\0\
        \0\0\0\0\M^P\^B\0\0\0\0\0\0\^X\0\0\0\0\0\0\0\^X\0\0\0\0\0\0\0\^D\0\0\0\0\0\0\0P\M-etd\^D\0\0\0\M-Ll\0\0\0\0\
        \0\0\M-Ll\0\0\0\0\0\0\M-Ll\0\0\0\0\0\0D\^B\0\0\0\0\0\0D\^B\0\0\0\0\0\0\^D\0\0\0\0\0\0\0Q\M-etd\^F\0\0\0\0\0\
        \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\b\0\0\0\0\0\0\0R\M-etd\^D\0\0\0\
        8}\0\0\0\0\0\08}\^P\0\0\0\0\08}\^P\0\0\0\0\0\M-0\^B\0\0\0\0\0\0\M-0\^B\0\0\0\0\0\0\b\0\0\0\0\0\0\0\^D\0\0\0\
        \^P\0\0\0\^A\0\0\0GNU\0"
  1848      1 date     RET   read 640/0x280
  1848      1 date     CALL  lseek(3,0x270,0)
  1848      1 date     RET   lseek 624/0x270
  1848      1 date     CALL  read(3,0x7f7fffffdae8,0x20)
  1848      1 date     GIO   fd 3 read 32 bytes
       "\^D\0\0\0\^P\0\0\0\^A\0\0\0GNU\0\0\0\0\0\^B\0\0\0\^D\0\0\0\^A\0\0\0"
  1848      1 date     RET   read 32/0x20
  1848      1 date     CALL  fstat64(3,0x7f7fffffda78)
  1848      1 date     RET   fstat64 0
  1848      1 date     CALL  mmap(0,0x117870,5,0x802,3,0)
  1848      1 date     RET   mmap 140187695742976/0x7f7ffdce8000
  1848      1 date     CALL  madvise(0x7f7ffdce8000,0x117870,3)
  1848      1 date     RET   madvise 0
  1848      1 date     CALL  mprotect(0x7f7ffdcf0000,0x10f870,0)
  1848      1 date     RET   mprotect 0
  1848      1 date     CALL  mmap(0x7f7ffddef000,0x2000,3,0x812,3,0x7000)
  1848      1 date     RET   mmap 140187696820224/0x7f7ffddef000
  1848      1 date     CALL  mmap(0x7f7ffddf1000,0xe870,3,0x32,0xffffffff,0)
  1848      1 date     RET   mmap 140187696828416/0x7f7ffddf1000
  1848      1 date     CALL  close(3)
  1848      1 date     RET   close 0
  1848      1 date     CALL  open(0x7f7ffdffec82,0,0xa7a)
  1848      1 date     NAMI  "/emul/linux/lib64/libc.so.6"
  1848      1 date     NAMI  "/emul/linux"
  1848      1 date     NAMI  "/emul/linux/lib64/libc.so.6"
  1848      1 date     RET   open 3
  1848      1 date     CALL  read(3,0x7f7fffffdb60,0x280)
  1848      1 date     GIO   fd 3 read 640 bytes
       "\^?ELF\^B\^A\^A\0\0\0\0\0\0\0\0\0\^C\0>\0\^A\0\0\0p\M-M\^A\0\0\0\0\0@\0\0\0\0\0\0\0\M-@&\^S\0\0\0\0\0\0\0\0\
        \0@\08\0
        \0@\0@\0=\0\^F\0\0\0\^E\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0000\^B\0\0\0\0\0\0000\^B\0\0\0\0\0\
        \0\b\0\0\0\0\0\0\0\^C\0\0\0\^D\0\0\0`t\^P\0\0\0\0\0`t\^P\0\0\0\0\0`t\^P\0\0\0\0\0\^\\0\0\0\0\0\0\0\^\\0\0\0\
        \0\0\0\0\^P\0\0\0\0\0\0\0\^A\0\0\0\^E\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\^P\M-n\^Q\0\0\0\
        \0\0\^P\M-n\^Q\0\0\0\0\0\0\0\^P\0\0\0\0\0\^A\0\0\0\^F\0\0\0\b\M-o\^Q\0\0\0\0\0\b\M-o!\0\0\0\0\0\b\M-o!\0\0\0\
        \0\0pN\0\0\0\0\0\0\0\M^T\0\0\0\0\0\0\0\0\^P\0\0\0\0\0\^B\0\0\0\^F\0\0\0\M^@\^Z\^R\0\0\0\0\0\M^@\^Z\"\0\0\0\0\
        \0\M^@\^Z\"\0\0\0\0\0\M-@\^A\0\0\0\0\0\0\M-@\^A\0\0\0\0\0\0\b\0\0\0\0\0\0\0\^D\0\0\0\^D\0\0\0p\^B\0\0\0\0\0\
        \0p\^B\0\0\0\0\0\0p\^B\0\0\0\0\0\0 \0\0\0\0\0\0\0 \0\0\0\0\0\0\0\^D\0\0\0\0\0\0\0\^D\0\0\0\^D\0\0\0\M^P\^B\0\
        \0\0\0\0\0\M^P\^B\0\0\0\0\0\0\M^P\^B\0\0\0\0\0\0\^X\0\0\0\0\0\0\0\^X\0\0\0\0\0\0\0\^D\0\0\0\0\0\0\0P\M-etd\
        \^D\0\0\0|t\^P\0\0\0\0\0|t\^P\0\0\0\0\0|t\^P\0\0\0\0\0\^DN\0\0\0\0\0\0\^DN\0\0\0\0\0\0\^D\0\0\0\0\0\0\0Q\M-e\
        td\^F\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\b\0\0\0\0\0\0\0R\
        \M-etd\^D\0\0\0\b\M-o\^Q\0\0\0\0\0\b\M-o!\0\0\0\0\0\b\M-o!\0\0\0\0\0(-\0\0\0\0\0\0(-\0\0\0\0\0\0 \0\0\0\0\0\
        \0\0\^D\0\0\0\^P\0\0\0\^A\0\0\0GNU\0"
  1848      1 date     RET   read 640/0x280
  1848      1 date     CALL  lseek(3,0x270,0)
  1848      1 date     RET   lseek 624/0x270
  1848      1 date     CALL  read(3,0x7f7fffffdab8,0x20)
  1848      1 date     GIO   fd 3 read 32 bytes
       "\^D\0\0\0\^P\0\0\0\^A\0\0\0GNU\0\0\0\0\0\^B\0\0\0\^D\0\0\0\^A\0\0\0"
  1848      1 date     RET   read 32/0x20
  1848      1 date     CALL  fstat64(3,0x7f7fffffda48)
  1848      1 date     RET   fstat64 0
  1848      1 date     CALL  mmap(0,0x228308,5,0x802,3,0)
  1848      1 date     RET   mmap 140187693477888/0x7f7ffdabf000
  1848      1 date     CALL  madvise(0x7f7ffdabf000,0x228308,3)
  1848      1 date     RET   madvise 0
  1848      1 date     CALL  mprotect(0x7f7ffdbde000,0x109308,0)
  1848      1 date     RET   mprotect 0
  1848      1 date     CALL  mmap(0x7f7ffdcdd000,0x6000,3,0x812,3,0x11e000)
  1848      1 date     RET   mmap 140187695697920/0x7f7ffdcdd000
  1848      1 date     CALL  mmap(0x7f7ffdce3000,0x4308,3,0x32,0xffffffff,0)
  1848      1 date     RET   mmap 140187695722496/0x7f7ffdce3000
  1848      1 date     CALL  close(3)
  1848      1 date     RET   close 0
  1848      1 date     CALL  open(0x7f7ffdffe893,0,0x68b)
  1848      1 date     NAMI  "/emul/linux/lib64/libpthread.so.0"
  1848      1 date     NAMI  "/emul/linux"
  1848      1 date     NAMI  "/emul/linux/lib64/libpthread.so.0"
  1848      1 date     RET   open 3
  1848      1 date     CALL  read(3,0x7f7fffffda30,0x280)
  1848      1 date     GIO   fd 3 read 640 bytes
       "\^?ELF\^B\^A\^A\0\0\0\0\0\0\0\0\0\^C\0>\0\^A\0\0\0\M-0S\0\0\0\0\0\0@\0\0\0\0\0\0\0\0\^S\^A\0\0\0\0\0\0\0\0\0\
        @\08\0
        \0@\0#\0 \0\^F\0\0\0\^E\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0000\^B\0\0\0\0\0\0000\^B\0\0\0\0\0\
        \0\b\0\0\0\0\0\0\0\^C\0\0\0\^D\0\0\0\M^@\M-V\0\0\0\0\0\0\M^@\M-V\0\0\0\0\0\0\M^@\M-V\0\0\0\0\0\0\^\\0\0\0\0\
        \0\0\0\^\\0\0\0\0\0\0\0\^P\0\0\0\0\0\0\0\^A\0\0\0\^E\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0l\
        \M-v\0\0\0\0\0\0l\M-v\0\0\0\0\0\0\0\0\^P\0\0\0\0\0\^A\0\0\0\^F\0\0\0 \M-|\0\0\0\0\0\0 \M-|\^P\0\0\0\0\0 \M-|\
        \^P\0\0\0\0\0\M-H
        \0\0\0\0\0\0\0L\b\0\0\0\0\0\0\0\^P\0\0\0\0\0\^B\0\0\0\^F\0\0\0\M-x\M-|\0\0\0\0\0\0\M-x\M-|\^P\0\0\0\0\0\M-x\
        \M-|\^P\0\0\0\0\0\M-P\^A\0\0\0\0\0\0\M-P\^A\0\0\0\0\0\0\b\0\0\0\0\0\0\0\^D\0\0\0\^D\0\0\0p\^B\0\0\0\0\0\0p\
        \^B\0\0\0\0\0\0p\^B\0\0\0\0\0\0 \0\0\0\0\0\0\0 \0\0\0\0\0\0\0\^D\0\0\0\0\0\0\0\^D\0\0\0\^D\0\0\0\M^P\^B\0\0\
        \0\0\0\0\M^P\^B\0\0\0\0\0\0\M^P\^B\0\0\0\0\0\0\^X\0\0\0\0\0\0\0\^X\0\0\0\0\0\0\0\^D\0\0\0\0\0\0\0P\M-etd\^D\
        \0\0\0\M^\\M-V\0\0\0\0\0\0\M^\\M-V\0\0\0\0\0\0\M^\\M-V\0\0\0\0\0\0\M-t\^F\0\0\0\0\0\0\M-t\^F\0\0\0\0\0\0\^D\
        \0\0\0\0\0\0\0Q\M-etd\^F\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
        \0\b\0\0\0\0\0\0\0R\M-etd\^D\0\0\0 \M-|\0\0\0\0\0\0 \M-|\^P\0\0\0\0\0 \M-|\^P\0\0\0\0\0\M^X\^B\0\0\0\0\0\0\
        \M^X\^B\0\0\0\0\0\0 \0\0\0\0\0\0\0\^D\0\0\0\^P\0\0\0\^A\0\0\0GNU\0"
  1848      1 date     RET   read 640/0x280
  1848      1 date     CALL  lseek(3,0x270,0)
  1848      1 date     RET   lseek 624/0x270
  1848      1 date     CALL  read(3,0x7f7fffffd988,0x20)
  1848      1 date     GIO   fd 3 read 32 bytes
       "\^D\0\0\0\^P\0\0\0\^A\0\0\0GNU\0\0\0\0\0\^B\0\0\0\^D\0\0\0\^A\0\0\0"
  1848      1 date     RET   read 32/0x20
  1848      1 date     CALL  fstat64(3,0x7f7fffffd918)
  1848      1 date     RET   fstat64 0
  1848      1 date     CALL  mmap(0,0x1000,3,0x22,0xffffffff,0)
  1848      1 date     RET   mmap 140187698974720/0x7f7ffdffd000
  1848      1 date     CALL  mmap(0,0x194820,5,0x802,3,0)
  1848      1 date     RET   mmap 140187691819008/0x7f7ffd92a000
  1848      1 date     CALL  madvise(0x7f7ffd92a000,0x194820,3)
  1848      1 date     RET   madvise 0
  1848      1 date     CALL  mprotect(0x7f7ffd93a000,0x184820,0)
  1848      1 date     RET   mprotect 0
  1848      1 date     CALL  mmap(0x7f7ffda39000,0x2000,3,0x812,3,0xf000)
  1848      1 date     RET   mmap 140187692929024/0x7f7ffda39000
  1848      1 date     CALL  mmap(0x7f7ffda3b000,0x83820,3,0x32,0xffffffff,0)
  1848      1 date     RET   mmap 140187692937216/0x7f7ffda3b000
  1848      1 date     CALL  close(3)
  1848      1 date     RET   close 0
  1848      1 date     CALL  mprotect(0x7f7ffdcdd000,0x3000,1)
  1848      1 date     RET   mprotect 0
  1848      1 date     CALL  munmap(0x7f7ffdffe000,0xd79)
  1848      1 date     RET   munmap 0
  1848      1 date     CALL  brk(0)
  1848      1 date     RET   brk 5292032/0x50c000
  1848      1 date     CALL  brk(0x52d000)
  1848      1 date     RET   brk 5427200/0x52d000
  1848      1 date     CALL  brk(0)
  1848      1 date     RET   brk 5427200/0x52d000
  1848      1 date     CALL  arch_prctl(0x1002,0x50cae0)
  1848      1 date     RET   arch_prctl 0
  1848      1 date     PSIG  SIGSEGV SIG_DFL
  1848      1 date     NAMI  "date.core"



>How-To-Repeat:


Install /usr/pkgsrc/emulators/suse100_base (64bit version) on amd64.
Try to run /emul/linux/bin/ls or other binaries.



>Fix: