1 /*****************************************************************************/
5 /* Handling object file data 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 /*****************************************************************************/
48 /*****************************************************************************/
50 /*****************************************************************************/
62 /* Values for the Flags field */
63 #define OBJ_REF 0x0001 /* We have a reference to this file */
65 /* Internal structure holding object file data */
66 typedef struct ObjData ObjData;
68 ObjData* Next; /* Linked list of all objects */
69 unsigned Id; /* Id of this module */
70 unsigned Name; /* Module name */
71 struct Library* Lib; /* Library where module comes from */
72 unsigned long MTime; /* Time of last modification */
73 ObjHeader Header; /* Header of file */
74 unsigned long Start; /* Start offset of data in library */
77 unsigned SymBaseId; /* Debug info base id for symbols */
78 unsigned ScopeBaseId; /* Debug info base id for scopes */
79 unsigned SpanBaseId; /* Debug info base id for spans */
81 Collection Files; /* List of input files */
82 Collection Sections; /* List of all sections */
83 Collection Exports; /* List of all exports */
84 Collection Imports; /* List of all imports */
85 Collection DbgSyms; /* List of debug symbols */
86 Collection LineInfos; /* List of line infos */
87 unsigned StringCount; /* Count of strings */
88 unsigned* Strings; /* List of global string indices */
89 Collection Assertions; /* List of module assertions */
90 Collection Scopes; /* List of scopes */
91 Collection Spans; /* List of spans */
96 /* Collection containing used ObjData objects */
97 extern Collection ObjDataList;
101 /*****************************************************************************/
103 /*****************************************************************************/
107 ObjData* NewObjData (void);
108 /* Allocate a new structure on the heap, insert it into the list, return it */
110 void FreeObjData (ObjData* O);
111 /* Free an ObjData object. NOTE: This function works only for unused object
112 * data, that is, ObjData objects that aren't used because they aren't
116 void FreeObjStrings (ObjData* O);
117 /* Free the module string data. Used once the object file is loaded completely
118 * when all strings are converted to global strings.
121 void InsertObjData (ObjData* O);
122 /* Insert the ObjData object into the collection of used ObjData objects. */
124 void InsertObjGlobals (ObjData* O);
125 /* Insert imports and exports from the object file into the global import and
129 unsigned MakeGlobalStringId (const ObjData* O, unsigned Index);
130 /* Convert a local string id into a global one and return it. */
132 const char* GetObjFileName (const ObjData* O);
133 /* Get the name of the object file. Return "[linker generated]" if the object
137 #if defined(HAVE_INLINE)
138 INLINE int ObjHasFiles (const ObjData* O)
139 /* Return true if the files list does exist */
141 return (O != 0 && CollCount (&O->Files) != 0);
144 # define ObjHasFiles(O) ((O) != 0 && CollCount (&(O)->Files) != 0)
147 const struct StrBuf* GetObjString (const ObjData* Obj, unsigned Id);
148 /* Get a string from an object file checking for an invalid index */
150 struct Section* GetObjSection (const ObjData* Obj, unsigned Id);
151 /* Get a section from an object file checking for a valid index */
153 struct Import* GetObjImport (const ObjData* Obj, unsigned Id);
154 /* Get an import from an object file checking for a valid index */
156 struct Export* GetObjExport (const ObjData* Obj, unsigned Id);
157 /* Get an export from an object file checking for a valid index */
159 struct Scope* GetObjScope (const ObjData* Obj, unsigned Id);
160 /* Get a scope from an object file checking for a valid index */
162 unsigned ObjDataCount (void);
163 /* Return the total number of modules */
165 void PrintDbgModules (FILE* F);
166 /* Output the modules to a debug info file */
170 /* End of objdata.h */