Commit 14eba969 authored by Gustavo Niemeyer's avatar Gustavo Niemeyer

ld: fix freebsd build reverting .interp move

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/4794046
parent 8cdee891
...@@ -185,14 +185,6 @@ doelf(void) ...@@ -185,14 +185,6 @@ doelf(void)
elfstr[ElfStrRelPlt] = addstring(shstrtab, ".rel.plt"); elfstr[ElfStrRelPlt] = addstring(shstrtab, ".rel.plt");
elfstr[ElfStrPlt] = addstring(shstrtab, ".plt"); elfstr[ElfStrPlt] = addstring(shstrtab, ".plt");
/* interpreter string */
if(interpreter == nil)
interpreter = linuxdynld;
s = lookup(".interp", 0);
s->type = SELFROSECT;
s->reachable = 1;
addstring(s, interpreter);
/* dynamic symbol table - first entry all zeros */ /* dynamic symbol table - first entry all zeros */
s = lookup(".dynsym", 0); s = lookup(".dynsym", 0);
s->type = SELFROSECT; s->type = SELFROSECT;
...@@ -492,7 +484,9 @@ asmb(void) ...@@ -492,7 +484,9 @@ asmb(void)
sh->type = SHT_PROGBITS; sh->type = SHT_PROGBITS;
sh->flags = SHF_ALLOC; sh->flags = SHF_ALLOC;
sh->addralign = 1; sh->addralign = 1;
shsym(sh, lookup(".interp", 0)); if(interpreter == nil)
interpreter = linuxdynld;
elfinterp(sh, startva, interpreter);
ph = newElfPhdr(); ph = newElfPhdr();
ph->type = PT_INTERP; ph->type = PT_INTERP;
...@@ -638,7 +632,7 @@ asmb(void) ...@@ -638,7 +632,7 @@ asmb(void)
a += elfwritephdrs(); a += elfwritephdrs();
a += elfwriteshdrs(); a += elfwriteshdrs();
cflush(); cflush();
if(a > ELFRESERVE) if(a+elfwriteinterp() > ELFRESERVE)
diag("ELFRESERVE too small: %d > %d", a, ELFRESERVE); diag("ELFRESERVE too small: %d > %d", a, ELFRESERVE);
break; break;
} }
......
...@@ -591,22 +591,6 @@ doelf(void) ...@@ -591,22 +591,6 @@ doelf(void)
elfstr[ElfStrGnuVersion] = addstring(shstrtab, ".gnu.version"); elfstr[ElfStrGnuVersion] = addstring(shstrtab, ".gnu.version");
elfstr[ElfStrGnuVersionR] = addstring(shstrtab, ".gnu.version_r"); elfstr[ElfStrGnuVersionR] = addstring(shstrtab, ".gnu.version_r");
/* interpreter string */
if(interpreter == nil) {
switch(HEADTYPE) {
case Hlinux:
interpreter = linuxdynld;
break;
case Hfreebsd:
interpreter = freebsddynld;
break;
}
}
s = lookup(".interp", 0);
s->type = SELFROSECT;
s->reachable = 1;
addstring(s, interpreter);
/* dynamic symbol table - first entry all zeros */ /* dynamic symbol table - first entry all zeros */
s = lookup(".dynsym", 0); s = lookup(".dynsym", 0);
s->type = SELFROSECT; s->type = SELFROSECT;
...@@ -909,7 +893,7 @@ asmb(void) ...@@ -909,7 +893,7 @@ asmb(void)
break; break;
} }
} }
shsym(sh, lookup(".interp", 0)); elfinterp(sh, startva, interpreter);
ph = newElfPhdr(); ph = newElfPhdr();
ph->type = PT_INTERP; ph->type = PT_INTERP;
...@@ -1088,7 +1072,7 @@ asmb(void) ...@@ -1088,7 +1072,7 @@ asmb(void)
a += elfwritephdrs(); a += elfwritephdrs();
a += elfwriteshdrs(); a += elfwriteshdrs();
cflush(); cflush();
if(a > ELFRESERVE) if(a+elfwriteinterp() > ELFRESERVE)
diag("ELFRESERVE too small: %d > %d", a, ELFRESERVE); diag("ELFRESERVE too small: %d > %d", a, ELFRESERVE);
break; break;
case Hwindows: case Hwindows:
......
...@@ -551,22 +551,6 @@ doelf(void) ...@@ -551,22 +551,6 @@ doelf(void)
elfstr[ElfStrGnuVersion] = addstring(shstrtab, ".gnu.version"); elfstr[ElfStrGnuVersion] = addstring(shstrtab, ".gnu.version");
elfstr[ElfStrGnuVersionR] = addstring(shstrtab, ".gnu.version_r"); elfstr[ElfStrGnuVersionR] = addstring(shstrtab, ".gnu.version_r");
/* interpreter string */
if(interpreter == nil) {
switch(HEADTYPE) {
case Hlinux:
interpreter = linuxdynld;
break;
case Hfreebsd:
interpreter = freebsddynld;
break;
}
}
s = lookup(".interp", 0);
s->type = SELFROSECT;
s->reachable = 1;
addstring(s, interpreter);
/* dynamic symbol table - first entry all zeros */ /* dynamic symbol table - first entry all zeros */
s = lookup(".dynsym", 0); s = lookup(".dynsym", 0);
s->type = SELFROSECT; s->type = SELFROSECT;
...@@ -964,7 +948,17 @@ asmb(void) ...@@ -964,7 +948,17 @@ asmb(void)
sh->type = SHT_PROGBITS; sh->type = SHT_PROGBITS;
sh->flags = SHF_ALLOC; sh->flags = SHF_ALLOC;
sh->addralign = 1; sh->addralign = 1;
shsym(sh, lookup(".interp", 0)); if(interpreter == nil) {
switch(HEADTYPE) {
case Hlinux:
interpreter = linuxdynld;
break;
case Hfreebsd:
interpreter = freebsddynld;
break;
}
}
elfinterp(sh, startva, interpreter);
ph = newElfPhdr(); ph = newElfPhdr();
ph->type = PT_INTERP; ph->type = PT_INTERP;
...@@ -1148,7 +1142,7 @@ asmb(void) ...@@ -1148,7 +1142,7 @@ asmb(void)
a += elfwritephdrs(); a += elfwritephdrs();
a += elfwriteshdrs(); a += elfwriteshdrs();
cflush(); cflush();
if(a > ELFRESERVE) if(a+elfwriteinterp() > ELFRESERVE)
diag("ELFRESERVE too small: %d > %d", a, ELFRESERVE); diag("ELFRESERVE too small: %d > %d", a, ELFRESERVE);
break; break;
......
...@@ -871,7 +871,7 @@ dodata(void) ...@@ -871,7 +871,7 @@ dodata(void)
/* data */ /* data */
sect = addsection(&segdata, ".data", 06); sect = addsection(&segdata, ".data", 06);
sect->vaddr = 0; sect->vaddr = datsize;
for(; s != nil && s->type < SBSS; s = s->next) { for(; s != nil && s->type < SBSS; s = s->next) {
s->type = SDATA; s->type = SDATA;
t = s->size; t = s->size;
......
...@@ -19,6 +19,7 @@ static int elf64; ...@@ -19,6 +19,7 @@ static int elf64;
static ElfEhdr hdr; static ElfEhdr hdr;
static ElfPhdr *phdr[NSECT]; static ElfPhdr *phdr[NSECT];
static ElfShdr *shdr[NSECT]; static ElfShdr *shdr[NSECT];
static char *interp;
typedef struct Elfstring Elfstring; typedef struct Elfstring Elfstring;
struct Elfstring struct Elfstring
...@@ -303,6 +304,32 @@ elfwritedynentsymsize(Sym *s, int tag, Sym *t) ...@@ -303,6 +304,32 @@ elfwritedynentsymsize(Sym *s, int tag, Sym *t)
addsize(s, t); addsize(s, t);
} }
int
elfwriteinterp(void)
{
int n;
if(interp == nil)
return 0;
n = strlen(interp)+1;
cseek(ELFRESERVE-n);
cwrite(interp, n);
return n;
}
void
elfinterp(ElfShdr *sh, uint64 startva, char *p)
{
int n;
interp = p;
n = strlen(interp)+1;
sh->addr = startva + ELFRESERVE - n;
sh->off = ELFRESERVE - n;
sh->size = n;
}
extern int nelfsym; extern int nelfsym;
int elfverneed; int elfverneed;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment