ref: e7b81f3f5b0030211190271574d1ade27dfab317
parent: 9f051be97f07bbb71ae4394a91f74ed5acbb007a
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed May 30 14:05:04 EDT 2018
[as/coff32] Prepare the code for unloading when a library member is loaded and it doesn't define any symbol then it must be unloaded since it is not needed.
--- a/ld/coff32.c
+++ b/ld/coff32.c
@@ -295,6 +295,10 @@
case 'U':
sym->type = type;
sym->value = getval(obj, &ent);
+ if (type != 'U') {
+ obj->define = 1;
+ sym->where = obj;
+ }
if (type == 'C')
sym->size = ent.n_value;
break;
@@ -306,6 +310,8 @@
sym->size = ent.n_value;
break;
default:
+ obj->define = 1;
+ sym->where = obj;
sym->type = type;
sym->value = getval(obj, &ent);
break;
@@ -327,7 +333,7 @@
}
static void
-readobj(Obj *obj)
+load(Obj *obj)
{
unsigned char buff[FILHSZ];
FILHDR *hdr;
@@ -362,9 +368,18 @@
}
static void
+unload(Obj *obj)
+{
+ /* TODO */
+}
+
+static void
pass1(Obj *obj)
{
- readobj(obj);
+ load(obj);
+ if (obj->member && !obj->define)
+ unload(obj);
+
}
static void
--- a/ld/ld.h
+++ b/ld/ld.h
@@ -20,6 +20,7 @@
int (*unpack)(unsigned char *, char *, ...);
int align;
+ int define;
struct obj *next;
};
@@ -31,6 +32,7 @@
long size;
TUINT base;
TUINT value;
+ Obj *where;
struct symbol *hash;
};
--- a/ld/obj.c
+++ b/ld/obj.c
@@ -26,6 +26,7 @@
s = malloc(len) + 1;
if (!obj || !s)
outmem();
+ memset(obj, 0, sizeof(*obj));
obj->fname = memcpy(s, fname, len);
if (!member) {