System V ABI 4.1 specifies that program header's p_vaddr should equal p_offset, modulo p_align.
(https://docs.oracle.com/cd/E19683-01/816-1386/chapter6-83432/index.html).
I was able to violate this using the linkerscript.
Patch fixes the issue.
Details
Diff Detail
Event Timeline
ELF/Writer.cpp | ||
---|---|---|
1656–1659 | // Adjusts the file alignment for a given output section and returns // its new file offset. The file offset must be the same with its // virtual address (modulo the page size) so that the loader can load // executables without any address adjustment. | |
1661 | Rename this getFileAlignment. | |
1691–1692 | You want to move these three lines of code to the new function because it handles alignment as well. Then you can remove Align parameter from the function. |
ELF/Writer.cpp | ||
---|---|---|
1672–1679 | Can this be return alignTo(Off, PageSize, Sec->getVA())? |
ELF/Writer.cpp | ||
---|---|---|
1667–1670 | For relocatable output, do we even have to adjust file offset? |
LGTM
ELF/Writer.cpp | ||
---|---|---|
1672–1679 | Nice. I knew alignTo accepts the third argument, but this is the first time I see that is useful. |
ELF/Writer.cpp | ||
---|---|---|
1672–1679 | Yeah, I also saw it, but it was completely not obvious for me that it can be replacement for what was wrote before. |