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

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 9 09:02:03 PST 2018


jhenderson added a comment.

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

> It is not that simple, because the size of the header part should be aligned to the page size (from what I remember at least)


I do not believe to be the case for the ELF header and program header table. What I therefore think you mean is that the first segment must be aligned based on the page size. From the ELF gABI:

> loadable process segments must have congruent values for p_vaddr and p_offset, modulo the page size

What this means is that the first segment will often be at the first page-size boundary, although it is not required to be. I do not believe we take account of the page size in llvm-objcopy, thinking about this, but it doesn't matter, as long as the p_align field of loadable segments is at least the size of the page size. We should add a function that maps machine types to page sizes and use that to align loadable segments in general, although using p_align is likely good enough for most cases. In your case, is the p_align smaller than the page size? If it isn't, then the pseudo-segment approach will work without any issues, otherwise, we'll need to figure out the page size somehow.

> And we cannot know the alignment rules / page sizes of the target system.

Can't we use the machine type? Or are there systems with different page sizes but the same machine type? If there are different, then the only way we can safely align things is by the page size being explicitly specified on the command-line. We cannot determine the page size just by inspecting the program headers.

> We could try checking the subsequent segments, but it is not so nice.

I think you may also be making an incorrect assumption: there is no guarantee that all the loadable segments are first in the file. It is valid to have a loadable segment after a non-loadable segment, which means that we cannot use the position of the first non-empty segment as a basis to determine the page size.


Repository:
  rL LLVM

https://reviews.llvm.org/D42872





More information about the llvm-commits mailing list