1 /*****************************************************************************/
5 /* Exports handing for the ld65 linker */
9 /* (C) 1998-2009, 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 /*****************************************************************************/
54 /*****************************************************************************/
56 /*****************************************************************************/
60 /* Import symbol structure */
61 typedef struct Import Import;
63 Import* Next; /* Single linked list */
64 ObjData* Obj; /* Object file that imports the name */
65 FilePos Pos; /* File position of reference */
66 struct Export* Exp; /* Matching export for this import */
67 unsigned Name; /* Name if not in table */
68 unsigned char Flags; /* Generic flags */
69 unsigned char AddrSize; /* Address size of import */
74 /* Export symbol structure */
75 typedef struct Export Export;
77 unsigned Name; /* Name */
78 Export* Next; /* Hash table link */
79 unsigned Flags; /* Generic flags */
80 ObjData* Obj; /* Object file that exports the name */
81 unsigned ImpCount; /* How many imports for this symbol? */
82 Import* ImpList; /* List of imports for this symbol */
83 FilePos Pos; /* File position of definition */
84 ExprNode* Expr; /* Expression (0 if not def'd) */
85 unsigned char Type; /* Type of export */
86 unsigned char AddrSize; /* Address size of export */
87 unsigned char ConDes[CD_TYPE_COUNT]; /* Constructor/destructor decls */
92 /* Prototype of a function that is called if an undefined symbol is found. It
93 * may check if the symbol is an external symbol (for binary formats that
94 * support externals) and will return zero if the symbol could not be
95 * resolved, or a value != zero if the symbol could be resolved. The
96 * CheckExports routine will print out the missing symbol in the first case.
98 typedef int (*ExpCheckFunc) (unsigned Name, void* Data);
102 /*****************************************************************************/
104 /*****************************************************************************/
108 void FreeImport (Import* I);
109 /* Free an import. NOTE: This won't remove the import from the exports table,
110 * so it may only be called for unused imports (imports from modules that
111 * aren't referenced).
114 Import* ReadImport (FILE* F, ObjData* Obj);
115 /* Read an import from a file and insert it into the table */
117 Import* GenImport (const char* Name, unsigned char AddrSize);
118 /* Generate a new import with the given name and address size and return it */
120 void InsertImport (Import* I);
121 /* Insert an import into the table */
123 void FreeExport (Export* E);
124 /* Free an export. NOTE: This won't remove the export from the exports table,
125 * so it may only be called for unused exports (exports from modules that
126 * aren't referenced).
129 Export* ReadExport (FILE* F, ObjData* Obj);
130 /* Read an export from a file */
132 void InsertExport (Export* E);
133 /* Insert an exported identifier and check if it's already in the list */
135 Export* CreateConstExport (unsigned Name, long Value);
136 /* Create an export for a literal date */
138 Export* CreateMemoryExport (unsigned Name, Memory* Mem, unsigned long Offs);
139 /* Create an relative export for a memory area offset */
141 Export* CreateSegmentExport (unsigned Name, Segment* Seg, unsigned long Offs);
142 /* Create a relative export to a segment */
144 Export* CreateSectionExport (unsigned Name, Section* S, unsigned long Offs);
145 /* Create a relative export to a section */
147 Export* FindExport (unsigned Name);
148 /* Check for an identifier in the list. Return 0 if not found, otherwise
149 * return a pointer to the export.
152 int IsUnresolved (unsigned Name);
153 /* Check if this symbol is an unresolved export */
155 int IsUnresolvedExport (const Export* E);
156 /* Return true if the given export is unresolved */
158 int IsConstExport (const Export* E);
159 /* Return true if the expression associated with this export is const */
161 long GetExportVal (const Export* E);
162 /* Get the value of this export */
164 void CheckExports (void);
165 /* Setup the list of all exports and check for export/import symbol type
169 void CheckUnresolvedImports (ExpCheckFunc F, void* Data);
170 /* Check if there are any unresolved imports. On unresolved imports, F is
171 * called (see the comments on ExpCheckFunc in the data section).
174 void PrintExportMap (FILE* F);
175 /* Print an export map to the given file */
177 void PrintImportMap (FILE* F);
178 /* Print an import map to the given file */
180 void PrintExportLabels (FILE* F);
181 /* Print the exports in a VICE label file */
183 void MarkExport (Export* E);
184 /* Mark the export */
186 void UnmarkExport (Export* E);
187 /* Remove the mark from the export */
189 int ExportHasMark (Export* E);
190 /* Return true if the export has a mark */
192 void CircularRefError (const Export* E);
193 /* Print an error about a circular reference using to define the given export */
197 /* End of exports.h */