This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: RFC: Objcopy --only-keep-debug update
- From: Mark Wielaard <mjw at redhat dot com>
- To: "H.J. Lu" <hjl dot tools at gmail dot com>
- Cc: Nicholas Clifton <nickc at redhat dot com>, "binutils at sourceware dot org" <binutils at sourceware dot org>
- Date: Wed, 29 Jul 2015 22:14:49 +0200
- Subject: Re: RFC: Objcopy --only-keep-debug update
- Authentication-results: sourceware.org; auth=none
- References: <55B8D362 dot 9070004 at redhat dot com> <1438196435 dot 28346 dot 120 dot camel at bordewijk dot wildebeest dot org> <CAMe9rOpc=nfBdFRCjNF3c9h3-CRQTBMOUUs8dOAyqXXt3tbcuQ at mail dot gmail dot com>
On Wed, 2015-07-29 at 12:09 -0700, H.J. Lu wrote:
> On Wed, Jul 29, 2015 at 12:00 PM, Mark Wielaard <mjw@redhat.com> wrote:
> > On Wed, 2015-07-29 at 14:21 +0100, Nicholas Clifton wrote:
> >> One problem I did have with this part of the patch was in determining
> >> which sections should have their sh_link fields preserved. In the
> >> end I had to encode the section names directly, but I feel that their
> >> ought to be a better way.
> >
> > I should prefix this with noting that eu-unstrip only got confused
> > because the sh_flags weren't preserved. In particular the missing
> > SHF_INFO_LINK on .plt.rela sections caused it to not match those in the
> > main and debug file. I have a workaround for that now:
> > https://lists.fedorahosted.org/pipermail/elfutils-devel/2015-July/005076.html
> >
>
> Can you try binutils master branch? I think I have fixed it.
It doesn't seem so. This is how I tried:
$ gcc --version | head -1
gcc (GCC) 5.1.1 20150618 (Red Hat 5.1.1-4)
$ ./objcopy --version | head -1
GNU objcopy (GNU Binutils) 2.25.51.20150729
$ cat > testprog.c <<EOF
int main()
{
return 0;
}
EOF
$ gcc -o testprog -g testprog.c
$ ./objcopy --only-keep-debug testprog testprog.debuginfo
$ eu-readelf -S testprog testprog.debuginfo | grep rela.plt
[10] .rela.plt RELA 0000000000400378 00000378 00000030 24 AI 5 12 8
[10] .rela.plt NOBITS 0000000000400378 00000298 00000030 24 A 0 0 8
Note how the SHF_INFO_LINK flag, sh_info and sh_link are missing in the
debuginfo file.
elfutils doesn't have a eu-objcopy, but when using eu-strip you'll get:
$ eu-strip --strip-debug -f testprog.debuginfo.eu testprog
$ eu-readelf -S testprog.debuginfo.eu | grep rela.plt
[10] .rela.plt NOBITS 0000000000400378 00000280 00000030 24 AI 5 12 8
So only the sh_type and sh_offset are different. Of course elfutils only
deals with ELF files in the first place, so it is easier. The elfutils
patch referenced above contains a fuller testcase (testfiles generated
with gcc5 and objcopy, eu-unstrip them and compare with eu-elfcmp to the
original).
Cheers,
Mark