scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit aa999e2efe9944cd1b47ea2f7de9c9dd9ae53e93
parent 35c819e31cdf871d0a61973b77484eea926267d6
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 10 Feb 2019 19:02:43 +0000

[libmach] Add namindex()

This function returns the name of the index file for the
object file format.

Diffstat:
Minclude/scc/scc/mach.h | 1+
Msrc/cmd/ld/main.c | 15+++++++--------
Msrc/cmd/ranlib.c | 8++++----
Msrc/libmach/.gitignore | 1+
Msrc/libmach/Makefile | 3+++
Msrc/libmach/coff32/Makefile | 1+
Asrc/libmach/coff32/coff32namidx.c | 9+++++++++
Msrc/libmach/libmach.h | 3+++
Asrc/libmach/namindex.c | 20++++++++++++++++++++
9 files changed, 49 insertions(+), 12 deletions(-)

diff --git a/include/scc/scc/mach.h b/include/scc/scc/mach.h @@ -75,6 +75,7 @@ extern int objstrip(Obj *obj); extern int objwrite(Obj *obj, FILE *fp); extern long setindex(int type, long nsyms, Objsymdef *def, FILE *fp); extern long getindex(int type, long *nsyms, Objsymdef **def, FILE *fp); +extern char *namindex(int type); /* TODO */ extern int objload(Obj *obj, Obj *to); diff --git a/src/cmd/ld/main.c b/src/cmd/ld/main.c @@ -275,8 +275,8 @@ clean: static int newmember(FILE *fp, char *name, void *data) { - int *nmemb = data; int t; + int *nmemb = data; membname = data; @@ -285,18 +285,17 @@ newmember(FILE *fp, char *name, void *data) return 0; } - /* TODO: This name depends of the format */ - if (*nmemb++ == 0 && !strncmp(name, "/", SARNAM)) { - loadlib(fp); - return 0; + if (*nmemb++ == 0) { + if(!strncmp(name, namindex(bintype), SARNAM)) { + loadlib(fp); + return 0; + } } if ((t = objtype(fp, NULL)) == -1) return 1; - if (bintype == -1) { - bintype = t; - } else if (bintype != t) { + if (bintype != t) { error("wrong object file format"); return 1; } diff --git a/src/cmd/ranlib.c b/src/cmd/ranlib.c @@ -198,7 +198,7 @@ static int merge(FILE *to, struct fprop *prop, FILE *lib, FILE *idx) { int c; - char mtime[13]; + char *index, mtime[13]; struct ar_hdr first; rewind(lib); @@ -208,8 +208,8 @@ merge(FILE *to, struct fprop *prop, FILE *lib, FILE *idx) if (fread(&first, sizeof(first), 1, lib) != 1) return 0; - /* TODO: This name depends of the format */ - if (!strncmp(first.ar_name, "/", SARNAM)) + index = namindex(artype); + if (!strncmp(first.ar_name, index, SARNAM)) fseek(lib, atol(first.ar_size), SEEK_CUR); fwrite(ARMAG, SARMAG, 1, to); @@ -217,7 +217,7 @@ merge(FILE *to, struct fprop *prop, FILE *lib, FILE *idx) strftime(mtime, sizeof(mtime), "%s", gmtime(&prop->time)); fprintf(to, "%-16.16s%-12s%-6u%-6u%-8lo%-10ld`\n", - "/", /* TODO: This name depends of the format */ + index, mtime, prop->uid, prop->gid, diff --git a/src/libmach/.gitignore b/src/libmach/.gitignore @@ -8,3 +8,4 @@ strip.c write.c getidx.c setidx.c +namidx.c diff --git a/src/libmach/Makefile b/src/libmach/Makefile @@ -16,6 +16,7 @@ OBJS = addr2line.o \ objstrip.o \ getindex.o \ setindex.o \ + namindex.o \ forsym.o \ forsect.o \ formember.o \ @@ -33,12 +34,14 @@ OBJS = addr2line.o \ write.o \ getidx.o \ setidx.o \ + namidx.o \ DIRS = coff32 TBLS = setidx.c \ getidx.c \ + namidx.c \ new.c \ read.c \ del.c \ diff --git a/src/libmach/coff32/Makefile b/src/libmach/coff32/Makefile @@ -12,6 +12,7 @@ OBJS = coff32del.o \ coff32getindex.o \ coff32setidx.o \ coff32getidx.o \ + coff32namidx.o \ all: $(OBJS) diff --git a/src/libmach/coff32/coff32namidx.c b/src/libmach/coff32/coff32namidx.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +#include <scc/mach.h> + +char * +coff32namidx(void) +{ + return "/"; +} diff --git a/src/libmach/libmach.h b/src/libmach/libmach.h @@ -36,6 +36,7 @@ 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 char *(*namidxfun_t)(void); /* common functions */ extern int pack(int order, unsigned char *dst, char *fmt, ...); @@ -57,3 +58,5 @@ extern long coff32setidx(int order, long nsyms, Objsymdef *head, FILE *fp); extern int coff32getindex(int type, long *nsyms, Objsymdef **def, FILE *fp); extern int coff32getidx(int order, long *nsyms, Objsymdef **def, FILE *fp); + +extern char *coff32namidx(void); diff --git a/src/libmach/namindex.c b/src/libmach/namindex.c @@ -0,0 +1,20 @@ +#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)(); +}