gcc 6 outputs a shared object by default instead of an executable

Bug #1635706 reported by Hadrien
20
This bug affects 4 people
Affects Status Importance Assigned to Milestone
build-essential (Ubuntu)
Invalid
Undecided
Unassigned
gcc-defaults (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

Ubuntu 16.10 with gcc version 6.2.0 20161005 (Ubuntu 6.2.0-5ubuntu12)

* Install gcc: sudo apt install build-essential
* Build any program with gcc.
    Minimal example: printf "int main() { return 1; }" | gcc -x c -
* Read the output file header: readelf -h a.out

Expected result: the ELF header Type shows: EXEC
Actual result: the ELF header Type shows: DYN

The side effect is that we cannot run any program built with gcc 6 from Nautilus. Nautilus opens an error message saying it does not know how to handle a shared library.

Most programs in /bin and /usr/bin cannot be started from Nautilus by double-clicking.

Everything was fine with the gcc release in Ubuntu 16.04

ProblemType: Bug
DistroRelease: Ubuntu 16.10
Package: gcc 4:6.1.1-1ubuntu2
ProcVersionSignature: Ubuntu 4.8.0-22.24-generic 4.8.0
Uname: Linux 4.8.0-22-generic x86_64
ApportVersion: 2.20.3-0ubuntu8
Architecture: amd64
CurrentDesktop: Unity
Date: Fri Oct 21 21:11:46 2016
EcryptfsInUse: Yes
InstallationDate: Installed on 2016-10-14 (6 days ago)
InstallationMedia: Ubuntu 16.10 "Yakkety Yak" - Release amd64 (20161012.2)
SourcePackage: gcc-defaults
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
Hadrien (psydk) wrote :
description: updated
Revision history for this message
Hadrien (psydk) wrote :
Revision history for this message
Hadrien (psydk) wrote :
Revision history for this message
Hadrien (psydk) wrote :

I tried with a two steps generation: first a call to "gcc" to generate a .o file, then a call to "ld" to generate an executable.

I attached a minimal example program that does not need the libc or standard crt.o. I used a slightly modified version of that program :

https://gist.github.com/lunixbochs/462ee21c3353c56b910f

in order to get the smallest "ld" command line possible. This is it:

ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -o exe plop.o

I found that when the "-pie" option is removed, the ELF header Type field changes from DYN to EXEC.

Hadrien (psydk)
description: updated
Revision history for this message
Hadrien (psydk) wrote :

It looks like it is actually expected for an ELF executable to have the type DYN when it is built with -pie.

Changed in build-essential (Ubuntu):
status: New → Invalid
Changed in gcc-defaults (Ubuntu):
status: New → Invalid
Revision history for this message
adfaure (adrien-faure2) wrote :

Hello, this bug affects me. The project I am working on requires to work with Executable ELF.
I try to rebuild gcc from apt-source, Unfortunately the command fails...

Do you know a solution (a part from re-install ubuntu 16.04 for example) ?

thank you.
Adrien.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.