started getting stuff to compile for ARM

There were lots of places where the ARM compiler is pickier about
alignment and the externals stuff had to be reworked to use the cross
compiler for everything.

The main issues left are the lack of opencv and the x86 asm.
diff --git a/aos/atom_code/configuration.cc b/aos/atom_code/configuration.cc
index a5dd4ee..2d6dab8 100644
--- a/aos/atom_code/configuration.cc
+++ b/aos/atom_code/configuration.cc
@@ -35,7 +35,8 @@
     if (addrs->ifa_addr->sa_family == AF_INET) {
       if (strcmp(kAtomNetInterface, addrs->ifa_name) == 0) {
         static const in_addr r =
-            reinterpret_cast<sockaddr_in *>(addrs->ifa_addr)->sin_addr;
+            reinterpret_cast<sockaddr_in *>(__builtin_assume_aligned(
+                addrs->ifa_addr, alignof(sockaddr_in)))->sin_addr;
         return &r;
       }
     }
diff --git a/aos/atom_code/core/LogFileCommon.h b/aos/atom_code/core/LogFileCommon.h
index 3798b06..8c1bd7b 100644
--- a/aos/atom_code/core/LogFileCommon.h
+++ b/aos/atom_code/core/LogFileCommon.h
@@ -132,15 +132,18 @@
         sizeof(mutex) > kPageSize) {
       char *const temp = current_;
       MapNextPage();
-      if (futex_set_value(reinterpret_cast<mutex *>(&temp[position_]), 2) == -1) {
-        fprintf(stderr, "LogFileCommon: futex_set_value(%p, 2) failed with %d: %s."
-                " readers will hang\n", &temp[position_], errno, strerror(errno));
+      if (futex_set_value(static_cast<mutex *>(static_cast<void *>(
+                      &temp[position_])), 2) == -1) {
+        fprintf(stderr,
+                "LogFileCommon: futex_set_value(%p, 2) failed with %d: %s."
+                " readers will hang\n",
+                &temp[position_], errno, strerror(errno));
       }
       Unmap(temp);
       position_ = 0;
     }
-    LogFileMessageHeader *const r = reinterpret_cast<LogFileMessageHeader *>(
-        &current_[position_]);
+    LogFileMessageHeader *const r = static_cast<LogFileMessageHeader *>(
+        static_cast<void *>(&current_[position_]));
     position_ += message_size;
     // keep it aligned for next time
     position_ += kAlignment - (position_ % kAlignment);
@@ -150,7 +153,8 @@
   const LogFileMessageHeader *ReadNextMessage(bool wait) {
     LogFileMessageHeader *r;
     do {
-      r = reinterpret_cast<LogFileMessageHeader *>(&current_[position_]);
+      r = static_cast<LogFileMessageHeader *>(
+          static_cast<void *>(&current_[position_]));
       if (wait) {
         if (futex_wait(&r->marker) != 0) continue;
       }
@@ -158,7 +162,7 @@
         Unmap(current_);
         MapNextPage();
         position_ = 0;
-        r = reinterpret_cast<LogFileMessageHeader *>(current_);
+        r = static_cast<LogFileMessageHeader *>(static_cast<void *>(current_));
       }
     } while (wait && r->marker == 0);
     if (r->marker == 0) {
diff --git a/aos/atom_code/ipc_lib/queue.cc b/aos/atom_code/ipc_lib/queue.cc
index 7ab7b6c..018f03a 100644
--- a/aos/atom_code/ipc_lib/queue.cc
+++ b/aos/atom_code/ipc_lib/queue.cc
@@ -39,9 +39,9 @@
   int ref_count;
   int index;  // in pool_
   static MessageHeader *Get(const void *msg) {
-    return reinterpret_cast<MessageHeader *>(
-        static_cast<uint8_t *>(const_cast<void *>(msg)) -
-        sizeof(MessageHeader));
+    return reinterpret_cast<MessageHeader *>(__builtin_assume_aligned(
+        static_cast<uint8_t *>(const_cast<void *>(msg)) - sizeof(MessageHeader),
+        alignof(MessageHeader)));
   }
   void Swap(MessageHeader *other) {
     MessageHeader temp;
diff --git a/aos/build/aos.gypi b/aos/build/aos.gypi
index d8a4016..aad5331 100644
--- a/aos/build/aos.gypi
+++ b/aos/build/aos.gypi
@@ -30,6 +30,10 @@
           'aos_target': 'static_library',
         },
       }, {
+        'make_global_settings': [
+          ['CC', '<!(which arm-linux-gnueabi-gcc-4.7)'],
+          ['CXX', '<!(which arm-linux-gnueabi-g++-4.7)'],
+        ],
         'variables': {
           'aos_target': 'executable',
         },
@@ -90,8 +94,8 @@
               ],
             }, {
               'cflags': [
-                '-march=atom',
-                '-mfpmath=sse',
+                #'-march=atom',
+                #'-mfpmath=sse',
 
                 '-fstack-protector-all',
               ],
@@ -169,14 +173,14 @@
           ],
           'ldflags': [
             '-pthread',
-            '-m32',
+            #'-m32',
           ],
           'library_dirs': [
             '/usr/lib32',
           ],
           'cflags': [
             '-pthread',
-            '-m32',
+            #'-m32',
 
             '-Wunused-local-typedefs',
 
diff --git a/aos/build/download_externals.sh b/aos/build/download_externals.sh
index be77aa5..e1eaab0 100755
--- a/aos/build/download_externals.sh
+++ b/aos/build/download_externals.sh
@@ -4,6 +4,14 @@
 
 AOS=$(readlink -f $(dirname $0)/..)
 . $(dirname $0)/tools_config
+COMPILED=${EXTERNALS}/../compiled-arm
+
+export CC=arm-linux-gnueabi-gcc-4.7
+export CXX=arm-linux-gnueabi-g++-4.7
+# Flags that should get passed to all configure scripts.
+# TODO(brians): If we're going to build everything ourselves, we should probably
+# optimize it for our target.
+CONFIGURE_FLAGS="--host=arm-linux-gnueabi CC=${CC} CXX=${CXX}"
 
 TMPDIR=/tmp/$$-aos-tmpdir
 mkdir -p ${EXTERNALS}
@@ -48,7 +56,10 @@
 LIBJPEG_TAR=${EXTERNALS}/jpegsrc.v${LIBJPEG_VERSION}.tar.gz
 [ -f ${LIBJPEG_TAR} ] || wget http://www.ijg.org/files/jpegsrc.v${LIBJPEG_VERSION}.tar.gz -O ${LIBJPEG_TAR}
 [ -d ${LIBJPEG_DIR} ] || ( mkdir ${LIBJPEG_DIR} && tar --strip-components=1 -C ${LIBJPEG_DIR} -xf ${LIBJPEG_TAR} )
-[ -f ${LIBJPEG_LIB} ] || env -i PATH="${PATH}" bash -c "cd ${LIBJPEG_DIR} && CFLAGS='-m32' ./configure --disable-shared --prefix=`readlink -f ${LIBJPEG_PREFIX}` && make && make install"
+[ -f ${LIBJPEG_LIB} ] || bash -c \
+	"cd ${LIBJPEG_DIR} && ./configure --disable-shared \
+	${CONFIGURE_FLAGS} --prefix=`readlink -f ${LIBJPEG_PREFIX}` \
+	&& make && make install"
 
 # get gtest
 GTEST_VERSION=1.6.0
@@ -77,10 +88,10 @@
 	[ -d ${CTEMPLATE_DIR} ] || \
 		svn checkout ${CTEMPLATE_URL} -r ${CTEMPLATE_VERSION} ${CTEMPLATE_DIR}
 fi
-[ -f ${CTEMPLATE_LIB} ] || env -i PATH="${PATH}" \
-	CFLAGS='-m32' CXXFLAGS='-m32' LDFLAGS='-m32' \
-	bash -c "cd ${CTEMPLATE_DIR} && ./configure --disable-shared \
-	--prefix=`readlink -f ${CTEMPLATE_PREFIX}` && make && make install"
+[ -f ${CTEMPLATE_LIB} ] || bash -c "cd ${CTEMPLATE_DIR} && \
+	./configure --disable-shared \
+	${CONFIGURE_FLAGS} --prefix=`readlink -f ${CTEMPLATE_PREFIX}` \
+	&& make && make install"
 
 # get and build gflags
 GFLAGS_VERSION=2.0
@@ -92,10 +103,9 @@
 [ -f ${GFLAGS_TAR} ] || wget ${GFLAGS_URL} -O ${GFLAGS_TAR}
 [ -d ${GFLAGS_DIR} ] || ( mkdir ${GFLAGS_DIR} && tar \
   --strip-components=1 -C ${GFLAGS_DIR} -xf ${GFLAGS_TAR} )
-[ -f ${GFLAGS_LIB} ] || env -i PATH="${PATH}" \
-  CFLAGS='-m32' CXXFLAGS='-m32' LDFLAGS='-m32' \
-  bash -c "cd ${GFLAGS_DIR} && ./configure \
-  --prefix=`readlink -f ${GFLAGS_PREFIX}` && make && make install"
+[ -f ${GFLAGS_LIB} ] || bash -c "cd ${GFLAGS_DIR} && ./configure \
+  ${CONFIGURE_FLAGS} --prefix=`readlink -f ${GFLAGS_PREFIX}` \
+  && make && make install"
 
 # get and build libusb
 LIBUSB_VERSION=1.0.9
@@ -108,10 +118,9 @@
 [ -f ${LIBUSB_TAR} ] || wget ${LIBUSB_URL} -O ${LIBUSB_TAR}
 [ -d ${LIBUSB_DIR} ] || ( mkdir ${LIBUSB_DIR} && tar \
   --strip-components=1 -C ${LIBUSB_DIR} -xf ${LIBUSB_TAR} )
-[ -f ${LIBUSB_LIB} ] || env -i PATH="${PATH}" \
-  CFLAGS='-m32' CXXFLAGS='-m32' LDFLAGS='-m32' \
-  bash -c "cd ${LIBUSB_DIR} && ./configure \
-  --prefix=`readlink -f ${LIBUSB_PREFIX}` && make && make install"
+[ -f ${LIBUSB_LIB} ] || bash -c "cd ${LIBUSB_DIR} && ./configure \
+	${CONFIGURE_FLAGS} --prefix=`readlink -f ${LIBUSB_PREFIX}` \
+	&& make && make install"
 
 # get the LLVM Compiler-RT source
 COMPILER_RT_TAG=RELEASE_32/final
@@ -131,10 +140,23 @@
 [ -f ${LIBEVENT_TAR} ] || wget ${LIBEVENT_URL} -O ${LIBEVENT_TAR}
 [ -d ${LIBEVENT_DIR} ] || ( mkdir ${LIBEVENT_DIR} && tar \
   --strip-components=1 -C ${LIBEVENT_DIR} -xf ${LIBEVENT_TAR} )
-[ -f ${LIBEVENT_LIB} ] || env -i PATH="${PATH}" \
-  CFLAGS='-m32' CXXFLAGS='-m32' LDFLAGS='-m32' \
-  bash -c "cd ${LIBEVENT_DIR} && ./configure \
-  --prefix=`readlink -f ${LIBEVENT_PREFIX}` && make && make install"
+[ -f ${LIBEVENT_LIB} ] || bash -c "cd ${LIBEVENT_DIR} && ./configure \
+	${CONFIGURE_FLAGS} --prefix=`readlink -f ${LIBEVENT_PREFIX}` \
+	&& make && make install"
+
+# get and build gmp
+GMP_VERSION=5.1.3
+GMP_TAR=${EXTERNALS}/gmp-${GMP_VERSION}.tar.lz
+GMP_DIR=${COMPILED}/gmp-${GMP_VERSION}
+GMP_PREFIX=${GMP_DIR}-prefix
+GMP_LIB=${GMP_PREFIX}/lib/libgmp.a
+GMP_URL=http://ftp.gmplib.org/gmp/gmp-${GMP_VERSION}.tar.lz
+[ -f ${GMP_TAR} ] || wget ${GMP_URL} -O ${GMP_TAR}
+[ -d ${GMP_DIR} ] || ( mkdir ${GMP_DIR} && tar \
+	--strip-components=1 -C ${GMP_DIR} -xf ${GMP_TAR} )
+[ -f ${GMP_LIB} ] || bash -c "cd ${GMP_DIR} && ./configure \
+	${CONFIGURE_FLAGS} --prefix=$(readlink -f ${GMP_PREFIX}) \
+	&& make && make install"
 
 # get and build libcdd
 LIBCDD_VERSION=094g
@@ -147,9 +169,10 @@
         wget ${LIBCDD_URL} -O ${LIBCDD_TAR}
 [ -d ${LIBCDD_DIR} ] || ( mkdir ${LIBCDD_DIR} && tar \
         --strip-components=1 -C ${LIBCDD_DIR} -xf ${LIBCDD_TAR} )
-[ -f ${LIBCDD_LIB} ] || env -i PATH="${PATH}" \
-        CFLAGS='-m32' CXXFLAGS='-m32' LDFLAGS='-m32' \
-        bash -c "cd ${LIBCDD_DIR} && ./configure --disable-shared \
-        --prefix=`readlink -f ${LIBCDD_PREFIX}` && make && make install"
+[ -f ${LIBCDD_LIB} ] || LDFLAGS=-L${GMP_PREFIX}/lib \
+	bash -c "cd ${LIBCDD_DIR} && ./configure \
+	--disable-shared ${CONFIGURE_FLAGS} \
+	--prefix=$(readlink -f ${LIBCDD_PREFIX}) \
+	&& make gmpdir=${GMP_PREFIX} && make install"
 
 rm -rf ${TMPDIR}
diff --git a/aos/build/externals.gyp b/aos/build/externals.gyp
index 283e7ce..836ddde 100644
--- a/aos/build/externals.gyp
+++ b/aos/build/externals.gyp
@@ -4,8 +4,8 @@
   'variables': {
     'externals': '<(AOS)/../output/downloaded',
     'externals_abs': '<!(readlink -f ../../output/downloaded)',
-    'compiled': '<(externals)/../compiled-i386',
-    'compiled_abs': '<(externals_abs)/../compiled-i386',
+    'compiled': '<(externals)/../compiled-arm',
+    'compiled_abs': '<(externals_abs)/../compiled-arm',
 
 # These versions have to be kept in sync with the ones in download_externals.sh.
     'eigen_version': '3.1.3',
@@ -211,6 +211,9 @@
       },
       'direct_dependent_settings': {
         'include_dirs': ['<(compiled)/libusb-<(libusb_version)-prefix/include'],
+        'cflags': [
+          '-Wno-error=cast-align',
+        ],
       },
     },
     {
diff --git a/aos/build/tools_config b/aos/build/tools_config
index 653c1ef..d47a3ce 100644
--- a/aos/build/tools_config
+++ b/aos/build/tools_config
@@ -2,7 +2,6 @@
 # that download_externals.sh downloads so build.sh can use.
 
 EXTERNALS=${AOS}/../output/downloaded
-COMPILED=${EXTERNALS}/../compiled-i386
 
 NINJA_RELEASE=v1.4.0
 NINJA_DIR=${EXTERNALS}/ninja-${NINJA_RELEASE}
diff --git a/aos/common/logging/logging_impl.cc b/aos/common/logging/logging_impl.cc
index bced835..a76c28a 100644
--- a/aos/common/logging/logging_impl.cc
+++ b/aos/common/logging/logging_impl.cc
@@ -57,8 +57,8 @@
   const size_t size = output_size - strlen(continued);
   const int ret = vsnprintf(output, size, format, ap);
   if (ret < 0) {
-    LOG(FATAL, "vsnprintf(%p, %zd, %s, %p) failed with %d (%s)\n",
-        output, size, format, ap, errno, strerror(errno));
+    LOG(FATAL, "vsnprintf(%p, %zd, %s, args) failed with %d (%s)\n",
+        output, size, format, errno, strerror(errno));
   } else if (static_cast<uintmax_t>(ret) >= static_cast<uintmax_t>(size)) {
     // Overwrite the '\0' at the end of the existing data and
     // copy in the one on the end of continued.
diff --git a/output/downloaded/.gitignore b/output/downloaded/.gitignore
index c45531d..079a15e 100644
--- a/output/downloaded/.gitignore
+++ b/output/downloaded/.gitignore
@@ -23,3 +23,4 @@
 /libevent-2.0.21/
 /libcdd-094g.tar.gz
 /libcdd-094g/
+/gmp-5.1.3.tar.lz