next up previous
Next: Inline Assembly Statements Up: ELF: From The Previous: Dynamic loading under

Programming in Assembly Language with PIC

When one specifies -fPIC to gcc, gcc will generate the position independent code (PIC) assembly language code from the C source code. But sometimes one needs to program in assembly language and support PIC at the same time. This is what happened in the Linux C library.

PIC under ELF is implemented using the base register. All the symbols are referenced via the base register under PIC and therefore to write assembly language code with PIC, one has to SAVE THE BASE REGISTER. Due to position independent code, the target destinations of control transfer instructions must be displacements or computed under PIC. For x86-based machines, the base register is ebx. Here we introduce two ways to write PIC-safe assembly code under x86. These techniques are used in the Linux C library.

Tue Aug 1 14:18:10 MDT 1995