Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:12

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 2012,2019 Chris Johns <chrisj@rtems.org>
0005  *
0006  * Redistribution and use in source and binary forms, with or without
0007  * modification, are permitted provided that the following conditions
0008  * are met:
0009  * 1. Redistributions of source code must retain the above copyright
0010  *    notice, this list of conditions and the following disclaimer.
0011  * 2. Redistributions in binary form must reproduce the above copyright
0012  *    notice, this list of conditions and the following disclaimer in the
0013  *    documentation and/or other materials provided with the distribution.
0014  *
0015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0016  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0018  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0019  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0020  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0021  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0024  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0025  * POSSIBILITY OF SUCH DAMAGE.
0026  */
0027 /**
0028  * @file
0029  *
0030  * @ingroup rtems_rtl
0031  *
0032  * @brief RTEMS Run-Time Linker Object Support.
0033  */
0034 
0035 #if !defined (_RTEMS_RTL_OBJ_H_)
0036 #define _RTEMS_RTL_OBJ_H_
0037 
0038 #include <rtems.h>
0039 #include <rtems/chain.h>
0040 #include <rtems/rtl/rtl-sym.h>
0041 #include <rtems/rtl/rtl-unresolved.h>
0042 
0043 #ifdef __cplusplus
0044 extern "C" {
0045 #endif /* __cplusplus */
0046 
0047 /**
0048  * Loader format flags.
0049  */
0050 #define RTEMS_RTL_FMT_ELF     (1 << 0)
0051 #define RTEMS_RTL_FMT_COMP    (1 << 1)
0052 #define RTEMS_RTL_FMT_PRIVATE (1 << 16)
0053 
0054 /**
0055  * Loader format definition.
0056  */
0057 typedef struct rtems_rtl_loader_format
0058 {
0059   /**
0060    * The format label. This can be used to determine and manage
0061    * specific formats.
0062    */
0063   const char* label;
0064 
0065   /**
0066    * The format flags.
0067    */
0068   uint32_t flags;
0069 } rtems_rtl_loader_format;
0070 
0071 /**
0072  * The type of the format loader check handler. This handler checks the format
0073  * and if it is detected as suitable it returns true.
0074  */
0075 typedef bool (*rtems_rtl_loader_check) (rtems_rtl_obj* obj, int fd);
0076 
0077 /**
0078  * The type of the format loader load handler. This handler loads the specific
0079  * format.
0080  */
0081 typedef bool (*rtems_rtl_loader_load) (rtems_rtl_obj* obj, int fd);
0082 
0083 /**
0084  * The type of the format loader unload handler. This handler unloads the
0085  * specific format.
0086  */
0087 typedef bool (*rtems_rtl_loader_unload) (rtems_rtl_obj* obj);
0088 
0089 /**
0090  * The type of the format loader signature handler. This handler checks the
0091  * format signature.
0092  */
0093 typedef rtems_rtl_loader_format* (*rtems_rtl_loader_sig) (void);
0094 
0095 /**
0096  * Table for supported loadable formats.
0097  */
0098 typedef struct rtems_rtl_loader_table
0099 {
0100   rtems_rtl_loader_check  check;     /**< The check handler. */
0101   rtems_rtl_loader_load   load;      /**< The loader. */
0102   rtems_rtl_loader_unload unload;    /**< The unloader. */
0103   rtems_rtl_loader_sig    signature; /**< The loader's signature. */
0104 } rtems_rtl_loader_table;
0105 
0106 /**
0107  * Flags for the various section types.
0108  */
0109 #define RTEMS_RTL_OBJ_SECT_TEXT       (1 << 0)  /**< Section holds program text. */
0110 #define RTEMS_RTL_OBJ_SECT_CONST      (1 << 1)  /**< Section holds program text. */
0111 #define RTEMS_RTL_OBJ_SECT_DATA       (1 << 2)  /**< Section holds program data. */
0112 #define RTEMS_RTL_OBJ_SECT_BSS        (1 << 3)  /**< Section holds program bss. */
0113 #define RTEMS_RTL_OBJ_SECT_EH         (1 << 4)  /**< Section holds exception data. */
0114 #define RTEMS_RTL_OBJ_SECT_TLS        (1 << 5)  /**< Section holds TLS data. */
0115 #define RTEMS_RTL_OBJ_SECT_REL        (1 << 6)  /**< Section holds relocation recs. */
0116 #define RTEMS_RTL_OBJ_SECT_RELA       (1 << 7)  /**< Section holds reloc addend recs. */
0117 #define RTEMS_RTL_OBJ_SECT_SYM        (1 << 8)  /**< Section holds symbols. */
0118 #define RTEMS_RTL_OBJ_SECT_STR        (1 << 9)  /**< Section holds strings. */
0119 #define RTEMS_RTL_OBJ_SECT_ALLOC      (1 << 10  /**< Section allocates runtime memory. */
0120 #define RTEMS_RTL_OBJ_SECT_LOAD       (1 << 11) /**< Section is loaded from object file. */
0121 #define RTEMS_RTL_OBJ_SECT_WRITE      (1 << 12) /**< Section is writable, ie data. */
0122 #define RTEMS_RTL_OBJ_SECT_EXEC       (1 << 13) /**< Section is executable. */
0123 #define RTEMS_RTL_OBJ_SECT_ZERO       (1 << 14) /**< Section is preset to zero. */
0124 #define RTEMS_RTL_OBJ_SECT_LINK       (1 << 15) /**< Section is link-ordered. */
0125 #define RTEMS_RTL_OBJ_SECT_CTOR       (1 << 16) /**< Section contains constructors. */
0126 #define RTEMS_RTL_OBJ_SECT_DTOR       (1 << 17) /**< Section contains destructors. */
0127 #define RTEMS_RTL_OBJ_SECT_LOCD       (1 << 18) /**< Section has been located. */
0128 #define RTEMS_RTL_OBJ_SECT_ARCH_ALLOC (1 << 19) /**< Section use arch allocator. */
0129 
0130 /**
0131  * Section types mask.
0132  */
0133 #define RTEMS_RTL_OBJ_SECT_TYPES (RTEMS_RTL_OBJ_SECT_TEXT | \
0134                                   RTEMS_RTL_OBJ_SECT_CONST | \
0135                                   RTEMS_RTL_OBJ_SECT_DATA | \
0136                                   RTEMS_RTL_OBJ_SECT_BSS | \
0137                                   RTEMS_RTL_OBJ_SECT_TLS | \
0138                                   RTEMS_RTL_OBJ_SECT_EH)
0139 
0140 /**
0141  * An object file is made up of sections and the can be more than
0142  * one of a specific type of sections. All sections and grouped
0143  * together in memory.
0144  */
0145 struct rtems_rtl_obj_sect
0146 {
0147   rtems_chain_node node;        /**< The node's link in the chain. */
0148   int              section;     /**< The section number. */
0149   const char*      name;        /**< The section's name. */
0150   size_t           size;        /**< The size of the section in memory. */
0151   off_t            offset;      /**< Offset into the object file. Relative to
0152                                  *   the start of the object file. */
0153   uint32_t         alignment;   /**< Alignment of this section. */
0154   int              link;        /**< Section link field. */
0155   int              info;        /**< Secfion info field. */
0156   uint32_t         flags;       /**< The section's flags. */
0157   void*            base;        /**< The base address of the section in
0158                                  *   memory. */
0159   int              load_order;  /**< Order we load sections. */
0160 };
0161 
0162 /**
0163  * Object file dependents. This is a list of tables of pointers to the object
0164  * modules the object file depends on. The table is a list of tables because
0165  * unresolved externals can exist when an object file is loaded and resolved
0166  * later when the dependent object file is loaded.
0167  */
0168 struct rtems_rtl_obj_depends
0169 {
0170   rtems_chain_node node;        /**< The node's link in the chain. */
0171   size_t           dependents;  /**< The number of dependent object pointers. */
0172   rtems_rtl_obj*   depends[];   /**< Dependtent objects. More follow. */
0173 };
0174 
0175 /**
0176  * Dependency iterator.
0177  */
0178 typedef bool (*rtems_rtl_obj_depends_iterator) (rtems_rtl_obj* obj,
0179                                                 rtems_rtl_obj* dependent,
0180                                                 void*          data);
0181 
0182 /**
0183  * Object file descriptor flags.
0184  */
0185 #define RTEMS_RTL_OBJ_LOCKED       (1 << 0) /**< Lock the object file so it cannot
0186                                              *   be unloaded. */
0187 #define RTEMS_RTL_OBJ_UNRESOLVED   (1 << 1) /**< The object file has unresolved
0188                                              *   external symbols. */
0189 #define RTEMS_RTL_OBJ_BASE         (1 << 2) /**< The base image. */
0190 #define RTEMS_RTL_OBJ_RELOC_TAG    (1 << 3) /**< Tag the object as visited when reloc
0191                                              *   parsing. */
0192 #define RTEMS_RTL_OBJ_DEP_VISITED  (1 << 4) /**< Dependency loop detection. */
0193 #define RTEMS_RTL_OBJ_CTOR_RUN     (1 << 5) /**< Constructors have been called. */
0194 
0195 /**
0196  * RTL Object. There is one for each object module loaded plus one for the base
0197  * kernel image.
0198  */
0199 struct rtems_rtl_obj
0200 {
0201   rtems_chain_node    link;            /**< The node's link in the chain. */
0202   uint32_t            flags;           /**< The status of the object file. */
0203   size_t              users;           /**< Users of this object file, number of loads. */
0204   size_t              refs;            /**< References to the object file. */
0205   int                 format;          /**< The format of the object file. */
0206   const char*         fname;           /**< The file name for the object. */
0207   const char*         oname;           /**< The object file name. Can be
0208                                         *   relative. */
0209   const char*         aname;           /**< The archive name containing the
0210                                         *   object. NULL means the object is not
0211                                         *   in a lib */
0212   off_t               ooffset;         /**< The object offset in the archive. */
0213   size_t              fsize;           /**< Size of the object file. */
0214   rtems_chain_control sections;        /**< The sections of interest in the object
0215                                         *   file. */
0216   rtems_chain_control dependents;      /**< The dependent object files. */
0217   rtems_rtl_obj_sym*  local_table;     /**< Local symbol table. */
0218   size_t              local_syms;      /**< Local symbol count. */
0219   size_t              local_size;      /**< Local symbol memory usage. */
0220   rtems_rtl_obj_sym*  global_table;    /**< Global symbol table. */
0221   size_t              global_syms;     /**< Global symbol count. */
0222   size_t              global_size;     /**< Global symbol memory usage. */
0223   size_t              unresolved;      /**< The number of unresolved relocations. */
0224   void*               text_base;       /**< The base address of the text section
0225                                         *   in memory. */
0226   size_t              text_size;       /**< The size of the text section. */
0227   void*               const_base;      /**< The base address of the const section
0228                                         *   in memory. */
0229   size_t              const_size;      /**< The size of the const section. */
0230   void*               eh_base;         /**< The base address of the eh section in
0231                                         *   memory. */
0232   size_t              eh_size;         /**< The size of the eh section. */
0233   void*               data_base;       /**< The base address of the data section
0234                                         *   in memory. */
0235   size_t              data_size;       /**< The size of the data section. */
0236   void*               bss_base;        /**< The base address of the bss section in
0237                                         *   memory. */
0238   size_t              bss_size;        /**< The size of the bss section. */
0239   size_t              exec_size;       /**< The amount of executable memory
0240                                         *   allocated */
0241   void*               entry;           /**< The entry point of the module. */
0242   uint32_t            checksum;        /**< The checksum of the text sections. A
0243                                         *   zero means do not checksum. */
0244   uint32_t*           sec_num;         /**< The sec nums of each obj. */
0245   uint32_t            obj_num;         /**< The count of elf files in an rtl
0246                                         *   obj. */
0247   void*               tramp_base;      /**< Trampoline memory. Used for fixups or
0248                                         *   veneers */
0249   size_t              tramp_size;      /**< Size of a trampoline memory. */
0250   size_t              tramp_slots;     /**< The number of tampoline slots. */
0251   size_t              tramp_slot_size; /**< The number of tampoline slots. */
0252   void*               tramp_brk;       /**< Trampoline memory allocator. MD
0253                                         *   relocators can take memory from the
0254                                         *   break up to the size. */
0255   size_t              tramp_relocs;    /**< Number of slots reserved for
0256                                         *   relocs. The remainder are for
0257                                         *   unresolved symbols. */
0258   struct link_map*    linkmap;         /**< For GDB. */
0259   void*               loader;          /**< The file details specific to a
0260                                         *   loader. */
0261 };
0262 
0263 /**
0264  * A section handler is called once for each section that needs to be
0265  * processed by this handler. The handler is specific to a task.
0266  *
0267  * @param obj The object file's descriptor the section belongs too.
0268  * @param fd The file descriptor of the object file beling loaded.
0269  * @param sect The section the handler is being invoked to handle.
0270  * @param data A user supplied data variable.
0271  * @retval true The operation was successful.
0272  * @retval false The operation failed and the RTL has been set.
0273  */
0274 typedef bool (*rtems_rtl_obj_sect_handler)(rtems_rtl_obj*      obj,
0275                                            int                 fd,
0276                                            rtems_rtl_obj_sect* sect,
0277                                            void*               data);
0278 
0279 /**
0280  * Get the file name.
0281  *
0282  * @param obj The object file.
0283  * @return const char* The string.
0284  */
0285 static inline const char* rtems_rtl_obj_fname (const rtems_rtl_obj* obj)
0286 {
0287   return obj->fname;
0288 }
0289 
0290 /**
0291  * Is the file name valid ?
0292  *
0293  * @param obj The object file.
0294  * @return bool There is a file name
0295  */
0296 static inline bool rtems_rtl_obj_fname_valid (const rtems_rtl_obj* obj)
0297 {
0298   return obj->fname;
0299 }
0300 
0301 /**
0302  * Get the object name.
0303  *
0304  * @param obj The object file.
0305  * @return const char* The string.
0306  */
0307 static inline const char* rtems_rtl_obj_oname (const rtems_rtl_obj* obj)
0308 {
0309   return obj->oname;
0310 }
0311 
0312 /**
0313  * Is the object name valid ?
0314  *
0315  * @param obj The object file.
0316  * @return bool There is an object name
0317  */
0318 static inline bool rtems_rtl_obj_oname_valid (const rtems_rtl_obj* obj)
0319 {
0320   return obj->oname;
0321 }
0322 
0323 /**
0324  * Get the archive name.
0325  *
0326  * @param obj The object file.
0327  * @return const char* The string.
0328  */
0329 static inline const char* rtems_rtl_obj_aname (const rtems_rtl_obj* obj)
0330 {
0331   return obj->aname;
0332 }
0333 
0334 /**
0335  * Is the archive name valid ?
0336  *
0337  * @param obj The object file.
0338  * @return bool There is an archive name
0339  */
0340 static inline bool rtems_rtl_obj_aname_valid (const rtems_rtl_obj* obj)
0341 {
0342   return obj->aname;
0343 }
0344 
0345 /**
0346  * Is the address inside the text section?
0347  *
0348  * @param obj The object file.
0349  * @return bool There is an archive name
0350  */
0351 static inline bool rtems_rtl_obj_text_inside (const rtems_rtl_obj* obj,
0352                                               const void*          address)
0353 {
0354   return
0355     (address >= obj->text_base) &&
0356     ((char*) address < ((char*) obj->text_base + obj->text_size));
0357 }
0358 
0359 /**
0360  * Align the size to the next alignment point. Assume the alignment is a
0361  * positive integral power of 2 if not 0 or 1. If 0 or 1 then there is no
0362  * alignment.
0363  *
0364  * @param offset Offset to align up from.
0365  * @param alignment The alignment.
0366  * @return size_t Aligned offset.
0367  */
0368 static inline size_t rtems_rtl_obj_align (size_t   offset,
0369                                           uint32_t alignment)
0370 {
0371   if ((alignment > 1) && ((offset & (alignment - 1)) != 0))
0372     offset = (offset + alignment) & ~(alignment - 1);
0373   return offset;
0374 }
0375 
0376 /**
0377  * Is the symbol in this object's files globa symbol table?
0378  *
0379  * @param obj The object file's descriptor to search.
0380  * @param sym The symbol to check.
0381  * @retval bool Returns @true if present else @false is returned.
0382  */
0383 static inline bool rtems_rtl_obj_has_symbol (const rtems_rtl_obj*     obj,
0384                                              const rtems_rtl_obj_sym* sym)
0385 {
0386   return (sym >= obj->global_table &&
0387           sym < (obj->global_table + obj->global_syms));
0388 }
0389 
0390 /**
0391  * Does the object file have any trampolines?
0392  *
0393  * @param obj The object file's descriptor to check for available space.
0394  * @retval bool Returns @true if the object file has trampolines
0395  */
0396 static inline size_t rtems_rtl_obj_has_trampolines (const rtems_rtl_obj* obj)
0397 {
0398   return obj->tramp_slot_size != 0 && obj->tramp_slots != 0;
0399 }
0400 
0401 /**
0402  * Is there space in the trampoline memory for a trapoline.
0403  *
0404  * @param obj The object file's descriptor to check for available space.
0405  * @param size The size to be allocated.
0406  * @retval bool Returns @true if the space is available.
0407  */
0408 static inline size_t rtems_rtl_obj_tramp_avail_space (const rtems_rtl_obj* obj)
0409 {
0410   return (char*) obj->tramp_brk - (char*) obj->tramp_base;
0411 }
0412 
0413 /**
0414  * Is there space in the trampoline memory for a trapoline.
0415  *
0416  * @param obj The object file's descriptor to check for available space.
0417  * @param size The size to be allocated.
0418  * @retval bool Returns @true if the space is available.
0419  */
0420 static inline bool rtems_rtl_obj_has_tramp_space (const rtems_rtl_obj* obj,
0421                                                   const size_t         size)
0422 {
0423   return (obj->tramp_base != NULL &&
0424           (rtems_rtl_obj_tramp_avail_space (obj) + size) <= obj->tramp_size);
0425 }
0426 
0427 /**
0428  * Trampoline slots.
0429  *
0430  * @param obj The object file's descriptor.
0431  * @retval size_t The number of trampoline slots.
0432  */
0433 static inline size_t rtems_rtl_obj_trampoline_slots (const rtems_rtl_obj* obj)
0434 {
0435   return obj->tramp_slots;
0436 }
0437 
0438 /**
0439  * Number of trampoline slot available.
0440  *
0441  * @param obj The object file's descriptor.
0442  * @retval size_t The number of trampoline slots available.
0443  */
0444 static inline size_t rtems_rtl_obj_trampolines (const rtems_rtl_obj* obj)
0445 {
0446   return obj->tramp_base == NULL || obj->tramp_slots == 0 ?
0447     0 : rtems_rtl_obj_tramp_avail_space (obj) / obj->tramp_slot_size;
0448 }
0449 
0450 /**
0451  * Does the section require architecture specific allocations?
0452  *
0453  * @param sect The section.
0454  * @retval bool Returns @true if the section requires arch allocation.
0455  */
0456 static inline bool rtems_rtl_obj_sect_is_arch_alloc (rtems_rtl_obj_sect* sect)
0457 {
0458   return (sect->flags & RTEMS_RTL_OBJ_SECT_ARCH_ALLOC) != 0;
0459 }
0460 
0461 /**
0462  * Allocate an object structure on the heap.
0463  *
0464  * @retval NULL No memory for the object.
0465  */
0466 rtems_rtl_obj* rtems_rtl_obj_alloc (void);
0467 
0468 /**
0469  * Free the object structure and related resources.
0470  *
0471  * @param obj The object file's descriptor to free.
0472  * @retval false The object has dependences.
0473  * @retval true The object has been freed.
0474  */
0475 bool rtems_rtl_obj_free (rtems_rtl_obj* obj);
0476 
0477 /**
0478  * Does the object file have unresolved external references ? If it does the
0479  * results of executing code is unpredictable.
0480  *
0481  * @param obj The object file's descriptor.
0482  * @retval true The object file has unresolved externals.
0483  * @retval false The object file has all external references resolved.
0484  */
0485 bool rtems_rtl_obj_unresolved (rtems_rtl_obj* obj);
0486 
0487 /**
0488  * Parses a filename and returns newly allocated strings with the archive name,
0489  * object name, and the object's offset
0490  *
0491  * @param name The filename of the object
0492  * @param aname Address of a string pointer that holds the archive name
0493  * @param oname Address of a string pointer that holds the object name
0494  * @param ooffset Address of an int that holds the object offset
0495  * @retval true The parsing was successful
0496  * @retval false The parsing was unsuccessful
0497  */
0498 bool rtems_rtl_parse_name (const char*  name,
0499                            const char** aname,
0500                            const char** oname,
0501                            off_t*       ooffset);
0502 
0503 /**
0504  * Find an object file on disk that matches the name. The object descriptor is
0505  * fill in with the various parts of a name. A name can have archive, object
0506  * file and offset components. The search path in the RTL is searched.
0507  *
0508  * @param obj The object file's descriptor.
0509  * @param name The name to locate on disk.
0510  * @retval true The file has been found.
0511  * @retval false The file could not be located. The RTL error has been set.
0512  */
0513 bool rtems_rtl_obj_find_file (rtems_rtl_obj* obj, const char* name);
0514 
0515 /**
0516  * Add a section to the object descriptor.
0517  *
0518  * @param obj The object file's descriptor.
0519  * @param section The section's index number.
0520  * @param name The name of the section.
0521  * @param size The size of the section in memory.
0522  * @param offset The offset of the section in the object file.
0523  * @param alignment The alignment of the section in memory.
0524  * @param link The section's link field (from the ELF format).
0525  * @param info The section's info field (from the ELF format).
0526  * @param flags The section's flags.
0527  * @retval true The section has been added.
0528  * @retval false The section has not been added. See the RTL error.
0529  */
0530 bool rtems_rtl_obj_add_section (rtems_rtl_obj* obj,
0531                                 int            section,
0532                                 const char*    name,
0533                                 size_t         size,
0534                                 off_t          offset,
0535                                 uint32_t       alignment,
0536                                 int            link,
0537                                 int            info,
0538                                 uint32_t       flags);
0539 
0540 /**
0541  * Erase the object file descriptor's sections.
0542  *
0543  * @param obj The object file's descriptor.
0544  */
0545 void rtems_rtl_obj_erase_sections (rtems_rtl_obj* obj);
0546 
0547 /**
0548  * Find the section given a name.
0549  *
0550  * @param obj The object file's descriptor.
0551  * @param name The name of the section to find.
0552  * @retval NULL The section was not found.
0553  * @return rtems_rtl_obj_sect_t* The named section.
0554  */
0555 rtems_rtl_obj_sect* rtems_rtl_obj_find_section (const rtems_rtl_obj* obj,
0556                                                 const char*          name);
0557 
0558 /**
0559  * Find a section given a section's index number.
0560  *
0561  * @param obj The object file's descriptor.
0562  * @param index The section's index to find.
0563  * @retval NULL The section was not found.
0564  * @return rtems_rtl_obj_sect_t* The found section.
0565  */
0566 rtems_rtl_obj_sect* rtems_rtl_obj_find_section_by_index (const rtems_rtl_obj* obj,
0567                                                          int                  index);
0568 
0569 /**
0570  * Find a section given a section's mask. The index is the section after which
0571  * the mask is matched. An index of -1 starts the search from the beginning of
0572  * the section list. You can find multiple matches for a mask by passing the
0573  * index of the last section that matched the mask on a subsequent call.
0574  *
0575  * @param obj The object file's descriptor.
0576  * @param index The section's index to start searching from, -1 for the start.
0577  * @param mask The section's mask to match against the section's flags.
0578  * @retval NULL The section was not found.
0579  * @return rtems_rtl_obj_sect_t* The found section.
0580  */
0581 rtems_rtl_obj_sect* rtems_rtl_obj_find_section_by_mask (const rtems_rtl_obj* obj,
0582                                                         int                  index,
0583                                                         uint32_t             mask);
0584 
0585 /**
0586  * Allocate a table for dependent objects.
0587  *
0588  * @param obj The object file's descriptor.
0589  * @param dependents The size of the table.
0590  * @retval true The table was allocated.
0591  * @retval false The alloction failed.
0592  */
0593 bool rtems_rtl_obj_alloc_dependents (rtems_rtl_obj* obj, size_t dependents);
0594 
0595 /**
0596  * Erase the object file descriptor's dependents.
0597  *
0598  * @param obj The object file's descriptor.
0599  */
0600 void rtems_rtl_obj_erase_dependents (rtems_rtl_obj* obj);
0601 
0602 /**
0603  * Add an object file to the dependents table.
0604  *
0605  * @param obj The object file's descriptor.
0606  * @param dependent The dependent object file to add.
0607  * @retval true The dependent has been added to the table.
0608  * @retval false There is no space in the table.
0609  */
0610 bool rtems_rtl_obj_add_dependent (rtems_rtl_obj* obj, rtems_rtl_obj* dependent);
0611 
0612 /**
0613  * Remove dependencies. This decrements the dependent object file references.
0614  *
0615  * @param obj The object file's descriptor.
0616  * @retval true The dependencies have been removed.
0617  * @retval false There is no space in the table.
0618  */
0619 bool rtems_rtl_obj_remove_dependencies (rtems_rtl_obj* obj);
0620 
0621 /**
0622  * Iterate over the module dependenices.
0623  *
0624  * @param obj The object file's descriptor.
0625  * @param handler The iterator handler. Returns true to end.
0626  * @param data User data passed to the iterator.
0627  * @retval true The iterator handler returned true.
0628  * @retval false The iterator handler returned false.
0629  */
0630 bool rtems_rtl_obj_iterate_dependents (rtems_rtl_obj*                 obj,
0631                                        rtems_rtl_obj_depends_iterator iterator,
0632                                        void*                          data);
0633 
0634 /**
0635  * The text section size. Only use once all the sections has been added. It
0636  * includes alignments between sections that are part of the object's text
0637  * area. The consts sections are included in this section.
0638  *
0639  * @param obj The object file's descriptor.
0640  * @return size_t The size of the text area of the object file.
0641  */
0642 size_t rtems_rtl_obj_text_size (const rtems_rtl_obj* obj);
0643 
0644 /**
0645  * The text section alignment for the object file. Only use once all the
0646  * sections has been added. The section alignment is the alignment of the first
0647  * text type section loaded the text section.
0648  *
0649  * You can assume the alignment is a positive integral power of 2 if not 0 or
0650  * 1. If 0 or 1 then there is no alignment.
0651  *
0652  * @param obj The object file's descriptor.
0653  * @return uint32_t The alignment. Can be 0 or 1 for not aligned or the alignment.
0654  */
0655 uint32_t rtems_rtl_obj_text_alignment (const rtems_rtl_obj* obj);
0656 
0657 /**
0658  * The const section size. Only use once all the sections has been added. It
0659  * includes alignments between sections that are part of the object's const
0660  * area. The consts sections are included in this section.
0661  *
0662  * @param obj The object file's descriptor.
0663  * @return size_t The size of the const area of the object file.
0664  */
0665 size_t rtems_rtl_obj_const_size (const rtems_rtl_obj* obj);
0666 
0667 /**
0668  * The const section alignment for the object file. Only use once all the
0669  * sections has been added. The section alignment is the alignment of the first
0670  * const type section loaded the const section.
0671  *
0672  * You can assume the alignment is a positive integral power of 2 if not 0 or
0673  * 1. If 0 or 1 then there is no alignment.
0674  *
0675  * @param obj The object file's descriptor.
0676  * @return uint32_t The alignment. Can be 0 or 1 for not aligned or the alignment.
0677  */
0678 uint32_t rtems_rtl_obj_const_alignment (const rtems_rtl_obj* obj);
0679 
0680 /**
0681  * The eh section size. Only use once all the sections has been added. It
0682  * includes alignments between sections that are part of the object's bss area.
0683  *
0684  * @param obj The object file's descriptor.
0685  * @return size_t The size of the bss area of the object file.
0686  */
0687 size_t rtems_rtl_obj_eh_size (const rtems_rtl_obj* obj);
0688 
0689 /**
0690  * The eh section alignment for the object file. Only use once all the sections
0691  * has been added. The section alignment is the alignment of the first bss type
0692  * section loaded the bss section.
0693  *
0694  * You can assume the alignment is a positive integral power of 2 if not 0 or
0695  * 1. If 0 or 1 then there is no alignment.
0696  *
0697  * @param obj The object file's descriptor.
0698  * @return uint32_t The alignment. Can be 0 or 1 for not aligned or the alignment.
0699  */
0700 uint32_t rtems_rtl_obj_eh_alignment (const rtems_rtl_obj* obj);
0701 
0702 /**
0703  * The data section size. Only use once all the sections has been added. It
0704  * includes alignments between sections that are part of the object's data
0705  * area.
0706  *
0707  * @param obj The object file's descriptor.
0708  * @return size_t The size of the data area of the object file.
0709  */
0710 size_t rtems_rtl_obj_data_size (const rtems_rtl_obj* obj);
0711 
0712 /**
0713  * The data section alignment for the object file. Only use once all the
0714  * sections has been added. The section alignment is the alignment of the first
0715  * data type section loaded the data section.
0716  *
0717  * You can assume the alignment is a positive integral power of 2 if not 0 or
0718  * 1. If 0 or 1 then there is no alignment.
0719  *
0720  * @param obj The object file's descriptor.
0721  * @return uint32_t The alignment. Can be 0 or 1 for not aligned or the alignment.
0722  */
0723 uint32_t rtems_rtl_obj_data_alignment (const rtems_rtl_obj* obj);
0724 
0725 /**
0726  * The bss section size. Only use once all the sections has been added. It
0727  * includes alignments between sections that are part of the object's bss area.
0728  *
0729  * @param obj The object file's descriptor.
0730  * @return size_t The size of the bss area of the object file.
0731  */
0732 size_t rtems_rtl_obj_bss_size (const rtems_rtl_obj* obj);
0733 
0734 /**
0735  * The bss section alignment for the object file. Only use once all the
0736  * sections has been added. The section alignment is the alignment of the first
0737  * bss type section loaded the bss section.
0738  *
0739  * You can assume the alignment is a positive integral power of 2 if not 0 or
0740  * 1. If 0 or 1 then there is no alignment.
0741  *
0742  * @param obj The object file's descriptor.
0743  * @return uint32_t The alignment. Can be 0 or 1 for not aligned or the alignment.
0744  */
0745 uint32_t rtems_rtl_obj_bss_alignment (const rtems_rtl_obj* obj);
0746 
0747 /**
0748  * The trampoline size.
0749  *
0750  * @param obj The object file's descriptor.
0751  * @return size_t The size of the trampoline memory of the object file.
0752  */
0753 size_t rtems_rtl_obj_tramp_size (const rtems_rtl_obj* obj);
0754 
0755 /**
0756  * The trampolinme alignment for the architecture.
0757  *
0758  * This is implemented and set in the architecture backend.
0759  *
0760  * @param obj The object file's descriptor.
0761  * @return uint32_t The alignment. Can be 0 or 1 for not aligned or the alignment.
0762  */
0763 uint32_t rtems_rtl_obj_tramp_alignment (const rtems_rtl_obj* obj);
0764 
0765 /**
0766  * Relocate the object file. The object file's section are parsed for any
0767  * relocation type sections.
0768  *
0769  * @param obj The object file's descriptor.
0770  * @param fd The object file's file descriptor.
0771  * @param handler The object file's format specific relocation handler.
0772  * @param data User specific data handle.
0773  * @retval true The object file was relocated.
0774  * @retval false The relocation failed. The RTL error is set.
0775  */
0776 bool rtems_rtl_obj_relocate (rtems_rtl_obj*             obj,
0777                              int                        fd,
0778                              rtems_rtl_obj_sect_handler handler,
0779                              void*                      data);
0780 
0781 /**
0782  * Synchronize caches to make code visible to CPU(s)
0783  *
0784  * @param obj The object file's descriptor.
0785  */
0786 void rtems_rtl_obj_synchronize_cache (rtems_rtl_obj* obj);
0787 
0788 /**
0789  * Relocate an object file's unresolved reference.
0790  *
0791  * @param rec The unresolved relocation record.
0792  * @param sym The unresolved relocation's referenced symbol.
0793  * @retval true The object file record was relocated.
0794  * @retval false The relocation failed. The RTL error is set.
0795  */
0796 bool rtems_rtl_obj_relocate_unresolved (rtems_rtl_unresolv_reloc* reloc,
0797                                         rtems_rtl_obj_sym*        sym);
0798 
0799 /**
0800  * Load the symbols from the object file. Only the exported or public symbols
0801  * are read into memory and held in the global symbol table.
0802  *
0803  * @param obj The object file's descriptor.
0804  * @param fd The object file's file descriptor.
0805  * @param handler The object file's format specific symbol handler.
0806  * @param data User specific data handle.
0807  * @retval true The object file's symbol where loaded.
0808  * @retval false The symbol loading failed. The RTL error is set.
0809  */
0810 bool rtems_rtl_obj_load_symbols (rtems_rtl_obj*             obj,
0811                                  int                        fd,
0812                                  rtems_rtl_obj_sect_handler handler,
0813                                  void*                      data);
0814 
0815 /**
0816  * Allocate the sections. If a handler is provided (not NULL) it is called for
0817  * all section.
0818  *
0819  * @param obj The object file's descriptor.
0820  * @param fd The object file's file descriptor.
0821  * @param handler The object file's format specific allocation handler.
0822  * @param data User specific data handle.
0823  * @retval true The object has been sucessfully loaded.
0824  * @retval false The load failed. The RTL error has been set.
0825  */
0826 bool rtems_rtl_obj_alloc_sections (rtems_rtl_obj*             obj,
0827                                    int                        fd,
0828                                    rtems_rtl_obj_sect_handler handler,
0829                                    void*                      data);
0830 
0831 /**
0832  * Resize the sections.
0833  *
0834  * @param obj The object file's descriptor.
0835  * @retval true The object has been sucessfully loaded.
0836  * @retval false The load failed. The RTL error has been set.
0837  */
0838 bool rtems_rtl_obj_resize_sections (rtems_rtl_obj* obj);
0839 
0840 /**
0841  * Load the sections that have been allocated memory in the target. The bss
0842  * type section does not load any data, it is set to 0. The text and data
0843  * sections read the detault data from the object file into the target memory.
0844  *
0845  * @param obj The object file's descriptor.
0846  * @param fd The object file's file descriptor.
0847  * @param handler The object file's format specific load handler.
0848  * @param data User specific data handle.
0849  * @retval true The object has been sucessfully loaded.
0850  * @retval false The load failed. The RTL error has been set.
0851  */
0852 bool rtems_rtl_obj_load_sections (rtems_rtl_obj*             obj,
0853                                   int                        fd,
0854                                   rtems_rtl_obj_sect_handler handler,
0855                                   void*                      data);
0856 
0857 /**
0858  * Does the object have constructors to run?
0859  *
0860  * @return bool True if there are constructors to run.
0861  */
0862 bool rtems_rtl_obj_ctors_to_run (rtems_rtl_obj* obj);
0863 
0864 /**
0865  * Invoke the constructors the object has. Constructors are a table of pointers
0866  * to "void (*)(void);" where NULL pointers are skipped. The table's size is
0867  * taken from the section's size. The objet ELF specific code is responisble
0868  * for flagging which sections contain constructors.
0869  *
0870  * @param obj The object file's descriptor.
0871  */
0872 void rtems_rtl_obj_run_ctors (rtems_rtl_obj* obj);
0873 
0874 /**
0875  * Does the object have destructors to run?
0876  *
0877  * @return bool True if there are destructors to run.
0878  */
0879 bool rtems_rtl_obj_dtors_to_run (rtems_rtl_obj* obj);
0880 
0881 /**
0882  * Invoke the destructors the object has. Destructors are a table of pointers
0883  * to "void (*)(void);" where NULL pointers are skipped. The table's size is
0884  * taken from the section's size. The objet ELF specific code is responisble
0885  * for flagging which sections contain destructors.
0886  *
0887  * @param obj The object file's descriptor.
0888  */
0889 void rtems_rtl_obj_run_dtors (rtems_rtl_obj* obj);
0890 
0891 /**
0892  * Get the object file reference count.
0893  *
0894  * @retval int The object file's reference count.
0895  */
0896 size_t rtems_rtl_obj_get_reference (rtems_rtl_obj* obj);
0897 
0898 /**
0899  * Increment the object file reference count.
0900  *
0901  * @param obj The object file's descriptor.
0902  */
0903 void rtems_rtl_obj_inc_reference (rtems_rtl_obj* obj);
0904 
0905 /**
0906  * Decrement the object file reference count.
0907  *
0908  * @param obj The object file's descriptor.
0909  */
0910 void rtems_rtl_obj_dec_reference (rtems_rtl_obj* obj);
0911 
0912 /**
0913  * Is the object file orphaned? An orphaned object file is not locked, has no
0914  * users and it not being referenced.
0915  *
0916  * @param obj The object file's descriptor.
0917  */
0918 bool rtems_rtl_obj_orphaned (rtems_rtl_obj* obj);
0919 
0920 /**
0921  * Load the object file, reading all sections into memory, symbols and
0922  * performing any relocation fixups.
0923  *
0924  * @param obj The object file's descriptor.
0925  * @retval true The object file has been loaded.
0926  * @retval false The load failed. The RTL error has been set.
0927  */
0928 bool rtems_rtl_obj_load (rtems_rtl_obj* obj);
0929 
0930 /**
0931  * Unload the object file, erasing all symbols and releasing all memory.
0932  *
0933  * @param obj The object file's descriptor.
0934  * @retval true The object file has been unloaded.
0935  * @retval false The unload failed. The RTL error has been set.
0936  */
0937 bool rtems_rtl_obj_unload (rtems_rtl_obj* obj);
0938 
0939 #ifdef __cplusplus
0940 }
0941 #endif /* __cplusplus */
0942 
0943 #endif