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

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 7 03:13:59 PST 2018


jhenderson added a comment.

I couldn't find any reference in the standard for the program header offset, but for section offsets of NOBITS sections, there's this:

> One section type, SHT_NOBITS described below, occupies no space in the file, and its sh_offset member locates the conceptual placement in the file.

I don't see why segment offsets should be any different. Also, by not adjusting the segment offsets of segments containing only NOBITS sections, the offset field of the section header for these sections will not be updated either, leaving the sh_offset field invalid.

For the record, linkers assign file offsets to such segments, after the previous segment, the same as if it had actual contents. When copying, GNU objcopy doesn't set the offset to zero, or similar (it leaves it unchanged, but then I haven't actually been able to create a case where the segment should be shifted yet).

In https://reviews.llvm.org/D42872#1000307, @vit9696 wrote:

> Also, I don't think yaml2obj supports segments with 0 FileSize and non-zero MemSize. Perhaps I simply failed to find a way to do it, in this case, could anyone give me a hint?


Take a look at the yaml2obj test "program-header-nobits.yaml". That uses a segment with a larger memsize than filesize, and could be adjusted to not have any filesize at all, by removing the .data section.


Repository:
  rL LLVM

https://reviews.llvm.org/D42872





More information about the llvm-commits mailing list