Mercurial > hg-old > index.cgi
annotate lwlink/lwlink.c @ 407:b2e007c28b8f
Changed ENDS to be ENDSTRUCT instead of ENDSECTION since ENDSTRUCT is required but ENDSECTION is not; updated docs to reflect change
author | lost@l-w.ca |
---|---|
date | Fri, 23 Jul 2010 19:53:43 -0600 |
parents | 54499b799779 |
children |
rev | line source |
---|---|
339 | 1 /* |
2 lwlink.c | |
3 Copyright © 2009 William Astle | |
4 | |
5 This file is part of LWLINK. | |
6 | |
7 LWLINK is free software: you can redistribute it and/or modify it under the | |
8 terms of the GNU General Public License as published by the Free Software | |
9 Foundation, either version 3 of the License, or (at your option) any later | |
10 version. | |
11 | |
12 This program is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
15 more details. | |
16 | |
17 You should have received a copy of the GNU General Public License along with | |
18 this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 | |
21 | |
22 */ | |
23 | |
24 #include <config.h> | |
25 | |
26 #define __lwlink_c_seen__ | |
27 | |
28 #include <argp.h> | |
29 #include <errno.h> | |
30 #include <stdio.h> | |
31 #include <stdlib.h> | |
32 #include <string.h> | |
33 | |
34 #include "lwlink.h" | |
35 #include "util.h" | |
36 | |
37 int debug_level = 0; | |
38 int outformat = OUTPUT_DECB; | |
39 char *outfile = NULL; | |
40 char *scriptfile = NULL; | |
41 int symerr = 0; | |
42 char *map_file = NULL; | |
43 | |
44 fileinfo_t **inputfiles = NULL; | |
45 int ninputfiles = 0; | |
46 | |
47 int nlibdirs = 0; | |
48 char **libdirs = NULL; | |
49 | |
50 int nscriptls = 0; | |
51 char **scriptls = NULL; | |
52 | |
53 void add_input_file(char *fn) | |
54 { | |
55 inputfiles = lw_realloc(inputfiles, sizeof(fileinfo_t *) * (ninputfiles + 1)); | |
56 inputfiles[ninputfiles] = lw_malloc(sizeof(fileinfo_t)); | |
57 memset(inputfiles[ninputfiles], 0, sizeof(fileinfo_t)); | |
58 inputfiles[ninputfiles] -> forced = 1; | |
59 inputfiles[ninputfiles++] -> filename = lw_strdup(fn); | |
60 } | |
61 | |
62 void add_input_library(char *libname) | |
63 { | |
64 inputfiles = lw_realloc(inputfiles, sizeof(fileinfo_t *) * (ninputfiles + 1)); | |
65 inputfiles[ninputfiles] = lw_malloc(sizeof(fileinfo_t)); | |
66 memset(inputfiles[ninputfiles], 0, sizeof(fileinfo_t)); | |
67 inputfiles[ninputfiles] -> islib = 1; | |
68 inputfiles[ninputfiles] -> forced = 0; | |
69 inputfiles[ninputfiles++] -> filename = lw_strdup(libname); | |
70 } | |
71 | |
72 void add_library_search(char *libdir) | |
73 { | |
74 libdirs = lw_realloc(libdirs, sizeof(char*) * (nlibdirs + 1)); | |
75 libdirs[nlibdirs] = lw_strdup(libdir); | |
76 nlibdirs++; | |
77 } | |
78 | |
79 void add_section_base(char *sectspec) | |
80 { | |
81 char *base; | |
82 int baseaddr; | |
83 char *t; | |
84 int l; | |
85 | |
86 base = strchr(sectspec, '='); | |
87 if (!base) | |
88 { | |
89 l = strlen(sectspec); | |
90 baseaddr = 0; | |
91 } | |
92 else | |
93 { | |
94 baseaddr = strtol(base + 1, NULL, 16); | |
95 l = base - sectspec; | |
96 *base = '\0'; | |
97 } | |
98 baseaddr = baseaddr & 0xffff; | |
99 | |
100 t = lw_malloc(l + 25); | |
101 sprintf(t, "section %s load %04X", sectspec, baseaddr); | |
102 if (base) | |
103 *base = '='; | |
104 | |
105 scriptls = lw_realloc(scriptls, sizeof(char *) * (nscriptls + 1)); | |
106 scriptls[nscriptls++] = t; | |
107 } | |
395
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
108 |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
109 char *sanitize_symbol(char *symbol) |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
110 { |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
111 static char symbuf[2048]; |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
112 char *sym = symbol; |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
113 char *tp = symbuf; |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
114 |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
115 for (; *sym; sym++) |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
116 { |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
117 int c1 = *sym; |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
118 if (c1 == '\\') |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
119 { |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
120 *tp++ = '\\'; |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
121 *tp++ = '\\'; |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
122 continue; |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
123 } |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
124 if (c1 < 32 || c1 > 126) |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
125 { |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
126 int c; |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
127 *tp++ = '\\'; |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
128 c = c1 >> 4; |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
129 c += 48; |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
130 if (c > 57) |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
131 c += 7; |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
132 *tp++ = c; |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
133 c = c1 & 15; |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
134 c += 48; |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
135 if (c > 57) |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
136 c += 7; |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
137 *tp++ = c; |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
138 continue; |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
139 } |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
140 *tp++ = c1; |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
141 } |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
142 *tp = 0; |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
143 return symbuf; |
54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents:
378
diff
changeset
|
144 } |