rdoff: use nasm-provided safe memory allocation and I/O

We already have abort-on-error memory allocation and I/O operations in
nasmlib, so use them for rdoff as well.

Delete long-since-obsolete rdoff Mkfiles directory.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:
H. Peter Anvin 2017-04-17 13:52:19 -07:00
parent 74fa0a736a
commit 8dc965347d
25 changed files with 268 additions and 648 deletions

View File

@ -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/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
rdoff/ldrdf.$(O): rdoff/ldrdf.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
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

View File

@ -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 \

View File

@ -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 &

View File

@ -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 *);
/*

View File

@ -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 */

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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.

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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) {

View File

@ -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);

View File

@ -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;
@ -374,7 +375,7 @@ int main(int argc, char **argv)
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 */

View File

@ -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;

View File

@ -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 */

View File

@ -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]) {

View File

@ -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) {

View File

@ -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);
}
/* =========================================================================
@ -233,6 +226,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
======================================================================== */
@ -326,7 +335,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 +348,7 @@ int rdfclose(rdffile * f)
fclose(f->fp);
f->fp = NULL;
}
free(f->name);
nasm_free(f->name);
return 0;
}
@ -510,7 +519,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 +598,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 +613,5 @@ int rdfwriteheader(FILE * fp, rdf_headerbuf * h)
void rdfdoneheader(rdf_headerbuf * h)
{
freemembuf(h->buf);
free(h);
nasm_free(h);
}

View File

@ -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) {

View File

@ -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)

View File

@ -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);