Bug 5037 - strip shrinks PT_GNU_RELRO on PIE objects
Summary: strip shrinks PT_GNU_RELRO on PIE objects
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.18
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-15 22:57 UTC by Mike Frysinger
Modified: 2007-09-18 00:37 UTC (History)
2 users (show)

See Also:
Host: x86_64-linux-gnu
Target:
Build:
Last reconfirmed:


Attachments
unstripped x86_64 dumpelf (14.49 KB, application/octet-stream)
2007-09-15 22:59 UTC, Mike Frysinger
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Frysinger 2007-09-15 22:57:41 UTC
using gcc-3.4.6 and building a PIE binary with -z relro results in an ELF that,
when stripped, causes the PT_GNU_RELRO to shrink the memsize more than the
filesize ... perhaps this is a dupe of Bug 3281 ...

$ gcc-3.4.6 dumpelf.c -o dumpelf -fPIE -Wl,-z,relro
$ readelf -Wl dumpelf | grep GNU_REL
GNU_RELRO 0x007d50 0x00607d50 0x00607d50 0x0002b0 0x0002b0 R 0x1
$ strip dumpelf
$ readelf -Wl dumpelf | grep GNU_REL
GNU_RELRO 0x007d50 0x00607d50 0x00607d50 0x000288 0x000280 R 0x1

the filesize (0x288) is larger than the memsize (0x280)

looking at the relevant section headers:
[17] .ctors         PROGBITS   00607d50 007d50 000010 00  WA  0   0  8
[18] .dtors         PROGBITS   00607d60 007d60 000010 00  WA  0   0  8
[19] .jcr           PROGBITS   00607d70 007d70 000008 00  WA  0   0  8
[20] .data.rel.ro   PROGBITS   00607d80 007d80 0000a0 00  WA  0   0 32
[21] .dynamic       DYNAMIC    00607e20 007e20 000190 10  WA  5   0  8
[22] .got           PROGBITS   00607fb0 007fb0 000028 08  WA  0   0  8

we see the filesize of the PT is correct (0x7d50 + 0x288 covers all these
sections) but the memsize of the PT does not include the last few entries of the
.got (0x7d50 + 0x280 is 0x8 bytes short of the end of the .got)
Comment 1 Mike Frysinger 2007-09-15 22:59:21 UTC
Created attachment 2004 [details]
unstripped x86_64 dumpelf

linked with vanilla binutils-2.18
Comment 2 H.J. Lu 2007-09-16 01:35:23 UTC
Does it with the current Linux binutils?
Comment 3 Mike Frysinger 2007-09-16 01:52:13 UTC
thought i had tested 2.18.50.0.1 already, but i guess not ...

strip in 2.18.50.0.1 does not mess up the PT, but strip in 2.18 does

i'll give the branch a spin as well
Comment 4 Mike Frysinger 2007-09-16 02:21:32 UTC
current 2.18 branch as well as CVS head exhibit same bug as the 2.18 release
Comment 5 H.J. Lu 2007-09-16 03:19:17 UTC
(In reply to comment #4)
> current 2.18 branch as well as CVS head exhibit same bug as the 2.18 release

In Linux binutils source tree, there is a patch for bug 3281 under "patches"
You can try it on binutils from CVS and binutils 2.18.
Comment 6 Mike Frysinger 2007-09-16 07:02:52 UTC
after applying binutils-tls-relro-14.patch to HEAD, strip did not break
PT_GNU_RELRO header (memsize == filesize)
Comment 7 H.J. Lu 2007-09-16 07:13:40 UTC
(In reply to comment #6)
> after applying binutils-tls-relro-14.patch to HEAD, strip did not break
> PT_GNU_RELRO header (memsize == filesize)

But it still increases memsize/filesize by 8. I will look into it.
Comment 8 H.J. Lu 2007-09-16 19:56:38 UTC
A patch is posted at

http://sourceware.org/ml/binutils/2007-09/msg00208.html
Comment 9 H.J. Lu 2007-09-18 00:36:20 UTC
Fixed by

http://sourceware.org/ml/binutils/2007-09/msg00229.html
Comment 10 H.J. Lu 2007-09-18 00:37:00 UTC
Fixed.