Skip to content

Commit

Permalink
Use x30 instead of lr which otherwise trip some versions of gcc (#1464)
Browse files Browse the repository at this point in the history
Some versions of GCC not liking the link register
notation `lr` being used instead of `x30` where an integer register is
expected for the instruction.

To recover, use `x30` instead of `lr` in the delocator. Doesn't change
behaviour.
  • Loading branch information
torben-hansen authored Mar 1, 2024
1 parent 0ae80ed commit ef6d5a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions util/fipstools/delocate/delocate.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,13 @@ func (d *delocation) loadAarch64Address(statement *node32, targetReg string, sym
// Save x0 (which will be stomped by the return value) and the link register
// to the stack. Then save the program counter into the link register and
// jump to the helper function.
d.output.WriteString("\tstp x0, lr, [sp, #-16]!\n")
d.output.WriteString("\tstp x0, x30, [sp, #-16]!\n")
d.output.WriteString("\tbl " + helperFunc + "\n")

if targetReg == "x0" {
// If the target happens to be x0 then restore the link register from the
// stack and send the saved value of x0 to the zero register.
d.output.WriteString("\tldp xzr, lr, [sp], #16\n")
d.output.WriteString("\tldp xzr, x30, [sp], #16\n")
} else if targetReg == "x30" {
// If the target is x30, restore x0 only because the lr (just an alias
// name for x30) register is used as a general-purpose register.
Expand All @@ -492,7 +492,7 @@ func (d *delocation) loadAarch64Address(statement *node32, targetReg string, sym
} else {
// Otherwise move the result into place and restore registers.
d.output.WriteString("\tmov " + targetReg + ", x0\n")
d.output.WriteString("\tldp x0, lr, [sp], #16\n")
d.output.WriteString("\tldp x0, x30, [sp], #16\n")
}

// Revert the red-zone adjustment.
Expand Down
30 changes: 15 additions & 15 deletions util/fipstools/delocate/testdata/aarch64-Basic/out.s
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@ foo:
// GOT load
// WAS adrp x1, :got:stderr
sub sp, sp, 128
stp x0, lr, [sp, #-16]!
stp x0, x30, [sp, #-16]!
bl .Lboringssl_loadgot_stderr
mov x1, x0
ldp x0, lr, [sp], #16
ldp x0, x30, [sp], #16
add sp, sp, 128
// WAS ldr x0, [x1, :got_lo12:stderr]
mov x0, x1

// GOT load to x0
// WAS adrp x0, :got:stderr
sub sp, sp, 128
stp x0, lr, [sp, #-16]!
stp x0, x30, [sp, #-16]!
bl .Lboringssl_loadgot_stderr
ldp xzr, lr, [sp], #16
ldp xzr, x30, [sp], #16
add sp, sp, 128
// WAS ldr x1, [x0, :got_lo12:stderr]
mov x1, x0

// GOT load with no register move
// WAS adrp x0, :got:stderr
sub sp, sp, 128
stp x0, lr, [sp, #-16]!
stp x0, x30, [sp, #-16]!
bl .Lboringssl_loadgot_stderr
ldp xzr, lr, [sp], #16
ldp xzr, x30, [sp], #16
add sp, sp, 128
// WAS ldr x0, [x0, :got_lo12:stderr]

Expand All @@ -58,18 +58,18 @@ foo:
// armcap
// WAS adrp x1, OPENSSL_armcap_P
sub sp, sp, 128
stp x0, lr, [sp, #-16]!
stp x0, x30, [sp, #-16]!
bl .LOPENSSL_armcap_P_addr
mov x1, x0
ldp x0, lr, [sp], #16
ldp x0, x30, [sp], #16
add sp, sp, 128
// WAS ldr w2, [x1, :lo12:OPENSSL_armcap_P]
ldr w2, [x1]

// armcap to x30
// WAS adrp x30, OPENSSL_armcap_P
sub sp, sp, 128
stp x0, lr, [sp, #-16]!
stp x0, x30, [sp, #-16]!
bl .LOPENSSL_armcap_P_addr
mov x30, x0
ldp x0, xzr, [sp], #16
Expand All @@ -80,9 +80,9 @@ foo:
// armcap to w0
// WAS adrp x0, OPENSSL_armcap_P
sub sp, sp, 128
stp x0, lr, [sp, #-16]!
stp x0, x30, [sp, #-16]!
bl .LOPENSSL_armcap_P_addr
ldp xzr, lr, [sp], #16
ldp xzr, x30, [sp], #16
add sp, sp, 128
// WAS ldr w1, [x1, :lo12:OPENSSL_armcap_P]
ldr w1, [x1]
Expand Down Expand Up @@ -146,17 +146,17 @@ foo:
// Ensure BORINGSSL_bcm_text_[end,start] are loaded through GOT
// WAS adrp x4, :got:BORINGSSL_bcm_text_start
sub sp, sp, 128
stp x0, lr, [sp, #-16]!
stp x0, x30, [sp, #-16]!
bl .Lboringssl_loadgot_BORINGSSL_bcm_text_start
mov x4, x0
ldp x0, lr, [sp], #16
ldp x0, x30, [sp], #16
add sp, sp, 128
// WAS adrp x5, :got:BORINGSSL_bcm_text_end
sub sp, sp, 128
stp x0, lr, [sp, #-16]!
stp x0, x30, [sp, #-16]!
bl .Lboringssl_loadgot_BORINGSSL_bcm_text_end
mov x5, x0
ldp x0, lr, [sp], #16
ldp x0, x30, [sp], #16
add sp, sp, 128

.Llocal_function_local_target:
Expand Down

0 comments on commit ef6d5a4

Please sign in to comment.