3
Example

When I run file on android-studio/bin/studio, I see:

android-studio/bin/studio: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=b4be78977494d9024646ef0e45685a4152512800, for GNU/Linux 3.2.0, not stripped

The section of that which matters for this is "ELF" and "dynamically linked".

Question

Considering that it appears that statically linking an ELF is possible, would I describe this as a "dynamically linked executable", as opposed to the common "dynamically linked library"?

Rationale

I ask because I have to use "s on Google to see any matches (which could be Google being "helpful" by default), but even then, the results are from very niche locations. Perhaps that's expected, though? I'm asking for confirmation from someone who's familiar with this.

2 Answers2

9

Yes, but only when you need to contrast it with statically-linked executables. Almost all Linux and Windows executables end up being dynamically linked.

From looking at https://en.wikipedia.org/wiki/Executable_and_Linkable_Format

and https://github.com/file/file/blob/f77a1092e1862c2295a21077c9e28c2614a0eede/src/readelf.c

It looks like "dynamic" is printed if there is a dynamic link information ELF segment and "static" otherwise.

pjc50
  • 15,223
2

When messing around with tiny hand-written assembly language programs, yeah it's 100% normal to say whether you're building a dynamically linked executable out of it or not. (Because a static executable is a very real possibility, so this is a special case of what @pjc50's answer mentioned.)

For example, in a dynamically linked executable, glibc's init hooks get called by the dynamic linker, so it's already initialized before execution reaches _start in the main program. So it can call printf even with a hand-written _start that doesn't call libc's init functions. (This is not something you should rely on for production use, but it is true on GNU/Linux. But not Cygwin glibc; I don't know why they don't take advantage of that.)

There's also ELF executable (ET_EXEC) vs. ELF PIE executable which is actually a "shared object", the same ELF type as a shared library. Most distros have configured GCC with -fPIE -pie as the default for several years now (https://stackoverflow.com/questions/43367427/32-bit-absolute-addresses-no-longer-allowed-in-x86-64-linux). Position Independent Executables (PIE) take advantage of the kernel and toolchain's support for an ELF shared object to be executable and have an INTERP field the same as an ELF executable (specifying a dynamic linker path, like how a text file can have a #!/bin/sh line specifying an interpreter.) Having an interpreter is what most people mean when they say "dynamically linked", even if there actually aren't any shared libraries that need to get linked.

file used to report PIE executables as "shared object" because that's what they were. They make ASLR possible, so that silly computer trick became a mainstream use-case. These days file identifies them as ELF 64-bit LSB pie executable (on my x86-64 desktop for example).


You can even have a static PIE, which ld and gcc won't create by default, only if you specify -static-pie, not -static -pie where -static overrides -pie.

Peter Cordes
  • 479
  • 5
  • 9