[Bug fortran/52846] [F2008] Support submodules

pault at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Jul 7 21:13:00 GMT 2015


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52846

--- Comment #7 from Paul Thomas <pault at gcc dot gnu.org> ---
Created attachment 35926
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35926&action=edit
A partially cooked patch to complete the implentation of submodules

The attached is a first attempt to complete the submodule implementation such
that private entities are correctly dealt with.

There are two parts to the patch:

(i) Modifications to the front end to write a second half to the module files,
which contains all the information about the private entities in the module.
This is the bulk of the patch; and

(ii) A change in the way that declarations of private entities are handled in
trans-decl.c. This follows a suggestion from Richard Biener to use a technique
borrowed from g++. In this patch it is only applied to variables.

Concerning (i), I am open to opinions as to whether or not it is better to
write the private parts to a separate file. At present, anything other than a
submodule does not visit the private part of the module file. Mention was made
on the list of encrypting this part of the file. Unfortunately, this overwhelms
the compression and module files remain rather large. This might be a strong
argument for emitting two files; one for the public part, as at present, and
the other for the private. In this way, a build could result in a library that
is only propagated with the public module file.

In respect of (ii), I have checked that the map shows no signs of the private
variables and that the library only carries their names.

A typical, basic makefile might look like this:

# Build submodule_8
#
submodule_8 : submodule_8_prog.o submodule_8_lib.so
        ~/irun/bin/gfortran -O3 submodule_8_prog.o submodule_8_lib.so -o
submodule_8
#
submodule_8_prog.o : submodule_8_prog.f90
        ~/irun/bin/gfortran -O3 -c submodule_8_prog.f90 -o submodule_8_prog.o
#
submodule_8_lib.so : submodule_8_lib1.o submodule_8_lib2.o
        ~/irun/bin/gfortran -O3 -shared submodule_8_lib1.o submodule_8_lib2.o
-o submodule_8_lib.so
#
# Relocation runs into problems without -fPIC for both of these compilations.
#
submodule_8_lib1.o : submodule_8_lib1.f90
        ~/irun/bin/gfortran -O3 -fPIC -c submodule_8_lib1.f90 -o
submodule_8_lib1.o
#
submodule_8_lib2.o : submodule_8_lib2.f90
        ~/irun/bin/gfortran -O3 -fPIC -c submodule_8_lib2.f90 -o
submodule_8_lib2.o

In this tested case, ~lib1 contains two modules and ~lib2 the submodules. Some
of the entities in ~lib1 are private but they are correctly propagated to ~lib2
but not to the program, ~prog.

Cheers

Paul



More information about the Gcc-bugs mailing list