Reproduction steps: 1. build a PIE (position independent executable) binary: $ cc -fpie -pie -o hello ~/hello.c $ ./hello Hello, world 2. use file to determine the type: $ file hello hello: ELF 64-bit LSB shared object, x86-64, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 13.0 (1300087), FreeBSD-style, with debug_info, not stripped As of very recently we have a DF_1_PIE flag to indicate that this is a PIE binary, not a DSO: $ readelf -d hello Dynamic section at offset 0xc20 contains 25 entries: Tag Type Name/Value 0x0000000000000001 NEEDED Shared library: [libc.so.7] 0x000000006ffffffb FLAGS_1 PIE We should report something like "ELF 64-bit LSB position independent executable..." from file/libmagic.
File 5.39 from ports works as expected: $ /usr/local/bin/file ~/hello /home/emaste/hello: ELF 64-bit LSB pie executable, x86-64, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 13.0 (1300087), FreeBSD-style, with debug_info, not stripped
File from ports gets both cases correct: % cp /lib/libc.so.7 /tmp/ % chmod +x /tmp/libc.so.7 % /usr/local/bin/file /tmp/libc.so.7 /tmp/libc.so.7: ELF 64-bit LSB shared object, x86-64, version 1 (FreeBSD), dynamically linked, stripped % /usr/local/bin/file ~/hello /home/emaste/hello: ELF 64-bit LSB pie executable, x86-64, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 13.0 (1300087), FreeBSD-style, with debug_info, not stripped while file in-tree incorrectly reports shared object for the PIE binary
A commit references this bug: Author: emaste Date: Mon Jun 29 13:30:48 UTC 2020 New revision: 362782 URL: https://svnweb.freebsd.org/changeset/base/362782 Log: Revert r362261, "Re-apply r333944 to unbreak ports" A file update in 2018 broke many ports as it misidentified shared libraries as PIE binaries. r333944 reverted part of the change, restoring ports builds but misidentifying objects in the opposite direction. Earlier this month file 5.39 was imported, and then the change originally from r333944 was recommitted as r362261. However, the issue was fixed upstream, so r362261 serves no purpose. PR: 246960, 247461 [exp-run] Sponsored by: The FreeBSD Foundation Changes: head/contrib/file/magic/Magdir/elf