annotate lwlink/lwlink.h @ 248:e8d70b95ec41 2.x

Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
author lost
date Sun, 22 Nov 2009 05:46:31 +0000
parents f9f01a499525
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
112
a567dbb3f1d4 command line options
lost
parents:
diff changeset
1 /*
a567dbb3f1d4 command line options
lost
parents:
diff changeset
2 lwlink.h
118
d450943305a7 Fixed copyright year
lost
parents: 117
diff changeset
3 Copyright © 2009 William Astle
112
a567dbb3f1d4 command line options
lost
parents:
diff changeset
4
a567dbb3f1d4 command line options
lost
parents:
diff changeset
5 This file is part of LWLINK.
a567dbb3f1d4 command line options
lost
parents:
diff changeset
6
a567dbb3f1d4 command line options
lost
parents:
diff changeset
7 LWLINK is free software: you can redistribute it and/or modify it under the
a567dbb3f1d4 command line options
lost
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
a567dbb3f1d4 command line options
lost
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
a567dbb3f1d4 command line options
lost
parents:
diff changeset
10 version.
a567dbb3f1d4 command line options
lost
parents:
diff changeset
11
a567dbb3f1d4 command line options
lost
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
a567dbb3f1d4 command line options
lost
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a567dbb3f1d4 command line options
lost
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
a567dbb3f1d4 command line options
lost
parents:
diff changeset
15 more details.
a567dbb3f1d4 command line options
lost
parents:
diff changeset
16
a567dbb3f1d4 command line options
lost
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
a567dbb3f1d4 command line options
lost
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
a567dbb3f1d4 command line options
lost
parents:
diff changeset
19
a567dbb3f1d4 command line options
lost
parents:
diff changeset
20 Contains the main defs used by the linker
a567dbb3f1d4 command line options
lost
parents:
diff changeset
21 */
a567dbb3f1d4 command line options
lost
parents:
diff changeset
22
a567dbb3f1d4 command line options
lost
parents:
diff changeset
23
a567dbb3f1d4 command line options
lost
parents:
diff changeset
24 #ifndef __lwlink_h_seen__
a567dbb3f1d4 command line options
lost
parents:
diff changeset
25 #define __lwlink_h_seen__
a567dbb3f1d4 command line options
lost
parents:
diff changeset
26
116
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
27 #include "expr.h"
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
28
112
a567dbb3f1d4 command line options
lost
parents:
diff changeset
29 #define OUTPUT_DECB 0 // DECB multirecord format
a567dbb3f1d4 command line options
lost
parents:
diff changeset
30 #define OUTPUT_RAW 1 // raw sequence of bytes
187
857cb407229e Added LWEX0 (LWOS simple binary) target to lwlink
lost
parents: 185
diff changeset
31 #define OUTPUT_LWEX0 2 // LWOS LWEX binary version 0
112
a567dbb3f1d4 command line options
lost
parents:
diff changeset
32
116
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
33 typedef struct symtab_s symtab_t;
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
34 struct symtab_s
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
35 {
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
36 unsigned char *sym; // symbol name
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
37 int offset; // local offset
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
38 // int realval; // resolved value
116
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
39 symtab_t *next; // next symbol
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
40 };
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
41
204
048ebb85f6ef Added 8 bit external references for base page addressing mode
lost
parents: 187
diff changeset
42 #define RELOC_NORM 0 // all default (16 bit)
048ebb85f6ef Added 8 bit external references for base page addressing mode
lost
parents: 187
diff changeset
43 #define RELOC_8BIT 1 // only use the low 8 bits for the reloc
243
f9f01a499525 Added zero-width external references
lost
parents: 205
diff changeset
44 #define RELOC_0BIT 2 // don't actual stuff a reloc anywhere!
116
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
45 typedef struct reloc_s reloc_t;
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
46 struct reloc_s
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
47 {
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
48 int offset; // where in the section
204
048ebb85f6ef Added 8 bit external references for base page addressing mode
lost
parents: 187
diff changeset
49 int flags; // flags for the relocation
116
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
50 lw_expr_stack_t *expr; // the expression to calculate it
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
51 reloc_t *next; // ptr to next relocation
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
52 };
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
53
119
8bc00221ae89 section order and address resolution done
lost
parents: 118
diff changeset
54 typedef struct fileinfo_s fileinfo_t;
8bc00221ae89 section order and address resolution done
lost
parents: 118
diff changeset
55
116
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
56 #define SECTION_BSS 1
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
57 typedef struct
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
58 {
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
59 unsigned char *name; // name of the section
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
60 int flags; // section flags
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
61 int codesize; // size of the code
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
62 unsigned char *code; // pointer to the code
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
63 int loadaddress; // the actual load address of the section
119
8bc00221ae89 section order and address resolution done
lost
parents: 118
diff changeset
64 int processed; // was the section processed yet?
8bc00221ae89 section order and address resolution done
lost
parents: 118
diff changeset
65
116
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
66 symtab_t *localsyms; // local symbol table
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
67 symtab_t *exportedsyms; // exported symbols table
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
68
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
69 reloc_t *incompletes; // table of incomplete references
119
8bc00221ae89 section order and address resolution done
lost
parents: 118
diff changeset
70
8bc00221ae89 section order and address resolution done
lost
parents: 118
diff changeset
71 fileinfo_t *file; // the file we are in
116
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
72 } section_t;
115
776d8bea5b46 implement reading files
lost
parents: 114
diff changeset
73
119
8bc00221ae89 section order and address resolution done
lost
parents: 118
diff changeset
74 struct fileinfo_s
115
776d8bea5b46 implement reading files
lost
parents: 114
diff changeset
75 {
776d8bea5b46 implement reading files
lost
parents: 114
diff changeset
76 char *filename;
776d8bea5b46 implement reading files
lost
parents: 114
diff changeset
77 unsigned char *filedata;
776d8bea5b46 implement reading files
lost
parents: 114
diff changeset
78 long filesize;
116
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
79 section_t *sections;
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
80 int nsections;
180
6ebb93b409ba Added library paths and --section-base
lost
parents: 171
diff changeset
81 int islib; // set to true if the file is a "-l" option
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
82
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
83 int forced; // set to true if the file is a "forced" include
248
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 243
diff changeset
84 int resolves; // set to true if the file resolves a symbol
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
85
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
86 // "sub" files (like in archives or libraries)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
87 int nsubs;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
88 fileinfo_t **subs;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
89 fileinfo_t *parent;
119
8bc00221ae89 section order and address resolution done
lost
parents: 118
diff changeset
90 };
115
776d8bea5b46 implement reading files
lost
parents: 114
diff changeset
91
121
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
92 struct section_list
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
93 {
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
94 section_t *ptr; // ptr to section structure
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
95 int forceaddr; // was this force to an address by the link script?
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
96 };
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
97
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
98 #ifndef __link_c_seen__
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
99 extern struct section_list *sectlist;
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
100 extern int nsects;
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
101 #endif
116
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
102
817ab0e124fa reading files implemented
lost
parents: 115
diff changeset
103
112
a567dbb3f1d4 command line options
lost
parents:
diff changeset
104 #ifndef __lwlink_c_seen__
a567dbb3f1d4 command line options
lost
parents:
diff changeset
105
a567dbb3f1d4 command line options
lost
parents:
diff changeset
106 extern int debug_level;
a567dbb3f1d4 command line options
lost
parents:
diff changeset
107 extern int outformat;
a567dbb3f1d4 command line options
lost
parents:
diff changeset
108 extern char *outfile;
114
c65fcec346cd Handle input files on command line and add some memory management utility functions
lost
parents: 112
diff changeset
109 extern int ninputfiles;
115
776d8bea5b46 implement reading files
lost
parents: 114
diff changeset
110 extern fileinfo_t **inputfiles;
117
bb3cc989e84b parse linking scripts
lost
parents: 116
diff changeset
111 extern char *scriptfile;
112
a567dbb3f1d4 command line options
lost
parents:
diff changeset
112
180
6ebb93b409ba Added library paths and --section-base
lost
parents: 171
diff changeset
113 extern int nlibdirs;
6ebb93b409ba Added library paths and --section-base
lost
parents: 171
diff changeset
114 extern char **libdirs;
6ebb93b409ba Added library paths and --section-base
lost
parents: 171
diff changeset
115
6ebb93b409ba Added library paths and --section-base
lost
parents: 171
diff changeset
116 extern int nscriptls;
6ebb93b409ba Added library paths and --section-base
lost
parents: 171
diff changeset
117 extern char **scriptls;
6ebb93b409ba Added library paths and --section-base
lost
parents: 171
diff changeset
118
184
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 180
diff changeset
119 extern int symerr;
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 180
diff changeset
120
185
b89adfb0d174 Added support for outputting a linkmap
lost
parents: 184
diff changeset
121 extern char *map_file;
b89adfb0d174 Added support for outputting a linkmap
lost
parents: 184
diff changeset
122
114
c65fcec346cd Handle input files on command line and add some memory management utility functions
lost
parents: 112
diff changeset
123 #define __lwlink_E__ extern
c65fcec346cd Handle input files on command line and add some memory management utility functions
lost
parents: 112
diff changeset
124 #else
c65fcec346cd Handle input files on command line and add some memory management utility functions
lost
parents: 112
diff changeset
125 #define __lwlink_E__
112
a567dbb3f1d4 command line options
lost
parents:
diff changeset
126 #endif // __lwlink_c_seen__
a567dbb3f1d4 command line options
lost
parents:
diff changeset
127
114
c65fcec346cd Handle input files on command line and add some memory management utility functions
lost
parents: 112
diff changeset
128 __lwlink_E__ void add_input_file(char *fn);
180
6ebb93b409ba Added library paths and --section-base
lost
parents: 171
diff changeset
129 __lwlink_E__ void add_input_library(char *fn);
6ebb93b409ba Added library paths and --section-base
lost
parents: 171
diff changeset
130 __lwlink_E__ void add_library_search(char *fn);
6ebb93b409ba Added library paths and --section-base
lost
parents: 171
diff changeset
131 __lwlink_E__ void add_section_base(char *fn);
114
c65fcec346cd Handle input files on command line and add some memory management utility functions
lost
parents: 112
diff changeset
132
c65fcec346cd Handle input files on command line and add some memory management utility functions
lost
parents: 112
diff changeset
133 #undef __lwlink_E__
117
bb3cc989e84b parse linking scripts
lost
parents: 116
diff changeset
134
bb3cc989e84b parse linking scripts
lost
parents: 116
diff changeset
135 struct scriptline_s
bb3cc989e84b parse linking scripts
lost
parents: 116
diff changeset
136 {
bb3cc989e84b parse linking scripts
lost
parents: 116
diff changeset
137 char *sectname; // name of section, NULL for wildcard
bb3cc989e84b parse linking scripts
lost
parents: 116
diff changeset
138 int loadat; // address to load at (or -1)
bb3cc989e84b parse linking scripts
lost
parents: 116
diff changeset
139 int noflags; // flags to NOT have
bb3cc989e84b parse linking scripts
lost
parents: 116
diff changeset
140 int yesflags; // flags to HAVE
bb3cc989e84b parse linking scripts
lost
parents: 116
diff changeset
141 };
bb3cc989e84b parse linking scripts
lost
parents: 116
diff changeset
142
bb3cc989e84b parse linking scripts
lost
parents: 116
diff changeset
143 typedef struct
bb3cc989e84b parse linking scripts
lost
parents: 116
diff changeset
144 {
bb3cc989e84b parse linking scripts
lost
parents: 116
diff changeset
145 int nlines; // number of lines in the script
bb3cc989e84b parse linking scripts
lost
parents: 116
diff changeset
146 struct scriptline_s *lines; // the parsed script lines (section)
bb3cc989e84b parse linking scripts
lost
parents: 116
diff changeset
147 int padsize; // the size to pad to, -1 for none
121
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
148 char *execsym; // entry point symbol
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
149 int execaddr; // execution address (entry point)
187
857cb407229e Added LWEX0 (LWOS simple binary) target to lwlink
lost
parents: 185
diff changeset
150 int stacksize; // stack size
117
bb3cc989e84b parse linking scripts
lost
parents: 116
diff changeset
151 } linkscript_t;
bb3cc989e84b parse linking scripts
lost
parents: 116
diff changeset
152
bb3cc989e84b parse linking scripts
lost
parents: 116
diff changeset
153 #ifndef __script_c_seen__
bb3cc989e84b parse linking scripts
lost
parents: 116
diff changeset
154 extern linkscript_t linkscript;
bb3cc989e84b parse linking scripts
lost
parents: 116
diff changeset
155 #endif
bb3cc989e84b parse linking scripts
lost
parents: 116
diff changeset
156
112
a567dbb3f1d4 command line options
lost
parents:
diff changeset
157 #endif //__lwlink_h_seen__