Commit ca9098ee authored by Luuk van Dijk's avatar Luuk van Dijk

Dwarf output for 6l.

Part 1, general scaffolding and pc/lc sections.

R=rsc, r, ken2
CC=golang-dev
https://golang.org/cl/1987042
parent 632417e5
...@@ -9,6 +9,7 @@ TARG=\ ...@@ -9,6 +9,7 @@ TARG=\
OFILES=\ OFILES=\
asm.$O\ asm.$O\
dwarf.$O\
elf.$O\ elf.$O\
enam.$O\ enam.$O\
go.$O\ go.$O\
...@@ -26,6 +27,7 @@ HFILES=\ ...@@ -26,6 +27,7 @@ HFILES=\
../ld/lib.h\ ../ld/lib.h\
../ld/elf.h\ ../ld/elf.h\
../ld/macho.h\ ../ld/macho.h\
../ld/dwarf.h\
$(TARG): $(OFILES) $(TARG): $(OFILES)
$(LD) -o $(TARG) -L"$(GOROOT)"/lib $(OFILES) -lbio -l9 $(LD) -o $(TARG) -L"$(GOROOT)"/lib $(OFILES) -lbio -l9
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "l.h" #include "l.h"
#include "../ld/lib.h" #include "../ld/lib.h"
#include "../ld/elf.h" #include "../ld/elf.h"
#include "../ld/dwarf.h"
#include "../ld/macho.h" #include "../ld/macho.h"
#define Dbufslop 100 #define Dbufslop 100
...@@ -300,10 +301,9 @@ doelf(void) ...@@ -300,10 +301,9 @@ 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");
if(debug['e']) { elfstr[ElfStrSymtab] = addstring(shstrtab, ".symtab");
elfstr[ElfStrSymtab] = addstring(shstrtab, ".symtab"); elfstr[ElfStrStrtab] = addstring(shstrtab, ".strtab");
elfstr[ElfStrStrtab] = addstring(shstrtab, ".strtab"); dwarfaddshstrings(shstrtab);
}
} }
elfstr[ElfStrShstrtab] = addstring(shstrtab, ".shstrtab"); elfstr[ElfStrShstrtab] = addstring(shstrtab, ".shstrtab");
...@@ -546,7 +546,7 @@ asmb(void) ...@@ -546,7 +546,7 @@ asmb(void)
seek(cout, v, 0); seek(cout, v, 0);
/* index of elf text section; needed by asmelfsym, double-checked below */ /* index of elf text section; needed by asmelfsym, double-checked below */
/* debug['d'] causes 8 extra sections before the .text section */ /* !debug['d'] causes 8 extra sections before the .text section */
elftextsh = 1; elftextsh = 1;
if(!debug['d']) if(!debug['d'])
elftextsh += 8; elftextsh += 8;
...@@ -627,7 +627,7 @@ asmb(void) ...@@ -627,7 +627,7 @@ asmb(void)
lputl(symsize); lputl(symsize);
lputl(lcsize); lputl(lcsize);
cflush(); cflush();
if(!debug['s'] && debug['e']) { if(!debug['s']) {
elfsymo = symo+8+symsize+lcsize; elfsymo = symo+8+symsize+lcsize;
seek(cout, elfsymo, 0); seek(cout, elfsymo, 0);
asmelfsym(); asmelfsym();
...@@ -635,7 +635,12 @@ asmb(void) ...@@ -635,7 +635,12 @@ asmb(void)
elfstro = seek(cout, 0, 1); elfstro = seek(cout, 0, 1);
elfsymsize = elfstro - elfsymo; elfsymsize = elfstro - elfsymo;
write(cout, elfstrdat, elfstrsize); write(cout, elfstrdat, elfstrsize);
}
if(debug['v'])
Bprint(&bso, "%5.2f dwarf\n", cputime());
dwarfemitdebugsections();
}
} else } else
if(dlm){ if(dlm){
seek(cout, HEADR+textsize+datsize, 0); seek(cout, HEADR+textsize+datsize, 0);
...@@ -910,22 +915,22 @@ asmb(void) ...@@ -910,22 +915,22 @@ asmb(void)
sh->size = w; sh->size = w;
sh->addralign = 1; sh->addralign = 1;
sh->addr = symdatva + 8 + symsize; sh->addr = symdatva + 8 + symsize;
if(debug['e']) { sh = newElfShdr(elfstr[ElfStrSymtab]);
sh = newElfShdr(elfstr[ElfStrSymtab]); sh->type = SHT_SYMTAB;
sh->type = SHT_SYMTAB; sh->off = elfsymo;
sh->off = elfsymo; sh->size = elfsymsize;
sh->size = elfsymsize; sh->addralign = 8;
sh->addralign = 8; sh->entsize = 24;
sh->entsize = 24; sh->link = eh->shnum; // link to strtab
sh->link = eh->shnum; // link to strtab
sh = newElfShdr(elfstr[ElfStrStrtab]);
sh = newElfShdr(elfstr[ElfStrStrtab]); sh->type = SHT_STRTAB;
sh->type = SHT_STRTAB; sh->off = elfstro;
sh->off = elfstro; sh->size = elfstrsize;
sh->size = elfstrsize; sh->addralign = 1;
sh->addralign = 1;
} dwarfaddheaders();
} }
sh = newElfShstrtab(elfstr[ElfStrShstrtab]); sh = newElfShstrtab(elfstr[ElfStrShstrtab]);
...@@ -977,6 +982,13 @@ cflush(void) ...@@ -977,6 +982,13 @@ cflush(void)
cbc = sizeof(buf.cbuf); cbc = sizeof(buf.cbuf);
} }
/* Current position in file */
vlong
cpos(void)
{
return seek(cout, 0, 1) + sizeof(buf.cbuf) - cbc;
}
void void
outa(int n, uchar *cast, uchar *map, vlong l) outa(int n, uchar *cast, uchar *map, vlong l)
{ {
...@@ -1322,4 +1334,3 @@ rnd(vlong v, vlong r) ...@@ -1322,4 +1334,3 @@ rnd(vlong v, vlong r)
v -= c; v -= c;
return v; return v;
} }
...@@ -394,6 +394,7 @@ Prog* brchain(Prog*); ...@@ -394,6 +394,7 @@ Prog* brchain(Prog*);
Prog* brloop(Prog*); Prog* brloop(Prog*);
void buildop(void); void buildop(void);
void cflush(void); void cflush(void);
vlong cpos(void);
void ckoff(Sym*, int32); void ckoff(Sym*, int32);
Prog* copyp(Prog*); Prog* copyp(Prog*);
double cputime(void); double cputime(void);
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "../ld/lib.h" #include "../ld/lib.h"
#include "../ld/elf.h" #include "../ld/elf.h"
#include "../ld/macho.h" #include "../ld/macho.h"
#include "../ld/dwarf.h"
#include <ar.h> #include <ar.h>
char *noname = "<none>"; char *noname = "<none>";
...@@ -575,6 +576,7 @@ loop: ...@@ -575,6 +576,7 @@ loop:
histfrogp++; histfrogp++;
} else } else
collapsefrog(s); collapsefrog(s);
dwarfaddfrag(s->value, s->name);
} }
goto loop; goto loop;
} }
...@@ -1058,4 +1060,3 @@ doprof2(void) ...@@ -1058,4 +1060,3 @@ doprof2(void)
} }
} }
} }
This diff is collapsed.
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
/*
* Register 'f' symbol file fragments. Doing this while parsing the
* .6 input saves a pass over the symbol table later.
*/
void dwarfaddfrag(int n, char* frag);
/*
* Add the dwarf section names to the ELF
* s[ection]h[eader]str[ing]tab.
*/
void dwarfaddshstrings(Sym *shstrtab);
/*
* Emit debug_abbrevs, debug_info and debug_line sections to current
* offset in cout.
*/
void dwarfemitdebugsections(void);
/*
* Add ELF section headers pointing to the sections emitted in
* dwarfemitdebugsections.
*/
void dwarfaddheaders(void);
This diff is collapsed.
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