[PATCH] D34956: [ELF] - Store pointer to PT_LOAD instead of pointer to first section (FirstInPtLoad) in OutputSection

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 12 05:08:59 PDT 2017


grimar 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,
----------------
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
```


https://reviews.llvm.org/D34956





More information about the llvm-commits mailing list