Nios II Classic Processor Reference Guide

ID 683620
Date 10/28/2016
Public
Document Table of Contents

7.9.2. Linux Function Calls

Register r23 is reserved for the thread pointer on GNU Linux systems. It is initialized by the C library and it may be used directly for TLS access, but not modified. On non-Linux systems r23 is a general-purpose, callee-saved register.

The global pointer, r26 or gp, is globally fixed. It is initialized in startup code and always valid on entry to a function. This method does not allow for multiple gp values, so gp-relative data references are only possible in the main application (that is, from position dependent code). gp is only used for small data access, not GOT access, because code compiled as PIC may be used from shared libraries. The linker may take advantage of gp for shorter PLT sequences when the addresses are in range. The compiler needs an option to disable use of gprel; the option is necessary for applications with excessive amounts of small data. For comparison, XUL (Mozilla display engine, 16 MB code, 2 MB data) has only 27 KB of small data and the limit is 64 KB. This option is separate from -G 0, because -G 0 creates ABI incompatibility. A file compiled with -G 0 puts global int variables into .data but files compiled with -G 8 expect such int variables to be in .sdata.

PIC code which needs a GOT pointer needs to initialize the pointer locally using nextpc; the GOT pointer is not passed during function calls. This approach is compatible with both static relocatable binaries and System V style shared objects. A separate ABI is needed for shared objects with independently relocatable text and data.

Stack alignment is 32-bit. The frame pointer points at the top of the stack when it is in use, to simplify backtracing. Insert alloca between the local variables and the outgoing arguments. The stack pointer points to the bottom of the outgoing argument area.

A large struct return value is handled by passing a pointer in the first argument register (not the disjoint return value register).