annotate lwlink/script.c @ 180:6ebb93b409ba

Added library paths and --section-base
author lost
date Thu, 05 Mar 2009 02:23:25 +0000
parents 106c2fe3c9d9
children 857cb407229e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
117
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
1 /*
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
2 script.c
118
d450943305a7 Fixed copyright year
lost
parents: 117
diff changeset
3 Copyright © 2009 William Astle
117
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
4
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
5 This file is part of LWLINK.
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
6
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
7 LWLINK is free software: you can redistribute it and/or modify it under the
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
10 version.
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
11
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
15 more details.
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
16
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
19
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
20
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
21 Read and parse linker scripts
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
22 */
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
23
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
25 #include "config.h"
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
26 #endif
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
27
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
28 #include <errno.h>
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
29 #include <stdio.h>
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
30 #include <stdlib.h>
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
31 #include <string.h>
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
32
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
33 #include "lwlink.h"
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
34 #include "util.h"
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
35
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
36 // the built-in DECB target linker script
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
37 static char *decb_script =
124
4ac96c697ef0 Corrected errors with parsing script and object files
lost
parents: 121
diff changeset
38 "section init load 2000\n"
117
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
39 "section code\n"
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
40 "section *,!bss\n"
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
41 "section *,bss\n"
121
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 119
diff changeset
42 "entry 2000\n"
117
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
43 ;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
44
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
45 // the built-in RAW target linker script
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
46 static char *raw_script =
124
4ac96c697ef0 Corrected errors with parsing script and object files
lost
parents: 121
diff changeset
47 "section init load 0000\n"
117
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
48 "section code\n"
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
49 "section *,!bss\n"
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
50 "section *,bss\n"
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
51 ;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
52
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
53 // the "simple" script
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
54 static char *simple_script =
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
55 "section *,!bss\n"
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
56 "section *,bss\n"
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
57 ;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
58
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
59 linkscript_t linkscript = { 0, NULL, -1 };
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
60
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
61 void setup_script()
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
62 {
125
f9bfc2986023 Actually allow script file to be specified and fix segfault on parsing script file
lost
parents: 124
diff changeset
63 char *script, *oscript;
117
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
64 long size;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
65
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
66 // read the file if needed
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
67 if (scriptfile)
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
68 {
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
69 FILE *f;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
70 long bread;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
71
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
72 f = fopen(scriptfile, "rb");
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
73 if (!f)
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
74 {
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
75 fprintf(stderr, "Can't open file %s:", scriptfile);
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
76 perror("");
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
77 exit(1);
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
78 }
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
79 fseek(f, 0, SEEK_END);
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
80 size = ftell(f);
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
81 rewind(f);
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
82
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
83 script = lw_malloc(size + 2);
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
84
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
85 bread = fread(script, 1, size, f);
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
86 if (bread < size)
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
87 {
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
88 fprintf(stderr, "Short read on file %s (%ld/%ld):", scriptfile, bread, size);
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
89 perror("");
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
90 exit(1);
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
91 }
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
92 fclose(f);
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
93
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
94 script[size] = '\n';
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
95 script[size + 1] = '\0';
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
96 }
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
97 else
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
98 {
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
99 // fetch defaults based on output mode
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
100 switch (outformat)
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
101 {
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
102 case OUTPUT_RAW:
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
103 script = raw_script;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
104 break;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
105
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
106 case OUTPUT_DECB:
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
107 script = decb_script;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
108 break;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
109
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
110 default:
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
111 script = simple_script;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
112 break;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
113 }
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
114
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
115 size = strlen(script);
180
6ebb93b409ba Added library paths and --section-base
lost
parents: 139
diff changeset
116 if (nscriptls)
6ebb93b409ba Added library paths and --section-base
lost
parents: 139
diff changeset
117 {
6ebb93b409ba Added library paths and --section-base
lost
parents: 139
diff changeset
118 char *rscript;
6ebb93b409ba Added library paths and --section-base
lost
parents: 139
diff changeset
119 int i;
6ebb93b409ba Added library paths and --section-base
lost
parents: 139
diff changeset
120 // prepend the "extra" script lines
6ebb93b409ba Added library paths and --section-base
lost
parents: 139
diff changeset
121 for (i = 0; i < nscriptls; i++)
6ebb93b409ba Added library paths and --section-base
lost
parents: 139
diff changeset
122 size += strlen(scriptls[i]) + 1;
6ebb93b409ba Added library paths and --section-base
lost
parents: 139
diff changeset
123
6ebb93b409ba Added library paths and --section-base
lost
parents: 139
diff changeset
124 rscript = lw_malloc(size + 1);
6ebb93b409ba Added library paths and --section-base
lost
parents: 139
diff changeset
125 oscript = rscript;
6ebb93b409ba Added library paths and --section-base
lost
parents: 139
diff changeset
126 for (i = 0; i < nscriptls; i++)
6ebb93b409ba Added library paths and --section-base
lost
parents: 139
diff changeset
127 {
6ebb93b409ba Added library paths and --section-base
lost
parents: 139
diff changeset
128 oscript += sprintf(oscript, "%s\n", scriptls[i]);
6ebb93b409ba Added library paths and --section-base
lost
parents: 139
diff changeset
129 }
6ebb93b409ba Added library paths and --section-base
lost
parents: 139
diff changeset
130 strcpy(oscript, script);
6ebb93b409ba Added library paths and --section-base
lost
parents: 139
diff changeset
131 script = rscript;
6ebb93b409ba Added library paths and --section-base
lost
parents: 139
diff changeset
132 }
117
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
133 }
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
134
125
f9bfc2986023 Actually allow script file to be specified and fix segfault on parsing script file
lost
parents: 124
diff changeset
135 oscript = script;
117
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
136 // now parse the script file
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
137 while (*script)
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
138 {
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
139 char *ptr, *ptr2, *line;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
140
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
141 for (ptr = script; *ptr && *ptr != '\n' && *ptr != '\r'; ptr++)
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
142 /* do nothing */ ;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
143
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
144 line = lw_malloc(ptr - script + 1);
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
145 memcpy(line, script, ptr - script);
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
146 line[ptr - script] = '\0';
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
147
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
148 // skip line terms
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
149 for (script = ptr + 1; *script == '\n' || *script == '\r'; script++)
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
150 /* do nothing */ ;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
151
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
152 // ignore leading whitespace
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
153 for (ptr = line; *ptr && isspace(*ptr); ptr++)
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
154 /* do nothing */ ;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
155
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
156 // ignore blank lines
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
157 if (!*ptr)
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
158 continue;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
159
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
160 for (ptr = line; *ptr && !isspace(*ptr); ptr++)
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
161 /* do nothing */ ;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
162
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
163 // now ptr points to the char past the first word
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
164 // NUL it out
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
165 if (*ptr)
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
166 *ptr++ = '\0';
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
167
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
168 // skip spaces after the first word
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
169 for ( ; *ptr && isspace(*ptr); ptr++)
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
170 /* do nothing */ ;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
171
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
172 if (!strcmp(line, "pad"))
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
173 {
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
174 // padding
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
175 // parse the hex number and stow it
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
176 linkscript.padsize = strtol(ptr, NULL, 16);
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
177 if (linkscript.padsize < 0)
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
178 linkscript.padsize = 0;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
179 }
121
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 119
diff changeset
180 else if (!strcmp(line, "entry"))
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 119
diff changeset
181 {
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 119
diff changeset
182 int eaddr;
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 119
diff changeset
183
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 119
diff changeset
184 eaddr = strtol(ptr, &ptr2, 16);
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 119
diff changeset
185 if (*ptr2)
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 119
diff changeset
186 {
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 119
diff changeset
187 linkscript.execaddr = -1;
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 119
diff changeset
188 linkscript.execsym = lw_strdup(ptr);
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 119
diff changeset
189 }
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 119
diff changeset
190 else
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 119
diff changeset
191 {
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 119
diff changeset
192 linkscript.execaddr = eaddr;
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 119
diff changeset
193 linkscript.execsym = NULL;
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 119
diff changeset
194 }
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 119
diff changeset
195 }
117
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
196 else if (!strcmp(line, "section"))
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
197 {
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
198 // section
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
199 // parse out the section name and flags
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
200 for (ptr2 = ptr; *ptr2 && !isspace(*ptr2); ptr2++)
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
201 /* do nothing */ ;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
202
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
203 if (*ptr2)
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
204 *ptr2++ = '\0';
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
205
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
206 while (*ptr2 && isspace(*ptr2))
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
207 ptr2++;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
208
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
209 // ptr now points to the section name and flags and ptr2
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
210 // to the first non-space character following
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
211
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
212 // then look for "load <addr>" clause
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
213 if (*ptr2)
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
214 {
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
215 if (!strncmp(ptr2, "load", 4))
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
216 {
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
217 ptr2 += 4;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
218 while (*ptr2 && isspace(*ptr2))
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
219 ptr2++;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
220
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
221 }
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
222 else
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
223 {
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
224 fprintf(stderr, "%s: bad script\n", scriptfile);
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
225 exit(1);
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
226 }
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
227 }
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
228
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
229 // now ptr2 points to the load address if there is one
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
230 // or NUL if not
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
231 linkscript.lines = lw_realloc(linkscript.lines, sizeof(struct scriptline_s) * (linkscript.nlines + 1));
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
232
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
233 linkscript.lines[linkscript.nlines].noflags = 0;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
234 linkscript.lines[linkscript.nlines].yesflags = 0;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
235 if (*ptr2)
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
236 linkscript.lines[linkscript.nlines].loadat = strtol(ptr2, NULL, 16);
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
237 else
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
238 linkscript.lines[linkscript.nlines].loadat = -1;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
239 for (ptr2 = ptr; *ptr2 && *ptr2 != ','; ptr2++)
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
240 /* do nothing */ ;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
241 if (*ptr2)
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
242 {
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
243 *ptr2++ = '\0';
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
244 if (!strcmp(ptr2, "!bss"))
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
245 {
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
246 linkscript.lines[linkscript.nlines].noflags = SECTION_BSS;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
247 }
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
248 else if (!strcmp(ptr2, "bss"))
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
249 {
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
250 linkscript.lines[linkscript.nlines].yesflags = SECTION_BSS;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
251 }
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
252 else
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
253 {
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
254 fprintf(stderr, "%s: bad script\n", scriptfile);
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
255 exit(1);
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
256 }
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
257 }
119
8bc00221ae89 section order and address resolution done
lost
parents: 118
diff changeset
258 if (ptr[0] == '*' && ptr[1] == '\0')
8bc00221ae89 section order and address resolution done
lost
parents: 118
diff changeset
259 linkscript.lines[linkscript.nlines].sectname = NULL;
8bc00221ae89 section order and address resolution done
lost
parents: 118
diff changeset
260 else
8bc00221ae89 section order and address resolution done
lost
parents: 118
diff changeset
261 linkscript.lines[linkscript.nlines].sectname = lw_strdup(ptr);
117
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
262 linkscript.nlines++;
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
263 }
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
264 else
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
265 {
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
266 fprintf(stderr, "%s: bad script\n", scriptfile);
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
267 exit(1);
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
268 }
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
269 lw_free(line);
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
270 }
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
271
180
6ebb93b409ba Added library paths and --section-base
lost
parents: 139
diff changeset
272 if (scriptfile || nscriptls)
125
f9bfc2986023 Actually allow script file to be specified and fix segfault on parsing script file
lost
parents: 124
diff changeset
273 lw_free(oscript);
117
bb3cc989e84b parse linking scripts
lost
parents:
diff changeset
274 }