RSB fails on FreeBSD 15.1

I have been trying to build amd/amd-kria-k26 target on FreeBSD 15.1.
I am facing these errors:

ld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in libfdt/fdt_addresses.o
>>> referenced by fdt_addresses.c:38 (libfdt/fdt_addresses.c:38)
>>>               libfdt/fdt_addresses.o:(fdt_address_cells)

ld: error: relocation R_X86_64_32S cannot be used against local symbol; recompile with -fPIC
>>> defined in libfdt/fdt_check.o
>>> referenced by fdt_check.c:49 (libfdt/fdt_check.c:49)
>>>               libfdt/fdt_check.o:(fdt_check_full)

ld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in libfdt/fdt_addresses.o
>>> referenced by fdt_addresses.c:50 (libfdt/fdt_addresses.c:50)
>>>               libfdt/fdt_addresses.o:(fdt_size_cells)

ld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in libfdt/fdt_check.o
>>> referenced by fdt_check.c
>>>               libfdt/fdt_check.o:(.rodata+0x0)

ld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in libfdt/fdt_check.o
>>> referenced by fdt_check.c
>>>               libfdt/fdt_check.o:(.rodata+0x8)

ld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in libfdt/fdt_check.o
>>> referenced by fdt_check.c
>>>               libfdt/fdt_check.o:(.rodata+0x10)

ld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in libfdt/fdt_check.o
>>> referenced by fdt_check.c
>>>               libfdt/fdt_check.o:(.rodata+0x18)

ld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in libfdt/fdt_check.o
>>> referenced by fdt_check.c
>>>               libfdt/fdt_check.o:(.rodata+0x20)

ld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in libfdt/fdt_check.o
>>> referenced by fdt_check.c
>>>               libfdt/fdt_check.o:(.rodata+0x28)

ld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in libfdt/fdt_addresses.o
>>> referenced by fdt_addresses.c:38 (libfdt/fdt_addresses.c:38)
>>>               libfdt/fdt_addresses.o:(fdt_appendprop_addrrange)

ld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in libfdt/fdt_check.o
>>> referenced by fdt_check.c
>>>               libfdt/fdt_check.o:(.rodata+0x30)

ld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in libfdt/fdt_check.o
>>> referenced by fdt_check.c
>>>               libfdt/fdt_check.o:(.rodata+0x38)

ld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in libfdt/fdt_check.o
>>> referenced by fdt_check.c
>>>               libfdt/fdt_check.o:(.rodata+0x40)

ld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in libfdt/fdt_addresses.o
>>> referenced by fdt_addresses.c:50 (libfdt/fdt_addresses.c:50)
>>>               libfdt/fdt_addresses.o:(fdt_appendprop_addrrange)

ld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in libfdt/fdt_strerror.o
>>> referenced by fdt_strerror.c:47 (libfdt/fdt_strerror.c:47)
>>>               libfdt/fdt_strerror.o:(fdt_strerror)

ld: error: relocation R_X86_64_32S cannot be used against local symbol; recompile with -fPIC
>>> defined in libfdt/fdt_strerror.o
>>> referenced by fdt_strerror.c:53 (libfdt/fdt_strerror.c:53)
>>>               libfdt/fdt_strerror.o:(fdt_strerror)

ld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in libfdt/fdt_strerror.o
>>> referenced by fdt_strerror.c:0 (libfdt/fdt_strerror.c:0)
>>>               libfdt/fdt_strerror.o:(fdt_strerror)

ld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in libfdt/fdt_strerror.o
>>> referenced by fdt_strerror.c:0 (libfdt/fdt_strerror.c:0)
>>>               libfdt/fdt_strerror.o:(fdt_strerror)

ld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in libfdt/fdt_empty_tree.o
>>> referenced by fdt_empty_tree.c:25 (libfdt/fdt_empty_tree.c:25)
>>>               libfdt/fdt_empty_tree.o:(fdt_create_empty_tree)

ld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in libfdt/fdt_strerror.o
>>> referenced by fdt_strerror.c
>>>               libfdt/fdt_strerror.o:(fdt_errtable)

ld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)
cc: error: linker command failed with exit code 1 (use -v to see invocation)
gmake: *** [Makefile:218: libfdt/libfdt.so.1.7.2] Error 1
shell cmd failed: /bin/sh -ex  /home/me/GSOC_Work/rtems-deployment/build/dtc-1.7.2-x86_64-freebsd15.1-1/do-build
error: building dtc-1.7.2-x86_64-freebsd15.1-1

I was facing the same errors on freeBSD 15.0 as well. I updated to 15.1 but still facing same errors.

Here is the output of uname -a:

❯ uname -a
FreeBSD beepboop 15.1-RELEASE FreeBSD 15.1-RELEASE releng/15.1-n283562-96841ea08dcf GENERIC amd64

The issue is happening because libfdt object files are being compiled without Position Independent Code (PIC) support, but later the build system tries to create the shared library libfdt.so. FreeBSD’s linker is stricter and refuses to link non-PIC objects into a shared library, which is why you’re seeing errors like:

relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
To fix this, first make sure that libfdt is being compiled with -fPIC.
Before starting the build, export the following flags:

export CFLAGS=“-fPIC”
export CXXFLAGS=“-fPIC”
export CPPFLAGS=“-fPIC”

You can verify them with:
echo $CFLAGS
echo $CXXFLAGS
echo $CPPFLAGS

After that, rerun the RSB build.
If the problem still persists, check the DTC build system itself. In the dtc-1.7.2 source tree, verify whether the Makefile adds PIC flags. If not, add:
CFLAGS += -fPIC

The V=1 option is useful because it prints the full compiler commands, allowing you to confirm that -fPIC is actually being passed to the compiler.
Another thing worth checking is whether DTC really needs to build a shared library on FreeBSD. If supported, try building only the static library:
./configure --enable-static --disable-shared

This avoids the PIC requirement completely since libfdt.a will be generated instead of libfdt.so.
Finally, I would also recommend testing with the latest RTEMS Source Builder revision:
cd rtems-source-builder
git pull
git log -1

There is a possibility that FreeBSD 15.1 compatibility fixes have already been added upstream.
From the error log, the failure occurs while building the dependency dtc-1.7.2, specifically libfdt.so.1.7.2; the build never actually reaches the amd/amd-kria-k26 target itself. The primary thing to verify is that all libfdt objects are compiled with -fPIC before the shared library link step.

Do you have any gcc or binutil packages installed?

I have been building on FreeBSD 15.1 a lot in the past week and I am not seeing any issues.

I have already tried manipulating environment vars to include the -fPIC flag, but the issue still persists.
I have not tried changing dtc source tree Makefile because then I have to repackage it, hash it, change the hash in required configuration, which would not be feasible as I need to rebuild various boards frequently for ongoing addition of freebsd support to rtems-deployment.
Also I am already on the latest revision of both RTEMS and RSB.
@saksham

Yes I do have gcc and binutils installed.

I have tried doing some basic troubleshooting.
Adding the following to dtc config file:

%build
  ...
  CFLAGS="-fPIC -O2" %{__make} PREFIX=%{_prefix} WARNINGS=
  ...

and these as well.

%{__make} PREFIX=%{_prefix} WARNINGS= EXTRA_CFLAGS="-fPIC"
%define host_cflags %{host_cflags} -fPIC
%define host_cxxflags %{host_cxxflags} -fPIC

None of these worked and resulted into the same error again.

Ah I do not. I use FreeBSD with the OS compiler. It should work but this explains why I can build.

After uninstalling gcc and binutils and invoking rsb results into this error:

RTEMS Source Builder - Set Builder, 7 (73092c85ab05)
error: exe: not found: (__as) as
error: host build environment is not set up correctly
Build FAILED

Thanks for the clarification. Since you’ve already verified that exporting “-fPIC” doesn’t change the build and you’re on the latest RTEMS/RSB revisions, I don’t think this is simply a missing compiler flag anymore.

It seems more likely that the “dtc” package recipe or the FreeBSD toolchain interaction is overriding or ignoring the exported flags during the “libfdt” build.

A few things that might help narrow it down:

  1. Could you build “dtc” with “gmake V=1” (or otherwise enable verbose output) and check whether “-fPIC” actually appears in the compile commands for “fdt_check.c”, “fdt_addresses.c”, etc.? If it doesn’t, then the environment variables are probably not propagating into the “libfdt” build.

  2. Which compiler and linker are being used? (“cc --version”, “clang --version”, and “ld --version”). I’m wondering if this is specific to the FreeBSD 15.1 LLVM/LLD toolchain.

  3. Does “dtc-1.7.2” build successfully outside of RSB on the same FreeBSD 15.1 system? If a standalone build fails with the same relocation errors, that would point to an upstream “dtc”/FreeBSD compatibility issue rather than an RSB packaging problem.

  4. Is RSB attempting to build “libfdt.so” by default on FreeBSD? If RTEMS only needs the host tools, perhaps forcing a static-only “libfdt” build in the package recipe would be a cleaner long-term solution than patching the source itself.

At this point, I’d be interested in seeing the verbose compile/link commands around the failing “libfdt.so” link step, as that should reveal whether this is a flag propagation issue or a linker/toolchain compatibility issue.

A discussion on Discord in the #gsoc channel with @amar isolated the problem to a FreeBSD installation problem. My understanding of the problem is Distribution Sets should be used when installing FreeBSD from an ISO image.

This was solved by re-installing FreeBSD 15.1 via distribution sets.

I somehow had the plan9ports package installed on my previous system and it was interfering with the build process.
Uninstalling it solved the issue.

1 Like

Thanks for letting us know.