diff --git a/sys/src/cmd/1l/mkfile b/sys/src/cmd/1l/mkfile index f021f8867..9324fb5ce 100644 --- a/sys/src/cmd/1l/mkfile +++ b/sys/src/cmd/1l/mkfile @@ -1,7 +1,7 @@ pcond) { @@ -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 @@ -841,7 +839,7 @@ writelines(void) } flushunit(epc, unitstart); - linesize = cpos() - lineo; + dwarflinesize = cpos() - dwarflineo; } /* @@ -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 @@ -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(); @@ -952,7 +950,7 @@ writeframes(void) seek(cout, fdeo + 4 + fdesize, 0); } cflush(); - framesize = cpos() - frameo; + dwarfframesize = cpos() - dwarfframeo; } /* @@ -966,7 +964,7 @@ writeinfo(void) reversetree(&dwinfo); - infoo = cpos(); + dwarfinfoo = cpos(); for (compunit = dwinfo; compunit; compunit = compunit->link) { unitstart = cpos(); @@ -989,7 +987,7 @@ writeinfo(void) } cflush(); - infosize = cpos() - infoo; + dwarfinfosize = cpos() - dwarfinfoo; } void @@ -1001,42 +999,3 @@ dwarfemitdebugsections(void) writeinfo(); } -/* - * 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; - } -} - diff --git a/sys/src/cmd/ld/dwarf.h b/sys/src/cmd/ld/dwarf.h index e4bde9a9a..7ef34b95f 100644 --- a/sys/src/cmd/ld/dwarf.h +++ b/sys/src/cmd/ld/dwarf.h @@ -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. diff --git a/sys/src/cmd/ld/elf.c b/sys/src/cmd/ld/elf.c index 98bc82793..b6b4cef1c 100644 --- a/sys/src/cmd/ld/elf.c +++ b/sys/src/cmd/ld/elf.c @@ -7,6 +7,7 @@ #include "l.h" #include "lib.h" #include "elf.h" +#include "dwarf.h" #define NSECT 48 @@ -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; + } +} diff --git a/sys/src/cmd/ql/mkfile b/sys/src/cmd/ql/mkfile index 63562839d..89cfa2f9a 100644 --- a/sys/src/cmd/ql/mkfile +++ b/sys/src/cmd/ql/mkfile @@ -1,7 +1,7 @@