diff lwlink/script.c @ 234:d389adbcc4ab

Added section base and length symbols to lwlink Added the ability for a link script to define section base and section length symbols when linking. These symbols are searched for when an external reference is resolved before looking up any symbols in the various objects being linked. Also documented the new link script directives and added such directives to all default link scripts.
author William Astle <lost@l-w.ca>
date Fri, 10 Aug 2012 23:47:56 -0600
parents c6a38fd8bd33
children ce1fdc8d6568
line wrap: on
line diff
--- a/lwlink/script.c	Thu Jul 19 13:17:30 2012 -0600
+++ b/lwlink/script.c	Fri Aug 10 23:47:56 2012 -0600
@@ -35,6 +35,8 @@
 // the built-in OS9 script
 // the 000D bit is to handle the module header!
 static char *os9_script =
+	"define basesympat s_%s\n"
+	"define lensympat l_%s\n"
 	"section code load 000D\n"
 	"section .text\n"
 	"section data\n"
@@ -46,6 +48,8 @@
 
 // the built-in DECB target linker script
 static char *decb_script =
+	"define basesympat s_%s\n"
+	"define lensympat l_%s\n"
 	"section init load 2000\n"
 	"section code\n"
 	"section *,!bss\n"
@@ -55,6 +59,8 @@
 
 // the built-in RAW target linker script
 static char *raw_script = 
+	"define basesympat s_%s\n"
+	"define lensympat l_%s\n"
 	"section init load 0000\n"
 	"section code\n"
 	"section *,!bss\n"
@@ -62,6 +68,8 @@
 	;
 
 static char *lwex0_script =
+	"define basesympat s_%s\n"
+	"define lensympat l_%s\n"
 	"section init load 0100\n"
 	"section .text\n"
 	"section .data\n"
@@ -79,6 +87,8 @@
 
 // the "simple" script
 static char *simple_script = 
+	"define basesympat s_%s\n"
+	"define lensympat l_%s\n"
 	"section *,!bss\n"
 	"section *,bss\n"
 	;
@@ -216,7 +226,38 @@
 		for ( ; *ptr && isspace(*ptr); ptr++)
 			/* do nothing */ ;
 		
-		if (!strcmp(line, "pad"))
+		if (!strcmp(line, "define"))
+		{
+			// parse out the definition type
+			for (ptr2 = ptr; *ptr2 && !isspace(*ptr2); ptr2++)
+				/* do nothing */ ;
+			
+			if (*ptr2)
+				*ptr2++ = '\0';
+			
+			while (*ptr2 && isspace(*ptr2))
+				ptr2++;
+			
+			// now ptr points to the define type
+			if (!strcmp(ptr, "basesympat"))
+			{
+				/* section base symbol pattern */
+				lw_free(linkscript.basesympat);
+				linkscript.basesympat = lw_strdup(ptr2);
+			}
+			else if (!strcmp(ptr, "lensympat"))
+			{
+				/* section length symbol pattern */
+				lw_free(linkscript.lensympat);
+				linkscript.lensympat = lw_strdup(ptr2);
+			}
+			else
+			{
+				fprintf(stderr, "%s: bad script line: %s\n", scriptfile, line);
+				exit(1);
+			}
+		}
+		else if (!strcmp(line, "pad"))
 		{
 			// padding
 			// parse the hex number and stow it