annotate lwlink/link.c @ 157:4682460aed00

Correct bug with handling symbol resolution and constant section handling
author lost@l-w.ca
date Sun, 28 Aug 2011 11:45:38 -0600
parents fc8386b13399
children d389adbcc4ab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
1 /*
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
2 link.c
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
3 Copyright © 2009 William Astle
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
4
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
5 This file is part of LWLINK.
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
6
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
7 LWLINK is free software: you can redistribute it and/or modify it under the
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
10 version.
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
11
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
15 more details.
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
16
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
19
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
20
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
21 Resolve section and symbol addresses; handle incomplete references
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
22 */
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
23
2c24602be78f 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>
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
29
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
30 #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
31 #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
32
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
33 void check_os9(void);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
34
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
35 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
36 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
37 static int nforced = 0;
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
38 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
39
2c24602be78f 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 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
41 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
42 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
43
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
44 // 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
45 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
46 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
47
2c24602be78f 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 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
49 {
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
50 // 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
51 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
52 {
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
53 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
54 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
55 // we have a match
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
56 // 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
57 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
58 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
59
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
60 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
61 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
62 *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
63 nsects++;
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
64 // 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
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 }
2c24602be78f 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 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
68 {
2c24602be78f 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 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
70 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
71 }
2c24602be78f 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 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
74 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
75 {
2c24602be78f 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 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
77
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
78 // 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
79
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
80 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
81 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
82
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
83 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
84 {
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
85 // 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
86 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
87 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
88 // 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
89 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
90 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
91 // 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
92 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
93 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
94 // 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
95 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
96 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
97
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
98 // 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
99 // fprintf(stderr, " Found\n");
2
7317fbe024af Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents: 0
diff changeset
100 add_matching_sections((char *)(fn -> sections[sn].name), 0, 0, base);
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
101
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
102 // 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
103 }
2c24602be78f 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 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
105 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
106 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
107 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
108 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
109
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
110
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
111
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
112 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
113 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
114 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
115 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
116 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
117 // 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
118 // 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
119 // 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
120 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
121 {
2c24602be78f 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 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
123 }
2c24602be78f 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 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
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 // 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
128 // 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
129 // 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
130 // 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
131 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
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 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
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 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
136 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
137
2c24602be78f 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 // 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
139 // 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
140 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
141 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
142 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
143 int ln, sn, 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 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
146 {
2c24602be78f 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 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
148 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
149 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
150
2c24602be78f 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 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
152 {
2c24602be78f 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 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
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 // 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
157 // 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
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 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
160 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
161 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
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 // 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
164 // 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
165 // 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
166 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
167 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
168 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
169 {
156
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
170 // ignore "constant" sections
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
171 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
172 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
173 // 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
174 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
175 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
176 // 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
177 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
178 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
179 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
180 {
2
7317fbe024af Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents: 0
diff changeset
181 sname = (char *)(inputfiles[fn0] -> sections[sn0].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
182 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
183 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
184 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
185 {
2
7317fbe024af Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents: 0
diff changeset
186 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
187 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
188 // 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
189 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
190 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
191
2c24602be78f 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 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
193 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
194 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
195 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
196 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
197 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
198 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
199 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
200 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
201 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
202 }
2c24602be78f 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 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
204 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
205 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
206 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
207 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
208 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
209 }
2c24602be78f 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 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
211 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
212 }
2c24602be78f 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 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
214
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
215 // 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
216 }
2c24602be78f 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
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
218 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
219 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
220 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
221 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
222 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
223 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
224 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
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 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
227 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
228 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
229 {
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
230 // 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
231 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
232 {
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
233 // 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
234 // 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
235 // 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
236 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
237 {
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
238 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
239 {
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
240 // add to section list
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
241 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
242 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
243 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
244 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
245 nsects++;
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
246 }
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
247 else
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
248 {
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
249 if (resolveonly == 0)
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
250 {
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
251 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
252 continue;
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
253 }
156
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
254 }
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
255 }
155
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
256 // 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
257 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
258 {
155
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
259 // 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
260 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
261 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
262 }
156
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
263 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
264 val = se -> offset;
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
265 else
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
266 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
267 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
268 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
269 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
270 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
271
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
272 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
273 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
274 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
275 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
276
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
277 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
278 {
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
279 // 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
280 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
281 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
282 {
155
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
283 // 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
284 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
285 {
155
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
286 // 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
287 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
288 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
289 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
290 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
291 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
292 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
293 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
294 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
295
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
296 // 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
297 // 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
298 // 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
299 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
300 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
301 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
302 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
303 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
304 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
305 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
306 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
307
155
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
308 // 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
309
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
310 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
311 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
312 // 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
313 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
314 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
315 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
316 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
317 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
318
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
319 // 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
320 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
321 {
2
7317fbe024af Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents: 0
diff changeset
322 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
323 {
156
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
324 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
325 val = se -> offset;
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
326 else
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
327 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
328 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
329 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
330 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
331 // 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
332 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
333 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
334 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
335 {
2
7317fbe024af Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents: 0
diff changeset
336 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
337 {
156
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
338 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
339 val = se -> offset;
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
340 else
fc8386b13399 Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents: 155
diff changeset
341 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
342 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
343 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
344 }
2c24602be78f 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 }
2c24602be78f 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 // 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
347 symerr = 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
348 fprintf(stderr, "Local symbol %s not found in %s:%s\n", sanitize_symbol(sym), sect -> file -> filename, sect -> 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
349 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
350 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
351 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
352 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
353 // external 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
354 // 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
355 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
356 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
357 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
358 {
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
359 // 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
360 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
361 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
362 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
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
2c24602be78f 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 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
367 {
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
368 // 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
369 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
370 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
371 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
372 }
2c24602be78f 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 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
374 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
375 fprintf(stderr, "External symbol %s not found in %s:%s\n", sanitize_symbol(sym), sect -> file -> filename, sect -> 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
376 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
377 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
378 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
379 fprintf(stderr, "External symbol %s not found\n", 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
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 symerr = 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
382 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
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 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
385 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
386 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
387 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
388 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
389 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
390 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
391 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
392 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
393 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
394 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
395
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
396 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
397 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
398 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
399 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
400 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
401
2c24602be78f 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 // 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
403 // 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
404 // 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
405 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
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 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
408
2c24602be78f 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 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
410 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
411 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
412 fprintf(stderr, "Cannot resolve exec address '%s'\n", 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
413 symerr = 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
414 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
415 else
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
416 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
417 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
418 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
419 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
420 }
2c24602be78f 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 (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
423 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
424 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
425 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
426 // 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
427 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
428
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
429 // 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
430 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
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 fprintf(stderr, "Incomplete reference at %s:%s+%02X\n", sectlist[sn].ptr -> file -> filename, sectlist[sn].ptr -> name, rl -> offset);
2c24602be78f 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 symerr = 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
434 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
435 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
436 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
437 // 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
438 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
439 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
440 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
441 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
442 }
2c24602be78f 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 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
444 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
445 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
446 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
447 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
448 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
449 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
450 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
451
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
452 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
453 exit(1);
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
454
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
455 if (outformat == OUTPUT_OS9)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
456 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
457 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
458
155
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
459 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
460 {
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
461 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
462 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
463 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
464
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
465 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
466
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
467
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
468 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
469 return;
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
470
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
471 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
472 {
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
473 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
474 {
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
475 // 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
476 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
477 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
478
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
479 // is it constant? error out if not
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
480 if (rval != 0 || !lw_expr_is_constant(te))
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
481 {
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
482 fprintf(stderr, "Incomplete reference at %s:%s+%02X\n", fn -> filename, fn -> sections[sn].name, rl -> offset);
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
483 symerr = 1;
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
484 }
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
485 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
486 }
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
487 }
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
488
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
489 // 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
490 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
491 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
492 }
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
493
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
494 /*
2c24602be78f 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 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
496 */
2c24602be78f 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 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
498 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
499 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
500
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
501 resolveonly = 1;
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
502
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
503 // 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
504 // 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
505 // 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
506 // if (linkscript.execsym)
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
507 // {
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
508 // lw_expr_stack_t *s;
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
509 //
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
510 // 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
511 // if (!s)
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
512 // {
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
513 // 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
514 // symerr = 1;
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
515 // }
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
516 // }
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
517
2c24602be78f 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 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
519 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
520 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
521 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
522 {
155
1571e150f1fd Fixed error where external references within a library file were not resolved when linking
lost@l-w.ca
parents: 149
diff changeset
523 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
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 }
2c24602be78f 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 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
527
157
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
528 resolveonly = 0;
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
529
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
530 // if (symerr)
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
531 // exit(1);
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
532
4682460aed00 Correct bug with handling symbol resolution and constant section handling
lost@l-w.ca
parents: 156
diff changeset
533 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
534 // 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
535 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
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 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
538 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
539
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
540 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
541 }
2c24602be78f 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 }
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
543 void find_section_by_name_once_aux(char *name, fileinfo_t *fn, section_t **rval, int *found);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
544 void find_section_by_name_once_aux(char *name, fileinfo_t *fn, section_t **rval, int *found)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
545 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
546 int sn;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
547
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
548 if (fn -> forced == 0)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
549 return;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
550
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
551 for (sn = 0; sn < fn -> nsections; sn++)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
552 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
553 if (!strcmp(name, (char *)(fn -> sections[sn].name)))
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
554 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
555 (*found)++;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
556 *rval = &(fn -> sections[sn]);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
557 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
558 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
559 for (sn = 0; sn < fn -> nsubs; sn++)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
560 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
561 find_section_by_name_once_aux(name, fn -> subs[sn], rval, found);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
562 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
563 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
564
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
565 section_t *find_section_by_name_once(char *name)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
566 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
567 int fn;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
568 int found = 0;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
569 section_t *rval = NULL;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
570
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
571 for (fn = 0; fn < ninputfiles; fn++)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
572 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
573 find_section_by_name_once_aux(name, inputfiles[fn], &rval, &found);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
574 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
575 if (found != 1)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
576 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
577 rval = NULL;
149
729a9c70934e Fixed crash and bogus warning with os9 module target
lost@l-w.ca
parents: 148
diff changeset
578 if (found > 1)
729a9c70934e Fixed crash and bogus warning with os9 module target
lost@l-w.ca
parents: 148
diff changeset
579 fprintf(stderr, "Warning: multiple instances of section %s found; ignoring all of them which is probably not what you want\n", name);
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
580 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
581 return rval;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
582 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
583
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
584 void check_os9(void)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
585 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
586 section_t *s;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
587 symtab_t *sym;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
588
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
589 s = find_section_by_name_once("__os9");
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
590 linkscript.name = outfile;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
591
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
592 if (!s)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
593 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
594 // use defaults if not found
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
595 return;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
596 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
597
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
598 // this section is special
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
599 // several symbols may be defined as LOCAL symbols:
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
600 // type: module type
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
601 // lang: module language
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
602 // attr: module attributes
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
603 // rev: module revision
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
604 //
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
605 // the symbols are not case sensitive
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
606 //
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
607 // any unrecognized symbols are ignored
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
608
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
609 // the contents of the actual data to the first NUL
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
610 // is assumed to be the module name unless it is an empty string
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
611 if (s -> codesize > 0 && (s -> flags & SECTION_BSS) == 0 && s -> code[0] != 0)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
612 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
613 linkscript.name = (char *)(s -> code);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
614 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
615
149
729a9c70934e Fixed crash and bogus warning with os9 module target
lost@l-w.ca
parents: 148
diff changeset
616 for (sym = s -> localsyms; sym; sym = sym -> next)
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
617 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
618 char *sm = (char *)(sym -> sym);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
619 if (!strcasecmp(sm, "type"))
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
620 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
621 linkscript.modtype = sym -> offset;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
622 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
623 else if (!strcasecmp(sm, "lang"))
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
624 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
625 linkscript.modlang = sym -> offset;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
626 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
627 else if (!strcasecmp(sm, "attr"))
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
628 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
629 linkscript.modlang = sym -> offset;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
630 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
631 else if (!strcasecmp(sm, "rev"))
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
632 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
633 linkscript.modrev = sym -> offset;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
634 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
635 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
636 if (linkscript.modtype > 15)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
637 linkscript.modtype = linkscript.modtype >> 4;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
638
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
639 if (linkscript.modattr > 15)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
640 linkscript.modattr = linkscript.modattr >> 4;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
641
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
642 linkscript.modlang &= 15;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
643 linkscript.modtype &= 15;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
644 linkscript.modrev &= 15;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
645 linkscript.modattr &= 15;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 8
diff changeset
646 }