RTEMS CPU Kit with SuperCore  4.11.3
rtl-obj.h
Go to the documentation of this file.
1 /*
2  * COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
3  *
4  * The license and distribution terms for this file may be
5  * found in the file LICENSE in this distribution or at
6  * http://www.rtems.org/license/LICENSE.
7  */
16 #if !defined (_RTEMS_RTL_OBJ_H_)
17 #define _RTEMS_RTL_OBJ_H_
18 
19 #include <rtems.h>
20 #include <rtems/chain.h>
21 #include <rtems/rtl/rtl-sym.h>
22 #include <rtems/rtl/rtl-unresolved.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif /* __cplusplus */
27 
31 #define RTEMS_RTL_FMT_ELF (1 << 0)
32 #define RTEMS_RTL_FMT_COMP (1 << 1)
33 #define RTEMS_RTL_FMT_PRIVATE (1 << 16)
34 
39 {
44  const char* label;
45 
49  uint32_t flags;
51 
56 typedef bool (*rtems_rtl_loader_check) (rtems_rtl_obj_t* obj, int fd);
57 
62 typedef bool (*rtems_rtl_loader_load) (rtems_rtl_obj_t* obj, int fd);
63 
69 
74 typedef rtems_rtl_loader_format_t* (*rtems_rtl_loader_sig) (void);
75 
80 {
86 
90 #define RTEMS_RTL_OBJ_SECT_TEXT (1 << 0)
91 #define RTEMS_RTL_OBJ_SECT_CONST (1 << 1)
92 #define RTEMS_RTL_OBJ_SECT_DATA (1 << 2)
93 #define RTEMS_RTL_OBJ_SECT_BSS (1 << 3)
94 #define RTEMS_RTL_OBJ_SECT_EH (1 << 4)
95 #define RTEMS_RTL_OBJ_SECT_REL (1 << 5)
96 #define RTEMS_RTL_OBJ_SECT_RELA (1 << 6)
98 #define RTEMS_RTL_OBJ_SECT_SYM (1 << 7)
99 #define RTEMS_RTL_OBJ_SECT_STR (1 << 8)
100 #define RTEMS_RTL_OBJ_SECT_ALLOC (1 << 9)
101 #define RTEMS_RTL_OBJ_SECT_LOAD (1 << 10)
102 #define RTEMS_RTL_OBJ_SECT_WRITE (1 << 11)
103 #define RTEMS_RTL_OBJ_SECT_EXEC (1 << 12)
104 #define RTEMS_RTL_OBJ_SECT_ZERO (1 << 13)
105 #define RTEMS_RTL_OBJ_SECT_LINK (1 << 14)
106 #define RTEMS_RTL_OBJ_SECT_CTOR (1 << 15)
107 #define RTEMS_RTL_OBJ_SECT_DTOR (1 << 16)
108 #define RTEMS_RTL_OBJ_SECT_LOCD (1 << 17)
113 #define RTEMS_RTL_OBJ_SECT_TYPES (RTEMS_RTL_OBJ_SECT_TEXT | \
114  RTEMS_RTL_OBJ_SECT_CONST | \
115  RTEMS_RTL_OBJ_SECT_DATA | \
116  RTEMS_RTL_OBJ_SECT_BSS | \
117  RTEMS_RTL_OBJ_SECT_EH)
118 
125 {
126  rtems_chain_node node;
127  int section;
128  const char* name;
129  size_t size;
130  off_t offset;
132  uint32_t alignment;
133  int link;
134  int info;
135  uint32_t flags;
136  void* base;
138  int load_order;
139 };
140 
144 #define RTEMS_RTL_OBJ_LOCKED (1 << 0)
146 #define RTEMS_RTL_OBJ_UNRESOLVED (1 << 1)
153 struct rtems_rtl_obj_s
154 {
156  uint32_t flags;
157  uint32_t users;
158  int format;
159  const char* fname;
160  const char* oname;
162  const char* aname;
165  off_t ooffset;
166  size_t fsize;
167  rtems_chain_control sections;
169  rtems_rtl_obj_sym_t* local_table;
170  size_t local_syms;
171  size_t local_size;
172  rtems_rtl_obj_sym_t* global_table;
173  size_t global_syms;
174  size_t global_size;
175  uint32_t unresolved;
176  void* text_base;
178  size_t text_size;
179  void* const_base;
181  void* eh_base;
183  size_t eh_size;
184  void* data_base;
186  void* bss_base;
188  size_t bss_size;
189  size_t exec_size;
191  void* entry;
192  uint32_t checksum;
194  uint32_t* sec_num;
195  uint32_t obj_num;
196  struct link_map* linkmap;
197  void* loader;
198 };
211 typedef bool (*rtems_rtl_obj_sect_handler_t)(rtems_rtl_obj_t* obj,
212  int fd,
213  rtems_rtl_obj_sect_t* sect,
214  void* data);
215 
222 static inline const char* rtems_rtl_obj_fname (const rtems_rtl_obj_t* obj)
223 {
224  return obj->fname;
225 }
226 
233 static inline bool rtems_rtl_obj_fname_valid (const rtems_rtl_obj_t* obj)
234 {
235  return obj->fname;
236 }
237 
244 static inline const char* rtems_rtl_obj_oname (const rtems_rtl_obj_t* obj)
245 {
246  return obj->oname;
247 }
248 
255 static inline bool rtems_rtl_obj_oname_valid (const rtems_rtl_obj_t* obj)
256 {
257  return obj->oname;
258 }
259 
266 static inline const char* rtems_rtl_obj_aname (const rtems_rtl_obj_t* obj)
267 {
268  return obj->aname;
269 }
270 
277 static inline bool rtems_rtl_obj_aname_valid (const rtems_rtl_obj_t* obj)
278 {
279  return obj->aname;
280 }
281 
288 static inline bool rtems_rtl_obj_text_inside (const rtems_rtl_obj_t* obj,
289  const void* address)
290 {
291  return
292  (address >= obj->text_base) &&
293  (address < (obj->text_base + obj->text_size));
294 }
295 
302 
311 
321 
333 bool rtems_rtl_parse_name (const char* name,
334  const char** aname,
335  const char** oname,
336  off_t* ooffset);
337 
344 bool rtems_rtl_match_name (rtems_rtl_obj_t* obj, const char* name);
345 
356 bool rtems_rtl_obj_find_file (rtems_rtl_obj_t* obj, const char* name);
357 
374  int section,
375  const char* name,
376  size_t size,
377  off_t offset,
378  uint32_t alignment,
379  int link,
380  int info,
381  uint32_t flags);
382 
389 
399  const char* name);
400 
410  int index);
411 
420 size_t rtems_rtl_obj_text_size (const rtems_rtl_obj_t* obj);
421 
433 uint32_t rtems_rtl_obj_text_alignment (const rtems_rtl_obj_t* obj);
434 
443 size_t rtems_rtl_obj_const_size (const rtems_rtl_obj_t* obj);
444 
456 uint32_t rtems_rtl_obj_const_alignment (const rtems_rtl_obj_t* obj);
457 
465 size_t rtems_rtl_obj_eh_size (const rtems_rtl_obj_t* obj);
466 
478 uint32_t rtems_rtl_obj_eh_alignment (const rtems_rtl_obj_t* obj);
479 
488 size_t rtems_rtl_obj_data_size (const rtems_rtl_obj_t* obj);
489 
501 uint32_t rtems_rtl_obj_data_alignment (const rtems_rtl_obj_t* obj);
502 
510 size_t rtems_rtl_obj_bss_size (const rtems_rtl_obj_t* obj);
511 
523 uint32_t rtems_rtl_obj_bss_alignment (const rtems_rtl_obj_t* obj);
524 
537  int fd,
539  void* data);
540 
547 
557  rtems_rtl_obj_sym_t* sym);
558 
571  int fd,
573  void* data);
574 
588  int fd,
590  void* data);
591 
601 
611 
621 
630 
631 #ifdef __cplusplus
632 }
633 #endif /* __cplusplus */
634 
635 #endif
size_t rtems_rtl_obj_text_size(const rtems_rtl_obj_t *obj)
The text section size.
Definition: rtl-obj.c:521
This is used to manage each element (node) which is placed on a chain.
Definition: chain.h:65
rtems_rtl_obj_t * rtems_rtl_obj_alloc(void)
Allocate an object structure on the heap.
Definition: rtl-obj.c:71
uint32_t rtems_rtl_obj_text_alignment(const rtems_rtl_obj_t *obj)
The text section alignment for the object file.
Definition: rtl-obj.c:527
Unresolved externals symbols require the relocation records to be held and references.
Definition: rtl-unresolved.h:94
Table for supported loadable formats.
Definition: rtl-obj.h:79
Definition: mknod-pack_dev.c:255
An object file is made up of sections and the can be more than one of a specific type of sections...
Definition: rtl-obj.h:125
bool rtems_rtl_obj_load_sections(rtems_rtl_obj_t *obj, int fd, rtems_rtl_obj_sect_handler_t handler, void *data)
Load the sections that have been allocated memory in the target.
Definition: rtl-obj.c:820
This is used to manage a chain.
Definition: chain.h:83
bool rtems_rtl_parse_name(const char *name, const char **aname, const char **oname, off_t *ooffset)
Parses a filename and returns newly allocated strings with the archive name, object name...
Definition: rtl-obj.c:130
rtems_rtl_loader_load load
The loader.
Definition: rtl-obj.h:82
bool rtems_rtl_obj_relocate_unresolved(rtems_rtl_unresolv_reloc_t *reloc, rtems_rtl_obj_sym_t *sym)
Relocate an object file&#39;s unresolved reference.
Definition: rtl-elf.c:283
bool(* rtems_rtl_loader_load)(rtems_rtl_obj_t *obj, int fd)
The type of the format loader load handler.
Definition: rtl-obj.h:62
uint32_t rtems_rtl_obj_bss_alignment(const rtems_rtl_obj_t *obj)
The bss section alignment for the object file.
Definition: rtl-obj.c:575
bool rtems_rtl_obj_relocate(rtems_rtl_obj_t *obj, int fd, rtems_rtl_obj_sect_handler_t handler, void *data)
Relocate the object file.
Definition: rtl-obj.c:581
uint32_t flags
The format flags.
Definition: rtl-obj.h:49
const char * oname
The object file name.
Definition: rtl-obj.h:163
rtems_rtl_obj_sect_t * rtems_rtl_obj_find_section_by_index(const rtems_rtl_obj_t *obj, int index)
Find a section given a section&#39;s index number.
Definition: rtl-obj.c:508
size_t text_size
The size of the text section.
Definition: rtl-obj.h:181
bool(* rtems_rtl_loader_unload)(rtems_rtl_obj_t *obj)
The type of the format loader unload handler.
Definition: rtl-obj.h:68
bool rtems_rtl_obj_add_section(rtems_rtl_obj_t *obj, int section, const char *name, size_t size, off_t offset, uint32_t alignment, int link, int info, uint32_t flags)
Add a section to the object descriptor.
Definition: rtl-obj.c:405
size_t rtems_rtl_obj_bss_size(const rtems_rtl_obj_t *obj)
The bss section size.
Definition: rtl-obj.c:569
An object file symbol.
Definition: rtl-sym.h:29
uint32_t rtems_rtl_obj_const_alignment(const rtems_rtl_obj_t *obj)
The const section alignment for the object file.
Definition: rtl-obj.c:551
bool rtems_rtl_obj_unresolved(rtems_rtl_obj_t *obj)
Does the object file have unresolved external references ? If it does the results of executing code i...
Definition: rtl-obj.c:124
rtems_rtl_obj_sect_t * rtems_rtl_obj_find_section(const rtems_rtl_obj_t *obj, const char *name)
Find the section given a name.
Definition: rtl-obj.c:482
uint32_t rtems_rtl_obj_eh_alignment(const rtems_rtl_obj_t *obj)
The eh section alignment for the object file.
Definition: rtl-obj.c:539
bool rtems_rtl_obj_free(rtems_rtl_obj_t *obj)
Free the object structure and related resources.
Definition: rtl-obj.c:102
void * text_base
The base address of the text section in memory.
Definition: rtl-obj.h:179
RTL Object.
Definition: rtl-obj.h:156
bool rtems_rtl_obj_find_file(rtems_rtl_obj_t *obj, const char *name)
Find an object file on disk that matches the name.
Definition: rtl-obj.c:365
void rtems_rtl_obj_erase_sections(rtems_rtl_obj_t *obj)
Erase the object file descriptor&#39;s sections.
Definition: rtl-obj.c:444
void rtems_rtl_obj_run_ctors(rtems_rtl_obj_t *obj)
Invoke the constructors the object has.
Definition: rtl-obj.c:928
bool rtems_rtl_obj_unload(rtems_rtl_obj_t *obj)
Unload the object file, erasing all symbols and releasing all memory.
Definition: rtl-obj.c:1245
uint32_t rtems_rtl_obj_data_alignment(const rtems_rtl_obj_t *obj)
The data section alignment for the object file.
Definition: rtl-obj.c:563
const char * aname
The archive name containing the object.
Definition: rtl-obj.h:165
bool rtems_rtl_match_name(rtems_rtl_obj_t *obj, const char *name)
Check of the name matches the object file&#39;s object name.
Definition: rtl-obj.c:349
void rtems_rtl_obj_synchronize_cache(rtems_rtl_obj_t *obj)
Synchronize caches to make code visible to CPU(s)
Definition: rtl-obj.c:635
Chain API.
rtems_rtl_loader_format_t *(* rtems_rtl_loader_sig)(void)
The type of the format loader signature handler.
Definition: rtl-obj.h:74
rtems_rtl_loader_check check
The check handler.
Definition: rtl-obj.h:81
bool(* rtems_rtl_obj_sect_handler_t)(rtems_rtl_obj_t *obj, int fd, rtems_rtl_obj_sect_t *sect, void *data)
A section handler is called once for each section that needs to be processed by this handler...
Definition: rtl-obj.h:214
struct rtems_rtl_loader_format_s rtems_rtl_loader_format_t
Loader format definition.
Definition: nfs_prot.h:234
rtems_rtl_loader_sig signature
The loader&#39;s signature.
Definition: rtl-obj.h:84
struct rtems_rtl_loader_table_s rtems_rtl_loader_table_t
Table for supported loadable formats.
bool rtems_rtl_obj_load_symbols(rtems_rtl_obj_t *obj, int fd, rtems_rtl_obj_sect_handler_t handler, void *data)
Load the symbols from the object file.
Definition: rtl-obj.c:661
size_t rtems_rtl_obj_const_size(const rtems_rtl_obj_t *obj)
The const section size.
Definition: rtl-obj.c:533
const char * fname
The file name for the object.
Definition: rtl-obj.h:162
size_t rtems_rtl_obj_eh_size(const rtems_rtl_obj_t *obj)
The eh section size.
Definition: rtl-obj.c:545
size_t rtems_rtl_obj_data_size(const rtems_rtl_obj_t *obj)
The data section size.
Definition: rtl-obj.c:557
Loader format definition.
Definition: rtl-obj.h:38
rtems_rtl_loader_unload unload
The unloader.
Definition: rtl-obj.h:83
void rtems_rtl_obj_run_dtors(rtems_rtl_obj_t *obj)
Invoke the destructors the object has.
Definition: rtl-obj.c:934
bool(* rtems_rtl_loader_check)(rtems_rtl_obj_t *obj, int fd)
The type of the format loader check handler.
Definition: rtl-obj.h:56
const char * label
The format label.
Definition: rtl-obj.h:44
bool rtems_rtl_obj_load(rtems_rtl_obj_t *obj)
Load the object file, reading all sections into memory, symbols and performing any relocation fixups...
Definition: rtl-obj.c:1194