Commit Graph

59 Commits

Author SHA1 Message Date
H. Peter Anvin
9f16cfde4c macho: implement do_dead_strip, make subsections_by_symbols a pragma
Implement the MachO do_dead_strip directive, which sets a flag on the
corresponding section.  This as well as subsections_by_symbols are
reimplemented as pragmas; if someone uses the predefined macro they
still get the expected behavior.

However, this allows someone to write:

%pragma macho subsections_by_symbols

... and have it ignored if compiling for, say, ELF.

Also, implement the following section attributes:

      zerofill, no_dead_strip, live_support, strip_static_syms

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-03-14 18:46:31 -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
8753425472 asm/pragma.c: if the handler is NULL, treat it as DIRR_UNKNOWN
If the handler is NULL, then all pragmas are by definition unknown, so
treat them exactly as if we had received DIRR_UNKNOWN from the
handler.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-03-08 20:28:13 -08:00
H. Peter Anvin
d9493fa440 pragma: use the directives hash to look up directive names
Very few things have any desire to do its own string parsing, and the
directives hash is already a plain string-to-numbers O(1) hash.  The
namespace is small enough that even if it makes some switch statements
compile a bit larger there is no real reason to have separate hashes,
even if the actual code as opposed to the data structure was shared.

So, for right now, just throw them together in one big happy pot.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-03-08 20:10:46 -08:00
H. Peter Anvin
e345e3d640 Merge remote-tracking branch 'origin/master' 2017-03-08 01:30:20 -08:00
H. Peter Anvin
b2047cbb98 Make -Werror controllable on a per-warning-class basis
Make -Werror possible to control on a per-warning-class basis.  While
I was fixing up that code anyway, merge the handling of the -w, -W and
[warning] argument and directives.

Furthermore, make *all* warnings suppressible; any warning that isn't
categorized now belong to category "other".  However, for cleanliness
sake an "other" option does not get listed in the warning messages.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-08 01:26:40 -08:00
Cyrill Gorcunov
485413344b asm/pragma: Add missing "assemble.h" inclusion
| asm/pragma.c:131:6: error: no previous prototype for ‘process_pragma’ [-Werror=missing-prototypes]
| void process_pragma(char *str)
|      ^~~~~~~~~~~~~~

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-03-08 11:39:42 +03:00
H. Peter Anvin
8e1cb8e594 outmacho: support the "subsections_via_symbols" directive
The "subsection_via_symbols" directive simply sets a flag in the
Mach-O file header.

Requested in BR 3392367.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-07 22:43:00 -08:00
H. Peter Anvin
e562b70cea output: make the return value from the directives method more meaningful
The directives code is already trying to do a bit more unified error
handling, so give ourselves a bit richer interface.  At this point,
the conversion was pretty automatic so we probably return DIRR_OK
instead of DIRR_ERROR in a fair number of places, but that's okay.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-07 22:42:39 -08:00
H. Peter Anvin
a6e26d9cca Add a generic pragma-handling infrastructure
Add infrastructure for handling %pragmas with a variety of namespaces,
etc., etc...

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-07 21:32:37 -08:00
H. Peter Anvin
b83b2b28ad asm/directiv.c: remove commented-out #include
Remove a commented-out #include mistakenly left in the file.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-07 19:52:12 -08: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
H. Peter Anvin
ed40e2528d Rename directiv.c to directbl.c to free up the name directiv.c
We want to move the directive handling to a separate file, so change
the filename of the directive table handler to something a bit more
specific.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-07 18:08:03 -08:00
H. Peter Anvin
c713168bc7 asm/nasm.c: Move directive parsing into a separate function
Move the directive parsing out of the main loop into a separate
function.  It is much cleaner this way, and opens up for further
refactoring -- a bunch of the directives do the same thing or very
similar things.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-07 17:45:01 -08:00
H. Peter Anvin
64e87d0dfc assemble.c: for the signed byte operand, check overflow then rawbyte
When we are generating a signed byte operand, we anyway have to do the
overflow check "manually".  After doing so, output the result using
out_rawbyte() instead of out_imm(), so we don't end up doing a
redundant, and incorrect, second overflow check.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-01 13:45:02 -08:00
H. Peter Anvin
02788e1675 Revert "asm/assemble.c: change the overflow handling for signed byte immediates"
This reverts commit fbb07d6843.

This change was quite wrong; it is explicitly there to verify the
validity of the value as a 16/32/64-bit number, not it's
8-bit-worthiness.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-01 13:39:10 -08:00
H. Peter Anvin
285222ffd6 assemble.c: always do overflow warnings on pass 2
It is very rare that it makes sense to warn on pass 1.  Instead, do
all the overflow warnings in pass 2.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-01 13:27:33 -08:00
H. Peter Anvin
fbb07d6843 asm/assemble.c: change the overflow handling for signed byte immediates
For byte immediates that are sign-extended to a wider operand size,
simplify the code and make the warning code behave as what is
expected.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-01 13:25:08 -08:00
H. Peter Anvin
09dff8b257 Remove casts in switch statements only meant to keep OpenWatcom happy
Remove casts in switch statements that were intended to keep
OpenWatcom happy.  It didn't work, and now we have a more general
solution for the problem, which also ought to be less dangerous.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-03-01 01:01:37 -08:00
H. Peter Anvin
a5a56bd117 exprlib: move dumping code to a separate C file
Most of the time we don't need the dumping code, so move it to a
separate C file to the linker can exclude it.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-02-28 18:13:43 -08:00
H. Peter Anvin
87646096a9 asm/parser.c: don't call reloc_value() twice, minor cleanups
There is absolutely no reason to call reloc_value() twice while
processing an immediate.  Doing so is both expensive and unnecessary.
Make some more deliberate decorations to try to avoid miscompilation
on OpenWatcom, but I'm not sure this will help enough.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-02-28 17:44:24 -08:00
H. Peter Anvin
11f18ec05b asm/exprlib.c: use PRId64 to print a 64-bit number
Use PRId64 instead of %ld to print a 64-bit number.  This is debugging
code, but as it is frequently useful I included it in mainline code
and, well, then it has to compile everywhere...

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-02-23 18:18:12 -08:00
H. Peter Anvin
c5cbb97db4 assemble: for relative addresses, convert *this segment* to fixed
We can remove OUT_ADDRESS relocations for absolute addresses (NO_SEG),
but for OUT_RELADDR relocations we can remove them if they point into
*our own segment*, not NO_SEG.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-02-21 11:53:15 -08:00
H. Peter Anvin
d97cceed61 We can have a WRT for a relative reference
It isn't illegal to have WRT for a relative reference.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-02-21 11:31:35 -08:00
H. Peter Anvin
8930a8fc15 Properly keep track of the base of relative relocations
For expressions like [foo - $] or [bar - $$] our relocation base is
not the same as the end of the instruction.  Make that explicit.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-02-21 11:30:22 -08:00
H. Peter Anvin
164d24677a Support self-relative expressions in offsets and immediates
Handle, hopefully correctly, self-relative expressions (that is,
expressions of the form X - Y where Y is a symbol in the current
segment, possibly $ or $$) used as offsets or immediates, as opposed
to arguments to Dx statements (which have already been supported for a
while.)

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-02-20 02:39:56 -08:00
H. Peter Anvin
2902fbc1d8 assemble.c: don't use a case for get_broadcast_num()
Instead of using a case, use a conditional shift.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-02-20 00:35:58 -08:00
H. Peter Anvin
94e4052a8a nasm_build_assert() -> nasm_static_assert()
The C11 standard calls this concept a static assert, so go with that
terminology.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-01-24 12:26:09 -08:00
Cyrill Gorcunov
15ce78fc5b macros: Define ofmt specific macros late
In commits e1f985c167 and f7606613d0
we reordered macros handling, but ofmt specific
macros are to be handled after standart ones
are processed.

In particular __SECT__ handling must not change,
so the order of inclusion does matter.

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

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-01-06 20:22:36 +03:00
Cyrill Gorcunov
4ff8c63ab6 preproc: Use found path when opening include
It's a typo in 169ac7c152

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

Reported-by: Ryan Prichard <ryan.prichard@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-01-06 00:36:23 +03:00
Martin Lindhe
8cc93f5232 assemble_file: Get rid of global variable @sb
fixes pvs-studio error 'V707 Giving short names to global variables
is considered to be bad practice. It is suggested to rename 'sb' variable.

gorcunov@: Use local non-static variable.

Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-01-05 22:38:41 +03:00
Martin Lindhe
58f37c1736 parser: Get rid of global variable
fixes pvs-studio error 'V707 Giving short names to global variables
is considered to be bad practice. It is suggested to rename 'i' variable.

gorcunov@: Simply define it as local variable.

Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-01-05 22:38:41 +03:00
Martin Lindhe
d551b431a1 Move @debugid declaration to same level as @q
fixes pvs-studio error 'V507 Pointer to local array 'debugid' is
stored outside the scope of this array. Such a pointer will become invalid.'

Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-01-05 22:38:41 +03:00
Martin Lindhe
b150e386ae Drop redundant test with isnumchar
Fix pvs-studio error 'V501 There are identical sub-expressions
'(c) == '_'' to the left and to the right of the '||' operator.'. isnumchar()
is a macro defined as (nasm_isalnum(c) || (c) == '_')

Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-01-05 22:38:41 +03:00
Martin Lindhe
9b5aa2e6d0 Drop redundant test with isnumchar
fix pvs-studio error 'V501 There are identical sub-expressions '(c) == '_'' to
the left and to the right of the '||' operator.'. isnumchar() is a macro
defined as (nasm_isalnum(c) || (c) == '_')

Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-01-05 22:38:41 +03:00
H. Peter Anvin
abd28c9ab9 If we have new features introduced by C11, use them
Instead of using hacks or compiler-specific features, if we have
standard features as defined in ISO C11, use them.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-12-20 02:29:58 -08:00
Cyrill Gorcunov
fd610f27d6 asm/parser.c -- Fix typo in testing for register
It should be EXPR_REG_END referred when testing
for register present.

A typo in 472a7c1d17

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

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-11-29 01:17:33 +03:00
H. Peter Anvin
472a7c1d17 Allow relative references to external symbols in data
Allow constructs like:

      dd foo - $

... where foo is an external symbol.  Currently this is only
implemented for extops, i.e. dx opcodes.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-10-31 08:44:25 -07:00
H. Peter Anvin
bc7f4fe275 preproc: add plumbing for the %pragma directive
Plumb the %pragma directive through the preprocessor and make it
generate an assembly directive unless given as %pragma preproc.  So
far no actual pragmas are actually defined.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-10-04 14:57:17 -07:00
H. Peter Anvin
e93572e6be Merge remote-tracking branch 'origin/nasm-2.12.xx' 2016-10-04 14:09:07 -07:00
H. Peter Anvin
436e367874 Factor out common string list handling code
Simplify the preprocessor code by factoring out the common string list
handling code.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-10-04 01:12:28 -07:00
H. Peter Anvin
9924d1ea85 preproc: clean up handing of the dependency lists
We search the dependency list anyway (ouch...) so we might as well
use that instead of keeping track of a tail pointer.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-10-04 00:59:39 -07:00
H. Peter Anvin
ccad6f929f preproc: return found_path as a constant string
Always return found_path as a constant string.  We end up making an
internal copy of it anyway to put in the fullpath hash, so there is no
reason to make a duplicate of it.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-10-04 00:34:35 -07:00
H. Peter Anvin
da8659dfd0 Merge remote-tracking branch 'origin/nasm-2.12.xx'
Resolved Conflicts:
	version

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-10-04 00:30:17 -07:00
H. Peter Anvin
55568c1193 nasm: scan the command line twice
Scan the command line twice, so we among other things can set up the
proper preprocessor before calling any of the preprocessor entry
points.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-10-03 19:46:49 -07:00
H. Peter Anvin
169ac7c152 Add a hash for pathname searches, instead of searching very pass
We have been doing a pathname search every time we encounter a file,
which means every file in every pass.  Instead, put the pathnames
found in a hash table.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-09-25 17:08:05 -07:00
H. Peter Anvin
96921a5ad8 backend: psas inslen == 0 to the backend for the INCBIN case
An INCBIN "instruction" can be enormous (up to an off_t size.)  There
is no reason to burden the rest of the code by widening the inslen and
insoffs fields just for INCBIN, so set inslen == 0 to indicate fields
not valid.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-09-24 09:53:03 -07:00
H. Peter Anvin
fa803abc61 backend: move wrapper for legacy output functions to a library routine
Move the wrapper for legacy output into a library routine so the
backends can be ported one at a time.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-09-24 09:46:47 -07:00
H. Peter Anvin
04445364fc incbin: if we have to fread(), try to do it only once...
If we can't mmap a file and instead have to fread(), if the data is
small enough that we can reasonably accomodate it in a memory buffer,
then just read it once.

It seems rather unlikely that very large files would be used with
TIMES anyway.

Also note: the previous comment about nasm_file_size[_by_path]() being
invoked twice was spurious; it does not actually happen.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-09-21 15:56:19 -07:00