# Relocation truncated to fit error when trying to compile

**URL:** <https://fortran-lang.discourse.group/t/relocation-truncated-to-fit-error-when-trying-to-compile/3208>\
**Category:** Help\
**Created:** [April 11, 2022, 5:19pm UTC](https://fortran-lang.discourse.group/t/relocation-truncated-to-fit-error-when-trying-to-compile/3208 "2022-04-11T17:19:37Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aurelius\_Nero](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@Aurelius\_Nero](https://fortran-lang.discourse.group/u/Aurelius_Nero)\
**Post date:** [April 11, 2022, 5:19pm UTC](https://fortran-lang.discourse.group/t/relocation-truncated-to-fit-error-when-trying-to-compile/3208/1 "2022-04-11T17:19:37Z")

</div>

Compiler: ifort  
Options: -O3

Hi all, I get this error:

```auto
/opt/intel/oneapi/compiler/2022.0.2/linux/compiler/lib/intel64_lin/libifcoremt.a(for_init.o): in function `for__process_start_time':
for_init.c:(.text+0xc): relocation truncated to fit: R_X86_64_PC32 against `for_process_start_time'
/opt/intel/oneapi/compiler/2022.0.2/linux/compiler/lib/intel64_lin/libifcoremt.a(for_init.o): in function `handle_flt_und':
for_init.c:(.text+0x3d): relocation truncated to fit: R_X86_64_PC32 against symbol `for__l_fpe_mask' defined in .bss section in /opt/intel/oneapi/compiler/2022.0.2/linux/compiler/lib/intel64_lin/libifcoremt.a(for_init.o)
for_init.c:(.text+0x344): relocation truncated to fit: R_X86_64_PC32 against symbol `for__l_undcnt' defined in .bss section in /opt/intel/oneapi/compiler/2022.0.2/linux/compiler/lib/intel64_lin/libifcoremt.a(for_init.o)
for_init.c:(.text+0x396): relocation truncated to fit: R_X86_64_PC32 against symbol `for__l_undcnt' defined in .bss section in /opt/intel/oneapi/compiler/2022.0.2/linux/compiler/lib/intel64_lin/libifcoremt.a(for_init.o)
for_init.c:(.text+0x39e): relocation truncated to fit: R_X86_64_PC32 against symbol `for__l_undcnt' defined in .bss section in /opt/intel/oneapi/compiler/2022.0.2/linux/compiler/lib/intel64_lin/libifcoremt.a(for_init.o)
for_init.c:(.text+0x3aa): relocation truncated to fit: R_X86_64_PC32 against symbol `for__l_excpt_info' defined in .bss section in /opt/intel/oneapi/compiler/2022.0.2/linux/compiler/lib/intel64_lin/libifcoremt.a(for_init.o)
for_init.c:(.text+0x3cb): relocation truncated to fit: R_X86_64_PC32 against symbol `for__l_excpt_info' defined in .bss section in /opt/intel/oneapi/compiler/2022.0.2/linux/compiler/lib/intel64_lin/libifcoremt.a(for_init.o)
for_init.c:(.text+0x41e): relocation truncated to fit: R_X86_64_PC32 against symbol `for__l_undcnt' defined in .bss section in /opt/intel/oneapi/compiler/2022.0.2/linux/compiler/lib/intel64_lin/libifcoremt.a(for_init.o)
/opt/intel/oneapi/compiler/2022.0.2/linux/compiler/lib/intel64_lin/libifcoremt.a(for_init.o): in function `for__signal_handler':
for_init.c:(.text+0x91a): relocation truncated to fit: R_X86_64_PC32 against `.bss'
for_init.c:(.text+0x944): relocation truncated to fit: R_X86_64_PC32 against `.bss'
for_init.c:(.text+0x961): additional relocation overflows omitted from the output
/opt/intel/oneapi/compiler/2022.0.2/linux/compiler/lib/intel64_lin/libirc.a(tbk_backtrace.o): in function `tbk_signal_handler':
tbk_backtrace.c:(.text+0x49d): failed to convert GOTPCREL relocation against 'tbk__jmp_env'; relink with --no-relax
/opt/intel/oneapi/compiler/2022.0.2/linux/compiler/lib/intel64_lin/libirc.a(tbk_backtrace.o): in function `tbk_trace_stack_impl':
tbk_backtrace.c:(.text+0x190c): failed to convert GOTPCREL relocation against 'tbk__jmp_env'; relink with --no-relax
tbk_backtrace.c:(.text+0x1a5b): failed to convert GOTPCREL relocation against 'tbk__jmp_env'; relink with --no-relax

```

This is my code:

```auto
program int_64_check
  use iso_fortran_env
  implicit none

  type data
     real :: phi,x,y,area,h
  end type data

  type(data) :: maximum
  real :: check
  integer(kind=int64) :: i,j,k,n
  integer(kind=int64),parameter :: total=1300*2500*18000
  type(data) :: arr(total)
  real,parameter :: pi=3.14159
  real,parameter,dimension(1:2500) :: mi=[(i*0.01,i=1,2500)]
  real,parameter,dimension(1:18000) :: mk=[(i*(pi/180.)*0.01,i=1,18000)]

  n=1

  do concurrent(i=1:1300,j=1:2500,k=1:18000)
     arr(n)%x=mi(i)
     arr(n)%y=mi(j)
     arr(n)%phi=mk(k)
     n=n+1
  end do

  call calculate(arr%x,arr%y,arr%phi,arr%h,arr%area)
  maximum%area=0.

contains
  
  elemental subroutine calculate(x,y,phi,h,area)
    real,intent(in) :: x,y,phi
    real,intent(out) :: h,area
    real :: b1,b2

    h=sin(phi)*x
    b1=(2*(cos(phi))+x)+y
    b2=y
    area=(1./2.)*h*(b1+b2)
  end subroutine calculate

end program int_64_check

```

---

<div class="post-metadata">

**Author:** ![milancurcic](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/milancurcic/32/2_2.png) [@milancurcic](https://fortran-lang.discourse.group/u/milancurcic)\
**Post date:** [April 11, 2022, 5:35pm UTC](https://fortran-lang.discourse.group/t/relocation-truncated-to-fit-error-when-trying-to-compile/3208/2 "2022-04-11T17:35:32Z")

</div>

As I understand it, this kind of error occurs when the addresses of statically allocated data don’t fit into the address space (2 GB default).

What happens if you add `-mcmodel=medium` to the compiler flags?

From the ifort manual:

```auto
       -mcmodel=mem_model (L*X only)

              Tells the compiler to use a specific
                     memory model to generate code and store data.

              Architecture Restrictions: Only available on Intel(R) 64 architecture

              Arguments:

              mem_model Is the memory model to use. Possible values are:

                                small Tells the compiler to restrict code and data to the first 2GB of address space. All accesses of code
                                               and data can be done with Instruction Pointer (IP)-relative addressing.

                                medium Tells the compiler to restrict code to the first 2GB; it places no memory restriction on data.
                                               Accesses of code can be done with IP-relative addressing, but accesses of data must be done with
                                               absolute addressing.

                                large Places no memory restriction on code or data. All accesses of code and data must be done with
                                               absolute addressing.

              Default:

              -mcmodel=small On systems using Intel(R) 64 architecture, the compiler restricts code and data to the first 2GB of address space.
                                Instruction Pointer (IP)-relative addressing can be used to access code and data.
...

```

Also, `type(data) :: arr(total)` is very large. Make sure it can fit in your computer’s RAM.

---

<div class="post-metadata">

**Author:** ![Aurelius\_Nero](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@Aurelius\_Nero](https://fortran-lang.discourse.group/u/Aurelius_Nero)\
**Post date:** [April 11, 2022, 5:44pm UTC](https://fortran-lang.discourse.group/t/relocation-truncated-to-fit-error-when-trying-to-compile/3208/3 "2022-04-11T17:44:32Z")

</div>

@milancurcic  
It compiles with the tag, but I get a segmentation fault error when I try to run it 😅

About the size, what’s the max size array that can be worked on at compilation time ?

---

<div class="post-metadata">

**Author:** ![CRquantum](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/crquantum/32/730_2.png) [@CRquantum](https://fortran-lang.discourse.group/u/CRquantum)\
**Post date:** [April 11, 2022, 6:04pm UTC](https://fortran-lang.discourse.group/t/relocation-truncated-to-fit-error-when-trying-to-compile/3208/4 "2022-04-11T18:04:51Z")

</div>

![image](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/a/a6cab9ecc593e2e380a291c6a461f4b85537a4bf.png)

Does the flag /heaps-arrays0 work?  
On linux it is -heap-arrays

---

<div class="post-metadata">

**Author:** ![Aurelius\_Nero](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@Aurelius\_Nero](https://fortran-lang.discourse.group/u/Aurelius_Nero)\
**Post date:** [April 11, 2022, 6:08pm UTC](https://fortran-lang.discourse.group/t/relocation-truncated-to-fit-error-when-trying-to-compile/3208/5 "2022-04-11T18:08:29Z")

</div>

Nope ☹ , sadly I get the same error  
I even tried with the previous tag suggested.

---

<div class="post-metadata">

**Author:** ![CRquantum](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/crquantum/32/730_2.png) [@CRquantum](https://fortran-lang.discourse.group/u/CRquantum)\
**Post date:** [April 11, 2022, 6:26pm UTC](https://fortran-lang.discourse.group/t/relocation-truncated-to-fit-error-when-trying-to-compile/3208/6 "2022-04-11T18:26:03Z")

</div>

yeah I see, the error I got is,

```auto
1>x64\Release\avx.obj: catastrophic error: Variable INT_64_CHECK$ARR.0.1 too large for NTCOFF. Bigger than 2GB. Use heap instead

```

I have also did

 ![image](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/5/532805fd8eda307ab6e835c9caae7af4225c1a5e.png)

But still got the same error. The 2147483647 is largest I can set, it is the upper bound of int32.

You parameter `total` is out of the bound of int32 and it is int64, so it seems does not fit.

I changed your code to below using allocatable array.

```auto
program int_64_check
  use iso_fortran_env
  implicit none

  type data
     real :: phi,x,y,area,h
  end type data

  type(data) :: maximum
  real :: check
  integer(kind=int64) :: i,j,k,n 
  integer(kind=int64) :: n1300,n2500,n18000,ntotal
  type(data), allocatable :: arr(:)
  real,parameter :: pi=3.14159
  real,allocatable :: mi(:)
  real,allocatable :: mk(:)

  n=1
  
  n1300 = 1300
  n2500 = 2500
  n18000 = 18000
  ntotal = n1300*n2500*n18000
  mi=[(i*0.01,i=1,n2500)]
  mk=[(i*(pi/180.)*0.01,i=1,n18000)]
  allocate(arr(ntotal))

  do concurrent(i=1:n1300,j=1:n2500,k=1:n18000)
     arr(n)%x=mi(i)
     arr(n)%y=mi(j)
     arr(n)%phi=mk(k)
     n=n+1
  end do

  call calculate(arr%x,arr%y,arr%phi,arr%h,arr%area)
  maximum%area=0.

contains
  
  elemental subroutine calculate(x,y,phi,h,area)
    real,intent(in) :: x,y,phi
    real,intent(out) :: h,area
    real :: b1,b2

    h=sin(phi)*x
    b1=(2*(cos(phi))+x)+y
    b2=y
    area=(1./2.)*h*(b1+b2)
  end subroutine calculate

end program int_64_check

```

But it shows not sufficient virtual memory, the I realize your array is indeed too big,

18000 \* 2500 \* 1300 \* 8/1024/1024/1024=432GB or so. It is too big for my memory.

Perhaps the below link may help,

> **[Severe: Variable ... too large for NTCOFF. Bigger than 2GB. Use heap instead...](https://community.intel.com/t5/Intel-Fortran-Compiler/Severe-Variable-too-large-for-NTCOFF-Bigger-than-2GB-Use-heap/td-p/873849)**
>
> The same program runs correctlywith the 3D array of (32,32,512) (double) by thevs2005 plus intel visual fortran complier 10.1 (Intel 64 ). When the array is extended to (512, 512, 512) (double), however, if compiling,it shows that ---- Severe:...

---

<div class="post-metadata">

**Author:** ![Aurelius\_Nero](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@Aurelius\_Nero](https://fortran-lang.discourse.group/u/Aurelius_Nero)\
**Post date:** [April 11, 2022, 6:30pm UTC](https://fortran-lang.discourse.group/t/relocation-truncated-to-fit-error-when-trying-to-compile/3208/7 "2022-04-11T18:30:50Z")

</div>

alright thank you . I’ll just make them allocatable

---

<div class="post-metadata">

**Author:** ![CRquantum](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/crquantum/32/730_2.png) [@CRquantum](https://fortran-lang.discourse.group/u/CRquantum)\
**Post date:** [April 11, 2022, 6:36pm UTC](https://fortran-lang.discourse.group/t/relocation-truncated-to-fit-error-when-trying-to-compile/3208/8 "2022-04-11T18:36:42Z")

</div>

> [@CRquantum](#):
>
> 18000 \* 2500 \* 1300 \* 8/1024/1024/1024=432GB or so. It is too big for my memory.

The 8 in 18000 \* 2500 \* 1300 \* 8 is for real 8 which means 8 bytes.  
See my edited post above (I use allocatable array), however, if I calculated correctly, your array may be really too big, lol.

---

<div class="post-metadata">

**Author:** ![CRquantum](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/crquantum/32/730_2.png) [@CRquantum](https://fortran-lang.discourse.group/u/CRquantum)\
**Post date:** [April 11, 2022, 6:47pm UTC](https://fortran-lang.discourse.group/t/relocation-truncated-to-fit-error-when-trying-to-compile/3208/9 "2022-04-11T18:47:04Z")

</div>

Perhaps you may use Monte Carlo to calculate your area.  
Or instead of using big arrays, you can use do loop instead.  
Using such big array (even if it fits you physics memory) is very likely make you memory bandwidth the bottleneck.

---

<div class="post-metadata">

**Author:** ![Aurelius\_Nero](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@Aurelius\_Nero](https://fortran-lang.discourse.group/u/Aurelius_Nero)\
**Post date:** [April 11, 2022, 6:52pm UTC](https://fortran-lang.discourse.group/t/relocation-truncated-to-fit-error-when-trying-to-compile/3208/10 "2022-04-11T18:52:38Z")

</div>

I will try the suggestions out 🙂 Thank you

---

<div class="post-metadata">

**Author:** ![CRquantum](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/crquantum/32/730_2.png) [@CRquantum](https://fortran-lang.discourse.group/u/CRquantum)\
**Post date:** [April 11, 2022, 7:05pm UTC](https://fortran-lang.discourse.group/t/relocation-truncated-to-fit-error-when-trying-to-compile/3208/11 "2022-04-11T19:05:58Z")

</div>

I am very sure you could figure out how to solve the problem 🙂  
For numerical integration, perhaps quadpack may help,

> **[QUADPACK](https://en.wikipedia.org/wiki/QUADPACK)**
>
> QUADPACK is a FORTRAN 77 library for numerical integration of one-dimensional functions. It was included in the SLATEC Common Mathematical Library and is therefore in the public domain. The individual subprograms are also available on netlib.
> The GNU Scientific Library reimplemented the QUADPACK routines in C. SciPy provides a Python interface to part of QUADPACK.
> The main focus of QUADPACK is on automatic integration routines in which the user inputs the problem and an absolute or relative err...

[https://people.sc.fsu.edu/~jburkardt/f77\_src/quadpack/quadpack.html](https://people.sc.fsu.edu/~jburkardt/f77_src/quadpack/quadpack.html)  
Good luck.

---

<div class="post-metadata">

**Author:** ![Aurelius\_Nero](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@Aurelius\_Nero](https://fortran-lang.discourse.group/u/Aurelius_Nero)\
**Post date:** [April 11, 2022, 7:10pm UTC](https://fortran-lang.discourse.group/t/relocation-truncated-to-fit-error-when-trying-to-compile/3208/12 "2022-04-11T19:10:10Z")

</div>

Thank you

---

<div class="post-metadata">

**Author:** ![Aurelius\_Nero](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@Aurelius\_Nero](https://fortran-lang.discourse.group/u/Aurelius_Nero)\
**Post date:** [April 11, 2022, 7:40pm UTC](https://fortran-lang.discourse.group/t/relocation-truncated-to-fit-error-when-trying-to-compile/3208/13 "2022-04-11T19:40:07Z")

</div>

Is there a library for 2D functions ?

---

<div class="post-metadata">

**Author:** ![CRquantum](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/crquantum/32/730_2.png) [@CRquantum](https://fortran-lang.discourse.group/u/CRquantum)\
**Post date:** [April 11, 2022, 11:35pm UTC](https://fortran-lang.discourse.group/t/relocation-truncated-to-fit-error-when-trying-to-compile/3208/14 "2022-04-11T23:35:38Z")

</div>

Perhaps there are other ones for numerical integration. But the one by @jacobwilliams may be a decent one,

> **[GitHub - jacobwilliams/quadrature-fortran: 1D-6D Adaptive Gaussian Quadrature with Modern...](https://github.com/jacobwilliams/quadrature-fortran)**
>
> 1D-6D Adaptive Gaussian Quadrature with Modern Fortran

Well, actually I should give the above link before, I mistakenly it with quadpack (I mistakenly though quadpack can deal with 2 or more dimensional numerical integrals). Perhaps @Beliavsky know some other libraries too.

I personally may use Monte Carlo.

Also, from

> [@New Fortran projects](https://fortran-lang.discourse.group/t/new-fortran-projects/2000):
>
> Here is list of projects from [Fortran Code on Github](https://github.com/Beliavsky/Fortran-code-on-GitHub/blob/main/README.md) that were added since the beginning of September. I can update this monthly if there is interest. For brevity I have excluded projects from domain-specific categories such as Astrophysics or Earth Science. They are on the main list. Some “new” projects are years old but were only recently added. Benchmarks [cumsum\_benchmark](https://github.com/ivan-pi/cumsum_benchmark): benchmarks for the cumulative sum of an array, in Fortran, C++, Matlab, and Python, using various methods [Simple N-Bod…](https://github.com/marblestation/benchmark-leapfrog)

I found

> **[GitHub - giacrossi/FORbID: Simple OOP Fortran Definite Integrals Solver](https://github.com/giacrossi/FORbID)**
>
> Simple OOP Fortran Definite Integrals Solver

---

<div class="post-metadata">

**Author:** ![Aurelius\_Nero](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@Aurelius\_Nero](https://fortran-lang.discourse.group/u/Aurelius_Nero)\
**Post date:** [April 12, 2022, 1:32am UTC](https://fortran-lang.discourse.group/t/relocation-truncated-to-fit-error-when-trying-to-compile/3208/15 "2022-04-12T01:32:51Z")

</div>

Thank you
