1/*****************************************************************************/
2/* */
3/* objdata.h */
4/* */
5/* Handling object file data 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 OBJDATA_H
37#define OBJDATA_H
38
39
40
41/* common */
42#include "coll.h"
43#include "inline.h"
44#include "objdefs.h"
45
46
47
48/*****************************************************************************/
49/* Data */
50/*****************************************************************************/
51
52
53
54/* Forwards */
55struct Export;
56struct Import;
57struct Library;
58struct Scope;
59struct Section;
60struct StrBuf;
61
62/* Values for the Flags field */
63#define OBJ_REF 0x0001 /* We have a reference to this file */
64
65/* Internal structure holding object file data */
66typedef struct ObjData ObjData;
67struct 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 */
75 unsigned Flags;
76
77 unsigned HLLSymBaseId; /* Debug info base id for hll symbols */
78 unsigned SymBaseId; /* Debug info base id for symbols */
79 unsigned ScopeBaseId; /* Debug info base id for scopes */
80 unsigned SpanBaseId; /* Debug info base id for spans */
81
82 Collection Files; /* List of input files */
83 Collection Sections; /* List of all sections */
84 Collection Exports; /* List of all exports */
85 Collection Imports; /* List of all imports */
86 Collection DbgSyms; /* List of debug symbols */
87 Collection HLLDbgSyms; /* List of hll debug symbols */
88 Collection LineInfos; /* List of line infos */
89 unsigned StringCount; /* Count of strings */
90 unsigned* Strings; /* List of global string indices */
91 Collection Assertions; /* List of module assertions */
92 Collection Scopes; /* List of scopes */
93 Collection Spans; /* List of spans */
94};
95
96
97
98/* Collection containing used ObjData objects */
99extern Collection ObjDataList;
100
101
102
103/*****************************************************************************/
104/* Code */
105/*****************************************************************************/
106
107
108
109ObjData* NewObjData (void);
110/* Allocate a new structure on the heap, insert it into the list, return it */
111
112void FreeObjData (ObjData* O);
113/* Free an ObjData object. NOTE: This function works only for unused object
114** data, that is, ObjData objects that aren't used because they aren't
115** referenced.
116*/
117
118void FreeObjStrings (ObjData* O);
119/* Free the module string data. Used once the object file is loaded completely
120** when all strings are converted to global strings.
121*/
122
123void InsertObjData (ObjData* O);
124/* Insert the ObjData object into the collection of used ObjData objects. */
125
126void InsertObjGlobals (ObjData* O);
127/* Insert imports and exports from the object file into the global import and
128** export lists.
129*/
130
131unsigned MakeGlobalStringId (const ObjData* O, unsigned Index);
132/* Convert a local string id into a global one and return it. */
133
134const char* GetObjFileName (const ObjData* O);
135/* Get the name of the object file. Return "[linker generated]" if the object
136** file is NULL.
137*/
138
139#if defined(HAVE_INLINE)
140INLINE int ObjHasFiles (const ObjData* O)
141/* Return true if the files list does exist */
142{
143 return (O != 0 && CollCount (&O->Files) != 0);
144}
145#else
146# define ObjHasFiles(O) ((O) != 0 && CollCount (&(O)->Files) != 0)
147#endif
148
149const struct StrBuf* GetObjString (const ObjData* Obj, unsigned Id);
150/* Get a string from an object file checking for an invalid index */
151
152struct Section* GetObjSection (const ObjData* Obj, unsigned Id);
153/* Get a section from an object file checking for a valid index */
154
155struct Import* GetObjImport (const ObjData* Obj, unsigned Id);
156/* Get an import from an object file checking for a valid index */
157
158struct Export* GetObjExport (const ObjData* Obj, unsigned Id);
159/* Get an export from an object file checking for a valid index */
160
161struct DbgSym* GetObjDbgSym (const ObjData* Obj, unsigned Id);
162/* Get a debug symbol from an object file checking for a valid index */
163
164struct Scope* GetObjScope (const ObjData* Obj, unsigned Id);
165/* Get a scope from an object file checking for a valid index */
166
167unsigned ObjDataCount (void);
168/* Return the total number of modules */
169
170void PrintDbgModules (FILE* F);
171/* Output the modules to a debug info file */
172
173
174
175/* End of objdata.h */
176
177#endif
178