(no subject)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

(no subject)

Neoklis Kyriazis
Hi,

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.

My thanks in advance.


P.S. I have more data: Actually an ELF executable is apparently
produced, but when the source directory is viewed in the ROX-Filer
that I use, the ELF file is shown and reported as a shared library
object. The same happens when I look at the installed binaries in
/usr/local/bin, they also appear as shared objects. But Debian

binaries are shown as such (with the cog wheel icon, rather than
the jigsaw puzle piece icon).

It seems that the ELF files compiled from the source code of my apps
are seen as shared object files by ROX-filer, whereas Debian ELF

files are seen as such. So for some reason the ELF file format seems
to be different for some reason when I compile my source code and
that seems to confuse ROX!

 --
Best Regards
Neoklis - Ham Radio Call:5B4AZ
http://www.5b4az.org/

Reply | Threaded
Open this post in threaded view
|

Re: shared objects vs. executables in Stretch

Christian Seiler
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