comparison 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
comparison
equal deleted inserted replaced
233:7887a48b74df 234:d389adbcc4ab
33 #include "lwlink.h" 33 #include "lwlink.h"
34 34
35 // the built-in OS9 script 35 // the built-in OS9 script
36 // the 000D bit is to handle the module header! 36 // the 000D bit is to handle the module header!
37 static char *os9_script = 37 static char *os9_script =
38 "define basesympat s_%s\n"
39 "define lensympat l_%s\n"
38 "section code load 000D\n" 40 "section code load 000D\n"
39 "section .text\n" 41 "section .text\n"
40 "section data\n" 42 "section data\n"
41 "section .data\n" 43 "section .data\n"
42 "section bss,bss load 0000\n" 44 "section bss,bss load 0000\n"
44 "entry __start\n" 46 "entry __start\n"
45 ; 47 ;
46 48
47 // the built-in DECB target linker script 49 // the built-in DECB target linker script
48 static char *decb_script = 50 static char *decb_script =
51 "define basesympat s_%s\n"
52 "define lensympat l_%s\n"
49 "section init load 2000\n" 53 "section init load 2000\n"
50 "section code\n" 54 "section code\n"
51 "section *,!bss\n" 55 "section *,!bss\n"
52 "section *,bss\n" 56 "section *,bss\n"
53 "entry 2000\n" 57 "entry 2000\n"
54 ; 58 ;
55 59
56 // the built-in RAW target linker script 60 // the built-in RAW target linker script
57 static char *raw_script = 61 static char *raw_script =
62 "define basesympat s_%s\n"
63 "define lensympat l_%s\n"
58 "section init load 0000\n" 64 "section init load 0000\n"
59 "section code\n" 65 "section code\n"
60 "section *,!bss\n" 66 "section *,!bss\n"
61 "section *,bss\n" 67 "section *,bss\n"
62 ; 68 ;
63 69
64 static char *lwex0_script = 70 static char *lwex0_script =
71 "define basesympat s_%s\n"
72 "define lensympat l_%s\n"
65 "section init load 0100\n" 73 "section init load 0100\n"
66 "section .text\n" 74 "section .text\n"
67 "section .data\n" 75 "section .data\n"
68 "section .ctors_start\n" 76 "section .ctors_start\n"
69 "section .ctors\n" 77 "section .ctors\n"
77 "stacksize 0100\n" // default 256 byte stack 85 "stacksize 0100\n" // default 256 byte stack
78 ; 86 ;
79 87
80 // the "simple" script 88 // the "simple" script
81 static char *simple_script = 89 static char *simple_script =
90 "define basesympat s_%s\n"
91 "define lensympat l_%s\n"
82 "section *,!bss\n" 92 "section *,!bss\n"
83 "section *,bss\n" 93 "section *,bss\n"
84 ; 94 ;
85 95
86 linkscript_t linkscript = { 0, NULL, -1 }; 96 linkscript_t linkscript = { 0, NULL, -1 };
214 224
215 // skip spaces after the first word 225 // skip spaces after the first word
216 for ( ; *ptr && isspace(*ptr); ptr++) 226 for ( ; *ptr && isspace(*ptr); ptr++)
217 /* do nothing */ ; 227 /* do nothing */ ;
218 228
219 if (!strcmp(line, "pad")) 229 if (!strcmp(line, "define"))
230 {
231 // parse out the definition type
232 for (ptr2 = ptr; *ptr2 && !isspace(*ptr2); ptr2++)
233 /* do nothing */ ;
234
235 if (*ptr2)
236 *ptr2++ = '\0';
237
238 while (*ptr2 && isspace(*ptr2))
239 ptr2++;
240
241 // now ptr points to the define type
242 if (!strcmp(ptr, "basesympat"))
243 {
244 /* section base symbol pattern */
245 lw_free(linkscript.basesympat);
246 linkscript.basesympat = lw_strdup(ptr2);
247 }
248 else if (!strcmp(ptr, "lensympat"))
249 {
250 /* section length symbol pattern */
251 lw_free(linkscript.lensympat);
252 linkscript.lensympat = lw_strdup(ptr2);
253 }
254 else
255 {
256 fprintf(stderr, "%s: bad script line: %s\n", scriptfile, line);
257 exit(1);
258 }
259 }
260 else if (!strcmp(line, "pad"))
220 { 261 {
221 // padding 262 // padding
222 // parse the hex number and stow it 263 // parse the hex number and stow it
223 linkscript.padsize = strtol(ptr, NULL, 16); 264 linkscript.padsize = strtol(ptr, NULL, 16);
224 if (linkscript.padsize < 0) 265 if (linkscript.padsize < 0)