8.2.3.3 Relocations
Some of these relocations are available for ECOFF, but mostly only for ELF. They are modeled after the relocation format introduced in Digital Unix 4.0, but there are additions.
The format is ! tag or ! tag ! number where tag is the name of the relocation. In some cases number is used to relate specific instructions.
The relocation is placed at the end of the instruction like so:
ldah $0,a($29) !gprelhigh
lda $0,a($0) !gprellow
ldq $1,b($29) !literal!100
ldl $2,0($1) !lituse_base!100
-
!literal -
!literal!N -
Used with an
ldqinstruction to load the address of a symbol from the GOT.A sequence number N is optional, and if present is used to pair
lituserelocations with thisliteralrelocation. Thelituserelocations are used by the linker to optimize the code based on the final location of the symbol.Note that these optimizations are dependent on the data flow of the program. Therefore, if any
lituseis paired with aliteralrelocation, then all uses of the register set by theliteralinstruction must also be marked withlituserelocations. This is because the originalliteralinstruction may be deleted or transformed into another instruction.Also note that there may be a one-to-many relationship between
literalandlituse, but not a many-to-one. That is, if there are two code paths that load up the same address and feed the value to a single use, then the use may not use alituserelocation.
-
!lituse_base!N - Used with any memory format instruction (e.g.
ldl) to indicate that the literal is used for an address load. The offset field of the instruction must be zero. During relaxation, the code may be altered to use a gp-relative load.
-
!lituse_jsr!N - Used with a register branch format instruction (e.g.
jsr) to indicate that the literal is used for a call. During relaxation, the code may be altered to use a direct branch (e.g.bsr).
-
!lituse_bytoff!N - Used with a byte mask instruction (e.g.
extbl) to indicate that only the low 3 bits of the address are relevant. During relaxation, the code may be altered to use an immediate instead of a register shift.
-
!lituse_addr!N -
Used with any other instruction to indicate that the original address is in fact used, and the original
ldqinstruction may not be altered or deleted. This is useful in conjunction withlituse_jsrto test whether a weak symbol is defined.ldq $27,foo($29) !literal!1 beq $27,is_undef !lituse_addr!1 jsr $26,($27),foo !lituse_jsr!1
-
!lituse_tlsgd!N - Used with a register branch format instruction to indicate that the literal is the call to
__tls_get_addrused to compute the address of the thread-local storage variable whose descriptor was loaded with!tlsgd!N.
-
!lituse_tlsldm!N - Used with a register branch format instruction to indicate that the literal is the call to
__tls_get_addrused to compute the address of the base of the thread-local storage block for the current module. The descriptor for the module must have been loaded with!tlsldm!N.
-
!gpdisp!N -
Used with
ldahandldato load the GP from the current address, a-la theldgpmacro. The source register for theldahinstruction must contain the address of theldahinstruction. There must be exactly oneldainstruction paired with theldahinstruction, though it may appear anywhere in the instruction stream. The immediate operands must be zero.bsr $26,foo ldah $29,0($26) !gpdisp!1 lda $29,0($29) !gpdisp!1
-
!gprelhigh - Used with an
ldahinstruction to add the high 16 bits of a 32-bit displacement from the GP.
-
!gprellow - Used with any memory format instruction to add the low 16 bits of a 32-bit displacement from the GP.
-
!gprel - Used with any memory format instruction to add a 16-bit displacement from the GP.
-
!samegp - Used with any branch format instruction to skip the GP load at the target address. The referenced symbol must have the same GP as the source object file, and it must be declared to either not use
$27or perform a standard GP load in the first two instructions via the.prologuedirective.
-
!tlsgd -
!tlsgd!N -
Used with an
ldainstruction to load the address of a TLS descriptor for a symbol in the GOT.The sequence number N is optional, and if present it used to pair the descriptor load with both the
literalloading the address of the__tls_get_addrfunction and thelituse_tlsgdmarking the call to that function.For proper relaxation, both the
tlsgd,literalandlituserelocations must be in the same extended basic block. That is, the relocation with the lowest address must be executed first at runtime.
-
!tlsldm -
!tlsldm!N -
Used with an
ldainstruction to load the address of a TLS descriptor for the current module in the GOT.Similar in other respects to
tlsgd.
-
!gotdtprel - Used with an
ldqinstruction to load the offset of the TLS symbol within its module's thread-local storage block. Also known as the dynamic thread pointer offset or dtp-relative offset.
-
!dtprelhi -
!dtprello -
!dtprel - Like
gprelrelocations except they compute dtp-relative offsets.
-
!gottprel - Used with an
ldqinstruction to load the offset of the TLS symbol from the thread pointer. Also known as the tp-relative offset.
-
!tprelhi -
!tprello -
!tprel - Like
gprelrelocations except they compute tp-relative offsets.