shithub: scc

Download patch

ref: d2a53b6785e6cdc93bc80220e03e3e27eef41edf
parent: 8d1263baee29b16b1ea7de48f1eb3e3d43e43e18
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Aug 23 13:16:45 EDT 2019

[libmach] Add write method to Objops

--- a/include/scc/scc/mach.h
+++ b/include/scc/scc/mach.h
@@ -50,6 +50,7 @@
 	int (*addr2line)(Obj *, unsigned long long , char *, int *);
 	int (*strip)(Obj *obj);
 	void (*del)(Obj *obj);
+	int (*write)(Obj *obj, FILE *fp);
 	int (*setidx)(long nsyms, Objsymdef *def, FILE *fp);
 	int (*getidx)(long *nsyms, Objsymdef **def, FILE *fp);
 };
@@ -74,7 +75,6 @@
 extern int objtype(FILE *fp, char **name);
 extern Obj *objnew(int type);
 extern Objsym *objlookup(Obj *obj, char *name, int install);
-extern int objwrite(Obj *obj, FILE *fp);
 extern int objpos(Obj *obj, FILE *fp, long pos);
 extern int archive(FILE *fp);
 extern long armember(FILE *fp, char *member);
--- a/src/cmd/ld/pass5.c
+++ b/src/cmd/ld/pass5.c
@@ -48,5 +48,5 @@
 
 	fp = fopen(output, "wb");
 	objsync(obj);
-	objwrite(obj, fp);
+	(obj->ops->write)(obj, fp);
 }
--- a/src/cmd/strip.c
+++ b/src/cmd/strip.c
@@ -65,7 +65,7 @@
 	if ((fp = fopen(fname, "wb")) == NULL)
 		goto err1;
 
-	if (objwrite(obj, fp) < 0) {
+	if (ops->write(obj, fp) < 0) {
 		error("error writing output");
 		goto err3;
 	}
--- a/src/libmach/coff32/coff32.c
+++ b/src/libmach/coff32/coff32.c
@@ -13,4 +13,5 @@
 	.addr2line = coff32addr2line,
 	.strip = coff32strip,
 	.del = coff32del,
+	.write = coff32write,
 };
--- a/src/libmach/coff32/coff32.h
+++ b/src/libmach/coff32/coff32.h
@@ -31,6 +31,7 @@
 extern int coff32addr2line(Obj *, unsigned long long , char *, int *);
 extern int coff32strip(Obj *obj);
 extern void coff32del(Obj *obj);
+extern int coff32write(Obj *obj, FILE *fp);
 
 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/libmach.h
+++ b/src/libmach/libmach.h
@@ -26,11 +26,10 @@
 /* common functions */
 extern int pack(int order, unsigned char *dst, char *fmt, ...);
 extern int unpack(int order, unsigned char *src, char *fmt, ...);
-extern void objfree(Obj *obj);
+extern void objdel(Obj *obj);
 
 /* coff32 functions */
 /* TODO: Move this functions to a coff32 files */
-extern int coff32write(Obj *obj, FILE *fp);
 extern int coff32probe(unsigned char *buf, char **name);
 
 extern char *coff32namidx(void);