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.
45 struct ObjectFileHeader {
49 /// Version ID of the object file format
50 /// For now it must match FORMAT_ID for the loader to be
52 /// Backwards compatibility might be implemented at some
53 /// point in the future, but don't bet on that ever
55 unsigned int versionId;
57 /// File-relative offsets of the export section's begin
58 /// and end respectively.
59 /// Exports are named and typed addresses within the
60 /// file. This is essentially an array of Export structs.
61 unsigned int exportsBegin;
62 unsigned int exportsEnd;
64 /// File-relative offsets of the externals section's
65 /// begin and end respectively.
66 /// Each external names an entity which must be linked in
67 /// for this object file to function properly. This is
68 /// essentially an array of External structs.
69 unsigned int externalsBegin;
70 unsigned int externalsEnd;
72 /// File-relative offsets of the objet section's begin
73 /// and end respectively.
74 /// Each object begins with its type ID followed by its
75 /// size and finally the raw object data.
76 /// All referecte type fields should contain either a
77 /// file-relative offset or zero to indicate a null
79 /// This can be sen as a linked list where the next
80 /// object for a node can be obtained by adding the size
81 /// of to int and the object to the current node's
83 unsigned int objectsBegin;
84 unsigned int objectsEnd;
86 /// File-relative offsets of the array section's begin
87 /// and end respectively.
88 /// Each array consists of an unsigned integer indicating
89 /// its size followed by a boolean flag which is true if
90 /// the arrays consists of pointers followed by the data.
91 unsigned int arraysBegin;
92 unsigned int arraysEnd;
96 /// Check if there are any problems with the file header.
97 /// Throws a std::runtime_error on failure.
98 void IntegrityCheck(unsigned int fileSize) const;
99 Export *ExportsBegin();
100 Export *ExportsEnd();
101 External *ExternalsBegin();
102 External *ExternalsEnd();
103 Object *ObjectsBegin();
104 Object *ObjectsEnd();
105 Array *ArraysBegin();
109 struct LoadedExport {