scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit bae24ac8e257fb16a2500a3edc4b4f50808cdc65
parent 18542295c55bbb5378505b1d2790ba96f4a11188
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 10 Feb 2019 11:37:24 +0000

[libmach] Add a parameter to objlookup()

It is useful if you only want to  check if a set of
symbols are defined.

Diffstat:
Minclude/scc/scc/mach.h | 2+-
Msrc/cmd/ld/main.c | 2+-
Msrc/libmach/coff32/coff32read.c | 2+-
Msrc/libmach/objlookup.c | 4+++-
4 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/include/scc/scc/mach.h b/include/scc/scc/mach.h @@ -74,7 +74,7 @@ extern Obj *objnew(int type); extern int objdel(Obj *obj); extern int objreset(Obj *obj); extern int objread(Obj *obj, FILE *fp); -extern Objsym *objlookup(Obj *obj, char *name); +extern Objsym *objlookup(Obj *obj, char *name, int install); extern int objstrip(Obj *obj); extern long arindex(int type, long nsyms, Objsymdef *def, FILE *fp); extern int objwrite(Obj *obj, FILE *fp); diff --git a/src/cmd/ld/main.c b/src/cmd/ld/main.c @@ -197,7 +197,7 @@ newobject(FILE *fp, int type, int inlib) if (inlib) { for (sym = refhead.next; sym != &refhead; sym = sym->next) { - if (objlookup(obj, sym->name)) + if (objlookup(obj, sym->name, 0)) break; } if (sym == &refhead) diff --git a/src/libmach/coff32/coff32read.c b/src/libmach/coff32/coff32read.c @@ -386,7 +386,7 @@ loadsyms(Obj *obj) if ((s = symname(coff, ent)) == NULL) return 0; - if ((sym = objlookup(obj, s)) == NULL) + if ((sym = objlookup(obj, s, 1)) == NULL) return 0; sym->type = t; diff --git a/src/libmach/objlookup.c b/src/libmach/objlookup.c @@ -5,7 +5,7 @@ #include <scc/mach.h> Objsym * -objlookup(Obj *obj, char *name) +objlookup(Obj *obj, char *name, int install) { unsigned h; size_t len; @@ -21,6 +21,8 @@ objlookup(Obj *obj, char *name) if (!strcmp(name, sym->name)) return sym; } + if (!install) + return NULL; if ((sym = malloc(sizeof(*sym))) == NULL) return NULL;