binutils Newspaper
NOVEMBER 30, 2026
ld — Proposed

ld: read the FreeBSD ELF hints file in either byte order

Fix linker to correctly parse FreeBSD ELF hints files on big-endian systems.

This patch addresses an issue where the FreeBSD linker’s hints file, which is typically written in little-endian byte order, is not correctly parsed on big-endian architectures like powerpc64. The change modifies the ldelf_check_ld_elf_hints function to detect and handle the byte order of the hints file header, ensuring compatibility across different architectures.

In the Thread 2 participants
  1. Piotr Kubaj <pkubaj@anongoth.pl> proposer

    Proposes to modify ldelf.c to correctly read FreeBSD ELF hints files, which are written in little-endian byte order and cause issues on big-endian systems like powerpc64. The patch introduces logic to detect and use the appropriate byte-swapping function for the hints file header.

    “FreeBSD's ldconfig writes the hints file in little-endian byte order on all architectures unless it is run with -B, so the header is not necessarily in host byte order. This causes an issue when trying to link some software on powerpc64 (big-endian POWER).”
  2. Jan Beulich <jbeulich@suse.com> reviewer

    Suggests a minor improvement to the patch by introducing a helper function to abstract the byte order detection and application, and also requests confirmation of copyright assignment.

    “Okay, preferably with ...”

Technical Tradeoffs

  • Ensures correct behavior on big-endian systems at the cost of slightly more complex code to handle byte order detection.

In Details

The ldelf_check_ld_elf_hints function in binutils' ld is responsible for processing FreeBSD-style ELF hints files. These files, generated by ldconfig, contain information used for optimizing dynamic linking. Historically, these hints files were written in little-endian format regardless of the host architecture. This patch addresses an issue on big-endian hosts (like powerpc64) where the hints file header is not correctly interpreted due to endianness mismatch.

Filed Under: ldELFendiannessFreeBSD