annotate lwlink/lwlink.h @ 404:0324fd09c7ac

Added documentation for the --symbol option for lwasm
author lost@l-w.ca
date Fri, 23 Jul 2010 18:31:33 -0600
parents 54499b799779
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1 /*
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
2 lwlink.h
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
3 Copyright © 2009 William Astle
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
4
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
5 This file is part of LWLINK.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
6
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
7 LWLINK is free software: you can redistribute it and/or modify it under the
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
10 version.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
11
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
15 more details.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
16
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
19
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
20 Contains the main defs used by the linker
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
21 */
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
22
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
23
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
24 #ifndef __lwlink_h_seen__
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
25 #define __lwlink_h_seen__
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
26
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
27 #include "expr.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
28
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
29 #define OUTPUT_DECB 0 // DECB multirecord format
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
30 #define OUTPUT_RAW 1 // raw sequence of bytes
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
31 #define OUTPUT_LWEX0 2 // LWOS LWEX binary version 0
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
32
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
33 typedef struct symtab_s symtab_t;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
34 struct symtab_s
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
35 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
36 unsigned char *sym; // symbol name
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
37 int offset; // local offset
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
38 // int realval; // resolved value
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
39 symtab_t *next; // next symbol
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
40 };
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
41
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
42 #define RELOC_NORM 0 // all default (16 bit)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
43 #define RELOC_8BIT 1 // only use the low 8 bits for the reloc
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
44 typedef struct reloc_s reloc_t;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
45 struct reloc_s
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
46 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
47 int offset; // where in the section
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
48 int flags; // flags for the relocation
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
49 lw_expr_stack_t *expr; // the expression to calculate it
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
50 reloc_t *next; // ptr to next relocation
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
51 };
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
52
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
53 typedef struct fileinfo_s fileinfo_t;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
54
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
55 #define SECTION_BSS 1
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
56 typedef struct
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
57 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
58 unsigned char *name; // name of the section
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
59 int flags; // section flags
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
60 int codesize; // size of the code
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
61 unsigned char *code; // pointer to the code
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
62 int loadaddress; // the actual load address of the section
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
63 int processed; // was the section processed yet?
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
64
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
65 symtab_t *localsyms; // local symbol table
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
66 symtab_t *exportedsyms; // exported symbols table
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
67
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
68 reloc_t *incompletes; // table of incomplete references
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
69
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
70 fileinfo_t *file; // the file we are in
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
71 } section_t;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
72
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
73 struct fileinfo_s
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
74 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
75 char *filename;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
76 unsigned char *filedata;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
77 long filesize;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
78 section_t *sections;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
79 int nsections;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
80 int islib; // set to true if the file is a "-l" option
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
81
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
82 int forced; // set to true if the file is a "forced" include
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
83
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
84 // "sub" files (like in archives or libraries)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
85 int nsubs;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
86 fileinfo_t **subs;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
87 fileinfo_t *parent;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
88 };
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
89
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
90 struct section_list
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
91 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
92 section_t *ptr; // ptr to section structure
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
93 int forceaddr; // was this force to an address by the link script?
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
94 };
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
95
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
96 #ifndef __link_c_seen__
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
97 extern struct section_list *sectlist;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
98 extern int nsects;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
99 #endif
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
100
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
101
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
102 #ifndef __lwlink_c_seen__
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
103
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
104 extern int debug_level;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
105 extern int outformat;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
106 extern char *outfile;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
107 extern int ninputfiles;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
108 extern fileinfo_t **inputfiles;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
109 extern char *scriptfile;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
110
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
111 extern int nlibdirs;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
112 extern char **libdirs;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
113
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
114 extern int nscriptls;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
115 extern char **scriptls;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
116
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
117 extern int symerr;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
118
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
119 extern char *map_file;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
120
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
121 #define __lwlink_E__ extern
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
122 #else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
123 #define __lwlink_E__
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
124 #endif // __lwlink_c_seen__
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
125
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
126 __lwlink_E__ void add_input_file(char *fn);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
127 __lwlink_E__ void add_input_library(char *fn);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
128 __lwlink_E__ void add_library_search(char *fn);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
129 __lwlink_E__ void add_section_base(char *fn);
395
54499b799779 Q&D sanitization of symbols in map files and error messages in lwlink
lost@l-w.ca
parents: 378
diff changeset
130 __lwlink_E__ char *sanitize_symbol(char *sym);
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
131
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
132 #undef __lwlink_E__
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
133
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
134 struct scriptline_s
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
135 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
136 char *sectname; // name of section, NULL for wildcard
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
137 int loadat; // address to load at (or -1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
138 int noflags; // flags to NOT have
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
139 int yesflags; // flags to HAVE
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
140 };
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
141
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
142 typedef struct
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
143 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
144 int nlines; // number of lines in the script
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
145 struct scriptline_s *lines; // the parsed script lines (section)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
146 int padsize; // the size to pad to, -1 for none
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
147 char *execsym; // entry point symbol
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
148 int execaddr; // execution address (entry point)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
149 int stacksize; // stack size
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
150 } linkscript_t;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
151
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
152 #ifndef __script_c_seen__
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
153 extern linkscript_t linkscript;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
154 #endif
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
155
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
156 #endif //__lwlink_h_seen__