changeset 245:eb499c146c0d 2.x

Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
author lost
date Thu, 19 Nov 2009 00:51:31 +0000
parents c8bcc396ec59
children c602f6eca3ed
files ChangeLog lwlink/link.c
diffstat 2 files changed, 39 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Sep 16 00:29:06 2009 +0000
+++ b/ChangeLog	Thu Nov 19 00:51:31 2009 +0000
@@ -13,6 +13,8 @@
 
 Version 2.6
 
+[!] Fixed symbol resolution so all externally referenced objects, including
+    within library archives, are properly included [LWLINK]
 [+] Added "EXTDEP" pseudo op to force a dependency on an external symbol
     without an actual external reference - a zero-width external reference
     so to speak [LWASM,LWLINK]
--- a/lwlink/link.c	Wed Sep 16 00:29:06 2009 +0000
+++ b/lwlink/link.c	Thu Nov 19 00:51:31 2009 +0000
@@ -213,6 +213,7 @@
 			{
 				if (!(fn -> forced))
 				{
+//					fprintf(stderr, "Forced inclusion of %s due to symbol reference\n", fn -> filename);
 					fn -> forced = 1;
 					nforced = 1;
 				}
@@ -398,12 +399,46 @@
 /*
 This is just a pared down version of the algo for resolving references.
 */
+void resolve_files_aux(fileinfo_t *fn)
+{
+	int n;
+	int sn;
+	int rval;
+	lw_expr_stack_t *te;
+	reloc_t *rl;
+	
+	if (fn -> forced != 0)
+	{
+		for (sn = 0; sn < fn -> nsections; sn++)
+		{
+			for (rl = fn -> sections[sn].incompletes; rl; rl = rl -> next)
+			{
+				// do a "simplify" on the expression
+				te = lw_expr_stack_dup(rl -> expr);
+				rval = lw_expr_reval(te, resolve_sym, &(fn -> sections[sn]));
+			
+				// is it constant? error out if not
+				if (rval != 0 || !lw_expr_is_constant(te))
+				{
+					fprintf(stderr, "Incomplete reference at %s:%s+%02X\n", fn -> filename, fn -> sections[sn].name, rl -> offset);
+					symerr = 1;
+				}
+				lw_expr_stack_free(te);
+			}
+		}
+	}
+	// handle sub files
+	for (n = 0; n < fn -> nsubs; n++)
+		resolve_files_aux(fn -> subs[n]);
+}
+
 void resolve_files(void)
 {
 	int sn;
 	int fn;
 	reloc_t *rl;
 	lw_expr_stack_t *te;
+	int c = 0;
 	
 	int rval;
 
@@ -430,24 +465,9 @@
 			if (inputfiles[fn] -> forced == 0)
 				continue;
 	
-			for (sn = 0; sn < inputfiles[fn] -> nsections; sn++)
-			{
-				for (rl = inputfiles[fn] -> sections[sn].incompletes; rl; rl = rl -> next)
-				{
-					// do a "simplify" on the expression
-					te = lw_expr_stack_dup(rl -> expr);
-					rval = lw_expr_reval(te, resolve_sym, &(inputfiles[fn] -> sections[sn]));
-					
-					// is it constant? error out if not
-					if (rval != 0 || !lw_expr_is_constant(te))
-					{
-						fprintf(stderr, "Incomplete reference at %s:%s+%02X\n", inputfiles[fn] -> filename, inputfiles[fn] -> sections[sn].name, rl -> offset);
-						symerr = 1;
-					}
-					lw_expr_stack_free(te);
-				}
-			}
+			resolve_files_aux(inputfiles[fn]);
 		}
+//		fprintf(stderr, "File resolution pass %d, nforced = %d\n", ++c, nforced);
 	}
 	while (nforced == 1);