annotate gcc/ada/libgnat/s-objrea.ads @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S Y S T E M . O B J E C T _ R E A D E R --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 2009-2019, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- This package implements a simple, minimal overhead reader for object files
kono
parents:
diff changeset
33 -- composed of sections of untyped heterogeneous binary data.
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 with Interfaces;
kono
parents:
diff changeset
36 with System.Mmap;
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 package System.Object_Reader is
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 --------------
kono
parents:
diff changeset
41 -- Limits --
kono
parents:
diff changeset
42 --------------
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 BUFFER_SIZE : constant := 8 * 1024;
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 ---------------------
kono
parents:
diff changeset
47 -- Object sections --
kono
parents:
diff changeset
48 ----------------------
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 type Object_Section is private;
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 Null_Section : constant Object_Section;
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 --------------------
kono
parents:
diff changeset
55 -- Object symbols --
kono
parents:
diff changeset
56 --------------------
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 type Object_Symbol is private;
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 ------------------------
kono
parents:
diff changeset
61 -- Object format type --
kono
parents:
diff changeset
62 ------------------------
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 type Object_Format is
kono
parents:
diff changeset
65 (ELF32,
kono
parents:
diff changeset
66 -- Object format is 32-bit ELF
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 ELF64,
kono
parents:
diff changeset
69 -- Object format is 64-bit ELF
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 PECOFF,
kono
parents:
diff changeset
72 -- Object format is Microsoft PECOFF
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 PECOFF_PLUS,
kono
parents:
diff changeset
75 -- Object format is Microsoft PECOFF+
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 XCOFF32);
kono
parents:
diff changeset
78 -- Object format is AIX 32-bit XCOFF
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 -- PECOFF | PECOFF_PLUS appears so often as a case choice, would
kono
parents:
diff changeset
81 -- seem a good idea to have a subtype name covering these two choices ???
kono
parents:
diff changeset
82
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
83 ------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
84 -- Object files --
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
85 ------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
86
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
87 type Object_File (Format : Object_Format) is private;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
88
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
89 type Object_File_Access is access Object_File;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
90
111
kono
parents:
diff changeset
91 ------------------------------
kono
parents:
diff changeset
92 -- Object architecture type --
kono
parents:
diff changeset
93 ------------------------------
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 type Object_Arch is
kono
parents:
diff changeset
96 (Unknown,
kono
parents:
diff changeset
97 -- The target architecture has not yet been determined
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 SPARC,
kono
parents:
diff changeset
100 -- 32-bit SPARC
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 SPARC64,
kono
parents:
diff changeset
103 -- 64-bit SPARC
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 i386,
kono
parents:
diff changeset
106 -- Intel IA32
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 MIPS,
kono
parents:
diff changeset
109 -- MIPS Technologies MIPS
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 x86_64,
kono
parents:
diff changeset
112 -- x86-64 (64-bit AMD/Intel)
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 IA64,
kono
parents:
diff changeset
115 -- Intel IA64
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 PPC,
kono
parents:
diff changeset
118 -- 32-bit PowerPC
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 PPC64);
kono
parents:
diff changeset
121 -- 64-bit PowerPC
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 ------------------
kono
parents:
diff changeset
124 -- Target types --
kono
parents:
diff changeset
125 ------------------
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 subtype Offset is Interfaces.Integer_64;
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 subtype uint8 is Interfaces.Unsigned_8;
kono
parents:
diff changeset
130 subtype uint16 is Interfaces.Unsigned_16;
kono
parents:
diff changeset
131 subtype uint32 is Interfaces.Unsigned_32;
kono
parents:
diff changeset
132 subtype uint64 is Interfaces.Unsigned_64;
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 subtype int8 is Interfaces.Integer_8;
kono
parents:
diff changeset
135 subtype int16 is Interfaces.Integer_16;
kono
parents:
diff changeset
136 subtype int32 is Interfaces.Integer_32;
kono
parents:
diff changeset
137 subtype int64 is Interfaces.Integer_64;
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 type Buffer is array (0 .. BUFFER_SIZE - 1) of uint8;
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 type String_Ptr_Len is record
kono
parents:
diff changeset
142 Ptr : Mmap.Str_Access;
kono
parents:
diff changeset
143 Len : Natural;
kono
parents:
diff changeset
144 end record;
kono
parents:
diff changeset
145 -- A string made from a pointer and a length. Not all strings for name
kono
parents:
diff changeset
146 -- are C strings: COFF inlined symbol names have a max length of 8.
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 -------------------------------------------
kono
parents:
diff changeset
149 -- Operations on buffers of untyped data --
kono
parents:
diff changeset
150 -------------------------------------------
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 function To_String (Buf : Buffer) return String;
kono
parents:
diff changeset
153 -- Construct string from C style null-terminated string stored in a buffer
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 function To_String_Ptr_Len
kono
parents:
diff changeset
156 (Ptr : Mmap.Str_Access;
kono
parents:
diff changeset
157 Max_Len : Natural := Natural'Last) return String_Ptr_Len;
kono
parents:
diff changeset
158 -- Convert PTR to a String_Ptr_Len.
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 function Strlen (Buf : Buffer) return int32;
kono
parents:
diff changeset
161 -- Return the length of a C style null-terminated string
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 -------------------------
kono
parents:
diff changeset
164 -- Opening and closing --
kono
parents:
diff changeset
165 -------------------------
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 function Open
kono
parents:
diff changeset
168 (File_Name : String;
kono
parents:
diff changeset
169 In_Exception : Boolean := False) return Object_File_Access;
kono
parents:
diff changeset
170 -- Open the object file and initialize the reader. In_Exception is true
kono
parents:
diff changeset
171 -- when the parsing is done as part of an exception handler decorator. In
kono
parents:
diff changeset
172 -- this mode we do not want to raise an exception.
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 procedure Close (Obj : in out Object_File);
kono
parents:
diff changeset
175 -- Close the object file
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 -----------------------
kono
parents:
diff changeset
178 -- Sequential access --
kono
parents:
diff changeset
179 -----------------------
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 type Mapped_Stream is private;
kono
parents:
diff changeset
182 -- Provide an abstraction of a stream on a memory mapped file
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 function Create_Stream (Mf : System.Mmap.Mapped_File;
kono
parents:
diff changeset
185 File_Offset : System.Mmap.File_Size;
kono
parents:
diff changeset
186 File_Length : System.Mmap.File_Size)
kono
parents:
diff changeset
187 return Mapped_Stream;
kono
parents:
diff changeset
188 -- Create a stream from Mf
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 procedure Close (S : in out Mapped_Stream);
kono
parents:
diff changeset
191 -- Close the stream (deallocate memory)
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 procedure Read_Raw
kono
parents:
diff changeset
194 (S : in out Mapped_Stream;
kono
parents:
diff changeset
195 Addr : Address;
kono
parents:
diff changeset
196 Size : uint32);
kono
parents:
diff changeset
197 pragma Inline (Read_Raw);
kono
parents:
diff changeset
198 -- Read a number of fixed sized records
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 procedure Seek (S : in out Mapped_Stream; Off : Offset);
kono
parents:
diff changeset
201 -- Seek to an absolute offset in bytes
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 procedure Tell (Obj : in out Mapped_Stream; Off : out Offset)
kono
parents:
diff changeset
204 with Inline;
kono
parents:
diff changeset
205 function Tell (Obj : Mapped_Stream) return Offset
kono
parents:
diff changeset
206 with Inline;
kono
parents:
diff changeset
207 -- Fetch the current offset
kono
parents:
diff changeset
208
kono
parents:
diff changeset
209 function Length (Obj : Mapped_Stream) return Offset
kono
parents:
diff changeset
210 with Inline;
kono
parents:
diff changeset
211 -- Length of the stream
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 function Read (S : in out Mapped_Stream) return Mmap.Str_Access;
kono
parents:
diff changeset
214 -- Provide a pointer in memory at the current offset
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 function Read (S : in out Mapped_Stream) return String_Ptr_Len;
kono
parents:
diff changeset
217 -- Provide a pointer in memory at the current offset
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 function Read (S : in out Mapped_Stream) return uint8;
kono
parents:
diff changeset
220 function Read (S : in out Mapped_Stream) return uint16;
kono
parents:
diff changeset
221 function Read (S : in out Mapped_Stream) return uint32;
kono
parents:
diff changeset
222 function Read (S : in out Mapped_Stream) return uint64;
kono
parents:
diff changeset
223 function Read (S : in out Mapped_Stream) return int8;
kono
parents:
diff changeset
224 function Read (S : in out Mapped_Stream) return int16;
kono
parents:
diff changeset
225 function Read (S : in out Mapped_Stream) return int32;
kono
parents:
diff changeset
226 function Read (S : in out Mapped_Stream) return int64;
kono
parents:
diff changeset
227 -- Read a scalar
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 function Read_Address
kono
parents:
diff changeset
230 (Obj : Object_File; S : in out Mapped_Stream) return uint64;
kono
parents:
diff changeset
231 -- Read either a 64 or 32 bit address from the file stream depending on the
kono
parents:
diff changeset
232 -- address size of the target architecture and promote it to a 64 bit type.
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 function Read_LEB128 (S : in out Mapped_Stream) return uint32;
kono
parents:
diff changeset
235 function Read_LEB128 (S : in out Mapped_Stream) return int32;
kono
parents:
diff changeset
236 -- Read a value encoding in Little-Endian Base 128 format
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 procedure Read_C_String (S : in out Mapped_Stream; B : out Buffer);
kono
parents:
diff changeset
239 function Read_C_String (S : in out Mapped_Stream) return Mmap.Str_Access;
kono
parents:
diff changeset
240 -- Read a C style NULL terminated string
kono
parents:
diff changeset
241
kono
parents:
diff changeset
242 function Offset_To_String
kono
parents:
diff changeset
243 (S : in out Mapped_Stream;
kono
parents:
diff changeset
244 Off : Offset) return String;
kono
parents:
diff changeset
245 -- Construct a string from a C style NULL terminated string located at an
kono
parents:
diff changeset
246 -- offset into the object file.
kono
parents:
diff changeset
247
kono
parents:
diff changeset
248 ------------------------
kono
parents:
diff changeset
249 -- Object information --
kono
parents:
diff changeset
250 ------------------------
kono
parents:
diff changeset
251
kono
parents:
diff changeset
252 function Arch (Obj : Object_File) return Object_Arch;
kono
parents:
diff changeset
253 -- Return the object architecture
kono
parents:
diff changeset
254
kono
parents:
diff changeset
255 function Format (Obj : Object_File) return Object_Format;
kono
parents:
diff changeset
256 -- Return the object file format
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 function Get_Load_Address (Obj : Object_File) return uint64;
kono
parents:
diff changeset
259 -- Return the load address defined in Obj. May raise Format_Error if not
kono
parents:
diff changeset
260 -- implemented
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262 function Num_Sections (Obj : Object_File) return uint32;
kono
parents:
diff changeset
263 -- Return the number of sections composing the object file
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 function Get_Section
kono
parents:
diff changeset
266 (Obj : in out Object_File;
kono
parents:
diff changeset
267 Shnum : uint32) return Object_Section;
kono
parents:
diff changeset
268 -- Return the Nth section (numbered from zero)
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 function Get_Section
kono
parents:
diff changeset
271 (Obj : in out Object_File;
kono
parents:
diff changeset
272 Sec_Name : String) return Object_Section;
kono
parents:
diff changeset
273 -- Return a section by name
kono
parents:
diff changeset
274
kono
parents:
diff changeset
275 function Create_Stream
kono
parents:
diff changeset
276 (Obj : Object_File;
kono
parents:
diff changeset
277 Sec : Object_Section) return Mapped_Stream;
kono
parents:
diff changeset
278 -- Create a stream for section Sec
kono
parents:
diff changeset
279
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
280 procedure Get_Xcode_Bounds
111
kono
parents:
diff changeset
281 (Obj : in out Object_File;
kono
parents:
diff changeset
282 Low, High : out uint64);
kono
parents:
diff changeset
283 -- Return the low and high addresses of the code for the object file. Can
kono
parents:
diff changeset
284 -- be used to check if an address in within this object file. This
kono
parents:
diff changeset
285 -- procedure is not efficient and the result should be saved to avoid
kono
parents:
diff changeset
286 -- recomputation.
kono
parents:
diff changeset
287
kono
parents:
diff changeset
288 -------------------------
kono
parents:
diff changeset
289 -- Section information --
kono
parents:
diff changeset
290 -------------------------
kono
parents:
diff changeset
291
kono
parents:
diff changeset
292 function Name
kono
parents:
diff changeset
293 (Obj : in out Object_File;
kono
parents:
diff changeset
294 Sec : Object_Section) return String;
kono
parents:
diff changeset
295 -- Return the name of a section as a string
kono
parents:
diff changeset
296
kono
parents:
diff changeset
297 function Size (Sec : Object_Section) return uint64;
kono
parents:
diff changeset
298 -- Return the size of a section in bytes
kono
parents:
diff changeset
299
kono
parents:
diff changeset
300 function Num (Sec : Object_Section) return uint32;
kono
parents:
diff changeset
301 -- Return the index of a section from zero
kono
parents:
diff changeset
302
kono
parents:
diff changeset
303 function Off (Sec : Object_Section) return Offset;
kono
parents:
diff changeset
304 -- Return the byte offset of the section within the object
kono
parents:
diff changeset
305
kono
parents:
diff changeset
306 ------------------------------
kono
parents:
diff changeset
307 -- Symbol table information --
kono
parents:
diff changeset
308 ------------------------------
kono
parents:
diff changeset
309
kono
parents:
diff changeset
310 Null_Symbol : constant Object_Symbol;
kono
parents:
diff changeset
311 -- An empty symbol table entry.
kono
parents:
diff changeset
312
kono
parents:
diff changeset
313 function First_Symbol (Obj : in out Object_File) return Object_Symbol;
kono
parents:
diff changeset
314 -- Return the first element in the symbol table or Null_Symbol if the
kono
parents:
diff changeset
315 -- symbol table is empty.
kono
parents:
diff changeset
316
kono
parents:
diff changeset
317 function Next_Symbol
kono
parents:
diff changeset
318 (Obj : in out Object_File;
kono
parents:
diff changeset
319 Prev : Object_Symbol) return Object_Symbol;
kono
parents:
diff changeset
320 -- Return the element following Prev in the symbol table, or Null_Symbol if
kono
parents:
diff changeset
321 -- Prev is the last symbol in the table.
kono
parents:
diff changeset
322
kono
parents:
diff changeset
323 function Read_Symbol
kono
parents:
diff changeset
324 (Obj : in out Object_File;
kono
parents:
diff changeset
325 Off : Offset) return Object_Symbol;
kono
parents:
diff changeset
326 -- Read symbol at Off
kono
parents:
diff changeset
327
kono
parents:
diff changeset
328 function Name
kono
parents:
diff changeset
329 (Obj : in out Object_File;
kono
parents:
diff changeset
330 Sym : Object_Symbol) return String_Ptr_Len;
kono
parents:
diff changeset
331 -- Return the name of the symbol
kono
parents:
diff changeset
332
kono
parents:
diff changeset
333 function Decoded_Ada_Name
kono
parents:
diff changeset
334 (Obj : in out Object_File;
kono
parents:
diff changeset
335 Sym : String_Ptr_Len) return String;
kono
parents:
diff changeset
336 -- Return the decoded name of a symbol encoded as per exp_dbug.ads
kono
parents:
diff changeset
337
kono
parents:
diff changeset
338 function Strip_Leading_Char
kono
parents:
diff changeset
339 (Obj : in out Object_File;
kono
parents:
diff changeset
340 Sym : String_Ptr_Len) return Positive;
kono
parents:
diff changeset
341 -- Return the index of the first character to decode the name. This can
kono
parents:
diff changeset
342 -- strip one character for ABI with a prefix (like x86 for PECOFF).
kono
parents:
diff changeset
343
kono
parents:
diff changeset
344 function Value (Sym : Object_Symbol) return uint64;
kono
parents:
diff changeset
345 -- Return the name of the symbol
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 function Size (Sym : Object_Symbol) return uint64;
kono
parents:
diff changeset
348 -- Return the size of the symbol in bytes
kono
parents:
diff changeset
349
kono
parents:
diff changeset
350 function Spans (Sym : Object_Symbol; Addr : uint64) return Boolean;
kono
parents:
diff changeset
351 -- Determine whether a particular address corresponds to the range
kono
parents:
diff changeset
352 -- referenced by this symbol.
kono
parents:
diff changeset
353
kono
parents:
diff changeset
354 function Off (Sym : Object_Symbol) return Offset;
kono
parents:
diff changeset
355 -- Return the offset of the symbol.
kono
parents:
diff changeset
356
kono
parents:
diff changeset
357 ----------------
kono
parents:
diff changeset
358 -- Exceptions --
kono
parents:
diff changeset
359 ----------------
kono
parents:
diff changeset
360
kono
parents:
diff changeset
361 IO_Error : exception;
kono
parents:
diff changeset
362 -- Input/Output error reading file
kono
parents:
diff changeset
363
kono
parents:
diff changeset
364 Format_Error : exception;
kono
parents:
diff changeset
365 -- Encountered a problem parsing the object
kono
parents:
diff changeset
366
kono
parents:
diff changeset
367 private
kono
parents:
diff changeset
368 type Mapped_Stream is record
kono
parents:
diff changeset
369 Region : System.Mmap.Mapped_Region;
kono
parents:
diff changeset
370 Off : Offset;
kono
parents:
diff changeset
371 Len : Offset;
kono
parents:
diff changeset
372 end record;
kono
parents:
diff changeset
373
kono
parents:
diff changeset
374 subtype ELF is Object_Format range ELF32 .. ELF64;
kono
parents:
diff changeset
375 subtype Any_PECOFF is Object_Format range PECOFF .. PECOFF_PLUS;
kono
parents:
diff changeset
376
kono
parents:
diff changeset
377 type Object_File (Format : Object_Format) is record
kono
parents:
diff changeset
378 Mf : System.Mmap.Mapped_File :=
kono
parents:
diff changeset
379 System.Mmap.Invalid_Mapped_File;
kono
parents:
diff changeset
380 Arch : Object_Arch := Unknown;
kono
parents:
diff changeset
381
kono
parents:
diff changeset
382 Num_Sections : uint32 := 0;
kono
parents:
diff changeset
383 -- Number of sections
kono
parents:
diff changeset
384
kono
parents:
diff changeset
385 Symtab_Last : Offset; -- Last offset of symbol table
kono
parents:
diff changeset
386
kono
parents:
diff changeset
387 In_Exception : Boolean := False;
kono
parents:
diff changeset
388 -- True if the parsing is done as part of an exception handler
kono
parents:
diff changeset
389
kono
parents:
diff changeset
390 Sectab_Stream : Mapped_Stream;
kono
parents:
diff changeset
391 -- Section table
kono
parents:
diff changeset
392
kono
parents:
diff changeset
393 Symtab_Stream : Mapped_Stream;
kono
parents:
diff changeset
394 -- Symbol table
kono
parents:
diff changeset
395
kono
parents:
diff changeset
396 Symstr_Stream : Mapped_Stream;
kono
parents:
diff changeset
397 -- Symbol strings
kono
parents:
diff changeset
398
kono
parents:
diff changeset
399 case Format is
kono
parents:
diff changeset
400 when ELF =>
kono
parents:
diff changeset
401 Secstr_Stream : Mapped_Stream;
kono
parents:
diff changeset
402 -- Section strings
kono
parents:
diff changeset
403 when Any_PECOFF =>
kono
parents:
diff changeset
404 ImageBase : uint64; -- ImageBase value from header
kono
parents:
diff changeset
405
kono
parents:
diff changeset
406 -- Cache for latest result of Get_Section_Virtual_Address
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408 GSVA_Sec : uint32 := uint32'Last;
kono
parents:
diff changeset
409 GSVA_Addr : uint64;
kono
parents:
diff changeset
410 when XCOFF32 =>
kono
parents:
diff changeset
411 null;
kono
parents:
diff changeset
412 end case;
kono
parents:
diff changeset
413 end record;
kono
parents:
diff changeset
414
kono
parents:
diff changeset
415 subtype ELF_Object_File is Object_File; -- with
kono
parents:
diff changeset
416 -- Predicate => ELF_Object_File.Format in ELF;
kono
parents:
diff changeset
417 subtype PECOFF_Object_File is Object_File; -- with
kono
parents:
diff changeset
418 -- Predicate => PECOFF_Object_File.Format in Any_PECOFF;
kono
parents:
diff changeset
419 subtype XCOFF32_Object_File is Object_File; -- with
kono
parents:
diff changeset
420 -- Predicate => XCOFF32_Object_File.Format in XCOFF32;
kono
parents:
diff changeset
421 -- ???Above predicates cause the compiler to crash when instantiating
kono
parents:
diff changeset
422 -- ELF64_Ops (see package body).
kono
parents:
diff changeset
423
kono
parents:
diff changeset
424 type Object_Section is record
kono
parents:
diff changeset
425 Num : uint32 := 0;
kono
parents:
diff changeset
426 -- Section index in the section table
kono
parents:
diff changeset
427
kono
parents:
diff changeset
428 Off : Offset := 0;
kono
parents:
diff changeset
429 -- First byte of the section in the object file
kono
parents:
diff changeset
430
kono
parents:
diff changeset
431 Addr : uint64 := 0;
kono
parents:
diff changeset
432 -- Load address of the section. Valid only when Flag_Alloc is true.
kono
parents:
diff changeset
433
kono
parents:
diff changeset
434 Size : uint64 := 0;
kono
parents:
diff changeset
435 -- Length of the section in bytes
kono
parents:
diff changeset
436
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
437 Flag_Xcode : Boolean := False;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
438 -- True if the section is advertised to contain executable code
111
kono
parents:
diff changeset
439 end record;
kono
parents:
diff changeset
440
kono
parents:
diff changeset
441 Null_Section : constant Object_Section := (0, 0, 0, 0, False);
kono
parents:
diff changeset
442
kono
parents:
diff changeset
443 type Object_Symbol is record
kono
parents:
diff changeset
444 Off : Offset := 0; -- Offset of underlying symbol on disk
kono
parents:
diff changeset
445 Next : Offset := 0; -- Offset of the following symbol
kono
parents:
diff changeset
446 Value : uint64 := 0; -- Value associated with this symbol
kono
parents:
diff changeset
447 Size : uint64 := 0; -- Size of the referenced entity
kono
parents:
diff changeset
448 end record;
kono
parents:
diff changeset
449
kono
parents:
diff changeset
450 Null_Symbol : constant Object_Symbol := (0, 0, 0, 0);
kono
parents:
diff changeset
451 end System.Object_Reader;