seg. fault when passing va_list from Fortran to C

For pgf90 15.7.0, on:

(1) Linux 2.6.18-308.13.1.el5PAE #1 SMP Tue Aug 21 17:50:26 EDT 2012 i686 i686 i386 GNU/Linux (pgf90 15.7-0 32-bit target on x86 Linux -tp penryn)

(2) Linux 2.6.32-573.3.1.el6.x86_64 #1 SMP Thu Aug 13 22:55:16 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux (pgf90 15.7-0 64-bit target on x86-64 Linux -tp nehalem)

The following C/Fortran program works on (1) but on (2) it seg. faults when va_start(ap, ier); is not commented out.

Fortran main:

PROGRAM main
USE ISO_C_BINDING
IMPLICIT NONE
INTEGER(C_INT) :: cg, base_no, ier, zone, discr_no
CALL cg_goto_f(cg, base_no, ier, ‘Zone_t’, zone, ‘DiscreteData_t’, discr_no, ‘end’)
END PROGRAM main

C:
#include <stdarg.h>
#include <stdio.h>
void cg_goto_f_(int *fn, int *B, int *ier, …)
{
va_list ap;
printf(“inside cg_goto_f\n”);
va_start(ap, ier);
return;
}

Makefile:

INTEL COMPILER

#CC = icc
#FC = ifort

GNU COMPILER

#CC = gcc
#FC = gfortran

CC = pgcc
FC = pgf90

F90FLAGS =
CFLAGS = -g

OBJ = ccode.o

OBJF90 = fcode.o

all: test

test: $(OBJ) $(OBJF90)
$(FC) $(CFLAGS) $(LDFLAGS) $(OBJ) $(OBJF90) -o $@ $(LIB)

.SUFFIXES: .o .f90

.f90.o:
$(FC) $(F90FLAGS) -c $< -o $@ $(LIB)

.SUFFIXES: .o .c

.c.o:
$(CC) $(CFLAGS) $(LDFLAGS) -c $< -o $@ $(LIB)

clean:
rm -f *.o *.mod test

spotless:
rm -f *.o *.mod test *~

Hi Breitenfeld,

I’ll refer you to this post: Calling varlist C routine from Fortran (corrupted stack?)

Basically Fortran isn’t aware of C varags which assumes certain calling conventions. We have an internal compiler flag that works around this, but due to the extra overhead that every Fortran call would incur, it’s not something we would want to enable by default.

  • Mat

Thanks Mat,

That’s too bad, I’m assuming that after 11 years there is no plan to fix this. I’ll try with the flag -Mx,125,0x200 (and see how much it slows down the library).

BTW, the test case I sent seems to work when using the -Mx,125,0x200 flag.


Thanks.
Scot

Hi Scot,

I’m assuming that after 11 years there is no plan to fix this.

Probably not. Given that you’re only the second person to ask about this and it would have to be applied to all Fortran calls, it would be high impact with little overall benefit. Though, I could ask that we name the flag so at least it’s not a surprise.

  • Mat