changeset 206:299c5d793aca

Made lwlink smarter about not included unneeded (unreferenced) members of a library file
author lost
date Mon, 20 Apr 2009 02:24:33 +0000
parents 42df94f30d82
children 0926c29426f4
files ChangeLog lwlink/expr.c lwlink/expr.h lwlink/link.c
diffstat 4 files changed, 30 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Apr 19 17:44:46 2009 +0000
+++ b/ChangeLog	Mon Apr 20 02:24:33 2009 +0000
@@ -26,6 +26,8 @@
 [+] allow exporting multiple symbols (export sym,sym,sym...)
 [+] allow extern references in base page addresing mode (LWASM)
 [+] handle 8 bit external references (LWLINK)
+[+] arranged for unused members of library files (archives) to be ignored
+    during linking to keep the final size of the binary down (LWLINK)
 [b] arranged for output files for lwasm/lwlink to be removed if the assembly
     or linking fails
 [ ] DECB output of LWLINK now collapses contiguous output blocks into single
--- a/lwlink/expr.c	Sun Apr 19 17:44:46 2009 +0000
+++ b/lwlink/expr.c	Mon Apr 20 02:24:33 2009 +0000
@@ -53,6 +53,19 @@
 	lw_free(s);
 }
 
+lw_expr_stack_t *lw_expr_stack_dup(lw_expr_stack_t *s)
+{
+	lw_expr_stack_node_t *t;
+	lw_expr_stack_t *s2;
+		
+	s2 = lw_expr_stack_create();	
+	for (t = s -> head; t; t = t -> next)
+	{
+		lw_expr_stack_push(s2, t -> term);
+	}
+	return s2;
+}
+
 void lw_expr_term_free(lw_expr_term_t *t)
 {
 	if (t)
--- a/lwlink/expr.h	Sun Apr 19 17:44:46 2009 +0000
+++ b/lwlink/expr.h	Mon Apr 20 02:24:33 2009 +0000
@@ -85,6 +85,7 @@
 
 __expr_E__ void lw_expr_stack_free(lw_expr_stack_t *s);
 __expr_E__ lw_expr_stack_t *lw_expr_stack_create(void);
+__expr_E__ lw_expr_stack_t *lw_expr_stack_dup(lw_expr_stack_t *s);
 
 __expr_E__ void lw_expr_stack_push(lw_expr_stack_t *s, lw_expr_term_t *t);
 __expr_E__ lw_expr_term_t *lw_expr_stack_pop(lw_expr_stack_t *s);
--- a/lwlink/link.c	Sun Apr 19 17:44:46 2009 +0000
+++ b/lwlink/link.c	Mon Apr 20 02:24:33 2009 +0000
@@ -402,6 +402,8 @@
 	int sn;
 	int fn;
 	reloc_t *rl;
+	lw_expr_stack_t *te;
+	
 	int rval;
 
 	// resolve entry point if required
@@ -432,14 +434,16 @@
 				for (rl = inputfiles[fn] -> sections[sn].incompletes; rl; rl = rl -> next)
 				{
 					// do a "simplify" on the expression
-					rval = lw_expr_reval(rl -> expr, resolve_sym, &(inputfiles[fn] -> sections[sn]));
-
+					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(rl -> expr))
+					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);
 				}
 			}
 		}
@@ -450,4 +454,11 @@
 		exit(1);
 	
 	// theoretically, all files referenced by other files now have "forced" set to 1
+	for (fn = 0; fn < ninputfiles; fn++)
+	{
+		if (inputfiles[fn] -> forced == 1)
+			continue;
+		
+		fprintf(stderr, "Warning: %s (%d) does not resolve any symbols\n", inputfiles[fn] -> filename, fn);
+	}
 }