1 /*****************************************************************************/
5 /* Exports handing for the ld65 linker */
9 /* (C) 1998-2010, 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 /*****************************************************************************/
55 /*****************************************************************************/
57 /*****************************************************************************/
61 /* Import symbol structure */
62 typedef struct Import Import;
64 Import* Next; /* Single linked list */
65 ObjData* Obj; /* Object file that imports the name */
66 FilePos Pos; /* File position of reference */
67 struct Export* Exp; /* Matching export for this import */
68 unsigned Name; /* Name if not in table */
69 unsigned char Flags; /* Generic flags */
70 unsigned char AddrSize; /* Address size of import */
75 /* Export symbol structure */
76 typedef struct Export Export;
78 unsigned Name; /* Name */
79 Export* Next; /* Hash table link */
80 unsigned Flags; /* Generic flags */
81 ObjData* Obj; /* Object file that exports the name */
82 unsigned ImpCount; /* How many imports for this symbol? */
83 Import* ImpList; /* List of imports for this symbol */
84 FilePos Pos; /* File position of definition */
85 ExprNode* Expr; /* Expression (0 if not def'd) */
86 unsigned char Type; /* Type of export */
87 unsigned char AddrSize; /* Address size of export */
88 unsigned char ConDes[CD_TYPE_COUNT]; /* Constructor/destructor decls */
93 /* Prototype of a function that is called if an undefined symbol is found. It
94 * may check if the symbol is an external symbol (for binary formats that
95 * support externals) and will return zero if the symbol could not be
96 * resolved, or a value != zero if the symbol could be resolved. The
97 * CheckExports routine will print out the missing symbol in the first case.
99 typedef int (*ExpCheckFunc) (unsigned Name, void* Data);
103 /*****************************************************************************/
105 /*****************************************************************************/
109 void FreeImport (Import* I);
110 /* Free an import. NOTE: This won't remove the import from the exports table,
111 * so it may only be called for unused imports (imports from modules that
112 * aren't referenced).
115 Import* ReadImport (FILE* F, ObjData* Obj);
116 /* Read an import from a file and insert it into the table */
118 Import* GenImport (unsigned Name, unsigned char AddrSize);
119 /* Generate a new import with the given name and address size and return it */
121 Import* InsertImport (Import* I);
122 /* Insert an import into the table, return I */
124 void FreeExport (Export* E);
125 /* Free an export. NOTE: This won't remove the export from the exports table,
126 * so it may only be called for unused exports (exports from modules that
127 * aren't referenced).
130 Export* ReadExport (FILE* F, ObjData* Obj);
131 /* Read an export from a file */
133 void InsertExport (Export* E);
134 /* Insert an exported identifier and check if it's already in the list */
136 Export* CreateConstExport (unsigned Name, long Value);
137 /* Create an export for a literal date */
139 Export* CreateMemoryExport (unsigned Name, MemoryArea* Mem, unsigned long Offs);
140 /* Create an relative export for a memory area offset */
142 Export* CreateSegmentExport (unsigned Name, Segment* Seg, unsigned long Offs);
143 /* Create a relative export to a segment */
145 Export* CreateSectionExport (unsigned Name, Section* S, unsigned long Offs);
146 /* Create a relative export to a section */
148 Export* FindExport (unsigned Name);
149 /* Check for an identifier in the list. Return 0 if not found, otherwise
150 * return a pointer to the export.
153 int IsUnresolved (unsigned Name);
154 /* Check if this symbol is an unresolved export */
156 int IsUnresolvedExport (const Export* E);
157 /* Return true if the given export is unresolved */
159 int IsConstExport (const Export* E);
160 /* Return true if the expression associated with this export is const */
162 long GetExportVal (const Export* E);
163 /* Get the value of this export */
165 void CheckExports (void);
166 /* Setup the list of all exports and check for export/import symbol type
170 void CheckUnresolvedImports (ExpCheckFunc F, void* Data);
171 /* Check if there are any unresolved imports. On unresolved imports, F is
172 * called (see the comments on ExpCheckFunc in the data section).
175 void PrintExportMap (FILE* F);
176 /* Print an export map to the given file */
178 void PrintImportMap (FILE* F);
179 /* Print an import map to the given file */
181 void PrintExportLabels (FILE* F);
182 /* Print the exports in a VICE label file */
184 void MarkExport (Export* E);
185 /* Mark the export */
187 void UnmarkExport (Export* E);
188 /* Remove the mark from the export */
190 int ExportHasMark (Export* E);
191 /* Return true if the export has a mark */
193 void CircularRefError (const Export* E);
194 /* Print an error about a circular reference using to define the given export */
198 /* End of exports.h */