Using objcopy to replace elftoaout

Nick Clifton nickc@redhat.com
Fri Oct 14 08:20:00 GMT 2005


Hi Jim,

> Which basically said the elftoaout converts symbols to .text.
> "elftoaout(1) folds .rodata and .data section into text"
> 
> How can I accomplish this using objcopy?

I do not believe that objcopy can do this (at the moment, anyway).  What 
you need is the ability to merge one section into another.  One thing 
that might work, although it is rather complicated and completely 
untested is:

   Make a copy of the file.

   In the copy use "objcopy --remove-section ..." to remove all sections 
except say the .rodata section.

   Then use "objcopy --rename-section 
.rodata=.text,alloc,load,readonly,code,contents" to get a .text section.

   Repeat the first three steps to get another file which contains the 
.data section renamed to .text.

   Now use "objcopy --remove-section..." to remove the .rodata and .data 
sections from the original file.

   Finally use the linker to link together these three new files, all of 
which contain .text sections.  The linker should now merge these 
sections together giving you the output that you want.


Or you could just write a patch for objcopy that does all of this for you...

Cheers
   Nick



More information about the Binutils mailing list