[SDKS] Build host runtime with correct bitness (#10742)
commit40d991c32574cb96824fd5918f40bd13310a7b6d
authormonojenkins <jo.shields+jenkins@xamarin.com>
Mon, 24 Sep 2018 17:52:54 +0000 (24 13:52 -0400)
committerLudovic Henry <luhenry@microsoft.com>
Mon, 24 Sep 2018 17:52:54 +0000 (24 13:52 -0400)
treeacd3408e377c1380856e817b3f4ca0f8729673a2
parent1a71d5101f24a7b9c5c04d9615699343ff3c356a
[SDKS] Build host runtime with correct bitness (#10742)

When building 32-bit binaries on a 64-bit system and vice versa, it is necessary
to pass the `-m32` or `-m64` compiler flags, respectively. Failure to do so will
result not only in linking problems (different binary architecture) but also in
problems when using some system headers which are sensitive to the architecture.
For instance, `ucontext.h` contains register set definitions for different
architectures and building Mono runtime with a 64-bit compiler targetting 32-bit
architecture results in this error:

   .../mono/mono/utils/mono-sigcontext.h:173:74: error: ‘REG_EIP’ undeclared (first use in this function); did you mean ‘REG_RIP’?
      #define UCONTEXT_REG_EIP(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [REG_EIP])

The issue here is that the compiler defines the `__x86_64__` macro which causes
`ucontext.h` to choose declarations for amd64 (which does not use `REG_EIP` but
has `REG_RIP` instead) while Mono runtime assumes its building for a 32-bit host
and uses 32-bit register names. Passing `-m32` to the compiler will fix the
issue as now the compiler will define the `__i386__` macro and all parties will
agree where they are and what they want.

This commit uses a rather baroque statement when constructing compiler flags to
build the Mono runtime to check whether the host triple targets 32 or 64-bit
host and adds the appropriate flag.
sdks/builds/runtime.mk