diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Makefile.in | 89 | ||||
-rw-r--r-- | Mkfiles/msvc.mak | 15 | ||||
-rw-r--r-- | Mkfiles/netware.mak | 17 | ||||
-rw-r--r-- | Mkfiles/openwcom.mak | 13 | ||||
-rw-r--r-- | Mkfiles/owlinux.mak | 15 | ||||
-rw-r--r-- | aclocal.m4 | 45 | ||||
-rw-r--r-- | assemble.c | 186 | ||||
-rw-r--r-- | assemble.h | 5 | ||||
-rw-r--r-- | compiler.h | 29 | ||||
-rw-r--r-- | configure.in | 48 | ||||
-rw-r--r-- | eval.c | 106 | ||||
-rw-r--r-- | eval.h | 11 | ||||
-rw-r--r-- | float.c | 38 | ||||
-rw-r--r-- | float.h | 3 | ||||
-rw-r--r-- | ilog2.c | 7 | ||||
-rw-r--r-- | labels.c | 10 | ||||
-rw-r--r-- | lib/strlcpy.c | 2 | ||||
-rw-r--r-- | listing.c | 18 | ||||
-rw-r--r-- | listing.h | 68 | ||||
-rw-r--r-- | nasm.c | 113 | ||||
-rw-r--r-- | nasm.h | 91 | ||||
-rw-r--r-- | nasmlib.c | 50 | ||||
-rw-r--r-- | nasmlib.h | 35 | ||||
-rw-r--r-- | output/codeview.c | 2 | ||||
-rw-r--r-- | output/nulldbg.c | 4 | ||||
-rw-r--r-- | output/outaout.c | 11 | ||||
-rw-r--r-- | output/outas86.c | 2 | ||||
-rw-r--r-- | output/outbin.c | 12 | ||||
-rw-r--r-- | output/outcoff.c | 20 | ||||
-rw-r--r-- | output/outdbg.c | 12 | ||||
-rw-r--r-- | output/outelf32.c | 184 | ||||
-rw-r--r-- | output/outelf64.c | 145 | ||||
-rw-r--r-- | output/outelfx32.c | 132 | ||||
-rw-r--r-- | output/outform.c | 22 | ||||
-rw-r--r-- | output/outform.h | 49 | ||||
-rw-r--r-- | output/outieee.c | 10 | ||||
-rw-r--r-- | output/outlib.h | 3 | ||||
-rw-r--r-- | output/outmacho.c | 4 | ||||
-rw-r--r-- | output/outobj.c | 12 | ||||
-rw-r--r-- | output/outrdf2.c | 2 | ||||
-rw-r--r-- | parser.c | 27 | ||||
-rw-r--r-- | parser.h | 1 | ||||
-rw-r--r-- | preproc-nop.c | 12 | ||||
-rw-r--r-- | preproc.c | 412 |
45 files changed, 1061 insertions, 1034 deletions
@@ -46,9 +46,8 @@ TAGS /insnsn.c /macros.c /nasm -/nasm.man /ndisasm -/ndisasm.man +/*.1 /pptok.c /pptok.h /pptok.ph diff --git a/Makefile.in b/Makefile.in index 6ee17b49..6b5fbb4c 100644 --- a/Makefile.in +++ b/Makefile.in @@ -22,9 +22,13 @@ INTERNAL_CFLAGS = -I$(srcdir) -I. ALL_CFLAGS = $(BUILD_CFLAGS) $(INTERNAL_CFLAGS) LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ -PERL = perl -I$(srcdir)/perllib +PERL = perl +PERLFLAGS = -I$(srcdir)/perllib -XOBJS = @XOBJS@ +RUNPERL = $(PERL) $(PERLFLAGS) + +LIBOBJDIR = @LIBOBJDIR@ +LIBOBJS = @LIBOBJS@ INSTALL = @INSTALL@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -90,7 +94,6 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \ macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) \ strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O) \ ilog2.$(O) \ - lib/strlcpy.$(O) \ preproc-nop.$(O) \ disp8.$(O) \ iflag.$(O) @@ -102,11 +105,11 @@ NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) \ all: nasm$(X) ndisasm$(X) manpages rdf -nasm$(X): $(NASM) $(XOBJS) - $(CC) $(LDFLAGS) -o nasm$(X) $(NASM) $(XOBJS) $(LIBS) +nasm$(X): $(NASM) $(LIBOBJS) + $(CC) $(LDFLAGS) -o nasm$(X) $(NASM) $(LIBOBJS) $(LIBS) -ndisasm$(X): $(NDISASM) $(XOBJS) - $(CC) $(LDFLAGS) -o ndisasm$(X) $(NDISASM) $(XOBJS) $(LIBS) +ndisasm$(X): $(NDISASM) $(LIBOBJS) + $(CC) $(LDFLAGS) -o ndisasm$(X) $(NDISASM) $(LIBOBJS) $(LIBS) # These source files are automagically generated from a single # instruction-table file by a Perl script. They're distributed, @@ -115,79 +118,79 @@ ndisasm$(X): $(NDISASM) $(XOBJS) INSDEP = insns.dat insns.pl insns-iflags.pl iflag.c: $(INSDEP) - $(PERL) $(srcdir)/insns.pl -fc $(srcdir)/insns.dat + $(RUNPERL) $(srcdir)/insns.pl -fc $(srcdir)/insns.dat iflaggen.h: $(INSDEP) - $(PERL) $(srcdir)/insns.pl -fh $(srcdir)/insns.dat + $(RUNPERL) $(srcdir)/insns.pl -fh $(srcdir)/insns.dat insnsb.c: $(INSDEP) - $(PERL) $(srcdir)/insns.pl -b $(srcdir)/insns.dat + $(RUNPERL) $(srcdir)/insns.pl -b $(srcdir)/insns.dat insnsa.c: $(INSDEP) - $(PERL) $(srcdir)/insns.pl -a $(srcdir)/insns.dat + $(RUNPERL) $(srcdir)/insns.pl -a $(srcdir)/insns.dat insnsd.c: $(INSDEP) - $(PERL) $(srcdir)/insns.pl -d $(srcdir)/insns.dat + $(RUNPERL) $(srcdir)/insns.pl -d $(srcdir)/insns.dat insnsi.h: $(INSDEP) - $(PERL) $(srcdir)/insns.pl -i $(srcdir)/insns.dat + $(RUNPERL) $(srcdir)/insns.pl -i $(srcdir)/insns.dat insnsn.c: $(INSDEP) - $(PERL) $(srcdir)/insns.pl -n $(srcdir)/insns.dat + $(RUNPERL) $(srcdir)/insns.pl -n $(srcdir)/insns.dat # These files contains all the standard macros that are derived from # the version number. version.h: version version.pl - $(PERL) $(srcdir)/version.pl h < $(srcdir)/version > version.h + $(RUNPERL) $(srcdir)/version.pl h < $(srcdir)/version > version.h version.mac: version version.pl - $(PERL) $(srcdir)/version.pl mac < $(srcdir)/version > version.mac + $(RUNPERL) $(srcdir)/version.pl mac < $(srcdir)/version > version.mac version.sed: version version.pl - $(PERL) $(srcdir)/version.pl sed < $(srcdir)/version > version.sed + $(RUNPERL) $(srcdir)/version.pl sed < $(srcdir)/version > version.sed version.mak: version version.pl - $(PERL) $(srcdir)/version.pl make < $(srcdir)/version > version.mak + $(RUNPERL) $(srcdir)/version.pl make < $(srcdir)/version > version.mak version.nsh: version version.pl - $(PERL) $(srcdir)/version.pl nsis < $(srcdir)/version > version.nsh + $(RUNPERL) $(srcdir)/version.pl nsis < $(srcdir)/version > version.nsh # This source file is generated from the standard macros file # `standard.mac' by another Perl script. Again, it's part of the # standard distribution. macros.c: macros.pl pptok.ph standard.mac version.mac \ $(srcdir)/macros/*.mac $(srcdir)/output/*.mac - $(PERL) $(srcdir)/macros.pl $(srcdir)/standard.mac version.mac \ + $(RUNPERL) $(srcdir)/macros.pl $(srcdir)/standard.mac version.mac \ $(srcdir)/macros/*.mac $(srcdir)/output/*.mac # These source files are generated from regs.dat by yet another # perl script. regs.c: regs.dat regs.pl - $(PERL) $(srcdir)/regs.pl c $(srcdir)/regs.dat > regs.c + $(RUNPERL) $(srcdir)/regs.pl c $(srcdir)/regs.dat > regs.c regflags.c: regs.dat regs.pl - $(PERL) $(srcdir)/regs.pl fc $(srcdir)/regs.dat > regflags.c + $(RUNPERL) $(srcdir)/regs.pl fc $(srcdir)/regs.dat > regflags.c regdis.c: regs.dat regs.pl - $(PERL) $(srcdir)/regs.pl dc $(srcdir)/regs.dat > regdis.c + $(RUNPERL) $(srcdir)/regs.pl dc $(srcdir)/regs.dat > regdis.c regdis.h: regs.dat regs.pl - $(PERL) $(srcdir)/regs.pl dh $(srcdir)/regs.dat > regdis.h + $(RUNPERL) $(srcdir)/regs.pl dh $(srcdir)/regs.dat > regdis.h regvals.c: regs.dat regs.pl - $(PERL) $(srcdir)/regs.pl vc $(srcdir)/regs.dat > regvals.c + $(RUNPERL) $(srcdir)/regs.pl vc $(srcdir)/regs.dat > regvals.c regs.h: regs.dat regs.pl - $(PERL) $(srcdir)/regs.pl h $(srcdir)/regs.dat > regs.h + $(RUNPERL) $(srcdir)/regs.pl h $(srcdir)/regs.dat > regs.h # Assembler token hash tokhash.c: insns.dat regs.dat tokens.dat tokhash.pl perllib/phash.ph - $(PERL) $(srcdir)/tokhash.pl c $(srcdir)/insns.dat $(srcdir)/regs.dat \ + $(RUNPERL) $(srcdir)/tokhash.pl c $(srcdir)/insns.dat $(srcdir)/regs.dat \ $(srcdir)/tokens.dat > tokhash.c # Assembler token metadata tokens.h: insns.dat regs.dat tokens.dat tokhash.pl perllib/phash.ph - $(PERL) $(srcdir)/tokhash.pl h $(srcdir)/insns.dat $(srcdir)/regs.dat \ + $(RUNPERL) $(srcdir)/tokhash.pl h $(srcdir)/insns.dat $(srcdir)/regs.dat \ $(srcdir)/tokens.dat > tokens.h # Preprocessor token hash pptok.h: pptok.dat pptok.pl perllib/phash.ph - $(PERL) $(srcdir)/pptok.pl h $(srcdir)/pptok.dat pptok.h + $(RUNPERL) $(srcdir)/pptok.pl h $(srcdir)/pptok.dat pptok.h pptok.c: pptok.dat pptok.pl perllib/phash.ph - $(PERL) $(srcdir)/pptok.pl c $(srcdir)/pptok.dat pptok.c + $(RUNPERL) $(srcdir)/pptok.pl c $(srcdir)/pptok.dat pptok.c pptok.ph: pptok.dat pptok.pl perllib/phash.ph - $(PERL) $(srcdir)/pptok.pl ph $(srcdir)/pptok.dat pptok.ph + $(RUNPERL) $(srcdir)/pptok.pl ph $(srcdir)/pptok.dat pptok.ph # Directives hash directiv.h: directiv.dat directiv.pl perllib/phash.ph - $(PERL) $(srcdir)/directiv.pl h $(srcdir)/directiv.dat directiv.h + $(RUNPERL) $(srcdir)/directiv.pl h $(srcdir)/directiv.dat directiv.h directiv.c: directiv.dat directiv.pl perllib/phash.ph - $(PERL) $(srcdir)/directiv.pl c $(srcdir)/directiv.dat directiv.c + $(RUNPERL) $(srcdir)/directiv.pl c $(srcdir)/directiv.dat directiv.c # This target generates all files that require perl. # This allows easier generation of distribution (see dist target). @@ -284,18 +287,18 @@ splint: splint -weak *.c test: nasm$(X) - cd test && $(PERL) performtest.pl --nasm=../nasm *.asm + cd test && $(RUNPERL) performtest.pl --nasm=../nasm *.asm golden: nasm$(X) - cd test && $(PERL) performtest.pl --golden --nasm=../nasm *.asm + cd test && $(RUNPERL) performtest.pl --golden --nasm=../nasm *.asm # # This build dependencies in *ALL* makefiles. Partially for that reason, # it's expected to be invoked manually. # alldeps: perlreq - $(PERL) syncfiles.pl Makefile.in Mkfiles/*.mak - $(PERL) mkdep.pl -M Makefile.in Mkfiles/*.mak -- \ + $(RUNPERL) syncfiles.pl Makefile.in Mkfiles/*.mak + $(RUNPERL) mkdep.pl -M Makefile.in Mkfiles/*.mak -- \ . output lib ./config.status @@ -304,8 +307,8 @@ alldeps: perlreq # @path-separator: "/" #-- Everything below is generated by mkdep.pl - do not edit --# assemble.$(O): assemble.c assemble.h compiler.h config.h directiv.h disp8.h \ - iflag.h iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h \ - preproc.h regs.h tables.h tokens.h + iflag.h iflaggen.h insns.h insnsi.h listing.h nasm.h nasmlib.h opflags.h \ + pptok.h preproc.h regs.h tables.h tokens.h crc64.$(O): crc64.c compiler.h config.h hashtbl.h nasmlib.h directiv.$(O): directiv.c compiler.h config.h directiv.h hashtbl.h insnsi.h \ nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h @@ -405,7 +408,7 @@ output/outlib.$(O): output/outlib.c compiler.h config.h directiv.h insnsi.h \ tables.h output/outmacho.$(O): output/outmacho.c compiler.h config.h directiv.h \ insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \ - pptok.h preproc.h raa.h regs.h saa.h tables.h + pptok.h preproc.h raa.h rbtree.h regs.h saa.h tables.h output/outobj.$(O): output/outobj.c compiler.h config.h directiv.h eval.h \ insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \ pptok.h preproc.h regs.h stdscan.h tables.h @@ -418,10 +421,10 @@ parser.$(O): parser.c compiler.h config.h directiv.h eval.h float.h iflag.h \ pptok.$(O): pptok.c compiler.h config.h hashtbl.h nasmlib.h pptok.h \ preproc.h preproc-nop.$(O): preproc-nop.c compiler.h config.h directiv.h insnsi.h \ - nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h + listing.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h preproc.$(O): preproc.c compiler.h config.h directiv.h eval.h hashtbl.h \ - insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h \ - stdscan.h tables.h tokens.h + insnsi.h listing.h nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h \ + regs.h stdscan.h tables.h tokens.h quote.$(O): quote.c compiler.h config.h nasmlib.h quote.h raa.$(O): raa.c compiler.h config.h nasmlib.h raa.h rbtree.$(O): rbtree.c compiler.h config.h rbtree.h diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak index a1bfd5eb..ae94ee20 100644 --- a/Mkfiles/msvc.mak +++ b/Mkfiles/msvc.mak @@ -61,7 +61,6 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \ macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) \ strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O) \ ilog2.$(O) \ - lib/strlcpy.$(O) \ preproc-nop.$(O) \ disp8.$(O) \ iflag.$(O) @@ -226,8 +225,8 @@ everything: all doc rdf # @exclude: "config.h" #-- Everything below is generated by mkdep.pl - do not edit --# assemble.$(O): assemble.c assemble.h compiler.h directiv.h disp8.h iflag.h \ - iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h \ - regs.h tables.h tokens.h + iflaggen.h insns.h insnsi.h listing.h nasm.h nasmlib.h opflags.h pptok.h \ + preproc.h regs.h tables.h tokens.h crc64.$(O): crc64.c compiler.h hashtbl.h nasmlib.h directiv.$(O): directiv.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \ nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h @@ -321,7 +320,7 @@ output/outlib.$(O): output/outlib.c compiler.h directiv.h insnsi.h nasm.h \ nasmlib.h opflags.h output/outlib.h pptok.h preproc.h regs.h tables.h output/outmacho.$(O): output/outmacho.c compiler.h directiv.h insnsi.h \ nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \ - preproc.h raa.h regs.h saa.h tables.h + preproc.h raa.h rbtree.h regs.h saa.h tables.h output/outobj.$(O): output/outobj.c compiler.h directiv.h eval.h insnsi.h \ nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \ preproc.h regs.h stdscan.h tables.h @@ -332,11 +331,11 @@ parser.$(O): parser.c compiler.h directiv.h eval.h float.h iflag.h \ iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h parser.h pptok.h \ preproc.h regs.h stdscan.h tables.h tokens.h pptok.$(O): pptok.c compiler.h hashtbl.h nasmlib.h pptok.h preproc.h -preproc-nop.$(O): preproc-nop.c compiler.h directiv.h insnsi.h nasm.h \ - nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h +preproc-nop.$(O): preproc-nop.c compiler.h directiv.h insnsi.h listing.h \ + nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h preproc.$(O): preproc.c compiler.h directiv.h eval.h hashtbl.h insnsi.h \ - nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h stdscan.h \ - tables.h tokens.h + listing.h nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h \ + stdscan.h tables.h tokens.h quote.$(O): quote.c compiler.h nasmlib.h quote.h raa.$(O): raa.c compiler.h nasmlib.h raa.h rbtree.$(O): rbtree.c compiler.h rbtree.h diff --git a/Mkfiles/netware.mak b/Mkfiles/netware.mak index d897f440..5d86b181 100644 --- a/Mkfiles/netware.mak +++ b/Mkfiles/netware.mak @@ -48,7 +48,6 @@ NASM = nasm.o nasmlib.o ver.o \ macros.o listing.o eval.o exprlib.o stdscan.o \ strfunc.o tokhash.o regvals.o regflags.o \ ilog2.o \ - strlcpy.o \ preproc-nop.o \ disp8.o \ iflag.o @@ -134,8 +133,8 @@ $(OBJDIR)/version.mak: $(PROOT)/version $(PROOT)/version.pl $(OBJDIR) # @continuation: "\" #-- Everything below is generated by mkdep.pl - do not edit --# assemble.o: assemble.c assemble.h compiler.h config.h directiv.h disp8.h \ - iflag.h iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h \ - preproc.h regs.h tables.h tokens.h + iflag.h iflaggen.h insns.h insnsi.h listing.h nasm.h nasmlib.h opflags.h \ + pptok.h preproc.h regs.h tables.h tokens.h crc64.o: crc64.c compiler.h config.h hashtbl.h nasmlib.h directiv.o: directiv.c compiler.h config.h directiv.h hashtbl.h insnsi.h \ nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h @@ -224,8 +223,8 @@ outieee.o: outieee.c compiler.h config.h directiv.h insnsi.h nasm.h \ outlib.o: outlib.c compiler.h config.h directiv.h insnsi.h nasm.h nasmlib.h \ opflags.h outlib.h pptok.h preproc.h regs.h tables.h outmacho.o: outmacho.c compiler.h config.h directiv.h insnsi.h nasm.h \ - nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h \ - tables.h + nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h raa.h rbtree.h \ + regs.h saa.h tables.h outobj.o: outobj.c compiler.h config.h directiv.h eval.h insnsi.h nasm.h \ nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h regs.h stdscan.h \ tables.h @@ -236,11 +235,11 @@ parser.o: parser.c compiler.h config.h directiv.h eval.h float.h iflag.h \ iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h parser.h pptok.h \ preproc.h regs.h stdscan.h tables.h tokens.h pptok.o: pptok.c compiler.h config.h hashtbl.h nasmlib.h pptok.h preproc.h -preproc-nop.o: preproc-nop.c compiler.h config.h directiv.h insnsi.h nasm.h \ - nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h +preproc-nop.o: preproc-nop.c compiler.h config.h directiv.h insnsi.h \ + listing.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h preproc.o: preproc.c compiler.h config.h directiv.h eval.h hashtbl.h \ - insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h \ - stdscan.h tables.h tokens.h + insnsi.h listing.h nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h \ + regs.h stdscan.h tables.h tokens.h quote.o: quote.c compiler.h config.h nasmlib.h quote.h raa.o: raa.c compiler.h config.h nasmlib.h raa.h rbtree.o: rbtree.c compiler.h config.h rbtree.h diff --git a/Mkfiles/openwcom.mak b/Mkfiles/openwcom.mak index 351df72c..e0428087 100644 --- a/Mkfiles/openwcom.mak +++ b/Mkfiles/openwcom.mak @@ -64,7 +64,6 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) & macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) & strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O) & ilog2.$(O) & - lib/strlcpy.$(O) & preproc-nop.$(O) & disp8.$(O) & iflag.$(O) @@ -271,8 +270,8 @@ alldeps: perlreq .SYMBOLIC # @continuation: "&" #-- Everything below is generated by mkdep.pl - do not edit --# assemble.$(O): assemble.c assemble.h compiler.h config.h directiv.h disp8.h & - iflag.h iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h & - preproc.h regs.h tables.h tokens.h + iflag.h iflaggen.h insns.h insnsi.h listing.h nasm.h nasmlib.h opflags.h & + pptok.h preproc.h regs.h tables.h tokens.h crc64.$(O): crc64.c compiler.h config.h hashtbl.h nasmlib.h directiv.$(O): directiv.c compiler.h config.h directiv.h hashtbl.h insnsi.h & nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h @@ -372,7 +371,7 @@ output/outlib.$(O): output/outlib.c compiler.h config.h directiv.h insnsi.h & tables.h output/outmacho.$(O): output/outmacho.c compiler.h config.h directiv.h & insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h & - pptok.h preproc.h raa.h regs.h saa.h tables.h + pptok.h preproc.h raa.h rbtree.h regs.h saa.h tables.h output/outobj.$(O): output/outobj.c compiler.h config.h directiv.h eval.h & insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h & pptok.h preproc.h regs.h stdscan.h tables.h @@ -385,10 +384,10 @@ parser.$(O): parser.c compiler.h config.h directiv.h eval.h float.h iflag.h & pptok.$(O): pptok.c compiler.h config.h hashtbl.h nasmlib.h pptok.h & preproc.h preproc-nop.$(O): preproc-nop.c compiler.h config.h directiv.h insnsi.h & - nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h + listing.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h preproc.$(O): preproc.c compiler.h config.h directiv.h eval.h hashtbl.h & - insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h & - stdscan.h tables.h tokens.h + insnsi.h listing.h nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h & + regs.h stdscan.h tables.h tokens.h quote.$(O): quote.c compiler.h config.h nasmlib.h quote.h raa.$(O): raa.c compiler.h config.h nasmlib.h raa.h rbtree.$(O): rbtree.c compiler.h config.h rbtree.h diff --git a/Mkfiles/owlinux.mak b/Mkfiles/owlinux.mak index 256abba8..b3c91ffb 100644 --- a/Mkfiles/owlinux.mak +++ b/Mkfiles/owlinux.mak @@ -75,7 +75,6 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \ macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) \ strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O) \ ilog2.$(O) \ - lib/strlcpy.$(O) \ preproc-nop.$(O) \ disp8.$(O) \ iflag.$(O) @@ -240,8 +239,8 @@ everything: all doc rdf # @continuation: "\" #-- Everything below is generated by mkdep.pl - do not edit --# assemble.$(O): assemble.c assemble.h compiler.h directiv.h disp8.h iflag.h \ - iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h \ - regs.h tables.h tokens.h + iflaggen.h insns.h insnsi.h listing.h nasm.h nasmlib.h opflags.h pptok.h \ + preproc.h regs.h tables.h tokens.h crc64.$(O): crc64.c compiler.h hashtbl.h nasmlib.h directiv.$(O): directiv.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \ nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h @@ -335,7 +334,7 @@ output/outlib.$(O): output/outlib.c compiler.h directiv.h insnsi.h nasm.h \ nasmlib.h opflags.h output/outlib.h pptok.h preproc.h regs.h tables.h output/outmacho.$(O): output/outmacho.c compiler.h directiv.h insnsi.h \ nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \ - preproc.h raa.h regs.h saa.h tables.h + preproc.h raa.h rbtree.h regs.h saa.h tables.h output/outobj.$(O): output/outobj.c compiler.h directiv.h eval.h insnsi.h \ nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \ preproc.h regs.h stdscan.h tables.h @@ -346,11 +345,11 @@ parser.$(O): parser.c compiler.h directiv.h eval.h float.h iflag.h \ iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h parser.h pptok.h \ preproc.h regs.h stdscan.h tables.h tokens.h pptok.$(O): pptok.c compiler.h hashtbl.h nasmlib.h pptok.h preproc.h -preproc-nop.$(O): preproc-nop.c compiler.h directiv.h insnsi.h nasm.h \ - nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h +preproc-nop.$(O): preproc-nop.c compiler.h directiv.h insnsi.h listing.h \ + nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h preproc.$(O): preproc.c compiler.h directiv.h eval.h hashtbl.h insnsi.h \ - nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h stdscan.h \ - tables.h tokens.h + listing.h nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h \ + stdscan.h tables.h tokens.h quote.$(O): quote.c compiler.h nasmlib.h quote.h raa.$(O): raa.c compiler.h nasmlib.h raa.h rbtree.$(O): rbtree.c compiler.h rbtree.h @@ -14,25 +14,32 @@ AC_DEFUN(PA_ADD_CFLAGS, CFLAGS="$pa_add_cflags__old_cflags")]) dnl -------------------------------------------------------------------------- -dnl PA_WORKING_STDBOOL +dnl PA_HAVE_FUNC dnl -dnl See if we have a working <stdbool.h> and bool support; in particular, -dnl OpenWatcom 1.8 has a broken _Bool type that we don't want to use. +dnl Look for a function with the specified arguments which could be +dnl a builtin/intrinsic function. dnl -------------------------------------------------------------------------- -AC_DEFUN(PA_WORKING_BOOL, -[AC_MSG_CHECKING([if $CC has a working bool type]) - AC_COMPILE_IFELSE([AC_LANG_SOURCE([ -#ifndef __cplusplus -#include <stdbool.h> -#endif -int foo(bool x, int y) -{ - return x+y; -} - ])], - [AC_MSG_RESULT([yes]) - AC_DEFINE(HAVE_WORKING_BOOL, 1, - [Define to 1 if your compiler has a correct implementation of bool])], - [AC_MSG_RESULT([no])]) -]) +AC_DEFUN(PA_HAVE_FUNC, +[AC_MSG_CHECKING([for $1]) +AC_TRY_LINK([], [(void)$1$2;], +AC_MSG_RESULT([yes]) +AC_DEFINE(m4_toupper([HAVE_$1]), [1], + [Define to 1 if you have the `$1' intrinsic function.]), +AC_MSG_RESULT([no]))]) +dnl -------------------------------------------------------------------------- +dnl PA_REPLACE_FUNC +dnl +dnl Look for a function and possible alternatives, unlike AC_REPLACE_FUNCS +dnl this will only add *one* replacement to LIBOBJS if no alternative is +dnl found. +dnl -------------------------------------------------------------------------- +AC_DEFUN(PA_REPLACE_FUNC_WITH, +[pa_replace_func__$2_missing=true +AC_CHECK_FUNCS([$1], [pa_replace_func__$2_missing=false], []) +if $pa_replace_func__$2_missing; then + AC_LIBOBJ([$2]) +fi]) + +AC_DEFUN(PA_REPLACE_FUNC, +[PA_REPLACE_FUNC_WITH([$1], m4_car(m4_unquote(m4_split(m4_normalize[$1]))))]) @@ -188,6 +188,7 @@ #include "insns.h" #include "tables.h" #include "disp8.h" +#include "listing.h" enum match_result { /* @@ -227,9 +228,6 @@ typedef struct { (((mod) << 6) | (((reg) & 7) << 3) | ((rm) & 7)) static iflag_t cpu; /* cpu level received from nasm.c */ -static efunc errfunc; -static struct ofmt *outfmt; -static ListGen *list; static int64_t calcsize(int32_t, int64_t, int, insn *, const struct itemplate *); @@ -257,8 +255,8 @@ static int has_prefix(insn * ins, enum prefix_pos pos, int prefix) static void assert_no_prefix(insn * ins, enum prefix_pos pos) { if (ins->prefixes[pos]) - errfunc(ERR_NONFATAL, "invalid %s prefix", - prefix_name(ins->prefixes[pos])); + nasm_error(ERR_NONFATAL, "invalid %s prefix", + prefix_name(ins->prefixes[pos])); } static const char *size_name(int size) @@ -287,7 +285,7 @@ static const char *size_name(int size) static void warn_overflow(int pass, int size) { - errfunc(ERR_WARNING | pass | ERR_WARN_NOV, + nasm_error(ERR_WARNING | pass | ERR_WARN_NOV, "%s data exceeds bounds", size_name(size)); } @@ -340,7 +338,7 @@ static void out(int64_t offset, int32_t segto, const void *data, static char *lnfname = NULL; uint8_t p[8]; int asize = addrsize(type, size); /* Address size in bytes */ - const int amax = outfmt->maxbits >> 3; /* Maximum address size in bytes */ + const int amax = ofmt->maxbits >> 3; /* Maximum address size in bytes */ if (type == OUT_ADDRESS && segment == NO_SEG && wrt == NO_SEG) { /* @@ -350,7 +348,7 @@ static void out(int64_t offset, int32_t segto, const void *data, uint8_t *q = p; if (asize > 8) { - errfunc(ERR_PANIC, "OUT_ADDRESS with size > 8"); + nasm_error(ERR_PANIC, "OUT_ADDRESS with size > 8"); return; } @@ -361,7 +359,7 @@ static void out(int64_t offset, int32_t segto, const void *data, asize = 0; /* No longer an address */ } - list->output(offset, data, type, size); + lfmt->output(offset, data, type, size); /* * this call to src_get determines when we call the @@ -373,19 +371,19 @@ static void out(int64_t offset, int32_t segto, const void *data, */ if (src_get(&lineno, &lnfname)) - outfmt->current_dfmt->linenum(lnfname, lineno, segto); + dfmt->linenum(lnfname, lineno, segto); if (asize && asize > amax) { if (type != OUT_ADDRESS || (int)size < 0) { - errfunc(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "%d-bit signed relocation unsupported by output format %s\n", - asize << 3, outfmt->shortname); + asize << 3, ofmt->shortname); size = asize; } else { - errfunc(ERR_WARNING | ERR_WARN_ZEXTRELOC, + nasm_error(ERR_WARNING | ERR_WARN_ZEXTRELOC, "%d-bit unsigned relocation zero-extended from %d bits\n", - asize << 3, outfmt->maxbits); - outfmt->output(segto, data, type, amax, segment, wrt); + asize << 3, ofmt->maxbits); + ofmt->output(segto, data, type, amax, segment, wrt); size = asize - amax; } data = zero_buffer; @@ -393,7 +391,7 @@ static void out(int64_t offset, int32_t segto, const void *data, segment = wrt = NO_SEG; } - outfmt->output(segto, data, type, size, segment, wrt); + ofmt->output(segto, data, type, size, segment, wrt); } static void out_imm8(int64_t offset, int32_t segment, @@ -438,7 +436,7 @@ static bool jmp_match(int32_t segment, int64_t offset, int bits, if (is_byte && c == 0371 && ins->prefixes[PPS_REP] == P_BND) { /* jmp short (opcode eb) cannot be used with bnd prefix. */ ins->prefixes[PPS_REP] = P_none; - errfunc(ERR_WARNING | ERR_WARN_BND | ERR_PASS2 , + nasm_error(ERR_WARNING | ERR_WARN_BND | ERR_PASS2 , "jmp short does not init bnd regs - bnd prefix dropped."); } @@ -446,8 +444,7 @@ static bool jmp_match(int32_t segment, int64_t offset, int bits, } int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp, - insn * instruction, struct ofmt *output, efunc error, - ListGen * listgen) + insn * instruction) { const struct itemplate *temp; int j; @@ -457,10 +454,7 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp, int64_t start = offset; int64_t wsize; /* size for DB etc. */ - errfunc = error; /* to pass to other functions */ cpu = cp; - outfmt = output; /* likewise */ - list = listgen; /* and again */ wsize = idata_bytes(instruction->opcode); if (wsize == -1) @@ -470,14 +464,13 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp, extop *e; int32_t t = instruction->times; if (t < 0) - errfunc(ERR_PANIC, - "instruction->times < 0 (%ld) in assemble()", t); + nasm_panic(0, "instruction->times < 0 (%"PRId32") in assemble()", t); while (t--) { /* repeat TIMES times */ list_for_each(e, instruction->eops) { if (e->type == EOT_DB_NUMBER) { if (wsize > 8) { - errfunc(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "integer supplied to a DT, DO or DY" " instruction"); } else { @@ -503,15 +496,15 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp, } if (t > 0 && t == instruction->times - 1) { /* - * Dummy call to list->output to give the offset to the + * Dummy call to lfmt->output to give the offset to the * listing module. */ - list->output(offset, NULL, OUT_RAWDATA, 0); - list->uplevel(LIST_TIMES); + lfmt->output(offset, NULL, OUT_RAWDATA, 0); + lfmt->uplevel(LIST_TIMES); } } if (instruction->times > 1) - list->downlevel(LIST_TIMES); + lfmt->downlevel(LIST_TIMES); return offset - start; } @@ -521,10 +514,10 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp, fp = fopen(fname, "rb"); if (!fp) { - error(ERR_NONFATAL, "`incbin': unable to open file `%s'", + nasm_error(ERR_NONFATAL, "`incbin': unable to open file `%s'", fname); } else if (fseek(fp, 0L, SEEK_END) < 0) { - error(ERR_NONFATAL, "`incbin': unable to seek on file `%s'", + nasm_error(ERR_NONFATAL, "`incbin': unable to seek on file `%s'", fname); fclose(fp); } else { @@ -542,11 +535,11 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp, len = (size_t)instruction->eops->next->next->offset; } /* - * Dummy call to list->output to give the offset to the + * Dummy call to lfmt->output to give the offset to the * listing module. */ - list->output(offset, NULL, OUT_RAWDATA, 0); - list->uplevel(LIST_INCBIN); + lfmt->output(offset, NULL, OUT_RAWDATA, 0); + lfmt->uplevel(LIST_INCBIN); while (t--) { size_t l; @@ -561,7 +554,7 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp, * actually changes while we are reading * it. */ - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`incbin': unexpected EOF while" " reading file `%s'", fname); t = 0; /* Try to exit cleanly */ @@ -572,15 +565,15 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp, l -= m; } } - list->downlevel(LIST_INCBIN); + lfmt->downlevel(LIST_INCBIN); if (instruction->times > 1) { /* - * Dummy call to list->output to give the offset to the + * Dummy call to lfmt->output to give the offset to the * listing module. */ - list->output(offset, NULL, OUT_RAWDATA, 0); - list->uplevel(LIST_TIMES); - list->downlevel(LIST_TIMES); + lfmt->output(offset, NULL, OUT_RAWDATA, 0); + lfmt->uplevel(LIST_TIMES); + lfmt->downlevel(LIST_TIMES); } fclose(fp); return instruction->times * len; @@ -598,7 +591,7 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp, int64_t insn_size = calcsize(segment, offset, bits, instruction, temp); itimes = instruction->times; if (insn_size < 0) /* shouldn't be, on pass two */ - error(ERR_PANIC, "errors made it through from pass one"); + nasm_error(ERR_PANIC, "errors made it through from pass one"); else while (itimes--) { for (j = 0; j < MAXPREFIX; j++) { @@ -624,21 +617,21 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp, break; case R_CS: if (bits == 64) { - error(ERR_WARNING | ERR_PASS2, + nasm_error(ERR_WARNING | ERR_PASS2, "cs segment base generated, but will be ignored in 64-bit mode"); } c = 0x2E; break; case R_DS: if (bits == 64) { - error(ERR_WARNING | ERR_PASS2, + nasm_error(ERR_WARNING | ERR_PASS2, "ds segment base generated, but will be ignored in 64-bit mode"); } c = 0x3E; break; case R_ES: if (bits == 64) { - error(ERR_WARNING | ERR_PASS2, + nasm_error(ERR_WARNING | ERR_PASS2, "es segment base generated, but will be ignored in 64-bit mode"); } c = 0x26; @@ -651,19 +644,19 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp, break; case R_SS: if (bits == 64) { - error(ERR_WARNING | ERR_PASS2, + nasm_error(ERR_WARNING | ERR_PASS2, "ss segment base generated, but will be ignored in 64-bit mode"); } c = 0x36; break; case R_SEGR6: case R_SEGR7: - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "segr6 and segr7 cannot be used as prefixes"); break; case P_A16: if (bits == 64) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "16-bit addressing is not supported " "in 64-bit mode"); } else if (bits != 16) @@ -675,7 +668,7 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp, break; case P_A64: if (bits != 64) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "64-bit addressing is only supported " "in 64-bit mode"); } @@ -704,7 +697,7 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp, case P_none: break; default: - error(ERR_PANIC, "invalid instruction prefix"); + nasm_error(ERR_PANIC, "invalid instruction prefix"); } if (c != 0) { out(offset, segment, &c, OUT_RAWDATA, 1, @@ -718,49 +711,49 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp, offset += insn_size; if (itimes > 0 && itimes == instruction->times - 1) { /* - * Dummy call to list->output to give the offset to the + * Dummy call to lfmt->output to give the offset to the * listing module. */ - list->output(offset, NULL, OUT_RAWDATA, 0); - list->uplevel(LIST_TIMES); + lfmt->output(offset, NULL, OUT_RAWDATA, 0); + lfmt->uplevel(LIST_TIMES); } } if (instruction->times > 1) - list->downlevel(LIST_TIMES); + lfmt->downlevel(LIST_TIMES); return offset - start; } else { /* No match */ switch (m) { case MERR_OPSIZEMISSING: - error(ERR_NONFATAL, "operation size not specified"); + nasm_error(ERR_NONFATAL, "operation size not specified"); break; case MERR_OPSIZEMISMATCH: - error(ERR_NONFATAL, "mismatch in operand sizes"); + nasm_error(ERR_NONFATAL, "mismatch in operand sizes"); break; case MERR_BRNUMMISMATCH: - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "mismatch in the number of broadcasting elements"); break; case MERR_BADCPU: - error(ERR_NONFATAL, "no instruction for this cpu level"); + nasm_error(ERR_NONFATAL, "no instruction for this cpu level"); break; case MERR_BADMODE: - error(ERR_NONFATAL, "instruction not supported in %d-bit mode", + nasm_error(ERR_NONFATAL, "instruction not supported in %d-bit mode", bits); break; case MERR_ENCMISMATCH: - error(ERR_NONFATAL, "specific encoding scheme not available"); + nasm_error(ERR_NONFATAL, "specific encoding scheme not available"); break; case MERR_BADBND: - error(ERR_NONFATAL, "bnd prefix is not allowed"); + nasm_error(ERR_NONFATAL, "bnd prefix is not allowed"); break; case MERR_BADREPNE: - error(ERR_NONFATAL, "%s prefix is not allowed", + nasm_error(ERR_NONFATAL, "%s prefix is not allowed", (has_prefix(instruction, PPS_REP, P_REPNE) ? "repne" : "repnz")); break; default: - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "invalid combination of opcode and operands"); break; } @@ -769,12 +762,11 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp, } int64_t insn_size(int32_t segment, int64_t offset, int bits, iflag_t cp, - insn * instruction, efunc error) + insn * instruction) { const struct itemplate *temp; enum match_result m; - errfunc = error; /* to pass to other functions */ cpu = cp; if (instruction->opcode == I_none) @@ -817,10 +809,10 @@ int64_t insn_size(int32_t segment, int64_t offset, int bits, iflag_t cp, fp = fopen(fname, "rb"); if (!fp) - error(ERR_NONFATAL, "`incbin': unable to open file `%s'", + nasm_error(ERR_NONFATAL, "`incbin': unable to open file `%s'", fname); else if (fseek(fp, 0L, SEEK_END) < 0) - error(ERR_NONFATAL, "`incbin': unable to seek on file `%s'", + nasm_error(ERR_NONFATAL, "`incbin': unable to seek on file `%s'", fname); else { len = ftell(fp); @@ -912,14 +904,14 @@ static void bad_hle_warn(const insn * ins, uint8_t hleok) case w_lock: if (ins->prefixes[PPS_LOCK] != P_LOCK) { - errfunc(ERR_WARNING | ERR_WARN_HLE | ERR_PASS2, + nasm_error(ERR_WARNING | ERR_WARN_HLE | ERR_PASS2, "%s with this instruction requires lock", prefix_name(rep_pfx)); } break; case w_inval: - errfunc(ERR_WARNING | ERR_WARN_HLE | ERR_PASS2, + nasm_error(ERR_WARNING | ERR_WARN_HLE | ERR_PASS2, "%s invalid with this instruction", prefix_name(rep_pfx)); break; @@ -1117,7 +1109,7 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits, if (pfx == P_O16) break; if (pfx != P_none) - errfunc(ERR_WARNING | ERR_PASS2, "invalid operand size prefix"); + nasm_error(ERR_WARNING | ERR_PASS2, "invalid operand size prefix"); else ins->prefixes[PPS_OSIZE] = P_O16; break; @@ -1129,7 +1121,7 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits, if (pfx == P_O32) break; if (pfx != P_none) - errfunc(ERR_WARNING | ERR_PASS2, "invalid operand size prefix"); + nasm_error(ERR_WARNING | ERR_PASS2, "invalid operand size prefix"); else ins->prefixes[PPS_OSIZE] = P_O32; break; @@ -1184,7 +1176,7 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits, case 0340: if (ins->oprs[0].segment != NO_SEG) - errfunc(ERR_NONFATAL, "attempt to reserve non-constant" + nasm_error(ERR_NONFATAL, "attempt to reserve non-constant" " quantity of BSS space"); else length += ins->oprs[0].offset; @@ -1299,7 +1291,7 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits, if (process_ea(opy, &ea_data, bits, rfield, rflags, ins) != eat) { - errfunc(ERR_NONFATAL, "invalid effective address"); + nasm_error(ERR_NONFATAL, "invalid effective address"); return -1; } else { ins->rex |= ea_data.rex; @@ -1309,7 +1301,7 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits, break; default: - errfunc(ERR_PANIC, "internal instruction table corrupt" + nasm_error(ERR_PANIC, "internal instruction table corrupt" ": instruction code \\%o (0x%02X) given", c, c); break; } @@ -1319,7 +1311,7 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits, if (ins->rex & REX_NH) { if (ins->rex & REX_H) { - errfunc(ERR_NONFATAL, "instruction cannot use high registers"); + nasm_error(ERR_NONFATAL, "instruction cannot use high registers"); return -1; } ins->rex &= ~REX_P; /* Don't force REX prefix due to high reg */ @@ -1343,7 +1335,7 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits, int bad32 = REX_R|REX_W|REX_X|REX_B; if (ins->rex & REX_H) { - errfunc(ERR_NONFATAL, "cannot use high register in AVX instruction"); + nasm_error(ERR_NONFATAL, "cannot use high register in AVX instruction"); return -1; } switch (ins->vex_wlp & 060) { @@ -1361,11 +1353,11 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits, } if (bits != 64 && ((ins->rex & bad32) || ins->vexreg > 7)) { - errfunc(ERR_NONFATAL, "invalid operands in non-64-bit mode"); + nasm_error(ERR_NONFATAL, "invalid operands in non-64-bit mode"); return -1; } else if (!(ins->rex & REX_EV) && ((ins->vexreg > 15) || (ins->evex_p[0] & 0xf0))) { - errfunc(ERR_NONFATAL, "invalid high-16 register in non-AVX-512"); + nasm_error(ERR_NONFATAL, "invalid high-16 register in non-AVX-512"); return -1; } if (ins->rex & REX_EV) @@ -1377,7 +1369,7 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits, length += 2; } else if (ins->rex & REX_MASK) { if (ins->rex & REX_H) { - errfunc(ERR_NONFATAL, "cannot use high register in rex instruction"); + nasm_error(ERR_NONFATAL, "cannot use high register in rex instruction"); return -1; } else if (bits == 64) { length++; @@ -1389,14 +1381,14 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits, lockcheck = false; /* Already errored, no need for warning */ length++; } else { - errfunc(ERR_NONFATAL, "invalid operands in non-64-bit mode"); + nasm_error(ERR_NONFATAL, "invalid operands in non-64-bit mode"); return -1; } } if (has_prefix(ins, PPS_LOCK, P_LOCK) && lockcheck && (!itemp_has(temp,IF_LOCK) || !is_class(MEMORY, ins->oprs[0].type))) { - errfunc(ERR_WARNING | ERR_WARN_LOCK | ERR_PASS2 , + nasm_error(ERR_WARNING | ERR_WARN_LOCK | ERR_PASS2 , "instruction is not lockable"); } @@ -1482,7 +1474,7 @@ static void gencode(int32_t segment, int64_t offset, int bits, case4(020): if (opx->offset < -256 || opx->offset > 255) { - errfunc(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV, + nasm_error(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV, "byte value exceeds bounds"); } out_imm8(offset, segment, opx, -1); @@ -1491,7 +1483,7 @@ static void gencode(int32_t segment, int64_t offset, int bits, case4(024): if (opx->offset < 0 || opx->offset > 255) - errfunc(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV, + nasm_error(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV, "unsigned byte value exceeds bounds"); out_imm8(offset, segment, opx, 1); offset += 1; @@ -1543,7 +1535,7 @@ static void gencode(int32_t segment, int64_t offset, int bits, } else { data = opx->offset - insn_end; if (data > 127 || data < -128) - errfunc(ERR_NONFATAL, "short jump is out of range"); + nasm_error(ERR_NONFATAL, "short jump is out of range"); out(offset, segment, &data, OUT_ADDRESS, 1, NO_SEG, NO_SEG); } @@ -1605,11 +1597,11 @@ static void gencode(int32_t segment, int64_t offset, int bits, case4(074): if (opx->segment == NO_SEG) - errfunc(ERR_NONFATAL, "value referenced by FAR is not" + nasm_error(ERR_NONFATAL, "value referenced by FAR is not" " relocatable"); data = 0; out(offset, segment, &data, OUT_ADDRESS, 2, - outfmt->segbase(1 + opx->segment), + ofmt->segbase(1 + opx->segment), opx->wrt); offset += 2; break; @@ -1620,12 +1612,12 @@ static void gencode(int32_t segment, int64_t offset, int bits, bytes[0] = nasm_regvals[opx->basereg] << 4; opx = &ins->oprs[c & 7]; if (opx->segment != NO_SEG || opx->wrt != NO_SEG) { - errfunc(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "non-absolute expression not permitted as argument %d", c & 7); } else { if (opx->offset & ~15) { - errfunc(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV, + nasm_error(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV, "four-bit argument exceeds bounds"); } bytes[0] |= opx->offset & 15; @@ -1653,7 +1645,7 @@ static void gencode(int32_t segment, int64_t offset, int bits, data = opx->offset; if (opx->wrt == NO_SEG && opx->segment == NO_SEG && (int32_t)data != (int64_t)data) { - errfunc(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV, + nasm_error(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV, "signed dword immediate exceeds bounds"); } out(offset, segment, &data, OUT_ADDRESS, -4, @@ -1727,7 +1719,7 @@ static void gencode(int32_t segment, int64_t offset, int bits, /* If this wasn't explicitly byte-sized, warn as though we * had fallen through to the imm16/32/64 case. */ - errfunc(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV, + nasm_error(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV, "%s value exceeds bounds", (opx->type & BITS8) ? "signed byte" : s == 16 ? "word" : @@ -1830,7 +1822,7 @@ static void gencode(int32_t segment, int64_t offset, int bits, case 0340: if (ins->oprs[0].segment != NO_SEG) - errfunc(ERR_PANIC, "non-constant BSS size in pass two"); + nasm_error(ERR_PANIC, "non-constant BSS size in pass two"); else { int64_t size = ins->oprs[0].offset; if (size > 0) @@ -1916,7 +1908,7 @@ static void gencode(int32_t segment, int64_t offset, int bits, if (process_ea(opy, &ea_data, bits, rfield, rflags, ins) != eat) - errfunc(ERR_NONFATAL, "invalid effective address"); + nasm_error(ERR_NONFATAL, "invalid effective address"); p = bytes; *p++ = ea_data.modrm; @@ -1975,7 +1967,7 @@ static void gencode(int32_t segment, int64_t offset, int bits, break; default: - errfunc(ERR_PANIC, "internal instruction table corrupt" + nasm_error(ERR_PANIC, "internal instruction table corrupt" ": instruction code \\%o (0x%02X) given", c, c); break; } @@ -1985,14 +1977,14 @@ static void gencode(int32_t segment, int64_t offset, int bits, static opflags_t regflag(const operand * o) { if (!is_register(o->basereg)) - errfunc(ERR_PANIC, "invalid operand passed to regflag()"); + nasm_error(ERR_PANIC, "invalid operand passed to regflag()"); return nasm_reg_flags[o->basereg]; } static int32_t regval(const operand * o) { if (!is_register(o->basereg)) - errfunc(ERR_PANIC, "invalid operand passed to regval()"); + nasm_error(ERR_PANIC, "invalid operand passed to regval()"); return nasm_regvals[o->basereg]; } @@ -2002,7 +1994,7 @@ static int op_rexflags(const operand * o, int mask) int val; if (!is_register(o->basereg)) - errfunc(ERR_PANIC, "invalid operand passed to op_rexflags()"); + nasm_error(ERR_PANIC, "invalid operand passed to op_rexflags()"); flags = nasm_reg_flags[o->basereg]; val = nasm_regvals[o->basereg]; @@ -2159,7 +2151,7 @@ static uint8_t get_broadcast_num(opflags_t opflags, opflags_t brsize) * this cannot be a simple arithmetic calculation. */ if (brsize > BITS64) - errfunc(ERR_FATAL, + nasm_error(ERR_FATAL, "size of broadcasting element is greater than 64 bits"); switch (opsize) { @@ -2966,7 +2958,7 @@ static void add_asp(insn *ins, int addrbits) ins->addr_size = (addrbits == 32) ? 16 : 32; } else { /* Impossible... */ - errfunc(ERR_NONFATAL, "impossible combination of address sizes"); + nasm_error(ERR_NONFATAL, "impossible combination of address sizes"); ins->addr_size = addrbits; /* Error recovery */ } @@ -41,8 +41,7 @@ #include "iflag.h" int64_t insn_size(int32_t segment, int64_t offset, int bits, iflag_t cp, - insn * instruction, efunc error); + insn * instruction); int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp, - insn * instruction, struct ofmt *output, efunc error, - ListGen * listgen); + insn * instruction); #endif @@ -73,15 +73,6 @@ #define __STDC_FORMAT_MACROS 1 #ifdef __GNUC__ -# if __GNUC__ >= 4 -# define HAVE_GNUC_4 -# endif -# if __GNUC__ >= 3 -# define HAVE_GNUC_3 -# endif -#endif - -#ifdef __GNUC__ # define _unused __attribute__((unused)) #else # define _unused @@ -108,13 +99,31 @@ int vsnprintf(char *, size_t, const char *, va_list); # endif #endif +/* Missing fseeko/ftello */ +#ifndef HAVE_FSEEKO +# undef off_t /* Just in case it is a macro */ +# ifdef HAVE__FSEEKI64 +# define fseeko _fseeki64 +# define ftello _ftelli64 +# define off_t int64_t +# else +# define fseeko fseek +# define ftello ftell +# define off_t long +# endif +#endif + #if !defined(HAVE_STRLCPY) || !HAVE_DECL_STRLCPY size_t strlcpy(char *, const char *, size_t); #endif #ifndef __cplusplus /* C++ has false, true, bool as keywords */ -# if defined(HAVE_STDBOOL_H) && defined(HAVE_WORKING_BOOL) +# ifdef HAVE_STDBOOL_H # include <stdbool.h> +# elif defined(HAVE__BOOL) +# typedef _Bool bool +# define false 0 +# define true 1 # else /* This is sort of dangerous, since casts will behave different than casting to the standard boolean type. Always use !!, not (bool). */ diff --git a/configure.in b/configure.in index 63192065..e05811a3 100644 --- a/configure.in +++ b/configure.in @@ -1,4 +1,4 @@ -dnl Process this file with autoconf 2.61 or later to produce +dnl Process this file with autoconf 2.63 or later to produce dnl a configure script. AC_PREREQ(2.63) AC_INIT(config.h.in) @@ -51,6 +51,7 @@ dnl Consider AC_USE_SYSTEM_EXTENSIONS if autoconf 2.61 is OK in the future AC_USE_SYSTEM_EXTENSIONS AC_SYS_LARGEFILE AC_PROG_CC +AC_PROG_CC_STDC AC_PROG_LN_S AC_PROG_MAKE_SET if test -f nasm.c; then @@ -66,7 +67,6 @@ AC_C_CONST AC_C_INLINE AC_C_RESTRICT AC_TYPE_SIZE_T -PA_WORKING_BOOL AC_C_BIGENDIAN(AC_DEFINE(WORDS_BIGENDIAN),AC_DEFINE(WORDS_LITTLEENDIAN)) AH_TEMPLATE(WORDS_BIGENDIAN, [Define to 1 if your processor stores words with the most significant @@ -75,11 +75,6 @@ AH_TEMPLATE(WORDS_LITTLEENDIAN, [Define to 1 if your processor stores words with the least significant byte first (like Intel and VAX, unlike Motorola and SPARC).]) -dnl If we have gcc, add appropriate options -PA_ADD_CFLAGS([-W]) -PA_ADD_CFLAGS([-Wall]) -PA_ADD_CFLAGS([-std=c99]) - dnl Look for programs... AC_CHECK_PROGS(NROFF, nroff, false) AC_CHECK_PROGS(ASCIIDOC, asciidoc, false) @@ -114,7 +109,10 @@ dnl The standard header for str*casecmp is <strings.h> AC_CHECK_HEADERS(strings.h) dnl Look for <stdbool.h> -AC_CHECK_HEADERS(stdbool.h) +AC_HEADER_STDBOOL + +dnl Look for <io.h> +AC_CHECK_HEADERS(io.h) dnl Look for <unistd.h> AC_CHECK_HEADERS(unistd.h) @@ -123,30 +121,15 @@ dnl Look for <sys/param.h> AC_CHECK_HEADERS(sys/param.h) dnl Checks for library functions. -AC_SUBST(XOBJS) - AC_CHECK_FUNCS(strcspn, , AC_MSG_ERROR([NASM requires ANSI C (specifically, "strcspn")])) AC_CHECK_FUNCS(strspn, , AC_MSG_ERROR([NASM requires ANSI C (specifically, "strspn")])) -missing=true -AC_CHECK_FUNCS([vsnprintf _vsnprintf], missing=false) -if $missing; then - XOBJS="$XOBJS lib/vsnprintf.o" -fi - -missing=true -AC_CHECK_FUNCS([snprintf _snprintf], missing=false) -if $missing; then - XOBJS="$XOBJS lib/snprintf.o" -fi - AC_CHECK_FUNCS(strcasecmp stricmp) AC_CHECK_FUNCS(strncasecmp strnicmp) AC_CHECK_FUNCS(strsep) -AC_CHECK_FUNCS(strlcpy) AC_CHECK_FUNCS(getuid) AC_CHECK_FUNCS(getgid) @@ -156,6 +139,22 @@ AC_CHECK_FUNCS(canonicalize_file_name) AC_CHECK_FUNCS(_fullpath) AC_CHECK_FUNCS(pathconf) +AC_FUNC_FSEEKO +AC_CHECK_FUNCS([_fseeki64]) +AC_CHECK_FUNCS([ftruncate _chsize _chsize_s]) +AC_CHECK_FUNCS([fileno]) + +PA_HAVE_FUNC(__builtin_ctz, (0U)) +PA_HAVE_FUNC(__builtin_ctzl, (0UL)) +PA_HAVE_FUNC(__builtin_ctzll, (0ULL)) + +dnl Functions for which we have replacements available in lib/ +AC_CONFIG_LIBOBJ_DIR([lib]) +AC_SUBST([LIBOBJDIR], [lib/]) +PA_REPLACE_FUNC([vsnprintf _vsnprintf]) +PA_REPLACE_FUNC([snprintf _snprintf]) +PA_REPLACE_FUNC([strlcpy]) + dnl Check for functions that might not be declared in the headers for dnl various idiotic reasons (mostly because of library authors dnl abusing the meaning of __STRICT_ANSI__) @@ -181,6 +180,9 @@ AC_ARG_ENABLE([ccache], [CC="ccache $CC"], []) +dnl If we have gcc, add appropriate options +PA_ADD_CFLAGS([-W]) +PA_ADD_CFLAGS([-Wall]) PA_ADD_CFLAGS([-pedantic]) AC_ARG_ENABLE([werror], [AC_HELP_STRING([--enable-werror], @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2012 The NASM Authors - All Rights Reserved + * Copyright 1996-2016 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * @@ -54,10 +54,6 @@ #define TEMPEXPR_DELTA 8 static scanner scan; /* Address of scanner routine */ -static efunc error; /* Address of error reporting routine */ -static lfunc labelfunc; /* Address of label routine */ - -static struct ofmt *outfmt; /* Structure of addresses of output routines */ static expr **tempexprs = NULL; static int ntempexprs; @@ -71,7 +67,6 @@ static struct tokenval *tokval; /* The current token */ static int i; /* The t_type of tokval */ static void *scpriv; -static struct location *location; /* Pointer to current line's segment,offset */ static int *opflags; static struct eval_hints *hint; @@ -227,22 +222,22 @@ static expr *segment_part(expr * e) return unknown_expr(); if (!is_reloc(e)) { - error(ERR_NONFATAL, "cannot apply SEG to a non-relocatable value"); + nasm_error(ERR_NONFATAL, "cannot apply SEG to a non-relocatable value"); return NULL; } seg = reloc_seg(e); if (seg == NO_SEG) { - error(ERR_NONFATAL, "cannot apply SEG to a non-relocatable value"); + nasm_error(ERR_NONFATAL, "cannot apply SEG to a non-relocatable value"); return NULL; } else if (seg & SEG_ABS) { return scalarvect(seg & ~SEG_ABS); } else if (seg & 1) { - error(ERR_NONFATAL, "SEG applied to something which" + nasm_error(ERR_NONFATAL, "SEG applied to something which" " is already a segment base"); return NULL; } else { - int32_t base = outfmt->segbase(seg + 1); + int32_t base = ofmt->segbase(seg + 1); begintemp(); addtotemp((base == NO_SEG ? EXPR_UNKNOWN : EXPR_SEGBASE + base), @@ -306,7 +301,7 @@ static expr *rexp0(int critical) return NULL; if (!(is_simple(e) || is_just_unknown(e)) || !(is_simple(f) || is_just_unknown(f))) { - error(ERR_NONFATAL, "`|' operator may only be applied to" + nasm_error(ERR_NONFATAL, "`|' operator may only be applied to" " scalar values"); } @@ -333,7 +328,7 @@ static expr *rexp1(int critical) return NULL; if (!(is_simple(e) || is_just_unknown(e)) || !(is_simple(f) || is_just_unknown(f))) { - error(ERR_NONFATAL, "`^' operator may only be applied to" + nasm_error(ERR_NONFATAL, "`^' operator may only be applied to" " scalar values"); } @@ -359,7 +354,7 @@ static expr *rexp2(int critical) return NULL; if (!(is_simple(e) || is_just_unknown(e)) || !(is_simple(f) || is_just_unknown(f))) { - error(ERR_NONFATAL, "`&' operator may only be applied to" + nasm_error(ERR_NONFATAL, "`&' operator may only be applied to" " scalar values"); } if (is_just_unknown(e) || is_just_unknown(f)) @@ -403,7 +398,7 @@ static expr *rexp3(int critical) if (is_unknown(e)) v = -1; /* means unknown */ else if (!is_really_simple(e)) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%s': operands differ by a non-scalar", (j == TOKEN_LE ? "<=" : j == TOKEN_LT ? "<" : j == TOKEN_GE ? ">=" : ">")); @@ -443,7 +438,7 @@ static expr *expr0(int critical) return NULL; if (!(is_simple(e) || is_just_unknown(e)) || !(is_simple(f) || is_just_unknown(f))) { - error(ERR_NONFATAL, "`|' operator may only be applied to" + nasm_error(ERR_NONFATAL, "`|' operator may only be applied to" " scalar values"); } if (is_just_unknown(e) || is_just_unknown(f)) @@ -469,7 +464,7 @@ static expr *expr1(int critical) return NULL; if (!(is_simple(e) || is_just_unknown(e)) || !(is_simple(f) || is_just_unknown(f))) { - error(ERR_NONFATAL, "`^' operator may only be applied to" + nasm_error(ERR_NONFATAL, "`^' operator may only be applied to" " scalar values"); } if (is_just_unknown(e) || is_just_unknown(f)) @@ -495,7 +490,7 @@ static expr *expr2(int critical) return NULL; if (!(is_simple(e) || is_just_unknown(e)) || !(is_simple(f) || is_just_unknown(f))) { - error(ERR_NONFATAL, "`&' operator may only be applied to" + nasm_error(ERR_NONFATAL, "`&' operator may only be applied to" " scalar values"); } if (is_just_unknown(e) || is_just_unknown(f)) @@ -522,7 +517,7 @@ static expr *expr3(int critical) return NULL; if (!(is_simple(e) || is_just_unknown(e)) || !(is_simple(f) || is_just_unknown(f))) { - error(ERR_NONFATAL, "shift operator may only be applied to" + nasm_error(ERR_NONFATAL, "shift operator may only be applied to" " scalar values"); } else if (is_just_unknown(e) || is_just_unknown(f)) { e = unknown_expr(); @@ -581,12 +576,12 @@ static expr *expr5(int critical) return NULL; if (j != '*' && (!(is_simple(e) || is_just_unknown(e)) || !(is_simple(f) || is_just_unknown(f)))) { - error(ERR_NONFATAL, "division operator may only be applied to" + nasm_error(ERR_NONFATAL, "division operator may only be applied to" " scalar values"); return NULL; } if (j != '*' && !is_unknown(f) && reloc_value(f) == 0) { - error(ERR_NONFATAL, "division by zero"); + nasm_error(ERR_NONFATAL, "division by zero"); return NULL; } switch (j) { @@ -598,7 +593,7 @@ static expr *expr5(int critical) else if (is_just_unknown(e) && is_just_unknown(f)) e = unknown_expr(); else { - error(ERR_NONFATAL, "unable to multiply two " + nasm_error(ERR_NONFATAL, "unable to multiply two " "non-scalar objects"); return NULL; } @@ -657,7 +652,7 @@ static expr *eval_floatize(enum floatize type) i = scan(scpriv, tokval); if (i != '(') { - error(ERR_NONFATAL, "expecting `('"); + nasm_error(ERR_NONFATAL, "expecting `('"); return NULL; } i = scan(scpriv, tokval); @@ -666,15 +661,14 @@ static expr *eval_floatize(enum floatize type) i = scan(scpriv, tokval); } if (i != TOKEN_FLOAT) { - error(ERR_NONFATAL, "expecting floating-point number"); + nasm_error(ERR_NONFATAL, "expecting floating-point number"); return NULL; } - if (!float_const(tokval->t_charptr, sign, result, - formats[type].bytes, error)) + if (!float_const(tokval->t_charptr, sign, result, formats[type].bytes)) return NULL; i = scan(scpriv, tokval); if (i != ')') { - error(ERR_NONFATAL, "expecting `)'"); + nasm_error(ERR_NONFATAL, "expecting `)'"); return NULL; } @@ -706,13 +700,13 @@ static expr *eval_strfunc(enum strfunc type) i = scan(scpriv, tokval); } if (i != TOKEN_STR) { - error(ERR_NONFATAL, "expecting string"); + nasm_error(ERR_NONFATAL, "expecting string"); return NULL; } string_len = string_transform(tokval->t_charptr, tokval->t_inttwo, &string, type); if (string_len == (size_t)-1) { - error(ERR_NONFATAL, "invalid string for transform"); + nasm_error(ERR_NONFATAL, "invalid string for transform"); return NULL; } @@ -720,13 +714,13 @@ static expr *eval_strfunc(enum strfunc type) if (parens) { i = scan(scpriv, tokval); if (i != ')') { - error(ERR_NONFATAL, "expecting `)'"); + nasm_error(ERR_NONFATAL, "expecting `)'"); return NULL; } } if (rn_warn) - error(ERR_WARNING|ERR_PASS1, "character constant too long"); + nasm_error(ERR_WARNING|ERR_PASS1, "character constant too long"); begintemp(); addtotemp(EXPR_SIMPLE, val); @@ -747,7 +741,7 @@ static int64_t eval_ifunc(int64_t val, enum ifunc func) errtype = (func == IFUNC_ILOG2E) ? ERR_NONFATAL : ERR_WARNING; if (!is_power2(uval)) - error(errtype, "ilog2 argument is not a power of two"); + nasm_error(errtype, "ilog2 argument is not a power of two"); /* fall through */ case IFUNC_ILOG2F: rv = ilog2_64(uval); @@ -758,7 +752,7 @@ static int64_t eval_ifunc(int64_t val, enum ifunc func) break; default: - error(ERR_PANIC, "invalid IFUNC token %d", func); + nasm_error(ERR_PANIC, "invalid IFUNC token %d", func); rv = 0; break; } @@ -796,7 +790,7 @@ static expr *expr6(int critical) if (is_just_unknown(e)) return unknown_expr(); else if (!is_simple(e)) { - error(ERR_NONFATAL, "`~' operator may only be applied to" + nasm_error(ERR_NONFATAL, "`~' operator may only be applied to" " scalar values"); return NULL; } @@ -810,7 +804,7 @@ static expr *expr6(int critical) if (is_just_unknown(e)) return unknown_expr(); else if (!is_simple(e)) { - error(ERR_NONFATAL, "`!' operator may only be applied to" + nasm_error(ERR_NONFATAL, "`!' operator may only be applied to" " scalar values"); return NULL; } @@ -826,7 +820,7 @@ static expr *expr6(int critical) if (is_just_unknown(e)) return unknown_expr(); else if (!is_simple(e)) { - error(ERR_NONFATAL, "function may only be applied to" + nasm_error(ERR_NONFATAL, "function may only be applied to" " scalar values"); return NULL; } @@ -842,7 +836,7 @@ static expr *expr6(int critical) if (!e) return NULL; if (is_unknown(e) && critical) { - error(ERR_NONFATAL, "unable to determine segment base"); + nasm_error(ERR_NONFATAL, "unable to determine segment base"); return NULL; } return e; @@ -859,7 +853,7 @@ static expr *expr6(int critical) if (!e) return NULL; if (i != ')') { - error(ERR_NONFATAL, "expecting `)'"); + nasm_error(ERR_NONFATAL, "expecting `)'"); return NULL; } i = scan(scpriv, tokval); @@ -881,7 +875,7 @@ static expr *expr6(int critical) case TOKEN_STR: tmpval = readstrnum(tokval->t_charptr, tokval->t_inttwo, &rn_warn); if (rn_warn) - error(ERR_WARNING|ERR_PASS1, "character constant too long"); + nasm_error(ERR_WARNING|ERR_PASS1, "character constant too long"); addtotemp(EXPR_SIMPLE, tmpval); break; case TOKEN_REG: @@ -894,12 +888,12 @@ static expr *expr6(int critical) case TOKEN_HERE: case TOKEN_BASE: /* - * If !location->known, this indicates that no + * If !location.known, this indicates that no * symbol, Here or Base references are valid because we * are in preprocess-only mode. */ - if (!location->known) { - error(ERR_NONFATAL, + if (!location.known) { + nasm_error(ERR_NONFATAL, "%s not supported in preprocess-only mode", (i == TOKEN_HERE ? "`$'" : i == TOKEN_BASE ? "`$$'" : @@ -910,20 +904,20 @@ static expr *expr6(int critical) type = EXPR_SIMPLE; /* might get overridden by UNKNOWN */ if (i == TOKEN_BASE) { - label_seg = in_abs_seg ? abs_seg : location->segment; + label_seg = in_abs_seg ? abs_seg : location.segment; label_ofs = 0; } else if (i == TOKEN_HERE) { - label_seg = in_abs_seg ? abs_seg : location->segment; - label_ofs = in_abs_seg ? abs_offset : location->offset; + label_seg = in_abs_seg ? abs_seg : location.segment; + label_ofs = in_abs_seg ? abs_offset : location.offset; } else { - if (!labelfunc(tokval->t_charptr, &label_seg, &label_ofs)) { + if (!lookup_label(tokval->t_charptr, &label_seg, &label_ofs)) { scope = local_scope(tokval->t_charptr); if (critical == 2) { - error(ERR_NONFATAL, "symbol `%s%s' undefined", + nasm_error(ERR_NONFATAL, "symbol `%s%s' undefined", scope,tokval->t_charptr); return NULL; } else if (critical == 1) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "symbol `%s%s' not defined before use", scope,tokval->t_charptr); return NULL; @@ -950,22 +944,13 @@ static expr *expr6(int critical) return finishtemp(); default: - error(ERR_NONFATAL, "expression syntax error"); + nasm_error(ERR_NONFATAL, "expression syntax error"); return NULL; } } -void eval_global_info(struct ofmt *output, lfunc lookup_label, - struct location * locp) -{ - outfmt = output; - labelfunc = lookup_label; - location = locp; -} - expr *evaluate(scanner sc, void *scprivate, struct tokenval *tv, - int *fwref, int critical, efunc report_error, - struct eval_hints *hints) + int *fwref, int critical, struct eval_hints *hints) { expr *e; expr *f = NULL; @@ -983,7 +968,6 @@ expr *evaluate(scanner sc, void *scprivate, struct tokenval *tv, scan = sc; scpriv = scprivate; tokval = tv; - error = report_error; opflags = fwref; if (tokval->t_type == TOKEN_INVALID) @@ -1013,14 +997,14 @@ expr *evaluate(scanner sc, void *scprivate, struct tokenval *tv, int64_t value; begintemp(); if (!is_reloc(f)) { - error(ERR_NONFATAL, "invalid right-hand operand to WRT"); + nasm_error(ERR_NONFATAL, "invalid right-hand operand to WRT"); return NULL; } value = reloc_seg(f); if (value == NO_SEG) value = reloc_value(f) | SEG_ABS; else if (!(value & SEG_ABS) && !(value % 2) && critical) { - error(ERR_NONFATAL, "invalid right-hand operand to WRT"); + nasm_error(ERR_NONFATAL, "invalid right-hand operand to WRT"); return NULL; } addtotemp(EXPR_WRT, value); @@ -39,19 +39,10 @@ #define NASM_EVAL_H /* - * Called once to tell the evaluator what output format is - * providing segment-base details, and what function can be used to - * look labels up. - */ -void eval_global_info(struct ofmt *output, lfunc lookup_label, - struct location * locp); - -/* * The evaluator itself. */ expr *evaluate(scanner sc, void *scprivate, struct tokenval *tv, - int *fwref, int critical, efunc report_error, - struct eval_hints *hints); + int *fwref, int critical, struct eval_hints *hints); void eval_cleanup(void); @@ -51,7 +51,6 @@ * local variables * ----------------- */ -static efunc error; static bool daz = false; /* denormals as zero */ static enum float_round rc = FLOAT_RC_NEAR; /* rounding control */ @@ -183,7 +182,7 @@ static int32_t read_exponent(const char *string, int32_t max) } else if (*string == '_') { /* do nothing */ } else { - error(ERR_NONFATAL|ERR_PASS1, + nasm_error(ERR_NONFATAL|ERR_PASS1, "invalid character in floating-point constant %s: '%c'", "exponent", *string); return INT32_MAX; @@ -220,7 +219,7 @@ static bool ieee_flconvert(const char *string, fp_limb *mant, if (!seendot) { seendot = true; } else { - error(ERR_NONFATAL|ERR_PASS1, + nasm_error(ERR_NONFATAL|ERR_PASS1, "too many periods in floating-point constant"); return false; } @@ -235,7 +234,7 @@ static bool ieee_flconvert(const char *string, fp_limb *mant, *p++ = *string - '0'; } else { if (!warned) { - error(ERR_WARNING|ERR_WARN_FL_TOOLONG|ERR_PASS1, + nasm_error(ERR_WARNING|ERR_WARN_FL_TOOLONG|ERR_PASS1, "floating-point constant significand contains " "more than %i digits", MANT_DIGITS); warned = true; @@ -248,7 +247,7 @@ static bool ieee_flconvert(const char *string, fp_limb *mant, } else if (*string == '_') { /* do nothing */ } else { - error(ERR_NONFATAL|ERR_PASS1, + nasm_error(ERR_NONFATAL|ERR_PASS1, "invalid character in floating-point constant %s: '%c'", "significand", *string); return false; @@ -534,7 +533,7 @@ static bool ieee_flconvert_bin(const char *string, int bits, if (!seendot) seendot = true; else { - error(ERR_NONFATAL|ERR_PASS1, + nasm_error(ERR_NONFATAL|ERR_PASS1, "too many periods in floating-point constant"); return false; } @@ -576,7 +575,7 @@ static bool ieee_flconvert_bin(const char *string, int bits, } else if (c == '_') { /* ignore */ } else { - error(ERR_NONFATAL|ERR_PASS1, + nasm_error(ERR_NONFATAL|ERR_PASS1, "floating-point constant: `%c' is invalid character", c); return false; } @@ -674,7 +673,7 @@ static int to_packed_bcd(const char *str, const char *p, int tv = -1; if (fmt != &ieee_80) { - error(ERR_NONFATAL|ERR_PASS1, + nasm_error(ERR_NONFATAL|ERR_PASS1, "packed BCD requires an 80-bit format"); return 0; } @@ -684,7 +683,7 @@ static int to_packed_bcd(const char *str, const char *p, if (c >= '0' && c <= '9') { if (tv < 0) { if (n == 9) { - error(ERR_WARNING|ERR_PASS1, + nasm_error(ERR_WARNING|ERR_PASS1, "packed BCD truncated to 18 digits"); } tv = c-'0'; @@ -697,7 +696,7 @@ static int to_packed_bcd(const char *str, const char *p, } else if (c == '_') { /* do nothing */ } else { - error(ERR_NONFATAL|ERR_PASS1, + nasm_error(ERR_NONFATAL|ERR_PASS1, "invalid character `%c' in packed BCD constant", c); return 0; } @@ -734,7 +733,7 @@ static int to_float(const char *str, int s, uint8_t *result, const char *strend; if (!str[0]) { - error(ERR_PANIC, + nasm_error(ERR_PANIC, "internal errror: empty string passed to float_const"); return 0; } @@ -762,7 +761,7 @@ static int to_float(const char *str, int s, uint8_t *result, type = FL_INFINITY; break; default: - error(ERR_NONFATAL|ERR_PASS1, + nasm_error(ERR_NONFATAL|ERR_PASS1, "internal error: unknown FP constant token `%s'\n", str); type = FL_QNAN; break; @@ -810,7 +809,7 @@ static int to_float(const char *str, int s, uint8_t *result, type = FL_NORMAL; } else if (exponent > 0) { if (pass0 == 1) - error(ERR_WARNING|ERR_WARN_FL_OVERFLOW|ERR_PASS1, + nasm_error(ERR_WARNING|ERR_WARN_FL_OVERFLOW|ERR_PASS1, "overflow in floating-point constant"); type = FL_INFINITY; } else { @@ -845,11 +844,11 @@ static int to_float(const char *str, int s, uint8_t *result, } else { if (daz || is_zero(mant)) { /* Flush denormals to zero */ - error(ERR_WARNING|ERR_WARN_FL_UNDERFLOW|ERR_PASS1, + nasm_error(ERR_WARNING|ERR_WARN_FL_UNDERFLOW|ERR_PASS1, "underflow in floating-point constant"); goto zero; } else { - error(ERR_WARNING|ERR_WARN_FL_DENORM|ERR_PASS1, + nasm_error(ERR_WARNING|ERR_WARN_FL_DENORM|ERR_PASS1, "denormal floating-point constant"); } } @@ -865,7 +864,7 @@ static int to_float(const char *str, int s, uint8_t *result, ieee_shr(mant, 1); exponent++; if (exponent >= (expmax << 1)-1) { - error(ERR_WARNING|ERR_WARN_FL_OVERFLOW|ERR_PASS1, + nasm_error(ERR_WARNING|ERR_WARN_FL_OVERFLOW|ERR_PASS1, "overflow in floating-point constant"); type = FL_INFINITY; goto overflow; @@ -901,11 +900,8 @@ static int to_float(const char *str, int s, uint8_t *result, return 1; /* success */ } -int float_const(const char *number, int sign, uint8_t *result, - int bytes, efunc err) +int float_const(const char *number, int sign, uint8_t *result, int bytes) { - error = err; - switch (bytes) { case 1: return to_float(number, sign, result, &ieee_8); @@ -920,7 +916,7 @@ int float_const(const char *number, int sign, uint8_t *result, case 16: return to_float(number, sign, result, &ieee_128); default: - error(ERR_PANIC, "strange value %d passed to float_const", bytes); + nasm_error(ERR_PANIC, "strange value %d passed to float_const", bytes); return 0; } } @@ -48,8 +48,7 @@ enum float_round { FLOAT_RC_UP, }; -int float_const(const char *string, int sign, uint8_t *result, int bytes, - efunc error); +int float_const(const char *string, int sign, uint8_t *result, int bytes); int float_option(const char *option); #endif @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2010 The NASM Authors - All Rights Reserved + * Copyright 1996-2016 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * @@ -42,6 +42,7 @@ } \ } while (0) + #if defined(__GNUC__) && defined(__x86_64__) int ilog2_32(uint32_t v) @@ -67,7 +68,7 @@ int ilog2_32(uint32_t v) return n; } -#elif defined(HAVE_GNUC_4) +#elif defined(HAVE___BUILTIN_CTZ) && INT_MAX >= 2147483647 int ilog2_32(uint32_t v) { @@ -106,7 +107,7 @@ int ilog2_64(uint64_t v) return n; } -#elif defined(HAVE_GNUC_4) +#elif defined(HAVE__BUILTIN_CTZLL) && LLONG_MAX >= 9223372036854775807L int ilog2_64(uint64_t v) { @@ -262,14 +262,14 @@ void redefine_label(char *label, int32_t segment, int64_t offset, char *special, ofmt->symdef(xsymbol, segment, offset, exi, special ? special : lptr->defn.special); - ofmt->current_dfmt->debug_deflabel(xsymbol, segment, offset, exi, + dfmt->debug_deflabel(xsymbol, segment, offset, exi, special ? special : lptr->defn.special); /** nasm_free(xsymbol); ! outobj.c stores the pointer; ouch!!! **/ } else { if ((lptr->defn.is_global & (GLOBAL_BIT | EXTERN_BIT)) != EXTERN_BIT) { ofmt->symdef(lptr->defn.label, segment, offset, exi, special ? special : lptr->defn.special); - ofmt->current_dfmt->debug_deflabel(label, segment, offset, exi, + dfmt->debug_deflabel(label, segment, offset, exi, special ? special : lptr->defn.special); } } @@ -327,14 +327,14 @@ void define_label(char *label, int32_t segment, int64_t offset, char *special, ofmt->symdef(xsymbol, segment, offset, exi, special ? special : lptr->defn.special); - ofmt->current_dfmt->debug_deflabel(xsymbol, segment, offset, exi, + dfmt->debug_deflabel(xsymbol, segment, offset, exi, special ? special : lptr->defn.special); /** nasm_free(xsymbol); ! outobj.c stores the pointer; ouch!!! **/ } else { if ((lptr->defn.is_global & (GLOBAL_BIT | EXTERN_BIT)) != EXTERN_BIT) { ofmt->symdef(lptr->defn.label, segment, offset, exi, special ? special : lptr->defn.special); - ofmt->current_dfmt->debug_deflabel(label, segment, offset, exi, + dfmt->debug_deflabel(label, segment, offset, exi, special ? special : lptr->defn.special); } } @@ -371,7 +371,7 @@ void define_common(char *label, int32_t segment, int32_t size, char *special) ofmt->symdef(lptr->defn.label, segment, size, 2, special ? special : lptr->defn.special); - ofmt->current_dfmt->debug_deflabel(lptr->defn.label, segment, size, 2, + dfmt->debug_deflabel(lptr->defn.label, segment, size, 2, special ? special : lptr->defn.special); } diff --git a/lib/strlcpy.c b/lib/strlcpy.c index 4335359c..22d9ccfb 100644 --- a/lib/strlcpy.c +++ b/lib/strlcpy.c @@ -14,8 +14,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <sys/types.h> -#include <string.h> #include "compiler.h" /* @@ -126,12 +126,17 @@ static void list_emit(void) } } -static void list_init(char *fname, efunc error) +static void list_init(const char *fname) { + if (!fname) { + listfp = NULL; + return; + } + listfp = fopen(fname, "w"); if (!listfp) { - error(ERR_NONFATAL, "unable to open listing file `%s'", - fname); + nasm_error(ERR_NONFATAL, "unable to open listing file `%s'", + fname); return; } @@ -197,7 +202,7 @@ static void list_output(int32_t offset, const void *data, { char q[20]; - if (!listp || suppress || user_nolist) /* fbk - 9/2/00 */ + if (!listp || suppress || user_nolist) return; switch (type) { @@ -321,7 +326,7 @@ static void list_error(int severity, const char *pfx, const char *msg) } -ListGen nasmlist = { +static const struct lfmt nasm_list = { list_init, list_cleanup, list_output, @@ -330,3 +335,6 @@ ListGen nasmlist = { list_downlevel, list_error }; + +const struct lfmt *lfmt = &nasm_list; + @@ -38,7 +38,71 @@ #ifndef NASM_LISTING_H #define NASM_LISTING_H -extern ListGen nasmlist; -extern int user_nolist; /* fbk - 9/1/00 */ +/* + * List-file generators should look like this: + */ +struct lfmt { + /* + * Called to initialize the listing file generator. Before this + * is called, the other routines will silently do nothing when + * called. The `char *' parameter is the file name to write the + * listing to. + */ + void (*init)(const char *fname); + + /* + * Called to clear stuff up and close the listing file. + */ + void (*cleanup)(void); + + /* + * Called to output binary data. Parameters are: the offset; + * the data; the data type. Data types are similar to the + * output-format interface, only OUT_ADDRESS will _always_ be + * displayed as if it's relocatable, so ensure that any non- + * relocatable address has been converted to OUT_RAWDATA by + * then. Note that OUT_RAWDATA,0 is a valid data type, and is a + * dummy call used to give the listing generator an offset to + * work with when doing things like uplevel(LIST_TIMES) or + * uplevel(LIST_INCBIN). + */ + void (*output)(int32_t offset, const void *data, enum out_type type, uint64_t size); + + /* + * Called to send a text line to the listing generator. The + * `int' parameter is LIST_READ or LIST_MACRO depending on + * whether the line came directly from an input file or is the + * result of a multi-line macro expansion. + */ + void (*line)(int type, char *line); + + /* + * Called to change one of the various levelled mechanisms in + * the listing generator. LIST_INCLUDE and LIST_MACRO can be + * used to increase the nesting level of include files and + * macro expansions; LIST_TIMES and LIST_INCBIN switch on the + * two binary-output-suppression mechanisms for large-scale + * pseudo-instructions. + * + * LIST_MACRO_NOLIST is synonymous with LIST_MACRO except that + * it indicates the beginning of the expansion of a `nolist' + * macro, so anything under that level won't be expanded unless + * it includes another file. + */ + void (*uplevel)(int type); + + /* + * Reverse the effects of uplevel. + */ + void (*downlevel)(int type); + + /* + * Called on a warning or error, with the error message. + */ + void (*error)(int severity, const char *pfx, const char *msg); +}; + +extern const struct lfmt *lfmt; +extern bool user_nolist; #endif @@ -78,10 +78,11 @@ static int get_bits(char *value); static iflag_t get_cpu(char *cpu_str); static void parse_cmdline(int, char **); static void assemble_file(char *, StrList **); +static bool is_suppressed_warning(int severity); +static bool skip_this_pass(int severity); static void nasm_verror_gnu(int severity, const char *fmt, va_list args); static void nasm_verror_vc(int severity, const char *fmt, va_list args); static void nasm_verror_common(int severity, const char *fmt, va_list args); -static bool is_suppressed_warning(int severity); static void usage(void); static int using_debug_info, opt_verbose_info; @@ -98,8 +99,8 @@ static char listname[FILENAME_MAX]; static char errname[FILENAME_MAX]; static int globallineno; /* for forward-reference tracking */ /* static int pass = 0; */ -struct ofmt *ofmt = &OF_DEFAULT; -struct ofmt_alias *ofmt_alias = NULL; +const struct ofmt *ofmt = &OF_DEFAULT; +const struct ofmt_alias *ofmt_alias = NULL; const struct dfmt *dfmt; static FILE *error_file; /* Where to write error messages */ @@ -115,7 +116,7 @@ int64_t global_offset_changed; /* referenced in labels.c */ int64_t prev_offset_changed; int32_t stall_count; -static struct location location; +struct location location; int in_abs_seg; /* Flag we are in ABSOLUTE seg */ int32_t abs_seg; /* ABSOLUTE segment basis */ int32_t abs_offset; /* ABSOLUTE offset */ @@ -125,7 +126,7 @@ static struct RAA *offsets; static struct SAA *forwrefs; /* keep track of forward references */ static const struct forwrefinfo *forwref; -static struct preproc_ops *preproc; +static const struct preproc_ops *preproc; #define OP_NORMAL (1u << 0) #define OP_PREPROCESS (1u << 1) @@ -172,7 +173,7 @@ static const struct warning { static bool want_usage; static bool terminate_after_phase; -int user_nolist = 0; /* fbk 9/2/00 */ +bool user_nolist = false; static char *quote_for_make(const char *str); @@ -357,12 +358,12 @@ int main(int argc, char **argv) /* If debugging info is disabled, suppress any debug calls */ if (!using_debug_info) - ofmt->current_dfmt = &null_debug_form; + dfmt = &null_debug_form; + else if (!dfmt) + dfmt = ofmt->default_dfmt; if (ofmt->stdmac) preproc->extra_stdmac(ofmt->stdmac); - parser_global_info(&location); - eval_global_info(ofmt, lookup_label, &location); /* define some macros dependent of command-line */ define_macros_late(); @@ -377,7 +378,7 @@ int main(int argc, char **argv) if (depend_missing_ok) preproc->include_path(NULL); /* "assume generated" */ - preproc->reset(inname, 0, &nasmlist, depend_ptr); + preproc->reset(inname, 0, depend_ptr); if (outname[0] == '\0') ofmt->filename(inname, outname); ofile = NULL; @@ -402,8 +403,9 @@ int main(int argc, char **argv) location.known = false; /* pass = 1; */ - preproc->reset(inname, 3, &nasmlist, depend_ptr); - memcpy(warning_on, warning_on_global, (ERR_WARN_MAX+1) * sizeof(bool)); + preproc->reset(inname, 3, depend_ptr); + memcpy(warning_on, warning_on_global, + (ERR_WARN_MAX+1) * sizeof(bool)); while ((line = preproc->getline())) { /* @@ -457,7 +459,6 @@ int main(int argc, char **argv) init_labels(); ofmt->init(); - dfmt = ofmt->current_dfmt; dfmt->init(); assemble_file(inname, depend_ptr); @@ -616,7 +617,7 @@ enum text_options { OPT_PREFIX, OPT_POSTFIX, }; -struct textargs textopts[] = { +static const struct textargs textopts[] = { {"prefix", OPT_PREFIX}, {"postfix", OPT_POSTFIX}, {NULL, 0} @@ -663,6 +664,7 @@ static bool process_arg(char *p, char *q) "unrecognised output format `%s' - " "use -hf for a list", param); } + dfmt = NULL; break; case 'O': /* Optimization level */ @@ -740,8 +742,8 @@ static bool process_arg(char *p, char *q) break; case 'F': /* specify debug format */ - ofmt->current_dfmt = dfmt_find(ofmt, param); - if (!ofmt->current_dfmt) { + dfmt = dfmt_find(ofmt, param); + if (!dfmt) { nasm_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE, "unrecognized debug format `%s' for" " output format `%s'", @@ -1203,8 +1205,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) int pass_max; if (cmd_sb == 32 && iflag_ffs(&cmd_cpu) < IF_386) - nasm_error(ERR_FATAL, "command line: " - "32-bit segment size requires a higher cpu"); + nasm_fatal(0, "command line: 32-bit segment size requires a higher cpu"); pass_max = prev_offset_changed = (INT_MAX >> 1) + 2; /* Almost unlimited */ for (passn = 1; pass0 <= 2; passn++) { @@ -1220,8 +1221,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) globalbits = sb = cmd_sb; /* set 'bits' to command line default */ cpu = cmd_cpu; if (pass0 == 2) { - if (*listname) - nasmlist.init(listname, nasm_error); + lfmt->init(listname); } in_abs_seg = false; global_offset_changed = 0; /* set by redefine_label */ @@ -1233,8 +1233,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) raa_free(offsets); offsets = raa_init(); } - preproc->reset(fname, pass1, &nasmlist, - pass1 == 2 ? depend_ptr : NULL); + preproc->reset(fname, pass1, pass1 == 2 ? depend_ptr : NULL); memcpy(warning_on, warning_on_global, (ERR_WARN_MAX+1) * sizeof(bool)); globallineno = 0; @@ -1273,7 +1272,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) stdscan_reset(); stdscan_set(value); tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, NULL, pass2, nasm_error, NULL); + e = evaluate(stdscan, NULL, &tokval, NULL, pass2, NULL); if (e) { unsigned int align = (unsigned int)e->value; if ((uint64_t)e->value > 0x7fffffff) { @@ -1431,8 +1430,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) stdscan_reset(); stdscan_set(value); tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, NULL, pass2, - nasm_error, NULL); + e = evaluate(stdscan, NULL, &tokval, NULL, pass2, NULL); if (e) { if (!is_reloc(e)) nasm_error(pass0 == @@ -1679,7 +1677,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) if (pass1 == 1) { int64_t l = insn_size(location.segment, offs, sb, cpu, - &output_ins, nasm_error); + &output_ins); /* if (using_debug_info) && output_ins.opcode != -1) */ if (using_debug_info) @@ -1758,8 +1756,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) } else { offs += assemble(location.segment, offs, sb, cpu, - &output_ins, ofmt, nasm_error, - &nasmlist); + &output_ins); set_curr_offs(offs); } @@ -1804,7 +1801,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) } preproc->cleanup(0); - nasmlist.cleanup(); + lfmt->cleanup(); if (!terminate_after_phase && opt_verbose_info) { /* -On and -Ov switches */ fprintf(stdout, "info: assembly required 1+%d+1 passes\n", passn-3); @@ -1876,11 +1873,13 @@ static void nasm_verror_gnu(int severity, const char *fmt, va_list ap) if (!(severity & ERR_NOFILE)) src_get(&lineno, ¤tfile); - if (currentfile) { - fprintf(error_file, "%s:%"PRId32": ", currentfile, lineno); - nasm_free(currentfile); - } else { - fputs("nasm: ", error_file); + if (!skip_this_pass(severity)) { + if (currentfile) { + fprintf(error_file, "%s:%"PRId32": ", currentfile, lineno); + nasm_free(currentfile); + } else { + fputs("nasm: ", error_file); + } } nasm_verror_common(severity, fmt, ap); @@ -1912,11 +1911,13 @@ static void nasm_verror_vc(int severity, const char *fmt, va_list ap) if (!(severity & ERR_NOFILE)) src_get(&lineno, ¤tfile); - if (currentfile) { - fprintf(error_file, "%s(%"PRId32") : ", currentfile, lineno); - nasm_free(currentfile); - } else { - fputs("nasm: ", error_file); + if (!skip_this_pass(severity)) { + if (currentfile) { + fprintf(error_file, "%s(%"PRId32") : ", currentfile, lineno); + nasm_free(currentfile); + } else { + fputs("nasm: ", error_file); + } } nasm_verror_common(severity, fmt, ap); @@ -1936,11 +1937,6 @@ static bool is_suppressed_warning(int severity) if ((severity & ERR_MASK) != ERR_WARNING) return false; - /* See if it's a pass-one only warning and we're not in pass one. */ - if (((severity & ERR_PASS1) && pass0 != 1) || - ((severity & ERR_PASS2) && pass0 != 2)) - return true; - /* Might be a warning but suppresed explicitly */ if (severity & ERR_WARN_MASK) return !warning_on[WARN_IDX(severity)]; @@ -1948,6 +1944,19 @@ static bool is_suppressed_warning(int severity) return false; } +static bool skip_this_pass(int severity) +{ + /* See if it's a pass-one only warning and we're not in pass one. */ + if ((severity & ERR_MASK) > ERR_WARNING) + return false; + + if (((severity & ERR_PASS1) && pass0 != 1) || + ((severity & ERR_PASS2) && pass0 != 2)) + return true; + + return false; +} + /** * common error reporting * This is the common back end of the error reporting schemes currently @@ -1986,10 +1995,15 @@ static void nasm_verror_common(int severity, const char *fmt, va_list args) vsnprintf(msg, sizeof msg, fmt, args); - fprintf(error_file, "%s%s\n", pfx, msg); + if (!skip_this_pass(severity)) + fprintf(error_file, "%s%s\n", pfx, msg); - if (*listname) - nasmlist.error(severity, pfx, msg); + /* + * Don't suppress this with skip_this_pass(), or we don't get + * preprocessor warnings in the list file + */ + if ((severity & ERR_MASK) >= ERR_WARNING) + lfmt->error(severity, pfx, msg); if (severity & ERR_USAGE) want_usage = true; @@ -2019,6 +2033,11 @@ static void nasm_verror_common(int severity, const char *fmt, va_list args) case ERR_PANIC: fflush(NULL); /* abort(); */ /* halt, catch fire, and dump core */ + if (ofile) { + fclose(ofile); + remove(outname); + ofile = NULL; + } exit(3); break; } @@ -127,70 +127,6 @@ void define_label(char *label, int32_t segment, int64_t offset, char *special, bool is_norm, bool isextrn); /* - * List-file generators should look like this: - */ -typedef struct { - /* - * Called to initialize the listing file generator. Before this - * is called, the other routines will silently do nothing when - * called. The `char *' parameter is the file name to write the - * listing to. - */ - void (*init)(char *fname, efunc error); - - /* - * Called to clear stuff up and close the listing file. - */ - void (*cleanup)(void); - - /* - * Called to output binary data. Parameters are: the offset; - * the data; the data type. Data types are similar to the - * output-format interface, only OUT_ADDRESS will _always_ be - * displayed as if it's relocatable, so ensure that any non- - * relocatable address has been converted to OUT_RAWDATA by - * then. Note that OUT_RAWDATA,0 is a valid data type, and is a - * dummy call used to give the listing generator an offset to - * work with when doing things like uplevel(LIST_TIMES) or - * uplevel(LIST_INCBIN). - */ - void (*output)(int32_t offset, const void *data, enum out_type type, uint64_t size); - - /* - * Called to send a text line to the listing generator. The - * `int' parameter is LIST_READ or LIST_MACRO depending on - * whether the line came directly from an input file or is the - * result of a multi-line macro expansion. - */ - void (*line)(int type, char *line); - - /* - * Called to change one of the various levelled mechanisms in - * the listing generator. LIST_INCLUDE and LIST_MACRO can be - * used to increase the nesting level of include files and - * macro expansions; LIST_TIMES and LIST_INCBIN switch on the - * two binary-output-suppression mechanisms for large-scale - * pseudo-instructions. - * - * LIST_MACRO_NOLIST is synonymous with LIST_MACRO except that - * it indicates the beginning of the expansion of a `nolist' - * macro, so anything under that level won't be expanded unless - * it includes another file. - */ - void (*uplevel)(int type); - - /* - * Reverse the effects of uplevel. - */ - void (*downlevel)(int type); - - /* - * Called on a warning or error, with the error message. - */ - void (*error)(int severity, const char *pfx, const char *msg); -} ListGen; - -/* * Token types returned by the scanner, in addition to ordinary * ASCII character values, and zero for end-of-string. */ @@ -284,6 +220,7 @@ struct location { int32_t segment; int known; }; +extern struct location location; /* * Expression-evaluator datatype. Expressions, within the @@ -351,7 +288,7 @@ struct eval_hints { #define CRITICAL 0x100 typedef expr *(*evalfunc)(scanner sc, void *scprivate, struct tokenval *tv, int *fwref, int critical, - efunc error, struct eval_hints *hints); + struct eval_hints *hints); /* * Special values for expr->type. @@ -382,7 +319,7 @@ struct preproc_ops { * of the pass, an error reporting function, an evaluator * function, and a listing generator to talk to. */ - void (*reset)(char *file, int pass, ListGen *listgen, StrList **deplist); + void (*reset)(char *file, int pass, StrList **deplist); /* * Called to fetch a line of preprocessed source. The line @@ -408,8 +345,8 @@ struct preproc_ops { void (*include_path)(char *path); }; -extern struct preproc_ops nasmpp; -extern struct preproc_ops preproc_nop; +extern const struct preproc_ops nasmpp; +extern const struct preproc_ops preproc_nop; /* * Some lexical properties of the NASM source language, included @@ -542,6 +479,10 @@ enum vex_class { * prefixes, we must ensure the enumerations for prefixes and * register names do not overlap. */ +#ifdef P_WAIT +# undef P_WAIT /* Macro defined on some Windows versions */ +#endif + enum prefixes { /* instruction prefixes */ P_none = 0, PREFIX_ENUM_START = REG_ENUM_LIMIT, @@ -746,16 +687,12 @@ struct ofmt { /* * this is a pointer to the first element of the debug information */ - struct dfmt **debug_formats; + const struct dfmt * const *debug_formats; /* - * and a pointer to the element that is being used - * note: this is set to the default at compile time and changed if the - * -F option is selected. If developing a set of new debug formats for - * an output format, be sure to set this to whatever default you want - * + * the default debugging format if -F is not specified */ - const struct dfmt *current_dfmt; + const struct dfmt *default_dfmt; /* * This, if non-NULL, is a NULL-terminated list of `char *'s @@ -916,10 +853,10 @@ struct ofmt { struct ofmt_alias { const char *shortname; const char *fullname; - struct ofmt *ofmt; + const struct ofmt *ofmt; }; -extern struct ofmt *ofmt; +extern const struct ofmt *ofmt; extern FILE *ofile; /* @@ -49,7 +49,7 @@ #include "insns.h" int globalbits = 0; /* defined in nasm.h, works better here for ASM+DISASM */ -static vefunc nasm_verror; /* Global error handling function */ +vefunc nasm_verror; /* Global error handling function */ /* Uninitialized -> all zero by C spec */ const uint8_t zero_buffer[ZERO_BUF_SIZE]; @@ -69,11 +69,6 @@ void tolower_init(void) nasm_tolower_tab[i] = tolower(i); } -void nasm_set_verror(vefunc ve) -{ - nasm_verror = ve; -} - void nasm_error(int severity, const char *fmt, ...) { va_list ap; @@ -83,6 +78,15 @@ void nasm_error(int severity, const char *fmt, ...) va_end(ap); } +no_return nasm_fatal(int flags, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + nasm_verror(flags | ERR_FATAL, fmt, ap); + abort(); /* We should never get here */ +} + no_return nasm_panic(int flags, const char *fmt, ...) { va_list ap; @@ -101,7 +105,7 @@ void *nasm_malloc(size_t size) { void *p = malloc(size); if (!p) - nasm_error(ERR_FATAL | ERR_NOFILE, "out of memory"); + nasm_fatal(ERR_NOFILE, "out of memory"); return p; } @@ -109,7 +113,7 @@ void *nasm_zalloc(size_t size) { void *p = calloc(size, 1); if (!p) - nasm_error(ERR_FATAL | ERR_NOFILE, "out of memory"); + nasm_fatal(ERR_NOFILE, "out of memory"); return p; } @@ -117,7 +121,7 @@ void *nasm_realloc(void *q, size_t size) { void *p = q ? realloc(q, size) : malloc(size); if (!p) - nasm_error(ERR_FATAL | ERR_NOFILE, "out of memory"); + nasm_fatal(ERR_NOFILE, "out of memory"); return p; } @@ -134,7 +138,7 @@ char *nasm_strdup(const char *s) p = malloc(size); if (!p) - nasm_error(ERR_FATAL | ERR_NOFILE, "out of memory"); + nasm_fatal(ERR_NOFILE, "out of memory"); strcpy(p, s); return p; } @@ -146,7 +150,7 @@ char *nasm_strndup(const char *s, size_t len) p = malloc(size); if (!p) - nasm_error(ERR_FATAL | ERR_NOFILE, "out of memory"); + nasm_fatal(ERR_NOFILE, "out of memory"); strncpy(p, s, len); p[len] = '\0'; return p; @@ -161,7 +165,7 @@ no_return nasm_assert_failed(const char *file, int line, const char *msg) void nasm_write(const void *ptr, size_t size, FILE *f) { size_t n = fwrite(ptr, 1, size, f); - if (n != size) + if (n != size || ferror(f) || feof(f)) nasm_error(ERR_FATAL, "unable to write output: %s", strerror(errno)); } @@ -455,10 +459,32 @@ void fwriteaddr(uint64_t data, int size, FILE * fp) #endif +#ifdef HAVE_FILENO /* Useless without fileno() */ +# ifdef HAVE__CHSIZE_S +# define nasm_ftruncate(fd,size) _chsize_s(fd,size) +# elif defined(HAVE__CHSIZE) +# define nasm_ftruncate(fd,size) _chsize(fd,size) +# elif defined(HAVE_FTRUNCATE) +# define nasm_ftruncate(fd,size) ftruncate(fd,size) +# endif +#endif + void fwritezero(size_t bytes, FILE *fp) { size_t blksize; +#ifdef nasm_ftruncate + if (bytes >= BUFSIZ && !ferror(fp) && !feof(fp)) { + off_t pos = ftello(fp); + if (pos >= 0) { + if (!fflush(fp) && + !nasm_ftruncate(fileno(fp), pos + bytes) && + !fseeko(fp, pos+bytes, SEEK_SET)) + return; + } + } +#endif + while (bytes) { blksize = (bytes < ZERO_BUF_SIZE) ? bytes : ZERO_BUF_SIZE; @@ -44,7 +44,13 @@ #include <stdio.h> #include <string.h> #ifdef HAVE_STRINGS_H -#include <strings.h> +# include <strings.h> +#endif +#ifdef HAVE_IO_H +# include <io.h> +#endif +#ifdef HAVE_UNISTD_H +# include <unistd.h> #endif /* @@ -73,31 +79,40 @@ extern unsigned char nasm_tolower_tab[256]; /* * An error reporting function should look like this. */ -typedef void (*efunc) (int severity, const char *fmt, ...); -typedef void (*vefunc) (int severity, const char *fmt, va_list ap); void printf_func(2, 3) nasm_error(int severity, const char *fmt, ...); -void nasm_set_verror(vefunc); +no_return printf_func(2, 3) nasm_fatal(int flags, const char *fmt, ...); no_return printf_func(2, 3) nasm_panic(int flags, const char *fmt, ...); no_return nasm_panic_from_macro(const char *file, int line); #define panic() nasm_panic_from_macro(__FILE__, __LINE__); +typedef void (*vefunc) (int severity, const char *fmt, va_list ap); +extern vefunc nasm_verror; +static inline vefunc nasm_set_verror(vefunc ve) +{ + vefunc old_verror = nasm_verror; + nasm_verror = ve; + return old_verror; +} + /* * These are the error severity codes which get passed as the first * argument to an efunc. */ -#define ERR_DEBUG 0x00000008 /* put out debugging message */ -#define ERR_WARNING 0x00000000 /* warn only: no further action */ -#define ERR_NONFATAL 0x00000001 /* terminate assembly after phase */ -#define ERR_FATAL 0x00000002 /* instantly fatal: exit with error */ -#define ERR_PANIC 0x00000003 /* internal error: panic instantly +#define ERR_DEBUG 0x00000000 /* put out debugging message */ +#define ERR_WARNING 0x00000001 /* warn only: no further action */ +#define ERR_NONFATAL 0x00000002 /* terminate assembly after phase */ +#define ERR_FATAL 0x00000006 /* instantly fatal: exit with error */ +#define ERR_PANIC 0x00000007 /* internal error: panic instantly * and dump core for reference */ -#define ERR_MASK 0x0000000F /* mask off the above codes */ +#define ERR_MASK 0x00000007 /* mask off the above codes */ #define ERR_NOFILE 0x00000010 /* don't give source file name/line */ #define ERR_USAGE 0x00000020 /* print a usage message */ #define ERR_PASS1 0x00000040 /* only print this error on pass one */ #define ERR_PASS2 0x00000080 + #define ERR_NO_SEVERITY 0x00000100 /* suppress printing severity */ +#define ERR_PP_PRECOND 0x00000200 /* for preprocessor use */ /* * These codes define specific types of suppressible warning. diff --git a/output/codeview.c b/output/codeview.c index 2f5bb690..f837c126 100644 --- a/output/codeview.c +++ b/output/codeview.c @@ -58,7 +58,7 @@ static void cv8_typevalue(int32_t type); static void cv8_output(int type, void *param); static void cv8_cleanup(void); -struct dfmt df_cv8 = { +const struct dfmt df_cv8 = { .fullname = "Codeview 8", .shortname = "cv8", .init = cv8_init, diff --git a/output/nulldbg.c b/output/nulldbg.c index 581a1c55..e8f87d75 100644 --- a/output/nulldbg.c +++ b/output/nulldbg.c @@ -77,7 +77,7 @@ void null_debug_cleanup(void) { } -struct dfmt null_debug_form = { +const struct dfmt null_debug_form = { "Null debug format", "null", null_debug_init, @@ -89,4 +89,4 @@ struct dfmt null_debug_form = { null_debug_cleanup }; -struct dfmt *null_debug_arr[2] = { &null_debug_form, NULL }; +const struct dfmt * const null_debug_arr[2] = { &null_debug_form, NULL }; diff --git a/output/outaout.c b/output/outaout.c index 360f549d..5a125408 100644 --- a/output/outaout.c +++ b/output/outaout.c @@ -188,7 +188,7 @@ static void aout_init(void) #ifdef OF_AOUTB -extern struct ofmt of_aoutb; +extern const struct ofmt of_aoutb; static void aoutb_init(void) { @@ -298,7 +298,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset, stdscan_reset(); stdscan_set(p); tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL); + e = evaluate(stdscan, NULL, &tokval, NULL, 1, NULL); if (e) { if (!is_simple(e)) nasm_error(ERR_NONFATAL, "cannot use relocatable" @@ -392,8 +392,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset, stdscan_reset(); stdscan_set(special + n); tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, &fwd, 0, nasm_error, - NULL); + e = evaluate(stdscan, NULL, &tokval, &fwd, 0, NULL); if (fwd) { sym->nextfwd = fwds; fwds = sym; @@ -909,7 +908,7 @@ extern macros_t aout_stdmac[]; #ifdef OF_AOUT -struct ofmt of_aout = { +const struct ofmt of_aout = { "Linux a.out object files", "aout", 0, @@ -933,7 +932,7 @@ struct ofmt of_aout = { #ifdef OF_AOUTB -struct ofmt of_aoutb = { +const struct ofmt of_aoutb = { "NetBSD/FreeBSD a.out object files", "aoutb", 0, diff --git a/output/outas86.c b/output/outas86.c index 43108c4e..ac3628f7 100644 --- a/output/outas86.c +++ b/output/outas86.c @@ -629,7 +629,7 @@ static void as86_filename(char *inname, char *outname) extern macros_t as86_stdmac[]; -struct ofmt of_as86 = { +const struct ofmt of_as86 = { "Linux as86 (bin86 version 0.3) object files", "as86", 0, diff --git a/output/outbin.c b/output/outbin.c index 71c7bcd4..5f993467 100644 --- a/output/outbin.c +++ b/output/outbin.c @@ -990,7 +990,7 @@ static int bin_read_attribute(char **line, int *attribute, stdscan_reset(); stdscan_set(exp); tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL); + e = evaluate(stdscan, NULL, &tokval, NULL, 1, NULL); if (e) { if (!is_really_simple(e)) { nasm_error(ERR_NONFATAL, "section attribute value must be" @@ -1299,7 +1299,7 @@ static int bin_directive(enum directives directive, char *args, int pass) stdscan_reset(); stdscan_set(args); tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL); + e = evaluate(stdscan, NULL, &tokval, NULL, 1, NULL); if (e) { if (!is_really_simple(e)) nasm_error(ERR_NONFATAL, "org value must be a critical" @@ -1405,7 +1405,7 @@ static int bin_set_info(enum geninfo type, char **val) return 0; } -struct ofmt of_bin, of_ith, of_srec; +const 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); @@ -1655,7 +1655,7 @@ static void do_output_srec(void) } -struct ofmt of_bin = { +const struct ofmt of_bin = { "flat-form binary files (e.g. DOS .COM, .SYS)", "bin", 0, @@ -1675,7 +1675,7 @@ struct ofmt of_bin = { bin_cleanup }; -struct ofmt of_ith = { +const struct ofmt of_ith = { "Intel hex", "ith", OFMT_TEXT, @@ -1695,7 +1695,7 @@ struct ofmt of_ith = { bin_cleanup }; -struct ofmt of_srec = { +const struct ofmt of_srec = { "Motorola S-records", "srec", OFMT_TEXT, diff --git a/output/outcoff.c b/output/outcoff.c index a712f953..3daccb7e 100644 --- a/output/outcoff.c +++ b/output/outcoff.c @@ -228,8 +228,8 @@ static void coff_cleanup(int debuginfo) struct coff_Reloc *r; int i; - if (debuginfo && ofmt->current_dfmt->cleanup) - ofmt->current_dfmt->cleanup(); + if (debuginfo && dfmt->cleanup) + dfmt->cleanup(); coff_write(); for (i = 0; i < coff_nsects; i++) { @@ -603,7 +603,7 @@ static void coff_out(int32_t segto, const void *data, memset(mydata, 0, sizeof(mydata)); - if (ofmt->current_dfmt && ofmt->current_dfmt->debug_output) { + if (dfmt && dfmt->debug_output) { struct coff_DebugInfo dinfo; dinfo.segto = segto; dinfo.seg = segment; @@ -614,7 +614,7 @@ static void coff_out(int32_t segto, const void *data, else dinfo.size = realsize(type, size); - ofmt->current_dfmt->debug_output(type, &dinfo); + dfmt->debug_output(type, &dinfo); } if (type == OUT_RESERVE) { @@ -1168,7 +1168,7 @@ static int coff_set_info(enum geninfo type, char **val) #ifdef OF_COFF -struct ofmt of_coff = { +const struct ofmt of_coff = { "COFF (i386) object files (e.g. DJGPP for DOS)", "coff", 0, @@ -1190,13 +1190,13 @@ struct ofmt of_coff = { #endif -extern struct dfmt df_cv8; +extern const struct dfmt df_cv8; #ifdef OF_WIN32 -struct dfmt *win32_debug_arr[2] = { &df_cv8, NULL }; +static const struct dfmt * const win32_debug_arr[2] = { &df_cv8, NULL }; -struct ofmt of_win32 = { +const struct ofmt of_win32 = { "Microsoft Win32 (i386) object files", "win32", 0, @@ -1220,9 +1220,9 @@ struct ofmt of_win32 = { #ifdef OF_WIN64 -struct dfmt *win64_debug_arr[2] = { &df_cv8, NULL }; +static const struct dfmt * const win64_debug_arr[2] = { &df_cv8, NULL }; -struct ofmt of_win64 = { +const struct ofmt of_win64 = { "Microsoft Win64 (x86-64) object files", "win64", 0, diff --git a/output/outdbg.c b/output/outdbg.c index 034a6152..60a3ad28 100644 --- a/output/outdbg.c +++ b/output/outdbg.c @@ -56,7 +56,7 @@ struct Section { char *name; } *dbgsect; -struct ofmt of_dbg; +const struct ofmt of_dbg; static void dbg_init(void) { dbgsect = NULL; @@ -66,7 +66,7 @@ static void dbg_init(void) static void dbg_cleanup(int debuginfo) { (void)debuginfo; - of_dbg.current_dfmt->cleanup(); + dfmt->cleanup(); while (dbgsect) { struct Section *tmp = dbgsect; dbgsect = dbgsect->next; @@ -203,7 +203,7 @@ static int dbg_set_info(enum geninfo type, char **val) return 0; } -char *types[] = { +static const char * const types[] = { "unknown", "label", "byte", "word", "dword", "float", "qword", "tbyte" }; static void dbgdbg_init(void) @@ -242,7 +242,7 @@ static void dbgdbg_typevalue(int32_t type) fprintf(ofile, "new type: %s(%"PRIX32")\n", types[TYM_TYPE(type) >> 3], TYM_ELEMENTS(type)); } -static struct dfmt debug_debug_form = { +static const struct dfmt debug_debug_form = { "Trace of all info passed to debug stage", "debug", dbgdbg_init, @@ -254,13 +254,13 @@ static struct dfmt debug_debug_form = { dbgdbg_cleanup, }; -static struct dfmt *debug_debug_arr[3] = { +static const struct dfmt * const debug_debug_arr[3] = { &debug_debug_form, &null_debug_form, NULL }; -struct ofmt of_dbg = { +const struct ofmt of_dbg = { "Trace of all info passed to output stage", "dbg", OFMT_TEXT, diff --git a/output/outelf32.c b/output/outelf32.c index e4971ed4..24efc0f5 100644 --- a/output/outelf32.c +++ b/output/outelf32.c @@ -43,7 +43,6 @@ #include <string.h> #include <ctype.h> #include <inttypes.h> -#include <limits.h> #include "nasm.h" #include "nasmlib.h" @@ -83,7 +82,7 @@ static struct elf_symbol *fwds; static char elf_module[FILENAME_MAX]; -extern struct ofmt of_elf32; +extern const struct ofmt of_elf32; static struct ELF_SECTDATA { void *data; @@ -153,29 +152,29 @@ static int arangeslen, arangesrellen, pubnameslen, infolen, inforellen, abbrevlen, linelen, linerellen, framelen, loclen; static int32_t dwarf_infosym, dwarf_abbrevsym, dwarf_linesym; -static struct dfmt df_dwarf; -static struct dfmt df_stabs; +static const struct dfmt df_dwarf; +static const struct dfmt df_stabs; static struct elf_symbol *lastsym; /* common debugging routines */ -static void debug32_typevalue(int32_t); -static void debug32_deflabel(char *, int32_t, int64_t, int, char *); -static void debug32_directive(const char *, const char *); +static void debug_typevalue(int32_t); +static void debug_deflabel(char *, int32_t, int64_t, int, char *); +static void debug_directive(const char *, const char *); /* stabs debugging routines */ -static void stabs32_linenum(const char *filename, int32_t linenumber, int32_t); -static void stabs32_output(int, void *); -static void stabs32_generate(void); -static void stabs32_cleanup(void); +static void stabs_linenum(const char *filename, int32_t linenumber, int32_t); +static void stabs_output(int, void *); +static void stabs_generate(void); +static void stabs_cleanup(void); /* dwarf debugging routines */ -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); -static void dwarf32_cleanup(void); -static void dwarf32_findfile(const char *); -static void dwarf32_findsect(const int); +static void dwarf_init(void); +static void dwarf_linenum(const char *filename, int32_t linenumber, int32_t); +static void dwarf_output(int, void *); +static void dwarf_generate(void); +static void dwarf_cleanup(void); +static void dwarf_findfile(const char *); +static void dwarf_findsect(const int); /* * Special NASM section numbers which are used to define ELF special @@ -242,8 +241,8 @@ static void elf_cleanup(int debuginfo) saa_free(syms); raa_free(bsym); saa_free(strs); - if (of_elf32.current_dfmt) { - of_elf32.current_dfmt->cleanup(); + if (dfmt) { + dfmt->cleanup(); } } @@ -383,7 +382,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, stdscan_reset(); stdscan_set(p); tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL); + e = evaluate(stdscan, NULL, &tokval, NULL, 1, NULL); if (e) { if (!is_simple(e)) nasm_error(ERR_NONFATAL, "cannot use relocatable" @@ -525,8 +524,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, stdscan_reset(); stdscan_set(special + n); tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, &fwd, 0, nasm_error, - NULL); + e = evaluate(stdscan, NULL, &tokval, &fwd, 0, NULL); if (fwd) { sym->nextfwd = fwds; fwds = sym; @@ -694,11 +692,11 @@ static void elf_out(int32_t segto, const void *data, } /* again some stabs debugging stuff */ - if (of_elf32.current_dfmt) { + if (dfmt) { sinfo.offset = s->len; sinfo.section = i; sinfo.name = s->name; - of_elf32.current_dfmt->debug_output(TY_STABSSYMLIN, &sinfo); + dfmt->debug_output(TY_STABSSYMLIN, &sinfo); } /* end of debugging stuff */ @@ -897,9 +895,9 @@ static void elf_write(void) * relocation sections for the user sections. */ nsections = sec_numspecial + 1; - if (of_elf32.current_dfmt == &df_stabs) + if (dfmt == &df_stabs) nsections += 3; - else if (of_elf32.current_dfmt == &df_dwarf) + else if (dfmt == &df_dwarf) nsections += 10; add_sectname("", ".shstrtab"); @@ -913,12 +911,12 @@ static void elf_write(void) } } - if (of_elf32.current_dfmt == &df_stabs) { + if (dfmt == &df_stabs) { /* in case the debug information is wanted, just add these three sections... */ add_sectname("", ".stab"); add_sectname("", ".stabstr"); add_sectname(".rel", ".stab"); - } else if (of_elf32.current_dfmt == &df_dwarf) { + } else if (dfmt == &df_dwarf) { /* the dwarf debug standard specifies the following ten sections, not all of which are currently implemented, although all of them are defined. */ @@ -1015,12 +1013,12 @@ static void elf_write(void) p += strlen(p) + 1; } - if (of_elf32.current_dfmt == &df_stabs) { + if (dfmt == &df_stabs) { /* for debugging information, create the last three sections which are the .stab , .stabstr and .rel.stab sections respectively */ /* this function call creates the stab sections in memory */ - stabs32_generate(); + stabs_generate(); if (stabbuf && stabstrbuf && stabrelbuf) { elf_section_header(p - shstrtab, SHT_PROGBITS, 0, stabbuf, false, @@ -1036,12 +1034,12 @@ static void elf_write(void) stabrellen, sec_symtab, sec_stab, 4, 8); p += strlen(p) + 1; } - } else if (of_elf32.current_dfmt == &df_dwarf) { + } else if (dfmt == &df_dwarf) { /* for dwarf debugging information, create the ten dwarf sections */ /* this function call creates the dwarf sections in memory */ if (dwarf_fsect) - dwarf32_generate(); + dwarf_generate(); elf_section_header(p - shstrtab, SHT_PROGBITS, 0, arangesbuf, false, arangeslen, 0, 0, 1, 0); @@ -1163,7 +1161,7 @@ static struct SAA *elf_build_symtab(int32_t *len, int32_t *local) * which are relocation targets. */ //*** fix for 32 bit - if (of_elf32.current_dfmt == &df_dwarf) { + if (dfmt == &df_dwarf) { dwarf_infosym = *local; p = entry; WRITELONG(p, 0); /* no symbol name */ @@ -1337,32 +1335,33 @@ static int elf_set_info(enum geninfo type, char **val) (void)val; return 0; } -static struct dfmt df_dwarf = { +static const struct dfmt df_dwarf = { "ELF32 (i386) dwarf debug format for Linux/Unix", "dwarf", - dwarf32_init, - dwarf32_linenum, - debug32_deflabel, - debug32_directive, - debug32_typevalue, - dwarf32_output, - dwarf32_cleanup + dwarf_init, + dwarf_linenum, + debug_deflabel, + debug_directive, + debug_typevalue, + dwarf_output, + dwarf_cleanup }; -static struct dfmt df_stabs = { +static const struct dfmt df_stabs = { "ELF32 (i386) stabs debug format for Linux/Unix", "stabs", null_debug_init, - stabs32_linenum, - debug32_deflabel, - debug32_directive, - debug32_typevalue, - stabs32_output, - stabs32_cleanup + stabs_linenum, + debug_deflabel, + debug_directive, + debug_typevalue, + stabs_output, + stabs_cleanup }; -struct dfmt *elf32_debugs_arr[3] = { &df_dwarf, &df_stabs, NULL }; +static const struct dfmt * const elf32_debugs_arr[3] = + { &df_dwarf, &df_stabs, NULL }; -struct ofmt of_elf32 = { +const struct ofmt of_elf32 = { "ELF32 (i386) object files (e.g. Linux)", "elf32", 0, @@ -1384,33 +1383,7 @@ struct ofmt of_elf32 = { /* again, the stabs debugging stuff (code) */ -static void stabs32_linenum(const char *filename, int32_t linenumber, - int32_t segto) -{ - (void)segto; - - if (!stabs_filename) { - stabs_filename = (char *)nasm_malloc(strlen(filename) + 1); - strcpy(stabs_filename, filename); - } else { - if (strcmp(stabs_filename, filename)) { - /* - * yep, a memory leak...this program is one-shot anyway, so who cares... - * in fact, this leak comes in quite handy to maintain a list of files - * encountered so far in the symbol lines... - */ - - /* why not nasm_free(stabs_filename); we're done with the old one */ - - stabs_filename = (char *)nasm_malloc(strlen(filename) + 1); - strcpy(stabs_filename, filename); - } - } - debug_immcall = 1; - currentline = linenumber; -} - -static void debug32_deflabel(char *name, int32_t segment, int64_t offset, int is_global, +static void debug_deflabel(char *name, int32_t segment, int64_t offset, int is_global, char *special) { (void)name; @@ -1420,13 +1393,13 @@ static void debug32_deflabel(char *name, int32_t segment, int64_t offset, int is (void)special; } -static void debug32_directive(const char *directive, const char *params) +static void debug_directive(const char *directive, const char *params) { (void)directive; (void)params; } -static void debug32_typevalue(int32_t type) +static void debug_typevalue(int32_t type) { int32_t stype, ssize; switch (TYM_TYPE(type)) { @@ -1493,7 +1466,34 @@ static void debug32_typevalue(int32_t type) } } -static void stabs32_output(int type, void *param) +/* stabs debugging routines */ + +static void stabs_linenum(const char *filename, int32_t linenumber, + int32_t segto) +{ + (void)segto; + + if (!stabs_filename) { + stabs_filename = (char *)nasm_malloc(strlen(filename) + 1); + strcpy(stabs_filename, filename); + } else { + if (strcmp(stabs_filename, filename)) { + /* yep, a memory leak...this program is one-shot anyway, so who cares... + in fact, this leak comes in quite handy to maintain a list of files + encountered so far in the symbol lines... */ + + + /* why not nasm_free(stabs_filename); we're done with the old one */ + + stabs_filename = (char *)nasm_malloc(strlen(filename) + 1); + strcpy(stabs_filename, filename); + } + } + debug_immcall = 1; + currentline = linenumber; +} + +static void stabs_output(int type, void *param) { struct symlininfo *s; struct linelist *el; @@ -1524,7 +1524,7 @@ static void stabs32_output(int type, void *param) /* for creating the .stab , .stabstr and .rel.stab sections in memory */ -static void stabs32_generate(void) +static void stabs_generate(void) { int i, numfiles, strsize, numstabs = 0, currfile, mainfileindex; uint8_t *sbuf, *ssbuf, *rbuf, *sptr, *rptr; @@ -1660,7 +1660,7 @@ static void stabs32_generate(void) stabstrbuf = ssbuf; } -static void stabs32_cleanup(void) +static void stabs_cleanup(void) { struct linelist *ptr, *del; if (!stabslines) @@ -1680,22 +1680,22 @@ static void stabs32_cleanup(void) /* dwarf routines */ -static void dwarf32_init(void) +static void dwarf_init(void) { ndebugs = 3; /* 3 debug symbols */ } -static void dwarf32_linenum(const char *filename, int32_t linenumber, +static void dwarf_linenum(const char *filename, int32_t linenumber, int32_t segto) { (void)segto; - dwarf32_findfile(filename); + dwarf_findfile(filename); debug_immcall = 1; currentline = linenumber; } /* called from elf_out with type == TY_DEBUGSYMLIN */ -static void dwarf32_output(int type, void *param) +static void dwarf_output(int type, void *param) { int ln, aa, inx, maxln, soc; struct symlininfo *s; @@ -1711,7 +1711,7 @@ static void dwarf32_output(int type, void *param) /* Check if section index has changed */ if (!(dwarf_csect && (dwarf_csect->section) == (s->section))) - dwarf32_findsect(s->section); + dwarf_findsect(s->section); /* do nothing unless line or file has changed */ if (!debug_immcall) @@ -1751,7 +1751,7 @@ static void dwarf32_output(int type, void *param) } -static void dwarf32_generate(void) +static void dwarf_generate(void) { uint8_t *pbuf; int indx; @@ -1984,7 +1984,7 @@ static void dwarf32_generate(void) WRITELONG(pbuf,0); /* null ending offset */ } -static void dwarf32_cleanup(void) +static void dwarf_cleanup(void) { nasm_free(arangesbuf); nasm_free(arangesrelbuf); @@ -1998,7 +1998,7 @@ static void dwarf32_cleanup(void) nasm_free(locbuf); } -static void dwarf32_findfile(const char * fname) +static void dwarf_findfile(const char * fname) { int finx; struct linelist *match; @@ -2035,7 +2035,7 @@ static void dwarf32_findfile(const char * fname) } } -static void dwarf32_findsect(const int index) +static void dwarf_findsect(const int index) { int sinx; struct sectlist *match; diff --git a/output/outelf64.c b/output/outelf64.c index f2a192a3..57be311b 100644 --- a/output/outelf64.c +++ b/output/outelf64.c @@ -82,7 +82,7 @@ static struct elf_symbol *fwds; static char elf_module[FILENAME_MAX]; -extern struct ofmt of_elf64; +extern const struct ofmt of_elf64; static struct ELF_SECTDATA { void *data; @@ -139,7 +139,6 @@ static int debug_immcall = 0; static struct linelist *stabslines = 0; static int numlinestabs = 0; static char *stabs_filename = 0; -static int symtabsection; static uint8_t *stabbuf = 0, *stabstrbuf = 0, *stabrelbuf = 0; static int stablen, stabstrlen, stabrellen; @@ -155,29 +154,29 @@ static int arangeslen, arangesrellen, pubnameslen, infolen, inforellen, static int64_t dwarf_infosym, dwarf_abbrevsym, dwarf_linesym; -static struct dfmt df_dwarf; -static struct dfmt df_stabs; +static const struct dfmt df_dwarf; +static const struct dfmt df_stabs; static struct elf_symbol *lastsym; /* common debugging routines */ -static void debug64_typevalue(int32_t); -static void debug64_deflabel(char *, int32_t, int64_t, int, char *); -static void debug64_directive(const char *, const char *); +static void debug_typevalue(int32_t); +static void debug_deflabel(char *, int32_t, int64_t, int, char *); +static void debug_directive(const char *, const char *); /* stabs debugging routines */ -static void stabs64_linenum(const char *filename, int32_t linenumber, int32_t); -static void stabs64_output(int, void *); -static void stabs64_generate(void); -static void stabs64_cleanup(void); +static void stabs_linenum(const char *filename, int32_t linenumber, int32_t); +static void stabs_output(int, void *); +static void stabs_generate(void); +static void stabs_cleanup(void); /* dwarf debugging routines */ -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); -static void dwarf64_cleanup(void); -static void dwarf64_findfile(const char *); -static void dwarf64_findsect(const int); +static void dwarf_init(void); +static void dwarf_linenum(const char *filename, int32_t linenumber, int32_t); +static void dwarf_output(int, void *); +static void dwarf_generate(void); +static void dwarf_cleanup(void); +static void dwarf_findfile(const char *); +static void dwarf_findsect(const int); /* * Special section numbers which are used to define ELF special @@ -246,8 +245,8 @@ static void elf_cleanup(int debuginfo) saa_free(syms); raa_free(bsym); saa_free(strs); - if (of_elf64.current_dfmt) { - of_elf64.current_dfmt->cleanup(); + if (dfmt) { + dfmt->cleanup(); } } @@ -388,7 +387,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, stdscan_reset(); stdscan_set(p); tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL); + e = evaluate(stdscan, NULL, &tokval, NULL, 1, NULL); if (e) { if (!is_simple(e)) nasm_error(ERR_NONFATAL, "cannot use relocatable" @@ -530,8 +529,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, stdscan_reset(); stdscan_set(special + n); tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, &fwd, 0, nasm_error, - NULL); + e = evaluate(stdscan, NULL, &tokval, &fwd, 0, NULL); if (fwd) { sym->nextfwd = fwds; fwds = sym; @@ -596,8 +594,8 @@ static void elf_add_reloc(struct elf_section *sect, int32_t segment, * _containing_ the symbol. Such relocations call to this routine, * which searches the symbol list for the symbol in question. * - * R_386_GOT32 references require the _exact_ symbol address to be - * used; R_386_32 references can be at an offset from the symbol. + * R_X86_64_GOT32 references require the _exact_ symbol address to be + * used; R_X86_64_32 references can be at an offset from the symbol. * The boolean argument `exact' tells us this. * * Return value is the adjusted value of `addr', having become an @@ -710,12 +708,12 @@ static void elf_out(int32_t segto, const void *data, } /* again some stabs debugging stuff */ - if (of_elf64.current_dfmt) { + if (dfmt) { sinfo.offset = s->len; sinfo.section = i; sinfo.segto = segto; sinfo.name = s->name; - of_elf64.current_dfmt->debug_output(TY_DEBUGSYMLIN, &sinfo); + dfmt->debug_output(TY_DEBUGSYMLIN, &sinfo); } /* end of debugging stuff */ @@ -978,9 +976,9 @@ static void elf_write(void) * relocation sections for the user sections. */ nsections = sec_numspecial + 1; - if (of_elf64.current_dfmt == &df_stabs) + if (dfmt == &df_stabs) nsections += 3; - else if (of_elf64.current_dfmt == &df_dwarf) + else if (dfmt == &df_dwarf) nsections += 10; add_sectname("", ".shstrtab"); @@ -994,14 +992,14 @@ static void elf_write(void) } } - if (of_elf64.current_dfmt == &df_stabs) { + if (dfmt == &df_stabs) { /* in case the debug information is wanted, just add these three sections... */ add_sectname("", ".stab"); add_sectname("", ".stabstr"); add_sectname(".rel", ".stab"); } - else if (of_elf64.current_dfmt == &df_dwarf) { + else if (dfmt == &df_dwarf) { /* the dwarf debug standard specifies the following ten sections, not all of which are currently implemented, although all of them are defined. */ @@ -1099,12 +1097,12 @@ static void elf_write(void) p += strlen(p) + 1; } - if (of_elf64.current_dfmt == &df_stabs) { + if (dfmt == &df_stabs) { /* for debugging information, create the last three sections which are the .stab , .stabstr and .rel.stab sections respectively */ /* this function call creates the stab sections in memory */ - stabs64_generate(); + stabs_generate(); if (stabbuf && stabstrbuf && stabrelbuf) { elf_section_header(p - shstrtab, SHT_PROGBITS, 0, stabbuf, false, @@ -1117,22 +1115,22 @@ static void elf_write(void) /* link -> symtable info -> section to refer to */ elf_section_header(p - shstrtab, SHT_REL, 0, stabrelbuf, false, - stabrellen, symtabsection, sec_stab, 4, 16); + stabrellen, sec_symtab, sec_stab, 4, 16); p += strlen(p) + 1; } - } else if (of_elf64.current_dfmt == &df_dwarf) { + } else if (dfmt == &df_dwarf) { /* for dwarf debugging information, create the ten dwarf sections */ /* this function call creates the dwarf sections in memory */ if (dwarf_fsect) - dwarf64_generate(); + dwarf_generate(); elf_section_header(p - shstrtab, SHT_PROGBITS, 0, arangesbuf, false, arangeslen, 0, 0, 1, 0); p += strlen(p) + 1; elf_section_header(p - shstrtab, SHT_RELA, 0, arangesrelbuf, false, - arangesrellen, symtabsection, debug_aranges, 1, 24); + arangesrellen, sec_symtab, debug_aranges, 1, 24); p += strlen(p) + 1; elf_section_header(p - shstrtab, SHT_PROGBITS, 0, pubnamesbuf, false, @@ -1144,7 +1142,7 @@ static void elf_write(void) p += strlen(p) + 1; elf_section_header(p - shstrtab, SHT_RELA, 0, inforelbuf, false, - inforellen, symtabsection, debug_info, 1, 24); + inforellen, sec_symtab, debug_info, 1, 24); p += strlen(p) + 1; elf_section_header(p - shstrtab, SHT_PROGBITS, 0, abbrevbuf, false, @@ -1156,7 +1154,7 @@ static void elf_write(void) p += strlen(p) + 1; elf_section_header(p - shstrtab, SHT_RELA, 0, linerelbuf, false, - linerellen, symtabsection, debug_line, 1, 24); + linerellen, sec_symtab, debug_line, 1, 24); p += strlen(p) + 1; elf_section_header(p - shstrtab, SHT_PROGBITS, 0, framebuf, false, @@ -1246,7 +1244,7 @@ static struct SAA *elf_build_symtab(int32_t *len, int32_t *local) * dwarf needs symbols for debug sections * which are relocation targets. */ - if (of_elf64.current_dfmt == &df_dwarf) { + if (dfmt == &df_dwarf) { dwarf_infosym = *local; p = entry; WRITELONG(p, 0); /* no symbol name */ @@ -1427,32 +1425,33 @@ static int elf_set_info(enum geninfo type, char **val) (void)val; return 0; } -static struct dfmt df_dwarf = { +static const struct dfmt df_dwarf = { "ELF64 (x86-64) dwarf debug format for Linux/Unix", "dwarf", - dwarf64_init, - dwarf64_linenum, - debug64_deflabel, - debug64_directive, - debug64_typevalue, - dwarf64_output, - dwarf64_cleanup + dwarf_init, + dwarf_linenum, + debug_deflabel, + debug_directive, + debug_typevalue, + dwarf_output, + dwarf_cleanup }; -static struct dfmt df_stabs = { +static const struct dfmt df_stabs = { "ELF64 (x86-64) stabs debug format for Linux/Unix", "stabs", null_debug_init, - stabs64_linenum, - debug64_deflabel, - debug64_directive, - debug64_typevalue, - stabs64_output, - stabs64_cleanup + stabs_linenum, + debug_deflabel, + debug_directive, + debug_typevalue, + stabs_output, + stabs_cleanup }; -struct dfmt *elf64_debugs_arr[3] = { &df_dwarf, &df_stabs, NULL }; +static const struct dfmt * const elf64_debugs_arr[3] = + { &df_dwarf, &df_stabs, NULL }; -struct ofmt of_elf64 = { +const struct ofmt of_elf64 = { "ELF64 (x86_64) object files (e.g. Linux)", "elf64", 0, @@ -1473,7 +1472,7 @@ struct ofmt of_elf64 = { }; /* common debugging routines */ -static void debug64_deflabel(char *name, int32_t segment, int64_t offset, +static void debug_deflabel(char *name, int32_t segment, int64_t offset, int is_global, char *special) { (void)name; @@ -1483,13 +1482,13 @@ static void debug64_deflabel(char *name, int32_t segment, int64_t offset, (void)special; } -static void debug64_directive(const char *directive, const char *params) +static void debug_directive(const char *directive, const char *params) { (void)directive; (void)params; } -static void debug64_typevalue(int32_t type) +static void debug_typevalue(int32_t type) { int32_t stype, ssize; switch (TYM_TYPE(type)) { @@ -1558,7 +1557,7 @@ static void debug64_typevalue(int32_t type) /* stabs debugging routines */ -static void stabs64_linenum(const char *filename, int32_t linenumber, int32_t segto) +static void stabs_linenum(const char *filename, int32_t linenumber, int32_t segto) { (void)segto; if (!stabs_filename) { @@ -1581,7 +1580,7 @@ static void stabs64_linenum(const char *filename, int32_t linenumber, int32_t se } -static void stabs64_output(int type, void *param) +static void stabs_output(int type, void *param) { struct symlininfo *s; struct linelist *el; @@ -1612,7 +1611,7 @@ static void stabs64_output(int type, void *param) /* for creating the .stab , .stabstr and .rel.stab sections in memory */ -static void stabs64_generate(void) +static void stabs_generate(void) { int i, numfiles, strsize, numstabs = 0, currfile, mainfileindex; uint8_t *sbuf, *ssbuf, *rbuf, *sptr, *rptr; @@ -1750,7 +1749,7 @@ static void stabs64_generate(void) stabstrbuf = ssbuf; } -static void stabs64_cleanup(void) +static void stabs_cleanup(void) { struct linelist *ptr, *del; if (!stabslines) @@ -1770,22 +1769,22 @@ static void stabs64_cleanup(void) /* dwarf routines */ -static void dwarf64_init(void) +static void dwarf_init(void) { ndebugs = 3; /* 3 debug symbols */ } -static void dwarf64_linenum(const char *filename, int32_t linenumber, +static void dwarf_linenum(const char *filename, int32_t linenumber, int32_t segto) { (void)segto; - dwarf64_findfile(filename); + dwarf_findfile(filename); debug_immcall = 1; currentline = linenumber; } /* called from elf_out with type == TY_DEBUGSYMLIN */ -static void dwarf64_output(int type, void *param) +static void dwarf_output(int type, void *param) { int ln, aa, inx, maxln, soc; struct symlininfo *s; @@ -1801,7 +1800,7 @@ static void dwarf64_output(int type, void *param) /* Check if section index has changed */ if (!(dwarf_csect && (dwarf_csect->section) == (s->section))) - dwarf64_findsect(s->section); + dwarf_findsect(s->section); /* do nothing unless line or file has changed */ if (!debug_immcall) @@ -1841,7 +1840,7 @@ static void dwarf64_output(int type, void *param) } -static void dwarf64_generate(void) +static void dwarf_generate(void) { uint8_t *pbuf; int indx; @@ -2076,7 +2075,7 @@ static void dwarf64_generate(void) WRITEDLONG(pbuf,0); /* null ending offset */ } -static void dwarf64_cleanup(void) +static void dwarf_cleanup(void) { nasm_free(arangesbuf); nasm_free(arangesrelbuf); @@ -2090,7 +2089,7 @@ static void dwarf64_cleanup(void) nasm_free(locbuf); } -static void dwarf64_findfile(const char * fname) +static void dwarf_findfile(const char * fname) { int finx; struct linelist *match; @@ -2127,7 +2126,7 @@ static void dwarf64_findfile(const char * fname) } } -static void dwarf64_findsect(const int index) +static void dwarf_findsect(const int index) { int sinx; struct sectlist *match; diff --git a/output/outelfx32.c b/output/outelfx32.c index c217c7be..5896af3b 100644 --- a/output/outelfx32.c +++ b/output/outelfx32.c @@ -82,7 +82,7 @@ static struct elf_symbol *fwds; static char elf_module[FILENAME_MAX]; -extern struct ofmt of_elfx32; +extern const struct ofmt of_elfx32; static struct ELF_SECTDATA { void *data; @@ -154,29 +154,29 @@ static int arangeslen, arangesrellen, pubnameslen, infolen, inforellen, static int32_t dwarf_infosym, dwarf_abbrevsym, dwarf_linesym; -static struct dfmt df_dwarf; -static struct dfmt df_stabs; +static const struct dfmt df_dwarf; +static const struct dfmt df_stabs; static struct elf_symbol *lastsym; /* common debugging routines */ -static void debugx32_typevalue(int32_t); -static void debugx32_deflabel(char *, int32_t, int64_t, int, char *); -static void debugx32_directive(const char *, const char *); +static void debug_typevalue(int32_t); +static void debug_deflabel(char *, int32_t, int64_t, int, char *); +static void debug_directive(const char *, const char *); /* stabs debugging routines */ -static void stabsx32_linenum(const char *filename, int32_t linenumber, int32_t); -static void stabsx32_output(int, void *); -static void stabsx32_generate(void); -static void stabsx32_cleanup(void); +static void stabs_linenum(const char *filename, int32_t linenumber, int32_t); +static void stabs_output(int, void *); +static void stabs_generate(void); +static void stabs_cleanup(void); /* dwarf debugging routines */ -static void dwarfx32_init(void); -static void dwarfx32_linenum(const char *filename, int32_t linenumber, int32_t); -static void dwarfx32_output(int, void *); -static void dwarfx32_generate(void); -static void dwarfx32_cleanup(void); -static void dwarfx32_findfile(const char *); -static void dwarfx32_findsect(const int); +static void dwarf_init(void); +static void dwarf_linenum(const char *filename, int32_t linenumber, int32_t); +static void dwarf_output(int, void *); +static void dwarf_generate(void); +static void dwarf_cleanup(void); +static void dwarf_findfile(const char *); +static void dwarf_findsect(const int); /* * Special section numbers which are used to define ELF special @@ -245,8 +245,8 @@ static void elf_cleanup(int debuginfo) saa_free(syms); raa_free(bsym); saa_free(strs); - if (of_elfx32.current_dfmt) { - of_elfx32.current_dfmt->cleanup(); + if (dfmt) { + dfmt->cleanup(); } } @@ -387,7 +387,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, stdscan_reset(); stdscan_set(p); tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL); + e = evaluate(stdscan, NULL, &tokval, NULL, 1, NULL); if (e) { if (!is_simple(e)) nasm_error(ERR_NONFATAL, "cannot use relocatable" @@ -529,8 +529,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, stdscan_reset(); stdscan_set(special + n); tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, &fwd, 0, nasm_error, - NULL); + e = evaluate(stdscan, NULL, &tokval, &fwd, 0, NULL); if (fwd) { sym->nextfwd = fwds; fwds = sym; @@ -709,12 +708,12 @@ static void elf_out(int32_t segto, const void *data, } /* again some stabs debugging stuff */ - if (of_elfx32.current_dfmt) { + if (dfmt) { sinfo.offset = s->len; sinfo.section = i; sinfo.segto = segto; sinfo.name = s->name; - of_elfx32.current_dfmt->debug_output(TY_DEBUGSYMLIN, &sinfo); + dfmt->debug_output(TY_DEBUGSYMLIN, &sinfo); } /* end of debugging stuff */ @@ -940,9 +939,9 @@ static void elf_write(void) * relocation sections for the user sections. */ nsections = sec_numspecial + 1; - if (of_elfx32.current_dfmt == &df_stabs) + if (dfmt == &df_stabs) nsections += 3; - else if (of_elfx32.current_dfmt == &df_dwarf) + else if (dfmt == &df_dwarf) nsections += 10; add_sectname("", ".shstrtab"); @@ -956,14 +955,14 @@ static void elf_write(void) } } - if (of_elfx32.current_dfmt == &df_stabs) { + if (dfmt == &df_stabs) { /* in case the debug information is wanted, just add these three sections... */ add_sectname("", ".stab"); add_sectname("", ".stabstr"); add_sectname(".rel", ".stab"); } - else if (of_elfx32.current_dfmt == &df_dwarf) { + else if (dfmt == &df_dwarf) { /* the dwarf debug standard specifies the following ten sections, not all of which are currently implemented, although all of them are defined. */ @@ -1060,12 +1059,12 @@ static void elf_write(void) p += strlen(p) + 1; } - if (of_elfx32.current_dfmt == &df_stabs) { + if (dfmt == &df_stabs) { /* for debugging information, create the last three sections which are the .stab , .stabstr and .rel.stab sections respectively */ /* this function call creates the stab sections in memory */ - stabsx32_generate(); + stabs_generate(); if (stabbuf && stabstrbuf && stabrelbuf) { elf_section_header(p - shstrtab, SHT_PROGBITS, 0, stabbuf, false, @@ -1081,12 +1080,12 @@ static void elf_write(void) stabrellen, sec_symtab, sec_stab, 4, 8); p += strlen(p) + 1; } - } else if (of_elfx32.current_dfmt == &df_dwarf) { + } else if (dfmt == &df_dwarf) { /* for dwarf debugging information, create the ten dwarf sections */ /* this function call creates the dwarf sections in memory */ if (dwarf_fsect) - dwarfx32_generate(); + dwarf_generate(); elf_section_header(p - shstrtab, SHT_PROGBITS, 0, arangesbuf, false, arangeslen, 0, 0, 1, 0); @@ -1207,7 +1206,7 @@ static struct SAA *elf_build_symtab(int32_t *len, int32_t *local) * dwarf needs symbols for debug sections * which are relocation targets. */ - if (of_elfx32.current_dfmt == &df_dwarf) { + if (dfmt == &df_dwarf) { dwarf_infosym = *local; p = entry; WRITELONG(p, 0); /* no symbol name */ @@ -1386,32 +1385,33 @@ static int elf_set_info(enum geninfo type, char **val) (void)val; return 0; } -static struct dfmt df_dwarf = { +static const struct dfmt df_dwarf = { "ELFX32 (x86-64) dwarf debug format for Linux/Unix", "dwarf", - dwarfx32_init, - dwarfx32_linenum, - debugx32_deflabel, - debugx32_directive, - debugx32_typevalue, - dwarfx32_output, - dwarfx32_cleanup + dwarf_init, + dwarf_linenum, + debug_deflabel, + debug_directive, + debug_typevalue, + dwarf_output, + dwarf_cleanup }; -static struct dfmt df_stabs = { +static const struct dfmt df_stabs = { "ELFX32 (x86-64) stabs debug format for Linux/Unix", "stabs", null_debug_init, - stabsx32_linenum, - debugx32_deflabel, - debugx32_directive, - debugx32_typevalue, - stabsx32_output, - stabsx32_cleanup + stabs_linenum, + debug_deflabel, + debug_directive, + debug_typevalue, + stabs_output, + stabs_cleanup }; -struct dfmt *elfx32_debugs_arr[3] = { &df_dwarf, &df_stabs, NULL }; +static const struct dfmt * const elfx32_debugs_arr[3] = + { &df_dwarf, &df_stabs, NULL }; -struct ofmt of_elfx32 = { +const struct ofmt of_elfx32 = { "ELFX32 (x86_64) object files (e.g. Linux)", "elfx32", 0, @@ -1432,7 +1432,7 @@ struct ofmt of_elfx32 = { }; /* common debugging routines */ -static void debugx32_deflabel(char *name, int32_t segment, int64_t offset, +static void debug_deflabel(char *name, int32_t segment, int64_t offset, int is_global, char *special) { (void)name; @@ -1442,13 +1442,13 @@ static void debugx32_deflabel(char *name, int32_t segment, int64_t offset, (void)special; } -static void debugx32_directive(const char *directive, const char *params) +static void debug_directive(const char *directive, const char *params) { (void)directive; (void)params; } -static void debugx32_typevalue(int32_t type) +static void debug_typevalue(int32_t type) { int32_t stype, ssize; switch (TYM_TYPE(type)) { @@ -1517,7 +1517,7 @@ static void debugx32_typevalue(int32_t type) /* stabs debugging routines */ -static void stabsx32_linenum(const char *filename, int32_t linenumber, int32_t segto) +static void stabs_linenum(const char *filename, int32_t linenumber, int32_t segto) { (void)segto; if (!stabs_filename) { @@ -1540,7 +1540,7 @@ static void stabsx32_linenum(const char *filename, int32_t linenumber, int32_t s } -static void stabsx32_output(int type, void *param) +static void stabs_output(int type, void *param) { struct symlininfo *s; struct linelist *el; @@ -1571,7 +1571,7 @@ static void stabsx32_output(int type, void *param) /* for creating the .stab , .stabstr and .rel.stab sections in memory */ -static void stabsx32_generate(void) +static void stabs_generate(void) { int i, numfiles, strsize, numstabs = 0, currfile, mainfileindex; uint8_t *sbuf, *ssbuf, *rbuf, *sptr, *rptr; @@ -1706,7 +1706,7 @@ static void stabsx32_generate(void) stabstrbuf = ssbuf; } -static void stabsx32_cleanup(void) +static void stabs_cleanup(void) { struct linelist *ptr, *del; if (!stabslines) @@ -1726,22 +1726,22 @@ static void stabsx32_cleanup(void) /* dwarf routines */ -static void dwarfx32_init(void) +static void dwarf_init(void) { ndebugs = 3; /* 3 debug symbols */ } -static void dwarfx32_linenum(const char *filename, int32_t linenumber, +static void dwarf_linenum(const char *filename, int32_t linenumber, int32_t segto) { (void)segto; - dwarfx32_findfile(filename); + dwarf_findfile(filename); debug_immcall = 1; currentline = linenumber; } /* called from elf_out with type == TY_DEBUGSYMLIN */ -static void dwarfx32_output(int type, void *param) +static void dwarf_output(int type, void *param) { int ln, aa, inx, maxln, soc; struct symlininfo *s; @@ -1757,7 +1757,7 @@ static void dwarfx32_output(int type, void *param) /* Check if section index has changed */ if (!(dwarf_csect && (dwarf_csect->section) == (s->section))) - dwarfx32_findsect(s->section); + dwarf_findsect(s->section); /* do nothing unless line or file has changed */ if (!debug_immcall) @@ -1797,7 +1797,7 @@ static void dwarfx32_output(int type, void *param) } -static void dwarfx32_generate(void) +static void dwarf_generate(void) { uint8_t *pbuf; int indx; @@ -2032,7 +2032,7 @@ static void dwarfx32_generate(void) WRITELONG(pbuf,0); /* null ending offset */ } -static void dwarfx32_cleanup(void) +static void dwarf_cleanup(void) { nasm_free(arangesbuf); nasm_free(arangesrelbuf); @@ -2046,7 +2046,7 @@ static void dwarfx32_cleanup(void) nasm_free(locbuf); } -static void dwarfx32_findfile(const char * fname) +static void dwarf_findfile(const char * fname) { int finx; struct linelist *match; @@ -2083,7 +2083,7 @@ static void dwarfx32_findfile(const char * fname) } } -static void dwarfx32_findsect(const int index) +static void dwarf_findsect(const int index) { int sinx; struct sectlist *match; diff --git a/output/outform.c b/output/outform.c index 0c8ae53b..f7c817e7 100644 --- a/output/outform.c +++ b/output/outform.c @@ -47,9 +47,11 @@ #define BUILD_DRIVERS_ARRAY #include "output/outform.h" -struct ofmt *ofmt_find(char *name, struct ofmt_alias **ofmt_alias) +const struct ofmt *ofmt_find(const char *name, + const struct ofmt_alias **ofmt_alias) { - struct ofmt **ofp, *of; + const struct ofmt * const *ofp; + const struct ofmt *of; unsigned int i; *ofmt_alias = NULL; @@ -72,9 +74,10 @@ struct ofmt *ofmt_find(char *name, struct ofmt_alias **ofmt_alias) return NULL; } -struct dfmt *dfmt_find(struct ofmt *ofmt, char *name) +const struct dfmt *dfmt_find(const struct ofmt *ofmt, const char *name) { - struct dfmt **dfp, *df; + const struct dfmt * const *dfp; + const struct dfmt *df; for (dfp = ofmt->debug_formats; (df = *dfp); dfp++) { if (!nasm_stricmp(name, df->shortname)) @@ -83,9 +86,9 @@ struct dfmt *dfmt_find(struct ofmt *ofmt, char *name) return NULL; } -void ofmt_list(struct ofmt *deffmt, FILE * fp) +void ofmt_list(const struct ofmt *deffmt, FILE * fp) { - struct ofmt **ofp, *of; + const struct ofmt * const *ofp, *of; unsigned int i; /* primary targets first */ @@ -105,13 +108,14 @@ void ofmt_list(struct ofmt *deffmt, FILE * fp) } } -void dfmt_list(struct ofmt *ofmt, FILE *fp) +void dfmt_list(const struct ofmt *ofmt, FILE *fp) { - struct dfmt **dfp, *df; + const struct dfmt * const *dfp; + const struct dfmt *df; for (dfp = ofmt->debug_formats; (df = *dfp); dfp++) { fprintf(fp, " %c %-10s%s\n", - df == ofmt->current_dfmt ? '*' : ' ', + df == dfmt ? '*' : ' ', df->shortname, df->fullname); } } diff --git a/output/outform.h b/output/outform.h index d37a61b4..d2dfef5f 100644 --- a/output/outform.h +++ b/output/outform.h @@ -262,24 +262,24 @@ #define OF_DEFAULT of_bin #endif -extern struct ofmt of_bin; -extern struct ofmt of_ith; -extern struct ofmt of_srec; -extern struct ofmt of_aout; -extern struct ofmt of_aoutb; -extern struct ofmt of_coff; -extern struct ofmt of_elf32; -extern struct ofmt of_elfx32; -extern struct ofmt of_elf64; -extern struct ofmt of_as86; -extern struct ofmt of_obj; -extern struct ofmt of_win32; -extern struct ofmt of_win64; -extern struct ofmt of_rdf2; -extern struct ofmt of_ieee; -extern struct ofmt of_macho32; -extern struct ofmt of_macho64; -extern struct ofmt of_dbg; +extern const struct ofmt of_bin; +extern const struct ofmt of_ith; +extern const struct ofmt of_srec; +extern const struct ofmt of_aout; +extern const struct ofmt of_aoutb; +extern const struct ofmt of_coff; +extern const struct ofmt of_elf32; +extern const struct ofmt of_elfx32; +extern const struct ofmt of_elf64; +extern const struct ofmt of_as86; +extern const struct ofmt of_obj; +extern const struct ofmt of_win32; +extern const struct ofmt of_win64; +extern const struct ofmt of_rdf2; +extern const struct ofmt of_ieee; +extern const struct ofmt of_macho32; +extern const struct ofmt of_macho64; +extern const struct ofmt of_dbg; #ifdef BUILD_DRIVERS_ARRAY /* only if included from outform.c */ @@ -288,7 +288,7 @@ extern struct ofmt of_dbg; * drivers array based on the above defines */ -static struct ofmt *drivers[] = { +static const struct ofmt * const drivers[] = { #ifdef OF_BIN &of_bin, &of_ith, @@ -343,7 +343,7 @@ static struct ofmt *drivers[] = { NULL }; -static struct ofmt_alias ofmt_aliases[] = { +static const struct ofmt_alias ofmt_aliases[] = { #ifdef OF_ELF32 { "elf", @@ -370,11 +370,10 @@ static struct ofmt_alias ofmt_aliases[] = { #endif /* BUILD_DRIVERS_ARRAY */ -struct ofmt *ofmt_find(char *name, struct ofmt_alias **ofmt_alias); -struct dfmt *dfmt_find(struct ofmt *, char *); -void ofmt_list(struct ofmt *, FILE *); -void dfmt_list(struct ofmt *ofmt, FILE * fp); -struct ofmt *ofmt_register(efunc error); +const struct ofmt *ofmt_find(const char *name, const struct ofmt_alias **ofmt_alias); +const struct dfmt *dfmt_find(const struct ofmt *, const char *); +void ofmt_list(const struct ofmt *, FILE *); +void dfmt_list(const struct ofmt *ofmt, FILE * fp); extern struct dfmt null_debug_form; #endif /* NASM_OUTFORM_H */ diff --git a/output/outieee.c b/output/outieee.c index 42f0fb66..05624657 100644 --- a/output/outieee.c +++ b/output/outieee.c @@ -184,7 +184,7 @@ struct ieeeFixupp { static int32_t ieee_entry_seg, ieee_entry_ofs; static int checksum; -extern struct ofmt of_ieee; +extern const struct ofmt of_ieee; static void ieee_data_new(struct ieeeSection *); static void ieee_write_fixup(int32_t, int32_t, struct ieeeSection *, @@ -235,7 +235,7 @@ static int ieee_set_info(enum geninfo type, char **val) static void ieee_cleanup(int debuginfo) { ieee_write_file(debuginfo); - of_ieee.current_dfmt->cleanup(); + dfmt->cleanup(); while (seghead) { struct ieeeSection *segtmp = seghead; seghead = seghead->next; @@ -1497,7 +1497,7 @@ static void dbgls_output(int output_type, void *param) (void)output_type; (void)param; } -static struct dfmt ladsoft_debug_form = { +static const struct dfmt ladsoft_debug_form = { "LADsoft Debug Records", "ladsoft", dbgls_init, @@ -1508,12 +1508,12 @@ static struct dfmt ladsoft_debug_form = { dbgls_output, dbgls_cleanup, }; -static struct dfmt *ladsoft_debug_arr[3] = { +static const struct dfmt * const ladsoft_debug_arr[3] = { &ladsoft_debug_form, &null_debug_form, NULL }; -struct ofmt of_ieee = { +const struct ofmt of_ieee = { "IEEE-695 (LADsoft variant) object file format", "ieee", OFMT_TEXT, diff --git a/output/outlib.h b/output/outlib.h index 29c27a09..c66dbf6b 100644 --- a/output/outlib.h +++ b/output/outlib.h @@ -44,7 +44,6 @@ int null_directive(enum directives directive, char *value, int pass); void null_sectalign(int32_t seg, unsigned int value); /* Do-nothing versions of all the debug routines */ -struct ofmt; void null_debug_init(void); void null_debug_linenum(const char *filename, int32_t linenumber, int32_t segto); @@ -54,7 +53,7 @@ void null_debug_directive(const char *directive, const char *params); void null_debug_typevalue(int32_t type); void null_debug_output(int type, void *param); void null_debug_cleanup(void); -extern struct dfmt *null_debug_arr[2]; +extern const struct dfmt * const null_debug_arr[2]; #endif /* NASM_OUTLIB_H */ diff --git a/output/outmacho.c b/output/outmacho.c index 881a4ae2..56b53d47 100644 --- a/output/outmacho.c +++ b/output/outmacho.c @@ -1643,7 +1643,7 @@ static void macho32_init(void) macho_gotpcrel_sect = NO_SEG; } -struct ofmt of_macho32 = { +const struct ofmt of_macho32 = { "NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (i386) object files", "macho32", 0, @@ -1690,7 +1690,7 @@ static void macho64_init(void) define_label("..gotpcrel", macho_gotpcrel_sect, 0L, NULL, false, false); } -struct ofmt of_macho64 = { +const struct ofmt of_macho64 = { "NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (x86_64) object files", "macho64", 0, diff --git a/output/outobj.c b/output/outobj.c index ff03664c..433fc2a2 100644 --- a/output/outobj.c +++ b/output/outobj.c @@ -624,7 +624,7 @@ static struct ExpDef { static int32_t obj_entry_seg, obj_entry_ofs; -struct ofmt of_obj; +const struct ofmt of_obj; /* The current segment */ static struct Segment *current_seg; @@ -670,7 +670,7 @@ static int obj_set_info(enum geninfo type, char **val) static void obj_cleanup(int debuginfo) { obj_write_file(debuginfo); - of_obj.current_dfmt->cleanup(); + dfmt->cleanup(); while (seghead) { struct Segment *segtmp = seghead; seghead = seghead->next; @@ -969,7 +969,7 @@ static void obj_deflabel(char *name, int32_t segment, stdscan_reset(); stdscan_set(special); tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL); + e = evaluate(stdscan, NULL, &tokval, NULL, 1, NULL); if (e) { if (!is_simple(e)) nasm_error(ERR_NONFATAL, "cannot use relocatable" @@ -2605,7 +2605,7 @@ static void dbgbi_output(int output_type, void *param) (void)output_type; (void)param; } -static struct dfmt borland_debug_form = { +static const struct dfmt borland_debug_form = { "Borland Debug Records", "borland", dbgbi_init, @@ -2617,13 +2617,13 @@ static struct dfmt borland_debug_form = { dbgbi_cleanup, }; -static struct dfmt *borland_debug_arr[3] = { +static const struct dfmt * const borland_debug_arr[3] = { &borland_debug_form, &null_debug_form, NULL }; -struct ofmt of_obj = { +const struct ofmt of_obj = { "MS-DOS 16-bit/32-bit OMF object files", "obj", 0, diff --git a/output/outrdf2.c b/output/outrdf2.c index 4dcae83c..235d7139 100644 --- a/output/outrdf2.c +++ b/output/outrdf2.c @@ -775,7 +775,7 @@ static int rdf2_set_info(enum geninfo type, char **val) return 0; } -struct ofmt of_rdf2 = { +const struct ofmt of_rdf2 = { "Relocatable Dynamic Object File Format v2.0", "rdf", 0, @@ -61,12 +61,6 @@ static int is_comma_next(void); static int i; static struct tokenval tokval; -static struct location *location; /* Pointer to current line's segment,offset */ - -void parser_global_info(struct location * locp) -{ - location = locp; -} static int prefix_slot(int prefix) { @@ -431,14 +425,14 @@ restart_parse: } if (i != TOKEN_INSN || tokval.t_integer != I_EQU) { /* - * FIXME: location->segment could be NO_SEG, in which case + * FIXME: location.segment could be NO_SEG, in which case * it is possible we should be passing 'abs_seg'. Look into this. * Work out whether that is *really* what we should be doing. * Generally fix things. I think this is right as it is, but * am still not certain. */ - ldef(result->label, in_abs_seg ? abs_seg : location->segment, - location->offset, NULL, true, false); + ldef(result->label, in_abs_seg ? abs_seg : location.segment, + location.offset, NULL, true, false); } } @@ -461,7 +455,7 @@ restart_parse: expr *value; i = stdscan(NULL, &tokval); - value = evaluate(stdscan, NULL, &tokval, NULL, pass0, nasm_error, NULL); + value = evaluate(stdscan, NULL, &tokval, NULL, pass0, NULL); i = tokval.t_type; if (!value) /* Error in evaluator */ goto fail; @@ -646,8 +640,7 @@ is_float: eop->stringval = (char *)eop + sizeof(extop); if (!eop->stringlen || !float_const(tokval.t_charptr, sign, - (uint8_t *)eop->stringval, - eop->stringlen, nasm_error)) + (uint8_t *)eop->stringval, eop->stringlen)) eop->type = EOT_NOTHING; i = stdscan(NULL, &tokval); /* eat the comma */ } else { @@ -656,7 +649,7 @@ is_float: is_expression: value = evaluate(stdscan, NULL, &tokval, NULL, - critical, nasm_error, NULL); + critical, NULL); i = tokval.t_type; if (!value) /* Error in evaluator */ goto fail; @@ -845,8 +838,7 @@ is_expression: } value = evaluate(stdscan, NULL, &tokval, - &op->opflags, - critical, nasm_error, &hints); + &op->opflags, critical, &hints); i = tokval.t_type; if (op->opflags & OPFLAG_FORWARD) { result->forw_ref = true; @@ -876,8 +868,7 @@ is_expression: i = stdscan(NULL, &tokval); } value = evaluate(stdscan, NULL, &tokval, - &op->opflags, - critical, nasm_error, &hints); + &op->opflags, critical, &hints); i = tokval.t_type; if (op->opflags & OPFLAG_FORWARD) { result->forw_ref = true; @@ -898,7 +889,7 @@ is_expression: i = stdscan(NULL, &tokval); /* Eat comma */ value = evaluate(stdscan, NULL, &tokval, &op->opflags, - critical, nasm_error, &hints); + critical, &hints); i = tokval.t_type; if (!value) goto fail; @@ -39,7 +39,6 @@ #ifndef NASM_PARSER_H #define NASM_PARSER_H -void parser_global_info(struct location *locp); insn *parse_line(int pass, char *buffer, insn *result, ldfunc ldef); void cleanup_insn(insn *instruction); diff --git a/preproc-nop.c b/preproc-nop.c index b43bd809..c5835ea9 100644 --- a/preproc-nop.c +++ b/preproc-nop.c @@ -51,14 +51,14 @@ #include "nasm.h" #include "nasmlib.h" #include "preproc.h" +#include "listing.h" #define BUF_DELTA 512 static FILE *nop_fp; -static ListGen *nop_list; static int32_t nop_lineinc; -static void nop_reset(char *file, int pass, ListGen *listgen, StrList **deplist) +static void nop_reset(char *file, int pass, StrList **deplist) { src_set_fname(nasm_strdup(file)); src_set_linnum(0); @@ -66,9 +66,7 @@ static void nop_reset(char *file, int pass, ListGen *listgen, StrList **deplist) nop_fp = fopen(file, "r"); if (!nop_fp) - nasm_error(ERR_FATAL | ERR_NOFILE, - "unable to open input file `%s'", file); - nop_list = listgen; + nasm_fatal(ERR_NOFILE, "unable to open input file `%s'", file); (void)pass; /* placate compilers */ if (deplist) { @@ -133,7 +131,7 @@ static char *nop_getline(void) break; } - nop_list->line(LIST_READ, buffer); + lfmt->line(LIST_READ, buffer); return buffer; } @@ -172,7 +170,7 @@ static void nop_include_path(char *path) (void)path; } -struct preproc_ops preproc_nop = { +const struct preproc_ops preproc_nop = { nop_reset, nop_getline, nop_cleanup, @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2014 The NASM Authors - All Rights Reserved + * Copyright 1996-2016 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * @@ -80,6 +80,7 @@ #include "eval.h" #include "tokens.h" #include "tables.h" +#include "listing.h" typedef struct SMacro SMacro; typedef struct MMacro MMacro; @@ -402,8 +403,6 @@ static uint64_t unique; /* unique identifier numbers */ static Line *predef = NULL; static bool do_predef; -static ListGen *list; - /* * The current set of multi-line macros we have defined. */ @@ -461,8 +460,8 @@ static Token *expand_smacro(Token * tline); static Token *expand_id(Token * tline); static Context *get_ctx(const char *name, const char **namep); static void make_tok_num(Token * tok, int64_t val); -static void error(int severity, const char *fmt, ...); -static void error_precond(int severity, const char *fmt, ...); +static void pp_verror(int severity, const char *fmt, va_list ap); +static vefunc real_verror; static void *new_Block(size_t size); static void delete_Blocks(void); static Token *new_Token(Token * next, enum pp_token_type type, @@ -488,7 +487,7 @@ static size_t nasm_unquote_cstr(char *qstr, enum preproc_token directive) size_t clen = strlen(qstr); if (len != clen) - error(ERR_NONFATAL, "NUL character in `%s' directive", + nasm_error(ERR_NONFATAL, "NUL character in `%s' directive", pp_directives[directive]); return clen; @@ -880,7 +879,7 @@ static char *read_line(void) */ buffer[strcspn(buffer, "\032")] = '\0'; - list->line(LIST_READ, buffer); + lfmt->line(LIST_READ, buffer); return buffer; } @@ -920,7 +919,8 @@ static Token *tokenize(char *line) p++; } if (*p != '}') - error(ERR_WARNING | ERR_PASS1, "unterminated %{ construct"); + nasm_error(ERR_WARNING | ERR_PASS1, + "unterminated %%{ construct"); p[-1] = '\0'; if (*p) p++; @@ -951,7 +951,8 @@ static Token *tokenize(char *line) if (*p) *p++ = '\0'; if (lvl) - error(ERR_NONFATAL, "unterminated %[ construct"); + nasm_error(ERR_NONFATAL|ERR_PASS1, + "unterminated %%[ construct"); type = TOK_INDIRECT; } else if (*p == '?') { type = TOK_PREPROC_Q; /* %? */ @@ -973,7 +974,8 @@ static Token *tokenize(char *line) if (*p) p++; else - error(ERR_NONFATAL|ERR_PASS1, "unterminated %! string"); + nasm_error(ERR_NONFATAL|ERR_PASS1, + "unterminated %%! string"); } else { /* %! without string or identifier */ type = TOK_OTHER; /* Legacy behavior... */ @@ -1006,7 +1008,7 @@ static Token *tokenize(char *line) if (*p) { p++; } else { - error(ERR_WARNING|ERR_PASS1, "unterminated string"); + nasm_error(ERR_WARNING|ERR_PASS1, "unterminated string"); /* Handling unterminated strings by UNV */ /* type = -1; */ } @@ -1253,8 +1255,8 @@ static char *detoken(Token * tlist, bool expand_locals) size_t clen = strlen(v); if (len != clen) { - error(ERR_NONFATAL | ERR_PASS1, - "NUL character in %! string"); + nasm_error(ERR_NONFATAL | ERR_PASS1, + "NUL character in %%! string"); v = NULL; } } @@ -1262,7 +1264,7 @@ static char *detoken(Token * tlist, bool expand_locals) if (v) { char *p = getenv(v); if (!p) { - error(ERR_NONFATAL | ERR_PASS1, + nasm_error(ERR_NONFATAL | ERR_PASS1, "nonexistent environment variable `%s'", v); p = ""; } @@ -1458,7 +1460,7 @@ static Context *get_ctx(const char *name, const char **namep) return NULL; if (!cstk) { - error(ERR_NONFATAL, "`%s': context stack is empty", name); + nasm_error(ERR_NONFATAL, "`%s': context stack is empty", name); return NULL; } @@ -1471,7 +1473,7 @@ static Context *get_ctx(const char *name, const char **namep) ctx = ctx->next; } if (!ctx) { - error(ERR_NONFATAL, "`%s': context stack is only" + nasm_error(ERR_NONFATAL, "`%s': context stack is only" " %d level%s deep", name, i, (i == 1 ? "" : "s")); return NULL; } @@ -1549,7 +1551,7 @@ static FILE *inc_fopen(const char *file, StrList **dhead, StrList ***dtail, } } - error(ERR_FATAL, "unable to open include file `%s'", file); + nasm_error(ERR_FATAL, "unable to open include file `%s'", file); return NULL; } @@ -1650,7 +1652,7 @@ static void count_mmac_params(Token * t, int *nparam, Token *** params) t = t->next; skip_white_(t); if (tok_isnt_(t, ",")) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "braces do not enclose all of macro parameter"); while (tok_isnt_(t, ",")) t = t->next; @@ -1692,7 +1694,7 @@ static bool if_condition(Token * tline, enum preproc_token ct) if (!tline) break; if (tline->type != TOK_ID) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%s' expects context identifiers", pp_directives[ct]); free_tlist(origline); return -1; @@ -1710,7 +1712,7 @@ static bool if_condition(Token * tline, enum preproc_token ct) if (!tline || (tline->type != TOK_ID && (tline->type != TOK_PREPROC_ID || tline->text[1] != '$'))) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%s' expects macro identifiers", pp_directives[ct]); goto fail; } @@ -1729,7 +1731,7 @@ static bool if_condition(Token * tline, enum preproc_token ct) tline->type != TOK_STRING && (tline->type != TOK_PREPROC_ID || tline->text[1] != '!'))) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%s' expects environment variable names", pp_directives[ct]); goto fail; @@ -1752,7 +1754,7 @@ static bool if_condition(Token * tline, enum preproc_token ct) while (tok_isnt_(tt, ",")) tt = tt->next; if (!tt) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%s' expects two comma-separated arguments", pp_directives[ct]); goto fail; @@ -1761,7 +1763,7 @@ static bool if_condition(Token * tline, enum preproc_token ct) j = true; /* assume equality unless proved not */ while ((t->type != TOK_OTHER || strcmp(t->text, ",")) && tt) { if (tt->type == TOK_OTHER && !strcmp(tt->text, ",")) { - error(ERR_NONFATAL, "`%s': more than one comma on line", + nasm_error(ERR_NONFATAL, "`%s': more than one comma on line", pp_directives[ct]); goto fail; } @@ -1810,7 +1812,7 @@ static bool if_condition(Token * tline, enum preproc_token ct) skip_white_(tline); tline = expand_id(tline); if (!tok_type_(tline, TOK_ID)) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%s' expects a macro name", pp_directives[ct]); goto fail; } @@ -1827,14 +1829,14 @@ static bool if_condition(Token * tline, enum preproc_token ct) skip_white_(tline); if (!tline) { } else if (!tok_type_(tline, TOK_NUMBER)) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%s' expects a parameter count or nothing", pp_directives[ct]); } else { searching.nparam_min = searching.nparam_max = readnum(tline->text, &j); if (j) - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "unable to parse parameter count `%s'", tline->text); } @@ -1843,17 +1845,17 @@ static bool if_condition(Token * tline, enum preproc_token ct) if (tok_is_(tline, "*")) searching.nparam_max = INT_MAX; else if (!tok_type_(tline, TOK_NUMBER)) - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%s' expects a parameter count after `-'", pp_directives[ct]); else { searching.nparam_max = readnum(tline->text, &j); if (j) - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "unable to parse parameter count `%s'", tline->text); if (searching.nparam_min > searching.nparam_max) - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "minimum parameter count exceeds maximum"); } } @@ -1874,7 +1876,7 @@ static bool if_condition(Token * tline, enum preproc_token ct) mmac = mmac->next; } if (tline && tline->next) - error(ERR_WARNING|ERR_PASS1, + nasm_error(ERR_WARNING|ERR_PASS1, "trailing garbage after %%ifmacro ignored"); nasm_free(searching.name); j = found; @@ -1931,14 +1933,14 @@ iftype: tptr = &t; tokval.t_type = TOKEN_INVALID; evalresult = evaluate(ppscan, tptr, &tokval, - NULL, pass | CRITICAL, error, NULL); + NULL, pass | CRITICAL, NULL); if (!evalresult) return -1; if (tokval.t_type) - error(ERR_WARNING|ERR_PASS1, + nasm_error(ERR_WARNING|ERR_PASS1, "trailing garbage after expression ignored"); if (!is_simple(evalresult)) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "non-constant value given to `%s'", pp_directives[ct]); goto fail; } @@ -1946,7 +1948,7 @@ iftype: break; default: - error(ERR_FATAL, + nasm_error(ERR_FATAL, "preprocessor directive `%s' not yet implemented", pp_directives[ct]); goto fail; @@ -1971,7 +1973,7 @@ static bool define_smacro(Context *ctx, const char *mname, bool casesense, if (smacro_defined(ctx, mname, nparam, &smac, casesense)) { if (!smac) { - error(ERR_WARNING|ERR_PASS1, + nasm_error(ERR_WARNING|ERR_PASS1, "single-line macro `%s' defined both with and" " without parameters", mname); /* @@ -2044,7 +2046,7 @@ static bool parse_mmacro_spec(Token *tline, MMacro *def, const char *directive) skip_white_(tline); tline = expand_id(tline); if (!tok_type_(tline, TOK_ID)) { - error(ERR_NONFATAL, "`%s' expects a macro name", directive); + nasm_error(ERR_NONFATAL, "`%s' expects a macro name", directive); return false; } @@ -2060,12 +2062,12 @@ static bool parse_mmacro_spec(Token *tline, MMacro *def, const char *directive) tline = expand_smacro(tline->next); skip_white_(tline); if (!tok_type_(tline, TOK_NUMBER)) { - error(ERR_NONFATAL, "`%s' expects a parameter count", directive); + nasm_error(ERR_NONFATAL, "`%s' expects a parameter count", directive); } else { def->nparam_min = def->nparam_max = readnum(tline->text, &err); if (err) - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "unable to parse parameter count `%s'", tline->text); } if (tline && tok_is_(tline->next, "-")) { @@ -2073,16 +2075,16 @@ static bool parse_mmacro_spec(Token *tline, MMacro *def, const char *directive) if (tok_is_(tline, "*")) { def->nparam_max = INT_MAX; } else if (!tok_type_(tline, TOK_NUMBER)) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%s' expects a parameter count after `-'", directive); } else { def->nparam_max = readnum(tline->text, &err); if (err) { - error(ERR_NONFATAL, "unable to parse parameter count `%s'", + nasm_error(ERR_NONFATAL, "unable to parse parameter count `%s'", tline->text); } if (def->nparam_min > def->nparam_max) { - error(ERR_NONFATAL, "minimum parameter count exceeds maximum"); + nasm_error(ERR_NONFATAL, "minimum parameter count exceeds maximum"); } } } @@ -2111,7 +2113,7 @@ static bool parse_mmacro_spec(Token *tline, MMacro *def, const char *directive) if (def->defaults && def->ndefs > def->nparam_max - def->nparam_min && !def->plus) - error(ERR_WARNING|ERR_PASS1|ERR_WARN_MDP, + nasm_error(ERR_WARNING|ERR_PASS1|ERR_WARN_MDP, "too many default macro parameters"); return true; @@ -2183,7 +2185,7 @@ static int do_directive(Token * tline) * in future release (2.09-2.10) */ if (i == PP_RMACRO || i == PP_IRMACRO || i == PP_EXITMACRO) { - error(ERR_NONFATAL, "unknown preprocessor directive `%s'", + nasm_error(ERR_NONFATAL, "unknown preprocessor directive `%s'", tline->text); return NO_DIRECTIVE_FOUND; } @@ -2238,7 +2240,7 @@ static int do_directive(Token * tline) switch (i) { case PP_INVALID: - error(ERR_NONFATAL, "unknown preprocessor directive `%s'", + nasm_error(ERR_NONFATAL, "unknown preprocessor directive `%s'", tline->text); return NO_DIRECTIVE_FOUND; /* didn't get it */ @@ -2251,7 +2253,7 @@ static int do_directive(Token * tline) if (tline && tline->type == TOK_WHITESPACE) tline = tline->next; if (!tline || tline->type != TOK_ID) { - error(ERR_NONFATAL, "`%%stacksize' missing size parameter"); + nasm_error(ERR_NONFATAL, "`%%stacksize' missing size parameter"); free_tlist(origline); return DIRECTIVE_FOUND; } @@ -2284,7 +2286,7 @@ static int do_directive(Token * tline) ArgOffset = 6; LocalOffset = 0; } else { - error(ERR_NONFATAL, "`%%stacksize' invalid size type"); + nasm_error(ERR_NONFATAL, "`%%stacksize' invalid size type"); free_tlist(origline); return DIRECTIVE_FOUND; } @@ -2307,7 +2309,7 @@ static int do_directive(Token * tline) if (tline && tline->type == TOK_WHITESPACE) tline = tline->next; if (!tline || tline->type != TOK_ID) { - error(ERR_NONFATAL, "`%%arg' missing argument parameter"); + nasm_error(ERR_NONFATAL, "`%%arg' missing argument parameter"); free_tlist(origline); return DIRECTIVE_FOUND; } @@ -2317,14 +2319,14 @@ static int do_directive(Token * tline) tline = tline->next; if (!tline || tline->type != TOK_OTHER || tline->text[0] != ':') { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "Syntax error processing `%%arg' directive"); free_tlist(origline); return DIRECTIVE_FOUND; } tline = tline->next; if (!tline || tline->type != TOK_ID) { - error(ERR_NONFATAL, "`%%arg' missing size type parameter"); + nasm_error(ERR_NONFATAL, "`%%arg' missing size type parameter"); free_tlist(origline); return DIRECTIVE_FOUND; } @@ -2334,7 +2336,7 @@ static int do_directive(Token * tline) tt = expand_smacro(tt); size = parse_size(tt->text); if (!size) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "Invalid size type for `%%arg' missing directive"); free_tlist(tt); free_tlist(origline); @@ -2380,7 +2382,7 @@ static int do_directive(Token * tline) if (tline && tline->type == TOK_WHITESPACE) tline = tline->next; if (!tline || tline->type != TOK_ID) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%%local' missing argument parameter"); free_tlist(origline); return DIRECTIVE_FOUND; @@ -2391,14 +2393,14 @@ static int do_directive(Token * tline) tline = tline->next; if (!tline || tline->type != TOK_OTHER || tline->text[0] != ':') { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "Syntax error processing `%%local' directive"); free_tlist(origline); return DIRECTIVE_FOUND; } tline = tline->next; if (!tline || tline->type != TOK_ID) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%%local' missing size type parameter"); free_tlist(origline); return DIRECTIVE_FOUND; @@ -2409,7 +2411,7 @@ static int do_directive(Token * tline) tt = expand_smacro(tt); size = parse_size(tt->text); if (!size) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "Invalid size type for `%%local' missing directive"); free_tlist(tt); free_tlist(origline); @@ -2443,7 +2445,7 @@ static int do_directive(Token * tline) case PP_CLEAR: if (tline->next) - error(ERR_WARNING|ERR_PASS1, + nasm_error(ERR_WARNING|ERR_PASS1, "trailing garbage after `%%clear' ignored"); free_macros(); init_macros(); @@ -2455,12 +2457,12 @@ static int do_directive(Token * tline) skip_white_(t); if (!t || (t->type != TOK_STRING && t->type != TOK_INTERNAL_STRING)) { - error(ERR_NONFATAL, "`%%depend' expects a file name"); + nasm_error(ERR_NONFATAL, "`%%depend' expects a file name"); free_tlist(origline); return DIRECTIVE_FOUND; /* but we did _something_ */ } if (t->next) - error(ERR_WARNING|ERR_PASS1, + nasm_error(ERR_WARNING|ERR_PASS1, "trailing garbage after `%%depend' ignored"); p = t->text; if (t->type != TOK_INTERNAL_STRING) @@ -2481,12 +2483,12 @@ static int do_directive(Token * tline) if (!t || (t->type != TOK_STRING && t->type != TOK_INTERNAL_STRING)) { - error(ERR_NONFATAL, "`%%include' expects a file name"); + nasm_error(ERR_NONFATAL, "`%%include' expects a file name"); free_tlist(origline); return DIRECTIVE_FOUND; /* but we did _something_ */ } if (t->next) - error(ERR_WARNING|ERR_PASS1, + nasm_error(ERR_WARNING|ERR_PASS1, "trailing garbage after `%%include' ignored"); p = t->text; if (t->type != TOK_INTERNAL_STRING) @@ -2505,7 +2507,7 @@ static int do_directive(Token * tline) inc->expansion = NULL; inc->mstk = NULL; istk = inc; - list->uplevel(LIST_INCLUDE); + lfmt->uplevel(LIST_INCLUDE); } free_tlist(origline); return DIRECTIVE_FOUND; @@ -2522,18 +2524,18 @@ static int do_directive(Token * tline) if (!tline || (tline->type != TOK_STRING && tline->type != TOK_INTERNAL_STRING && tline->type != TOK_ID)) { - error(ERR_NONFATAL, "`%%use' expects a package name"); + nasm_error(ERR_NONFATAL, "`%%use' expects a package name"); free_tlist(origline); return DIRECTIVE_FOUND; /* but we did _something_ */ } if (tline->next) - error(ERR_WARNING|ERR_PASS1, + nasm_error(ERR_WARNING|ERR_PASS1, "trailing garbage after `%%use' ignored"); if (tline->type == TOK_STRING) nasm_unquote_cstr(tline->text, i); use_pkg = nasm_stdmac_find_package(tline->text); if (!use_pkg) - error(ERR_NONFATAL, "unknown `%%use' package: %s", tline->text); + nasm_error(ERR_NONFATAL, "unknown `%%use' package: %s", tline->text); else pkg_macro = (char *)use_pkg + 1; /* The first string will be <%define>__USE_*__ */ if (use_pkg && ! smacro_defined(NULL, pkg_macro, 0, NULL, true)) { @@ -2551,13 +2553,13 @@ static int do_directive(Token * tline) tline = expand_id(tline); if (tline) { if (!tok_type_(tline, TOK_ID)) { - error(ERR_NONFATAL, "`%s' expects a context identifier", + nasm_error(ERR_NONFATAL, "`%s' expects a context identifier", pp_directives[i]); free_tlist(origline); return DIRECTIVE_FOUND; /* but we did _something_ */ } if (tline->next) - error(ERR_WARNING|ERR_PASS1, + nasm_error(ERR_WARNING|ERR_PASS1, "trailing garbage after `%s' ignored", pp_directives[i]); p = nasm_strdup(tline->text); @@ -2575,11 +2577,11 @@ static int do_directive(Token * tline) } else { /* %pop or %repl */ if (!cstk) { - error(ERR_NONFATAL, "`%s': context stack is empty", + nasm_error(ERR_NONFATAL, "`%s': context stack is empty", pp_directives[i]); } else if (i == PP_POP) { if (p && (!cstk->name || nasm_stricmp(p, cstk->name))) - error(ERR_NONFATAL, "`%%pop' in wrong context: %s, " + nasm_error(ERR_NONFATAL, "`%%pop' in wrong context: %s, " "expected %s", cstk->name ? cstk->name : "anonymous", p); else @@ -2619,11 +2621,11 @@ issue_error: /* The line contains only a quoted string */ p = tline->text; nasm_unquote(p, NULL); /* Ignore NUL character truncation */ - error(severity, "%s", p); + nasm_error(severity, "%s", p); } else { /* Not a quoted string, or more than a quoted string */ p = detoken(tline, false); - error(severity, "%s", p); + nasm_error(severity, "%s", p); nasm_free(p); } free_tlist(origline); @@ -2649,7 +2651,7 @@ issue_error: CASE_PP_ELIF: if (!istk->conds) - error(ERR_FATAL, "`%s': no matching `%%if'", pp_directives[i]); + nasm_error(ERR_FATAL, "`%s': no matching `%%if'", pp_directives[i]); switch(istk->conds->state) { case COND_IF_TRUE: istk->conds->state = COND_DONE; @@ -2661,8 +2663,8 @@ issue_error: case COND_ELSE_TRUE: case COND_ELSE_FALSE: - error_precond(ERR_WARNING|ERR_PASS1, - "`%%elif' after `%%else' ignored"); + nasm_error(ERR_WARNING|ERR_PASS1|ERR_PP_PRECOND, + "`%%elif' after `%%else' ignored"); istk->conds->state = COND_NEVER; break; @@ -2686,10 +2688,10 @@ issue_error: case PP_ELSE: if (tline->next) - error_precond(ERR_WARNING|ERR_PASS1, - "trailing garbage after `%%else' ignored"); + nasm_error(ERR_WARNING|ERR_PASS1|ERR_PP_PRECOND, + "trailing garbage after `%%else' ignored"); if (!istk->conds) - error(ERR_FATAL, "`%%else': no matching `%%if'"); + nasm_fatal(0, "`%%else: no matching `%%if'"); switch(istk->conds->state) { case COND_IF_TRUE: case COND_DONE: @@ -2705,7 +2707,7 @@ issue_error: case COND_ELSE_TRUE: case COND_ELSE_FALSE: - error_precond(ERR_WARNING|ERR_PASS1, + nasm_error(ERR_WARNING|ERR_PASS1|ERR_PP_PRECOND, "`%%else' after `%%else' ignored."); istk->conds->state = COND_NEVER; break; @@ -2715,10 +2717,10 @@ issue_error: case PP_ENDIF: if (tline->next) - error_precond(ERR_WARNING|ERR_PASS1, - "trailing garbage after `%%endif' ignored"); + nasm_error(ERR_WARNING|ERR_PASS1|ERR_PP_PRECOND, + "trailing garbage after `%%endif' ignored"); if (!istk->conds) - error(ERR_FATAL, "`%%endif': no matching `%%if'"); + nasm_error(ERR_FATAL, "`%%endif': no matching `%%if'"); cond = istk->conds; istk->conds = cond->next; nasm_free(cond); @@ -2732,7 +2734,7 @@ issue_error: case PP_MACRO: case PP_IMACRO: if (defining) { - error(ERR_FATAL, "`%s': already defining a macro", + nasm_error(ERR_FATAL, "`%s': already defining a macro", pp_directives[i]); return DIRECTIVE_FOUND; } @@ -2753,7 +2755,7 @@ issue_error: || defining->plus) && (defining->nparam_min <= mmac->nparam_max || mmac->plus)) { - error(ERR_WARNING|ERR_PASS1, + nasm_error(ERR_WARNING|ERR_PASS1, "redefining multi-line macro `%s'", defining->name); return DIRECTIVE_FOUND; } @@ -2765,7 +2767,7 @@ issue_error: case PP_ENDM: case PP_ENDMACRO: if (! (defining && defining->name)) { - error(ERR_NONFATAL, "`%s': not defining a macro", tline->text); + nasm_error(ERR_NONFATAL, "`%s': not defining a macro", tline->text); return DIRECTIVE_FOUND; } mmhead = (MMacro **) hash_findi_add(&mmacros, defining->name); @@ -2797,7 +2799,7 @@ issue_error: } istk->expansion = l; } else { - error(ERR_NONFATAL, "`%%exitmacro' not within `%%macro' block"); + nasm_error(ERR_NONFATAL, "`%%exitmacro' not within `%%macro' block"); } free_tlist(origline); return DIRECTIVE_FOUND; @@ -2836,7 +2838,7 @@ issue_error: tline = tline->next; if (!tline->next) { free_tlist(origline); - error(ERR_NONFATAL, "`%%rotate' missing rotate count"); + nasm_error(ERR_NONFATAL, "`%%rotate' missing rotate count"); return DIRECTIVE_FOUND; } t = expand_smacro(tline->next); @@ -2846,24 +2848,24 @@ issue_error: tptr = &t; tokval.t_type = TOKEN_INVALID; evalresult = - evaluate(ppscan, tptr, &tokval, NULL, pass, error, NULL); + evaluate(ppscan, tptr, &tokval, NULL, pass, NULL); free_tlist(tline); if (!evalresult) return DIRECTIVE_FOUND; if (tokval.t_type) - error(ERR_WARNING|ERR_PASS1, + nasm_error(ERR_WARNING|ERR_PASS1, "trailing garbage after expression ignored"); if (!is_simple(evalresult)) { - error(ERR_NONFATAL, "non-constant value given to `%%rotate'"); + nasm_error(ERR_NONFATAL, "non-constant value given to `%%rotate'"); return DIRECTIVE_FOUND; } mmac = istk->mstk; while (mmac && !mmac->name) /* avoid mistaking %reps for macros */ mmac = mmac->next_active; if (!mmac) { - error(ERR_NONFATAL, "`%%rotate' invoked outside a macro call"); + nasm_error(ERR_NONFATAL, "`%%rotate' invoked outside a macro call"); } else if (mmac->nparam == 0) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%%rotate' invoked within macro without parameters"); } else { int rotate = mmac->rotate + reloc_value(evalresult); @@ -2895,26 +2897,26 @@ issue_error: tptr = &t; tokval.t_type = TOKEN_INVALID; evalresult = - evaluate(ppscan, tptr, &tokval, NULL, pass, error, NULL); + evaluate(ppscan, tptr, &tokval, NULL, pass, NULL); if (!evalresult) { free_tlist(origline); return DIRECTIVE_FOUND; } if (tokval.t_type) - error(ERR_WARNING|ERR_PASS1, + nasm_error(ERR_WARNING|ERR_PASS1, "trailing garbage after expression ignored"); if (!is_simple(evalresult)) { - error(ERR_NONFATAL, "non-constant value given to `%%rep'"); + nasm_error(ERR_NONFATAL, "non-constant value given to `%%rep'"); return DIRECTIVE_FOUND; } count = reloc_value(evalresult); if (count >= REP_LIMIT) { - error(ERR_NONFATAL, "`%%rep' value exceeds limit"); + nasm_error(ERR_NONFATAL, "`%%rep' value exceeds limit"); count = 0; } else count++; } else { - error(ERR_NONFATAL, "`%%rep' expects a repeat count"); + nasm_error(ERR_NONFATAL, "`%%rep' expects a repeat count"); count = 0; } free_tlist(origline); @@ -2938,7 +2940,7 @@ issue_error: case PP_ENDREP: if (!defining || defining->name) { - error(ERR_NONFATAL, "`%%endrep': no matching `%%rep'"); + nasm_error(ERR_NONFATAL, "`%%endrep': no matching `%%rep'"); return DIRECTIVE_FOUND; } @@ -2961,7 +2963,7 @@ issue_error: istk->mstk = defining; - list->uplevel(defining->nolist ? LIST_MACRO_NOLIST : LIST_MACRO); + lfmt->uplevel(defining->nolist ? LIST_MACRO_NOLIST : LIST_MACRO); tmp_defining = defining; defining = defining->rep_nest; free_tlist(origline); @@ -2980,7 +2982,7 @@ issue_error: if (l) l->finishes->in_progress = 1; else - error(ERR_NONFATAL, "`%%exitrep' not within `%%rep' block"); + nasm_error(ERR_NONFATAL, "`%%exitrep' not within `%%rep' block"); free_tlist(origline); return DIRECTIVE_FOUND; @@ -2996,7 +2998,7 @@ issue_error: if (!tline || (tline->type != TOK_ID && (tline->type != TOK_PREPROC_ID || tline->text[1] != '$'))) { - error(ERR_NONFATAL, "`%s' expects a macro identifier", + nasm_error(ERR_NONFATAL, "`%s' expects a macro identifier", pp_directives[i]); free_tlist(origline); return DIRECTIVE_FOUND; @@ -3020,12 +3022,12 @@ issue_error: while (1) { skip_white_(tline); if (!tline) { - error(ERR_NONFATAL, "parameter identifier expected"); + nasm_error(ERR_NONFATAL, "parameter identifier expected"); free_tlist(origline); return DIRECTIVE_FOUND; } if (tline->type != TOK_ID) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%s': parameter identifier expected", tline->text); free_tlist(origline); @@ -3038,7 +3040,7 @@ issue_error: tline = tline->next; } else { if (!tok_is_(tline, ")")) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`)' expected to terminate macro template"); free_tlist(origline); return DIRECTIVE_FOUND; @@ -3085,12 +3087,12 @@ issue_error: if (!tline || (tline->type != TOK_ID && (tline->type != TOK_PREPROC_ID || tline->text[1] != '$'))) { - error(ERR_NONFATAL, "`%%undef' expects a macro identifier"); + nasm_error(ERR_NONFATAL, "`%%undef' expects a macro identifier"); free_tlist(origline); return DIRECTIVE_FOUND; } if (tline->next) { - error(ERR_WARNING|ERR_PASS1, + nasm_error(ERR_WARNING|ERR_PASS1, "trailing garbage after macro name ignored"); } @@ -3110,7 +3112,7 @@ issue_error: if (!tline || (tline->type != TOK_ID && (tline->type != TOK_PREPROC_ID || tline->text[1] != '$'))) { - error(ERR_NONFATAL, "`%s' expects a macro identifier", + nasm_error(ERR_NONFATAL, "`%s' expects a macro identifier", pp_directives[i]); free_tlist(origline); return DIRECTIVE_FOUND; @@ -3151,7 +3153,7 @@ issue_error: if (!tline || (tline->type != TOK_ID && (tline->type != TOK_PREPROC_ID || tline->text[1] != '$'))) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%s' expects a macro identifier as first parameter", pp_directives[i]); free_tlist(origline); @@ -3167,7 +3169,7 @@ issue_error: t = t->next; /* t should now point to the string */ if (!tok_type_(t, TOK_STRING)) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%s` requires string as second parameter", pp_directives[i]); free_tlist(tline); @@ -3207,7 +3209,7 @@ issue_error: if (!tline || (tline->type != TOK_ID && (tline->type != TOK_PREPROC_ID || tline->text[1] != '$'))) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%%pathsearch' expects a macro identifier as first parameter"); free_tlist(origline); return DIRECTIVE_FOUND; @@ -3223,13 +3225,13 @@ issue_error: if (!t || (t->type != TOK_STRING && t->type != TOK_INTERNAL_STRING)) { - error(ERR_NONFATAL, "`%%pathsearch' expects a file name"); + nasm_error(ERR_NONFATAL, "`%%pathsearch' expects a file name"); free_tlist(tline); free_tlist(origline); return DIRECTIVE_FOUND; /* but we did _something_ */ } if (t->next) - error(ERR_WARNING|ERR_PASS1, + nasm_error(ERR_WARNING|ERR_PASS1, "trailing garbage after `%%pathsearch' ignored"); p = t->text; if (t->type != TOK_INTERNAL_STRING) @@ -3268,7 +3270,7 @@ issue_error: if (!tline || (tline->type != TOK_ID && (tline->type != TOK_PREPROC_ID || tline->text[1] != '$'))) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%%strlen' expects a macro identifier as first parameter"); free_tlist(origline); return DIRECTIVE_FOUND; @@ -3283,7 +3285,7 @@ issue_error: t = t->next; /* t should now point to the string */ if (!tok_type_(t, TOK_STRING)) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%%strlen` requires string as second parameter"); free_tlist(tline); free_tlist(origline); @@ -3314,7 +3316,7 @@ issue_error: if (!tline || (tline->type != TOK_ID && (tline->type != TOK_PREPROC_ID || tline->text[1] != '$'))) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%%strcat' expects a macro identifier as first parameter"); free_tlist(origline); return DIRECTIVE_FOUND; @@ -3337,7 +3339,7 @@ issue_error: break; /* else fall through */ default: - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "non-string passed to `%%strcat' (%d)", t->type); free_tlist(tline); free_tlist(origline); @@ -3379,7 +3381,7 @@ issue_error: if (!tline || (tline->type != TOK_ID && (tline->type != TOK_PREPROC_ID || tline->text[1] != '$'))) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%%substr' expects a macro identifier as first parameter"); free_tlist(origline); return DIRECTIVE_FOUND; @@ -3396,7 +3398,7 @@ issue_error: /* t should now point to the string */ if (!tok_type_(t, TOK_STRING)) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%%substr` requires string as second parameter"); free_tlist(tline); free_tlist(origline); @@ -3406,14 +3408,13 @@ issue_error: tt = t->next; tptr = &tt; tokval.t_type = TOKEN_INVALID; - evalresult = evaluate(ppscan, tptr, &tokval, NULL, - pass, error, NULL); + evalresult = evaluate(ppscan, tptr, &tokval, NULL, pass, NULL); if (!evalresult) { free_tlist(tline); free_tlist(origline); return DIRECTIVE_FOUND; } else if (!is_simple(evalresult)) { - error(ERR_NONFATAL, "non-constant value given to `%%substr`"); + nasm_error(ERR_NONFATAL, "non-constant value given to `%%substr`"); free_tlist(tline); free_tlist(origline); return DIRECTIVE_FOUND; @@ -3426,14 +3427,13 @@ issue_error: count = 1; /* Backwards compatibility: one character */ } else { tokval.t_type = TOKEN_INVALID; - evalresult = evaluate(ppscan, tptr, &tokval, NULL, - pass, error, NULL); + evalresult = evaluate(ppscan, tptr, &tokval, NULL, pass, NULL); if (!evalresult) { free_tlist(tline); free_tlist(origline); return DIRECTIVE_FOUND; } else if (!is_simple(evalresult)) { - error(ERR_NONFATAL, "non-constant value given to `%%substr`"); + nasm_error(ERR_NONFATAL, "non-constant value given to `%%substr`"); free_tlist(tline); free_tlist(origline); return DIRECTIVE_FOUND; @@ -3480,7 +3480,7 @@ issue_error: if (!tline || (tline->type != TOK_ID && (tline->type != TOK_PREPROC_ID || tline->text[1] != '$'))) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "`%%%sassign' expects a macro identifier", (i == PP_IASSIGN ? "i" : "")); free_tlist(origline); @@ -3494,8 +3494,7 @@ issue_error: t = tline; tptr = &t; tokval.t_type = TOKEN_INVALID; - evalresult = - evaluate(ppscan, tptr, &tokval, NULL, pass, error, NULL); + evalresult = evaluate(ppscan, tptr, &tokval, NULL, pass, NULL); free_tlist(tline); if (!evalresult) { free_tlist(origline); @@ -3503,11 +3502,11 @@ issue_error: } if (tokval.t_type) - error(ERR_WARNING|ERR_PASS1, + nasm_error(ERR_WARNING|ERR_PASS1, "trailing garbage after expression ignored"); if (!is_simple(evalresult)) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "non-constant value given to `%%%sassign'", (i == PP_IASSIGN ? "i" : "")); free_tlist(origline); @@ -3535,7 +3534,7 @@ issue_error: tline = tline->next; skip_white_(tline); if (!tok_type_(tline, TOK_NUMBER)) { - error(ERR_NONFATAL, "`%%line' expects line number"); + nasm_error(ERR_NONFATAL, "`%%line' expects line number"); free_tlist(origline); return DIRECTIVE_FOUND; } @@ -3545,7 +3544,7 @@ issue_error: if (tok_is_(tline, "+")) { tline = tline->next; if (!tok_type_(tline, TOK_NUMBER)) { - error(ERR_NONFATAL, "`%%line' expects line increment"); + nasm_error(ERR_NONFATAL, "`%%line' expects line increment"); free_tlist(origline); return DIRECTIVE_FOUND; } @@ -3562,7 +3561,7 @@ issue_error: return DIRECTIVE_FOUND; default: - error(ERR_FATAL, + nasm_error(ERR_FATAL, "preprocessor directive `%s' not yet implemented", pp_directives[i]); return DIRECTIVE_FOUND; @@ -3649,7 +3648,7 @@ static bool paste_tokens(Token **head, const struct tokseq_match *m, /* Left pasting token is start of line */ if (!prev_nonspace) - error(ERR_FATAL, "No lvalue found on pasting"); + nasm_error(ERR_FATAL, "No lvalue found on pasting"); /* * No ending token, this might happen in two @@ -3841,7 +3840,7 @@ static Token *expand_mmac_params_range(MMacro *mac, Token *tline, Token ***last) return head; err: - error(ERR_NONFATAL, "`%%{%s}': macro parameters out of range", + nasm_error(ERR_NONFATAL, "`%%{%s}': macro parameters out of range", &tline->text[1]); return tline; } @@ -3879,7 +3878,7 @@ static Token *expand_mmac_params(Token * tline) while (mac && !mac->name) /* avoid mistaking %reps for macros */ mac = mac->next_active; if (!mac) { - error(ERR_NONFATAL, "`%s': not in a macro call", t->text); + nasm_error(ERR_NONFATAL, "`%s': not in a macro call", t->text); } else { pos = strchr(t->text, ':'); if (!pos) { @@ -3910,14 +3909,14 @@ static Token *expand_mmac_params(Token * tline) } cc = find_cc(tt); if (cc == -1) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "macro parameter %d is not a condition code", n + 1); text = NULL; } else { type = TOK_ID; if (inverse_ccs[cc] == -1) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "condition code `%s' is not invertible", conditions[cc]); text = NULL; @@ -3936,7 +3935,7 @@ static Token *expand_mmac_params(Token * tline) } cc = find_cc(tt); if (cc == -1) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "macro parameter %d is not a condition code", n + 1); text = NULL; @@ -4078,7 +4077,7 @@ again: while (tline) { /* main token loop */ if (!--deadman) { - error(ERR_NONFATAL, "interminable macro recursion"); + nasm_error(ERR_NONFATAL, "interminable macro recursion"); goto err; } @@ -4185,7 +4184,7 @@ again: tline = t; if (!tline) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "macro call expects terminating `)'"); break; } @@ -4235,7 +4234,7 @@ again: } if (brackets < 0) { brackets = 0; - error(ERR_NONFATAL, "braces do not " + nasm_error(ERR_NONFATAL, "braces do not " "enclose all of macro parameter"); } paramsize[nparam] += white + 1; @@ -4247,7 +4246,7 @@ again: m->casesense))) m = m->next; if (!m) - error(ERR_WARNING|ERR_PASS1|ERR_WARN_MNP, + nasm_error(ERR_WARNING|ERR_PASS1|ERR_WARN_MNP, "macro `%s' exists, " "but not taking %d parameters", mstart->text, nparam); @@ -4485,7 +4484,7 @@ static MMacro *is_mmacro(Token * tline, Token *** params_array) */ if (m->in_progress > m->max_depth) { if (m->max_depth > 0) { - error(ERR_WARNING, + nasm_error(ERR_WARNING, "reached maximum recursion depth of %i", m->max_depth); } @@ -4537,7 +4536,7 @@ static MMacro *is_mmacro(Token * tline, Token *** params_array) * After all that, we didn't find one with the right number of * parameters. Issue a warning, and fail to expand the macro. */ - error(ERR_WARNING|ERR_PASS1|ERR_WARN_MNP, + nasm_error(ERR_WARNING|ERR_PASS1|ERR_WARN_MNP, "macro `%s' exists, but not taking %d parameters", tline->text, nparam); nasm_free(params); @@ -4673,7 +4672,7 @@ static int expand_mmacro(Token * tline) paramlen[i]++; } if (brace) - error(ERR_NONFATAL, "macro params should be enclosed in braces"); + nasm_error(ERR_NONFATAL, "macro params should be enclosed in braces"); } /* @@ -4771,73 +4770,57 @@ static int expand_mmacro(Token * tline) } } - list->uplevel(m->nolist ? LIST_MACRO_NOLIST : LIST_MACRO); + lfmt->uplevel(m->nolist ? LIST_MACRO_NOLIST : LIST_MACRO); return 1; } -/* The function that actually does the error reporting */ -static void verror(int severity, const char *fmt, va_list arg) +/* + * This function adds macro names to error messages, and suppresses + * them if necessary. + */ +static void pp_verror(int severity, const char *fmt, va_list arg) { - char buff[1024]; + char buff[BUFSIZ]; MMacro *mmac = NULL; int delta = 0; - vsnprintf(buff, sizeof(buff), fmt, arg); + /* + * If we're in a dead branch of IF or something like it, ignore the error. + * However, because %else etc are evaluated in the state context + * of the previous branch, errors might get lost: + * %if 0 ... %else trailing garbage ... %endif + * So %else etc should set the ERR_PP_PRECOND flag. + */ + if ((severity & ERR_MASK) < ERR_FATAL && + istk && istk->conds && + ((severity & ERR_PP_PRECOND) ? + istk->conds->state == COND_NEVER : + emitting(istk->conds->state))) + return; /* get %macro name */ - if (istk && istk->mstk) { + if (!(severity & ERR_NOFILE) && istk && istk->mstk) { mmac = istk->mstk; /* but %rep blocks should be skipped */ while (mmac && !mmac->name) mmac = mmac->next_active, delta++; } - if (mmac) - nasm_error(severity, "(%s:%d) %s", - mmac->name, mmac->lineno - delta, buff); - else - nasm_error(severity, "%s", buff); -} - -/* - * Since preprocessor always operate only on the line that didn't - * arrived yet, we should always use ERR_OFFBY1. - */ -static void error(int severity, const char *fmt, ...) -{ - va_list arg; - - /* If we're in a dead branch of IF or something like it, ignore the error */ - if (istk && istk->conds && !emitting(istk->conds->state)) - return; - - va_start(arg, fmt); - verror(severity, fmt, arg); - va_end(arg); -} - -/* - * Because %else etc are evaluated in the state context - * of the previous branch, errors might get lost with error(): - * %if 0 ... %else trailing garbage ... %endif - * So %else etc should report errors with this function. - */ -static void error_precond(int severity, const char *fmt, ...) -{ - va_list arg; - - /* Only ignore the error if it's really in a dead branch */ - if (istk && istk->conds && istk->conds->state == COND_NEVER) - return; + if (mmac) { + vsnprintf(buff, sizeof(buff), fmt, arg); - va_start(arg, fmt); - verror(severity, fmt, arg); - va_end(arg); + nasm_set_verror(real_verror); + nasm_error(severity, "(%s:%d) %s", + mmac->name, mmac->lineno - delta, buff); + nasm_set_verror(pp_verror); + } else { + real_verror(severity, fmt, arg); + } } static void -pp_reset(char *file, int apass, ListGen * listgen, StrList **deplist) +pp_reset(char *file, int apass, StrList **deplist) { Token *t; @@ -4853,8 +4836,7 @@ pp_reset(char *file, int apass, ListGen * listgen, StrList **deplist) src_set_linnum(0); istk->lineinc = 1; if (!istk->fp) - error(ERR_FATAL|ERR_NOFILE, "unable to open input file `%s'", - file); + nasm_fatal(ERR_NOFILE, "unable to open input file `%s'", file); defining = NULL; nested_mac_count = 0; nested_rep_count = 0; @@ -4867,7 +4849,6 @@ pp_reset(char *file, int apass, ListGen * listgen, StrList **deplist) } any_extrastdmac = extrastdmac && *extrastdmac; do_predef = true; - list = listgen; /* * 0 for dependencies, 1 for preparatory passes, 2 for final pass. @@ -4902,6 +4883,8 @@ static char *pp_getline(void) char *line; Token *tline; + real_verror = nasm_set_verror(pp_verror); + while (1) { /* * Fetch a tokenized line, either from the macro-expansion @@ -4955,13 +4938,11 @@ static char *pp_getline(void) */ if (defining) { if (defining->name) - error(ERR_PANIC, - "defining with name in expansion"); + nasm_panic(0, "defining with name in expansion"); else if (istk->mstk->name) - error(ERR_FATAL, - "`%%rep' without `%%endrep' within" - " expansion of macro `%s'", - istk->mstk->name); + nasm_fatal(0, "`%%rep' without `%%endrep' within" + " expansion of macro `%s'", + istk->mstk->name); } /* @@ -4991,7 +4972,7 @@ static char *pp_getline(void) } istk->expansion = l->next; nasm_free(l); - list->downlevel(LIST_MACRO); + lfmt->downlevel(LIST_MACRO); } } while (1) { /* until we get a line we can use */ @@ -5005,7 +4986,7 @@ static char *pp_getline(void) istk->expansion = l->next; nasm_free(l); p = detoken(tline, false); - list->line(LIST_MACRO, p); + lfmt->line(LIST_MACRO, p); nasm_free(p); break; } @@ -5033,10 +5014,12 @@ static char *pp_getline(void) nasm_free(src_set_fname(nasm_strdup(i->fname))); } istk = i->next; - list->downlevel(LIST_INCLUDE); + lfmt->downlevel(LIST_INCLUDE); nasm_free(i); - if (!istk) - return NULL; + if (!istk) { + line = NULL; + goto done; + } if (istk->expansion && istk->expansion->finishes) break; } @@ -5109,23 +5092,30 @@ static char *pp_getline(void) } } +done: + nasm_set_verror(real_verror); return line; } static void pp_cleanup(int pass) { + real_verror = nasm_set_verror(pp_verror); + if (defining) { if (defining->name) { - error(ERR_NONFATAL, - "end of file while still defining macro `%s'", - defining->name); + nasm_error(ERR_NONFATAL, + "end of file while still defining macro `%s'", + defining->name); } else { - error(ERR_NONFATAL, "end of file while still in %%rep"); + nasm_error(ERR_NONFATAL, "end of file while still in %%rep"); } free_mmacro(defining); defining = NULL; } + + nasm_set_verror(real_verror); + while (cstk) ctx_pop(); free_macros(); @@ -5194,6 +5184,8 @@ static void pp_pre_define(char *definition) Line *l; char *equals; + real_verror = nasm_set_verror(pp_verror); + equals = strchr(definition, '='); space = new_Token(NULL, TOK_WHITESPACE, NULL, 0); def = new_Token(space, TOK_PREPROC_ID, "%define", 0); @@ -5205,13 +5197,15 @@ static void pp_pre_define(char *definition) if (space->next->type != TOK_PREPROC_ID && space->next->type != TOK_ID) - error(ERR_WARNING, "pre-defining non ID `%s\'\n", definition); + nasm_error(ERR_WARNING, "pre-defining non ID `%s\'\n", definition); l = nasm_malloc(sizeof(Line)); l->next = predef; l->first = def; l->finishes = NULL; predef = l; + + nasm_set_verror(real_verror); } static void pp_pre_undefine(char *definition) @@ -5243,7 +5237,7 @@ static void make_tok_num(Token * tok, int64_t val) tok->type = TOK_NUMBER; } -struct preproc_ops nasmpp = { +const struct preproc_ops nasmpp = { pp_reset, pp_getline, pp_cleanup, |