ref: 8ad82c1a61620e3b865bfbe937b4ff9440383091
parent: bcd0eb471c18a1cd0148b284b9c0a489e4ead6d5
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Feb 19 04:09:01 EST 2019
[libmach] Remove array files
--- a/include/scc/scc/mach.h
+++ b/include/scc/scc/mach.h
@@ -42,6 +42,7 @@
struct object {
int type;
+ char *index;
Objsym *htab[NR_SYMHASH];
Objsym *syms;;
Objsect *secs;
@@ -69,7 +70,6 @@
extern long armember(FILE *fp, char *member);
extern long setindex(int type, long nsyms, Objsymdef *def, FILE *fp);
extern int getindex(int type, long *nsyms, Objsymdef **def, FILE *fp);
-extern char *namindex(int type);
/* TODO */
extern int objload(Obj *obj, Obj *to);
--- a/src/cmd/ld.c
+++ b/src/cmd/ld.c
@@ -327,7 +327,8 @@
}
if (*nmemb++ == 0) {
- if(!strncmp(name, namindex(bintype), SARNAM)) {
+ if (!strncmp(name, "/", SARNAM) ||
+ !strncmp(name, "__.SYMDEF", SARNAM)) {
loadlib(fp);
return 0;
}
--- a/src/cmd/ranlib.c
+++ b/src/cmd/ranlib.c
@@ -16,6 +16,7 @@
#define NR_SYMDEF 32
+static char *namidx;
static long nsymbols;
static int status, artype, nolib;
static char *filename, *membname;
@@ -143,6 +144,7 @@
error("out of memory");
return 0;
}
+ namidx = obj->index;
if (objread(obj, fp) < 0 || objsyms(obj) < 0) {
error("file corrupted");
@@ -198,7 +200,7 @@
merge(FILE *to, struct fprop *prop, FILE *lib, FILE *idx)
{
int c;
- char *index, mtime[13];
+ char mtime[13];
struct ar_hdr first;
rewind(lib);
@@ -208,8 +210,7 @@
if (fread(&first, sizeof(first), 1, lib) != 1)
return 0;
- index = namindex(artype);
- if (!strncmp(first.ar_name, index, SARNAM))
+ if (!strncmp(first.ar_name, namidx, SARNAM))
fseek(lib, atol(first.ar_size), SEEK_CUR);
else
fseek(lib, SARMAG, SEEK_SET);
@@ -219,7 +220,7 @@
strftime(mtime, sizeof(mtime), "%s", gmtime(&prop->time));
fprintf(to,
"%-16.16s%-12s%-6u%-6u%-8lo%-10ld`\n",
- index,
+ namidx,
mtime,
prop->uid,
prop->gid,
--- a/src/libmach/.gitignore
+++ b/src/libmach/.gitignore
@@ -1,13 +1,1 @@
objlst.mk
-del.c
-index.c
-new.c
-probe.c
-read.c
-strip.c
-write.c
-getidx.c
-setidx.c
-namidx.c
-getsect.c
-getsyms.c
--- a/src/libmach/Makefile
+++ b/src/libmach/Makefile
@@ -18,47 +18,20 @@
objlookup.o \
getindex.o \
setindex.o \
- namindex.o \
formember.o \
objtype.o \
objwrite.o \
pack.o \
unpack.o \
- new.o \
- read.o \
- del.o \
- strip.o \
- probe.o \
- write.o \
- getidx.o \
- setidx.o \
- namidx.o \
- getsect.o \
- getsyms.o \
DIRS = coff32
-TBLS = setidx.c \
- getidx.c \
- getsect.c \
- getsyms.c \
- namidx.c \
- new.c \
- read.c \
- del.c \
- strip.c \
- probe.c \
- write.c \
-
all: $(OBJS) $(DIRS) objlst.mk
+@$(MAKE) -f Makefile.mach
$(DIRS): FORCE
+@cd $@ && $(MAKE)
-
-$(TBLS): formats.lst
- mktbl -t `echo $@ | sed 's/\.c//'` -o $@
objlst.mk: $(OBJS) $(DIRS)
mklst $@
--- a/src/libmach/coff32/Makefile
+++ b/src/libmach/coff32/Makefile
@@ -12,7 +12,6 @@
coff32getindex.o \
coff32setidx.o \
coff32getidx.o \
- coff32namidx.o \
coff32getsect.o \
coff32getsyms.o \
--- a/src/libmach/coff32/coff32namidx.c
+++ /dev/null
@@ -1,9 +1,0 @@
-#include <stdio.h>
-
-#include <scc/mach.h>
-
-char *
-coff32namidx(void)
-{
- return "/";
-}
--- a/src/libmach/coff32/coff32new.c
+++ b/src/libmach/coff32/coff32new.c
@@ -14,5 +14,6 @@
if ((coff = calloc(1, sizeof(*coff))) == NULL)
return -1;
obj->data = coff;
+ obj->index = "/";
return 0;
}
--- a/src/libmach/getindex.c
+++ b/src/libmach/getindex.c
@@ -4,17 +4,18 @@
#include "libmach.h"
-extern getidxfun_t getidxv[];
+static int (*funv[])(int, long*, Objsymdef**, FILE*) = {
+ [COFF32] = coff32getidx,
+};
int
getindex(int type, long *nsyms, Objsymdef **head, FILE *fp)
{
int fmt;
- getidxfun_t fn;
fmt = FORMAT(type);
if (fmt >= NFORMATS)
return -1;
- fn = getidxv[fmt];
- return (*fn)(type, nsyms, head, fp);
+
+ return (*funv[fmt])(type, nsyms, head, fp);
}
--- a/src/libmach/libmach.h
+++ b/src/libmach/libmach.h
@@ -28,18 +28,6 @@
TARGETDEL = 1 << 1,
};
-typedef int (*newfun_t)(Obj *obj);
-typedef int (*readfun_t)(Obj *obj, FILE *fp);
-typedef void (*delfun_t)(Obj *new);
-typedef void (*stripfun_t)(Obj *obj);
-typedef int (*probefun_t)(unsigned char *buf, char **name);
-typedef int (*writefun_t)(Obj *obj, FILE *fp);
-typedef long (*setidxfun_t)(int, long, Objsymdef *, FILE *);
-typedef int (*getidxfun_t)(int t, long *n, Objsymdef **def, FILE *fp);
-typedef int (*getsectfun_t)(Obj *obj);
-typedef char *(*namidxfun_t)(void);
-typedef int (*getsymsfun_t)(Obj *obj);
-
/* common functions */
extern int pack(int order, unsigned char *dst, char *fmt, ...);
extern int unpack(int order, unsigned char *src, char *fmt, ...);
--- a/src/libmach/mktbl
+++ /dev/null
@@ -1,35 +1,0 @@
-#!/bin/sh
-
-for i
-do
- case "$1" in
- -t)
- target=$2
- shift 2
- ;;
- -o)
- out=$2
- shift 2
- ;;
- -*)
- echo mktbl [-t target][-o file] >&2
- exit 1
- ;;
- *)
- break
- ;;
- esac
-done
-
-cat < formats.lst > $out <<EOF
-#include <stdio.h>
-#include <scc/mach.h>
-#include "libmach.h"
-
-${target}fun_t ${target}v[] = {
-`while read i
- do
- printf "\t%s," ${i}${target}
- done`
-};
-EOF
--- a/src/libmach/namindex.c
+++ /dev/null
@@ -1,20 +1,0 @@
-#include <stdio.h>
-
-#include <scc/mach.h>
-
-#include "libmach.h"
-
-extern namidxfun_t namidxv[];
-
-char *
-namindex(int type)
-{
- int fmt;
- namidxfun_t fn;
-
- fmt = FORMAT(type);
- if (fmt >= NFORMATS)
- return NULL;
- fn = namidxv[fmt];
- return (*fn)();
-}
--- a/src/libmach/objfree.c
+++ b/src/libmach/objfree.c
@@ -6,20 +6,20 @@
#include "libmach.h"
-extern delfun_t delv[];
+static void (*funv[])(Obj *) = {
+ [COFF32] = coff32del,
+};
int
objfree(Obj *obj, int what)
{
int fmt;
- delfun_t fn;
if (what & TARGETDEL) {
fmt = FORMAT(obj->type);
if (fmt < NFORMATS)
return -1;
- fn = delv[fmt];
- (*fn)(obj);
+ (*funv[fmt])(obj);
}
if (what & GENERICDEL) {
--- a/src/libmach/objnew.c
+++ b/src/libmach/objnew.c
@@ -6,7 +6,9 @@
#include "libmach.h"
-extern newfun_t newv[];
+static int (*funv[])(Obj *) = {
+ [COFF32] = coff32new,
+};
Obj *
objnew(int type)
@@ -13,7 +15,6 @@
{
Obj *obj;
int fmt;
- newfun_t fn;
fmt = FORMAT(type);
if (fmt >= NFORMATS)
@@ -29,8 +30,7 @@
obj->nsecs = 0;
memset(obj->htab, 0, sizeof(obj->htab));
- fn = newv[fmt];
- if ((*fn)(obj) < 0) {
+ if ((*funv[fmt])(obj) < 0) {
free(obj);
return NULL;
}
--- a/src/libmach/objread.c
+++ b/src/libmach/objread.c
@@ -4,20 +4,20 @@
#include "libmach.h"
-extern readfun_t readv[];
+static int (*funv[])(Obj *, FILE *) = {
+ [COFF32] = coff32read,
+};
int
objread(Obj *obj, FILE *fp)
{
int fmt;
- readfun_t fn;
fmt = FORMAT(obj->type);
if (fmt >= NFORMATS)
return -1;
- fn = readv[fmt];
- if ((*fn)(obj, fp) < 0)
+ if ((*funv[fmt])(obj, fp) < 0)
return -1;
return 0;
}
--- a/src/libmach/objsect.c
+++ b/src/libmach/objsect.c
@@ -4,18 +4,18 @@
#include "libmach.h"
-extern getsectfun_t getsectv[];
+static int (*funv[])(Obj *) = {
+ [COFF32] = coff32getsect,
+};
int
objsect(Obj *obj)
{
int fmt;
- getsectfun_t fn;
fmt = FORMAT(obj->type);
if (fmt >= NFORMATS)
return -1;
- fn = getsectv[fmt];
- return (*fn)(obj);
+ return (*funv[fmt])(obj);
}
--- a/src/libmach/objstrip.c
+++ b/src/libmach/objstrip.c
@@ -4,19 +4,19 @@
#include "libmach.h"
-extern stripfun_t stripv[];
+static void (*funv[])(Obj *) = {
+ [COFF32] = coff32strip,
+};
int
objstrip(Obj *obj)
{
int fmt;
- stripfun_t fn;
fmt = FORMAT(obj->type);
if (fmt >= NFORMATS)
return -1;
- fn = stripv[fmt];
- (*fn)(obj);
+ (*funv[fmt])(obj);
objfree(obj, GENERICDEL);
--- a/src/libmach/objsyms.c
+++ b/src/libmach/objsyms.c
@@ -4,18 +4,18 @@
#include "libmach.h"
-extern getsymsfun_t getsymsv[];
+static int (*funv[])(Obj *) = {
+ [COFF32] = coff32getsyms,
+};
int
objsyms(Obj *obj)
{
int fmt;
- getsymsfun_t fn;
fmt = FORMAT(obj->type);
if (fmt >= NFORMATS)
return -1;
- fn = getsymsv[fmt];
- return (*fn)(obj);
+ return (*funv[fmt])(obj);
}
--- a/src/libmach/objtype.c
+++ b/src/libmach/objtype.c
@@ -4,13 +4,15 @@
#include "libmach.h"
-extern probefun_t probev[];
+static int (*funv[])(unsigned char *, char **) = {
+ [COFF32] = coff32probe,
+};
int
objtype(FILE *fp, char **name)
{
int n, i;
- probefun_t *fn;
+ int (**fn)(unsigned char *, char **);
fpos_t pos;
unsigned char buf[NBYTES];
@@ -21,8 +23,8 @@
if (n != 1 || ferror(fp))
return -1;
- for (fn = probev; fn < &probev[NFORMATS]; ++fn) {
- n = (*fn)(buf, name);
+ for (fn = funv; fn < &funv[NFORMATS]; ++fn) {
+ n = (**fn)(buf, name);
if (n == -1)
continue;
return n;
--- a/src/libmach/objwrite.c
+++ b/src/libmach/objwrite.c
@@ -4,19 +4,20 @@
#include "libmach.h"
-extern writefun_t writev[];
+static int (*funv[])(Obj *, FILE *) = {
+ [COFF32] = coff32write,
+};
int
objwrite(Obj *obj, FILE *fp)
{
int fmt;
- writefun_t fn;
fmt = FORMAT(obj->type);
if (fmt >= NFORMATS)
return -1;
- fn = writev[fmt];
- if ((*fn)(obj, fp) < 0)
+
+ if ((*funv[fmt])(obj, fp) < 0)
return -1;
return 0;
}
--- a/src/libmach/setindex.c
+++ b/src/libmach/setindex.c
@@ -4,17 +4,18 @@
#include "libmach.h"
-extern setidxfun_t setidxv[];
+static long (*funv[])(int, long, Objsymdef *, FILE *) = {
+ [COFF32] = coff32setidx,
+};
long
setindex(int type, long nsyms, Objsymdef *head, FILE *fp)
{
int fmt;
- setidxfun_t fn;
fmt = FORMAT(type);
if (fmt >= NFORMATS)
return -1;
- fn = setidxv[fmt];
- return (*fn)(type, nsyms, head, fp);
+
+ return (*funv[fmt])(type, nsyms, head, fp);
}