scc

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

commit aa246eb1d1ffd3f5ce9b6fc297bf01789f0b79c8
parent 2b8586296aa24f827684ab8e79a271530e56c323
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 10 Aug 2019 13:35:49 +0100

[ld] Simplify newobject() in pass1

This function had some statements that were too complex
and they needed a comment to specify the condition requested
to include an object in the final link list. This rewrite
modifies the code in a way that the comment is not needed
anymore.

Diffstat:
Msrc/cmd/ld/ld.h | 2+-
Msrc/cmd/ld/pass1.c | 21++++++++-------------
2 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/src/cmd/ld/ld.h b/src/cmd/ld/ld.h @@ -55,4 +55,4 @@ extern int rflag; extern int dflag; extern int gflag; extern char *Dflag; -extern Objlst *objhead, *objlast; +extern Objlst *objhead; diff --git a/src/cmd/ld/pass1.c b/src/cmd/ld/pass1.c @@ -20,8 +20,9 @@ static Symbol refhead = { .next = &refhead, .prev = &refhead, }; +static Objlst *objlast; -Objlst *objhead, *objlast; +Objlst *objhead; static Symbol * define(Objsym *osym, Obj *obj) @@ -81,7 +82,7 @@ listundef(void) } static int -defasym(Obj *obj) +is_needed(Obj *obj) { Symbol *sym, *p; @@ -179,17 +180,11 @@ newobject(FILE *fp, int type, int inlib) goto delete; } - /* - * we add the object to the list of objects - * if we are in an object file. If we are in - * a library (without index) then we check - * if the object defines some symbol in the - * undefined list. - */ - if (!inlib || defasym(obj)) { - addobj(obj, fp); - return; - } + if (inlib && !is_needed(obj)) + goto delete; + + addobj(obj, fp); + return; delete: objdel(obj);