ldconfig: small optimization

Swap which side of a comparison is byte-swapped by be32toh()
on little-endian architectures.

The be32toh() macro just returns the operand and big-endian
architectures and returns it byte-swapped on little-endian
architectures.

When operating on a constant argument, the compiler can perform
the swap operation at build time instead of swapping the data
read from the hints file at run time.

Reviewed by:	kib
Tested by:	tuexen
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D44734
This commit is contained in:
Stefan Eßer 2024-04-19 16:29:12 +02:00
parent 178cf4b9db
commit 6b13e4cb3d

View file

@ -220,7 +220,7 @@ read_elf_hints(const char *hintsfile, bool must_exist, bool force_be)
close(fd);
hdr = (struct elfhints_hdr *)mapbase;
is_be = be32toh(hdr->magic) == ELFHINTS_MAGIC;
is_be = hdr->magic == htobe32(ELFHINTS_MAGIC);
if (COND_SWAP(hdr->magic) != ELFHINTS_MAGIC)
errx(1, "\"%s\": invalid file format", hintsfile);
if (force_be && !is_be)