polarssl/polarssl — pull request #100 by barrykn (2014-05-06 09:32:56+00:00)
Title: Two fixes for bn_mul PowerPC asm code on OS X

Two fixes:

1. I'm not sure if this is the fault of Apple's gcc, or Apple's assembler, or both, but when targeting PPC32 or PPC64 it's treating semicolons as comment delimiters even for inline assembly. (Incidentally, this only happens when targeting PPC, not Intel.) Without any \n's in the inline assembly macros, everything after the first instruction in MULADDC_INIT ends up being commented out. (This is a regression that was introduced in PolarSSL 1.3.4, in commit 02d800c15160b1e8dc26e405e41c1ae91d38dcd2, but I fixed the new code rather than reverting to the old code.)

2. The #if defined... checks for PPC32 vs PPC64 were incorrect. Specifically, for OS X __ppc64__ is only defined when targeting PPC64, and __ppc__ is *only defined when targeting PPC32*. Since the __ppc64__ check was nested inside the __ppc__ check, the PPC64 asm code was not being used at all on OS X.

On my PPC32 OS X systems, the test suite of vanilla PolarSSL 1.3.7 fails 6 tests and appears to enter infinite loops on 7 others (out of 52 total). With these changes applied, all 52 tests pass. I also tested a PPC32 Linux system to make sure these changes did not cause a regression there; with or without these changes, all 52 tests pass on that system. I currently don't have any PPC64 systems, but I cross-compiled to OS X PPC64 and used otool (the OS X equivalent to objdump) to check the output emitted by the toolchain for bignum.c.o, to check whether the first problem affected PPC64 as well as PPC32 -- and that's how I stumbled into the second problem.