Find the answer to your Linux question:
Page 2 of 2 FirstFirst 1 2
Results 11 to 12 of 12
Static executables produced by gcc (at least, by the gcc that ships with Ubuntu...) produce statically linked ELF binaries: Code: $ echo 'int main(){}' | gcc -x c - -static ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #11
    Linux Newbie
    Join Date
    Mar 2010
    Posts
    152

    Static executables produced by gcc (at least, by the gcc that ships with Ubuntu...) produce statically linked ELF binaries:

    Code:
    $ echo 'int main(){}' | gcc -x c - -static
    $ file a.out 
    a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, for GNU/Linux 2.6.15, not stripped
    ELF is meant to have quite a wide scope, but on a system that supports them it makes sense to use ELF for executables in general so you can tell the OS what sections to make read-only or executable and such - otherwise there's no other option but to plonk the whole file into a fixed address in memory and make the whole of the process's virtual memory copy-on-write (or give each process its own copy of the executable image) and executable, which, while it would work, is something I'm certainly glad isn't done in practice.

    P.S. Nice thinking on using GDB - hadn't thought of that...

  2. #12
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,449
    Quote Originally Posted by JohnGraham View Post
    Static executables produced by gcc (at least, by the gcc that ships with Ubuntu...) produce statically linked ELF binaries:

    Code:
    $ echo 'int main(){}' | gcc -x c - -static
    $ file a.out 
    a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, for GNU/Linux 2.6.15, not stripped
    ELF is meant to have quite a wide scope, but on a system that supports them it makes sense to use ELF for executables in general so you can tell the OS what sections to make read-only or executable and such - otherwise there's no other option but to plonk the whole file into a fixed address in memory and make the whole of the process's virtual memory copy-on-write (or give each process its own copy of the executable image) and executable, which, while it would work, is something I'm certainly glad isn't done in practice.

    P.S. Nice thinking on using GDB - hadn't thought of that...
    I guess I need to do some reading up on ELF in particular. I wasn't aware that it's scope included statically linked executables. Thanks for pointing that out for me. No matter how long one has been in this business (almost 40 years serious full-time multi-platform software development in my case) there is more to learn!
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Page 2 of 2 FirstFirst 1 2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •