This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/29899] New: [Segfault] Fortran entry point caught from C function


Hello,

I work for a long time on a programming language and it is written in C, F77
and F90. I can build this code with all release of gcc/gfortran before the
4.1.x.
I have tried to found a bug in my code without any success, thus, I write this
bug report.

Test program:
schroedinger:[~/test] > gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-mpfr --with-tune=i686
--enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.1.2 20061028 (prerelease) (Debian 4.1.1-19)
schroedinger:[~/test] > gfortran -v 
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-mpfr --with-tune=i686
--enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.1.2 20061028 (prerelease) (Debian 4.1.1-19)
schroedinger:[~/test] > cat a.c   
#include <stdlib.h>

//#define integer4 int
typedef long int integer4;

void rluxgo_(integer4 *luxuriance, integer4 *racine, integer4 *k1,
                integer4 *k2);

int main (void)
{
  integer4 k1, k2, luxuriance, racine;

  k1 = 0;
  k2 = 0;
  printf("%d\n", sizeof(k1));
  luxuriance = 4;
  racine = (integer4) time(NULL);

  rluxgo_ (&luxuriance, &racine, &k1, &k2);
}

schroedinger:[~/test] > cat ranlux.f 
      subroutine RANLUX(RVEC, LENV)

      implicit none

      integer*4                         I
      integer*4                         I24
      integer*4                         IN24
      integer*4                         ICONS
      integer*4                         IGIGA
      integer*4                         ILX
      integer*4                         INNER
      integer*4                         INOUT
      integer*4                         INS
      integer*4                         INSEED
      integer*4                         IOUTER
...
      entry RLUXAT(LOUT,INOUT,K1,K2)

      LOUT = LUXLEV
      INOUT = INSEED
      K1 = KOUNT
      K2 = MKOUNT

      return

      entry RLUXGO(LUX,INS,K1,K2)

      if (LUX.lt.0) then
          LUXLEV = LXDFLT
      else if (LUX.le.MAXLEV) then
          LUXLEV = LUX
      else if ((LUX.lt.24).or.(LUX.gt.2000)) then
          LUXLEV = MAXLEV
      else
          LUXLEV = LUX

          do ILX = 0, MAXLEV
              if (LUX.eq.(NDSKIP(ILX) + 24)) then
                  LUXLEV = ILX
              end if
          end do
      end if

      if (LUXLEV.le.MAXLEV) then
          NSKIP = NDSKIP(LUXLEV)
      else
          NSKIP = LUXLEV - 24
      end if

      IN24 = 0
...
      end subroutine
schroedinger:[~/test] > gfortran a.c ranlux.f
schroedinger:[~/test] > ./a.out 
4
schroedinger:[~/test] > 

You can found the complete ranlux.f subroutine at
http://www.systella.fr/~bertrand/rpl2/download/rpl-4.00pre8q.tar.bz2

Calling a Fortran entry point from C seems to work. But if I call the same
entry point (or another) from the C function :
void
instruction_rand(struct_processus *s_etat_processus)
{
    integer4                    k1;
    integer4                    k2;
    integer4                    luxuriance;
    integer4                    nombre_valeurs;
    integer4                    racine;

    struct_objet                *s_objet;

    (*s_etat_processus).erreur_execution = d_ex;

    if ((*s_etat_processus).affichage_arguments == 'Y')
    {
        printf("\n  RAND ");

        if ((*s_etat_processus).langue == 'F')
        {
            printf("(variable aléatoire uniforme)\n\n");
        }
        else
        {
            printf("(uniform random number)\n\n");
        }

        printf("->  1: %s\n", d_REL);

        return;
    }

printf("Ici\n");
    if (test_cfsf(s_etat_processus, 31) == d_vrai)
    {
        if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
        {
            return;
        }
    }

printf("Là\n");
    if ((*s_etat_processus).initialisation_generateur_aleatoire == d_faux)
    {
        k1 = 0;
        k2 = 0;
printf("%d\n", sizeof(k1));
        luxuriance = 4;
        racine = (integer4) time(NULL);

        rluxat_(&luxuriance, &racine, &k1, &k2);
printf("Encore ici\n");
...

I obtain a superb segmentation fault:
rayleigh:[~/gopher/rpl2/rpl-4.00pre8r/src] > LANG=C ./rpl -isd
+++RPL/2 version 4.00pre8r (Sunday 11/19/06, 16:46:42 CET)
+++Copyright (C) 1989 to 2005, 2006 BERTRAND Joël

+++This is a free software with absolutely no warranty.
+++For details, type 'warranty'.

+++rand
Ici
Là
4
Erreur de segmentation
rayleigh:[~/gopher/rpl2/rpl-4.00pre8r/src] > 

I have tried to debug the core dump without any success. The good values are
sent to the Fortran code. In my code, I use some system calls (sigaction to
manage stacks), but I don't understand the mistake. I'm not sure it is a bug in
gfortran, but I don't found any bug in my code.

All sources are available at
http://www.systella.fr/~bertrand/rpl2/download/rpl-4.00pre8q.tar.bz2

Regards,

JKB


-- 
           Summary: [Segfault] Fortran entry point caught from C function
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jkb at systella dot fr
 GCC build triplet: i586-pc-linux-gnu
  GCC host triplet: i586-pc-linux-gnu
GCC target triplet: i486-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29899


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]