Commit Graph

544 Commits

Author SHA1 Message Date
H. Peter Anvin
97577e82d7 macho64: remove LC_DATA_IN_CODE, change reloc type to 1
Change the relocation type to SIGNED instead of BRANCH, this is
probably more correct.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-11 19:25:33 -08:00
H. Peter Anvin
5eebc6bc2b macho64: fix alignment problems, add LC_DATA_IN_CODE
Hopefully actually fix the issues with alignment this time.
Avoid a linear search of segments for each symbol emitted.
Issue an empty LC_DATA_IN_CODE command since that seems to be
expected.

With this, ffmpeg builds but still crashes on startup, which seems
very strange.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-11 17:51:37 -08:00
H. Peter Anvin
ae01785d87 LLVM portability fix for abs(size)
size is actually an uint64_t, and LLVM drops the abs() on the
principle that the uint64_t should always be positive.  Make it
explicit that we are converting to a signed integer first, by using
abs((int)size) instead.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-05 11:34:07 -08:00
H. Peter Anvin
5482a15e17 codeview.c: remove superfluous pointer test
A pointer to a field in a structure can never be NULL so remove
the test.  There is no reason to test the field for an empty string
either, since we immediately thereafter do a strcmp().

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-05 11:31:46 -08:00
H. Peter Anvin
def81d5c71 outmac64: Fix the handling of section data alignment
Fix a number of places which failed to account for padding to
alignment of section data.  Also, fix confusion between aligning
section data in the linkable object code and final address alignment;
LLVM/Xcode always align section data to 4 bytes (with a comment saying
that it probably should be 8 bytes for 64-bit output) independent of the
section alignment.

This will need to be ported to the macho32 backend, as well; ideally
the two should be merged as they are really very similar and we don't
want to have these kinds of cross-porting problems.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-05 11:19:29 -08:00
Jim Kukunas
3115e789d6 coff: Add support for the Codeview 8 debug format
Codeview is a debug format for win32/win64 PE/COFF files. It adds two sections,
.debug$S (symbols) and .debug$T (types), to the generated object file. These
sections are then used by the linker to generate a PDB file which can be used
by various debuggers (WinDbg, Visual Studio, etc).

Signed-off-by: Jim Kukunas <james.t.kukunas@linux.intel.com>
Acked-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-01-24 14:14:39 +03:00
Cyrill Gorcunov
8aa9c2eb91 output: macho64 -- Fix OUT_REL4ADR on bigendians
We're converting address value into bigendian
(on BE machine) and then continue doing arithmetics
on top, which is of course incorrect.

Instead do all operations first then convert
to BE and write it into image.

Reported-by: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-11-05 00:43:29 +03:00
Mark Scott
be8a5c8f2d out: elf,stabs -- Fix @n_value attribute for HdrSym entry
Each stabs entry is 12 bytes in size, for some reason we've
been pasing wrong attribute here in @n_value.

Signed-off-by: Mark Scott <nasm@mscott.cx>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-11-03 01:14:14 +03:00
Cyrill Gorcunov
94b4a2c819 output: aout -- Use nasm_x_space helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-07-26 16:42:27 +03:00
Martin Storsjö
561242bd43 out: maco64 -- Properly update the full 64 bit value when adding relocations
Previously only the first byte was updated (since @mydata
is a an uint8_t[]).

Signed-off-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-07-24 00:45:59 +03:00
Cyrill Gorcunov
6f05b8008c output: outmacho32 -- Fix stack overwrite
The size of address migh be up to 8 bytes here
so allocate enough stack space.

http://bugzilla.nasm.us/show_bug.cgi?id=3392317

Reported-by: Kyle Brodie <kylecbrodie@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-07-21 22:51:34 +03:00
Cyrill Gorcunov
bd628dedea output: outmach64 -- Use back WRITELONG for OUT_REL4ADR
Because of 74a08cc3f we no longer need to write all
8 bytes here, revert it back as it were before
5b730a197

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-07-19 14:24:32 +03:00
Cyrill Gorcunov
2e6297ff1b out: Zeroify temp buffer before use
This is a a buffer on stack big enough to hold
bigger object we might need (address, number and
etc) but it's defined as an array of bytes and
we treat it as different types depending on context,
which may lead to situation where data from stack
been treated as meaningful.

In particular in commit 5b730a197 we've fixed such
problem simply using a "big" write to zeroify stack
data before use.

Lets simply zeroify this buffer explicitly to escape
such problems in future.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-07-19 14:24:26 +03:00
Delan Azabani
5b730a197a out: maco64 -- Fix erroneously small write for OUT_REL4ADR
Ensure that the int64_t offset value, which ultimately comes from an
int64_t value in gencode() (assemble.c:1906), is completely written to
the temporary buffer, instead of merely its least significant 32 bits.

Prior to this change, WRITELONG was used instead of WRITEDLONG, which
resulted in add_reloc being passed an int64_t "reloff" whose least
significant 32 bits were those from the aforementioned offset value,
and whose most significant 32 bits were stack garbage from "mydata".

This led to get_closest_section_symbol_by_offset() attempting to search
for extremely large values of "offset" among the symbols in "syms",
which meant that the last symbol with a matching section number would
always win the symbol search.

In effect, this clobbered the resultant relocation information, such
that all entries would be resolved with the same symbol.

Test output can be found here

https://www.azabani.com/patch/2/output.txt

This patch fixes

http://bugzilla.nasm.us/show_bug.cgi?id=3392306

Signed-off-by: Delan Azabani <delan@azabani.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-02 13:22:32 +03:00
Cyrill Gorcunov
4920a03243 output: outmac64 -- Fix the case when first hit matches the symbol
In case if we're looking up for a symbol and it's first
one in symbol table we might endup with error because of
using GE here (78f477b35f) ending cycle with @nearest = NULL.

http://bugzilla.nasm.us/show_bug.cgi?id=3392306

Reprted-by: Benjamin Randazzo <benjamin@linuxcrashing.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-05-09 18:07:47 +03:00
Ed Maste
1f0cb0f2c1 output: elf64 -- increase .symtab and .rel* alignment to 8
Discovered while working on ELF Tool Chain elfcopy (strip),
which originally crashed on an assert while processing
a nasm-generated ELF object.

The .symtab and .rela.text sections report 4 byte alignment,
but require 8.

As an aside, see https://sourceforge.net/p/elftoolchain/tickets/485/ for a
discussion of the ELF Tool Chain issue that this bug exposed.

With my WIP elfcopy change and nasm-assembled jccolss2-64.o from libjpeg-turbo:

% strip -o /dev/null --strip-debug jccolss2-64.o
strip: section .symtab alignment 4 increased to 8
strip: section .rela.text alignment 4 increased to 8

http://bugzilla.nasm.us/show_bug.cgi?id=3392307

Signed-off-by: Ed Maste <emaste@freebsd.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-04-16 01:02:55 +03:00
Cyrill Gorcunov
775153b1bf output: dbg,aout,elf32 -- Fix out for signed relocations
@size might be negative for signed relocations but its length
is abs value. This is rather a fix for future use because at
moment we can't hit this problems but better be on a safe side.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-02-21 21:14:28 +03:00
Cyrill Gorcunov
d72bec12bc output: bin -- Fix section length miscalc for OUT_ADDRESS
While we using proper @asize variable for relocation itself
we miss the fact that @size variable (which might be negative
for signed relocations since fd52c277dd) is used to calculate
section size increment.

http://bugzilla.nasm.us/show_bug.cgi?id=3392299

Reported-by: Ben de Waal <ben@dewaals.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-02-15 18:18:57 +03:00
Cyrill Gorcunov
d4923fc6a2 output: maco 64 -- Fix data conversion
Looks like were a typo in first place

http://bugzilla.nasm.us/show_bug.cgi?id=3392298

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-01-11 17:21:46 +03:00
Cyrill Gorcunov
78f477b35f output: maco 64 -- Fix get_closest_section_symbol_by_offset
- fixup comparision it should be GE
 - make sure we never return nil here

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-01-11 17:19:34 +03:00
H. Peter Anvin
d4184a0e0f Add missing static declarations in output/outobj.c
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-11-25 12:14:52 -08:00
H. Peter Anvin
895ac7e53f Add missing static declaration in output/outdbg.c
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-11-25 12:14:52 -08:00
H. Peter Anvin
443b8e9b5f Add missing static declaration in output/outieee.c
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-11-25 12:14:52 -08:00
H. Peter Anvin
aa433d738c Add missing static declaration in output/outcoff.c
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-11-25 12:14:52 -08:00
H. Peter Anvin
c0c67c67c8 Add missing header file in output/nulldbg.c
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-11-25 12:14:52 -08:00
H. Peter Anvin
e76a626055 Replace unchecked fwrite() calls
Instead of having unchecked fwrite() calls, introduce nasm_write()
which does error checking (and fatal errors if the write fails).

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-10-21 12:50:47 -07:00
Cyrill Gorcunov
8a076f4260 output: elf -- Use common elf_ structures
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2014-09-21 13:05:03 +04:00
Cyrill Gorcunov
c24568b0b0 output: elf -- Move common structures into outelf.h header
All Elf formats we're supporting at the moment have
are using same structures, move them into a header
and name then with elf_ prefix.

This makes a few fields to carry 64 bit integers while
in former Elf32|x formats they can be 32 bit wide, but
I think it's acceptable tradeoff.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2014-09-21 13:03:26 +04:00
Cyrill Gorcunov
500dd5461c output: elf -- Move elf_directive into single instance
For all Elf32/32x/64 this routine is the same. So lets
merge it into one instance.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2014-08-29 20:30:57 +04:00
Cyrill Gorcunov
9b76c802ae output: elf -- Rename section_attrib to elf_section_attrib
Global section_attrib name is too general.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2014-08-29 20:24:24 +04:00
Cyrill Gorcunov
6ebe3bcd2e output: outbin -- Fix relocation size
In commit fd52c277dd
we've started handling negative address relocations
but support Elf format only and got a typo in bin
format which leaded to endless cycle of applying
relocation due to negative argument (make test
hangs).

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2014-06-28 22:31:06 +04:00
H. Peter Anvin
49de44e56d Merge remote-tracking branch 'origin/signrel' 2014-05-09 15:09:43 -07:00
H. Peter Anvin
0ace62cb6a outelf: Error out on "section align" without value
If someone specifies "section align" without =value, error out.

Reported-by: Ilya Albrekht <ilya.albrekht@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-02-18 13:30:44 -08:00
Cyrill Gorcunov
d0293d3392 BR3392274: output: Elf -- Don't crash on erronious syntax
Elf align section attribute requires syntax "align=value",
but in case if '=' is missed we pass nil pointer into
atoi function which cause libc to crash.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2014-02-15 18:40:12 +04:00
H. Peter Anvin
fd52c277dd output: Allow OUT_ADDRESS with a negative size to mean signed relocation
This only matters for ELF64/ELFx32, at least for now.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2013-11-26 18:12:39 -08:00
Marat Dukhan
29227125f0 coff: Better handling of section redefinition
Currently, if we try to define an already defined section and specify
section flags, NASM will output "warning: section attributes ignored
on redeclaration of section %SECTIONNAME%".

The patch modifies this behaviour:

1. If the previous section definition differs only in alignment flags,
   no warning is generated

2. If the new definition implies larger alignment, it overrides the
   previous section alignment

3. If the new definition specifies any section alignment, the content of
   the section will be aligned on the new boundary (i.e. the effect is the
   same as if there was ALIGN macro)

Signed-off-by: Marat Dukhan <maratek@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-10-03 16:55:50 +04:00
Marat Dukhan
91c43d789a coff: Support for section names longer than 8 bytes
http://bugzilla.nasm.us/show_bug.cgi?id=3392233

Signed-off-by: Marat Dukhan <maratek@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-09-21 13:09:03 +04:00
Philipp Kloke
91a2f99346 Fixed wrong format specifier in format string
Signed-off-by: Philipp Kloke <philipp.kloke@web.de>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-04-01 02:11:51 +04:00
Philipp Kloke
c51a224ceb Remove unnecessary calls to memset
The C standard guarantees that strncpy pads
the string with zeros if source string is smaller
than destination buffer.

Signed-off-by: Philipp Kloke <philipp.kloke@web.de>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-04-01 02:11:01 +04:00
Andrew Nayenko
57162eb084 Fix warnings generated by clang 3.0
Fix warnings like this:

output/outelf32.c:2120:33: warning: equality comparison with extraneous
      parentheses [-Wparentheses-equality]
            if ((match->section == index)) {
                 ~~~~~~~~~~~~~~~^~~~~~~~
output/outelf32.c:2120:33: note: remove extraneous parentheses around the
      comparison to silence this warning
            if ((match->section == index)) {
                ~               ^       ~
output/outelf32.c:2120:33: note: use '=' to turn this equality comparison into
      an assignment
            if ((match->section == index)) {
                                ^~
                                =
1 warning generated.

Signed-off-by: Andrew Nayenko <resver@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-02-25 01:08:00 +04:00
Keith Kanios
0863bc386b BR3392232: Fix relocations in MachO64
Signed-off-by: Keith Kanios <keith@kanios.net>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2012-11-28 20:05:20 +04:00
Cyrill Gorcunov
5fa17e8398 output: Add more Elf unification
One day the elf output routines would be abstracted
enough to be merged in one file. This patch simply
removes some differences from elf32/64 code.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2012-11-16 22:57:07 +04:00
Cyrill Gorcunov
7ce86b500c BR3392231: Fix get_closest_section_symbol_by_offset
This patch changes get_closest_section_symbol_by_offset
logic to lookup only the closest symbols which are at
or before the supplied offset.

Signed-off-by: Keith Kanios <keith@kanios.net>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2012-11-06 00:47:20 +04:00
H.J. Lu
04633d07b6 backend: add support for x32 ELF
Add an x32 ELF (32-bit code with the CPU in 64-bit mode) backend.
2012-02-03 12:08:59 -08:00
Cyrill Gorcunov
7add67f949 elf64: Make linelist to look the same as elf32
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-08-28 17:07:26 +04:00
Cyrill Gorcunov
5a8944af59 elf32: Drop holes in linelist structure
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-08-28 17:05:17 +04:00
Cyrill Gorcunov
e07bd499f8 outobj: Reorder Segment members to eliminate holes
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-08-28 17:03:21 +04:00
Cyrill Gorcunov
a30090b7e5 outieee: Reorder ieeeSection members to eliminate holes
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-08-28 17:00:04 +04:00
Cyrill Gorcunov
32af9d75f3 elf64: Drop unused 'zero' variable
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-07-17 14:04:44 +04:00
Keith Kanios
8052664433 BR3282788: Fix 64-bit Mach-O bug that crashes NASM due to NULL symbols 2011-04-11 21:38:50 -05:00
Cyrill Gorcunov
a4f98b3aab Merge branch 'nasm-2.09.xx'
Conflicts:
	nasm.h
	version

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-04-06 19:12:17 +04:00
Cyrill Gorcunov
c1936da942 ofmt: Alias shortname must be used for __OUTPUT_FORMAT__ macro
__OUTPUT_FORMAT__ must consist of shortname of output format
or its alias, otherwise userspace ABI gets broken.

For example source code still can refer to __OUTPUT_FORMAT__=elf,
instead of __OUTPUT_FORMAT__=elf32.

BR3246990

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-04-06 18:32:15 +04:00
Keith Kanios
e3f4780665 output/outbin.c: initialize section align/start attributes upon creation 2011-02-28 09:49:04 +03:00
Cyrill Gorcunov
befc631d04 elf64: Use nasm_zalloc helper
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-02-28 09:45:43 +03:00
Cyrill Gorcunov
efc249d8fc outelf32: Use nasm_zalloc helper
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-02-28 09:40:43 +03:00
Cyrill Gorcunov
b4af1ac765 outcoff: Use nasm_zalloc helper
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-02-28 09:33:08 +03:00
Cyrill Gorcunov
c13deef255 bin: Use nasm_zalloc for default section creation
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-02-28 09:28:25 +03:00
Cyrill Gorcunov
3bc3ff2fb6 bin: Use nasm_zalloc helper for section allocation in a sake of simplicity
Instead of opencoded zero assignments better to use nasm_zalloc
and set fields which are supposed to be non-nil. This simplifies
code and makes it more readable.

Also note the field 'ifollows' renamed to 'prev' as it should
be from the very beginning in terms of lists.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-02-28 01:26:24 +03:00
Keith Kanios
11db774a15 output/outbin.c: initialize section align/start attributes upon creation 2011-02-27 13:14:32 -06:00
Cyrill Gorcunov
cb9a459560 coff: Handle massive relocations
The backport of

4db724fdd7
359b63f897
01102ee8e6
2672af7379

so coff output target to be able to handle
massive relocations.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-11-20 14:18:23 +03:00
Cyrill Gorcunov
2672af7379 coff: Cover 'else' with cond compilation
It was a nit in first place.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-11-07 01:09:36 +03:00
Cyrill Gorcunov
01102ee8e6 coff: Handle massive relocations
In case if relocations number exceed 16bit values
we have to hande such case by a special way, as described
in COFF specification.

 "IMAGE_SCN_LNK_NRELOC_OVFL indicates that the count of
relocations for the section exceeds the 16 bits that are
reserved for it in the section header. If the bit is set
and the NumberOfRelocations field in the section header
is 0xffff, the actual relocation count is stored in the
32-bit VirtualAddress field of the first relocation. It
is an error if IMAGE_SCN_LNK_NRELOC_OVFL is set and
there are fewer than 0xffff relocations in the section."

[ BR3092924 ]

Reported-by: Robert Yates
Investigated-by: nasm64developer
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-11-06 18:38:00 +03:00
Cyrill Gorcunov
359b63f897 coff: Issue fatal signal on relocations more then 0xffff
Actually it's temporary action. We have to support more
relocations then that but it requires some more code rework.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-11-06 02:45:45 +03:00
Cyrill Gorcunov
4db724fdd7 coff: Add IMAGE_SCN_MAX_RELOC constant
We will need it to analyze if section relocations
are overflowed.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-11-05 13:50:04 +03:00
Cyrill Gorcunov
2c157002f2 BR3079550: NASM crash on run-time for OMF output format
We could have accessed malloc'ed data on external symbols
in obj and ieee output formats. Fix it by using nasm_zalloc.

Reported-by: Jiri Malak
Patch-by: Jiri Malak
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-10-27 21:41:11 +04:00
Cyrill Gorcunov
9e8f0ac460 BR3079550: NASM crash on run-time for OMF output format
We could have accessed malloc'ed data on external symbols
in obj and ieee output formats. Fix it by using nasm_zalloc.

Reported-by: Jiri Malak
Patch-by: Jiri Malak
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-10-02 01:21:00 +04:00
Cyrill Gorcunov
d7b654c73d elf: Move stabs symbol table format into outelf.h
Get rid of code duplication

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-07-30 00:51:44 +04:00
Cyrill Gorcunov
4cc1064328 outbin: Cleanup bin_cleanup
No need for 'q' variable.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-07-06 19:40:02 +04:00
Cyrill Gorcunov
faf23d1302 outbin: Simplify reverse address computing
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-07-06 19:08:28 +04:00
Cyrill Gorcunov
2b416c9def BR3025702: outbin -- Fix byte ordering
In commit 55ae12052c we occasionally broke byte ordering. Fix it.
Note that current stable version 2.08.01 is not affected by this bug.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-07-06 18:33:29 +04:00
H. Peter Anvin
5e2e8b9105 Rename filenames to 8.3 format
Apparently some people still care about compiling native on MS-DOS,
and we don't have a significant number of files which need adjustment.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-06-15 10:47:16 -07:00
H. Peter Anvin
b714cb27cb outobj: handle compilers without 64-bit switch() support
OpenWatcom, in particular, doesn't handle switch() statements with
64-bit expressions, sigh.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-06-07 11:34:28 -07:00
H. Peter Anvin
4dff757ba5 outelf32: handle compilers without 64-bit switch() support
OpenWatcom, in particular, doesn't handle switch() statements with
64-bit expressions, sigh.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-06-07 11:26:11 -07:00
Cyrill Gorcunov
a731924978 nasmlib: Rename elements() macro to ARRAY_SIZE
ARRAY_SIZE is a well known name pointing out that
we're dealing with array in macro argument.

Also to be on a safe side prefix_name helper should
check the index been in bounds more precisely.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-06-03 23:17:21 +04:00
H. Peter Anvin
62de275527 outobj: update error message
The possible sizes we can encounter are 1, 2, 4, 8... make sure we get
a proper error message.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-05-06 17:58:46 -07:00
H. Peter Anvin
931ce775cf outobj: properly error on unsupported relocations
Error out on any relocations not supported by the backend.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-05-06 17:52:57 -07:00
H. Peter Anvin
bce369022a outelf64: update copyright date
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-05-06 17:45:39 -07:00
H. Peter Anvin
32575e46ac ELF support for 8-bit relocations
Support 8-bit relocations (OUT_ADDRESS and OUT_REL1ADR) in ELF.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-05-06 16:14:00 -07:00
H. Peter Anvin
55ae12052c Add support for one-byte relocations
Add OUT_REL1ADR (one-byte relative address) and support for
OUT_ADDRESs with size == 1.  Add support for it in
outbin and outdbg.  *It still needs to be added to other backends*,
both the OUT_REL*ADR and OUT_ADDRESS codepaths need to be handled.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-05-06 15:33:24 -07:00
Cyrill Gorcunov
97ec06a16a MachO: Fix misprinted macho_sectalign
macho_sectalign was occasionally misprinted
with macho_setcalign, fix it. No change on functionality.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-28 23:17:13 +04:00
Cyrill Gorcunov
a20b668add obj: Implement sectalign helper
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-25 22:00:15 +04:00
Cyrill Gorcunov
573d25fe92 macho: Implement sectalign handler
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-25 21:35:09 +04:00
Cyrill Gorcunov
9868bfe80f ieee: Fix section index match in sectalign handler
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-25 17:55:52 +04:00
Cyrill Gorcunov
b9fd67b38e outieee: Implement sectalign handler
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-25 01:17:11 +04:00
Cyrill Gorcunov
bb196d4fd3 outbin: Drop current_section variable
There is no need for it anymore.

Reported-by: "H. Peter Anvin" <hpa@linux.intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-22 22:32:17 +04:00
Cyrill Gorcunov
4c45e83aac outbin: Prune ancient format_mode variable
format_mode is always set to 1 so there is no need to
keep this variable. "Old chicken bit" (c) :)

Reported-by: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-22 22:25:55 +04:00
Cyrill Gorcunov
630f221b01 bin: Implement sectalign handler
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-22 19:06:29 +04:00
Cyrill Gorcunov
279d8f146a coff: Use IMAGE_SCN_ALIGN_MASK macro
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-22 19:06:14 +04:00
Cyrill Gorcunov
3834305507 coff: Allow alignment greater then 64 bytes on win
On win32/64 we have no 64 bytes limit so hit it on
"coff" target only.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-22 19:06:03 +04:00
Cyrill Gorcunov
7c8c258cdd coff: Fix section alignment computation
Section alignment is broken due to not being
direct "align -> power of two set" mapping but
rather including second addition operation.

Fix it by introducing coff_sectalign_flags helper.
This also allow us to use this helper for getting
rid of open coded computation as well.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-22 19:05:50 +04:00
Cyrill Gorcunov
42017a6115 coff: Use predefined macros instead of numbers and style fix
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-22 19:03:56 +04:00
Cyrill Gorcunov
557a57bd55 pecoff.h: Complete header
Put in all constants pecoff v8 states. Most probably we
will never need most of them but lets have them here for
completeness.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-22 19:02:22 +04:00
H. Peter Anvin
35c30da61b Remove open-coded ilog2() implementations
When we need integer log2, use the new library routine.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-04-21 16:46:57 -07:00
Cyrill Gorcunov
83ffe8ca24 coff: Use predefined macro in common section flags
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 22:40:11 +04:00
Cyrill Gorcunov
d0c6dbe0fe coff: Use predefined macro and eliminate open coded constants
Not all are covered but process initiated.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 22:03:33 +04:00
Cyrill Gorcunov
d71d876f46 pecoff.h: Add more constants
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 21:47:03 +04:00
Cyrill Gorcunov
2ece71588c pecoff: Update machine types
Update up to pecoff v8

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 18:46:27 +04:00
Cyrill Gorcunov
8906629f4f output: Introduce pecoff.h
Better to have common constants grouped.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 18:10:04 +04:00
Cyrill Gorcunov
f8dc028c07 coff: Implement sectalign handler
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 18:10:00 +04:00
Cyrill Gorcunov
2ef5c27be7 Rename SEGALIGN to SECTALIGN
"sectalign" is preferred over "segalign"
since it operates over section attributes.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 18:09:54 +04:00
Cyrill Gorcunov
c56a7a2c82 Elf64: Implement segalign handler
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 01:15:28 +04:00
Cyrill Gorcunov
f68feb08c2 Elf-32: Implement segalign handling
Via elf_segalign helper

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 01:09:02 +04:00
Cyrill Gorcunov
2a587ab1c9 ofmt: Implement null_segalign stubs
Set stubs for all targets

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 01:08:36 +04:00
Cyrill Gorcunov
d807d911fe Elf: Rename SEG_ALIGN to SEC_FILEALIGN
It's Elf specifics. To not mess with segment alignment.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 01:06:44 +04:00
Cyrill Gorcunov
8d4d060104 Add "win" alias for "win32" output format
We already have "elf" and "macho" aliases for respective
32 bit output formats. Make the same for "win32" in a
sake of consistency.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 01:06:36 +04:00
Cyrill Gorcunov
ba3c0513dd Elf: switch section_attrib to a new nasm_opt_val interface
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-11 13:12:20 +04:00
Cyrill Gorcunov
c084467eba Elf: Use SHA_ANY constant instead of open coded number
SHA_ANY is not part of Elf specification but rather our own symbolic
definition for convenience.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-11 12:58:05 +04:00
Cyrill Gorcunov
6837749d85 ofmt: Introduce output format aliases
This allow us to keep compatibility layer without
needing the separated struct ofmt for this and
elf_init_hack routine.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-10 00:11:00 +04:00
Cyrill Gorcunov
f134cc63da Elf: Some unification snippets for 32/64 bit versions
Nothing serious, comments and style movements.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-10 00:10:38 +04:00
Cyrill Gorcunov
e3c4791300 Elf: Merge WRITE_STAB to outelf.h
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-10 00:10:20 +04:00
Cyrill Gorcunov
6620d1aa6d Elf: Drop never used SOC helper
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-10 00:10:07 +04:00
Cyrill Gorcunov
572dd0021c Elf: Introduce section_attrib helper
In a sake of removing code duplication.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-10 00:02:38 +04:00
Cyrill Gorcunov
6fe313a719 output/outbin.c: Fix misprinted alignment bound
Due to a misprint in commit
9b66d8e4c3

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-02-11 21:49:58 +03:00
Cyrill Gorcunov
3cbd9e7215 Elf: Drop useless SEG_ALIGN_1
No need for SEG_ALIGN_1 since we have switched
to ALIGN helper.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-02-11 21:28:34 +03:00
Cyrill Gorcunov
9b66d8e4c3 Use ALIGN helper
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-02-11 21:28:30 +03:00
Cyrill Gorcunov
a135658e83 ELF: Explicitly point out SYM_GLOBAL, SYM_LOCAL binding
Instead of implicit declaration of global symbols obtained
by STB_GLOBAL << 4, and local symbols by STB_LOCAL << 4
use ELF32_ST_MKBIND helpers.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-01-03 15:04:46 +03:00
Cyrill Gorcunov
de623f2679 elf.h: Add ELFXX_ST_MKBIND and move ELFXX_ST_ helpers
The profit of ELFXX_ST_MKBIND helper is that we
will use it for SYM_GLOBAL explicitly pointing
out from where this magic 0x10 came from.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-01-03 15:04:41 +03:00
Cyrill Gorcunov
126faf2e3b output/outelfX.c: Use definitions from stabs.h
Also made Makefile.in to handle dependency.
There are some makefiles in Mkfiles\ should
be fixed as well.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-01-03 15:04:36 +03:00
Cyrill Gorcunov
d1428b23da Add common STABs definition into output/stabs.h
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-01-03 15:04:31 +03:00
Cyrill Gorcunov
c9862c009b outelfX.c: Trivial cleanup
Some tab\space convertions together with
trivial style nitfix.

No change on binary level.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-01-03 15:04:26 +03:00
Cyrill Gorcunov
3b4c769d99 Elf: Allow symbols binding to undefined section
Commit 2ddcd03900
did bind symbols (in case of omitted SECTION directive)
to .text section but break COMMON binding.
Fix it.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-01-02 23:00:43 +03:00
Cyrill Gorcunov
2ddcd03900 Elf: bind labels to text section by default
In case if SECTION directive is omitted but the real
code exist we form .text section by default and put compiled
code here. In turn labels are not handled in a same manner.

So lets bind them to text section by default as well.

[ BR: 2835192 ]

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-12-10 00:36:37 +03:00
H. Peter Anvin
3c9d7ea8a6 outrdf.c: remove obsolete file
The old RDF format has been unsupported for long time now.  Remove it
from the tree.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-11-30 13:27:49 -08:00
H. Peter Anvin
3b861a7766 outform.h: fix OF_NO_RDF2
OF_NO_RDF2 should turn off OF_RDF2, not OF_RDF

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-11-30 13:26:34 -08:00
H. Peter Anvin
b512fb56db outmacho32: replace error() -> nasm_error()
Somehow outmacho32.c escaped the global change of error variables to
hard-coded nasm_error().

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-11-30 11:27:47 -08:00
Cyrill Gorcunov
bc0113d977 outcoff: BuildExportTable -- tab/space fix
Due to previous commit an indent by tab (occasionally) brought in.
Fix it as well. No change on binary level.

We're not that far from NASM release so it's a bit unpleasant
manner to push in such trivial change. But since it's the previous
commit dependent -- I dare to push it.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-11-17 23:25:15 +03:00
Cyrill Gorcunov
bf8cebd813 outcoff: Do not fail on long export identifiers
If an export identifier is greater then 241 symbols
we do fail due to buffer overflow. Fix it.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-11-17 20:49:58 +03:00
Cyrill Gorcunov
2e7a84b829 outelf32/64 - various cleanups in a sake of unification
Make a small step forward elf32/64 unification procedure.
Mostly style fixes. Nothing serious.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-11-06 22:00:59 +03:00
Cyrill Gorcunov
b15ed1f836 dwarfX_output: dont check for "ln" twice
And make dwarf64 version to be more familiar to
32bit version (preparation work for merge).

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-11-06 22:00:54 +03:00
Cyrill Gorcunov
24f9398a6f output/outelf64.c: simplify stabs64_cleanup, dwarf64_cleanup
nasm_free is failsafe against NULL passed

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-11-06 22:00:49 +03:00
Cyrill Gorcunov
a50f829435 Merge elf header files
Merge elfcommon.h, elf32.h, elf64.h into
single elf.h -- we do support both elf32
and elf64 anyway. Let put them into common
place.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-11-06 22:00:41 +03:00
Cyrill Gorcunov
a353955a8d output/outelf32-64: use string helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-10-31 20:03:29 +03:00
Cyrill Gorcunov
54e94a56e2 Remove outdated comments
From Frank Kotler:
| ...
| > -                stdscan_bufptr = saveme;        /* bugfix? fbk 8/10/00 */
| > +                stdscan_set(saveme);            /* bugfix? fbk 8/10/00 */
|
| While you're at it, you could remove my comment(s - it seems to have
| reproduced). It *is* a bugfix (apparently). "saveme" might have a better
| name, too...

So get rid of the comments.

Reported-by: Frank Kotler <fbkotler@zytor.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-10-31 20:03:14 +03:00
Cyrill Gorcunov
917117ff69 stdscan: switch to stdscan_get/set routines
Instead of manipulating stdscan buffer pointer directly
we switch to a routine interface.

This allow us to unify stdscan access: ie caller should
"talk" to stdscan via stdscan_get/set routines.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-10-31 20:02:43 +03:00
Keith Kanios
d2a553c072 BR 2840300: fix macho symbol alignment bug 2009-10-16 21:53:59 -05:00
Cyrill Gorcunov
69c4f63c25 elf,stabs: stabs32/64_generate -- append ending token
This represent "end of compilation unit" token.
Since gcc does (almost) the same lets be on the
same side.

Though to be precise gcc puts offset which points
to the first byte right after the last instruction
issued but in fact string index is analyzed only
so we may safely write zero here (without relocation
as well).

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-09-14 22:43:30 +04:00
Cyrill Gorcunov
28032a027c output/elfcommon.h: tab/space cleanup
No change on binary level

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-09-06 15:25:35 +04:00
Cyrill Gorcunov
7ea1ef1c84 output/outelf32.c: code style simplification
1) nasm_free is safe against NULL passed so call
   it without test

2) dwarf32_output: check for debug_immcall early
   and get out of procedure if success. This allow
   us to move code blocks left removing indents.

3) dwarf32_findfile and dwarf32_findsect: no need
   for 'else' when 'if' target is plain return.
   Move code blocks left removing indents.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-09-03 20:16:28 +04:00
Cyrill Gorcunov
6ae5903676 output/outelf32.c: tab-space cleanup
Together with a small style nitpicking.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-09-03 20:02:33 +04:00
Cyrill Gorcunov
82a440da6d output/elf64.h: tab-space cleanup
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-09-03 19:10:55 +04:00
Cyrill Gorcunov
c5e7878943 output/elf32.h: tab-space cleanup
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-09-03 19:06:04 +04:00
Cyrill Gorcunov
2cff224e4b output/outelf.h - tab-space cleanup
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-09-03 19:04:23 +04:00
Victor van den Elzen
0dd450c0ef Use fputs instead of fprintf for plain strings
LLVM's Clang warns about this. outieee.c had a real problem.
2009-08-13 15:07:59 +02:00
Victor van den Elzen
15bb233036 Fix some format strings for nasm_error
Added a format attribute to nasm_error (only for GCC) and
used the resulting warnings to fix some format strings.
2009-08-11 02:43:41 +02:00
Cyrill Gorcunov
5a49e7c578 output/dwarf.h: update dwarf constants
There is a hope we'll be supporting dwarf in full form in future. So
I've encoded the standard constants (though binutils uses some
additional codes).

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-08-10 16:00:43 -07:00
H. Peter Anvin
767750b666 output: change null_debug_routine to null_debug_directive
This is the null implementation of the function debug_directive.  For
some reason it ended up getting mangled as "null_debug_routine".

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-08-09 13:04:13 -07:00
Cyrill Gorcunov
6f742649fe output/outbin.c -- use list helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-08-01 23:52:25 +04:00
Cyrill Gorcunov
a95a76a868 outaout.c -- use list helpers
Note that we use list_for_each(var,var) sometime
which actually brings in at least one redundant
assignment in case of NULL being passed but save
us a few lines of code.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-07-28 23:26:12 +04:00
H. Peter Anvin
e39dc8c5b2 Merge branch 'nasm-2.07.xx' 2009-07-26 15:31:59 -07:00
H. Peter Anvin
7ad24562dc BR 2827397: fix invalid C in outcoff AddExports()
The construct:

         if (i == nsects)
             directive_sec =
                 sects[coff_make_section
                       (EXPORT_SECTION_NAME, EXPORT_SECTION_FLAGS)];

... where coff_make_section() can change the global variable "sects"
is undefined C, since there is no sequence point involved in the []
operator, and it is therefore fully permitted for the C compiler to
read the sects variable first.  Change this construct into two
statements to enforce defined behavior; this also ends up with the
code slightly simpler.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-26 15:29:09 -07:00
H. Peter Anvin
605f5155ee Drop the ofmt and errfunc arguments to label definition functions
We never set ofmt and errfunc to anything but the global values.
Dropping them from the label definition function command line
simplifies the code.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-18 18:43:58 -07:00
H. Peter Anvin
9bd1506d59 Remove function pointers in output, simplify error handling
Remove a bunch of function pointers in the output stage; they are
never changed and don't add any value.  Also make "ofile" a global
variable and let the backend use it directly.

All we ever did with these variables were stashing it in locals and
using them as-is anyway for no benefit.

Also change the global error function, nasm_error() into a true
function which invokes a function pointer internally.  That lets us
use direct calls to it.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-18 18:43:12 -07:00
H. Peter Anvin
159178f2aa Merge commit 'nasm-2.07rc7' into new-preproc 2009-07-17 00:55:17 -04:00
H. Peter Anvin
a5fd1ca895 outcoff: fix invalid reference to ofmt
ofmt is a static in nasm.c (why?), not a global...

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-16 22:46:34 -04:00
H. Peter Anvin
d1904c6cbb outcoff: this is COFF, not binary
Fix error message in outcoff to say COFF, not binary format...

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-16 22:44:19 -04:00
Keith Kanios
e5b9d2dac0 outform.h: update comments regarding macho32/macho64 2009-07-16 21:13:10 -05:00
H. Peter Anvin
68bec0872f outobj: don't fclose() the output
Missed fclose() in outobj when converting system to global fclose().

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-14 14:47:04 -04:00
H. Peter Anvin
340ee009d6 Merge branch 'master' into new-preproc
Conflicts:
	.gitignore
2009-07-13 21:41:33 -04:00
H. Peter Anvin
2a3154c4d3 ELF: add debug support for TY_YWORD
Add debug support for TY_YWORD (256 bits/32 bytes).

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-13 21:25:36 -04:00
Cyrill Gorcunov
e3042cb103 elf32: debug32_typevalue - fix TY_OWORD size
TY_OWORD is 8 * TY_WORD = 16 bytes length

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-13 17:19:21 -04:00
H. Peter Anvin
afa06137fa Hash even backend-specific directives, unify null functions
Hash all directives, even the ones that are backend-specific,
and instead pass the backend an already-parsed directive number.

Furthermore, unify null functions across various backends.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-12 12:55:24 -07:00
H. Peter Anvin
d0fbb7f0ab Don't fclose() the output in the backend
We fopen() the output file in common code but fclose() it in the
backend.  This is bad for a variety of reasons:

1. it is generally an awkward interface to change ownership.
2. we should use ferror() to test for write errors, and that is
   better done in common code.
3. it requires more code.
4. we still need to fclose() in common code during error handing.

Thus, move the fclose() of the output out of the backends, and add
fflush() so we can test ferror() on output.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-12 12:15:35 -07:00
Keith Kanios
6d0d0d2736 macho64: Manually merge macho64 branch with master branch. 2009-07-08 23:04:52 -05:00
Keith Kanios
745560e65a outmacho.c: fix section/relocation alignment issue 2009-07-07 23:09:22 -05:00
H. Peter Anvin
5bc87609d2 outdbg: be excrutiatingly correct...
outdbg is actually a good starting point to make a new backend, so we
really should endeavor to make it do things "right".

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-07 10:27:51 -07:00
H. Peter Anvin
62c0e8379c outdbg: fix OUT_REL*ADR, add OUT_REL8ADR
The OUT_REL*ADR types pass a pointer which points to an int64_t
which then should be truncated down to size.  This matters on
bigendian platforms.

Add OUT_REL8ADR.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-07 10:24:52 -07:00
H. Peter Anvin
215086ace8 outbin: be consistent in spelling "Intel hex" with those caps
The documentation uses "Intel hex", with that capitalization (Intel
being a proper noun, hex being descriptive) so make the help message
match.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-06 23:37:00 -07:00
Keith Kanios
5051c63d7e outmacho: fixed section/relocation alignment issue 2009-07-06 21:07:15 -05:00
H. Peter Anvin
8ee2e244eb NASM: relicense under the 2-clause BSD license
*To the best of my knowledge*, we now have authorization from everyone
who has significantly contributed to NASM in the past.  As such,
change the license to the 2-clause BSD license.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-06 11:09:11 -07:00
H. Peter Anvin
0bc3bf61db outbin: minor cleanups
- add assert so we don't try to write 2^64 bytes of zero
- explicitly track the Intel hex "LBA" (64K page) instead of playing
  games with the last byte written.  This way it is more explicit
  what we're doing and why.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-06 10:58:37 -07:00
H. Peter Anvin
ffe782a322 outbin: when using saa_rnbytes() we have to saa_rewind()
Using saa_fpwrite() to dump a section to a file automatically does
saa_rewind(), but if we use saa_rnbytes() to do bit by bit then we
manually need to to saa_rewind() before we start.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-05 15:40:45 -07:00
H. Peter Anvin
31f336183c outbin: when writing S-records, write head record
When writing S-record output, we should write the head record (S0),
too.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-05 15:32:14 -07:00
H. Peter Anvin
4660a2b4a0 outbin: add support for Intel hex and Motorola S-records
Add support for directly generating Intel hex or Motorola S-records.
These formats are commonly used with ROM burners.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-05 15:29:55 -07:00
H. Peter Anvin
0cba107579 Make it possible for outputs to be either text or binary
Allow the backend to specify that an output format is either text or
binary.  For future uses, define this as a flag word so we can define
other flags in the future if it would make sense.

Currently, the ieee and dbg formats are text; all the others are
binary.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-05 14:45:12 -07:00
H. Peter Anvin
d3544ff534 outobj: handle the case of SEG <undefined> in pass 0
SEG <undefined> can happen, validly, for a common symbol during the
optimization passes.  It better not happen during the real passes,
however!

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-01 22:04:11 -07:00
H. Peter Anvin
8beadd4da8 outmacho: change license to 2-BSD
Received authorization from Apple to change the license of outmacho.c
to the 2-clause BSD license.  Thanks!

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-30 21:17:07 -07:00
Cyrill Gorcunov
2118261e1a ELF64: fix incorrect type for the .strtab section header
The .strtab section is SHT_STRTAB, not SHT_SYMTAB.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-30 14:09:39 -07:00
H. Peter Anvin
d7392ad814 Add new copyright headers to the output modules
Add new copyright headers to the new output modules.  As far as I
know, the only module which we still don't have a green light to
release under 2-BSD is outmacho.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-28 17:25:15 -07:00
H. Peter Anvin
b45b21b411 Add copyright headers to macro files
These are definitely overly restrictive, need auditing to pare them
down to proper BSD licensing.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-28 17:16:54 -07:00
H. Peter Anvin
69925e5b78 Move prototypes for null_debug to outform.h and outlib.h
Move the prototypes for the null debugging format to outform.h (for
the top-level structure declaration only) and outlib.h (for the
internal routines.)

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-27 22:15:25 -07:00
H. Peter Anvin
31b707bef0 Move backend-specific code to output/; break out null debug stuff
Move backend-specific code into the output/ directory, and make the
null debugging backend a separate file (it certainly isn't needed for
ndisasm...)

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-27 22:07:33 -07:00
H. Peter Anvin
2b1f51f1ca debug: make *all* the null debug routines available as a library
Make all the null debug routines available as a library, so we can use
them whenever appropriate.  We really don't need to have a bunch of
dummy functions scattered all over the code.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-27 21:58:21 -07:00
H. Peter Anvin
2d115448b4 output: call debug init from a central location
We already call current_dfmt->init in the same place (at the very end
of ofmt->init) in all the backends that do it; instead call it
centrally in nasm.c after ofmt->init.

This fixes invalid ELF files with when compiling with -F dwarf, since
the dwarf initialization routine never got called.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-27 21:55:31 -07:00
H. Peter Anvin
0638193769 outelf.c: add appropriate #ifdefs
Only build outelf.c if ELF32 or ELF64 is included.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-27 21:10:09 -07:00
H. Peter Anvin
28abe7ada5 outdbg: make outdbg.c compile cleanly
Make outdbg.c compile cleanly again.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-27 21:05:42 -07:00
H. Peter Anvin
a564a02788 ELF: make debugging functions static
The debugging functions can and should all be static.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-25 17:43:54 -07:00
H. Peter Anvin
ca2a788edf ELF: remove loop invariant calculation of global offset
The global symbol offset is a loop invariant; no need to compute it
over and over.  The compiler probably will not be able to do this for
us due to global variables and function calls.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-25 17:30:58 -07:00
H. Peter Anvin
559d936ad7 ELF: clean up the arithmetic for global symbols
Clean up the arithmetic for global symbols; in particular, make it
clear where the dependency on the debug format comes from (DWARF needs
three symbol table entries all by itself.)

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-25 17:26:43 -07:00
H. Peter Anvin
3716238058 ELF: bump GLOBAL_TEMP_BASE
Bump GLOBAL_TEMP_BASE so far that it *cannot* conflict for ELF32
(which has 24-bit symbol table indicies) and is *unlikely* to conflict
for ELF64 (which has 32-bit symbol table indicies.)

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-25 17:25:35 -07:00
H. Peter Anvin
c4471462dc ELF: eliminate hard-coded section numbers
Eliminiate hard-coded section numbers, at least to the best of our
ability.  There is still a very odd piece of computation in
elf_build_reltab() which I can't really figure out...

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-25 14:54:44 -07:00
H. Peter Anvin
1acf6ba822 Handle the new ELF headers in the dependency generation
The dependency machinery relies on properly rooted includes, so give
it to them... the path syntax munging machinery in the dependency
script handles it from a Makefile syntax perspective, and then we can
hope that C compilers are smart enough to deal with forward-slash
paths even when that is not the native syntax.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-25 13:06:49 -07:00
H. Peter Anvin
d219a3e46f ELF: add header files, begin merging common code, drop .comment
Add something approaching real ELF header files.

Begin merging the common ELF code, beginning with the section name
detection.

Drop automatic generation of .comment section, and in particular the
treatment of .common as a special section (if we decide generating
.comment is still a good idea, we should just do it as a macro.)

Augment the list of known sections, and make it table-driven.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-25 12:30:50 -07:00
H. Peter Anvin
34c768fcc5 outbin: replace fprintf(rf, not_defined); with fputs(not_defined, rf);
Some vendors get nervous about parameterized printf patterns;
furthermore, it's completely unnecessary in this case.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-04-30 08:06:25 -07:00
Andy Polyakov
08ced1d5b4 outcoff: BR 2685756: fix SAFESEH with an internal symbol
Fix the SAFESEH directive for the specific case of a symbol internal
to the program.  With the optimizer enabled, it would otherwise fail
unless the symbol is external.
2009-03-18 14:49:23 -07:00
Michael Scherer
92cb18f2a8 outelf32/64: fix uninitialized rbtree
Fix crash caused by uninitialised memory that lead to dangling pointer
in the rbtree. This can be seen by compiling zsnes 1.50, with a file
that define many symbols, such as fxemu2c.asm.
2009-03-18 14:47:33 -07:00
H. Peter Anvin
577f57614a outelf32/64: remove align_str in favor of fwritezero()
Drop the use of yet another local all-zero buffer, align_str, in favor
of calling fwritezero().
2009-02-21 17:27:51 -08:00
H. Peter Anvin
a5c2455f8a outbin: fix typo: "sections" not "section"
Fix silly typo: the variable is "sections" not "section"...
2009-02-21 17:27:13 -08:00
H. Peter Anvin
999868f06f Unify all-zero buffers; add fwritezero()
We have a number of all-zero buffers in the code.  Put a single
all-zero buffer in nasmlib.c.  Additionally, add fwritezero()
which can be used to write an arbitrary number of all-zero bytes;
this prevents the situation where the all-zero buffer is simply
too small.
2009-02-21 17:24:08 -08:00
H. Peter Anvin
04616f4e85 BR 2611906: proper error message for start < origin
When a section other than .text has a start < origin, we would
segfault; fix that.

Furthermore, at bin_cleanup() we don't have usable file/line
information, so pass ERR_NOFILE to the error() function.  Perhaps less
than ideal, but better than printing a null pointer.
2009-02-21 17:19:05 -08:00
Charles Crayne
cc88d658ce Generate warning for unknown section atributes
Previously, the ELF backends silently ignored incorrect or unknown
attributes on section declarations, and therefore used default values
in cases where the user had make an error in attempting to specify
custom values.
2009-01-18 15:27:03 -08:00
H. Peter Anvin
f5fb723495 outas86: slight stylistic cleanups
Minor stylistic cleanups to previous patch.
2009-01-03 17:56:41 -08:00
Soronel Haetir
e07949dc3f Add entry point support to as86 backend
I needed entry point support with the as86 format, and after looking through
the archives found a similar desire from someone in 2002.  For some reason
such a patch never made it into the code, even though the required flag
value is present, so I offer the a patch of my own.

I compared against what is done in the .obj format and the approaches are
quite similar which I hope will aid in its acceptability.  While I have
tested it extensively it does do the job asked, and I'm honestly not sure
what extensive testing of the change would look like.
2009-01-03 17:54:48 -08:00
David DeHaven
74a8755fe3 Mach-O alignment fix
Several projects have taken to using .text to store read-only data
when building on Mac OS X due to crashes in SSE code from the .rodata
section being mis-aligned. It seems there was a misunderstanding about
how ld/ld64 handles section alignment in outmacho.c so I wrote a patch
to fix it. I tested it against x264 git, modified it to use ".rodata
align=16" for the data section and use movdqa instructions (guaranteed
to crash when built with unpatched nasm) and it passed all tests in
its checkasm tool.

If you want more data I can provide, but it's late and I've had a
couple glasses of mulled wine :)

-DrD-
2008-12-18 14:58:24 -08:00
H. Peter Anvin
1fee7d2d23 ELF: use rbtree for symbol searches
Linear searches are evil, so use an llrbtree to search for symbols by
offset.  This doesn't change the preexisting behaviour that we only
look for global symbols.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-11-06 19:55:05 -08:00
Victor van den Elzen
f568613c2a Fix BR #916647
nasm.c should respect the default debug format of the output format,
instead of replacing it with the first format in the list.
This is cleaner and allows the list to be sorted normally.

This commit rewrites commit 116994111b which was very fragile.
2008-11-05 14:19:15 +01:00
Charles Crayne
5fb6a39bc9 ELF32 support for offset to IE GOT entry
Add new WRT type ..tlsie.
Generate R_386_TLS_IE relocation entries
for references to thread local variables.
2008-11-01 16:48:31 -07:00
H. Peter Anvin
4b9358928b Move all version strings to a single compilation unit (ver.c)
Move all the version strings to a single compilation unit, ver.c; this
does not include the version macros, which are fed into macros.c.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-31 16:53:49 -07:00
Charles Crayne
dcd3a21145 ELF32 bit support of .tdata and .tbss sections
Set default attributes for .tdata and .tbss sections
Implement new attribute 'tls' for arbitrary section names
Flag variables in sections with tls attribute with STT_TLS
2008-10-30 21:59:42 -07:00
H. Peter Anvin
03c4f90afa output: add common file outlib.c for common functions; realsize()
Add a common file, outlib.c, for output formats.  Add the function
realsize() instead of open-coded variants in almost every backend.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-27 22:19:59 -07:00
Charles Crayne
10a863d87e ELF64 support for PC relative offset to IE GOT entry
Add new WRT type ..gottpoff.
Generate R_X86_64_GOTTPOFF relocation entries
for references to thread local variables.
2008-10-26 17:32:38 -07:00
Charles Crayne
efb515b98e Flag thread local symbols in symbol table
Set STT_TLS in symbol table for symbols declared
in thread local storage sections. Note that,
for now at least, such symbols must also be
declared as GLOBAL.
2008-10-25 19:31:09 -07:00
Charles Crayne
4adf21c08c ELF64 segment definitions for TLS
Add default definitions for .tdata & .tbss sections
Add definition for SHF_TLS section header flag
Add support for "tls" keyword on section statement
2008-10-25 15:23:30 -07:00
H. Peter Anvin
9cd543e5fd BR 2148448: fix relative addresses in bin output
The "bin" format was misinterpreting the overloading of the "size"
argument to out(), which caused another source of 64-bit relative
offset errors.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-22 11:05:43 -07:00
H. Peter Anvin
21da3006b5 ELF64: once again, fix generation of "naked" OUT_REL*ADR
It is unclear if we will ever see any "naked" (absolute bytes)
OUT_REL*ADR coming from the assembler, but if we do, we should
generate them correctly.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-18 11:29:11 -07:00
H. Peter Anvin
2a282275fe ELF64: PLT32, GOTPCREL, and GOTPCREL64 really need exactitude
Now when the assembler is properly generating the address that we push
down to the backend, enable requesting an exact value for these
relocations (these are pointing to a specific GOT or PLT slot; the
addend is used to adjust the computed value in the instruction, not
for offset for the symbol.)

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-17 23:32:40 -07:00
H. Peter Anvin
7f1315070e ELF64: the "size" argument to OUT_REL*ADR isn't really the size
The "size" argument to the OUT_REL*ADR output types is actually
intra-instruction offset, not the actual size.  Thus, emit the size
properly.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-17 23:30:54 -07:00
H. Peter Anvin
d5e7498556 ELF64: actually generate relative GOT/PLT references correctly
Fix the arithmetic for relative GOT/PLT references.

We still can't enable exactitude, because of the assumption that
"size" is always the proper adjustment for the offset of the
displacement inside the instruction, which is wrong in the case of
displacements that are followed by an immediate.  This also affects
the list file, so it really should be fixed.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-17 23:06:46 -07:00
H. Peter Anvin
8218572d5e ELF64: GOTOFF64 doesn't need a gsym at all
GOTOFF64 is used for local variables (as a 64-bit offset from the GOT;
only needed in the Medium PIC or Large PIC models.)  It therefore
should *not* be a elf_add_gsym_reloc() invocation.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-17 22:22:17 -07:00
H. Peter Anvin
bdfd3b3b87 ELF64: We apparently don't need exactitude for GOTOFF64
I am having a bit of a hard time understanding the proper operation of
the "exact" flag to elf_add_gsym_reloc().  We apparently won't
generate proper GOTOFF64 relocations with this flag set; it is
possible that there are *no* proper uses of this flag.  This clearly
needs to be figured out.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-17 22:11:20 -07:00
H. Peter Anvin
70e6c2a6cb ELF64: GOT and PLT references need a symbol (a slot!) to reference
GOT and PLT references need a symbol; after all, they reference a GOT
or PLT slot.  Thus, they need elf_add_gsym_reloc().  Mungify the
interface so that they can communicate the need for the PC-shifted
offset into the relocation.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-17 20:01:16 -07:00
H. Peter Anvin
8140afbaf1 ELF64: unbreak generating no-segment addresses
When generating an address that is *not* tied to a symbol, we just
want to emit the bytes.  I believe the assembler is already supposed
to do that for us, but just in case, do it right here too.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-17 19:32:10 -07:00
H. Peter Anvin
64fa04f019 ELF64: use the RELA addend field instead of relying on the code stream
The x86-64 ABI wants the symbol addend to reside in the addend field
of the RELA relocation, not in the code stream.  Apparently it's
something one can get away with, but the linker would still botch it
for some cases.  Change it so we pass the proper output and emit zero
into the code stream.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-17 18:23:29 -07:00
H. Peter Anvin
c3cea48430 ELF64: fix various GOT relocations
Try to make the various GOT relocations do the right thing in ELF64,
including erring out when appropriate.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-15 15:23:18 -07:00
Charles Crayne
154f6f2380 Fix typo in previous outelf64.c commit
Stray line fragment left in when removing debug code.
2008-10-12 14:14:45 -07:00
Charles Crayne
cff8dc6d6b RIP rel relocations for PIC released for testing.
Expressions like
  mov	r15,[rel integer wrt ..got]
  lea   rax,[rel integer wrt ..gotoff]
now assemble correctly.

In addition, a fix has been made to the corresponding
abs relocations.

Both of these areas still need additional testing.
2008-10-12 14:00:11 -07:00
H. Peter Anvin
5618e0063d outaout.mac: aoutb is an alias for aout
aoutb is an alias format for aout (in the sense they use the same
macro set.)

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-09-09 09:53:20 -07:00
H. Peter Anvin
c357381da4 macros: win32 and win64 are COFF, not Mach-O
Somehow the win32 and win64 aliases got listed on Mach-O, not on
COFF.  This doesn't have any effect on the current code, but might in
the future.  Correct.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-09-09 09:37:37 -07:00
H. Peter Anvin
fafb6a50e2 outcoff: stylistic cleanups
Don't use explicit L's for things which are really size_t; not only is
it unnecessarily ugly, but it's wrong in a lot of ways.  Do some other
minor stylistic cleanups.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-09-02 12:56:39 -07:00
H. Peter Anvin
c00c897df7 outcoff: default output symbols to T_NULL
We would leave the output symbol type uninitialized.  Explicitly
initialize it to zero (T_NULL, meaning no symbol type information),
since that's what was effectively done.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-09-02 12:55:35 -07:00
Slavik Gnatenko
1b67bd25b2 BR 2010180: outobj: Garbage may be written in a last PUBDEF
The testcase illustrates the problem. After "nasm -f obj
alonesym.nasm"
let's look to dump:

======
PUBDEF386(91) recnum:5, offset:0000005bh, len:03f9h, chksum:bbh(bb)
Group: 0, Seg: 1
00020000h - 'sym0000' Type:0
00020004h - 'sym0001' Type:0
....
00020134h - 'sym0077' Type:0

PUBDEF(90) recnum:6, offset:00000457h, len:000ah, chksum:b6h(b6)
Group: 0, Seg: 1
00000138h - 's' Type:2
0000b600h - '' Type:0
======

The problem is while 's' offset is 20138h it is marked as type 90h not
91h.  The root cause is located in obj_x():

static ObjRecord *obj_x(ObjRecord * orp, uint32_t val)
{
    if (orp->type & 1)
    	orp->x_size = 32;
    if (val > 0xFFFF)
        orp = obj_force(orp, 32);
    if (orp->x_size == 32)
        return (obj_dword(orp, val));
    orp->x_size = 16;
    return (obj_word(orp, val));
}

It sets up x_size and than writes data. In the testcase data are the
offset and this offset overflows a record. In this case the record is
emitted and its x_size is cleared. Because this is last PUBDEF the new
record with only 's' symbol is emitted also but its x_size is not 32
(it's still zero) so obj_fwrite doesn't switch to 91h type.

The problem seems to be very generic and expected to be occurred on
many other record types as well.

        ----

And the fix is simple:

if (orp->x_size == 32)
{
  ObjRecord * nxt = obj_dword(orp, val);
  nxt->x_size = 32; /* x_size is cleared when a record overflows */
  return nxt;
}
2008-07-19 19:27:41 -07:00
H. Peter Anvin
bda7a6e371 ctype.h: wrapper ctype functions with a cast to (unsigned char)
ctype functions take an *int*, which the user is expected to have
taken the input character from getc() and friends, or taken a
character and cast it to (unsigned char).

We don't care about EOF (-1), so use macros that cast to (unsigned
char) for us.
2008-06-21 10:23:17 -07:00
H. Peter Anvin
cfb7176ca2 Move the output format macros into the macros.pl mechanism
Move the handling of "extra" macros (i.e. output format macros) into
the macros.pl mechanism.  This allows us to change the format of the
internal macro store in the future - e.g. to a single byte store
without redundant pointers.

Also, stop using indicies into a long array when there is no good
reason to not just use different arrays.
2008-06-20 15:20:16 -07:00
Charles Crayne
842da0ad0b Correct X86_64 reference in dwarf support message 2008-06-11 16:15:01 -07:00
H. Peter Anvin
fcb8909749 Move all the RAA code out of nasmlib
The RAA code doesn't have to be in nasmlib; it is only used by nasm
itself, and is better handled in a separate module.
2008-06-09 17:40:16 -07:00
H. Peter Anvin
1803dedae8 Move all the SAA code out of nasmlib
Move all the SAA code out of nasmlib; it's not used by anything than
nasm itself.  Cleaning out the kitchen sink known as nasmlib is a good
thing, too.
2008-06-09 17:32:43 -07:00
H. Peter Anvin
c735d1a6b2 Replace the WSAA macros with functions
Change the WSAA macros into functions; reducing the icache footprint.
2008-06-08 21:15:01 -07:00
H. Peter Anvin
cb38f505e4 WSAA: make the WSAA macros contain their own buffer
Make the WSAA macros contain their own buffer definitions.  This
eliminates the need to have a separate "workbuf" declared in the
outelf backends, which isn't even used for anything else, except for a
few completely redundant strcpys.

Note: these macros probably should be replaced with actual
functions.  The overhead of the function call is likely to be more
than offset by lower icache footprint.
2008-06-08 18:39:55 -07:00
Charles Crayne
2d900f5488 Avoid obscure segfault in DWARF generation
If DWARF debugging info is requested, and no section
is marked executable, output empty debug sections,
instead of allowing assembler to segfault.
2008-06-05 16:12:06 -07:00
Andy Polyakov
082dbb471f outcoff.c: remove dead code, add check for imagerel
Remove commented-out (dead) code, add check that the imagerel
references are valid.
2008-05-27 14:01:25 -07:00
Andy Polyakov
94cd4dd113 Win64: IMAGEREL references (SEH support for Win64)
Guess what, SEH again, but in Win64 context, which is completely
different matter from Win32. At lowest level this one boils down to
putting so called imagerel references, or in practical terms
relocations of type ADDR32NB, 0x0003, into .pdata and .xdata
segments. Two possibilities. 1. implement say 'wrt ..imagerel' or 'wrt
..imagebase'. 2. silently enforce ADDR32NB relocations in .pdata and
.xdata segments.
2008-05-23 19:45:39 -07:00
H. Peter Anvin
45b7431a0c Make SAFESEH syntax error ERR_NONFATAL
Incorrect use of SAFESEH is more suited for ERR_NONFATAL than ERR_FATAL
2008-05-23 18:38:51 -07:00
Andy Polyakov
4401cc79a2 Support for Win32 safeseh (BR 195417)
This is basically not a bug report, but a feature request.

It's desired to be able to link .obj modules compiled with 'nasm -f
win32' with Microsoft 'link /safeseh'. As well as to register symbols
(commonly subroutine's entry points or even external symbols) as "safe
handlers." In order to achieve this, several points are required.

First of all, object module has to have absolute symbol named @feat.00
with value of 1. This can actually be achived by adding 'absolute 1'
and '@feat.00:' to source code, but it's desirable that it's
autogenerated for win32 modules.

Handler registration is essentially symbol's *index* in current
module's symbol table in .sxdata, segment with 0x200 segment flags, an
"info" segment. It's also essential that symbol has type 0x20 (see
below). All this is depicted in following framgents of 'objdump -xD'
output:

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .sxdata       00000004  00000000  00000000  0000003c  2**2
                  CONTENTS, READONLY, DEBUGGING

SYMBOL TABLE:
...
[  5](sec -1)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00000001 @feat.00
[  6](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _handler
...
<.sxdata>
0: 06 00 00 00

Note [6] and (ty 20) in _handle line in SYMBOL TABLE. "06 00 00 00" in
.sxdata is little-endian 6, _handler's index. This is what makes up
"registration." It's impossible to achieve this with current nasm
facilities and it's probably appropriate to introduce a directive for
it, 'safeseh _handler' is probably most natural choice.
2008-05-23 18:37:52 -07:00
H. Peter Anvin
72ec0e4144 Temporaries in macros need a unique prefix; WSAA*() macros to header
When using temporaries in macros, given them a unique prefix to avoid
namespace collisions when using one macro inside another.

Move the WSAA*() macros from outelf32/outelf64 to a separate header
file.
2008-04-10 14:56:09 -07:00
Charles Crayne
6f15b9884e Correctly identify dwarf support for elf32
Change architecture tag to i386.
2008-04-07 13:15:53 -07:00
Charles Crayne
aed5cfea58 Adjust symbol number for global symbols
Reloc entries were pointing to wrong target section
2008-03-04 14:25:34 -08:00
Charles Crayne
90131d500b Report dwarf as V2 for ELF32
Older versions of gdb reject version 3
2008-02-24 21:05:46 -08:00
Charles Crayne
225f82fa12 Dwarf3 support for ELF32
1. Port dwarf3 support from ELF64 to ELF32
2. Move common SAA extentions to nasmlib
2008-02-24 19:14:17 -08:00
Charles Crayne
986312b17a Dwarf support tweeks and clean-up
1. Add relocation entries for dwarf sections.
2. Combine common dwarf and stabs routines.
2008-02-23 18:35:11 -08:00
H. Peter Anvin
338a3b6882 Clear up WRITE macros causing compile failures with Watcom
The OpenWatcom compiler warns about invalid shifts (correctly, it
appears) due to the non-X86_MEMORY versions of the various WRITE
macros.  Fix.
2008-02-16 15:25:02 -08:00
Charles Crayne
f0b43d212e Upgrade dwarf3 support for elf64
Add support for multiple executable segments
2008-02-13 19:58:54 -08:00