Skip to content
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

Backport 2.28: bn_mul.h: fix x86 PIC inline ASM compilation with GCC < 5 #6096

Conversation

tom-cosgrove-arm
Copy link
Contributor

Backport of #1986

jacmet and others added 2 commits July 19, 2022 09:02
Fixes Mbed-TLS#1910

With ebx added to the MULADDC_STOP clobber list to fix Mbed-TLS#1550, the inline
assembly fails to build with GCC < 5 in PIC mode with the following error:

include/mbedtls/bn_mul.h:46:13: error: PIC register clobbered by ‘ebx’ in ‘asm’

This is because older GCC versions treated the x86 ebx register (which is
used for the GOT) as a fixed reserved register when building as PIC.

This is fixed by an improved register allocator in GCC 5+.  From the release
notes:

Register allocation improvements: Reuse of the PIC hard register, instead of
using a fixed register, was implemented on x86/x86-64 targets.  This
improves generated PIC code performance as more hard registers can be used.

https://www.gnu.org/software/gcc/gcc-5/changes.html

As a workaround, detect this situation and disable the inline assembly,
similar to the MULADDC_CANNOT_USE_R7 logic.

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
@tom-cosgrove-arm tom-cosgrove-arm marked this pull request as ready for review July 19, 2022 08:05
@tom-cosgrove-arm tom-cosgrove-arm added needs-review Every commit must be reviewed by at least two team members, needs-ci Needs to pass CI tests needs-reviewer This PR needs someone to pick it up for review bug component-crypto Crypto primitives and low-level interfaces labels Jul 19, 2022
@daverodgman daverodgman removed needs-ci Needs to pass CI tests needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review labels Jul 20, 2022
@daverodgman daverodgman added needs-review Every commit must be reviewed by at least two team members, priority-low Low priority - this may not receive review soon labels Jul 20, 2022
Copy link
Contributor

@mpg mpg left a comment

Choose a reason for hiding this comment

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

LGTM

@mpg mpg added approved Design and code approved - may be waiting for CI or backports and removed needs-review Every commit must be reviewed by at least two team members, labels Jul 21, 2022
@daverodgman daverodgman merged commit 5048045 into Mbed-TLS:mbedtls-2.28 Jul 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Design and code approved - may be waiting for CI or backports bug component-crypto Crypto primitives and low-level interfaces priority-low Low priority - this may not receive review soon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants