Closed
Description
On the current nightly and stable, compiling hello world with --target x86_64-unknown-linux-musl
results in a static PIE binary that still has a DYNAMIC
segment and .dynamic
section. This causes file
to report it as:
$ file /tmp/main
/tmp/main: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, stripped
This was previously reported as #79624, which I believe to be incorrectly closed: on a hand-created binary without a DYNAMIC
segment, file
reports:
$ file out/fa6l
out/fa6l: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), statically linked, not stripped
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
mati865 commentedon Dec 14, 2020
How have you "hand-created" your binary?
GCC creates PIE the similarly to Rust:
axonasif commentedon Dec 14, 2020
@petrochenkov explained the reason at here: #79624 (comment)
remexre commentedon Dec 14, 2020
@mati865 With Rust, of course :) https://git.sr.ht/~remexre/exps/tree/dbe21d43f7902d52bda5a0b3a72520075cd09c89/fa6l/bs/src/main.rs
@Axim0s Yeah, I saw that; if you look at the #70740 PR that was linked, it shows the correct(?) behavior, from
file
at least.axonasif commentedon Dec 14, 2020
Yeah I know, it bothers me as well but the output binary does seem to work alike any other static binary, so guess I'll just ignore this for now or maybe it's
file
which needs an update over this ?petrochenkov commentedon Dec 14, 2020
I didn't investigate why exactly static PIEs have the
DYNAMIC
segment, but given that they basically have a chunk of dynamic linker (rcrt1.o
) statically compiled into them, it's not too surprising at least.Feel free to investigate further, the source is available - https://github.com/ifduyue/musl/blob/master/crt/rcrt1.c, https://github.com/ifduyue/musl/blob/master/ldso/dlstart.c etc.
workingjubilee commentedon Feb 26, 2023
There doesn't seem to be anything that we need to change here, so long as the binaries remain functional?
file
is indeed probably applying an imperfect heuristic.polarathene commentedon Mar 7, 2024
TL;DR: Issue can be closed.
These two examples below are built against a basic
cargo init example
generated project, Rust 1.76.DYNAMIC segment:
Now with additional flag
-C relocation-model=static
:Actual issue with the
file
program was resolved withfile-5.38
.But in prior versions if you do use
-C relocation-model=static
, it will not mistakenly output it as dynamically linked like shown in my earlier snippets 👍