native-base: Fix the aarch64 qemu binaries in memory
On Ubuntu 18.04 just about everything is in place to allow qemu-user-static
interpreters to be used inside of other namespaces. Unfortunately, Ubuntu
18.04's qemu-user-static doesn't actually turn on the fix-binary flag for its
interpreters.
This patch force-enables the fix-binary flag for qemu-aarch64 so we can at least
create the native-base.tgz pbuilder environment. Once it's been built, we still
copy the interpreters into the environment so we don't have to force enable it
every single time we build.
Change-Id: I3ea9cb6f203f4a2989c7fcc3b51dbbff7af38ebe
diff --git a/Makefile b/Makefile
index f53324f..a20d113 100644
--- a/Makefile
+++ b/Makefile
@@ -13,11 +13,27 @@
# limitations under the License.
SHELL := $(shell which /bin/bash)
+HAVE_QEMU := $(shell [[ -f /var/lib/binfmts/qemu-aarch64 ]] && echo yes)
+HAVE_FIXATED_QEMU := $(shell [[ -f /var/lib/binfmts/qemu-aarch64 ]] && tail -n1 /var/lib/binfmts/qemu-aarch64)
ifeq ($(ROOTDIR),)
$(error $$ROOTDIR IS NOT DEFINED -- don\'t forget to source setup.sh)
endif
+ifeq ($(HAVE_QEMU),)
+$(error qemu-user-static is either not installed or not configured properly.)
+endif
+
+ifeq ($(HAVE_FIXATED_QEMU),)
+$(warning Your version of qemu-user-static is too old and does not support)
+$(warning fixated binaries. On Debian-based systems, you can run)
+$(warning `build/fix_aarch64_binfmts.sh` to update your system binfmts)
+$(warning to fixate the aarch64 interpreter in kernel space.)
+$(warning )
+$(warning NOTE: This will modify the global state of your system!)
+$(error Build cannot continue)
+endif
+
include $(ROOTDIR)/build/preamble.mk
precheck:
diff --git a/fix_aarch64_binfmts.sh b/fix_aarch64_binfmts.sh
new file mode 100755
index 0000000..8de6e2f
--- /dev/null
+++ b/fix_aarch64_binfmts.sh
@@ -0,0 +1,11 @@
+#!/bin/bash -xe
+
+sudo update-binfmts --package qemu-user-static --remove qemu-aarch64 /usr/bin/qemu-aarch64-static
+sudo update-binfmts \
+ --package qemu-user-static \
+ --install qemu-aarch64 /usr/bin/qemu-aarch64-static \
+ --magic '\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00' \
+ --mask '\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' \
+ --offset 0 \
+ --credential yes \
+ --fix-binary yes