Channels ▼

Walter Bright

Dr. Dobb's Bloggers

Porting D to FreeBSD

April 28, 2009

It took me about 6 weeks to get D ported to the Mac OSX. During this, I learned that OSX was based on BSD unix. The Digital Mars web server is hosted on a FreeBSD system, and Jan Knepper who manages that had been encouraging me to look at FreeBSD for years. So I thought it was an ideal time to try it out.

First I needed a box running FreeBSD. Being in the programming business for a long time, I had a bunch of older machines moldering away in the basement, unusued. FreeBSD did not have demanding hardware requirements, so I wondered if one of them could be recycled with FreeBSD. It wouldn't hurt to try.

The first box I try wouldn't even turn on. Click on the power, and absolutely nothing happened. I put that back on the shelf. The next one coughed, turned over, put out a cloud of blue smoke, and sputtered back into life. It was around 9 years old, with a 20G drive and maybe 100 Mb of ram.

I looked around online, downloaded the FreeBSD ISO's and burned them on CDs. (The machine only has a CD drive, DVD installs won't work!) Putting in the CD and rebooted, the install recognized the ancient hardware and the install went smoothly. Mostly smoothly, anyway. The install isn't as polished as Ubuntu's is, and when it was finished there were a number of things, especially about the network, that needed manual editting of configuration files. Fortunately, Jan Knepper is an expert with FreeBSD and he walked me through all that. Looking at how Ubuntu had configured itself also helped.

I brought up the GUI interface, tried the browser, and was delighted that the system worked well on such old, slow, memory deficient hardware. It did sound like a GM turbine car with a rusted out tailpipe, though, so I configured it for remote operation via SSH and banished it to the basement alongside the Mac.

Now was the time to do the real work. First of all, the library (archive) format was identical to that on Linux. The object file format was also ELF, same as on Linux. Some of the function ABI conventions matched that on Mac OSX. The header files tended to match OSX. So doing a FreeBSD port turned out to be mixing and matching parts from the Linux and OSX ports.

The most tedious part turned out to be writing the import translations for the various C header files. They were almost the same as under OSX, but had to be carefully checked line by line as out of nowhere one of the values of a #define would be different.

The most annoying part was that gcc on FreeBSD has poor support for long doubles. Half of the long double math functions are unimplemented. LDBL_MAX comes out of gcc as infinity, even though the float.h header file defines it correctly. It looks like in order to get correct, accurate and portable math functions for D, we'll just have to reimplement them all.

The best part of this was it took a whole three days, and the FreeBSD D compiler was up and passing its test suite. I'll defer the D 2.0 version for the moment, as its runtime library is in a state of flux. Trying to add FreeBSD support to it would be too disruptive for now.

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 


Video