mirror of
https://github.com/golang/go
synced 2024-11-19 17:14:44 -07:00
5l, 8l: add ELF symbol table to binary
Should have been added long ago. Thanks to Alex Brainman for noticing. R=ken2 CC=golang-dev https://golang.org/cl/4538046
This commit is contained in:
parent
4fca395321
commit
70798eaad6
@ -73,6 +73,8 @@ enum {
|
|||||||
ElfStrGosymcounts,
|
ElfStrGosymcounts,
|
||||||
ElfStrGosymtab,
|
ElfStrGosymtab,
|
||||||
ElfStrGopclntab,
|
ElfStrGopclntab,
|
||||||
|
ElfStrSymtab,
|
||||||
|
ElfStrStrtab,
|
||||||
ElfStrShstrtab,
|
ElfStrShstrtab,
|
||||||
ElfStrRelPlt,
|
ElfStrRelPlt,
|
||||||
ElfStrPlt,
|
ElfStrPlt,
|
||||||
@ -163,6 +165,8 @@ doelf(void)
|
|||||||
elfstr[ElfStrGosymcounts] = addstring(shstrtab, ".gosymcounts");
|
elfstr[ElfStrGosymcounts] = addstring(shstrtab, ".gosymcounts");
|
||||||
elfstr[ElfStrGosymtab] = addstring(shstrtab, ".gosymtab");
|
elfstr[ElfStrGosymtab] = addstring(shstrtab, ".gosymtab");
|
||||||
elfstr[ElfStrGopclntab] = addstring(shstrtab, ".gopclntab");
|
elfstr[ElfStrGopclntab] = addstring(shstrtab, ".gopclntab");
|
||||||
|
elfstr[ElfStrSymtab] = addstring(shstrtab, ".symtab");
|
||||||
|
elfstr[ElfStrStrtab] = addstring(shstrtab, ".strtab");
|
||||||
}
|
}
|
||||||
elfstr[ElfStrShstrtab] = addstring(shstrtab, ".shstrtab");
|
elfstr[ElfStrShstrtab] = addstring(shstrtab, ".shstrtab");
|
||||||
|
|
||||||
@ -288,7 +292,7 @@ asmb(void)
|
|||||||
{
|
{
|
||||||
int32 t;
|
int32 t;
|
||||||
int a, dynsym;
|
int a, dynsym;
|
||||||
uint32 va, fo, w, startva;
|
uint32 va, fo, w, symo, startva, elfsymo, elfstro, elfsymsize;
|
||||||
int strtabsize;
|
int strtabsize;
|
||||||
ElfEhdr *eh;
|
ElfEhdr *eh;
|
||||||
ElfPhdr *ph, *pph;
|
ElfPhdr *ph, *pph;
|
||||||
@ -301,6 +305,10 @@ asmb(void)
|
|||||||
Bprint(&bso, "%5.2f asmb\n", cputime());
|
Bprint(&bso, "%5.2f asmb\n", cputime());
|
||||||
Bflush(&bso);
|
Bflush(&bso);
|
||||||
|
|
||||||
|
elfsymsize = 0;
|
||||||
|
elfstro = 0;
|
||||||
|
elfsymo = 0;
|
||||||
|
|
||||||
sect = segtext.sect;
|
sect = segtext.sect;
|
||||||
seek(cout, sect->vaddr - segtext.vaddr + segtext.fileoff, 0);
|
seek(cout, sect->vaddr - segtext.vaddr + segtext.fileoff, 0);
|
||||||
codeblk(sect->vaddr, sect->len);
|
codeblk(sect->vaddr, sect->len);
|
||||||
@ -322,15 +330,30 @@ asmb(void)
|
|||||||
seek(cout, sect->vaddr - segtext.vaddr + segtext.fileoff, 0);
|
seek(cout, sect->vaddr - segtext.vaddr + segtext.fileoff, 0);
|
||||||
datblk(sect->vaddr, sect->len);
|
datblk(sect->vaddr, sect->len);
|
||||||
|
|
||||||
|
if(iself) {
|
||||||
|
/* index of elf text section; needed by asmelfsym, double-checked below */
|
||||||
|
/* !debug['d'] causes extra sections before the .text section */
|
||||||
|
elftextsh = 1;
|
||||||
|
if(!debug['d']) {
|
||||||
|
elftextsh += 10;
|
||||||
|
if(elfverneed)
|
||||||
|
elftextsh += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* output symbol table */
|
/* output symbol table */
|
||||||
symsize = 0;
|
symsize = 0;
|
||||||
lcsize = 0;
|
lcsize = 0;
|
||||||
|
symo = 0;
|
||||||
if(!debug['s']) {
|
if(!debug['s']) {
|
||||||
// TODO: rationalize
|
// TODO: rationalize
|
||||||
if(debug['v'])
|
if(debug['v'])
|
||||||
Bprint(&bso, "%5.2f sym\n", cputime());
|
Bprint(&bso, "%5.2f sym\n", cputime());
|
||||||
Bflush(&bso);
|
Bflush(&bso);
|
||||||
switch(HEADTYPE) {
|
switch(HEADTYPE) {
|
||||||
|
default:
|
||||||
|
if(iself)
|
||||||
|
goto ElfSym;
|
||||||
case Hnoheader:
|
case Hnoheader:
|
||||||
case Hrisc:
|
case Hrisc:
|
||||||
case Hixp1200:
|
case Hixp1200:
|
||||||
@ -345,14 +368,29 @@ asmb(void)
|
|||||||
OFFSET += rnd(segdata.filelen, 4096);
|
OFFSET += rnd(segdata.filelen, 4096);
|
||||||
seek(cout, OFFSET, 0);
|
seek(cout, OFFSET, 0);
|
||||||
break;
|
break;
|
||||||
case Hlinux:
|
ElfSym:
|
||||||
OFFSET += segdata.filelen;
|
symo = rnd(HEADR+segtext.filelen, INITRND)+segdata.filelen;
|
||||||
seek(cout, rnd(OFFSET, INITRND), 0);
|
symo = rnd(symo, INITRND);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(!debug['s'])
|
if(iself) {
|
||||||
|
if(debug['v'])
|
||||||
|
Bprint(&bso, "%5.2f elfsym\n", cputime());
|
||||||
|
elfsymo = symo+8+symsize+lcsize;
|
||||||
|
seek(cout, elfsymo, 0);
|
||||||
|
asmelfsym32();
|
||||||
|
cflush();
|
||||||
|
elfstro = seek(cout, 0, 1);
|
||||||
|
elfsymsize = elfstro - elfsymo;
|
||||||
|
ewrite(cout, elfstrdat, elfstrsize);
|
||||||
|
|
||||||
|
// if(debug['v'])
|
||||||
|
// Bprint(&bso, "%5.2f dwarf\n", cputime());
|
||||||
|
// dwarfemitdebugsections();
|
||||||
|
}
|
||||||
asmthumbmap();
|
asmthumbmap();
|
||||||
cflush();
|
cflush();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cursym = nil;
|
cursym = nil;
|
||||||
@ -541,6 +579,8 @@ asmb(void)
|
|||||||
ph->flags = PF_W+PF_R;
|
ph->flags = PF_W+PF_R;
|
||||||
ph->align = 4;
|
ph->align = 4;
|
||||||
|
|
||||||
|
if(elftextsh != eh->shnum)
|
||||||
|
diag("elftextsh = %d, want %d", elftextsh, eh->shnum);
|
||||||
for(sect=segtext.sect; sect!=nil; sect=sect->next)
|
for(sect=segtext.sect; sect!=nil; sect=sect->next)
|
||||||
elfshbits(sect);
|
elfshbits(sect);
|
||||||
for(sect=segdata.sect; sect!=nil; sect=sect->next)
|
for(sect=segdata.sect; sect!=nil; sect=sect->next)
|
||||||
@ -558,6 +598,22 @@ asmb(void)
|
|||||||
sh->flags = SHF_ALLOC;
|
sh->flags = SHF_ALLOC;
|
||||||
sh->addralign = 1;
|
sh->addralign = 1;
|
||||||
shsym(sh, lookup("pclntab", 0));
|
shsym(sh, lookup("pclntab", 0));
|
||||||
|
|
||||||
|
sh = newElfShdr(elfstr[ElfStrSymtab]);
|
||||||
|
sh->type = SHT_SYMTAB;
|
||||||
|
sh->off = elfsymo;
|
||||||
|
sh->size = elfsymsize;
|
||||||
|
sh->addralign = 4;
|
||||||
|
sh->entsize = 16;
|
||||||
|
sh->link = eh->shnum; // link to strtab
|
||||||
|
|
||||||
|
sh = newElfShdr(elfstr[ElfStrStrtab]);
|
||||||
|
sh->type = SHT_STRTAB;
|
||||||
|
sh->off = elfstro;
|
||||||
|
sh->size = elfstrsize;
|
||||||
|
sh->addralign = 1;
|
||||||
|
|
||||||
|
// dwarfaddelfheaders();
|
||||||
}
|
}
|
||||||
|
|
||||||
sh = newElfShstrtab(elfstr[ElfStrShstrtab]);
|
sh = newElfShstrtab(elfstr[ElfStrShstrtab]);
|
||||||
|
@ -350,9 +350,6 @@ EXTERN Sym* fromgotype; // type symbol on last p->from read
|
|||||||
|
|
||||||
EXTERN vlong textstksiz;
|
EXTERN vlong textstksiz;
|
||||||
EXTERN vlong textarg;
|
EXTERN vlong textarg;
|
||||||
EXTERN int elfstrsize;
|
|
||||||
EXTERN char* elfstrdat;
|
|
||||||
EXTERN int elftextsh;
|
|
||||||
|
|
||||||
extern Optab optab[];
|
extern Optab optab[];
|
||||||
extern Optab* opindex[];
|
extern Optab* opindex[];
|
||||||
|
@ -532,6 +532,8 @@ doelf(void)
|
|||||||
elfstr[ElfStrGosymcounts] = addstring(shstrtab, ".gosymcounts");
|
elfstr[ElfStrGosymcounts] = addstring(shstrtab, ".gosymcounts");
|
||||||
elfstr[ElfStrGosymtab] = addstring(shstrtab, ".gosymtab");
|
elfstr[ElfStrGosymtab] = addstring(shstrtab, ".gosymtab");
|
||||||
elfstr[ElfStrGopclntab] = addstring(shstrtab, ".gopclntab");
|
elfstr[ElfStrGopclntab] = addstring(shstrtab, ".gopclntab");
|
||||||
|
elfstr[ElfStrSymtab] = addstring(shstrtab, ".symtab");
|
||||||
|
elfstr[ElfStrStrtab] = addstring(shstrtab, ".strtab");
|
||||||
dwarfaddshstrings(shstrtab);
|
dwarfaddshstrings(shstrtab);
|
||||||
}
|
}
|
||||||
elfstr[ElfStrShstrtab] = addstring(shstrtab, ".shstrtab");
|
elfstr[ElfStrShstrtab] = addstring(shstrtab, ".shstrtab");
|
||||||
@ -658,7 +660,7 @@ asmb(void)
|
|||||||
{
|
{
|
||||||
int32 v, magic;
|
int32 v, magic;
|
||||||
int a, dynsym;
|
int a, dynsym;
|
||||||
uint32 symo, startva, machlink;
|
uint32 symo, startva, machlink, elfsymo, elfstro, elfsymsize;
|
||||||
ElfEhdr *eh;
|
ElfEhdr *eh;
|
||||||
ElfPhdr *ph, *pph;
|
ElfPhdr *ph, *pph;
|
||||||
ElfShdr *sh;
|
ElfShdr *sh;
|
||||||
@ -670,6 +672,10 @@ asmb(void)
|
|||||||
Bprint(&bso, "%5.2f asmb\n", cputime());
|
Bprint(&bso, "%5.2f asmb\n", cputime());
|
||||||
Bflush(&bso);
|
Bflush(&bso);
|
||||||
|
|
||||||
|
elfsymsize = 0;
|
||||||
|
elfstro = 0;
|
||||||
|
elfsymo = 0;
|
||||||
|
|
||||||
sect = segtext.sect;
|
sect = segtext.sect;
|
||||||
seek(cout, sect->vaddr - segtext.vaddr + segtext.fileoff, 0);
|
seek(cout, sect->vaddr - segtext.vaddr + segtext.fileoff, 0);
|
||||||
codeblk(sect->vaddr, sect->len);
|
codeblk(sect->vaddr, sect->len);
|
||||||
@ -741,10 +747,8 @@ asmb(void)
|
|||||||
symo = rnd(symo, PEFILEALIGN);
|
symo = rnd(symo, PEFILEALIGN);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(!debug['s']) {
|
|
||||||
seek(cout, symo, 0);
|
|
||||||
|
|
||||||
if(HEADTYPE == Hplan9x32) {
|
if(HEADTYPE == Hplan9x32) {
|
||||||
|
seek(cout, symo, 0);
|
||||||
asmplan9sym();
|
asmplan9sym();
|
||||||
cflush();
|
cflush();
|
||||||
|
|
||||||
@ -756,14 +760,22 @@ asmb(void)
|
|||||||
|
|
||||||
cflush();
|
cflush();
|
||||||
}
|
}
|
||||||
|
} else if(iself) {
|
||||||
|
if(debug['v'])
|
||||||
|
Bprint(&bso, "%5.2f elfsym\n", cputime());
|
||||||
|
elfsymo = symo+8+symsize+lcsize;
|
||||||
|
seek(cout, elfsymo, 0);
|
||||||
|
asmelfsym32();
|
||||||
|
cflush();
|
||||||
|
elfstro = seek(cout, 0, 1);
|
||||||
|
elfsymsize = elfstro - elfsymo;
|
||||||
|
ewrite(cout, elfstrdat, elfstrsize);
|
||||||
|
|
||||||
} else if(HEADTYPE != Hwindows) {
|
|
||||||
if(debug['v'])
|
if(debug['v'])
|
||||||
Bprint(&bso, "%5.2f dwarf\n", cputime());
|
Bprint(&bso, "%5.2f dwarf\n", cputime());
|
||||||
dwarfemitdebugsections();
|
dwarfemitdebugsections();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(debug['v'])
|
if(debug['v'])
|
||||||
Bprint(&bso, "%5.2f headr\n", cputime());
|
Bprint(&bso, "%5.2f headr\n", cputime());
|
||||||
Bflush(&bso);
|
Bflush(&bso);
|
||||||
@ -1082,6 +1094,20 @@ asmb(void)
|
|||||||
sh->addralign = 1;
|
sh->addralign = 1;
|
||||||
shsym(sh, lookup("pclntab", 0));
|
shsym(sh, lookup("pclntab", 0));
|
||||||
|
|
||||||
|
sh = newElfShdr(elfstr[ElfStrSymtab]);
|
||||||
|
sh->type = SHT_SYMTAB;
|
||||||
|
sh->off = elfsymo;
|
||||||
|
sh->size = elfsymsize;
|
||||||
|
sh->addralign = 4;
|
||||||
|
sh->entsize = 16;
|
||||||
|
sh->link = eh->shnum; // link to strtab
|
||||||
|
|
||||||
|
sh = newElfShdr(elfstr[ElfStrStrtab]);
|
||||||
|
sh->type = SHT_STRTAB;
|
||||||
|
sh->off = elfstro;
|
||||||
|
sh->size = elfstrsize;
|
||||||
|
sh->addralign = 1;
|
||||||
|
|
||||||
dwarfaddelfheaders();
|
dwarfaddelfheaders();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -978,6 +978,10 @@ ElfShdr* elfshbits(Section*);
|
|||||||
void elfsetstring(char*, int);
|
void elfsetstring(char*, int);
|
||||||
void elfaddverneed(Sym*);
|
void elfaddverneed(Sym*);
|
||||||
|
|
||||||
|
EXTERN int elfstrsize;
|
||||||
|
EXTERN char* elfstrdat;
|
||||||
|
EXTERN int elftextsh;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Total amount of space to reserve at the start of the file
|
* Total amount of space to reserve at the start of the file
|
||||||
* for Header, PHeaders, SHeaders, and interp.
|
* for Header, PHeaders, SHeaders, and interp.
|
||||||
|
@ -186,6 +186,7 @@ vlong addsize(Sym*, Sym*);
|
|||||||
vlong adduint8(Sym*, uint8);
|
vlong adduint8(Sym*, uint8);
|
||||||
vlong adduint16(Sym*, uint16);
|
vlong adduint16(Sym*, uint16);
|
||||||
void asmsym(void);
|
void asmsym(void);
|
||||||
|
void asmelfsym32(void);
|
||||||
void asmelfsym64(void);
|
void asmelfsym64(void);
|
||||||
void asmplan9sym(void);
|
void asmplan9sym(void);
|
||||||
void strnput(char*, int);
|
void strnput(char*, int);
|
||||||
|
Loading…
Reference in New Issue
Block a user