Segfault

Librairie C++ de calcul formel/ C++ symbolic computation library

Modérateur : xcasadmin

JKB
Messages : 20
Inscription : mar. juin 28, 2011 7:57 am
Localisation : Paris, France
Contact :

Segfault

Message par JKB » mar. mai 29, 2018 4:29 pm

Hello,

I use giac for a long time in RPL/2 project (http://www.rpl2.fr). As gcc7 is unable to correctly build giac 1.2, I have upgraded giac to 1.4.9. Now, my software crashes with a segfault.

Code : Tout sélectionner

(gdb) run -is
Starting program: /usr/local/bin/rpl -is
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
giac::gen::~gen (this=0x7fffffffe8a8, __in_chrg=<optimized out>)
    at ../rplcas/include/giac/gen.h:692
692             if (*rc!=-1 && !--*rc){
(gdb) up
#1  0x000055555571fc2c in __static_initialization_and_destruction_0(int, int) [clone .constprop.222] ()
(gdb) bt
#0  giac::gen::~gen (this=0x7fffffffe8a8, __in_chrg=<optimized out>)
    at ../rplcas/include/giac/gen.h:692
#1  0x000055555571fc2c in __static_initialization_and_destruction_0(int, int) [clone .constprop.222] ()
#2  0x00005555566ecc8d in __libc_csu_init ()
#3  0x00007ffff44caa18 in __libc_start_main (main=0x5555557027d0 <main>, 
    argc=2, argv=0x7fffffffea28, init=0x5555566ecc40 <__libc_csu_init>, 
    fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffea18)
    at ../csu/libc-start.c:266
#4  0x000055555575629a in _start ()
I don't understanf my mistake as my program aborts in initialization stage, not in my code. And I don't think I have done a mistake when I have built giac.

Of course, I have find some occurrences of "__static_initialization_and_destruction_0" on several C++ forums but I'm not a C++ specialist and I have no idea to fix this mistake.

System : Linux debian Buster (glibc 2.27), gcc 7.3.0. I have built Pari, NTL, CoCoaLib, mpfr gmp and mpfi from sources (I don't use debian packages for these libraries).

Help will be welcome ;-)

Best regards,

JB

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

Re:

Message par parisse » mar. mai 29, 2018 7:25 pm

Not much information unfortunately. Perhaps valgrind would give more info (valgrind --leak-check=yes). Other ideas: did you compile rpl with -DHAVE_CONFIG_H? Did you include giacPCH.h first? Is rpl dynamically linked to giac?

JKB
Messages : 20
Inscription : mar. juin 28, 2011 7:57 am
Localisation : Paris, France
Contact :

Re: Re:

Message par JKB » mar. mai 29, 2018 9:26 pm

parisse a écrit :Not much information unfortunately. Perhaps valgrind would give more info (valgrind --leak-check=yes). Other ideas: did you compile rpl with -DHAVE_CONFIG_H? Did you include giacPCH.h first? Is rpl dynamically linked to giac?
I never start rpl with valgrind when it is linked with libgiac (1.2.2) as valgrind returns a lot of errors... If I rebuild RPL/2 without giac support, valgrind doesn't return memory error.

The first one, with giac, is :

Code : Tout sélectionner

==14749== Memcheck, a memory error detector
==14749== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==14749== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==14749== Command: rpl -is
==14749==
==14749== Invalid read of size 4
==14749==    at 0x42AD8C: giac::gen::~gen() (gen.h:692)
==14749==    by 0x2D3C2B: __static_initialization_and_destruction_0(int, int) [clone .constprop.222] (in /usr/local/bin/rpl)
==14749==    by 0x12A0C8C: __libc_csu_init (in /usr/local/bin/rpl)
==14749==    by 0x83CFA17: (below main) (libc-start.c:266)
==14749==  Address 0xfffffffe is not stack'd, malloc'd or (recently) free'd
==14749==
==14749==
==14749== Process terminating with default action of signal 11 (SIGSEGV)
==14749==  Access not within mapped region at address 0xFFFFFFFE
==14749==    at 0x42AD8C: giac::gen::~gen() (gen.h:692)
==14749==    by 0x2D3C2B: __static_initialization_and_destruction_0(int, int) [clone .constprop.222] (in /usr/local/bin/rpl)
==14749==    by 0x12A0C8C: __libc_csu_init (in /usr/local/bin/rpl)
==14749==    by 0x83CFA17: (below main) (libc-start.c:266)
==14749==  If you believe this happened as a result of a stack
==14749==  overflow in your program's main thread (unlikely but
==14749==  possible), you can try to increase the size of the
==14749==  main thread stack using the --main-stacksize= flag.
==14749==  The main thread stack size used in this run was 8388608.
rpl is statically linked with librplcas.a that contains libcocoa.a, libgmp.a, libmpfr.a, libgiac.a, libmpfi.a, libpari.a and ntl.a. I only include giac.h in one of RPL/2 C sources :

Code : Tout sélectionner

...
#ifdef RPLCAS

// Giac inclut <semaphore.h> et définit sem_t. Or l'émulation
// des IPCS POSIX requiert une redéfinition de sem_t.

#   ifdef IPCS_SYSV
//      NetBSD : _SEMAPHORE_H_
#       define _SEMAPHORE_H_
//      Linux : _SEMAPHORE_H
#       define _SEMAPHORE_H
#   endif

#   pragma GCC diagnostic push
#   pragma GCC diagnostic ignored "-Wstrict-aliasing"
#   pragma GCC diagnostic ignored "-Wunused-parameter"
#   pragma GCC diagnostic ignored "-Wempty-body"
#   pragma GCC diagnostic ignored "-Wunknown-pragmas"
#   include "giac.h"
#   pragma GCC diagnostic pop

#   undef PACKAGE
#   undef PACKAGE_NAME
#   undef PACKAGE_STRING
#   undef PACKAGE_TARNAME
#   undef PACKAGE_VERSION
#   undef VERSION
#endif

extern "C"
{
#   define __RPLCAS
#   include "rpl-conv.h"
}

#include <iostream>

using namespace std;

#ifdef RPLCAS
    using namespace giac;
#endif

void
initialisation_contexte_cas(struct_processus *s_etat_processus)
{
    s_etat_processus->contexte_cas = NULL;
    return;
}

...
    return;
#else

    if (s_etat_processus->langue == 'F')
    {
        printf("+++Attention : RPL/CAS non compilé !\n");
    }
    else
    {
        printf("+++Warning : RPL/CAS not available !\n");
    }

    fflush(stdout);

    return;

#endif
}
#pragma GCC diagnostic pop
(source file : http://www.rpl2.fr/cgi-bin/cvsweb/rpl/s ... web-markup)

rpl aborts with segfault before the first statement of its code. I have added a raise(SIGBUS) on the top of main() and this function is not reached.

Regards,

JB

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

Re:

Message par parisse » mer. mai 30, 2018 4:56 am

Try to compile with -DHAVE_CONFIG_H and replace #include "giac.h" with #include "giacPCH.h".

JKB
Messages : 20
Inscription : mar. juin 28, 2011 7:57 am
Localisation : Paris, France
Contact :

Re: Re:

Message par JKB » mer. mai 30, 2018 5:39 am

parisse a écrit :Try to compile with -DHAVE_CONFIG_H and replace #include "giac.h" with #include "giacPCH.h".
giac is always built with -DHAVE_CONFIG_H. If I replace #include "giac.h" by "giacPCH.h", RPL/2 runs as expected. What are the differences between giac.h and giacPCH.h ?

Best regards,

JB

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

Re:

Message par parisse » mer. mai 30, 2018 7:13 am

Inclusion of config.h

JKB
Messages : 20
Inscription : mar. juin 28, 2011 7:57 am
Localisation : Paris, France
Contact :

Re: Re:

Message par JKB » mer. mai 30, 2018 9:28 am

parisse a écrit :Inclusion of config.h
Thanks a lot for your explanations.

JB

Répondre