From: Mark Wooding Date: Sun, 11 Oct 2020 23:18:15 +0000 (+0100) Subject: base/regdump-arm64.S, base/regdump.h: Save NZCV and x8--x15 early. X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/commitdiff_plain/818bad9b1b5e68bdd26595a0ec5f513fe56ba174 base/regdump-arm64.S, base/regdump.h: Save NZCV and x8--x15 early. Alas, the processor flags /and/ at least x14 and x15 are clobbered by the PLT on-demand linkage machinery, so we must save them in the macro before calling out to the library. To be safe, preserve all of the non-argument call-clobbered registers. --- diff --git a/base/regdump-arm64.S b/base/regdump-arm64.S index 81c9f8e7..183d38f0 100644 --- a/base/regdump-arm64.S +++ b/base/regdump-arm64.S @@ -56,10 +56,6 @@ FUNC(regdump_gpsave) stp x2, x3, [sp, #16] stp x4, x5, [sp, #32] stp x6, x7, [sp, #48] - stp x8, x9, [sp, #64] - stp x10, x11, [sp, #80] - stp x12, x13, [sp, #96] - stp x14, x15, [sp, #112] stp x18, x19, [sp, #144] stp x20, x21, [sp, #160] stp x22, x23, [sp, #176] @@ -73,10 +69,6 @@ FUNC(regdump_gpsave) add x0, x20, #REGDUMP_GPSIZE str x0, [x20, #31*8] - // Capture the status flags. - mrs x0, nzcv - str x0, [x20, #8*REGIX_NZCV] - // Set the return address as our PC. str x30, [x20, #8*REGIX_PC] diff --git a/base/regdump.h b/base/regdump.h index a07072df..3a6d59cb 100644 --- a/base/regdump.h +++ b/base/regdump.h @@ -774,8 +774,15 @@ DO32(REGDEF_FP) // Make space for the register save area. sub sp, sp, #REGDUMP_GPSIZE - // Save flags and general-purpose registers. - stp x16, x17, [sp, #8*16] + // Save flags and general-purpose registers. The PLT linkage code + // makes free with x8--x17, so we must save those here. + mrs x30, nzcv + str x30, [sp, #8*REGIX_NZCV] + stp x8, x9, [sp, #64] + stp x10, x11, [sp, #80] + stp x12, x13, [sp, #96] + stp x14, x15, [sp, #112] + stp x16, x17, [sp, #128] bl regdump_gpsave // Make space for the extended registers.