Skip to content

Add call frame information (CFI) annotations #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5b78cf7
Wrap most CFI-relevant instructions up as macros
jargh Mar 22, 2025
0a66845
Undo CFI macro transformations inside comments
jargh Mar 22, 2025
1ca8a84
Add CFI start directives for standard ABI forms in Windows subcalls
jargh Mar 23, 2025
89726d6
Merge branch 'awslabs:main' into cfi
jargh Mar 24, 2025
b0126a7
Add CFI start directives at internal/nested procedure entry points
jargh Mar 24, 2025
07dce91
Add CFI directives for non-push/pop save and restore
jargh Mar 24, 2025
e0deebf
Add actual cfi_startproc and cfi_endproc directives
jargh Mar 25, 2025
7da27e9
Incorporate actual relative CFA offsets into CFI macros
jargh Mar 25, 2025
4bc18f5
Add saved register offsets to the CFI macro definitions
jargh Mar 25, 2025
bb401ed
Add explicit private prefix L to all non-global labels
jargh Mar 26, 2025
597ff3a
Regenerate AT&T forms of CFI-enabled code
jargh Mar 26, 2025
11416fa
Add local prefix to a rogue label that was missing it
jargh Mar 26, 2025
85bc16c
Update local header file name in the ARM unopt code as well
jargh Mar 26, 2025
87b4e76
Add a function type directive for each toplevel function
jargh Mar 27, 2025
08f8ce5
Add a function type directive for internally called functions
jargh Mar 27, 2025
87df1a1
Merge branch 'awslabs:main' into cfi
jargh Mar 31, 2025
3d48f62
Merge branch 'awslabs:main' into cfi
jargh Apr 2, 2025
418d53b
Merge branch 'awslabs:main' into cfi
jargh Apr 3, 2025
df81139
Merge branch 'awslabs:main' into cfi
jargh Apr 8, 2025
8abbd61
Merge remote-tracking branch 'awslabs/main' into cfi
jargh Apr 13, 2025
707c5d4
Merge branch 'awslabs:main' into cfi
jargh Apr 14, 2025
2c038d9
Merge branch 'awslabs:main' into cfi
jargh Apr 16, 2025
c357785
Merge branch 'awslabs:main' into cfi
jargh May 2, 2025
956e288
Merge remote-tracking branch 'awslabs/main' into cfi
jargh May 20, 2025
5715ba9
Adopt refinement to _CET_ENDBR definition in bifurcated include files
jargh May 20, 2025
f5ddda4
Merge branch 'awslabs:main' into cfi
jargh May 22, 2025
742a142
Merge branch 'awslabs:main' into cfi
jargh May 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 5 additions & 2 deletions arm/curve25519/bignum_add_p25519.S
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
//
// Standard ARM ABI: X0 = z, X1 = x, X2 = y
// ----------------------------------------------------------------------------
#include "_internal_s2n_bignum.h"

#include "_internal_s2n_bignum_arm.h"

S2N_BN_SYM_VISIBILITY_DIRECTIVE(bignum_add_p25519)
S2N_BN_FUNCTION_TYPE_DIRECTIVE(bignum_add_p25519)
S2N_BN_SYM_PRIVACY_DIRECTIVE(bignum_add_p25519)

.text
Expand All @@ -31,6 +33,7 @@
#define c3 x10

S2N_BN_SYMBOL(bignum_add_p25519):
CFI_START

// Add as [d3; d2; d1; d0] = x + y; since we assume x, y < 2^255 - 19
// this sum fits in 256 bits
Expand Down Expand Up @@ -67,7 +70,7 @@ S2N_BN_SYMBOL(bignum_add_p25519):
stp d0, d1, [z]
stp d2, d3, [z, #16]

ret
CFI_RET

#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits
Expand Down
8 changes: 6 additions & 2 deletions arm/curve25519/bignum_cmul_p25519.S
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
//
// Standard ARM ABI: X0 = z, X1 = c, X2 = x
// ----------------------------------------------------------------------------
#include "_internal_s2n_bignum.h"

#include "_internal_s2n_bignum_arm.h"

S2N_BN_SYM_VISIBILITY_DIRECTIVE(bignum_cmul_p25519)
S2N_BN_FUNCTION_TYPE_DIRECTIVE(bignum_cmul_p25519)
S2N_BN_SYM_PRIVACY_DIRECTIVE(bignum_cmul_p25519)
S2N_BN_SYM_VISIBILITY_DIRECTIVE(bignum_cmul_p25519_alt)
S2N_BN_FUNCTION_TYPE_DIRECTIVE(bignum_cmul_p25519_alt)
S2N_BN_SYM_PRIVACY_DIRECTIVE(bignum_cmul_p25519_alt)
.text
.balign 4
Expand Down Expand Up @@ -44,6 +47,7 @@

S2N_BN_SYMBOL(bignum_cmul_p25519):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit confused here. Is the idea that bignum_cmul_p25519 and bignum_cmul_p25519_alt are the same function, i.e. one is an alias for the other? I wonder if this pattern is allowed by all ABIs and/or if it might be the source of some of the issues here. In OpenSSL when they have such aliases, the alias is implemented as a whole separate function that jmps to the function it is aliasing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were initially trying to support a uniform naming scheme for both ARM and x86. The bifurcation into "alt" and "non-alt" arises when for at least one architecture there is value in different variants with different microarchitectural targets. Cases like this where the same function has both names reflect those where on the other architecture (only) there is value in two versions, but on this architecture it didn't seem worth it. Currently, consumers like AWS-LC handle the dispatch according to uarch. Now, we no longer quite maintain the uniformity of this naming scheme since there are a few extra functions for ARM, so perhaps we should revisit this.

S2N_BN_SYMBOL(bignum_cmul_p25519_alt):
CFI_START

// First do the multiply, straightforwardly to get [d4;d3;d2;d1;d0]

Expand Down Expand Up @@ -92,7 +96,7 @@ S2N_BN_SYMBOL(bignum_cmul_p25519_alt):
stp d0, d1, [z]
stp d2, d3, [z, #16]

ret
CFI_RET

#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits
Expand Down
7 changes: 5 additions & 2 deletions arm/curve25519/bignum_double_p25519.S
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
//
// Standard ARM ABI: X0 = z, X1 = x
// ----------------------------------------------------------------------------
#include "_internal_s2n_bignum.h"

#include "_internal_s2n_bignum_arm.h"

S2N_BN_SYM_VISIBILITY_DIRECTIVE(bignum_double_p25519)
S2N_BN_FUNCTION_TYPE_DIRECTIVE(bignum_double_p25519)
S2N_BN_SYM_PRIVACY_DIRECTIVE(bignum_double_p25519)

.text
Expand All @@ -30,6 +32,7 @@
#define c3 x9

S2N_BN_SYMBOL(bignum_double_p25519):
CFI_START

// Double by adding as [d3; d2; d1; d0] = 2 * x; since we assume
// x < 2^255 - 19 this result fits in 256 bits
Expand Down Expand Up @@ -64,7 +67,7 @@ S2N_BN_SYMBOL(bignum_double_p25519):
stp d0, d1, [z]
stp d2, d3, [z, #16]

ret
CFI_RET

#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits
Expand Down
29 changes: 16 additions & 13 deletions arm/curve25519/bignum_inv_p25519.S
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
//
// Standard ARM ABI: X0 = z, X1 = x
// ----------------------------------------------------------------------------
#include "_internal_s2n_bignum.h"

#include "_internal_s2n_bignum_arm.h"

S2N_BN_SYM_VISIBILITY_DIRECTIVE(bignum_inv_p25519)
S2N_BN_FUNCTION_TYPE_DIRECTIVE(bignum_inv_p25519)
S2N_BN_SYM_PRIVACY_DIRECTIVE(bignum_inv_p25519)

.text
Expand Down Expand Up @@ -70,7 +72,7 @@

// Total size to reserve on the stack

#define NSPACE #(16*N)
#define NSPACE (16*N)

// Very similar to a subroutine call to the s2n-bignum word_divstep59.
// But different in register usage and returning the final matrix in
Expand Down Expand Up @@ -695,12 +697,13 @@
movk nn, n3, lsl #48

S2N_BN_SYMBOL(bignum_inv_p25519):
CFI_START

// Save registers and make room for temporaries

stp x19, x20, [sp, -16]!
stp x21, x22, [sp, -16]!
sub sp, sp, NSPACE
CFI_PUSH2(x19,x20)
CFI_PUSH2(x21,x22)
CFI_DEC_SP(NSPACE)

// Save the return pointer for the end so we can overwrite x0 later

Expand Down Expand Up @@ -755,9 +758,9 @@ S2N_BN_SYMBOL(bignum_inv_p25519):

mov i, #10
mov d, #1
b bignum_inv_p25519_midloop
b Lbignum_inv_p25519_midloop

bignum_inv_p25519_loop:
Lbignum_inv_p25519_loop:

// Separate the matrix elements into sign-magnitude pairs

Expand Down Expand Up @@ -1086,7 +1089,7 @@ bignum_inv_p25519_loop:
stp x0, x1, [v]
stp x3, x2, [v+16]

bignum_inv_p25519_midloop:
Lbignum_inv_p25519_midloop:

mov x1, d
ldr x2, [f]
Expand All @@ -1097,7 +1100,7 @@ bignum_inv_p25519_midloop:
// Next iteration

subs i, i, #1
bne bignum_inv_p25519_loop
bne Lbignum_inv_p25519_loop

// The 10th and last iteration does not need anything except the
// u value and the sign of f; the latter can be obtained from the
Expand Down Expand Up @@ -1245,10 +1248,10 @@ bignum_inv_p25519_midloop:

// Restore stack and registers

add sp, sp, NSPACE
ldp x21, x22, [sp], 16
ldp x19, x20, [sp], 16
ret
CFI_INC_SP(NSPACE)
CFI_POP2(x21,x22)
CFI_POP2(x19,x20)
CFI_RET

#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack, "", %progbits
Expand Down
40 changes: 24 additions & 16 deletions arm/curve25519/bignum_invsqrt_p25519.S
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@
//
// Standard ARM ABI: X0 = z, X1 = x
// ----------------------------------------------------------------------------
#include "_internal_s2n_bignum.h"

#include "_internal_s2n_bignum_arm.h"

S2N_BN_SYM_VISIBILITY_DIRECTIVE(bignum_invsqrt_p25519)
S2N_BN_FUNCTION_TYPE_DIRECTIVE(bignum_invsqrt_p25519)
S2N_BN_SYM_PRIVACY_DIRECTIVE(bignum_invsqrt_p25519)

S2N_BN_FUNCTION_TYPE_DIRECTIVE(Lbignum_invsqrt_p25519_mul_p25519)
S2N_BN_FUNCTION_TYPE_DIRECTIVE(Lbignum_invsqrt_p25519_nsqr_p25519)

.text
.balign 4

Expand All @@ -45,7 +50,7 @@

// Total size to reserve on the stack

#define NSPACE #(16*N)
#define NSPACE (16*N)

// Loading large constants

Expand All @@ -61,20 +66,21 @@
add x0, dest __LF \
add x1, src1 __LF \
add x2, src2 __LF \
bl bignum_invsqrt_p25519_mul_p25519
CFI_BL(Lbignum_invsqrt_p25519_mul_p25519)

#define nsqr(dest,n,src) \
add x0, dest __LF \
mov x1, n __LF \
add x2, src __LF \
bl bignum_invsqrt_p25519_nsqr_p25519
CFI_BL(Lbignum_invsqrt_p25519_nsqr_p25519)

S2N_BN_SYMBOL(bignum_invsqrt_p25519):
CFI_START

// Save registers and make room for temporaries

stp x19, x30, [sp, -16]!
sub sp, sp, NSPACE
CFI_PUSH2(x19,x30)
CFI_DEC_SP(NSPACE)

// Save the return pointer for the end so we can overwrite x0 later

Expand Down Expand Up @@ -215,7 +221,7 @@ S2N_BN_SYMBOL(bignum_invsqrt_p25519):

add x0, b
mov x1, #1
bl bignum_invsqrt_p25519_nsqr_p25519
CFI_BL(Lbignum_invsqrt_p25519_nsqr_p25519)
mulp(b,a,b)

ldp x10, x11, [b]
Expand All @@ -236,15 +242,16 @@ S2N_BN_SYMBOL(bignum_invsqrt_p25519):

// Restore stack and registers

add sp, sp, NSPACE
ldp x19, x30, [sp], 16
ret
CFI_INC_SP(NSPACE)
CFI_POP2(x19,x30)
CFI_RET

// *************************************************************
// Local z = x * y
// *************************************************************

bignum_invsqrt_p25519_mul_p25519:
Lbignum_invsqrt_p25519_mul_p25519:
CFI_START
ldp x3, x4, [x1]
ldp x5, x6, [x2]
umull x7, w3, w5
Expand Down Expand Up @@ -425,13 +432,14 @@ bignum_invsqrt_p25519_mul_p25519:
and x10, x10, #0x7fffffffffffffff
stp x7, x8, [x0]
stp x9, x10, [x0, #16]
ret
CFI_RET

// *************************************************************
// Local z = 2^n * x
// *************************************************************

bignum_invsqrt_p25519_nsqr_p25519:
Lbignum_invsqrt_p25519_nsqr_p25519:
CFI_START

// Copy input argument into [x13;x12;x11;x10]

Expand All @@ -441,7 +449,7 @@ bignum_invsqrt_p25519_nsqr_p25519:
// Main squaring loop, accumulating in [x13;x12;x11;x10] consistently and
// only ensuring the intermediates are < 2 * p_25519 = 2^256 - 38

bignum_invsqrt_p25519_loop:
Lbignum_invsqrt_p25519_loop:
umull x2, w10, w10
lsr x14, x10, #32
umull x3, w14, w14
Expand Down Expand Up @@ -572,7 +580,7 @@ bignum_invsqrt_p25519_loop:
// Loop as applicable

subs x1, x1, #1
bne bignum_invsqrt_p25519_loop
bne Lbignum_invsqrt_p25519_loop

// We know the intermediate result x < 2^256 - 38, and now we do strict
// modular reduction mod 2^255 - 19. Note x < 2^255 - 19 <=> x + 19 < 2^255
Expand All @@ -593,7 +601,7 @@ bignum_invsqrt_p25519_loop:

stp x10, x11, [x0]
stp x12, x13, [x0, #16]
ret
CFI_RET

#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack, "", %progbits
Expand Down
Loading