1 #ifndef LOADER_OBJECTFILE_H_
2 #define LOADER_OBJECTFILE_H_
8 const unsigned int FORMAT_ID = 2;
11 /// Offset of the identifier in the file.
12 unsigned int nameOffset;
13 /// Type ID of referenced object.
15 /// File-offset of the object's actual data.
16 unsigned int dataOffset;
20 /// File-relative offset of the referenced object's
22 unsigned int nameOffset;
23 /// Target position for linking/inlining.
24 unsigned int referenceOffset;
25 /// Nonzero if the object should be copied rather that
26 /// just writing a reference.
44 struct ObjectFileHeader {
48 /// Version ID of the object file format
49 /// For now it must match FORMAT_ID for the loader to be
51 /// Backwards compatibility might be implemented at some
52 /// point in the future, but don't bet on that ever
54 unsigned int versionId;
56 /// File-relative offsets of the export section's begin
57 /// and end respectively.
58 /// Exports are named and typed addresses within the
59 /// file. This is essentially an array of Export structs.
60 unsigned int exportsBegin;
61 unsigned int exportsEnd;
63 /// File-relative offsets of the externals section's
64 /// begin and end respectively.
65 /// Each external names an entity which must be linked in
66 /// for this object file to function properly. This is
67 /// essentially an array of External structs.
68 unsigned int externalsBegin;
69 unsigned int externalsEnd;
71 /// File-relative offsets of the objet section's begin
72 /// and end respectively.
73 /// Each object begins with its type ID followed by its
74 /// size and finally the raw object data.
75 /// All referecte type fields should contain either a
76 /// file-relative offset or zero to indicate a null
78 /// This can be sen as a linked list where the next
79 /// object for a node can be obtained by adding the size
80 /// of to int and the object to the current node's
82 unsigned int objectsBegin;
83 unsigned int objectsEnd;
85 /// File-relative offsets of the array section's begin
86 /// and end respectively.
87 /// Each array consists of an unsigned integer indicating
88 /// its size followed by a boolean flag which is true if
89 /// the arrays consists of pointers followed by the data.
90 unsigned int arraysBegin;
91 unsigned int arraysEnd;
95 /// Check if there are any problems with the file header.
96 /// Throws a std::runtime_error on failure.
97 void IntegrityCheck(unsigned int fileSize) const;
98 Export *ExportsBegin();
100 External *ExternalsBegin();
101 External *ExternalsEnd();
102 Object *ObjectsBegin();
103 Object *ObjectsEnd();
104 Array *ArraysBegin();
108 struct LoadedExport {