Go to main content

SPARC Assembly Language Reference Manual

Exit Print View

Updated: October 2017

5.1 Basics of Compiling C Programs

When compiling a simple C program like:

int sum = 0;
void add(int a)
   sum += a;

the kind of code used to access the variable sum is different for different code models. All the code models need a way to create the address for sum so that the address can be used to load or store the value. Different code models use different methods for creating an address.

There are two basic kinds of code models, absolute and position independent. Absolute code models create an address that is a constant, so that the variable cannot be moved without changing the code. Position independent code models create an address that is more movable and can be decided at run-time. Position independent code (PIC) is recommended and sometimes required for creating shared objects. The dynamic linker (ld.so) determines the location of the shared object at run-time and finalizes the position independent address. See the Oracle Solaris Linkers and Libraries Guide for more info on this topic.