aws / s2n-tls

An implementation of the TLS/SSL protocols
https://aws.github.io/s2n-tls/usage-guide/
Apache License 2.0
4.52k stars 705 forks source link

32bit Build -fPIC Compile Error #829

Open RandyGaul opened 6 years ago

RandyGaul commented 6 years ago

Problem:

Attempting to compile for 32bit using the flags from the usage guide for gcc4:

setarch i386 ./config -fPIC no-shared     \
        -m32 no-md2 no-rc5 no-rfc3779 no-sctp no-ssl-trace no-zlib     \
        no-hw no-mdc2 no-seed no-idea no-camellia\
        no-bf no-ripemd no-dsa no-ssl2 no-ssl3 no-capieng     \
        -DSSL_FORBID_ENULL -DOPENSSL_NO_DTLS1 -DOPENSSL_NO_HEARTBEATS   \
        --prefix=`pwd`/../../libcrypto-root/

And ran into a compile error in s2n_random.c:

s2n_random.c: In function 's2n_get_rdrand_data':
s2n_random.c:346:13: error: inconsistent operand constraints in an 'asm'
             __asm__ __volatile__(".byte 0x48;\n" ".byte 0x0f;\n" ".byte 0xc7;\n" ".byte 0xf0;\n" "adcl $0x00, %%ebx;\n":"=b"(success_low), "=a"(output.i386_fields.u_low)
             ^
s2n_random.c:350:13: error: inconsistent operand constraints in an 'asm'
             __asm__ __volatile__(".byte 0x48;\n" ".byte 0x0f;\n" ".byte 0xc7;\n" ".byte 0xf0;\n" "adcl $0x00, %%ebx;\n":"=b"(success_high), "=a"(output.i386_fields.u_high)

Proposed Solution:

No idea what the solution here would be. Should the setarch flags be changed to not include -fPIC? Found a seemingly relevant SO answer talking about the ebx register not being allowed for usage within inline asm if the -fPIC flag is set: https://stackoverflow.com/questions/22160093/inconsistent-operand-constraints-in-an-asm/28976166#28976166

Any ideas?

JonathanHenson commented 6 years ago

This isn't related to the openssl build at all. The problem is the way -fPIC uses the ebx register on GCC 4 (and that my 32-bit tests were done on a modern compiler). I'll look into a fix.

RandyGaul commented 6 years ago

As per henso's suggestion, probably going to just not build in gcc4 and do 5 instead as a workaround.

RandyGaul commented 6 years ago

Potential fix: https://github.com/awslabs/s2n/pull/830