From 6b13e4cb3da28be82f9d3b8bd98e229ae107c73a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20E=C3=9Fer?= Date: Fri, 19 Apr 2024 16:29:12 +0200 Subject: [PATCH] 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 --- sbin/ldconfig/elfhints.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbin/ldconfig/elfhints.c b/sbin/ldconfig/elfhints.c index d6ee5e0918d6..64b3f916ba8d 100644 --- a/sbin/ldconfig/elfhints.c +++ b/sbin/ldconfig/elfhints.c @@ -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)