ref: f2f8265148da2575342a68a2b55e3bade3551e33
parent: e2bebadc98949a25c7d987a9d2c8e69a71dd9397
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sun Feb 10 00:59:53 EST 2019
[libmach] Use Obj prefix for public types
--- a/include/scc/scc/mach.h
+++ b/include/scc/scc/mach.h
@@ -1,8 +1,8 @@
#define NR_SYMHASH 32
-typedef struct section Section;
-typedef struct symbol Symbol;
-typedef struct symdef Symdef;
+typedef struct objsect Objsect;
+typedef struct objsym Objsym;
+typedef struct objsymdef Objsymdef;
typedef struct object Obj;
enum sectype {
@@ -16,7 +16,7 @@
SSHARED = 1 << 7,
};
-struct section {
+struct objsect {
char *name;
int type;
unsigned flags;
@@ -25,55 +25,57 @@
unsigned long long size;
};
-struct symbol {
+struct objsym {
char type;
char *name;
unsigned long long size;
unsigned long long value;
- Symbol *next;
- Symbol *hash;
+ Objsym *next, *hash;
};
-struct symdef {
+struct objsymdef {
char *name;
int type;
long offset;
- Symdef *hash, *next;
+ Objsymdef *hash, *next;
};
struct object {
int type;
- Symbol *htab[NR_SYMHASH];
- Symbol *head;
+ Objsym *htab[NR_SYMHASH];
+ Objsym *head;
fpos_t pos;
int nsecs;
- Section *sections;
+ Objsect *sections;
void *data;
};
-extern int archive(FILE *fp);
-extern long armember(FILE *fp, char *member);
extern int artraverse(FILE *fp,
int (*fn)(FILE *, char *, void *),
void *data);
+extern int objtraverse(Obj *obj,
+ int (*fn)(Objsym *sym, void *data),
+ void *data);
+
+extern int archive(FILE *fp);
+extern long armember(FILE *fp, char *member);
extern int objtype(FILE *fp, char **name);
extern Obj *objnew(int type);
extern int objdel(Obj *obj);
extern int objreset(Obj *obj);
extern int objread(Obj *obj, FILE *fp);
-extern Symbol *objlookup(Obj *obj, char *name);
-extern int objtraverse(Obj *obj, int (*fn)(Symbol *sym, void *data), void *data);
+extern Objsym *objlookup(Obj *obj, char *name);
extern int objstrip(Obj *obj);
extern int objsize(Obj *obj,
unsigned long long *text,
unsigned long long *data,
unsigned long long *bss);
-extern long arindex(int type, long nsyms, Symdef *def, FILE *fp);
+extern long arindex(int type, long nsyms, Objsymdef *def, FILE *fp);
+extern int objwrite(Obj *obj, FILE *fp);
/* TODO */
extern int objload(Obj *obj, Obj *to);
extern int objreloc(Obj *obj, char *sect, void *rel);
-extern int objwrite(Obj *obj, FILE *fp);
extern int addr2line(Obj *obj, unsigned long long addr, char *fname, int *line);
--- a/src/cmd/nm.c
+++ b/src/cmd/nm.c
@@ -13,7 +13,7 @@
struct symtbl {
- Symbol **buf;
+ Objsym **buf;
size_t nsyms;
};
@@ -46,8 +46,8 @@
static int
cmp(const void *p1, const void *p2)
{
- Symbol **s1 = (Symbol **) p1, **s2 = (Symbol **) p2;
- Symbol *sym1 = *s1, *sym2 = *s2;
+ Objsym **s1 = (Objsym **) p1, **s2 = (Objsym **) p2;
+ Objsym *sym1 = *s1, *sym2 = *s2;
if (vflag) {
if (sym1->value > sym2->value)
@@ -67,7 +67,7 @@
}
static void
-printsyms(Symbol **syms, size_t nsym)
+printsyms(Objsym **syms, size_t nsym)
{
size_t i;
@@ -77,7 +77,7 @@
printf("%s:\n", (membname) ? membname : filename);
for (i = 0; i < nsym; i++) {
- Symbol *sym = syms[i];
+ Objsym *sym = syms[i];
int type = sym->type;
char *fmt;
@@ -114,10 +114,10 @@
}
static int
-newsym(Symbol *sym, void *data)
+newsym(Objsym *sym, void *data)
{
struct symtbl *tbl = data;
- Symbol **p;
+ Objsym **p;
size_t n, size;
int type = sym->type;
--- a/src/cmd/ranlib.c
+++ b/src/cmd/ranlib.c
@@ -18,7 +18,7 @@
static long nsymbols;
static int status, artype, nolib;
static char *filename, *membname;
-static Symdef *htab[NR_SYMDEF], *head;
+static Objsymdef *htab[NR_SYMDEF], *head;
static long offset;
char *argv0;
@@ -44,11 +44,11 @@
status = EXIT_FAILURE;
}
-Symdef *
+Objsymdef *
lookup(char *name)
{
unsigned h;
- Symdef *dp;
+ Objsymdef *dp;
char *s;
size_t len;
@@ -85,9 +85,9 @@
}
static int
-newsymbol(Symbol *sym, void *data)
+newsymbol(Objsym *sym, void *data)
{
- Symdef *np;
+ Objsymdef *np;
if (!isupper(sym->type) || sym->type == 'N')
return 1;
@@ -165,7 +165,7 @@
static void
freehash(void)
{
- Symdef **npp, *next, *np;
+ Objsymdef **npp, *next, *np;
for (npp = htab; npp < &htab[NR_SYMDEF]; npp++)
*npp = NULL;
--- a/src/libmach/arindex.c
+++ b/src/libmach/arindex.c
@@ -7,7 +7,7 @@
extern indexfun_t indexv[];
long
-arindex(int type, long nsyms, Symdef *head, FILE *fp)
+arindex(int type, long nsyms, Objsymdef *head, FILE *fp)
{
int fmt;
indexfun_t fn;
--- a/src/libmach/coff32/coff32index.c
+++ b/src/libmach/coff32/coff32index.c
@@ -6,7 +6,7 @@
#include "coff32.h"
long
-coff32index(int type, long nsymbols, Symdef *head, FILE *fp)
+coff32index(int type, long nsymbols, Objsymdef *head, FILE *fp)
{
return coff32idx(BIG_ENDIAN, nsymbols, head, fp);
}
--- a/src/libmach/coff32/coff32read.c
+++ b/src/libmach/coff32/coff32read.c
@@ -144,13 +144,13 @@
FILHDR *hdr;
struct coff32 *coff;
SCNHDR *scn;
- Section *secs, *sp;
+ Objsect *secs, *sp;
coff = obj->data;
hdr = &coff->hdr;
scn = coff->scns;
- secs = malloc(sizeof(Section) * hdr->f_nscns);
+ secs = malloc(sizeof(Objsect) * hdr->f_nscns);
if (!secs)
return 0;
obj->sections = secs;
@@ -373,7 +373,7 @@
int t;
long i;
char *s;
- Symbol *sym;
+ Objsym *sym;
SYMENT *ent;
Coff32 *coff = obj->data;
--- a/src/libmach/coffelf32.c
+++ b/src/libmach/coffelf32.c
@@ -6,11 +6,11 @@
#include "libmach.h"
long
-coff32idx(int order, long nsyms, Symdef *head, FILE *fp)
+coff32idx(int order, long nsyms, Objsymdef *head, FILE *fp)
{
long i, n;
size_t len;
- Symdef *def;
+ Objsymdef *def;
unsigned char buff[4];
pack(order, buff, "l", nsyms);
--- a/src/libmach/libmach.h
+++ b/src/libmach/libmach.h
@@ -28,7 +28,7 @@
FREESECT,
};
-typedef long (*indexfun_t)(int, long, Symdef *, FILE *);
+typedef long (*indexfun_t)(int, long, Objsymdef *, FILE *);
typedef int (*newfun_t)(Obj *obj);
typedef int (*readfun_t)(Obj *obj, FILE *fp);
typedef void (*delfun_t)(Obj *new);
@@ -43,11 +43,11 @@
extern void objfree(Obj *obj, int what);
/* idx functions */
-extern long coff32idx(int order, long nsyms, Symdef *def, FILE *fp);
+extern long coff32idx(int order, long nsyms, Objsymdef *def, FILE *fp);
/* coff32 functions */
-extern long coff32index(int type, long nsyms, Symdef *head, FILE *fp);
+extern long coff32index(int type, long nsyms, Objsymdef *head, FILE *fp);
extern int coff32new(Obj *obj);
extern void coff32del(Obj *obj);
extern int coff32read(Obj *obj, FILE *fp);
--- a/src/libmach/objfree.c
+++ b/src/libmach/objfree.c
@@ -9,7 +9,7 @@
static void
delsyms(Obj *obj)
{
- Symbol *sym, *next;
+ Objsym *sym, *next;
for (sym = obj->head; sym; sym = next) {
next = sym->next;
--- a/src/libmach/objlookup.c
+++ b/src/libmach/objlookup.c
@@ -4,13 +4,13 @@
#include <scc/mach.h>
-Symbol *
+Objsym *
objlookup(Obj *obj, char *name)
{
unsigned h;
size_t len;
char *s;
- Symbol *sym;
+ Objsym *sym;
h = 0;
for (s = name; *s; s++)
--- a/src/libmach/objsize.c
+++ b/src/libmach/objsize.c
@@ -11,7 +11,7 @@
unsigned long long *data,
unsigned long long *bss)
{
- Section *sp, *secs = obj->sections;
+ Objsect *sp, *secs = obj->sections;
unsigned long long *p;
*text = 0;
--- a/src/libmach/objtraverse.c
+++ b/src/libmach/objtraverse.c
@@ -5,9 +5,9 @@
#include "libmach.h"
int
-objtraverse(Obj *obj, int (*fn)(Symbol *, void *), void *data)
+objtraverse(Obj *obj, int (*fn)(Objsym *, void *), void *data)
{
- Symbol *sym;
+ Objsym *sym;
for (sym = obj->head; sym; sym = sym->next) {
if (!(*fn)(sym, data))