Due to reasons, I have to set up the dev environment on my Mac 10.9 for OpenJDK. Being someone who is mostly coding on Linux, I was surely unaware of what an arduous journey I put myself onto.

The most import doc I followed in the process is https://github.com/dmlloyd/OpenJDK/blob/jdk/jdk/doc/building.md, even though it contains a lot of outdated information.


  1. Fetch source of jdk:

    hg clone http://hg.openjdk.java.net/jdk/jdk
  2. Download JTReg from https://adopt-openjdk.ci.cloudbees.com/job/jtreg/lastSuccessfulBuild/artifact/

  3. Configure

    bash configure --disable-warnings-as-errors --with-jtreg=<downloade_unpacked_path_of_jtreg>
  4. Build

    make images
  5. Test

    make run-test-tier1

Realizing my clang is obsolete

On Mac, it’s recommended to use Xcode command line to build OpenJDK. On my box, it’s installed at /Library/Developer/CommandLineTools, which provides the real executables for development related tools, e.g. clang. (I was firstly a bit confused because which clang gives me /usr/bin/clang, which is not a symlink. I don’t know what’s the relation between /usr/bin/clang and /Library/Developer/CommandLineTools/usr/bin/clang. A quick experiment (renaming) reveals that /usr/bin/clang calls /Library/Developer/CommandLineTools/usr/bin/clang somehow, and it would crash if it’s not found.

Since Xcode command line is already installed for me, I should be able to build OpenJDK. bash configure works fine; however, the build failed when I call make, and the error is something like error: unknown warning option '-Wno-tautological-undefined-compare'. Apparently, this option wasn’t understood by my obsolete clang.

$ clang -v
Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix

Building clang-5

Since I have Homebrew, the easiest way to install clang-5 is brew install llvm, which failed because of my obsolete clang (of course). Then, I tried if gcc could be installed: brew install gcc worked fortunately, making gcc-7 available on my box, so I tried to specify it as the C compiler on installing llvm via brew install --cc=gcc-7 llvm, which surprisingly failed on building libunwind, a runtime dependency of llvm. I searched on google concerning the error message, error: storage class specified..., but didn’t find anything useful. (Possibly, my setup is too weird.)

Building OpenJDK using gcc-7

Since I have a working gcc-7, I thought I could tell OpenJDK to use gcc instead of clang: CC=gcc-7 CXX=g++-7 bash configure --with-toolchain-type=gcc. gcc-7 was indeed used, but failed with errors like “gcc-7: error: unrecognized command line option ‘-mstack-alignment=16’”. Some googling indicates that -mstack-alignment is specific to clang. It seems that OpenJDK doesn’t support compilers on Mac other than clang.

Using clang-5 binary with hacky linker

All of the sudden, I realized that I actually can try downloading the binary directly from http://releases.llvm.org/download.html. After unpacking and adding it into my PATH, I restarted with bash configure which failed complaining that the C compiler (clang-5) can’t build executable. On reading the verbose log, I found that my clang-5 can’t compiler the following trivial C program:

int main() {
return 0;

Trying it manually on the command line, I could confirm that it’s indeed not working. By passing -v option, I was able to locate the error to be in the linking process, and the linker was complaining -no_deduplicate was an unknow option. Some googling leaded me to https://github.com/llvm-mirror/clang/blob/master/test/Driver/darwin-ld-dedup.c, so my linker was obsolete.

I was able to find the latest source code for ld64 at https://opensource.apple.com/source/ld64/, but the build system is Xcode, which I don’t have on my box. Apparently, ld64 was not something in huge demand separately, so I can’t find any places to download the binary. When all hopes are forsaken, I decided to “hack” around the problem; filtering out this unknown option before calling the real linker.

/usr/bin/ld "${(@)@:#-no_deduplicate}"

This way, I was able to trick bash configure to believe that I have a working C compiler. However, the actual building process wasn’t smooth; the error is that “…/clang+llvm-5.0.0-x86_64-apple-darwin/lib/arc/libarclite_macosx.a can’t be found”. After locating the path of libarclite_macosx.a is/Library/Developer/CommandLineTools/usr/lib/arc/libarclite_macosx.a, I just copiedarcfolder in…/clang+llvm-5.0.0-x86_64-apple-darwin/lib` to mirror the original layout. With this change, I was finally able to build OpenJDK.

For this kind of low level programming, Linux is surely more friendly, for more developers use that env.