FreeBSD Specific Notes

Builtin LLVM linker for ARM targets has reached such level of maturity that GNU binutils are no longer necessary to form a functional cross-toolchain for FreeBSD 12 on Rasbperry Pi.

So we won't compile any source code in this guide, just combine pre-existing binary files.

  1. Download FreeBSD 12 for Raspberry Pi 3 and deploy it to microSD card, then boot your Rasbperry Pi device from this card.
  2. Log in as root via SSH, then archive FreeBSD libc and other libraries in the base system:
    cd /
    tar -L -zcf root/FreeBSD-12.0-rpi-include.tar.gz \
      usr/include
    tar -L -zcf root/FreeBSD-12.0-rpi-lib.tar.gz \
      lib libexec usr/lib
    
  3. Download FreeBSD-12.0-rpi-include.tar.gz and FreeBSD-12.0-rpi-lib.tar.gz from Raspberry Pi to your PC.
  4. Unpack these .tar.gz files in Windows to C:\cc_test\freebsd12.0-rpi using WinRAR.
  5. Download LLVM 6.0.1, install it temporarily to the "C:\Program Files\LLVM" folder, then copy folders as shown below:
    "C:\Program Files\LLVM\bin"
      -> C:\cc_test\freebsd12.0-rpi\bin
    "C:\Program Files\LLVM\lib\clang"
      -> C:\cc_test\freebsd12.0-rpi\lib\clang
  6. You may uninstall LLVM from "C:\Program Files\LLVM" now.
  7. Use the following script to test your Windows-to-FreeBSD12-on-RaspberryPi cross-compiler (C:\cc_test\test.cmd):
    @echo off
    set CROSSPI=%~dp0\freebsd-12.0-rpi\aarch64-unknown-freebsd\bin
    set TARGETPI=-target aarch64-unknown-freebsd12.0 ^
      --sysroot %~dp0\freebsd-12.0-rpi
    cd %~dp0
    if exist tmp\. rmdir /S /Q tmp
    mkdir tmp
    
    %CROSSPI%\clang %TARGETPI% -c hello1.c -o tmp\hello1.o
    %CROSSPI%\clang %TARGETPI% -fuse-ld=%CROSSPI%\ld.lld.exe ^
      tmp\hello1.o -o tmp\hello1
    %CROSSPI%\clang %TARGETPI% -fuse-ld=%CROSSPI%\ld.lld.exe ^
      -static -Wl,-s tmp\hello1.o -o tmp\hello1-static
    del tmp\hello1.o
    
    %CROSSPI%\clang++ %TARGETPI% -c hello2.cpp -o tmp\hello2.o
    %CROSSPI%\clang++ %TARGETPI% -fuse-ld=%CROSSPI%\ld.lld.exe ^
      tmp\hello2.o -o tmp\hello2
    %CROSSPI%\clang++ %TARGETPI% -fuse-ld=%CROSSPI%\ld.lld.exe ^
      -static -Wl,-s tmp\hello2.o -o tmp\hello2-static
    del tmp\hello2.o
  8. Source code for test samples (hello1.c and hello2.cpp) can be found in the previous section of this guide.

  9. >> Look at screenshots or buy already prepared cross-compiler (€10) to save your time.