Frederic Cambus

Home · Archives · Text Mode · GitHub · Twitter · RSS

Building LLVM on OpenBSD/loongson

· OpenBSD

I've been attempting to build LLVM on the Lemote Yeeloong for some time now, starting with LLVM 3.7.1. Sadly, the port doesn't build out of the box due to RAM constraints; the machine only has a 1GB RAM module, and while it's easily accessible and removable, upgrading the RAM on this machine is borderline impossible, more on that in a later article.

After a first full build fail, I decided to try the suggestions from pascal@ regarding LLVM on PowerPC, and started disabling additional architecture support first, then the static analyzer. This dramatically drops the number of files to compile and sounds reasonable, as I don't see anybody in his right mind attempt to cross-build the system for another architecture using a Loongson powered machine.

So I tweaked the port Makefile to include this conditional check:

# Disable additional architecture support and static analyzer on Loongson
.if ${MACHINE_ARCH} == "mips64el"
CONFIGURE_ARGS +=       -DLLVM_TARGETS_TO_BUILD="Mips"
CONFIGURE_ARGS +=       -DCLANG_ENABLE_STATIC_ANALYZER=OFF
CONFIGURE_ARGS +=       -DCLANG_ENABLE_ARCMT=OFF
.endif

While it was helping (at least regarding total compilation time), the build would still fail due to a lack of available RAM. Trying to decrease GCC optimization level using the -O1 flag globally wouldn't change a thing, the build would always hit a wall when trying to compile lib/IR/Function.cpp.

cc1plus: out of memory allocating 6482400 bytes after a total of 0 bytes

Diving further into the issue, I found that lib/IR/CMakeLists.txt had a special check targetting this exact file, leading me to find LLVM commits rL247427 and r258897. Interesting.

As a last resort, I tried one last build after adding this line to the port Makefile:

CXXFLAGS =              -O1

And tweaking lib/IR/CMakeLists.txt to append the following parameter for this one problematic file:

set_property(
	SOURCE Function.cpp
	PROPERTY COMPILE_FLAGS "--param ggc-min-expand=0 --param ggc-min-heapsize=8192"
)

For information, GCC's cc1plus has an internal garbage collector, which can be fine tuned using those parameters. Please refer to the GCC documentation for more information.

This time, while the build didn't run out of memory, it stalled on lib/IR/Function.cpp for 90+ minutes. After cancelling and trying again with ggc-min-heapsize set to 65536, it would still be stalled for 120+ minutes until I decided to postpone the experiment.

So where do we go from here? In light of the previously mentioned LLVM commits, it appears that there is a better chance to succeed once LLVM 3.9.0 is released. I'm publishing those notes meanwhile, and also in hope it could help building LLVM on similar RAM constrained platforms, such as OpenBSD/octeon.

Regarding OpenBSD/loongson specifically, there might also be a chance to get the current LLVM port to build on a Fuloong upgraded to 2GB, as they seem to be more tolerant regarding the type of accepted RAM modules. I verified that I could do a full LLVM build on amd64 with only 2GB of RAM and no swap, so there is definitely hope.

Lastly, if anyone reading this has an unused Fuloong collecting dust in a drawer, feel free to contact me.