This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: objcopy with automatic adjusting sections feature


Hi Piotr,

I have a question related objcopy tool. I have the ELF object file
'object', and I want to update the data of one section (assume
'.mysec'). Is there any possibility to re-compute start, VMA and LMA
addresses of all sections which are placed below '.mysec'?

Are you sure that you mean an object file and not an executable ? Sections in object files are not assigned LMAs until they are linked into an executable, and you can specify their LMA and VMA addresses explicitly using a linker script. So I am assuming for the rest of this email that you are actually talking about an executable, not an object file.


The simplest method, if you have access to all of the object files and libraries that made the original executable, is to just relink it with the new .mysec section replacing the old one on the linker command line.

Now, I do it manually in this way:

Remove the current section:
objcopy object -R .mysec

Add new section and fill it with data of mysec_data file
objcopy object --add-section .mysec=mysec_data

Change the section flags
objcopy object --set-section flags .mysec=contents,alloc,load,readonly,data

Set a new VMA and LMA values
objcopy vmlinux --change-section-vma .mysec=0x80b9b000

And then I change the addresses of .machvec.init and .bss sections to
fit the new memory arrangement.

Do you know any tips of hints to do it automatically instead of
annoying computing and changing it step by step?

if you do not have access to the original objects and libraries then the method that you describe above is really the only option you have. You could automate the process by creating a script to run each of the commands, but that is it.


Cheers
  Nick



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]