Page MenuHomeFreeBSD

Architecture independent file

Authored by se on Feb 24 2024, 2:26 PM.
Referenced Files
Unknown Object (File)
Sun, Apr 14, 5:41 PM
Unknown Object (File)
Mon, Apr 8, 10:40 PM
Unknown Object (File)
Feb 27 2024, 5:37 PM



The file contains binary data in the endianness of the respective architecture.
This is relevant for example when a file system image for an emulated CPU with a different byte order is prepared.
FreeBSD used to support several big-endian architectures, but only powerpc64 is of some relevance today.

The patch in this review changes the definition of the hints file to use little-endian values on all architectures.
It provides both a run-time linker rtld and a ldconfig command that support both endiannesses on all architectures, as a step towards using only little endian data.
The ldconfig command will create little-endian hints files unless invoked with the new -B option, which will enforce big-endian mode (and will check it when reading or merging).

This allows for example to create a powerpc64 file system image for stable releases that lack the run-time linker with support for both byte order schemes.
The support for big-endian hints files on little-endian architectures exists solely for testing purposes. There is a commented-out test in rtld that evaluates to a constant "true" value on little endian architectures and when activated will remove the support for big-endian hints files on little-endian systems, which results in all byte-swap macros to be eliminated (i.e., no code size or run-time overhead remains).

This patch is an intermediary step - when all supported releases support the new rtld, support for big-endian hint files can be removed.
This would involve the logical substitution of the force_be variable in all expression by a constant false value (i.e., the simplification of expressions and parameter lists).

The commented out test in the calculation of is_be in rtld should be activated as soon as sufficient testing has been performed and testing of the byte swap macro on amd64 is no longer considered necessary (i.e., when this review has been tested and is approved).

Test Plan
  • Apply the patch on a little-endian and on a big-endian system and verify that the run-time loader is still working as expected.
  • Create a hints file in a non-defaut place and verify the correctness of embedded integer values for both the little-endian and big-endian mode.
  • Reboot the system to force a new hints file to be written.
  • Copy hints files between systems of different endiannesses and use ldconfig -r -f $file" to verify the automatic detection of the endianness of the hints file.
  • Merge a directory into a hints file of either endianness and verify the resulting change.

Due to the symmetry between le/be the tests could also be performed with a forced big-endian hints file on amd64.

Diff Detail

rG FreeBSD src repository
Lint Not Applicable
Tests Not Applicable

Event Timeline

se requested review of this revision.Feb 24 2024, 2:26 PM

I have noticed that the usage message and man-page have not been finalized for this version of the patches, see inline comments.


If the test "le32toh(1) == 1" is enabled, then is_le will be true on all little-endian systems and the COND_SWAP macro will be reduced to an assignment to a local variable which should be eliminated by constant expression elimination. If support of big-endian hints files on little-endian CPUs is not required, then the code could of course be further simplified.

134 ↗(On Diff #134924)

The usage message is left over from the previous review and will be changed to just mention -B (unless this testing-only option is removed before the commit of the ldconfig patches in this review). I did not want to upload a new diff just for this detail ...
(If ldconfig is committed with support for the -B option then the synopsis in the man-page will also be updated.)


Would be useful to report the reason for hints file rejection. May be not always, it is too noisy if the file is corrupted, but e.g. when ld_debug is enabled.


Yes, I'll wait a few days for further review comments before updating the diff with this change..

Please split this change into two commits, one for rtld, and next for ldconfig. I am not sure about your plans for merging to stable/13 and 14 for ldconfig part, but I keep rtld completely synced on all branches.

Split review in 2 parts:

  • Make the run-time loader detect the byte-order of the hints file (kept in this review)
  • Make ldconfig detect the byte-order of an existing hints file and create new hints file using little-endian values by default (new review, yet to be created)

The suggested changes have been incorporated.
This review contains the enhanced debug messages of review D44080 (with changes requested by reviewers).

This revision is now accepted and ready to land.Feb 26 2024, 10:13 PM