ref: 28163a945e4ed77893ac692ddff3ab35432c676b
parent: 9332f34cf7bae72b9ccaa290cae5a1eec3f34f3d
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Aug 23 04:29:08 EDT 2019
[libmach] Intropduce Objops strip method
--- a/include/scc/scc/mach.h
+++ b/include/scc/scc/mach.h
@@ -48,6 +48,7 @@
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 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);
--- a/src/cmd/strip.c
+++ b/src/cmd/strip.c
@@ -31,6 +31,7 @@
int type;
FILE *fp;
Obj *obj;
+ Objops *ops;
errno = 0;
filename = fname;
@@ -46,7 +47,9 @@
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;
}
@@ -53,8 +56,12 @@
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;
--- a/src/libmach/coff32/coff32.c
+++ b/src/libmach/coff32/coff32.c
@@ -11,4 +11,5 @@
.getidx = coff32getidx,
.setidx = coff32setidx,
.addr2line = coff32addr2line,
+ .strip = coff32strip,
};
--- a/src/libmach/coff32/coff32.h
+++ b/src/libmach/coff32/coff32.h
@@ -29,6 +29,7 @@
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);
--- 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 @@
coff->ents = NULL;
coff->rels = NULL;
coff->lines = NULL;
+
+ return 0;
}
--- a/src/libmach/libmach.h
+++ b/src/libmach/libmach.h
@@ -37,7 +37,6 @@
/* 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);
--- a/src/libmach/objstrip.c
+++ /dev/null
@@ -1,24 +1,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;
-}