ref: 8109417716fb89a5feb0f9029f13cc2c0613c94f
parent: 9e604423d747253990c6b62da8769a9ebbba29a2
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Aug 10 09:35:49 EDT 2019
[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.
--- a/src/cmd/ld/ld.h
+++ b/src/cmd/ld/ld.h
@@ -55,4 +55,4 @@
extern int dflag;
extern int gflag;
extern char *Dflag;
-extern Objlst *objhead, *objlast;
+extern Objlst *objhead;
--- a/src/cmd/ld/pass1.c
+++ b/src/cmd/ld/pass1.c
@@ -20,8 +20,9 @@
.next = &refhead,
.prev = &refhead,
};
+static Objlst *objlast;
-Objlst *objhead, *objlast;
+Objlst *objhead;
static Symbol *
define(Objsym *osym, Obj *obj)
@@ -81,7 +82,7 @@
}
static int
-defasym(Obj *obj)
+is_needed(Obj *obj)
{
Symbol *sym, *p;
@@ -179,17 +180,11 @@
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);