annotate lwlink/script.c @ 258:ebda5c96665e

Improved stack handling for os9 target in lwlink Added "stack" as a valid symbol in the __os9 section. All instances of __os9 are now polled for "stack" symobls and the values added to the stack size set in the linker script. The stack size is then added to the final data size of the module. Also set a default minimum stack size of 32 bytes.
author William Astle <lost@l-w.ca>
date Thu, 31 Jan 2013 19:34:54 -0700
parents ce1fdc8d6568
children 7de7b14ebaee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
1 /*
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
2 script.c
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
3 Copyright © 2009 William Astle
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
4
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
5 This file is part of LWLINK.
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
6
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
7 LWLINK is free software: you can redistribute it and/or modify it under the
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
10 version.
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
11
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
15 more details.
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
16
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
19
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
20
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
21 Read and parse linker scripts
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
22 */
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
23
2
7317fbe024af Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents: 0
diff changeset
24 #include <ctype.h>
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
25 #include <errno.h>
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
26 #include <stdio.h>
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
27 #include <stdlib.h>
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
28 #include <string.h>
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
29
8
fdc11ef4115b Switched lwlink to lw_cmdline from argp and also brought in lw_alloc and lw_string to replace util.c
lost@l-w.ca
parents: 2
diff changeset
30 #include <lw_alloc.h>
fdc11ef4115b Switched lwlink to lw_cmdline from argp and also brought in lw_alloc and lw_string to replace util.c
lost@l-w.ca
parents: 2
diff changeset
31 #include <lw_string.h>
fdc11ef4115b Switched lwlink to lw_cmdline from argp and also brought in lw_alloc and lw_string to replace util.c
lost@l-w.ca
parents: 2
diff changeset
32
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
33 #include "lwlink.h"
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
34
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
35 // the built-in OS9 script
151
3b58d76ea032 Fix up some minor thinkos in handling the module layout and header
lost@l-w.ca
parents: 148
diff changeset
36 // the 000D bit is to handle the module header!
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
37 static char *os9_script =
234
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
38 "define basesympat s_%s\n"
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
39 "define lensympat l_%s\n"
151
3b58d76ea032 Fix up some minor thinkos in handling the module layout and header
lost@l-w.ca
parents: 148
diff changeset
40 "section code load 000D\n"
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
41 "section .text\n"
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
42 "section data\n"
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
43 "section .data\n"
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
44 "section bss,bss load 0000\n"
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
45 "section .bss,bss\n"
258
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 236
diff changeset
46 "stacksize 32\n"
151
3b58d76ea032 Fix up some minor thinkos in handling the module layout and header
lost@l-w.ca
parents: 148
diff changeset
47 "entry __start\n"
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
48 ;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
49
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
50 // the built-in DECB target linker script
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
51 static char *decb_script =
234
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
52 "define basesympat s_%s\n"
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
53 "define lensympat l_%s\n"
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
54 "section init load 2000\n"
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
55 "section code\n"
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
56 "section *,!bss\n"
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
57 "section *,bss\n"
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
58 "entry 2000\n"
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
59 ;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
60
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
61 // the built-in RAW target linker script
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
62 static char *raw_script =
234
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
63 "define basesympat s_%s\n"
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
64 "define lensympat l_%s\n"
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
65 "section init load 0000\n"
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
66 "section code\n"
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
67 "section *,!bss\n"
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
68 "section *,bss\n"
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
69 ;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
70
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
71 static char *lwex0_script =
234
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
72 "define basesympat s_%s\n"
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
73 "define lensympat l_%s\n"
236
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
74 "sectopt .ctors padafter 00,00\n"
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
75 "sectopt .dtors padafter 00,00\n"
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
76 "section init load 0100\n"
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
77 "section .text\n"
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
78 "section .data\n"
78
19df13313b27 Updated default linkscript for lwex target
lost@l-w.ca
parents: 67
diff changeset
79 "section .ctors_start\n"
19df13313b27 Updated default linkscript for lwex target
lost@l-w.ca
parents: 67
diff changeset
80 "section .ctors\n"
19df13313b27 Updated default linkscript for lwex target
lost@l-w.ca
parents: 67
diff changeset
81 "section .ctors_end\n"
19df13313b27 Updated default linkscript for lwex target
lost@l-w.ca
parents: 67
diff changeset
82 "section .dtors_start\n"
19df13313b27 Updated default linkscript for lwex target
lost@l-w.ca
parents: 67
diff changeset
83 "section .dtors\n"
19df13313b27 Updated default linkscript for lwex target
lost@l-w.ca
parents: 67
diff changeset
84 "section .dtors_end\n"
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
85 "section *,!bss\n"
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
86 "section *,bss\n"
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
87 "entry __start\n"
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
88 "stacksize 0100\n" // default 256 byte stack
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
89 ;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
90
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
91 // the "simple" script
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
92 static char *simple_script =
234
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
93 "define basesympat s_%s\n"
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
94 "define lensympat l_%s\n"
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
95 "section *,!bss\n"
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
96 "section *,bss\n"
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
97 ;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
98
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
99 linkscript_t linkscript = { 0, NULL, -1 };
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
100
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
101 void setup_script()
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
102 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
103 char *script, *oscript;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
104 long size;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
105
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
106 // read the file if needed
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
107 if (scriptfile)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
108 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
109 FILE *f;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
110 long bread;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
111
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
112 f = fopen(scriptfile, "rb");
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
113 if (!f)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
114 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
115 fprintf(stderr, "Can't open file %s:", scriptfile);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
116 perror("");
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
117 exit(1);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
118 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
119 fseek(f, 0, SEEK_END);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
120 size = ftell(f);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
121 rewind(f);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
122
8
fdc11ef4115b Switched lwlink to lw_cmdline from argp and also brought in lw_alloc and lw_string to replace util.c
lost@l-w.ca
parents: 2
diff changeset
123 script = lw_alloc(size + 2);
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
124
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
125 bread = fread(script, 1, size, f);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
126 if (bread < size)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
127 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
128 fprintf(stderr, "Short read on file %s (%ld/%ld):", scriptfile, bread, size);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
129 perror("");
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
130 exit(1);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
131 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
132 fclose(f);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
133
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
134 script[size] = '\n';
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
135 script[size + 1] = '\0';
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
136 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
137 else
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
138 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
139 // fetch defaults based on output mode
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
140 switch (outformat)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
141 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
142 case OUTPUT_RAW:
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
143 script = raw_script;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
144 break;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
145
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
146 case OUTPUT_DECB:
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
147 script = decb_script;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
148 break;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
149
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
150 case OUTPUT_LWEX0:
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
151 script = lwex0_script;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
152 break;
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
153
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
154 case OUTPUT_OS9:
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
155 script = os9_script;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
156 break;
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
157
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
158 default:
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
159 script = simple_script;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
160 break;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
161 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
162
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
163 size = strlen(script);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
164 if (nscriptls)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
165 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
166 char *rscript;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
167 int i;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
168 // prepend the "extra" script lines
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
169 for (i = 0; i < nscriptls; i++)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
170 size += strlen(scriptls[i]) + 1;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
171
8
fdc11ef4115b Switched lwlink to lw_cmdline from argp and also brought in lw_alloc and lw_string to replace util.c
lost@l-w.ca
parents: 2
diff changeset
172 rscript = lw_alloc(size + 1);
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
173 oscript = rscript;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
174 for (i = 0; i < nscriptls; i++)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
175 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
176 oscript += sprintf(oscript, "%s\n", scriptls[i]);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
177 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
178 strcpy(oscript, script);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
179 script = rscript;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
180 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
181 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
182
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
183 if (outformat == OUTPUT_LWEX0)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
184 linkscript.stacksize = 0x100;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
185
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
186 if (outformat == OUTPUT_OS9)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
187 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
188 linkscript.modtype = 0x01;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
189 linkscript.modlang = 0x01;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
190 linkscript.modattr = 0x08;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
191 linkscript.modrev = 0x00;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
192 linkscript.name = NULL;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
193 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
194
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
195 oscript = script;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
196 // now parse the script file
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
197 while (*script)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
198 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
199 char *ptr, *ptr2, *line;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
200
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
201 for (ptr = script; *ptr && *ptr != '\n' && *ptr != '\r'; ptr++)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
202 /* do nothing */ ;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
203
8
fdc11ef4115b Switched lwlink to lw_cmdline from argp and also brought in lw_alloc and lw_string to replace util.c
lost@l-w.ca
parents: 2
diff changeset
204 line = lw_alloc(ptr - script + 1);
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
205 memcpy(line, script, ptr - script);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
206 line[ptr - script] = '\0';
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
207
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
208 // skip line terms
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
209 for (script = ptr + 1; *script == '\n' || *script == '\r'; script++)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
210 /* do nothing */ ;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
211
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
212 // ignore leading whitespace
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
213 for (ptr = line; *ptr && isspace(*ptr); ptr++)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
214 /* do nothing */ ;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
215
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
216 // ignore blank lines
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
217 if (!*ptr)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
218 continue;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
219
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
220 for (ptr = line; *ptr && !isspace(*ptr); ptr++)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
221 /* do nothing */ ;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
222
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
223 // now ptr points to the char past the first word
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
224 // NUL it out
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
225 if (*ptr)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
226 *ptr++ = '\0';
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
227
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
228 // skip spaces after the first word
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
229 for ( ; *ptr && isspace(*ptr); ptr++)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
230 /* do nothing */ ;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
231
236
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
232 if (!strcmp(line, "sectopt"))
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
233 {
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
234 char *sn;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
235 char *ptr3;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
236 sectopt_t *so;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
237
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
238 for (ptr2 = ptr; *ptr && !isspace(*ptr2); ptr2++)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
239 /* do nothing */ ;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
240
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
241 if (*ptr2)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
242 *ptr2++ = '\0';
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
243
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
244 while (*ptr2 && isspace(*ptr2))
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
245 ptr2++;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
246
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
247 // section name is at ptr
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
248 // ptr2 is the option type
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
249 sn = ptr;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
250
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
251 // now ptr2 points to the section option name
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
252 for (ptr3 = ptr2; *ptr3 && !isspace(*ptr3); ptr3++)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
253 /* do nothing */ ;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
254
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
255 if (*ptr3)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
256 *ptr3++ = 0;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
257
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
258 while (*ptr3 && isspace(*ptr3))
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
259 ptr3++;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
260
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
261 // now ptr3 points to option value
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
262 for (so = section_opts; so; so = so -> next)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
263 {
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
264 if (!strcmp(so -> name, sn))
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
265 break;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
266 }
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
267
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
268 if (!so)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
269 {
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
270 so = lw_alloc(sizeof(sectopt_t));
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
271 so -> name = lw_strdup(sn);
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
272 so -> aftersize = 0;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
273 so -> afterbytes = NULL;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
274 so -> next = section_opts;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
275 section_opts = so;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
276 }
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
277
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
278 if (!strcmp(ptr2, "padafter"))
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
279 {
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
280 if (so -> afterbytes)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
281 lw_free(so -> afterbytes);
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
282 so -> aftersize = 0;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
283
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
284 for (;;)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
285 {
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
286 int v;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
287 char *ptr4;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
288
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
289 while (*ptr3 && isspace(*ptr3))
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
290 ptr3++;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
291
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
292 if (!ptr3)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
293 break;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
294
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
295 v = strtoul(ptr3, &ptr4, 16);
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
296 if (ptr3 == ptr4)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
297 break;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
298
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
299
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
300 so -> afterbytes = lw_realloc(so -> afterbytes, so -> aftersize + 1);
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
301 so -> afterbytes[so -> aftersize] = v;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
302 so -> aftersize++;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
303 ptr3 = ptr4;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
304 while (*ptr3 && isspace(*ptr3))
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
305 ptr3++;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
306
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
307 if (*ptr3 != ',')
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
308 break;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
309
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
310 ptr3++;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
311 }
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
312 }
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
313 else
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
314 {
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
315 fprintf(stderr, "%s: bad script line: %s %s\n", scriptfile, line, ptr2);
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
316 exit(1);
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
317 }
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
318 }
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
319 else if (!strcmp(line, "define"))
234
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
320 {
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
321 // parse out the definition type
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
322 for (ptr2 = ptr; *ptr2 && !isspace(*ptr2); ptr2++)
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
323 /* do nothing */ ;
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
324
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
325 if (*ptr2)
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
326 *ptr2++ = '\0';
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
327
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
328 while (*ptr2 && isspace(*ptr2))
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
329 ptr2++;
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
330
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
331 // now ptr points to the define type
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
332 if (!strcmp(ptr, "basesympat"))
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
333 {
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
334 /* section base symbol pattern */
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
335 lw_free(linkscript.basesympat);
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
336 linkscript.basesympat = lw_strdup(ptr2);
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
337 }
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
338 else if (!strcmp(ptr, "lensympat"))
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
339 {
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
340 /* section length symbol pattern */
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
341 lw_free(linkscript.lensympat);
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
342 linkscript.lensympat = lw_strdup(ptr2);
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
343 }
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
344 else
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
345 {
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
346 }
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
347 }
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
348 else if (!strcmp(line, "pad"))
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
349 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
350 // padding
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
351 // parse the hex number and stow it
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
352 linkscript.padsize = strtol(ptr, NULL, 16);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
353 if (linkscript.padsize < 0)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
354 linkscript.padsize = 0;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
355 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
356 else if (!strcmp(line, "stacksize"))
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
357 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
358 // stack size for targets that support it
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
359 // parse the hex number and stow it
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
360 linkscript.padsize = strtol(ptr, NULL, 16);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
361 if (linkscript.stacksize < 0)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
362 linkscript.stacksize = 0x100;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
363 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
364 else if (!strcmp(line, "entry"))
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
365 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
366 int eaddr;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
367
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
368 eaddr = strtol(ptr, &ptr2, 16);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
369 if (*ptr2)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
370 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
371 linkscript.execaddr = -1;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
372 linkscript.execsym = lw_strdup(ptr);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
373 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
374 else
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
375 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
376 linkscript.execaddr = eaddr;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
377 linkscript.execsym = NULL;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
378 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
379 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
380 else if (!strcmp(line, "section"))
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
381 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
382 // section
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
383 // parse out the section name and flags
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
384 for (ptr2 = ptr; *ptr2 && !isspace(*ptr2); ptr2++)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
385 /* do nothing */ ;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
386
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
387 if (*ptr2)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
388 *ptr2++ = '\0';
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
389
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
390 while (*ptr2 && isspace(*ptr2))
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
391 ptr2++;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
392
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
393 // ptr now points to the section name and flags and ptr2
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
394 // to the first non-space character following
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
395
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
396 // then look for "load <addr>" clause
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
397 if (*ptr2)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
398 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
399 if (!strncmp(ptr2, "load", 4))
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
400 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
401 ptr2 += 4;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
402 while (*ptr2 && isspace(*ptr2))
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
403 ptr2++;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
404
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
405 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
406 else
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
407 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
408 fprintf(stderr, "%s: bad script\n", scriptfile);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
409 exit(1);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
410 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
411 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
412
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
413 // now ptr2 points to the load address if there is one
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
414 // or NUL if not
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
415 linkscript.lines = lw_realloc(linkscript.lines, sizeof(struct scriptline_s) * (linkscript.nlines + 1));
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
416
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
417 linkscript.lines[linkscript.nlines].noflags = 0;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
418 linkscript.lines[linkscript.nlines].yesflags = 0;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
419 if (*ptr2)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
420 linkscript.lines[linkscript.nlines].loadat = strtol(ptr2, NULL, 16);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
421 else
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
422 linkscript.lines[linkscript.nlines].loadat = -1;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
423 for (ptr2 = ptr; *ptr2 && *ptr2 != ','; ptr2++)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
424 /* do nothing */ ;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
425 if (*ptr2)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
426 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
427 *ptr2++ = '\0';
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
428 if (!strcmp(ptr2, "!bss"))
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
429 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
430 linkscript.lines[linkscript.nlines].noflags = SECTION_BSS;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
431 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
432 else if (!strcmp(ptr2, "bss"))
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
433 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
434 linkscript.lines[linkscript.nlines].yesflags = SECTION_BSS;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
435 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
436 else
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
437 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
438 fprintf(stderr, "%s: bad script\n", scriptfile);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
439 exit(1);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
440 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
441 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
442 if (ptr[0] == '*' && ptr[1] == '\0')
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
443 linkscript.lines[linkscript.nlines].sectname = NULL;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
444 else
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
445 linkscript.lines[linkscript.nlines].sectname = lw_strdup(ptr);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
446 linkscript.nlines++;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
447 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
448 else
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
449 {
67
554831f03338 Make lwlink more verbose about unrecognized linkscript lines
lost@l-w.ca
parents: 8
diff changeset
450 fprintf(stderr, "%s: bad script line: %s\n", scriptfile, line);
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
451 exit(1);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
452 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
453 lw_free(line);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
454 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
455
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
456 if (scriptfile || nscriptls)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
457 lw_free(oscript);
183
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
458
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
459 if (entrysym)
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
460 {
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
461 int eaddr;
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
462 char *ptr2;
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
463
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
464 lw_free(linkscript.execsym);
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
465
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
466 eaddr = strtol(entrysym, &ptr2, 0);
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
467 if (*ptr2)
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
468 {
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
469 linkscript.execaddr = -1;
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
470 linkscript.execsym = lw_strdup(entrysym);
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
471 }
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
472 else
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
473 {
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
474 linkscript.execaddr = eaddr;
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
475 linkscript.execsym = NULL;
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
476 }
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
477
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
478 }
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
479 }