diff options
author | Robert de Bath <rdebath@poboxes.com> | 1996-03-24 17:45:55 +0100 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2013-10-23 23:29:43 +0200 |
commit | fe22c37817ce338fbbc90b239320248c270957fa (patch) | |
tree | d9550410c4a20bdd382fcc58d2d3d7c5e04e5245 /ld | |
parent | a7aba15e8efffb1c5d3097656f1a93955a64f01f (diff) | |
parent | 42192453ea219b80d0bf9f41e51e36d3d4d0740b (diff) | |
download | dev86-fe22c37817ce338fbbc90b239320248c270957fa.tar.gz |
Import Dev86-0.0.4.tar.gzv0.0.4
Diffstat (limited to 'ld')
-rw-r--r-- | ld/Makefile | 19 | ||||
-rw-r--r-- | ld/Makefile.minix | 20 | ||||
-rw-r--r-- | ld/a.out.h | 115 | ||||
-rw-r--r-- | ld/const.h | 2 | ||||
-rw-r--r-- | ld/dumps.c | 6 | ||||
-rw-r--r-- | ld/include/fcntl.h | 2 | ||||
-rw-r--r-- | ld/io.c | 21 | ||||
-rw-r--r-- | ld/ld.c | 40 | ||||
-rw-r--r-- | ld/readobj.c | 31 | ||||
-rw-r--r-- | ld/table.c | 21 | ||||
-rw-r--r-- | ld/writebin.c | 80 |
11 files changed, 239 insertions, 118 deletions
diff --git a/ld/Makefile b/ld/Makefile index 756a25c..d93579a 100644 --- a/ld/Makefile +++ b/ld/Makefile @@ -1,13 +1,24 @@ -CFLAGS =-O -DBSD_A_OUT -DSTANDARD_GNU_A_OUT -LDFLAGS =-N -s + +ifneq ($(TOPDIR),) +include $(TOPDIR)/Make.defs +else +CC=bcc +LDFLAGS=-s +endif OBJS =dumps.o io.o ld.o readobj.o table.o typeconv.o writebin.o -ld: $(OBJS) +all: ld86 + +ld86: $(OBJS) $(CC) $(LDFLAGS) $(OBJS) -o $@ +install: ld86 + install -d $(LIBDIR) + install -m 755 ld86 $(LIBDIR) + clean: - rm -f $(OBJS) ld + rm -f $(OBJS) ld86 dumps.o: dumps.c const.h config.h obj.h type.h globvar.h io.o: io.c const.h config.h obj.h type.h globvar.h diff --git a/ld/Makefile.minix b/ld/Makefile.minix deleted file mode 100644 index 7f819fa..0000000 --- a/ld/Makefile.minix +++ /dev/null @@ -1,20 +0,0 @@ -CFLAGS =-O -DBSD_A_OUT -LDFLAGS = - -OBJS =dumps.o io.o ld.o readobj.o table.o typeconv.o writebin.o - -ld: $(OBJS) - $(CC) $(LDFLAGS) $(OBJS) -o $@ - chmem =232000 $@ - -clean: - rm -f $(OBJS) ld - -dumps.o: dumps.c const.h config.h obj.h type.h globvar.h -io.o: io.c const.h config.h obj.h type.h globvar.h -ld.o: ld.c const.h config.h byteord.h type.h globvar.h -readobj.o: readobj.c ar.h const.h config.h byteord.h obj.h type.h globvar.h -table.o: table.c const.h config.h align.h obj.h type.h globvar.h -typeconv.o: typeconv.c const.h config.h type.h globvar.h -writebin.o: writebin.c bsd-a.out.h a.out.gnu.h const.h config.h obj.h type.h \ - globvar.h diff --git a/ld/a.out.h b/ld/a.out.h new file mode 100644 index 0000000..f6a7b94 --- /dev/null +++ b/ld/a.out.h @@ -0,0 +1,115 @@ +/* Copyright (C) 1990-1996 + * This file is part of the ld86 command for Linux-86 + * It is distributed under the GNU Library General Public License. + * + * - This may actually be BSD or Minix code, can someone clarify please. -RDB + */ + +#ifndef __AOUT_H +#define __AOUT_H + +struct exec { /* a.out header */ + unsigned char a_magic[2]; /* magic number */ + unsigned char a_flags; /* flags, see below */ + unsigned char a_cpu; /* cpu id */ + unsigned char a_hdrlen; /* length of header */ + unsigned char a_unused; /* reserved for future use */ + unsigned short a_version; /* version stamp (not used at present) */ + long a_text; /* size of text segement in bytes */ + long a_data; /* size of data segment in bytes */ + long a_bss; /* size of bss segment in bytes */ + long a_entry; /* entry point */ + long a_total; /* total memory allocated */ + long a_syms; /* size of symbol table */ + + /* SHORT FORM ENDS HERE */ + long a_trsize; /* text relocation size */ + long a_drsize; /* data relocation size */ + long a_tbase; /* text relocation base */ + long a_dbase; /* data relocation base */ +}; + +#define A_MAGIC0 (unsigned char) 0x01 +#define A_MAGIC1 (unsigned char) 0x03 +#define BADMAG(X) ((X).a_magic[0] != A_MAGIC0 ||(X).a_magic[1] != A_MAGIC1) + +/* CPU Id of TARGET machine (byte order coded in low order two bits) */ +#define A_NONE 0x00 /* unknown */ +#define A_I8086 0x04 /* intel i8086/8088 */ +#define A_M68K 0x0B /* motorola m68000 */ +#define A_NS16K 0x0C /* national semiconductor 16032 */ +#define A_I80386 0x10 /* intel i80386 */ +#define A_SPARC 0x17 /* Sun SPARC */ + +#define A_BLR(cputype) ((cputype&0x01)!=0) /* TRUE if bytes left-to-right */ +#define A_WLR(cputype) ((cputype&0x02)!=0) /* TRUE if words left-to-right */ + +/* Flags. */ +#define A_UZP 0x01 /* unmapped zero page (pages) */ +#define A_PAL 0x02 /* page aligned executable */ +#define A_NSYM 0x04 /* new style symbol table */ +#define A_EXEC 0x10 /* executable */ +#define A_SEP 0x20 /* separate I/D */ +#define A_PURE 0x40 /* pure text */ +#define A_TOVLY 0x80 /* text overlay */ + +/* Offsets of various things. */ +#define A_MINHDR 32 +#define A_TEXTPOS(X) ((long)(X).a_hdrlen) +#define A_DATAPOS(X) (A_TEXTPOS(X) + (X).a_text) +#define A_HASRELS(X) ((X).a_hdrlen > (unsigned char) A_MINHDR) +#define A_HASEXT(X) ((X).a_hdrlen > (unsigned char) (A_MINHDR + 8)) +#define A_HASLNS(X) ((X).a_hdrlen > (unsigned char) (A_MINHDR + 16)) +#define A_HASTOFF(X) ((X).a_hdrlen > (unsigned char) (A_MINHDR + 24)) +#define A_TRELPOS(X) (A_DATAPOS(X) + (X).a_data) +#define A_DRELPOS(X) (A_TRELPOS(X) + (X).a_trsize) +#define A_SYMPOS(X) (A_TRELPOS(X) + (A_HASRELS(X) ? \ + ((X).a_trsize + (X).a_drsize) : 0)) + +struct reloc { + long r_vaddr; /* virtual address of reference */ + unsigned short r_symndx; /* internal segnum or extern symbol num */ + unsigned short r_type; /* relocation type */ +}; + +/* r_tyep values: */ +#define R_ABBS 0 +#define R_RELLBYTE 2 +#define R_PCRBYTE 3 +#define R_RELWORD 4 +#define R_PCRWORD 5 +#define R_RELLONG 6 +#define R_PCRLONG 7 +#define R_REL3BYTE 8 +#define R_KBRANCHE 9 + +/* r_symndx for internal segments */ +#define S_ABS ((unsigned short)-1) +#define S_TEXT ((unsigned short)-2) +#define S_DATA ((unsigned short)-3) +#define S_BSS ((unsigned short)-4) + +struct nlist { /* symbol table entry */ + char n_name[24]; /* symbol name */ + long n_value; /* value */ + unsigned char n_sclass; /* storage class */ + unsigned char n_numaux; /* number of auxiliary entries (not used) */ + unsigned short n_type; /* language base and derived type (not used) */ +}; + +/* Low bits of storage class (section). */ +#define N_SECT 07 /* section mask */ +#define N_UNDF 00 /* undefined */ +#define N_ABS 01 /* absolute */ +#define N_TEXT 02 /* text */ +#define N_DATA 03 /* data */ +#define N_BSS 04 /* bss */ +#define N_COMM 05 /* (common) */ + +/* High bits of storage class. */ +#define N_CLASS 0370 /* storage class mask */ +#define C_NULL +#define C_EXT 0020 /* external symbol */ +#define C_STAT 0030 /* static */ + +#endif /* _AOUT_H */ @@ -3,7 +3,7 @@ /* Copyright (C) 1994 Bruce Evans */ #define FALSE 0 -#define NULL 0 +#define NUL_PTR ((void*)0) #define TRUE 1 #define EXTERN extern @@ -13,7 +13,7 @@ PUBLIC void dumpmods() { struct modstruct *modptr; - for (modptr = modfirst; modptr != NULL; modptr = modptr->modnext) + for (modptr = modfirst; modptr != NUL_PTR; modptr = modptr->modnext) { putstr(modptr->loadflag ? "L " : " "); putbstr(20, modptr->modname); @@ -31,11 +31,11 @@ PUBLIC void dumpsyms() struct symstruct *symptr; char uflag; - for (modptr = modfirst; modptr != NULL; modptr = modptr->modnext) + for (modptr = modfirst; modptr != NUL_PTR; modptr = modptr->modnext) if (modptr->loadflag) { for (symparray = modptr->symparray; - (symptr = *symparray) != NULL; ++symparray) + (symptr = *symparray) != NUL_PTR; ++symparray) if (symptr->modptr == modptr) { uflag = FALSE; diff --git a/ld/include/fcntl.h b/ld/include/fcntl.h new file mode 100644 index 0000000..8c1ec8b --- /dev/null +++ b/ld/include/fcntl.h @@ -0,0 +1,2 @@ +#define O_RDONLY 0 +#define O_WRONLY 1 @@ -6,20 +6,19 @@ #include "obj.h" /* needed for LONG_OFFSETS and offset_t */ #include "type.h" #include "globvar.h" +#include <fcntl.h> #ifdef STDC_HEADERS_MISSING void exit P((int status)); void *malloc P((unsigned size)); #else -#undef NULL #include <stdlib.h> #endif #ifdef POSIX_HEADERS_MISSING -#define O_RDONLY 0 -#define O_WRONLY 1 #define SEEK_SET 0 #define STDOUT_FILENO 0 +#include <sys/types.h> #include <sys/stat.h> #define mode_t unsigned short #define off_t long @@ -33,7 +32,6 @@ int read P((int fd, void *buf, unsigned nbytes)); mode_t umask P((int oldmask)); int write P((int fd, const void *buf, unsigned nbytes)); #else -#undef NULL #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -46,6 +44,9 @@ int write P((int fd, const void *buf, unsigned nbytes)); #define INBUFSIZE 1024 #define OUTBUFSIZE 2048 #define TRELBUFSIZE 1024 +#ifndef O_BINARY +#define O_BINARY 0 +#endif #ifdef BSD_A_OUT PRIVATE char *drelbuf; /* extra output buffer for data relocations */ @@ -197,7 +198,7 @@ char *filename; { closein(); inputname = filename; /* this relies on filename being static */ - if ((infd = open(filename, O_RDONLY)) < 0) + if ((infd = open(filename, O_BINARY|O_RDONLY)) < 0) inputerror("cannot open"); inbufptr = inbufend = inbuf; } @@ -209,7 +210,7 @@ char *filename; struct stat statbuf; outputname = filename; - if ((outfd = creat(filename, CREAT_PERMS)) == ERR) + if ((outfd = open(filename, O_BINARY|O_RDWR|O_CREAT|O_TRUNC, CREAT_PERMS)) == ERR) outputerror("cannot open"); if (fstat(outfd, &statbuf) != 0) outputerror("cannot stat"); @@ -220,7 +221,7 @@ char *filename; #endif outbufptr = outbuf; #ifdef BSD_A_OUT - if ((trelfd = open(filename, O_WRONLY)) == ERR) + if ((trelfd = open(filename, O_BINARY|O_WRONLY|O_CREAT|O_TRUNC, CREAT_PERMS)) == ERR) outputerror("cannot reopen"); trelbufptr = trelbuf; #endif @@ -528,7 +529,7 @@ char *defarchentry; putstr(message); putstr(" in file "); putstr(inputname); - if (archentry != NULL) + if (archentry != NUL_PTR) { putbyte('('); putstr(archentry); @@ -536,7 +537,7 @@ char *defarchentry; } putstr("; using definition in "); putstr(deffilename); - if (defarchentry != NULL) + if (defarchentry != NUL_PTR) { putbyte('('); putstr(defarchentry); @@ -560,7 +561,7 @@ char *name; } PUBLIC void size_error(seg, count, size) -char seg; +int seg; offset_t count; offset_t size; { @@ -12,7 +12,6 @@ extern int errno; char *strcat P((char *dest, const char *src)); unsigned long strtoul P((const char *s, char **endptr, int base)); #else -#undef NULL #include <errno.h> #include <stdlib.h> #include <string.h> @@ -22,23 +21,23 @@ unsigned long strtoul P((const char *s, char **endptr, int base)); #define R_OK 0 int access P((const char *path, int amode)); #else -#undef NULL #include <unistd.h> #endif #define MAX_LIBS (NR_STDLIBS + 5) +#ifdef MC6809 #define NR_STDLIBS 1 +#else +#define NR_STDLIBS 0 +#endif PUBLIC long text_base_address; /* XXX */ +PUBLIC int doscomfile = 0; PRIVATE bool_t flag[128]; PRIVATE char *libs[MAX_LIBS] = { #ifdef MC6809 "/usr/local/lib/m09/", -#else - /* One of the following values will be inserted at run time. */ -# define std386lib "/usr/local/lib/i386/" -# define std86lib "/usr/local/lib/i86/" #endif 0 }; @@ -67,10 +66,6 @@ char *fn; char *path; int i; -#ifndef MC6809 - libs[0] = flag['3'] ? std386lib : std86lib; -#endif - for (i = lastlib - 1; i >= 0; --i) { path = ourmalloc(strlen(libs[i]) + strlen(fn) + 1); @@ -80,7 +75,7 @@ char *fn; return path; ourfree(path); } - return NULL; + return NUL_PTR; } PUBLIC int main(argc, argv) @@ -104,7 +99,7 @@ char **argv; #ifndef MC6809 flag['z'] = flag['3'] = sizeof(char *) >= 4; #endif - outfilename = NULL; + outfilename = NUL_PTR; for (argn = 1; argn < argc; ++argn) { arg = argv[argn]; @@ -133,9 +128,17 @@ char **argv; if (arg[1] == '0') /* flag 0 is negative logic flag 3 */ flag['3'] = !flag['0']; break; + case 'd': /* Make DOS com file */ + flag['3'] = FALSE; + flag['z'] = FALSE; + flag['0'] = TRUE; + flag['s'] = TRUE; + flag['d'] = TRUE; + text_base_address = 0x100; + break; case 'C': /* startfile name */ tfn = buildname(crtprefix, arg + 2, crtsuffix); - if ((infilename = expandlib(tfn)) == NULL) + if ((infilename = expandlib(tfn)) == NUL_PTR) fatalerror(tfn); /* XXX - need to describe failure */ readsyms(infilename, flag['t']); break; @@ -146,7 +149,7 @@ char **argv; fatalerror("too many library paths"); break; case 'O': /* library file name */ - if ((infilename = expandlib(arg + 2)) == NULL) + if ((infilename = expandlib(arg + 2)) == NUL_PTR) fatalerror(arg); /* XXX */ readsyms(infilename, flag['t']); break; @@ -154,18 +157,18 @@ char **argv; if (arg[2] != 0 || ++argn >= argc) usage(); errno = 0; - text_base_address = strtoul(argv[argn], (char **) NULL, 16); + text_base_address = strtoul(argv[argn], (char **) NUL_PTR, 16); if (errno != 0) use_error("invalid text address"); break; case 'l': /* library name */ tfn = buildname(libprefix, arg + 2, libsuffix); - if ((infilename = expandlib(tfn)) == NULL) + if ((infilename = expandlib(tfn)) == NUL_PTR) fatalerror(tfn); /* XXX */ readsyms(infilename, flag['t']); break; case 'o': /* output file name */ - if (arg[2] != 0 || ++argn >= argc || outfilename != NULL) + if (arg[2] != 0 || ++argn >= argc || outfilename != NUL_PTR) usage(); outfilename = argv[argn]; break; @@ -173,8 +176,9 @@ char **argv; usage(); } } + doscomfile = flag['d']; linksyms(flag['r']); - if (outfilename == NULL) + if (outfilename == NUL_PTR) outfilename = "a.out"; writebin(outfilename, flag['i'], flag['3'], flag['s'], flag['z'] & flag['3']); diff --git a/ld/readobj.c b/ld/readobj.c index 791436f..bb6a6b5 100644 --- a/ld/readobj.c +++ b/ld/readobj.c @@ -14,7 +14,6 @@ int strncmp P((const char *s1, const char *s2, unsigned n)); char *strncpy P((char *dest, const char *src, unsigned n)); unsigned long strtoul P((const char *s, char **endptr, int base)); #else -#undef NULL #include <stdlib.h> #include <string.h> #endif @@ -51,9 +50,9 @@ FORWARD unsigned segbits P((unsigned seg, char *sizedesc)); PUBLIC void objinit() { - modfirst = modlast = NULL; - entryfirst = entrylast = NULL; - redfirst = redlast = NULL; + modfirst = modlast = NUL_PTR; + entryfirst = entrylast = NUL_PTR; + redfirst = redlast = NUL_PTR; } /* read all symbol definitions in an object file */ @@ -76,7 +75,7 @@ bool_pt trace; case OMAGIC: seekin((unsigned long) 0); for (modcount = readfileheader(); modcount-- != 0;) - readmodule(filename, (char *) NULL); + readmodule(filename, (char *) NUL_PTR); break; default: seekin((unsigned long) 0); @@ -118,7 +117,7 @@ char **parchentry; do *endptr = 0; while (endptr > nameptr && *--endptr == ' '); - return strtoul(arheader.ar_size, (char **) NULL, 0); + return strtoul(arheader.ar_size, (char **) NUL_PTR, 0); } /* read and check file header of the object file just opened */ @@ -185,7 +184,7 @@ char *archentry; { symname = readstring(); if ((flags = symdptr->dflags) & (E_MASK | I_MASK) && - (symptr = findsym(symname)) != NULL) + (symptr = findsym(symname)) != NUL_PTR) { /* weaken segment-checking by letting the maximum segment @@ -220,7 +219,7 @@ char *archentry; if (flags & N_MASK) entrysym(symptr); } - *symparray = NULL; + *symparray = NUL_PTR; } /* put symbol on entry symbol list if it is not already */ @@ -230,13 +229,13 @@ struct symstruct *symptr; { register struct entrylist *elptr; - for (elptr = entryfirst; elptr != NULL; elptr = elptr->elnext) + for (elptr = entryfirst; elptr != NUL_PTR; elptr = elptr->elnext) if (symptr == elptr->elsymptr) return; elptr = (struct entrylist *) ourmalloc(sizeof(struct entrylist)); - elptr->elnext = NULL; + elptr->elnext = NUL_PTR; elptr->elsymptr = symptr; - if (entryfirst == NULL) + if (entryfirst == NUL_PTR) entryfirst = elptr; else entrylast->elnext = elptr; @@ -263,7 +262,7 @@ PRIVATE void reedmodheader() readin((char *) &modheader, sizeof modheader); modptr = (struct modstruct *) ourmalloc(sizeof(struct modstruct)); - modptr->modnext = NULL; + modptr->modnext = NUL_PTR; modptr->textoffset = c4u4(modheader.htextoffset); modptr->class = modheader.hclass; readin(modptr->segmaxsize, sizeof modptr->segmaxsize); @@ -281,7 +280,7 @@ PRIVATE void reedmodheader() cptr += count; } } - if (modfirst == NULL) + if (modfirst == NUL_PTR) modfirst = modptr; else modlast->modnext = modptr; @@ -298,11 +297,11 @@ offset_t value; if (symptr->modptr->class != (class = modlast->class)) for (rlptr = redfirst;; rlptr = rlptr->rlnext) { - if (rlptr == NULL) + if (rlptr == NUL_PTR) { rlptr = (struct redlist *) ourmalloc(sizeof(struct redlist)); - rlptr->rlnext = NULL; + rlptr->rlnext = NUL_PTR; rlptr->rlsymptr = symptr; if (symptr->modptr->class < class) /* prefer lower class - put other on redlist */ @@ -317,7 +316,7 @@ offset_t value; rlptr->rlvalue = symptr->value; symptr->value = value; } - if (redfirst == NULL) + if (redfirst == NUL_PTR) redfirst = rlptr; else redlast->rlnext = rlptr; @@ -10,9 +10,10 @@ #ifdef STDC_HEADERS_MISSING void *malloc P((unsigned size)); +char * strcpy P((char* dest, char* src)); #else -#undef NULL #include <stdlib.h> +#include <string.h> #endif #define GOLDEN 157 /* GOLDEN/HASHTABSIZE approx golden ratio */ @@ -32,13 +33,13 @@ PUBLIC void syminit() for (i = sizeof(int) <= 2 ? 0xE000 : (unsigned) 0x38000; i != 0; i -= 512) - if ((tableptr = malloc(i)) != NULL) + if ((tableptr = malloc(i)) != NUL_PTR) break; - if (tableptr == NULL) + if (tableptr == NUL_PTR) outofmemory(); tableend = tableptr + i; for (i = 0; i < HASHTABSIZE; i++) - hashtab[i] = NULL; + hashtab[i] = NUL_PTR; } /* add named symbol to end of table - initialise only name and next fields */ @@ -48,12 +49,12 @@ PUBLIC struct symstruct *addsym(name) char *name; { struct symstruct **hashptr; - struct symstruct *oldsymptr; + struct symstruct *oldsymptr = 0; struct symstruct *symptr; hashptr = gethashptr(name); symptr = *hashptr; - while (symptr != NULL) + while (symptr != NUL_PTR) { oldsymptr = symptr; symptr = symptr->next; @@ -62,11 +63,11 @@ char *name; symptr = (struct symstruct *) tableptr; if ((tableptr = symptr->name + (strlen(name) + 1)) > tableend) outofmemory(); - symptr->modptr = NULL; - symptr->next = NULL; + symptr->modptr = NUL_PTR; + symptr->next = NUL_PTR; if (name != symptr->name) strcpy(symptr->name, name); /* should't happen */ - if (*hashptr == NULL) + if (*hashptr == NUL_PTR) *hashptr = symptr; else oldsymptr->next = symptr; @@ -81,7 +82,7 @@ char *name; struct symstruct *symptr; symptr = *gethashptr(name); - while (symptr != NULL && (!(symptr->flags & (E_MASK | I_MASK)) || + while (symptr != NUL_PTR && (!(symptr->flags & (E_MASK | I_MASK)) || strcmp(symptr->name, name) != 0)) symptr = symptr->next; return symptr; diff --git a/ld/writebin.c b/ld/writebin.c index a95280c..3e7602d 100644 --- a/ld/writebin.c +++ b/ld/writebin.c @@ -27,7 +27,11 @@ static long bdataoffset; # define n_was_strx n_un.n_strx # define n_was_type n_desc # else /* not BSD_A_OUT */ -# include "a.out.h" /* maybe local copy of <a.out.h> for X-link */ +# ifdef MSDOS +# include "a_out.h" +# else +# include "a.out.h" /* maybe local copy of <a.out.h> for X-link */ +# endif # define n_was_name n_name # define n_was_numaux n_numaux # define n_was_other n_other @@ -46,7 +50,6 @@ static long bdataoffset; #ifdef STDC_HEADERS_MISSING void *memset P((void *s, int c, unsigned n)); #else -#undef NULL #include <string.h> #endif @@ -58,10 +61,10 @@ void *memset P((void *s, int c, unsigned n)); # ifdef STANDARD_GNU_A_OUT # define FILEHEADERLENGTH 32 # else -# define FILEHEADERLENGTH 48 +# define FILEHEADERLENGTH (doscomfile?0:48) # endif # else -# define FILEHEADERLENGTH A_MINHDR +# define FILEHEADERLENGTH (doscomfile?0:A_MINHDR) /* part of header not counted in offsets */ # endif #endif @@ -139,6 +142,8 @@ FORWARD void writeheader P((void)); #endif FORWARD void writenulls P((offset_t count)); +extern int doscomfile; + /* link all symbols connected to entry symbols */ PUBLIC void linksyms(argreloc_output) @@ -153,31 +158,31 @@ bool_pt argreloc_output; reloc_output = argreloc_output; if (argreloc_output) { - if (modfirst->modnext != NULL) + if (modfirst->modnext != NUL_PTR) fatalerror("relocatable output only works for one input file"); - for (modptr = modfirst; modptr != NULL; modptr = modptr->modnext) + for (modptr = modfirst; modptr != NUL_PTR; modptr = modptr->modnext) modptr->loadflag = TRUE; return; } #endif - if ((symptr = findsym("_main")) != NULL) + if ((symptr = findsym("_main")) != NUL_PTR) entrysym(symptr); do { - if ((elptr = entryfirst) == NULL) + if ((elptr = entryfirst) == NUL_PTR) fatalerror("no start symbol"); - for (modptr = modfirst; modptr != NULL; modptr = modptr->modnext) + for (modptr = modfirst; modptr != NUL_PTR; modptr = modptr->modnext) modptr->loadflag = FALSE; - for (; elptr != NULL; elptr = elptr->elnext) + for (; elptr != NUL_PTR; elptr = elptr->elnext) linkrefs(elptr->elsymptr->modptr); - if ((symptr = findsym("start")) != NULL) + if ((symptr = findsym("start")) != NUL_PTR) linkrefs(symptr->modptr); needlink = FALSE; { - struct redlist *prlptr; + struct redlist *prlptr = 0; struct redlist *rlptr; - for (rlptr = redfirst; rlptr != NULL; + for (rlptr = redfirst; rlptr != NUL_PTR; rlptr = (prlptr = rlptr)->rlnext) if (rlptr->rlmodptr->loadflag && rlptr->rlmodptr->class > rlptr->rlsymptr->modptr->class) @@ -233,9 +238,9 @@ bool_pt arguzp; } #ifdef EDOS commandname = stralloc(outfilename); - if ((cptr = strchr(commandname, ':')) != NULL) + if ((cptr = strchr(commandname, ':')) != NUL_PTR) commandname = cptr + 1; - if ((cptr = strrchr(commandname, '.')) != NULL) + if ((cptr = strrchr(commandname, '.')) != NUL_PTR) *cptr = 0; #endif @@ -261,18 +266,19 @@ bool_pt arguzp; symres("__end"); curseg = 0; /* text seg, s.b. variable */ symres("__etext"); + symres("__segoff"); /* calculate segment and common sizes (sum over loaded modules) */ /* use zero init of segsz[] */ /* also relocate symbols relative to starts of their segments */ - for (modptr = modfirst; modptr != NULL; modptr = modptr->modnext) + for (modptr = modfirst; modptr != NUL_PTR; modptr = modptr->modnext) if (modptr->loadflag) { register struct symstruct **symparray; register struct symstruct *symptr; for (symparray = modptr->symparray; - (symptr = *symparray) != NULL; ++symparray) + (symptr = *symparray) != NUL_PTR; ++symparray) if (symptr->modptr == modptr && !(symptr->flags & A_MASK)) { if (!(symptr->flags & (I_MASK | SA_MASK))) @@ -363,14 +369,14 @@ bool_pt arguzp; } /* relocate symbols by offsets of segments in memory */ - for (modptr = modfirst; modptr != NULL; modptr = modptr->modnext) + for (modptr = modfirst; modptr != NUL_PTR; modptr = modptr->modnext) if (modptr->loadflag) { register struct symstruct **symparray; register struct symstruct *symptr; for (symparray = modptr->symparray; - (symptr = *symparray) != NULL; ++symparray) + (symptr = *symparray) != NUL_PTR; ++symparray) if (symptr->modptr == modptr && !(symptr->flags & A_MASK)) { if (symptr->flags & (C_MASK | SA_MASK)) @@ -414,6 +420,7 @@ bool_pt arguzp; setsym("__etext", etextoffset); setsym("__edata", edataoffset); setsym("__end", endoffset = combase[NSEG - 1] + comsz[NSEG - 1]); + setsym("__segoff", (offset_t)(segadj[1]-segadj[0])/0x10); openout(outfilename); #ifdef BSD_A_OUT @@ -427,7 +434,7 @@ bool_pt arguzp; #else writeheader(); #endif - for (modptr = modfirst; modptr != NULL; modptr = modptr->modnext) + for (modptr = modfirst; modptr != NUL_PTR; modptr = modptr->modnext) if (modptr->loadflag) { linkmod(modptr); @@ -453,21 +460,21 @@ bool_pt arguzp; #ifdef BSD_A_OUT stringoff = 4; #endif - for (modptr = modfirst; modptr != NULL; modptr = modptr->modnext) + for (modptr = modfirst; modptr != NUL_PTR; modptr = modptr->modnext) if (modptr->loadflag) { register struct symstruct **symparray; register struct symstruct *symptr; for (symparray = modptr->symparray; - (symptr = *symparray) != NULL; ++symparray) + (symptr = *symparray) != NUL_PTR; ++symparray) if (symptr->modptr == modptr) { #ifdef BSD_A_OUT offtocn((char *) &extsym.n_was_strx, (offset_t) stringoff, 4); #else - strncpy((char *) &extsym.n_was_name, symptr->name, + strncpy((char *) extsym.n_was_name, symptr->name, sizeof extsym.n_was_name); #endif u4cn((char *) &extsym.n_value, (u4_t) symptr->value, @@ -506,14 +513,14 @@ bool_pt arguzp; #ifdef BSD_A_OUT offtocn((char *) &extsym.n_was_strx, (offset_t) stringoff, 4); writeout((char *) &extsym.n_was_strx, 4); - for (modptr = modfirst; modptr != NULL; modptr = modptr->modnext) + for (modptr = modfirst; modptr != NUL_PTR; modptr = modptr->modnext) if (modptr->loadflag) { register struct symstruct **symparray; register struct symstruct *symptr; for (symparray = modptr->symparray; - (symptr = *symparray) != NULL; ++symparray) + (symptr = *symparray) != NUL_PTR; ++symparray) if (symptr->modptr == modptr) writeout(symptr->name, strlen(symptr->name) + 1); } @@ -553,12 +560,12 @@ char *commandname; count = 2 + 2 + 1; /* len len nul */ startptr = findsym("start"); - for (elptr = entryfirst; elptr != NULL; elptr = elptr->elnext) + for (elptr = entryfirst; elptr != NUL_PTR; elptr = elptr->elnext) { name = idconvert(elptr, commandname); count += strlen(name) + 1 + 2 + 1; /* nul off flg */ ourfree(name); - if (startptr != NULL) + if (startptr != NUL_PTR) count += 6; /* LBSR $xxxx and LBRA $xxxx */ } return count; @@ -772,7 +779,7 @@ struct modstruct *modptr; modptr->loadflag = TRUE; for (symparray = modptr->symparray; - (symptr = *symparray) != NULL; ++symparray) + (symptr = *symparray) != NUL_PTR; ++symparray) if (symptr->modptr->loadflag == FALSE) linkrefs(symptr->modptr); } @@ -815,7 +822,7 @@ offset_t value; #ifdef BSD_A_OUT if (!reloc_output) #endif - if ((symptr = findsym(name)) != NULL) + if ((symptr = findsym(name)) != NUL_PTR) symptr->value = value; } @@ -824,7 +831,7 @@ register char *name; { register struct symstruct *symptr; - if ((symptr = findsym(name)) != NULL) + if ((symptr = findsym(name)) != NUL_PTR) { if ((symptr->flags & SEGM_MASK) == SEGM_MASK) symptr->flags &= ~SEGM_MASK | curseg; @@ -870,7 +877,7 @@ char *commandname; struct symstruct *startptr; headlength = binheaderlength(commandname); - for (elptr = entryfirst; elptr != NULL; elptr = elptr->elnext) + for (elptr = entryfirst; elptr != NUL_PTR; elptr = elptr->elnext) headlength -= 6; offset = headlength; startptr = findsym("start"); @@ -878,21 +885,21 @@ char *commandname; writeout(buf, 2); writechar(0xFF); /* dummy data length 0xFFFF takes everything */ writechar(0xFF); - for (elptr = entryfirst; elptr != NULL; elptr = elptr->elnext) + for (elptr = entryfirst; elptr != NUL_PTR; elptr = elptr->elnext) { name = idconvert(elptr, commandname); writeout(name, (unsigned) strlen(name) + 1); ourfree(name); - offtocn(buf, startptr == NULL ? elptr->elsymptr->value : offset, 2); + offtocn(buf, startptr == NUL_PTR ? elptr->elsymptr->value : offset, 2); writeout(buf, 2); writechar(0x82); /* 8 = set flags from here, 2 = cmd line */ offset += 6; /* LBSR $xxxx and LBRA $xxxx */ } writechar(0); - if (startptr != NULL) + if (startptr != NUL_PTR) { offset = headlength + 3; /* over 1st LBSR */ - for (elptr = entryfirst; elptr != NULL; elptr = elptr->elnext) + for (elptr = entryfirst; elptr != NUL_PTR; elptr = elptr->elnext) { writechar(0x17); /* LBSR */ offtocn(buf, startptr->value - offset, 2); @@ -975,7 +982,8 @@ PRIVATE void writeheader() sizeof header.a_total); #endif } - writeout((char *) &header, FILEHEADERLENGTH); + if( FILEHEADERLENGTH ) + writeout((char *) &header, FILEHEADERLENGTH); } #endif /* MINIX */ |