This patch adds --update-section option which is present in GNU objcopy. It's being occasionally used for hacking/binary patching tasks.
Details
Diff Detail
Event Timeline
I suspect that this is going to interact nastily with D59843.
Sorry, can't find this patch. What's this?
Does GNU objcopy support updating sections within segments?
Yep. Here is RFC https://binutils.sourceware.narkive.com/LI0gnMHb/rfc-objcopy-add-update-section-option.
tools/llvm-objcopy/ObjcopyOpts.td | ||
---|---|---|
260 | s/Add/Update/g |
Oops typo (now fixed). It should be D59483.
Does GNU objcopy support updating sections within segments?
Yep. Here is RFC https://binutils.sourceware.narkive.com/LI0gnMHb/rfc-objcopy-add-update-section-option.
Okay, thanks. I'll take a look at that.
Rather than updating a section in place we should extend the "replaceSectionReferences" method to work in every section type, and then swap the object out for a new object rather than updating in place.
tools/llvm-objcopy/ELF/Object.cpp | ||
---|---|---|
783 | We need to be *very* careful here. Can you explain why you did this? | |
1489 | We should not be changing segment layout. This is a huge bag of worms and this function does not correctly handle this. You basically have to re-link an executable to do this. Changing the size of a section that's within a segment should just simply be an error. I'm highly skeptical of use cases that require this. |
tools/llvm-objcopy/ELF/Object.cpp | ||
---|---|---|
783 | This patch introduces segment fixup procedure which works incorrectly without this change
| |
1489 | One of use cases is adding some initialization to existing binary, e.g you dump text section and your own function, change start address, write section back to the module. There are other use cases as well: https://github.com/hioa-cs/IncludeOS/blob/master/cmake/post.service.cmake Also see RFC |
What's up with this PR? What happens if the section size increases? Where do you handle the fixing of the .bss section?
@AsafFisher I don't have time for this ATM. Feel free to take over.
Probably you can simplify this patch, so it doesn't touch segments
*Sections.rbegin() is slightly simpler