[File] Detecting PIE binaries

Ed Maste emaste at freebsd.org
Wed Jun 3 17:30:46 UTC 2020


PIE binaries are currently (FreeBSD, file 5.38) reported as shared objects:

$ cc -fpie -pie -o hello hello.c
$ /usr/local/bin/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

There is a .dynamic flag to indicate that the object is a PIE:

$ 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
...

Flag value:
#define DF_1_PIE        0x08000000      /* Is position-independent executable */


More information about the File mailing list