[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: shared objects vs. executables in Stretch



Hi there,

On 04/13/2017 09:16 PM, Neoklis Kyriazis wrote:
> Having just completed installation of development tools in my
> first installation of Debian (stretch), I tried to compile the
> sources of some of my own apps but I end up with a shared library
> object instead of an ELF executable! My apps are on my web site
> in the signature below, and they compile well in Void Linux. Its
> a puzzle for me but I am a complete beginner in Debian so it may
> have something to do with my installation's setup.

Debian activates PIE by default starting from Stretch in the
compiler. This allows ASLR (address space layout randomization)
to work not only for external library code, but also for the
executable code itself.

The thing is: internally, PIE executables don't exist in ELF.
There are either executables (with fixed addresses for their
code and no dynamic relocations) and shared objects (which are
relocated by the dynamic linker). Hence gcc/binutils actually
generate a shared library when PIE is enabled. Shared libraries
can be executable (try running /lib/x86_64-linux-gnu/libc.so.6
on your system, which is the standard C library - that will
print some version information), so that's how PIE executables
work.

Try doing:

file /bin/ls

and that will also tell you it's a shared object. Some binaries
in Debian have not been compiled with PIE (for various reasons),
so they will still appear as executables.

See also:
http://stackoverflow.com/questions/34519521/gcc-creates-a-shared-object-instead-of-an-executable-binary

You can link your code with -no-pie to get a regular ELF
executable again - but that won't benefit from ASLR for the
executable's own code.

Regards,
Christian


Reply to: