-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
MPI inline assembly doesn't compile for PIC on i386 with older gcc #1910
Comments
ARM Internal Ref: IOTSSL-2461 |
We encountered this bug and worked around this problem by modifying
To this:
Note that This solution for us was preferable to the other options (using a newer compiler, dropping support for x86, not using position independent code, disabling ASM throughout mbedTLS, etc.) |
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: 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>
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: SSE4 <tomskside@gmail.com>
we need #1986 merged please |
@mckaygerhard Can you please make a rebased version of it for the three supported branches ( |
i can help with that.. for the weekend if you guys wait for me! thanks to accept the proposal |
I forgot about this, I was too busy, this patch must be apply .. yet many devices still use gcc 4.X for example embedded... this patch should still be supported because linux kernels like 4.X are still in use... for devices that can't use 5.X as an example, i cannot rebase, cos i used older devices (have a lot of those with large life and i will not change cos represent a cost) i will try again for, next weekend if there's no response |
Note that the supported branches are now |
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>
Fixes #1910 With ebx added to the MULADDC_STOP clobber list to fix #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>
Note: This is just a template, so feel free to use/remove the unnecessary things
Description
Bug
mbed TLS build:
Version: mbedtls-2.12.0
With older versions of gcc, Mbed TLS is unable to compile in very specific circumstances:-
-O1
or-O2
)-fPIC
and-shared
)The problem is that the inline assembly for i386 specifies a lot of registers to clobber, and older versions of gcc can't compile with so few registers.
To reproduce the fault:-
This will result in the following error:
Workarounds
There’s a couple of ways around this:
the easiest option is probably going to be to update the compiler. The code will work with gcc 7 and gcc 6 with no issue. There's also no issue with clang, so swapping to clang may fix this.
you can specify to turn off inline assembly. This can be done by commenting out the line
’#define MBEDTLS_HAVE_ASM
in the Mbed TLS configuration file, found ininclude/mbedlts/config.h
. That slows down some of the asymmetric crypto operations slower, but at least it builds.The text was updated successfully, but these errors were encountered: