summaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorRobert de Bath <rdebath@poboxes.com>2003-11-02 09:31:19 +0100
committerLubomir Rintel <lkundrak@v3.sk>2013-10-23 23:48:49 +0200
commitb5dac1e3bdd01a2ce105df747a9073ff0d6a94e2 (patch)
tree2ce4628567071bbb680b6c81f40f5fd3192eda02 /ld
parent22950ba3df3a0b739786243679d69cd4094e8b20 (diff)
downloaddev86-b5dac1e3bdd01a2ce105df747a9073ff0d6a94e2.tar.gz
Import Dev86src-0.16.14.tar.gzv0.16.14
Diffstat (limited to 'ld')
-rw-r--r--ld/Makefile12
-rw-r--r--ld/bindef.h29
-rw-r--r--ld/dumps.c8
-rw-r--r--ld/io.c4
-rw-r--r--ld/ld.c46
-rw-r--r--ld/ld86r.c7
-rw-r--r--ld/mkar.c74
-rw-r--r--ld/objdump86.c202
-rw-r--r--ld/table.c31
-rw-r--r--ld/type.h3
-rw-r--r--ld/writebin.c6
-rw-r--r--ld/writeemu.c (renamed from ld/writerel.c)6
12 files changed, 287 insertions, 141 deletions
diff --git a/ld/Makefile b/ld/Makefile
index 69170bd..b4aed62 100644
--- a/ld/Makefile
+++ b/ld/Makefile
@@ -3,20 +3,22 @@ LIBDIR =/usr/bin
CFLAGS =-O
LDFLAGS =
-# May need some of these if the auto-sense fails.
+# Will need some of these if you want native executables on non-Linux/i386
+# -DDETECTAOUT # Turn on detection.
# -DV7_A_OUT # a.out.h is like V7
# -DBSD_A_OUT # a.out.h is like BSD
# -DSTANDARD_GNU_A_OUT # a.out.h is like GNU normal.
-# -DNO_AOUT # a.out.h is like nothing known!
#
-DEFS =-DREL_OUTPUT -DBUGCOMPAT
+# -DREL_OUTPUT -DBUGCOMPAT # -r Produces weird *.o files.
+#
+DEFS =-DREL_OUTPUT
# An alternative file for a non-standard a.out.h (eg i386 linux on an Alpha)
#
# NATIVE=-DA_OUT_INCL='"a_out_local.h"'
-OBJS= dumps.o io.o ld.o readobj.o table.o typeconv.o linksyms.o \
- writex86.o writebin.o writerel.o
+OBJS= dumps.o io.o ld.o readobj.o table.o typeconv.o linksyms.o mkar.o \
+ writex86.o writebin.o writeemu.o
all: ld86 objchop catimage objdump86
diff --git a/ld/bindef.h b/ld/bindef.h
index 1c8dc49..c359509 100644
--- a/ld/bindef.h
+++ b/ld/bindef.h
@@ -1,22 +1,19 @@
-#if defined(__i386__) || defined(__8086__) || defined(__i386)
-#ifndef MSDOS
-#ifndef NO_AOUT
-/* Ok, I'm just gonna make it simple ... override this if you like. */
-#ifndef A_OUT_INCL
-#define A_OUT_INCL "a.out.h"
+/* Only do native on Linux/i386 by default -- it's safer. */
+#ifndef DETECTAOUT
+#if defined(__i386__) && defined(__linux__)
+#define DETECTAOUT
+#else
+# ifdef A_OUT_INCL
+# define DETECTAOUT
+# endif
+#endif
#endif
-/* This is how it used to be ... */
+#ifdef DETECTAOUT
+/* Ok, I'm just gonna make it simple ... override this if you like. */
#ifndef A_OUT_INCL
-# ifdef BSD_A_OUT
-# ifdef STANDARD_GNU_A_OUT
-# define A_OUT_INCL <a.out.h>
-# else
-# define A_OUT_INCL "bsd-a.out.h"
-# endif
-# define A_OUT_INCL "a.out.h" /* maybe local copy of <a.out.h> for X-link */
-# endif /* BSD_A_OUT */
+#define A_OUT_INCL <a.out.h>
#endif
#include A_OUT_INCL
@@ -76,5 +73,3 @@
#endif
#endif /* NO_AOUT */
-#endif /* MSDOS */
-#endif /* CPU type */
diff --git a/ld/dumps.c b/ld/dumps.c
index a969123..4732017 100644
--- a/ld/dumps.c
+++ b/ld/dumps.c
@@ -83,4 +83,12 @@ PUBLIC void dumpsyms()
putbyte('\n');
}
}
+
+ putstr("Total memory used: ");
+#ifdef LONG_OFFSETS
+ put08lx(memory_used());
+#else
+ put08x(memory_used());
+#endif
+ putbyte('\n');
}
diff --git a/ld/io.c b/ld/io.c
index 743fa94..bc8e73c 100644
--- a/ld/io.c
+++ b/ld/io.c
@@ -615,11 +615,11 @@ PUBLIC void usage()
#ifdef REL_OUTPUT
errexit("\
[-03NMdimrstz[-]] [-llib_extension] [-o outfile] [-Ccrtfile]\n\
- [-Llibdir] [-Olibfile] [-T textaddr] [-D dataaddr] [-H heapsize] infile...");
+ [-Llibdir] [-Olibfile] [-Ttextaddr] [-Ddataaddr] [-Hheapsize] infile...");
#else
errexit("\
[-03NMdimstz[-]] [-llib_extension] [-o outfile] [-Ccrtfile]\n\
- [-Llibdir] [-Olibfile] [-T textaddr] [-D dataaddr] [-H heapsize] infile...");
+ [-Llibdir] [-Olibfile] [-Ttextaddr] [-Ddataaddr] [-Hheapsize] infile...");
#endif
}
diff --git a/ld/ld.c b/ld/ld.c
index 403bdfb..cc95fb7 100644
--- a/ld/ld.c
+++ b/ld/ld.c
@@ -105,16 +105,10 @@ char **argv;
case 'v':
version_msg();
case 'r': /* relocatable output */
-#ifndef REL_OUTPUT
-#ifndef MSDOS
- /* Ok, try for an alternate linker */
- if( strcmp(argv[0], "ld86r") != 0 )
- {
- argv[0] = "ld86r";
- execv("/usr/bin/ld86r", argv);
- }
-#endif
- usage();
+ case 't': /* trace modules linked */
+ if (icount > 0) usage();
+#ifdef REL_OUTPUT
+ case 'B': /* Broken -r for dosemu. */
#endif
case '0': /* use 16-bit libraries */
case '3': /* use 32-bit libraries */
@@ -122,7 +116,6 @@ char **argv;
case 'i': /* separate I & D output */
case 'm': /* print modules linked */
case 's': /* strip symbols */
- case 't': /* trace modules linked */
case 'z': /* unmapped zero page */
case 'N': /* Native format a.out */
case 'd': /* Make a headerless outfile */
@@ -209,22 +202,21 @@ char **argv;
usage();
}
}
- if(icount==0) fatalerror("no input files");
+ if(icount==0) usage();
+
+#ifdef BUGCOMPAT
+ if( icount==1 && ( flag['r'] && !flag['N'] ) ) {
+ flag['r'] = 0;
+ flag['B'] = 1;
+ }
+#endif
#ifdef REL_OUTPUT
#ifndef MSDOS
-#ifdef BUGCOMPAT
- if( icount>1 && ( flag['r'] && !flag['N'] ) )
-#else
if( flag['r'] && !flag['N'] )
-#endif
{
- /* Ok, try for an alternate linker */
- if( strcmp(argv[0], "ld86r") != 0 )
- {
- argv[0] = "ld86r";
- execv("/usr/bin/ld86r", argv);
- }
+ /* Do a relocatable link -- actually fake it with 'ar.c' */
+ ld86r(argc, argv);
}
#endif
#endif
@@ -249,7 +241,7 @@ char **argv;
if ( cpm86 ) flag['s'] = 1;
#endif
- linksyms(flag['r']);
+ linksyms(flag['r'] | flag['B']);
if (outfilename == NUL_PTR)
outfilename = "a.out";
#ifndef MSDOS
@@ -258,12 +250,10 @@ char **argv;
flag['z'] & flag['3']);
else
#endif
-#ifdef BUGCOMPAT
- if( flag['r'] )
- write_rel(outfilename, flag['i'], flag['3'], flag['s'],
- flag['z'] & flag['3']);
+ if( flag['B'] )
+ write_dosemu(outfilename, flag['i'], flag['3'], flag['s'],
+ flag['z'] & flag['3']);
else
-#endif
write_elks(outfilename, flag['i'], flag['3'], flag['s'],
flag['z'], flag['y']);
if (flag['m'])
diff --git a/ld/ld86r.c b/ld/ld86r.c
index c8c0631..dfc876d 100644
--- a/ld/ld86r.c
+++ b/ld/ld86r.c
@@ -1,8 +1,13 @@
#include <stdio.h>
+#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include <string.h>
+#ifdef __STDC__
+#include <stdlib.h>
+#include <unistd.h>
+#else
#include <malloc.h>
+#endif
#define ARMAG "!<arch>\n"
#define SARMAG 8
diff --git a/ld/mkar.c b/ld/mkar.c
new file mode 100644
index 0000000..96163b7
--- /dev/null
+++ b/ld/mkar.c
@@ -0,0 +1,74 @@
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#ifdef __STDC__
+#include <stdlib.h>
+#include <unistd.h>
+#else
+#include <malloc.h>
+#endif
+
+#include "ar.h"
+
+static struct ar_hdr arbuf;
+
+void
+ld86r(int argc, char ** argv)
+{
+char buf[128];
+ FILE * fd, * ifd;
+ struct stat st;
+ int ar, libarg=0, need_o = 0, got_o = 0;
+
+ for(ar=1; ar<argc; ar++) if( argv[ar][0] == '-' )
+ {
+ if( argv[ar][1] == 'r' ) need_o = 1;
+ if( argv[ar][1] == 'o' ) { got_o++; libarg = 0; }
+ }
+ else
+ {
+ if( libarg == 0 ) libarg = ar;
+ }
+
+ if( libarg == 0 || got_o > 1 || need_o > got_o )
+ fatalerror("-o option required for -r");
+
+ if( (fd =fopen(argv[libarg], "wb")) == 0 ) fatalerror("Cannot open archive");
+ if( fwrite(ARMAG, 1, SARMAG, fd) != SARMAG) fatalerror("Cannot write magic");
+
+ for(ar=1; ar<argc; ar++) if( ar != libarg && argv[ar][0] != '-' )
+ {
+ char * ptr;
+ if( stat(argv[ar], &st) < 0 ) fatalerror("Cannot stat object");
+ if((ptr=strchr(argv[ar], '/'))) ptr++; else ptr=argv[ar];
+ memset(&arbuf, ' ', sizeof(arbuf));
+ strcpy(buf, ptr); strcat(buf, "/ ");
+ strncpy(arbuf.ar_name, buf, sizeof(arbuf.ar_name));
+
+ sprintf(arbuf.ar_date, "%-12ld", (long)st.st_mtime);
+ sprintf(arbuf.ar_uid, "%-6d", (int)(st.st_uid%1000000L));
+ sprintf(arbuf.ar_gid, "%-6d", (int)(st.st_gid%1000000L));
+ sprintf(arbuf.ar_mode, "%-8lo", (long)st.st_mode);
+ sprintf(arbuf.ar_size, "%-10ld", (long)st.st_size);
+ memcpy(arbuf.ar_fmag, ARFMAG, sizeof(arbuf.ar_fmag));
+
+ if( fwrite(&arbuf, 1, sizeof(arbuf), fd) != sizeof(arbuf) )
+ fatalerror("Cannot write header");
+
+ ptr = malloc(st.st_size+2);
+ if( ptr == 0 ) fatalerror("Out of memory");
+ ptr[st.st_size] = ' ';
+ if( (ifd = fopen(argv[ar], "rb")) == 0 ) fatalerror("Cannot open input");
+ if( fread(ptr, 1, st.st_size, ifd) != st.st_size )
+ fatalerror("Cannot read input file");
+ fclose(ifd);
+
+ if( st.st_size&1 ) st.st_size++;
+ if( fwrite(ptr, 1, st.st_size, fd) != st.st_size )
+ fatalerror("Cannot write output file");
+ }
+ fclose(fd);
+ exit(0);
+}
diff --git a/ld/objdump86.c b/ld/objdump86.c
index b29c24d..2c93aa0 100644
--- a/ld/objdump86.c
+++ b/ld/objdump86.c
@@ -16,11 +16,12 @@
*/
#include <stdio.h>
-#include <malloc.h>
-#include <string.h>
#ifdef __STDC__
#include <stdlib.h>
+#else
+#include <malloc.h>
#endif
+#include <string.h>
#include "ar.h"
#include "obj.h"
@@ -36,6 +37,7 @@ char * ifname;
long get_long _((void));
long get_sized _((int sz));
unsigned int get_word _((void));
+int get_byte _((void));
int main _((int argc, char**argv));
void do_file _((char * fname));
long read_arheader _((char *archentry));
@@ -44,6 +46,8 @@ int error _((char * str));
int read_objheader _((void));
int read_sectheader _((void));
int read_syms _((void));
+void disp_sectheader _((void));
+int disp_syms _((void));
void read_databytes _((void));
void hex_output _((int ch));
void fetch_aout_hdr _((void));
@@ -51,14 +55,24 @@ void dump_aout _((void));
void size_aout _((void));
void nm_aout _((void));
+int obj_ver;
int sections;
long segsizes[16];
-long textoff, textlen;
-long str_off, str_len;
+long textoff;
+long textlen;
+long str_off;
+long str_len;
long filepos;
+int num_syms;
+long code_bytes;
char ** symnames;
-char * symtab;
+char * strtab;
+
+struct {
+ unsigned int nameoff, symtype;
+ long offset;
+} *symtab;
int display_mode = 0;
int multiple_files = 0;
@@ -177,7 +191,7 @@ do_module(fname, archive)
char * fname;
char * archive;
{
- int modno, i, ch;
+ int modno, i;
size_text = size_data = size_bss = 0;
byte_order = 0;
@@ -209,6 +223,14 @@ char * archive;
if( read_syms() < 0 ) break;
+ strtab = malloc((unsigned int)str_len+1);
+ if( strtab == 0 ) { error("Out of memory"); break; }
+ str_off = ftell(ifd);
+ fread(strtab, 1, (unsigned int)str_len, ifd);
+
+ disp_sectheader();
+ disp_syms();
+
if( display_mode == 0 )
printf("text\tdata\tbss\tdec\thex\tfilename\n");
if( display_mode != 2 )
@@ -227,20 +249,6 @@ char * archive;
read_databytes();
}
- if( !archive && !display_mode )
- {
- i=0;
- while( (ch=getc(ifd)) != EOF )
- {
- if( i == 0 )
- {
- printf("TRAILER\n");
- i=1;
- }
- hex_output(ch);
- }
- hex_output(EOF);
- }
break;
case 1: /* ELKS executable */
@@ -256,9 +264,9 @@ char * archive;
break;
}
- if( symtab ) free(symtab);
+ if( strtab ) free(strtab);
if( symnames ) free(symnames);
- symtab = 0;
+ strtab = 0;
symnames = 0;
}
@@ -306,32 +314,16 @@ read_objheader()
int
read_sectheader()
{
- long ssenc, cpos;
- int i, ver;
-
- textoff = get_long(); textlen = get_long();
- str_len=get_word(); str_off=textoff-str_len;
- ver = get_word();
+ long ssenc;
+ int i;
- symtab = malloc((unsigned int)str_len+1);
- if( symtab == 0 ) return error("Out of memory");
+ textoff = get_long(); /* Offset of bytecode in file */
+ textlen = get_long(); /* Length of text+data (no bss) in memory */
+ str_len = get_word(); /* Length of string table in file */
+ obj_ver = get_word(); /* 0.0 */
- cpos = ftell(ifd);
- fseek(ifd, filepos+str_off, 0);
- fread(symtab, 1, (unsigned int)str_len, ifd);
- fseek(ifd, cpos, 0);
-
- if( !display_mode )
- {
- printf("MODULE '%s'\n", symtab);
- printf("BYTEPOS %08lx\n", textoff);
- printf("BINLEN %08lx\n", textlen);
- printf("STRINGS %04lx +%04lx\n", str_off, str_len);
- printf("VERSION %d.%d\n", ver/256, ver%256);
- }
-
- (void)get_long(); /* Ignore fives */
- ssenc=get_long();
+ (void)get_long(); /* Ignore fives */
+ ssenc = get_long(); /* Sixteen segment size sizes */
for(i=0; i<16; i++)
{
@@ -339,48 +331,92 @@ read_sectheader()
ss = (i^3);
ss = ((ssenc>>(2*(15-ss)))&3);
segsizes[i] = get_sized(ss);
- if( segsizes[i] && !display_mode )
- printf("SEG%x %08lx\n", i, segsizes[i]);
}
- if( !display_mode )
- printf("\n");
+
+ num_syms = get_word(); /* Number of symbol codes */
return 0;
}
+void
+disp_sectheader()
+{
+ int i;
+ if( display_mode ) return;
+
+ printf("MODULE '%s'\n", strtab);
+ printf("BYTEPOS %08lx\n", textoff);
+ printf("BINLEN %08lx\n", textlen);
+ printf("STRINGS %04lx +%04lx\n", str_off, str_len);
+ printf("VERSION %d.%d\n", obj_ver/256, obj_ver%256);
+
+ for(i=0; i<16; i++)
+ if( segsizes[i] )
+ printf("SEG%x %08lx\n", i, segsizes[i]);
+
+ printf("\n");
+ printf("SYMS %u\n", num_syms);
+}
+
int
read_syms()
{
- int syms, i;
-
- syms=get_word();
+ int i;
- if( !display_mode ) printf("SYMS %u\n", syms);
- if( syms < 0 ) return error("Bad symbol table");
+ if( num_syms < 0 ) return error("Bad symbol table");
- symnames = malloc(syms*sizeof(char*)+1);
+ symnames = malloc(num_syms*sizeof(char*)+1);
if( symnames == 0 ) return error("Out of memory");
+ symtab = calloc(num_syms, sizeof(*symtab));
+ if( symtab == 0 ) return error("Out of memory");
+
if(display_mode == 2 && multiple_files)
printf("\n%s:\n", ifname);
- for(i=0; i<syms; i++)
+ for(i=0; i<num_syms; i++)
{
- long offset=0;
- unsigned int nameoff, symtype;
+ unsigned int symtype;
- nameoff = get_word();
- symtype = get_word();
- if (nameoff == -1 || symtype == -1) {
+ symtab[i].nameoff = get_word();
+ symtab[i].symtype = get_word();
+ symtype = (symtab[i].symtype & 0x3FFF);
+
+ if (symtab[i].nameoff == -1 || symtab[i].symtype == -1) {
printf("!!! EOF in symbol table\n");
break;
}
- offset = get_sized((symtype>>14)&3);
+ symtab[i].offset = get_sized((symtab[i].symtype>>14)&3);
+
+ if( symtype == 0x43 || symtype == 0x2003 )
+ size_bss += symtab[i].offset;
+ }
+
+ return 0;
+}
+
+int
+disp_syms()
+{
+ int i;
+
+ if(display_mode == 2 && multiple_files)
+ printf("\n%s:\n", ifname);
+
+ for(i=0; i<num_syms; i++)
+ {
+ long offset=0;
+ unsigned int nameoff, symtype;
+
+ nameoff = symtab[i].nameoff;
+ symtype = symtab[i].symtype;
+ offset = symtab[i].offset;
+
symtype &= 0x3FFF;
if (nameoff > str_len || nameoff < 0)
- symnames[i] = symtab + str_len;
+ symnames[i] = strtab + str_len;
else
- symnames[i] = symtab+nameoff;
+ symnames[i] = strtab+nameoff;
if( !display_mode )
{
@@ -425,9 +461,6 @@ read_syms()
}
printf(" %s\n", symnames[i]);
}
-
- if( symtype == 0x43 || symtype == 0x2003 )
- size_bss += offset;
}
if( !display_mode )
printf("\n");
@@ -439,16 +472,18 @@ void
read_databytes()
{
static char * relstr[] = {"ERR", "DB", "DW", "DD"};
- long l;
+ long l, cpos;
int ch, i;
int curseg = 0;
int relsize = 0;
+
+ cpos = ftell(ifd);
fseek(ifd, filepos+textoff, 0);
printf("\nBYTECODE\n");
for(;;)
{
- if( (ch=getc(ifd)) == EOF ) break;
+ if( (ch=get_byte()) == -1 ) break;
if( ch == 0 ) break;
@@ -467,7 +502,7 @@ static char * relstr[] = {"ERR", "DB", "DW", "DD"};
printf("SEG %x\n", curseg= (ch&0xF));
break;
default: printf("CODE %02x - unknown\n", ch);
- return ;
+ goto break_break ;
}
break;
case 0x40: /* Raw bytes */
@@ -476,12 +511,12 @@ static char * relstr[] = {"ERR", "DB", "DW", "DD"};
if( abscnt == 0 ) abscnt = 64;
for( i=0; i<abscnt; i++ )
{
- if( (ch=getc(ifd)) == EOF ) break;
+ if( (ch=get_byte()) == -1 ) break;
hex_output(ch);
}
hex_output(EOF);
- if( ch == EOF ) return;
+ if( ch == -1 ) goto break_break;
}
break;
case 0x80: /* Relocator - simple */
@@ -498,10 +533,10 @@ static char * relstr[] = {"ERR", "DB", "DW", "DD"};
if( ch & 0x18 )
{
printf("CODE %02x - unknown\n", ch);
- return;
+ goto break_break;
}
if( ch & 4 ) i = get_word();
- else i = getc(ifd);
+ else i = get_byte();
l = get_sized(ch&3);
printf("%s %s%s%s", relstr[relsize],
@@ -514,7 +549,9 @@ static char * relstr[] = {"ERR", "DB", "DW", "DD"};
break;
}
}
+break_break:;
printf("\n");
+ fseek(ifd, cpos, 0);
}
long
@@ -524,7 +561,7 @@ int sz;
switch(sz)
{
case 0: return 0;
- case 1: return getc(ifd);
+ case 1: return get_byte();
case 2: return get_word();
case 3: return get_long();
}
@@ -556,6 +593,7 @@ get_word()
{
int v = getc(ifd);
if( v == EOF ) return -1;
+ code_bytes++;
if( byte_order & 1 )
retv += (v<<(8-i));
else
@@ -564,6 +602,15 @@ get_word()
return retv;
}
+int
+get_byte()
+{
+ int v = getc(ifd);
+ if (v == EOF) return -1;
+ code_bytes++;
+ return v;
+}
+
void
hex_output(ch)
int ch;
@@ -719,7 +766,8 @@ nm_aout()
fseek(ifd, h_len+header[2]+header[3]+header[8]+header[9], 0);
- if( h_flgs & 4 ) { error("Executable has new format symtab\n"); return; }
+ if( h_flgs & 4 )
+ { error("Executable has new format symbol table.\n"); return; }
bytes_left = header[7];
diff --git a/ld/table.c b/ld/table.c
index 509c838..f960da0 100644
--- a/ld/table.c
+++ b/ld/table.c
@@ -16,7 +16,11 @@ PRIVATE struct symstruct *hashtab[HASHTABSIZE]; /* hash table */
PRIVATE char *tableptr; /* next free spot in catchall table */
PRIVATE char *tableend; /* ptr to spot after last in table */
+PUBLIC int maxused = 0; /* Stats */
+PRIVATE int mainavail, usedtop; /* Stats */
+
FORWARD struct symstruct **gethashptr P((char *name));
+FORWARD void check_used P((void));
/* initialise symbol table */
@@ -33,6 +37,9 @@ PUBLIC void syminit()
tableend = tableptr + i;
for (i = 0; i < HASHTABSIZE; i++)
hashtab[i] = NUL_PTR;
+
+ mainavail = tableend - tableptr;
+ usedtop = 0;
}
/* add named symbol to end of table - initialise only name and next fields */
@@ -130,6 +137,9 @@ unsigned nbytes;
register char *source;
register char *target;
+ usedtop += nbytes;
+ mainavail -= nbytes;
+
source = tableptr;
target = tableend;
while (nbytes--)
@@ -157,7 +167,9 @@ unsigned nbytes;
PUBLIC void ourfree(cptr)
char *cptr;
{
+ check_used();
tableptr = cptr;
+ check_used();
}
/* read string from file into table at offset suitable for next symbol */
@@ -172,6 +184,7 @@ PUBLIC char *readstring()
start = s = ((struct symstruct *) tableptr)->name;
while (TRUE)
{
+ /* Stats: need a checkused against 's', maybe. */
if (s >= tableend)
outofmemory();
if ((c = readchar()) < 0)
@@ -187,9 +200,27 @@ PUBLIC char *readstring()
PUBLIC void release(cptr)
char *cptr;
{
+ check_used();
+ mainavail += cptr - tableend;
+ usedtop -= cptr - tableend;
+
tableend = cptr;
}
+PRIVATE void check_used()
+{
+ int used;
+
+ used = usedtop + mainavail - (tableend - tableptr);
+ if (used > maxused) maxused = used;
+}
+
+PUBLIC int memory_used()
+{
+ check_used();
+ return maxused;
+}
+
/* allocate space for string */
PUBLIC char *stralloc(s)
diff --git a/ld/type.h b/ld/type.h
index 8d4390f..950446f 100644
--- a/ld/type.h
+++ b/ld/type.h
@@ -144,6 +144,7 @@ char *ourmalloc P((unsigned nbytes));
void ourfree P((char *cptr));
char *readstring P((void));
void release P((char *cptr));
+int memory_used P((void));
char *stralloc P((char *s));
/* typeconvert.c */
@@ -161,7 +162,7 @@ bool_pt typeconv_init P((bool_pt big_endian, bool_pt long_big_endian));
void writebin P((char *outfilename, bool_pt argsepid, bool_pt argbits32,
bool_pt argstripflag, bool_pt arguzp));
-void write_rel P((char *outfilename, bool_pt argsepid, bool_pt argbits32,
+void write_dosemu P((char *outfilename, bool_pt argsepid, bool_pt argbits32,
bool_pt argstripflag, bool_pt arguzp));
/* write_elks.c */
diff --git a/ld/writebin.c b/ld/writebin.c
index e833f6c..d3032e3 100644
--- a/ld/writebin.c
+++ b/ld/writebin.c
@@ -3,12 +3,6 @@
/* Copyright (C) 1994 Bruce Evans */
-#ifndef NO_AOUT
-#ifndef A_OUT_INCL
-#define A_OUT_INCL <a.out.h>
-#endif
-#endif
-
#include "syshead.h"
#include "bindef.h"
#include "const.h"
diff --git a/ld/writerel.c b/ld/writeemu.c
index a0294f5..b0438fc 100644
--- a/ld/writerel.c
+++ b/ld/writeemu.c
@@ -9,14 +9,12 @@
* an as86 object file.
*/
-#ifdef BUGCOMPAT
+#undef A_OUT_INCL
#define A_OUT_INCL "rel_aout.h"
#define BSD_A_OUT 1
#define FILEHEADERLENGTH 32
#define ELF_SYMS 0
-#define FUNCNAME write_rel
-#undef NO_AOUT
+#define FUNCNAME write_dosemu
#include "writebin.c"
-#endif