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

ocb.c fails to build on Ubuntu 12.04 armel and armhf #86

Closed
kmcallister opened this issue Mar 27, 2012 · 0 comments
Closed

ocb.c fails to build on Ubuntu 12.04 armel and armhf #86

kmcallister opened this issue Mar 27, 2012 · 0 comments

Comments

@kmcallister
Copy link
Contributor

Mosh's file src/crypto/ocb.cc fails to build on Ubuntu 12.04 LTS (Precise Pangolin) for architectures armel and armhf (build logs: 1, 2). The problem is the same in both cases.

ARM processors support three different instruction sets:

  • The original ARM instruction set. All instructions are 32 bits. Any instruction can be conditional.
  • Thumb, a compact 16-bit encoding for a subset of ARM instructions. Only branches may be conditional. Thumb code has worse performance per instruction, and is expected to call ARM code for CPU-intensive tasks.
  • Thumb-2, which adds some 32-bit instructions to Thumb, and is considered a full replacement for ARM. Any instruction can be conditional, but a block of conditional instructions must be introduced by an instruction such as IT (if-then), ITE (if-then-else), etc.

Ted Krovetz's ocb.c contains inline ARM assembly with a conditional instruction eorcs (exclusive OR if carry set). It lacks an IT instruction and so can only be assembled in ARM mode. But GCC on Ubuntu 12.04 is compiled with --with-arch=armv7-a --with-mode=thumb, so it will emit Thumb-2 code by default.

Steps to reproduce:

$ wget http://www.cs.ucdavis.edu/~rogaway/ocb/{ocb-ref/rijndael-alg-fst.h,news/code/{ae.h,ocb.c}}
$ sed -i '/^#define USE_.*$/ d' ocb.c
$ gcc -DUSE_REFERENCE_AES=1 -c ocb.c
/tmp/ccLgYjJc.s: Assembler messages:
/tmp/ccLgYjJc.s:269: Error: thumb conditional instruction should be in IT block -- `eorcs r2,r2,#135'

Adding an IT instruction solves the problem:

--- ocb.c.orig  2011-07-14 12:54:08.000000000 -0400
+++ ocb.c       2012-03-27 02:53:09.000000000 -0400
@@ -294,6 +294,7 @@
                                 "adcs %H1,%H1,%H1\n\t"
                                 "adcs %0,%0,%0\n\t"
                                 "adcs %H0,%H0,%H0\n\t"
+                                "it cs\n\t"
                                 "eorcs %1,%1,#135"
                : "+r"(b.l), "+r"(b.r) : : "cc");
                return b;

This will build in ARM mode too, but presumably not on a sufficiently old as.

Besides this patch, we have a few other options:

  • Remove the inline assembly and use the C version of this function.
  • Override distribution preferences and build Mosh in ARM mode, using gcc -marm.
  • Build just ocb.cc in ARM mode. ARM-Thumb interworking is supposed to work, but there might be bugs down this road.
  • Pass -Wa,-mimplicit-it=thumb to GCC, telling the assembler to insert IT instructions as necessary. Ubuntu warns that it "is not implemented as of gcc-4.4 4.4.2-3ubuntu1, but [sic] it's probably best to avoid manually adding this flag to packages which encounter build problems".

I've confirmed that CXXFLAGS=-marm, CXXFLAGS=-Wa,-mimplicit-it=thumb, and the patch are each sufficient to build mosh-1.1 (using ./configure; make) on Ubuntu 12.04 armel. You can set up your own armel QEMUlated chroot on Debian using roughly:

$ sudo apt-get install ubuntu-dev-tools qemu-user-static
$ mk-sbuild --arch=armel precise
$ sudo schroot -c precise-armel-source
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

2 participants