[PATCH] D34956: [ELF] - Store pointer to PT_LOAD instead of pointer to first section (FirstInPtLoad) in OutputSection
Rui Ueyama via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 12 15:33:59 PDT 2017
ruiu added inline comments.
================
Comment at: ELF/LinkerScript.cpp:794-795
+
static void
-allocateHeaders(std::vector<PhdrEntry> &Phdrs,
+allocateHeaders(std::vector<PhdrEntry *> &Phdrs,
ArrayRef<OutputSectionCommand *> OutputSectionCommands,
----------------
grimar wrote:
> ruiu wrote:
> > This change seems fine, but I realized that I do not understand what this function is supposed to do. What is this for?
> Function checks if elf header and program header can be allocated.
> If there is no room for them, PT_PHDR should not be emited.
>
> See:
> `PT_PHDR` description:
> "Specifies the location and size of the program header table itself, both in the file and in the memory image of the program. This segment type cannot occur more than once in a file. **Moreover, it can occur only if the program header table is part of the memory image of the program**." (https://docs.oracle.com/cd/E19683-01/816-1386/chapter6-83432/index.html)
>
> Imagine we have script like:
> `SECTIONS {foo 0 : {*(foo*)} }` (took it from no-space.s testcase)
>
> In that case there is no VA space for headers. That means we do not allocate them in PT_LOAD. Output will be:
>
> ```
> Program Headers:
> Type Offset VirtAddr PhysAddr
> LOAD 0x001000 0x0000000000000000 0x0000000000000000
> ```
There's no rule or something that says a program header must be at beginning of a file, right? If there's no space at beginning of a file for a program header, why don't you put it at end of the file?
https://reviews.llvm.org/D34956
More information about the llvm-commits
mailing list