-D_GLIBCXX_ASSERTIONS

Bugs

Modérateur : xcasadmin

frederic han
Messages : 1110
Inscription : dim. mai 20, 2007 7:09 am
Localisation : Paris
Contact :

-D_GLIBCXX_ASSERTIONS

Message par frederic han » jeu. avr. 18, 2019 7:28 pm

Hi bernard,
fedora packages are built with some flags and I experience runtime crashes. A typical example is:

Code : Tout sélectionner

ifactor(10**40+68)

it gives

Code : Tout sélectionner

58283 icas_eval ifactor(10^40+68)
[New Thread 0x7fffe58b2700 (LWP 1813)]
66791 Pollard-rho failure, ntries 15001

86851 sieve on 42975263438364877176697093153181029
Number of primes 333.039
88639 sieve basis OK, size 334 largest prime in basis 5003 large prime 130078 Mtarget 55000
Using 3 square factors per a coefficient in polynomials
1 fixed begin at 113 and 2 variables at 239
First M 6920.5
/usr/include/c++/8/bits/stl_vector.h:932: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = giac::basis_t; _Alloc = std::allocator<giac::basis_t>; std::vector<_Tp, _Alloc>::reference = giac::basis_t&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]: Assertion '__builtin_expect(__n < this->size(), true)' failed.
I think I have found the guilty one:
While a classic ./configure and make, it gives a good binary, but if I do:

Code : Tout sélectionner

env CXXFLAGS='-g  -Wp,-D_GLIBCXX_ASSERTIONS' ./configure
then I can reproduce the crash:

Code : Tout sélectionner

(gdb) bt
#0  0x00007ffff42a853f in raise () from /lib64/libc.so.6
#1  0x00007ffff4292895 in abort () from /lib64/libc.so.6
#2  0x000000000043caa5 in std::__replacement_assert (
    __file=0x7ffff7903810 "/usr/include/c++/8/bits/stl_vector.h", __line=932, 
    __function=0x7ffff7903f40 <std::vector<giac::basis_t, std::allocator<giac::basis_t> >::operator[](unsigned long)::__PRETTY_FUNCTION__> "std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = giac::basis_t; _Alloc = std::allocator<giac::basis_t>; std::vector<_Tp, _Alloc"..., __condition=0x7ffff79037e0 "__builtin_expect(__n < this->size(), true)")
    at /usr/include/c++/8/x86_64-redhat-linux/bits/c++config.h:2391
#3  0x00007ffff72df83b in std::vector<giac::basis_t, std::allocator<giac::basis_t> >::operator[] (
    this=0x7fffe58af3c0, __n=334) at /usr/include/c++/8/bits/stl_vector.h:932
#4  0x00007ffff72cc8ea in giac::msieve (n_orig=..., pn=..., contextptr=0x7fffffffc710) at ifactor.cc:2520
#5  0x00007ffff72d41cf in giac::pollardsieve (a=..., k=..., do_pollard=@0x7fffe58afc6f: false, 
    contextptr=0x7fffffffc710) at ifactor.cc:3797
#6  0x00007ffff72d4782 in giac::ifactor2 (n=..., v=..., do_pollard=@0x7fffe58afc6f: false, 
    contextptr=0x7fffffffc710) at ifactor.cc:3835
any idea?
Best
Frederic

frederic han
Messages : 1110
Inscription : dim. mai 20, 2007 7:09 am
Localisation : Paris
Contact :

Re: -D_GLIBCXX_ASSERTIONS

Message par frederic han » jeu. avr. 18, 2019 7:33 pm

NB: It could be related to vector of zero length

parisse
Messages : 5055
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: -D_GLIBCXX_ASSERTIONS

Message par parisse » ven. avr. 19, 2019 4:21 am

Try this:

Code : Tout sélectionner

diff ifactor.cc ifactor.cc~
2520c2520
< 	      basis_t * bit=&basis[0]+lp_basis_pos, * bitend=&basis[0]+bs;
---
> 	      basis_t * bit=&basis[lp_basis_pos], * bitend=&basis[0]+bs;

frederic han
Messages : 1110
Inscription : dim. mai 20, 2007 7:09 am
Localisation : Paris
Contact :

Re: -D_GLIBCXX_ASSERTIONS

Message par frederic han » ven. avr. 19, 2019 8:53 am

Indeed it helps, but there was similar problems after: I found:
3 in ifactor.cc, 1 in vecteur.cc, 1 in quater.cc

with the following patch I was able to run the test suite without crash

Code : Tout sélectionner

--- /home/fred/dev/win64/giac-1.5.0/src/ifactor.cc	2019-03-15 08:04:02.000000000 +0100
+++ src/ifactor.cc	2019-04-19 10:50:35.946113043 +0200
@@ -2517,7 +2517,7 @@
 	    lp_map[k].clear();
 	  if (lp_basis_pos){
 	    for (int k=0;;){
-	      basis_t * bit=&basis[lp_basis_pos], * bitend=&basis[0]+bs;
+	      basis_t * bit=&basis[0] + lp_basis_pos, * bitend=&basis[0]+bs; //-D_GLIBCXX_ASSERTIONS
 	      unsigned endpos=nslices*slicesize;
 	      lp_tab_t * ptr=&lp_map[0]+k*nslices;
 	      for (;bit!=bitend;++bit){
@@ -2543,7 +2543,7 @@
 	      // switch roots to next polynomial
 	      int * bvpos=&bainv2[(bv-1)*bs],* bvposend=bvpos+bs;
 	      bvpos += lp_basis_pos;
-	      basis_t * basisptr=&basis[lp_basis_pos];
+	      basis_t * basisptr=&basis[0] + lp_basis_pos; //-D_GLIBCXX_ASSERTIONS
 	      if (be>0){
 		for (;bvpos<bvposend;++basisptr,++bvpos){
 		  register unsigned p=basisptr->p;
@@ -2580,7 +2580,7 @@
 	for (int k=0;k< nslices;++k)
 	  lp_map[k].clear();
 	if (lp_basis_pos){
-	  basis_t * bit=&basis[lp_basis_pos], * bitend=&basis[0]+bs;
+	  basis_t * bit=&basis[0] + lp_basis_pos, * bitend=&basis[0]+bs;
 	  unsigned endpos=nslices*slicesize;
 	  for (;bit!=bitend;++bit){
 	    register ushort_t p=bit->p;
--- /home/fred/dev/win64/giac-1.5.0/src/vecteur.cc	2019-03-15 15:51:10.000000000 +0100
+++ src/vecteur.cc	2019-04-19 10:26:55.440442226 +0200
@@ -7470,7 +7470,7 @@
     res.clear();
     if (m==0) {
       res.resize(itend-it);
-      int * jt=&res.front();
+      int * jt=0;   if(res.size()>0) {jt=&res.front();}//-D_GLIBCXX_ASSERTIONS
       for (;it!=itend;++it,++jt){
 	int t=it->type;
 	if (t==0)
--- /home/fred/dev/win64/giac-1.5.0/src/quater.cc	2019-02-06 14:28:04.000000000 +0100
+++ src/quater.cc	2019-04-19 10:45:18.705466742 +0200
@@ -739,7 +739,7 @@
 	  vecteur2vector_int(*P._VECTptr,0,pmod);
 	  mulext(amod,bmod,pmod,m,ab);
 	  int absize=int(ab.size());
-	  int * i=&ab.front(),*iend=i+absize;
+	  int * i=0,*iend=0; if(absize>0){i=&ab.front();iend=i+absize;}//-D_GLIBCXX_ASSERTIONS
 	  for (;i<iend;++i){
 	    int j=*i;
 	    //j =smod(j,m);

parisse
Messages : 5055
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: -D_GLIBCXX_ASSERTIONS

Message par parisse » ven. avr. 19, 2019 11:56 am

Source updated, thanks!

frederic han
Messages : 1110
Inscription : dim. mai 20, 2007 7:09 am
Localisation : Paris
Contact :

Re: -D_GLIBCXX_ASSERTIONS

Message par frederic han » lun. avr. 22, 2019 12:29 pm

when building 1.5.0-49 like this (as in fedora package)

Code : Tout sélectionner

env CXXFLAGS='-g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-strict-aliasing -DGIAC_GENERIC_CONSTANTS' ./configure --enable-static=no --with-included-gettext=no --enable-nls=yes  --enable-tommath=no --enable-debug=no --enable-gc=no --enable-sscl=no  --enable-dl=yes --enable-gsl=yes --enable-lapack=yes --enable-pari=yes  --enable-ntl=yes --enable-gmpxx=yes --enable-cocoa=autodetect  --enable-gui=yes --disable-rpath
the doctest also gives a crash

Code : Tout sélectionner

limit(exp(log(log(x+exp(log(x)*log(log(x)))))/log(log(log(exp(x)+x+log(x))))),x,inf);

Code : Tout sélectionner

0>> limit(exp(log(log(x+exp(log(x)*log(log(x)))))/log(log(log(exp(x)+x+log(x))))),x,inf);
[New Thread 0x7fffdffff700 (LWP 12082)]
/usr/include/c++/8/bits/stl_vector.h:1010: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::front() [with _Tp = giac::monome; _Alloc = std::allocator<giac::monome>; std::vector<_Tp, _Alloc>::reference = giac::monome&]: Assertion '__builtin_expect(!this->empty(), true)' failed.

Thread 3 "icas" received signal SIGABRT, Aborted.
[Switching to Thread 0x7fffdffff700 (LWP 12082)]
0x00007ffff3d2f53f in raise () from /lib64/libc.so.6
...
(gdb) bt
#0  0x00007ffff3d2f53f in raise () from /lib64/libc.so.6
#1  0x00007ffff3d19895 in abort () from /lib64/libc.so.6
#2  0x000000000043d8ab in std::__replacement_assert (__file=0x7ffff78e3ba8 "/usr/include/c++/8/bits/stl_vector.h", __line=1010, 
    __function=0x7ffff78e3f80 <std::vector<giac::monome, std::allocator<giac::monome> >::front()::__PRETTY_FUNCTION__> "std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::front() [with _Tp = giac::monome; _Alloc = std::allocator<giac::monome>; std::vector<_Tp, _Alloc>::reference = giac::monome&]", 
    __condition=0x7ffff78e3b80 "__builtin_expect(!this->empty(), true)") at /usr/include/c++/8/x86_64-redhat-linux/bits/c++config.h:2391
#3  0x00007ffff70ee3a2 in std::vector<giac::monome, std::allocator<giac::monome> >::front (this=0x7fffdfffb3a0) at /usr/include/c++/8/bits/stl_vector.h:1010
#4  0x00007ffff70e4679 in giac::mrv_lead_term (e=..., x=..., coeff=..., mrv_var=..., exponent=..., q=std::vector of length 0, capacity 0, begin_ordre=2, 
    contextptr=0x7fffffffcda0, series=false) at series.cc:2943
in the following line 2943 of series.cc

Code : Tout sélectionner

      if (ctrl_c || interrupted || is_undef(p.front().exponent))
p had also size 0 here.

parisse
Messages : 5055
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: -D_GLIBCXX_ASSERTIONS

Message par parisse » mar. avr. 23, 2019 11:32 am

Try
if (ctrl_c || interrupted || p.empty() || is_undef(p.front().exponent))

frederic han
Messages : 1110
Inscription : dim. mai 20, 2007 7:09 am
Localisation : Paris
Contact :

Re: -D_GLIBCXX_ASSERTIONS

Message par frederic han » jeu. avr. 25, 2019 12:40 pm

yes it works, thanks

Répondre