Commit Graph

42 Commits

Author SHA1 Message Date
H. Peter Anvin
8960e1bc83 Remove #includes already provided by "compiler.h"
"compiler.h" already includes a bunch of common include files. There
is absolutely no reason to duplicate them in individual files, and in
fact it robs us of central control of how these files are used.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-27 12:45:44 -08:00
H. Peter Anvin
bd2803964e Merge tag 'nasm-2.14.03rc1'
NASM 2.14.03rc1

Resolved Conflicts:
	asm/labels.c
	include/error.h

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-27 11:37:22 -08:00
H. Peter Anvin
4cf86ddde8 BR 3392539: some errors can "cascade". Allow suppressing if dead.
In BR 3392539, the error:

helloW.s:18: error: label `rurt' changed during code generation
[-w+error=label-redef-late]

... occurs a number of times after we have already issued an
error. This is because the erroring instruction computes to a
different size during code generation; this causes each subsequent
label to cause a phase error.

The phase error simply doesn't make much sense to report: if we are
already committed to erroring out, it is more likely an error cascade
rather than an error in its own right, so just suppress it in that
case.

Reported-by: <russvz@comcast.net>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-27 11:24:17 -08:00
H. Peter Anvin
2e53f27e9d Move <string.h> inclusion to compiler.h
There is absolutely no reason not to include <string.h> globally, and
with the inline function for mempcpy() we need it there anyway.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-26 06:32:37 -08:00
H. Peter Anvin (Intel)
e55d03dd47 Clean up the handling of various passes
The use of pass0, pass1, pass2, and "pass" passed as an argument is
really confusing and already caused a severe bug in the 2.14.01
release cycle. Clean them up and be far more explicit about what
various passes mean.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-18 11:14:59 -08:00
H. Peter Anvin (Intel)
80c4f23c52 nasm_warnf() -> nasm_warn()
We want to strongly encourage writers of warnings to create warning
categories, so remove the flagless nasm_warn() and change nasm_warnf()
to nasm_warn().

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-14 13:33:24 -08:00
H. Peter Anvin (Intel)
727c85263f Merge tag 'nasm-2.14.01rc5'
NASM 2.14.01rc5

Resolved Conflicts:
	asm/labels.c
	asm/nasm.c
	version
2018-12-14 13:24:19 -08:00
H. Peter Anvin (Intel)
0402a2d402 labels.c: redefine test should be passn, not pass0
Stupid thinko: lpass should be passn + 1, not pass0 + 1.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-14 13:01:39 -08:00
H. Peter Anvin (Intel)
374312cde4 strlist, warnings: improve strlist, buffer warnings until error
Make strlist_free() take a pointer to a pointer, so we can set it to
NULL.

Buffer warnings on a strlist until we either get an error or we are in
pass 2. Hopefully this should let us get rid of a lot of the ERR_PASS*
bullshit, which far too often causes messages to get lost.

asm/labels.c contains one example of a warning that cannot be made
correct with a specific pass number.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-14 00:17:13 -08:00
H. Peter Anvin (Intel)
723ab481a6 warnings: define warning classes at point of use
It is extremely desirable to allow the user fine-grained control of
warnings, but this has been complicated by the fact that a warning
class has had to be defined in no less than three places (error.h,
error.c, nasmdoc.src) before it can be used in source code. Instead,
use a script to define these via magic comments at the point of use.

This hopefully will encourage creating new classes as needed.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-13 21:53:31 -08:00
H. Peter Anvin (Intel)
fef75c265a warnings: Make WARN_ constants consistent with -w options
Not only does this make it consistent, but allows for automation.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-12 18:13:47 -08:00
H. Peter Anvin (Intel)
8e08fb6da7 Merge remote-tracking branch 'origin/nasm-2.14.xx'
Resolved Conflicts:
	asm/assemble.c
	asm/directiv.c
	asm/error.c
	asm/float.c
	asm/labels.c
	asm/listing.c
	asm/nasm.c
	asm/parser.c
	asm/preproc.c
	asm/stdscan.c
	include/error.h
	output/outelf.c
	version

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-12 18:05:52 -08:00
H. Peter Anvin
e2f5edbb3a error: new flag ERR_HERE
ERR_HERE is used to mark messages of the form "... here" so that we
can emit sane output to the list file with filename and line number,
instead of a nonsensical "here" which could point almost anywhere.

This patch contains some changes from the one in the master branch to
make the code cleaner.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-12 17:43:25 -08:00
H. Peter Anvin (Intel)
950dee9edc BR 3392535: warning on redefine, promote define-on-pass2 to error
If we redefine consistently, make it a suppressed-by-default warning.
If we end up doing the define on pass 2, promote that to a
default-error warning; using a default-error warning allows the user
to demote it should they so wish.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Requested-by: C. Masloch <pushbx@38.de>
2018-12-12 16:49:07 -08:00
H. Peter Anvin (Intel)
ebb05a0e5f hashtbl: revamp the hash table interface, support binary keys
Add binary key support to the hash table interface. Clean up the
interface to contain less extraneous crud.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-11 13:18:49 -08:00
H. Peter Anvin
ddb290681e error: new flag ERR_HERE
ERR_HERE is used to mark messages of the form "... here" so that we
can emit sane output to the list file with filename and line number,
instead of a nonsensical "here" which could point almost anywhere.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-11 00:06:29 -08:00
H. Peter Anvin
a7bc437eab asm/labels.c: use error helpers
Replace explicit calls to nasm_error() with error helpers.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-10 22:46:24 -08:00
H. Peter Anvin
36e3c70790 Merge remote-tracking branch 'origin/nasm-2.14.xx'
Resolved Conflicts:
	asm/labels.c
	include/error.h
	version
2018-12-10 21:28:59 -08:00
H. Peter Anvin
b424ae3130 BR 3392534: error out on an inconsistently redefined label
If a label is redefined in the same pass, and the value is
inconsistent, then error out. While we are at it, give the source
location of the previous definition.

This explicitly rejects BR 3392535; there seems to be no reason to
reject duplicate definitions with the same value, as there is no
inconsistency involved.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-10 13:30:51 -08:00
Cyrill Gorcunov
46c37b3772 labels: Use nasm_error helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-12-01 20:03:55 +03:00
Cyrill Gorcunov
8e740c6773 labels: Make sure nil label is never passed
We already catched a case where we've missed
test for non nil label and in result got sigsegv,
lets rather panic next time.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-13 17:18:05 +03:00
Cyrill Gorcunov
70d429676b labels: Add missing backend type for extern symbols
Typo in 98578071b9

https://bugzilla.nasm.us/show_bug.cgi?id=3392494

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-07-01 02:00:12 +03:00
Cyrill Gorcunov
a8e3d6a836 labels: Shrink declare_label
No need to pass unused 'created', find_label can
handle nil here.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-06-30 20:02:24 +03:00
H. Peter Anvin (Intel)
d644119ded subsections: don't lose the offset in the parent section
We don't want to lose the offset into the parent section when we
create a subsection, at least not for the MachO backend which is
currently the only user of subsections. Allow ofmt->herelabel() to set
a flag to copy the section offset from the previous section.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-27 20:20:21 -07:00
H. Peter Anvin, Intel
c5e45f6b70 labels: auto-promote EXTERN labels to GLOBAL if defined
If we define a label which was previously declared EXTERN, then
automatically treat is as GLOBAL.

Previously, we would fail to converge and loop forever, which is
obviously not what we want.  This is more user-friendly anyway.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 13:16:53 -07:00
H. Peter Anvin, Intel
4fb2acc0d3 labels: if we have overridden EXTERN, don't call define_label()
If we have overridden EXTERN, then we should not call define_label()
on it again.  Return a fail status from declare_label(), indicating
that the type declaration failed, but of course we don't print an
error message.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 13:11:01 -07:00
H. Peter Anvin, Intel
2139874de2 labels: fix formatting of warning message
Output was backwards...

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 13:03:39 -07:00
H. Peter Anvin, Intel
bc77f9c587 labels: don't update the local variable base for *ANY* dot labels
..@ labels (macro-local) are NASM specials, although not "magic": they
are explicitly defined to not preturb the local label base name.
However, they return false for both islocal() and ismagic(), so we
need to add a new function containing the correct test for when the
local label base should be advanced.

Reported-by: <balducci@units.it>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Bae, Chang Seok <chang.seok.bae@intel.com>
2018-06-25 12:45:14 -07:00
H. Peter Anvin
a7c8e39686 labels: pass the mangled name to the backend for fixups
ofmt->symdef() always takes the mangled label name, make sure we
actually do the correct thing even for forward fixups.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-18 14:17:26 -07:00
H. Peter Anvin
46c839a03d labels: allocation of a segment number counts as a change
If we allocate a new segment number, that has to cause
global_offset_changed to be incremented.  Thus, we should not update
lptr->defn.segment until that would ordinarily be done.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-14 20:00:07 -07:00
H. Peter Anvin
af5f918a92 Don't keep assigning segment numbers to EXTERN or COMMON
If a symbol is EXTERN or COMMON, then we should not keep assigning it
new segment numbers over and over. Instead, change the label code so
that it assignes a new segment value if and only if one has not been
assigned before.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-14 19:53:45 -07:00
H. Peter Anvin
29695c85fb labels: add a subsection field available for backend use
Allow the subsection to store a subsection value directly in the
label, rather than having to do strange encoding hacks.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-14 17:04:32 -07:00
H. Peter Anvin
734824823e Unbreak special segment symbols, unbreak COMMON
Recent changes broke:

1. Backend-provided special segments, due to seg_alloc() getting
   reset.
2. COMMON; the old code would pass size in the "offset" *without*
   setting it in the label structure. Containing all this information
   in the label structure requires another field.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-11 14:54:14 -07:00
H. Peter Anvin
3cb9068ee0 asm/directiv.c: fix bug in perm_alloc()
Fix dumb thinko in perm_alloc().

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-01 21:05:45 -07:00
H. Peter Anvin
98578071b9 Cleanup of label renaming infrastructure, add subsection support
In order to support Mach-O better, add support for subsections, as
used by Mach-O "subsections_via_symbols". We also want to add
infrastructure to support this by downcalling to the backend to
indicate if a new subsection is needed.

Currently this supports a maximum of 2^14 subsections per section for
Mach-O; this can be addressed by adding a level of indirection (or
cleaning up the handling of sections so we have an actual data
structure.)

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-01 18:06:25 -07:00
H. Peter Anvin
892c4818ce Add support for backend-defined subsections and label hacks
MachO has this odd thing called "subsections via symbols", by which a
symbol can magically start what effectively is a new section. To
support this, add support for a calldown into the backend when a new
symbol is defined *at the current output location*, and allow it to
switch the current segment.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-05-30 14:48:18 -07:00
H. Peter Anvin
3e555483b3 labels, outelf: remove casts for allocations
Remove casts from allocations.  This is simply Not How To Do Things:
every cast carries a potential risk of being a toxic type misuse
(e.g. pointer as integer) and so any unnecessary cast is actively
harmful.

Note that a lot of allocations here are completely unnecessary: the
core code now guarantees that all filenames are permanently allocated
for the duration of the assembly, and so should be turned into const
char * without any further allocation.  Any remaining malloc+strcpy
should be turned into nasm_strdup(), and nasm_new[n]() used whereever
possible.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-04-23 17:02:46 -07:00
H. Peter Anvin
785ffb95da labels: make lookup_labels and is_extern take a const char *
Whenever we can, we should constipate our arguments...

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-03-14 18:41:25 -07:00
H. Peter Anvin
9c595b6bb4 Fix global variables without declarations
Global variables need to be declared in a header file; "extern" in C
files should be used extremely rarely (it is OK at least for now for
macro tables as they are generally only ever used in one specific
location, but otherwise, no.)

In a few cases the global variables were actually function-local!

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-07 19:44:21 -08:00
H. Peter Anvin
b20bc733c9 asm/*: Move directive processing to its own file, refactor error handling
Move directive processing to its own file, and move nasmlib/error.c to
asm/error.c (it was not used by the disassembler); remove some extern
declarations from .c files, and do some general code cleanups.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-07 19:31:04 -08:00
Cyrill Gorcunov
43bb293432 Merge branch 'nasm-2.12.xx'
* nasm-2.12.xx:
  codeview: Fix ill-formed "S_COMPILE2" record.
  rdoff: Add rdf2bin input dependency
  labels: Warn if new label created on pass two
  Add explicit void parameter to newmembuf() function declaration.
  compiler.h: always undefine __STRICT_ANSI__ for gcc

| Conflicts:
|	rdoff/Makefile.in

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-07-27 01:08:51 +03:00
H. Peter Anvin
e1f985c167 Reorganize the source code into subdirectories
Make the source code easier to understand and keep track of by
organizing it into subdirectories depending on the function.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-05-25 12:06:29 -07:00