RTEMS  5.1
rtl-obj.h
Go to the documentation of this file.
1 /*
2  * COPYRIGHT (c) 2012,2019 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>
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* obj, int fd);
57 
62 typedef bool (*rtems_rtl_loader_load) (rtems_rtl_obj* obj, int fd);
63 
68 typedef bool (*rtems_rtl_loader_unload) (rtems_rtl_obj* obj);
69 
74 typedef rtems_rtl_loader_format* (*rtems_rtl_loader_sig) (void);
75 
79 typedef struct rtems_rtl_loader_table
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_TLS (1 << 5)
96 #define RTEMS_RTL_OBJ_SECT_REL (1 << 6)
97 #define RTEMS_RTL_OBJ_SECT_RELA (1 << 7)
98 #define RTEMS_RTL_OBJ_SECT_SYM (1 << 8)
99 #define RTEMS_RTL_OBJ_SECT_STR (1 << 9)
100 #define RTEMS_RTL_OBJ_SECT_ALLOC (1 << 10
101 #define RTEMS_RTL_OBJ_SECT_LOAD (1 << 11)
102 #define RTEMS_RTL_OBJ_SECT_WRITE (1 << 12)
103 #define RTEMS_RTL_OBJ_SECT_EXEC (1 << 13)
104 #define RTEMS_RTL_OBJ_SECT_ZERO (1 << 14)
105 #define RTEMS_RTL_OBJ_SECT_LINK (1 << 15)
106 #define RTEMS_RTL_OBJ_SECT_CTOR (1 << 16)
107 #define RTEMS_RTL_OBJ_SECT_DTOR (1 << 17)
108 #define RTEMS_RTL_OBJ_SECT_LOCD (1 << 18)
109 #define RTEMS_RTL_OBJ_SECT_ARCH_ALLOC (1 << 19)
114 #define RTEMS_RTL_OBJ_SECT_TYPES (RTEMS_RTL_OBJ_SECT_TEXT | \
115  RTEMS_RTL_OBJ_SECT_CONST | \
116  RTEMS_RTL_OBJ_SECT_DATA | \
117  RTEMS_RTL_OBJ_SECT_BSS | \
118  RTEMS_RTL_OBJ_SECT_TLS | \
119  RTEMS_RTL_OBJ_SECT_EH)
120 
127 {
129  int section;
130  const char* name;
131  size_t size;
132  off_t offset;
134  uint32_t alignment;
135  int link;
136  int info;
137  uint32_t flags;
138  void* base;
141 };
142 
150 {
152  size_t dependents;
154 };
155 
160  rtems_rtl_obj* dependent,
161  void* data);
162 
166 #define RTEMS_RTL_OBJ_LOCKED (1 << 0)
168 #define RTEMS_RTL_OBJ_UNRESOLVED (1 << 1)
170 #define RTEMS_RTL_OBJ_BASE (1 << 2)
171 #define RTEMS_RTL_OBJ_RELOC_TAG (1 << 3)
173 #define RTEMS_RTL_OBJ_DEP_VISITED (1 << 4)
174 #define RTEMS_RTL_OBJ_CTOR_RUN (1 << 5)
180 struct rtems_rtl_obj
181 {
183  uint32_t flags;
184  size_t users;
185  size_t refs;
186  int format;
187  const char* fname;
188  const char* oname;
190  const char* aname;
193  off_t ooffset;
194  size_t fsize;
195  rtems_chain_control sections;
197  rtems_chain_control dependents;
198  rtems_rtl_obj_sym* local_table;
199  size_t local_syms;
200  size_t local_size;
201  rtems_rtl_obj_sym* global_table;
202  size_t global_syms;
203  size_t global_size;
204  size_t unresolved;
205  void* text_base;
207  size_t text_size;
208  void* const_base;
210  size_t const_size;
211  void* eh_base;
213  size_t eh_size;
214  void* data_base;
216  size_t data_size;
217  void* bss_base;
219  size_t bss_size;
220  size_t exec_size;
222  void* entry;
223  uint32_t checksum;
225  uint32_t* sec_num;
226  uint32_t obj_num;
228  void* trampoline;
230  size_t tramp_size;
231  size_t tramps_size;
232  void* tramp_brk;
235  size_t tramp_relocs;
238  struct link_map* linkmap;
239  void* loader;
241 };
254 typedef bool (*rtems_rtl_obj_sect_handler)(rtems_rtl_obj* obj,
255  int fd,
256  rtems_rtl_obj_sect* sect,
257  void* data);
258 
265 static inline const char* rtems_rtl_obj_fname (const rtems_rtl_obj* obj)
266 {
267  return obj->fname;
268 }
269 
276 static inline bool rtems_rtl_obj_fname_valid (const rtems_rtl_obj* obj)
277 {
278  return obj->fname;
279 }
280 
287 static inline const char* rtems_rtl_obj_oname (const rtems_rtl_obj* obj)
288 {
289  return obj->oname;
290 }
291 
298 static inline bool rtems_rtl_obj_oname_valid (const rtems_rtl_obj* obj)
299 {
300  return obj->oname;
301 }
302 
309 static inline const char* rtems_rtl_obj_aname (const rtems_rtl_obj* obj)
310 {
311  return obj->aname;
312 }
313 
320 static inline bool rtems_rtl_obj_aname_valid (const rtems_rtl_obj* obj)
321 {
322  return obj->aname;
323 }
324 
331 static inline bool rtems_rtl_obj_text_inside (const rtems_rtl_obj* obj,
332  const void* address)
333 {
334  return
335  (address >= obj->text_base) &&
336  (address < (obj->text_base + obj->text_size));
337 }
338 
348 static inline size_t rtems_rtl_obj_align (size_t offset,
349  uint32_t alignment)
350 {
351  if ((alignment > 1) && ((offset & (alignment - 1)) != 0))
352  offset = (offset + alignment) & ~(alignment - 1);
353  return offset;
354 }
355 
363 static inline bool rtems_rtl_obj_has_symbol (const rtems_rtl_obj* obj,
364  const rtems_rtl_obj_sym* sym)
365 {
366  return (sym >= obj->global_table &&
367  sym < (obj->global_table + obj->global_syms));
368 }
369 
377 static inline bool rtems_rtl_obj_has_tramp_space (const rtems_rtl_obj* obj,
378  const size_t size)
379 {
380  return (obj->trampoline != NULL &&
381  ((obj->tramp_brk - obj->trampoline) + size) <= obj->tramps_size);
382 }
383 
390 static inline size_t rtems_rtl_obj_trampoline_slots (const rtems_rtl_obj* obj)
391 {
392  return obj->trampoline == NULL || obj->tramp_size == 0 ?
393  0 : obj->tramps_size / obj->tramp_size;
394 }
395 
402 static inline size_t rtems_rtl_obj_trampolines (const rtems_rtl_obj* obj)
403 {
404  return obj->trampoline == NULL || obj->tramp_size == 0 ?
405  0 : (obj->tramp_brk - obj->trampoline) / obj->tramp_size;
406 }
407 
414 static inline bool rtems_rtl_obj_sect_is_arch_alloc (rtems_rtl_obj_sect* sect)
415 {
416  return (sect->flags & RTEMS_RTL_OBJ_SECT_ARCH_ALLOC) != 0;
417 }
418 
425 
434 
444 
456 bool rtems_rtl_parse_name (const char* name,
457  const char** aname,
458  const char** oname,
459  off_t* ooffset);
460 
471 bool rtems_rtl_obj_find_file (rtems_rtl_obj* obj, const char* name);
472 
489  int section,
490  const char* name,
491  size_t size,
492  off_t offset,
493  uint32_t alignment,
494  int link,
495  int info,
496  uint32_t flags);
497 
504 
514  const char* name);
515 
525  int index);
526 
540  int index,
541  uint32_t mask);
542 
551 
558 
567 bool rtems_rtl_obj_alloc_dependents (rtems_rtl_obj* obj, size_t dependents);
568 
575 
585 
594 
606  void* data);
607 
616 size_t rtems_rtl_obj_text_size (const rtems_rtl_obj* obj);
617 
629 uint32_t rtems_rtl_obj_text_alignment (const rtems_rtl_obj* obj);
630 
639 size_t rtems_rtl_obj_const_size (const rtems_rtl_obj* obj);
640 
652 uint32_t rtems_rtl_obj_const_alignment (const rtems_rtl_obj* obj);
653 
661 size_t rtems_rtl_obj_eh_size (const rtems_rtl_obj* obj);
662 
674 uint32_t rtems_rtl_obj_eh_alignment (const rtems_rtl_obj* obj);
675 
684 size_t rtems_rtl_obj_data_size (const rtems_rtl_obj* obj);
685 
697 uint32_t rtems_rtl_obj_data_alignment (const rtems_rtl_obj* obj);
698 
706 size_t rtems_rtl_obj_bss_size (const rtems_rtl_obj* obj);
707 
719 uint32_t rtems_rtl_obj_bss_alignment (const rtems_rtl_obj* obj);
720 
733  int fd,
735  void* data);
736 
743 
753  rtems_rtl_obj_sym* sym);
754 
767  int fd,
769  void* data);
770 
782 bool
784  int fd,
786  void* data);
787 
801  int fd,
803  void* data);
804 
811 
821 
828 
838 
845 
852 
859 
867 
877 
886 
887 #ifdef __cplusplus
888 }
889 #endif /* __cplusplus */
890 
891 #endif
bool rtems_rtl_obj_dtors_to_run(rtems_rtl_obj *obj)
Definition: rtl-obj.c:1309
Definition: rtl-unresolved.h:108
Definition: chain.h:68
bool rtems_rtl_obj_find_file(rtems_rtl_obj *obj, const char *name)
Definition: rtl-obj.c:385
void rtems_rtl_obj_run_dtors(rtems_rtl_obj *obj)
Definition: rtl-obj.c:1315
rtems_rtl_obj_sym * global_table
Definition: rtl-obj.h:204
void * text_base
Definition: rtl-obj.h:208
uint32_t rtems_rtl_obj_bss_alignment(const rtems_rtl_obj *obj)
Definition: rtl-obj.c:812
bool rtems_rtl_obj_free(rtems_rtl_obj *obj)
Definition: rtl-obj.c:106
rtems_rtl_loader_sig signature
Definition: rtl-obj.h:84
const char * name
Definition: rtl-obj.h:130
rtems_rtl_obj * rtems_rtl_obj_alloc(void)
Definition: rtl-obj.c:74
void * base
Definition: rtl-obj.h:138
void rtems_rtl_obj_dec_reference(rtems_rtl_obj *obj)
Definition: rtl-obj.c:1357
bool rtems_rtl_obj_ctors_to_run(rtems_rtl_obj *obj)
Definition: rtl-obj.c:1297
Definition: mknod-pack_dev.c:254
rtems_rtl_loader_format *(* rtems_rtl_loader_sig)(void)
Definition: rtl-obj.h:74
bool rtems_rtl_obj_add_section(rtems_rtl_obj *obj, int section, const char *name, size_t size, off_t offset, uint32_t alignment, int link, int info, uint32_t flags)
Definition: rtl-obj.c:425
bool rtems_rtl_obj_orphaned(rtems_rtl_obj *obj)
Definition: rtl-obj.c:1364
uint32_t flags
Definition: rtl-obj.h:49
bool(* rtems_rtl_loader_load)(rtems_rtl_obj *obj, int fd)
Definition: rtl-obj.h:62
Definition: chain.h:86
rtems_rtl_obj_sect * rtems_rtl_obj_find_section(const rtems_rtl_obj *obj, const char *name)
Definition: rtl-obj.c:504
bool rtems_rtl_parse_name(const char *name, const char **aname, const char **oname, off_t *ooffset)
Definition: rtl-obj.c:202
Definition: rtl-obj.h:183
RTEMS Run-Time Linker Object File Symbol Table.
size_t size
Definition: rtl-obj.h:131
#define RTEMS_RTL_OBJ_SECT_ARCH_ALLOC
Definition: rtl-obj.h:109
void * trampoline
Definition: rtl-obj.h:231
Definition: rtl-obj.h:38
rtems_rtl_loader_unload unload
Definition: rtl-obj.h:83
bool(* rtems_rtl_loader_unload)(rtems_rtl_obj *obj)
Definition: rtl-obj.h:68
uint32_t rtems_rtl_obj_const_alignment(const rtems_rtl_obj *obj)
Definition: rtl-obj.c:771
bool rtems_rtl_obj_unload(rtems_rtl_obj *obj)
Definition: rtl-obj.c:1433
void rtems_rtl_obj_erase_trampoline(rtems_rtl_obj *obj)
Definition: rtl-obj.c:597
size_t tramp_size
Definition: rtl-obj.h:233
rtems_rtl_obj_sect * rtems_rtl_obj_find_section_by_mask(const rtems_rtl_obj *obj, int index, uint32_t mask)
Definition: rtl-obj.c:567
bool rtems_rtl_obj_relocate(rtems_rtl_obj *obj, int fd, rtems_rtl_obj_sect_handler handler, void *data)
Definition: rtl-obj.c:818
size_t rtems_rtl_obj_data_size(const rtems_rtl_obj *obj)
Definition: rtl-obj.c:792
Definition: rtl-sym.h:29
bool rtems_rtl_obj_alloc_dependents(rtems_rtl_obj *obj, size_t dependents)
Definition: rtl-obj.c:603
bool rtems_rtl_obj_load(rtems_rtl_obj *obj)
Definition: rtl-obj.c:1372
void rtems_rtl_obj_synchronize_cache(rtems_rtl_obj *obj)
Definition: rtl-obj.c:876
size_t rtems_rtl_obj_eh_size(const rtems_rtl_obj *obj)
Definition: rtl-obj.c:785
Definition: rtl-obj.h:79
bool(* rtems_rtl_obj_sect_handler)(rtems_rtl_obj *obj, int fd, rtems_rtl_obj_sect *sect, void *data)
Definition: rtl-obj.h:257
bool rtems_rtl_obj_load_symbols(rtems_rtl_obj *obj, int fd, rtems_rtl_obj_sect_handler handler, void *data)
Definition: rtl-obj.c:910
rtems_chain_node node
Definition: rtl-obj.h:151
void * tramp_brk
Definition: rtl-obj.h:235
bool(* rtems_rtl_loader_check)(rtems_rtl_obj *obj, int fd)
Definition: rtl-obj.h:56
bool rtems_rtl_obj_remove_dependencies(rtems_rtl_obj *obj)
Definition: rtl-obj.c:694
void rtems_rtl_obj_run_ctors(rtems_rtl_obj *obj)
Definition: rtl-obj.c:1303
uint32_t rtems_rtl_obj_text_alignment(const rtems_rtl_obj *obj)
Definition: rtl-obj.c:757
int load_order
Definition: rtl-obj.h:140
bool rtems_rtl_obj_load_sections(rtems_rtl_obj *obj, int fd, rtems_rtl_obj_sect_handler handler, void *data)
Definition: rtl-obj.c:1227
void rtems_rtl_obj_erase_dependents(rtems_rtl_obj *obj)
Definition: rtl-obj.c:627
int info
Definition: rtl-obj.h:136
size_t tramps_size
Definition: rtl-obj.h:234
size_t rtems_rtl_obj_bss_size(const rtems_rtl_obj *obj)
Definition: rtl-obj.c:806
uint32_t alignment
Definition: rtl-obj.h:134
rtems_chain_node node
Definition: rtl-obj.h:128
size_t dependents
Definition: rtl-obj.h:152
Definition: rtl-obj.h:149
bool rtems_rtl_obj_iterate_dependents(rtems_rtl_obj *obj, rtems_rtl_obj_depends_iterator iterator, void *data)
Definition: rtl-obj.c:727
Chain API.
rtems_rtl_loader_check check
Definition: rtl-obj.h:81
size_t rtems_rtl_obj_get_reference(rtems_rtl_obj *obj)
Definition: rtl-obj.c:1345
const char * fname
Definition: rtl-obj.h:190
uint32_t flags
Definition: rtl-obj.h:137
size_t rtems_rtl_obj_text_size(const rtems_rtl_obj *obj)
Definition: rtl-obj.c:750
bool rtems_rtl_obj_unresolved(rtems_rtl_obj *obj)
Definition: rtl-obj.c:171
bool(* rtems_rtl_obj_depends_iterator)(rtems_rtl_obj *obj, rtems_rtl_obj *dependent, void *data)
Definition: rtl-obj.h:159
size_t global_syms
Definition: rtl-obj.h:205
bool rtems_rtl_obj_relocate_unresolved(rtems_rtl_unresolv_reloc *reloc, rtems_rtl_obj_sym *sym)
Definition: rtl-elf.c:565
struct rtems_rtl_loader_table rtems_rtl_loader_table
struct rtems_rtl_loader_format rtems_rtl_loader_format
const char * label
Definition: rtl-obj.h:44
Definition: rtl-obj.h:126
const char * oname
Definition: rtl-obj.h:191
int section
Definition: rtl-obj.h:129
uint32_t rtems_rtl_obj_data_alignment(const rtems_rtl_obj *obj)
Definition: rtl-obj.c:799
rtems_rtl_loader_load load
Definition: rtl-obj.h:82
size_t rtems_rtl_obj_const_size(const rtems_rtl_obj *obj)
Definition: rtl-obj.c:764
Definition: mmu-config.c:40
uint32_t rtems_rtl_obj_eh_alignment(const rtems_rtl_obj *obj)
Definition: rtl-obj.c:778
unsigned size
Definition: tte.h:74
RTEMS Run-Time Linker Object File Unresolved Relocations Table.
int link
Definition: rtl-obj.h:135
rtems_rtl_obj * depends[]
Definition: rtl-obj.h:153
off_t offset
Definition: rtl-obj.h:132
rtems_rtl_obj_sect * rtems_rtl_obj_find_section_by_index(const rtems_rtl_obj *obj, int index)
Definition: rtl-obj.c:532
bool rtems_rtl_obj_alloc_trampoline(rtems_rtl_obj *obj)
Definition: rtl-obj.c:583
void rtems_rtl_obj_erase_sections(rtems_rtl_obj *obj)
Definition: rtl-obj.c:464
void rtems_rtl_obj_inc_reference(rtems_rtl_obj *obj)
Definition: rtl-obj.c:1351
bool rtems_rtl_obj_add_dependent(rtems_rtl_obj *obj, rtems_rtl_obj *dependent)
Definition: rtl-obj.c:641
#define NULL
Requests a GPIO pin group configuration.
Definition: bestcomm_api.h:77
size_t text_size
Definition: rtl-obj.h:210
bool rtems_rtl_obj_alloc_sections(rtems_rtl_obj *obj, int fd, rtems_rtl_obj_sect_handler handler, void *data)
Definition: rtl-obj.c:1053
const char * aname
Definition: rtl-obj.h:193