changeset 393:c94436adce83

Actually include local symbols in object files
author lost@l-w.ca
date Thu, 22 Jul 2010 23:11:04 -0600
parents e3567a9f0d54
children a2f52e97b454
files lwasm/output.c
diffstat 1 files changed, 24 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/output.c	Wed Jul 21 22:21:35 2010 -0600
+++ b/lwasm/output.c	Thu Jul 22 23:11:04 2010 -0600
@@ -436,16 +436,36 @@
 		writebytes("\0", 2, 1, of);
 		for (se = as -> symtab.head; se; se = se -> next)
 		{
+			lw_expr_t te;
+			
+			debug_message(as, 200, "Consider symbol %s (%p) for export in section %p", se -> symbol, se -> section, s);
+			
 			// ignore symbols not in this section
 			if (se -> section != s)
 				continue;
 			
+			debug_message(as, 200, "  In section");
+			
 			if (se -> flags & symbol_flag_set)
 				continue;
 			
+			debug_message(as, 200, "  Not symbol_flag_set");
+			
+			te = lw_expr_copy(se -> value);
+			debug_message(as, 200, "  Value=%s", lw_expr_print(te));
+			as -> exportcheck = 1;
+			as -> csect = s;
+			lwasm_reduce_expr(as, te);
+			as -> exportcheck = 0;
+
+			debug_message(as, 200, "  Value2=%s", lw_expr_print(te));
+			
 			// don't output non-constant symbols
-			if (!lw_expr_istype(se -> value, lw_expr_type_int))
+			if (!lw_expr_istype(te, lw_expr_type_int))
+			{
+				lw_expr_destroy(te);
 				continue;
+			}
 
 			writebytes(se -> symbol, strlen(se -> symbol), 1, of);
 			if (se -> context >= 0)
@@ -458,9 +478,10 @@
 			writebytes("", 1, 1, of);
 			
 			// write the address
-			buf[0] = (lw_expr_intval(se -> value) >> 8) & 0xff;
-			buf[1] = lw_expr_intval(se -> value) & 0xff;
+			buf[0] = (lw_expr_intval(te) >> 8) & 0xff;
+			buf[1] = lw_expr_intval(te) & 0xff;
 			writebytes(buf, 2, 1, of);
+			lw_expr_destroy(te);
 		}	
 		// flag end of local symbol table - "" is NOT an error
 		writebytes("", 1, 1, of);