Re: crash on __gmpz_init

2024-01-22 Thread igor pesando - Dept of Physics, University of Torino

Hi Marc,
thanks for the quick answer on the first case.
But the issue is also present if I use malloc in C.
Bests
Igor P

On 22/01/24 11:02, Marc Glisse wrote:

Hello,

   mpz_class M[LINES][COLS];

you are trying to put an array with millions of elements on the stack, 
so the stack overflows. Very large arrays need to be allocated on the 
heap in C++ (new, malloc, or some wrapper like std::vector).


On Mon, 22 Jan 2024, igor pesando - Dept of Physics, University of 
Torino wrote:



Hi *,
first of all thanks for your work.

The programs are attached as required.


Best regards
Igor Pesando

*

The issue I have is that the allocation in of a matrix in c++ crashes
the program with SEGFAULT if the dimension are big enough.

LINES and COLS are the number of lines and columns of a matrix.


g++ -DLINES=5000 -DCOLS=5000 test2_mem.cpp -lgmp -lgmpxx -o t_500x500
./t_500x500
version6.2.1; bits/limb 64


g++ -DLINES=5000 -DCOLS=5000 test2_mem.cpp -lgmp -lgmpxx -o t_5000x5000
./t_5000x5000
Segmentation fault (core dumped)


The issue is not that my computer has not enough memory.
In facts when I run the corresponding program in C it crashes in 
__gmpz_init
BUT it does not crash when I allocate twice as much memory (SC is the 
scaling factor for the allocated memory).



gcc -DLINES=500 -DCOLS=500 -DSC=1 test2_mem.c -lgmp  -o tc_500x500
./tc_500x500
allocating 25; size=16


gcc -DLINES=5000 -DCOLS=5000 -DSC=1 test2_mem.c -lgmp  -o tc_5000x5000
igor@igor7a:~/tex/LCSFT/cpp/BUG_GMP_20240122$ ./tc_5000x5000
allocating 2500; size=16


gcc -DLINES=7000 -DCOLS=5000 -DSC=1 test2_mem.c -lgmp  -o tc_7000x5000
./tc_7000x5000 -g
allocating 3500; size=16
Segmentation fault (core dumped)


Twice as much memory
gcc -DLINES=7000 -DCOLS=5000 -DSC=2 test2_mem.c -lgmp  -o tc_7000x5000x2
./tc_7000x5000x2
allocating 3500; size=16


**
GDB

gdb ./tc_7000x5000

(gdb) r
Starting program: /home/igor/tex/LCSFT/cpp/BUG_GMP_20240122/tc_7000x5000
[Thread debugging using libthread_db enabled]
Using host libthread_db library 
"/lib/x86_64-linux-gnu/libthread_db.so.1".

allocating 3500; size=16

Program received signal SIGSEGV, Segmentation fault.
0x77f39c9b in __gmpz_init () from 
/lib/x86_64-linux-gnu/libgmp.so.10

(gdb) bt
#0  0x77f39c9b in __gmpz_init () from 
/lib/x86_64-linux-gnu/libgmp.so.10

#1  0x52e9 in main () at test2_mem.c:28

#1  0x52e9 in main () at test2_mem.c:28
(gdb) f 1
#1  0x52e9 in main () at test2_mem.c:28
28  mpz_init( M[ lin*LINES +col] );
(gdb) p lin
$1 = 5000
(gdb) p col
$2 = 63
(gdb)

here lin is


Please include the following in any report:


The GMP version number, and if pre-packaged or patched then say so.
gmp pre-packaged 6.2.1
gmp 6.3.0 from sources






A test program that makes it possible for us to reproduce the
bug. Include instructions on how to run the program.

In attachment


   A description of what is wrong. If the results are incorrect, in
   what way. If you get a crash, say so.

   If you get a crash, include a stack backtrace from the debugger if
   it’s informative (‘where’ in gdb, or ‘$C’ in adb).

Above


   Please do not send core dumps, executables or straces.


The ‘configure’ options you used when building GMP, if any.

   The output from ‘configure’, as printed to stdout, with any
   options used.



   The name of the compiler and its version. For gcc, get the version 
with ‘gcc -v’, otherwise perhaps ‘what `which cc`’, or similar.


gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 
11.4.0-1ubuntu1~22.04' 
--with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs 
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 
--prefix=/usr --with-gcc-major-version-only --program-suffix=-11 
--program-prefix=x86_64-linux-gnu- --enable-shared 
--enable-linker-build-id --libexecdir=/usr/lib 
--without-included-gettext --enable-threads=posix --libdir=/usr/lib 
--enable-nls --enable-bootstrap --enable-clocale=gnu 
--enable-libstdcxx-debug --enable-libstdcxx-time=yes 
--with-default-libstdcxx-abi=new --enable-gnu-unique-object 
--disable-vtable-verify --enable-plugin --enable-default-pie 
--with-system-zlib --enable-libphobos-checking=release 
--w

crash on __gmpz_init

2024-01-22 Thread igor pesando - Dept of Physics, University of Torino

Hi *,
first of all thanks for your work.

The programs are attached as required.


Best regards
Igor Pesando

*

The issue I have is that the allocation in of a matrix in c++ crashes
the program with SEGFAULT if the dimension are big enough.

LINES and COLS are the number of lines and columns of a matrix.


g++ -DLINES=5000 -DCOLS=5000 test2_mem.cpp -lgmp -lgmpxx -o t_500x500
./t_500x500
version6.2.1; bits/limb 64


g++ -DLINES=5000 -DCOLS=5000 test2_mem.cpp -lgmp -lgmpxx -o t_5000x5000
./t_5000x5000
Segmentation fault (core dumped)


The issue is not that my computer has not enough memory.
In facts when I run the corresponding program in C it crashes in __gmpz_init
BUT it does not crash when I allocate twice as much memory (SC is the 
scaling factor for the allocated memory).



gcc -DLINES=500 -DCOLS=500 -DSC=1 test2_mem.c -lgmp  -o tc_500x500
./tc_500x500
allocating 25; size=16


gcc -DLINES=5000 -DCOLS=5000 -DSC=1 test2_mem.c -lgmp  -o tc_5000x5000
igor@igor7a:~/tex/LCSFT/cpp/BUG_GMP_20240122$ ./tc_5000x5000
allocating 2500; size=16


gcc -DLINES=7000 -DCOLS=5000 -DSC=1 test2_mem.c -lgmp  -o tc_7000x5000
./tc_7000x5000 -g
allocating 3500; size=16
Segmentation fault (core dumped)


Twice as much memory
gcc -DLINES=7000 -DCOLS=5000 -DSC=2 test2_mem.c -lgmp  -o tc_7000x5000x2
./tc_7000x5000x2
allocating 3500; size=16


**
GDB

gdb ./tc_7000x5000

(gdb) r
Starting program: /home/igor/tex/LCSFT/cpp/BUG_GMP_20240122/tc_7000x5000
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
allocating 3500; size=16

Program received signal SIGSEGV, Segmentation fault.
0x77f39c9b in __gmpz_init () from /lib/x86_64-linux-gnu/libgmp.so.10
(gdb) bt
#0  0x77f39c9b in __gmpz_init () from 
/lib/x86_64-linux-gnu/libgmp.so.10

#1  0x52e9 in main () at test2_mem.c:28

#1  0x52e9 in main () at test2_mem.c:28
(gdb) f 1
#1  0x52e9 in main () at test2_mem.c:28
28mpz_init( M[ lin*LINES +col] );
(gdb) p lin
$1 = 5000
(gdb) p col
$2 = 63
(gdb)

here lin is


Please include the following in any report:


The GMP version number, and if pre-packaged or patched then say so.
gmp pre-packaged 6.2.1
gmp 6.3.0 from sources






A test program that makes it possible for us to reproduce the
bug. Include instructions on how to run the program.

In attachment


A description of what is wrong. If the results are incorrect, in
what way. If you get a crash, say so.

If you get a crash, include a stack backtrace from the debugger if
it’s informative (‘where’ in gdb, or ‘$C’ in adb).

Above


Please do not send core dumps, executables or straces.


The ‘configure’ options you used when building GMP, if any.

The output from ‘configure’, as printed to stdout, with any
options used.



The name of the compiler and its version. For gcc, get the version 
with ‘gcc -v’, otherwise perhaps ‘what `which cc`’, or similar.


gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 
11.4.0-1ubuntu1~22.04' 
--with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs 
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 
--prefix=/usr --with-gcc-major-version-only --program-suffix=-11 
--program-prefix=x86_64-linux-gnu- --enable-shared 
--enable-linker-build-id --libexecdir=/usr/lib 
--without-included-gettext --enable-threads=posix --libdir=/usr/lib 
--enable-nls --enable-bootstrap --enable-clocale=gnu 
--enable-libstdcxx-debug --enable-libstdcxx-time=yes 
--with-default-libstdcxx-abi=new --enable-gnu-unique-object 
--disable-vtable-verify --enable-plugin --enable-default-pie 
--with-system-zlib --enable-libphobos-checking=release 
--with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch 
--disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic 
--enable-offload-targets=nvptx-none=/build/gcc-11-XeT9lY/gcc-11-11.4.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-XeT9lY/gcc-11-11.4.0/debian/tmp-gcn/usr 
--without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu 
--host=x86_64-linux-gnu --target=x86_64-linux-gnu