X': ADDIL

L'ltoff,%r19

; get procedure entry point

LDW

R'ltoff(%r1),%r21

 

 

LDW

R'ltoff+4(%r1),%r19

; get new r19

value

LDSID

(%r21),%r1

 

 

 

MTSP

%r1,%sr0

 

 

 

BE

0(%sr0,%r21)

; branch to target

 

STW

%rp,-24(%sp)

; save rp

 

;Export Stub (Shared libs and Incomplete Executables)

X': BL,N

X,%rp ; trap the return

NOP

 

 

LDW

-24(%sp),%rp

; restore the original rp

LDSID

(%rp),%r1

 

MTSP

%r1,%sr0

 

BE,N

0(%sr0,%rp) ; inter-space return

For More Information: The remainder of this section describes how compilers generate PIC for the following addressing situations:

“PIC Requirements for Compilers and Assembly Code” (page 187)

“Long Calls” (page 188)

“Long Branches and Switch Tables” (page 188)

“Assigned GOTO Statements ” (page 188)

“Literal References” (page 188)

“Global and Static Variable References” (page 189)

“Procedure Labels” (page 189)

You can use these guidelines to write assembly language programs that generate PIC object code. For details on assembly language, see the Assembler Reference Manual and PA-RISC 2.0 Architecture.

PIC Requirements for Compilers and Assembly Code

The linkage table pointer register, %r19, must be stored at %sp-32by all PIC routines. This can be done once on procedure entry. The %r19 linkage table pointer register must also be restored on return from a procedure call. The value must be stored in %sp-32(and possibly in a callee-saves register). If the PIC routine makes several procedure calls, the routine copies %r19 into a callee-saves register as well, to avoid a memory reference when restoring %r19 upon return from each procedure call. Just like %r27 (%dp), the compilers treat %r19 as a reserved register whenever PIC mode is in effect. In general, references to code are handled by the linker, and the compilers act differently only in the few cases where they would have generated long calls or long branches. References to data, however, need a new fixup request to identify indirect references through the linkage table, and the code generated changes slightly.

NOTE: Any code which is PIC or which makes calls to PIC must follow the standard procedure call mechanism.

When linking files produced by the assembler, the linker exports only those assembly language routines that have been explicitly exported as entry (that is, symbols of type ST_ENTRY). Compiler-generated assembly code does not explicitly export routines with the entry type specified. So, the assembly language programmer must ensure that this is done with the .EXPORT pseudo-op. For example, in assembly language, a symbol is exported using

.EXPORT foo, type

where type can be code, data, entry, and others. To ensure that foo is exported from a shared library, the assembly statement must be:

.EXPORT foo,entry

Generating Position-Independent Code 187

Page 187
Image 187
HP UX Software Transition Kit (STK) manual PIC Requirements for Compilers and Assembly Code