Brian Robert Callahan

academic, developer, with an eye towards a brighter techno-social life



[prev]
[next]

2021-05-22
The GNU D Compiler on OpenBSD/armv7

Following from our previous blog post, I ran a build of GDC on my BeagleBone Black, an OpenBSD/armv7 machine. Let's record the issues I had so that we can replicate things.

The setup

I began with my GDC for arm64. See this patch for my changes on top of a vanilla gcc git clone. Much like arm64, I also installed the g++ package to get access to gcc-8.4.0, which I used as my bootstrap compiler.

The build

I used the same build script as arm64 that you can find in the previous blog post, with the exception of removing -j6 from the GMake invocation.

Getting fixes from the OpenBSD ports tree

I had to incorporate some fixes to get it working.

Like AArch64 support, ARM support for OpenBSD has not yet been upstreamed, so I needed to pull the analogous patches for armv7 from the ports tree. This was straightforward.

A compiler crash

Unfortunately, gcc-8.4.0 crashed when trying to compile gimple-match.c. In my experience, this is the most difficult file during the build. It appears to be a bug in the optimizer on armv7 that is the culprit. I was able to work around this issue by leveraging a GCC extension. I added this line to the very top of gimple-match.c:

#pragma GCC optimize ("O0")

According to the GCC documentation, this #pragma "allows you to set global optimization options for functions defined later in the source file." I hear it is not quite the same as specifying -O0 on the command line but it is enough to not have GCC error out with the optimizer bug, so it is good enough for me. If I wanted to be a little better, I would find the function that was causing the optimizer bug and wrap only that function in this #pragma. Additionally, another page in the GCC documentation says about optimize: "The optimize attribute should be used for debugging purposes only. It is not suitable in production code." I very much do not care about this admonition. Do whatever works and makes you happy. This worked and I am happy.

Teaching Phobos about OpenBSD/armv7

All I had to do was turn on building Phobos and DRuntime. No other changes were needed:

  arm*-*-openbsd*)
	LIBPHOBOS_SUPPORTED=yes
	;;

Another arch in the books

Of course, the real people to thank are the D team for having all the bits necessary for armv7 support already in-tree and ready to be used. I am just trying out what is already there and being happily suprised and then I can share packages with you to make your life easier.

A package?

If people want, I can toss a package up on GitHub. Let me know.

Next

No one has offered me an account on a sparc64 machine, so mips64{,el} next I suppose.

Top

RSS