Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion sys/src/cmd/1l/mkfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
</$objtype/mkfile

TARG=1l
OFILES= asm.$O obj.$O optab.$O pass.$O span.$O list.$O enam.$O compat.$O dwarf.$O lib.$O go.$O
OFILES= asm.$O obj.$O optab.$O pass.$O span.$O list.$O enam.$O compat.$O dwarf.$O lib.$O go.$O elf.$O

HFILES= l.h ../2c/2.out.h ../cc/compat.h
APEXPROOT=../../../..
Expand All @@ -26,4 +26,7 @@ lib.$O: ../ld/lib.c
go.$O: ../ld/go.c
$CC $CFLAGS -I../ld ../ld/go.c

elf.$O: ../ld/elf.c
$CC $CFLAGS -I../ld ../ld/elf.c

compat.$O: ../cc/compat
5 changes: 4 additions & 1 deletion sys/src/cmd/2l/mkfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
</$objtype/mkfile

TARG=2l
OFILES= asm.$O obj.$O optab.$O pass.$O span.$O list.$O enam.$O compat.$O dwarf.$O lib.$O go.$O
OFILES= asm.$O obj.$O optab.$O pass.$O span.$O list.$O enam.$O compat.$O dwarf.$O lib.$O go.$O elf.$O

HFILES= l.h ../2c/2.out.h ../cc/compat.h
APEXPROOT=../../../..
Expand All @@ -26,4 +26,7 @@ lib.$O: ../ld/lib.c
go.$O: ../ld/go.c
$CC $CFLAGS -I../ld ../ld/go.c

elf.$O: ../ld/elf.c
$CC $CFLAGS -I../ld ../ld/elf.c

compat.$O: ../cc/compat
6 changes: 5 additions & 1 deletion sys/src/cmd/5l/mkfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ OFILES= asm.$O\
# sched.$O\
dwarf.$O\
lib.$O\
go.$O
go.$O\
elf.$O

HFILES= l.h ../5c/5.out.h ../cc/compat.h
APEXPROOT=../../../..
Expand All @@ -38,4 +39,7 @@ lib.$O: ../ld/lib.c
go.$O: ../ld/go.c
$CC $CFLAGS -I../ld ../ld/go.c

elf.$O: ../ld/elf.c
$CC $CFLAGS -I../ld ../ld/elf.c

compat.$O: ../cc/compat
5 changes: 4 additions & 1 deletion sys/src/cmd/7l/mkfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
</$objtype/mkfile

TARG=7l
OFILES= asm.$O obj.$O optab.$O pass.$O span.$O list.$O enam.$O compat.$O asmout.$O bits.$O cnam.$O dyn.$O mod.$O noop.$O dwarf.$O lib.$O go.$O
OFILES= asm.$O obj.$O optab.$O pass.$O span.$O list.$O enam.$O compat.$O asmout.$O bits.$O cnam.$O dyn.$O mod.$O noop.$O dwarf.$O lib.$O go.$O elf.$O

HFILES= l.h ../7c/7.out.h ../cc/compat.h
APEXPROOT=../../../..
Expand All @@ -26,4 +26,7 @@ lib.$O: ../ld/lib.c
go.$O: ../ld/go.c
$CC $CFLAGS -I../ld ../ld/go.c

elf.$O: ../ld/elf.c
$CC $CFLAGS -I../ld ../ld/elf.c

compat.$O: ../cc/compat
5 changes: 4 additions & 1 deletion sys/src/cmd/8l/mkfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
</$objtype/mkfile

TARG=8l
OFILES= asm.$O obj.$O optab.$O pass.$O span.$O list.$O enam.$O compat.$O dwarf.$O lib.$O go.$O
OFILES= asm.$O obj.$O optab.$O pass.$O span.$O list.$O enam.$O compat.$O dwarf.$O lib.$O go.$O elf.$O

HFILES= l.h ../8c/8.out.h ../cc/compat.h
APEXPROOT=../../../..
Expand All @@ -26,4 +26,7 @@ lib.$O: ../ld/lib.c
go.$O: ../ld/go.c
$CC $CFLAGS -I../ld ../ld/go.c

elf.$O: ../ld/elf.c
$CC $CFLAGS -I../ld ../ld/elf.c

compat.$O: ../cc/compat
5 changes: 4 additions & 1 deletion sys/src/cmd/9l/mkfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
</$objtype/mkfile

TARG=9l
OFILES= asm.$O obj.$O optab.$O pass.$O span.$O list.$O enam.$O compat.$O asmout.$O cnam.$O cputime.$O noop.$O sched.$O dwarf.$O lib.$O go.$O
OFILES= asm.$O obj.$O optab.$O pass.$O span.$O list.$O enam.$O compat.$O asmout.$O cnam.$O cputime.$O noop.$O sched.$O dwarf.$O lib.$O go.$O elf.$O

HFILES= l.h ../9c/9.out.h ../cc/compat.h
APEXPROOT=../../../..
Expand All @@ -26,4 +26,7 @@ lib.$O: ../ld/lib.c
go.$O: ../ld/go.c
$CC $CFLAGS -I../ld ../ld/go.c

elf.$O: ../ld/elf.c
$CC $CFLAGS -I../ld ../ld/elf.c

compat.$O: ../cc/compat
5 changes: 4 additions & 1 deletion sys/src/cmd/kl/mkfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
</$objtype/mkfile

TARG=kl
OFILES= asm.$O obj.$O optab.$O pass.$O span.$O list.$O enam.$O compat.$O noop.$O sched.$O dwarf.$O lib.$O go.$O
OFILES= asm.$O obj.$O optab.$O pass.$O span.$O list.$O enam.$O compat.$O noop.$O sched.$O dwarf.$O lib.$O go.$O elf.$O

HFILES= l.h ../kc/k.out.h ../cc/compat.h
APEXPROOT=../../../..
Expand All @@ -26,4 +26,7 @@ lib.$O: ../ld/lib.c
go.$O: ../ld/go.c
$CC $CFLAGS -I../ld ../ld/go.c

elf.$O: ../ld/elf.c
$CC $CFLAGS -I../ld ../ld/elf.c

compat.$O: ../cc/compat
77 changes: 18 additions & 59 deletions sys/src/cmd/ld/dwarf.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#include "lib.h"
#include "dwarf.h"
#include "dwarf_defs.h"
#include "elf.h"

/* Calculate stack adjustment from AADJSP instruction (x86 only) */
static long
getspadj(Prog *p)
Expand Down Expand Up @@ -53,14 +51,14 @@ extern void free(void*);
* Offsets and sizes of the debug_* sections in the cout file.
*/

static vlong abbrevo;
static vlong abbrevsize;
static vlong lineo;
static vlong linesize;
static vlong infoo;
static vlong infosize;
static vlong frameo;
static vlong framesize;
vlong dwarfabbrevo;
vlong dwarfabbrevsize;
vlong dwarflineo;
vlong dwarflinesize;
vlong dwarfinfoo;
vlong dwarfinfosize;
vlong dwarfframeo;
vlong dwarfframesize;

/*
* Basic I/O
Expand Down Expand Up @@ -188,7 +186,7 @@ writeabbrev(void)
{
int i, n;

abbrevo = cpos();
dwarfabbrevo = cpos();
for (i = 1; i < DW_NABRV; i++) {
// See section 7.5.3
uleb128put(i);
Expand All @@ -201,7 +199,7 @@ writeabbrev(void)
(n+1) * sizeof(DWAttrForm));
}
cput(0);
abbrevsize = cpos() - abbrevo;
dwarfabbrevsize = cpos() - dwarfabbrevo;
}

/*
Expand Down Expand Up @@ -726,7 +724,7 @@ writelines(void)
lc = 1;
llc = 1;
currfile = -1;
lineo = cpos();
dwarflineo = cpos();

#ifdef PROG_HAS_PCOND
for(cursym = textp; cursym != P; cursym = cursym->pcond) {
Expand Down Expand Up @@ -758,7 +756,7 @@ writelines(void)
dwinfo = newdie(dwinfo, DW_ABRV_COMPUNIT);
newattr(dwinfo, DW_AT_name, DW_CLS_STRING, strlen(unitname), unitname);
newattr(dwinfo, DW_AT_language, DW_CLS_CONSTANT, guesslang(unitname), 0);
newattr(dwinfo, DW_AT_stmt_list, DW_CLS_PTR, unitstart - lineo, 0);
newattr(dwinfo, DW_AT_stmt_list, DW_CLS_PTR, unitstart - dwarflineo, 0);
newattr(dwinfo, DW_AT_low_pc, DW_CLS_ADDRESS, cursym->pc, 0);
// Write .debug_line Line Number Program Header (sec 6.2.4)
// Fields marked with (*) must be changed for 64-bit dwarf
Expand Down Expand Up @@ -841,7 +839,7 @@ writelines(void)
}

flushunit(epc, unitstart);
linesize = cpos() - lineo;
dwarflinesize = cpos() - dwarflineo;
}

/*
Expand Down Expand Up @@ -880,7 +878,7 @@ writeframes(void)
vlong fdeo, fdesize, pad, cfa, pc;
Prog *p;

frameo = cpos();
dwarfframeo = cpos();

// Emit the CIE, Section 6.4.1
LPUT(CIERESERVE); // initial length, must be multiple of PtrSize
Expand All @@ -899,7 +897,7 @@ writeframes(void)
uleb128put(-PtrSize / DATAALIGNMENTFACTOR); // at cfa - x*4

// 4 is to exclude the length field.
pad = CIERESERVE + frameo + 4 - cpos();
pad = CIERESERVE + dwarfframeo + 4 - cpos();
if (pad < 0) {
diag("CIERESERVE too small by %lld bytes.", -pad);
errorexit();
Expand Down Expand Up @@ -952,7 +950,7 @@ writeframes(void)
seek(cout, fdeo + 4 + fdesize, 0);
}
cflush();
framesize = cpos() - frameo;
dwarfframesize = cpos() - dwarfframeo;
}

/*
Expand All @@ -966,7 +964,7 @@ writeinfo(void)

reversetree(&dwinfo);

infoo = cpos();
dwarfinfoo = cpos();

for (compunit = dwinfo; compunit; compunit = compunit->link) {
unitstart = cpos();
Expand All @@ -989,7 +987,7 @@ writeinfo(void)
}

cflush();
infosize = cpos() - infoo;
dwarfinfosize = cpos() - dwarfinfoo;
}

void
Expand All @@ -1001,42 +999,3 @@ dwarfemitdebugsections(void)
writeinfo();
}

Comment on lines 999 to 1001

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The removal of dwarfaddelfheaders from the shared dwarf.c and its relocation to elf.c (in sys/src/cmd/ld/elf.c) requires that all linkers using dwarf.c also link elf.c. While this PR updates several linkers (1l, 2l, 5l, 7l, 8l, 9l, kl, ql, vl), it appears to miss others that typically reside in the same toolchain, such as 0l (sparc), 4l (mips), and most importantly 6l (amd64). This will likely cause link errors for those architectures if they call dwarfaddelfheaders during the linking process.

/*
* dwarfaddelfheaders: create ELF section headers for the DWARF sections.
* Called after dwarfemitdebugsections() so that offsets and sizes are known.
*/
void
dwarfaddelfheaders(void)
{
ElfShdr *sh;

if(abbrevsize > 0) {
sh = elfshname(".debug_abbrev");
sh->type = SHT_PROGBITS;
sh->off = abbrevo;
sh->size = abbrevsize;
sh->addralign = 1;
}
if(linesize > 0) {
sh = elfshname(".debug_line");
sh->type = SHT_PROGBITS;
sh->off = lineo;
sh->size = linesize;
sh->addralign = 1;
}
if(framesize > 0) {
sh = elfshname(".debug_frame");
sh->type = SHT_PROGBITS;
sh->off = frameo;
sh->size = framesize;
sh->addralign = 1;
}
if(infosize > 0) {
sh = elfshname(".debug_info");
sh->type = SHT_PROGBITS;
sh->off = infoo;
sh->size = infosize;
sh->addralign = 1;
}
}

14 changes: 14 additions & 0 deletions sys/src/cmd/ld/dwarf.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
// license that can be found in the LICENSE file.


/*
* Offsets and sizes of the DWARF debug sections, set by dwarfemitdebugsections().
* Exposed so that elf.c (and any future format handler) can create section headers
* without pulling in ELF-specific code into dwarf.c.
*/
extern vlong dwarfabbrevo;
extern vlong dwarfabbrevsize;
extern vlong dwarflineo;
extern vlong dwarflinesize;
extern vlong dwarfinfoo;
extern vlong dwarfinfosize;
extern vlong dwarfframeo;
extern vlong dwarfframesize;

/*
* Register 'f' symbol file fragments. Doing this while parsing the
* .6 input saves a pass over the symbol table later.
Expand Down
41 changes: 41 additions & 0 deletions sys/src/cmd/ld/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "l.h"
#include "lib.h"
#include "elf.h"
#include "dwarf.h"

#define NSECT 48

Expand Down Expand Up @@ -290,3 +291,43 @@ elfwritestrtab(void)
cflush();
return elfstrtabsz;
}

/*
* dwarfaddelfheaders: create ELF section headers for the DWARF sections.
* Called after dwarfemitdebugsections() so that offsets and sizes are known.
* Lives here (not dwarf.c) so that only linkers that link elf.$O get it.
*/
void
dwarfaddelfheaders(void)
{
ElfShdr *sh;

if(dwarfabbrevsize > 0) {
sh = elfshname(".debug_abbrev");
sh->type = SHT_PROGBITS;
sh->off = dwarfabbrevo;
sh->size = dwarfabbrevsize;
sh->addralign = 1;
}
if(dwarflinesize > 0) {
sh = elfshname(".debug_line");
sh->type = SHT_PROGBITS;
sh->off = dwarflineo;
sh->size = dwarflinesize;
sh->addralign = 1;
}
if(dwarfframesize > 0) {
sh = elfshname(".debug_frame");
sh->type = SHT_PROGBITS;
sh->off = dwarfframeo;
sh->size = dwarfframesize;
sh->addralign = 1;
}
if(dwarfinfosize > 0) {
sh = elfshname(".debug_info");
sh->type = SHT_PROGBITS;
sh->off = dwarfinfoo;
sh->size = dwarfinfosize;
sh->addralign = 1;
}
}
5 changes: 4 additions & 1 deletion sys/src/cmd/ql/mkfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
</$objtype/mkfile

TARG=ql
OFILES= asm.$O obj.$O optab.$O pass.$O span.$O list.$O enam.$O compat.$O asmout.$O cnam.$O noop.$O sched.$O dwarf.$O lib.$O go.$O
OFILES= asm.$O obj.$O optab.$O pass.$O span.$O list.$O enam.$O compat.$O asmout.$O cnam.$O noop.$O sched.$O dwarf.$O lib.$O go.$O elf.$O

HFILES= l.h ../qc/q.out.h ../cc/compat.h
APEXPROOT=../../../..
Expand All @@ -26,4 +26,7 @@ lib.$O: ../ld/lib.c
go.$O: ../ld/go.c
$CC $CFLAGS -I../ld ../ld/go.c

elf.$O: ../ld/elf.c
$CC $CFLAGS -I../ld ../ld/elf.c

compat.$O: ../cc/compat
5 changes: 4 additions & 1 deletion sys/src/cmd/vl/mkfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
</$objtype/mkfile

TARG=vl
OFILES= asm.$O obj.$O optab.$O pass.$O span.$O list.$O enam.$O compat.$O noop.$O sched.$O dwarf.$O lib.$O go.$O
OFILES= asm.$O obj.$O optab.$O pass.$O span.$O list.$O enam.$O compat.$O noop.$O sched.$O dwarf.$O lib.$O go.$O elf.$O

HFILES= l.h ../vc/v.out.h ../cc/compat.h
APEXPROOT=../../../..
Expand All @@ -26,4 +26,7 @@ lib.$O: ../ld/lib.c
go.$O: ../ld/go.c
$CC $CFLAGS -I../ld ../ld/go.c

elf.$O: ../ld/elf.c
$CC $CFLAGS -I../ld ../ld/elf.c

compat.$O: ../cc/compat
Loading