annotate lwlink/link.c @ 548:cde1a5a48636

Add IHEX output format to lwlink At the request of Craig Iannello who provided a small bribe, IHEX output format is now available in lwlink. At least a first pass version of it.
author William Astle <lost@l-w.ca>
date Thu, 16 Mar 2023 16:59:50 -0600
parents 4f6b2c615818
children
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 link.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 Resolve section and symbol addresses; handle incomplete references
2c24602be78f 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
510
3425005b9980 Fix segfault if no instances of a section are in the final result
William Astle <lost@l-w.ca>
parents: 445
diff changeset
24 #define __link_c_seen__
3425005b9980 Fix segfault if no instances of a section are in the final result
William Astle <lost@l-w.ca>
parents: 445
diff changeset
25
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
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>
2
7317fbe024af Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents: 0
diff changeset
28 #include <string.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
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>
234
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
31 #include <lw_string.h>
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
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 "expr.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 #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
35
386
221b5f58d8ad Port remainder of tools to Windows
William Astle <lost@l-w.ca>
parents: 325
diff changeset
36 #ifdef _MSC_VER
221b5f58d8ad Port remainder of tools to Windows
William Astle <lost@l-w.ca>
parents: 325
diff changeset
37 #include <lw_win.h> // windows build
221b5f58d8ad Port remainder of tools to Windows
William Astle <lost@l-w.ca>
parents: 325
diff changeset
38 #endif
221b5f58d8ad Port remainder of tools to Windows
William Astle <lost@l-w.ca>
parents: 325
diff changeset
39
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
40 void check_os9(void);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
41
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
42 struct section_list *sectlist = 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
43 int nsects = 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
44 static int nforced = 0;
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
45 static int resolveonly = 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
46
235
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
47 int quietsym = 1;
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
48
234
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
49 symlist_t *symlist = NULL;
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
50
236
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
51 sectopt_t *section_opts = NULL;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
52
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
53 void check_section_name(char *name, int *base, fileinfo_t *fn, int down)
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 {
2c24602be78f 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 int sn;
325
6821f4855702 Fix bug with section padding and downward allocation.
William Astle <lost@l-w.ca>
parents: 315
diff changeset
56 sectopt_t *so;
6821f4855702 Fix bug with section padding and downward allocation.
William Astle <lost@l-w.ca>
parents: 315
diff changeset
57
510
3425005b9980 Fix segfault if no instances of a section are in the final result
William Astle <lost@l-w.ca>
parents: 445
diff changeset
58 //fprintf(stderr, "Considering sections in %s (%d) for %s\n", fn -> filename, fn -> forced, name);
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
59 if (fn -> forced == 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
60 return;
2c24602be78f 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
325
6821f4855702 Fix bug with section padding and downward allocation.
William Astle <lost@l-w.ca>
parents: 315
diff changeset
62 for (so = section_opts; so; so = so -> next)
6821f4855702 Fix bug with section padding and downward allocation.
William Astle <lost@l-w.ca>
parents: 315
diff changeset
63 if (!strcmp(so -> name, name))
6821f4855702 Fix bug with section padding and downward allocation.
William Astle <lost@l-w.ca>
parents: 315
diff changeset
64 break;
6821f4855702 Fix bug with section padding and downward allocation.
William Astle <lost@l-w.ca>
parents: 315
diff changeset
65
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
66 for (sn = 0; sn < fn -> nsections; sn++)
2c24602be78f 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 {
510
3425005b9980 Fix segfault if no instances of a section are in the final result
William Astle <lost@l-w.ca>
parents: 445
diff changeset
68 //fprintf(stderr, " Considering section %s\n", fn -> sections[sn].name);
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
69 if (!strcmp(name, (char *)(fn -> sections[sn].name)))
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
70 {
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
71 if (fn -> sections[sn].flags & SECTION_CONST)
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
72 continue;
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
73 // we have a match
510
3425005b9980 Fix segfault if no instances of a section are in the final result
William Astle <lost@l-w.ca>
parents: 445
diff changeset
74 //fprintf(stderr, " Found\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
75 sectlist = lw_realloc(sectlist, sizeof(struct section_list) * (nsects + 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
76 sectlist[nsects].ptr = &(fn -> sections[sn]);
325
6821f4855702 Fix bug with section padding and downward allocation.
William Astle <lost@l-w.ca>
parents: 315
diff changeset
77
6821f4855702 Fix bug with section padding and downward allocation.
William Astle <lost@l-w.ca>
parents: 315
diff changeset
78
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
79 fn -> sections[sn].processed = 1;
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
80 if (down)
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
81 {
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
82 *base -= fn -> sections[sn].codesize;
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
83 fn -> sections[sn].loadaddress = *base;
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
84 }
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
85 else
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
86 {
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
87 fn -> sections[sn].loadaddress = *base;
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
88 *base += fn -> sections[sn].codesize;
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
89 }
325
6821f4855702 Fix bug with section padding and downward allocation.
William Astle <lost@l-w.ca>
parents: 315
diff changeset
90 if (down && so && so -> aftersize)
6821f4855702 Fix bug with section padding and downward allocation.
William Astle <lost@l-w.ca>
parents: 315
diff changeset
91 {
6821f4855702 Fix bug with section padding and downward allocation.
William Astle <lost@l-w.ca>
parents: 315
diff changeset
92 sectlist[nsects].ptr -> afterbytes = so -> afterbytes;
6821f4855702 Fix bug with section padding and downward allocation.
William Astle <lost@l-w.ca>
parents: 315
diff changeset
93 sectlist[nsects].ptr -> aftersize = so -> aftersize;
6821f4855702 Fix bug with section padding and downward allocation.
William Astle <lost@l-w.ca>
parents: 315
diff changeset
94 sectlist[nsects].ptr -> loadaddress -= so -> aftersize;
6821f4855702 Fix bug with section padding and downward allocation.
William Astle <lost@l-w.ca>
parents: 315
diff changeset
95 *base -= so -> aftersize;
6821f4855702 Fix bug with section padding and downward allocation.
William Astle <lost@l-w.ca>
parents: 315
diff changeset
96 so -> aftersize = 0;
6821f4855702 Fix bug with section padding and downward allocation.
William Astle <lost@l-w.ca>
parents: 315
diff changeset
97 }
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
98 nsects++;
510
3425005b9980 Fix segfault if no instances of a section are in the final result
William Astle <lost@l-w.ca>
parents: 445
diff changeset
99 //fprintf(stderr, "Adding section %s (%s) %p %d\n",fn -> sections[sn].name, fn -> filename, sectlist, nsects);
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
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 }
2c24602be78f 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 for (sn = 0; sn < fn -> nsubs; sn++)
2c24602be78f 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 {
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
104 check_section_name(name, base, fn -> subs[sn], down);
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
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 }
2c24602be78f 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
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
108 void add_matching_sections(char *name, int yesflags, int noflags, int *base, int down);
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
109 void check_section_flags(int yesflags, int noflags, int *base, fileinfo_t *fn, int down)
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
110 {
2c24602be78f 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 int sn;
236
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
112 sectopt_t *so;
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
113
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
114 // fprintf(stderr, "Considering sections in %s (%d) for %x/%x\n", fn -> filename, fn -> forced, yesflags, noflags);
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
115
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
116 if (fn -> forced == 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
117 return;
2c24602be78f 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 for (sn = 0; sn < fn -> nsections; sn++)
2c24602be78f 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 {
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
121 // ignore "constant" sections - they're added during the file resolve stage
156
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
122 if (fn -> sections[sn].flags & SECTION_CONST)
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
123 continue;
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 // ignore if the noflags tell us to
2c24602be78f 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 if (noflags && (fn -> sections[sn].flags & noflags))
2c24602be78f 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 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
127 // ignore unless the yesflags tell us not to
2
7317fbe024af Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents: 0
diff changeset
128 if (yesflags && ((fn -> sections[sn].flags & yesflags) == 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
129 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
130 // ignore it if already processed
2c24602be78f 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 if (fn -> sections[sn].processed)
2c24602be78f 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 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
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 // we have a match - now collect *all* sections of the same name!
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
135 // fprintf(stderr, " Found\n");
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
136 add_matching_sections((char *)(fn -> sections[sn].name), 0, 0, base, down);
236
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
137
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
138 /* handle "after padding" */
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
139 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: 235
diff changeset
140 if (!strcmp(so -> name, (char *)(fn -> sections[sn].name)))
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
141 break;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
142 if (so)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
143 {
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
144 if (so -> aftersize)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
145 {
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
146 sectlist[nsects - 1].ptr -> afterbytes = so -> afterbytes;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
147 sectlist[nsects - 1].ptr -> aftersize = so -> aftersize;
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
148 if (down)
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
149 {
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
150 sectlist[nsects - 1].ptr -> loadaddress -= so -> aftersize;
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
151 *base -= so -> aftersize;
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
152 }
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
153 else
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
154 {
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
155 *base += so -> aftersize;
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
156 }
236
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
157 }
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
158 }
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
159
2c24602be78f 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 // and then continue looking for sections
2c24602be78f 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 for (sn = 0; sn < fn -> nsubs; sn++)
2c24602be78f 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 {
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
164 check_section_flags(yesflags, noflags, base, fn -> subs[sn], down);
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
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 }
2c24602be78f 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
2c24602be78f 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
2c24602be78f 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
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
170 void add_matching_sections(char *name, int yesflags, int noflags, int *base, int down)
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
171 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
172 int fn;
2c24602be78f 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 if (name)
2c24602be78f 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 {
2c24602be78f 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 // named 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
176 // look for all instances of a section by the specified name
2c24602be78f 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 // and resolve base addresses and add to the list
2c24602be78f 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 for (fn = 0; fn < ninputfiles; fn++)
2c24602be78f 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 {
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
180 check_section_name(name, base, inputfiles[fn], down);
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
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 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
184 {
2c24602be78f 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 // wildcard 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
186 // named 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
187 // look for all instances of a section by the specified name
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
188 // and resolve base addresses and add to the list
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
189 for (fn = 0; fn < ninputfiles; fn++)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
190 {
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
191 check_section_flags(yesflags, noflags, base, inputfiles[fn], down);
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
192 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
193 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
194 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
195
2c24602be78f 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 // work out section load order and resolve base addresses for each 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
197 // make a list of sections to load in order
2c24602be78f 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 void resolve_sections(void)
2c24602be78f 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 int laddr = 0;
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
201 int growdown = 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
202 int ln, sn, fn;
236
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
203 sectopt_t *so;
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
204
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
205 for (ln = 0; ln < linkscript.nlines; ln++)
2c24602be78f 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 {
2c24602be78f 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 if (linkscript.lines[ln].loadat >= 0)
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
208 {
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
209 laddr = linkscript.lines[ln].loadat;
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
210 growdown = linkscript.lines[ln].growsdown;
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
211 }
511
4f6b2c615818 Remove stray debugging message.
William Astle <lost@l-w.ca>
parents: 510
diff changeset
212 //fprintf(stderr, "Adding section %s\n", linkscript.lines[ln].sectname);
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
213 add_matching_sections(linkscript.lines[ln].sectname, linkscript.lines[ln].yesflags, linkscript.lines[ln].noflags, &laddr, growdown);
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
214
2c24602be78f 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 if (linkscript.lines[ln].sectname)
2c24602be78f 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 {
236
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
217 char *sname = linkscript.lines[ln].sectname;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
218 /* handle "after padding" */
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
219 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: 235
diff changeset
220 if (!strcmp(so -> name, sname))
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
221 break;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
222 if (so)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
223 {
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
224 if (so -> aftersize)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
225 {
510
3425005b9980 Fix segfault if no instances of a section are in the final result
William Astle <lost@l-w.ca>
parents: 445
diff changeset
226 if (nsects == 0)
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
227 {
510
3425005b9980 Fix segfault if no instances of a section are in the final result
William Astle <lost@l-w.ca>
parents: 445
diff changeset
228 fprintf(stderr, "Warning: no instances of section listed in link script: %s\n", sname);
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
229 }
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
230 else
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
231 {
510
3425005b9980 Fix segfault if no instances of a section are in the final result
William Astle <lost@l-w.ca>
parents: 445
diff changeset
232 sectlist[nsects - 1].ptr -> afterbytes = so -> afterbytes;
3425005b9980 Fix segfault if no instances of a section are in the final result
William Astle <lost@l-w.ca>
parents: 445
diff changeset
233 sectlist[nsects - 1].ptr -> aftersize = so -> aftersize;
3425005b9980 Fix segfault if no instances of a section are in the final result
William Astle <lost@l-w.ca>
parents: 445
diff changeset
234 if (growdown)
3425005b9980 Fix segfault if no instances of a section are in the final result
William Astle <lost@l-w.ca>
parents: 445
diff changeset
235 {
3425005b9980 Fix segfault if no instances of a section are in the final result
William Astle <lost@l-w.ca>
parents: 445
diff changeset
236 if (sectlist) sectlist[nsects-1].ptr -> loadaddress -= so -> aftersize;
3425005b9980 Fix segfault if no instances of a section are in the final result
William Astle <lost@l-w.ca>
parents: 445
diff changeset
237 laddr -= so -> aftersize;
3425005b9980 Fix segfault if no instances of a section are in the final result
William Astle <lost@l-w.ca>
parents: 445
diff changeset
238 }
3425005b9980 Fix segfault if no instances of a section are in the final result
William Astle <lost@l-w.ca>
parents: 445
diff changeset
239 else
3425005b9980 Fix segfault if no instances of a section are in the final result
William Astle <lost@l-w.ca>
parents: 445
diff changeset
240 {
3425005b9980 Fix segfault if no instances of a section are in the final result
William Astle <lost@l-w.ca>
parents: 445
diff changeset
241 laddr += so -> aftersize;
3425005b9980 Fix segfault if no instances of a section are in the final result
William Astle <lost@l-w.ca>
parents: 445
diff changeset
242 }
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
243 }
236
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
244 }
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
245 }
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
246 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
247 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
248 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
249 // wildcard 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
250 // look for all sections not yet processed that match 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
251
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
252 int f = 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
253 int fn0, sn0;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
254 char *sname;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
255
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
256 // named 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
257 // look for all instances of a section by the specified name
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
258 // and resolve base addresses and add to the list
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
259 for (fn0 = 0; fn0 < ninputfiles; fn0++)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
260 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
261 for (sn0 = 0; sn0 < inputfiles[fn0] -> nsections; sn0++)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
262 {
156
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
263 // ignore "constant" sections
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
264 if (inputfiles[fn0] -> sections[sn0].flags & SECTION_CONST)
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
265 continue;
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
266 // ignore if the "no flags" bit says to
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
267 if (linkscript.lines[ln].noflags && (inputfiles[fn0] -> sections[sn0].flags & linkscript.lines[ln].noflags))
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
268 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
269 // ignore unless the yes flags tell us not to
2
7317fbe024af Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents: 0
diff changeset
270 if (linkscript.lines[ln].yesflags && ((inputfiles[fn0] -> sections[sn0].flags & linkscript.lines[ln].yesflags) == 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
271 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
272 if (inputfiles[fn0] -> sections[sn0].processed == 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
273 {
2
7317fbe024af Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents: 0
diff changeset
274 sname = (char *)(inputfiles[fn0] -> sections[sn0].name);
236
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
275 fprintf(stderr, "Adding sectoin %s\n", sname);
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
276 for (fn = 0; fn < ninputfiles; fn++)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
277 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
278 for (sn = 0; sn < inputfiles[fn] -> nsections; sn++)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
279 {
2
7317fbe024af Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents: 0
diff changeset
280 if (!strcmp(sname, (char *)(inputfiles[fn] -> sections[sn].name)))
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
281 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
282 // we have a match
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
283 sectlist = lw_realloc(sectlist, sizeof(struct section_list) * (nsects + 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
284 sectlist[nsects].ptr = &(inputfiles[fn] -> sections[sn]);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
285
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
286 inputfiles[fn] -> sections[sn].processed = 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
287 if (!f && linkscript.lines[ln].loadat >= 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
288 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
289 f = 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
290 sectlist[nsects].forceaddr = 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
291 laddr = linkscript.lines[ln].loadat;
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
292 growdown = linkscript.lines[ln].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
293 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
294 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
295 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
296 sectlist[nsects].forceaddr = 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
297 }
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
298 if (growdown)
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
299 {
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
300 laddr -= inputfiles[fn] -> sections[sn].codesize;
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
301 inputfiles[fn] -> sections[sn].loadaddress = laddr;
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
302 }
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
303 else
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
304 {
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
305 inputfiles[fn] -> sections[sn].loadaddress = laddr;
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
306 laddr += inputfiles[fn] -> sections[sn].codesize;
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
307 }
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
308 nsects++;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
309 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
310 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
311 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
312 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
313 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
314 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
315 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
316 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
317
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
318 // theoretically, all the base addresses are set now
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
319 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
320
234
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
321 /* run through all sections and generate any synthetic symbols */
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
322 void generate_symbols(void)
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
323 {
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
324 int sn;
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
325 char *lastsect = NULL;
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
326 char sym[256];
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
327 int len;
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
328 symlist_t *se;
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
329 int lowaddr;
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
330
234
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
331 for (sn = 0; sn < nsects; sn++)
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
332 {
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
333 if (!lastsect || strcmp(lastsect, (char *)(sectlist[sn].ptr -> name)))
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
334 {
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
335 if (lastsect && linkscript.lensympat)
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
336 {
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
337 /* handle length symbol */
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
338 se = lw_alloc(sizeof(symlist_t));
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
339 se -> val = len;
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
340 snprintf(sym, 255, linkscript.lensympat, lastsect);
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
341 se -> sym = lw_strdup(sym);
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
342 se -> next = symlist;
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
343 symlist = se;
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
344 }
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
345 if (lastsect && linkscript.basesympat)
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
346 {
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
347 se = lw_alloc(sizeof(symlist_t));
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
348 se -> val = lowaddr;
234
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
349 snprintf(sym, 255, linkscript.basesympat, lastsect);
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
350 se -> sym = lw_strdup(sym);
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
351 se -> next = symlist;
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
352 symlist = se;
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
353 }
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
354 lastsect = (char *)(sectlist[sn].ptr -> name);
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
355 len = 0;
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
356 lowaddr = sectlist[sn].ptr -> loadaddress;
234
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
357 }
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
358 len += sectlist[sn].ptr -> codesize;
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
359 if (sectlist[sn].ptr -> loadaddress < lowaddr)
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
360 lowaddr = sectlist[sn].ptr -> loadaddress;
234
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
361 }
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
362 if (lastsect && linkscript.lensympat)
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
363 {
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
364 /* handle length symbol */
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
365 se = lw_alloc(sizeof(symlist_t));
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
366 se -> val = len;
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
367 snprintf(sym, 255, linkscript.lensympat, lastsect);
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
368 se -> sym = lw_strdup(sym);
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
369 se -> next = symlist;
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
370 symlist = se;
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
371 }
315
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
372 if (lastsect && linkscript.basesympat)
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
373 {
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
374 se = lw_alloc(sizeof(symlist_t));
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
375 se -> val = lowaddr;
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
376 snprintf(sym, 255, linkscript.basesympat, lastsect);
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
377 se -> sym = lw_strdup(sym);
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
378 se -> next = symlist;
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
379 symlist = se;
fcd103148aa6 Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents: 264
diff changeset
380 }
234
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
381 }
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
382
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
383 lw_expr_stack_t *find_external_sym_recurse(char *sym, fileinfo_t *fn)
2c24602be78f 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 {
2c24602be78f 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 int sn;
2c24602be78f 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 lw_expr_stack_t *r;
2c24602be78f 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 lw_expr_term_t *term;
2c24602be78f 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 symtab_t *se;
2c24602be78f 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 int val;
2c24602be78f 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
2c24602be78f 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 for (sn = 0; sn < fn -> nsections; sn++)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
392 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
393 for (se = fn -> sections[sn].exportedsyms; se; se = se -> next)
2c24602be78f 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 {
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
395 // fprintf(stderr, " Considering %s\n", se -> sym);
2
7317fbe024af Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents: 0
diff changeset
396 if (!strcmp(sym, (char *)(se -> sym)))
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
397 {
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
398 // fprintf(stderr, " Match (%d)\n", fn -> sections[sn].processed);
156
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
399 // if the section was not previously processed and is CONSTANT, force it in
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
400 // otherwise error out if it is not being processed
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
401 if (fn -> sections[sn].processed == 0)
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
402 {
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
403 if (fn -> sections[sn].flags & SECTION_CONST)
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
404 {
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
405 // add to section list
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
406 sectlist = lw_realloc(sectlist, sizeof(struct section_list) * (nsects + 1));
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
407 sectlist[nsects].ptr = &(fn -> sections[sn]);
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
408 fn -> sections[sn].processed = 1;
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
409 fn -> sections[sn].loadaddress = 0;
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
410 nsects++;
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
411 }
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
412 else
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
413 {
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
414 if (resolveonly == 0)
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
415 {
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
416 fprintf(stderr, "Symbol %s found in section %s (%s) which is not going to be included\n", sym, fn -> sections[sn].name, fn -> filename);
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
417 continue;
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
418 }
156
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
419 }
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
420 }
155
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
421 // fprintf(stderr, "Found symbol %s in %s\n", sym, fn -> filename);
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
422 if (!(fn -> forced))
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
423 {
155
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
424 // fprintf(stderr, " Forced\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
425 fn -> forced = 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
426 nforced = 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
427 }
156
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
428 if (fn -> sections[sn].flags & SECTION_CONST)
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
429 val = se -> offset;
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
430 else
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
431 val = se -> offset + fn -> sections[sn].loadaddress;
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 r = lw_expr_stack_create();
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
433 term = lw_expr_term_create_int(val & 0xffff);
2c24602be78f 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 lw_expr_stack_push(r, term);
2c24602be78f 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 lw_expr_term_free(term);
156
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
436
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
437 return r;
2c24602be78f 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 }
2c24602be78f 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 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
440 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
441
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
442 for (sn = 0; sn < fn -> nsubs; sn++)
2c24602be78f 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 {
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
444 // fprintf(stderr, "Looking in %s\n", fn -> subs[sn] -> filename);
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
445 r = find_external_sym_recurse(sym, fn -> subs[sn]);
2c24602be78f 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 if (r)
2c24602be78f 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 {
155
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
448 // fprintf(stderr, "Found symbol %s in %s\n", sym, fn -> filename);
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
449 if (!(fn -> forced))
2c24602be78f 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 {
155
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
451 // fprintf(stderr, " Forced\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
452 nforced = 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
453 fn -> forced = 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
454 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
455 return r;
2c24602be78f 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 }
2c24602be78f 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 return 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 }
2c24602be78f 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
2c24602be78f 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 // resolve all incomplete references now
2c24602be78f 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 // anything that is unresolvable at this stage will throw an error
2c24602be78f 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 // because we know the load address of every section now
2c24602be78f 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 lw_expr_stack_t *resolve_sym(char *sym, int symtype, void *state)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
465 {
2c24602be78f 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 section_t *sect = state;
2c24602be78f 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 lw_expr_term_t *term;
2c24602be78f 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 int val = 0, i, fn;
2c24602be78f 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 lw_expr_stack_t *s;
2c24602be78f 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 symtab_t *se;
2c24602be78f 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 fileinfo_t *fp;
2c24602be78f 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
155
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
473 // fprintf(stderr, "Looking up %s\n", sym);
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
474
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
475 if (symtype == 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
476 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
477 // local symbol
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
478 if (!sym)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
479 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
480 val = sect -> loadaddress;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
481 goto 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
482 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
483
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
484 // start with this 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
485 for (se = sect -> localsyms; se; se = se -> next)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
486 {
2
7317fbe024af Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents: 0
diff changeset
487 if (!strcmp((char *)(se -> sym), sym))
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
488 {
156
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
489 if (sect -> flags & SECTION_CONST)
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
490 val = se -> offset;
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
491 else
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
492 val = se -> offset + sect -> loadaddress;
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
493 goto 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
494 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
495 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
496 // not in this section - check all sections in this 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
497 for (i = 0; i < sect -> file -> nsections; 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
498 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
499 for (se = sect -> file -> sections[i].localsyms; se; se = se -> next)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
500 {
2
7317fbe024af Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents: 0
diff changeset
501 if (!strcmp((char *)(se -> sym), sym))
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
502 {
156
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
503 if (sect -> file -> sections[i].flags & SECTION_CONST)
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
504 val = se -> offset;
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
505 else
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
506 val = se -> offset + sect -> file -> sections[i].loadaddress;
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
507 goto 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
508 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
509 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
510 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
511 // not found
235
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
512 if (!quietsym)
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
513 {
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
514 symerr = 1;
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
515 fprintf(stderr, "Local symbol %s not found in %s:%s\n", sanitize_symbol(sym), sect -> file -> filename, sect -> name);
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
516 }
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
517 goto outerr;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
518 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
519 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
520 {
234
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
521 symlist_t *se;
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
522
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
523 // external symbol
234
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
524 // first look up synthesized symbols
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
525 for (se = symlist; se; se = se -> next)
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
526 {
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
527 if (!strcmp(se -> sym, sym))
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
528 {
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
529 val = se -> val;
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
530 goto out;
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
531 }
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
532 }
d389adbcc4ab Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents: 157
diff changeset
533
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
534 // read all files in order until found (or not found)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
535 if (sect)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
536 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
537 for (fp = sect -> file; fp; fp = fp -> parent)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
538 {
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
539 // fprintf(stderr, "Looking in %s\n", fp -> filename);
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
540 s = find_external_sym_recurse(sym, fp);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
541 if (s)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
542 return s;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
543 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
544 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
545
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
546 for (fn = 0; fn < ninputfiles; fn++)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
547 {
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
548 // fprintf(stderr, "Looking in %s\n", inputfiles[fn] -> filename);
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
549 s = find_external_sym_recurse(sym, inputfiles[fn]);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
550 if (s)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
551 return s;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
552 }
235
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
553 if (!quietsym)
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
554 {
235
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
555 if (sect)
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
556 {
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
557 fprintf(stderr, "External symbol %s not found in %s:%s\n", sanitize_symbol(sym), sect -> file -> filename, sect -> name);
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
558 }
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
559 else
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
560 {
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
561 fprintf(stderr, "External symbol %s not found\n", sym);
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
562 }
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
563 symerr = 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
564 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
565 goto outerr;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
566 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
567 fprintf(stderr, "Shouldn't ever get here!!!\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
568 exit(88);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
569 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
570 s = lw_expr_stack_create();
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
571 term = lw_expr_term_create_int(val & 0xffff);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
572 lw_expr_stack_push(s, term);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
573 lw_expr_term_free(term);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
574 return s;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
575 outerr:
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
576 return 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
577 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
578
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
579 void resolve_references(void)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
580 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
581 int sn;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
582 reloc_t *rl;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
583 int rval;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
584
235
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
585 quietsym = 0;
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
586
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
587 // resolve entry point if required
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
588 // this must resolve to an *exported* symbol and will resolve to 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
589 // first instance of that symbol
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
590 if (linkscript.execsym)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
591 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
592 lw_expr_stack_t *s;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
593
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
594 s = resolve_sym(linkscript.execsym, 0, 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
595 if (!s)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
596 {
235
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
597 fprintf(stderr, "Cannot resolve exec address '%s'\n", linkscript.execsym);
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
598 symerr = 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
599 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
600 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
601 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
602 linkscript.execaddr = lw_expr_get_value(s);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
603 lw_expr_stack_free(s);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
604 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
605 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
606
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
607 for (sn = 0; sn < nsects; sn++)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
608 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
609 for (rl = sectlist[sn].ptr -> incompletes; rl; rl = rl -> next)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
610 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
611 // do a "simplify" on the expression
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
612 rval = lw_expr_reval(rl -> expr, resolve_sym, sectlist[sn].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
613
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
614 // is it constant? error out 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
615 if (rval != 0 || !lw_expr_is_constant(rl -> expr))
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
616 {
235
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
617 fprintf(stderr, "Incomplete reference at %s:%s+%02X\n", sectlist[sn].ptr -> file -> filename, sectlist[sn].ptr -> name, rl -> offset);
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
618 symerr = 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
619 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
620 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
621 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
622 // put the value into the relocation address
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
623 rval = lw_expr_get_value(rl -> expr);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
624 if (rl -> flags & RELOC_8BIT)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
625 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
626 sectlist[sn].ptr -> code[rl -> offset] = rval & 0xff;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
627 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
628 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
629 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
630 sectlist[sn].ptr -> code[rl -> offset] = (rval >> 8) & 0xff;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
631 sectlist[sn].ptr -> code[rl -> offset + 1] = rval & 0xff;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
632 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
633 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
634 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
635 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
636
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
637 if (symerr)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
638 exit(1);
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
639
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
640 if (outformat == OUTPUT_OS9)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
641 check_os9();
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
642 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
643
155
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
644 void resolve_files_aux(fileinfo_t *fn)
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
645 {
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
646 int sn;
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
647 reloc_t *rl;
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
648 lw_expr_stack_t *te;
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
649
264
346966cffeef Clean up various warnings when building under -Wall
William Astle <lost@l-w.ca>
parents: 263
diff changeset
650 // int rval;
155
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
651
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
652
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
653 if (fn -> forced == 0)
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
654 return;
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
655
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
656 for (sn = 0; sn < fn -> nsections; sn++)
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
657 {
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
658 for (rl = fn -> sections[sn].incompletes; rl; rl = rl -> next)
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
659 {
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
660 // do a "simplify" on the expression
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
661 te = lw_expr_stack_dup(rl -> expr);
264
346966cffeef Clean up various warnings when building under -Wall
William Astle <lost@l-w.ca>
parents: 263
diff changeset
662 lw_expr_reval(te, resolve_sym, &(fn -> sections[sn]));
155
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
663
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
664 // is it constant? error out if not
235
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
665 // incompletes will error out during resolve_references()
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
666 //if (rval != 0 || !lw_expr_is_constant(te))
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
667 //{
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
668 // fprintf(stderr, "Incomplete reference at %s:%s+%02X\n", fn -> filename, fn -> sections[sn].name, rl -> offset);
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
669 // symerr = 1;
e3741cf53e00 Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents: 234
diff changeset
670 //}
155
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
671 lw_expr_stack_free(te);
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
672 }
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
673 }
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
674
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
675 // handle any sub files
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
676 for (sn = 0; sn < fn -> nsubs; sn++)
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
677 resolve_files_aux(fn -> subs[sn]);
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
678 }
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
679
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
680 /*
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
681 This is just a pared down version of the algo for resolving references.
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
682 */
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
683 void resolve_files(void)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
684 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
685 int fn;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
686
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
687 resolveonly = 1;
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
688
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
689 // resolve entry point if required
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
690 // this must resolve to an *exported* symbol and will resolve to 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
691 // first instance of that symbol
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
692 // if (linkscript.execsym)
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
693 // {
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
694 // lw_expr_stack_t *s;
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
695 //
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
696 // s = resolve_sym(linkscript.execsym, 0, NULL);
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
697 // if (!s)
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
698 // {
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
699 // fprintf(stderr, "Cannot resolve exec address '%s'\n", sanitize_symbol(linkscript.execsym));
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
700 // symerr = 1;
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
701 // }
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
702 // }
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
703
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
704 do
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
705 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
706 nforced = 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
707 for (fn = 0; fn < ninputfiles; fn++)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
708 {
155
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
709 resolve_files_aux(inputfiles[fn]);
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
710 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
711 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
712 while (nforced == 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
713
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
714 resolveonly = 0;
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
715
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
716 // if (symerr)
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
717 // exit(1);
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
718
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
719 symerr = 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
720 // theoretically, all files referenced by other files now have "forced" set to 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
721 for (fn = 0; fn < ninputfiles; fn++)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
722 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
723 if (inputfiles[fn] -> forced == 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
724 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
725
445
9c6204534ab8 Improve diagnostic message from lwlink when an object isn't needed
William Astle <lost@l-w.ca>
parents: 386
diff changeset
726 fprintf(stderr, "Warning: library -l%s (%d) does not resolve any symbols\n", inputfiles[fn] -> filename, fn);
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
727 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
728 }
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
729 void find_section_by_name_once_aux(char *name, fileinfo_t *fn, section_t **rval, int *found);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
730 void find_section_by_name_once_aux(char *name, fileinfo_t *fn, section_t **rval, int *found)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
731 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
732 int sn;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
733
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
734 if (fn -> forced == 0)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
735 return;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
736
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
737 for (sn = 0; sn < fn -> nsections; sn++)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
738 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
739 if (!strcmp(name, (char *)(fn -> sections[sn].name)))
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
740 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
741 (*found)++;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
742 *rval = &(fn -> sections[sn]);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
743 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
744 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
745 for (sn = 0; sn < fn -> nsubs; sn++)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
746 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
747 find_section_by_name_once_aux(name, fn -> subs[sn], rval, found);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
748 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
749 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
750
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
751 section_t *find_section_by_name_once(char *name)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
752 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
753 int fn;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
754 int found = 0;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
755 section_t *rval = NULL;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
756
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
757 for (fn = 0; fn < ninputfiles; fn++)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
758 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
759 find_section_by_name_once_aux(name, inputfiles[fn], &rval, &found);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
760 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
761 if (found != 1)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
762 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
763 rval = NULL;
149
729a9c70934e Fixed crash and bogus warning with os9 module target
lost@l-w.ca
parents: 148
diff changeset
764 if (found > 1)
729a9c70934e Fixed crash and bogus warning with os9 module target
lost@l-w.ca
parents: 148
diff changeset
765 fprintf(stderr, "Warning: multiple instances of section %s found; ignoring all of them which is probably not what you want\n", name);
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
766 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
767 return rval;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
768 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
769
258
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
770 void foreach_section_aux(char *name, fileinfo_t *fn, void (*fnp)(section_t *s, void *arg), void *arg)
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
771 {
258
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
772 int sn;
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
773
258
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
774 if (fn -> forced == 0)
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
775 return;
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
776
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
777 for (sn = 0; sn < fn -> nsections; sn++)
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
778 {
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
779 if (!strcmp(name, (char *)(fn -> sections[sn].name)))
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
780 {
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
781 (*fnp)(&(fn -> sections[sn]), arg);
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
782 }
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
783 }
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
784 for (sn = 0; sn < fn -> nsubs; sn++)
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
785 {
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
786 foreach_section_aux(name, fn -> subs[sn], fnp, arg);
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
787 }
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
788 }
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
789 void foreach_section(char *name, void (*fnp)(section_t *s, void *arg), void *arg)
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
790 {
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
791 int fn;
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
792
258
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
793 for (fn = 0; fn < ninputfiles; fn++)
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
794 {
258
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
795 foreach_section_aux(name, inputfiles[fn], fnp, arg);
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
796 }
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
797 }
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
798
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
799 struct check_os9_aux_s
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
800 {
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
801 int typeseen;
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
802 int attrseen;
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
803 int langseen;
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
804 int revseen;
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
805 int nameseen;
262
7de7b14ebaee Add support for os9 module edition byte
William Astle <lost@l-w.ca>
parents: 258
diff changeset
806 int edseen;
258
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
807 };
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
808
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
809 void check_os9_aux(section_t *s, void *arg)
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
810 {
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
811 struct check_os9_aux_s *st = arg;
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
812 symtab_t *sym;
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
813
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
814 // this section is special
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
815 // several symbols may be defined as LOCAL symbols:
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
816 // type: module type
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
817 // lang: module language
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
818 // attr: module attributes
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
819 // rev: module revision
262
7de7b14ebaee Add support for os9 module edition byte
William Astle <lost@l-w.ca>
parents: 258
diff changeset
820 // ed: module edition
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
821 //
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
822 // the symbols are not case sensitive
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
823 //
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
824 // any unrecognized symbols are ignored
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
825
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
826 // the contents of the actual data to the first NUL
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
827 // is assumed to be the module name unless it is an empty string
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
828 if (s -> codesize > 0 && (s -> flags & SECTION_BSS) == 0 && s -> code[0] != 0)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
829 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
830 linkscript.name = (char *)(s -> code);
258
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
831 st -> nameseen++;
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
832 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
833
149
729a9c70934e Fixed crash and bogus warning with os9 module target
lost@l-w.ca
parents: 148
diff changeset
834 for (sym = s -> localsyms; sym; sym = sym -> next)
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
835 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
836 char *sm = (char *)(sym -> sym);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
837 if (!strcasecmp(sm, "type"))
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
838 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
839 linkscript.modtype = sym -> offset;
258
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
840 st -> typeseen++;
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
841 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
842 else if (!strcasecmp(sm, "lang"))
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
843 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
844 linkscript.modlang = sym -> offset;
258
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
845 st -> langseen++;
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
846 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
847 else if (!strcasecmp(sm, "attr"))
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
848 {
257
d5374e80dd04 Fix handling of attr override for os9 output
William Astle <lost@l-w.ca>
parents: 238
diff changeset
849 linkscript.modattr = sym -> offset;
258
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
850 st -> attrseen++;
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
851 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
852 else if (!strcasecmp(sm, "rev"))
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
853 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
854 linkscript.modrev = sym -> offset;
258
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
855 st -> revseen++;
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
856 }
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
857 else if (!strcasecmp(sm, "stack"))
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
858 {
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
859 linkscript.stacksize += sym -> offset;
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
860 }
263
8dd8c3bdca7c Fix stupid error with ' vs " handling os9 edition
William Astle <lost@l-w.ca>
parents: 262
diff changeset
861 else if (!strcasecmp(sm, "edition"))
262
7de7b14ebaee Add support for os9 module edition byte
William Astle <lost@l-w.ca>
parents: 258
diff changeset
862 {
7de7b14ebaee Add support for os9 module edition byte
William Astle <lost@l-w.ca>
parents: 258
diff changeset
863 linkscript.edition = sym -> offset;
7de7b14ebaee Add support for os9 module edition byte
William Astle <lost@l-w.ca>
parents: 258
diff changeset
864 st -> edseen++;
7de7b14ebaee Add support for os9 module edition byte
William Astle <lost@l-w.ca>
parents: 258
diff changeset
865 }
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
866 }
258
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
867 }
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
868
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
869 void check_os9(void)
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
870 {
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
871 struct check_os9_aux_s st = { 0 };
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
872
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
873 linkscript.name = outfile;
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
874 foreach_section("__os9", check_os9_aux, &st);
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
875 if (linkscript.modtype > 15)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
876 linkscript.modtype = linkscript.modtype >> 4;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
877
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
878 if (linkscript.modattr > 15)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
879 linkscript.modattr = linkscript.modattr >> 4;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
880
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
881 linkscript.modlang &= 15;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
882 linkscript.modtype &= 15;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
883 linkscript.modrev &= 15;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
884 linkscript.modattr &= 15;
258
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
885
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
886 if (st.attrseen > 1 || st.typeseen > 1 ||
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
887 st.langseen > 1 || st.revseen > 1 ||
264
346966cffeef Clean up various warnings when building under -Wall
William Astle <lost@l-w.ca>
parents: 263
diff changeset
888 st.nameseen > 1 || st.edseen > 1
258
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
889 )
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
890 {
262
7de7b14ebaee Add support for os9 module edition byte
William Astle <lost@l-w.ca>
parents: 258
diff changeset
891 fprintf(stderr, "Warning: multiple instances of __os9 found with duplicate settings of type, lang, attr, rev, edition, or module name.\n");
258
ebda5c96665e Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents: 257
diff changeset
892 }
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
893 }
236
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
894
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
895 void resolve_padding(void)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
896 {
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
897 int sn;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
898
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
899 for (sn = 0; sn < nsects; sn++)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
900 {
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
901 if (sectlist[sn].ptr -> afterbytes)
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
902 {
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
903 unsigned char *t;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
904
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
905 t = lw_alloc(sectlist[sn].ptr -> codesize + sectlist[sn].ptr -> aftersize);
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
906 memmove(t, sectlist[sn].ptr -> code, sectlist[sn].ptr -> codesize);
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
907 sectlist[sn].ptr -> code = t;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
908 memmove(sectlist[sn].ptr -> code + sectlist[sn].ptr -> codesize, sectlist[sn].ptr -> afterbytes, sectlist[sn].ptr -> aftersize);
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
909 sectlist[sn].ptr -> codesize += sectlist[sn].ptr -> aftersize;
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
910 }
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
911 }
ce1fdc8d6568 Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents: 235
diff changeset
912 }