commit c58d9b48426a885653291bf259205d7b9d1893e6
parent aed49c6c0f2119764a1f905d01929cb294e0d228
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Wed, 30 May 2018 18:05:04 +0100
[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.
Diffstat:
3 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/ld/coff32.c b/ld/coff32.c
@@ -295,6 +295,10 @@ readsyms(Obj *obj, long off)
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 @@ readsyms(Obj *obj, long off)
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 @@ readsyms(Obj *obj, long off)
}
static void
-readobj(Obj *obj)
+load(Obj *obj)
{
unsigned char buff[FILHSZ];
FILHDR *hdr;
@@ -362,9 +368,18 @@ bad_file:
}
static void
+unload(Obj *obj)
+{
+ /* TODO */
+}
+
+static void
pass1(Obj *obj)
{
- readobj(obj);
+ load(obj);
+ if (obj->member && !obj->define)
+ unload(obj);
+
}
static void
diff --git a/ld/ld.h b/ld/ld.h
@@ -20,6 +20,7 @@ struct obj {
int (*unpack)(unsigned char *, char *, ...);
int align;
+ int define;
struct obj *next;
};
@@ -31,6 +32,7 @@ struct symbol {
long size;
TUINT base;
TUINT value;
+ Obj *where;
struct symbol *hash;
};
diff --git a/ld/obj.c b/ld/obj.c
@@ -26,6 +26,7 @@ newobj(char *fname, char *member)
s = malloc(len) + 1;
if (!obj || !s)
outmem();
+ memset(obj, 0, sizeof(*obj));
obj->fname = memcpy(s, fname, len);
if (!member) {