Commit Graph

3393 Commits

Author SHA1 Message Date
Cyrill Gorcunov
3a994a92cc output: Elf -- Start using ElfX_Ehdr instead of opencoded writes
This should be more convenient. At least both headers
are well documented in specifications so we simply
follow them.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-03-18 15:16:10 +03:00
Cyrill Gorcunov
2f038e9d5d nasmlib: Add _le helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-03-18 15:16:10 +03:00
H. Peter Anvin
e74fd4b7b8 outelf: claim %pragma elf as our namespace
We don't have any elf pragmas yet, but we want to be able to do
"%pragma elf" and have it work for any of the elf formats.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-03-14 18:58:35 -07:00
H. Peter Anvin
6e4ceb7ba1 Merge remote-tracking branch 'origin/master' 2017-03-14 18:48:21 -07:00
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
b852d351f6 nasmlib.h: explicitly include <ctype.h>
There are macros in this file which depend on <ctype.h>, so treat them
that way.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-03-14 18:42:25 -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
Cyrill Gorcunov
fa38564c49 output: elf -- Fix typo in ELF32_ST_INFO
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-03-12 11:40:52 +03:00
Cyrill Gorcunov
bcf0389481 elf: Drop code duplication in elf_section_header
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-03-12 11:37:41 +03:00
Cyrill Gorcunov
660101a02e elf: Align members for file format defs
For readability sake.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-03-12 11:37:23 +03:00
Cyrill Gorcunov
37034f1cc8 elf: Add EI_ constants
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-03-12 11:37:15 +03: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
d49a3bf6db changes.src: some minor textual improvements
Document the new -Werror= options a little bit better.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-08 01:50:08 -08:00
H. Peter Anvin
024d0e0fd0 NASM 2.13rc8 2017-03-08 01:32:56 -08:00
H. Peter Anvin
ea33e83081 Run "make alldeps"
Missing dependencies strike again :(

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-08 01:31:10 -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
38373e8f1c NASM 2.13rc7 2017-03-07 23:04:15 -08:00
H. Peter Anvin
7fcd9898f4 doc: document subsections_via_symbols
Document the subsections_via_symbols directive.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-07 23:03:11 -08:00
H. Peter Anvin
fc7c5c3967 outmacho.mac: fix typo in subsections_via_symbols
subsections_via_symbols is plural for both nouns.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-07 23:02:31 -08:00
H. Peter Anvin
b786f66c2e output: output format macros should be case insensitive
Use %imacro instead of %macro for ELF "osabi" and Mach-O
"subsections_by_symbols".

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-07 22:53:48 -08: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
bb4524cf9a include/error.h: add file missing from previous commit
The include file include/error.h was missing from checkin
b20bc733c9, oops...

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-07 19:52:57 -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
e28d5ea5d7 Merge remote-tracking branch 'origin/master'
The directiv.c renaming unfortunately got pushed in two separate
version; force the correct one.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-07 19:32:46 -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
17cb4eb659 Rename directiv.[ch] to directbl.[ch] 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 17:56:42 -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
f786ef7371 outelf.c: char * -> const char *
Make the arguments to add_sectname() constant.  There are definitely
more things about this that ought to be cleaned up, including not
relying on magic offsets for the section numbers, but this is a
trivial cleanup that really needed to be done anyway.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-01 21:17:45 -08:00
H. Peter Anvin
14d0085f0b NASM 2.13rc6 2017-03-01 13:46:46 -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
964d502248 changes.src: correct form is "%idefine ptr $%?"
Actually do the right thing this time, hopefully...

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-01 13:35:13 -08:00
H. Peter Anvin
f23bd426be changes.src: to hide a keyword, %idefine foo $%??
The $ in "%idefine ptr $%??" was missing.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-01 13:32:27 -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
55e06dead1 test/imm.asm: test more combinations of immediates
A few more combinations of immediates that can or should be converted.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-01 13:23:52 -08:00
H. Peter Anvin
2d89477ef4 configure.ac: smarter way to handle -O2 -> -O3 default change
We don't want to tack on -O3 if the user has specified, say,
CFLAGS='-g -O1' for debugging.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-01 12:57:46 -08:00
H. Peter Anvin
6980985eb9 make clean: clean up more things that ought to be
Cleaning up hasn't really kept up to date with source code changes.
Try make it better for now; this also ought to make it easier to do
the corresponding cleaning in the *.mak files.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-03-01 01:23:00 -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
e90a89abe4 compiler.h: add redundant cast to quiet Watcom warning
Add a redundant cast in watcom_switch_hack() to quiet a Watcom
warning, and remove open-coded implementation of the Watcom switch
hack.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-03-01 00:52:48 -08:00
H. Peter Anvin
e29c7bb241 include/compiler.h: change __WATCOM__ to __WATCOMC__
The correct macro to test for (Open)Watcom is __WATCOMC__ not
__WATCOM__.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-02-28 23:05:17 -08:00
sezeroz
34b5dbe496 openwcom.mak: further fixes to build with OpenWatcom WMAKE
Further fixes for OpenWatcom/WMAKE (BR 3392383).

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-02-28 23:01:14 -08:00
H. Peter Anvin
844cbe88a2 NASM 2.13rc5 2017-02-28 19:37:27 -08:00