[Bug fortran/34136] New: [g77 regression] Add entry point and symbol for linker
burnus at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Sat Nov 17 14:38:00 GMT 2007
As reported by Jack Howarth
http://gcc.gnu.org/ml/fortran/2007-11/msg00122.html
Analysis by Walter Spector:
a) http://gcc.gnu.org/ml/fortran/2007-11/msg00131.html
Ah - the old "put block data in a library, and use EXTERNAL to make sure
it gets linked in" trick. Many compilers have gotten this wrong over
the years, because it is kinda on the edge of being required by the
Standard (any of them).
On my cygwin system, g77 and g95 get it right and gfortran gets it wrong.
See below.
While F90 modules fixed this problem by obsoleting BLOCK DATA and
COMMON, quite a number of older library packages depend on this working.
Walter
$ cat testsub.f
SUBROUTINE TESTSUB
EXTERNAL BDTEST
COMMON/TEST/WK
INTEGER WK
PRINT *,'TESTSUB: WK = ',WK, '...it should be 20'
RETURN
END
$ g77 -c testsub.f
$ nm testsub.o
00000000 b .bss
00000000 d .data
00000000 r .rdata
00000000 t .text
00000004 d ___g77_cilist_0.1
00000000 d ___g77_forceload_0.0
U _bdtest_ <<<< This references the BLOCK DATA
U _do_lio
U _e_wsle
U _s_wsle
00000010 C _test_
00000000 T _testsub_
$ gfortran -c testsub.f
$ nm testsub.o
00000000 b .bss
00000000 d .data
00000000 r .rdata
00000000 t .text <<<< Missing a reference to _bdtest_ here
U __gfortran_st_write
U __gfortran_st_write_done
U __gfortran_transfer_character
U __gfortran_transfer_integer
00000010 C _test_
00000000 T _testsub_
***************************************************************++
b) http://gcc.gnu.org/ml/fortran/2007-11/msg00132.html
The other half of this issue is on the BLOCK DATA side. There has to be
an entry point that the linker can find:
$ cat testbd.f
BLOCKDATA BDTEST
COMMON/TEST/WK
INTEGER WK
DATA WK/20/
END
$ gfortran testbd.f -c
$ nm testbd.o
00000000 b .bss
00000000 d .data
00000000 t .text
00000000 B _bdtest_ <<<< gfortran creates a BSS section
00000000 D _test_
$ g77 -c testbd.f
$ nm testbd.o
00000000 b .bss
00000000 d .data
00000000 t .text
00000000 T _bdtest_ <<<< g77 creates a TEXT entry (even though no code
exists)
00000000 D _test_
$
Again, while there used to be debates about whether the Standard required
this to work, many older packages depend on it.
--
Summary: [g77 regression] Add entry point and symbol for linker
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: burnus at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34136
More information about the Gcc-bugs
mailing list