Trying to build OpenJDK 9 for iOS x86_64

Andreas Vigneront andreasvigneront at gmail.com
Wed Jan 20 09:15:33 UTC 2016


Hi,

I've been trying to get OpenJDK 9 to compile for iOS x86_64 (so a simulator
build), using the latest forest at hg.openjdk.java.net/mobile/dev/. I ran
into a couple of issues and hope you can help me resolve them.

Here's how I build things:

hg clone http://hg.openjdk.java.net/mobile/dev/
cd dev
./get_sources.sh
./configure --openjdk-target=x86_64-macos-ios --with-boot-jdk=$JAVA_HOME
--disable-warnings-as-errors --disable-headful --enable-static-build=yes
--with-jvm-variants=minimal1

This is essentially based on one of the earlier mailing list posts. After
installing FreeType via brew, this compiles without a problem and i end up
with static libraries in the build/ directory.

I then created a simple iOS project in Xcode, linking the static libs to
the binary, and including the jdk/include directory in the search paths. I
use some standard JNI code to initialize the VM just to have the linker
pull in symbols from the static libs. However, when linking, i get the
following error:

/Users/andreas/workspace/openjdk9-mobile/build/ios-x86_64-normal-minimal1-release/jdk/lib/amd64/minimal/libjvm.a(jni.o),
building for iOS simulator, but linking in object file built for OSX, for
architecture x86_64

The build has two issues it turns out:

1) To resolve the linker issue, one has to pass
"-miphoneos-version-min=6.0" (or a higher version) to Clang. The Mach-O
object files will then have the proper load command denoting the target OS
and minimum version.

2) The build should use the proper sysroot, e.g.
"-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk".
This will ensure that the native bits of the build actually use the proper
frameworks.

I tried to fix issue 1. by passing the minimum iOS version with
--with-extra-cflags/--with-extra-cxxflags. However, then the build fails

"configure: error: C compiler cannot create executables"

Since the binaries are the same for x86_64 Mac OS X builds (what the
OpenJDK build generates) and iOS Simulator builds, i simply fixed up all
object files with a little tool i wrote, replacing the minimum OS load
command.

When i link these modified binaries, i get a lot of undefined symbols which
are not available in the iOS SDK:

_finite
_opendir$INODE64
_readdir$INODE64
_readdir_r$INODE64

I checked the files that use these functions, e.g. os_bsd.c to figure out
what's wrong. It appears the calls to these functions are actually
#ifdef'ed out when passing TARGET_OS_IPHONE. It appears the autoconf output
generated by the above configure call doesn't add this to CFLAGS/CXXFLAGS.

Finally, i tried passing the proper sysroot to configure. That fails
because iOS doesn't support cups.

I saw that Gluon had a working OpenJDK build for the simulator, so i must
be doing something wrong. It'd be awesome if you could point out my errors
:)

Best,
Andreas


More information about the mobile-dev mailing list