I found that it is probably a bit more convinent and helps to simplify logic
of program headers allocation a little.
Details
Diff Detail
Event Timeline
ELF/LinkerScript.cpp | ||
---|---|---|
778–779 | This change seems fine, but I realized that I do not understand what this function is supposed to do. What is this for? |
ELF/LinkerScript.cpp | ||
---|---|---|
778–779 | Function checks if elf header and program header can be allocated. See: Imagine we have script like: 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 |
ELF/LinkerScript.cpp | ||
---|---|---|
778–779 | 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? |
ELF/LinkerScript.cpp | ||
---|---|---|
778–779 | But why would we want to do that ? Neither bfd or gold allocate program headers in this case I think, why should we ? Spec says about PT_PHDR: "This type, if present, must precede any loadable segment entry." (https://docs.oracle.com/cd/E19683-01/816-1386/chapter6-83432/index.html). Also I think if script is writen in the way when there is no room for headers it may assume them are not allocated. And the last - there is still ELF file header there which must be placed at the begining of the file and we can't move it anyways. Basing on all above I believe moving of program headers at least does not make sense (or even may be harmfull). Just in case, this patch does not change any logic, only simplifies the existent code. |
ELF/LinkerScript.cpp | ||
---|---|---|
778–779 | We actually ran into this in our kernel: we're using a custom linker script to avoid emitting ELF file or program headers because we don't want them in the kernel image. Since the kernel doesn't start at the beginning of the file, there's always a space so LLD always emits those headers unlike BFD ld or gold. I have a WIP change that avoids emitting the headers if there's no output section covering them which is the behavior BFD ld and gold use. |
LGTM
ELF/LinkerScript.cpp | ||
---|---|---|
796 | First is too terse. The member should be renamed FirstSec in a follow-up patch. |
ELF/LinkerScript.cpp | ||
---|---|---|
796 | Will do, thanks for review ! |
I'd name this findSection as it finds a given argument from a list. "get" prefix doesn't feel perfectly match to what this function does.