From ef6d5a4d63829c5216948f9fbc80a45e5ef3e802 Mon Sep 17 00:00:00 2001 From: torben-hansen <50673096+torben-hansen@users.noreply.github.com> Date: Fri, 1 Mar 2024 18:03:39 +0100 Subject: [PATCH] Use x30 instead of lr which otherwise trip some versions of gcc (#1464) 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. --- util/fipstools/delocate/delocate.go | 6 ++-- .../delocate/testdata/aarch64-Basic/out.s | 30 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/util/fipstools/delocate/delocate.go b/util/fipstools/delocate/delocate.go index 635d4377d1..a1d9a57b26 100644 --- a/util/fipstools/delocate/delocate.go +++ b/util/fipstools/delocate/delocate.go @@ -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. @@ -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. diff --git a/util/fipstools/delocate/testdata/aarch64-Basic/out.s b/util/fipstools/delocate/testdata/aarch64-Basic/out.s index c947525e18..dafe5d2a9b 100644 --- a/util/fipstools/delocate/testdata/aarch64-Basic/out.s +++ b/util/fipstools/delocate/testdata/aarch64-Basic/out.s @@ -11,10 +11,10 @@ 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 @@ -22,9 +22,9 @@ foo: // 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 @@ -32,9 +32,9 @@ foo: // 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] @@ -58,10 +58,10 @@ 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] @@ -69,7 +69,7 @@ foo: // 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 @@ -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] @@ -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: