From: ceriel Date: Wed, 10 Nov 1993 15:11:28 +0000 (+0000) Subject: Many changes, mostly for Solaris 2 X-Git-Tag: release-5-5~239 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=b95ae2fa7044fa6662b49b299b92ba4aece3daee;p=ack.git Many changes, mostly for Solaris 2 --- diff --git a/util/grind/.distr b/util/grind/.distr index abcfe807b..097bdb05c 100644 --- a/util/grind/.distr +++ b/util/grind/.distr @@ -26,6 +26,7 @@ make.ops make.tokcase make.tokfile message.h +misc.h modula-2.c operator.h operators.ot diff --git a/util/grind/c.c b/util/grind/c.c index c9c2d3647..949109fef 100644 --- a/util/grind/c.c +++ b/util/grind/c.c @@ -14,6 +14,7 @@ #include "expr.h" #include "tree.h" #include "operator.h" +#include "misc.h" extern FILE *db_out, *db_in; diff --git a/util/grind/commands.g b/util/grind/commands.g index a271671f7..7c8a65426 100644 --- a/util/grind/commands.g +++ b/util/grind/commands.g @@ -16,6 +16,7 @@ #include "langdep.h" #include "token.h" #include "expr.h" +#include "misc.h" extern char *Salloc(); extern char *strindex(); diff --git a/util/grind/db_symtab.g b/util/grind/db_symtab.g index d25ad58dc..d25c3f357 100644 --- a/util/grind/db_symtab.g +++ b/util/grind/db_symtab.g @@ -16,6 +16,7 @@ #include "class.h" #include "idf.h" #include "rd.h" +#include "misc.h" extern char *strindex(); extern long str2long(); diff --git a/util/grind/do_comm.c b/util/grind/do_comm.c index 5b8cb170b..42c84390d 100644 --- a/util/grind/do_comm.c +++ b/util/grind/do_comm.c @@ -16,6 +16,7 @@ #include "symbol.h" #include "scope.h" #include "file.h" +#include "misc.h" extern FILE *db_out; extern t_lineno listline, currline; diff --git a/util/grind/expr.c b/util/grind/expr.c index 6240e5828..3ca7aa799 100644 --- a/util/grind/expr.c +++ b/util/grind/expr.c @@ -52,12 +52,14 @@ #include "langdep.h" #include "scope.h" #include "idf.h" +#include "misc.h" extern FILE *db_out; extern int stack_offset; extern char *strcpy(); extern t_addr *get_EM_regs(); extern char *memcpy(); +extern char *malloc(), *realloc(); #define malloc_succeeded(p) if (! (p)) {\ error("could not allocate enough memory");\ diff --git a/util/grind/itemlist.cc b/util/grind/itemlist.cc index 5d6674121..3dc4f685f 100644 --- a/util/grind/itemlist.cc +++ b/util/grind/itemlist.cc @@ -7,6 +7,7 @@ #include "position.h" #include "tree.h" #include "operator.h" +#include "misc.h" extern FILE *db_out; extern int db_ss; diff --git a/util/grind/list.c b/util/grind/list.c index 995edcbc1..59f69bf45 100644 --- a/util/grind/list.c +++ b/util/grind/list.c @@ -7,6 +7,7 @@ #include "idf.h" #include "file.h" #include "symbol.h" +#include "misc.h" static line_positions(); extern char *dirs[]; diff --git a/util/grind/main.c b/util/grind/main.c index bdedac56f..2d6549482 100644 --- a/util/grind/main.c +++ b/util/grind/main.c @@ -1,8 +1,12 @@ /* $Header$ */ #include -#include #include +#if __STDC__ +#include +#else +#include +#endif #include "tokenname.h" #include "position.h" @@ -12,6 +16,7 @@ #include "Lpars.h" #include "type.h" #include "langdep.h" +#include "misc.h" static char *usage = "Usage: %s [] []"; char *progname; @@ -114,7 +119,58 @@ prompt() } } +extern int errorgiven; + +#if __STDC__ +void +fatal(char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + { + fprintf(db_out, "%s: ", progname); + vfprintf(db_out, fmt, ap); + fprintf(db_out, "\n"); + } + va_end(ap); + exit(1); +} + +void +error(char *fmt, ...) +{ + va_list ap; + + if (! interrupted) { + va_start(ap, fmt); + { + fprintf(db_out, "%s: ", progname); + vfprintf(db_out, fmt, ap); + fprintf(db_out, "\n"); + } + va_end(ap); + } + errorgiven = 1; +} + +void +warning(char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + { + fprintf(db_out, "%s: ", progname); + vfprintf(db_out, fmt, ap); + fprintf(db_out, "\n"); + } + va_end(ap); +} + +#else /*VARARGS*/ +void fatal(va_alist) va_dcl { @@ -132,9 +188,8 @@ fatal(va_alist) exit(1); } -extern int errorgiven; - /*VARARGS*/ +void error(va_alist) va_dcl { @@ -155,6 +210,7 @@ error(va_alist) } /*VARARGS*/ +void warning(va_alist) va_dcl { @@ -170,12 +226,15 @@ warning(va_alist) } va_end(ap); } +#endif +void rd_fatal() { fatal("read error in %s", AckObj); } +void No_Mem() { fatal("out of memory"); diff --git a/util/grind/misc.h b/util/grind/misc.h new file mode 100644 index 000000000..f3cadeb0b --- /dev/null +++ b/util/grind/misc.h @@ -0,0 +1,7 @@ +/* $Header$ */ + +#include + +_PROTOTYPE(void fatal, (char *, ...)); +_PROTOTYPE(void error, (char *, ...)); +_PROTOTYPE(void warning, (char *, ...)); diff --git a/util/grind/modula-2.c b/util/grind/modula-2.c index 0a3d2670b..53be33461 100644 --- a/util/grind/modula-2.c +++ b/util/grind/modula-2.c @@ -15,6 +15,7 @@ #include "expr.h" #include "tree.h" #include "operator.h" +#include "misc.h" extern FILE *db_out, *db_in; diff --git a/util/grind/pascal.c b/util/grind/pascal.c index 1f08f219b..dbfe4f24a 100644 --- a/util/grind/pascal.c +++ b/util/grind/pascal.c @@ -16,6 +16,7 @@ #include "expr.h" #include "tree.h" #include "operator.h" +#include "misc.h" extern FILE *db_out, *db_in; diff --git a/util/grind/position.c b/util/grind/position.c index 746dc7d81..f92432927 100644 --- a/util/grind/position.c +++ b/util/grind/position.c @@ -11,6 +11,7 @@ #include "file.h" #include "idf.h" #include "symbol.h" +#include "misc.h" extern FILE *db_out; diff --git a/util/grind/print.c b/util/grind/print.c index e9f9a9b04..87f58b950 100644 --- a/util/grind/print.c +++ b/util/grind/print.c @@ -11,9 +11,11 @@ #include "position.h" #include "idf.h" #include "expr.h" +#include "misc.h" extern FILE *db_out; extern char *strindex(); +extern char *malloc(); static print_unsigned(tp, v, format) diff --git a/util/grind/proto.main b/util/grind/proto.main index a51900606..9a9d4445e 100644 --- a/util/grind/proto.main +++ b/util/grind/proto.main @@ -22,7 +22,7 @@ MODLIB = \ $(LIBDIR)/libstring.$(LIBSUF) \ $(LIBDIR)/libsystem.$(LIBSUF) -LIBS = $(MODLIB) +LIBS = $(EXTRALIB) $(MODLIB) LINTLIBS = \ $(LINTLIBDIR)/$(LINTPREF)assert.$(LINTSUF) \ @@ -33,7 +33,7 @@ LINTLIBS = \ PROFILE = INCLUDES = -I. -I$(SRC_DIR) -I$(TARGET_HOME)/modules/h -I$(TARGET_HOME)/h -I$(TARGET_HOME)/modules/pkg -CFLAGS = $(PROFILE) $(INCLUDES) $(COPTIONS) +CFLAGS = $(PROFILE) $(INCLUDES) $(COPTIONS) -DNDEBUG LINTFLAGS = $(INCLUDES) $(LINTOPTIONS) LDFLAGS = $(PROFILE) $(LDOPTIONS) diff --git a/util/grind/proto.make b/util/grind/proto.make index ac5d91bad..5c4765f4d 100644 --- a/util/grind/proto.make +++ b/util/grind/proto.make @@ -7,6 +7,7 @@ UTIL_BIN = $(UTIL_HOME)/bin TABGEN= $(UTIL_BIN)/tabgen LLGEN = $(UTIL_BIN)/LLgen LLGENOPTIONS = -v +EXTRALIB = SRC_G1 = $(SRC_DIR)/commands.g GEN_G1 = tokenfile.g @@ -64,7 +65,7 @@ NEXTFILES = $(SRC_DIR)/file.hh \ $(SRC_DIR)/langdep.cc all: make.main - make -f make.main grind + make -f make.main "EXTRALIB="$(EXTRALIB) grind install: all cp grind $(TARGET_HOME)/bin/grind diff --git a/util/grind/rd.c b/util/grind/rd.c index 16213b026..cefbc3bef 100644 --- a/util/grind/rd.c +++ b/util/grind/rd.c @@ -3,10 +3,15 @@ /* a.out file reading ... */ #include "rd.h" +#include "misc.h" +#include +#include #if defined(__sun) +#if ! defined(sun) #define sun #endif +#endif #if defined(__i386) #define i386 @@ -17,13 +22,20 @@ #endif #if defined(__sparc) +#if ! defined(sparc) #define sparc #endif +#endif #if defined(__vax) #define vax #endif +#if defined(__solaris) || defined(__solaris__) +#define solaris +#endif + +#if ! defined(solaris) #if defined(sun) || defined(vax) struct exec { @@ -215,6 +227,7 @@ rd_close() fclose(inf); } +#endif #endif #if defined(i386) @@ -380,3 +393,248 @@ rd_close() { } #endif + +#if defined(solaris) +#include +#include +#include + +struct nlist { + union { + char *n_name; + long n_strx; + } n_un; + unsigned char n_type; + char n_other; + short n_desc; + unsigned long n_value; +}; + +static int fildes; +static Elf *elf; +static Elf32_Ehdr *ehdr; +static struct nlist *dbtab; +static char *dbstringtab; +static Elf32_Sym *tab; +static char *stringtab; +static struct outhead hh; +static struct nlist *maxdn; + +#define N_STAB 0xe0 + +int +rd_open(f) + char *f; +{ + if ((fildes = open(f, 0)) < 0) return 0; + elf_version(EV_CURRENT); + if ((elf = elf_begin(fildes, ELF_C_READ, (Elf *) 0)) == 0) { + close(fildes); + return 0; + } + if ((ehdr = elf32_getehdr(elf)) == NULL) { + elf_end(elf); + close(fildes); + return 0; + } + return 1; +} + +rd_ohead(h) + struct outhead *h; +{ + Elf_Scn *scn = 0; + Elf32_Shdr *shdr; + Elf_Data *sectnames; + Elf_Data *dt; + register struct nlist *dn; + register Elf32_Sym *n; + long text_offset, data_offset, bss_offset, fun_offset; + int fixnamoff = 0, newfixnamoff = 0; + + h->oh_magic = O_CONVERTED; + h->oh_stamp = 0; + h->oh_nsect = 4; + h->oh_nrelo = 0; + h->oh_flags = 0; + h->oh_nemit = 0; + h->oh_nname = 0; + + scn = elf_getscn(elf, (size_t) ehdr->e_shstrndx); + sectnames = elf_getdata(scn, (Elf_Data *) 0); + + scn = 0; + while ((scn = elf_nextscn(elf, scn)) != 0) { + shdr = elf32_getshdr(scn); + switch(shdr->sh_type) { + case SHT_PROGBITS: + /* Get stab symbol table. Elf does not know about it, + and, unfortunately, no relocation is done on it. + */ + h->oh_nemit += shdr->sh_size; + if (! strcmp(".stab", (char *)(sectnames->d_buf)+shdr->sh_name)) { + dt = elf_getdata(scn, (Elf_Data *) 0); + if (dt->d_size == 0) { + fatal("(part of) symbol table is missing"); + } + dbtab = (struct nlist *) Malloc(dt->d_size); + memcpy((char *) dbtab, (char *) dt->d_buf, dt->d_size); + maxdn = (struct nlist *)((char *)dbtab+dt->d_size); + break; + } + break; + + case SHT_STRTAB: + /* Get the stab string table, as well as the usual string + table. + */ + if (! strcmp(".stabstr", (char *)(sectnames->d_buf)+shdr->sh_name)) { + dt = elf_getdata(scn, (Elf_Data *) 0); + if (dt->d_size == 0) { + fatal("(part of) symbol table is missing"); + } + dbstringtab = dt->d_buf; + h->oh_nchar = dt->d_size; + break; + } + if (! strcmp(".strtab", (char *)(sectnames->d_buf)+shdr->sh_name)) { + dt = elf_getdata(scn, (Elf_Data *) 0); + if (dt->d_size == 0) { + fatal("(part of) symbol table is missing"); + } + stringtab = dt->d_buf; + } + break; + + case SHT_SYMTAB: + /* Get the symbol table. */ + if (! strcmp(".symtab", (char *)(sectnames->d_buf)+shdr->sh_name)) { + dt = elf_getdata(scn, (Elf_Data *) 0); + if (dt->d_size == 0) { + fatal("(part of) symbol table is missing"); + } + tab = dt->d_buf; + } + break; + } + } + + /* Convert offsets in stab symbol table. */ + n = tab; + dn = dbtab; + while (dn < maxdn) { + int i; + + if (dn->n_un.n_strx) { + dn->n_un.n_strx += fixnamoff; + } + switch(dn->n_type) { + case 0: + fixnamoff = newfixnamoff; + newfixnamoff += dn->n_value; + break; + + case N_SO: + h->oh_nname++; + i = 0; + while (i < 3) { + while (stringtab[n->st_name] != 'B') n++; + if (! strcmp("Btext.text", &(stringtab[n->st_name]))) { + text_offset = n->st_value; i++; + } + else if (! strcmp("Bdata.data", &(stringtab[n->st_name]))) { + data_offset = n->st_value; i++; + } + else if (! strcmp("Bbss.bss", &(stringtab[n->st_name]))) { + bss_offset = n->st_value; i++; + } + n++; + } + break; + + case N_GSYM: + h->oh_nname++; + /* Fortunately, we don't use this in ACK, so we don't + have to handle it here. The problem is that we don't know + which segment it comes from. + */ + break; + + case N_STSYM: + h->oh_nname++; + dn->n_value += data_offset; + break; + + case N_LCSYM: + h->oh_nname++; + dn->n_value += bss_offset; + break; + + case N_FUN: + h->oh_nname++; + dn->n_value += text_offset; + fun_offset = dn->n_value; + break; + + case N_MAIN: + dn->n_value += text_offset; + break; + + case N_LBRAC: + case N_RBRAC: + case N_SLINE: + h->oh_nname++; + dn->n_value += fun_offset; + break; + + case N_SOL: + case N_EINCL: + case N_BINCL: + case N_PSYM: + case N_SSYM: + case N_SCOPE: + case N_RSYM: + case N_LSYM: + h->oh_nname++; + /* Nothing to be done. */ + break; + } + dn++; + } + hh = *h; +} + +rd_name(nm, count) + struct outname *nm; + unsigned int count; +{ + register struct nlist *dn = dbtab; + register struct outname *n = nm; + while (dn < maxdn) { + if (dn->n_type & N_STAB) { + n->on_type = dn->n_type << 8; + n->on_valu = dn->n_value; + n->on_desc = dn->n_desc; + if (dn->n_un.n_strx == 0) n->on_foff = 0; + else n->on_foff = OFF_CHAR(hh) + dn->n_un.n_strx; + n++; + } + dn++; + } + free(dbtab); +} + +rd_string(nm, count) + char *nm; + long count; +{ + memcpy(nm, dbstringtab, count); +} + +rd_close() +{ + elf_end(elf); + close(fildes); +} + +#endif diff --git a/util/grind/run.c b/util/grind/run.c index 2498f79ba..223b0d489 100644 --- a/util/grind/run.c +++ b/util/grind/run.c @@ -18,10 +18,12 @@ #include "scope.h" #include "type.h" #include "expr.h" +#include "misc.h" #define MAXARG 128 extern char *strncpy(); +extern char *malloc(); extern struct idf *str2idf(); extern char *AObj; diff --git a/util/grind/symbol.c b/util/grind/symbol.c index 031099f05..d2bda33ba 100644 --- a/util/grind/symbol.c +++ b/util/grind/symbol.c @@ -16,6 +16,7 @@ #include "scope.h" #include "tree.h" #include "operator.h" +#include "misc.h" p_symbol currfile, listfile; diff --git a/util/grind/tokenname.c b/util/grind/tokenname.c index 9d6fb7a3c..9a1c1455d 100644 --- a/util/grind/tokenname.c +++ b/util/grind/tokenname.c @@ -5,6 +5,7 @@ #include "position.h" #include "file.h" #include "idf.h" +#include "misc.h" /* To centralize the declaration of %tokens, their presence in this file is taken as their declaration. The Makefile will produce diff --git a/util/grind/tree.c b/util/grind/tree.c index 2e9f0e1ca..41982f82c 100644 --- a/util/grind/tree.c +++ b/util/grind/tree.c @@ -16,6 +16,7 @@ #include "langdep.h" #include "type.h" #include "expr.h" +#include "misc.h" extern FILE *db_out; t_lineno currline; diff --git a/util/grind/type.c b/util/grind/type.c index 9120f7553..857d88370 100644 --- a/util/grind/type.c +++ b/util/grind/type.c @@ -11,6 +11,7 @@ #include "scope.h" #include "langdep.h" #include "expr.h" +#include "misc.h" p_type int_type, char_type, short_type, long_type, bool_type; p_type uint_type, uchar_type, ushort_type, ulong_type;