[suse-amd64] pthread program put a core. why?
I made a pthread program, and executed after compiled it.
It was core dump At the last.
$> gcc -m64 loadtest.c -o loadtest -lpthread
$> ./loadtest
ret = 0
ret = 1
:
[snip]
:
ret = 253
ret = 254
Segmentation fault (core dumped)
$> gdb ./loadtest ./core.11662
GNU gdb 5.3.92
Copyright 2003 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-suse-linux"...
Core was generated by `./loadtest'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /lib64/libpthread.so.0...done.
Loaded symbols for /lib64/libpthread.so.0
Reading symbols from /lib64/libc.so.6...done.
Loaded symbols for /lib64/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
#0 0x0000002a95561897 in _dl_fini () from /lib64/ld-linux-x86-64.so.2
(gdb) bt full
#0 0x0000002a95561897 in _dl_fini () from /lib64/ld-linux-x86-64.so.2
No symbol table info available.
#1 0x0000002a95834c8b in exit () from /lib64/libc.so.6
No symbol table info available.
#2 0x0000002a9581fca5 in __libc_start_main () from /lib64/libc.so.6
No symbol table info available.
#3 0x000000000040051a in _start () at ../sysdeps/x86_64/elf/start.S:96
No locals.
But, It is not core dump if it compile at -m32 option.
$> gcc -m32 loadtest.c -o loadtest -lpthread
$> ./loadtest
ret = 0
:
[snip]
:
ret = 254
$>
$> gcc -v
Reading specs from /usr/lib64/gcc-lib/x86_64-suse-linux/3.3.1/specs
Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --enable-languages=c,c++,f77,objc,java,ada --disable-checking --enable-libgcj --with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib64 --with-system-zlib --enable-shared --enable-__cxa_atexit x86_64-suse-linux
Thread model: posix
gcc version 3.3.1 (SuSE Linux)
$> uname -mvrip
2.6.4 #8 SMP Fri Mar 12 10:38:40 JST 2004 x86_64 x86_64 x86_64
(I updated to Kernel 2.6.4)
$> cat loadtest.c
#include
I've modified your program slightly to make it work: int main(void) { int i; void *ret; pthread_t p[255]; for(i=0; i<255; i++){ pthread_create(&p[i], NULL, (void *(*)(void *))thread, &i); } for(i=0; i<255; i++){ pthread_join(p[i], &ret); printf("ret = %d\n", *(int**)ret); } return(0); } I'm not clear on what I fixed exactly but I think it may have to do with the size of void* and the size of int on 32-bit vs. 64-bit. Someone else may know more than me on this. Mark eshsf@mbj.nifty.com wrote:
I made a pthread program, and executed after compiled it. It was core dump At the last.
$> gcc -m64 loadtest.c -o loadtest -lpthread $> ./loadtest ret = 0 ret = 1 : [snip] : ret = 253 ret = 254 Segmentation fault (core dumped)
$> gdb ./loadtest ./core.11662 GNU gdb 5.3.92 Copyright 2003 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-suse-linux"... Core was generated by `./loadtest'. Program terminated with signal 11, Segmentation fault. Reading symbols from /lib64/libpthread.so.0...done. Loaded symbols for /lib64/libpthread.so.0 Reading symbols from /lib64/libc.so.6...done. Loaded symbols for /lib64/libc.so.6 Reading symbols from /lib64/ld-linux-x86-64.so.2...done. Loaded symbols for /lib64/ld-linux-x86-64.so.2 #0 0x0000002a95561897 in _dl_fini () from /lib64/ld-linux-x86-64.so.2 (gdb) bt full #0 0x0000002a95561897 in _dl_fini () from /lib64/ld-linux-x86-64.so.2 No symbol table info available. #1 0x0000002a95834c8b in exit () from /lib64/libc.so.6 No symbol table info available. #2 0x0000002a9581fca5 in __libc_start_main () from /lib64/libc.so.6 No symbol table info available. #3 0x000000000040051a in _start () at ../sysdeps/x86_64/elf/start.S:96 No locals.
But, It is not core dump if it compile at -m32 option.
$> gcc -m32 loadtest.c -o loadtest -lpthread $> ./loadtest ret = 0 : [snip] : ret = 254 $>
$> gcc -v Reading specs from /usr/lib64/gcc-lib/x86_64-suse-linux/3.3.1/specs Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --enable-languages=c,c++,f77,objc,java,ada --disable-checking --enable-libgcj --with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib64 --with-system-zlib --enable-shared --enable-__cxa_atexit x86_64-suse-linux Thread model: posix gcc version 3.3.1 (SuSE Linux)
$> uname -mvrip 2.6.4 #8 SMP Fri Mar 12 10:38:40 JST 2004 x86_64 x86_64 x86_64 (I updated to Kernel 2.6.4)
$> cat loadtest.c #include
#include #include #include static void* thread(int *arg) { int i,j,k; for(i=k=0; i<0x7FF;i++) for(j=0; j<0x7FF; j++) k=i+j; pthread_exit(arg); }
int main(void) { int i, **ret; pthread_t p[255];
for(i=0; i<255; i++){ pthread_create(&p[i], NULL, (void *(*)(void *))thread, &i); } for(i=0; i<255; i++){ pthread_join(p[i], (void **)ret); printf("ret = %d\n", **ret); } return(0); }
[SYSTEM] SUSE LINUX professional 9.0 64bit version for AMD64 CPU Opteron 246 * 2 Mem 2GB
Thanks. eshsf
Thanks Mark, Your source was perfect. I was wrong in "void*" and "int" being the same sizes on 64bit code. eshsf On Tue, 16 Mar 2004 01:58:38 -0500 Mark Horton wrote:
I've modified your program slightly to make it work:
int main(void) { int i; void *ret;
pthread_t p[255];
for(i=0; i<255; i++){ pthread_create(&p[i], NULL, (void *(*)(void *))thread, &i); } for(i=0; i<255; i++){ pthread_join(p[i], &ret); printf("ret = %d\n", *(int**)ret); } return(0); }
I'm not clear on what I fixed exactly but I think it may have to do with the size of void* and the size of int on 32-bit vs. 64-bit. Someone else may know more than me on this.
Mark
eshsf@mbj.nifty.com wrote:
I made a pthread program, and executed after compiled it. It was core dump At the last.
$> gcc -m64 loadtest.c -o loadtest -lpthread $> ./loadtest ret = 0 ret = 1 : [snip] : ret = 253 ret = 254 Segmentation fault (core dumped)
$> gdb ./loadtest ./core.11662 GNU gdb 5.3.92 Copyright 2003 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-suse-linux"... Core was generated by `./loadtest'. Program terminated with signal 11, Segmentation fault. Reading symbols from /lib64/libpthread.so.0...done. Loaded symbols for /lib64/libpthread.so.0 Reading symbols from /lib64/libc.so.6...done. Loaded symbols for /lib64/libc.so.6 Reading symbols from /lib64/ld-linux-x86-64.so.2...done. Loaded symbols for /lib64/ld-linux-x86-64.so.2 #0 0x0000002a95561897 in _dl_fini () from /lib64/ld-linux-x86-64.so.2 (gdb) bt full #0 0x0000002a95561897 in _dl_fini () from /lib64/ld-linux-x86-64.so.2 No symbol table info available. #1 0x0000002a95834c8b in exit () from /lib64/libc.so.6 No symbol table info available. #2 0x0000002a9581fca5 in __libc_start_main () from /lib64/libc.so.6 No symbol table info available. #3 0x000000000040051a in _start () at ../sysdeps/x86_64/elf/start.S:96 No locals.
But, It is not core dump if it compile at -m32 option.
$> gcc -m32 loadtest.c -o loadtest -lpthread $> ./loadtest ret = 0 : [snip] : ret = 254 $>
$> gcc -v Reading specs from /usr/lib64/gcc-lib/x86_64-suse-linux/3.3.1/specs Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --enable-languages=c,c++,f77,objc,java,ada --disable-checking --enable-libgcj --with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib64 --with-system-zlib --enable-shared --enable-__cxa_atexit x86_64-suse-linux Thread model: posix gcc version 3.3.1 (SuSE Linux)
$> uname -mvrip 2.6.4 #8 SMP Fri Mar 12 10:38:40 JST 2004 x86_64 x86_64 x86_64 (I updated to Kernel 2.6.4)
$> cat loadtest.c #include
#include #include #include static void* thread(int *arg) { int i,j,k; for(i=k=0; i<0x7FF;i++) for(j=0; j<0x7FF; j++) k=i+j; pthread_exit(arg); }
int main(void) { int i, **ret; pthread_t p[255];
for(i=0; i<255; i++){ pthread_create(&p[i], NULL, (void *(*)(void *))thread, &i); } for(i=0; i<255; i++){ pthread_join(p[i], (void **)ret); printf("ret = %d\n", **ret); } return(0); }
[SYSTEM] SUSE LINUX professional 9.0 64bit version for AMD64 CPU Opteron 246 * 2 Mem 2GB
Thanks. eshsf
-- Check the List-Unsubscribe header to unsubscribe For additional commands, email: suse-amd64-help@suse.com
* eshsf@mbj.nifty.com (eshsf@mbj.nifty.com) [20040316 10:43]:
I was wrong in "void*" and "int" being the same sizes on 64bit code.
You should *never* make that assumption. I don't know how much code in SUSE packages I fixed that made the same mistake. If you're willing to use C99 features, simply include inttypes.h and use intptr_t or uintptr_t as these are guaranteed to always be big enough to hold a pointer. Philipp -- Philipp Thomas SUSE LINUX AG, Maxfeldstr. 5, D-90409 Nuremberg, Germany
participants (3)
-
eshsf@mbj.nifty.com
-
Mark Horton
-
Philipp Thomas