From 0d902d2b561a7118deedfa88cef8048edee5707c Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Fri, 24 Aug 2018 09:38:11 +0200 Subject: [PATCH] 8208665: Amend cross-compilation docs with qemu-debootstrap recipe Reviewed-by: martin, glaubitz, erikj --- doc/building.html | 67 +++++++++++++++++++++++++++++++++++++++++++++++ doc/building.md | 45 +++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) diff --git a/doc/building.html b/doc/building.html index d6f7b5a8c19..71c0d621ee2 100644 --- a/doc/building.html +++ b/doc/building.html @@ -72,6 +72,7 @@
  • Specifying the Target Platform
  • Toolchain Considerations
  • Native Libraries
  • +
  • Creating And Using Sysroots With qemu-deboostrap
  • Building for ARM/aarch64
  • Verifying the Build
  • @@ -634,6 +635,72 @@ cp: cannot stat `arm-linux-gnueabihf/libSM.so': No such file or directory cp: cannot stat `arm-linux-gnueabihf/libXt.so': No such file or directory
  • If the X11 libraries are not properly detected by configure, you can point them out by --with-x.

  • +

    Creating And Using Sysroots With qemu-deboostrap

    +

    Fortunately, you can create sysroots for foreign architectures with tools provided by your OS. On Debian/Ubuntu systems, one could use qemu-deboostrap to create the target system chroot, which would have the native libraries and headers specific to that target system. After that, we can use the cross-compiler on the build system, pointing into chroot to get the build dependencies right. This allows building for foreign architectures with native compilation speed.

    +

    For example, cross-compiling to AArch64 from x86_64 could be done like this:

    + +

    The build does not create new files in that chroot, so it can be reused for multiple builds without additional cleanup.

    +

    Architectures that are known to successfully cross-compile like this are:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    TargetCCCXX--arch=...--openjdk-target=...
    x86defaultdefaulti386i386-linux-gnu
    armhfgcc-arm-linux-gnueabihfg++-arm-linux-gnueabihfarmhfarm-linux-gnueabihf
    aarch64gcc-aarch64-linux-gnug++-aarch64-linux-gnuarm64aarch64-linux-gnu
    ppc64elgcc-powerpc64le-linux-gnug++-powerpc64le-linux-gnuppc64elpowerpc64le-linux-gnu
    s390xgcc-s390x-linux-gnug++-s390x-linux-gnus390xs390x-linux-gnu
    +

    Additional architectures might be supported by Debian/Ubuntu Ports.

    Building for ARM/aarch64

    A common cross-compilation target is the ARM CPU. When building for ARM, it is useful to set the ABI profile. A number of pre-defined ABI profiles are available using --with-abi-profile: arm-vfp-sflt, arm-vfp-hflt, arm-sflt, armv5-vfp-sflt, armv6-vfp-hflt. Note that soft-float ABIs are no longer properly supported by the JDK.

    The JDK contains two different ports for the aarch64 platform, one is the original aarch64 port from the AArch64 Port Project and one is a 64-bit version of the Oracle contributed ARM port. When targeting aarch64, by the default the original aarch64 port is used. To select the Oracle ARM 64 port, use --with-cpu-port=arm64. Also set the corresponding value (aarch64 or arm64) to --with-abi-profile, to ensure a consistent build.

    diff --git a/doc/building.md b/doc/building.md index e5990a76300..653683d10d7 100644 --- a/doc/building.md +++ b/doc/building.md @@ -1018,6 +1018,51 @@ Note that X11 is needed even if you only want to build a headless JDK. * If the X11 libraries are not properly detected by `configure`, you can point them out by `--with-x`. +### Creating And Using Sysroots With qemu-deboostrap + +Fortunately, you can create sysroots for foreign architectures with tools +provided by your OS. On Debian/Ubuntu systems, one could use `qemu-deboostrap` to +create the *target* system chroot, which would have the native libraries and headers +specific to that *target* system. After that, we can use the cross-compiler on the *build* +system, pointing into chroot to get the build dependencies right. This allows building +for foreign architectures with native compilation speed. + +For example, cross-compiling to AArch64 from x86_64 could be done like this: + + * Install cross-compiler on the *build* system: +``` +apt install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu +``` + + * Create chroot on the *build* system, configuring it for *target* system: +``` +sudo qemu-debootstrap --arch=arm64 --verbose \ + --include=fakeroot,build-essential,libx11-dev,libxext-dev,libxrender-dev,libxtst-dev,libxt-dev,libcups2-dev,libfontconfig1-dev,libasound2-dev,libfreetype6-dev,libpng12-dev \ + --resolve-deps jessie /chroots/arm64 http://httpredir.debian.org/debian/ +``` + + * Configure and build with newly created chroot as sysroot/toolchain-path: +``` +CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ sh ./configure --openjdk-target=aarch64-linux-gnu --with-sysroot=/chroots/arm64/ --with-toolchain-path=/chroots/arm64/ +make images +ls build/linux-aarch64-normal-server-release/ +``` + +The build does not create new files in that chroot, so it can be reused for multiple builds +without additional cleanup. + +Architectures that are known to successfully cross-compile like this are: + + Target `CC` `CXX` `--arch=...` `--openjdk-target=...` + ------------ ------------------------- --------------------------- ------------ ---------------------- + x86 default default i386 i386-linux-gnu + armhf gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf armhf arm-linux-gnueabihf + aarch64 gcc-aarch64-linux-gnu g++-aarch64-linux-gnu arm64 aarch64-linux-gnu + ppc64el gcc-powerpc64le-linux-gnu g++-powerpc64le-linux-gnu ppc64el powerpc64le-linux-gnu + s390x gcc-s390x-linux-gnu g++-s390x-linux-gnu s390x s390x-linux-gnu + +Additional architectures might be supported by Debian/Ubuntu Ports. + ### Building for ARM/aarch64 A common cross-compilation target is the ARM CPU. When building for ARM, it is