Portable C Compiler

June 07, 2010 posted by Iain Hibbert

After reading about progress with the Portable C Compiler (PCC) last year, I was inspired to try building it on NetBSD. Gregory McGarry had done some work integrating it into the toolchain though it is not yet useable to build a full release, but the native build framework in external/bsd/pcc was incomplete.

I updated this a while ago so that it is possible to build a distribution or release containing pcc(1), pcpp(1) and ccom(1) binaries for the target architecture by setting the following two variables in your /etc/mk.conf or passing them to build.sh on the commandline


There had been many bug fixes and features added since previous import in September 2009, but the major addition was that GCC compatibility is now enabled by default, and many commonly used attributes and builtin functions are now supported. I had heard of people trying to use pcc to build a kernel without success and went for an alternative approach, building userland programs, as my feeling was that testing smaller code units would be a lot easier. I wrote a script (src/external/bsd/pcc/prepare-import.sh) to configure the PCC sources for import to NetBSD in a consistent manner, and have been using it to follow development for a few months, reporting problems along the way where I could.

The latest pcc can build all of bin/ and sbin/, most of games/ (except for dab(6) which is C++), and only a few issues remain in usr.bin/ and usr.sbin/. There are still issues outstanding with PIC support on i386 at least, which prevents building shared libraries within the NetBSD framework at this time, though this can be worked around by setting MKPIC=no.

The in-tree version has been updated and is now at "pcc 0.9.9 [20100603]" which I've been using successfully on i386 though there is support included for amd64, arm, hppa, mips, powerpc, sparc64 & vax CPUs which may also work.

All the credit and many thanks go to Anders Magnusson who has been working on pcc for many years, he is very responsive to problem reports, sometimes with fixes posted the same day.




Aside from being small and portable, I can't help but think LLVM and clang are a better choice for modern BSD compiling. Any chance the FreeBSD work can serve as a springboard for NetBSD?

Posted by Kevin Bowling on June 07, 2010 at 12:04 PM UTC #

PCC runs ultra fast. The blazing speed is somehow breathtaking since GCC is getting doggy slower year-by-year. I hope NetBSD whole source code emphasises on avoiding GCC-ism to facilitate other compilers including commercial ones.

Posted by Toru Nishimura on June 07, 2010 at 06:15 PM UTC #

I haven't looked at clang though I think that there are more developers working on it than pcc, so it is likely that it will be able to build NetBSD before pcc can. I have heard from people who have built and run NetBSD kernels with a few modifications already using clang/LLVM, perhaps it just needs 'some work' integrating it to the build system. I am not sure about the C++ nature of it though, if that will be as welcome as pcc would.

Posted by Iain Hibbert on June 07, 2010 at 07:21 PM UTC #

Post a Comment:
Comments are closed for this entry.