summaryrefslogtreecommitdiff
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
parent22950ba3df3a0b739786243679d69cd4094e8b20 (diff)
downloaddev86-b5dac1e3bdd01a2ce105df747a9073ff0d6a94e2.tar.gz
Import Dev86src-0.16.14.tar.gzv0.16.14
-rw-r--r--Changes5
-rw-r--r--Makefile2
-rw-r--r--ar/alloca.c2
-rw-r--r--ar/ar.c6
-rw-r--r--bcc/bcc.c3
-rw-r--r--copt/copt.c1
-rw-r--r--cpp/cc.h24
-rw-r--r--cpp/cpp.c43
-rw-r--r--cpp/cygwin.c99
-rw-r--r--cpp/hash.c6
-rw-r--r--cpp/main.c29
-rw-r--r--cpp/token1.c2
-rw-r--r--cpp/token2.c2
-rw-r--r--ifdef.c7
-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
-rw-r--r--makefile.in40
-rw-r--r--unproto/Makefile2
28 files changed, 380 insertions, 321 deletions
diff --git a/Changes b/Changes
index 88a23d8..680d76d 100644
--- a/Changes
+++ b/Changes
@@ -3,6 +3,11 @@ For version 0.16.*.
> More changes so it compiles better on 'other' machines.
Removed some GNU-Make'isms in the top header file.
+> It seems that CYGWin's problem with _P is inherited from BSD. It also
+ seems most of my problems come from BSD recently, haven't they realised
+ that they down own the 'Unix Standard' anymore and haven't since SYSV
+ got popular.
+
> Some changes for cygwin, it isn't quite as nasty as compiling for minix
but it doesn't miss by much!
diff --git a/Makefile b/Makefile
index 429ce8e..704c9d2 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
# This file is part of the Linux-8086 Development environment and is
# distributed under the GNU General Public License.
-VERSION=0.16.13
+VERSION=0.16.14
TARGETS= \
clean bcc unproto copt as86 ld86 elksemu \
diff --git a/ar/alloca.c b/ar/alloca.c
index 880c100..80c95e2 100644
--- a/ar/alloca.c
+++ b/ar/alloca.c
@@ -6,7 +6,7 @@
#include <string.h>
#endif
-#ifdef __TINYC__
+#if defined(__TINYC__) || defined(__HP_cc)
typedef union mem_cell
{
union mem_cell *next; /* A pointer to the next mem */
diff --git a/ar/ar.c b/ar/ar.c
index 1753293..b0694ac 100644
--- a/ar/ar.c
+++ b/ar/ar.c
@@ -15,7 +15,7 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-
+
#include <stdio.h>
#include <stdlib.h>
@@ -29,11 +29,11 @@
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include <sys/errno.h>
+#include <errno.h>
#include "ar.h"
#include "rel_aout.h"
-#ifdef __BCC__
+#if defined(__BCC__) || defined(__HP_cc)
#define HAVE_RENAME
#undef HAVE_FSYNC
#define SHORT_FILENAME
diff --git a/bcc/bcc.c b/bcc/bcc.c
index 9b053e5..67e5469 100644
--- a/bcc/bcc.c
+++ b/bcc/bcc.c
@@ -21,10 +21,11 @@
#ifndef MSDOS
#include <unistd.h>
#endif
+#else
+#include <malloc.h>
#endif
#include <string.h>
#include <memory.h>
-#include <malloc.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
diff --git a/copt/copt.c b/copt/copt.c
index 350c163..d744da8 100644
--- a/copt/copt.c
+++ b/copt/copt.c
@@ -36,7 +36,6 @@
#include <stdio.h>
#include <stdlib.h>
-#include <malloc.h>
#include <string.h>
#include <ctype.h>
diff --git a/cpp/cc.h b/cpp/cc.h
index 5781f05..9bb7ebd 100644
--- a/cpp/cc.h
+++ b/cpp/cc.h
@@ -1,16 +1,16 @@
-#ifndef _P
+#ifndef P
#if __STDC__
-#define _P(x) x
+#define P(x) x
#else
-#define _P(x) ()
+#define P(x) ()
#endif
#endif
-extern void cfatal _P((char*));
-extern void cerror _P((char*));
-extern void cwarn _P((char*));
-extern FILE * open_include _P((char*, char*, int));
+extern void cfatal P((char*));
+extern void cerror P((char*));
+extern void cwarn P((char*));
+extern FILE * open_include P((char*, char*, int));
extern FILE * curfile;
extern char curword[];
@@ -22,11 +22,11 @@ extern int dialect;
#define DI_KNR 1
#define DI_ANSI 2
-extern int gettok _P((void));
+extern int gettok P((void));
struct token_trans { char * name; int token; };
-struct token_trans * is_ctok _P((const char *str, unsigned int len));
-struct token_trans * is_ckey _P((const char *str, unsigned int len));
+struct token_trans * is_ctok P((const char *str, unsigned int len));
+struct token_trans * is_ckey P((const char *str, unsigned int len));
#define WORDSIZE 128
#define TK_WSPACE 256
@@ -101,8 +101,8 @@ struct token_trans * is_ckey _P((const char *str, unsigned int len));
#define MAX_INCLUDE 64 /* Nested includes */
#define MAX_DEFINE 64 /* Nested defines */
-extern char * set_entry _P((int,char*,void*));
-extern void * read_entry _P((int,char*));
+extern char * set_entry P((int,char*,void*));
+extern void * read_entry P((int,char*));
struct define_item
{
diff --git a/cpp/cpp.c b/cpp/cpp.c
index 231760b..7fcc4b5 100644
--- a/cpp/cpp.c
+++ b/cpp/cpp.c
@@ -1,9 +1,10 @@
#include <stdio.h>
#include <string.h>
-#include <malloc.h>
#ifdef __STDC__
#include <stdlib.h>
+#else
+#include <malloc.h>
#endif
#include "cc.h"
@@ -92,26 +93,26 @@ struct arg_store {
int in_define;
};
-static int chget _P((void));
-static int chget_raw _P((void));
-static void unchget _P((int));
-static int gettok_nosub _P((void));
-static int get_onetok _P((int));
-static int pgetc _P((void));
-static int do_preproc _P((void));
-static int do_proc_copy_hashline _P((void));
-static int do_proc_if _P((int));
-static void do_proc_include _P((void));
-static void do_proc_define _P((void));
-static void do_proc_undef _P((void));
-static void do_proc_else _P((void));
-static void do_proc_endif _P((void));
-static void do_proc_tail _P((void));
-static int get_if_expression _P((void));
-static int_type get_expression _P((int));
-static int_type get_exp_value _P((void));
-static void gen_substrings _P((char *, char *, int));
-static char * insert_substrings _P((char *, struct arg_store *, int));
+static int chget P((void));
+static int chget_raw P((void));
+static void unchget P((int));
+static int gettok_nosub P((void));
+static int get_onetok P((int));
+static int pgetc P((void));
+static int do_preproc P((void));
+static int do_proc_copy_hashline P((void));
+static int do_proc_if P((int));
+static void do_proc_include P((void));
+static void do_proc_define P((void));
+static void do_proc_undef P((void));
+static void do_proc_else P((void));
+static void do_proc_endif P((void));
+static void do_proc_tail P((void));
+static int get_if_expression P((void));
+static int_type get_expression P((int));
+static int_type get_exp_value P((void));
+static void gen_substrings P((char *, char *, int));
+static char * insert_substrings P((char *, struct arg_store *, int));
int
gettok()
diff --git a/cpp/cygwin.c b/cpp/cygwin.c
deleted file mode 100644
index 5cb6e39..0000000
--- a/cpp/cygwin.c
+++ /dev/null
@@ -1,99 +0,0 @@
-/* Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
- * This file is part of the Linux-8086 C library and is distributed
- * under the GNU Library General Public License.
- */
-
-/*
- * CTYPE Character classification and conversion
- */
-
-/*
- * I've copied this here from the bcc libs because cygwin's version has
- * the _very_ silly feature of using _P as a private library constant.
- *
- * Single underscore variables are generally used for private variables
- * in user libraries; the few stdio ones being 'leftovers' from version7
- * where user and system libraries were one and the same.
- *
- */
-#ifndef __CTYPE_H
-#define __CTYPE_H
-
-static unsigned char __ctype[];
-
-#define __CT_d 0x01 /* numeric digit */
-#define __CT_u 0x02 /* upper case */
-#define __CT_l 0x04 /* lower case */
-#define __CT_c 0x08 /* control character */
-#define __CT_s 0x10 /* whitespace */
-#define __CT_p 0x20 /* punctuation */
-#define __CT_x 0x40 /* hexadecimal */
-
-/* Define these as simple old style ascii versions */
-#define toupper(c) (((c)>='a'&&(c)<='z') ? (c)^0x20 : (c))
-#define tolower(c) (((c)>='A'&&(c)<='Z') ? (c)^0x20 : (c))
-#define _toupper(c) ((c)^0x20)
-#define _tolower(c) ((c)^0x20)
-#define toascii(c) ((c)&0x7F)
-
-#define __CT(c) (__ctype[1+(unsigned char)c])
-
-/* Note the '!!' is a cast to 'bool' and even BCC deletes it in an if() */
-#define isalnum(c) (!!(__CT(c)&(__CT_u|__CT_l|__CT_d)))
-#define isalpha(c) (!!(__CT(c)&(__CT_u|__CT_l)))
-#define isascii(c) (!((c)&~0x7F))
-#define iscntrl(c) (!!(__CT(c)&__CT_c))
-#define isdigit(c) (!!(__CT(c)&__CT_d))
-#define isgraph(c) (!(__CT(c)&(__CT_c|__CT_s)))
-#define islower(c) (!!(__CT(c)&__CT_l))
-#define isprint(c) (!(__CT(c)&__CT_c))
-#define ispunct(c) (!!(__CT(c)&__CT_p))
-#define isspace(c) (!!(__CT(c)&__CT_s))
-#define isupper(c) (!!(__CT(c)&__CT_u))
-#define isxdigit(c) (!!(__CT(c)&__CT_x))
-
-static unsigned char __ctype[257] =
-{
- 0, /* -1 */
- __CT_c, __CT_c, __CT_c, __CT_c, /* 0x00..0x03 */
- __CT_c, __CT_c, __CT_c, __CT_c, /* 0x04..0x07 */
- __CT_c, __CT_c|__CT_s, __CT_c|__CT_s, __CT_c|__CT_s, /* 0x08..0x0B */
- __CT_c|__CT_s, __CT_c|__CT_s, __CT_c, __CT_c, /* 0x0C..0x0F */
-
- __CT_c, __CT_c, __CT_c, __CT_c, /* 0x10..0x13 */
- __CT_c, __CT_c, __CT_c, __CT_c, /* 0x14..0x17 */
- __CT_c, __CT_c, __CT_c, __CT_c, /* 0x18..0x1B */
- __CT_c, __CT_c, __CT_c, __CT_c, /* 0x1C..0x1F */
-
- __CT_s, __CT_p, __CT_p, __CT_p, /* 0x20..0x23 */
- __CT_p, __CT_p, __CT_p, __CT_p, /* 0x24..0x27 */
- __CT_p, __CT_p, __CT_p, __CT_p, /* 0x28..0x2B */
- __CT_p, __CT_p, __CT_p, __CT_p, /* 0x2C..0x2F */
-
- __CT_d|__CT_x, __CT_d|__CT_x, __CT_d|__CT_x, __CT_d|__CT_x,/* 0x30..0x33 */
- __CT_d|__CT_x, __CT_d|__CT_x, __CT_d|__CT_x, __CT_d|__CT_x,/* 0x34..0x37 */
- __CT_d|__CT_x, __CT_d|__CT_x, __CT_p, __CT_p, /* 0x38..0x3B */
- __CT_p, __CT_p, __CT_p, __CT_p, /* 0x3C..0x3F */
-
- __CT_p, __CT_u|__CT_x, __CT_u|__CT_x, __CT_u|__CT_x, /* 0x40..0x43 */
- __CT_u|__CT_x, __CT_u|__CT_x, __CT_u|__CT_x, __CT_u, /* 0x44..0x47 */
- __CT_u, __CT_u, __CT_u, __CT_u, /* 0x48..0x4B */
- __CT_u, __CT_u, __CT_u, __CT_u, /* 0x4C..0x4F */
-
- __CT_u, __CT_u, __CT_u, __CT_u, /* 0x50..0x53 */
- __CT_u, __CT_u, __CT_u, __CT_u, /* 0x54..0x57 */
- __CT_u, __CT_u, __CT_u, __CT_p, /* 0x58..0x5B */
- __CT_p, __CT_p, __CT_p, __CT_p, /* 0x5C..0x5F */
-
- __CT_p, __CT_l|__CT_x, __CT_l|__CT_x, __CT_l|__CT_x, /* 0x60..0x63 */
- __CT_l|__CT_x, __CT_l|__CT_x, __CT_l|__CT_x, __CT_l, /* 0x64..0x67 */
- __CT_l, __CT_l, __CT_l, __CT_l, /* 0x68..0x6B */
- __CT_l, __CT_l, __CT_l, __CT_l, /* 0x6C..0x6F */
-
- __CT_l, __CT_l, __CT_l, __CT_l, /* 0x70..0x73 */
- __CT_l, __CT_l, __CT_l, __CT_l, /* 0x74..0x77 */
- __CT_l, __CT_l, __CT_l, __CT_p, /* 0x78..0x7B */
- __CT_p, __CT_p, __CT_p, __CT_c /* 0x7C..0x7F */
-};
-
-#endif /* __CTYPE_H */
diff --git a/cpp/hash.c b/cpp/hash.c
index 11c32da..7cab819 100644
--- a/cpp/hash.c
+++ b/cpp/hash.c
@@ -1,6 +1,10 @@
#include <stdio.h>
+#ifdef __STDC__
+#include <stdlib.h>
+#else
#include <malloc.h>
+#endif
#include "cc.h"
/*
@@ -23,7 +27,7 @@ struct hashentry
struct hashentry ** hashtable;
int hashsize = 0xFF; /* 2^X -1 */
int hashcount = 0;
-static int hashvalue _P((int namespace, char * word));
+static int hashvalue P((int namespace, char * word));
void *
read_entry(namespace, word)
diff --git a/cpp/main.c b/cpp/main.c
index b7cf0ee..78db160 100644
--- a/cpp/main.c
+++ b/cpp/main.c
@@ -3,31 +3,28 @@
#if __STDC__
#include <stdlib.h>
#include <locale.h>
-#endif
-#ifndef __CYGWIN__
-#include <ctype.h>
#else
-#include "cygwin.c"
+#include <malloc.h>
#endif
+#include <ctype.h>
#include <string.h>
-#include <malloc.h>
#include <time.h>
#include "cc.h"
#define MAXINCPATH 5
-int main _P((int argc, char ** argv));
-void undefine_macro _P((char * name));
-void define_macro _P((char * name));
-void print_toks_cpp _P((void));
-void print_toks_raw _P((void));
-void define_macro _P((char *));
-void undefine_macro _P((char *));
-void cmsg _P((char * mtype, char * str));
-char * token_txn _P((int));
-void pr_indent _P((int));
-void hash_line _P((void));
+int main P((int argc, char ** argv));
+void undefine_macro P((char * name));
+void define_macro P((char * name));
+void print_toks_cpp P((void));
+void print_toks_raw P((void));
+void define_macro P((char *));
+void undefine_macro P((char *));
+void cmsg P((char * mtype, char * str));
+char * token_txn P((int));
+void pr_indent P((int));
+void hash_line P((void));
char * include_paths[MAXINCPATH];
diff --git a/cpp/token1.c b/cpp/token1.c
index 4b966f7..f3aa420 100644
--- a/cpp/token1.c
+++ b/cpp/token1.c
@@ -6,6 +6,6 @@
#ifdef __GNUC__
__inline
#endif
-static unsigned int hash1 _P((register const char *, register unsigned int));
+static unsigned int hash1 P((register const char *, register unsigned int));
#include "token1.h"
diff --git a/cpp/token2.c b/cpp/token2.c
index c535746..b4d22b1 100644
--- a/cpp/token2.c
+++ b/cpp/token2.c
@@ -6,6 +6,6 @@
#ifdef __GNUC__
__inline
#endif
-static unsigned int hash2 _P((register const char *, register unsigned int));
+static unsigned int hash2 P((register const char *, register unsigned int));
#include "token2.h"
diff --git a/ifdef.c b/ifdef.c
index 0d7fcdd..7289dc1 100644
--- a/ifdef.c
+++ b/ifdef.c
@@ -5,7 +5,7 @@
#include <string.h>
#ifdef __STDC__ /* == Not braindead compiler (hopefully!) */
-#include <malloc.h>
+#include <stdlib.h>
#define P(x) x
#else
@@ -441,7 +441,7 @@ manifest_constant()
#ifdef __linux__
save_name("__linux__", 'D');
#ifdef __i386__
- save_name("__linux____i386__", 'D');
+ save_name("__linux_i386__", 'D');
#endif
#endif
#ifdef __unix__
@@ -499,4 +499,7 @@ manifest_constant()
#ifdef __CYGWIN__
save_name("__CYGWIN__", 'D');
#endif
+#ifdef __APPLE__
+ save_name("__APPLE__", 'D');
+#endif
}
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
diff --git a/makefile.in b/makefile.in
index ac4c989..c026376 100644
--- a/makefile.in
+++ b/makefile.in
@@ -27,7 +27,7 @@ MAKEX=
# files. This should be fine for Linux, but it won't be for AIX etc.
# Unfortunatly it's even _required_ for linux because some versions
# of Redhat have a broken standard ar command.
-#ifdef __linux__
+#ifdef __linux_i386__
AR=ar86
#endif
@@ -68,21 +68,22 @@ BCCARCH =-Mf -O
#endif
#endif
-# Alter these if for some reason you don't want this done as root.
-#ifdef __CYGWIN__
-INDAT=-m 644
-INEXE=-m 755
-INSCR=-m 755
-#else
-#ifdef __BCC__
-INDAT=-o root -g root -m 644
-INEXE=-o root -g root -m 755
-INSCR=-o root -g root -m 755
-#else
+# Apple cpp-precomp 6.14 (devkit-213/devkit_tools-214) cannot
+# handle the QUOT macro in bcc. It puts a space in /usr so that
+# it becomes / usr
+#ifdef __APPLE__
+CFLAGS += -no-cpp-precomp
+#endif
+
+# Yet again other systems have general weirdness here.
+#ifdef __linux__
INDAT=-o root -g root -m 644
INEXE=-o root -g root -m 755 -s
INSCR=-o root -g root -m 755
-#endif
+#else
+INDAT=-m 644
+INEXE=-m 755
+INSCR=-m 755
#endif
#ifdef __CYGWIN__
@@ -188,14 +189,10 @@ objdump86: bindir
elksemu: bindir
#ifndef __AS386_16__
#ifdef __linux_i386__
- $(MAKEC) elksemu \
- CC='$(CC)' PREFIX=$(PREFIX) LIBPRE='$(LIBPRE)' LIBDIR='$(LIBDIR)' BINDIR='$(BINDIR)' \
- elksemu
-#else
$(MAKEC) elksemu CC='ncc' elksemu
-#endif
cp -p elksemu/elksemu bin/elksemu
#endif
+#endif
install-ln: bcc cpp unproto copt as86 ar86 ld86 elksemu
install -d $(DISTBIN)
@@ -205,8 +202,10 @@ install-ln: bcc cpp unproto copt as86 ar86 ld86 elksemu
ln -fs `pwd`/bin/ar86 $(DISTBIN)/ar86
ln -fs `pwd`/bin/ld86 $(DISTBIN)/ld86
#ifndef __AS386_16__
+#ifdef __linux_i386__
ln -fs `pwd`/bin/elksemu $(DIST)/lib/elksemu
#endif
+#endif
-install -d $(DIST)/usr/lib
-install $(INDAT) libc/error/liberror.txt $(DIST)/usr/lib/liberror.txt
@@ -231,9 +230,11 @@ install-bcc: bcc cpp unproto copt as86 ar86 ld86 objdump86
# NB: This doesn't install as a suid root, that's ok though.
install-emu: elksemu
#ifndef __AS386_16__
+#ifdef __linux_i386__
install -d $(DIST)/lib
install $(INEXE) bin/elksemu $(DIST)/lib/elksemu
#endif
+#endif
install-man:
-$(MAKEC) man MANDIR=$(DIST)$(PREFIX)/man install
@@ -287,10 +288,11 @@ lib-bsd: bindir
#ifdef __AS386_16__
alt-libs: lib-stand lib-dos lib-fast
+ @touch lib/lib1-done
#else
alt-libs: lib-stand lib-dos lib-386 lib-fast
-#endif
@touch lib/lib1-done
+#endif
lib-fast: bindir
test -f bin/ncc
diff --git a/unproto/Makefile b/unproto/Makefile
index 42fb1d9..55b8a9d 100644
--- a/unproto/Makefile
+++ b/unproto/Makefile
@@ -83,7 +83,7 @@ OBJECTS = tok_io.o tok_class.o tok_pool.o unproto.o vstring.o symbol.o error.o \
CFLAGS = -O
LDFLAGS =
-CCFLAGS = $(CFLAGS) $(PIPE) $(SKIP) $(BELL) $(MAP) $(ALIAS) -DREOPEN
+CCFLAGS = $(CFLAGS) -w $(PIPE) $(SKIP) $(BELL) $(MAP) $(ALIAS) -DREOPEN
#CFLAGS = -O $(PIPE) $(SKIP) $(BELL) $(MAP) $(ALIAS) -p -Dstatic=
#CFLAGS = -g $(PIPE) $(SKIP) $(BELL) $(MAP) $(ALIAS) -DDEBUG