[android-developers] Re: a simple native pthread test but SIGSEGV generated!

2008-11-20 Thread allstars

i found the reason why SIGSEGV is generated
i didnt call exit(0) in the end

thanks

On Nov 17, 10:04 pm, David Turner [EMAIL PROTECTED] wrote:
 You are using arm-none-linux-gnueabi-gcc which is not compatible with the
 android toolchain.
 This kind of issue is perfectly normal and non supported.

 Only trivial programs may correctly work that way, more by chance that
 anything else.

 On Mon, Nov 17, 2008 at 1:35 PM, allstars [EMAIL PROTECTED] wrote:

  hello world
  i try to do a simple pthread test on android (natively)

  /*START OF CODE ===*/
  #include stdio.h
  #include sys/types.h
  #include pthread.h

  void *hello(void *arg)
  {
         printf(Hello from node %d\n, *(int *)arg);
  }

  int main(int argc, char* argv[])
  {
         int n,i;
         pthread_t threads[2];

         n = 2;

         /* Start up thread */
         for (i = 0; i  n; i++)
         {
                 pthread_create(threads[i], NULL, hello, (void *)i);
         }

         /* Synchronize the completion of each thread. */
         for (i = 0; i  n; i++)
         {
                 pthread_join(threads[i],NULL);
         }
     printf(pthread_test returns \n);
     return 0;
  }
  /*===END OF CODE=*/

  then i compile it  (pthread.c)
  $arm-none-linux-gnueabi-gcc -c -g pthread.c
  $arm-none-linux-gnueabi-ld --entry=main --dynamic-linker /system/bin/
  linker -nostdlib -rpath /system/lib -rpath system/lib -L system/lib  -
  lc -o pthread_test pthread.o

  ./system is the directory of system image

  but in pthread_join , SIGSEGV will be generated

  i use strace to debug this
  # ./strace ./pthread_test
  execve(./pthread_test, [./pthread_test], [/* 10 vars */]) = 0
  getpid()                                = 189
  syscall_983045(0xb00169c4, 0x4990, 0xb0011030, 0, 0x1, 0xbecf6d94,
  0xbecf6d9c, 0xf0005, 0, 0, 0, 0, 0, 0xbecf6d60, 0xbdcd,
  0xb00015ac, 0x8010, 0xb00169c4, 0, 0, 0, 0xeb48, 0xcd1f8, 0xcd1d0,
  0, 0, 0, 0, 0, 0, 0, 0) = 0
  gettid()                                = 189
  sigaction(SIGILL, {0xb0001211, [], SA_RESTART}, {SIG_DFL}, 0) = 0
  sigaction(SIGABRT, {0xb0001211, [], SA_RESTART}, {SIG_DFL}, 0) = 0
  sigaction(SIGBUS, {0xb0001211, [], SA_RESTART}, {SIG_DFL}, 0) = 0
  sigaction(SIGFPE, {0xb0001211, [], SA_RESTART}, {SIG_DFL}, 0) = 0
  sigaction(SIGSEGV, {0xb0001211, [], SA_RESTART}, {SIG_DFL}, 0) = 0
  sigaction(SIGSTKFLT, {0xb0001211, [], SA_RESTART}, {SIG_DFL}, 0) = 0
  open(libc.so, O_RDONLY|O_LARGEFILE)   = -1 ENOENT (No such file or
  directory)
  open(/system/lib/libc.so, O_RDONLY|O_LARGEFILE) = 3
  lseek(3, 0, SEEK_SET)                   = 0
  read(3, \177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0`
  \225\0\000..., 4096) = 4096
  lseek(3, -8, SEEK_END)                  = 227472
  read(3, \0\0\340\257PRE , 8)          = 8
  mmap2(0xafe0, 274432, PROT_READ|PROT_EXEC, MAP_PRIVATE|
  MAP_ANONYMOUS, -1, 0) = 0xafe0
  mmap2(0xafe0, 214032, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED,
  3, 0) = 0xafe0
  mprotect(0xafe0, 217088, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
  mmap2(0xafe35000, 8420, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED,
  3, 0x35) = 0xafe35000
  mmap2(0xafe38000, 41760, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|
  MAP_ANONYMOUS, -1, 0) = 0xafe38000
  close(3)                                = 0
  mprotect(0xafe0, 217088, PROT_READ|PROT_EXEC) = 0
  getuid32()                              = 0
  geteuid32()                             = 0
  open(/dev/urandom, O_RDONLY|O_LARGEFILE) = 3
  read(3, %\374\353\364, 4)             = 4
  close(3)                                = 0
  mprotect(0x8000, 4096, PROT_READ|PROT_EXEC) = 0
  getuid32()                              = 0
  geteuid32()                             = 0
  brk(0)                                  = 0x11000
  brk(0x11000)                            = 0x11000
  brk(0x12000)                            = 0x12000
  mmap2(0x1000, 1048576, PROT_READ|PROT_WRITE, MAP_PRIVATE|
  MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = 0x1000
  mprotect(0x1000, 4096, PROT_NONE)   = 0
  clone(child_stack=0x100fff00, flags=CLONE_VM|CLONE_FS|CLONE_FILES|
  CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_DETACHED) = 190
  futex(0x100fff00, FUTEX_WAKE, 1Hello from node 0
  )        = 1
  mmap2(0x1000, 1048576, PROT_READ|PROT_WRITE, MAP_PRIVATE|
  MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = 0x1000
  mprotect(0x1000, 4096, PROT_NONE)   = 0
  clone(child_stack=0x100fff00, flags=CLONE_VM|CLONE_FS|CLONE_FILES|
  CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_DETACHED) = 191
  futex(0x100fff00, FUTEX_WAKE, 1Hello from node 1
  )        = 1
  --- SIGSEGV (Segmentation fault) @ 0 (4) ---
  sigaction(SIGUSR1, {SIG_IGN}, {SIG_DFL}, 0) = 0
  gettid()                                = 189
  SYS_281(0x1, 0x1, 0, 0xe52c, 0xb000f55c) = 3
  SYS_283(0x3, 0xbecf69b6, 0x14, 0x1, 0x3) = 0
  write(3, \275\0\0\0, 4)               = 4
  read(3, 0xbecf6a54, 1)                  = ? ERESTARTSYS (To be
  

[android-developers] Re: a simple native pthread test but SIGSEGV generated!

2008-11-17 Thread David Turner
You are using arm-none-linux-gnueabi-gcc which is not compatible with the
android toolchain.
This kind of issue is perfectly normal and non supported.

Only trivial programs may correctly work that way, more by chance that
anything else.

On Mon, Nov 17, 2008 at 1:35 PM, allstars [EMAIL PROTECTED] wrote:


 hello world
 i try to do a simple pthread test on android (natively)

 /*START OF CODE ===*/
 #include stdio.h
 #include sys/types.h
 #include pthread.h

 void *hello(void *arg)
 {
printf(Hello from node %d\n, *(int *)arg);
 }

 int main(int argc, char* argv[])
 {
int n,i;
pthread_t threads[2];

n = 2;

/* Start up thread */
for (i = 0; i  n; i++)
{
pthread_create(threads[i], NULL, hello, (void *)i);
}

/* Synchronize the completion of each thread. */
for (i = 0; i  n; i++)
{
pthread_join(threads[i],NULL);
}
printf(pthread_test returns \n);
return 0;
 }
 /*===END OF CODE=*/

 then i compile it  (pthread.c)
 $arm-none-linux-gnueabi-gcc -c -g pthread.c
 $arm-none-linux-gnueabi-ld --entry=main --dynamic-linker /system/bin/
 linker -nostdlib -rpath /system/lib -rpath system/lib -L system/lib  -
 lc -o pthread_test pthread.o

 ./system is the directory of system image


 but in pthread_join , SIGSEGV will be generated

 i use strace to debug this
 # ./strace ./pthread_test
 execve(./pthread_test, [./pthread_test], [/* 10 vars */]) = 0
 getpid()= 189
 syscall_983045(0xb00169c4, 0x4990, 0xb0011030, 0, 0x1, 0xbecf6d94,
 0xbecf6d9c, 0xf0005, 0, 0, 0, 0, 0, 0xbecf6d60, 0xbdcd,
 0xb00015ac, 0x8010, 0xb00169c4, 0, 0, 0, 0xeb48, 0xcd1f8, 0xcd1d0,
 0, 0, 0, 0, 0, 0, 0, 0) = 0
 gettid()= 189
 sigaction(SIGILL, {0xb0001211, [], SA_RESTART}, {SIG_DFL}, 0) = 0
 sigaction(SIGABRT, {0xb0001211, [], SA_RESTART}, {SIG_DFL}, 0) = 0
 sigaction(SIGBUS, {0xb0001211, [], SA_RESTART}, {SIG_DFL}, 0) = 0
 sigaction(SIGFPE, {0xb0001211, [], SA_RESTART}, {SIG_DFL}, 0) = 0
 sigaction(SIGSEGV, {0xb0001211, [], SA_RESTART}, {SIG_DFL}, 0) = 0
 sigaction(SIGSTKFLT, {0xb0001211, [], SA_RESTART}, {SIG_DFL}, 0) = 0
 open(libc.so, O_RDONLY|O_LARGEFILE)   = -1 ENOENT (No such file or
 directory)
 open(/system/lib/libc.so, O_RDONLY|O_LARGEFILE) = 3
 lseek(3, 0, SEEK_SET)   = 0
 read(3, \177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0`
 \225\0\000..., 4096) = 4096
 lseek(3, -8, SEEK_END)  = 227472
 read(3, \0\0\340\257PRE , 8)  = 8
 mmap2(0xafe0, 274432, PROT_READ|PROT_EXEC, MAP_PRIVATE|
 MAP_ANONYMOUS, -1, 0) = 0xafe0
 mmap2(0xafe0, 214032, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED,
 3, 0) = 0xafe0
 mprotect(0xafe0, 217088, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
 mmap2(0xafe35000, 8420, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED,
 3, 0x35) = 0xafe35000
 mmap2(0xafe38000, 41760, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|
 MAP_ANONYMOUS, -1, 0) = 0xafe38000
 close(3)= 0
 mprotect(0xafe0, 217088, PROT_READ|PROT_EXEC) = 0
 getuid32()  = 0
 geteuid32() = 0
 open(/dev/urandom, O_RDONLY|O_LARGEFILE) = 3
 read(3, %\374\353\364, 4) = 4
 close(3)= 0
 mprotect(0x8000, 4096, PROT_READ|PROT_EXEC) = 0
 getuid32()  = 0
 geteuid32() = 0
 brk(0)  = 0x11000
 brk(0x11000)= 0x11000
 brk(0x12000)= 0x12000
 mmap2(0x1000, 1048576, PROT_READ|PROT_WRITE, MAP_PRIVATE|
 MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = 0x1000
 mprotect(0x1000, 4096, PROT_NONE)   = 0
 clone(child_stack=0x100fff00, flags=CLONE_VM|CLONE_FS|CLONE_FILES|
 CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_DETACHED) = 190
 futex(0x100fff00, FUTEX_WAKE, 1Hello from node 0
 )= 1
 mmap2(0x1000, 1048576, PROT_READ|PROT_WRITE, MAP_PRIVATE|
 MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = 0x1000
 mprotect(0x1000, 4096, PROT_NONE)   = 0
 clone(child_stack=0x100fff00, flags=CLONE_VM|CLONE_FS|CLONE_FILES|
 CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_DETACHED) = 191
 futex(0x100fff00, FUTEX_WAKE, 1Hello from node 1
 )= 1
 --- SIGSEGV (Segmentation fault) @ 0 (4) ---
 sigaction(SIGUSR1, {SIG_IGN}, {SIG_DFL}, 0) = 0
 gettid()= 189
 SYS_281(0x1, 0x1, 0, 0xe52c, 0xb000f55c) = 3
 SYS_283(0x3, 0xbecf69b6, 0x14, 0x1, 0x3) = 0
 write(3, \275\0\0\0, 4)   = 4
 read(3, 0xbecf6a54, 1)  = ? ERESTARTSYS (To be
 restarted)
 --- SIGCONT (Continued) @ 0 (0) ---
 read(3, , 1)  = 0
 close(3)= 0
 sigaction(SIGSEGV, {SIG_IGN}, {0xb0001211, [], SA_RESTART}, 0) = 0
 sigreturn() = ? (mask now