Combining a Fortran-routine and a C-routine gives a binary, which produces
almost all errors, like illegal instruction, segmention fault, invalid output,
when the switch -m64 is used. The program works fine using -m32 or using -m64
and an older version of GCC or using a Sun compiler.
Example:
---- snip: file test2.F -----
PROGRAM TEST
IMPLICIT NONE
INTEGER wrtmsg
EXTERNAL wrtmsg
INTEGER I, IERROR
I = 1
IERROR = wrtmsg(I,
* 'This is the string %s no. %d: %s.'//CHAR(0),
* 'test1'//CHAR(0), I, 'TEST 1'//CHAR(0))
I = 2
IERROR = wrtmsg(I,
* 'This is the string %s no. %d: %s.'//CHAR(0),
* 'test2'//CHAR(0), I, 'TEST 2'//CHAR(0))
I = 3
IERROR = wrtmsg(I,
* 'This is the %drd string %s no. %d: %s.'//CHAR(0),
* I, 'test3'//CHAR(0), I, 'TEST 3'//CHAR(0))
STOP
END
---- snap ---
---- snip: file wrtmsg.c ----
#include <stdarg.h>
#include <stdio.h>
int
wrtmsg_(int *i, char *format, ...)
{
char tmp_string[1000];
va_list args;
int *i1, *i2;
char *s1, *s2;
va_start(args, format);
if (*i == 1 || *i == 2)
{
s1 = (char *) va_arg(args, char*);
i1 = (int *) va_arg(args, int*);
s2 = (char *) va_arg(args, char*);
snprintf(tmp_string, 1000, format, s1, *i1, s2);
}
else
{
i1 = (int *) va_arg(args, int*);
s1 = (char *) va_arg(args, char*);
i2 = (int *) va_arg(args, int*);
s2 = (char *) va_arg(args, char*);
snprintf(tmp_string, 1000, format, *i1, s1, *i2, s2);
}
va_end(args);
printf("%s\n", tmp_string);
return *i+1;
}
---- snap ----
Compiler used:
% gfortran -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../../gcc-4.0.1/configure --prefix=/tmp2/denk/GCC4.0.1
--exec-prefix=/tmp2/denk/GCC4.0.1/LINUXAMD64 --enable-languages=c,c++,f95,java
--with-gmp=/tmp2/denk/GCC4.0.1/LINUXAMD64 --with-mpfr=/tmp2/denk/GCC4.0.1
Thread model: posix
gcc version 4.0.1
How to reproduce:
% gfortran -c -fno-second-underscore -Wall -m64 -g test2.F
% gcc -c -Wall -m64 -g wrtmsg.c
% gfortran -o test2 -Wall -m64 -g wrtmsg.o test2.o
Results:
% ./test2
This is the string test1 no. 1: TEST 1.
This is the string test2 no. 2: TEST 2.
Illegal instruction
% ./test2
This is the string test1 no. 1: TEST 1.
This is the string test2 no. 2: TEST 2.
Segmentation fault
% ./test2
This is the string test1 no. 1: TEST 1.
This is the string test2 no. 2: TEST 2.
STOP 0
(which means that the last output line has got lost)
--
Summary: -m64 gives runtime errors in combined Fortran/C programs
Product: gcc
Version: 4.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: georg dot denk at infineon dot com
CC: gcc-bugs at gcc dot gnu dot org,georg dot denk at
infineon dot com
GCC build triplet: x86_64-unknown-linux-gnu
GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23349