shithub: scc

Download patch

ref: 5b919477354727041f8a522f0f91273e623fa58d
parent: e34837b2825e060fb31c87ad739214590e3b4354
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Aug 23 15:02:19 EDT 2019

[libmach] Define Objseg type

This type is going to be used by several functions to handle
segments composed by sections.

--- a/include/scc/scc/mach.h
+++ b/include/scc/scc/mach.h
@@ -1,8 +1,9 @@
 #define NR_SYMHASH 32
 
-typedef struct objsect Objsect;
-typedef struct objsym Objsym;
 typedef struct objsymdef Objsymdef;
+typedef struct objsec Objsec;
+typedef struct objsym Objsym;
+typedef struct objseg Objseg;
 typedef struct objops Objops;
 typedef struct obj Obj;
 
@@ -17,7 +18,7 @@
 	SSHARED = 1 << 7,
 };
 
-struct objsect {
+struct objsec {
 	char *name;
 	int id;
 	int type;
@@ -25,13 +26,13 @@
 	unsigned flags;
 	long seek;
 	unsigned long long size, base;
-	Objsect *next;
+	Objsec *next;
 };
 
 struct objsym {
 	char *name;
 	int type;
-	int sect;
+	int sec;
 	unsigned long long size;
 	unsigned long long value;
 	Objsym *next, *hash;
@@ -44,6 +45,11 @@
 	Objsymdef *hash, *next;
 };
 
+struct objseg {
+	unsigned long long size;
+	unsigned long long value;
+};
+
 struct objops {
 	int (*probe)(unsigned char *buf, char **name);
 	int (*new)(Obj *obj);
@@ -50,6 +56,7 @@
 	void (*del)(Obj *obj);
 	int (*read)(Obj *obj, FILE *fp);
 	int (*write)(Obj *obj, FILE *fp);
+	int (*addseg)(Obj *obj, void *seg);
 	int (*strip)(Obj *obj);
 	int (*addr2line)(Obj *, unsigned long long , char *, int *);
 	int (*setidx)(long nsyms, Objsymdef *def, FILE *fp);
@@ -62,7 +69,7 @@
 	char *index;
 	Objsym *htab[NR_SYMHASH];
 	Objsym *syms;
-	Objsect *secs;
+	Objsec *secs;
 	long pos;
 	int nsecs;
 	int nsyms;
@@ -78,8 +85,3 @@
 extern Obj *objnew(int type);
 extern Objsym *objlookup(Obj *obj, char *name, int install);
 extern int objpos(Obj *obj, FILE *fp, long pos);
-
-
-/* TODO */
-extern int objaddseg(Obj *obj, void *seg);
-extern int objreloc(Obj *obj, char *sect, void *rel);
--- a/src/cmd/ld/pass1.c
+++ b/src/cmd/ld/pass1.c
@@ -150,7 +150,7 @@
 	int n;
 	Objlst *lst;
 	Objsym *sym;
-	Objsect *secp;
+	Objsec *secp;
 
 	if ((lst = malloc(sizeof(*lst))) == NULL) {
 		error("out of memory");
--- a/src/cmd/ld/pass2.c
+++ b/src/cmd/ld/pass2.c
@@ -10,7 +10,7 @@
 mksecs(void)
 {
 	Objlst *lp;
-	Objsect *sp;
+	Objsec *sp;
 	Section *sec;
 
 	for (lp = objhead; lp; lp = lp->next) {
--- a/src/cmd/ld/pass3.c
+++ b/src/cmd/ld/pass3.c
@@ -22,11 +22,11 @@
 			 * we have an error in our code.
 			 */
 			aux = lookup(sym->name);
-			aux->value += obj->secs[sym->sect].base;
+			aux->value += obj->secs[sym->sec].base;
 		case 't':
 		case 'd':
 		case 'b':
-			sym->value += obj->secs[sym->sect].base;
+			sym->value += obj->secs[sym->sec].base;
 		case 'U':
 		case 'N':
 		case '?':
@@ -45,7 +45,7 @@
 {
 	Obj *obj;
 	Objlst *lst;
-	Objsect *sp;
+	Objsec *sp;
 	Segment *seg;
 
 	/*
--- a/src/cmd/ld/pass4.c
+++ b/src/cmd/ld/pass4.c
@@ -9,7 +9,7 @@
 pass4(int argc, char *argv[])
 {
 	Objlst *lp;
-	Objsect *sp;
+	Objsec *sp;
 	Section *sec;
 	unsigned long i;
 	FILE *fp;
--- a/src/cmd/ld/pass5.c
+++ b/src/cmd/ld/pass5.c
@@ -35,7 +35,7 @@
 	obj = objnew(bintype);
 
 	for (segp = segv; *segp; segp++)
-		objaddseg(obj, *segp);
+		/* objaddseg(obj, *segp) */ ;
 
 	for (sym = defhead.next; sym != &defhead; sym = sym->next) {
 		osym = objlookup(obj, sym->name, 1);
--- a/src/cmd/size.c
+++ b/src/cmd/size.c
@@ -42,7 +42,7 @@
 	int i;
 	Obj *obj;
 	unsigned long long total, *p;
-	Objsect *sp;
+	Objsec *sp;
 	struct sizes siz;
 
 	if ((obj = objnew(type)) == NULL) {
--- a/src/libmach/coff32/coff32read.c
+++ b/src/libmach/coff32/coff32read.c
@@ -365,7 +365,7 @@
 }
 
 static int
-convsect(Obj *obj)
+convsecs(Obj *obj)
 {
 	int i;
 	unsigned sflags, type;
@@ -373,12 +373,12 @@
 	FILHDR *hdr;
 	struct coff32 *coff;
 	SCNHDR *scn;
-	Objsect *secs, *sp;
+	Objsec *secs, *sp;
 
 	coff  = obj->data;
 	hdr = &coff->hdr;
 
-	secs = malloc(sizeof(Objsect) * hdr->f_nscns);
+	secs = malloc(sizeof(Objsec) * hdr->f_nscns);
 	if (!secs)
 		return -1;
 
@@ -513,7 +513,7 @@
 		sym->type = t;
 		sym->value = ent->n_value;
 		sym->size = (sym->type == 'C') ? ent->n_value : 0;
-		sym->sect = ent->n_scnum-1;
+		sym->sec = ent->n_scnum-1;
 	}
 
 	return i;
@@ -524,7 +524,7 @@
 {
 	if (readfile(obj, fp) < 0)
 		return -1;
-	if (convsect(obj) < 0)
+	if (convsecs(obj) < 0)
 		return -1;
 	if (convsyms(obj) < 0)
 		return -1;