RTEMS 6.1-rc5
Loading...
Searching...
No Matches
rtl-obj.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 * COPYRIGHT (c) 2012,2019 Chris Johns <chrisj@rtems.org>
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
35#if !defined (_RTEMS_RTL_OBJ_H_)
36#define _RTEMS_RTL_OBJ_H_
37
38#include <rtems.h>
39#include <rtems/chain.h>
40#include <rtems/rtl/rtl-sym.h>
42
43#ifdef __cplusplus
44extern "C" {
45#endif /* __cplusplus */
46
50#define RTEMS_RTL_FMT_ELF (1 << 0)
51#define RTEMS_RTL_FMT_COMP (1 << 1)
52#define RTEMS_RTL_FMT_PRIVATE (1 << 16)
53
58{
63 const char* label;
64
68 uint32_t flags;
70
75typedef bool (*rtems_rtl_loader_check) (rtems_rtl_obj* obj, int fd);
76
81typedef bool (*rtems_rtl_loader_load) (rtems_rtl_obj* obj, int fd);
82
88
93typedef rtems_rtl_loader_format* (*rtems_rtl_loader_sig) (void);
94
99{
105
109#define RTEMS_RTL_OBJ_SECT_TEXT (1 << 0)
110#define RTEMS_RTL_OBJ_SECT_CONST (1 << 1)
111#define RTEMS_RTL_OBJ_SECT_DATA (1 << 2)
112#define RTEMS_RTL_OBJ_SECT_BSS (1 << 3)
113#define RTEMS_RTL_OBJ_SECT_EH (1 << 4)
114#define RTEMS_RTL_OBJ_SECT_TLS (1 << 5)
115#define RTEMS_RTL_OBJ_SECT_REL (1 << 6)
116#define RTEMS_RTL_OBJ_SECT_RELA (1 << 7)
117#define RTEMS_RTL_OBJ_SECT_SYM (1 << 8)
118#define RTEMS_RTL_OBJ_SECT_STR (1 << 9)
119#define RTEMS_RTL_OBJ_SECT_ALLOC (1 << 10
120#define RTEMS_RTL_OBJ_SECT_LOAD (1 << 11)
121#define RTEMS_RTL_OBJ_SECT_WRITE (1 << 12)
122#define RTEMS_RTL_OBJ_SECT_EXEC (1 << 13)
123#define RTEMS_RTL_OBJ_SECT_ZERO (1 << 14)
124#define RTEMS_RTL_OBJ_SECT_LINK (1 << 15)
125#define RTEMS_RTL_OBJ_SECT_CTOR (1 << 16)
126#define RTEMS_RTL_OBJ_SECT_DTOR (1 << 17)
127#define RTEMS_RTL_OBJ_SECT_LOCD (1 << 18)
128#define RTEMS_RTL_OBJ_SECT_ARCH_ALLOC (1 << 19)
133#define RTEMS_RTL_OBJ_SECT_TYPES (RTEMS_RTL_OBJ_SECT_TEXT | \
134 RTEMS_RTL_OBJ_SECT_CONST | \
135 RTEMS_RTL_OBJ_SECT_DATA | \
136 RTEMS_RTL_OBJ_SECT_BSS | \
137 RTEMS_RTL_OBJ_SECT_TLS | \
138 RTEMS_RTL_OBJ_SECT_EH)
139
146{
149 const char* name;
150 size_t size;
151 off_t offset;
153 uint32_t alignment;
154 int link;
155 int info;
156 uint32_t flags;
157 void* base;
160};
161
169{
171 size_t dependents;
173};
174
179 rtems_rtl_obj* dependent,
180 void* data);
181
185#define RTEMS_RTL_OBJ_LOCKED (1 << 0)
187#define RTEMS_RTL_OBJ_UNRESOLVED (1 << 1)
189#define RTEMS_RTL_OBJ_BASE (1 << 2)
190#define RTEMS_RTL_OBJ_RELOC_TAG (1 << 3)
192#define RTEMS_RTL_OBJ_DEP_VISITED (1 << 4)
193#define RTEMS_RTL_OBJ_CTOR_RUN (1 << 5)
200{
202 uint32_t flags;
203 size_t users;
204 size_t refs;
205 int format;
206 const char* fname;
207 const char* oname;
209 const char* aname;
212 off_t ooffset;
213 size_t fsize;
218 size_t local_syms;
219 size_t local_size;
221 size_t global_syms;
222 size_t global_size;
223 size_t unresolved;
224 void* text_base;
226 size_t text_size;
229 size_t const_size;
230 void* eh_base;
232 size_t eh_size;
233 void* data_base;
235 size_t data_size;
236 void* bss_base;
238 size_t bss_size;
239 size_t exec_size;
241 void* entry;
242 uint32_t checksum;
244 uint32_t* sec_num;
245 uint32_t obj_num;
249 size_t tramp_size;
250 size_t tramp_slots;
252 void* tramp_brk;
259 void* loader;
261};
262
275 int fd,
276 rtems_rtl_obj_sect* sect,
277 void* data);
278
285static inline const char* rtems_rtl_obj_fname (const rtems_rtl_obj* obj)
286{
287 return obj->fname;
288}
289
296static inline bool rtems_rtl_obj_fname_valid (const rtems_rtl_obj* obj)
297{
298 return obj->fname;
299}
300
307static inline const char* rtems_rtl_obj_oname (const rtems_rtl_obj* obj)
308{
309 return obj->oname;
310}
311
318static inline bool rtems_rtl_obj_oname_valid (const rtems_rtl_obj* obj)
319{
320 return obj->oname;
321}
322
329static inline const char* rtems_rtl_obj_aname (const rtems_rtl_obj* obj)
330{
331 return obj->aname;
332}
333
340static inline bool rtems_rtl_obj_aname_valid (const rtems_rtl_obj* obj)
341{
342 return obj->aname;
343}
344
351static inline bool rtems_rtl_obj_text_inside (const rtems_rtl_obj* obj,
352 const void* address)
353{
354 return
355 (address >= obj->text_base) &&
356 ((char*) address < ((char*) obj->text_base + obj->text_size));
357}
358
368static inline size_t rtems_rtl_obj_align (size_t offset,
369 uint32_t alignment)
370{
371 if ((alignment > 1) && ((offset & (alignment - 1)) != 0))
372 offset = (offset + alignment) & ~(alignment - 1);
373 return offset;
374}
375
383static inline bool rtems_rtl_obj_has_symbol (const rtems_rtl_obj* obj,
384 const rtems_rtl_obj_sym* sym)
385{
386 return (sym >= obj->global_table &&
387 sym < (obj->global_table + obj->global_syms));
388}
389
396static inline size_t rtems_rtl_obj_has_trampolines (const rtems_rtl_obj* obj)
397{
398 return obj->tramp_slot_size != 0 && obj->tramp_slots != 0;
399}
400
408static inline size_t rtems_rtl_obj_tramp_avail_space (const rtems_rtl_obj* obj)
409{
410 return (char*) obj->tramp_brk - (char*) obj->tramp_base;
411}
412
420static inline bool rtems_rtl_obj_has_tramp_space (const rtems_rtl_obj* obj,
421 const size_t size)
422{
423 return (obj->tramp_base != NULL &&
424 (rtems_rtl_obj_tramp_avail_space (obj) + size) <= obj->tramp_size);
425}
426
433static inline size_t rtems_rtl_obj_trampoline_slots (const rtems_rtl_obj* obj)
434{
435 return obj->tramp_slots;
436}
437
444static inline size_t rtems_rtl_obj_trampolines (const rtems_rtl_obj* obj)
445{
446 return obj->tramp_base == NULL || obj->tramp_slots == 0 ?
447 0 : rtems_rtl_obj_tramp_avail_space (obj) / obj->tramp_slot_size;
448}
449
456static inline bool rtems_rtl_obj_sect_is_arch_alloc (rtems_rtl_obj_sect* sect)
457{
458 return (sect->flags & RTEMS_RTL_OBJ_SECT_ARCH_ALLOC) != 0;
459}
460
467
476
486
498bool rtems_rtl_parse_name (const char* name,
499 const char** aname,
500 const char** oname,
501 off_t* ooffset);
502
513bool rtems_rtl_obj_find_file (rtems_rtl_obj* obj, const char* name);
514
531 int section,
532 const char* name,
533 size_t size,
534 off_t offset,
535 uint32_t alignment,
536 int link,
537 int info,
538 uint32_t flags);
539
546
556 const char* name);
557
567 int index);
568
582 int index,
583 uint32_t mask);
584
593bool rtems_rtl_obj_alloc_dependents (rtems_rtl_obj* obj, size_t dependents);
594
601
611
620
632 void* data);
633
642size_t rtems_rtl_obj_text_size (const rtems_rtl_obj* obj);
643
655uint32_t rtems_rtl_obj_text_alignment (const rtems_rtl_obj* obj);
656
665size_t rtems_rtl_obj_const_size (const rtems_rtl_obj* obj);
666
678uint32_t rtems_rtl_obj_const_alignment (const rtems_rtl_obj* obj);
679
687size_t rtems_rtl_obj_eh_size (const rtems_rtl_obj* obj);
688
700uint32_t rtems_rtl_obj_eh_alignment (const rtems_rtl_obj* obj);
701
710size_t rtems_rtl_obj_data_size (const rtems_rtl_obj* obj);
711
723uint32_t rtems_rtl_obj_data_alignment (const rtems_rtl_obj* obj);
724
732size_t rtems_rtl_obj_bss_size (const rtems_rtl_obj* obj);
733
745uint32_t rtems_rtl_obj_bss_alignment (const rtems_rtl_obj* obj);
746
753size_t rtems_rtl_obj_tramp_size (const rtems_rtl_obj* obj);
754
763uint32_t rtems_rtl_obj_tramp_alignment (const rtems_rtl_obj* obj);
764
777 int fd,
779 void* data);
780
787
797 rtems_rtl_obj_sym* sym);
798
811 int fd,
813 void* data);
814
827 int fd,
829 void* data);
830
839
853 int fd,
855 void* data);
856
863
873
880
890
897
904
911
919
929
938
939#ifdef __cplusplus
940}
941#endif /* __cplusplus */
942
943#endif
This header file provides the Chains API.
This header file defines the RTEMS Classic API.
bool rtems_rtl_obj_find_file(rtems_rtl_obj *obj, const char *name)
Definition: rtl-obj.c:404
rtems_rtl_loader_format *(* rtems_rtl_loader_sig)(void)
Definition: rtl-obj.h:93
uint32_t rtems_rtl_obj_bss_alignment(const rtems_rtl_obj *obj)
Definition: rtl-obj.c:817
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:444
bool(* rtems_rtl_obj_depends_iterator)(rtems_rtl_obj *obj, rtems_rtl_obj *dependent, void *data)
Definition: rtl-obj.h:178
bool rtems_rtl_obj_ctors_to_run(rtems_rtl_obj *obj)
Definition: rtl-obj.c:1380
size_t rtems_rtl_obj_get_reference(rtems_rtl_obj *obj)
Definition: rtl-obj.c:1428
uint32_t rtems_rtl_obj_text_alignment(const rtems_rtl_obj *obj)
Definition: rtl-obj.c:756
bool rtems_rtl_obj_resize_sections(rtems_rtl_obj *obj)
Definition: rtl-obj.c:1203
size_t rtems_rtl_obj_const_size(const rtems_rtl_obj *obj)
Definition: rtl-obj.c:763
rtems_rtl_obj_sect * rtems_rtl_obj_find_section(const rtems_rtl_obj *obj, const char *name)
Definition: rtl-obj.c:523
void rtems_rtl_obj_erase_sections(rtems_rtl_obj *obj)
Definition: rtl-obj.c:483
bool rtems_rtl_obj_load(rtems_rtl_obj *obj)
Definition: rtl-obj.c:1455
bool rtems_rtl_obj_relocate(rtems_rtl_obj *obj, int fd, rtems_rtl_obj_sect_handler handler, void *data)
Definition: rtl-obj.c:823
#define RTEMS_RTL_OBJ_SECT_ARCH_ALLOC
Definition: rtl-obj.h:128
void rtems_rtl_obj_run_dtors(rtems_rtl_obj *obj)
Definition: rtl-obj.c:1398
bool rtems_rtl_obj_add_dependent(rtems_rtl_obj *obj, rtems_rtl_obj *dependent)
Definition: rtl-obj.c:640
size_t rtems_rtl_obj_eh_size(const rtems_rtl_obj *obj)
Definition: rtl-obj.c:784
size_t rtems_rtl_obj_text_size(const rtems_rtl_obj *obj)
Definition: rtl-obj.c:749
uint32_t rtems_rtl_obj_tramp_alignment(const rtems_rtl_obj *obj)
Definition: rtl-mdreloc-aarch64.c:166
size_t rtems_rtl_obj_data_size(const rtems_rtl_obj *obj)
Definition: rtl-obj.c:791
size_t rtems_rtl_obj_bss_size(const rtems_rtl_obj *obj)
Definition: rtl-obj.c:805
bool rtems_rtl_obj_remove_dependencies(rtems_rtl_obj *obj)
Definition: rtl-obj.c:693
bool rtems_rtl_obj_unresolved(rtems_rtl_obj *obj)
Definition: rtl-obj.c:190
bool(* rtems_rtl_loader_load)(rtems_rtl_obj *obj, int fd)
Definition: rtl-obj.h:81
bool rtems_rtl_obj_free(rtems_rtl_obj *obj)
Definition: rtl-obj.c:126
void rtems_rtl_obj_dec_reference(rtems_rtl_obj *obj)
Definition: rtl-obj.c:1440
bool rtems_rtl_parse_name(const char *name, const char **aname, const char **oname, off_t *ooffset)
Definition: rtl-obj.c:221
bool(* rtems_rtl_obj_sect_handler)(rtems_rtl_obj *obj, int fd, rtems_rtl_obj_sect *sect, void *data)
Definition: rtl-obj.h:274
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:586
void rtems_rtl_obj_inc_reference(rtems_rtl_obj *obj)
Definition: rtl-obj.c:1434
bool rtems_rtl_obj_unload(rtems_rtl_obj *obj)
Definition: rtl-obj.c:1516
bool rtems_rtl_obj_alloc_dependents(rtems_rtl_obj *obj, size_t dependents)
Definition: rtl-obj.c:602
void rtems_rtl_obj_synchronize_cache(rtems_rtl_obj *obj)
Definition: rtl-obj.c:881
uint32_t rtems_rtl_obj_data_alignment(const rtems_rtl_obj *obj)
Definition: rtl-obj.c:798
uint32_t rtems_rtl_obj_eh_alignment(const rtems_rtl_obj *obj)
Definition: rtl-obj.c:777
rtems_rtl_obj * rtems_rtl_obj_alloc(void)
Definition: rtl-obj.c:94
bool rtems_rtl_obj_load_sections(rtems_rtl_obj *obj, int fd, rtems_rtl_obj_sect_handler handler, void *data)
Definition: rtl-obj.c:1310
void rtems_rtl_obj_run_ctors(rtems_rtl_obj *obj)
Definition: rtl-obj.c:1386
bool rtems_rtl_obj_alloc_sections(rtems_rtl_obj *obj, int fd, rtems_rtl_obj_sect_handler handler, void *data)
Definition: rtl-obj.c:1136
bool rtems_rtl_obj_load_symbols(rtems_rtl_obj *obj, int fd, rtems_rtl_obj_sect_handler handler, void *data)
Definition: rtl-obj.c:915
bool rtems_rtl_obj_relocate_unresolved(rtems_rtl_unresolv_reloc *reloc, rtems_rtl_obj_sym *sym)
Definition: rtl-elf.c:599
size_t rtems_rtl_obj_tramp_size(const rtems_rtl_obj *obj)
Definition: rtl-obj.c:811
bool rtems_rtl_obj_dtors_to_run(rtems_rtl_obj *obj)
Definition: rtl-obj.c:1392
bool(* rtems_rtl_loader_check)(rtems_rtl_obj *obj, int fd)
Definition: rtl-obj.h:75
rtems_rtl_obj_sect * rtems_rtl_obj_find_section_by_index(const rtems_rtl_obj *obj, int index)
Definition: rtl-obj.c:551
void rtems_rtl_obj_erase_dependents(rtems_rtl_obj *obj)
Definition: rtl-obj.c:626
uint32_t rtems_rtl_obj_const_alignment(const rtems_rtl_obj *obj)
Definition: rtl-obj.c:770
bool rtems_rtl_obj_orphaned(rtems_rtl_obj *obj)
Definition: rtl-obj.c:1447
bool(* rtems_rtl_loader_unload)(rtems_rtl_obj *obj)
Definition: rtl-obj.h:87
bool rtems_rtl_obj_iterate_dependents(rtems_rtl_obj *obj, rtems_rtl_obj_depends_iterator iterator, void *data)
Definition: rtl-obj.c:726
RTEMS Run-Time Linker Object File Symbol Table.
RTEMS Run-Time Linker Object File Unresolved Relocations Table.
This structure represents a chain node.
Definition: chain.h:78
Definition: rtl-obj.h:58
const char * label
Definition: rtl-obj.h:63
uint32_t flags
Definition: rtl-obj.h:68
Definition: rtl-obj.h:99
rtems_rtl_loader_load load
Definition: rtl-obj.h:101
rtems_rtl_loader_sig signature
Definition: rtl-obj.h:103
rtems_rtl_loader_unload unload
Definition: rtl-obj.h:102
rtems_rtl_loader_check check
Definition: rtl-obj.h:100
Definition: rtl-obj.h:169
rtems_chain_node node
Definition: rtl-obj.h:170
rtems_rtl_obj * depends[]
Definition: rtl-obj.h:172
size_t dependents
Definition: rtl-obj.h:171
Definition: rtl-obj.h:146
off_t offset
Definition: rtl-obj.h:151
const char * name
Definition: rtl-obj.h:149
int section
Definition: rtl-obj.h:148
int info
Definition: rtl-obj.h:155
uint32_t flags
Definition: rtl-obj.h:156
uint32_t alignment
Definition: rtl-obj.h:153
size_t size
Definition: rtl-obj.h:150
void * base
Definition: rtl-obj.h:157
int link
Definition: rtl-obj.h:154
int load_order
Definition: rtl-obj.h:159
rtems_chain_node node
Definition: rtl-obj.h:147
Definition: rtl-sym.h:49
Definition: rtl-obj.h:200
void * bss_base
Definition: rtl-obj.h:236
off_t ooffset
Definition: rtl-obj.h:212
size_t tramp_slots
Definition: rtl-obj.h:250
void * tramp_base
Definition: rtl-obj.h:247
const char * fname
Definition: rtl-obj.h:206
rtems_chain_node link
Definition: rtl-obj.h:201
size_t const_size
Definition: rtl-obj.h:229
size_t tramp_relocs
Definition: rtl-obj.h:255
size_t local_syms
Definition: rtl-obj.h:218
size_t eh_size
Definition: rtl-obj.h:232
size_t bss_size
Definition: rtl-obj.h:238
void * data_base
Definition: rtl-obj.h:233
size_t text_size
Definition: rtl-obj.h:226
rtems_rtl_obj_sym * global_table
Definition: rtl-obj.h:220
void * entry
Definition: rtl-obj.h:241
size_t users
Definition: rtl-obj.h:203
uint32_t * sec_num
Definition: rtl-obj.h:244
void * loader
Definition: rtl-obj.h:259
size_t unresolved
Definition: rtl-obj.h:223
uint32_t flags
Definition: rtl-obj.h:202
size_t global_size
Definition: rtl-obj.h:222
void * tramp_brk
Definition: rtl-obj.h:252
int format
Definition: rtl-obj.h:205
size_t tramp_size
Definition: rtl-obj.h:249
size_t tramp_slot_size
Definition: rtl-obj.h:251
uint32_t obj_num
Definition: rtl-obj.h:245
size_t local_size
Definition: rtl-obj.h:219
struct link_map * linkmap
Definition: rtl-obj.h:258
size_t fsize
Definition: rtl-obj.h:213
void * text_base
Definition: rtl-obj.h:224
rtems_chain_control dependents
Definition: rtl-obj.h:216
size_t global_syms
Definition: rtl-obj.h:221
void * eh_base
Definition: rtl-obj.h:230
rtems_rtl_obj_sym * local_table
Definition: rtl-obj.h:217
size_t exec_size
Definition: rtl-obj.h:239
void * const_base
Definition: rtl-obj.h:227
size_t data_size
Definition: rtl-obj.h:235
rtems_chain_control sections
Definition: rtl-obj.h:214
size_t refs
Definition: rtl-obj.h:204
const char * oname
Definition: rtl-obj.h:207
uint32_t checksum
Definition: rtl-obj.h:242
const char * aname
Definition: rtl-obj.h:209
Definition: rtl-unresolved.h:127
This union represents a chain control block.
Definition: chain.h:96