Skip to content

Compiling Latest QEMU on AARCH64 machine

AshwinKrishn edited this page Oct 1, 2021 · 3 revisions

Overview

This is a write on compiling and using latest qemu on aarch64 systems natively. We have tested for qemu 6.0.0 with glibc 2.48.

Prerequisites

sudo apt-get install git libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev

If you want to virtualize any other component, install appropriate libraries.

Glibc installation

QEMU requires latest glibc. Changing the default glibc can be disastrous to the userspace and can result in bricked system. To avoid this, install glib latest version using the following steps into a different directory.

mkdir ~/glibc_install; cd ~/glibc_install 
wget "http://ftp.gnome.org/pub/gnome/sources/glib/2.48/glib-2.48.2.tar.xz"
tar xf glib-2.48.2.tar.xz 
cd glibc-2.48 
mkdir build 
cd build 
../configure --prefix=/opt/glibc-2.48 
make -j32
sudo make install 
export LD_LIBRARY_PATH=/opt/glibc-2.48/lib

Either do export LD_LIBRARY_PATH every time or store it into the .bashrc to update during startup.

 echo "export LD_LIBRARY_PATH=/opt/glibc-2.48/lib" >> ~/.bashrc 

Download and setup the QEMU repository

git clone https://github.com/qemu/qemu.git
cd qemu/
git checkout v6.0.0

You will need to perform this change in the configure file.

vim configure 

Change these lines as per the following git diff:

diff --git a/configure b/configure
index 4f374b4..ce303c5 100755
--- a/configure
+++ b/configure
@@ -3331,7 +3331,7 @@ if ! test "$gio" = "no"; then
         gio_cflags=$($pkg_config --cflags gio-2.0)
         gio_libs=$($pkg_config --libs gio-2.0)
         gdbus_codegen=$($pkg_config --variable=gdbus_codegen gio-2.0)
-        if [ ! -x "$gdbus_codegen" ]; then
+        if ! has "$gdbus_codegen" ; then
             gdbus_codegen=
         fi
         # Check that the libraries actually work -- Ubuntu 18.04 ships
@@ -5678,6 +5678,8 @@ if test "$gio" = "yes" ; then
     echo "CONFIG_GIO=y" >> $config_host_mak
     echo "GIO_CFLAGS=$gio_cflags" >> $config_host_mak
     echo "GIO_LIBS=$gio_libs" >> $config_host_mak
+fi
+if test "$gdbus_codegen" != "" ; then
     echo "GDBUS_CODEGEN=$gdbus_codegen" >> $config_host_mak
 fi
 echo "CONFIG_TLS_PRIORITY=\"$tls_priority\"" >> $config_host_mak

The reason for doing this change is to avoid checking for codegen strictly. This is still not on mainline.

Configure and build the QEMU

mkdir build 
cd build 
../configure --target-list=aarch64-softmmu --extra-cflags=-I/usr/include/capstone/
make -j32

We are giving the extra-cflags because, the headers are not present readily for pickup. Ubuntu bug ???

Once the make -j32 is done, you can use the latest version of qemu-system-aarch64.