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

gcc : ‘asm’ operand has impossible constraints, on 32bit intel #4245

Closed
vaintroub opened this issue Jul 26, 2021 · 10 comments
Closed

gcc : ‘asm’ operand has impossible constraints, on 32bit intel #4245

vaintroub opened this issue Jul 26, 2021 · 10 comments
Assignees

Comments

@vaintroub
Copy link
Contributor

vaintroub commented Jul 26, 2021

Tring to use TFM library (-DUSE_FAST_MATH) on 32bit intel results into

In file included from wolfssl/wolfssl/wolfcrypt/src/tfm.c:51:
wolfssl/wolfssl/wolfcrypt/src/tfm.c: In function ‘fp_sqr_comba’:
wolfssl/wolfcrypt/src/asm.c:709:1: error: ‘asm’ operand has impossible constraints
asm(
^~~~~~~
wolfssl/wolfssl/wolfcrypt/src/tfm.c:3148:11: note: in expansion of macro ‘SQRADD2’
SQRADD2(*tmpx++, *tmpy--);
^~~~~~~
wolfssl/wolfssl/wolfcrypt/src/asm.c:700:1: error: ‘asm’ operand has impossible constraints
asm(
^~~~~~~
/home/wlad/10.4/extra/wolfssl/wolfssl/wolfcrypt/src/tfm.c:3154:11: note: in expansion of macro ‘SQRADD’
SQRADD(A->dp[ix>>1], A->dp[ix>>1]);

Relevant compile line

cd /home/wlad/10.4/xxx/extra/wolfssl && /usr/bin/cc -DBUILDING_WOLFSSL -DDBUG_TRACE -DHAVE_CONFIG_H -DWOLFSSL_LIB -D_FILE_OFFSET_BITS=64 -I/home/wlad/10.4/extra/wolfssl/wolfssl -I/home/wlad/10.4/wsrep-lib/include -I/home/wlad/10.4/wsrep-lib/wsrep-API/v26 -I/home/wlad/10.4/xxx/include -I/home/wlad/10.4/xxx/extra/wolfssl -I/home/wlad/10.4/extra/wolfssl/wolfssl/wolfssl  -m32 -pie -fPIC -fstack-protector --param=ssp-buffer-size=4 -g1 -DENABLED_DEBUG_SYNC  -DSAFE_MUTEX -DSAFEMALLOC -DTRASH_FREED_MEMORY   -DHAVE_OPENSSL -DHAVE_WOLFSSL  -DWOLFSSL_USER_SETTINGS -fPIC -o CMakeFiles/wolfcrypt.dir/wolfssl/wolfcrypt/src/tfm.c.o   -c /home/wlad/10.4/extra/wolfssl/wolfssl/wolfcrypt/src/tfm.c

user_settings.h

#ifndef WOLFSSL_USER_SETTINGS_H
#define WOLFSSL_USER_SETTINGS_H

#define HAVE_CRL
#define WOLFSSL_MYSQL_COMPATIBLE
#define HAVE_ECC
#define ECC_TIMING_RESISTANT
#define HAVE_HASHDRBG
#define WOLFSSL_AES_DIRECT
#define WOLFSSL_SHA384
#define WOLFSSL_SHA512
#define WOLFSSL_SHA224
#define SESSION_CERT
#define KEEP_OUR_CERT
#define WOLFSSL_STATIC_RSA
#define WOLFSSL_USER_IO
#define WC_RSA_BLINDING
#define HAVE_TLS_EXTENSIONS
#define HAVE_AES_ECB
#define HAVE_AESGCM
#define WOLFSSL_AES_COUNTER
#define NO_WOLFSSL_STUB
#define OPENSSL_ALL
#define WOLFSSL_ALLOW_TLSV10
#define NO_OLD_TIMEVAL_NAME

/* TLSv1.3 definitions (all needed to build) */
#define WOLFSSL_TLS13
#define HAVE_HKDF
#define HAVE_TLS_EXTENSIONS
#define HAVE_SUPPORTED_CURVES
#define HAVE_FFDHE_2048
#define WC_RSA_PSS
/* End of TLSv1.3 defines */

/*
  FP_MAX_BITS is set high solely to satisfy ssl_8k_key.test
  WolfSSL will use more stack space with it, with fastmath
*/
#define FP_MAX_BITS 16384

/* #undef WOLFSSL_AESNI */
#define USE_FAST_MATH
#define TFM_TIMING_RESISTANT
/* #undef HAVE_INTEL_RDSEED */
/* #undef HAVE_INTEL_RDRAND */
/* #undef USE_INTEL_SPEEDUP */
#define USE_FAST_MATH
/* #undef WOLFSSL_X86_64_BUILD */

#endif  /* WOLFSSL_USER_SETTINGS_H */

@kareem-wolfssl
Copy link
Contributor

Hi @vaintroub ,

Thank you for reaching out to us. I will work on reproducing your issue here.

Thanks,
Kareem

@kareem-wolfssl kareem-wolfssl self-assigned this Jul 26, 2021
@elms elms assigned elms and unassigned kareem-wolfssl Jul 26, 2021
@elms
Copy link

elms commented Jul 26, 2021

Hi @vaintroub,

Thanks for the report. I have reproduced and believe I know a solution. I was able to compile by adding -O2. The exact command I used to test was cmake .. -DWOLFSSL_USER_SETTINGS=yes -DCMAKE_C_FLAGS="-m32 -I$PWD -O2" && make.

I'll work on putting a PR up. If you are able, can you confirm that adding -O2 solves the issue?

@vaintroub
Copy link
Contributor Author

vaintroub commented Jul 27, 2021

That does not solve it in all circumstances. We use sometimes -fno-omit-frame-pointer, also with optimized build.
I assume you need to add -fomit-frame-pointers, to free a register . Not only that, on downlevel compilers, such as GCC 4.8.5, that we are also using, you'd need to add -fno-PIC, to free yet another register - we compile everything with -fPIC. However -fno-PIC fortunately works on Intel 32bit.

Here is an example where -fomit-frame-pointer -fPIC fails :
https://buildbot.askmonty.org/buildbot/builders/kvm-bintar-centos6-x86/builds/5541/steps/compile/logs/stdio
(look for tfm.c.o on how it is compiled, and for error: on how it fails)

Here is an example where -fomit-frame-pointer -fno-PIC succeeds (same machine)
https://buildbot.askmonty.org/buildbot/builders/kvm-bintar-centos6-x86/builds/5549/steps/compile/logs/stdio

@elms
Copy link

elms commented Jul 29, 2021

@vaintroub Do I understand correctly that you have a workaround for now?

The only solution that I know of that would avoid this completely is using WOLFSSL_NO_ASM. I'll discuss other options with the team.

Out of curiosity have you considered WOLFSSL_SP_MATH?

@stintel
Copy link

stintel commented Aug 18, 2021

We're also seeing this in OpenWrt after switching the default GCC version from 8 to 10.

@SparkiDev
Copy link
Contributor

Hi @vaintroub,

Please try pull request #4317

I've made a small change to make the assembly code snippets work.

Thanks.

@stintel
Copy link

stintel commented Aug 20, 2021

Please try pull request #4317

This seems to fix the problem for 32bit x86 in OpenWrt, thanks!

@vaintroub
Copy link
Contributor Author

Unfortunately, it is a not easy to test for me at the moment, but once it is in, but I'm happy to hear about the progress,
Once it is in main tree, I will try to remove workarounds and see what it says.
But if it works for you with -fno-omit-frame-pointer -fPIC, and/or with Debug compilation, it should be fine here too.

@SparkiDev
Copy link
Contributor

Hi @vaintroub

The pull request has been merged to master.

Let me know when you have a chance to test it.

Thanks,
Sean :-)

@elms
Copy link

elms commented May 16, 2022

@vaintroub Haven't heard back for a while and worked for others, so I'm marking it closed. Please open a new bug if you have any issues.

@elms elms closed this as completed May 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants