Avoiding Relocation Errors when Building Applications with Large Global or Static Data on Intel64 Linux

Problem :  Relocation overflow errors at link time, with messages such as "relocation truncated to fit"


Environment :  Linux* for Intel64;  the Intel C/C++ and Fortran Compilers; applications with >2GB of global or static data.


Root Cause : The default memory model for the Intel® Compiler for Intel64 Linux* is small (–mcmodel=small). This restricts both code and global or static data to the first 2 GB of address space and allows all accesses to be made with instruction pointer (IP)-relative addressing. If an application containing a total of more than 2 GB of global or static data is built with default options, the IP-relative addressing may result in a relocation overflow error at link time.


Resolution : Such applications should be compiled with the medium memory model (–mcmodel=medium), which ensures that data accesses use absolute addressing that can accommodate large addresses.

Applications built with –mcmodel=medium should normally be linked against shared libraries. Shared libraries are built with position independent code (-fpic), do not normally themselves contain large, static data and are compatible with both small and medium memory models.

If an application built with –mcmodel=medium is linked against a static library, that library should also be built with the medium memory model. Such a library may also be linked against an application built with the small memory model, provided that the library does not itself contain large static or global data. There may be a slight performance advantage in linking an application built with the small memory model to a static library built in the same way, but any performance benefit is usually rather small.

The static libraries within the Intel compiler runtime library are built with the default small memory model. Therefore, applications built with –mcmodel=medium should not link against these, but should use –shared-intel to link against the shared runtime libraries, which are built with –fpic and are compatible with the medium memory model. From version 13 of the Intel compiler, -shared-intel becomes the default when -mcmodel medium is specified.

The same is true of many other libraries. For applications compiled with the medium memory model, it is recommended to link against the shared versions of other libraries such as IMSL or Intel MPI.

The Intel® Math Kernel Library (MKL) is an exception. The static version of MKL has been built to be compatible with both small and medium memory models. Therefore, applications built with –mcmodel=medium may link against either the static or the shared library version of MKL.


This article applies only to applications with more than 2 GB of global or statically allocated data. Applications where large data are allocated dynamically at runtime, e.g. with malloc() in C, with new() in C++ or with ALLOCATE in Fortran, do not need to be built with the medium memory model.
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.