Subject: Why is static linking not quite entirely static?

From: Benson Margulies <[email-masked]>
Date: Thu, 5 Mar 2020 22:12:04 -0800

Executables built with (e.g.) g++ -static still show a runtime dependency
on /lib/ld-musl-x86_64.so.1. My recollection from the past was that it was
possible to achieve a completely static a.out. Is there a way?

---

From: Konstantin Kulikov <[email-masked]>
Date: Fri, 6 Mar 2020 11:42:50 +0300

On 3/6/20 9:12 AM, Benson Margulies wrote:
> Executables built with (e.g.) g++ -static still show a runtime 
> dependency on /lib/ld-musl-x86_64.so.1. My recollection from the past 
> was that it was possible to achieve a completely static a.out. Is there 
> a way?
> 

It is not possible to run PIE binary without dynamic linker - it needs 
to do relocations at runtime.

I don't know if it's possible to bundle dynamic linker with your binary.

---

From: Benson Margulies <[email-masked]>
Date: Fri, 6 Mar 2020 08:06:47 -0800

Thank you.

Is it possible to turn off the PIE?

I may be able to ship the linker along with, but I just want to understand
the options.

---

From: Marco Dickert <[email-masked]>
Date: Mon, 9 Mar 2020 10:18:14 +0100

> Is it possible to turn off the PIE?

I wouldn't recommend that. As far as I understand one should be able to
compile static PIE binaries, at least with gcc [1]. See also the
documentation [2] for `--static-pie` (ctrl-f static-pie).

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81498
[2] https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html

-- 
Marco Dickert
[email-masked]
https://misterunknown.de