commit 1b1fe72607dfe27b214377e74fce3c0ccf34f3a2
parent a8ee619de91a3d5c8e54f7601c0bfe7f08546c4e
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Fri, 23 Aug 2019 08:29:08 +0100
[libmach] Intropduce Objops strip method
Diffstat:
7 files changed, 15 insertions(+), 29 deletions(-)
diff --git a/include/scc/scc/mach.h b/include/scc/scc/mach.h
@@ -48,6 +48,7 @@ struct objops {
int (*new)(Obj *obj);
int (*read)(Obj *obj, FILE *fp);
int (*addr2line)(Obj *, unsigned long long , char *, int *);
+ int (*strip)(Obj *obj);
int (*setidx)(long nsyms, Objsymdef *def, FILE *fp);
int (*getidx)(long *nsyms, Objsymdef **def, FILE *fp);
};
@@ -73,7 +74,6 @@ extern int objtype(FILE *fp, char **name);
extern Obj *objnew(int type);
extern void objdel(Obj *obj);
extern Objsym *objlookup(Obj *obj, char *name, int install);
-extern int objstrip(Obj *obj);
extern int objwrite(Obj *obj, FILE *fp);
extern int objpos(Obj *obj, FILE *fp, long pos);
extern int archive(FILE *fp);
diff --git a/src/cmd/strip.c b/src/cmd/strip.c
@@ -31,6 +31,7 @@ strip(char *fname)
int type;
FILE *fp;
Obj *obj;
+ Objops *ops;
errno = 0;
filename = fname;
@@ -46,15 +47,21 @@ strip(char *fname)
error("out of memory");
goto err3;
}
- if ((*obj->ops->read)(obj, fp) < 0) {
+ ops = obj->ops;
+
+ if ((*ops->read)(obj, fp) < 0) {
error("file corrupted");
goto err3;
}
fclose(fp);
fp = NULL;
- objstrip(obj);
+ if ((*ops->strip)(obj) < 0) {
+ error("error stripping");
+ goto err3;
+ }
+ /* TODO: Use a temporary file */
if ((fp = fopen(fname, "wb")) == NULL)
goto err1;
diff --git a/src/libmach/coff32/coff32.c b/src/libmach/coff32/coff32.c
@@ -11,4 +11,5 @@ Objops coff32 = {
.getidx = coff32getidx,
.setidx = coff32setidx,
.addr2line = coff32addr2line,
+ .strip = coff32strip,
};
diff --git a/src/libmach/coff32/coff32.h b/src/libmach/coff32/coff32.h
@@ -29,6 +29,7 @@ extern int coff32read(Obj *obj, FILE *fp);
extern int coff32setidx(long nsymbols, Objsymdef *head, FILE *fp);
extern int coff32getidx(long *nsyms, Objsymdef **def, FILE *fp);
extern int coff32addr2line(Obj *, unsigned long long , char *, int *);
+extern int coff32strip(Obj *obj);
extern int coff32xsetidx(int order, long nsyms, Objsymdef *head, FILE *fp);
extern int coff32xgetidx(int order, long *nsyms, Objsymdef **def, FILE *fp);
diff --git a/src/libmach/coff32/coff32strip.c b/src/libmach/coff32/coff32strip.c
@@ -6,7 +6,7 @@
#include "../libmach.h"
#include "coff32.h"
-void
+int
coff32strip(Obj *obj)
{
int i;
@@ -34,4 +34,6 @@ coff32strip(Obj *obj)
coff->ents = NULL;
coff->rels = NULL;
coff->lines = NULL;
+
+ return 0;
}
diff --git a/src/libmach/libmach.h b/src/libmach/libmach.h
@@ -37,7 +37,6 @@ extern int objfree(Obj *obj, int what);
/* TODO: Move this functions to a coff32 files */
extern void coff32del(Obj *obj);
extern int coff32write(Obj *obj, FILE *fp);
-extern void coff32strip(Obj *obj);
extern int coff32probe(unsigned char *buf, char **name);
extern char *coff32namidx(void);
diff --git a/src/libmach/objstrip.c b/src/libmach/objstrip.c
@@ -1,24 +0,0 @@
-#include <stdio.h>
-
-#include <scc/mach.h>
-
-#include "libmach.h"
-
-static void (*funv[])(Obj *) = {
- [COFF32] = coff32strip,
-};
-
-int
-objstrip(Obj *obj)
-{
- int fmt;
-
- fmt = FORMAT(obj->type);
- if (fmt >= NFORMATS)
- return -1;
- (*funv[fmt])(obj);
-
- objfree(obj, GENERICDEL);
-
- return 0;
-}