-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools: simplify lone segment creator tool
There's a better and simpler way to implement this feature: take advantage of the fact that the PT_PHDR program header is optional. Instead of moving the whole program header table to the end of the file and then wrangling pointers, I can just overwrite the PT_PHDR entry. There seems to be no downsides to this. Since the kernel passes programs pointers to their program header tables, as well as the entry count and even the size of each entry, the PT_PHDR segment does not appear to be necessary at all for accessing the program header table. This enables even simpler integration with mold and its new features: look for spare PT_NULL segments to use for the lone segment before using the PT_PHDR segment. This allows keeping the PT_PHDR segment and avoids disturbing the linker's output. The ELF documentation says, emphasis mine: > PT_PHDR > > The array element, _if present_ ... > _If it is present_ ... So it might not be present and is not required to be present. > Moreover, it _may_ occur only if the program header table > is part of the memory image of the program. A lack of the PT_PHDR segment does not imply the program header table is not part of the program's memory image. It could still be covered by a PT_LOAD segment and be in memory anyway. All linkers I've tried generate PT_LOAD segments that cover the ELF header and the program headers and so accessing the table at runtime should work. GitHub-Issue: rui314/mold#1148
- Loading branch information
1 parent
547b7b8
commit 1724fec
Showing
1 changed file
with
76 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters