g77 block data initialization

Skip Egdorf egdorf@zaphod.lanl.gov
Mon Oct 19 08:00:00 GMT 1998


Intel Linux 2.0.34/35, both libc5/6
egcs-2.91.57/g77-0.5.24 19980804
brief description: In a shared dynamic library environment, Fortran
block data initializations ONLY happen in the FIRST dynamic library
loaded, and are ignored in the second and later libraraies.

I am attempting to load some large (100k-lines), existing fortran-77
legacy codes in a new way. These codes currently are in seperate
source files (typically one subroutine/function/block-data per file)
that are compiled into .o's and then loaded with "ar" into ".a"
archives. These archives are then linked with ld into the final
executable. There are about a dozen .a's in the link, and the
code is "owned" by different groups so that re-organization of the
which files go into which archives is not feasable.

The inportant piece of the structure is that there are several
block data programs initializing many different labeled commons.
These block datas are located in several different archives.

I am changing the process to a dynamic link scheme where the
.a's are loaded shared as .so's and then loaded at run-time
with the -libdl dlopen and dlsym routines.

The main program is basically
      PROGRAM MAIN
      CALL STUFF
      STOP
      END

where STUFF is all the actual program. I am replacing this with
something like

#include <dlfcn.h>
      main (int ac, char **av)
      {
      h1 = dlopen ("flib1.so", ...);
      h2 = dlopen ("flib2.so", ...);
      ...
      f = dlsym (h1, "STUFF_");
      (*f)();
      }

The details of using the -libdl stuff, compiling with -pic,
loading with -rdynamic and -shared, etc. are all fairly worked out
and the basic idea seems sound. At least on egcs, I can go look at
main.c in libF77 and see what sort of global initialization is done
to get IO going and make getarg work. Solaris doesn't give much of a
clue (bug reports have been filed).

The egcs problem seems to be that the initialization performed by the
block-data programs ONLY happens in the FIRST archive loaded. Any
block datas in the second, third, ... libraries do not seem to have
their initializations performed.

I understand that there are some quirky things regarding the precise
definition of f77 block data initialization that cause problems for
implementors here. I have looked at the assembler generated for
the block data's, but don't see what could be going on to prevent
the block-data's from doing their thing.

Could someone

a) give a brief tutorial, or point at a brief tutorial on how fortran
   block data is implemented in egcs? I'm stonewalled, not knowing exactly
   what I am looking at or for.

b) give a brief overview of the problems in the f77 spec dealing with
   block data?

c) suggest a fix???

Thanks for any help.

					Skip Egdorf
					hwe@lanl.gov



More information about the Gcc-bugs mailing list