1/*****************************************************************************/
2/* */
3/* exports.h */
4/* */
5/* Exports handing for the ld65 linker */
6/* */
7/* */
8/* */
9/* (C) 1998-2011, Ullrich von Bassewitz */
10/* Roemerstrasse 52 */
11/* D-70794 Filderstadt */
12/* EMail: uz@cc65.org */
13/* */
14/* */
15/* This software is provided 'as-is', without any expressed or implied */
16/* warranty. In no event will the authors be held liable for any damages */
17/* arising from the use of this software. */
18/* */
19/* Permission is granted to anyone to use this software for any purpose, */
20/* including commercial applications, and to alter it and redistribute it */
21/* freely, subject to the following restrictions: */
22/* */
23/* 1. The origin of this software must not be misrepresented; you must not */
24/* claim that you wrote the original software. If you use this software */
25/* in a product, an acknowledgment in the product documentation would be */
26/* appreciated but is not required. */
27/* 2. Altered source versions must be plainly marked as such, and must not */
28/* be misrepresented as being the original software. */
29/* 3. This notice may not be removed or altered from any source */
30/* distribution. */
31/* */
32/*****************************************************************************/
33
34
35
36#ifndef EXPORTS_H
37#define EXPORTS_H
38
39
40
41#include <stdio.h>
42
43/* common */
44#include "cddefs.h"
45#include "coll.h"
46#include "exprdefs.h"
47
48/* ld65 */
49#include "config.h"
50#include "lineinfo.h"
51#include "memarea.h"
52#include "objdata.h"
53
54
55
56/*****************************************************************************/
57/* Data */
58/*****************************************************************************/
59
60
61
62/* Import symbol structure */
63typedef struct Import Import;
64struct Import {
65 Import* Next; /* Single linked list */
66 ObjData* Obj; /* Object file that imports the name */
67 Collection DefLines; /* Line infos of definition */
68 Collection RefLines; /* Line infos of reference */
69 struct Export* Exp; /* Matching export for this import */
70 unsigned Name; /* Name if not in table */
71 unsigned short Flags; /* Generic flags */
72 unsigned short AddrSize; /* Address size of import */
73};
74
75
76
77/* Export symbol structure */
78typedef struct Export Export;
79struct Export {
80 unsigned Name; /* Name */
81 Export* Next; /* Hash table link */
82 unsigned Flags; /* Generic flags */
83 ObjData* Obj; /* Object file that exports the name */
84 unsigned ImpCount; /* How many imports for this symbol? */
85 Import* ImpList; /* List of imports for this symbol */
86 ExprNode* Expr; /* Expression (0 if not def'd) */
87 unsigned Size; /* Size of the symbol if any */
88 Collection DefLines; /* Line infos of definition */
89 Collection RefLines; /* Line infos of reference */
90 unsigned DbgSymId; /* Id of debug symbol for this export */
91 unsigned short Type; /* Type of export */
92 unsigned short AddrSize; /* Address size of export */
93 unsigned char ConDes[CD_TYPE_COUNT]; /* Constructor/destructor decls */
94};
95
96
97
98/* Prototype of a function that is called if an undefined symbol is found. It
99** may check if the symbol is an external symbol (for binary formats that
100** support externals) and will return zero if the symbol could not be
101** resolved, or a value != zero if the symbol could be resolved. The
102** CheckExports routine will print out the missing symbol in the first case.
103*/
104typedef int (*ExpCheckFunc) (unsigned Name, void* Data);
105
106
107
108/*****************************************************************************/
109/* Code */
110/*****************************************************************************/
111
112
113
114void FreeImport (Import* I);
115/* Free an import. NOTE: This won't remove the import from the exports table,
116** so it may only be called for unused imports (imports from modules that
117** aren't referenced).
118*/
119
120Import* ReadImport (FILE* F, ObjData* Obj);
121/* Read an import from a file and insert it into the table */
122
123Import* GenImport (unsigned Name, unsigned char AddrSize);
124/* Generate a new import with the given name and address size and return it */
125
126Import* InsertImport (Import* I);
127/* Insert an import into the table, return I */
128
129const LineInfo* GetImportPos (const Import* I);
130/* Return the basic line info of an import */
131
132void FreeExport (Export* E);
133/* Free an export. NOTE: This won't remove the export from the exports table,
134** so it may only be called for unused exports (exports from modules that
135** aren't referenced).
136*/
137
138Export* ReadExport (FILE* F, ObjData* Obj);
139/* Read an export from a file */
140
141void InsertExport (Export* E);
142/* Insert an exported identifier and check if it's already in the list */
143
144const LineInfo* GetExportPos (const Export* E);
145/* Return the basic line info of an export */
146
147Export* CreateConstExport (unsigned Name, long Value);
148/* Create an export for a literal date */
149
150Export* CreateExprExport (unsigned Name, ExprNode* Expr, unsigned char AddrSize);
151/* Create an export for an expression */
152
153Export* CreateMemoryExport (unsigned Name, MemoryArea* Mem, unsigned long Offs);
154/* Create an relative export for a memory area offset */
155
156Export* CreateSegmentExport (unsigned Name, Segment* Seg, unsigned long Offs);
157/* Create a relative export to a segment */
158
159Export* CreateSectionExport (unsigned Name, Section* S, unsigned long Offs);
160/* Create a relative export to a section */
161
162Export* FindExport (unsigned Name);
163/* Check for an identifier in the list. Return 0 if not found, otherwise
164** return a pointer to the export.
165*/
166
167int IsUnresolved (unsigned Name);
168/* Check if this symbol is an unresolved export */
169
170int IsUnresolvedExport (const Export* E);
171/* Return true if the given export is unresolved */
172
173int IsConstExport (const Export* E);
174/* Return true if the expression associated with this export is const */
175
176long GetExportVal (const Export* E);
177/* Get the value of this export */
178
179void CheckExports (void);
180/* Setup the list of all exports and check for export/import symbol type
181** mismatches.
182*/
183
184void CheckUnresolvedImports (ExpCheckFunc F, void* Data);
185/* Check if there are any unresolved imports. On unresolved imports, F is
186** called (see the comments on ExpCheckFunc in the data section).
187*/
188
189void PrintExportMapByName (FILE* F);
190/* Print an export map to the given file (sorted by symbol name) */
191
192void PrintExportMapByValue (FILE* F);
193/* Print an export map to the given file (sorted by export value) */
194
195void PrintImportMap (FILE* F);
196/* Print an import map to the given file */
197
198void PrintExportLabels (FILE* F);
199/* Print the exports in a VICE label file */
200
201void MarkExport (Export* E);
202/* Mark the export */
203
204void UnmarkExport (Export* E);
205/* Remove the mark from the export */
206
207int ExportHasMark (Export* E);
208/* Return true if the export has a mark */
209
210void CircularRefError (const Export* E);
211/* Print an error about a circular reference using to define the given export */
212
213
214
215/* End of exports.h */
216
217#endif
218