[PATCH] D42872: Fix handling of zero-size segments in llvm-objcopy

vit9696 via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 13 13:57:45 PST 2018


vit9696 updated this revision to Diff 134108.
vit9696 added a comment.

Thanks for a quick reply. I think your comments were less helpful, because we had different assumptions, and you ended up explaining fairly trivial things leaving the ones I asked about unanswered. Apparently, assuming you got it right, I indeed misunderstood what James suggested. However, that's less important and easy to change.

More importantly,

> The FileSize should always be sizeof(Elf_Ehdr). It should never be PageAlign. I think you may be misunderstanding the spec. Here's the spec: http://www.sco.com/developers/gabi/2012-12-31/contents.html

Here is what we had different assumptions about. And it is not the spec, this one is not perfect but pretty clear to me, but why would your code be happy with a random segment that is not contiguous to the other segments and possibly overlaps with the existing segments (e.g. when the program header table or elf header is mentioned in a loadable segment). I assumed that it won't work this way, and thus wrote the code to account for padding and stuff.

I rewrote the stuff in a way you suggested, and it worked fine for my ELF. However, I am currently on macOS and I do not have many real world examples (or time to review llvm-objcopy code) to say that this will work just fine in all the edge cases. Tests do pass at least.

Regarding PT_PHDR. I set the types of both added segments to PT_PHDR, because PT_LOAD segments must not overlap each other and other types fit even less. Neither 2, nor 3 PT_PHDR segments are allowed by the spec, but for now it should be fine.


Repository:
  rL LLVM

https://reviews.llvm.org/D42872

Files:
  test/tools/llvm-objcopy/marker-segment.test
  tools/llvm-objcopy/Object.cpp
  tools/llvm-objcopy/Object.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42872.134108.patch
Type: text/x-patch
Size: 5454 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180213/38aa2552/attachment.bin>


More information about the llvm-commits mailing list