diff options
author | H. Peter Anvin <hpa@zytor.com> | 2008-06-08 18:39:55 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2008-06-08 18:39:55 -0700 |
commit | cb38f505e48e47fda39fb1956b71ea571b9ea5a8 (patch) | |
tree | 4031171402ba1911d0d07537bb919b9f556325d6 /output/outelf64.c | |
parent | 435f1863be5627fd4541e283bb12727b7a91445c (diff) | |
download | nasm-cb38f505e48e47fda39fb1956b71ea571b9ea5a8.tar.gz nasm-cb38f505e48e47fda39fb1956b71ea571b9ea5a8.tar.bz2 nasm-cb38f505e48e47fda39fb1956b71ea571b9ea5a8.zip |
WSAA: make the WSAA macros contain their own buffer
Make the WSAA macros contain their own buffer definitions. This
eliminates the need to have a separate "workbuf" declared in the
outelf backends, which isn't even used for anything else, except for a
few completely redundant strcpys.
Note: these macros probably should be replaced with actual
functions. The overhead of the function call is likely to be more
than offset by lower icache footprint.
Diffstat (limited to 'output/outelf64.c')
-rw-r--r-- | output/outelf64.c | 226 |
1 files changed, 112 insertions, 114 deletions
diff --git a/output/outelf64.c b/output/outelf64.c index 3811a03..f4b6af5 100644 --- a/output/outelf64.c +++ b/output/outelf64.c @@ -267,7 +267,6 @@ static int8_t line_base = -5, line_range = 14, opcode_base = 13; static int arangeslen, arangesrellen, pubnameslen, infolen, inforellen, abbrevlen, linelen, linerellen, framelen, loclen; static int64_t dwarf_infosym, dwarf_abbrevsym, dwarf_linesym; -static char workbuf[1024]; static struct dfmt df_dwarf; @@ -1915,8 +1914,8 @@ void dwarf64_output(int type, void *param) /* check for file change */ if (!(inx == dwarf_csect->file)) { - WSAACHAR(plinep,workbuf,DW_LNS_set_file); - WSAACHAR(plinep,workbuf,inx); + WSAACHAR(plinep,DW_LNS_set_file); + WSAACHAR(plinep,inx); dwarf_csect->file = inx; } /* check for line change */ @@ -1927,18 +1926,18 @@ void dwarf64_output(int type, void *param) soc = (ln - line_base) + (line_range * aa) + opcode_base; if (ln >= line_base && ln < maxln && soc < 256) { - WSAACHAR(plinep,workbuf,soc); + WSAACHAR(plinep,soc); } else { if (ln) { - WSAACHAR(plinep,workbuf,DW_LNS_advance_line); + WSAACHAR(plinep,DW_LNS_advance_line); saa_wleb128s(plinep,ln); } if (aa) { - WSAACHAR(plinep,workbuf,DW_LNS_advance_pc); + WSAACHAR(plinep,DW_LNS_advance_pc); saa_wleb128u(plinep,aa); } } @@ -1953,6 +1952,7 @@ void dwarf64_output(int type, void *param) void dwarf64_generate(void) { + static const char nasm_signature[] = "NASM " NASM_VER; uint8_t *pbuf; int indx; struct linelist *ftentry; @@ -1965,14 +1965,14 @@ void dwarf64_generate(void) /* and build aranges section */ paranges = saa_init(1L); parangesrel = saa_init(1L); - WSAASHORT(paranges,workbuf,3); /* dwarf version */ - WSAADLONG(parangesrel,workbuf, paranges->datalen+4); - WSAADLONG(parangesrel,workbuf, (dwarf_infosym << 32) + R_X86_64_32); /* reloc to info */ - WSAADLONG(parangesrel,workbuf, (uint64_t) 0); - WSAALONG(paranges,workbuf,0); /* offset into info */ - WSAACHAR(paranges,workbuf,8); /* pointer size */ - WSAACHAR(paranges,workbuf,0); /* not segmented */ - WSAALONG(paranges,workbuf,0); /* padding */ + WSAASHORT(paranges,3); /* dwarf version */ + WSAADLONG(parangesrel, paranges->datalen+4); + WSAADLONG(parangesrel, (dwarf_infosym << 32) + R_X86_64_32); /* reloc to info */ + WSAADLONG(parangesrel, 0); + WSAALONG(paranges,0); /* offset into info */ + WSAACHAR(paranges,8); /* pointer size */ + WSAACHAR(paranges,0); /* not segmented */ + WSAALONG(paranges,0); /* padding */ /* iterate though sectlist entries */ psect = dwarf_fsect; totlen = 0; @@ -1981,25 +1981,25 @@ void dwarf64_generate(void) { plinep = psect->psaa; /* Line Number Program Epilogue */ - WSAACHAR(plinep,workbuf,2); /* std op 2 */ - WSAACHAR(plinep,workbuf,(sects[psect->section]->len)-psect->offset); - WSAACHAR(plinep,workbuf,DW_LNS_extended_op); - WSAACHAR(plinep,workbuf,1); /* operand length */ - WSAACHAR(plinep,workbuf,DW_LNE_end_sequence); + WSAACHAR(plinep,2); /* std op 2 */ + WSAACHAR(plinep,(sects[psect->section]->len)-psect->offset); + WSAACHAR(plinep,DW_LNS_extended_op); + WSAACHAR(plinep,1); /* operand length */ + WSAACHAR(plinep,DW_LNE_end_sequence); totlen += plinep->datalen; /* range table relocation entry */ - WSAADLONG(parangesrel,workbuf, paranges->datalen + 4); - WSAADLONG(parangesrel,workbuf, ((uint64_t) (psect->section + 2) << 32) + R_X86_64_64); - WSAADLONG(parangesrel,workbuf, (uint64_t) 0); + WSAADLONG(parangesrel, paranges->datalen + 4); + WSAADLONG(parangesrel, ((uint64_t) (psect->section + 2) << 32) + R_X86_64_64); + WSAADLONG(parangesrel, (uint64_t) 0); /* range table entry */ - WSAADLONG(paranges,workbuf,0x0000); /* range start */ - WSAADLONG(paranges,workbuf,sects[psect->section]->len); /* range length */ + WSAADLONG(paranges,0x0000); /* range start */ + WSAADLONG(paranges,sects[psect->section]->len); /* range length */ highaddr += sects[psect->section]->len; /* done with this entry */ psect = psect->next; } - WSAADLONG(paranges,workbuf,0); /* null address */ - WSAADLONG(paranges,workbuf,0); /* null length */ + WSAADLONG(paranges,0); /* null address */ + WSAADLONG(paranges,0); /* null length */ saalen = paranges->datalen; arangeslen = saalen + 4; arangesbuf = pbuf = nasm_malloc(arangeslen); @@ -2015,10 +2015,10 @@ void dwarf64_generate(void) /* build pubnames section */ ppubnames = saa_init(1L); - WSAASHORT(ppubnames,workbuf,3); /* dwarf version */ - WSAALONG(ppubnames,workbuf,0); /* offset into info */ - WSAALONG(ppubnames,workbuf,0); /* space used in info */ - WSAALONG(ppubnames,workbuf,0); /* end of list */ + WSAASHORT(ppubnames,3); /* dwarf version */ + WSAALONG(ppubnames,0); /* offset into info */ + WSAALONG(ppubnames,0); /* space used in info */ + WSAALONG(ppubnames,0); /* end of list */ saalen = ppubnames->datalen; pubnameslen = saalen + 4; pubnamesbuf = pbuf = nasm_malloc(pubnameslen); @@ -2029,37 +2029,35 @@ void dwarf64_generate(void) /* build info section */ pinfo = saa_init(1L); pinforel = saa_init(1L); - WSAASHORT(pinfo,workbuf,3); /* dwarf version */ - WSAADLONG(pinforel,workbuf, pinfo->datalen + 4); - WSAADLONG(pinforel,workbuf, (dwarf_abbrevsym << 32) + R_X86_64_32); /* reloc to abbrev */ - WSAADLONG(pinforel,workbuf, (uint64_t) 0); - WSAALONG(pinfo,workbuf,0); /* offset into abbrev */ - WSAACHAR(pinfo,workbuf,8); /* pointer size */ - WSAACHAR(pinfo,workbuf,1); /* abbrviation number LEB128u */ - WSAADLONG(pinforel,workbuf, pinfo->datalen + 4); - WSAADLONG(pinforel,workbuf, ((uint64_t)(dwarf_fsect->section + 2) << 32) + R_X86_64_64); - WSAADLONG(pinforel,workbuf, (uint64_t) 0); - WSAADLONG(pinfo,workbuf,0); /* DW_AT_low_pc */ - WSAADLONG(pinforel,workbuf, pinfo->datalen + 4); - WSAADLONG(pinforel,workbuf, ((uint64_t)(dwarf_fsect->section + 2) << 32) + R_X86_64_64); - WSAADLONG(pinforel,workbuf, (uint64_t) 0); - WSAADLONG(pinfo,workbuf,highaddr); /* DW_AT_high_pc */ - WSAADLONG(pinforel,workbuf, pinfo->datalen + 4); - WSAADLONG(pinforel,workbuf, (dwarf_linesym << 32) + R_X86_64_32); /* reloc to line */ - WSAADLONG(pinforel,workbuf, (uint64_t) 0); - WSAALONG(pinfo,workbuf,0); /* DW_AT_stmt_list */ - strcpy(workbuf,elf_module); /* input file name */ - saa_wbytes(pinfo, workbuf, (int32_t)(strlen(elf_module) + 1)); - sprintf(workbuf, "NASM %s", NASM_VER); - saa_wbytes(pinfo, workbuf, (int32_t)(strlen(workbuf) + 1)); - WSAASHORT(pinfo,workbuf,DW_LANG_Mips_Assembler); - WSAACHAR(pinfo,workbuf,2); /* abbrviation number LEB128u */ - WSAADLONG(pinforel,workbuf, pinfo->datalen + 4); - WSAADLONG(pinforel,workbuf, ((uint64_t)(dwarf_fsect->section + 2) << 32) + R_X86_64_64); - WSAADLONG(pinforel,workbuf, (uint64_t) 0); - WSAADLONG(pinfo,workbuf,0); /* DW_AT_low_pc */ - WSAADLONG(pinfo,workbuf,0); /* DW_AT_frame_base */ - WSAACHAR(pinfo,workbuf,0); /* end of entries */ + WSAASHORT(pinfo,3); /* dwarf version */ + WSAADLONG(pinforel, pinfo->datalen + 4); + WSAADLONG(pinforel, (dwarf_abbrevsym << 32) + R_X86_64_32); /* reloc to abbrev */ + WSAADLONG(pinforel, 0); + WSAALONG(pinfo,0); /* offset into abbrev */ + WSAACHAR(pinfo,8); /* pointer size */ + WSAACHAR(pinfo,1); /* abbrviation number LEB128u */ + WSAADLONG(pinforel, pinfo->datalen + 4); + WSAADLONG(pinforel, ((uint64_t)(dwarf_fsect->section + 2) << 32) + R_X86_64_64); + WSAADLONG(pinforel, 0); + WSAADLONG(pinfo,0); /* DW_AT_low_pc */ + WSAADLONG(pinforel, pinfo->datalen + 4); + WSAADLONG(pinforel, ((uint64_t)(dwarf_fsect->section + 2) << 32) + R_X86_64_64); + WSAADLONG(pinforel, 0); + WSAADLONG(pinfo,highaddr); /* DW_AT_high_pc */ + WSAADLONG(pinforel, pinfo->datalen + 4); + WSAADLONG(pinforel, (dwarf_linesym << 32) + R_X86_64_32); /* reloc to line */ + WSAADLONG(pinforel, 0); + WSAALONG(pinfo,0); /* DW_AT_stmt_list */ + saa_wbytes(pinfo, elf_module, strlen(elf_module)+1); + saa_wbytes(pinfo, nasm_signature, strlen(nasm_signature)+1); + WSAASHORT(pinfo,DW_LANG_Mips_Assembler); + WSAACHAR(pinfo,2); /* abbrviation number LEB128u */ + WSAADLONG(pinforel, pinfo->datalen + 4); + WSAADLONG(pinforel, ((uint64_t)(dwarf_fsect->section + 2) << 32) + R_X86_64_64); + WSAADLONG(pinforel, 0); + WSAADLONG(pinfo,0); /* DW_AT_low_pc */ + WSAADLONG(pinfo,0); /* DW_AT_frame_base */ + WSAACHAR(pinfo,0); /* end of entries */ saalen = pinfo->datalen; infolen = saalen + 4; infobuf = pbuf = nasm_malloc(infolen); @@ -2075,32 +2073,32 @@ void dwarf64_generate(void) /* build abbrev section */ pabbrev = saa_init(1L); - WSAACHAR(pabbrev,workbuf,1); /* entry number LEB128u */ - WSAACHAR(pabbrev,workbuf,DW_TAG_compile_unit); /* tag LEB128u */ - WSAACHAR(pabbrev,workbuf,1); /* has children */ + WSAACHAR(pabbrev,1); /* entry number LEB128u */ + WSAACHAR(pabbrev,DW_TAG_compile_unit); /* tag LEB128u */ + WSAACHAR(pabbrev,1); /* has children */ /* the following attributes and forms are all LEB128u values */ - WSAACHAR(pabbrev,workbuf,DW_AT_low_pc); - WSAACHAR(pabbrev,workbuf,DW_FORM_addr); - WSAACHAR(pabbrev,workbuf,DW_AT_high_pc); - WSAACHAR(pabbrev,workbuf,DW_FORM_addr); - WSAACHAR(pabbrev,workbuf,DW_AT_stmt_list); - WSAACHAR(pabbrev,workbuf,DW_FORM_data4); - WSAACHAR(pabbrev,workbuf,DW_AT_name); - WSAACHAR(pabbrev,workbuf,DW_FORM_string); - WSAACHAR(pabbrev,workbuf,DW_AT_producer); - WSAACHAR(pabbrev,workbuf,DW_FORM_string); - WSAACHAR(pabbrev,workbuf,DW_AT_language); - WSAACHAR(pabbrev,workbuf,DW_FORM_data2); - WSAASHORT(pabbrev,workbuf,0); /* end of entry */ + WSAACHAR(pabbrev,DW_AT_low_pc); + WSAACHAR(pabbrev,DW_FORM_addr); + WSAACHAR(pabbrev,DW_AT_high_pc); + WSAACHAR(pabbrev,DW_FORM_addr); + WSAACHAR(pabbrev,DW_AT_stmt_list); + WSAACHAR(pabbrev,DW_FORM_data4); + WSAACHAR(pabbrev,DW_AT_name); + WSAACHAR(pabbrev,DW_FORM_string); + WSAACHAR(pabbrev,DW_AT_producer); + WSAACHAR(pabbrev,DW_FORM_string); + WSAACHAR(pabbrev,DW_AT_language); + WSAACHAR(pabbrev,DW_FORM_data2); + WSAASHORT(pabbrev,0); /* end of entry */ /* LEB128u usage same as above */ - WSAACHAR(pabbrev,workbuf,2); /* entry number */ - WSAACHAR(pabbrev,workbuf,DW_TAG_subprogram); - WSAACHAR(pabbrev,workbuf,0); /* no children */ - WSAACHAR(pabbrev,workbuf,DW_AT_low_pc); - WSAACHAR(pabbrev,workbuf,DW_FORM_addr); - WSAACHAR(pabbrev,workbuf,DW_AT_frame_base); - WSAACHAR(pabbrev,workbuf,DW_FORM_data4); - WSAASHORT(pabbrev,workbuf,0); /* end of entry */ + WSAACHAR(pabbrev,2); /* entry number */ + WSAACHAR(pabbrev,DW_TAG_subprogram); + WSAACHAR(pabbrev,0); /* no children */ + WSAACHAR(pabbrev,DW_AT_low_pc); + WSAACHAR(pabbrev,DW_FORM_addr); + WSAACHAR(pabbrev,DW_AT_frame_base); + WSAACHAR(pabbrev,DW_FORM_data4); + WSAASHORT(pabbrev,0); /* end of entry */ abbrevlen = saalen = pabbrev->datalen; abbrevbuf = pbuf = nasm_malloc(saalen); saa_rnbytes(pabbrev, pbuf, saalen); @@ -2109,37 +2107,37 @@ void dwarf64_generate(void) /* build line section */ /* prolog */ plines = saa_init(1L); - WSAACHAR(plines,workbuf,1); /* Minimum Instruction Length */ - WSAACHAR(plines,workbuf,1); /* Initial value of 'is_stmt' */ - WSAACHAR(plines,workbuf,line_base); /* Line Base */ - WSAACHAR(plines,workbuf,line_range); /* Line Range */ - WSAACHAR(plines,workbuf,opcode_base); /* Opcode Base */ + WSAACHAR(plines,1); /* Minimum Instruction Length */ + WSAACHAR(plines,1); /* Initial value of 'is_stmt' */ + WSAACHAR(plines,line_base); /* Line Base */ + WSAACHAR(plines,line_range); /* Line Range */ + WSAACHAR(plines,opcode_base); /* Opcode Base */ /* standard opcode lengths (# of LEB128u operands) */ - WSAACHAR(plines,workbuf,0); /* Std opcode 1 length */ - WSAACHAR(plines,workbuf,1); /* Std opcode 2 length */ - WSAACHAR(plines,workbuf,1); /* Std opcode 3 length */ - WSAACHAR(plines,workbuf,1); /* Std opcode 4 length */ - WSAACHAR(plines,workbuf,1); /* Std opcode 5 length */ - WSAACHAR(plines,workbuf,0); /* Std opcode 6 length */ - WSAACHAR(plines,workbuf,0); /* Std opcode 7 length */ - WSAACHAR(plines,workbuf,0); /* Std opcode 8 length */ - WSAACHAR(plines,workbuf,1); /* Std opcode 9 length */ - WSAACHAR(plines,workbuf,0); /* Std opcode 10 length */ - WSAACHAR(plines,workbuf,0); /* Std opcode 11 length */ - WSAACHAR(plines,workbuf,1); /* Std opcode 12 length */ + WSAACHAR(plines,0); /* Std opcode 1 length */ + WSAACHAR(plines,1); /* Std opcode 2 length */ + WSAACHAR(plines,1); /* Std opcode 3 length */ + WSAACHAR(plines,1); /* Std opcode 4 length */ + WSAACHAR(plines,1); /* Std opcode 5 length */ + WSAACHAR(plines,0); /* Std opcode 6 length */ + WSAACHAR(plines,0); /* Std opcode 7 length */ + WSAACHAR(plines,0); /* Std opcode 8 length */ + WSAACHAR(plines,1); /* Std opcode 9 length */ + WSAACHAR(plines,0); /* Std opcode 10 length */ + WSAACHAR(plines,0); /* Std opcode 11 length */ + WSAACHAR(plines,1); /* Std opcode 12 length */ /* Directory Table */ - WSAACHAR(plines,workbuf,0); /* End of table */ + WSAACHAR(plines,0); /* End of table */ /* File Name Table */ ftentry = dwarf_flist; for (indx = 0;indx<dwarf_numfiles;indx++) { saa_wbytes(plines, ftentry->filename, (int32_t)(strlen(ftentry->filename) + 1)); - WSAACHAR(plines,workbuf,0); /* directory LEB128u */ - WSAACHAR(plines,workbuf,0); /* time LEB128u */ - WSAACHAR(plines,workbuf,0); /* size LEB128u */ + WSAACHAR(plines,0); /* directory LEB128u */ + WSAACHAR(plines,0); /* time LEB128u */ + WSAACHAR(plines,0); /* size LEB128u */ ftentry = ftentry->next; } - WSAACHAR(plines,workbuf,0); /* End of table */ + WSAACHAR(plines,0); /* End of table */ linepoff = plines->datalen; linelen = linepoff + totlen + 10; linebuf = pbuf = nasm_malloc(linelen); @@ -2157,9 +2155,9 @@ void dwarf64_generate(void) psect = dwarf_fsect; for (indx = 0; indx < dwarf_nsections; indx++) { - WSAADLONG(plinesrel,workbuf, linepoff); - WSAADLONG(plinesrel,workbuf, ((uint64_t) (psect->section + 2) << 32) + R_X86_64_64); - WSAADLONG(plinesrel,workbuf, (uint64_t) 0); + WSAADLONG(plinesrel, linepoff); + WSAADLONG(plinesrel, ((uint64_t) (psect->section + 2) << 32) + R_X86_64_64); + WSAADLONG(plinesrel, (uint64_t) 0); plinep = psect->psaa; saalen = plinep->datalen; saa_rnbytes(plinep, pbuf, saalen); @@ -2294,10 +2292,10 @@ void dwarf64_findsect(const int index) dwarf_csect->section = index; dwarf_csect->next = 0; /* set relocatable address at start of line program */ - WSAACHAR(plinep,workbuf,DW_LNS_extended_op); - WSAACHAR(plinep,workbuf,9); /* operand length */ - WSAACHAR(plinep,workbuf,DW_LNE_set_address); - WSAADLONG(plinep,workbuf,0); /* Start Address */ + WSAACHAR(plinep,DW_LNS_extended_op); + WSAACHAR(plinep,9); /* operand length */ + WSAACHAR(plinep,DW_LNE_set_address); + WSAADLONG(plinep,0); /* Start Address */ /* if first entry */ if (!dwarf_fsect) { |