Bug 23610 - objcopy is not removing the sectiones like .rela.plt and rela.dyn.
Summary: objcopy is not removing the sectiones like .rela.plt and rela.dyn.
Status: RESOLVED DUPLICATE of bug 23611
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.32
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-06 08:24 UTC by Kamlesh Kumar
Modified: 2018-09-10 05:14 UTC (History)
0 users

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


Attachments
patch that fix the issue. (482 bytes, patch)
2018-09-06 08:24 UTC, Kamlesh Kumar
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kamlesh Kumar 2018-09-06 08:24:43 UTC
Created attachment 11233 [details]
patch that fix the issue.

Hi All,

 

we have the requirement in our inhouse product were we strip out the relocations sections like  “.rela.plt” and “rela.dyn” from the executable by objcopy/strip utility.

i.e simple example like

 

$cat test.c

int g;

int main()

{

  printf ("Hello World\n");

  return g;

}

 

$gcc -fpic -shared  test.c

 

$readelf -S a.out

 

  [ 6] .gnu.version_r    VERNEED          0000000000000468  00000468

       0000000000000020  0000000000000000   A       4     1     8

  [ 7] .rela.dyn         RELA             0000000000000488  00000488

       00000000000000d8  0000000000000018   A       3     0     8

  [ 8] .rela.plt         RELA             0000000000000560  00000560

       0000000000000018  0000000000000018  AI       3    22     8

 

$objcopy -R .rela.plt -R rela.dyn a.out

 

$readelf -S a.out

                [ 6] .gnu.version_r    VERNEED          0000000000000468  00000468

                       0000000000000020  0000000000000000   A       4     1     8

                [ 7] .rela.dyn         RELA             0000000000000488  00000488

                       00000000000000d8  0000000000000018   A       3     0     8

                [ 8] .rela.plt         RELA             0000000000000560  00000560

                       0000000000000018  0000000000000018  AI       3    22     8

 

$objcopy --remove-relocations=.rela.plt --remove-relocations=.rela.dyn a.out

 

$readelf -S a.out

                [ 6] .gnu.version_r    VERNEED          0000000000000468  00000468

                       0000000000000020  0000000000000000   A       4     1     8

                [ 7] .rela.dyn         RELA             0000000000000488  00000488

                       00000000000000d8  0000000000000018   A       3     0     8

                [ 8] .rela.plt         RELA             0000000000000560  00000560

                       0000000000000018  0000000000000018  AI       3    22     8

                      

we upgrade the binutils from version 2.25 to 2.29  and please note that we are able to strip out the relocation sections w.r.t 2.25 and this regression was from following changes that had a some major code refactoring in the remove-relocations front in 2.29 and which made our case fail .

https://github.com/qtumproject/x86-toolchain/blob/master/binutils-2.29/binutils/ChangeLog-2016

 

and also note that ,"objcopy -R .rela.text  test.o "for  the object file works as expected and  for executable were relocation sections was not removed  like above is expected behavior by objcopy/strip utility ?

 

We made some changes and same is attached( objcopy.patch ) that fix the issue  .

But before we move forward on the fix ,we would like to hear any thoughts /comments from experts on the issue/patch will be highly helpful for us.

 

Thank you ,awaiting for any insights/comments .
Comment 1 Alan Modra 2018-09-10 05:14:54 UTC
Dup

*** This bug has been marked as a duplicate of bug 23611 ***