1
0
mirror of https://github.com/golang/go synced 2024-11-19 12:44:51 -07:00

5l, 6l, 8l: Add a PT_LOAD PHDR entry for the PHDR.

Per the TIS ELF spec, if a PHDR entry is present in the
program header table, it must be part of the memory image of
the program. Failure to do this makes elflint complain, and
causes some tools that manipulate ELF to crash.

R=iant, rsc
CC=dave, golang-dev
https://golang.org/cl/4650067
This commit is contained in:
David Anderson 2011-07-12 17:49:55 -07:00 committed by Russ Cox
parent 75780f99f4
commit f1df07bf6a
3 changed files with 36 additions and 0 deletions

View File

@ -294,6 +294,7 @@ asmb(void)
ElfPhdr *ph, *pph; ElfPhdr *ph, *pph;
ElfShdr *sh; ElfShdr *sh;
Section *sect; Section *sect;
int o;
if(debug['v']) if(debug['v'])
Bprint(&bso, "%5.2f asmb\n", cputime()); Bprint(&bso, "%5.2f asmb\n", cputime());
@ -462,6 +463,17 @@ asmb(void)
pph->paddr = INITTEXT - HEADR + pph->off; pph->paddr = INITTEXT - HEADR + pph->off;
pph->align = INITRND; pph->align = INITRND;
/*
* PHDR must be in a loaded segment. Adjust the text
* segment boundaries downwards to include it.
*/
o = segtext.vaddr - pph->vaddr;
segtext.vaddr -= o;
segtext.len += o;
o = segtext.fileoff - pph->off;
segtext.fileoff -= o;
segtext.filelen += o;
if(!debug['d']) { if(!debug['d']) {
/* interpreter for dynamic linking */ /* interpreter for dynamic linking */
sh = newElfShdr(elfstr[ElfStrInterp]); sh = newElfShdr(elfstr[ElfStrInterp]);

View File

@ -699,6 +699,7 @@ asmb(void)
ElfPhdr *ph, *pph; ElfPhdr *ph, *pph;
ElfShdr *sh; ElfShdr *sh;
Section *sect; Section *sect;
int o;
if(debug['v']) if(debug['v'])
Bprint(&bso, "%5.2f asmb\n", cputime()); Bprint(&bso, "%5.2f asmb\n", cputime());
@ -862,6 +863,17 @@ asmb(void)
pph->paddr = INITTEXT - HEADR + pph->off; pph->paddr = INITTEXT - HEADR + pph->off;
pph->align = INITRND; pph->align = INITRND;
/*
* PHDR must be in a loaded segment. Adjust the text
* segment boundaries downwards to include it.
*/
o = segtext.vaddr - pph->vaddr;
segtext.vaddr -= o;
segtext.len += o;
o = segtext.fileoff - pph->off;
segtext.fileoff -= o;
segtext.filelen += o;
if(!debug['d']) { if(!debug['d']) {
/* interpreter */ /* interpreter */
sh = newElfShdr(elfstr[ElfStrInterp]); sh = newElfShdr(elfstr[ElfStrInterp]);

View File

@ -665,6 +665,7 @@ asmb(void)
ElfShdr *sh; ElfShdr *sh;
Section *sect; Section *sect;
Sym *sym; Sym *sym;
int o;
int i; int i;
if(debug['v']) if(debug['v'])
@ -932,6 +933,17 @@ asmb(void)
pph->paddr = INITTEXT - HEADR + pph->off; pph->paddr = INITTEXT - HEADR + pph->off;
pph->align = INITRND; pph->align = INITRND;
/*
* PHDR must be in a loaded segment. Adjust the text
* segment boundaries downwards to include it.
*/
o = segtext.vaddr - pph->vaddr;
segtext.vaddr -= o;
segtext.len += o;
o = segtext.fileoff - pph->off;
segtext.fileoff -= o;
segtext.filelen += o;
if(!debug['d']) { if(!debug['d']) {
/* interpreter */ /* interpreter */
sh = newElfShdr(elfstr[ElfStrInterp]); sh = newElfShdr(elfstr[ElfStrInterp]);