[PATCH] D112116: [llvm-objcopy] Add --update-section

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 21 00:27:11 PDT 2021


jhenderson added a comment.

In D112116#3075927 <https://reviews.llvm.org/D112116#3075927>, @leonardchan wrote:

> In D112116#3074501 <https://reviews.llvm.org/D112116#3074501>, @jhenderson wrote:
>
>> High-level question: does GNU objcopy change the section size for sections that are updated?
>
> Looks like it does. It will change the section size to whatever the size of the file was. If the section happens to be part of a segment, then that segment (FileSize/MemSize) will increase/decrease by however much larger/smaller the file is compared to the original section size. (Example: given an 8 byte section, then using a 6 byte file will decrease the section size to 6 and reduce the segment size by 2. Given a 10 byte file, the section size increases to 10 and the segment size increases by 2).
>
> For this implementation, we just want to avoid the hassle of resizing a segment. Currently this patch throws an error for a file larger than the section, but kinda just "accepts" files smaller than the section (effectively doing a short memcpy only overwriting part of the section without resizing). If in the future, there's a demand for resizing sections/segments, then maybe it would be more desirable to update this patch such that it will only work on same-size files and throw an error if the file is smaller. This way, the behavior can still be defined down the line rather than saying it's just a short memcpy for now. Thoughts?
>
> In the meantime, I'll address code comments that aren't too crucial to design.

I think we can leave the segment size, to avoid having to change segments in general (I could see an argument for shrinking or even possibly growing a segment, if the section is last, but I don't think we want to go down that route in this patch). I do think it's important to change the section size, though, in my opinion. You can just leave behind the old data in the part of the segment that is no longer covered by a section header, or do what happens when a section is explicitly removed from a segment.

Now that I think about it, there should be nothing stopping you growing a section that isn't in a segment - llvm-objcopy should be able to happily update the other section offsets. I think we should only reject growing sections if they are part of a segment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112116/new/

https://reviews.llvm.org/D112116



More information about the llvm-commits mailing list