mcmodel

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

IDE Equivalent

None

Architectures

Intel® EM64T

Syntax

Linux: -mcmodel=mem_model
Mac OS: None
Windows:  None

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 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.

Description

This option tells the compiler to use a specific memory model to generate code and store data. It can affect code size and performance. If your program has COMMON blocks and local data with a total size smaller than 2GB, -mcmodel=small is sufficient. COMMONs larger than 2GB require -mcmodel=medium or -mcmodel=large. Allocation of memory larger than 2GB can be done with any setting of -mcmodel.

IP-relative addressing requires only 32 bits, whereas absolute addressing requires 64-bits. IP-relative addressing is somewhat faster. So, the small memory model has the least impact on performance.

Note

When you specify -mcmodel=medium or -mcmodel=large, you must also specify compiler option -i-dynamic to ensure that the correct dynamic versions of the Intel run-time libraries are used.

When shared objects (.so files) are built, Position-Independent Code (PIC) is specified so that a single .so file can support all three memory models. The compiler driver adds compiler option -fpic to implement the PIC.

However, you must specify a memory model for code that is to be placed in a static library or code that will be linked statically.

Alternate Options

None

See Also

i-dynamic compiler option

fpic compiler option