Question about gcc option -mcmodel
Ramana Radhakrishnan
ramana.radhakrishnan@foss.arm.com
Thu Aug 2 12:36:00 GMT 2018
On 01/08/2018 03:56, xiebin (F) wrote:
> Hi everyone,
> I was compiling a HPC application named NorESM on ARM64 machine with GCC7.3.
> I met "relocation truncated to fit" error, so I added "-mcmodel=large" and successfully built the project. However, the executable seems not executable.
> [xie@sms bld]$ strace ./cesm.exe
> execve("./cesm.exe", ["./cesm.exe"], [/* 64 vars */]) = -1 ENOMEM (Cannot allocate memory)
> --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} ---
> +++ killed by SIGSEGV +++
> Segmentation fault (core dumped)
> I found this in GCC manual aarch64 section:
> -mcmodel=small
> Generate code for the small code model. The program and its statically defined symbols must be within 4GB of each other. Programs can be statically or
> dynamically linked. This is the default code model.
>
> -mcmodel=large
> Generate code for the large code model. This makes no assumptions about addresses and sizes of sections. Programs can be statically linked only.
I don't think we ever got everything working for building shared objects
with -mcmodel=large fully implemented.
Applications should be able to interoperate with executables built with
-mcmodel=large and libraries built with -mcmodel=small.
Can you debug this in gdb and see why you get the SEGV ?
regards
Ramana
>
> I also compiled the project on x86-64 with intel compiler. In this situation, I added "-mcmodel=medium" and compilation and execution are successful. Below is its explanation:
> -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.
>
> Here are my questions:
>
> 1. What does "Programs can be statically linked only" means? Does it mean I must compile all dependency libraries staticly? What about the basic librarie like libc and libgcc?
>
> 2. Does GCC has similar option to separate code and data like Intel Compiler does?
>
More information about the Gcc-help
mailing list