-
Notifications
You must be signed in to change notification settings - Fork 122
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
Wrap pointers to s2n-bignum functions - delocator fix #2165
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between defining this wrapper function and how s2n-bignum defines bignum_add_p384? Is my mental model of C functions are equivalent to functions defined in the assembly files wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a valid question. This change stemmed from the observation that those 3 functions that were wrapped, when they were being assigned to the
p521_methods
struct in crypto/fipsmodule/ec/p521.c#L292-L296, they were creating the following (commented) assembly instructions that were replaced by delocate.go by the ones right underneath in<build-folder>/crypto/fipsmodule/bcm-delocated.S
.In the case of gcc compilations (not all versions, it depends which ones get lucky), the target address of the
adr
instructions was further than the admissible 1MB.The observation that other s2n-bignum functions assigned to the same method such as
bignum_sqr_p521_alt
was accessed viabignum_sqr_p521_selector
which is defined in the header fileaws-lc/third_party/s2n-bignum/include/s2n-bignum_aws-lc.h
Line 165 in 51ae4b1
bcm-delocated.S
:and not too far from it
the
b
(branch) instructions on the last line doesn’t suffer from the same range limit as theadr
instruction;b
has a range of of +/- 32MB, whileadr
has a range of +/- 1MB.That's why I thought that wrapping the s2n-bignum function which may be far with a "nearby" static function may result in the same pattern as with
bignum_sqr_p521_selector
Before this PR, i.e. adding the wrappers, the initialiser of
p521_methods
was compiled to get the address of, e.g.,bignum_add_p521
from an unknown location and assign it to a register, butdelocator.go
found that label within the module and considered it local, but was unluckily too far to be treated like other local labels.Adding a wrapper function caused the address of a "closer" function to be put in the address and a branch instruction to that target, which the delocator treated still as local but didn't need to change the
b
instruction because it doesn't cause relocation likeadrp
does.