mirror of
https://github.com/golang/go
synced 2024-11-25 09:07:58 -07:00
8l: emit DWARF in ELF.
R=rsc, r, ken2 CC=golang-dev https://golang.org/cl/2004046
This commit is contained in:
parent
5c603dbb75
commit
b433552ebc
@ -641,8 +641,7 @@ asmb(void)
|
||||
|
||||
dwarfemitdebugsections();
|
||||
}
|
||||
} else
|
||||
if(dlm){
|
||||
} else if(dlm){
|
||||
seek(cout, HEADR+textsize+datsize, 0);
|
||||
asmdyn();
|
||||
cflush();
|
||||
|
@ -394,9 +394,9 @@ Prog* brchain(Prog*);
|
||||
Prog* brloop(Prog*);
|
||||
void buildop(void);
|
||||
void cflush(void);
|
||||
vlong cpos(void);
|
||||
void ckoff(Sym*, int32);
|
||||
Prog* copyp(Prog*);
|
||||
vlong cpos(void);
|
||||
double cputime(void);
|
||||
void datblk(int32, int32);
|
||||
void deadcode(void);
|
||||
|
@ -9,8 +9,10 @@ TARG=8l
|
||||
|
||||
OFILES=\
|
||||
asm.$O\
|
||||
dwarf.$O\
|
||||
elf.$O\
|
||||
enam.$O\
|
||||
go.$O\
|
||||
lib.$O\
|
||||
list.$O\
|
||||
macho.$O\
|
||||
@ -19,11 +21,12 @@ OFILES=\
|
||||
pass.$O\
|
||||
pe.$O\
|
||||
span.$O\
|
||||
go.$O\
|
||||
|
||||
|
||||
HFILES=\
|
||||
l.h\
|
||||
../8l/8.out.h\
|
||||
../ld/dwarf.h\
|
||||
../ld/elf.h\
|
||||
../ld/macho.h\
|
||||
../ld/pe.h\
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "l.h"
|
||||
#include "../ld/lib.h"
|
||||
#include "../ld/elf.h"
|
||||
#include "../ld/dwarf.h"
|
||||
#include "../ld/macho.h"
|
||||
#include "../ld/pe.h"
|
||||
|
||||
@ -293,6 +294,7 @@ doelf(void)
|
||||
elfstr[ElfStrGosymcounts] = addstring(shstrtab, ".gosymcounts");
|
||||
elfstr[ElfStrGosymtab] = addstring(shstrtab, ".gosymtab");
|
||||
elfstr[ElfStrGopclntab] = addstring(shstrtab, ".gopclntab");
|
||||
dwarfaddshstrings(shstrtab);
|
||||
}
|
||||
elfstr[ElfStrShstrtab] = addstring(shstrtab, ".shstrtab");
|
||||
|
||||
@ -649,8 +651,13 @@ asmb(void)
|
||||
lputl(symsize);
|
||||
lputl(lcsize);
|
||||
cflush();
|
||||
if(!debug['s']) {
|
||||
seek(cout, symo+8+symsize+lcsize, 0);
|
||||
if(debug['v'])
|
||||
Bprint(&bso, "%5.2f dwarf\n", cputime());
|
||||
dwarfemitdebugsections();
|
||||
}
|
||||
else if(dlm){
|
||||
} else if(dlm){
|
||||
seek(cout, HEADR+textsize+datsize, 0);
|
||||
asmdyn();
|
||||
cflush();
|
||||
@ -1042,6 +1049,8 @@ asmb(void)
|
||||
sh->size = w;
|
||||
sh->addralign = 1;
|
||||
sh->addr = symdatva + 8 + symsize;
|
||||
|
||||
dwarfaddheaders();
|
||||
}
|
||||
|
||||
sh = newElfShstrtab(elfstr[ElfStrShstrtab]);
|
||||
@ -1118,6 +1127,13 @@ cflush(void)
|
||||
cbc = sizeof(buf.cbuf);
|
||||
}
|
||||
|
||||
/* Current position in file */
|
||||
vlong
|
||||
cpos(void)
|
||||
{
|
||||
return seek(cout, 0, 1) + sizeof(buf.cbuf) - cbc;
|
||||
}
|
||||
|
||||
void
|
||||
datblk(int32 s, int32 n)
|
||||
{
|
||||
|
@ -345,6 +345,7 @@ Prog* brloop(Prog*);
|
||||
void cflush(void);
|
||||
void ckoff(Sym*, int32);
|
||||
Prog* copyp(Prog*);
|
||||
vlong cpos(void);
|
||||
double cputime(void);
|
||||
void datblk(int32, int32);
|
||||
void diag(char*, ...);
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "../ld/lib.h"
|
||||
#include "../ld/elf.h"
|
||||
#include "../ld/macho.h"
|
||||
#include "../ld/dwarf.h"
|
||||
#include "../ld/pe.h"
|
||||
#include <ar.h>
|
||||
|
||||
@ -604,6 +605,7 @@ loop:
|
||||
histfrogp++;
|
||||
} else
|
||||
collapsefrog(s);
|
||||
dwarfaddfrag(s->value, s->name);
|
||||
}
|
||||
goto loop;
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ enum
|
||||
{
|
||||
DW_ABRV_NULL,
|
||||
DW_ABRV_COMPUNIT,
|
||||
DW_ABRV_FUNCTION,
|
||||
DW_NABRV
|
||||
};
|
||||
|
||||
@ -60,6 +61,14 @@ struct DWAbbrev {
|
||||
DW_AT_stmt_list, DW_FORM_data4,
|
||||
0, 0
|
||||
},
|
||||
/* FUNCTION */
|
||||
{
|
||||
DW_TAG_subprogram, DW_CHILDREN_no,
|
||||
DW_AT_name, DW_FORM_string,
|
||||
DW_AT_low_pc, DW_FORM_addr,
|
||||
DW_AT_high_pc, DW_FORM_addr,
|
||||
0, 0
|
||||
},
|
||||
};
|
||||
|
||||
/*
|
||||
@ -116,6 +125,18 @@ newattr(DWDie *die, uint8 attr, int cls, vlong value, char *data)
|
||||
return a;
|
||||
}
|
||||
|
||||
static void addrput(vlong addr)
|
||||
{
|
||||
switch(PtrSize) {
|
||||
case 4:
|
||||
LPUT(addr);
|
||||
break;
|
||||
case 8:
|
||||
VPUT(addr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
uleb128put(uvlong v)
|
||||
{
|
||||
@ -149,7 +170,7 @@ putattr(int form, int cls, vlong value, char *data)
|
||||
{
|
||||
switch(form) {
|
||||
case DW_FORM_addr: // address
|
||||
VPUT(value);
|
||||
addrput(value);
|
||||
break;
|
||||
|
||||
case DW_FORM_block1: // block
|
||||
@ -280,6 +301,17 @@ reverselist(DWDie** list)
|
||||
*list = prev;
|
||||
}
|
||||
|
||||
static void
|
||||
reversetree(DWDie** list)
|
||||
{
|
||||
DWDie *die;
|
||||
|
||||
reverselist(list);
|
||||
if (*list != nil && abbrevs[(*list)->abbrev].children)
|
||||
for (die = *list; die != nil; die = die->link)
|
||||
reversetree(&die->child);
|
||||
}
|
||||
|
||||
/*
|
||||
* Filename fragments for the line history stack.
|
||||
*/
|
||||
@ -320,7 +352,7 @@ decodez(char *s)
|
||||
return 0;
|
||||
}
|
||||
f = ftab[o];
|
||||
if (!f) {
|
||||
if (f == nil) {
|
||||
diag("corrupt z entry");
|
||||
return 0;
|
||||
}
|
||||
@ -667,24 +699,34 @@ writelines(void)
|
||||
strnput(histfile[i], strlen(histfile[i]) + 4);
|
||||
// 4 zeros: the string termination + 3 fields.
|
||||
}
|
||||
|
||||
pc = p->pc;
|
||||
currfile = 1;
|
||||
lc = 1;
|
||||
llc = 1;
|
||||
|
||||
cput(0); // start extended opcode
|
||||
uleb128put(1 + sizeof pc);
|
||||
uleb128put(1 + PtrSize);
|
||||
cput(DW_LNE_set_address);
|
||||
VPUT(pc);
|
||||
addrput(pc);
|
||||
}
|
||||
if (!p->from.sym->reachable)
|
||||
continue;
|
||||
if (unitstart < 0) {
|
||||
diag("Reachable code before seeing any history: %P", p);
|
||||
diag("reachable code before seeing any history: %P", p);
|
||||
continue;
|
||||
}
|
||||
|
||||
dwinfo->child = newdie(dwinfo->child, DW_ABRV_FUNCTION);
|
||||
newattr(dwinfo->child, DW_AT_name, DW_CLS_STRING, strlen(s->name), s->name);
|
||||
newattr(dwinfo->child, DW_AT_low_pc, DW_CLS_ADDRESS, p->pc, 0);
|
||||
if (debug['v'] > 1)
|
||||
print("frame offset: %d\n", p->to.offset);
|
||||
// newattr(dwinfo->child, DW_AT_return_addr, DW_CLS_BLOCK, p->to.offset, 0);
|
||||
|
||||
for(q = p; q != P && (q == p || q->as != ATEXT); q = q->link) {
|
||||
lh = searchhist(q->line);
|
||||
if (!lh) {
|
||||
if (lh == nil) {
|
||||
diag("corrupt history or bad absolute line: %P", q);
|
||||
continue;
|
||||
}
|
||||
@ -704,6 +746,7 @@ writelines(void)
|
||||
lc = q->line;
|
||||
llc = lline;
|
||||
}
|
||||
newattr(dwinfo->child, DW_AT_high_pc, DW_CLS_ADDRESS, pc, 0);
|
||||
}
|
||||
flushunit(pc, unitstart);
|
||||
linesize = cpos() - lineo;
|
||||
@ -718,7 +761,7 @@ writeinfo(void)
|
||||
DWDie *compunit;
|
||||
vlong unitstart;
|
||||
|
||||
reverselist(&dwinfo);
|
||||
reversetree(&dwinfo);
|
||||
|
||||
infoo = cpos();
|
||||
|
||||
@ -730,7 +773,7 @@ writeinfo(void)
|
||||
LPUT(0); // unit_length (*), will be filled in later.
|
||||
WPUT(3); // version
|
||||
LPUT(0); // debug_abbrev_offset (*)
|
||||
cput(8); // address_size
|
||||
cput(PtrSize); // address_size
|
||||
|
||||
putdie(compunit);
|
||||
|
||||
@ -749,7 +792,8 @@ writeinfo(void)
|
||||
/*
|
||||
* Elf sections.
|
||||
*/
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
ElfStrDebugAbbrev,
|
||||
ElfStrDebugAranges,
|
||||
ElfStrDebugFrame,
|
||||
|
Loading…
Reference in New Issue
Block a user