medium mem model can't cope with large data

Hi,

I’m using pgf77 6.1-6 64-bit target on x86-64 Linux with the -mcmodel=medium flag to compile a program that contains a 3GB integer array initialized to 0.

      block data
      integer n
      parameter (n=750 000 000)
      integer x(n)
      common /global/ x
      data x /n*0/
      end

      program mem
      integer n, i
      parameter (n=750 000 000)
      integer x(n)
      common /global/ x
      do i = 1, n
         x(i) = 1
      end do
      stop
      end

The result is

$ pgf77 -mcmodel=medium mem.f
/usr/lib/gcc/x86_64-redhat-linux/3.4.4//crtbegin.o(.text+0x2): In function `__do_global_dtors_aux':
: relocation truncated to fit: R_X86_64_PC32 .bss
/usr/lib/gcc/x86_64-redhat-linux/3.4.4//crtbegin.o(.text+0x2e): In function `__do_global_dtors_aux':
: relocation truncated to fit: R_X86_64_PC32 .bss

I had to set TMP to the current working dir, as /tmp was not big enough. What am I doing wrong?

Ed

Hi Ed,

Initialized data gets stored in the “.data” section and since each element of your array elements gets an assembly statement to perform the initialization, your object grows to over 3GB. Unfortunately, it appears that the Linux system files were not compiled correctly for this case. They contain references to the “.bss” sections using 32-bit addressing. Since “.data” is in between “.text” and “.bss”, the large data section causes the relocation errors.

I’ll need to pass this along to the folks at GCC to see what can be done. However, I’m not sure how much of a priority it will be for them. In the mean time, I would suggest initializing large arrays at runtime instead of block data. Besides this problem, your binaries will be extremely large and take an extraordinary long time to load.

-Mat

Thanks for the analysis Mat.

I don’t normally program with block data, preferring to initialize at runtime as you recommend. This was just one of many experiments I was conducting with different memory layout scenarios in order to get a better idea of how the -mcmodel, -fpic, and -Mlarge_arrays switches work.

Ed