]> Cypherpunks repositories - gostls13.git/commitdiff
5l, 6l, 8l: Add a PT_LOAD PHDR entry for the PHDR.
authorDavid Anderson <danderson@google.com>
Wed, 13 Jul 2011 00:49:55 +0000 (17:49 -0700)
committerRuss Cox <rsc@golang.org>
Wed, 13 Jul 2011 00:49:55 +0000 (17:49 -0700)
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

src/cmd/5l/asm.c
src/cmd/6l/asm.c
src/cmd/8l/asm.c

index 2c9e50d00e05ffa4fc5ce43247f1d46262544a2d..28de6255a6164485b78f02f7ee74e63bd9b208c3 100644 (file)
@@ -294,6 +294,7 @@ asmb(void)
        ElfPhdr *ph, *pph;
        ElfShdr *sh;
        Section *sect;
+       int o;
 
        if(debug['v'])
                Bprint(&bso, "%5.2f asmb\n", cputime());
@@ -462,6 +463,17 @@ asmb(void)
                pph->paddr = INITTEXT - HEADR + pph->off;
                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']) {
                        /* interpreter for dynamic linking */
                        sh = newElfShdr(elfstr[ElfStrInterp]);
index 9136e03794c0831fc2be495eaf6964cbff4fa33e..581ec5a20b89600395389ef02406445afb3c58a6 100644 (file)
@@ -699,6 +699,7 @@ asmb(void)
        ElfPhdr *ph, *pph;
        ElfShdr *sh;
        Section *sect;
+       int o;
 
        if(debug['v'])
                Bprint(&bso, "%5.2f asmb\n", cputime());
@@ -862,6 +863,17 @@ asmb(void)
                pph->paddr = INITTEXT - HEADR + pph->off;
                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']) {
                        /* interpreter */
                        sh = newElfShdr(elfstr[ElfStrInterp]);
index e1ccfb8a3ddddcb301b944d22bb0139a2e976b7d..82bff3e1ed41cc49619ab2c45a751c09205e713b 100644 (file)
@@ -665,6 +665,7 @@ asmb(void)
        ElfShdr *sh;
        Section *sect;
        Sym *sym;
+       int o;
        int i;
 
        if(debug['v'])
@@ -932,6 +933,17 @@ asmb(void)
                pph->paddr = INITTEXT - HEADR + pph->off;
                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']) {
                        /* interpreter */
                        sh = newElfShdr(elfstr[ElfStrInterp]);