Page MenuHomeFreeBSD

Make ldconfig support hints files of either byte-order
ClosedPublic

Authored by se on Feb 26 2024, 10:14 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Dec 7, 1:35 PM
Unknown Object (File)
Sun, Dec 1, 9:43 PM
Unknown Object (File)
Mon, Nov 25, 2:09 PM
Unknown Object (File)
Mon, Nov 25, 2:50 AM
Unknown Object (File)
Nov 24 2024, 11:55 AM
Unknown Object (File)
Nov 23 2024, 1:36 PM
Unknown Object (File)
Nov 22 2024, 9:24 PM
Unknown Object (File)
Nov 22 2024, 8:33 PM
Subscribers
None

Details

Summary

This review has been split off from review D44053 as requested by kib@ to allow the rtld changes to be committed and MFCed before these ldconfig changes.

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). It is expected, that new releases will use little-endian hints files on all architectures. As long as there are supported releases with architecture dependent byte order in the hints file, the -B option will allow to prepare images with a hints file for those old releases.

Test Plan

On a system that has a run-time linker with the changes from review D44053 apply this patch set and verify that the hints file is generated with little endian parameters in the file header on a big-endian architecture (powerpc64).

This version can also be used to verify the changes from review D44053 on a little-endian system by forcing the creation of a big-endian hints file (e.g., by adding -B to the command that creates the hints file in rc.d/ldconfig). Since the byte swap operations are symmetrical, support of a big-endian hints file on e.g. amd64 depends on the same functionality as a little-endian hints file on powerpc64 requires.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

se requested review of this revision.Feb 26 2024, 10:14 PM
se created this revision.
sbin/ldconfig/elfhints.c
189

Why do you need is_be global? Wouldn't it be better to keep local vars, by the minor cost of additional argument to COND_SWAP?

239

The return is excessive

se marked an inline comment as done.Feb 27 2024, 12:01 PM

The version of elfhints.c in the sources of the pkg command has been updated to implemented byte-order independent updates of the hints file, see:

https://github.com/freebsd/pkg/commit/cd941a627d4e55257cd78467ef74e2e7e2c80ac0 .

Making little-endian hints files the default (instead of creating files in the host's byte order by default) must be enabled only after the ports-mgmt/pkg port has been updated to a version that implements that feature (see comment at elfhints.c:254).

sbin/ldconfig/elfhints.c
189

The detected endinanness will be used to write the hints file in the original format when it is updated. (A default format is chosen when no hints file exists (either native byte-order or preferably little-endian for all CPUs).)
Since the byte-order is a stable feature of the hints file being operated on, a global seemed to be an appropriate change that minimizes the difference compared to the existing code.
It can be assumed that the existing byte-order is valid, and this makes it possible to update the hints file for an architecture with a byte-order different from that of the host system.

An earlier version had read_elf_hints return the is_be value, and write_elf_hints() and COND_SWAP got an extra parameter.

A planned ldconfig extension is a "-C $DESTDIR" option (similar to "make -C"), which would allow to create or update the hints file within a mounted file system image (including one for a CPU with different byte-order, e.g. for vbox emulation of that other CPU). This mode of operation should also respect the byte-order of an existing hints file.

If you still prefer the local variable being passed as return value and as parameter, I'll change the code back to what it was in my earlier draft version.

(And BTW: my hope is that the "is_be" variable will be removed when all supported FreeBSD releases use a little-endian hints file. COND_SWAP can be replaced by an unconditional le32toh() then, which will reduce it to an assignment that can be eliminated by the compiler on little-endian architectures.)

239

Yes, an earlier version returned a local is_be value, but I decided to use the global variable instead.
The return statement has been removed in my sources.

256
// Until the port of the pkg command (ports-mgmt/pkg) has been
// updated to support little-endian hints files on big-endian hosts,
// the above line should read:
		is_be = be32toh(1) == 1 || force_be;
sbin/ldconfig/ldconfig.c
70

I have restored the previous use of strcmp() in my sources.
The strncmp() is a relict from an earlier draft that used "-32b" and "-64b" to force a big-endian byte-order, "-32l" and -64l" for little endian.

se marked an inline comment as done.

Update diff to include changes suggested by reviewers. The is_be flag is still stored in a global variable, since this is a "global" feature of the hints file that is being processed and the global variable minimizes the required changes.

This version continues to create hints files in the native byte-order by default, since this is required by the current version of the ports-mgmt/pkg port.

An update of the pkg command that supports either byte-order on all platforms has been planned to have been released end of March 2024 (according to https://github.com/freebsd/pkg/pull/2248#issuecomment-1966390730). This feature has already been committed to the pkg repository (commit ID cd941a627d4e5).

sbin/ldconfig/ldconfig.8
44

The -elf option is accepted but ignored.
I'm not sure whether it should be mentioned in the SYNOPSIS section (as is the -v option, which also has no effect).

134

The -v option sets a global variable ("verbose"), which is never checked.
This option is therefore effectively ignored - this fact should perhaps be mentioned in the man-page ...
The ldconfig command on Linux prints the program version and the directories as they are scanned (and any symlinks that are created, which does not apply to FreeBSD).

kib added inline comments.
sbin/ldconfig/ldconfig.8
44

The options should be removed, finally. At best, there could be a note somewhere listing accepted historic options that are nops today.

This revision is now accepted and ready to land.Feb 27 2024, 9:58 PM