Bug 292079 - file(1) on ppc64 -HEAD (at least) builds do not detect libraries, binaries, etc
Summary: file(1) on ppc64 -HEAD (at least) builds do not detect libraries, binaries, etc
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 16.0-CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Jessica Clarke
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-12-31 17:13 UTC by Adrian Chadd
Modified: 2026-03-15 21:16 UTC (History)
2 users (show)

See Also:
jrtc27: mfc-stable15+
jrtc27: mfc-stable14+
jrtc27: mfc-stable13+
jrtc27: needs_errata?


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Adrian Chadd freebsd_committer freebsd_triage 2025-12-31 17:13:48 UTC
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.
Comment 1 commit-hook freebsd_committer freebsd_triage 2025-12-31 17:17:04 UTC
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(-)
Comment 2 Jessica Clarke freebsd_committer freebsd_triage 2025-12-31 17:29:04 UTC
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).
Comment 3 Adrian Chadd freebsd_committer freebsd_triage 2025-12-31 17:36:58 UTC
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!
Comment 4 Adrian Chadd freebsd_committer freebsd_triage 2025-12-31 17:48:01 UTC
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?
Comment 5 Jessica Clarke freebsd_committer freebsd_triage 2025-12-31 17:50:11 UTC
I'd expect kyua test -k /usr/tests/usr.bin/file/Kyuafile to fail.
Comment 7 Adrian Chadd freebsd_committer freebsd_triage 2026-01-01 03:53:09 UTC
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:~ % 
```
Comment 8 commit-hook freebsd_committer freebsd_triage 2026-01-11 19:23:40 UTC
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(-)
Comment 9 commit-hook freebsd_committer freebsd_triage 2026-01-30 01:19:37 UTC
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(-)
Comment 10 commit-hook freebsd_committer freebsd_triage 2026-01-30 01:20:38 UTC
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(-)