dot-asm / cryptogams

CRYPTOGAMS distribution repository
Other
56 stars 16 forks source link

MinGW cross-compilation fails due to .size/.type directives #9

Closed dwmw2 closed 3 years ago

dwmw2 commented 3 years ago

Building for Win64, I get:

$ CC="x86_64-w64-mingw32-gcc" /usr/bin/perl ../aesni/aesni-x86_64.pl | sed s/OPENSSL_ia32/OPENCONNECT_ia32/g > aesni-x86_64.s
$ x86_64-w64-mingw32-gcc  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 -c -o aesni-x86_64.o aesni-x86_64.s
aesni-x86_64.s: Assembler messages:
aesni-x86_64.s:4: Warning: .type pseudo-op used outside of .def/.endef: ignored.
aesni-x86_64.s:4: Error: junk at end of line, first unrecognized character is `a'
aesni-x86_64.s:27: Warning: .size pseudo-op used outside of .def/.endef: ignored.
aesni-x86_64.s:27: Error: junk at end of line, first unrecognized character is `a'
…
dot-asm commented 3 years ago

You've got to "flavour" it, perl <script> mingw64. As for sed-ing, another possibility is to change suffix to .S, capital S, and use -D at compiler line.

dwmw2 commented 3 years ago

Thanks, that works. I'm dusting off the OpenConnect AES-NI support, at https://gitlab.com/openconnect/openconnect/-/commits/hacks2/

I have bigger problems with OPEN{SSL,CONNECT}_ia32cap_P anyway... now the Android build is failing because it wants PIC support:

/opt/android-sdk-linux_x86/toolchains/x86_64-linux-android-23/bin/../lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: .libs/aesni-sha1-x86_64.o: requires dynamic R_X86_64_PC32 reloc against 'OPENCONNECT_ia32cap_P' which may overflow at runtime; recompile with -fPIC
/opt/android-sdk-linux_x86/toolchains/x86_64-linux-android-23/bin/../lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: .libs/aesni-x86_64.o: requires dynamic R_X86_64_PC32 reloc against 'OPENCONNECT_ia32cap_P' which may overflow at runtime; recompile with -fPIC
/opt/android-sdk-linux_x86/toolchains/x86_64-linux-android-23/bin/../lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: .libs/sha1-x86_64.o: requires dynamic R_X86_64_PC32 reloc against 'OPENCONNECT_ia32cap_P' which may overflow at runtime; recompile with -fPIC
/opt/android-sdk-linux_x86/toolchains/x86_64-linux-android-23/bin/../lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: warning: shared library text segment is not shareable
dot-asm commented 3 years ago

recompile with -fPIC

I for one argue that it should be a warning, not error. But anyway. Declare the affected symbol hidden, for example with __attribute__((visibility("hidden"))), or use -Wl,-Bsymbolic flag when linking shared object. -Wl,-Bsymbolic is generally better for security, because other shared libraries won't override internal symbols in your shared library, unintentionally or not.

dwmw2 commented 3 years ago

Got it, thanks. In fact OpenSSL's x86_64cpuid.pl was doing precisely that, but I'd ripped it out along with a lot of other things from that file, and kept only the OPENSSL_ia32_cpuid() function. I put it back , and my Android CI builds are now passing again; thanks.

This is giving me a 40% update on ESP performance; I'd love to have the licence issue resolved (#7) so that I can merge it for real into my LGPLv2.1-licensed project :)