Commit graph

50 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Beroset
095e6a2973 regularized spelling of license to match name of LICENSE file 2007-12-29 09:44:23 -05:00
H. Peter Anvin
682221438e Clean up remaining build warnings
Clean up remaining build warnings.  None of this should affect code
operations.  The only warnings which were actually relevant might have
been the ones in ldrdf.c, but it's not clear if anyone ever uses that.
2007-11-18 22:18:09 -08:00
H. Peter Anvin
d1fb15c154 Address data is int64_t; simplify writing an address object
Address data is always int64_t even if the size itself is smaller;
this was broken on bigendian hosts (still need testing!)

Create simple "write sized object" macros.
2007-11-13 09:37:59 -08:00
H. Peter Anvin
34f6fb0a65 Don't combine type and size into a single argument
Don't combine type and size into a single argument; *every* backend
immediately breaks them apart, so it's really just a huge waste of
effort.  Additionally, it avoids using short immediates in the
resulting code, which is a bad thing.
2007-11-09 14:44:02 -08:00
Charles Crayne
8c7eca4936 Pass 64-bit instruction lengths to back-ends. 2007-11-06 21:48:12 -08:00
Charles Crayne
4e8563d5c4 Upgrade label functions to 64-bit 2007-11-05 17:19:32 -08:00
H. Peter Anvin
7065309739 Formatting: kill off "stealth whitespace"
"Stealth whitespace" makes it harder to read diffs, and just generally
cause unwanted weirdness.  Do a source-wide pass to get rid of it.
2007-10-19 14:42:29 -07:00
H. Peter Anvin
70055964fc Additional uses of bool and enum
Proper use of bool and enum makes code easier to debug.  Do more of
it.  In particular, we really should stomp out any residual uses of
magic constants that aren't enums or, in some cases, even #defines.
2007-10-11 00:05:57 -07:00
H. Peter Anvin
6867acc18e Use the compiler-provided booleans if available, otherwise emulate
Both C and C++ have "bool", "true" and "false" in lower case; C
requires <stdbool.h> for this, in C++ it is an inherent type built
into the compiler.  Use those instead of the old macros; emulate with
a simple typedef enum if unavailable.
2007-10-10 14:58:45 -07:00
H. Peter Anvin
fe501957c0 Portability fixes
Concentrate compiler dependencies to compiler.h; make sure compiler.h
is included first in every .c file (since some prototypes may depend
on the presence of feature request macros.)

Actually use the conditional inclusion of various functions (totally
broken in previous releases.)
2007-10-02 21:53:51 -07:00
H. Peter Anvin
74cc5e569c Finishing touches on perfect hash tokenizer; actually turn the thing on
Finish the perfect hash tokenizer, and actually enable it.

Move stdscan() et al to a separate file, since it's not needed in any
of the clients of nasmlib other than nasm itself.

Run make alldeps.
2007-08-30 22:35:34 +00:00
Keith Kanios
8b2a72881c Fixed obj_fwrite() declaration to match "static" definition. 2007-04-13 22:07:53 +00:00
Keith Kanios
a6dfa78b78 Fixed distinction between char and int8_t data types. 2007-04-13 16:47:53 +00:00
Keith Kanios
b7a89544d0 General push for x86-64 support, dubbed 0.99.00. 2007-04-12 02:40:54 +00:00
Frank Kotler
f3071da71e fix outobj.c bug - every 256th extern crashed nasm
-
2005-06-08 16:41:10 +00:00
H. Peter Anvin
e2c80181b6 Apply Nindent to all .c and .h files 2005-01-15 22:15:51 +00:00
Stanislav Karchebny
d52236c00e Revert erroneous macro added and modify __OUTPUT_FORMAT__ to a string const 2003-09-25 11:43:28 +00:00
Stanislav Karchebny
5e8f36611f Consistency fix 2003-09-25 11:28:45 +00:00
Stanislav Karchebny
88a049aca1 Added _NASM_FORMAT_ macro 2003-09-24 10:30:56 +00:00
H. Peter Anvin
c9f57c24d0 Fixes from Bart Oldeman 2002-09-19 04:27:01 +00:00
H. Peter Anvin
bfebdb0a07 "const"-ipation fixes from Trevor Woerner 2002-09-12 02:23:54 +00:00
H. Peter Anvin
8215a54b21 Fix off-by-one error found when running theowl's test cases. 2002-05-26 23:48:09 +00:00
H. Peter Anvin
310b3e165f Code cleanup fixes from Ed Beroset 2002-05-14 22:38:55 +00:00
H. Peter Anvin
8ff796d817 Fix from John Coffman to 16-bit OBJ format output. 2002-05-09 05:35:23 +00:00
H. Peter Anvin
8ac364139a NASM 0.98.30 2002-04-30 21:09:12 +00:00
Renamed from outobj.c (Browse further)