Mercurial > hg > index.cgi
annotate lwlink/link.c @ 247:4b36eaaf80c3
First attempt at fixing the drive letter problem on Windows
Absolute paths in windows cannot be detected by simply checking for a
leading slash, even in MinGW. Instead, apply a heuristic that looks for
either a leading slash or a letter followed by a colon. This heuristic is
only activated on windows builds.
author | William Astle <lost@l-w.ca> |
---|---|
date | Thu, 24 Jan 2013 21:00:00 -0700 |
parents | 91f91557dc9e |
children | d5374e80dd04 |
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 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
24 #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
|
25 #include <stdlib.h> |
2
7317fbe024af
Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents:
0
diff
changeset
|
26 #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
|
27 |
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
|
28 #include <lw_alloc.h> |
234
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
29 #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
|
30 |
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
|
31 #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
|
32 #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
|
33 |
148 | 34 void check_os9(void); |
35 | |
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
|
36 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
|
37 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
|
38 static int nforced = 0; |
157
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
39 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
|
40 |
235
e3741cf53e00
Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
41 int quietsym = 1; |
e3741cf53e00
Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
42 |
234
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
43 symlist_t *symlist = NULL; |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
44 |
236
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
45 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
|
46 |
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
|
47 void check_section_name(char *name, int *base, 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
|
48 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
49 int sn; |
157
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
50 // 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
|
51 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
|
52 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
|
53 |
2c24602be78f
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 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
|
55 { |
157
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
56 // fprintf(stderr, " Considering section %s\n", fn -> sections[sn].name); |
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
57 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
|
58 { |
157
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
59 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
|
60 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
|
61 // we have a match |
157
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
62 // 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
|
63 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
|
64 sectlist[nsects].ptr = &(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
|
65 |
2c24602be78f
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 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
|
67 fn -> sections[sn].loadaddress = *base; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
68 *base += fn -> sections[sn].codesize; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
69 nsects++; |
157
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
70 // fprintf(stderr, "Adding section %s (%s)\n",fn -> sections[sn].name, 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
|
71 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
72 } |
2c24602be78f
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 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
|
74 { |
2c24602be78f
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 check_section_name(name, base, 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
|
76 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
77 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
78 |
2c24602be78f
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 void add_matching_sections(char *name, int yesflags, int noflags, int *base); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
80 void check_section_flags(int yesflags, int noflags, int *base, 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
|
81 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
82 int sn; |
236
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
83 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
|
84 |
157
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
85 // 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
|
86 |
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
|
87 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
|
88 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
|
89 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
90 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
|
91 { |
157
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
92 // 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
|
93 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
|
94 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
|
95 // 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
|
96 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
|
97 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
|
98 // 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
|
99 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
|
100 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
|
101 // 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
|
102 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
|
103 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
|
104 |
2c24602be78f
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 // 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
|
106 // fprintf(stderr, " Found\n"); |
2
7317fbe024af
Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents:
0
diff
changeset
|
107 add_matching_sections((char *)(fn -> sections[sn].name), 0, 0, base); |
236
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
108 |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
109 /* handle "after padding" */ |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
110 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
|
111 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
|
112 break; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
113 if (so) |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
114 { |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
115 if (so -> aftersize) |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
116 { |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
117 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
|
118 sectlist[nsects - 1].ptr -> aftersize = so -> aftersize; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
119 *base += so -> aftersize; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
120 } |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
121 } |
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
|
122 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
123 // 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
|
124 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
125 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
|
126 { |
2c24602be78f
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 check_section_flags(yesflags, noflags, base, 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
|
128 } |
2c24602be78f
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 } |
2c24602be78f
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 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
131 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
132 |
2c24602be78f
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 void add_matching_sections(char *name, int yesflags, int noflags, int *base) |
2c24602be78f
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 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
135 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
|
136 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
|
137 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
138 // 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
|
139 // 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
|
140 // 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
|
141 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
|
142 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
143 check_section_name(name, base, 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
|
144 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
145 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
146 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
|
147 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
148 // 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
|
149 // 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
|
150 // 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
|
151 // 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
|
152 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
|
153 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
154 check_section_flags(yesflags, noflags, base, 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
|
155 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
156 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
157 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
158 |
2c24602be78f
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 // 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
|
160 // 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
|
161 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
|
162 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
163 int laddr = 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
|
164 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
|
165 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
|
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 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
|
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 if (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
|
170 laddr = linkscript.lines[ln].loadat; |
238
91f91557dc9e
Removed extraneous debug message.
William Astle <lost@l-w.ca>
parents:
236
diff
changeset
|
171 //fprintf(stderr, "Adding section %s\n", linkscript.lines[ln].sectname); |
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
|
172 add_matching_sections(linkscript.lines[ln].sectname, linkscript.lines[ln].yesflags, linkscript.lines[ln].noflags, &laddr); |
2c24602be78f
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 |
2c24602be78f
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 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
|
175 { |
236
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
176 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
|
177 /* handle "after padding" */ |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
178 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
|
179 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
|
180 break; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
181 if (so) |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
182 { |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
183 if (so -> aftersize) |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
184 { |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
185 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
|
186 sectlist[nsects - 1].ptr -> aftersize = so -> aftersize; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
187 laddr += so -> aftersize; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
188 } |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
189 } |
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
|
190 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
191 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
|
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 // 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
|
194 // 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
|
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 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
|
197 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
|
198 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
|
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 // 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
|
201 // 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
|
202 // 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
|
203 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
|
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 (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
|
206 { |
156
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
155
diff
changeset
|
207 // ignore "constant" sections |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
155
diff
changeset
|
208 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
|
209 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
|
210 // 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
|
211 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
|
212 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
|
213 // 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
|
214 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
|
215 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
|
216 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
|
217 { |
2
7317fbe024af
Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents:
0
diff
changeset
|
218 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
|
219 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
|
220 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
|
221 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
222 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
|
223 { |
2
7317fbe024af
Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents:
0
diff
changeset
|
224 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
|
225 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
226 // 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
|
227 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
|
228 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
|
229 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
230 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
|
231 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
|
232 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
233 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
|
234 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
|
235 laddr = linkscript.lines[ln].loadat; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
236 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
237 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
|
238 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
239 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
|
240 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
241 inputfiles[fn] -> sections[sn].loadaddress = laddr; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
242 laddr += inputfiles[fn] -> sections[sn].codesize; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
243 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
|
244 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
245 } |
2c24602be78f
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 } |
2c24602be78f
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 } |
2c24602be78f
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 } |
2c24602be78f
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 |
2c24602be78f
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 // 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
|
254 } |
2c24602be78f
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 |
234
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
256 /* 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
|
257 void generate_symbols(void) |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
258 { |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
259 int sn; |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
260 char *lastsect = NULL; |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
261 char sym[256]; |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
262 int len; |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
263 symlist_t *se; |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
264 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
|
265 { |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
266 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
|
267 { |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
268 if (lastsect && linkscript.lensympat) |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
269 { |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
270 /* handle length symbol */ |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
271 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
|
272 se -> val = len; |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
273 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
|
274 se -> sym = lw_strdup(sym); |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
275 se -> next = symlist; |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
276 symlist = se; |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
277 } |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
278 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
|
279 len = 0; |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
280 /* handle base symbol */ |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
281 if (lastsect && linkscript.basesympat) |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
282 { |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
283 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
|
284 se -> val = sectlist[sn].ptr -> loadaddress; |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
285 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
|
286 se -> sym = lw_strdup(sym); |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
287 se -> next = symlist; |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
288 symlist = se; |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
289 } |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
290 } |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
291 len += sectlist[sn].ptr -> codesize; |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
292 } |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
293 if (lastsect && linkscript.lensympat) |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
294 { |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
295 /* handle length symbol */ |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
296 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
|
297 se -> val = len; |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
298 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
|
299 se -> sym = lw_strdup(sym); |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
300 se -> next = symlist; |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
301 symlist = se; |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
302 } |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
303 |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
304 } |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
305 |
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
|
306 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
|
307 { |
2c24602be78f
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 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
|
309 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
|
310 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
|
311 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
|
312 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
|
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 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
|
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 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
|
317 { |
157
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
318 // 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
|
319 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
|
320 { |
157
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
321 // 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
|
322 // 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
|
323 // 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
|
324 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
|
325 { |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
155
diff
changeset
|
326 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
|
327 { |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
155
diff
changeset
|
328 // add to section list |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
155
diff
changeset
|
329 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
|
330 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
|
331 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
|
332 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
|
333 nsects++; |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
155
diff
changeset
|
334 } |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
155
diff
changeset
|
335 else |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
155
diff
changeset
|
336 { |
157
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
337 if (resolveonly == 0) |
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
338 { |
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
339 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
|
340 continue; |
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
341 } |
156
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
155
diff
changeset
|
342 } |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
155
diff
changeset
|
343 } |
155
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
344 // 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
|
345 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
|
346 { |
155
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
347 // 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
|
348 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
|
349 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
|
350 } |
156
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
155
diff
changeset
|
351 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
|
352 val = se -> offset; |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
155
diff
changeset
|
353 else |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
155
diff
changeset
|
354 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
|
355 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
|
356 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
|
357 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
|
358 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
|
359 |
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
|
360 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
|
361 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
362 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
363 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
364 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
365 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
|
366 { |
157
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
367 // 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
|
368 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
|
369 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
|
370 { |
155
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
371 // 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
|
372 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
|
373 { |
155
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
374 // 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
|
375 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
|
376 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
|
377 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
378 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
|
379 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
380 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
381 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
|
382 } |
2c24602be78f
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 |
2c24602be78f
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 // 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
|
385 // 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
|
386 // 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
|
387 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
|
388 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
389 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
|
390 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
|
391 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
|
392 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
|
393 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
|
394 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
|
395 |
155
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
396 // 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
|
397 |
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
|
398 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
|
399 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
400 // 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
|
401 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
|
402 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
403 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
|
404 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
|
405 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
406 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
407 // 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
|
408 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
|
409 { |
2
7317fbe024af
Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents:
0
diff
changeset
|
410 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
|
411 { |
156
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
155
diff
changeset
|
412 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
|
413 val = se -> offset; |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
155
diff
changeset
|
414 else |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
155
diff
changeset
|
415 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
|
416 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
|
417 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
418 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
419 // 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
|
420 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
|
421 { |
2c24602be78f
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 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
|
423 { |
2
7317fbe024af
Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents:
0
diff
changeset
|
424 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
|
425 { |
156
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
155
diff
changeset
|
426 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
|
427 val = se -> offset; |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
155
diff
changeset
|
428 else |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
155
diff
changeset
|
429 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
|
430 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
|
431 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
432 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
433 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
434 // not found |
235
e3741cf53e00
Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
435 if (!quietsym) |
e3741cf53e00
Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
436 { |
e3741cf53e00
Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
437 symerr = 1; |
e3741cf53e00
Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
438 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
|
439 } |
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
|
440 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
|
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 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
|
443 { |
234
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
444 symlist_t *se; |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
445 |
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
|
446 // external symbol |
234
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
447 // first look up synthesized symbols |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
448 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
|
449 { |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
450 if (!strcmp(se -> sym, sym)) |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
451 { |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
452 val = se -> val; |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
453 goto out; |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
454 } |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
455 } |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
157
diff
changeset
|
456 |
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
|
457 // 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
|
458 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
|
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 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
|
461 { |
157
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
462 // 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
|
463 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
|
464 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
|
465 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
|
466 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
467 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
468 |
2c24602be78f
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 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
|
470 { |
157
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
471 // 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
|
472 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
|
473 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
|
474 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
|
475 } |
235
e3741cf53e00
Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
476 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
|
477 { |
235
e3741cf53e00
Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
478 if (sect) |
e3741cf53e00
Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
479 { |
e3741cf53e00
Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
480 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
|
481 } |
e3741cf53e00
Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
482 else |
e3741cf53e00
Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
483 { |
e3741cf53e00
Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
484 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
|
485 } |
e3741cf53e00
Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
486 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
|
487 } |
2c24602be78f
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 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
|
489 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
490 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
|
491 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
|
492 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
|
493 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
|
494 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
|
495 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
|
496 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
|
497 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
|
498 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
|
499 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
|
500 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
501 |
2c24602be78f
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 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
|
503 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
504 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
|
505 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
|
506 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
|
507 |
235
e3741cf53e00
Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
508 quietsym = 0; |
e3741cf53e00
Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
509 |
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
|
510 // 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
|
511 // 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
|
512 // 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
|
513 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
|
514 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
515 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
|
516 |
2c24602be78f
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 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
|
518 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
|
519 { |
235
e3741cf53e00
Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
520 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
|
521 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
|
522 } |
2c24602be78f
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 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
|
524 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
525 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
|
526 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
|
527 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
528 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
529 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
530 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
|
531 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
532 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
|
533 { |
2c24602be78f
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 // 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
|
535 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
|
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 // 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
|
538 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
|
539 { |
235
e3741cf53e00
Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
540 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
|
541 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
|
542 } |
2c24602be78f
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 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
|
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 // 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
|
546 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
|
547 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
|
548 { |
2c24602be78f
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 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
|
550 } |
2c24602be78f
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 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
|
552 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
553 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
|
554 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
|
555 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
556 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
557 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
558 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
559 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
560 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
|
561 exit(1); |
148 | 562 |
563 if (outformat == OUTPUT_OS9) | |
564 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
|
565 } |
2c24602be78f
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 |
155
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
567 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
|
568 { |
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
569 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
|
570 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
|
571 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
|
572 |
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
573 int rval; |
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
574 |
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
575 |
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
576 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
|
577 return; |
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
578 |
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
579 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
|
580 { |
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
581 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
|
582 { |
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
583 // 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
|
584 te = lw_expr_stack_dup(rl -> expr); |
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
585 rval = lw_expr_reval(te, resolve_sym, &(fn -> sections[sn])); |
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
586 |
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
587 // 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
|
588 // 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
|
589 //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
|
590 //{ |
e3741cf53e00
Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
591 // 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
|
592 // symerr = 1; |
e3741cf53e00
Fix error messages related to undefined symbols in lwlink
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
593 //} |
155
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
594 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
|
595 } |
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
596 } |
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
597 |
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
598 // 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
|
599 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
|
600 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
|
601 } |
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
602 |
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
|
603 /* |
2c24602be78f
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 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
|
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 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
|
607 { |
2c24602be78f
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 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
|
609 |
157
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
610 resolveonly = 1; |
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
611 |
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
|
612 // 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
|
613 // 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
|
614 // 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
|
615 // if (linkscript.execsym) |
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
616 // { |
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
617 // lw_expr_stack_t *s; |
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
618 // |
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
619 // 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
|
620 // if (!s) |
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
621 // { |
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
622 // 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
|
623 // symerr = 1; |
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
624 // } |
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
625 // } |
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
|
626 |
2c24602be78f
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 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
|
628 { |
2c24602be78f
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 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
|
630 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
|
631 { |
155
1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents:
149
diff
changeset
|
632 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
|
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 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
|
636 |
157
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
637 resolveonly = 0; |
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
638 |
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
639 // if (symerr) |
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
640 // exit(1); |
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
641 |
4682460aed00
Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents:
156
diff
changeset
|
642 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
|
643 // 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
|
644 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
|
645 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
646 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
|
647 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
|
648 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
649 fprintf(stderr, "Warning: %s (%d) does not resolve any symbols\n", inputfiles[fn] -> filename, 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
|
650 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
651 } |
148 | 652 void find_section_by_name_once_aux(char *name, fileinfo_t *fn, section_t **rval, int *found); |
653 void find_section_by_name_once_aux(char *name, fileinfo_t *fn, section_t **rval, int *found) | |
654 { | |
655 int sn; | |
656 | |
657 if (fn -> forced == 0) | |
658 return; | |
659 | |
660 for (sn = 0; sn < fn -> nsections; sn++) | |
661 { | |
662 if (!strcmp(name, (char *)(fn -> sections[sn].name))) | |
663 { | |
664 (*found)++; | |
665 *rval = &(fn -> sections[sn]); | |
666 } | |
667 } | |
668 for (sn = 0; sn < fn -> nsubs; sn++) | |
669 { | |
670 find_section_by_name_once_aux(name, fn -> subs[sn], rval, found); | |
671 } | |
672 } | |
673 | |
674 section_t *find_section_by_name_once(char *name) | |
675 { | |
676 int fn; | |
677 int found = 0; | |
678 section_t *rval = NULL; | |
679 | |
680 for (fn = 0; fn < ninputfiles; fn++) | |
681 { | |
682 find_section_by_name_once_aux(name, inputfiles[fn], &rval, &found); | |
683 } | |
684 if (found != 1) | |
685 { | |
686 rval = NULL; | |
149
729a9c70934e
Fixed crash and bogus warning with os9 module target
lost@l-w.ca
parents:
148
diff
changeset
|
687 if (found > 1) |
729a9c70934e
Fixed crash and bogus warning with os9 module target
lost@l-w.ca
parents:
148
diff
changeset
|
688 fprintf(stderr, "Warning: multiple instances of section %s found; ignoring all of them which is probably not what you want\n", name); |
148 | 689 } |
690 return rval; | |
691 } | |
692 | |
693 void check_os9(void) | |
694 { | |
695 section_t *s; | |
696 symtab_t *sym; | |
697 | |
698 s = find_section_by_name_once("__os9"); | |
699 linkscript.name = outfile; | |
700 | |
701 if (!s) | |
702 { | |
703 // use defaults if not found | |
704 return; | |
705 } | |
706 | |
707 // this section is special | |
708 // several symbols may be defined as LOCAL symbols: | |
709 // type: module type | |
710 // lang: module language | |
711 // attr: module attributes | |
712 // rev: module revision | |
713 // | |
714 // the symbols are not case sensitive | |
715 // | |
716 // any unrecognized symbols are ignored | |
717 | |
718 // the contents of the actual data to the first NUL | |
719 // is assumed to be the module name unless it is an empty string | |
720 if (s -> codesize > 0 && (s -> flags & SECTION_BSS) == 0 && s -> code[0] != 0) | |
721 { | |
722 linkscript.name = (char *)(s -> code); | |
723 } | |
724 | |
149
729a9c70934e
Fixed crash and bogus warning with os9 module target
lost@l-w.ca
parents:
148
diff
changeset
|
725 for (sym = s -> localsyms; sym; sym = sym -> next) |
148 | 726 { |
727 char *sm = (char *)(sym -> sym); | |
728 if (!strcasecmp(sm, "type")) | |
729 { | |
730 linkscript.modtype = sym -> offset; | |
731 } | |
732 else if (!strcasecmp(sm, "lang")) | |
733 { | |
734 linkscript.modlang = sym -> offset; | |
735 } | |
736 else if (!strcasecmp(sm, "attr")) | |
737 { | |
738 linkscript.modlang = sym -> offset; | |
739 } | |
740 else if (!strcasecmp(sm, "rev")) | |
741 { | |
742 linkscript.modrev = sym -> offset; | |
743 } | |
744 } | |
745 if (linkscript.modtype > 15) | |
746 linkscript.modtype = linkscript.modtype >> 4; | |
747 | |
748 if (linkscript.modattr > 15) | |
749 linkscript.modattr = linkscript.modattr >> 4; | |
750 | |
751 linkscript.modlang &= 15; | |
752 linkscript.modtype &= 15; | |
753 linkscript.modrev &= 15; | |
754 linkscript.modattr &= 15; | |
755 } | |
236
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
756 |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
757 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
|
758 { |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
759 int sn; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
760 |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
761 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
|
762 { |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
763 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
|
764 { |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
765 unsigned char *t; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
766 |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
767 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
|
768 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
|
769 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
|
770 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
|
771 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
|
772 } |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
773 } |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
235
diff
changeset
|
774 } |