file(1) in the latest (20251222) powerpc64 (big endian) doesn't detect binary/library files correctly. This was installed from a cross-built -HEAD snapshot install ISO. See: ``` adrian@freebsd-16-ppc64-be:~ % file /bin/ls /bin/ls: data adrian@freebsd-16-ppc64-be:~ % /usr/local/bin/file /bin/ls /bin/ls: ELF 64-bit MSB pie executable, 64-bit PowerPC or cisco 7500, OpenPOWER ELF V2 ABI, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 16.0 (1600007), FreeBSD-style, stripped adrian@freebsd-16-ppc64-be:~ % ``` The port built file works fine. Weirdly, port built file magic w/ the cross-built base file also works: ``` adrian@freebsd-16-ppc64-be:~ % !105 file -m /usr/local/share/file/magic.mgc /bin/ls /bin/ls: ELF 64-bit MSB pie executable, 64-bit PowerPC or cisco 7500, OpenPOWER ELF V2 ABI, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 16.0 (1600007), FreeBSD-style, stripped adrian@freebsd-16-ppc64-be:~ % ``` but the reverse (port file, local file.mgc) doesn't work.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=39047538cf5d8f26112f7b08b3c56967f70f7f94 commit 39047538cf5d8f26112f7b08b3c56967f70f7f94 Author: Jessica Clarke <jrtc27@FreeBSD.org> AuthorDate: 2025-12-31 17:14:55 +0000 Commit: Jessica Clarke <jrtc27@FreeBSD.org> CommitDate: 2025-12-31 17:14:55 +0000 Merge commit faa5141b9be4 from file git (by Christos Zoulas): PR/656: harry.sintonen: Fix bug in byte swapping that was caused by the change to make flags uint16_t and cont_level uint8_t. This fixes using a magic.mgc built with a different endianness than file(1) itself, e.g. when building powerpc64 on amd64. PR: 292079 Fixes: ae316d1d1cff ("MFV: file 5.46.") MFC after: 3 days contrib/file/src/apprentice.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
15.0, 14.3 and 13.5 are all affected, since release media is cross-built from a little-endian host (`tar Oxf base.txz usr/share/misc/magic.mgc | file` will confirm that it's a little-endian magic file, i.e. foreign endianness, and they all have file 5.46).
I'm doing a cross build for ppc64 big endian right now to test before and after this diff to validate things, stay tuned. thanks for jumping on this quickly jessica!
hm, can we craft up a CI test for this somehow? like, have file(1) run on a bunch of installed system files (text, library, binary) and verify that they're correctly identified?
I'd expect kyua test -k /usr/tests/usr.bin/file/Kyuafile to fail.
https://ci.freebsd.org/job/FreeBSD-main-powerpc64-test/1832/testReport/junit/usr.bin.file/file_test/contrib_file_tests/
ok, the commit to -head fixed it, it requires an updated libmagic from the build: ``` adrian@freebsd-16-ppc64-be:~ % env LD_PRELOAD=./libmagic.so.4 ./file-ppc64-post /bin/ls /bin/ls: ELF 64-bit MSB pie executable, 64-bit PowerPC or cisco 7500, OpenPOWER ELF V2 ABI, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 16.0 (1600007), FreeBSD-style, stripped adrian@freebsd-16-ppc64-be:~ % env LD_PRELOAD=./libmagic.so.4 ./file-ppc64-pre /bin/ls /bin/ls: ELF 64-bit MSB pie executable, 64-bit PowerPC or cisco 7500, OpenPOWER ELF V2 ABI, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 16.0 (1600007), FreeBSD-style, stripped adrian@freebsd-16-ppc64-be:~ % ./file-ppc64-pre /bin/ls /bin/ls: data adrian@freebsd-16-ppc64-be:~ % ./file-ppc64-post /bin/ls /bin/ls: data adrian@freebsd-16-ppc64-be:~ % ```
A commit in branch stable/15 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=e5861dc2ea529527894b9be2df99f359c0d5b6ef commit e5861dc2ea529527894b9be2df99f359c0d5b6ef Author: Jessica Clarke <jrtc27@FreeBSD.org> AuthorDate: 2025-12-31 17:14:55 +0000 Commit: Adrian Chadd <adrian@FreeBSD.org> CommitDate: 2026-01-11 19:21:47 +0000 Merge commit faa5141b9be4 from file git (by Christos Zoulas): PR/656: harry.sintonen: Fix bug in byte swapping that was caused by the change to make flags uint16_t and cont_level uint8_t. This fixes using a magic.mgc built with a different endianness than file(1) itself, e.g. when building powerpc64 on amd64. PR: 292079 Fixes: ae316d1d1cff ("MFV: file 5.46.") MFC after: 3 days (cherry picked from commit 39047538cf5d8f26112f7b08b3c56967f70f7f94) contrib/file/src/apprentice.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=10f4191e2f85857045f5f971cc5720b977457068 commit 10f4191e2f85857045f5f971cc5720b977457068 Author: Jessica Clarke <jrtc27@FreeBSD.org> AuthorDate: 2025-12-31 17:14:55 +0000 Commit: Jessica Clarke <jrtc27@FreeBSD.org> CommitDate: 2026-01-30 01:17:53 +0000 Merge commit faa5141b9be4 from file git (by Christos Zoulas): PR/656: harry.sintonen: Fix bug in byte swapping that was caused by the change to make flags uint16_t and cont_level uint8_t. This fixes using a magic.mgc built with a different endianness than file(1) itself, e.g. when building powerpc64 on amd64. PR: 292079 Fixes: ae316d1d1cff ("MFV: file 5.46.") MFC after: 3 days (cherry picked from commit 39047538cf5d8f26112f7b08b3c56967f70f7f94) contrib/file/src/apprentice.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
A commit in branch stable/14 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=afedf568e111b5b6093e8465c1e22ab3895c6162 commit afedf568e111b5b6093e8465c1e22ab3895c6162 Author: Jessica Clarke <jrtc27@FreeBSD.org> AuthorDate: 2025-12-31 17:14:55 +0000 Commit: Jessica Clarke <jrtc27@FreeBSD.org> CommitDate: 2026-01-30 01:19:18 +0000 Merge commit faa5141b9be4 from file git (by Christos Zoulas): PR/656: harry.sintonen: Fix bug in byte swapping that was caused by the change to make flags uint16_t and cont_level uint8_t. This fixes using a magic.mgc built with a different endianness than file(1) itself, e.g. when building powerpc64 on amd64. PR: 292079 Fixes: ae316d1d1cff ("MFV: file 5.46.") MFC after: 3 days (cherry picked from commit 39047538cf5d8f26112f7b08b3c56967f70f7f94) contrib/file/src/apprentice.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)