diff options
author | H. Peter Anvin <hpa@zytor.com> | 2009-07-18 21:07:17 -0400 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2009-07-18 18:43:12 -0700 |
commit | 9bd1506d5999d7c41a4cf6de2f43b97939bb260e (patch) | |
tree | d3dad5bda2b167af7dfe29cad7cb532406ddb1c4 /output | |
parent | 159178f2aa516718fcb420a281c17adc8b330492 (diff) | |
download | nasm-9bd1506d5999d7c41a4cf6de2f43b97939bb260e.tar.gz nasm-9bd1506d5999d7c41a4cf6de2f43b97939bb260e.tar.bz2 nasm-9bd1506d5999d7c41a4cf6de2f43b97939bb260e.zip |
Remove function pointers in output, simplify error handling
Remove a bunch of function pointers in the output stage; they are
never changed and don't add any value. Also make "ofile" a global
variable and let the backend use it directly.
All we ever did with these variables were stashing it in locals and
using them as-is anyway for no benefit.
Also change the global error function, nasm_error() into a true
function which invokes a function pointer internally. That lets us
use direct calls to it.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'output')
-rw-r--r-- | output/nulldbg.c | 12 | ||||
-rw-r--r-- | output/outaout.c | 145 | ||||
-rw-r--r-- | output/outas86.c | 124 | ||||
-rw-r--r-- | output/outbin.c | 159 | ||||
-rw-r--r-- | output/outcoff.c | 175 | ||||
-rw-r--r-- | output/outdbg.c | 60 | ||||
-rw-r--r-- | output/outelf32.c | 195 | ||||
-rw-r--r-- | output/outelf64.c | 196 | ||||
-rw-r--r-- | output/outform.c | 55 | ||||
-rw-r--r-- | output/outform.h | 12 | ||||
-rw-r--r-- | output/outieee.c | 67 | ||||
-rw-r--r-- | output/outlib.h | 2 | ||||
-rw-r--r-- | output/outmacho32.c | 134 | ||||
-rw-r--r-- | output/outmacho64.c | 196 | ||||
-rw-r--r-- | output/outobj.c | 128 | ||||
-rw-r--r-- | output/outrdf2.c | 70 |
16 files changed, 799 insertions, 931 deletions
diff --git a/output/nulldbg.c b/output/nulldbg.c index 54a4580..2b985c5 100644 --- a/output/nulldbg.c +++ b/output/nulldbg.c @@ -34,19 +34,17 @@ #include "nasm.h" #include "nasmlib.h" -void null_debug_init(struct ofmt *of, void *id, FILE * fp, efunc error) +void null_debug_init(void) { - (void)of; - (void)id; - (void)fp; - (void)error; } + void null_debug_linenum(const char *filename, int32_t linenumber, int32_t segto) { (void)filename; (void)linenumber; (void)segto; } + void null_debug_deflabel(char *name, int32_t segment, int64_t offset, int is_global, char *special) { @@ -56,20 +54,24 @@ void null_debug_deflabel(char *name, int32_t segment, int64_t offset, (void)is_global; (void)special; } + void null_debug_routine(const char *directive, const char *params) { (void)directive; (void)params; } + void null_debug_typevalue(int32_t type) { (void)type; } + void null_debug_output(int type, void *param) { (void)type; (void)param; } + void null_debug_cleanup(void) { } diff --git a/output/outaout.c b/output/outaout.c index c39eedd..0b3c7ca 100644 --- a/output/outaout.c +++ b/output/outaout.c @@ -49,6 +49,7 @@ #include "saa.h" #include "raa.h" #include "stdscan.h" +#include "eval.h" #include "output/outform.h" #include "output/outlib.h" @@ -129,10 +130,6 @@ static uint32_t strslen; static struct Symbol *fwds; -static FILE *aoutfp; -static efunc error; -static evalfunc evaluate; - static int bsd; static int is_pic; @@ -153,13 +150,8 @@ static int32_t aout_gotpc_sect, aout_gotoff_sect; static int32_t aout_got_sect, aout_plt_sect; static int32_t aout_sym_sect; -static void aoutg_init(FILE * fp, efunc errfunc, ldfunc ldef, - evalfunc eval) +static void aoutg_init(void) { - aoutfp = fp; - error = errfunc; - evaluate = eval; - (void)ldef; /* placate optimisers */ stext.data = saa_init(1L); stext.head = NULL; stext.tail = &stext.head; @@ -183,10 +175,10 @@ static void aoutg_init(FILE * fp, efunc errfunc, ldfunc ldef, #ifdef OF_AOUT -static void aout_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval) +static void aout_init(void) { bsd = false; - aoutg_init(fp, errfunc, ldef, eval); + aoutg_init(); aout_gotpc_sect = aout_gotoff_sect = aout_got_sect = aout_plt_sect = aout_sym_sect = NO_SEG; @@ -198,29 +190,28 @@ static void aout_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval) extern struct ofmt of_aoutb; -static void aoutb_init(FILE * fp, efunc errfunc, ldfunc ldef, - evalfunc eval) +static void aoutb_init(void) { bsd = true; - aoutg_init(fp, errfunc, ldef, eval); + aoutg_init(); is_pic = 0x00; /* may become 0x40 */ aout_gotpc_sect = seg_alloc(); - ldef("..gotpc", aout_gotpc_sect + 1, 0L, NULL, false, false, &of_aoutb, - error); + define_label("..gotpc", aout_gotpc_sect + 1, 0L, NULL, false, false, &of_aoutb, + nasm_error); aout_gotoff_sect = seg_alloc(); - ldef("..gotoff", aout_gotoff_sect + 1, 0L, NULL, false, false, - &of_aoutb, error); + define_label("..gotoff", aout_gotoff_sect + 1, 0L, NULL, false, false, + &of_aoutb, nasm_error); aout_got_sect = seg_alloc(); - ldef("..got", aout_got_sect + 1, 0L, NULL, false, false, &of_aoutb, - error); + define_label("..got", aout_got_sect + 1, 0L, NULL, false, false, &of_aoutb, + nasm_error); aout_plt_sect = seg_alloc(); - ldef("..plt", aout_plt_sect + 1, 0L, NULL, false, false, &of_aoutb, - error); + define_label("..plt", aout_plt_sect + 1, 0L, NULL, false, false, &of_aoutb, + nasm_error); aout_sym_sect = seg_alloc(); - ldef("..sym", aout_sym_sect + 1, 0L, NULL, false, false, &of_aoutb, - error); + define_label("..sym", aout_sym_sect + 1, 0L, NULL, false, false, &of_aoutb, + nasm_error); } #endif @@ -292,7 +283,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset, if (strcmp(name, "..gotpc") && strcmp(name, "..gotoff") && strcmp(name, "..got") && strcmp(name, "..plt") && strcmp(name, "..sym")) - error(ERR_NONFATAL, "unrecognised special symbol `%s'", name); + nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name); return; } @@ -315,10 +306,10 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset, stdscan_reset(); stdscan_bufptr = p; tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, NULL, 1, error, NULL); + e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL); if (e) { if (!is_simple(e)) - error(ERR_NONFATAL, "cannot use relocatable" + nasm_error(ERR_NONFATAL, "cannot use relocatable" " expression as symbol size"); else (*s)->size = reloc_value(e); @@ -387,7 +378,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset, !nasm_strnicmp(special, "object", n)) sym->type |= SYM_DATA; else - error(ERR_NONFATAL, "unrecognised symbol type `%.*s'", + nasm_error(ERR_NONFATAL, "unrecognised symbol type `%.*s'", n, special); if (special[n]) { struct tokenval tokval; @@ -396,7 +387,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset, char *saveme = stdscan_bufptr; /* bugfix? fbk 8/10/00 */ if (!bsd) { - error(ERR_NONFATAL, "Linux a.out does not support" + nasm_error(ERR_NONFATAL, "Linux a.out does not support" " symbol size information"); } else { while (special[n] && nasm_isspace(special[n])) @@ -409,7 +400,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset, stdscan_reset(); stdscan_bufptr = special + n; tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, &fwd, 0, error, + e = evaluate(stdscan, NULL, &tokval, &fwd, 0, nasm_error, NULL); if (fwd) { sym->nextfwd = fwds; @@ -417,7 +408,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset, sym->name = nasm_strdup(name); } else if (e) { if (!is_simple(e)) - error(ERR_NONFATAL, "cannot use relocatable" + nasm_error(ERR_NONFATAL, "cannot use relocatable" " expression as symbol size"); else sym->size = reloc_value(e); @@ -443,7 +434,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset, nsyms++; /* and another for the size */ if (special && !special_used) - error(ERR_NONFATAL, "no special symbol features supported here"); + nasm_error(ERR_NONFATAL, "no special symbol features supported here"); } static void aout_add_reloc(struct Section *sect, int32_t segment, @@ -511,7 +502,7 @@ static int32_t aout_add_gsym_reloc(struct Section *sect, shead = sbss.gsyms; if (!shead) { if (exact && offset != 0) - error(ERR_NONFATAL, "unable to find a suitable global symbol" + nasm_error(ERR_NONFATAL, "unable to find a suitable global symbol" " for this reference"); else aout_add_reloc(sect, segment, type, bytes); @@ -535,7 +526,7 @@ static int32_t aout_add_gsym_reloc(struct Section *sect, sym = sm; } if (!sym && exact) { - error(ERR_NONFATAL, "unable to find a suitable global symbol" + nasm_error(ERR_NONFATAL, "unable to find a suitable global symbol" " for this reference"); return 0; } @@ -582,7 +573,7 @@ static int32_t aout_add_gotoff_reloc(struct Section *sect, int32_t segment, else if (segment == sbss.index) asym = sbss.asym; if (!asym) - error(ERR_NONFATAL, "`..gotoff' relocations require a non-global" + nasm_error(ERR_NONFATAL, "`..gotoff' relocations require a non-global" " symbol in the section"); r = *sect->tail = nasm_malloc(sizeof(struct Reloc)); @@ -612,7 +603,7 @@ static void aout_out(int32_t segto, const void *data, */ if (segto == NO_SEG) { if (type != OUT_RESERVE) - error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]" + nasm_error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]" " space"); return; } @@ -624,13 +615,13 @@ static void aout_out(int32_t segto, const void *data, else if (segto == sbss.index) s = NULL; else { - error(ERR_WARNING, "attempt to assemble code in" + nasm_error(ERR_WARNING, "attempt to assemble code in" " segment %d: defaulting to `.text'", segto); s = &stext; } if (!s && type != OUT_RESERVE) { - error(ERR_WARNING, "attempt to initialize memory in the" + nasm_error(ERR_WARNING, "attempt to initialize memory in the" " BSS section: ignored"); sbss.len += realsize(type, size); return; @@ -638,7 +629,7 @@ static void aout_out(int32_t segto, const void *data, if (type == OUT_RESERVE) { if (s) { - error(ERR_WARNING, "uninitialized space declared in" + nasm_error(ERR_WARNING, "uninitialized space declared in" " %s section: zeroing", (segto == stext.index ? "code" : "data")); aout_sect_write(s, NULL, size); @@ -646,20 +637,20 @@ static void aout_out(int32_t segto, const void *data, sbss.len += size; } else if (type == OUT_RAWDATA) { if (segment != NO_SEG) - error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG"); + nasm_error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG"); aout_sect_write(s, data, size); } else if (type == OUT_ADDRESS) { addr = *(int64_t *)data; if (segment != NO_SEG) { if (segment % 2) { - error(ERR_NONFATAL, "a.out format does not support" + nasm_error(ERR_NONFATAL, "a.out format does not support" " segment base references"); } else { if (wrt == NO_SEG) { aout_add_reloc(s, segment, RELTYPE_ABSOLUTE, size); } else if (!bsd) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "Linux a.out format does not support" " any use of WRT"); wrt = NO_SEG; /* we can at least _try_ to continue */ @@ -681,11 +672,11 @@ static void aout_out(int32_t segto, const void *data, false); } else if (wrt == aout_plt_sect + 1) { is_pic = 0x40; - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "a.out format cannot produce non-PC-" "relative PLT references"); } else { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "a.out format does not support this" " use of WRT"); wrt = NO_SEG; /* we can at least _try_ to continue */ @@ -700,15 +691,15 @@ static void aout_out(int32_t segto, const void *data, aout_sect_write(s, mydata, size); } else if (type == OUT_REL2ADR) { if (segment == segto) - error(ERR_PANIC, "intra-segment OUT_REL2ADR"); + nasm_error(ERR_PANIC, "intra-segment OUT_REL2ADR"); if (segment != NO_SEG && segment % 2) { - error(ERR_NONFATAL, "a.out format does not support" + nasm_error(ERR_NONFATAL, "a.out format does not support" " segment base references"); } else { if (wrt == NO_SEG) { aout_add_reloc(s, segment, RELTYPE_RELATIVE, 2); } else if (!bsd) { - error(ERR_NONFATAL, "Linux a.out format does not support" + nasm_error(ERR_NONFATAL, "Linux a.out format does not support" " any use of WRT"); wrt = NO_SEG; /* we can at least _try_ to continue */ } else if (wrt == aout_plt_sect + 1) { @@ -717,10 +708,10 @@ static void aout_out(int32_t segto, const void *data, } else if (wrt == aout_gotpc_sect + 1 || wrt == aout_gotoff_sect + 1 || wrt == aout_got_sect + 1) { - error(ERR_NONFATAL, "a.out format cannot produce PC-" + nasm_error(ERR_NONFATAL, "a.out format cannot produce PC-" "relative GOT references"); } else { - error(ERR_NONFATAL, "a.out format does not support this" + nasm_error(ERR_NONFATAL, "a.out format does not support this" " use of WRT"); wrt = NO_SEG; /* we can at least _try_ to continue */ } @@ -730,15 +721,15 @@ static void aout_out(int32_t segto, const void *data, aout_sect_write(s, mydata, 2L); } else if (type == OUT_REL4ADR) { if (segment == segto) - error(ERR_PANIC, "intra-segment OUT_REL4ADR"); + nasm_error(ERR_PANIC, "intra-segment OUT_REL4ADR"); if (segment != NO_SEG && segment % 2) { - error(ERR_NONFATAL, "a.out format does not support" + nasm_error(ERR_NONFATAL, "a.out format does not support" " segment base references"); } else { if (wrt == NO_SEG) { aout_add_reloc(s, segment, RELTYPE_RELATIVE, 4); } else if (!bsd) { - error(ERR_NONFATAL, "Linux a.out format does not support" + nasm_error(ERR_NONFATAL, "Linux a.out format does not support" " any use of WRT"); wrt = NO_SEG; /* we can at least _try_ to continue */ } else if (wrt == aout_plt_sect + 1) { @@ -747,10 +738,10 @@ static void aout_out(int32_t segto, const void *data, } else if (wrt == aout_gotpc_sect + 1 || wrt == aout_gotoff_sect + 1 || wrt == aout_got_sect + 1) { - error(ERR_NONFATAL, "a.out format cannot produce PC-" + nasm_error(ERR_NONFATAL, "a.out format cannot produce PC-" "relative GOT references"); } else { - error(ERR_NONFATAL, "a.out format does not support this" + nasm_error(ERR_NONFATAL, "a.out format does not support this" " use of WRT"); wrt = NO_SEG; /* we can at least _try_ to continue */ } @@ -822,20 +813,20 @@ static void aout_write(void) * Emit the a.out header. */ /* OMAGIC, M_386 or MID_I386, no flags */ - fwriteint32_t(bsd ? 0x07018600 | is_pic : 0x640107L, aoutfp); - fwriteint32_t(stext.len, aoutfp); - fwriteint32_t(sdata.len, aoutfp); - fwriteint32_t(sbss.len, aoutfp); - fwriteint32_t(nsyms * 12, aoutfp); /* length of symbol table */ - fwriteint32_t(0L, aoutfp); /* object files have no entry point */ - fwriteint32_t(stext.nrelocs * 8, aoutfp); /* size of text relocs */ - fwriteint32_t(sdata.nrelocs * 8, aoutfp); /* size of data relocs */ + fwriteint32_t(bsd ? 0x07018600 | is_pic : 0x640107L, ofile); + fwriteint32_t(stext.len, ofile); + fwriteint32_t(sdata.len, ofile); + fwriteint32_t(sbss.len, ofile); + fwriteint32_t(nsyms * 12, ofile); /* length of symbol table */ + fwriteint32_t(0L, ofile); /* object files have no entry point */ + fwriteint32_t(stext.nrelocs * 8, ofile); /* size of text relocs */ + fwriteint32_t(sdata.nrelocs * 8, ofile); /* size of data relocs */ /* * Write out the code section and the data section. */ - saa_fpwrite(stext.data, aoutfp); - saa_fpwrite(sdata.data, aoutfp); + saa_fpwrite(stext.data, ofile); + saa_fpwrite(sdata.data, ofile); /* * Write out the relocations. @@ -851,8 +842,8 @@ static void aout_write(void) /* * And the string table. */ - fwriteint32_t(strslen + 4, aoutfp); /* length includes length count */ - saa_fpwrite(strs, aoutfp); + fwriteint32_t(strslen + 4, ofile); /* length includes length count */ + saa_fpwrite(strs, ofile); } static void aout_write_relocs(struct Reloc *r) @@ -860,7 +851,7 @@ static void aout_write_relocs(struct Reloc *r) while (r) { uint32_t word2; - fwriteint32_t(r->address, aoutfp); + fwriteint32_t(r->address, ofile); if (r->symbol >= 0) word2 = r->symbol; @@ -869,7 +860,7 @@ static void aout_write_relocs(struct Reloc *r) word2 |= r->reltype << 24; word2 |= (r->bytes == 1 ? 0 : r->bytes == 2 ? 0x2000000L : 0x4000000L); - fwriteint32_t(word2, aoutfp); + fwriteint32_t(word2, ofile); r = r->next; } @@ -882,8 +873,8 @@ static void aout_write_syms(void) saa_rewind(syms); for (i = 0; i < nsyms; i++) { struct Symbol *sym = saa_rstruct(syms); - fwriteint32_t(sym->strpos, aoutfp); - fwriteint32_t((int32_t)sym->type & ~SYM_WITH_SIZE, aoutfp); + fwriteint32_t(sym->strpos, ofile); + fwriteint32_t((int32_t)sym->type & ~SYM_WITH_SIZE, ofile); /* * Fix up the symbol value now we know the final section * sizes. @@ -892,14 +883,14 @@ static void aout_write_syms(void) sym->value += stext.len; if ((sym->type & SECT_MASK) == SECT_BSS) sym->value += stext.len + sdata.len; - fwriteint32_t(sym->value, aoutfp); + fwriteint32_t(sym->value, ofile); /* * Output a size record if necessary. */ if (sym->type & SYM_WITH_SIZE) { - fwriteint32_t(sym->strpos, aoutfp); - fwriteint32_t(0x0DL, aoutfp); /* special value: means size */ - fwriteint32_t(sym->size, aoutfp); + fwriteint32_t(sym->strpos, ofile); + fwriteint32_t(0x0DL, ofile); /* special value: means size */ + fwriteint32_t(sym->size, ofile); i++; /* use up another of `nsyms' */ } } @@ -917,9 +908,9 @@ static int32_t aout_segbase(int32_t segment) return segment; } -static void aout_filename(char *inname, char *outname, efunc error) +static void aout_filename(char *inname, char *outname) { - standard_extension(inname, outname, ".o", error); + standard_extension(inname, outname, ".o"); } extern macros_t aout_stdmac[]; diff --git a/output/outas86.c b/output/outas86.c index efef143..877eebd 100644 --- a/output/outas86.c +++ b/output/outas86.c @@ -107,21 +107,14 @@ static uint32_t strslen; static int as86_reloc_size; -static FILE *as86fp; -static efunc error; - static void as86_write(void); static void as86_write_section(struct Section *, int); static int as86_add_string(char *name); static void as86_sect_write(struct Section *, const uint8_t *, uint32_t); -static void as86_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval) +static void as86_init(void) { - as86fp = fp; - error = errfunc; - (void)ldef; /* placate optimisers */ - (void)eval; stext.data = saa_init(1L); stext.datalen = 0L; stext.head = stext.last = NULL; @@ -211,13 +204,13 @@ static void as86_deflabel(char *name, int32_t segment, int64_t offset, struct Symbol *sym; if (special) - error(ERR_NONFATAL, "as86 format does not support any" + nasm_error(ERR_NONFATAL, "as86 format does not support any" " special symbol types"); if (name[0] == '.' && name[1] == '.' && name[2] != '@') { if (strcmp(name, "..start")) { - error(ERR_NONFATAL, "unrecognised special symbol `%s'", name); + nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name); return; } else { is_start = true; @@ -305,7 +298,7 @@ static void as86_out(int32_t segto, const void *data, if (wrt != NO_SEG) { wrt = NO_SEG; /* continue to do _something_ */ - error(ERR_NONFATAL, "WRT not supported by as86 output format"); + nasm_error(ERR_NONFATAL, "WRT not supported by as86 output format"); } /* @@ -313,7 +306,7 @@ static void as86_out(int32_t segto, const void *data, */ if (segto == NO_SEG) { if (type != OUT_RESERVE) - error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]" + nasm_error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]" " space"); return; } @@ -325,13 +318,13 @@ static void as86_out(int32_t segto, const void *data, else if (segto == bssindex) s = NULL; else { - error(ERR_WARNING, "attempt to assemble code in" + nasm_error(ERR_WARNING, "attempt to assemble code in" " segment %d: defaulting to `.text'", segto); s = &stext; } if (!s && type != OUT_RESERVE) { - error(ERR_WARNING, "attempt to initialize memory in the" + nasm_error(ERR_WARNING, "attempt to initialize memory in the" " BSS section: ignored"); bsslen += realsize(type, size); return; @@ -339,7 +332,7 @@ static void as86_out(int32_t segto, const void *data, if (type == OUT_RESERVE) { if (s) { - error(ERR_WARNING, "uninitialized space declared in" + nasm_error(ERR_WARNING, "uninitialized space declared in" " %s section: zeroing", (segto == stext.index ? "code" : "data")); as86_sect_write(s, NULL, size); @@ -348,13 +341,13 @@ static void as86_out(int32_t segto, const void *data, bsslen += size; } else if (type == OUT_RAWDATA) { if (segment != NO_SEG) - error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG"); + nasm_error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG"); as86_sect_write(s, data, size); as86_add_piece(s, 0, 0L, 0L, size, 0); } else if (type == OUT_ADDRESS) { if (segment != NO_SEG) { if (segment % 2) { - error(ERR_NONFATAL, "as86 format does not support" + nasm_error(ERR_NONFATAL, "as86 format does not support" " segment base references"); } else { offset = *(int64_t *)data; @@ -368,10 +361,10 @@ static void as86_out(int32_t segto, const void *data, } } else if (type == OUT_REL2ADR) { if (segment == segto) - error(ERR_PANIC, "intra-segment OUT_REL2ADR"); + nasm_error(ERR_PANIC, "intra-segment OUT_REL2ADR"); if (segment != NO_SEG) { if (segment % 2) { - error(ERR_NONFATAL, "as86 format does not support" + nasm_error(ERR_NONFATAL, "as86 format does not support" " segment base references"); } else { offset = *(int64_t *)data; @@ -381,10 +374,10 @@ static void as86_out(int32_t segto, const void *data, } } else if (type == OUT_REL4ADR) { if (segment == segto) - error(ERR_PANIC, "intra-segment OUT_REL4ADR"); + nasm_error(ERR_PANIC, "intra-segment OUT_REL4ADR"); if (segment != NO_SEG) { if (segment % 2) { - error(ERR_NONFATAL, "as86 format does not support" + nasm_error(ERR_NONFATAL, "as86 format does not support" " segment base references"); } else { offset = *(int64_t *)data; @@ -439,23 +432,23 @@ static void as86_write(void) /* * Emit the as86 header. */ - fwriteint32_t(0x000186A3L, as86fp); - fputc(0x2A, as86fp); - fwriteint32_t(27 + symlen + seglen + strslen, as86fp); /* header length */ - fwriteint32_t(stext.len + sdata.len + bsslen, as86fp); - fwriteint16_t(strslen, as86fp); - fwriteint16_t(0, as86fp); /* class = revision = 0 */ - fwriteint32_t(0x55555555L, as86fp); /* segment max sizes: always this */ - fwriteint32_t(segsize, as86fp); /* segment size descriptors */ + fwriteint32_t(0x000186A3L, ofile); + fputc(0x2A, ofile); + fwriteint32_t(27 + symlen + seglen + strslen, ofile); /* header length */ + fwriteint32_t(stext.len + sdata.len + bsslen, ofile); + fwriteint16_t(strslen, ofile); + fwriteint16_t(0, ofile); /* class = revision = 0 */ + fwriteint32_t(0x55555555L, ofile); /* segment max sizes: always this */ + fwriteint32_t(segsize, ofile); /* segment size descriptors */ if (segsize & 0x01000000L) - fwriteint32_t(stext.len, as86fp); + fwriteint32_t(stext.len, ofile); else - fwriteint16_t(stext.len, as86fp); + fwriteint16_t(stext.len, ofile); if (segsize & 0x40000000L) - fwriteint32_t(sdata.len + bsslen, as86fp); + fwriteint32_t(sdata.len + bsslen, ofile); else - fwriteint16_t(sdata.len + bsslen, as86fp); - fwriteint16_t(nsyms, as86fp); + fwriteint16_t(sdata.len + bsslen, ofile); + fwriteint16_t(nsyms, ofile); /* * Write the symbol table. @@ -463,19 +456,19 @@ static void as86_write(void) saa_rewind(syms); for (i = 0; i < nsyms; i++) { struct Symbol *sym = saa_rstruct(syms); - fwriteint16_t(sym->strpos, as86fp); - fwriteint16_t(sym->flags, as86fp); + fwriteint16_t(sym->strpos, ofile); + fwriteint16_t(sym->flags, ofile); switch (sym->flags & (3 << 14)) { case 0 << 14: break; case 1 << 14: - fputc(sym->value, as86fp); + fputc(sym->value, ofile); break; case 2 << 14: - fwriteint16_t(sym->value, as86fp); + fwriteint16_t(sym->value, ofile); break; case 3 << 14: - fwriteint32_t(sym->value, as86fp); + fwriteint32_t(sym->value, ofile); break; } } @@ -483,7 +476,7 @@ static void as86_write(void) /* * Write out the string table. */ - saa_fpwrite(strs, as86fp); + saa_fpwrite(strs, ofile); /* * Write the program text. @@ -495,17 +488,17 @@ static void as86_write(void) * Append the BSS section to the .data section */ if (bsslen > 65535L) { - fputc(0x13, as86fp); - fwriteint32_t(bsslen, as86fp); + fputc(0x13, ofile); + fwriteint32_t(bsslen, ofile); } else if (bsslen > 255) { - fputc(0x12, as86fp); - fwriteint16_t(bsslen, as86fp); + fputc(0x12, ofile); + fwriteint16_t(bsslen, ofile); } else if (bsslen) { - fputc(0x11, as86fp); - fputc(bsslen, as86fp); + fputc(0x11, ofile); + fputc(bsslen, ofile); } - fputc(0, as86fp); /* termination */ + fputc(0, ofile); /* termination */ } static void as86_set_rsize(int size) @@ -513,16 +506,17 @@ static void as86_set_rsize(int size) if (as86_reloc_size != size) { switch (as86_reloc_size = size) { case 1: - fputc(0x01, as86fp); + fputc(0x01, ofile); break; case 2: - fputc(0x02, as86fp); + fputc(0x02, ofile); break; case 4: - fputc(0x03, as86fp); + fputc(0x03, ofile); break; default: - error(ERR_PANIC, "bizarre relocation size %d", size); + nasm_error(ERR_PANIC, "bizarre relocation size %d", size); + break; } } } @@ -533,7 +527,7 @@ static void as86_write_section(struct Section *sect, int index) uint32_t s; int32_t length; - fputc(0x20 + index, as86fp); /* select the right section */ + fputc(0x20 + index, ofile); /* select the right section */ saa_rewind(sect->data); @@ -548,9 +542,9 @@ static void as86_write_section(struct Section *sect, int index) do { char buf[64]; int32_t tmplen = (length > 64 ? 64 : length); - fputc(0x40 | (tmplen & 0x3F), as86fp); + fputc(0x40 | (tmplen & 0x3F), ofile); saa_rnbytes(sect->data, buf, tmplen); - fwrite(buf, 1, tmplen, as86fp); + fwrite(buf, 1, tmplen, ofile); length -= tmplen; } while (length > 0); break; @@ -561,11 +555,11 @@ static void as86_write_section(struct Section *sect, int index) if (p->number == SECT_BSS) p->number = SECT_DATA, p->offset += sdata.len; as86_set_rsize(p->bytes); - fputc(0x80 | (p->relative ? 0x20 : 0) | p->number, as86fp); + fputc(0x80 | (p->relative ? 0x20 : 0) | p->number, ofile); if (as86_reloc_size == 2) - fwriteint16_t(p->offset, as86fp); + fwriteint16_t(p->offset, ofile); else - fwriteint32_t(p->offset, as86fp); + fwriteint32_t(p->offset, ofile); break; case 2: /* @@ -583,22 +577,22 @@ static void as86_write_section(struct Section *sect, int index) s = 0; fputc(0xC0 | (p->relative ? 0x20 : 0) | - (p->number > 255 ? 0x04 : 0) | s, as86fp); + (p->number > 255 ? 0x04 : 0) | s, ofile); if (p->number > 255) - fwriteint16_t(p->number, as86fp); + fwriteint16_t(p->number, ofile); else - fputc(p->number, as86fp); + fputc(p->number, ofile); switch ((int)s) { case 0: break; case 1: - fputc(p->offset, as86fp); + fputc(p->offset, ofile); break; case 2: - fwriteint16_t(p->offset, as86fp); + fwriteint16_t(p->offset, ofile); break; case 3: - fwriteint32_t(p->offset, as86fp); + fwriteint32_t(p->offset, ofile); break; } break; @@ -617,7 +611,7 @@ static int32_t as86_segbase(int32_t segment) return segment; } -static void as86_filename(char *inname, char *outname, efunc error) +static void as86_filename(char *inname, char *outname) { char *p; @@ -627,7 +621,7 @@ static void as86_filename(char *inname, char *outname, efunc error) } else strcpy(as86_module, inname); - standard_extension(inname, outname, ".o", error); + standard_extension(inname, outname, ".o"); } extern macros_t as86_stdmac[]; diff --git a/output/outbin.c b/output/outbin.c index 216397b..79f5d20 100644 --- a/output/outbin.c +++ b/output/outbin.c @@ -92,9 +92,7 @@ #ifdef OF_BIN -static FILE *fp, *rf = NULL; -static efunc error; -static struct ofmt *my_ofmt; +static FILE *rf = NULL; static void (*do_output)(void); /* Section flags keep track of which attributes the user has defined. */ @@ -278,7 +276,7 @@ static void bin_cleanup(int debuginfo) if (s->flags & (START_DEFINED | ALIGN_DEFINED | FOLLOWS_DEFINED)) { /* Check for a mixture of real and virtual section attributes. */ if (s->flags & (VSTART_DEFINED | VALIGN_DEFINED | VFOLLOWS_DEFINED)) - error(ERR_FATAL|ERR_NOFILE, + nasm_error(ERR_FATAL|ERR_NOFILE, "cannot mix real and virtual attributes" " in nobits section (%s)", s->name); /* Real and virtual attributes mean the same thing for nobits sections. */ @@ -349,11 +347,11 @@ static void bin_cleanup(int debuginfo) s && strcmp(s->name, g->follows); sp = &s->next, s = s->next) ; if (!s) - error(ERR_FATAL|ERR_NOFILE, "section %s follows an invalid or" + nasm_error(ERR_FATAL|ERR_NOFILE, "section %s follows an invalid or" " unknown section (%s)", g->name, g->follows); if (s->next && (s->next->flags & FOLLOWS_DEFINED) && !strcmp(s->name, s->next->follows)) - error(ERR_FATAL|ERR_NOFILE, "sections %s and %s can't both follow" + nasm_error(ERR_FATAL|ERR_NOFILE, "sections %s and %s can't both follow" " section %s", g->name, s->next->name, s->name); /* Find the end of the current follows group (gs). */ for (gsp = &g->next, gs = g->next; @@ -397,7 +395,7 @@ static void bin_cleanup(int debuginfo) if (sections->flags & START_DEFINED) { /* Make sure this section doesn't begin before the origin. */ if (sections->start < origin) - error(ERR_FATAL|ERR_NOFILE, "section %s begins" + nasm_error(ERR_FATAL|ERR_NOFILE, "section %s begins" " before program origin", sections->name); } else if (sections->flags & ALIGN_DEFINED) { sections->start = ((origin + sections->align - 1) & @@ -454,13 +452,13 @@ static void bin_cleanup(int debuginfo) /* Check for section overlap. */ if (s) { if (s->start < origin) - error(ERR_FATAL|ERR_NOFILE, "section %s beings before program origin", + nasm_error(ERR_FATAL|ERR_NOFILE, "section %s beings before program origin", s->name); if (g->start > s->start) - error(ERR_FATAL|ERR_NOFILE, "sections %s ~ %s and %s overlap!", + nasm_error(ERR_FATAL|ERR_NOFILE, "sections %s ~ %s and %s overlap!", gs->name, g->name, s->name); if (pend > s->start) - error(ERR_FATAL|ERR_NOFILE, "sections %s and %s overlap!", + nasm_error(ERR_FATAL|ERR_NOFILE, "sections %s and %s overlap!", g->name, s->name); } /* Remember this section as the latest >0 length section. */ @@ -489,7 +487,7 @@ static void bin_cleanup(int debuginfo) for (s = sections; s && strcmp(g->vfollows, s->name); s = s->next) ; if (!s) - error(ERR_FATAL|ERR_NOFILE, + nasm_error(ERR_FATAL|ERR_NOFILE, "section %s vfollows unknown section (%s)", g->name, g->vfollows); } else if (g->ifollows != NULL) @@ -523,13 +521,13 @@ static void bin_cleanup(int debuginfo) for (h = 0, s = sections; s; s = s->next) { if (!(s->flags & VSTART_DEFINED)) { /* Non-fatal errors after assembly has completed are generally a * no-no, but we'll throw a fatal one eventually so it's ok. */ - error(ERR_NONFATAL, "cannot compute vstart for section %s", + nasm_error(ERR_NONFATAL, "cannot compute vstart for section %s", s->name); h++; } } if (h) - error(ERR_FATAL|ERR_NOFILE, "circular vfollows path detected"); + nasm_error(ERR_FATAL|ERR_NOFILE, "circular vfollows path detected"); #ifdef DEBUG fprintf(stdout, @@ -756,13 +754,13 @@ static void bin_out(int32_t segto, const void *data, if (wrt != NO_SEG) { wrt = NO_SEG; /* continue to do _something_ */ - error(ERR_NONFATAL, "WRT not supported by binary output format"); + nasm_error(ERR_NONFATAL, "WRT not supported by binary output format"); } /* Handle absolute-assembly (structure definitions). */ if (segto == NO_SEG) { if (type != OUT_RESERVE) - error(ERR_NONFATAL, "attempt to assemble code in" + nasm_error(ERR_NONFATAL, "attempt to assemble code in" " [ABSOLUTE] space"); return; } @@ -770,7 +768,7 @@ static void bin_out(int32_t segto, const void *data, /* Find the segment we are targeting. */ s = find_section_by_index(segto); if (!s) - error(ERR_PANIC, "code directed to nonexistent segment?"); + nasm_error(ERR_PANIC, "code directed to nonexistent segment?"); /* "Smart" section-type adaptation code. */ if (!(s->flags & TYPE_DEFINED)) { @@ -781,16 +779,16 @@ static void bin_out(int32_t segto, const void *data, } if ((s->flags & TYPE_NOBITS) && (type != OUT_RESERVE)) - error(ERR_WARNING, "attempt to initialize memory in a" + nasm_error(ERR_WARNING, "attempt to initialize memory in a" " nobits section: ignored"); if (type == OUT_ADDRESS) { if (segment != NO_SEG && !find_section_by_index(segment)) { if (segment % 2) - error(ERR_NONFATAL, "binary output format does not support" + nasm_error(ERR_NONFATAL, "binary output format does not support" " segment base references"); else - error(ERR_NONFATAL, "binary output format does not support" + nasm_error(ERR_NONFATAL, "binary output format does not support" " external references"); segment = NO_SEG; } @@ -808,7 +806,7 @@ static void bin_out(int32_t segto, const void *data, s->length += size; } else if (type == OUT_RESERVE) { if (s->flags & TYPE_PROGBITS) { - error(ERR_WARNING, "uninitialized space declared in" + nasm_error(ERR_WARNING, "uninitialized space declared in" " %s section: zeroing", s->name); saa_wbytes(s->contents, NULL, size); } @@ -819,10 +817,10 @@ static void bin_out(int32_t segto, const void *data, size = realsize(type, size); if (segment != NO_SEG && !find_section_by_index(segment)) { if (segment % 2) - error(ERR_NONFATAL, "binary output format does not support" + nasm_error(ERR_NONFATAL, "binary output format does not support" " segment base references"); else - error(ERR_NONFATAL, "binary output format does not support" + nasm_error(ERR_NONFATAL, "binary output format does not support" " external references"); segment = NO_SEG; } @@ -843,12 +841,12 @@ static void bin_deflabel(char *name, int32_t segment, int64_t offset, (void)offset; /* Don't warn that this parameter is unused */ if (special) - error(ERR_NONFATAL, "binary format does not support any" + nasm_error(ERR_NONFATAL, "binary format does not support any" " special symbol types"); else if (name[0] == '.' && name[1] == '.' && name[2] != '@') - error(ERR_NONFATAL, "unrecognised special symbol `%s'", name); + nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name); else if (is_global == 2) - error(ERR_NONFATAL, "binary output format does not support common" + nasm_error(ERR_NONFATAL, "binary output format does not support common" " variables"); else { struct Section *s; @@ -964,14 +962,14 @@ static int bin_read_attribute(char **line, int *attribute, break; } if (!**line) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "invalid syntax in `section' directive"); return -1; } ++(*line); } if (!**line) { - error(ERR_NONFATAL, "expecting `)'"); + nasm_error(ERR_NONFATAL, "expecting `)'"); return -1; } } @@ -980,7 +978,7 @@ static int bin_read_attribute(char **line, int *attribute, /* Check for no value given. */ if (!*exp) { - error(ERR_WARNING, "No value given to attribute in" + nasm_error(ERR_WARNING, "No value given to attribute in" " `section' directive"); return -1; } @@ -989,15 +987,15 @@ static int bin_read_attribute(char **line, int *attribute, stdscan_reset(); stdscan_bufptr = exp; tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, NULL, 1, error, NULL); + e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL); if (e) { if (!is_really_simple(e)) { - error(ERR_NONFATAL, "section attribute value must be" + nasm_error(ERR_NONFATAL, "section attribute value must be" " a critical expression"); return -1; } } else { - error(ERR_NONFATAL, "Invalid attribute value" + nasm_error(ERR_NONFATAL, "Invalid attribute value" " specified in `section' directive."); return -1; } @@ -1028,7 +1026,7 @@ static void bin_assign_attributes(struct Section *sec, char *astring) *astring = '\0'; astring++; } - error(ERR_WARNING, "ignoring unknown section attribute:" + nasm_error(ERR_WARNING, "ignoring unknown section attribute:" " \"%s\"", p); } continue; @@ -1038,7 +1036,7 @@ static void bin_assign_attributes(struct Section *sec, char *astring) case ATTRIB_NOBITS: if ((sec->flags & TYPE_DEFINED) && (sec->flags & TYPE_PROGBITS)) - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "attempt to change section type" " from progbits to nobits"); else @@ -1048,7 +1046,7 @@ static void bin_assign_attributes(struct Section *sec, char *astring) /* Handle progbits attribute. */ case ATTRIB_PROGBITS: if ((sec->flags & TYPE_DEFINED) && (sec->flags & TYPE_NOBITS)) - error(ERR_NONFATAL, "attempt to change section type" + nasm_error(ERR_NONFATAL, "attempt to change section type" " from nobits to progbits"); else sec->flags |= TYPE_DEFINED | TYPE_PROGBITS; @@ -1057,11 +1055,11 @@ static void bin_assign_attributes(struct Section *sec, char *astring) /* Handle align attribute. */ case ATTRIB_ALIGN: if (!format_mode && (!strcmp(sec->name, ".text"))) - error(ERR_NONFATAL, "cannot specify an alignment" + nasm_error(ERR_NONFATAL, "cannot specify an alignment" " to the .text section"); else { if (!value || ((value - 1) & value)) - error(ERR_NONFATAL, "argument to `align' is not a" + nasm_error(ERR_NONFATAL, "argument to `align' is not a" " power of two"); else { /* Alignment is already satisfied if the previous * align value is greater. */ @@ -1072,7 +1070,7 @@ static void bin_assign_attributes(struct Section *sec, char *astring) /* Don't allow a conflicting align value. */ if ((sec->flags & START_DEFINED) && (sec->start & (value - 1))) - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`align' value conflicts " "with section start address"); else { @@ -1086,7 +1084,7 @@ static void bin_assign_attributes(struct Section *sec, char *astring) /* Handle valign attribute. */ case ATTRIB_VALIGN: if (!value || ((value - 1) & value)) - error(ERR_NONFATAL, "argument to `valign' is not a" + nasm_error(ERR_NONFATAL, "argument to `valign' is not a" " power of two"); else { /* Alignment is already satisfied if the previous * align value is greater. */ @@ -1096,7 +1094,7 @@ static void bin_assign_attributes(struct Section *sec, char *astring) /* Don't allow a conflicting valign value. */ if ((sec->flags & VSTART_DEFINED) && (sec->vstart & (value - 1))) - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`valign' value conflicts " "with `vstart' address"); else { @@ -1109,16 +1107,16 @@ static void bin_assign_attributes(struct Section *sec, char *astring) /* Handle start attribute. */ case ATTRIB_START: if (sec->flags & FOLLOWS_DEFINED) - error(ERR_NONFATAL, "cannot combine `start' and `follows'" + nasm_error(ERR_NONFATAL, "cannot combine `start' and `follows'" " section attributes"); else if ((sec->flags & START_DEFINED) && (value != sec->start)) - error(ERR_NONFATAL, "section start address redefined"); + nasm_error(ERR_NONFATAL, "section start address redefined"); else { sec->start = value; sec->flags |= START_DEFINED; if (sec->flags & ALIGN_DEFINED) { if (sec->start & (sec->align - 1)) - error(ERR_NONFATAL, "`start' address conflicts" + nasm_error(ERR_NONFATAL, "`start' address conflicts" " with section alignment"); sec->flags ^= ALIGN_DEFINED; } @@ -1128,12 +1126,12 @@ static void bin_assign_attributes(struct Section *sec, char *astring) /* Handle vstart attribute. */ case ATTRIB_VSTART: if (sec->flags & VFOLLOWS_DEFINED) - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "cannot combine `vstart' and `vfollows'" " section attributes"); else if ((sec->flags & VSTART_DEFINED) && (value != sec->vstart)) - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "section virtual start address" " (vstart) redefined"); else { @@ -1141,7 +1139,7 @@ static void bin_assign_attributes(struct Section *sec, char *astring) sec->flags |= VSTART_DEFINED; if (sec->flags & VALIGN_DEFINED) { if (sec->vstart & (sec->valign - 1)) - error(ERR_NONFATAL, "`vstart' address conflicts" + nasm_error(ERR_NONFATAL, "`vstart' address conflicts" " with `valign' value"); sec->flags ^= VALIGN_DEFINED; } @@ -1153,12 +1151,12 @@ static void bin_assign_attributes(struct Section *sec, char *astring) p = astring; astring += strcspn(astring, " \t"); if (astring == p) - error(ERR_NONFATAL, "expecting section name for `follows'" + nasm_error(ERR_NONFATAL, "expecting section name for `follows'" " attribute"); else { *(astring++) = '\0'; if (sec->flags & START_DEFINED) - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "cannot combine `start' and `follows'" " section attributes"); sec->follows = nasm_strdup(p); @@ -1169,14 +1167,14 @@ static void bin_assign_attributes(struct Section *sec, char *astring) /* Handle vfollows attribute. */ case ATTRIB_VFOLLOWS: if (sec->flags & VSTART_DEFINED) - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "cannot combine `vstart' and `vfollows'" " section attributes"); else { p = astring; astring += strcspn(astring, " \t"); if (astring == p) - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "expecting section name for `vfollows'" " attribute"); else { @@ -1208,12 +1206,12 @@ static void bin_define_section_labels(void) /* section.<name>.start */ strcpy(label_name + base_len, ".start"); define_label(label_name, sec->start_index, 0L, - NULL, 0, 0, my_ofmt, error); + NULL, 0, 0, ofmt, nasm_error); /* section.<name>.vstart */ strcpy(label_name + base_len, ".vstart"); define_label(label_name, sec->vstart_index, 0L, - NULL, 0, 0, my_ofmt, error); + NULL, 0, 0, ofmt, nasm_error); nasm_free(label_name); } @@ -1263,7 +1261,7 @@ static int32_t bin_secname(char *name, int pass, int *bits) sec->flags |= TYPE_DEFINED | TYPE_NOBITS; sec->ifollows = NULL; } else if (!format_mode) { - error(ERR_NONFATAL, "section name must be " + nasm_error(ERR_NONFATAL, "section name must be " ".text, .data, or .bss"); return current_section; } @@ -1298,23 +1296,23 @@ static int bin_directive(enum directives directive, char *args, int pass) stdscan_reset(); stdscan_bufptr = args; tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, NULL, 1, error, NULL); + e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL); if (e) { if (!is_really_simple(e)) - error(ERR_NONFATAL, "org value must be a critical" + nasm_error(ERR_NONFATAL, "org value must be a critical" " expression"); else { value = reloc_value(e); /* Check for ORG redefinition. */ if (origin_defined && (value != origin)) - error(ERR_NONFATAL, "program origin redefined"); + nasm_error(ERR_NONFATAL, "program origin redefined"); else { origin = value; origin_defined = 1; } } } else - error(ERR_NONFATAL, "No or invalid offset specified" + nasm_error(ERR_NONFATAL, "No or invalid offset specified" " in ORG directive."); return 1; } @@ -1351,14 +1349,14 @@ static int bin_directive(enum directives directive, char *args, int pass) else { /* Must be a filename. */ rf = fopen(p, "wt"); if (!rf) { - error(ERR_WARNING, "unable to open map file `%s'", + nasm_error(ERR_WARNING, "unable to open map file `%s'", p); map_control = 0; return 1; } } } else - error(ERR_WARNING, "map file already specified"); + nasm_error(ERR_WARNING, "map file already specified"); } if (map_control == 0) map_control |= MAP_ORIGIN | MAP_SUMMARY; @@ -1371,23 +1369,23 @@ static int bin_directive(enum directives directive, char *args, int pass) } } -static void bin_filename(char *inname, char *outname, efunc error) +static void bin_filename(char *inname, char *outname) { - standard_extension(inname, outname, "", error); + standard_extension(inname, outname, ""); infile = inname; outfile = outname; } -static void ith_filename(char *inname, char *outname, efunc error) +static void ith_filename(char *inname, char *outname) { - standard_extension(inname, outname, ".ith", error); + standard_extension(inname, outname, ".ith"); infile = inname; outfile = outname; } -static void srec_filename(char *inname, char *outname, efunc error) +static void srec_filename(char *inname, char *outname) { - standard_extension(inname, outname, ".srec", error); + standard_extension(inname, outname, ".srec"); infile = inname; outfile = outname; } @@ -1404,41 +1402,32 @@ static int bin_set_info(enum geninfo type, char **val) return 0; } -static void binfmt_init(FILE *afp, efunc errfunc, ldfunc ldef, evalfunc eval); struct ofmt of_bin, of_ith, of_srec; +static void binfmt_init(void); static void do_output_bin(void); static void do_output_ith(void); static void do_output_srec(void); -static void bin_init(FILE *afp, efunc errfunc, ldfunc ldef, evalfunc eval) +static void bin_init(void) { - my_ofmt = &of_bin; do_output = do_output_bin; - binfmt_init(afp, errfunc, ldef, eval); + binfmt_init(); } -static void ith_init(FILE *afp, efunc errfunc, ldfunc ldef, evalfunc eval) +static void ith_init(void) { - my_ofmt = &of_ith; do_output = do_output_ith; - binfmt_init(afp, errfunc, ldef, eval); + binfmt_init(); } -static void srec_init(FILE *afp, efunc errfunc, ldfunc ldef, evalfunc eval) +static void srec_init(void) { - my_ofmt = &of_srec; do_output = do_output_srec; - binfmt_init(afp, errfunc, ldef, eval); + binfmt_init(); } -static void binfmt_init(FILE *afp, efunc errfunc, ldfunc ldef, evalfunc eval) +static void binfmt_init(void) { - fp = afp; - error = errfunc; - - (void)eval; /* Don't warn that this parameter is unused. */ - (void)ldef; /* Placate optimizers. */ - maxbits = 64; /* Support 64-bit Segments */ relocs = NULL; reloctail = &relocs; @@ -1480,10 +1469,10 @@ static void do_output_bin(void) /* Pad the space between sections. */ nasm_assert(addr <= s->start); - fwritezero(s->start - addr, fp); + fwritezero(s->start - addr, ofile); /* Write the section to the output file. */ - saa_fpwrite(s->contents, fp); + saa_fpwrite(s->contents, ofile); /* Keep track of the current file position */ addr = s->start + s->length; @@ -1511,7 +1500,7 @@ static int write_ith_record(unsigned int len, uint16_t addr, p += sprintf(p, "%02X", dptr[i]); p += sprintf(p, "%02X\n", csum); - if (fwrite(buf, 1, p-buf, fp) != (size_t)(p-buf)) + if (fwrite(buf, 1, p-buf, ofile) != (size_t)(p-buf)) return -1; return 0; @@ -1599,7 +1588,7 @@ static int write_srecord(unsigned int len, unsigned int alen, p += sprintf(p, "%02X", dptr[i]); p += sprintf(p, "%02X\n", csum); - if (fwrite(buf, 1, p-buf, fp) != (size_t)(p-buf)) + if (fwrite(buf, 1, p-buf, ofile) != (size_t)(p-buf)) return -1; return 0; diff --git a/output/outcoff.c b/output/outcoff.c index 92c0d29..f147ea9 100644 --- a/output/outcoff.c +++ b/output/outcoff.c @@ -49,6 +49,7 @@ #include "nasmlib.h" #include "saa.h" #include "raa.h" +#include "eval.h" #include "output/outform.h" #include "output/outlib.h" @@ -135,8 +136,6 @@ struct Symbol { int32_t namlen; /* full name length */ }; -static FILE *coffp; -static efunc error; static char coff_infile[FILENAME_MAX]; struct Section { @@ -172,7 +171,7 @@ static struct RAA *bsym, *symval; static struct SAA *strs; static uint32_t strslen; -static void coff_gen_init(FILE *, efunc); +static void coff_gen_init(void); static void coff_sect_write(struct Section *, const uint8_t *, uint32_t); static void coff_write(void); @@ -180,43 +179,33 @@ static void coff_section_header(char *, int32_t, int32_t, int32_t, int32_t, int, static void coff_write_relocs(struct Section *); static void coff_write_symbols(void); -static void coff_win32_init(FILE * fp, efunc errfunc, - ldfunc ldef, evalfunc eval) +static void coff_win32_init(void) { - win32 = true; win64 = false; - (void)ldef; /* placate optimizers */ - (void)eval; - coff_gen_init(fp, errfunc); + win32 = true; + win64 = false; + coff_gen_init(); } -static void coff_win64_init(FILE * fp, efunc errfunc, - ldfunc ldef, evalfunc eval) +static void coff_win64_init(void) { - extern struct ofmt of_win64; - maxbits = 64; - win32 = false; win64 = true; - (void)ldef; /* placate optimizers */ - (void)eval; - coff_gen_init(fp, errfunc); + win32 = false; + win64 = true; + coff_gen_init(); imagebase_sect = seg_alloc()+1; - ldef(WRT_IMAGEBASE,imagebase_sect,0,NULL,false,false,&of_win64,errfunc); + define_label(WRT_IMAGEBASE, imagebase_sect, 0, NULL, false, false, + ofmt, nasm_error); } -static void coff_std_init(FILE * fp, efunc errfunc, ldfunc ldef, - evalfunc eval) +static void coff_std_init(void) { win32 = win64 = false; - (void)ldef; /* placate optimizers */ - (void)eval; - coff_gen_init(fp, errfunc); + coff_gen_init(); } -static void coff_gen_init(FILE * fp, efunc errfunc) +static void coff_gen_init(void) { - coffp = fp; - error = errfunc; sects = NULL; nsects = sectlen = 0; syms = saa_init(sizeof(struct Symbol)); @@ -309,7 +298,7 @@ static int32_t coff_section_names(char *name, int pass, int *bits) if (*p) *p++ = '\0'; if (strlen(name) > 8) { - error(ERR_WARNING, "COFF section names limited to 8 characters:" + nasm_error(ERR_WARNING, "COFF section names limited to 8 characters:" " truncating"); name[8] = '\0'; } @@ -335,7 +324,7 @@ static int32_t coff_section_names(char *name, int pass, int *bits) flags = RDATA_FLAGS; else { flags = DATA_FLAGS; /* gotta do something */ - error(ERR_NONFATAL, "standard COFF does not support" + nasm_error(ERR_NONFATAL, "standard COFF does not support" " read-only data sections"); } } else if (!nasm_stricmp(q, "bss")) { @@ -345,24 +334,24 @@ static int32_t coff_section_names(char *name, int pass, int *bits) flags = INFO_FLAGS; else { flags = DATA_FLAGS; /* gotta do something */ - error(ERR_NONFATAL, "standard COFF does not support" + nasm_error(ERR_NONFATAL, "standard COFF does not support" " informational sections"); } } else if (!nasm_strnicmp(q, "align=", 6)) { if (!(win32 | win64)) - error(ERR_NONFATAL, "standard COFF does not support" + nasm_error(ERR_NONFATAL, "standard COFF does not support" " section alignment specification"); else { if (q[6 + strspn(q + 6, "0123456789")]) - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "argument to `align' is not numeric"); else { unsigned int align = atoi(q + 6); if (!align || ((align - 1) & align)) - error(ERR_NONFATAL, "argument to `align' is not a" + nasm_error(ERR_NONFATAL, "argument to `align' is not a" " power of two"); else if (align > 64) - error(ERR_NONFATAL, "Win32 cannot align sections" + nasm_error(ERR_NONFATAL, "Win32 cannot align sections" " to better than 64-byte boundaries"); else { align_and = ~0x00F00000L; @@ -404,7 +393,7 @@ static int32_t coff_section_names(char *name, int pass, int *bits) sects[i]->flags |= align_or; } else if (pass == 1) { if (flags) - error(ERR_WARNING, "section attributes ignored on" + nasm_error(ERR_WARNING, "section attributes ignored on" " redeclaration of section `%s'", name); } @@ -418,12 +407,12 @@ static void coff_deflabel(char *name, int32_t segment, int64_t offset, struct Symbol *sym; if (special) - error(ERR_NONFATAL, "COFF format does not support any" + nasm_error(ERR_NONFATAL, "COFF format does not support any" " special symbol types"); if (name[0] == '.' && name[1] == '.' && name[2] != '@') { if (strcmp(name,WRT_IMAGEBASE)) - error(ERR_NONFATAL, "unrecognized special symbol `%s'", name); + nasm_error(ERR_NONFATAL, "unrecognized special symbol `%s'", name); return; } @@ -521,7 +510,7 @@ static void coff_out(int32_t segto, const void *data, if (wrt != NO_SEG && !win64) { wrt = NO_SEG; /* continue to do _something_ */ - error(ERR_NONFATAL, "WRT not supported by COFF output formats"); + nasm_error(ERR_NONFATAL, "WRT not supported by COFF output formats"); } /* @@ -529,7 +518,7 @@ static void coff_out(int32_t segto, const void *data, */ if (segto == NO_SEG) { if (type != OUT_RESERVE) - error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]" + nasm_error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]" " space"); return; } @@ -543,7 +532,7 @@ static void coff_out(int32_t segto, const void *data, if (!s) { int tempint; /* ignored */ if (segto != coff_section_names(".text", 2, &tempint)) - error(ERR_PANIC, "strange segment conditions in COFF driver"); + nasm_error(ERR_PANIC, "strange segment conditions in COFF driver"); else s = sects[nsects - 1]; } @@ -554,7 +543,7 @@ static void coff_out(int32_t segto, const void *data, wrt = imagebase_sect; if (!s->data && type != OUT_RESERVE) { - error(ERR_WARNING, "attempt to initialize memory in" + nasm_error(ERR_WARNING, "attempt to initialize memory in" " BSS section `%s': ignored", s->name); s->len += realsize(type, size); return; @@ -562,28 +551,28 @@ static void coff_out(int32_t segto, const void *data, if (type == OUT_RESERVE) { if (s->data) { - error(ERR_WARNING, "uninitialised space declared in" + nasm_error(ERR_WARNING, "uninitialised space declared in" " non-BSS section `%s': zeroing", s->name); coff_sect_write(s, NULL, size); } else s->len += size; } else if (type == OUT_RAWDATA) { if (segment != NO_SEG) - error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG"); + nasm_error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG"); coff_sect_write(s, data, size); } else if (type == OUT_ADDRESS) { if (!(win64)) { if (size != 4 && (segment != NO_SEG || wrt != NO_SEG)) - error(ERR_NONFATAL, "COFF format does not support non-32-bit" + nasm_error(ERR_NONFATAL, "COFF format does not support non-32-bit" " relocations"); else { int32_t fix = 0; if (segment != NO_SEG || wrt != NO_SEG) { if (wrt != NO_SEG) { - error(ERR_NONFATAL, "COFF format does not support" + nasm_error(ERR_NONFATAL, "COFF format does not support" " WRT types"); } else if (segment % 2) { - error(ERR_NONFATAL, "COFF format does not support" + nasm_error(ERR_NONFATAL, "COFF format does not support" " segment base references"); } else fix = coff_add_reloc(s, segment, IMAGE_REL_I386_DIR32); @@ -597,7 +586,7 @@ static void coff_out(int32_t segto, const void *data, p = mydata; if (size == 8) { if (wrt == imagebase_sect) { - error(ERR_NONFATAL, "operand size mismatch: 'wrt " + nasm_error(ERR_NONFATAL, "operand size mismatch: 'wrt " WRT_IMAGEBASE "' is a 32-bit operand"); } fix = coff_add_reloc(s, segment, IMAGE_REL_AMD64_ADDR64); @@ -612,18 +601,18 @@ static void coff_out(int32_t segto, const void *data, } } } else if (type == OUT_REL2ADR) { - error(ERR_NONFATAL, "COFF format does not support 16-bit" + nasm_error(ERR_NONFATAL, "COFF format does not support 16-bit" " relocations"); } else if (type == OUT_REL4ADR) { if (segment == segto && !(win64)) /* Acceptable for RIP-relative */ - error(ERR_PANIC, "intra-segment OUT_REL4ADR"); + nasm_error(ERR_PANIC, "intra-segment OUT_REL4ADR"); else if (segment == NO_SEG && win32) - error(ERR_NONFATAL, "Win32 COFF does not correctly support" + nasm_error(ERR_NONFATAL, "Win32 COFF does not correctly support" " relative references to absolute addresses"); else { int32_t fix = 0; if (segment != NO_SEG && segment % 2) { - error(ERR_NONFATAL, "COFF format does not support" + nasm_error(ERR_NONFATAL, "COFF format does not support" " segment base references"); } else fix = coff_add_reloc(s, segment, @@ -735,11 +724,11 @@ static int coff_directives(enum directives directive, char *value, int pass) } if (!*name) { - error(ERR_NONFATAL, "`export' directive requires export name"); + nasm_error(ERR_NONFATAL, "`export' directive requires export name"); return 1; } if (*q) { - error(ERR_NONFATAL, "unrecognized export qualifier `%s'", q); + nasm_error(ERR_NONFATAL, "unrecognized export qualifier `%s'", q); return 1; } AddExport(name); @@ -795,7 +784,7 @@ static int coff_directives(enum directives directive, char *value, int pass) } } if (n == nsyms) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`safeseh' directive requires valid symbol"); } } @@ -849,16 +838,16 @@ static void coff_write(void) * Output the COFF header. */ if (win64) - fwriteint16_t(0x8664, coffp); /* MACHINE_x86-64 */ + fwriteint16_t(0x8664, ofile); /* MACHINE_x86-64 */ else - fwriteint16_t(0x014C, coffp); /* MACHINE_i386 */ - fwriteint16_t(nsects, coffp); /* number of sections */ - fwriteint32_t(time(NULL), coffp); /* time stamp */ - fwriteint32_t(sympos, coffp); - fwriteint32_t(nsyms + initsym, coffp); - fwriteint16_t(0, coffp); /* no optional header */ + fwriteint16_t(0x014C, ofile); /* MACHINE_i386 */ + fwriteint16_t(nsects, ofile); /* number of sections */ + fwriteint32_t(time(NULL), ofile); /* time stamp */ + fwriteint32_t(sympos, ofile); + fwriteint32_t(nsyms + initsym, ofile); + fwriteint16_t(0, ofile); /* no optional header */ /* Flags: 32-bit, no line numbers. Win32 doesn't even bother with them. */ - fwriteint16_t((win32 | win64) ? 0 : 0x104, coffp); + fwriteint16_t((win32 | win64) ? 0 : 0x104, ofile); /* * Output the section headers. @@ -876,7 +865,7 @@ static void coff_write(void) */ for (i = 0; i < nsects; i++) if (sects[i]->data) { - saa_fpwrite(sects[i]->data, coffp); + saa_fpwrite(sects[i]->data, ofile); coff_write_relocs(sects[i]); } @@ -884,8 +873,8 @@ static void coff_write(void) * Output the symbol and string tables. */ coff_write_symbols(); - fwriteint32_t(strslen + 4, coffp); /* length includes length count */ - saa_fpwrite(strs, coffp); + fwriteint32_t(strslen + 4, ofile); /* length includes length count */ + saa_fpwrite(strs, ofile); } static void coff_section_header(char *name, int32_t vsize, @@ -898,16 +887,16 @@ static void coff_section_header(char *name, int32_t vsize, memset(padname, 0, 8); strncpy(padname, name, 8); - fwrite(padname, 8, 1, coffp); - fwriteint32_t(0, coffp); /* Virtual size field - set to 0 or vsize */ - fwriteint32_t(0L, coffp); /* RVA/offset - we ignore */ - fwriteint32_t(datalen, coffp); - fwriteint32_t(datapos, coffp); - fwriteint32_t(relpos, coffp); - fwriteint32_t(0L, coffp); /* no line numbers - we don't do 'em */ - fwriteint16_t(nrelocs, coffp); - fwriteint16_t(0, coffp); /* again, no line numbers */ - fwriteint32_t(flags, coffp); + fwrite(padname, 8, 1, ofile); + fwriteint32_t(0, ofile); /* Virtual size field - set to 0 or vsize */ + fwriteint32_t(0L, ofile); /* RVA/offset - we ignore */ + fwriteint32_t(datalen, ofile); + fwriteint32_t(datapos, ofile); + fwriteint32_t(relpos, ofile); + fwriteint32_t(0L, ofile); /* no line numbers - we don't do 'em */ + fwriteint16_t(nrelocs, ofile); + fwriteint16_t(0, ofile); /* again, no line numbers */ + fwriteint32_t(flags, ofile); } static void coff_write_relocs(struct Section *s) @@ -915,12 +904,12 @@ static void coff_write_relocs(struct Section *s) struct Reloc *r; for (r = s->head; r; r = r->next) { - fwriteint32_t(r->address, coffp); + fwriteint32_t(r->address, ofile); fwriteint32_t(r->symbol + (r->symbase == REAL_SYMBOLS ? initsym : r->symbase == ABS_SYMBOL ? initsym - 1 : r->symbase == SECT_SYMBOLS ? 2 : 0), - coffp); - fwriteint16_t(r->type, coffp); + ofile); + fwriteint16_t(r->type, ofile); } } @@ -932,16 +921,16 @@ static void coff_symbol(char *name, int32_t strpos, int32_t value, if (name) { memset(padname, 0, 8); strncpy(padname, name, 8); - fwrite(padname, 8, 1, coffp); + fwrite(padname, 8, 1, ofile); } else { - fwriteint32_t(0, coffp); - fwriteint32_t(strpos, coffp); + fwriteint32_t(0, ofile); + fwriteint32_t(strpos, ofile); } - fwriteint32_t(value, coffp); - fwriteint16_t(section, coffp); - fwriteint16_t(type, coffp); - fputc(storageclass, coffp); - fputc(aux, coffp); + fwriteint32_t(value, ofile); + fwriteint16_t(section, ofile); + fwriteint16_t(type, ofile); + fputc(storageclass, ofile); + fputc(aux, ofile); } static void coff_write_symbols(void) @@ -955,7 +944,7 @@ static void coff_write_symbols(void) coff_symbol(".file", 0L, 0L, -2, 0, 0x67, 1); memset(filename, 0, 18); strncpy(filename, coff_infile, 18); - fwrite(filename, 18, 1, coffp); + fwrite(filename, 18, 1, ofile); /* * The section records, with their auxiliaries. @@ -964,9 +953,9 @@ static void coff_write_symbols(void) for (i = 0; i < (uint32_t) nsects; i++) { coff_symbol(sects[i]->name, 0L, 0L, i + 1, 0, 3, 1); - fwriteint32_t(sects[i]->len, coffp); - fwriteint16_t(sects[i]->nrelocs, coffp); - fwrite(filename, 12, 1, coffp); + fwriteint32_t(sects[i]->len, ofile); + fwriteint16_t(sects[i]->nrelocs, ofile); + fwrite(filename, 12, 1, ofile); } /* @@ -991,16 +980,16 @@ static int32_t coff_segbase(int32_t segment) return segment; } -static void coff_std_filename(char *inname, char *outname, efunc error) +static void coff_std_filename(char *inname, char *outname) { strcpy(coff_infile, inname); - standard_extension(inname, outname, ".o", error); + standard_extension(inname, outname, ".o"); } -static void coff_win32_filename(char *inname, char *outname, efunc error) +static void coff_win32_filename(char *inname, char *outname) { strcpy(coff_infile, inname); - standard_extension(inname, outname, ".obj", error); + standard_extension(inname, outname, ".obj"); } extern macros_t coff_stdmac[]; diff --git a/output/outdbg.c b/output/outdbg.c index 96c110b..891bc17 100644 --- a/output/outdbg.c +++ b/output/outdbg.c @@ -56,19 +56,11 @@ struct Section { char *name; } *dbgsect; -FILE *dbgf; -efunc dbgef; - struct ofmt of_dbg; -static void dbg_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval) +static void dbg_init(void) { - (void)eval; - - dbgf = fp; - dbgef = errfunc; dbgsect = NULL; - (void)ldef; - fprintf(fp, "NASM Output format debug dump\n"); + fprintf(ofile, "NASM Output format debug dump\n"); } static void dbg_cleanup(int debuginfo) @@ -94,7 +86,7 @@ static int32_t dbg_section_names(char *name, int pass, int *bits) *bits = 16; if (!name) - fprintf(dbgf, "section_name on init: returning %d\n", + fprintf(ofile, "section_name on init: returning %d\n", seg = seg_alloc()); else { int n = strcspn(name, " \t"); @@ -112,7 +104,7 @@ static int32_t dbg_section_names(char *name, int pass, int *bits) s->number = seg = seg_alloc(); s->next = dbgsect; dbgsect = s; - fprintf(dbgf, "section_name %s (pass %d): returning %d\n", + fprintf(ofile, "section_name %s (pass %d): returning %d\n", name, pass, seg); } } @@ -122,7 +114,7 @@ static int32_t dbg_section_names(char *name, int pass, int *bits) static void dbg_deflabel(char *name, int32_t segment, int64_t offset, int is_global, char *special) { - fprintf(dbgf, "deflabel %s := %08"PRIx32":%016"PRIx64" %s (%d)%s%s\n", + fprintf(ofile, "deflabel %s := %08"PRIx32":%016"PRIx64" %s (%d)%s%s\n", name, segment, offset, is_global == 2 ? "common" : is_global ? "global" : "local", is_global, special ? ": " : "", special); @@ -135,41 +127,41 @@ static void dbg_out(int32_t segto, const void *data, int32_t ldata; int id; - fprintf(dbgf, "out to %"PRIx32", len = %"PRIu64": ", segto, size); + fprintf(ofile, "out to %"PRIx32", len = %"PRIu64": ", segto, size); switch (type) { case OUT_RESERVE: - fprintf(dbgf, "reserved.\n"); + fprintf(ofile, "reserved.\n"); break; case OUT_RAWDATA: - fprintf(dbgf, "raw data = "); + fprintf(ofile, "raw data = "); while (size--) { id = *(uint8_t *)data; data = (char *)data + 1; - fprintf(dbgf, "%02x ", id); + fprintf(ofile, "%02x ", id); } - fprintf(dbgf, "\n"); + fprintf(ofile, "\n"); break; case OUT_ADDRESS: ldata = *(int64_t *)data; - fprintf(dbgf, "addr %08"PRIx32" (seg %08"PRIx32", wrt %08"PRIx32")\n", ldata, + fprintf(ofile, "addr %08"PRIx32" (seg %08"PRIx32", wrt %08"PRIx32")\n", ldata, segment, wrt); break; case OUT_REL2ADR: - fprintf(dbgf, "rel2adr %04"PRIx16" (seg %08"PRIx32")\n", + fprintf(ofile, "rel2adr %04"PRIx16" (seg %08"PRIx32")\n", (uint16_t)*(int64_t *)data, segment); break; case OUT_REL4ADR: - fprintf(dbgf, "rel4adr %08"PRIx32" (seg %08"PRIx32")\n", + fprintf(ofile, "rel4adr %08"PRIx32" (seg %08"PRIx32")\n", (uint32_t)*(int64_t *)data, segment); break; case OUT_REL8ADR: - fprintf(dbgf, "rel8adr %016"PRIx64" (seg %08"PRIx32")\n", + fprintf(ofile, "rel8adr %016"PRIx64" (seg %08"PRIx32")\n", (uint64_t)*(int64_t *)data, segment); break; default: - fprintf(dbgf, "unknown\n"); + fprintf(ofile, "unknown\n"); break; } } @@ -181,14 +173,14 @@ static int32_t dbg_segbase(int32_t segment) static int dbg_directive(enum directives directive, char *value, int pass) { - fprintf(dbgf, "directive [%s] value [%s] (pass %d)\n", + fprintf(ofile, "directive [%s] value [%s] (pass %d)\n", directives[directive], value, pass); return 1; } -static void dbg_filename(char *inname, char *outname, efunc error) +static void dbg_filename(char *inname, char *outname) { - standard_extension(inname, outname, ".dbg", error); + standard_extension(inname, outname, ".dbg"); } static int dbg_set_info(enum geninfo type, char **val) @@ -201,13 +193,9 @@ static int dbg_set_info(enum geninfo type, char **val) char *types[] = { "unknown", "label", "byte", "word", "dword", "float", "qword", "tbyte" }; -void dbgdbg_init(struct ofmt *of, void *id, FILE * fp, efunc error) +void dbgdbg_init(void) { - (void)of; - (void)id; - (void)fp; - (void)error; - fprintf(fp, " With debug info\n"); + fprintf(ofile, " With debug info\n"); } static void dbgdbg_cleanup(void) { @@ -215,13 +203,13 @@ static void dbgdbg_cleanup(void) static void dbgdbg_linnum(const char *lnfname, int32_t lineno, int32_t segto) { - fprintf(dbgf, "dbglinenum %s(%"PRId32") := %08"PRIx32"\n", + fprintf(ofile, "dbglinenum %s(%"PRId32") := %08"PRIx32"\n", lnfname, lineno, segto); } static void dbgdbg_deflabel(char *name, int32_t segment, int64_t offset, int is_global, char *special) { - fprintf(dbgf, "dbglabel %s := %08"PRIx32":%016"PRIx64" %s (%d)%s%s\n", + fprintf(ofile, "dbglabel %s := %08"PRIx32":%016"PRIx64" %s (%d)%s%s\n", name, segment, offset, is_global == 2 ? "common" : is_global ? "global" : "local", @@ -229,7 +217,7 @@ static void dbgdbg_deflabel(char *name, int32_t segment, } static void dbgdbg_define(const char *type, const char *params) { - fprintf(dbgf, "dbgdirective [%s] value [%s]\n", type, params); + fprintf(ofile, "dbgdirective [%s] value [%s]\n", type, params); } static void dbgdbg_output(int output_type, void *param) { @@ -238,7 +226,7 @@ static void dbgdbg_output(int output_type, void *param) } static void dbgdbg_typevalue(int32_t type) { - fprintf(dbgf, "new type: %s(%"PRIX32")\n", + fprintf(ofile, "new type: %s(%"PRIX32")\n", types[TYM_TYPE(type) >> 3], TYM_ELEMENTS(type)); } static struct dfmt debug_debug_form = { diff --git a/output/outelf32.c b/output/outelf32.c index 1e2d573..cec3feb 100644 --- a/output/outelf32.c +++ b/output/outelf32.c @@ -49,6 +49,7 @@ #include "saa.h" #include "raa.h" #include "stdscan.h" +#include "eval.h" #include "output/outform.h" #include "output/outlib.h" #include "rbtree.h" @@ -113,10 +114,6 @@ static struct RAA *bsym; static struct SAA *strs; static uint32_t strslen; -static FILE *elffp; -static efunc error; -static evalfunc evaluate; - static struct Symbol *fwds; static char elf_module[FILENAME_MAX]; @@ -221,7 +218,7 @@ static void stabs32_generate(void); static void stabs32_cleanup(void); /* dwarf debugging routines */ -static void dwarf32_init(struct ofmt *, void *, FILE *, efunc); +static void dwarf32_init(void); static void dwarf32_linenum(const char *filename, int32_t linenumber, int32_t); static void dwarf32_output(int, void *); static void dwarf32_generate(void); @@ -238,12 +235,8 @@ static int32_t elf_gotpc_sect, elf_gotoff_sect; static int32_t elf_got_sect, elf_plt_sect; static int32_t elf_sym_sect, elf_tlsie_sect; -static void elf_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval) +static void elf_init(void) { - elffp = fp; - error = errfunc; - evaluate = eval; - (void)ldef; /* placate optimisers */ sects = NULL; nsects = sectlen = 0; syms = saa_init((int32_t)sizeof(struct Symbol)); @@ -260,32 +253,31 @@ static void elf_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval) fwds = NULL; elf_gotpc_sect = seg_alloc(); - ldef("..gotpc", elf_gotpc_sect + 1, 0L, NULL, false, false, &of_elf32, - error); + define_label("..gotpc", elf_gotpc_sect + 1, 0L, NULL, false, false, &of_elf32, + nasm_error); elf_gotoff_sect = seg_alloc(); - ldef("..gotoff", elf_gotoff_sect + 1, 0L, NULL, false, false, &of_elf32, - error); + define_label("..gotoff", elf_gotoff_sect + 1, 0L, NULL, false, false, &of_elf32, + nasm_error); elf_got_sect = seg_alloc(); - ldef("..got", elf_got_sect + 1, 0L, NULL, false, false, &of_elf32, - error); + define_label("..got", elf_got_sect + 1, 0L, NULL, false, false, &of_elf32, + nasm_error); elf_plt_sect = seg_alloc(); - ldef("..plt", elf_plt_sect + 1, 0L, NULL, false, false, &of_elf32, - error); + define_label("..plt", elf_plt_sect + 1, 0L, NULL, false, false, &of_elf32, + nasm_error); elf_sym_sect = seg_alloc(); - ldef("..sym", elf_sym_sect + 1, 0L, NULL, false, false, &of_elf32, - error); + define_label("..sym", elf_sym_sect + 1, 0L, NULL, false, false, &of_elf32, + nasm_error); elf_tlsie_sect = seg_alloc(); - ldef("..tlsie", elf_tlsie_sect + 1, 0L, NULL, false, false, &of_elf32, - error); + define_label("..tlsie", elf_tlsie_sect + 1, 0L, NULL, false, false, &of_elf32, + nasm_error); def_seg = seg_alloc(); } -static void elf_init_hack(FILE * fp, efunc errfunc, ldfunc ldef, - evalfunc eval) +static void elf_init_hack(void) { of_elf32.current_dfmt = of_elf.current_dfmt; /* Sync debugging format */ - elf_init(fp, errfunc, ldef, eval); + elf_init(); } static void elf_cleanup(int debuginfo) @@ -396,7 +388,7 @@ static int32_t elf_section_names(char *name, int pass, int *bits) if (align == 0) align = 1; if ((align - 1) & align) { /* means it's not a power of two */ - error(ERR_NONFATAL, "section alignment %d is not" + nasm_error(ERR_NONFATAL, "section alignment %d is not" " a power of two", align); align = 1; } @@ -426,7 +418,7 @@ static int32_t elf_section_names(char *name, int pass, int *bits) } else if (!nasm_stricmp(q, "nobits")) { type = SHT_NOBITS; } else if (pass == 1) { - error(ERR_WARNING, "Unknown section attribute '%s' ignored on" + nasm_error(ERR_WARNING, "Unknown section attribute '%s' ignored on" " declaration of section `%s'", q, name); } } @@ -434,7 +426,7 @@ static int32_t elf_section_names(char *name, int pass, int *bits) if (!strcmp(name, ".shstrtab") || !strcmp(name, ".symtab") || !strcmp(name, ".strtab")) { - error(ERR_NONFATAL, "attempt to redefine reserved section" + nasm_error(ERR_NONFATAL, "attempt to redefine reserved section" "name `%s'", name); return NO_SEG; } @@ -460,7 +452,7 @@ static int32_t elf_section_names(char *name, int pass, int *bits) if ((type && sects[i]->type != type) || (align && sects[i]->align != align) || (flags_and && ((sects[i]->flags & flags_and) != flags_or))) - error(ERR_WARNING, "section attributes ignored on" + nasm_error(ERR_WARNING, "section attributes ignored on" " redeclaration of section `%s'", name); } @@ -488,7 +480,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, if (strcmp(name, "..gotpc") && strcmp(name, "..gotoff") && strcmp(name, "..got") && strcmp(name, "..plt") && strcmp(name, "..sym") && strcmp(name, "..tlsie")) - error(ERR_NONFATAL, "unrecognised special symbol `%s'", name); + nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name); return; } @@ -511,10 +503,10 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, stdscan_reset(); stdscan_bufptr = p; tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, NULL, 1, error, NULL); + e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL); if (e) { if (!is_simple(e)) - error(ERR_NONFATAL, "cannot use relocatable" + nasm_error(ERR_NONFATAL, "cannot use relocatable" " expression as symbol size"); else (*s)->size = reloc_value(e); @@ -549,7 +541,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, if (nsects == 0 && segment == def_seg) { int tempint; if (segment != elf_section_names(".text", 2, &tempint)) - error(ERR_PANIC, + nasm_error(ERR_PANIC, "strange segment conditions in ELF driver"); sym->section = nsects; } else { @@ -574,11 +566,11 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, bool err; sym->symv.key = readnum(special, &err); if (err) - error(ERR_NONFATAL, "alignment constraint `%s' is not a" + nasm_error(ERR_NONFATAL, "alignment constraint `%s' is not a" " valid number", special); else if ((sym->symv.key | (sym->symv.key - 1)) != 2 * sym->symv.key - 1) - error(ERR_NONFATAL, "alignment constraint `%s' is not a" + nasm_error(ERR_NONFATAL, "alignment constraint `%s' is not a" " power of two", special); } special_used = true; @@ -620,7 +612,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, else if (!nasm_strnicmp(special, "notype", n)) sym->type |= STT_NOTYPE; else - error(ERR_NONFATAL, "unrecognised symbol type `%.*s'", + nasm_error(ERR_NONFATAL, "unrecognised symbol type `%.*s'", n, special); special += n; @@ -656,7 +648,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, stdscan_reset(); stdscan_bufptr = special + n; tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, &fwd, 0, error, + e = evaluate(stdscan, NULL, &tokval, &fwd, 0, nasm_error, NULL); if (fwd) { sym->nextfwd = fwds; @@ -664,7 +656,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, sym->name = nasm_strdup(name); } else if (e) { if (!is_simple(e)) - error(ERR_NONFATAL, "cannot use relocatable" + nasm_error(ERR_NONFATAL, "cannot use relocatable" " expression as symbol size"); else sym->size = reloc_value(e); @@ -687,7 +679,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, nlocals++; if (special && !special_used) - error(ERR_NONFATAL, "no special symbol features supported here"); + nasm_error(ERR_NONFATAL, "no special symbol features supported here"); } static void elf_add_reloc(struct Section *sect, int32_t segment, int type) @@ -762,7 +754,7 @@ static int32_t elf_add_gsym_reloc(struct Section *sect, } if (!s) { if (exact && offset != 0) - error(ERR_NONFATAL, "unable to find a suitable global symbol" + nasm_error(ERR_NONFATAL, "unable to find a suitable global symbol" " for this reference"); else elf_add_reloc(sect, segment, type); @@ -771,7 +763,7 @@ static int32_t elf_add_gsym_reloc(struct Section *sect, srb = rb_search(s->gsyms, offset); if (!srb || (exact && srb->key != offset)) { - error(ERR_NONFATAL, "unable to find a suitable global symbol" + nasm_error(ERR_NONFATAL, "unable to find a suitable global symbol" " for this reference"); return 0; } @@ -805,7 +797,7 @@ static void elf_out(int32_t segto, const void *data, */ if (segto == NO_SEG) { if (type != OUT_RESERVE) - error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]" + nasm_error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]" " space"); return; } @@ -819,7 +811,7 @@ static void elf_out(int32_t segto, const void *data, if (!s) { int tempint; /* ignored */ if (segto != elf_section_names(".text", 2, &tempint)) - error(ERR_PANIC, "strange segment conditions in ELF driver"); + nasm_error(ERR_PANIC, "strange segment conditions in ELF driver"); else { s = sects[nsects - 1]; i = nsects - 1; @@ -836,7 +828,7 @@ static void elf_out(int32_t segto, const void *data, /* end of debugging stuff */ if (s->type == SHT_NOBITS && type != OUT_RESERVE) { - error(ERR_WARNING, "attempt to initialize memory in" + nasm_error(ERR_WARNING, "attempt to initialize memory in" " BSS section `%s': ignored", s->name); s->len += realsize(type, size); return; @@ -844,21 +836,21 @@ static void elf_out(int32_t segto, const void *data, if (type == OUT_RESERVE) { if (s->type == SHT_PROGBITS) { - error(ERR_WARNING, "uninitialized space declared in" + nasm_error(ERR_WARNING, "uninitialized space declared in" " non-BSS section `%s': zeroing", s->name); elf_sect_write(s, NULL, size); } else s->len += size; } else if (type == OUT_RAWDATA) { if (segment != NO_SEG) - error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG"); + nasm_error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG"); elf_sect_write(s, data, size); } else if (type == OUT_ADDRESS) { bool gnu16 = false; addr = *(int64_t *)data; if (segment != NO_SEG) { if (segment % 2) { - error(ERR_NONFATAL, "ELF format does not support" + nasm_error(ERR_NONFATAL, "ELF format does not support" " segment base references"); } else { if (wrt == NO_SEG) { @@ -894,10 +886,10 @@ static void elf_out(int32_t segto, const void *data, R_386_32, false); } } else if (wrt == elf_plt_sect + 1) { - error(ERR_NONFATAL, "ELF format cannot produce non-PC-" + nasm_error(ERR_NONFATAL, "ELF format cannot produce non-PC-" "relative PLT references"); } else { - error(ERR_NONFATAL, "ELF format does not support this" + nasm_error(ERR_NONFATAL, "ELF format does not support this" " use of WRT"); wrt = NO_SEG; /* we can at least _try_ to continue */ } @@ -905,12 +897,12 @@ static void elf_out(int32_t segto, const void *data, } p = mydata; if (gnu16) { - error(ERR_WARNING | ERR_WARN_GNUELF, + nasm_error(ERR_WARNING | ERR_WARN_GNUELF, "16-bit relocations in ELF is a GNU extension"); WRITESHORT(p, addr); } else { if (size != 4 && segment != NO_SEG) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "Unsupported non-32-bit ELF relocation"); } WRITELONG(p, addr); @@ -918,17 +910,17 @@ static void elf_out(int32_t segto, const void *data, elf_sect_write(s, mydata, size); } else if (type == OUT_REL2ADR) { if (segment == segto) - error(ERR_PANIC, "intra-segment OUT_REL2ADR"); + nasm_error(ERR_PANIC, "intra-segment OUT_REL2ADR"); if (segment != NO_SEG && segment % 2) { - error(ERR_NONFATAL, "ELF format does not support" + nasm_error(ERR_NONFATAL, "ELF format does not support" " segment base references"); } else { if (wrt == NO_SEG) { - error(ERR_WARNING | ERR_WARN_GNUELF, + nasm_error(ERR_WARNING | ERR_WARN_GNUELF, "16-bit relocations in ELF is a GNU extension"); elf_add_reloc(s, segment, R_386_PC16); } else { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "Unsupported non-32-bit ELF relocation"); } } @@ -937,9 +929,9 @@ static void elf_out(int32_t segto, const void *data, elf_sect_write(s, mydata, 2L); } else if (type == OUT_REL4ADR) { if (segment == segto) - error(ERR_PANIC, "intra-segment OUT_REL4ADR"); + nasm_error(ERR_PANIC, "intra-segment OUT_REL4ADR"); if (segment != NO_SEG && segment % 2) { - error(ERR_NONFATAL, "ELF format does not support" + nasm_error(ERR_NONFATAL, "ELF format does not support" " segment base references"); } else { if (wrt == NO_SEG) { @@ -949,10 +941,10 @@ static void elf_out(int32_t segto, const void *data, } else if (wrt == elf_gotpc_sect + 1 || wrt == elf_gotoff_sect + 1 || wrt == elf_got_sect + 1) { - error(ERR_NONFATAL, "ELF format cannot produce PC-" + nasm_error(ERR_NONFATAL, "ELF format cannot produce PC-" "relative GOT references"); } else { - error(ERR_NONFATAL, "ELF format does not support this" + nasm_error(ERR_NONFATAL, "ELF format does not support this" " use of WRT"); wrt = NO_SEG; /* we can at least _try_ to continue */ } @@ -1019,28 +1011,28 @@ static void elf_write(void) /* * Output the ELF header. */ - fwrite("\177ELF\1\1\1", 7, 1, elffp); - fputc(elf_osabi, elffp); - fputc(elf_abiver, elffp); - fwritezero(7, elffp); - fwriteint16_t(1, elffp); /* ET_REL relocatable file */ - fwriteint16_t(3, elffp); /* EM_386 processor ID */ - fwriteint32_t(1L, elffp); /* EV_CURRENT file format version */ - fwriteint32_t(0L, elffp); /* no entry point */ - fwriteint32_t(0L, elffp); /* no program header table */ - fwriteint32_t(0x40L, elffp); /* section headers straight after + fwrite("\177ELF\1\1\1", 7, 1, ofile); + fputc(elf_osabi, ofile); + fputc(elf_abiver, ofile); + fwritezero(7, ofile); + fwriteint16_t(1, ofile); /* ET_REL relocatable file */ + fwriteint16_t(3, ofile); /* EM_386 processor ID */ + fwriteint32_t(1L, ofile); /* EV_CURRENT file format version */ + fwriteint32_t(0L, ofile); /* no entry point */ + fwriteint32_t(0L, ofile); /* no program header table */ + fwriteint32_t(0x40L, ofile); /* section headers straight after * ELF header plus alignment */ - fwriteint32_t(0L, elffp); /* 386 defines no special flags */ - fwriteint16_t(0x34, elffp); /* size of ELF header */ - fwriteint16_t(0, elffp); /* no program header table, again */ - fwriteint16_t(0, elffp); /* still no program header table */ - fwriteint16_t(0x28, elffp); /* size of section header */ - fwriteint16_t(nsections, elffp); /* number of sections */ - fwriteint16_t(sec_shstrtab, elffp); /* string table section index for + fwriteint32_t(0L, ofile); /* 386 defines no special flags */ + fwriteint16_t(0x34, ofile); /* size of ELF header */ + fwriteint16_t(0, ofile); /* no program header table, again */ + fwriteint16_t(0, ofile); /* still no program header table */ + fwriteint16_t(0x28, ofile); /* size of section header */ + fwriteint16_t(nsections, ofile); /* number of sections */ + fwriteint16_t(sec_shstrtab, ofile); /* string table section index for * section header table */ - fwriteint32_t(0L, elffp); /* align to 0x40 bytes */ - fwriteint32_t(0L, elffp); - fwriteint32_t(0L, elffp); + fwriteint32_t(0L, ofile); /* align to 0x40 bytes */ + fwriteint32_t(0L, ofile); + fwriteint32_t(0L, ofile); /* * Build the symbol table and relocation tables. @@ -1167,7 +1159,7 @@ static void elf_write(void) loclen, 0, 0, 1, 0); p += strlen(p) + 1; } - fwritezero(align, elffp); + fwritezero(align, ofile); /* * Now output the sections. @@ -1350,18 +1342,18 @@ static void elf_section_header(int name, int type, int flags, elf_sects[elf_nsect].is_saa = is_saa; elf_nsect++; - fwriteint32_t((int32_t)name, elffp); - fwriteint32_t((int32_t)type, elffp); - fwriteint32_t((int32_t)flags, elffp); - fwriteint32_t(0L, elffp); /* no address, ever, in object files */ - fwriteint32_t(type == 0 ? 0L : elf_foffs, elffp); - fwriteint32_t(datalen, elffp); + fwriteint32_t((int32_t)name, ofile); + fwriteint32_t((int32_t)type, ofile); + fwriteint32_t((int32_t)flags, ofile); + fwriteint32_t(0L, ofile); /* no address, ever, in object files */ + fwriteint32_t(type == 0 ? 0L : elf_foffs, ofile); + fwriteint32_t(datalen, ofile); if (data) elf_foffs += (datalen + SEG_ALIGN_1) & ~SEG_ALIGN_1; - fwriteint32_t((int32_t)link, elffp); - fwriteint32_t((int32_t)info, elffp); - fwriteint32_t((int32_t)align, elffp); - fwriteint32_t((int32_t)eltsize, elffp); + fwriteint32_t((int32_t)link, ofile); + fwriteint32_t((int32_t)info, ofile); + fwriteint32_t((int32_t)align, ofile); + fwriteint32_t((int32_t)eltsize, ofile); } static void elf_write_sections(void) @@ -1373,10 +1365,10 @@ static void elf_write_sections(void) int32_t reallen = (len + SEG_ALIGN_1) & ~SEG_ALIGN_1; int32_t align = reallen - len; if (elf_sects[i].is_saa) - saa_fpwrite(elf_sects[i].data, elffp); + saa_fpwrite(elf_sects[i].data, ofile); else - fwrite(elf_sects[i].data, len, 1, elffp); - fwritezero(align, elffp); + fwrite(elf_sects[i].data, len, 1, ofile); + fwritezero(align, ofile); } } @@ -1405,11 +1397,11 @@ static int elf_directive(enum directives directive, char *value, int pass) n = readnum(value, &err); if (err) { - error(ERR_NONFATAL, "`osabi' directive requires a parameter"); + nasm_error(ERR_NONFATAL, "`osabi' directive requires a parameter"); return 1; } if (n < 0 || n > 255) { - error(ERR_NONFATAL, "valid osabi numbers are 0 to 255"); + nasm_error(ERR_NONFATAL, "valid osabi numbers are 0 to 255"); return 1; } elf_osabi = n; @@ -1420,7 +1412,7 @@ static int elf_directive(enum directives directive, char *value, int pass) n = readnum(p+1, &err); if (err || n < 0 || n > 255) { - error(ERR_NONFATAL, "invalid ABI version number (valid: 0 to 255)"); + nasm_error(ERR_NONFATAL, "invalid ABI version number (valid: 0 to 255)"); return 1; } @@ -1432,10 +1424,10 @@ static int elf_directive(enum directives directive, char *value, int pass) } } -static void elf_filename(char *inname, char *outname, efunc error) +static void elf_filename(char *inname, char *outname) { strcpy(elf_module, inname); - standard_extension(inname, outname, ".o", error); + standard_extension(inname, outname, ".o"); } extern macros_t elf_stdmac[]; @@ -1807,13 +1799,8 @@ static void stabs32_cleanup(void) /* dwarf routines */ -static void dwarf32_init(struct ofmt *of, void *id, FILE * fp, efunc error) +static void dwarf32_init(void) { - (void)of; - (void)id; - (void)fp; - (void)error; - ndebugs = 3; /* 3 debug symbols */ } diff --git a/output/outelf64.c b/output/outelf64.c index c98bfae..1e73fcc 100644 --- a/output/outelf64.c +++ b/output/outelf64.c @@ -49,6 +49,7 @@ #include "saa.h" #include "raa.h" #include "stdscan.h" +#include "eval.h" #include "output/outform.h" #include "output/outlib.h" #include "rbtree.h" @@ -114,10 +115,6 @@ static struct RAA *bsym; static struct SAA *strs; static uint32_t strslen; -static FILE *elffp; -static efunc error; -static evalfunc evaluate; - static struct Symbol *fwds; static char elf_module[FILENAME_MAX]; @@ -229,7 +226,7 @@ static void stabs64_generate(void); static void stabs64_cleanup(void); /* dwarf debugging routines */ -static void dwarf64_init(struct ofmt *, void *, FILE *, efunc); +static void dwarf64_init(void); static void dwarf64_linenum(const char *filename, int32_t linenumber, int32_t); static void dwarf64_output(int, void *); static void dwarf64_generate(void); @@ -247,13 +244,9 @@ static int32_t elf_got_sect, elf_plt_sect; static int32_t elf_sym_sect; static int32_t elf_gottpoff_sect; -static void elf_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval) +static void elf_init(void) { maxbits = 64; - elffp = fp; - error = errfunc; - evaluate = eval; - (void)ldef; /* placate optimisers */ sects = NULL; nsects = sectlen = 0; syms = saa_init((int32_t)sizeof(struct Symbol)); @@ -270,23 +263,23 @@ static void elf_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval) fwds = NULL; elf_gotpc_sect = seg_alloc(); - ldef("..gotpc", elf_gotpc_sect + 1, 0L, NULL, false, false, &of_elf64, - error); + define_label("..gotpc", elf_gotpc_sect + 1, 0L, NULL, false, false, &of_elf64, + nasm_error); elf_gotoff_sect = seg_alloc(); - ldef("..gotoff", elf_gotoff_sect + 1, 0L, NULL, false, false, &of_elf64, - error); + define_label("..gotoff", elf_gotoff_sect + 1, 0L, NULL, false, false, &of_elf64, + nasm_error); elf_got_sect = seg_alloc(); - ldef("..got", elf_got_sect + 1, 0L, NULL, false, false, &of_elf64, - error); + define_label("..got", elf_got_sect + 1, 0L, NULL, false, false, &of_elf64, + nasm_error); elf_plt_sect = seg_alloc(); - ldef("..plt", elf_plt_sect + 1, 0L, NULL, false, false, &of_elf64, - error); + define_label("..plt", elf_plt_sect + 1, 0L, NULL, false, false, &of_elf64, + nasm_error); elf_sym_sect = seg_alloc(); - ldef("..sym", elf_sym_sect + 1, 0L, NULL, false, false, &of_elf64, - error); + define_label("..sym", elf_sym_sect + 1, 0L, NULL, false, false, &of_elf64, + nasm_error); elf_gottpoff_sect = seg_alloc(); - ldef("..gottpoff", elf_gottpoff_sect + 1, 0L, NULL, false, false, &of_elf64, - error); + define_label("..gottpoff", elf_gottpoff_sect + 1, 0L, NULL, false, false, &of_elf64, + nasm_error); def_seg = seg_alloc(); @@ -399,7 +392,7 @@ static int32_t elf_section_names(char *name, int pass, int *bits) if (align == 0) align = 1; if ((align - 1) & align) { /* means it's not a power of two */ - error(ERR_NONFATAL, "section alignment %d is not" + nasm_error(ERR_NONFATAL, "section alignment %d is not" " a power of two", align); align = 1; } @@ -429,7 +422,7 @@ static int32_t elf_section_names(char *name, int pass, int *bits) } else if (!nasm_stricmp(q, "nobits")) { type = SHT_NOBITS; } else if (pass == 1) { - error(ERR_WARNING, "Unknown section attribute '%s' ignored on" + nasm_error(ERR_WARNING, "Unknown section attribute '%s' ignored on" " declaration of section `%s'", q, name); } } @@ -437,7 +430,7 @@ static int32_t elf_section_names(char *name, int pass, int *bits) if (!strcmp(name, ".shstrtab") || !strcmp(name, ".symtab") || !strcmp(name, ".strtab")) { - error(ERR_NONFATAL, "attempt to redefine reserved section" + nasm_error(ERR_NONFATAL, "attempt to redefine reserved section" "name `%s'", name); return NO_SEG; } @@ -463,7 +456,7 @@ static int32_t elf_section_names(char *name, int pass, int *bits) if ((type && sects[i]->type != type) || (align && sects[i]->align != align) || (flags_and && ((sects[i]->flags & flags_and) != flags_or))) - error(ERR_WARNING, "incompatible section attributes ignored on" + nasm_error(ERR_WARNING, "incompatible section attributes ignored on" " redeclaration of section `%s'", name); } @@ -491,7 +484,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, if (strcmp(name, "..gotpc") && strcmp(name, "..gotoff") && strcmp(name, "..got") && strcmp(name, "..plt") && strcmp(name, "..sym") && strcmp(name, "..gottpoff")) - error(ERR_NONFATAL, "unrecognised special symbol `%s'", name); + nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name); return; } @@ -514,10 +507,10 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, stdscan_reset(); stdscan_bufptr = p; tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, NULL, 1, error, NULL); + e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL); if (e) { if (!is_simple(e)) - error(ERR_NONFATAL, "cannot use relocatable" + nasm_error(ERR_NONFATAL, "cannot use relocatable" " expression as symbol size"); else (*s)->size = reloc_value(e); @@ -552,7 +545,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, if (nsects == 0 && segment == def_seg) { int tempint; if (segment != elf_section_names(".text", 2, &tempint)) - error(ERR_PANIC, + nasm_error(ERR_PANIC, "strange segment conditions in ELF driver"); sym->section = nsects; } else { @@ -577,11 +570,11 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, bool err; sym->symv.key = readnum(special, &err); if (err) - error(ERR_NONFATAL, "alignment constraint `%s' is not a" + nasm_error(ERR_NONFATAL, "alignment constraint `%s' is not a" " valid number", special); else if ((sym->symv.key | (sym->symv.key - 1)) != 2 * sym->symv.key - 1) - error(ERR_NONFATAL, "alignment constraint `%s' is not a" + nasm_error(ERR_NONFATAL, "alignment constraint `%s' is not a" " power of two", special); } special_used = true; @@ -623,7 +616,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, else if (!nasm_strnicmp(special, "notype", n)) sym->type |= STT_NOTYPE; else - error(ERR_NONFATAL, "unrecognised symbol type `%.*s'", + nasm_error(ERR_NONFATAL, "unrecognised symbol type `%.*s'", n, special); special += n; @@ -659,7 +652,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, stdscan_reset(); stdscan_bufptr = special + n; tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, &fwd, 0, error, + e = evaluate(stdscan, NULL, &tokval, &fwd, 0, nasm_error, NULL); if (fwd) { sym->nextfwd = fwds; @@ -667,7 +660,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, sym->name = nasm_strdup(name); } else if (e) { if (!is_simple(e)) - error(ERR_NONFATAL, "cannot use relocatable" + nasm_error(ERR_NONFATAL, "cannot use relocatable" " expression as symbol size"); else sym->size = reloc_value(e); @@ -690,7 +683,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, nlocals++; if (special && !special_used) - error(ERR_NONFATAL, "no special symbol features supported here"); + nasm_error(ERR_NONFATAL, "no special symbol features supported here"); } static void elf_add_reloc(struct Section *sect, int32_t segment, @@ -767,7 +760,7 @@ static void elf_add_gsym_reloc(struct Section *sect, if (!s) { if (exact && offset) - error(ERR_NONFATAL, "invalid access to an external symbol"); + nasm_error(ERR_NONFATAL, "invalid access to an external symbol"); else elf_add_reloc(sect, segment, offset - pcrel, type); return; @@ -775,7 +768,7 @@ static void elf_add_gsym_reloc(struct Section *sect, srb = rb_search(s->gsyms, offset); if (!srb || (exact && srb->key != offset)) { - error(ERR_NONFATAL, "unable to find a suitable global symbol" + nasm_error(ERR_NONFATAL, "unable to find a suitable global symbol" " for this reference"); return; } @@ -818,7 +811,7 @@ static void elf_out(int32_t segto, const void *data, */ if (segto == NO_SEG) { if (type != OUT_RESERVE) - error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]" + nasm_error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]" " space"); return; } @@ -832,7 +825,7 @@ static void elf_out(int32_t segto, const void *data, if (!s) { int tempint; /* ignored */ if (segto != elf_section_names(".text", 2, &tempint)) - error(ERR_PANIC, "strange segment conditions in ELF driver"); + nasm_error(ERR_PANIC, "strange segment conditions in ELF driver"); else { s = sects[nsects - 1]; i = nsects - 1; @@ -849,7 +842,7 @@ static void elf_out(int32_t segto, const void *data, /* end of debugging stuff */ if (s->type == SHT_NOBITS && type != OUT_RESERVE) { - error(ERR_WARNING, "attempt to initialize memory in" + nasm_error(ERR_WARNING, "attempt to initialize memory in" " BSS section `%s': ignored", s->name); s->len += realsize(type, size); return; @@ -857,21 +850,21 @@ static void elf_out(int32_t segto, const void *data, if (type == OUT_RESERVE) { if (s->type == SHT_PROGBITS) { - error(ERR_WARNING, "uninitialized space declared in" + nasm_error(ERR_WARNING, "uninitialized space declared in" " non-BSS section `%s': zeroing", s->name); elf_sect_write(s, NULL, size); } else s->len += size; } else if (type == OUT_RAWDATA) { if (segment != NO_SEG) - error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG"); + nasm_error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG"); elf_sect_write(s, data, size); } else if (type == OUT_ADDRESS) { addr = *(int64_t *)data; if (segment == NO_SEG) { /* Do nothing */ } else if (segment % 2) { - error(ERR_NONFATAL, "ELF format does not support" + nasm_error(ERR_NONFATAL, "ELF format does not support" " segment base references"); } else { if (wrt == NO_SEG) { @@ -889,7 +882,7 @@ static void elf_out(int32_t segto, const void *data, elf_add_reloc(s, segment, addr, R_X86_64_64); break; default: - error(ERR_PANIC, "internal error elf64-hpa-871"); + nasm_error(ERR_PANIC, "internal error elf64-hpa-871"); break; } addr = 0; @@ -904,7 +897,7 @@ static void elf_out(int32_t segto, const void *data, addr = 0; } else if (wrt == elf_gotoff_sect + 1) { if (size != 8) { - error(ERR_NONFATAL, "ELF64 requires ..gotoff " + nasm_error(ERR_NONFATAL, "ELF64 requires ..gotoff " "references to be qword"); } else { elf_add_reloc(s, segment, addr, R_X86_64_GOTOFF64); @@ -923,7 +916,7 @@ static void elf_out(int32_t segto, const void *data, addr = 0; break; default: - error(ERR_NONFATAL, "invalid ..got reference"); + nasm_error(ERR_NONFATAL, "invalid ..got reference"); break; } } else if (wrt == elf_sym_sect + 1) { @@ -949,14 +942,14 @@ static void elf_out(int32_t segto, const void *data, addr = 0; break; default: - error(ERR_PANIC, "internal error elf64-hpa-903"); + nasm_error(ERR_PANIC, "internal error elf64-hpa-903"); break; } } else if (wrt == elf_plt_sect + 1) { - error(ERR_NONFATAL, "ELF format cannot produce non-PC-" + nasm_error(ERR_NONFATAL, "ELF format cannot produce non-PC-" "relative PLT references"); } else { - error(ERR_NONFATAL, "ELF format does not support this" + nasm_error(ERR_NONFATAL, "ELF format does not support this" " use of WRT"); } } @@ -964,18 +957,18 @@ static void elf_out(int32_t segto, const void *data, } else if (type == OUT_REL2ADR) { addr = *(int64_t *)data - size; if (segment == segto) - error(ERR_PANIC, "intra-segment OUT_REL2ADR"); + nasm_error(ERR_PANIC, "intra-segment OUT_REL2ADR"); if (segment == NO_SEG) { /* Do nothing */ } else if (segment % 2) { - error(ERR_NONFATAL, "ELF format does not support" + nasm_error(ERR_NONFATAL, "ELF format does not support" " segment base references"); } else { if (wrt == NO_SEG) { elf_add_reloc(s, segment, addr, R_X86_64_PC16); addr = 0; } else { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "Unsupported non-32-bit ELF relocation [2]"); } } @@ -983,11 +976,11 @@ static void elf_out(int32_t segto, const void *data, } else if (type == OUT_REL4ADR) { addr = *(int64_t *)data - size; if (segment == segto) - error(ERR_PANIC, "intra-segment OUT_REL4ADR"); + nasm_error(ERR_PANIC, "intra-segment OUT_REL4ADR"); if (segment == NO_SEG) { /* Do nothing */ } else if (segment % 2) { - error(ERR_NONFATAL, "ELF64 format does not support" + nasm_error(ERR_NONFATAL, "ELF64 format does not support" " segment base references"); } else { if (wrt == NO_SEG) { @@ -1004,14 +997,14 @@ static void elf_out(int32_t segto, const void *data, addr = 0; } else if (wrt == elf_gotoff_sect + 1 || wrt == elf_got_sect + 1) { - error(ERR_NONFATAL, "ELF64 requires ..gotoff references to be " + nasm_error(ERR_NONFATAL, "ELF64 requires ..gotoff references to be " "qword absolute"); } else if (wrt == elf_gottpoff_sect + 1) { elf_add_gsym_reloc(s, segment, addr+size, size, R_X86_64_GOTTPOFF, true); addr = 0; } else { - error(ERR_NONFATAL, "ELF64 format does not support this" + nasm_error(ERR_NONFATAL, "ELF64 format does not support this" " use of WRT"); } } @@ -1019,11 +1012,11 @@ static void elf_out(int32_t segto, const void *data, } else if (type == OUT_REL8ADR) { addr = *(int64_t *)data - size; if (segment == segto) - error(ERR_PANIC, "intra-segment OUT_REL8ADR"); + nasm_error(ERR_PANIC, "intra-segment OUT_REL8ADR"); if (segment == NO_SEG) { /* Do nothing */ } else if (segment % 2) { - error(ERR_NONFATAL, "ELF64 format does not support" + nasm_error(ERR_NONFATAL, "ELF64 format does not support" " segment base references"); } else { if (wrt == NO_SEG) { @@ -1036,13 +1029,13 @@ static void elf_out(int32_t segto, const void *data, addr = 0; } else if (wrt == elf_gotoff_sect + 1 || wrt == elf_got_sect + 1) { - error(ERR_NONFATAL, "ELF64 requires ..gotoff references to be " + nasm_error(ERR_NONFATAL, "ELF64 requires ..gotoff references to be " "absolute"); } else if (wrt == elf_gottpoff_sect + 1) { - error(ERR_NONFATAL, "ELF64 requires ..gottpoff references to be " + nasm_error(ERR_NONFATAL, "ELF64 requires ..gottpoff references to be " "dword"); } else { - error(ERR_NONFATAL, "ELF64 format does not support this" + nasm_error(ERR_NONFATAL, "ELF64 format does not support this" " use of WRT"); } } @@ -1112,24 +1105,24 @@ static void elf_write(void) /* * Output the ELF header. */ - fwrite("\177ELF\2\1\1", 7, 1, elffp); - fputc(elf_osabi, elffp); - fputc(elf_abiver, elffp); - fwritezero(7, elffp); - fwriteint16_t(ET_REL, elffp); /* relocatable file */ - fwriteint16_t(EM_X86_64, elffp); /* processor ID */ - fwriteint32_t(1L, elffp); /* EV_CURRENT file format version */ - fwriteint64_t(0L, elffp); /* no entry point */ - fwriteint64_t(0L, elffp); /* no program header table */ - fwriteint64_t(0x40L, elffp); /* section headers straight after + fwrite("\177ELF\2\1\1", 7, 1, ofile); + fputc(elf_osabi, ofile); + fputc(elf_abiver, ofile); + fwritezero(7, ofile); + fwriteint16_t(ET_REL, ofile); /* relocatable file */ + fwriteint16_t(EM_X86_64, ofile); /* processor ID */ + fwriteint32_t(1L, ofile); /* EV_CURRENT file format version */ + fwriteint64_t(0L, ofile); /* no entry point */ + fwriteint64_t(0L, ofile); /* no program header table */ + fwriteint64_t(0x40L, ofile); /* section headers straight after * ELF header plus alignment */ - fwriteint32_t(0L, elffp); /* 386 defines no special flags */ - fwriteint16_t(0x40, elffp); /* size of ELF header */ - fwriteint16_t(0, elffp); /* no program header table, again */ - fwriteint16_t(0, elffp); /* still no program header table */ - fwriteint16_t(sizeof(Elf64_Shdr), elffp); /* size of section header */ - fwriteint16_t(nsections, elffp); /* number of sections */ - fwriteint16_t(sec_shstrtab, elffp); /* string table section index for + fwriteint32_t(0L, ofile); /* 386 defines no special flags */ + fwriteint16_t(0x40, ofile); /* size of ELF header */ + fwriteint16_t(0, ofile); /* no program header table, again */ + fwriteint16_t(0, ofile); /* still no program header table */ + fwriteint16_t(sizeof(Elf64_Shdr), ofile); /* size of section header */ + fwriteint16_t(nsections, ofile); /* number of sections */ + fwriteint16_t(sec_shstrtab, ofile); /* string table section index for * section header table */ /* @@ -1256,7 +1249,7 @@ static void elf_write(void) loclen, 0, 0, 1, 0); p += strlen(p) + 1; } - fwritezero(align, elffp); + fwritezero(align, ofile); /* * Now output the sections. @@ -1437,18 +1430,18 @@ static void elf_section_header(int name, int type, uint64_t flags, elf_sects[elf_nsect].is_saa = is_saa; elf_nsect++; - fwriteint32_t((int32_t)name, elffp); - fwriteint32_t((int32_t)type, elffp); - fwriteint64_t((int64_t)flags, elffp); - fwriteint64_t(0L, elffp); /* no address, ever, in object files */ - fwriteint64_t(type == 0 ? 0L : elf_foffs, elffp); - fwriteint64_t(datalen, elffp); + fwriteint32_t((int32_t)name, ofile); + fwriteint32_t((int32_t)type, ofile); + fwriteint64_t((int64_t)flags, ofile); + fwriteint64_t(0L, ofile); /* no address, ever, in object files */ + fwriteint64_t(type == 0 ? 0L : elf_foffs, ofile); + fwriteint64_t(datalen, ofile); if (data) elf_foffs += (datalen + SEG_ALIGN_1) & ~SEG_ALIGN_1; - fwriteint32_t((int32_t)link, elffp); - fwriteint32_t((int32_t)info, elffp); - fwriteint64_t((int64_t)align, elffp); - fwriteint64_t((int64_t)eltsize, elffp); + fwriteint32_t((int32_t)link, ofile); + fwriteint32_t((int32_t)info, ofile); + fwriteint64_t((int64_t)align, ofile); + fwriteint64_t((int64_t)eltsize, ofile); } static void elf_write_sections(void) @@ -1460,10 +1453,10 @@ static void elf_write_sections(void) int32_t reallen = (len + SEG_ALIGN_1) & ~SEG_ALIGN_1; int32_t align = reallen - len; if (elf_sects[i].is_saa) - saa_fpwrite(elf_sects[i].data, elffp); + saa_fpwrite(elf_sects[i].data, ofile); else - fwrite(elf_sects[i].data, len, 1, elffp); - fwritezero(align, elffp); + fwrite(elf_sects[i].data, len, 1, ofile); + fwritezero(align, ofile); } } @@ -1496,11 +1489,11 @@ static int elf_directive(enum directives directive, char *value, int pass) n = readnum(value, &err); if (err) { - error(ERR_NONFATAL, "`osabi' directive requires a parameter"); + nasm_error(ERR_NONFATAL, "`osabi' directive requires a parameter"); return 1; } if (n < 0 || n > 255) { - error(ERR_NONFATAL, "valid osabi numbers are 0 to 255"); + nasm_error(ERR_NONFATAL, "valid osabi numbers are 0 to 255"); return 1; } elf_osabi = n; @@ -1511,7 +1504,7 @@ static int elf_directive(enum directives directive, char *value, int pass) n = readnum(p+1, &err); if (err || n < 0 || n > 255) { - error(ERR_NONFATAL, "invalid ABI version number (valid: 0 to 255)"); + nasm_error(ERR_NONFATAL, "invalid ABI version number (valid: 0 to 255)"); return 1; } @@ -1523,10 +1516,10 @@ static int elf_directive(enum directives directive, char *value, int pass) } } -static void elf_filename(char *inname, char *outname, efunc error) +static void elf_filename(char *inname, char *outname) { strcpy(elf_module, inname); - standard_extension(inname, outname, ".o", error); + standard_extension(inname, outname, ".o"); } extern macros_t elf_stdmac[]; @@ -1883,13 +1876,8 @@ static void stabs64_cleanup(void) nasm_free(stabstrbuf); } /* dwarf routines */ -static void dwarf64_init(struct ofmt *of, void *id, FILE * fp, efunc error) +static void dwarf64_init(void) { - (void)of; - (void)id; - (void)fp; - (void)error; - ndebugs = 3; /* 3 debug symbols */ } diff --git a/output/outform.c b/output/outform.c index f8cdca8..fa30986 100644 --- a/output/outform.c +++ b/output/outform.c @@ -47,55 +47,46 @@ #define BUILD_DRIVERS_ARRAY #include "output/outform.h" -static int ndrivers = 0; - struct ofmt *ofmt_find(char *name) { /* find driver */ - int i; - - for (i = 0; i < ndrivers; i++) - if (!strcmp(name, drivers[i]->shortname)) - return drivers[i]; + struct ofmt **ofp, *of; + for (ofp = drivers; (of = *ofp); ofp++) { + if (!nasm_stricmp(name, of->shortname)) + return of; + } return NULL; } + struct dfmt *dfmt_find(struct ofmt *ofmt, char *name) { /* find driver */ - struct dfmt **dfmt = ofmt->debug_formats; - while (*dfmt) { - if (!strcmp(name, (*dfmt)->shortname)) - return (*dfmt); - dfmt++; + struct dfmt **dfp, *df; + + for (dfp = ofmt->debug_formats; (df = *dfp); dfp++) { + if (!nasm_stricmp(name, df->shortname)) + return df; } return NULL; } void ofmt_list(struct ofmt *deffmt, FILE * fp) { - int i; - for (i = 0; i < ndrivers; i++) - fprintf(fp, " %c %-10s%s\n", - drivers[i] == deffmt ? '*' : ' ', - drivers[i]->shortname, drivers[i]->fullname); -} -void dfmt_list(struct ofmt *ofmt, FILE * fp) -{ - struct dfmt **drivers = ofmt->debug_formats; - while (*drivers) { + struct ofmt **ofp, *of; + + for (ofp = drivers; (of = *ofp); ofp++) { fprintf(fp, " %c %-10s%s\n", - drivers[0] == ofmt->current_dfmt ? '*' : ' ', - drivers[0]->shortname, drivers[0]->fullname); - drivers++; + of == deffmt ? '*' : ' ', + of->shortname, of->fullname); } } -struct ofmt *ofmt_register(efunc error) + +void dfmt_list(struct ofmt *ofmt, FILE *fp) { - for (ndrivers = 0; drivers[ndrivers] != NULL; ndrivers++) ; + struct dfmt **dfp, *df; - if (ndrivers == 0) { - error(ERR_PANIC | ERR_NOFILE, - "No output drivers given at compile time"); + for (dfp = ofmt->debug_formats; (df = *dfp); dfp++) { + fprintf(fp, " %c %-10s%s\n", + df == ofmt->current_dfmt ? '*' : ' ', + df->shortname, df->fullname); } - - return (&OF_DEFAULT); } diff --git a/output/outform.h b/output/outform.h index 391aabe..74522ed 100644 --- a/output/outform.h +++ b/output/outform.h @@ -253,11 +253,6 @@ #define OF_DEFAULT of_bin #endif -#ifdef BUILD_DRIVERS_ARRAY /* only if included from outform.c */ - -/* pull in the externs for the different formats, then make the *drivers - * array based on the above defines */ - extern struct ofmt of_bin; extern struct ofmt of_ith; extern struct ofmt of_srec; @@ -278,7 +273,12 @@ extern struct ofmt of_macho; extern struct ofmt of_macho64; extern struct ofmt of_dbg; -struct ofmt *drivers[] = { +#ifdef BUILD_DRIVERS_ARRAY /* only if included from outform.c */ + +/* pull in the externs for the different formats, then make the *drivers + * array based on the above defines */ + +static struct ofmt *drivers[] = { #ifdef OF_BIN &of_bin, &of_ith, diff --git a/output/outieee.c b/output/outieee.c index 534e561..0fc3c40 100644 --- a/output/outieee.c +++ b/output/outieee.c @@ -87,9 +87,6 @@ static char ieee_infile[FILENAME_MAX]; static int ieee_uppercase; -static efunc error; -static ldfunc deflabel; -static FILE *ofp; static bool any_segs; static int arrindex; @@ -207,12 +204,8 @@ static void ieee_unqualified_name(char *, char *); /* * pup init */ -static void ieee_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval) +static void ieee_init(void) { - (void)eval; - ofp = fp; - error = errfunc; - deflabel = ldef; any_segs = false; fpubhead = NULL; fpubtail = &fpubhead; @@ -306,7 +299,7 @@ static void ieee_deflabel(char *name, int32_t segment, int i; if (special) { - error(ERR_NONFATAL, "unrecognised symbol type `%s'", special); + nasm_error(ERR_NONFATAL, "unrecognised symbol type `%s'", special); } /* * First check for the double-period, signifying something @@ -414,7 +407,7 @@ static void ieee_out(int32_t segto, const void *data, */ if (segto == NO_SEG) { if (type != OUT_RESERVE) - error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]" + nasm_error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]" " space"); return; } @@ -426,7 +419,7 @@ static void ieee_out(int32_t segto, const void *data, if (!any_segs) { int tempint; /* ignored */ if (segto != ieee_segment("__NASMDEFSEG", 2, &tempint)) - error(ERR_PANIC, "strange segment conditions in IEEE driver"); + nasm_error(ERR_PANIC, "strange segment conditions in IEEE driver"); } /* @@ -436,7 +429,7 @@ static void ieee_out(int32_t segto, const void *data, if (seg->index == segto) break; if (!seg) - error(ERR_PANIC, "code directed to nonexistent segment?"); + nasm_error(ERR_PANIC, "code directed to nonexistent segment?"); if (type == OUT_RAWDATA) { ucdata = data; @@ -445,7 +438,7 @@ static void ieee_out(int32_t segto, const void *data, } else if (type == OUT_ADDRESS || type == OUT_REL2ADR || type == OUT_REL4ADR) { if (segment == NO_SEG && type != OUT_ADDRESS) - error(ERR_NONFATAL, "relative call to absolute address not" + nasm_error(ERR_NONFATAL, "relative call to absolute address not" " supported by IEEE format"); ldata = *(int64_t *)data; if (type == OUT_REL2ADR) @@ -535,15 +528,15 @@ static void ieee_write_fixup(int32_t segment, int32_t wrt, s.addend = 0; s.id2 = eb->index[i]; } else - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "Source of WRT must be an offset"); } } else - error(ERR_PANIC, + nasm_error(ERR_PANIC, "unrecognised WRT value in ieee_write_fixup"); } else - error(ERR_NONFATAL, "target of WRT must be a section "); + nasm_error(ERR_NONFATAL, "target of WRT must be a section "); } s.size = size; ieee_install_fixup(segto, &s); @@ -582,7 +575,7 @@ static void ieee_write_fixup(int32_t segment, int32_t wrt, */ if (eb) { if (realtype == OUT_REL2ADR || realtype == OUT_REL4ADR) { - error(ERR_PANIC, + nasm_error(ERR_PANIC, "Segment of a rel not supported in ieee_write_fixup"); } else { /* If we want the segment */ @@ -593,7 +586,7 @@ static void ieee_write_fixup(int32_t segment, int32_t wrt, } else /* If we get here the seg value doesn't make sense */ - error(ERR_PANIC, + nasm_error(ERR_PANIC, "unrecognised segment value in ieee_write_fixup"); } @@ -648,12 +641,12 @@ static void ieee_write_fixup(int32_t segment, int32_t wrt, } else /* If we get here the seg value doesn't make sense */ - error(ERR_PANIC, + nasm_error(ERR_PANIC, "unrecognised segment value in ieee_write_fixup"); } } if (size != 2 && s.ftype == FT_SEG) - error(ERR_NONFATAL, "IEEE format can only handle 2-byte" + nasm_error(ERR_NONFATAL, "IEEE format can only handle 2-byte" " segment base references"); s.size = size; ieee_install_fixup(segto, &s); @@ -731,7 +724,7 @@ static int32_t ieee_segment(char *name, int pass, int *bits) ieee_idx++; if (!strcmp(seg->name, name)) { if (attrs > 0 && pass == 1) - error(ERR_WARNING, "segment attributes specified on" + nasm_error(ERR_WARNING, "segment attributes specified on" " redeclaration of segment: ignoring"); if (seg->use32) *bits = 32; @@ -787,7 +780,7 @@ static int32_t ieee_segment(char *name, int pass, int *bits) seg->align = 1; if (rn_error) { seg->align = 1; - error(ERR_NONFATAL, "segment alignment should be" + nasm_error(ERR_NONFATAL, "segment alignment should be" " numeric"); } switch ((int)seg->align) { @@ -802,7 +795,7 @@ static int32_t ieee_segment(char *name, int pass, int *bits) case 128: break; default: - error(ERR_NONFATAL, "invalid alignment value %d", + nasm_error(ERR_NONFATAL, "invalid alignment value %d", seg->align); seg->align = 1; break; @@ -810,18 +803,18 @@ static int32_t ieee_segment(char *name, int pass, int *bits) } else if (!nasm_strnicmp(p, "absolute=", 9)) { seg->align = SEG_ABS + readnum(p + 9, &rn_error); if (rn_error) - error(ERR_NONFATAL, "argument to `absolute' segment" + nasm_error(ERR_NONFATAL, "argument to `absolute' segment" " attribute should be numeric"); } } ieee_seg_needs_update = seg; if (seg->align >= SEG_ABS) - deflabel(name, NO_SEG, seg->align - SEG_ABS, - NULL, false, false, &of_ieee, error); + define_label(name, NO_SEG, seg->align - SEG_ABS, + NULL, false, false, &of_ieee, nasm_error); else - deflabel(name, seg->index + 1, 0L, - NULL, false, false, &of_ieee, error); + define_label(name, seg->index + 1, 0L, + NULL, false, false, &of_ieee, nasm_error); ieee_seg_needs_update = NULL; if (seg->use32) @@ -877,10 +870,10 @@ static int32_t ieee_segbase(int32_t segment) /* * filename */ -static void ieee_filename(char *inname, char *outname, efunc error) +static void ieee_filename(char *inname, char *outname) { strcpy(ieee_infile, inname); - standard_extension(inname, outname, ".o", error); + standard_extension(inname, outname, ".o"); } static void ieee_write_file(int debuginfo) @@ -978,7 +971,7 @@ static void ieee_write_file(int debuginfo) if (seg->index == ieee_entry_seg) break; if (!seg) - error(ERR_PANIC, "Start address records are incorrect"); + nasm_error(ERR_PANIC, "Start address records are incorrect"); else ieee_putascii("ASG,R%X,%lX,+.\n", seg->ieee_index, ieee_entry_ofs); @@ -1160,7 +1153,7 @@ static void ieee_putascii(char *format, ...) if ((uint8_t)buffer[i] > 31) checksum += buffer[i]; va_end(ap); - fprintf(ofp, buffer); + fprintf(ofile, buffer); } /* @@ -1283,13 +1276,9 @@ static void ieee_unqualified_name(char *dest, char *source) } else strcpy(dest, source); } -void dbgls_init(struct ofmt *of, void *id, FILE * fp, efunc error) +void dbgls_init(void) { int tempint; - (void)of; - (void)id; - (void)fp; - (void)error; fnhead = NULL; fntail = &fnhead; @@ -1345,7 +1334,7 @@ static void dbgls_linnum(const char *lnfname, int32_t lineno, int32_t segto) if (!any_segs) { int tempint; /* ignored */ if (segto != ieee_segment("__NASMDEFSEG", 2, &tempint)) - error(ERR_PANIC, "strange segment conditions in OBJ driver"); + nasm_error(ERR_PANIC, "strange segment conditions in OBJ driver"); } /* @@ -1355,7 +1344,7 @@ static void dbgls_linnum(const char *lnfname, int32_t lineno, int32_t segto) if (seg->index == segto) break; if (!seg) - error(ERR_PANIC, "lineno directed to nonexistent segment?"); + nasm_error(ERR_PANIC, "lineno directed to nonexistent segment?"); for (fn = fnhead; fn; fn = fn->next) { if (!nasm_stricmp(lnfname, fn->name)) diff --git a/output/outlib.h b/output/outlib.h index 4089a6a..babe1d0 100644 --- a/output/outlib.h +++ b/output/outlib.h @@ -44,7 +44,7 @@ int null_directive(enum directives directive, char *value, int pass); /* Do-nothing versions of all the debug routines */ struct ofmt; -void null_debug_init(struct ofmt *of, void *id, FILE * fp, efunc error); +void null_debug_init(void); void null_debug_linenum(const char *filename, int32_t linenumber, int32_t segto); void null_debug_deflabel(char *name, int32_t segment, int64_t offset, diff --git a/output/outmacho32.c b/output/outmacho32.c index 3a2e59c..234cf28 100644 --- a/output/outmacho32.c +++ b/output/outmacho32.c @@ -51,6 +51,7 @@ #include "nasmlib.h" #include "saa.h" #include "raa.h" +#include "eval.h" #include "output/outform.h" #include "output/outlib.h" @@ -207,9 +208,7 @@ static struct RAA *extsyms; static struct SAA *strs; static uint32_t strslen; -static FILE *machofp; static efunc error; -static evalfunc evaluate; extern struct ofmt of_macho; @@ -328,17 +327,10 @@ static uint8_t get_section_fileindex_by_index(const int32_t index) return NO_SECT; } -static void macho_init(FILE * fp, efunc errfunc, ldfunc ldef, - evalfunc eval) +static void macho_init(void) { char zero = 0; - machofp = fp; - error = errfunc; - evaluate = eval; - - (void)ldef; /* placate optimisers */ - sects = NULL; sectstail = §s; @@ -713,9 +705,9 @@ static int32_t macho_segbase(int32_t section) return section; } -static void macho_filename(char *inname, char *outname, efunc error) +static void macho_filename(char *inname, char *outname) { - standard_extension(inname, outname, ".o", error); + standard_extension(inname, outname, ".o"); } extern macros_t macho_stdmac[]; @@ -869,13 +861,13 @@ static void macho_calculate_sizes (void) static void macho_write_header (void) { - fwriteint32_t(MH_MAGIC, machofp); /* magic */ - fwriteint32_t(CPU_TYPE_I386, machofp); /* CPU type */ - fwriteint32_t(CPU_SUBTYPE_I386_ALL, machofp); /* CPU subtype */ - fwriteint32_t(MH_OBJECT, machofp); /* Mach-O file type */ - fwriteint32_t(head_ncmds, machofp); /* number of load commands */ - fwriteint32_t(head_sizeofcmds, machofp); /* size of load commands */ - fwriteint32_t(0, machofp); /* no flags */ + fwriteint32_t(MH_MAGIC, ofile); /* magic */ + fwriteint32_t(CPU_TYPE_I386, ofile); /* CPU type */ + fwriteint32_t(CPU_SUBTYPE_I386_ALL, ofile); /* CPU subtype */ + fwriteint32_t(MH_OBJECT, ofile); /* Mach-O file type */ + fwriteint32_t(head_ncmds, ofile); /* number of load commands */ + fwriteint32_t(head_sizeofcmds, ofile); /* size of load commands */ + fwriteint32_t(0, ofile); /* no flags */ } /* Write out the segment load command at offset. */ @@ -886,56 +878,56 @@ static uint32_t macho_write_segment (uint32_t offset) uint32_t s_reloff = 0; struct section *s; - fwriteint32_t(LC_SEGMENT, machofp); /* cmd == LC_SEGMENT */ + fwriteint32_t(LC_SEGMENT, ofile); /* cmd == LC_SEGMENT */ /* size of load command including section load commands */ fwriteint32_t(MACHO_SEGCMD_SIZE + seg_nsects * - MACHO_SECTCMD_SIZE, machofp); + MACHO_SECTCMD_SIZE, ofile); /* in an MH_OBJECT file all sections are in one unnamed (name ** all zeros) segment */ - fwritezero(16, machofp); - fwriteint32_t(0, machofp); /* in-memory offset */ - fwriteint32_t(seg_vmsize, machofp); /* in-memory size */ - fwriteint32_t(offset, machofp); /* in-file offset to data */ - fwriteint32_t(seg_filesize, machofp); /* in-file size */ - fwriteint32_t(VM_PROT_DEFAULT, machofp); /* maximum vm protection */ - fwriteint32_t(VM_PROT_DEFAULT, machofp); /* initial vm protection */ - fwriteint32_t(seg_nsects, machofp); /* number of sections */ - fwriteint32_t(0, machofp); /* no flags */ + fwritezero(16, ofile); + fwriteint32_t(0, ofile); /* in-memory offset */ + fwriteint32_t(seg_vmsize, ofile); /* in-memory size */ + fwriteint32_t(offset, ofile); /* in-file offset to data */ + fwriteint32_t(seg_filesize, ofile); /* in-file size */ + fwriteint32_t(VM_PROT_DEFAULT, ofile); /* maximum vm protection */ + fwriteint32_t(VM_PROT_DEFAULT, ofile); /* initial vm protection */ + fwriteint32_t(seg_nsects, ofile); /* number of sections */ + fwriteint32_t(0, ofile); /* no flags */ /* emit section headers */ for (s = sects; s != NULL; s = s->next) { - fwrite(s->sectname, sizeof(s->sectname), 1, machofp); - fwrite(s->segname, sizeof(s->segname), 1, machofp); - fwriteint32_t(s->addr, machofp); - fwriteint32_t(s->size, machofp); + fwrite(s->sectname, sizeof(s->sectname), 1, ofile); + fwrite(s->segname, sizeof(s->segname), 1, ofile); + fwriteint32_t(s->addr, ofile); + fwriteint32_t(s->size, ofile); /* dummy data for zerofill sections or proper values */ if ((s->flags & SECTION_TYPE) != S_ZEROFILL) { - fwriteint32_t(offset, machofp); + fwriteint32_t(offset, ofile); /* Write out section alignment, as a power of two. e.g. 32-bit word alignment would be 2 (2^^2 = 4). */ if (s->align == -1) s->align = DEFAULT_SECTION_ALIGNMENT; - fwriteint32_t(s->align, machofp); + fwriteint32_t(s->align, ofile); /* To be compatible with cctools as we emit a zero reloff if we have no relocations. */ - fwriteint32_t(s->nreloc ? rel_base + s_reloff : 0, machofp); - fwriteint32_t(s->nreloc, machofp); + fwriteint32_t(s->nreloc ? rel_base + s_reloff : 0, ofile); + fwriteint32_t(s->nreloc, ofile); offset += s->size; s_reloff += s->nreloc * MACHO_RELINFO_SIZE; } else { - fwriteint32_t(0, machofp); - fwriteint32_t(0, machofp); - fwriteint32_t(0, machofp); - fwriteint32_t(0, machofp); + fwriteint32_t(0, ofile); + fwriteint32_t(0, ofile); + fwriteint32_t(0, ofile); + fwriteint32_t(0, ofile); } - fwriteint32_t(s->flags, machofp); /* flags */ - fwriteint32_t(0, machofp); /* reserved */ - fwriteint32_t(0, machofp); /* reserved */ + fwriteint32_t(s->flags, ofile); /* flags */ + fwriteint32_t(0, ofile); /* reserved */ + fwriteint32_t(0, ofile); /* reserved */ } rel_padcnt = rel_base - offset; @@ -952,14 +944,14 @@ static void macho_write_relocs (struct reloc *r) while (r) { uint32_t word2; - fwriteint32_t(r->addr, machofp); /* reloc offset */ + fwriteint32_t(r->addr, ofile); /* reloc offset */ word2 = r->snum; word2 |= r->pcrel << 24; word2 |= r->length << 25; word2 |= r->ext << 27; word2 |= r->type << 28; - fwriteint32_t(word2, machofp); /* reloc data */ + fwriteint32_t(word2, ofile); /* reloc data */ r = r->next; } @@ -1026,11 +1018,11 @@ static void macho_write_section (void) } /* dump the section data to file */ - saa_fpwrite(s->data, machofp); + saa_fpwrite(s->data, ofile); } /* pad last section up to reloc entries on int32_t boundary */ - fwritezero(rel_padcnt, machofp); + fwritezero(rel_padcnt, ofile); /* emit relocation entries */ for (s = sects; s != NULL; s = s->next) @@ -1050,10 +1042,10 @@ static void macho_write_symtab (void) for (sym = syms; sym != NULL; sym = sym->next) { if ((sym->type & N_EXT) == 0) { - fwriteint32_t(sym->strx, machofp); /* string table entry number */ - fwrite(&sym->type, 1, 1, machofp); /* symbol type */ - fwrite(&sym->sect, 1, 1, machofp); /* section */ - fwriteint16_t(sym->desc, machofp); /* description */ + fwriteint32_t(sym->strx, ofile); /* string table entry number */ + fwrite(&sym->type, 1, 1, ofile); /* symbol type */ + fwrite(&sym->sect, 1, 1, ofile); /* section */ + fwriteint16_t(sym->desc, ofile); /* description */ /* Fix up the symbol value now that we know the final section sizes. */ @@ -1063,16 +1055,16 @@ static void macho_write_symtab (void) sym->value += s->size; } - fwriteint32_t(sym->value, machofp); /* value (i.e. offset) */ + fwriteint32_t(sym->value, ofile); /* value (i.e. offset) */ } } for (i = 0; i < nextdefsym; i++) { sym = extdefsyms[i]; - fwriteint32_t(sym->strx, machofp); - fwrite(&sym->type, 1, 1, machofp); /* symbol type */ - fwrite(&sym->sect, 1, 1, machofp); /* section */ - fwriteint16_t(sym->desc, machofp); /* description */ + fwriteint32_t(sym->strx, ofile); + fwrite(&sym->type, 1, 1, ofile); /* symbol type */ + fwrite(&sym->sect, 1, 1, ofile); /* section */ + fwriteint16_t(sym->desc, ofile); /* description */ /* Fix up the symbol value now that we know the final section sizes. */ @@ -1082,15 +1074,15 @@ static void macho_write_symtab (void) sym->value += s->size; } - fwriteint32_t(sym->value, machofp); /* value (i.e. offset) */ + fwriteint32_t(sym->value, ofile); /* value (i.e. offset) */ } for (i = 0; i < nundefsym; i++) { sym = undefsyms[i]; - fwriteint32_t(sym->strx, machofp); - fwrite(&sym->type, 1, 1, machofp); /* symbol type */ - fwrite(&sym->sect, 1, 1, machofp); /* section */ - fwriteint16_t(sym->desc, machofp); /* description */ + fwriteint32_t(sym->strx, ofile); + fwrite(&sym->type, 1, 1, ofile); /* symbol type */ + fwrite(&sym->sect, 1, 1, ofile); /* section */ + fwriteint16_t(sym->desc, ofile); /* description */ /* Fix up the symbol value now that we know the final section sizes. */ @@ -1100,7 +1092,7 @@ static void macho_write_symtab (void) sym->value += s->size; } - fwriteint32_t(sym->value, machofp); /* value (i.e. offset) */ + fwriteint32_t(sym->value, ofile); /* value (i.e. offset) */ } } @@ -1217,15 +1209,15 @@ static void macho_write (void) if (nsyms > 0) { /* write out symbol command */ - fwriteint32_t(LC_SYMTAB, machofp); /* cmd == LC_SYMTAB */ - fwriteint32_t(MACHO_SYMCMD_SIZE, machofp); /* size of load command */ - fwriteint32_t(offset, machofp); /* symbol table offset */ - fwriteint32_t(nsyms, machofp); /* number of symbol + fwriteint32_t(LC_SYMTAB, ofile); /* cmd == LC_SYMTAB */ + fwriteint32_t(MACHO_SYMCMD_SIZE, ofile); /* size of load command */ + fwriteint32_t(offset, ofile); /* symbol table offset */ + fwriteint32_t(nsyms, ofile); /* number of symbol ** table entries */ offset += nsyms * MACHO_NLIST_SIZE; - fwriteint32_t(offset, machofp); /* string table offset */ - fwriteint32_t(strslen, machofp); /* string table size */ + fwriteint32_t(offset, ofile); /* string table offset */ + fwriteint32_t(strslen, ofile); /* string table size */ } /* emit section data */ @@ -1239,7 +1231,7 @@ static void macho_write (void) /* we don't need to pad here since MACHO_NLIST_SIZE == 12 */ /* emit string table */ - saa_fpwrite(strs, machofp); + saa_fpwrite(strs, ofile); } /* We do quite a bit here, starting with finalizing all of the data for the object file, writing, and then freeing all of the data from diff --git a/output/outmacho64.c b/output/outmacho64.c index d3f5a8e..3c38ddb 100644 --- a/output/outmacho64.c +++ b/output/outmacho64.c @@ -209,10 +209,6 @@ static struct RAA *extsyms; static struct SAA *strs; static uint32_t strslen; -static FILE *machofp; -static efunc error; -static evalfunc evaluate; - extern struct ofmt of_macho64; /* Global file information. This should be cleaned up into either @@ -327,7 +323,7 @@ static uint8_t get_section_fileindex_by_index(const int32_t index) return i; if (i == MAX_SECT) - error(ERR_WARNING, + nasm_error(ERR_WARNING, "too many sections (>255) - clipped by fileindex"); return NO_SECT; @@ -355,17 +351,11 @@ static struct symbol *get_closest_section_symbol_by_offset(uint8_t fileindex, in */ static int32_t macho_gotpcrel_sect; -static void macho_init(FILE * fp, efunc errfunc, ldfunc ldef, - evalfunc eval) +static void macho_init(void) { char zero = 0; - maxbits = 64; - machofp = fp; - error = errfunc; - evaluate = eval; - - (void)ldef; /* placate optimizers */ + maxbits = 64; sects = NULL; sectstail = §s; @@ -387,7 +377,7 @@ static void macho_init(FILE * fp, efunc errfunc, ldfunc ldef, /* add special symbol for ..gotpcrel */ macho_gotpcrel_sect = seg_alloc(); macho_gotpcrel_sect ++; - ldef("..gotpcrel", macho_gotpcrel_sect, 0L, NULL, false, false, &of_macho64, error); + define_label("..gotpcrel", macho_gotpcrel_sect, 0L, NULL, false, false, &of_macho64, nasm_error); } static void sect_write(struct section *sect, @@ -521,7 +511,7 @@ static void macho_output(int32_t secto, const void *data, if (secto == NO_SEG) { if (type != OUT_RESERVE) - error(ERR_NONFATAL, "attempt to assemble code in " + nasm_error(ERR_NONFATAL, "attempt to assemble code in " "[ABSOLUTE] space"); return; @@ -530,19 +520,19 @@ static void macho_output(int32_t secto, const void *data, s = get_section_by_index(secto); if (s == NULL) { - error(ERR_WARNING, "attempt to assemble code in" + nasm_error(ERR_WARNING, "attempt to assemble code in" " section %d: defaulting to `.text'", secto); s = get_section_by_name("__TEXT", "__text"); /* should never happen */ if (s == NULL) - error(ERR_PANIC, "text section not found"); + nasm_error(ERR_PANIC, "text section not found"); } sbss = get_section_by_name("__DATA", "__bss"); if (s == sbss && type != OUT_RESERVE) { - error(ERR_WARNING, "attempt to initialize memory in the" + nasm_error(ERR_WARNING, "attempt to initialize memory in the" " BSS section: ignored"); s->size += realsize(type, size); return; @@ -551,7 +541,7 @@ static void macho_output(int32_t secto, const void *data, switch (type) { case OUT_RESERVE: if (s != sbss) { - error(ERR_WARNING, "uninitialized space declared in" + nasm_error(ERR_WARNING, "uninitialized space declared in" " %s section: zeroing", get_section_name_by_index(secto)); @@ -563,7 +553,7 @@ static void macho_output(int32_t secto, const void *data, case OUT_RAWDATA: if (section != NO_SEG) - error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG"); + nasm_error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG"); sect_write(s, data, size); break; @@ -572,12 +562,12 @@ static void macho_output(int32_t secto, const void *data, addr = *(int64_t *)data; if (section != NO_SEG) { if (section % 2) { - error(ERR_NONFATAL, "Mach-O format does not support" + nasm_error(ERR_NONFATAL, "Mach-O format does not support" " section base references"); } else { if (wrt == NO_SEG) { if (size < 8) { - error(ERR_NONFATAL, "Mach-O 64-bit format does not support" + nasm_error(ERR_NONFATAL, "Mach-O 64-bit format does not support" " 32-bit absolute addresses"); /* Seemingly, Mach-O's X86_64_RELOC_SUBTRACTOR would require @@ -588,7 +578,7 @@ static void macho_output(int32_t secto, const void *data, addr -= add_reloc(s, section, 0, size, addr); // X86_64_RELOC_UNSIGNED } } else { - error(ERR_NONFATAL, "Mach-O format does not support" + nasm_error(ERR_NONFATAL, "Mach-O format does not support" " this use of WRT"); } } @@ -604,15 +594,15 @@ static void macho_output(int32_t secto, const void *data, WRITESHORT(p, *(int64_t *)data); if (section == secto) - error(ERR_PANIC, "intra-section OUT_REL2ADR"); + nasm_error(ERR_PANIC, "intra-section OUT_REL2ADR"); if (section == NO_SEG) { /* Do nothing */ } else if (section % 2) { - error(ERR_NONFATAL, "Mach-O format does not support" + nasm_error(ERR_NONFATAL, "Mach-O format does not support" " section base references"); } else { - error(ERR_NONFATAL, "Unsupported non-32-bit" + nasm_error(ERR_NONFATAL, "Unsupported non-32-bit" " Macho-O relocation [2]"); } @@ -624,10 +614,10 @@ static void macho_output(int32_t secto, const void *data, WRITELONG(p, *(int64_t *)data); if (section == secto) - error(ERR_PANIC, "intra-section OUT_REL4ADR"); + nasm_error(ERR_PANIC, "intra-section OUT_REL4ADR"); if (section != NO_SEG && section % 2) { - error(ERR_NONFATAL, "Mach-O format does not support" + nasm_error(ERR_NONFATAL, "Mach-O format does not support" " section base references"); } else { if (wrt == NO_SEG) { @@ -644,7 +634,7 @@ static void macho_output(int32_t secto, const void *data, *mydata -= add_reloc(s, section, 3, 4, (int64_t)*mydata); // X86_64_GOT } } else { - error(ERR_NONFATAL, "Mach-O format does not support" + nasm_error(ERR_NONFATAL, "Mach-O format does not support" " this use of WRT"); wrt = NO_SEG; /* we can at least _try_ to continue */ } @@ -654,7 +644,7 @@ static void macho_output(int32_t secto, const void *data, break; default: - error(ERR_PANIC, "unknown output type?"); + nasm_error(ERR_PANIC, "unknown output type?"); break; } } @@ -720,14 +710,14 @@ static int32_t macho_section(char *name, int pass, int *bits) newAlignment = exact_log2(value); if (0 != *end) { - error(ERR_PANIC, + nasm_error(ERR_PANIC, "unknown or missing alignment value \"%s\" " "specified for section \"%s\"", currentAttribute + 6, name); return NO_SEG; } else if (0 > newAlignment) { - error(ERR_PANIC, + nasm_error(ERR_PANIC, "alignment of %d (for section \"%s\") is not " "a power of two", value, @@ -738,7 +728,7 @@ static int32_t macho_section(char *name, int pass, int *bits) if ((-1 != originalIndex) && (s->align != newAlignment) && (s->align != -1)) { - error(ERR_PANIC, + nasm_error(ERR_PANIC, "section \"%s\" has already been specified " "with alignment %d, conflicts with new " "alignment of %d", @@ -752,7 +742,7 @@ static int32_t macho_section(char *name, int pass, int *bits) } else if (!nasm_stricmp("data", currentAttribute)) { /* Do nothing; 'data' is implicit */ } else { - error(ERR_PANIC, + nasm_error(ERR_PANIC, "unknown section attribute %s for section %s", currentAttribute, name); @@ -765,7 +755,7 @@ static int32_t macho_section(char *name, int pass, int *bits) } } - error(ERR_PANIC, "invalid section name %s", name); + nasm_error(ERR_PANIC, "invalid section name %s", name); return NO_SEG; } @@ -775,13 +765,13 @@ static void macho_symdef(char *name, int32_t section, int64_t offset, struct symbol *sym; if (special) { - error(ERR_NONFATAL, "The Mach-O output format does " + nasm_error(ERR_NONFATAL, "The Mach-O output format does " "not support any special symbol types"); return; } if (is_global == 3) { - error(ERR_NONFATAL, "The Mach-O format does not " + nasm_error(ERR_NONFATAL, "The Mach-O format does not " "(yet) support forward reference fixups."); return; } @@ -793,7 +783,7 @@ static void macho_symdef(char *name, int32_t section, int64_t offset, * _isn't_ a valid one, we should barf immediately. */ if (strcmp(name, "..gotpcrel")) - error(ERR_NONFATAL, "unrecognized special symbol `%s'", name); + nasm_error(ERR_NONFATAL, "unrecognized special symbol `%s'", name); return; } @@ -847,7 +837,7 @@ static void macho_symdef(char *name, int32_t section, int64_t offset, /* give an error on unfound section if it's not an ** external or common symbol (assemble_file() does a ** seg_alloc() on every call for them) */ - error(ERR_PANIC, "in-file index for section %d not found", + nasm_error(ERR_PANIC, "in-file index for section %d not found", section); } } @@ -860,9 +850,9 @@ static int32_t macho_segbase(int32_t section) return section; } -static void macho_filename(char *inname, char *outname, efunc error) +static void macho_filename(char *inname, char *outname) { - standard_extension(inname, outname, ".o", error); + standard_extension(inname, outname, ".o"); } extern macros_t macho_stdmac[]; @@ -1018,14 +1008,14 @@ static void macho_calculate_sizes (void) static void macho_write_header (void) { - fwriteint32_t(MH_MAGIC_64, machofp); /* magic */ - fwriteint32_t(CPU_TYPE_X86_64, machofp); /* CPU type */ - fwriteint32_t(CPU_SUBTYPE_I386_ALL, machofp); /* CPU subtype */ - fwriteint32_t(MH_OBJECT, machofp); /* Mach-O file type */ - fwriteint32_t(head_ncmds64, machofp); /* number of load commands */ - fwriteint32_t(head_sizeofcmds64, machofp); /* size of load commands */ - fwriteint32_t(0, machofp); /* no flags */ - fwriteint32_t(0, machofp); /* reserved for future use */ + fwriteint32_t(MH_MAGIC_64, ofile); /* magic */ + fwriteint32_t(CPU_TYPE_X86_64, ofile); /* CPU type */ + fwriteint32_t(CPU_SUBTYPE_I386_ALL, ofile); /* CPU subtype */ + fwriteint32_t(MH_OBJECT, ofile); /* Mach-O file type */ + fwriteint32_t(head_ncmds64, ofile); /* number of load commands */ + fwriteint32_t(head_sizeofcmds64, ofile); /* size of load commands */ + fwriteint32_t(0, ofile); /* no flags */ + fwriteint32_t(0, ofile); /* reserved for future use */ } /* Write out the segment load command at offset. */ @@ -1036,51 +1026,51 @@ static uint32_t macho_write_segment (uint64_t offset) uint32_t s_reloff = 0; struct section *s; - fwriteint32_t(LC_SEGMENT_64, machofp); /* cmd == LC_SEGMENT_64 */ + fwriteint32_t(LC_SEGMENT_64, ofile); /* cmd == LC_SEGMENT_64 */ /* size of load command including section load commands */ fwriteint32_t(MACHO_SEGCMD64_SIZE + seg_nsects64 * - MACHO_SECTCMD64_SIZE, machofp); + MACHO_SECTCMD64_SIZE, ofile); /* in an MH_OBJECT file all sections are in one unnamed (name ** all zeros) segment */ - fwritezero(16, machofp); - fwriteint64_t(0, machofp); /* in-memory offset */ - fwriteint64_t(seg_vmsize64, machofp); /* in-memory size */ - fwriteint64_t(offset, machofp); /* in-file offset to data */ - fwriteint64_t(seg_filesize64, machofp); /* in-file size */ - fwriteint32_t(VM_PROT_DEFAULT, machofp); /* maximum vm protection */ - fwriteint32_t(VM_PROT_DEFAULT, machofp); /* initial vm protection */ - fwriteint32_t(seg_nsects64, machofp); /* number of sections */ - fwriteint32_t(0, machofp); /* no flags */ + fwritezero(16, ofile); + fwriteint64_t(0, ofile); /* in-memory offset */ + fwriteint64_t(seg_vmsize64, ofile); /* in-memory size */ + fwriteint64_t(offset, ofile); /* in-file offset to data */ + fwriteint64_t(seg_filesize64, ofile); /* in-file size */ + fwriteint32_t(VM_PROT_DEFAULT, ofile); /* maximum vm protection */ + fwriteint32_t(VM_PROT_DEFAULT, ofile); /* initial vm protection */ + fwriteint32_t(seg_nsects64, ofile); /* number of sections */ + fwriteint32_t(0, ofile); /* no flags */ /* emit section headers */ for (s = sects; s != NULL; s = s->next) { - fwrite(s->sectname, sizeof(s->sectname), 1, machofp); - fwrite(s->segname, sizeof(s->segname), 1, machofp); - fwriteint64_t(s->addr, machofp); - fwriteint64_t(s->size, machofp); + fwrite(s->sectname, sizeof(s->sectname), 1, ofile); + fwrite(s->segname, sizeof(s->segname), 1, ofile); + fwriteint64_t(s->addr, ofile); + fwriteint64_t(s->size, ofile); /* dummy data for zerofill sections or proper values */ if ((s->flags & SECTION_TYPE) != S_ZEROFILL) { - fwriteint32_t(offset, machofp); + fwriteint32_t(offset, ofile); /* Write out section alignment, as a power of two. e.g. 32-bit word alignment would be 2 (2^2 = 4). */ if (s->align == -1) s->align = DEFAULT_SECTION_ALIGNMENT; - fwriteint32_t(s->align, machofp); + fwriteint32_t(s->align, ofile); /* To be compatible with cctools as we emit a zero reloff if we have no relocations. */ - fwriteint32_t(s->nreloc ? rel_base + s_reloff : 0, machofp); - fwriteint32_t(s->nreloc, machofp); + fwriteint32_t(s->nreloc ? rel_base + s_reloff : 0, ofile); + fwriteint32_t(s->nreloc, ofile); offset += s->size; s_reloff += s->nreloc * MACHO_RELINFO64_SIZE; } else { - fwriteint32_t(0, machofp); - fwriteint32_t(0, machofp); - fwriteint32_t(0, machofp); - fwriteint32_t(0, machofp); + fwriteint32_t(0, ofile); + fwriteint32_t(0, ofile); + fwriteint32_t(0, ofile); + fwriteint32_t(0, ofile); } if (s->nreloc) { @@ -1089,11 +1079,11 @@ static uint32_t macho_write_segment (uint64_t offset) s->flags |= S_ATTR_EXT_RELOC; } - fwriteint32_t(s->flags, machofp); /* flags */ - fwriteint32_t(0, machofp); /* reserved */ - fwriteint32_t(0, machofp); /* reserved */ + fwriteint32_t(s->flags, ofile); /* flags */ + fwriteint32_t(0, ofile); /* reserved */ + fwriteint32_t(0, ofile); /* reserved */ - fwriteint32_t(0, machofp); /* align */ + fwriteint32_t(0, ofile); /* align */ } rel_padcnt64 = rel_base - offset; @@ -1110,14 +1100,14 @@ static void macho_write_relocs (struct reloc *r) while (r) { uint32_t word2; - fwriteint32_t(r->addr, machofp); /* reloc offset */ + fwriteint32_t(r->addr, ofile); /* reloc offset */ word2 = r->snum; word2 |= r->pcrel << 24; word2 |= r->length << 25; word2 |= r->ext << 27; word2 |= r->type << 28; - fwriteint32_t(word2, machofp); /* reloc data */ + fwriteint32_t(word2, ofile); /* reloc data */ r = r->next; } } @@ -1197,11 +1187,11 @@ static void macho_write_section (void) } /* dump the section data to file */ - saa_fpwrite(s->data, machofp); + saa_fpwrite(s->data, ofile); } /* pad last section up to reloc entries on int64_t boundary */ - fwritezero(rel_padcnt64, machofp); + fwritezero(rel_padcnt64, ofile); /* emit relocation entries */ for (s = sects; s != NULL; s = s->next) @@ -1221,10 +1211,10 @@ static void macho_write_symtab (void) for (sym = syms; sym != NULL; sym = sym->next) { if ((sym->type & N_EXT) == 0) { - fwriteint32_t(sym->strx, machofp); /* string table entry number */ - fwrite(&sym->type, 1, 1, machofp); /* symbol type */ - fwrite(&sym->sect, 1, 1, machofp); /* section */ - fwriteint16_t(sym->desc, machofp); /* description */ + fwriteint32_t(sym->strx, ofile); /* string table entry number */ + fwrite(&sym->type, 1, 1, ofile); /* symbol type */ + fwrite(&sym->sect, 1, 1, ofile); /* section */ + fwriteint16_t(sym->desc, ofile); /* description */ /* Fix up the symbol value now that we know the final section sizes. */ @@ -1234,16 +1224,16 @@ static void macho_write_symtab (void) sym->value += s->size; } - fwriteint64_t(sym->value, machofp); /* value (i.e. offset) */ + fwriteint64_t(sym->value, ofile); /* value (i.e. offset) */ } } for (i = 0; i < nextdefsym; i++) { sym = extdefsyms[i]; - fwriteint32_t(sym->strx, machofp); - fwrite(&sym->type, 1, 1, machofp); /* symbol type */ - fwrite(&sym->sect, 1, 1, machofp); /* section */ - fwriteint16_t(sym->desc, machofp); /* description */ + fwriteint32_t(sym->strx, ofile); + fwrite(&sym->type, 1, 1, ofile); /* symbol type */ + fwrite(&sym->sect, 1, 1, ofile); /* section */ + fwriteint16_t(sym->desc, ofile); /* description */ /* Fix up the symbol value now that we know the final section sizes. */ @@ -1253,15 +1243,15 @@ static void macho_write_symtab (void) sym->value += s->size; } - fwriteint64_t(sym->value, machofp); /* value (i.e. offset) */ + fwriteint64_t(sym->value, ofile); /* value (i.e. offset) */ } for (i = 0; i < nundefsym; i++) { sym = undefsyms[i]; - fwriteint32_t(sym->strx, machofp); - fwrite(&sym->type, 1, 1, machofp); /* symbol type */ - fwrite(&sym->sect, 1, 1, machofp); /* section */ - fwriteint16_t(sym->desc, machofp); /* description */ + fwriteint32_t(sym->strx, ofile); + fwrite(&sym->type, 1, 1, ofile); /* symbol type */ + fwrite(&sym->sect, 1, 1, ofile); /* section */ + fwriteint16_t(sym->desc, ofile); /* description */ // Fix up the symbol value now that we know the final section sizes. if (((sym->type & N_TYPE) == N_SECT) && (sym->sect != NO_SECT)) { @@ -1270,7 +1260,7 @@ static void macho_write_symtab (void) sym->value += s->size; } - fwriteint64_t(sym->value, machofp); // value (i.e. offset) + fwriteint64_t(sym->value, ofile); // value (i.e. offset) } } @@ -1382,19 +1372,19 @@ static void macho_write (void) if (seg_nsects64 > 0) offset = macho_write_segment (offset); else - error(ERR_WARNING, "no sections?"); + nasm_error(ERR_WARNING, "no sections?"); if (nsyms > 0) { /* write out symbol command */ - fwriteint32_t(LC_SYMTAB, machofp); /* cmd == LC_SYMTAB */ - fwriteint32_t(MACHO_SYMCMD_SIZE, machofp); /* size of load command */ - fwriteint32_t(offset, machofp); /* symbol table offset */ - fwriteint32_t(nsyms, machofp); /* number of symbol + fwriteint32_t(LC_SYMTAB, ofile); /* cmd == LC_SYMTAB */ + fwriteint32_t(MACHO_SYMCMD_SIZE, ofile); /* size of load command */ + fwriteint32_t(offset, ofile); /* symbol table offset */ + fwriteint32_t(nsyms, ofile); /* number of symbol ** table entries */ offset += nsyms * MACHO_NLIST64_SIZE; - fwriteint32_t(offset, machofp); /* string table offset */ - fwriteint32_t(strslen, machofp); /* string table size */ + fwriteint32_t(offset, ofile); /* string table offset */ + fwriteint32_t(strslen, ofile); /* string table size */ } /* emit section data */ @@ -1408,7 +1398,7 @@ static void macho_write (void) /* we don't need to pad here since MACHO_NLIST64_SIZE == 16 */ /* emit string table */ - saa_fpwrite(strs, machofp); + saa_fpwrite(strs, ofile); } /* We do quite a bit here, starting with finalizing all of the data for the object file, writing, and then freeing all of the data from diff --git a/output/outobj.c b/output/outobj.c index 7eb21cd..2011a87 100644 --- a/output/outobj.c +++ b/output/outobj.c @@ -47,6 +47,7 @@ #include "nasm.h" #include "nasmlib.h" #include "stdscan.h" +#include "eval.h" #include "output/outform.h" #include "output/outlib.h" @@ -497,10 +498,6 @@ static void ori_null(ObjRecord * orp) static char obj_infile[FILENAME_MAX]; -static efunc error; -static evalfunc evaluate; -static ldfunc deflabel; -static FILE *ofp; static int32_t first_seg; static bool any_segs; static int passtwo; @@ -635,12 +632,8 @@ static int32_t obj_segment(char *, int, int *); static void obj_write_file(int debuginfo); static int obj_directive(enum directives, char *, int); -static void obj_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval) +static void obj_init(void) { - ofp = fp; - error = errfunc; - evaluate = eval; - deflabel = ldef; first_seg = seg_alloc(); any_segs = false; fpubhead = NULL; @@ -802,7 +795,7 @@ static void obj_deflabel(char *name, int32_t segment, obj_entry_ofs = offset; return; } - error(ERR_NONFATAL, "unrecognised special symbol `%s'", name); + nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name); } /* @@ -833,7 +826,7 @@ static void obj_deflabel(char *name, int32_t segment, pub->segment = (segment == NO_SEG ? 0 : segment & ~SEG_ABS); } if (special) - error(ERR_NONFATAL, "OBJ supports no special symbol features" + nasm_error(ERR_NONFATAL, "OBJ supports no special symbol features" " for this symbol type"); return; } @@ -846,7 +839,7 @@ static void obj_deflabel(char *name, int32_t segment, if (!any_segs && segment == first_seg) { int tempint; /* ignored */ if (segment != obj_segment("__NASMDEFSEG", 2, &tempint)) - error(ERR_PANIC, "strange segment conditions in OBJ driver"); + nasm_error(ERR_PANIC, "strange segment conditions in OBJ driver"); } for (seg = seghead; seg && is_global; seg = seg->next) @@ -862,7 +855,7 @@ static void obj_deflabel(char *name, int32_t segment, loc->offset = offset; if (special) - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "OBJ supports no special symbol features" " for this symbol type"); return; @@ -929,7 +922,7 @@ static void obj_deflabel(char *name, int32_t segment, obj_ext_set_defwrt(ext, p); special += len; if (*special && *special != ':') - error(ERR_NONFATAL, "`:' expected in special symbol" + nasm_error(ERR_NONFATAL, "`:' expected in special symbol" " text for `%s'", ext->name); else if (*special == ':') special++; @@ -943,7 +936,7 @@ static void obj_deflabel(char *name, int32_t segment, if (ext->commonsize) ext->commonelem = 1; else - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%s': `far' keyword may only be applied" " to common variables\n", ext->name); special += 3; @@ -952,7 +945,7 @@ static void obj_deflabel(char *name, int32_t segment, if (ext->commonsize) ext->commonelem = 0; else - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%s': `far' keyword may only be applied" " to common variables\n", ext->name); special += 4; @@ -975,17 +968,17 @@ static void obj_deflabel(char *name, int32_t segment, stdscan_reset(); stdscan_bufptr = special; tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, NULL, 1, error, NULL); + e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL); if (e) { if (!is_simple(e)) - error(ERR_NONFATAL, "cannot use relocatable" + nasm_error(ERR_NONFATAL, "cannot use relocatable" " expression as common-variable element size"); else ext->commonelem = reloc_value(e); } special = stdscan_bufptr; } else { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%s': element-size specifications only" " apply to common variables", ext->name); while (*special && *special != ':') @@ -1017,7 +1010,7 @@ static void obj_deflabel(char *name, int32_t segment, ext->index = ++externals; if (special && !used_special) - error(ERR_NONFATAL, "OBJ supports no special symbol features" + nasm_error(ERR_NONFATAL, "OBJ supports no special symbol features" " for this symbol type"); } @@ -1040,7 +1033,7 @@ static void obj_out(int32_t segto, const void *data, */ if (segto == NO_SEG) { if (type != OUT_RESERVE) - error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]" + nasm_error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]" " space"); return; } @@ -1052,7 +1045,7 @@ static void obj_out(int32_t segto, const void *data, if (!any_segs) { int tempint; /* ignored */ if (segto != obj_segment("__NASMDEFSEG", 2, &tempint)) - error(ERR_PANIC, "strange segment conditions in OBJ driver"); + nasm_error(ERR_PANIC, "strange segment conditions in OBJ driver"); } /* @@ -1062,7 +1055,7 @@ static void obj_out(int32_t segto, const void *data, if (seg->index == segto) break; if (!seg) - error(ERR_PANIC, "code directed to nonexistent segment?"); + nasm_error(ERR_PANIC, "code directed to nonexistent segment?"); orp = seg->orp; orp->parm[0] = seg->currentpos; @@ -1086,10 +1079,10 @@ static void obj_out(int32_t segto, const void *data, int rsize; if (segment == NO_SEG && type != OUT_ADDRESS) - error(ERR_NONFATAL, "relative call to absolute address not" + nasm_error(ERR_NONFATAL, "relative call to absolute address not" " supported by OBJ format"); if (segment >= SEG_ABS) - error(ERR_NONFATAL, "far-absolute relocations not supported" + nasm_error(ERR_NONFATAL, "far-absolute relocations not supported" " by OBJ format"); ldata = *(int64_t *)data; if (type == OUT_REL2ADR) { @@ -1115,7 +1108,7 @@ static void obj_out(int32_t segto, const void *data, */ rsize = 2; if (ldata & 0xFFFF) - error(ERR_NONFATAL, "OBJ format cannot handle complex" + nasm_error(ERR_NONFATAL, "OBJ format cannot handle complex" " dword-size segment base references"); } if (segment != NO_SEG) @@ -1145,7 +1138,7 @@ static void obj_write_fixup(ObjRecord * orp, int bytes, ObjRecord *forp; if (bytes == 1) { - error(ERR_NONFATAL, "`obj' output driver does not support" + nasm_error(ERR_NONFATAL, "`obj' output driver does not support" " one-byte relocations"); return; } @@ -1167,7 +1160,7 @@ static void obj_write_fixup(ObjRecord * orp, int bytes, locat = FIX_16_SELECTOR; seg--; if (bytes != 2) - error(ERR_PANIC, "OBJ: 4-byte segment base fixup got" + nasm_error(ERR_PANIC, "OBJ: 4-byte segment base fixup got" " through sanity check"); } else { base = false; @@ -1213,7 +1206,7 @@ static void obj_write_fixup(ObjRecord * orp, int bytes, if (eb) method = 6, e = eb->exts[i], tidx = e->index; else - error(ERR_PANIC, + nasm_error(ERR_PANIC, "unrecognised segment value in obj_write_fixup"); } } @@ -1237,7 +1230,7 @@ static void obj_write_fixup(ObjRecord * orp, int bytes, else if (e->defwrt_type == DEFWRT_GROUP) method |= 0x10, fidx = e->defwrt_ptr.grp->obj_index; else { - error(ERR_NONFATAL, "default WRT specification for" + nasm_error(ERR_NONFATAL, "default WRT specification for" " external `%s' unresolved", e->name); method |= 0x50, fidx = -1; /* got to do _something_ */ } @@ -1272,7 +1265,7 @@ static void obj_write_fixup(ObjRecord * orp, int bytes, if (eb) method |= 0x20, fidx = eb->exts[i]->index; else - error(ERR_PANIC, + nasm_error(ERR_PANIC, "unrecognised WRT value in obj_write_fixup"); } } @@ -1341,7 +1334,7 @@ static int32_t obj_segment(char *name, int pass, int *bits) obj_idx++; if (!strcmp(seg->name, name)) { if (attrs > 0 && pass == 1) - error(ERR_WARNING, "segment attributes specified on" + nasm_error(ERR_WARNING, "segment attributes specified on" " redeclaration of segment: ignoring"); if (seg->use32) *bits = 32; @@ -1421,7 +1414,7 @@ static int32_t obj_segment(char *name, int pass, int *bits) if (!strcmp(grp->name, "FLAT")) break; if (!grp) - error(ERR_PANIC, "failure to define FLAT?!"); + nasm_error(ERR_PANIC, "failure to define FLAT?!"); } seg->grp = grp; } else if (!nasm_strnicmp(p, "class=", 6)) @@ -1432,7 +1425,7 @@ static int32_t obj_segment(char *name, int pass, int *bits) seg->align = readnum(p + 6, &rn_error); if (rn_error) { seg->align = 1; - error(ERR_NONFATAL, "segment alignment should be" + nasm_error(ERR_NONFATAL, "segment alignment should be" " numeric"); } switch ((int)seg->align) { @@ -1444,7 +1437,7 @@ static int32_t obj_segment(char *name, int pass, int *bits) case 4096: /* PharLap extension */ break; case 8: - error(ERR_WARNING, + nasm_error(ERR_WARNING, "OBJ format does not support alignment" " of 8: rounding up to 16"); seg->align = 16; @@ -1452,7 +1445,7 @@ static int32_t obj_segment(char *name, int pass, int *bits) case 32: case 64: case 128: - error(ERR_WARNING, + nasm_error(ERR_WARNING, "OBJ format does not support alignment" " of %d: rounding up to 256", seg->align); seg->align = 256; @@ -1460,13 +1453,13 @@ static int32_t obj_segment(char *name, int pass, int *bits) case 512: case 1024: case 2048: - error(ERR_WARNING, + nasm_error(ERR_WARNING, "OBJ format does not support alignment" " of %d: rounding up to 4096", seg->align); seg->align = 4096; break; default: - error(ERR_NONFATAL, "invalid alignment value %d", + nasm_error(ERR_NONFATAL, "invalid alignment value %d", seg->align); seg->align = 1; break; @@ -1474,7 +1467,7 @@ static int32_t obj_segment(char *name, int pass, int *bits) } else if (!nasm_strnicmp(p, "absolute=", 9)) { seg->align = SEG_ABS + readnum(p + 9, &rn_error); if (rn_error) - error(ERR_NONFATAL, "argument to `absolute' segment" + nasm_error(ERR_NONFATAL, "argument to `absolute' segment" " attribute should be numeric"); } } @@ -1484,11 +1477,11 @@ static int32_t obj_segment(char *name, int pass, int *bits) obj_seg_needs_update = seg; if (seg->align >= SEG_ABS) - deflabel(name, NO_SEG, seg->align - SEG_ABS, - NULL, false, false, &of_obj, error); + define_label(name, NO_SEG, seg->align - SEG_ABS, + NULL, false, false, &of_obj, nasm_error); else - deflabel(name, seg->index + 1, 0L, - NULL, false, false, &of_obj, error); + define_label(name, seg->index + 1, 0L, + NULL, false, false, &of_obj, nasm_error); obj_seg_needs_update = NULL; /* @@ -1501,7 +1494,7 @@ static int32_t obj_segment(char *name, int pass, int *bits) grp->segs[i] = grp->segs[grp->nindices]; grp->segs[grp->nindices++].index = seg->obj_index; if (seg->grp) - error(ERR_WARNING, + nasm_error(ERR_WARNING, "segment `%s' is already part of" " a group: first one takes precedence", seg->name); @@ -1567,7 +1560,7 @@ static int obj_directive(enum directives directive, char *value, int pass) * practice, so the sanity check has been removed. * * if (!*q) { - * error(ERR_NONFATAL,"GROUP directive contains no segments"); + * nasm_error(ERR_NONFATAL,"GROUP directive contains no segments"); * return 1; * } */ @@ -1576,7 +1569,7 @@ static int obj_directive(enum directives directive, char *value, int pass) for (grp = grphead; grp; grp = grp->next) { obj_idx++; if (!strcmp(grp->name, v)) { - error(ERR_NONFATAL, "group `%s' defined twice", v); + nasm_error(ERR_NONFATAL, "group `%s' defined twice", v); return 1; } } @@ -1590,8 +1583,8 @@ static int obj_directive(enum directives directive, char *value, int pass) grp->name = NULL; obj_grp_needs_update = grp; - deflabel(v, grp->index + 1, 0L, - NULL, false, false, &of_obj, error); + define_label(v, grp->index + 1, 0L, + NULL, false, false, &of_obj, nasm_error); obj_grp_needs_update = NULL; while (*q) { @@ -1617,7 +1610,7 @@ static int obj_directive(enum directives directive, char *value, int pass) grp->segs[grp->nentries++] = grp->segs[grp->nindices]; grp->segs[grp->nindices++].index = seg->obj_index; if (seg->grp) - error(ERR_WARNING, + nasm_error(ERR_WARNING, "segment `%s' is already part of" " a group: first one takes precedence", seg->name); @@ -1682,7 +1675,7 @@ static int obj_directive(enum directives directive, char *value, int pass) impname = q; if (!*extname || !*libname) - error(ERR_NONFATAL, "`import' directive requires symbol name" + nasm_error(ERR_NONFATAL, "`import' directive requires symbol name" " and library name"); else { struct ImpDef *imp; @@ -1730,7 +1723,7 @@ static int obj_directive(enum directives directive, char *value, int pass) } if (!*intname) { - error(ERR_NONFATAL, "`export' directive requires export name"); + nasm_error(ERR_NONFATAL, "`export' directive requires export name"); return 1; } if (!*extname) { @@ -1754,7 +1747,7 @@ static int obj_directive(enum directives directive, char *value, int pass) bool err = false; flags |= EXPDEF_MASK_PARMCNT & readnum(v + 5, &err); if (err) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "value `%s' for `parm' is non-numeric", v + 5); return 1; } @@ -1762,7 +1755,7 @@ static int obj_directive(enum directives directive, char *value, int pass) bool err = false; ordinal = readnum(v, &err); if (err) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "unrecognised export qualifier `%s'", v); return 1; } @@ -1842,10 +1835,10 @@ static int32_t obj_segbase(int32_t segment) return segment; /* no special treatment */ } -static void obj_filename(char *inname, char *outname, efunc lerror) +static void obj_filename(char *inname, char *outname) { strcpy(obj_infile, inname); - standard_extension(inname, outname, ".obj", lerror); + standard_extension(inname, outname, ".obj"); } static void obj_write_file(int debuginfo) @@ -1968,7 +1961,7 @@ static void obj_write_file(int debuginfo) /* acbp |= 0x00 */ ; else if (seg->align >= 4096) { if (seg->align > 4096) - error(ERR_NONFATAL, "segment `%s' requires more alignment" + nasm_error(ERR_NONFATAL, "segment `%s' requires more alignment" " than OBJ format supports", seg->name); acbp |= 0xC0; /* PharLap extension */ } else if (seg->align >= 256) { @@ -2003,7 +1996,7 @@ static void obj_write_file(int debuginfo) if (grp->nindices != grp->nentries) { for (i = grp->nindices; i < grp->nentries; i++) { - error(ERR_NONFATAL, "group `%s' contains undefined segment" + nasm_error(ERR_NONFATAL, "group `%s' contains undefined segment" " `%s'", grp->name, grp->segs[i].name); nasm_free(grp->segs[i].name); grp->segs[i].name = NULL; @@ -2237,7 +2230,7 @@ static void obj_write_file(int debuginfo) } } if (!seg) - error(ERR_NONFATAL, "entry point is not in this module"); + nasm_error(ERR_NONFATAL, "entry point is not in this module"); } /* @@ -2324,25 +2317,20 @@ static void obj_fwrite(ObjRecord * orp) cksum = orp->type; if (orp->x_size == 32) cksum |= 1; - fputc(cksum, ofp); + fputc(cksum, ofile); len = orp->committed + 1; cksum += (len & 0xFF) + ((len >> 8) & 0xFF); - fwriteint16_t(len, ofp); - fwrite(orp->buf, 1, len - 1, ofp); + fwriteint16_t(len, ofile); + fwrite(orp->buf, 1, len - 1, ofile); for (ptr = orp->buf; --len; ptr++) cksum += *ptr; - fputc((-cksum) & 0xFF, ofp); + fputc((-cksum) & 0xFF, ofile); } extern macros_t obj_stdmac[]; -void dbgbi_init(struct ofmt *of, void *id, FILE * fp, efunc error) +void dbgbi_init(void) { - (void)of; - (void)id; - (void)fp; - (void)error; - fnhead = NULL; fntail = &fnhead; arrindex = ARRAYBOT; @@ -2394,7 +2382,7 @@ static void dbgbi_linnum(const char *lnfname, int32_t lineno, int32_t segto) if (!any_segs) { int tempint; /* ignored */ if (segto != obj_segment("__NASMDEFSEG", 2, &tempint)) - error(ERR_PANIC, "strange segment conditions in OBJ driver"); + nasm_error(ERR_PANIC, "strange segment conditions in OBJ driver"); } /* @@ -2404,7 +2392,7 @@ static void dbgbi_linnum(const char *lnfname, int32_t lineno, int32_t segto) if (seg->index == segto) break; if (!seg) - error(ERR_PANIC, "lineno directed to nonexistent segment?"); + nasm_error(ERR_PANIC, "lineno directed to nonexistent segment?"); /* for (fn = fnhead; fn; fn = fnhead->next) */ for (fn = fnhead; fn; fn = fn->next) /* fbk - Austin Lunnen - John Fine */ diff --git a/output/outrdf2.c b/output/outrdf2.c index dd80438..6d95803 100644 --- a/output/outrdf2.c +++ b/output/outrdf2.c @@ -97,10 +97,6 @@ static int segmenttypenumbers[COUNT_SEGTYPES] = { static struct SAA *seg[RDF_MAXSEGS]; /* seg 0 = code, seg 1 = data */ static struct SAA *header; /* relocation/import/export records */ -static FILE *ofile; - -static efunc error; - static struct seginfo { char *segname; int segnumber; @@ -114,13 +110,10 @@ static int nsegments; static int32_t bsslength; static int32_t headerlength; -static void rdf2_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval) +static void rdf2_init(void) { int segtext, segdata, segbss; - (void)ldef; - (void)eval; - maxbits = 64; /* set up the initial segments */ @@ -144,9 +137,6 @@ static void rdf2_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval) nsegments = 3; - ofile = fp; - error = errfunc; - seg[0] = saa_init(1L); seg[1] = saa_init(1L); seg[2] = NULL; /* special case! */ @@ -157,7 +147,7 @@ static void rdf2_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval) segdata = seg_alloc(); segbss = seg_alloc(); if (segtext != 0 || segdata != 2 || segbss != 4) - error(ERR_PANIC, + nasm_error(ERR_PANIC, "rdf segment numbers not allocated as expected (%d,%d,%d)", segtext, segdata, segbss); bsslength = 0; @@ -200,7 +190,7 @@ static int32_t rdf2_section_names(char *name, int pass, int *bits) reserved = readnum(q, &err); if (err) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "value following comma must be numeric"); reserved = 0; } @@ -217,7 +207,7 @@ static int32_t rdf2_section_names(char *name, int pass, int *bits) if (code == -1) { /* didn't find anything */ code = readnum(p, &err); if (err) { - error(ERR_NONFATAL, "unrecognised RDF segment type (%s)", + nasm_error(ERR_NONFATAL, "unrecognised RDF segment type (%s)", p); code = 3; } @@ -226,7 +216,7 @@ static int32_t rdf2_section_names(char *name, int pass, int *bits) for (i = 0; i < nsegments; i++) { if (!strcmp(name, segments[i].segname)) { if (code != -1 || reserved != 0) - error(ERR_NONFATAL, "segment attributes specified on" + nasm_error(ERR_NONFATAL, "segment attributes specified on" " redeclaration of segment"); return segments[i].segnumber * 2; } @@ -235,11 +225,11 @@ static int32_t rdf2_section_names(char *name, int pass, int *bits) /* declaring a new segment! */ if (code == -1) { - error(ERR_NONFATAL, "new segment declared without type code"); + nasm_error(ERR_NONFATAL, "new segment declared without type code"); code = 3; } if (nsegments == RDF_MAXSEGS) { - error(ERR_FATAL, "reached compiled-in maximum segment limit (%d)", + nasm_error(ERR_FATAL, "reached compiled-in maximum segment limit (%d)", RDF_MAXSEGS); return NO_SEG; } @@ -247,7 +237,7 @@ static int32_t rdf2_section_names(char *name, int pass, int *bits) segments[nsegments].segname = nasm_strdup(name); i = seg_alloc(); if (i % 2 != 0) - error(ERR_PANIC, "seg_alloc() returned odd number"); + nasm_error(ERR_PANIC, "seg_alloc() returned odd number"); segments[nsegments].segnumber = i >> 1; segments[nsegments].segtype = code; segments[nsegments].segreserved = reserved; @@ -396,11 +386,11 @@ static void rdf2_deflabel(char *name, int32_t segment, int64_t offset, /* Check if the label length is OK */ if ((len = strlen(name)) >= EXIM_LABEL_MAX) { - error(ERR_NONFATAL, "label size exceeds %d bytes", EXIM_LABEL_MAX); + nasm_error(ERR_NONFATAL, "label size exceeds %d bytes", EXIM_LABEL_MAX); return; } if (!len) { - error(ERR_NONFATAL, "zero-length label"); + nasm_error(ERR_NONFATAL, "zero-length label"); return; } @@ -421,10 +411,10 @@ static void rdf2_deflabel(char *name, int32_t segment, int64_t offset, bool err; ci.align = readnum(special, &err); if (err) - error(ERR_NONFATAL, "alignment constraint `%s' is not a" + nasm_error(ERR_NONFATAL, "alignment constraint `%s' is not a" " valid number", special); else if ((ci.align | (ci.align - 1)) != 2 * ci.align - 1) - error(ERR_NONFATAL, "alignment constraint `%s' is not a" + nasm_error(ERR_NONFATAL, "alignment constraint `%s' is not a" " power of two", special); } write_common_rec(&ci); @@ -460,13 +450,13 @@ static void rdf2_deflabel(char *name, int32_t segment, int64_t offset, !nasm_stricmp(special, "object")) { symflags |= SYM_DATA; } else - error(ERR_NONFATAL, "unrecognised symbol type `%s'", + nasm_error(ERR_NONFATAL, "unrecognised symbol type `%s'", special); } } if (name[0] == '.' && name[1] == '.' && name[2] != '@') { - error(ERR_NONFATAL, "unrecognised special symbol `%s'", name); + nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name); return; } @@ -478,7 +468,7 @@ static void rdf2_deflabel(char *name, int32_t segment, int64_t offset, if (i >= nsegments) { /* EXTERN declaration */ ri.type = farsym ? RDFREC_FARIMPORT : RDFREC_IMPORT; if (symflags & SYM_GLOBAL) - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "symbol type conflict - EXTERN cannot be EXPORT"); ri.flags = symflags; ri.segment = segment; @@ -488,7 +478,7 @@ static void rdf2_deflabel(char *name, int32_t segment, int64_t offset, } else if (is_global) { r.type = RDFREC_GLOBAL; /* GLOBAL declaration */ if (symflags & SYM_IMPORT) - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "symbol type conflict - GLOBAL cannot be IMPORT"); r.flags = symflags; r.segment = segment; @@ -509,7 +499,7 @@ static void membufwrite(int segment, const void *data, int bytes) break; } if (i == nsegments) - error(ERR_PANIC, "can't find segment %d", segment); + nasm_error(ERR_PANIC, "can't find segment %d", segment); if (bytes < 0) { b = buf; @@ -532,7 +522,7 @@ static int getsegmentlength(int segment) break; } if (i == nsegments) - error(ERR_PANIC, "can't find segment %d", segment); + nasm_error(ERR_PANIC, "can't find segment %d", segment); return segments[i].seglength; } @@ -547,7 +537,7 @@ static void rdf2_out(int32_t segto, const void *data, if (segto == NO_SEG) { if (type != OUT_RESERVE) - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "attempt to assemble code in ABSOLUTE space"); return; } @@ -559,18 +549,18 @@ static void rdf2_out(int32_t segto, const void *data, break; } if (seg >= nsegments) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "specified segment not supported by rdf output format"); return; } if (wrt != NO_SEG) { wrt = NO_SEG; /* continue to do _something_ */ - error(ERR_NONFATAL, "WRT not supported by rdf output format"); + nasm_error(ERR_NONFATAL, "WRT not supported by rdf output format"); } if (segto == 2 && type != OUT_RESERVE) { - error(ERR_NONFATAL, "BSS segments may not be initialized"); + nasm_error(ERR_NONFATAL, "BSS segments may not be initialized"); /* just reserve the space for now... */ @@ -589,7 +579,7 @@ static void rdf2_out(int32_t segto, const void *data, membufwrite(segto, databuf, 1); } else if (type == OUT_RAWDATA) { if (segment != NO_SEG) - error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG"); + nasm_error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG"); membufwrite(segto, data, size); } else if (type == OUT_ADDRESS) { @@ -617,7 +607,7 @@ static void rdf2_out(int32_t segto, const void *data, membufwrite(segto, databuf, size); } else if (type == OUT_REL2ADR) { if (segment == segto) - error(ERR_PANIC, "intra-segment OUT_REL2ADR"); + nasm_error(ERR_PANIC, "intra-segment OUT_REL2ADR"); rr.reclen = 8; rr.offset = getsegmentlength(segto); /* current offset */ @@ -649,9 +639,9 @@ static void rdf2_out(int32_t segto, const void *data, membufwrite(segto, &rr.offset, -2); } else if (type == OUT_REL4ADR) { if ((segment == segto) && (globalbits != 64)) - error(ERR_PANIC, "intra-segment OUT_REL4ADR"); + nasm_error(ERR_PANIC, "intra-segment OUT_REL4ADR"); if (segment != NO_SEG && segment % 2) { - error(ERR_PANIC, "erm... 4 byte segment base ref?"); + nasm_error(ERR_PANIC, "erm... 4 byte segment base ref?"); } rr.type = RDFREC_RELOC; /* type signature */ @@ -741,7 +731,7 @@ static int rdf2_directive(enum directives directive, char *value, int pass) case D_LIBRARY: n = strlen(value); if (n >= MODLIB_NAME_MAX) { - error(ERR_NONFATAL, "name size exceeds %d bytes", MODLIB_NAME_MAX); + nasm_error(ERR_NONFATAL, "name size exceeds %d bytes", MODLIB_NAME_MAX); return 1; } if (pass == 1) { @@ -755,7 +745,7 @@ static int rdf2_directive(enum directives directive, char *value, int pass) case D_MODULE: if ((n = strlen(value)) >= MODLIB_NAME_MAX) { - error(ERR_NONFATAL, "name size exceeds %d bytes", MODLIB_NAME_MAX); + nasm_error(ERR_NONFATAL, "name size exceeds %d bytes", MODLIB_NAME_MAX); return 1; } if (pass == 1) { @@ -772,9 +762,9 @@ static int rdf2_directive(enum directives directive, char *value, int pass) } } -static void rdf2_filename(char *inname, char *outname, efunc error) +static void rdf2_filename(char *inname, char *outname) { - standard_extension(inname, outname, ".rdf", error); + standard_extension(inname, outname, ".rdf"); } extern macros_t rdf2_stdmac[]; |