1

I'm trying to compile a large scale FORTRAN application and need to link the HDF5 library to it. The program needs to be compiled with gfortran and needs the -mcmodel=large options. When using only -mcmodel=medium I'm getting error messages like:

:(.text+0x3019): relocation truncated to fit: R_X86_64_32 against `.lrodata'

I'm compiling the HDF5 library using configure:

./configure --enable-static-exec --enable-fortran FCFLAGS="-mcmodel=large" CFLAGS="-mcmodel=large"
make -j
make install

When compiling the FORTRAN program, I'm getting:

H5_ff.f90:(.text+0x23): relocation truncated to fit: R_X86_64_PC32 against symbol `predefined_types_' defined in COMMON section in /tmp/ccHO0WzS.o
H5_ff.f90:(.text+0x3c): relocation truncated to fit: R_X86_64_PC32 against symbol `predefined_types_' defined in COMMON section in /tmp/ccHO0WzS.o
H5_ff.f90:(.text+0x52): relocation truncated to fit: R_X86_64_PC32 against symbol `predefined_types_' defined in COMMON section in /tmp/ccHO0WzS.o
H5_ff.f90:(.text+0x68): relocation truncated to fit: R_X86_64_PC32 against symbol `predefined_types_' defined in COMMON section in /tmp/ccHO0WzS.o
H5_ff.f90:(.text+0x89): relocation truncated to fit: R_X86_64_PC32 against symbol `predefined_types_' defined in COMMON section in /tmp/ccHO0WzS.o
H5_ff.f90:(.text+0x9f): relocation truncated to fit: R_X86_64_PC32 against symbol `predefined_types_' defined in COMMON section in /tmp/ccHO0WzS.o
H5_ff.f90:(.text+0xb5): relocation truncated to fit: R_X86_64_PC32 against symbol `predefined_types_' defined in COMMON section in /tmp/ccHO0WzS.o

I'm on linux and am using gfortran version: 4.7.2.

Compiling with -mcmodel=medium works, but only if I reduce the size of variables in the FORTRAN program. So, what can I do to compile a FORTRAN program with gfortran and the HDF5 libraries when using -mcmodel=large?

I can not show the real program here, but to get the idea, here is a fortran program which reproduces the error:

PROGRAM test
IMPLICIT NONE
DOUBLE PRECISION tst(1000,1000,1000,1),bf
COMMON /tt/ tst
bf = tst(1,1,1,1)
print *,'Hello World.'
call kk
END PROGRAM


SUBROUTINE kk
USE H5LT
USE HDF5
IMPLICIT NONE
INTEGER(KIND=4)::errcode
call h5open_f(errcode)
print *,"Hello Subroutine."
END SUBROUTINE

Compiling it with:

gfortran -o tst -mcmodel=large tst.f90 -I./hdf5/hdf5/include -L./hdf5/hdf5/lib ./hdf5/hdf5/lib/libhdf5hl_fortran.a ./hdf5/hdf5/lib/libhdf5_hl.a ./hdf5/hdf5/lib/libhdf5_fortran.a ./hdf5/hdf5/lib/libhdf5.a -lz -lrt -ldl -lm -Wl,-rpath -Wl,./hdf5/hdf5/lib

and assuming the HDF5 library in ./hdf5/hdf5. However, this program would compile and run with -mcmodel=medium, but my real program does not. I wasn't able to come up with a simple program which would not compile with -mcmodel=medium, but with -mcmodel=large. I'm not even sure why -mcmodel=medium is not working for the real program.

The HDF5 library is available here: http://www.hdfgroup.org/HDF5/release/obtain5.html

Andre
  • 427
  • 4
  • 17
  • Please show part with the declaration of the large arrays and the values of the dimensions. Even better, come up with a fully compilable example that still fails. – Vladimir F Героям слава Aug 27 '14 at 14:49
  • Right, I just did that. But as I explained in the question, this dummy program doesn't fully reproduce the problem. – Andre Aug 27 '14 at 15:05
  • Works for me `gfortran-4.7 -mcmodel=large large.f90 -I/usr/include -lhdf5_fortran` --> `./a.out Hello World. Hello Subroutine. ` With my preinstalled hdf5 in OpenSUSE. – Vladimir F Героям слава Aug 27 '14 at 15:16
  • Find a code which fails for `-mcmodel=large` as you suggest in the first part of your question. How does the compilation command look like when you do your "When compiling the FORTRAN program, I'm getting:"? – Vladimir F Героям слава Aug 27 '14 at 15:19
  • Could it be the `--enable-static-exec` flag? I could be wrong but I thought that and the `-mcmodel=large` don't play nice together. How much memory do you have on your machine? – Timothy Brown Aug 27 '14 at 15:20
  • Do you use `large` or `medium` when "When compiling the FORTRAN program, I'm getting:" ?? – Vladimir F Героям слава Aug 27 '14 at 15:20
  • @Timothy Brown, your guess were right, now the program compiles nicly, thanks a lot for that idea!, I thought that '--enable-static-exec' was really needed – Andre Aug 27 '14 at 15:37
  • @Timothy Brown, can you post your comment as answer?, then I can accept it – Andre Aug 27 '14 at 15:48
  • @Vladimir F, I was using this consistently, so medium with medium and large with large, the comment from Timothy Brown really solved this issue for me, however I don't really understand why – Andre Aug 27 '14 at 15:50

1 Answers1

1

I think it is because your large array is in a COMMON block. This puts the array in the TEXT segment. By having this in combination with --enable-static-exec means the TEXT segment is over 2GB.

By removing the --enable-static-exec you are now using dynamic libraries and have managed to pull the TEXT segment down to below 2GB.

I dare say, if you need -mcmodel=large you should not mix it with --enable-static-exec.

Timothy Brown
  • 2,220
  • 18
  • 22