summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2017-04-20 01:39:42 -0700
committerH. Peter Anvin <hpa@zytor.com>2017-04-20 01:39:42 -0700
commitc2f371c0b99979a78d96af528c08722c1aff7bde (patch)
tree99e500fa4206c4dd57bfabdfe494ee5538eebb24
parent4d993a1c03a5371768daacd8a727f232e47ebbb9 (diff)
parentb68edcac72dc490bfba50bc144c0c6cce8c17b25 (diff)
downloadnasm-c2f371c0b99979a78d96af528c08722c1aff7bde.tar.gz
Merge branch 'master' of ssh://repo.or.cz/nasm
-rw-r--r--Makefile.in40
-rw-r--r--Mkfiles/msvc.mak35
-rw-r--r--Mkfiles/openwcom.mak35
-rw-r--r--doc/changes.src7
-rwxr-xr-xdoc/genps.pl6
-rw-r--r--include/nasmlib.h4
-rw-r--r--include/rdoff.h131
-rw-r--r--nasmlib/file.c12
-rw-r--r--output/outdbg.c2
-rw-r--r--output/outmacho.c486
-rw-r--r--rdoff/Mkfiles/Makefile.dj75
-rw-r--r--rdoff/Mkfiles/Makefile.emx76
-rw-r--r--rdoff/Mkfiles/Makefile.sc56
-rw-r--r--rdoff/Mkfiles/Makefile.unx75
-rw-r--r--rdoff/Mkfiles/README4
-rw-r--r--rdoff/collectn.c7
-rw-r--r--rdoff/hash.c4
-rw-r--r--rdoff/ldrdf.c93
-rw-r--r--rdoff/rdf2bin.c8
-rw-r--r--rdoff/rdfdump.c78
-rw-r--r--rdoff/rdflib.c21
-rw-r--r--rdoff/rdfload.c46
-rw-r--r--rdoff/rdfload.h4
-rw-r--r--rdoff/rdfutils.h165
-rw-r--r--rdoff/rdlar.c6
-rw-r--r--rdoff/rdlib.c26
-rw-r--r--rdoff/rdoff.c57
-rw-r--r--rdoff/rdx.c6
-rw-r--r--rdoff/segtab.c13
-rw-r--r--rdoff/symtab.c16
-rwxr-xr-xtools/release13
-rw-r--r--version2
32 files changed, 943 insertions, 666 deletions
diff --git a/Makefile.in b/Makefile.in
index ebe793ff..b377b79c 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -751,33 +751,41 @@ rdoff/collectn.$(O): rdoff/collectn.c config/config.h config/msvc.h \
rdoff/collectn.h
rdoff/hash.$(O): rdoff/hash.c config/config.h config/msvc.h config/unknown.h \
config/watcom.h include/compiler.h include/nasmint.h rdoff/hash.h
-rdoff/ldrdf.$(O): rdoff/ldrdf.c config/config.h config/msvc.h \
+rdoff/iochk.$(O): rdoff/iochk.c config/config.h config/msvc.h \
config/unknown.h config/watcom.h include/compiler.h include/nasmint.h \
- include/nasmlib.h include/rdoff.h rdoff/collectn.h rdoff/ldsegs.h \
- rdoff/rdlib.h rdoff/segtab.h rdoff/symtab.h
+ include/nasmlib.h
+rdoff/ldrdf.$(O): rdoff/ldrdf.c config/config.h config/msvc.h \
+ config/unknown.h config/watcom.h include/compiler.h include/error.h \
+ include/nasmint.h include/nasmlib.h include/rdoff.h rdoff/collectn.h \
+ rdoff/ldsegs.h rdoff/rdfutils.h rdoff/rdlib.h rdoff/segtab.h rdoff/symtab.h
rdoff/rdf2bin.$(O): rdoff/rdf2bin.c config/config.h config/msvc.h \
- config/unknown.h config/watcom.h include/compiler.h include/nasmint.h \
- include/nasmlib.h include/rdoff.h rdoff/rdfload.h
+ config/unknown.h config/watcom.h include/compiler.h include/error.h \
+ include/nasmint.h include/nasmlib.h include/rdoff.h rdoff/rdfload.h \
+ rdoff/rdfutils.h
rdoff/rdfdump.$(O): rdoff/rdfdump.c config/config.h config/msvc.h \
- config/unknown.h config/watcom.h include/compiler.h include/nasmint.h \
- include/rdoff.h
+ config/unknown.h config/watcom.h include/compiler.h include/error.h \
+ include/nasmint.h include/nasmlib.h include/rdoff.h rdoff/rdfutils.h
rdoff/rdflib.$(O): rdoff/rdflib.c config/config.h config/msvc.h \
- config/unknown.h config/watcom.h include/compiler.h include/nasmint.h
+ config/unknown.h config/watcom.h include/compiler.h include/error.h \
+ include/nasmint.h include/nasmlib.h include/rdoff.h rdoff/rdfutils.h
rdoff/rdfload.$(O): rdoff/rdfload.c config/config.h config/msvc.h \
- config/unknown.h config/watcom.h include/compiler.h include/nasmint.h \
- include/rdoff.h rdoff/collectn.h rdoff/rdfload.h rdoff/symtab.h
+ config/unknown.h config/watcom.h include/compiler.h include/error.h \
+ include/nasmint.h include/nasmlib.h include/rdoff.h rdoff/collectn.h \
+ rdoff/rdfload.h rdoff/rdfutils.h rdoff/symtab.h
rdoff/rdlar.$(O): rdoff/rdlar.c config/config.h config/msvc.h \
config/unknown.h config/watcom.h include/compiler.h include/nasmint.h \
rdoff/rdlar.h
rdoff/rdlib.$(O): rdoff/rdlib.c config/config.h config/msvc.h \
- config/unknown.h config/watcom.h include/compiler.h include/nasmint.h \
- include/rdoff.h rdoff/rdlar.h rdoff/rdlib.h
+ config/unknown.h config/watcom.h include/compiler.h include/error.h \
+ include/nasmint.h include/nasmlib.h include/rdoff.h rdoff/rdfutils.h \
+ rdoff/rdlar.h rdoff/rdlib.h
rdoff/rdoff.$(O): rdoff/rdoff.c config/config.h config/msvc.h \
- config/unknown.h config/watcom.h include/compiler.h include/nasmint.h \
- include/rdoff.h
+ config/unknown.h config/watcom.h include/compiler.h include/error.h \
+ include/nasmint.h include/nasmlib.h include/rdoff.h rdoff/rdfutils.h
rdoff/rdx.$(O): rdoff/rdx.c config/config.h config/msvc.h config/unknown.h \
- config/watcom.h include/compiler.h include/nasmint.h include/rdoff.h \
- rdoff/rdfload.h rdoff/symtab.h
+ config/watcom.h include/compiler.h include/error.h include/nasmint.h \
+ include/nasmlib.h include/rdoff.h rdoff/rdfload.h rdoff/rdfutils.h \
+ rdoff/symtab.h
rdoff/segtab.$(O): rdoff/segtab.c config/config.h config/msvc.h \
config/unknown.h config/watcom.h include/compiler.h include/nasmint.h \
rdoff/segtab.h
diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak
index 8ddafdf0..d43e76e1 100644
--- a/Mkfiles/msvc.mak
+++ b/Mkfiles/msvc.mak
@@ -644,30 +644,37 @@ rdoff\collectn.$(O): rdoff\collectn.c config\msvc.h config\unknown.h \
config\watcom.h include\compiler.h include\nasmint.h rdoff\collectn.h
rdoff\hash.$(O): rdoff\hash.c config\msvc.h config\unknown.h config\watcom.h \
include\compiler.h include\nasmint.h rdoff\hash.h
+rdoff\iochk.$(O): rdoff\iochk.c config\msvc.h config\unknown.h \
+ config\watcom.h include\compiler.h include\nasmint.h include\nasmlib.h
rdoff\ldrdf.$(O): rdoff\ldrdf.c config\msvc.h config\unknown.h \
- config\watcom.h include\compiler.h include\nasmint.h include\nasmlib.h \
- include\rdoff.h rdoff\collectn.h rdoff\ldsegs.h rdoff\rdlib.h \
- rdoff\segtab.h rdoff\symtab.h
+ config\watcom.h include\compiler.h include\error.h include\nasmint.h \
+ include\nasmlib.h include\rdoff.h rdoff\collectn.h rdoff\ldsegs.h \
+ rdoff\rdfutils.h rdoff\rdlib.h rdoff\segtab.h rdoff\symtab.h
rdoff\rdf2bin.$(O): rdoff\rdf2bin.c config\msvc.h config\unknown.h \
- config\watcom.h include\compiler.h include\nasmint.h include\nasmlib.h \
- include\rdoff.h rdoff\rdfload.h
+ config\watcom.h include\compiler.h include\error.h include\nasmint.h \
+ include\nasmlib.h include\rdoff.h rdoff\rdfload.h rdoff\rdfutils.h
rdoff\rdfdump.$(O): rdoff\rdfdump.c config\msvc.h config\unknown.h \
- config\watcom.h include\compiler.h include\nasmint.h include\rdoff.h
+ config\watcom.h include\compiler.h include\error.h include\nasmint.h \
+ include\nasmlib.h include\rdoff.h rdoff\rdfutils.h
rdoff\rdflib.$(O): rdoff\rdflib.c config\msvc.h config\unknown.h \
- config\watcom.h include\compiler.h include\nasmint.h
+ config\watcom.h include\compiler.h include\error.h include\nasmint.h \
+ include\nasmlib.h include\rdoff.h rdoff\rdfutils.h
rdoff\rdfload.$(O): rdoff\rdfload.c config\msvc.h config\unknown.h \
- config\watcom.h include\compiler.h include\nasmint.h include\rdoff.h \
- rdoff\collectn.h rdoff\rdfload.h rdoff\symtab.h
+ config\watcom.h include\compiler.h include\error.h include\nasmint.h \
+ include\nasmlib.h include\rdoff.h rdoff\collectn.h rdoff\rdfload.h \
+ rdoff\rdfutils.h rdoff\symtab.h
rdoff\rdlar.$(O): rdoff\rdlar.c config\msvc.h config\unknown.h \
config\watcom.h include\compiler.h include\nasmint.h rdoff\rdlar.h
rdoff\rdlib.$(O): rdoff\rdlib.c config\msvc.h config\unknown.h \
- config\watcom.h include\compiler.h include\nasmint.h include\rdoff.h \
- rdoff\rdlar.h rdoff\rdlib.h
+ config\watcom.h include\compiler.h include\error.h include\nasmint.h \
+ include\nasmlib.h include\rdoff.h rdoff\rdfutils.h rdoff\rdlar.h \
+ rdoff\rdlib.h
rdoff\rdoff.$(O): rdoff\rdoff.c config\msvc.h config\unknown.h \
- config\watcom.h include\compiler.h include\nasmint.h include\rdoff.h
+ config\watcom.h include\compiler.h include\error.h include\nasmint.h \
+ include\nasmlib.h include\rdoff.h rdoff\rdfutils.h
rdoff\rdx.$(O): rdoff\rdx.c config\msvc.h config\unknown.h config\watcom.h \
- include\compiler.h include\nasmint.h include\rdoff.h rdoff\rdfload.h \
- rdoff\symtab.h
+ include\compiler.h include\error.h include\nasmint.h include\nasmlib.h \
+ include\rdoff.h rdoff\rdfload.h rdoff\rdfutils.h rdoff\symtab.h
rdoff\segtab.$(O): rdoff\segtab.c config\msvc.h config\unknown.h \
config\watcom.h include\compiler.h include\nasmint.h rdoff\segtab.h
rdoff\symtab.$(O): rdoff\symtab.c config\msvc.h config\unknown.h \
diff --git a/Mkfiles/openwcom.mak b/Mkfiles/openwcom.mak
index 7c626d34..b6468dd6 100644
--- a/Mkfiles/openwcom.mak
+++ b/Mkfiles/openwcom.mak
@@ -618,30 +618,37 @@ rdoff/collectn.$(O): rdoff/collectn.c config/msvc.h config/unknown.h &
config/watcom.h include/compiler.h include/nasmint.h rdoff/collectn.h
rdoff/hash.$(O): rdoff/hash.c config/msvc.h config/unknown.h config/watcom.h &
include/compiler.h include/nasmint.h rdoff/hash.h
+rdoff/iochk.$(O): rdoff/iochk.c config/msvc.h config/unknown.h &
+ config/watcom.h include/compiler.h include/nasmint.h include/nasmlib.h
rdoff/ldrdf.$(O): rdoff/ldrdf.c config/msvc.h config/unknown.h &
- config/watcom.h include/compiler.h include/nasmint.h include/nasmlib.h &
- include/rdoff.h rdoff/collectn.h rdoff/ldsegs.h rdoff/rdlib.h &
- rdoff/segtab.h rdoff/symtab.h
+ config/watcom.h include/compiler.h include/error.h include/nasmint.h &
+ include/nasmlib.h include/rdoff.h rdoff/collectn.h rdoff/ldsegs.h &
+ rdoff/rdfutils.h rdoff/rdlib.h rdoff/segtab.h rdoff/symtab.h
rdoff/rdf2bin.$(O): rdoff/rdf2bin.c config/msvc.h config/unknown.h &
- config/watcom.h include/compiler.h include/nasmint.h include/nasmlib.h &
- include/rdoff.h rdoff/rdfload.h
+ config/watcom.h include/compiler.h include/error.h include/nasmint.h &
+ include/nasmlib.h include/rdoff.h rdoff/rdfload.h rdoff/rdfutils.h
rdoff/rdfdump.$(O): rdoff/rdfdump.c config/msvc.h config/unknown.h &
- config/watcom.h include/compiler.h include/nasmint.h include/rdoff.h
+ config/watcom.h include/compiler.h include/error.h include/nasmint.h &
+ include/nasmlib.h include/rdoff.h rdoff/rdfutils.h
rdoff/rdflib.$(O): rdoff/rdflib.c config/msvc.h config/unknown.h &
- config/watcom.h include/compiler.h include/nasmint.h
+ config/watcom.h include/compiler.h include/error.h include/nasmint.h &
+ include/nasmlib.h include/rdoff.h rdoff/rdfutils.h
rdoff/rdfload.$(O): rdoff/rdfload.c config/msvc.h config/unknown.h &
- config/watcom.h include/compiler.h include/nasmint.h include/rdoff.h &
- rdoff/collectn.h rdoff/rdfload.h rdoff/symtab.h
+ config/watcom.h include/compiler.h include/error.h include/nasmint.h &
+ include/nasmlib.h include/rdoff.h rdoff/collectn.h rdoff/rdfload.h &
+ rdoff/rdfutils.h rdoff/symtab.h
rdoff/rdlar.$(O): rdoff/rdlar.c config/msvc.h config/unknown.h &
config/watcom.h include/compiler.h include/nasmint.h rdoff/rdlar.h
rdoff/rdlib.$(O): rdoff/rdlib.c config/msvc.h config/unknown.h &
- config/watcom.h include/compiler.h include/nasmint.h include/rdoff.h &
- rdoff/rdlar.h rdoff/rdlib.h
+ config/watcom.h include/compiler.h include/error.h include/nasmint.h &
+ include/nasmlib.h include/rdoff.h rdoff/rdfutils.h rdoff/rdlar.h &
+ rdoff/rdlib.h
rdoff/rdoff.$(O): rdoff/rdoff.c config/msvc.h config/unknown.h &
- config/watcom.h include/compiler.h include/nasmint.h include/rdoff.h
+ config/watcom.h include/compiler.h include/error.h include/nasmint.h &
+ include/nasmlib.h include/rdoff.h rdoff/rdfutils.h
rdoff/rdx.$(O): rdoff/rdx.c config/msvc.h config/unknown.h config/watcom.h &
- include/compiler.h include/nasmint.h include/rdoff.h rdoff/rdfload.h &
- rdoff/symtab.h
+ include/compiler.h include/error.h include/nasmint.h include/nasmlib.h &
+ include/rdoff.h rdoff/rdfload.h rdoff/rdfutils.h rdoff/symtab.h
rdoff/segtab.$(O): rdoff/segtab.c config/msvc.h config/unknown.h &
config/watcom.h include/compiler.h include/nasmint.h rdoff/segtab.h
rdoff/symtab.$(O): rdoff/symtab.c config/msvc.h config/unknown.h &
diff --git a/doc/changes.src b/doc/changes.src
index cf66ca3a..b168a437 100644
--- a/doc/changes.src
+++ b/doc/changes.src
@@ -23,13 +23,16 @@ since 2007.
\b NASM can now generate sparse output files for relevant output
formats, if the underlying operating system supports them.
-\b \c{macho} object format now supports the \c{subsections_via_symbols}
+\b The \c{macho} object format now supports the \c{subsections_via_symbols}
and \c{no_dead_strip} directives, see \k{macho-ssvs}.
-\b \c{macho} object format now supports the \c{no_dead_strip},
+\b The \c{macho} object format now supports the \c{no_dead_strip},
\c{live_support} and \c{strip_static_syms} section flags, see
\k{machosect}.
+\b The \c{macho} object format now supports the \c{dwarf} debugging
+ format, as required by newer toolchains.
+
\b All warnings can now be suppressed if desired; warnings not
otherwise part of any warning class are now considered its own
warning class called \c{other} (e.g. \c{-w-other}). Furthermore,
diff --git a/doc/genps.pl b/doc/genps.pl
index 88e57388..4758bb9d 100755
--- a/doc/genps.pl
+++ b/doc/genps.pl
@@ -829,6 +829,8 @@ sub ps_break_pages($$) {
# First line of a new chapter heading. Start a new page.
undef $columnstart;
$curpage++ if ( $curypos > 0 || defined($columnstart) );
+ # Always start on an odd page
+ $curpage |= 1;
$curypos = $chapstart;
} elsif ( defined($columnstart) && $$linfo[0] !~ /$columnregexp/o ) {
undef $columnstart;
@@ -1232,10 +1234,10 @@ ps_start_page();
foreach $line ( @pslines ) {
my $linfo = $line->[0];
- if ( $$linfo[4] != $curpage ) {
+ while ( $$linfo[4] > $curpage ) {
ps_end_page($curpage > 2);
ps_start_page();
- $curpage = $$linfo[4];
+ $curpage++;
}
print '[';
diff --git a/include/nasmlib.h b/include/nasmlib.h
index 747ee11c..0b2bcb17 100644
--- a/include/nasmlib.h
+++ b/include/nasmlib.h
@@ -101,8 +101,10 @@ char * safe_alloc nasm_strndup(const char *, size_t);
#define nasm_zeron(p,n) (memset((p), 0, (n)*sizeof(*(p))))
/*
- * Wrapper around fwrite() which fatal-errors on output failure.
+ * Wrappers around fread()/fwrite() which fatal-errors on failure.
+ * For fread(), only use this if EOF is supposed to be a fatal error!
*/
+void nasm_read(void *, size_t, FILE *);
void nasm_write(const void *, size_t, FILE *);
/*
diff --git a/include/rdoff.h b/include/rdoff.h
index 019d012d..973be8c0 100644
--- a/include/rdoff.h
+++ b/include/rdoff.h
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------- *
*
- * Copyright 1996-2009 The NASM Authors - All Rights Reserved
+ * Copyright 1996-2017 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
*
@@ -35,9 +35,8 @@
* rdoff.h RDOFF Object File manipulation routines header file
*/
-#ifndef RDOFF_RDOFF_H
-#define RDOFF_RDOFF_H 1
-
+#ifndef RDOFF_H
+#define RDOFF_H 1
/*
* RDOFF definitions. They are used by RDOFF utilities and by NASM's
@@ -167,126 +166,4 @@ struct CommonRec {
#define SYM_GLOBAL 4
#define SYM_IMPORT 8
-/*** The following part is used only by the utilities *************************/
-
-#ifdef RDOFF_UTILS
-
-/* Some systems don't define this automatically */
-#if !defined(strdup)
-extern char *strdup(const char *);
-#endif
-
-typedef union RDFHeaderRec {
- char type; /* invariant throughout all below */
- struct GenericRec g; /* type 0 */
- struct RelocRec r; /* type == 1 / 6 */
- struct ImportRec i; /* type == 2 / 7 */
- struct ExportRec e; /* type == 3 */
- struct DLLRec d; /* type == 4 */
- struct BSSRec b; /* type == 5 */
- struct ModRec m; /* type == 8 */
- struct CommonRec c; /* type == 10 */
-} rdfheaderrec;
-
-struct SegmentHeaderRec {
- /* information from file */
- uint16_t type;
- uint16_t number;
- uint16_t reserved;
- int32_t length;
-
- /* information built up here */
- int32_t offset;
- uint8_t *data; /* pointer to segment data if it exists in memory */
-};
-
-typedef struct RDFFileInfo {
- FILE *fp; /* file descriptor; must be open to use this struct */
- int rdoff_ver; /* should be 1; any higher => not guaranteed to work */
- int32_t header_len;
- int32_t header_ofs;
-
- uint8_t *header_loc; /* keep location of header */
- int32_t header_fp; /* current location within header for reading */
-
- struct SegmentHeaderRec seg[RDF_MAXSEGS];
- int nsegs;
-
- int32_t eof_offset; /* offset of the first uint8_t beyond the end of this
- module */
-
- char *name; /* name of module in libraries */
- int *refcount; /* pointer to reference count on file, or NULL */
-} rdffile;
-
-#define BUF_BLOCK_LEN 4088 /* selected to match page size (4096)
- * on 80x86 machines for efficiency */
-typedef struct memorybuffer {
- int length;
- uint8_t buffer[BUF_BLOCK_LEN];
- struct memorybuffer *next;
-} memorybuffer;
-
-typedef struct {
- memorybuffer *buf; /* buffer containing header records */
- int nsegments; /* number of segments to be written */
- int32_t seglength; /* total length of all the segments */
-} rdf_headerbuf;
-
-/* segments used by RDOFF, understood by rdoffloadseg */
-#define RDOFF_CODE 0
-#define RDOFF_DATA 1
-#define RDOFF_HEADER -1
-/* mask for 'segment' in relocation records to find if relative relocation */
-#define RDOFF_RELATIVEMASK 64
-/* mask to find actual segment value in relocation records */
-#define RDOFF_SEGMENTMASK 63
-
-extern int rdf_errno;
-
-/* rdf_errno can hold these error codes */
-enum {
- /* 0 */ RDF_OK,
- /* 1 */ RDF_ERR_OPEN,
- /* 2 */ RDF_ERR_FORMAT,
- /* 3 */ RDF_ERR_READ,
- /* 4 */ RDF_ERR_UNKNOWN,
- /* 5 */ RDF_ERR_HEADER,
- /* 6 */ RDF_ERR_NOMEM,
- /* 7 */ RDF_ERR_VER,
- /* 8 */ RDF_ERR_RECTYPE,
- /* 9 */ RDF_ERR_RECLEN,
- /* 10 */ RDF_ERR_SEGMENT
-};
-
-/* utility functions */
-int32_t translateint32_t(int32_t in);
-uint16_t translateint16_t(uint16_t in);
-char *translatesegmenttype(uint16_t type);
-
-/* RDOFF file manipulation functions */
-int rdfopen(rdffile * f, const char *name);
-int rdfopenhere(rdffile * f, FILE * fp, int *refcount, const char *name);
-int rdfclose(rdffile * f);
-int rdffindsegment(rdffile * f, int segno);
-int rdfloadseg(rdffile * f, int segment, void *buffer);
-rdfheaderrec *rdfgetheaderrec(rdffile * f); /* returns static storage */
-void rdfheaderrewind(rdffile * f); /* back to start of header */
-void rdfperror(const char *app, const char *name);
-
-/* functions to write a new RDOFF header to a file -
- use rdfnewheader to allocate a header, rdfaddheader to add records to it,
- rdfaddsegment to notify the header routines that a segment exists, and
- to tell it how int32_t the segment will be.
- rdfwriteheader to write the file id, object length, and header
- to a file, and then rdfdoneheader to dispose of the header */
-
-rdf_headerbuf *rdfnewheader(void);
-int rdfaddheader(rdf_headerbuf * h, rdfheaderrec * r);
-int rdfaddsegment(rdf_headerbuf * h, int32_t seglength);
-int rdfwriteheader(FILE * fp, rdf_headerbuf * h);
-void rdfdoneheader(rdf_headerbuf * h);
-
-#endif /* RDOFF_UTILS */
-
-#endif /* RDOFF_RDOFF_H */
+#endif /* RDOFF_H */
diff --git a/nasmlib/file.c b/nasmlib/file.c
index 95f3c52a..0d0c24bc 100644
--- a/nasmlib/file.c
+++ b/nasmlib/file.c
@@ -33,6 +33,16 @@
#include "file.h"
+void nasm_read(void *ptr, size_t size, FILE *f)
+{
+ size_t n = fread(ptr, 1, size, f);
+ if (ferror(f)) {
+ nasm_fatal(0, "unable to read input: %s", strerror(errno));
+ } else if (n != size || feof(f)) {
+ nasm_fatal(0, "fatal short read on input");
+ }
+}
+
void nasm_write(const void *ptr, size_t size, FILE *f)
{
size_t n = fwrite(ptr, 1, size, f);
@@ -122,7 +132,7 @@ void fwritezero(off_t bytes, FILE *fp)
FILE *nasm_open_read(const char *filename, enum file_flags flags)
{
- FILE *f;
+ FILE *f = NULL;
bool again = true;
#ifdef __GLIBC__
diff --git a/output/outdbg.c b/output/outdbg.c
index 1a18c482..130c9d72 100644
--- a/output/outdbg.c
+++ b/output/outdbg.c
@@ -165,7 +165,7 @@ static void dbg_out(const struct out_data *data)
"out to %"PRIx32":%"PRIx64" %s %s bits %d insoffs %d/%d "
"size %"PRIu64,
data->segment, data->offset,
- out_type(data->type), out_sign(data->type),
+ out_type(data->type), out_sign(data->sign),
data->bits, data->insoffs, data->inslen, data->size);
if (data->itemp) {
fprintf(ofile, " ins %s(%d)",
diff --git a/output/outmacho.c b/output/outmacho.c
index 76de154a..173706b9 100644
--- a/output/outmacho.c
+++ b/output/outmacho.c
@@ -52,6 +52,8 @@
#include "rbtree.h"
#include "outform.h"
#include "outlib.h"
+#include "ver.h"
+#include "dwarf.h"
#if defined(OF_MACHO) || defined(OF_MACHO64)
@@ -185,6 +187,7 @@ struct section {
#define S_ATTR_STRIP_STATIC_SYMS 0x20000000
#define S_ATTR_NO_TOC 0x40000000
#define S_ATTR_PURE_INSTRUCTIONS 0x80000000 /* section uses pure machine instructions */
+#define S_ATTR_DEBUG 0x02000000 /* debug section */
#define S_NASM_TYPE_MASK 0x800004ff /* we consider these bits "section type" */
@@ -320,6 +323,39 @@ static struct section *get_section_by_index(const int32_t index)
return s;
}
+struct file_list {
+ struct file_list *next;
+ struct file_list *last;
+ char *file_name;
+ uint32_t file;
+};
+
+struct dw_sect_list {
+ struct SAA *psaa;
+ int32_t section;
+ uint32_t line;
+ uint64_t offset;
+ uint32_t file;
+ struct dw_sect_list *next;
+ struct dw_sect_list *last;
+};
+
+struct section_info {
+ uint64_t size;
+ int32_t secto;
+};
+
+#define DW_LN_BASE (-5)
+#define DW_LN_RANGE 14
+#define DW_OPCODE_BASE 13
+#define DW_MAX_LN (DW_LN_BASE + DW_LN_RANGE)
+#define DW_MAX_SP_OPCODE 256
+
+static struct file_list *dw_head_list = 0, *dw_cur_list = 0, *dw_last_list = 0;
+static struct dw_sect_list *dw_head_sect = 0, *dw_cur_sect = 0, *dw_last_sect = 0;
+static uint32_t cur_line = 0, dw_num_files = 0, dw_num_sects = 0;
+static bool dbg_immcall = false;
+
/*
* Special section numbers which are used to define Mach-O special
* symbols, which can be used with WRT to provide PIC relocation
@@ -551,6 +587,16 @@ static void macho_output(int32_t secto, const void *data,
nasm_panic(0, "text section not found");
}
+ /* debug code generation only for sections tagged with
+ * instruction attribute */
+ if (s->flags & S_ATTR_SOME_INSTRUCTIONS)
+ {
+ struct section_info sinfo;
+ sinfo.size = s->size;
+ sinfo.secto = secto;
+ dfmt->debug_output(0, &sinfo);
+ }
+
is_bss = (s->flags & SECTION_TYPE) == S_ZEROFILL;
if (is_bss && type != OUT_RESERVE) {
@@ -713,6 +759,10 @@ static const struct sectmap {
{".data", "__DATA", "__data", S_REGULAR},
{".rodata", "__DATA", "__const", S_REGULAR},
{".bss", "__DATA", "__bss", S_ZEROFILL},
+ {".debug_abbrev", "__DWARF", "__debug_abbrev", S_ATTR_DEBUG},
+ {".debug_info", "__DWARF", "__debug_info", S_ATTR_DEBUG},
+ {".debug_line", "__DWARF", "__debug_line", S_ATTR_DEBUG},
+ {".debug_str", "__DWARF", "__debug_str", S_ATTR_DEBUG},
{NULL, NULL, NULL, 0}
};
@@ -1162,6 +1212,9 @@ static void macho_calculate_sizes (void)
s->pad = ALIGN(seg_filesize, 4) - seg_filesize;
s->offset = seg_filesize + s->pad;
seg_filesize += s->size + s->pad;
+
+ /* filesize and vmsize needs to be aligned */
+ seg_vmsize += s->pad;
}
}
@@ -1590,6 +1643,8 @@ static void macho_cleanup(void)
struct reloc *r;
struct symbol *sym;
+ dfmt->cleanup();
+
/* Sort all symbols. */
macho_layout_symbols (&nsyms, &strslen);
@@ -1723,6 +1778,397 @@ static const struct pragma_facility macho_pragma_list[] = {
{ NULL, macho_pragma } /* Implements macho32/macho64 namespaces */
};
+static void macho_dbg_generate(void)
+{
+ uint8_t *p_buf = NULL, *p_buf_base = NULL;
+ size_t saa_len = 0, high_addr = 0, total_len = 0;
+ struct section *p_section = NULL;
+ /* calculated at debug_str and referenced at debug_info */
+ uint32_t producer_str_offset = 0, module_str_offset = 0;
+
+ /* debug section defines */
+ {
+ int bits = 0;
+ macho_section(".debug_abbrev", 0, &bits);
+ macho_section(".debug_info", 0, &bits);
+ macho_section(".debug_line", 0, &bits);
+ macho_section(".debug_str", 0, &bits);
+ }
+
+ /* dw section walk to find high_addr and total_len */
+ {
+ struct dw_sect_list *p_sect = dw_head_sect;
+ uint32_t idx = 0;
+ for(; idx < dw_num_sects; idx++) {
+ uint64_t offset = get_section_by_index(p_sect->section)->size;
+ struct SAA *p_linep = p_sect->psaa;
+
+ saa_write8(p_linep, 2); /* std op 2 */
+ saa_write8(p_linep, offset - p_sect->offset);
+ saa_write8(p_linep, DW_LNS_extended_op);
+ saa_write8(p_linep, 1); /* operand length */
+ saa_write8(p_linep, DW_LNE_end_sequence);
+
+ total_len += p_linep->datalen;
+ high_addr += offset;
+ p_sect = p_sect->next;
+ }
+ }
+
+ /* debug line */
+ {
+ struct file_list *p_file = dw_head_list;
+ struct dw_sect_list *p_sect = dw_head_sect;
+ size_t linep_off = 0;
+ uint32_t idx = 0, buf_size = 0;
+ struct SAA *p_lines = saa_init(1L);
+ nasm_assert(p_lines != NULL);
+
+ p_section = get_section_by_name("__DWARF", "__debug_line");
+ nasm_assert(p_section != NULL);
+
+ saa_write8(p_lines, 1); /* minimum instruction length */
+ saa_write8(p_lines, 1); /* initial value of "is_stmt" */
+ saa_write8(p_lines, DW_LN_BASE); /* line base */
+ saa_write8(p_lines, DW_LN_RANGE); /* line range */
+ saa_write8(p_lines, DW_OPCODE_BASE); /* opcode base */
+ saa_write8(p_lines, 0); /* std opcode 1 length */
+ saa_write8(p_lines, 1); /* std opcode 2 length */
+ saa_write8(p_lines, 1); /* std opcode 3 length */
+ saa_write8(p_lines, 1); /* std opcode 4 length */
+ saa_write8(p_lines, 1); /* std opcode 5 length */
+ saa_write8(p_lines, 0); /* std opcode 6 length */
+ saa_write8(p_lines, 0); /* std opcode 7 length */
+ saa_write8(p_lines, 0); /* std opcode 8 length */
+ saa_write8(p_lines, 1); /* std opcode 9 length */
+ saa_write8(p_lines, 0); /* std opcode 10 length */
+ saa_write8(p_lines, 0); /* std opcode 11 length */
+ saa_write8(p_lines, 1); /* std opcode 12 length */
+ saa_write8(p_lines, 0); /* end of table */
+
+ for(idx = 0; idx < dw_num_files; idx++) {
+ saa_wbytes(p_lines, p_file->file_name, (int32_t)(strlen(p_file->file_name) +1));
+ saa_write8(p_lines, 0); /* directory */
+ saa_write8(p_lines, 0); /* time */
+ saa_write8(p_lines, 0); /* size */
+ p_file = p_file->next;
+ }
+ saa_write8(p_lines, 0); /* end of table */
+
+ linep_off = p_lines->datalen;
+ /* 10 bytes for initial & prolong length, and dwarf version info */
+ buf_size = saa_len = linep_off + total_len + 10;
+ p_buf_base = p_buf = nasm_malloc(buf_size);
+
+ WRITELONG(p_buf, saa_len - 4); /* initial length; size excluding itself */
+ WRITESHORT(p_buf, 2); /* dwarf version */
+ WRITELONG(p_buf, linep_off); /* prolong length */
+
+ saa_rnbytes(p_lines, p_buf, linep_off);
+ p_buf += linep_off;
+ saa_free(p_lines);
+
+ for(idx = 0; idx < dw_num_sects; idx++) {
+ struct SAA *p_linep = p_sect->psaa;
+ saa_len = p_linep->datalen;
+ saa_rnbytes(p_linep, p_buf, saa_len);
+ p_buf += saa_len;
+ saa_free(p_linep);
+ p_sect = p_sect->next;
+ }
+
+ macho_output(p_section->index, p_buf_base, OUT_RAWDATA, buf_size, NO_SEG, 0);
+
+ }
+
+ /* string section */
+ {
+ struct file_list *p_file = dw_head_list;
+ uint32_t idx = 0;
+ struct SAA *p_str = saa_init(1L);
+ nasm_assert(p_str != NULL);
+
+ p_section = get_section_by_name("__DWARF", "__debug_str");
+ nasm_assert(p_section != NULL);
+
+ producer_str_offset = 0;
+ saa_wbytes(p_str, nasm_signature, strlen(nasm_signature) + 1);
+
+ module_str_offset = producer_str_offset + strlen(nasm_signature) + 1;
+ for(; idx < dw_num_files; idx++) {
+ saa_wbytes(p_str, p_file->file_name, (int32_t)(strlen(p_file->file_name) + 1));
+ p_file = p_file->next;
+ }
+
+ saa_len = p_str->datalen;
+
+ p_buf = nasm_malloc(saa_len);
+ saa_rnbytes(p_str, p_buf, saa_len);
+ macho_output(p_section->index, p_buf, OUT_RAWDATA, saa_len, NO_SEG, 0);
+
+ saa_free(p_str);
+ }
+
+ /* debug info */
+ {
+ struct SAA *p_info = saa_init(1L);
+ nasm_assert(p_info != NULL);
+
+ p_section = get_section_by_name("__DWARF", "__debug_info");
+ nasm_assert(p_section != NULL);
+
+ /* size will be overwritten once determined, so skip in p_info layout */
+ saa_write16(p_info, 2); /* dwarf version */
+ saa_write32(p_info, 0); /* offset info abbrev */
+ saa_write8(p_info, (ofmt == &of_macho64) ? 8 : 4); /* pointer size */
+
+ saa_write8(p_info, 1); /* abbrev entry number */
+
+ saa_write32(p_info, producer_str_offset); /* offset from string table for DW_AT_producer */
+ saa_write16(p_info, DW_LANG_Mips_Assembler); /* DW_AT_language */
+ saa_write32(p_info, module_str_offset); /* offset from string table for DW_AT_name */
+ saa_write32(p_info, 0); /* DW_AT_stmt_list */
+
+ if (ofmt == &of_macho64) {
+ saa_write64(p_info, 0); /* DW_AT_low_pc */
+ saa_write64(p_info, high_addr); /* DW_AT_high_pc */
+ } else {
+ saa_write32(p_info, 0); /* DW_AT_low_pc */
+ saa_write32(p_info, high_addr); /* DW_AT_high_pc */
+ }
+
+ saa_write8(p_info, 2); /* abbrev entry number */
+
+ if (ofmt == &of_macho64) {
+ saa_write64(p_info, 0); /* DW_AT_low_pc */
+ saa_write64(p_info, 0); /* DW_AT_frame_base */
+ } else {
+ saa_write32(p_info, 0); /* DW_AT_low_pc */
+ saa_write32(p_info, 0); /* DW_AT_frame_base */
+ }
+ saa_write8(p_info, DW_END_default);
+
+ saa_len = p_info->datalen;
+ p_buf_base = p_buf = nasm_malloc(saa_len + 4); /* 4B for size info */
+
+ WRITELONG(p_buf, saa_len);
+ saa_rnbytes(p_info, p_buf, saa_len);
+ macho_output(p_section->index, p_buf_base, OUT_RAWDATA, saa_len + 4, NO_SEG, 0);
+
+ saa_free(p_info);
+ }
+
+ /* abbrev section */
+ {
+ struct SAA *p_abbrev = saa_init(1L);
+ nasm_assert(p_abbrev != NULL);
+
+ p_section = get_section_by_name("__DWARF", "__debug_abbrev");
+ nasm_assert(p_section != NULL);
+
+ saa_write8(p_abbrev, 1); /* entry number */
+
+ saa_write8(p_abbrev, DW_TAG_compile_unit);
+ saa_write8(p_abbrev, DW_CHILDREN_yes);
+
+ saa_write8(p_abbrev, DW_AT_producer);
+ saa_write8(p_abbrev, DW_FORM_strp);
+
+ saa_write8(p_abbrev, DW_AT_language);
+ saa_write8(p_abbrev, DW_FORM_data2);
+
+ saa_write8(p_abbrev, DW_AT_name);
+ saa_write8(p_abbrev, DW_FORM_strp);
+
+ saa_write8(p_abbrev, DW_AT_stmt_list);
+ saa_write8(p_abbrev, DW_FORM_data4);
+
+ saa_write8(p_abbrev, DW_AT_low_pc);
+ saa_write8(p_abbrev, DW_FORM_addr);
+
+ saa_write8(p_abbrev, DW_AT_high_pc);
+ saa_write8(p_abbrev, DW_FORM_addr);
+
+ saa_write16(p_abbrev, DW_END_default);
+
+ saa_write8(p_abbrev, 2); /* entry number */
+
+ saa_write8(p_abbrev, DW_TAG_subprogram);
+ saa_write8(p_abbrev, DW_CHILDREN_no);
+
+ saa_write8(p_abbrev, DW_AT_low_pc);
+ saa_write8(p_abbrev, DW_FORM_addr);
+
+ saa_write8(p_abbrev, DW_AT_frame_base);
+ saa_write8(p_abbrev, DW_FORM_addr);
+
+ saa_write16(p_abbrev, DW_END_default);
+
+ saa_len = p_abbrev->datalen;
+
+ p_buf = nasm_malloc(saa_len);
+
+ saa_rnbytes(p_abbrev, p_buf, saa_len);
+ macho_output(p_section->index, p_buf, OUT_RAWDATA, saa_len, NO_SEG, 0);
+
+ saa_free(p_abbrev);
+ }
+}
+
+static void macho_dbg_init(void)
+{
+}
+
+static void macho_dbg_linenum(const char *file_name, int32_t line_num, int32_t segto)
+{
+ bool need_new_list = true;
+ (void)segto;
+
+ if(!dw_cur_list || strcmp(file_name, dw_cur_list->file_name)) {
+ if(dw_head_list) {
+ struct file_list *match = dw_head_list;
+ uint32_t idx = 0;
+
+ for (; idx < dw_num_files; idx++ ) {
+ if(!(strcmp(file_name, match->file_name))) {
+ dw_cur_list = match;
+ need_new_list = false;
+ break;
+ }
+ match = match->next;
+ }
+ }
+
+ if(need_new_list) {
+ nasm_new(dw_cur_list);
+ dw_cur_list->file = ++dw_num_files;
+ dw_cur_list->file_name = (char*) file_name;
+
+ if(!dw_head_list) {
+ dw_head_list = dw_last_list = dw_cur_list;
+ } else {
+ dw_last_list->next = dw_cur_list;
+ dw_last_list = dw_cur_list;
+ }
+ }
+ }
+
+ dbg_immcall = true;
+ cur_line = line_num;
+}
+
+static void macho_dbg_output(int type, void *param)
+{
+ struct section_info *sinfo_param = (struct section_info *)param;
+ int32_t secto = sinfo_param->secto;
+ bool need_new_sect = false;
+ struct SAA *p_linep = NULL;
+ (void)type;
+
+ if(!(dw_cur_sect && (dw_cur_sect->section == secto))) {
+ need_new_sect = true;
+ if(dw_head_sect) {
+ struct dw_sect_list *match = dw_head_sect;
+ uint32_t idx = 0;
+
+ for(; idx < dw_num_sects; idx++) {
+ if(match->section == secto) {
+ dw_cur_sect = match;
+ need_new_sect = false;
+ break;
+ }
+ match = match->next;
+ }
+ }
+ }
+
+ if(need_new_sect) {
+ nasm_new(dw_cur_sect);
+ dw_num_sects ++;
+ p_linep = dw_cur_sect->psaa = saa_init(1L);
+ dw_cur_sect->line = dw_cur_sect->file = 1;
+ dw_cur_sect->offset = 0;
+ dw_cur_sect->next = NULL;
+ dw_cur_sect->section = secto;
+
+ saa_write8(p_linep, DW_LNS_extended_op);
+ saa_write8(p_linep, (ofmt == &of_macho64) ? 9 : 5);
+ saa_write8(p_linep, DW_LNE_set_address);
+ if (ofmt == &of_macho64) {
+ saa_write64(p_linep, 0);
+ } else {
+ saa_write32(p_linep, 0);
+ }
+
+ if(!dw_head_sect) {
+ dw_head_sect = dw_last_sect = dw_cur_sect;
+ } else {
+ dw_last_sect->next = dw_cur_sect;
+ dw_last_sect = dw_cur_sect;
+ }
+ }
+
+ if(dbg_immcall == true) {
+ int32_t line_delta = cur_line - dw_cur_sect->line;
+ int32_t offset_delta = sinfo_param->size - dw_cur_sect->offset;
+ uint32_t cur_file = dw_cur_list->file;
+ p_linep = dw_cur_sect->psaa;
+
+ if(cur_file != dw_cur_sect->file) {
+ saa_write8(p_linep, DW_LNS_set_file);
+ saa_write8(p_linep, cur_file);
+ dw_cur_sect->file = cur_file;
+ }
+
+ if(line_delta) {
+ int special_opcode = (line_delta - DW_LN_BASE) + (DW_LN_RANGE * offset_delta) +
+ DW_OPCODE_BASE;
+
+ if((line_delta >= DW_LN_BASE) && (line_delta < DW_MAX_LN) &&
+ (special_opcode < DW_MAX_SP_OPCODE)) {
+ saa_write8(p_linep, special_opcode);
+ } else {
+ saa_write8(p_linep, DW_LNS_advance_line);
+ saa_wleb128s(p_linep, line_delta);
+ if(offset_delta) {
+ saa_write8(p_linep, DW_LNS_advance_pc);
+ saa_wleb128u(p_linep, offset_delta);
+ }
+ saa_write8(p_linep, DW_LNS_copy);
+ }
+
+ dw_cur_sect->line = cur_line;
+ dw_cur_sect->offset = sinfo_param->size;
+ }
+
+ dbg_immcall = false;
+ }
+}
+
+static void macho_dbg_cleanup(void)
+{
+ /* dwarf sectors generation */
+ macho_dbg_generate();
+
+ {
+ struct dw_sect_list *p_sect = dw_head_sect;
+ struct file_list *p_file = dw_head_list;
+ uint32_t idx = 0;
+
+ for(; idx < dw_num_sects; idx++) {
+ struct dw_sect_list *next = p_sect->next;
+ nasm_free(p_sect);
+ p_sect = next;
+ }
+
+ for(idx = 0; idx < dw_num_files; idx++) {
+ struct file_list *next = p_file->next;
+ nasm_free(p_file);
+ p_file = next;
+ }
+ }
+}
+
#ifdef OF_MACHO32
static const struct macho_fmt macho32_fmt = {
4,
@@ -1747,13 +2193,29 @@ static void macho32_init(void)
macho_gotpcrel_sect = NO_SEG;
}
+static const struct dfmt macho32_df_dwarf = {
+ "MachO32 (i386) dwarf debug format for Darwin/MacOS",
+ "dwarf",
+ macho_dbg_init,
+ macho_dbg_linenum,
+ null_debug_deflabel,
+ null_debug_directive,
+ null_debug_typevalue,
+ macho_dbg_output,
+ macho_dbg_cleanup,
+ NULL /*pragma list*/
+};
+
+static const struct dfmt * const macho32_df_arr[2] =
+ { &macho32_df_dwarf, NULL };
+
const struct ofmt of_macho32 = {
"NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (i386) object files",
"macho32",
0,
32,
- null_debug_arr,
- &null_debug_form,
+ macho32_df_arr,
+ &macho32_df_dwarf,
macho_stdmac,
macho32_init,
nasm_do_legacy_output,
@@ -1795,13 +2257,29 @@ static void macho64_init(void)
define_label("..gotpcrel", macho_gotpcrel_sect, 0L, NULL, false, false);
}
+static const struct dfmt macho64_df_dwarf = {
+ "MachO64 (x86-64) dwarf debug format for Darwin/MacOS",
+ "dwarf",
+ macho_dbg_init,
+ macho_dbg_linenum,
+ null_debug_deflabel,
+ null_debug_directive,
+ null_debug_typevalue,
+ macho_dbg_output,
+ macho_dbg_cleanup,
+ NULL /*pragma list*/
+};
+
+static const struct dfmt * const macho64_df_arr[2] =
+ { &macho64_df_dwarf, NULL };
+
const struct ofmt of_macho64 = {
"NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (x86_64) object files",
"macho64",
0,
64,
- null_debug_arr,
- &null_debug_form,
+ macho64_df_arr,
+ &macho64_df_dwarf,
macho_stdmac,
macho64_init,
nasm_do_legacy_output,
diff --git a/rdoff/Mkfiles/Makefile.dj b/rdoff/Mkfiles/Makefile.dj
deleted file mode 100644
index 5621ed62..00000000
--- a/rdoff/Mkfiles/Makefile.dj
+++ /dev/null
@@ -1,75 +0,0 @@
-# Generated automatically from Makefile.in by configure.
-#
-# Auto-configuring Makefile for RDOFF object file utils; part of the
-# Netwide Assembler
-#
-# The Netwide Assembler is copyright (C) 1996 Simon Tatham and
-# Julian Hall. All rights reserved. The software is
-# redistributable under the license given in the file "LICENSE"
-# distributed in the NASM archive.
-
-# You may need to adjust these values.
-
-prefix = /djgpp
-CC = gcc -s
-CFLAGS = -O2 -I..
-
-# You _shouldn't_ need to adjust anything below this line.
-
-exec_prefix = ${prefix}
-bindir = ${exec_prefix}/bin
-mandir = ${prefix}/man
-
-INSTALL = /usr/bin/install -c
-INSTALL_PROGRAM = ${INSTALL}
-INSTALL_DATA = ${INSTALL} -m 644
-LN_S = ln -s
-
-LDRDFLIBS = rdoff.o ../nasmlib.o symtab.o hash.o collectn.o rdlib.o segtab.o
-RDXLIBS = rdoff.o rdfload.o symtab.o hash.o collectn.o
-
-.c.o:
- $(CC) -c $(CFLAGS) $*.c
-
-all: rdfdump ldrdf rdx rdflib rdf2bin rdf2com
-
-rdfdump: rdfdump.o rdoff.o
- $(CC) -o rdfdump rdfdump.o rdoff.o
-
-ldrdf: ldrdf.o $(LDRDFLIBS)
- $(CC) -o ldrdf ldrdf.o $(LDRDFLIBS)
-rdx: rdx.o $(RDXLIBS)
- $(CC) -o rdx rdx.o $(RDXLIBS)
-rdflib: rdflib.o
- $(CC) -o rdflib rdflib.o
-rdf2bin: rdf2bin.o $(RDXLIBS) nasmlib.o
- $(CC) -o rdf2bin rdf2bin.o $(RDXLIBS) nasmlib.o
-rdf2com:
- $(LN_S) rdf2bin rdf2com
-
-rdf2bin.o: rdf2bin.c
-rdfdump.o: rdfdump.c
-rdoff.o: rdoff.c rdoff.h
-ldrdf.o: ldrdf.c rdoff.h ../nasmlib.h symtab.h collectn.h rdlib.h
-symtab.o: symtab.c symtab.h hash.h
-collectn.o: collectn.c collectn.h
-rdx.o: rdx.c rdoff.h rdfload.h symtab.h
-rdfload.o: rdfload.c rdfload.h rdoff.h collectn.h symtab.h
-rdlib.o: rdlib.c rdlib.h
-rdflib.o: rdflib.c
-hash.o: hash.c hash.h
-segtab.o: segtab.c segtab.h
-
-nasmlib.o: ../nasmlib.c ../nasmlib.h ../names.c ../nasm.h
- $(CC) -c $(CFLAGS) ../nasmlib.c
-
-clean:
- rm -f *.o rdfdump ldrdf rdx rdflib rdf2bin rdf2com
-
-install: rdfdump ldrdf rdx rdflib rdf2bin rdf2com
- $(INSTALL_PROGRAM) rdfdump $(bindir)/rdfdump
- $(INSTALL_PROGRAM) ldrdf $(bindir)/ldrdf
- $(INSTALL_PROGRAM) rdx $(bindir)/rdx
- $(INSTALL_PROGRAM) rdflib $(bindir)/rdflib
- $(INSTALL_PROGRAM) rdf2bin $(bindir)/rdf2bin
- cd $(bindir); $(LN_S) rdf2bin rdf2com
diff --git a/rdoff/Mkfiles/Makefile.emx b/rdoff/Mkfiles/Makefile.emx
deleted file mode 100644
index aa535886..00000000
--- a/rdoff/Mkfiles/Makefile.emx
+++ /dev/null
@@ -1,76 +0,0 @@
-# Generated automatically from Makefile.in by configure.
-# $Id$
-#
-# Auto-configuring Makefile for RDOFF object file utils; part of the
-# Netwide Assembler
-#
-# The Netwide Assembler is copyright (C) 1996 Simon Tatham and
-# Julian Hall. All rights reserved. The software is
-# redistributable under the license given in the file "LICENSE"
-# distributed in the NASM archive.
-
-top_srcdir = ..
-srcdir = .
-prefix = /usr/local
-exec_prefix = ${prefix}
-bindir = ${exec_prefix}/bin
-mandir = ${prefix}/man
-
-CC = gcc
-CFLAGS = -s -Zomf -O2 -fomit-frame-pointer -Wall -ansi -pedantic -I$(srcdir) -I$(top_srcdir)
-LDFLAGS = -s -Zomf -Zexe -Zcrtdll
-LIBS = -lgcc
-
-INSTALL = .././install-sh -c
-INSTALL_PROGRAM = ${INSTALL}
-INSTALL_DATA = ${INSTALL} -m 644
-
-LDRDFLIBS = rdoff.o nasmlib.o symtab.o collectn.o rdlib.o segtab.o hash.o
-RDXLIBS = rdoff.o rdfload.o symtab.o collectn.o hash.o
-
-.c.o:
- $(CC) -c $(CFLAGS) -o $@ $<
-
-all: rdfdump ldrdf rdx rdflib rdf2bin
-
-rdfdump: rdfdump.o rdoff.o
- $(CC) $(LDFLAGS) -o rdfdump rdfdump.o rdoff.o $(LIBS)
-ldrdf: ldrdf.o $(LDRDFLIBS)
- $(CC) $(LDFLAGS) -o ldrdf ldrdf.o $(LDRDFLIBS) $(LIBS)
-rdx: rdx.o $(RDXLIBS)
- $(CC) $(LDFLAGS) -o rdx rdx.o $(RDXLIBS) $(LIBS)
-rdflib: rdflib.o
- $(CC) $(LDFLAGS) -o rdflib rdflib.o $(LIBS)
-rdf2bin: rdf2bin.o $(RDXLIBS) nasmlib.o
- $(CC) $(LDFLAGS) -o rdf2bin rdf2bin.o $(RDXLIBS) nasmlib.o $(LIBS)
-
-rdf2bin.o: rdf2bin.c
-rdfdump.o: rdfdump.c
-rdoff.o: rdoff.c rdoff.h
-ldrdf.o: ldrdf.c rdoff.h $(top_srcdir)/nasmlib.h symtab.h collectn.h rdlib.h
-symtab.o: symtab.c symtab.h
-collectn.o: collectn.c collectn.h
-rdx.o: rdx.c rdoff.h rdfload.h symtab.h
-rdfload.o: rdfload.c rdfload.h rdoff.h collectn.h symtab.h
-rdlib.o: rdlib.c rdlib.h
-rdflib.o: rdflib.c
-segtab.o: segtab.c
-
-nasmlib.o: $(top_srcdir)/nasmlib.c
- $(CC) -c $(CFLAGS) -o $@ $(top_srcdir)/nasmlib.c
-
-clean:
- rm -f *.o rdfdump ldrdf rdx rdflib rdf2bin rdf2com
-
-spotless: clean
- rm -f Makefile
-
-distclean: spotless
-
-install: rdfdump ldrdf rdx rdflib rdf2bin rdf2com
- $(INSTALL_PROGRAM) rdfdump $(INSTALLROOT)$(bindir)/rdfdump
- $(INSTALL_PROGRAM) ldrdf $(INSTALLROOT)$(bindir)/ldrdf
- $(INSTALL_PROGRAM) rdx $(INSTALLROOT)$(bindir)/rdx
- $(INSTALL_PROGRAM) rdflib $(INSTALLROOT)$(bindir)/rdflib
- $(INSTALL_PROGRAM) rdf2bin $(INSTALLROOT)$(bindir)/rdf2bin
- cd $(INSTALLROOT)$(bindir) && rm -f rdf2com && $(LN_S) rdf2bin rdf2com
diff --git a/rdoff/Mkfiles/Makefile.sc b/rdoff/Mkfiles/Makefile.sc
deleted file mode 100644
index 501d487b..00000000
--- a/rdoff/Mkfiles/Makefile.sc
+++ /dev/null
@@ -1,56 +0,0 @@
-# Makefile for RDOFF object file utils; part of the Netwide Assembler
-#
-# The Netwide Assembler is copyright (C) 1996 Simon Tatham and
-# Julian Hall. All rights reserved. The software is
-# redistributable under the license given in the file "LICENSE"
-# distributed in the NASM archive.
-#
-# This Makefile is designed for use under Unix (probably fairly
-# portably).
-
-CC = sc
-CCFLAGS = -I..\ -c -a1 -mn -Nc -w2 -w7 -o+time -5
-LINK = link
-LINKFLAGS = /noi /exet:NT /su:console
-
-OBJ=obj
-EXE=.exe
-
-NASMLIB = ..\nasmlib.$(OBJ)
-NASMLIB_H = ..\nasmlib.h
-LDRDFLIBS = rdoff.$(OBJ) $(NASMLIB) symtab.$(OBJ) collectn.$(OBJ) rdlib.$(OBJ)
-RDXLIBS = rdoff.$(OBJ) rdfload.$(OBJ) symtab.$(OBJ) collectn.$(OBJ)
-
-.c.$(OBJ):
- $(CC) $(CCFLAGS) $*.c
-
-all : rdfdump$(EXE) ldrdf$(EXE) rdx$(EXE) rdflib$(EXE) rdf2bin$(EXE) rdf2com$(EXE)
-
-rdfdump$(EXE) : rdfdump.$(OBJ)
- $(LINK) $(LINKFLAGS) rdfdump.$(OBJ), rdfdump$(EXE);
-ldrdf$(EXE) : ldrdf.$(OBJ) $(LDRDFLIBS)
- $(LINK) $(LINKFLAGS) ldrdf.$(OBJ) $(LDRDFLIBS), ldrdf$(EXE);
-rdx$(EXE) : rdx.$(OBJ) $(RDXLIBS)
- $(LINK) $(LINKFLAGS) rdx.$(OBJ) $(RDXLIBS), rdx$(EXE);
-rdflib$(EXE) : rdflib.$(OBJ)
- $(LINK) $(LINKFLAGS) rdflib.$(OBJ), rdflib$(EXE);
-rdf2bin$(EXE) : rdf2bin.$(OBJ) $(RDXLIBS) $(NASMLIB)
- $(LINK) $(LINKFLAGS) rdf2bin.$(OBJ) $(RDXLIBS) $(NASMLIB), rdf2bin$(EXE);
-rdf2com$(EXE) : rdf2bin$(EXE)
- copy rdf2bin$(EXE) rdf2com$(EXE)
-
-rdf2bin.$(OBJ) : rdf2bin.c
-rdfdump.$(OBJ) : rdfdump.c
-rdoff.$(OBJ) : rdoff.c rdoff.h
-ldrdf.$(OBJ) : ldrdf.c rdoff.h $(NASMLIB_H) symtab.h collectn.h rdlib.h
-symtab.$(OBJ) : symtab.c symtab.h
-collectn.$(OBJ) : collectn.c collectn.h
-rdx.$(OBJ) : rdx.c rdoff.h rdfload.h symtab.h
-rdfload.$(OBJ) : rdfload.c rdfload.h rdoff.h collectn.h symtab.h
-rdlib.$(OBJ) : rdlib.c rdlib.h
-rdflib.$(OBJ) : rdflib.c
-
-clean :
- del *.$(OBJ) rdfdump$(EXE) ldrdf$(EXE) rdx$(EXE) rdflib$(EXE) rdf2bin$(EXE)
-
-
diff --git a/rdoff/Mkfiles/Makefile.unx b/rdoff/Mkfiles/Makefile.unx
deleted file mode 100644
index 9041b417..00000000
--- a/rdoff/Mkfiles/Makefile.unx
+++ /dev/null
@@ -1,75 +0,0 @@
-# Generated automatically from Makefile.in by configure.
-#
-# Auto-configuring Makefile for RDOFF object file utils; part of the
-# Netwide Assembler
-#
-# The Netwide Assembler is copyright (C) 1996 Simon Tatham and
-# Julian Hall. All rights reserved. The software is
-# redistributable under the license given in the file "LICENSE"
-# distributed in the NASM archive.
-
-# You may need to adjust these values.
-
-prefix = /usr/local
-CC = cc
-CFLAGS = -O -I..
-
-# You _shouldn't_ need to adjust anything below this line.
-
-exec_prefix = ${prefix}
-bindir = ${exec_prefix}/bin
-mandir = ${prefix}/man
-
-INSTALL = /usr/bin/install -c
-INSTALL_PROGRAM = ${INSTALL}
-INSTALL_DATA = ${INSTALL} -m 644
-LN_S = ln -s
-
-LDRDFLIBS = rdoff.o ../nasmlib.o symtab.o hash.o collectn.o rdlib.o segtab.o
-RDXLIBS = rdoff.o rdfload.o symtab.o hash.o collectn.o
-
-.c.o:
- $(CC) -c $(CFLAGS) $*.c
-
-all: rdfdump ldrdf rdx rdflib rdf2bin rdf2com
-
-rdfdump: rdfdump.o rdoff.o
- $(CC) -o rdfdump rdfdump.o rdoff.o
-
-ldrdf: ldrdf.o $(LDRDFLIBS)
- $(CC) -o ldrdf ldrdf.o $(LDRDFLIBS)
-rdx: rdx.o $(RDXLIBS)
- $(CC) -o rdx rdx.o $(RDXLIBS)
-rdflib: rdflib.o
- $(CC) -o rdflib rdflib.o
-rdf2bin: rdf2bin.o $(RDXLIBS) nasmlib.o
- $(CC) -o rdf2bin rdf2bin.o $(RDXLIBS) nasmlib.o
-rdf2com:
- $(LN_S) rdf2bin rdf2com
-
-rdf2bin.o: rdf2bin.c
-rdfdump.o: rdfdump.c
-rdoff.o: rdoff.c rdoff.h
-ldrdf.o: ldrdf.c rdoff.h ../nasmlib.h symtab.h collectn.h rdlib.h
-symtab.o: symtab.c symtab.h hash.h
-collectn.o: collectn.c collectn.h
-rdx.o: rdx.c rdoff.h rdfload.h symtab.h
-rdfload.o: rdfload.c rdfload.h rdoff.h collectn.h symtab.h
-rdlib.o: rdlib.c rdlib.h
-rdflib.o: rdflib.c
-hash.o: hash.c hash.h
-segtab.o: segtab.c segtab.h
-
-nasmlib.o: ../nasmlib.c ../nasmlib.h ../names.c ../nasm.h
- $(CC) -c $(CFLAGS) ../nasmlib.c
-
-clean:
- rm -f *.o rdfdump ldrdf rdx rdflib rdf2bin rdf2com
-
-install: rdfdump ldrdf rdx rdflib rdf2bin rdf2com
- $(INSTALL_PROGRAM) rdfdump $(bindir)/rdfdump
- $(INSTALL_PROGRAM) ldrdf $(bindir)/ldrdf
- $(INSTALL_PROGRAM) rdx $(bindir)/rdx
- $(INSTALL_PROGRAM) rdflib $(bindir)/rdflib
- $(INSTALL_PROGRAM) rdf2bin $(bindir)/rdf2bin
- cd $(bindir); $(LN_S) rdf2bin rdf2com
diff --git a/rdoff/Mkfiles/README b/rdoff/Mkfiles/README
deleted file mode 100644
index 7e684992..00000000
--- a/rdoff/Mkfiles/README
+++ /dev/null
@@ -1,4 +0,0 @@
-These are pre-created Makefiles for various platforms, use them if
-GNU autoconf/automake packages are not supported on your system.
-
-Copy appropriate Makefile to ../Makefile and run make.
diff --git a/rdoff/collectn.c b/rdoff/collectn.c
index 317c5286..d77f54b5 100644
--- a/rdoff/collectn.c
+++ b/rdoff/collectn.c
@@ -4,8 +4,7 @@
* This file is public domain.
*/
-#include "compiler.h"
-#include <stdlib.h>
+#include "rdfutils.h"
#include "collectn.h"
void collection_init(Collection * c)
@@ -22,7 +21,7 @@ void **colln(Collection * c, int index)
while (index >= 32) {
index -= 32;
if (c->next == NULL) {
- c->next = malloc(sizeof(Collection));
+ c->next = nasm_malloc(sizeof(Collection));
collection_init(c->next);
}
c = c->next;
@@ -36,7 +35,7 @@ void collection_reset(Collection * c)
if (c->next) {
collection_reset(c->next);
- free(c->next);
+ nasm_free(c->next);
}
c->next = NULL;
diff --git a/rdoff/hash.c b/rdoff/hash.c
index ad2b568e..f2afad0f 100644
--- a/rdoff/hash.c
+++ b/rdoff/hash.c
@@ -1,5 +1,5 @@
/* ----------------------------------------------------------------------- *
- *
+ *
* Copyright 1996-2009 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
@@ -14,7 +14,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
diff --git a/rdoff/ldrdf.c b/rdoff/ldrdf.c
index 2db980f0..dd80d70e 100644
--- a/rdoff/ldrdf.c
+++ b/rdoff/ldrdf.c
@@ -56,9 +56,7 @@
#include <stdlib.h>
#include <string.h>
-#define RDOFF_UTILS
-
-#include "rdoff.h"
+#include "rdfutils.h"
#include "symtab.h"
#include "collectn.h"
#include "rdlib.h"
@@ -91,9 +89,6 @@ struct modulenode {
#include "ldsegs.h"
-#define newstr(str) strcpy(malloc(strlen(str) + 1),str)
-#define newstrcat(s1,s2) strcat(strcpy(malloc(strlen(s1)+strlen(s2)+1),s1),s2)
-
/* ==========================================================================
* Function prototypes of private utility functions
*/
@@ -200,10 +195,10 @@ static void loadmodule(const char *filename)
/* allocate a new module entry on the end of the modules list */
if (!modules) {
- modules = malloc(sizeof(*modules));
+ modules = nasm_malloc(sizeof(*modules));
lastmodule = modules;
} else {
- lastmodule->next = malloc(sizeof(*modules));
+ lastmodule->next = nasm_malloc(sizeof(*modules));
lastmodule = lastmodule->next;
}
@@ -224,7 +219,7 @@ static void loadmodule(const char *filename)
* factor if we decide to keep them)
*/
lastmodule->header = NULL;
- lastmodule->name = strdup(filename);
+ lastmodule->name = nasm_strdup(filename);
lastmodule->next = NULL;
processmodule(filename, lastmodule);
@@ -325,7 +320,7 @@ void processmodule(const char *filename, struct modulenode *mod)
* extract symbols from the header, and dump them into the
* symbol table
*/
- header = malloc(mod->f.header_len);
+ header = nasm_malloc(mod->f.header_len);
if (!header) {
fprintf(stderr, "ldrdf: not enough memory\n");
exit(1);
@@ -420,7 +415,7 @@ void processmodule(const char *filename, struct modulenode *mod)
* of this program...
*/
mod->f.header_loc = NULL;
- free(header);
+ nasm_free(header);
#endif
@@ -524,12 +519,12 @@ void symtab_add(const char *symbol, int segment, int32_t offset)
/*
* this is the first declaration of this symbol
*/
- ste = malloc(sizeof(symtabEnt));
+ ste = nasm_malloc(sizeof(symtabEnt));
if (!ste) {
fprintf(stderr, "ldrdf: out of memory\n");
exit(1);
}
- ste->name = strdup(symbol);
+ ste->name = nasm_strdup(symbol);
ste->segment = segment;
ste->offset = offset;
ste->flags = 0;
@@ -571,13 +566,13 @@ static void add_library(const char *name)
return;
}
if (!libraries) {
- lastlib = libraries = malloc(sizeof(*libraries));
+ lastlib = libraries = nasm_malloc(sizeof(*libraries));
if (!libraries) {
fprintf(stderr, "ldrdf: out of memory\n");
exit(1);
}
} else {
- lastlib->next = malloc(sizeof(*libraries));
+ lastlib->next = nasm_malloc(sizeof(*libraries));
if (!lastlib->next) {
fprintf(stderr, "ldrdf: out of memory\n");
exit(1);
@@ -626,7 +621,7 @@ static int search_libraries(void)
if (options.verbose > 3)
printf(" looking in module `%s'\n", f.name);
- header = malloc(f.header_len);
+ header = nasm_malloc(f.header_len);
if (!header) {
fprintf(stderr, "ldrdf: not enough memory\n");
exit(1);
@@ -671,20 +666,20 @@ static int search_libraries(void)
* there are modules on the module list by the time
* we get here.
*/
- lastmodule->next = malloc(sizeof(*lastmodule->next));
+ lastmodule->next = nasm_malloc(sizeof(*lastmodule->next));
if (!lastmodule->next) {
fprintf(stderr, "ldrdf: not enough memory\n");
exit(1);
}
lastmodule = lastmodule->next;
memcpy(&lastmodule->f, &f, sizeof(f));
- lastmodule->name = strdup(f.name);
+ lastmodule->name = nasm_strdup(f.name);
lastmodule->next = NULL;
processmodule(f.name, lastmodule);
break;
}
if (!keepfile) {
- free(f.name);
+ nasm_free(f.name);
f.name = NULL;
f.fp = NULL;
}
@@ -744,7 +739,7 @@ static void write_output(const char *filename)
printf("\nadding generic record from binary file %s\n",
generic_rec_file);
- hr = (rdfheaderrec *) malloc(sizeof(struct GenericRec));
+ hr = (rdfheaderrec *) nasm_malloc(sizeof(struct GenericRec));
if ((ff = fopen(generic_rec_file, "r")) == NULL) {
fprintf(stderr, "ldrdf: couldn't open %s for input\n",
generic_rec_file);
@@ -763,7 +758,7 @@ static void write_output(const char *filename)
hr->g.type = RDFREC_GENERIC;
hr->g.reclen = n;
rdfaddheader(rdfheader, hr);
- free(hr);
+ nasm_free(hr);
}
/*
@@ -774,19 +769,19 @@ static void write_output(const char *filename)
if ((n < 1) || (n >= MODLIB_NAME_MAX)) {
fprintf(stderr, "ldrdf: invalid length of module name `%s'\n",
- modname_specified);
+ modname_specified);
exit(1);
}
if (options.verbose)
printf("\nadding module name record %s\n", modname_specified);
- hr = (rdfheaderrec *) malloc(sizeof(struct ModRec));
+ hr = (rdfheaderrec *) nasm_malloc(sizeof(struct ModRec));
hr->m.type = RDFREC_MODNAME;
hr->m.reclen = n + 1;
strcpy(hr->m.modname, modname_specified);
rdfaddheader(rdfheader, hr);
- free(hr);
+ nasm_free(hr);
}
@@ -803,7 +798,7 @@ static void write_output(const char *filename)
outputseg[i].data = NULL;
if (!outputseg[i].length)
continue;
- outputseg[i].data = malloc(outputseg[i].length);
+ outputseg[i].data = nasm_malloc(outputseg[i].length);
if (!outputseg[i].data) {
fprintf(stderr, "ldrdf: out of memory\n");
exit(1);
@@ -841,7 +836,7 @@ static void write_output(const char *filename)
* Perform fixups, and add new header records where required
*/
- header = malloc(cur->f.header_len);
+ header = nasm_malloc(cur->f.header_len);
if (!header) {
fprintf(stderr, "ldrdf: out of memory\n");
exit(1);
@@ -1000,12 +995,12 @@ static void write_output(const char *filename)
* future reference
*/
if (!se) {
- se = malloc(sizeof(*se));
+ se = nasm_malloc(sizeof(*se));
if (!se) {
fprintf(stderr, "ldrdf: out of memory\n");
exit(1);
}
- se->name = strdup(hr->i.label);
+ se->name = nasm_strdup(hr->i.label);
se->flags = 0;
se->segment = availableseg++;
se->offset = 0;
@@ -1125,7 +1120,7 @@ static void write_output(const char *filename)
}
}
- free(header);
+ nasm_free(header);
done_seglocations(&segs);
}
@@ -1155,22 +1150,14 @@ static void write_output(const char *filename)
* the output file
*/
for (i = 0; i < nsegs; i++) {
- uint16_t s;
- int32_t l;
-
if (i == 2)
continue;
- s = translateint16_t(outputseg[i].type);
- fwrite(&s, 2, 1, f);
- s = translateint16_t(outputseg[i].number);
- fwrite(&s, 2, 1, f);
- s = translateint16_t(outputseg[i].reserved);
- fwrite(&s, 2, 1, f);
- l = translateint32_t(outputseg[i].length);
- fwrite(&l, 4, 1, f);
-
- fwrite(outputseg[i].data, outputseg[i].length, 1, f);
+ fwriteint16_t(outputseg[i].type, f);
+ fwriteint16_t(outputseg[i].number, f);
+ fwriteint16_t(outputseg[i].reserved, f);
+ fwriteint32_t(outputseg[i].length, f);
+ nasm_write(outputseg[i].data, outputseg[i].length, f);
}
fwritezero(10, f);
@@ -1204,6 +1191,8 @@ int main(int argc, char **argv)
int moduleloaded = 0;
char *respstrings[128] = { 0, };
+ rdoff_init();
+
options.verbose = 0;
options.align = 16;
options.dynalink = 0;
@@ -1252,11 +1241,11 @@ int main(int argc, char **argv)
case 'm':
if (argv[0][2] == 'n') {
modname_specified = argv[1];
- argv++, argc--;
- if (!argc) {
- fprintf(stderr, "ldrdf: -mn expects a module name\n");
- exit(1);
- }
+ argv++, argc--;
+ if (!argc) {
+ fprintf(stderr, "ldrdf: -mn expects a module name\n");
+ exit(1);
+ }
}
break;
case 'o':
@@ -1317,7 +1306,7 @@ int main(int argc, char **argv)
fprintf(stderr, "ldrdf: too many input files\n");
exit(1);
}
- *(respstrings + i) = newstr(buf);
+ *(respstrings + i) = nasm_strdup(buf);
argc++, i++;
}
fclose(f);
@@ -1331,8 +1320,8 @@ int main(int argc, char **argv)
generic_rec_file = argv[1];
argv++, argc--;
if (!argc) {
- fprintf(stderr, "ldrdf: -g expects a file name\n");
- exit(1);
+ fprintf(stderr, "ldrdf: -g expects a file name\n");
+ exit(1);
}
break;
default:
@@ -1371,12 +1360,12 @@ int main(int argc, char **argv)
break;
if (!strncmp(*argv, "-l", 2)) {
if (libpath && (argv[0][2] != '/'))
- add_library(newstrcat(libpath, *argv + 2));
+ add_library(nasm_strcat(libpath, *argv + 2));
else
add_library(*argv + 2);
} else {
if (objpath && (argv[0][0] != '/'))
- loadmodule(newstrcat(objpath, *argv));
+ loadmodule(nasm_strcat(objpath, *argv));
else
loadmodule(*argv);
moduleloaded = 1;
diff --git a/rdoff/rdf2bin.c b/rdoff/rdf2bin.c
index 1e33075c..1beb8245 100644
--- a/rdoff/rdf2bin.c
+++ b/rdoff/rdf2bin.c
@@ -1,5 +1,5 @@
/* ----------------------------------------------------------------------- *
- *
+ *
* Copyright 1996-2009 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
@@ -14,7 +14,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -254,7 +254,7 @@ static const char *getformat(const char *pathname)
const char *p;
static char fmt_buf[16];
- /*
+ /*
* Search backwards for the string "rdf2" followed by a string
* of alphanumeric characters. This should handle path prefixes,
* as well as extensions (e.g. C:\FOO\RDF2SREC.EXE).
@@ -303,6 +303,8 @@ int main(int argc, char **argv)
return 1;
}
+ rdoff_init();
+
argv++, argc--;
while (argc > 2) {
diff --git a/rdoff/rdfdump.c b/rdoff/rdfdump.c
index 2e977ace..b483477b 100644
--- a/rdoff/rdfdump.c
+++ b/rdoff/rdfdump.c
@@ -1,5 +1,5 @@
/* ----------------------------------------------------------------------- *
- *
+ *
* Copyright 1996-2014 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
@@ -14,7 +14,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -41,9 +41,7 @@
#include <stdlib.h>
#include <string.h>
-#define RDOFF_UTILS
-
-#include "rdoff.h"
+#include "rdfutils.h"
#define PROGRAM_VERSION "2.3"
@@ -57,9 +55,9 @@ static void print_header(int32_t length, int rdf_version)
uint16_t rs;
while (length > 0) {
- fread(&t, 1, 1, infile);
+ nasm_read(&t, 1, infile);
if (rdf_version >= 2) {
- fread(&reclen, 1, 1, infile);
+ nasm_read(&reclen, 1, infile);
}
switch (t) {
case RDFREC_GENERIC: /* generic record */
@@ -69,10 +67,10 @@ static void print_header(int32_t length, int rdf_version)
case RDFREC_RELOC: /* relocation record */
case RDFREC_SEGRELOC: /* segment relocation */
- fread(&s, 1, 1, infile);
- fread(&o, 4, 1, infile);
- fread(&l, 1, 1, infile);
- fread(&rs, 2, 1, infile);
+ nasm_read(&s, 1, infile);
+ nasm_read(&o, 4, infile);
+ nasm_read(&l, 1, infile);
+ nasm_read(&rs, 2, infile);
printf(" %s: location (%04x:%08"PRIx32"), length %d, "
"referred seg %04x\n",
t == 1 ? "relocation" : "seg relocation", (int)s,
@@ -88,17 +86,17 @@ static void print_header(int32_t length, int rdf_version)
case RDFREC_IMPORT: /* import record */
case RDFREC_FARIMPORT: /* import far symbol */
- fread(&flags, 1, 1, infile);
- fread(&rs, 2, 1, infile);
+ nasm_read(&flags, 1, infile);
+ nasm_read(&rs, 2, infile);
ll = 0;
if (rdf_version == 1) {
do {
- fread(&buf[ll], 1, 1, infile);
+ nasm_read(&buf[ll], 1, infile);
} while (buf[ll++]);
} else {
for (; ll < reclen - 3; ll++)
- fread(&buf[ll], 1, 1, infile);
+ nasm_read(&buf[ll], 1, infile);
}
if (t == 7)
@@ -117,18 +115,18 @@ static void print_header(int32_t length, int rdf_version)
break;
case RDFREC_GLOBAL: /* export record */
- fread(&flags, 1, 1, infile);
- fread(&s, 1, 1, infile);
- fread(&o, 4, 1, infile);
+ nasm_read(&flags, 1, infile);
+ nasm_read(&s, 1, infile);
+ nasm_read(&o, 4, infile);
ll = 0;
if (rdf_version == 1) {
do {
- fread(&buf[ll], 1, 1, infile);
+ nasm_read(&buf[ll], 1, infile);
} while (buf[ll++]);
} else {
for (; ll < reclen - 6; ll++)
- fread(&buf[ll], 1, 1, infile);
+ nasm_read(&buf[ll], 1, infile);
}
printf((flags & SYM_GLOBAL) ? " export" : " public");
if (flags & SYM_FUNCTION)
@@ -145,11 +143,11 @@ static void print_header(int32_t length, int rdf_version)
ll = 0;
if (rdf_version == 1) {
do {
- fread(&buf[ll], 1, 1, infile);
+ nasm_read(&buf[ll], 1, infile);
} while (buf[ll++]);
} else {
for (; ll < reclen; ll++)
- fread(&buf[ll], 1, 1, infile);
+ nasm_read(&buf[ll], 1, infile);
}
if (t == 4)
printf(" dll: %s\n", buf);
@@ -160,7 +158,7 @@ static void print_header(int32_t length, int rdf_version)
break;
case RDFREC_BSS: /* BSS reservation */
- fread(&ll, 4, 1, infile);
+ nasm_read(&ll, 4, infile);
printf(" bss reservation: %08"PRIx32" bytes\n", translateint32_t(ll));
if (rdf_version == 1)
length -= 5;
@@ -172,11 +170,11 @@ static void print_header(int32_t length, int rdf_version)
uint16_t seg, align;
uint32_t size;
- fread(&seg, 2, 1, infile);
- fread(&size, 4, 1, infile);
- fread(&align, 2, 1, infile);
+ nasm_read(&seg, 2, infile);
+ nasm_read(&size, 4, infile);
+ nasm_read(&align, 2, infile);
for (ll = 0; ll < reclen - 8; ll++)
- fread(buf + ll, 1, 1, infile);
+ nasm_read(buf + ll, 1, infile);
printf(" common: segment %04x = %s, %"PRId32":%d\n",
translateint16_t(seg), buf, translateint32_t(size),
translateint16_t(align));
@@ -221,6 +219,8 @@ int main(int argc, char **argv)
exit(1);
}
+ rdoff_init();
+
if (!strcmp(argv[1], "-v")) {
verbose = 1;
if (argc < 3) {
@@ -236,7 +236,7 @@ int main(int argc, char **argv)
exit(1);
}
- fread(id, 6, 1, infile);
+ nasm_read(id, 6, infile);
if (strncmp(id, "RDOFF", 5)) {
fputs("rdfdump: File does not contain valid RDOFF header\n",
stderr);
@@ -251,23 +251,23 @@ int main(int argc, char **argv)
version = id[5] - '0';
if (version > 1) {
- fread(&l, 4, 1, infile);
+ nasm_read(&l, 4, infile);
objectlength = translateint32_t(l);
printf("Object content size: %"PRId32" bytes\n", objectlength);
}
- fread(&l, 4, 1, infile);
+ nasm_read(&l, 4, infile);
headerlength = translateint32_t(l);
printf("Header (%"PRId32" bytes):\n", headerlength);
print_header(headerlength, version);
if (version == 1) {
- fread(&l, 4, 1, infile);
+ nasm_read(&l, 4, infile);
l = translateint32_t(l);
printf("\nText segment length = %"PRId32" bytes\n", l);
offset = 0;
while (l--) {
- fread(id, 1, 1, infile);
+ nasm_read(id, 1, infile);
if (verbose) {
if (offset % 16 == 0)
printf("\n%08"PRIx32" ", offset);
@@ -278,14 +278,14 @@ int main(int argc, char **argv)
if (verbose)
printf("\n\n");
- fread(&l, 4, 1, infile);
+ nasm_read(&l, 4, infile);
l = translateint32_t(l);
printf("Data segment length = %"PRId32" bytes\n", l);
if (verbose) {
offset = 0;
while (l--) {
- fread(id, 1, 1, infile);
+ nasm_read(id, 1, infile);
if (offset % 16 == 0)
printf("\n%08"PRIx32" ", offset);
printf(" %02x", (int)(uint8_t)id[0]);
@@ -295,7 +295,7 @@ int main(int argc, char **argv)
}
} else {
do {
- fread(&s, 2, 1, infile);
+ nasm_read(&s, 2, infile);
s = translateint16_t(s);
if (!s) {
printf("\nNULL segment\n");
@@ -306,18 +306,18 @@ int main(int argc, char **argv)
translatesegmenttype(s));
nsegments++;
- fread(&s, 2, 1, infile);
+ nasm_read(&s, 2, infile);
printf(" Number = %04X\n", (int)translateint16_t(s));
- fread(&s, 2, 1, infile);
+ nasm_read(&s, 2, infile);
printf(" Resrvd = %04X\n", (int)translateint16_t(s));
- fread(&l, 4, 1, infile);
+ nasm_read(&l, 4, infile);
l = translateint32_t(l);
printf(" Length = %"PRId32" bytes\n", l);
segmentcontentlength += l;
offset = 0;
while (l--) {
- fread(id, 1, 1, infile);
+ nasm_read(id, 1, infile);
if (verbose) {
if (offset % 16 == 0)
printf("\n%08"PRIx32" ", offset);
diff --git a/rdoff/rdflib.c b/rdoff/rdflib.c
index a1c3abe7..ee7f19f6 100644
--- a/rdoff/rdflib.c
+++ b/rdoff/rdflib.c
@@ -1,5 +1,5 @@
/* ----------------------------------------------------------------------- *
- *
+ *
* Copyright 1996-2009 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
@@ -14,7 +14,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -57,6 +57,7 @@
*/
#include "compiler.h"
+#include "rdfutils.h"
#include <stdio.h>
#include <stdlib.h>
@@ -168,6 +169,8 @@ int main(int argc, char **argv)
exit(1);
}
+ rdoff_init();
+
switch (argv[1][0]) {
case 'c': /* create library */
fp = fopen(argv[2], "wb");
@@ -176,12 +179,10 @@ int main(int argc, char **argv)
perror("rdflib");
exit(1);
}
- fwrite(sig_modname, 1, strlen(sig_modname) + 1, fp);
- fwrite(rdl_signature, 1, strlen(rdl_signature), fp);
+ nasm_write(sig_modname, strlen(sig_modname) + 1, fp);
+ nasm_write(rdl_signature, strlen(rdl_signature), fp);
t = time(NULL);
- l = sizeof(t);
- fwrite(&l, sizeof(l), 1, fp);
- fwrite(&t, 1, l, fp);
+ fwriteint32_t(t, fp);
fclose(fp);
break;
@@ -369,12 +370,14 @@ int main(int argc, char **argv)
/* check against desired name */
if (!strcmp(buf, argv[3])) {
- fread(p = rdbuf, 1, sizeof(rdbuf), fptmp);
+ if (fread(p = rdbuf, 1, sizeof(rdbuf), fptmp) < 10) {
+ nasm_fatal(0, "short read on input");
+ }
l = *(int32_t *)(p + 6);
fseek(fptmp, l, SEEK_CUR);
break;
} else {
- fwrite(buf, 1, strlen(buf) + 1, fp); /* module name */
+ nasm_write(buf, strlen(buf) + 1, fp); /* module name */
if ((c = copybytes(fptmp, fp, 6)) >= '2') {
l = copyint32_t(fptmp, fp); /* version 2 or above */
copybytes(fptmp, fp, l); /* entire object */
diff --git a/rdoff/rdfload.c b/rdoff/rdfload.c
index 5a7ab631..6977a707 100644
--- a/rdoff/rdfload.c
+++ b/rdoff/rdfload.c
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------- *
- *
- * Copyright 1996-2009 The NASM Authors - All Rights Reserved
+ *
+ * Copyright 1996-2017 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
*
@@ -14,7 +14,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -61,7 +61,7 @@ rdfmodule *rdfload(const char *filename)
char *hdr;
rdfheaderrec *r;
- f = malloc(sizeof(rdfmodule));
+ f = nasm_malloc(sizeof(rdfmodule));
if (f == NULL) {
rdf_errno = RDF_ERR_NOMEM;
return NULL;
@@ -69,32 +69,32 @@ rdfmodule *rdfload(const char *filename)
f->symtab = symtabNew();
if (!f->symtab) {
- free(f);
+ nasm_free(f);
rdf_errno = RDF_ERR_NOMEM;
return NULL;
}
/* open the file */
if (rdfopen(&(f->f), filename)) {
- free(f);
+ nasm_free(f);
return NULL;
}
/* read in text and data segments, and header */
- f->t = malloc(f->f.seg[0].length);
- f->d = malloc(f->f.seg[1].length); /* BSS seg allocated later */
- hdr = malloc(f->f.header_len);
+ f->t = nasm_malloc(f->f.seg[0].length);
+ f->d = nasm_malloc(f->f.seg[1].length); /* BSS seg allocated later */
+ hdr = nasm_malloc(f->f.header_len);
if (!f->t || !f->d || !hdr) {
rdf_errno = RDF_ERR_NOMEM;
rdfclose(&f->f);
if (f->t)
- free(f->t);
+ nasm_free(f->t);
if (f->d)
- free(f->d);
- free(f);
- free(hdr);
+ nasm_free(f->d);
+ nasm_free(f);
+ nasm_free(hdr);
return NULL;
}
@@ -102,10 +102,10 @@ rdfmodule *rdfload(const char *filename)
rdfloadseg(&f->f, RDOFF_CODE, f->t) ||
rdfloadseg(&f->f, RDOFF_DATA, f->d)) {
rdfclose(&f->f);
- free(f->t);
- free(f->d);
- free(f);
- free(hdr);
+ nasm_free(f->t);
+ nasm_free(f->d);
+ nasm_free(f);
+ nasm_free(hdr);
return NULL;
}
@@ -118,12 +118,12 @@ rdfmodule *rdfload(const char *filename)
bsslength += r->b.amount;
}
- f->b = malloc(bsslength);
+ f->b = nasm_malloc(bsslength);
if (bsslength && (!f->b)) {
- free(f->t);
- free(f->d);
- free(f);
- free(hdr);
+ nasm_free(f->t);
+ nasm_free(f->d);
+ nasm_free(f);
+ nasm_free(hdr);
rdf_errno = RDF_ERR_NOMEM;
return NULL;
}
@@ -195,7 +195,7 @@ int rdf_relocate(rdfmodule * m)
e.segment == 1 ? m->datarel : /* 1 -> data */
m->bssrel); /* 2 -> bss */
e.flags = 0;
- e.name = malloc(strlen(r->e.label) + 1);
+ e.name = nasm_malloc(strlen(r->e.label) + 1);
if (!e.name)
return 1;
diff --git a/rdoff/rdfload.h b/rdoff/rdfload.h
index 87d7ecc5..1ca5e92d 100644
--- a/rdoff/rdfload.h
+++ b/rdoff/rdfload.h
@@ -12,9 +12,7 @@
#ifndef RDOFF_RDFLOAD_H
#define RDOFF_RDFLOAD_H 1
-#define RDOFF_UTILS
-
-#include "rdoff.h"
+#include "rdfutils.h"
typedef struct RDFModuleStruct {
rdffile f; /* file structure */
diff --git a/rdoff/rdfutils.h b/rdoff/rdfutils.h
new file mode 100644
index 00000000..27f21443
--- /dev/null
+++ b/rdoff/rdfutils.h
@@ -0,0 +1,165 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 1996-2017 The NASM Authors - All Rights Reserved
+ * See the file AUTHORS included with the NASM distribution for
+ * the specific copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * rdfutils.h
+ *
+ * Internal header file for RDOFF utilities
+ */
+
+#ifndef RDOFF_RDFUTILS_H
+#define RDOFF_RDFUTILS_H 1
+
+#include "compiler.h"
+#include "nasmlib.h"
+#include "error.h"
+#include "rdoff.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+
+typedef union RDFHeaderRec {
+ char type; /* invariant throughout all below */
+ struct GenericRec g; /* type 0 */
+ struct RelocRec r; /* type == 1 / 6 */
+ struct ImportRec i; /* type == 2 / 7 */
+ struct ExportRec e; /* type == 3 */
+ struct DLLRec d; /* type == 4 */
+ struct BSSRec b; /* type == 5 */
+ struct ModRec m; /* type == 8 */
+ struct CommonRec c; /* type == 10 */
+} rdfheaderrec;
+
+struct SegmentHeaderRec {
+ /* information from file */
+ uint16_t type;
+ uint16_t number;
+ uint16_t reserved;
+ int32_t length;
+
+ /* information built up here */
+ int32_t offset;
+ uint8_t *data; /* pointer to segment data if it exists in memory */
+};
+
+typedef struct RDFFileInfo {
+ FILE *fp; /* file descriptor; must be open to use this struct */
+ int rdoff_ver; /* should be 1; any higher => not guaranteed to work */
+ int32_t header_len;
+ int32_t header_ofs;
+
+ uint8_t *header_loc; /* keep location of header */
+ int32_t header_fp; /* current location within header for reading */
+
+ struct SegmentHeaderRec seg[RDF_MAXSEGS];
+ int nsegs;
+
+ int32_t eof_offset; /* offset of the first uint8_t beyond the end of this
+ module */
+
+ char *name; /* name of module in libraries */
+ int *refcount; /* pointer to reference count on file, or NULL */
+} rdffile;
+
+#define BUF_BLOCK_LEN 4088 /* selected to match page size (4096)
+ * on 80x86 machines for efficiency */
+typedef struct memorybuffer {
+ int length;
+ uint8_t buffer[BUF_BLOCK_LEN];
+ struct memorybuffer *next;
+} memorybuffer;
+
+typedef struct {
+ memorybuffer *buf; /* buffer containing header records */
+ int nsegments; /* number of segments to be written */
+ int32_t seglength; /* total length of all the segments */
+} rdf_headerbuf;
+
+/* segments used by RDOFF, understood by rdoffloadseg */
+#define RDOFF_CODE 0
+#define RDOFF_DATA 1
+#define RDOFF_HEADER -1
+/* mask for 'segment' in relocation records to find if relative relocation */
+#define RDOFF_RELATIVEMASK 64
+/* mask to find actual segment value in relocation records */
+#define RDOFF_SEGMENTMASK 63
+
+extern int rdf_errno;
+
+/* rdf_errno can hold these error codes */
+enum {
+ /* 0 */ RDF_OK,
+ /* 1 */ RDF_ERR_OPEN,
+ /* 2 */ RDF_ERR_FORMAT,
+ /* 3 */ RDF_ERR_READ,
+ /* 4 */ RDF_ERR_UNKNOWN,
+ /* 5 */ RDF_ERR_HEADER,
+ /* 6 */ RDF_ERR_NOMEM,
+ /* 7 */ RDF_ERR_VER,
+ /* 8 */ RDF_ERR_RECTYPE,
+ /* 9 */ RDF_ERR_RECLEN,
+ /* 10 */ RDF_ERR_SEGMENT
+};
+
+/* library init */
+void rdoff_init(void);
+
+/* utility functions */
+int32_t translateint32_t(int32_t in);
+uint16_t translateint16_t(uint16_t in);
+char *translatesegmenttype(uint16_t type);
+
+/* RDOFF file manipulation functions */
+int rdfopen(rdffile * f, const char *name);
+int rdfopenhere(rdffile * f, FILE * fp, int *refcount, const char *name);
+int rdfclose(rdffile * f);
+int rdffindsegment(rdffile * f, int segno);
+int rdfloadseg(rdffile * f, int segment, void *buffer);
+rdfheaderrec *rdfgetheaderrec(rdffile * f); /* returns static storage */
+void rdfheaderrewind(rdffile * f); /* back to start of header */
+void rdfperror(const char *app, const char *name);
+
+/* functions to write a new RDOFF header to a file -
+ use rdfnewheader to allocate a header, rdfaddheader to add records to it,
+ rdfaddsegment to notify the header routines that a segment exists, and
+ to tell it how int32_t the segment will be.
+ rdfwriteheader to write the file id, object length, and header
+ to a file, and then rdfdoneheader to dispose of the header */
+
+rdf_headerbuf *rdfnewheader(void);
+int rdfaddheader(rdf_headerbuf * h, rdfheaderrec * r);
+int rdfaddsegment(rdf_headerbuf * h, int32_t seglength);
+int rdfwriteheader(FILE * fp, rdf_headerbuf * h);
+void rdfdoneheader(rdf_headerbuf * h);
+
+#endif /* RDOFF_RDFUTILS_H */
diff --git a/rdoff/rdlar.c b/rdoff/rdlar.c
index 98b0f8f6..419d2d0d 100644
--- a/rdoff/rdlar.c
+++ b/rdoff/rdlar.c
@@ -1,5 +1,5 @@
/* ----------------------------------------------------------------------- *
- *
+ *
* Copyright 1996-2009 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
@@ -14,7 +14,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -285,6 +285,8 @@ int main(int argc, char **argv)
exit(1);
}
+ rdoff_init();
+
/* Check whether some modifiers were specified */
for (i = 1; i < strlen(argv[1]); i++) {
switch (c = argv[1][i]) {
diff --git a/rdoff/rdlib.c b/rdoff/rdlib.c
index 7f8ddac7..d8f2fc7a 100644
--- a/rdoff/rdlib.c
+++ b/rdoff/rdlib.c
@@ -1,5 +1,5 @@
/* ----------------------------------------------------------------------- *
- *
+ *
* Copyright 1996-2014 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
@@ -14,7 +14,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -41,9 +41,7 @@
#include <stdlib.h>
#include <string.h>
-#define RDOFF_UTILS
-
-#include "rdoff.h"
+#include "rdfutils.h"
#include "rdlib.h"
#include "rdlar.h"
@@ -92,11 +90,11 @@ int rdl_verify(const char *filename)
* content
* so we can handle it uniformaly with RDOFF2 modules.
*/
- fread(buf, 6, 1, fp);
+ nasm_read(buf, 6, fp);
buf[6] = 0;
/* Currently, nothing useful to do with signature block.. */
} else {
- fread(buf, 6, 1, fp);
+ nasm_read(buf, 6, fp);
buf[6] = 0;
if (strncmp(buf, "RDOFF", 5)) {
fclose(fp);
@@ -106,7 +104,7 @@ int rdl_verify(const char *filename)
return rdl_error = lastresult = 3;
}
}
- fread(&length, 4, 1, fp);
+ nasm_read(&length, 4, fp);
fseek(fp, length, SEEK_CUR); /* skip over the module */
}
fclose(fp);
@@ -120,7 +118,7 @@ int rdl_open(struct librarynode *lib, const char *name)
return i;
lib->fp = NULL;
- lib->name = strdup(name);
+ lib->name = nasm_strdup(name);
lib->referenced = 0;
lib->next = NULL;
return 0;
@@ -165,7 +163,7 @@ int rdl_searchlib(struct librarynode *lib, const char *label, rdffile * f)
if (feof(lib->fp))
break;
if (!strcmp(buf + t, ".dir")) { /* skip over directory */
- fread(&l, 4, 1, lib->fp);
+ nasm_read(&l, 4, lib->fp);
fseek(lib->fp, l, SEEK_CUR);
continue;
}
@@ -179,7 +177,7 @@ int rdl_searchlib(struct librarynode *lib, const char *label, rdffile * f)
/*
* read in the header, and scan for exported symbols
*/
- hdr = malloc(f->header_len);
+ hdr = nasm_malloc(f->header_len);
rdfloadseg(f, RDOFF_HEADER, hdr);
while ((r = rdfgetheaderrec(f))) {
@@ -187,7 +185,7 @@ int rdl_searchlib(struct librarynode *lib, const char *label, rdffile * f)
continue;
if (!strcmp(r->e.label, label)) { /* match! */
- free(hdr); /* reset to 'just open' */
+ nasm_free(hdr); /* reset to 'just open' */
f->header_loc = NULL; /* state... */
f->header_fp = 0;
return 1;
@@ -254,7 +252,7 @@ int rdl_openmodule(struct librarynode *lib, int moduleno, rdffile * f)
return rdl_error;
}
- fread(buf, 6, 1, lib->fp);
+ nasm_read(buf, 6, lib->fp);
buf[6] = 0;
if (buf[t] == '.') {
/* do nothing */
@@ -272,7 +270,7 @@ int rdl_openmodule(struct librarynode *lib, int moduleno, rdffile * f)
return rdl_error = 3;
}
- fread(&length, 4, 1, lib->fp);
+ nasm_read(&length, 4, lib->fp);
fseek(lib->fp, length, SEEK_CUR); /* skip over the module */
}
if (!--lib->referenced) {
diff --git a/rdoff/rdoff.c b/rdoff/rdoff.c
index ef9a5651..77fec399 100644
--- a/rdoff/rdoff.c
+++ b/rdoff/rdoff.c
@@ -1,5 +1,5 @@
/* ----------------------------------------------------------------------- *
- *
+ *
* Copyright 1996-2014 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
@@ -14,7 +14,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -47,13 +47,7 @@
#include <string.h>
#include <errno.h>
-#define RDOFF_UTILS
-
-#include "rdoff.h"
-
-#define newstr(str) strcpy(malloc(strlen(str) + 1),str)
-#define newstrcat(s1,s2) strcat(strcpy(malloc(strlen(s1) + strlen(s2) + 1), \
- s1),s2)
+#include "rdfutils.h"
/*
* Comment this out to allow the module to read & write header record types
@@ -72,7 +66,7 @@ static memorybuffer *newmembuf(void)
{
memorybuffer *t;
- t = malloc(sizeof(memorybuffer));
+ t = nasm_malloc(sizeof(memorybuffer));
if (!t)
return NULL;
@@ -134,8 +128,7 @@ static void membufdump(memorybuffer * b, FILE * fp)
if (!b)
return;
- fwrite(b->buffer, 1, b->length, fp);
-
+ nasm_write(b->buffer, b->length, fp);
membufdump(b->next, fp);
}
@@ -151,7 +144,7 @@ static void freemembuf(memorybuffer * b)
if (!b)
return;
freemembuf(b->next);
- free(b);
+ nasm_free(b);
}
/* =========================================================================
@@ -234,6 +227,22 @@ const char *rdf_errors[11] = {
int rdf_errno = 0;
/* ========================================================================
+ * Hook for nasm_error() to work
+ * ======================================================================== */
+static void rdoff_verror(int severity, const char *fmt, va_list val)
+{
+ vfprintf(stderr, fmt, val);
+
+ if ((severity & ERR_MASK) >= ERR_FATAL)
+ exit(1);
+}
+
+void rdoff_init(void)
+{
+ nasm_set_verror(rdoff_verror);
+}
+
+/* ========================================================================
The library functions
======================================================================== */
@@ -266,7 +275,11 @@ int rdfopenhere(rdffile * f, FILE * fp, int *refcount, const char *name)
f->fp = fp;
initpos = ftell(fp);
- fread(buf, 6, 1, f->fp); /* read header */
+ /* read header */
+ if (fread(buf, 1, 6, f->fp) != 6) {
+ fclose(f->fp);
+ return rdf_errno = RDF_ERR_READ;
+ }
buf[6] = 0;
if (strcmp(buf, RDOFFId)) {
@@ -326,7 +339,7 @@ int rdfopenhere(rdffile * f, FILE * fp, int *refcount, const char *name)
fseek(f->fp, initpos, SEEK_SET);
f->header_loc = NULL;
- f->name = newstr(name);
+ f->name = nasm_strdup(name);
f->refcount = refcount;
if (refcount)
(*refcount)++;
@@ -339,7 +352,7 @@ int rdfclose(rdffile * f)
fclose(f->fp);
f->fp = NULL;
}
- free(f->name);
+ nasm_free(f->name);
return 0;
}
@@ -510,7 +523,7 @@ void rdfheaderrewind(rdffile * f)
rdf_headerbuf *rdfnewheader(void)
{
- rdf_headerbuf *hb = malloc(sizeof(rdf_headerbuf));
+ rdf_headerbuf *hb = nasm_malloc(sizeof(rdf_headerbuf));
if (hb == NULL)
return NULL;
@@ -589,14 +602,12 @@ int rdfwriteheader(FILE * fp, rdf_headerbuf * h)
{
int32_t l, l2;
- fwrite(RDOFFId, 1, strlen(RDOFFId), fp);
+ nasm_write(RDOFFId, strlen(RDOFFId), fp);
l = membuflength(h->buf);
l2 = l + 14 + 10 * h->nsegments + h->seglength;
- l = translateint32_t(l);
- l2 = translateint32_t(l2);
- fwrite(&l2, 4, 1, fp); /* object length */
- fwrite(&l, 4, 1, fp); /* header length */
+ fwriteint32_t(l, fp);
+ fwriteint32_t(l2, fp);
membufdump(h->buf, fp);
@@ -606,5 +617,5 @@ int rdfwriteheader(FILE * fp, rdf_headerbuf * h)
void rdfdoneheader(rdf_headerbuf * h)
{
freemembuf(h->buf);
- free(h);
+ nasm_free(h);
}
diff --git a/rdoff/rdx.c b/rdoff/rdx.c
index 240ab592..f52e6879 100644
--- a/rdoff/rdx.c
+++ b/rdoff/rdx.c
@@ -1,5 +1,5 @@
/* ----------------------------------------------------------------------- *
- *
+ *
* Copyright 1996-2009 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
@@ -14,7 +14,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -62,6 +62,8 @@ int main(int argc, char **argv)
exit(255);
}
+ rdoff_init();
+
m = rdfload(argv[1]);
if (!m) {
diff --git a/rdoff/segtab.c b/rdoff/segtab.c
index ab162a9f..3c076b6e 100644
--- a/rdoff/segtab.c
+++ b/rdoff/segtab.c
@@ -1,5 +1,5 @@
/* ----------------------------------------------------------------------- *
- *
+ *
* Copyright 1996-2014 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
@@ -14,7 +14,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -31,10 +31,7 @@
*
* ----------------------------------------------------------------------- */
-#include "compiler.h"
-
-#include <stdio.h>
-#include <stdlib.h>
+#include "rdfutils.h"
#include "segtab.h"
struct segtabnode {
@@ -76,7 +73,7 @@ static void descend_tree_add(struct segtabnode **node,
struct segtabnode *n;
if (*node == NULL) {
- *node = malloc(sizeof(**node));
+ *node = nasm_malloc(sizeof(**node));
if (!*node) {
fprintf(stderr, "segment table: out of memory\n");
exit(1);
@@ -149,7 +146,7 @@ static void freenode(struct segtabnode *n)
return;
freenode(n->left);
freenode(n->right);
- free(n);
+ nasm_free(n);
}
void done_seglocations(segtab * root)
diff --git a/rdoff/symtab.c b/rdoff/symtab.c
index 1dfee1ae..270fb89c 100644
--- a/rdoff/symtab.c
+++ b/rdoff/symtab.c
@@ -1,5 +1,5 @@
/* ----------------------------------------------------------------------- *
- *
+ *
* Copyright 1996-2009 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
@@ -14,7 +14,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -31,13 +31,13 @@
*
* ----------------------------------------------------------------------- */
-/*
+/*
* symtab.c Routines to maintain and manipulate a symbol table
*
* These routines donated to the NASM effort by Graeme Defty.
*/
-#include "compiler.h"
+#include "rdfutils.h"
#include <stdio.h>
#include <stdlib.h>
@@ -66,7 +66,7 @@ void *symtabNew(void)
{
symtab mytab;
- mytab = (symtabTab *) calloc(SYMTABSIZE, sizeof(symtabNode *));
+ mytab = (symtabTab *) nasm_calloc(SYMTABSIZE, sizeof(symtabNode *));
if (mytab == NULL) {
fprintf(stderr, "symtab: out of memory\n");
exit(3);
@@ -86,11 +86,11 @@ void symtabDone(void *stab)
for (this = (*mytab)[i]; this; this = next) {
next = this->next;
- free(this);
+ nasm_free(this);
}
}
- free(*mytab);
+ nasm_free(*mytab);
}
/* ------------------------------------- */
@@ -100,7 +100,7 @@ void symtabInsert(void *stab, symtabEnt * ent)
symtabNode *node;
int slot;
- node = malloc(sizeof(symtabNode));
+ node = nasm_malloc(sizeof(symtabNode));
if (node == NULL) {
fprintf(stderr, "symtab: out of memory\n");
exit(3);
diff --git a/tools/release b/tools/release
index 06d2ee42..dd68ec7c 100755
--- a/tools/release
+++ b/tools/release
@@ -38,13 +38,16 @@ unset GIT_DIR
git clone -s -l "$HERE" nasm
rm -rf nasm/.git nasm/.gitignore
+# How to invoke make if makej is not set
+makej="${makej:-make}"
+
# Create files which are in the release but automatically generated
cd nasm
./autogen.sh
./configure --prefix=/usr/local
-make perlreq spec manpages
-make alldeps
-make distclean
+$makej perlreq spec manpages
+$makej alldeps
+$makej distclean
cd ..
# Clean up any previous attempt
@@ -75,9 +78,9 @@ find nasm-"$version" -not -type d -print > main
# Create documentation
cd nasm-"$version"
./configure --prefix=/usr/local
-make doc
+$makej doc
# Remove intermediate files.
-make cleaner
+$makej cleaner
cd ..
# Remove non-documentation
diff --git a/version b/version
index 68832e0a..562d30e4 100644
--- a/version
+++ b/version
@@ -1 +1 @@
-2.13rc18
+2.13rc20