gcc 6 outputs a shared object by default instead of an executable
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
ProcVersionSign
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)
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/ 462ee21c3353c56 b910f
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.