commit dc8b78a3c50b7e18ac720e59302373ac08758943
parent f20644a9c4d448fbc39b1622f521e3f93442d061
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Fri, 23 Aug 2019 19:02:19 +0100
[libmach] Define Objseg type
This type is going to be used by several functions to handle
segments composed by sections.
Diffstat:
8 files changed, 26 insertions(+), 24 deletions(-)
diff --git 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 @@ enum sectype {
SSHARED = 1 << 7,
};
-struct objsect {
+struct objsec {
char *name;
int id;
int type;
@@ -25,13 +26,13 @@ struct objsect {
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,12 +45,18 @@ struct objsymdef {
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);
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 @@ struct obj {
char *index;
Objsym *htab[NR_SYMHASH];
Objsym *syms;
- Objsect *secs;
+ Objsec *secs;
long pos;
int nsecs;
int nsyms;
@@ -78,8 +85,3 @@ extern int objtype(FILE *fp, char **name);
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);
diff --git a/src/cmd/ld/pass1.c b/src/cmd/ld/pass1.c
@@ -150,7 +150,7 @@ addobj(Obj *obj, FILE *fp)
int n;
Objlst *lst;
Objsym *sym;
- Objsect *secp;
+ Objsec *secp;
if ((lst = malloc(sizeof(*lst))) == NULL) {
error("out of memory");
diff --git a/src/cmd/ld/pass2.c b/src/cmd/ld/pass2.c
@@ -10,7 +10,7 @@ static void
mksecs(void)
{
Objlst *lp;
- Objsect *sp;
+ Objsec *sp;
Section *sec;
for (lp = objhead; lp; lp = lp->next) {
diff --git a/src/cmd/ld/pass3.c b/src/cmd/ld/pass3.c
@@ -22,11 +22,11 @@ rebase(Obj *obj)
* 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 @@ pass3(int argc, char *argv[])
{
Obj *obj;
Objlst *lst;
- Objsect *sp;
+ Objsec *sp;
Segment *seg;
/*
diff --git a/src/cmd/ld/pass4.c b/src/cmd/ld/pass4.c
@@ -9,7 +9,7 @@ void
pass4(int argc, char *argv[])
{
Objlst *lp;
- Objsect *sp;
+ Objsec *sp;
Section *sec;
unsigned long i;
FILE *fp;
diff --git a/src/cmd/ld/pass5.c b/src/cmd/ld/pass5.c
@@ -35,7 +35,7 @@ pass5(int argc, char *argv[])
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);
diff --git a/src/cmd/size.c b/src/cmd/size.c
@@ -42,7 +42,7 @@ newobject(FILE *fp, int type)
int i;
Obj *obj;
unsigned long long total, *p;
- Objsect *sp;
+ Objsec *sp;
struct sizes siz;
if ((obj = objnew(type)) == NULL) {
diff --git a/src/libmach/coff32/coff32read.c b/src/libmach/coff32/coff32read.c
@@ -365,7 +365,7 @@ readfile(Obj *obj, FILE *fp)
}
static int
-convsect(Obj *obj)
+convsecs(Obj *obj)
{
int i;
unsigned sflags, type;
@@ -373,12 +373,12 @@ convsect(Obj *obj)
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 @@ convsyms(Obj *obj)
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 @@ coff32read(Obj *obj, FILE *fp)
{
if (readfile(obj, fp) < 0)
return -1;
- if (convsect(obj) < 0)
+ if (convsecs(obj) < 0)
return -1;
if (convsyms(obj) < 0)
return -1;