1 /*****************************************************************************/
5 /* Exports handing for the ld65 linker */
9 /* (C) 1998-2011, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
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. */
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: */
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 */
32 /*****************************************************************************/
56 /*****************************************************************************/
58 /*****************************************************************************/
62 /* Import symbol structure */
63 typedef struct Import 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 */
77 /* Export symbol structure */
78 typedef struct Export 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 */
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.
104 typedef int (*ExpCheckFunc) (unsigned Name, void* Data);
108 /*****************************************************************************/
110 /*****************************************************************************/
114 void 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).
120 Import* ReadImport (FILE* F, ObjData* Obj);
121 /* Read an import from a file and insert it into the table */
123 Import* GenImport (unsigned Name, unsigned char AddrSize);
124 /* Generate a new import with the given name and address size and return it */
126 Import* InsertImport (Import* I);
127 /* Insert an import into the table, return I */
129 const LineInfo* GetImportPos (const Import* I);
130 /* Return the basic line info of an import */
132 void 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).
138 Export* ReadExport (FILE* F, ObjData* Obj);
139 /* Read an export from a file */
141 void InsertExport (Export* E);
142 /* Insert an exported identifier and check if it's already in the list */
144 const LineInfo* GetExportPos (const Export* E);
145 /* Return the basic line info of an export */
147 Export* CreateConstExport (unsigned Name, long Value);
148 /* Create an export for a literal date */
150 Export* CreateExprExport (unsigned Name, ExprNode* Expr, unsigned char AddrSize);
151 /* Create an export for an expression */
153 Export* CreateMemoryExport (unsigned Name, MemoryArea* Mem, unsigned long Offs);
154 /* Create an relative export for a memory area offset */
156 Export* CreateSegmentExport (unsigned Name, Segment* Seg, unsigned long Offs);
157 /* Create a relative export to a segment */
159 Export* CreateSectionExport (unsigned Name, Section* S, unsigned long Offs);
160 /* Create a relative export to a section */
162 Export* FindExport (unsigned Name);
163 /* Check for an identifier in the list. Return 0 if not found, otherwise
164 * return a pointer to the export.
167 int IsUnresolved (unsigned Name);
168 /* Check if this symbol is an unresolved export */
170 int IsUnresolvedExport (const Export* E);
171 /* Return true if the given export is unresolved */
173 int IsConstExport (const Export* E);
174 /* Return true if the expression associated with this export is const */
176 long GetExportVal (const Export* E);
177 /* Get the value of this export */
179 void CheckExports (void);
180 /* Setup the list of all exports and check for export/import symbol type
184 void 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).
189 void PrintExportMap (FILE* F);
190 /* Print an export map to the given file */
192 void PrintImportMap (FILE* F);
193 /* Print an import map to the given file */
195 void PrintExportLabels (FILE* F);
196 /* Print the exports in a VICE label file */
198 void MarkExport (Export* E);
199 /* Mark the export */
201 void UnmarkExport (Export* E);
202 /* Remove the mark from the export */
204 int ExportHasMark (Export* E);
205 /* Return true if the export has a mark */
207 void CircularRefError (const Export* E);
208 /* Print an error about a circular reference using to define the given export */
212 /* End of exports.h */