annotate lwlink/script.c @ 315:fcd103148aa6

Add ability to load sections downward instead of upward Add "section ... high ..." statement to link scripts to allow a section to be placed based on its end address instead of its start address. All sections listed after such a statement are treated as growing downward until the next section statement specifying a load address.
author William Astle <lost@l-w.ca>
date Wed, 27 Nov 2013 16:01:26 -0700
parents 86eb8814a05c
children 55c1f9a321e9
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;
262
7de7b14ebaee Add support for os9 module edition byte
William Astle <lost@l-w.ca>
parents: 258
diff changeset
192 linkscript.edition = -1;
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
193 linkscript.name = NULL;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
194 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 78
diff changeset
195
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
196 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
197 // 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
198 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
199 {
2c24602be78f 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 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
201
2c24602be78f 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 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
203 /* 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
204
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
205 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
206 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
207 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
208
2c24602be78f 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 // 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
210 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
211 /* 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
212
2c24602be78f 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 // 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
214 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
215 /* 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
216
310
86eb8814a05c Add comments to linker scripts.
William Astle <lost@l-w.ca>
parents: 262
diff changeset
217 // ignore blank lines and comments
86eb8814a05c Add comments to linker scripts.
William Astle <lost@l-w.ca>
parents: 262
diff changeset
218 if (!*ptr || *ptr == '#' || *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
219 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
220
2c24602be78f 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 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
222 /* 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
223
2c24602be78f 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 // 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
225 // 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
226 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
227 *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
228
2c24602be78f 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 // 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
230 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
231 /* 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
232
236
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
233 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
234 {
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
235 char *sn;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
236 char *ptr3;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
237 sectopt_t *so;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
238
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
239 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
240 /* do nothing */ ;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
241
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
242 if (*ptr2)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
243 *ptr2++ = '\0';
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
244
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
245 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
246 ptr2++;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
247
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
248 // 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
249 // 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
250 sn = ptr;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
251
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
252 // 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
253 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
254 /* do nothing */ ;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
255
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
256 if (*ptr3)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
257 *ptr3++ = 0;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
258
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
259 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
260 ptr3++;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
261
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
262 // 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
263 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
264 {
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
265 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
266 break;
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
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
269 if (!so)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
270 {
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
271 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
272 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
273 so -> aftersize = 0;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
274 so -> afterbytes = NULL;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
275 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
276 section_opts = so;
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
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
279 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
280 {
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
281 if (so -> afterbytes)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
282 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
283 so -> aftersize = 0;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
284
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
285 for (;;)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
286 {
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
287 int v;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
288 char *ptr4;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
289
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
290 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
291 ptr3++;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
292
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
293 if (!ptr3)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
294 break;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
295
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
296 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
297 if (ptr3 == ptr4)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
298 break;
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
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
301 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
302 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
303 so -> aftersize++;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
304 ptr3 = ptr4;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
305 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
306 ptr3++;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
307
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
308 if (*ptr3 != ',')
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
309 break;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
310
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
311 ptr3++;
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 }
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
314 else
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
315 {
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
316 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
317 exit(1);
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 }
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 234
diff changeset
320 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
321 {
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
322 // parse out the definition type
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
323 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
324 /* do nothing */ ;
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
325
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
326 if (*ptr2)
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
327 *ptr2++ = '\0';
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
328
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
329 while (*ptr2 && isspace(*ptr2))
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
330 ptr2++;
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
331
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
332 // 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
333 if (!strcmp(ptr, "basesympat"))
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
334 {
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
335 /* section base symbol pattern */
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
336 lw_free(linkscript.basesympat);
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
337 linkscript.basesympat = lw_strdup(ptr2);
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
338 }
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
339 else if (!strcmp(ptr, "lensympat"))
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
340 {
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
341 /* section length symbol pattern */
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
342 lw_free(linkscript.lensympat);
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
343 linkscript.lensympat = lw_strdup(ptr2);
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
344 }
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
345 else
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 }
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 183
diff changeset
349 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
350 {
2c24602be78f 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 // 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
352 // 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
353 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
354 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
355 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
356 }
2c24602be78f 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 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
358 {
2c24602be78f 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 // 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
360 // 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
361 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
362 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
363 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
364 }
2c24602be78f 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 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
366 {
2c24602be78f 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 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
368
2c24602be78f 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 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
370 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
371 {
2c24602be78f 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.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
373 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
374 }
2c24602be78f 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 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
376 {
2c24602be78f 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.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
378 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
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 }
2c24602be78f 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 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
382 {
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 310
diff changeset
383 int growsdown = 0;
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
384 // 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
385 // 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
386 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
387 /* 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
388
2c24602be78f 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 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
390 *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
391
2c24602be78f 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 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
393 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
2c24602be78f 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 // 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
396 // 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
397
2c24602be78f 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 // 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
399 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
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 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
402 {
2c24602be78f 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 += 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
404 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
405 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
406
2c24602be78f 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 }
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 310
diff changeset
408 else if (!strncmp(ptr2, "high", 4))
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 310
diff changeset
409 {
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 310
diff changeset
410 ptr2 += 4;
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 310
diff changeset
411 while (*ptr2 && isspace(*ptr2))
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 310
diff changeset
412 ptr2++;
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 310
diff changeset
413 growsdown = 1;
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 310
diff changeset
414 }
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
415 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
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 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
418 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
419 }
2c24602be78f 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 }
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 310
diff changeset
421 else
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 310
diff changeset
422 {
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 310
diff changeset
423 if (linkscript.nlines > 0)
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 310
diff changeset
424 growsdown = linkscript.lines[linkscript.nlines - 1].growsdown;
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 310
diff changeset
425 }
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
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 // 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
428 // 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
429 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
430
2c24602be78f 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 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
432 linkscript.lines[linkscript.nlines].yesflags = 0;
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 310
diff changeset
433 linkscript.lines[linkscript.nlines].growsdown = growsdown;
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
434 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
435 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
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 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
438 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
439 /* 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
440 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
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 *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
443 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
444 {
2c24602be78f 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].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
446 }
2c24602be78f 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 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
448 {
2c24602be78f 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 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
450 }
2c24602be78f 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 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
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 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
454 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
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 }
2c24602be78f 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 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
458 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
459 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
460 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
461 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
462 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
463 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
464 {
67
554831f03338 Make lwlink more verbose about unrecognized linkscript lines
lost@l-w.ca
parents: 8
diff changeset
465 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
466 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
467 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
468 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
469 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
470
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
471 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
472 lw_free(oscript);
183
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 if (entrysym)
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
475 {
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
476 int eaddr;
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
477 char *ptr2;
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
478
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
479 lw_free(linkscript.execsym);
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
480
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
481 eaddr = strtol(entrysym, &ptr2, 0);
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
482 if (*ptr2)
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
483 {
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
484 linkscript.execaddr = -1;
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
485 linkscript.execsym = lw_strdup(entrysym);
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
486 }
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
487 else
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
488 {
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
489 linkscript.execaddr = eaddr;
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
490 linkscript.execsym = NULL;
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
491 }
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
492
c6a38fd8bd33 Added --entry option for lwlink
lost@l-w.ca
parents: 151
diff changeset
493 }
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
494 }