Bug 10802 - objcopy an executable file compiled with PIE failed
Summary: objcopy an executable file compiled with PIE failed
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.21
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-18 08:28 UTC by Peter Hjalmarsson
Modified: 2009-10-20 00:52 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Hjalmarsson 2009-10-18 08:28:07 UTC
As mentioned on the mailinglist, objcopy does not make an executable of an
executable file if it is compiled with -fPIE -pie.
Problem confirmed with git as today (GNU objcopy (GNU Binutils) 2.20.51.20091018).

And now how to easy reproduce.
Notice how for the first round tmp and tmp2 got the same permissions,
while when compiled with "-fPIE -pie" they have not:


$ echo "main(){}" > tmp.c && gcc -o tmp tmp.c && objcopy tmp tmp2 && ls
-l tmp tmp2
-rwxr-xr-x 1 xake xake 8081 17 okt 09.12 tmp
-rwxr-xr-x 1 xake xake 8081 17 okt 09.12 tmp2

$ echo "main(){}" > tmp.c && gcc -fPIE -pie -o tmp tmp.c && objcopy tmp
tmp2 && ls -l tmp tmp2
-rwxr-xr-x 1 xake xake 8133 17 okt 09.13 tmp
-rw-r--r-- 1 xake xake 8133 17 okt 09.13 tmp2
Comment 1 H.J. Lu 2009-10-19 18:33:42 UTC
A patch is posted at

http://sourceware.org/ml/binutils/2009-10/msg00396.html
Comment 2 Peter Hjalmarsson 2009-10-19 19:36:32 UTC
(In reply to comment #1)
> A patch is posted at
> 
> http://sourceware.org/ml/binutils/2009-10/msg00396.html

Works for me.:-)
Comment 3 Sourceware Commits 2009-10-20 00:49:44 UTC
Subject: Bug 10802

CVSROOT:	/cvs/src
Module name:	src
Changes by:	amodra@sourceware.org	2009-10-20 00:49:31

Modified files:
	bfd            : ChangeLog opncls.c 

Log message:
	PR binutils/10802
	* opncls.c (_maybe_make_executable): Make DYNAMIC files executable.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.4818&r2=1.4819
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/opncls.c.diff?cvsroot=src&r1=1.59&r2=1.60

Comment 4 Alan Modra 2009-10-20 00:52:31 UTC
I'll put this on the branch after verifying that testsuite results are not
perturbed.
Comment 5 Sourceware Commits 2009-10-20 08:40:54 UTC
Subject: Bug 10802

CVSROOT:	/cvs/src
Module name:	src
Branch: 	binutils-2_20-branch
Changes by:	amodra@sourceware.org	2009-10-20 08:40:37

Modified files:
	bfd            : ChangeLog opncls.c 

Log message:
	PR binutils/10802
	* opncls.c (_maybe_make_executable): Make DYNAMIC files executable.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_20-branch&r1=1.4761.2.29&r2=1.4761.2.30
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/opncls.c.diff?cvsroot=src&only_with_tag=binutils-2_20-branch&r1=1.57.2.2&r2=1.57.2.3