diff --git a/cpukit/include/rtems/rtl/dlfcn-shell.h b/cpukit/include/rtems/rtl/dlfcn-shell.h index bf815da294..da59ea1354 100644 --- a/cpukit/include/rtems/rtl/dlfcn-shell.h +++ b/cpukit/include/rtems/rtl/dlfcn-shell.h @@ -28,9 +28,9 @@ #if !defined(_DLFCN_SHELL_H_) #define _DLFCN_SHELL_H_ -int shell_dlopen (int argc, char* argv[]); -int shell_dlclose (int argc, char* argv[]); -int shell_dlsym (int argc, char* argv[]); -int shell_dlcall (int argc, char* argv[]); +int shell_dlopen(int argc, char* argv[]); +int shell_dlclose(int argc, char* argv[]); +int shell_dlsym(int argc, char* argv[]); +int shell_dlcall(int argc, char* argv[]); #endif diff --git a/cpukit/include/rtems/rtl/rap-shell.h b/cpukit/include/rtems/rtl/rap-shell.h index 30d203f5f9..8448374f5e 100644 --- a/cpukit/include/rtems/rtl/rap-shell.h +++ b/cpukit/include/rtems/rtl/rap-shell.h @@ -28,6 +28,6 @@ #if !defined(_RAP_SHELL_H_) #define _RAP_SHELL_H_ -int shell_rap (int argc, char* argv[]); +int shell_rap(int argc, char* argv[]); #endif diff --git a/cpukit/include/rtems/rtl/rap.h b/cpukit/include/rtems/rtl/rap.h index 83d47c6659..96d458dc3d 100644 --- a/cpukit/include/rtems/rtl/rap.h +++ b/cpukit/include/rtems/rtl/rap.h @@ -34,7 +34,7 @@ * This is the RTEMS Application loader for files in the RAP format. */ -#if !defined (_RAP_H_) +#if !defined(_RAP_H_) #define _RAP_H_ #include @@ -63,7 +63,7 @@ extern "C" { /** * The module iterator handle. */ -typedef bool (*rtems_rap_iterator) (void* handle); +typedef bool (*rtems_rap_iterator)(void* handle); /** * Load an application. @@ -71,7 +71,7 @@ typedef bool (*rtems_rap_iterator) (void* handle); * @param name The name of the application file. * @return bool True if the module loads else an error. */ -bool rtems_rap_load (const char* name, int mode, int argc, const char* argv[]); +bool rtems_rap_load(const char* name, int mode, int argc, const char* argv[]); /** * Unload an application. @@ -80,7 +80,7 @@ bool rtems_rap_load (const char* name, int mode, int argc, const char* argv[]); * @retval true The application file has been unloaded. * @retval false The application could not be unloaded. */ -bool rtems_rap_unload (const char* name); +bool rtems_rap_unload(const char* name); /** * Find the application handle given a file name. @@ -90,7 +90,7 @@ bool rtems_rap_unload (const char* name); * @retval NULL No application file with that name found. * @return void* The application descriptor. */ -void* rtems_rap_find (const char* name); +void* rtems_rap_find(const char* name); /** * Run an iterator over the modules calling the iterator function. @@ -99,7 +99,7 @@ void* rtems_rap_find (const char* name); * @retval true The iterator function returned did not return false. * @retval false The iterator function returned false.. */ -bool rtems_rap_iterate (rtems_rap_iterator iterator); +bool rtems_rap_iterate(rtems_rap_iterator iterator); /** * Return the name of the module given a handle. @@ -108,7 +108,7 @@ bool rtems_rap_iterate (rtems_rap_iterator iterator); * @return const char* The name of the module if the handle is valid else it * is NULL. */ -const char* rtems_rap_name (void* handle); +const char* rtems_rap_name(void* handle); /** * Return the DL handle used to load the module given the RAP handle. @@ -116,7 +116,7 @@ const char* rtems_rap_name (void* handle); * @param handle The module handle. * @return void* The DL handle returned by the dlopen call. */ -void* rtems_rap_dl_handle (void* handle); +void* rtems_rap_dl_handle(void* handle); /** * Get the last error message clearing it. This call is not thread safe is @@ -127,7 +127,7 @@ void* rtems_rap_dl_handle (void* handle); * @param max_message The maximum message that can be copied. * @return int The last error number. */ -int rtems_rap_get_error (char* message, size_t max_message); +int rtems_rap_get_error(char* message, size_t max_message); #ifdef __cplusplus } diff --git a/cpukit/include/rtems/rtl/rtl-allocator.h b/cpukit/include/rtems/rtl/rtl-allocator.h index 7d291c65f4..2eeee5ea18 100644 --- a/cpukit/include/rtems/rtl/rtl-allocator.h +++ b/cpukit/include/rtems/rtl/rtl-allocator.h @@ -32,7 +32,7 @@ * @brief RTEMS Run-Time Linker Allocator */ -#if !defined (_RTEMS_RTL_ALLOCATOR_H_) +#if !defined(_RTEMS_RTL_ALLOCATOR_H_) #define _RTEMS_RTL_ALLOCATOR_H_ #include @@ -84,7 +84,7 @@ typedef enum rtems_rtl_alloc_cmd rtems_rtl_alloc_cmd; /** * The number of tags. */ -#define RTEMS_RTL_ALLOC_TAGS ((size_t) (RTEMS_RTL_ALLOC_READ_EXEC + 1)) +#define RTEMS_RTL_ALLOC_TAGS ((size_t)(RTEMS_RTL_ALLOC_READ_EXEC + 1)) /** * Allocator handler handles all RTL allocations. It can be hooked and @@ -101,9 +101,8 @@ typedef enum rtems_rtl_alloc_cmd rtems_rtl_alloc_cmd; * not used if deleting or freeing a previous allocation. */ typedef void (*rtems_rtl_allocator)(rtems_rtl_alloc_cmd cmd, - rtems_rtl_alloc_tag tag, - void** address, - size_t size); + rtems_rtl_alloc_tag tag, void** address, + size_t size); /** * The allocator data. @@ -122,7 +121,7 @@ typedef struct rtems_rtl_alloc_data rtems_rtl_alloc_data; * * @param data The data to initialise. */ -void rtems_rtl_alloc_initialise (rtems_rtl_alloc_data* data); +void rtems_rtl_alloc_initialise(rtems_rtl_alloc_data* data); /** * The Runtime Loader allocator new allocates new memory and optionally clear @@ -133,7 +132,7 @@ void rtems_rtl_alloc_initialise (rtems_rtl_alloc_data* data); * @param zero If true the memory is cleared. * @return void* The memory address or NULL is not memory available. */ -void* rtems_rtl_alloc_new (rtems_rtl_alloc_tag tag, size_t size, bool zero); +void* rtems_rtl_alloc_new(rtems_rtl_alloc_tag tag, size_t size, bool zero); /** * The Runtime Loader allocator delete deletes allocated memory. @@ -141,7 +140,7 @@ void* rtems_rtl_alloc_new (rtems_rtl_alloc_tag tag, size_t size, bool zero); * @param tag The type of allocation request. * @param address The memory address to delete. A NULL is ignored. */ -void rtems_rtl_alloc_del (rtems_rtl_alloc_tag tag, void* address); +void rtems_rtl_alloc_del(rtems_rtl_alloc_tag tag, void* address); /** * The Runtime Loader allocator resize resizes allocated memory. @@ -157,10 +156,8 @@ void rtems_rtl_alloc_del (rtems_rtl_alloc_tag tag, void* address); * @param zero If true the memory is cleared. * @return void* The memory address or NULL is not memory available. */ -void* rtems_rtl_alloc_resize (rtems_rtl_alloc_tag tag, - void* address, - size_t size, - bool zero); +void* rtems_rtl_alloc_resize(rtems_rtl_alloc_tag tag, void* address, + size_t size, bool zero); /** * The Runtime Loader allocator lock. An allocator that depends on a @@ -169,7 +166,7 @@ void* rtems_rtl_alloc_resize (rtems_rtl_alloc_tag tag, * of the memory. This call be used to lock such an allocator. * Allocator calls in this interface are protected by the RTL lock. */ -void rtems_rtl_alloc_lock (void); +void rtems_rtl_alloc_lock(void); /** * The Runtime Loader allocator unlock. An allocator that depends on a @@ -178,7 +175,7 @@ void rtems_rtl_alloc_lock (void); * of the memory. This call can be used to unlock such an allocator. * Allocator calls in this interface are protected by the RTL lock. */ -void rtems_rtl_alloc_unlock (void); +void rtems_rtl_alloc_unlock(void); /** * The Runtime Loader allocator enable write on a bloc of allocated memory. @@ -186,7 +183,7 @@ void rtems_rtl_alloc_unlock (void); * @param tag The type of allocation request. Must match the address. * @param address The memory address to write enable. A NULL is ignored. */ -void rtems_rtl_alloc_wr_enable (rtems_rtl_alloc_tag tag, void* address); +void rtems_rtl_alloc_wr_enable(rtems_rtl_alloc_tag tag, void* address); /** * The Runtime Loader allocator disable write on a bloc of allocated memory. @@ -194,7 +191,7 @@ void rtems_rtl_alloc_wr_enable (rtems_rtl_alloc_tag tag, void* address); * @param tag The type of allocation request. Must match the address. * @param address The memory address to write disable. A NULL is ignored. */ -void rtems_rtl_alloc_wr_disable (rtems_rtl_alloc_tag tag, void* address); +void rtems_rtl_alloc_wr_disable(rtems_rtl_alloc_tag tag, void* address); /** * Hook the Runtime Loader allocatior. A handler can call the previous handler @@ -205,7 +202,7 @@ void rtems_rtl_alloc_wr_disable (rtems_rtl_alloc_tag tag, void* address); * @param handler The handler to use as the allocator. * @return rtems_rtl_alloc_handler The previous handler. */ -rtems_rtl_allocator rtems_rtl_alloc_hook (rtems_rtl_allocator handler); +rtems_rtl_allocator rtems_rtl_alloc_hook(rtems_rtl_allocator handler); /** * Allocate memory to an indirect handle. @@ -214,9 +211,8 @@ rtems_rtl_allocator rtems_rtl_alloc_hook (rtems_rtl_allocator handler); * @param handle The handle to allocate the memory to. * @param size The size of the allocation. */ -void rtems_rtl_alloc_indirect_new (rtems_rtl_alloc_tag tag, - rtems_rtl_ptr* handle, - size_t size); +void rtems_rtl_alloc_indirect_new(rtems_rtl_alloc_tag tag, + rtems_rtl_ptr* handle, size_t size); /** * Free memory from an indirect handle. @@ -224,43 +220,43 @@ void rtems_rtl_alloc_indirect_new (rtems_rtl_alloc_tag tag, * @param tag The type of allocation request. * @param handle The handle to free the memory from. */ -void rtems_rtl_alloc_indirect_del (rtems_rtl_alloc_tag tag, - rtems_rtl_ptr* handle); +void rtems_rtl_alloc_indirect_del(rtems_rtl_alloc_tag tag, + rtems_rtl_ptr* handle); /** * Return the default tag for text sections. * * @return The text tag. */ -rtems_rtl_alloc_tag rtems_rtl_alloc_text_tag (void); +rtems_rtl_alloc_tag rtems_rtl_alloc_text_tag(void); /** * Return the default tag for const sections. * * @return The const tag. */ -rtems_rtl_alloc_tag rtems_rtl_alloc_const_tag (void); +rtems_rtl_alloc_tag rtems_rtl_alloc_const_tag(void); /** * Return the default tag for exception sections. * * @return The eh tag. */ -rtems_rtl_alloc_tag rtems_rtl_alloc_eh_tag (void); +rtems_rtl_alloc_tag rtems_rtl_alloc_eh_tag(void); /** * Return the default tag for data sections. * * @return The data tag. */ -rtems_rtl_alloc_tag rtems_rtl_alloc_data_tag (void); +rtems_rtl_alloc_tag rtems_rtl_alloc_data_tag(void); /** * Return the default tag for bss sections. * * @return The bss tag. */ -rtems_rtl_alloc_tag rtems_rtl_alloc_bss_tag (void); +rtems_rtl_alloc_tag rtems_rtl_alloc_bss_tag(void); /** * Allocate the memory for a module given the size of the text, const, data and @@ -280,11 +276,11 @@ rtems_rtl_alloc_tag rtems_rtl_alloc_bss_tag (void); * @retval true The memory has been allocated. * @retval false The allocation of memory has failed. */ -bool rtems_rtl_alloc_module_new (void** text_base, size_t text_size, - void** const_base, size_t const_size, - void** eh_base, size_t eh_size, - void** data_base, size_t data_size, - void** bss_base, size_t bss_size); +bool rtems_rtl_alloc_module_new(void** text_base, size_t text_size, + void** const_base, size_t const_size, + void** eh_base, size_t eh_size, + void** data_base, size_t data_size, + void** bss_base, size_t bss_size); /** * Resize the allocated memory for a module given the new size of the text, @@ -304,11 +300,11 @@ bool rtems_rtl_alloc_module_new (void** text_base, size_t text_size, * @retval true The memory has been allocated. * @retval false The allocation of memory has failed. */ -bool rtems_rtl_alloc_module_resize (void** text_base, size_t text_size, - void** const_base, size_t const_size, - void** eh_base, size_t eh_size, - void** data_base, size_t data_size, - void** bss_base, size_t bss_size); +bool rtems_rtl_alloc_module_resize(void** text_base, size_t text_size, + void** const_base, size_t const_size, + void** eh_base, size_t eh_size, + void** data_base, size_t data_size, + void** bss_base, size_t bss_size); /** * Free the memory allocated to a module. @@ -319,9 +315,9 @@ bool rtems_rtl_alloc_module_resize (void** text_base, size_t text_size, * @param data_base Pointer to the data base pointer. * @param bss_base Pointer to the bss base pointer. */ -void rtems_rtl_alloc_module_del (void** text_base, void** const_base, - void** eh_base, void** data_base, - void** bss_base); +void rtems_rtl_alloc_module_del(void** text_base, void** const_base, + void** eh_base, void** data_base, + void** bss_base); #ifdef __cplusplus } diff --git a/cpukit/include/rtems/rtl/rtl-archive.h b/cpukit/include/rtems/rtl/rtl-archive.h index 3c8516e02f..d595bac169 100644 --- a/cpukit/include/rtems/rtl/rtl-archive.h +++ b/cpukit/include/rtems/rtl/rtl-archive.h @@ -45,7 +45,7 @@ * reported to a user. The user error is undefined symbols. */ -#if !defined (_RTEMS_RTL_ARCHIVE_H_) +#if !defined(_RTEMS_RTL_ARCHIVE_H_) #define _RTEMS_RTL_ARCHIVE_H_ #include @@ -60,14 +60,13 @@ extern "C" { * Flags for archives. */ #define RTEMS_RTL_ARCHIVE_USER_LOAD (1 << 0) /**< User forced load. */ -#define RTEMS_RTL_ARCHIVE_REMOVE (1 << 1) /**< The achive is not found. */ -#define RTEMS_RTL_ARCHIVE_LOAD (1 << 2) /**< Load the achive. */ +#define RTEMS_RTL_ARCHIVE_REMOVE (1 << 1) /**< The achive is not found. */ +#define RTEMS_RTL_ARCHIVE_LOAD (1 << 2) /**< Load the achive. */ /** * Symbol search and loading results. */ -typedef enum rtems_rtl_archive_search -{ +typedef enum rtems_rtl_archive_search { rtems_rtl_archive_search_not_found = 0, /**< The search failed to find the symbol. */ rtems_rtl_archive_search_found = 1, /**< The symbols was found. */ @@ -75,56 +74,52 @@ typedef enum rtems_rtl_archive_search object file has been loaded */ rtems_rtl_archive_search_error = 3, /**< There was an error searching or loading. */ - rtems_rtl_archive_search_no_config = 4 /**< There is no config or it is - * invalid. */ + rtems_rtl_archive_search_no_config = 4 /**< There is no config or it is + * invalid. */ } rtems_rtl_archive_search; /** * RTL Archive symbols. */ -typedef struct rtems_rtl_archive_symbol -{ - size_t entry; /**< Index in the symbol offset table. */ - const char* label; /**< The symbol's label. */ +typedef struct rtems_rtl_archive_symbol { + size_t entry; /**< Index in the symbol offset table. */ + const char* label; /**< The symbol's label. */ } rtems_rtl_archive_symbol; /** * RTL Archive symbols. */ -typedef struct rtems_rtl_archive_symbols -{ - void* base; /**< Base of the symbol table. */ - size_t size; /**< Size of the symbol table. */ - size_t entries; /**< Entries in the symbol table. */ - const char* names; /**< Start of the symbol names. */ - rtems_rtl_archive_symbol* symbols; /**< Sorted symbol table. */ +typedef struct rtems_rtl_archive_symbols { + void* base; /**< Base of the symbol table. */ + size_t size; /**< Size of the symbol table. */ + size_t entries; /**< Entries in the symbol table. */ + const char* names; /**< Start of the symbol names. */ + rtems_rtl_archive_symbol* symbols; /**< Sorted symbol table. */ } rtems_rtl_archive_symbols; /** * RTL Archive data. */ -typedef struct rtems_rtl_archive -{ - rtems_chain_node node; /**< Chain link. */ - const char* name; /**< Archive absolute path. */ - size_t size; /**< Size of the archive. */ - time_t mtime; /**< Archive's last modified time. */ - off_t enames; /**< Extended file name offset, lazy load. */ - rtems_rtl_archive_symbols symbols; /**< Ranlib symbol table. */ - size_t refs; /**< Loaded object modules. */ - uint32_t flags; /**< Some flags. */ +typedef struct rtems_rtl_archive { + rtems_chain_node node; /**< Chain link. */ + const char* name; /**< Archive absolute path. */ + size_t size; /**< Size of the archive. */ + time_t mtime; /**< Archive's last modified time. */ + off_t enames; /**< Extended file name offset, lazy load. */ + rtems_rtl_archive_symbols symbols; /**< Ranlib symbol table. */ + size_t refs; /**< Loaded object modules. */ + uint32_t flags; /**< Some flags. */ } rtems_rtl_archive; /** * RTL Archive data. */ -typedef struct rtems_rtl_archives -{ - const char* config_name; /**< Config file name. */ - time_t config_mtime; /**< Config last modified time. */ - ssize_t config_length; /**< Length the config data. */ - char* config; /**< Config file contents. */ - rtems_chain_control archives; /**< The located archives. */ +typedef struct rtems_rtl_archives { + const char* config_name; /**< Config file name. */ + time_t config_mtime; /**< Config last modified time. */ + ssize_t config_length; /**< Length the config data. */ + char* config; /**< Config file contents. */ + rtems_chain_control archives; /**< The located archives. */ } rtems_rtl_archives; /** @@ -139,14 +134,14 @@ typedef void (*rtems_rtl_archive_error)(int num, const char* text); * @param config The path to the configuration file. * @return bool Returns @true is the archives are open. */ -void rtems_rtl_archives_open (rtems_rtl_archives* archives, const char* config); +void rtems_rtl_archives_open(rtems_rtl_archives* archives, const char* config); /** * Close the RTL archives support. * * @param archives The archives data to close. */ -void rtems_rtl_archives_close (rtems_rtl_archives* archives); +void rtems_rtl_archives_close(rtems_rtl_archives* archives); /** * Refresh the archives data. Check if the configuration has changes and if it @@ -159,7 +154,7 @@ void rtems_rtl_archives_close (rtems_rtl_archives* archives); * @param archives The archives data to refresh. * @retval false The refresh failed, an error will have been set. */ -bool rtems_rtl_archives_refresh (rtems_rtl_archives* archives); +bool rtems_rtl_archives_refresh(rtems_rtl_archives* archives); /** * Load an archive. @@ -168,7 +163,7 @@ bool rtems_rtl_archives_refresh (rtems_rtl_archives* archives); * @param name The archive to load. * @retval true The archive is loaded. */ -bool rtems_rtl_archive_load (rtems_rtl_archives* archives, const char* name); +bool rtems_rtl_archive_load(rtems_rtl_archives* archives, const char* name); /** * Search for a symbol and load the first object file that has the symbol. @@ -178,9 +173,9 @@ bool rtems_rtl_archive_load (rtems_rtl_archives* archives, const char* name); * @param load If @true load the object file the symbol is found in * else return the found not found status. */ -rtems_rtl_archive_search rtems_rtl_archive_obj_load (rtems_rtl_archives* archives, - const char* symbol, - bool load); +rtems_rtl_archive_search +rtems_rtl_archive_obj_load(rtems_rtl_archives* archives, const char* symbol, + bool load); /** * Find a module in an archive returning the offset in the archive and @@ -201,13 +196,10 @@ rtems_rtl_archive_search rtems_rtl_archive_obj_load (rtems_rtl_archives* archive * @retval true The file was found in the archive. * @retval false The file was not found. */ -bool rtems_rtl_obj_archive_find_obj (int fd, - size_t fsize, - const char** name, - off_t* offset, - size_t* size, - off_t* extended_names, - rtems_rtl_archive_error error); +bool rtems_rtl_obj_archive_find_obj(int fd, size_t fsize, const char** name, + off_t* offset, size_t* size, + off_t* extended_names, + rtems_rtl_archive_error error); #ifdef __cplusplus } diff --git a/cpukit/include/rtems/rtl/rtl-fwd.h b/cpukit/include/rtems/rtl/rtl-fwd.h index 46b0dc6830..7784d613f3 100644 --- a/cpukit/include/rtems/rtl/rtl-fwd.h +++ b/cpukit/include/rtems/rtl/rtl-fwd.h @@ -32,7 +32,7 @@ * @brief RTEMS Run-Time Linker ELF Headers */ -#if !defined (_RTEMS_RTL_FWD_H_) +#if !defined(_RTEMS_RTL_FWD_H_) #define _RTEMS_RTL_FWD_H_ #ifdef __cplusplus diff --git a/cpukit/include/rtems/rtl/rtl-indirect-ptr.h b/cpukit/include/rtems/rtl/rtl-indirect-ptr.h index a0e252cdf2..7962a46368 100644 --- a/cpukit/include/rtems/rtl/rtl-indirect-ptr.h +++ b/cpukit/include/rtems/rtl/rtl-indirect-ptr.h @@ -33,7 +33,7 @@ * compaction in the allocator. */ -#if !defined (_RTEMS_RTL_INDIRECT_PTR_H_) +#if !defined(_RTEMS_RTL_INDIRECT_PTR_H_) #define _RTEMS_RTL_INDIRECT_PTR_H_ #ifdef __cplusplus @@ -46,8 +46,8 @@ extern "C" { * The RTL Indirect pointer. */ struct rtems_rtl_ptr { - rtems_chain_node node; /**< Indirect pointers are held on lists. */ - void* pointer; /**< The actual pointer. */ + rtems_chain_node node; /**< Indirect pointers are held on lists. */ + void* pointer; /**< The actual pointer. */ }; typedef struct rtems_rtl_ptr rtems_rtl_ptr; @@ -56,8 +56,8 @@ typedef struct rtems_rtl_ptr rtems_rtl_ptr; * The RTL Indirect size and pointer. */ struct rtems_rtl_sptr { - rtems_rtl_ptr ptr; /**< The indirect pointer. */ - size_t size; /**< The size of the memory block. */ + rtems_rtl_ptr ptr; /**< The indirect pointer. */ + size_t size; /**< The size of the memory block. */ }; typedef struct rtems_rtl_sptr rtems_rtl_sptr; @@ -69,8 +69,8 @@ typedef struct rtems_rtl_sptr rtems_rtl_sptr; * used by applications. */ struct rtems_rtl_ptr_chain { - rtems_chain_node node; /**< Chain of indirect pointers. */ - rtems_rtl_ptr ptr; /**< The indirect pointer. */ + rtems_chain_node node; /**< Chain of indirect pointers. */ + rtems_rtl_ptr ptr; /**< The indirect pointer. */ }; typedef struct rtems_rtl_ptr_chain rtems_rtl_ptr_chain; @@ -83,7 +83,7 @@ typedef struct rtems_rtl_ptr_chain rtems_rtl_ptr_chain; */ struct rtems_rtl_sptr_chain { rtems_chain_node node; /**< Chain of indirect pointers. */ - rtems_rtl_sptr ptr; /**< The indirect pointer. */ + rtems_rtl_sptr ptr; /**< The indirect pointer. */ }; typedef struct rtems_rtl_sptr_chain rtems_rtl_sptr_chain; @@ -94,8 +94,7 @@ typedef struct rtems_rtl_sptr_chain rtems_rtl_sptr_chain; * @param handle The handle the pointer is returned from. * @return void* The pointer held in the handle. */ -static inline void* rtems_rtl_ptr_get (rtems_rtl_ptr* handle) -{ +static inline void* rtems_rtl_ptr_get(rtems_rtl_ptr* handle) { return handle->pointer; } @@ -105,8 +104,7 @@ static inline void* rtems_rtl_ptr_get (rtems_rtl_ptr* handle) * @param handle The handle the pointer is returned from. * @param pointer The pointer to set in the handle. */ -static inline void rtems_rtl_ptr_set (rtems_rtl_ptr* handle, void* pointer) -{ +static inline void rtems_rtl_ptr_set(rtems_rtl_ptr* handle, void* pointer) { handle->pointer = pointer; } @@ -115,9 +113,8 @@ static inline void rtems_rtl_ptr_set (rtems_rtl_ptr* handle, void* pointer) * * @param handle The handle to initialise. */ -static inline void rtems_rtl_ptr_init (rtems_rtl_ptr* handle) -{ - rtems_chain_set_off_chain (&handle->node); +static inline void rtems_rtl_ptr_init(rtems_rtl_ptr* handle) { + rtems_chain_set_off_chain(&handle->node); handle->pointer = NULL; } @@ -127,8 +124,7 @@ static inline void rtems_rtl_ptr_init (rtems_rtl_ptr* handle) * @param handle The handle to test. * @return bool True if the pointer is NULL. */ -static inline bool rtems_rtl_ptr_null (rtems_rtl_ptr* handle) -{ +static inline bool rtems_rtl_ptr_null(rtems_rtl_ptr* handle) { return handle->pointer == NULL; } @@ -139,16 +135,15 @@ static inline bool rtems_rtl_ptr_null (rtems_rtl_ptr* handle) * @param src The source handle to move the pointer from. * @param dst The destination handle to receive the pointer. */ -static inline void rtems_rtl_ptr_move (rtems_rtl_ptr* dst, rtems_rtl_ptr* src) -{ +static inline void rtems_rtl_ptr_move(rtems_rtl_ptr* dst, rtems_rtl_ptr* src) { /* * We do not know which chain the src handle resides on so insert the dst * handle after the src handle then extract the src handle. */ - rtems_chain_insert_unprotected (&src->node, &dst->node); - rtems_chain_extract_unprotected (&src->node); + rtems_chain_insert_unprotected(&src->node, &dst->node); + rtems_chain_extract_unprotected(&src->node); dst->pointer = src->pointer; - rtems_rtl_ptr_init (src); + rtems_rtl_ptr_init(src); } /** @@ -157,7 +152,7 @@ static inline void rtems_rtl_ptr_move (rtems_rtl_ptr* dst, rtems_rtl_ptr* src) * @param _h The handle. * @param _t The type. */ -#define rtems_rtl_ptr_type_get(_h, _t) ((_t*) rtems_rtl_ptr_get (_h)) +#define rtems_rtl_ptr_type_get(_h, _t) ((_t*)rtems_rtl_ptr_get(_h)) /** * Get the pointer given an indirect handle. @@ -165,9 +160,8 @@ static inline void rtems_rtl_ptr_move (rtems_rtl_ptr* dst, rtems_rtl_ptr* src) * @param handle The handle the pointer is returned from. * @return void* The pointer held in the handle. */ -static inline void* rtems_rtl_sptr_get (rtems_rtl_sptr* handle) -{ - return rtems_rtl_ptr_get (&handle->ptr); +static inline void* rtems_rtl_sptr_get(rtems_rtl_sptr* handle) { + return rtems_rtl_ptr_get(&handle->ptr); } /** @@ -176,9 +170,8 @@ static inline void* rtems_rtl_sptr_get (rtems_rtl_sptr* handle) * @param handle The handle the pointer is returned from. * @param pointer The pointer to set in the handle. */ -static inline void rtems_rtl_sptr_set (rtems_rtl_sptr* handle, void* pointer) -{ - rtems_rtl_ptr_set (&handle->ptr, pointer); +static inline void rtems_rtl_sptr_set(rtems_rtl_sptr* handle, void* pointer) { + rtems_rtl_ptr_set(&handle->ptr, pointer); } /** @@ -186,9 +179,8 @@ static inline void rtems_rtl_sptr_set (rtems_rtl_sptr* handle, void* pointer) * * @param handle The handle to initialise. */ -static inline void rtems_rtl_sptr_init (rtems_rtl_sptr* handle) -{ - rtems_rtl_ptr_init (&handle->ptr); +static inline void rtems_rtl_sptr_init(rtems_rtl_sptr* handle) { + rtems_rtl_ptr_init(&handle->ptr); handle->size = 0; } @@ -198,9 +190,8 @@ static inline void rtems_rtl_sptr_init (rtems_rtl_sptr* handle) * @param handle The handle to test. * @return bool True if the pointer is NULL. */ -static inline bool rtems_rtl_sptr_null (rtems_rtl_sptr* handle) -{ - return rtems_rtl_ptr_null (&handle->ptr); +static inline bool rtems_rtl_sptr_null(rtems_rtl_sptr* handle) { + return rtems_rtl_ptr_null(&handle->ptr); } /** @@ -210,9 +201,9 @@ static inline bool rtems_rtl_sptr_null (rtems_rtl_sptr* handle) * @param src The source handle to move the pointer from. * @param dst The destination handle to receive the pointer. */ -static inline void rtems_rtl_sptr_move (rtems_rtl_sptr* dst, rtems_rtl_sptr* src) -{ - rtems_rtl_ptr_move (&dst->ptr, &src->ptr); +static inline void rtems_rtl_sptr_move(rtems_rtl_sptr* dst, + rtems_rtl_sptr* src) { + rtems_rtl_ptr_move(&dst->ptr, &src->ptr); dst->size = src->size; src->size = 0; } @@ -223,8 +214,7 @@ static inline void rtems_rtl_sptr_move (rtems_rtl_sptr* dst, rtems_rtl_sptr* src * @param handle The handle to get the size from. * @return size_t The size_t. */ -static inline size_t rtems_rtl_sptr_get_size (rtems_rtl_sptr* handle) -{ +static inline size_t rtems_rtl_sptr_get_size(rtems_rtl_sptr* handle) { return handle->size; } @@ -234,8 +224,8 @@ static inline size_t rtems_rtl_sptr_get_size (rtems_rtl_sptr* handle) * @param handle The handle to set the size. * @param size The size to set.. */ -static inline void rtems_rtl_sptr_set_size (rtems_rtl_sptr* handle, size_t size) -{ +static inline void rtems_rtl_sptr_set_size(rtems_rtl_sptr* handle, + size_t size) { handle->size = size; } @@ -245,7 +235,7 @@ static inline void rtems_rtl_sptr_set_size (rtems_rtl_sptr* handle, size_t size) * @param _h The handle. * @param _t The type. */ -#define rtems_rtl_sptr_type_get(_h, _t) ((_t*) rtems_rtl_sptr_get (_h)) +#define rtems_rtl_sptr_type_get(_h, _t) ((_t*)rtems_rtl_sptr_get(_h)) #ifdef __cplusplus } diff --git a/cpukit/include/rtems/rtl/rtl-obj-cache.h b/cpukit/include/rtems/rtl/rtl-obj-cache.h index c80e1f7b09..1a04e58bcd 100644 --- a/cpukit/include/rtems/rtl/rtl-obj-cache.h +++ b/cpukit/include/rtems/rtl/rtl-obj-cache.h @@ -54,7 +54,7 @@ * parts of the file. */ -#if !defined (_RTEMS_RTL_OBJ_CACHE_H_) +#if !defined(_RTEMS_RTL_OBJ_CACHE_H_) #define _RTEMS_RTL_OBJ_CACHE_H_ #include @@ -69,15 +69,14 @@ extern "C" { /** * The buffer cache. */ -typedef struct rtems_rtl_obj_cache -{ - int fd; /**< The file descriptor of the data in the cache. */ - size_t file_size; /**< The size of the file. */ - off_t offset; /**< The base offset of the buffer. */ - size_t size; /**< The size of the cache. */ - size_t level; /**< The amount of data in the cache. A file can be - * smaller than the cache file. */ - uint8_t* buffer; /**< The buffer */ +typedef struct rtems_rtl_obj_cache { + int fd; /**< The file descriptor of the data in the cache. */ + size_t file_size; /**< The size of the file. */ + off_t offset; /**< The base offset of the buffer. */ + size_t size; /**< The size of the cache. */ + size_t level; /**< The amount of data in the cache. A file can be + * smaller than the cache file. */ + uint8_t* buffer; /**< The buffer */ } rtems_rtl_obj_cache; /** @@ -89,21 +88,21 @@ typedef struct rtems_rtl_obj_cache * @retval true The cache is open. * @retval false The cache is not open. The RTL error is set. */ -bool rtems_rtl_obj_cache_open (rtems_rtl_obj_cache* cache, size_t size); +bool rtems_rtl_obj_cache_open(rtems_rtl_obj_cache* cache, size_t size); /** * Close a cache. * * @param cache The cache to close. */ -void rtems_rtl_obj_cache_close (rtems_rtl_obj_cache* cache); +void rtems_rtl_obj_cache_close(rtems_rtl_obj_cache* cache); /** * Flush the cache. Any further read will read the data from the file. * * @param cache The cache to flush. */ -void rtems_rtl_obj_cache_flush (rtems_rtl_obj_cache* cache); +void rtems_rtl_obj_cache_flush(rtems_rtl_obj_cache* cache); /** * Read data by reference. The length contains the amount of data that should @@ -121,11 +120,8 @@ void rtems_rtl_obj_cache_flush (rtems_rtl_obj_cache* cache); * @retval true The data referenced is in the cache. * @retval false The read failed and the RTL error has been set. */ -bool rtems_rtl_obj_cache_read (rtems_rtl_obj_cache* cache, - int fd, - off_t offset, - void** buffer, - size_t* length); +bool rtems_rtl_obj_cache_read(rtems_rtl_obj_cache* cache, int fd, off_t offset, + void** buffer, size_t* length); /** * Read data by value. The data is copied to the user supplied buffer. @@ -138,11 +134,8 @@ bool rtems_rtl_obj_cache_read (rtems_rtl_obj_cache* cache, * @retval true The data has been read from the cache. * @retval false The read failed and the RTL error has been set. */ -bool rtems_rtl_obj_cache_read_byval (rtems_rtl_obj_cache* cache, - int fd, - off_t offset, - void* buffer, - size_t length); +bool rtems_rtl_obj_cache_read_byval(rtems_rtl_obj_cache* cache, int fd, + off_t offset, void* buffer, size_t length); #ifdef __cplusplus } diff --git a/cpukit/include/rtems/rtl/rtl-obj-comp.h b/cpukit/include/rtems/rtl/rtl-obj-comp.h index 9ff3e5d147..7b84c6db47 100644 --- a/cpukit/include/rtems/rtl/rtl-obj-comp.h +++ b/cpukit/include/rtems/rtl/rtl-obj-comp.h @@ -39,7 +39,7 @@ * allocated. */ -#if !defined (_RTEMS_RTL_OBJ_COMP_H_) +#if !defined(_RTEMS_RTL_OBJ_COMP_H_) #define _RTEMS_RTL_OBJ_COMP_H_ #include @@ -62,24 +62,22 @@ extern "C" { /** * The compressed file. */ -typedef struct rtems_rtl_obj_cpmp -{ - rtems_rtl_obj_cache* cache; /**< The cache provides the input - * buffer. */ - int fd; /**< The file descriptor. */ - int compression; /**< The type of compression. */ - off_t offset; /**< The base offset of the buffer. */ - size_t size; /**< The size of the output buffer. */ - size_t level; /**< The amount of data in the buffer. */ - uint8_t* buffer; /**< The buffer */ - uint32_t read; /**< The amount of data read. */ +typedef struct rtems_rtl_obj_cpmp { + rtems_rtl_obj_cache* cache; /**< The cache provides the input + * buffer. */ + int fd; /**< The file descriptor. */ + int compression; /**< The type of compression. */ + off_t offset; /**< The base offset of the buffer. */ + size_t size; /**< The size of the output buffer. */ + size_t level; /**< The amount of data in the buffer. */ + uint8_t* buffer; /**< The buffer */ + uint32_t read; /**< The amount of data read. */ } rtems_rtl_obj_comp; /** * Return the input level. */ -static inline uint32_t rtems_rtl_obj_comp_input (rtems_rtl_obj_comp* comp) -{ +static inline uint32_t rtems_rtl_obj_comp_input(rtems_rtl_obj_comp* comp) { return comp->read; } @@ -91,15 +89,14 @@ static inline uint32_t rtems_rtl_obj_comp_input (rtems_rtl_obj_comp* comp) * @retval true The compressor is open. * @retval false The compressor is not open. The RTL error is set. */ -bool rtems_rtl_obj_comp_open (rtems_rtl_obj_comp* comp, - size_t size); +bool rtems_rtl_obj_comp_open(rtems_rtl_obj_comp* comp, size_t size); /** * Close a compressor. * * @param comp The compressor to close. */ -void rtems_rtl_obj_comp_close (rtems_rtl_obj_comp* comp); +void rtems_rtl_obj_comp_close(rtems_rtl_obj_comp* comp); /** * Set the cache and offset in the file the compressed stream starts. @@ -110,11 +107,9 @@ void rtems_rtl_obj_comp_close (rtems_rtl_obj_comp* comp); * @param compression The type of compression being streamed. * @param offset The offset in the file the compressed stream starts. */ -void rtems_rtl_obj_comp_set (rtems_rtl_obj_comp* comp, - rtems_rtl_obj_cache* cache, - int fd, - int compression, - off_t offset); +void rtems_rtl_obj_comp_set(rtems_rtl_obj_comp* comp, + rtems_rtl_obj_cache* cache, int fd, int compression, + off_t offset); /** * Read decompressed data. The length contains the amount of data that should @@ -130,9 +125,8 @@ void rtems_rtl_obj_comp_set (rtems_rtl_obj_comp* comp, * @retval true The data referenced is in the cache. * @retval false The read failed and the RTL error has been set. */ -bool rtems_rtl_obj_comp_read (rtems_rtl_obj_comp* comp, - void* buffer, - size_t length); +bool rtems_rtl_obj_comp_read(rtems_rtl_obj_comp* comp, void* buffer, + size_t length); #ifdef __cplusplus } diff --git a/cpukit/include/rtems/rtl/rtl-obj-fwd.h b/cpukit/include/rtems/rtl/rtl-obj-fwd.h index 2c452dcdc6..78f8556b0b 100644 --- a/cpukit/include/rtems/rtl/rtl-obj-fwd.h +++ b/cpukit/include/rtems/rtl/rtl-obj-fwd.h @@ -32,7 +32,7 @@ * @brief RTEMS Run-Time Linker ELF Headers */ -#if !defined (_RTEMS_RTL_OBJ_FWD_H_) +#if !defined(_RTEMS_RTL_OBJ_FWD_H_) #define _RTEMS_RTL_OBJ_FWD_H_ #ifdef __cplusplus diff --git a/cpukit/include/rtems/rtl/rtl-obj.h b/cpukit/include/rtems/rtl/rtl-obj.h index 7ac8765a06..a0606b5a0d 100644 --- a/cpukit/include/rtems/rtl/rtl-obj.h +++ b/cpukit/include/rtems/rtl/rtl-obj.h @@ -32,7 +32,7 @@ * @brief RTEMS Run-Time Linker Object Support. */ -#if !defined (_RTEMS_RTL_OBJ_H_) +#if !defined(_RTEMS_RTL_OBJ_H_) #define _RTEMS_RTL_OBJ_H_ #include @@ -47,15 +47,14 @@ extern "C" { /** * Loader format flags. */ -#define RTEMS_RTL_FMT_ELF (1 << 0) -#define RTEMS_RTL_FMT_COMP (1 << 1) +#define RTEMS_RTL_FMT_ELF (1 << 0) +#define RTEMS_RTL_FMT_COMP (1 << 1) #define RTEMS_RTL_FMT_PRIVATE (1 << 16) /** * Loader format definition. */ -typedef struct rtems_rtl_loader_format -{ +typedef struct rtems_rtl_loader_format { /** * The format label. This can be used to determine and manage * specific formats. @@ -72,91 +71,96 @@ typedef struct rtems_rtl_loader_format * The type of the format loader check handler. This handler checks the format * and if it is detected as suitable it returns true. */ -typedef bool (*rtems_rtl_loader_check) (rtems_rtl_obj* obj, int fd); +typedef bool (*rtems_rtl_loader_check)(rtems_rtl_obj* obj, int fd); /** * The type of the format loader load handler. This handler loads the specific * format. */ -typedef bool (*rtems_rtl_loader_load) (rtems_rtl_obj* obj, int fd); +typedef bool (*rtems_rtl_loader_load)(rtems_rtl_obj* obj, int fd); /** * The type of the format loader unload handler. This handler unloads the * specific format. */ -typedef bool (*rtems_rtl_loader_unload) (rtems_rtl_obj* obj); +typedef bool (*rtems_rtl_loader_unload)(rtems_rtl_obj* obj); /** * The type of the format loader signature handler. This handler checks the * format signature. */ -typedef rtems_rtl_loader_format* (*rtems_rtl_loader_sig) (void); +typedef rtems_rtl_loader_format* (*rtems_rtl_loader_sig)(void); /** * Table for supported loadable formats. */ -typedef struct rtems_rtl_loader_table -{ - rtems_rtl_loader_check check; /**< The check handler. */ - rtems_rtl_loader_load load; /**< The loader. */ - rtems_rtl_loader_unload unload; /**< The unloader. */ - rtems_rtl_loader_sig signature; /**< The loader's signature. */ +typedef struct rtems_rtl_loader_table { + rtems_rtl_loader_check check; /**< The check handler. */ + rtems_rtl_loader_load load; /**< The loader. */ + rtems_rtl_loader_unload unload; /**< The unloader. */ + rtems_rtl_loader_sig signature; /**< The loader's signature. */ } rtems_rtl_loader_table; /** * Flags for the various section types. */ -#define RTEMS_RTL_OBJ_SECT_TEXT (1 << 0) /**< Section holds program text. */ -#define RTEMS_RTL_OBJ_SECT_CONST (1 << 1) /**< Section holds program text. */ -#define RTEMS_RTL_OBJ_SECT_DATA (1 << 2) /**< Section holds program data. */ -#define RTEMS_RTL_OBJ_SECT_BSS (1 << 3) /**< Section holds program bss. */ -#define RTEMS_RTL_OBJ_SECT_EH (1 << 4) /**< Section holds exception data. */ -#define RTEMS_RTL_OBJ_SECT_TLS (1 << 5) /**< Section holds TLS data. */ -#define RTEMS_RTL_OBJ_SECT_REL (1 << 6) /**< Section holds relocation recs. */ -#define RTEMS_RTL_OBJ_SECT_RELA (1 << 7) /**< Section holds reloc addend recs. */ -#define RTEMS_RTL_OBJ_SECT_SYM (1 << 8) /**< Section holds symbols. */ -#define RTEMS_RTL_OBJ_SECT_STR (1 << 9) /**< Section holds strings. */ +#define RTEMS_RTL_OBJ_SECT_TEXT (1 << 0) /**< Section holds program text. */ +#define RTEMS_RTL_OBJ_SECT_CONST (1 << 1) /**< Section holds program text. */ +#define RTEMS_RTL_OBJ_SECT_DATA (1 << 2) /**< Section holds program data. */ +#define RTEMS_RTL_OBJ_SECT_BSS (1 << 3) /**< Section holds program bss. */ +#define RTEMS_RTL_OBJ_SECT_EH (1 << 4) /**< Section holds exception data. */ +#define RTEMS_RTL_OBJ_SECT_TLS (1 << 5) /**< Section holds TLS data. */ +#define RTEMS_RTL_OBJ_SECT_REL (1 << 6) /**< Section holds relocation recs. */ +#define RTEMS_RTL_OBJ_SECT_RELA \ + (1 << 7) /**< Section holds reloc addend recs. */ +#define RTEMS_RTL_OBJ_SECT_SYM (1 << 8) /**< Section holds symbols. */ +#define RTEMS_RTL_OBJ_SECT_STR (1 << 9) /**< Section holds strings. */ #define RTEMS_RTL_OBJ_SECT_ALLOC (1 << 10 /**< Section allocates runtime memory. */ -#define RTEMS_RTL_OBJ_SECT_LOAD (1 << 11) /**< Section is loaded from object file. */ -#define RTEMS_RTL_OBJ_SECT_WRITE (1 << 12) /**< Section is writable, ie data. */ -#define RTEMS_RTL_OBJ_SECT_EXEC (1 << 13) /**< Section is executable. */ -#define RTEMS_RTL_OBJ_SECT_ZERO (1 << 14) /**< Section is preset to zero. */ -#define RTEMS_RTL_OBJ_SECT_LINK (1 << 15) /**< Section is link-ordered. */ -#define RTEMS_RTL_OBJ_SECT_CTOR (1 << 16) /**< Section contains constructors. */ -#define RTEMS_RTL_OBJ_SECT_DTOR (1 << 17) /**< Section contains destructors. */ -#define RTEMS_RTL_OBJ_SECT_LOCD (1 << 18) /**< Section has been located. */ -#define RTEMS_RTL_OBJ_SECT_ARCH_ALLOC (1 << 19) /**< Section use arch allocator. */ +#define RTEMS_RTL_OBJ_SECT_LOAD \ + (1 << 11) /**< Section is loaded from object file. */ +#define RTEMS_RTL_OBJ_SECT_WRITE \ + (1 << 12) /**< Section is writable, ie data. \ + */ +#define RTEMS_RTL_OBJ_SECT_EXEC (1 << 13) /**< Section is executable. */ +#define RTEMS_RTL_OBJ_SECT_ZERO (1 << 14) /**< Section is preset to zero. */ +#define RTEMS_RTL_OBJ_SECT_LINK (1 << 15) /**< Section is link-ordered. */ +#define RTEMS_RTL_OBJ_SECT_CTOR \ + (1 << 16) /**< Section contains constructors. \ + */ +#define RTEMS_RTL_OBJ_SECT_DTOR \ + (1 << 17) /**< Section contains destructors. \ + */ +#define RTEMS_RTL_OBJ_SECT_LOCD (1 << 18) /**< Section has been located. */ +#define RTEMS_RTL_OBJ_SECT_ARCH_ALLOC \ + (1 << 19) /**< Section use arch allocator. */ /** * Section types mask. */ -#define RTEMS_RTL_OBJ_SECT_TYPES (RTEMS_RTL_OBJ_SECT_TEXT | \ - RTEMS_RTL_OBJ_SECT_CONST | \ - RTEMS_RTL_OBJ_SECT_DATA | \ - RTEMS_RTL_OBJ_SECT_BSS | \ - RTEMS_RTL_OBJ_SECT_TLS | \ - RTEMS_RTL_OBJ_SECT_EH) +#define RTEMS_RTL_OBJ_SECT_TYPES \ + (RTEMS_RTL_OBJ_SECT_TEXT | RTEMS_RTL_OBJ_SECT_CONST | \ + RTEMS_RTL_OBJ_SECT_DATA | RTEMS_RTL_OBJ_SECT_BSS | RTEMS_RTL_OBJ_SECT_TLS | \ + RTEMS_RTL_OBJ_SECT_EH) /** * An object file is made up of sections and the can be more than * one of a specific type of sections. All sections and grouped * together in memory. */ -struct rtems_rtl_obj_sect -{ - rtems_chain_node node; /**< The node's link in the chain. */ - int section; /**< The section number. */ - const char* name; /**< The section's name. */ - size_t size; /**< The size of the section in memory. */ - off_t offset; /**< Offset into the object file. Relative to - * the start of the object file. */ - uint32_t alignment; /**< Alignment of this section. */ - int link; /**< Section link field. */ - int info; /**< Secfion info field. */ - uint32_t flags; /**< The section's flags. */ - void* base; /**< The base address of the section in - * memory. */ - int load_order; /**< Order we load sections. */ +struct rtems_rtl_obj_sect { + rtems_chain_node node; /**< The node's link in the chain. */ + int section; /**< The section number. */ + const char* name; /**< The section's name. */ + size_t size; /**< The size of the section in memory. */ + off_t offset; /**< Offset into the object file. Relative to + * the start of the object file. */ + uint32_t alignment; /**< Alignment of this section. */ + int link; /**< Section link field. */ + int info; /**< Secfion info field. */ + uint32_t flags; /**< The section's flags. */ + void* base; /**< The base address of the section in + * memory. */ + int load_order; /**< Order we load sections. */ }; /** @@ -165,99 +169,100 @@ struct rtems_rtl_obj_sect * unresolved externals can exist when an object file is loaded and resolved * later when the dependent object file is loaded. */ -struct rtems_rtl_obj_depends -{ - rtems_chain_node node; /**< The node's link in the chain. */ - size_t dependents; /**< The number of dependent object pointers. */ - rtems_rtl_obj* depends[]; /**< Dependtent objects. More follow. */ +struct rtems_rtl_obj_depends { + rtems_chain_node node; /**< The node's link in the chain. */ + size_t dependents; /**< The number of dependent object pointers. */ + rtems_rtl_obj* depends[]; /**< Dependtent objects. More follow. */ }; /** * Dependency iterator. */ -typedef bool (*rtems_rtl_obj_depends_iterator) (rtems_rtl_obj* obj, - rtems_rtl_obj* dependent, - void* data); +typedef bool (*rtems_rtl_obj_depends_iterator)(rtems_rtl_obj* obj, + rtems_rtl_obj* dependent, + void* data); /** * Object file descriptor flags. */ -#define RTEMS_RTL_OBJ_LOCKED (1 << 0) /**< Lock the object file so it cannot - * be unloaded. */ -#define RTEMS_RTL_OBJ_UNRESOLVED (1 << 1) /**< The object file has unresolved - * external symbols. */ -#define RTEMS_RTL_OBJ_BASE (1 << 2) /**< The base image. */ -#define RTEMS_RTL_OBJ_RELOC_TAG (1 << 3) /**< Tag the object as visited when reloc - * parsing. */ -#define RTEMS_RTL_OBJ_DEP_VISITED (1 << 4) /**< Dependency loop detection. */ -#define RTEMS_RTL_OBJ_CTOR_RUN (1 << 5) /**< Constructors have been called. */ +#define RTEMS_RTL_OBJ_LOCKED \ + (1 << 0) /**< Lock the object file so it cannot \ + * be unloaded. */ +#define RTEMS_RTL_OBJ_UNRESOLVED \ + (1 << 1) /**< The object file has unresolved \ + * external symbols. */ +#define RTEMS_RTL_OBJ_BASE (1 << 2) /**< The base image. */ +#define RTEMS_RTL_OBJ_RELOC_TAG \ + (1 << 3) /**< Tag the object as visited when reloc \ + * parsing. */ +#define RTEMS_RTL_OBJ_DEP_VISITED (1 << 4) /**< Dependency loop detection. */ +#define RTEMS_RTL_OBJ_CTOR_RUN (1 << 5) /**< Constructors have been called. */ /** * RTL Object. There is one for each object module loaded plus one for the base * kernel image. */ -struct rtems_rtl_obj -{ - rtems_chain_node link; /**< The node's link in the chain. */ - uint32_t flags; /**< The status of the object file. */ - size_t users; /**< Users of this object file, number of loads. */ - size_t refs; /**< References to the object file. */ - int format; /**< The format of the object file. */ - const char* fname; /**< The file name for the object. */ - const char* oname; /**< The object file name. Can be - * relative. */ - const char* aname; /**< The archive name containing the - * object. NULL means the object is not - * in a lib */ - off_t ooffset; /**< The object offset in the archive. */ - size_t fsize; /**< Size of the object file. */ - rtems_chain_control sections; /**< The sections of interest in the object - * file. */ - rtems_chain_control dependents; /**< The dependent object files. */ - rtems_rtl_obj_sym* local_table; /**< Local symbol table. */ - size_t local_syms; /**< Local symbol count. */ - size_t local_size; /**< Local symbol memory usage. */ - rtems_rtl_obj_sym* global_table; /**< Global symbol table. */ - size_t global_syms; /**< Global symbol count. */ - size_t global_size; /**< Global symbol memory usage. */ - size_t unresolved; /**< The number of unresolved relocations. */ - void* text_base; /**< The base address of the text section - * in memory. */ - size_t text_size; /**< The size of the text section. */ - void* const_base; /**< The base address of the const section - * in memory. */ - size_t const_size; /**< The size of the const section. */ - void* eh_base; /**< The base address of the eh section in - * memory. */ - size_t eh_size; /**< The size of the eh section. */ - void* data_base; /**< The base address of the data section - * in memory. */ - size_t data_size; /**< The size of the data section. */ - void* bss_base; /**< The base address of the bss section in - * memory. */ - size_t bss_size; /**< The size of the bss section. */ - size_t exec_size; /**< The amount of executable memory - * allocated */ - void* entry; /**< The entry point of the module. */ - uint32_t checksum; /**< The checksum of the text sections. A - * zero means do not checksum. */ - uint32_t* sec_num; /**< The sec nums of each obj. */ - uint32_t obj_num; /**< The count of elf files in an rtl - * obj. */ - void* tramp_base; /**< Trampoline memory. Used for fixups or - * veneers */ - size_t tramp_size; /**< Size of a trampoline memory. */ - size_t tramp_slots; /**< The number of tampoline slots. */ - size_t tramp_slot_size; /**< The number of tampoline slots. */ - void* tramp_brk; /**< Trampoline memory allocator. MD - * relocators can take memory from the - * break up to the size. */ - size_t tramp_relocs; /**< Number of slots reserved for - * relocs. The remainder are for - * unresolved symbols. */ - struct link_map* linkmap; /**< For GDB. */ - void* loader; /**< The file details specific to a - * loader. */ +struct rtems_rtl_obj { + rtems_chain_node link; /**< The node's link in the chain. */ + uint32_t flags; /**< The status of the object file. */ + size_t users; /**< Users of this object file, number of loads. */ + size_t refs; /**< References to the object file. */ + int format; /**< The format of the object file. */ + const char* fname; /**< The file name for the object. */ + const char* oname; /**< The object file name. Can be + * relative. */ + const char* aname; /**< The archive name containing the + * object. NULL means the object is not + * in a lib */ + off_t ooffset; /**< The object offset in the archive. */ + size_t fsize; /**< Size of the object file. */ + rtems_chain_control sections; /**< The sections of interest in the object + * file. */ + rtems_chain_control dependents; /**< The dependent object files. */ + rtems_rtl_obj_sym* local_table; /**< Local symbol table. */ + size_t local_syms; /**< Local symbol count. */ + size_t local_size; /**< Local symbol memory usage. */ + rtems_rtl_obj_sym* global_table; /**< Global symbol table. */ + size_t global_syms; /**< Global symbol count. */ + size_t global_size; /**< Global symbol memory usage. */ + size_t unresolved; /**< The number of unresolved relocations. */ + void* text_base; /**< The base address of the text section + * in memory. */ + size_t text_size; /**< The size of the text section. */ + void* const_base; /**< The base address of the const section + * in memory. */ + size_t const_size; /**< The size of the const section. */ + void* eh_base; /**< The base address of the eh section in + * memory. */ + size_t eh_size; /**< The size of the eh section. */ + void* data_base; /**< The base address of the data section + * in memory. */ + size_t data_size; /**< The size of the data section. */ + void* bss_base; /**< The base address of the bss section in + * memory. */ + size_t bss_size; /**< The size of the bss section. */ + size_t exec_size; /**< The amount of executable memory + * allocated */ + void* entry; /**< The entry point of the module. */ + uint32_t checksum; /**< The checksum of the text sections. A + * zero means do not checksum. */ + uint32_t* sec_num; /**< The sec nums of each obj. */ + uint32_t obj_num; /**< The count of elf files in an rtl + * obj. */ + void* tramp_base; /**< Trampoline memory. Used for fixups or + * veneers */ + size_t tramp_size; /**< Size of a trampoline memory. */ + size_t tramp_slots; /**< The number of tampoline slots. */ + size_t tramp_slot_size; /**< The number of tampoline slots. */ + void* tramp_brk; /**< Trampoline memory allocator. MD + * relocators can take memory from the + * break up to the size. */ + size_t tramp_relocs; /**< Number of slots reserved for + * relocs. The remainder are for + * unresolved symbols. */ + struct link_map* linkmap; /**< For GDB. */ + void* loader; /**< The file details specific to a + * loader. */ }; /** @@ -271,10 +276,9 @@ struct rtems_rtl_obj * @retval true The operation was successful. * @retval false The operation failed and the RTL has been set. */ -typedef bool (*rtems_rtl_obj_sect_handler)(rtems_rtl_obj* obj, - int fd, +typedef bool (*rtems_rtl_obj_sect_handler)(rtems_rtl_obj* obj, int fd, rtems_rtl_obj_sect* sect, - void* data); + void* data); /** * Get the file name. @@ -282,8 +286,7 @@ typedef bool (*rtems_rtl_obj_sect_handler)(rtems_rtl_obj* obj, * @param obj The object file. * @return const char* The string. */ -static inline const char* rtems_rtl_obj_fname (const rtems_rtl_obj* obj) -{ +static inline const char* rtems_rtl_obj_fname(const rtems_rtl_obj* obj) { return obj->fname; } @@ -293,8 +296,7 @@ static inline const char* rtems_rtl_obj_fname (const rtems_rtl_obj* obj) * @param obj The object file. * @return bool There is a file name */ -static inline bool rtems_rtl_obj_fname_valid (const rtems_rtl_obj* obj) -{ +static inline bool rtems_rtl_obj_fname_valid(const rtems_rtl_obj* obj) { return obj->fname; } @@ -304,8 +306,7 @@ static inline bool rtems_rtl_obj_fname_valid (const rtems_rtl_obj* obj) * @param obj The object file. * @return const char* The string. */ -static inline const char* rtems_rtl_obj_oname (const rtems_rtl_obj* obj) -{ +static inline const char* rtems_rtl_obj_oname(const rtems_rtl_obj* obj) { return obj->oname; } @@ -315,8 +316,7 @@ static inline const char* rtems_rtl_obj_oname (const rtems_rtl_obj* obj) * @param obj The object file. * @return bool There is an object name */ -static inline bool rtems_rtl_obj_oname_valid (const rtems_rtl_obj* obj) -{ +static inline bool rtems_rtl_obj_oname_valid(const rtems_rtl_obj* obj) { return obj->oname; } @@ -326,8 +326,7 @@ static inline bool rtems_rtl_obj_oname_valid (const rtems_rtl_obj* obj) * @param obj The object file. * @return const char* The string. */ -static inline const char* rtems_rtl_obj_aname (const rtems_rtl_obj* obj) -{ +static inline const char* rtems_rtl_obj_aname(const rtems_rtl_obj* obj) { return obj->aname; } @@ -337,8 +336,7 @@ static inline const char* rtems_rtl_obj_aname (const rtems_rtl_obj* obj) * @param obj The object file. * @return bool There is an archive name */ -static inline bool rtems_rtl_obj_aname_valid (const rtems_rtl_obj* obj) -{ +static inline bool rtems_rtl_obj_aname_valid(const rtems_rtl_obj* obj) { return obj->aname; } @@ -348,12 +346,10 @@ static inline bool rtems_rtl_obj_aname_valid (const rtems_rtl_obj* obj) * @param obj The object file. * @return bool There is an archive name */ -static inline bool rtems_rtl_obj_text_inside (const rtems_rtl_obj* obj, - const void* address) -{ - return - (address >= obj->text_base) && - ((char*) address < ((char*) obj->text_base + obj->text_size)); +static inline bool rtems_rtl_obj_text_inside(const rtems_rtl_obj* obj, + const void* address) { + return (address >= obj->text_base) && + ((char*)address < ((char*)obj->text_base + obj->text_size)); } /** @@ -365,9 +361,7 @@ static inline bool rtems_rtl_obj_text_inside (const rtems_rtl_obj* obj, * @param alignment The alignment. * @return size_t Aligned offset. */ -static inline size_t rtems_rtl_obj_align (size_t offset, - uint32_t alignment) -{ +static inline size_t rtems_rtl_obj_align(size_t offset, uint32_t alignment) { if ((alignment > 1) && ((offset & (alignment - 1)) != 0)) offset = (offset + alignment) & ~(alignment - 1); return offset; @@ -380,9 +374,8 @@ static inline size_t rtems_rtl_obj_align (size_t offset, * @param sym The symbol to check. * @retval bool Returns @true if present else @false is returned. */ -static inline bool rtems_rtl_obj_has_symbol (const rtems_rtl_obj* obj, - const rtems_rtl_obj_sym* sym) -{ +static inline bool rtems_rtl_obj_has_symbol(const rtems_rtl_obj* obj, + const rtems_rtl_obj_sym* sym) { return (sym >= obj->global_table && sym < (obj->global_table + obj->global_syms)); } @@ -393,8 +386,7 @@ static inline bool rtems_rtl_obj_has_symbol (const rtems_rtl_obj* obj, * @param obj The object file's descriptor to check for available space. * @retval bool Returns @true if the object file has trampolines */ -static inline size_t rtems_rtl_obj_has_trampolines (const rtems_rtl_obj* obj) -{ +static inline size_t rtems_rtl_obj_has_trampolines(const rtems_rtl_obj* obj) { return obj->tramp_slot_size != 0 && obj->tramp_slots != 0; } @@ -405,9 +397,8 @@ static inline size_t rtems_rtl_obj_has_trampolines (const rtems_rtl_obj* obj) * @param size The size to be allocated. * @retval bool Returns @true if the space is available. */ -static inline size_t rtems_rtl_obj_tramp_avail_space (const rtems_rtl_obj* obj) -{ - return (char*) obj->tramp_brk - (char*) obj->tramp_base; +static inline size_t rtems_rtl_obj_tramp_avail_space(const rtems_rtl_obj* obj) { + return (char*)obj->tramp_brk - (char*)obj->tramp_base; } /** @@ -417,11 +408,10 @@ static inline size_t rtems_rtl_obj_tramp_avail_space (const rtems_rtl_obj* obj) * @param size The size to be allocated. * @retval bool Returns @true if the space is available. */ -static inline bool rtems_rtl_obj_has_tramp_space (const rtems_rtl_obj* obj, - const size_t size) -{ +static inline bool rtems_rtl_obj_has_tramp_space(const rtems_rtl_obj* obj, + const size_t size) { return (obj->tramp_base != NULL && - (rtems_rtl_obj_tramp_avail_space (obj) + size) <= obj->tramp_size); + (rtems_rtl_obj_tramp_avail_space(obj) + size) <= obj->tramp_size); } /** @@ -430,8 +420,7 @@ static inline bool rtems_rtl_obj_has_tramp_space (const rtems_rtl_obj* obj, * @param obj The object file's descriptor. * @retval size_t The number of trampoline slots. */ -static inline size_t rtems_rtl_obj_trampoline_slots (const rtems_rtl_obj* obj) -{ +static inline size_t rtems_rtl_obj_trampoline_slots(const rtems_rtl_obj* obj) { return obj->tramp_slots; } @@ -441,10 +430,10 @@ static inline size_t rtems_rtl_obj_trampoline_slots (const rtems_rtl_obj* obj) * @param obj The object file's descriptor. * @retval size_t The number of trampoline slots available. */ -static inline size_t rtems_rtl_obj_trampolines (const rtems_rtl_obj* obj) -{ - return obj->tramp_base == NULL || obj->tramp_slots == 0 ? - 0 : rtems_rtl_obj_tramp_avail_space (obj) / obj->tramp_slot_size; +static inline size_t rtems_rtl_obj_trampolines(const rtems_rtl_obj* obj) { + return obj->tramp_base == NULL || obj->tramp_slots == 0 + ? 0 + : rtems_rtl_obj_tramp_avail_space(obj) / obj->tramp_slot_size; } /** @@ -453,8 +442,7 @@ static inline size_t rtems_rtl_obj_trampolines (const rtems_rtl_obj* obj) * @param sect The section. * @retval bool Returns @true if the section requires arch allocation. */ -static inline bool rtems_rtl_obj_sect_is_arch_alloc (rtems_rtl_obj_sect* sect) -{ +static inline bool rtems_rtl_obj_sect_is_arch_alloc(rtems_rtl_obj_sect* sect) { return (sect->flags & RTEMS_RTL_OBJ_SECT_ARCH_ALLOC) != 0; } @@ -463,7 +451,7 @@ static inline bool rtems_rtl_obj_sect_is_arch_alloc (rtems_rtl_obj_sect* sect) * * @retval NULL No memory for the object. */ -rtems_rtl_obj* rtems_rtl_obj_alloc (void); +rtems_rtl_obj* rtems_rtl_obj_alloc(void); /** * Free the object structure and related resources. @@ -472,7 +460,7 @@ rtems_rtl_obj* rtems_rtl_obj_alloc (void); * @retval false The object has dependences. * @retval true The object has been freed. */ -bool rtems_rtl_obj_free (rtems_rtl_obj* obj); +bool rtems_rtl_obj_free(rtems_rtl_obj* obj); /** * Does the object file have unresolved external references ? If it does the @@ -482,7 +470,7 @@ bool rtems_rtl_obj_free (rtems_rtl_obj* obj); * @retval true The object file has unresolved externals. * @retval false The object file has all external references resolved. */ -bool rtems_rtl_obj_unresolved (rtems_rtl_obj* obj); +bool rtems_rtl_obj_unresolved(rtems_rtl_obj* obj); /** * Parses a filename and returns newly allocated strings with the archive name, @@ -495,10 +483,8 @@ bool rtems_rtl_obj_unresolved (rtems_rtl_obj* obj); * @retval true The parsing was successful * @retval false The parsing was unsuccessful */ -bool rtems_rtl_parse_name (const char* name, - const char** aname, - const char** oname, - off_t* ooffset); +bool rtems_rtl_parse_name(const char* name, const char** aname, + const char** oname, off_t* ooffset); /** * Find an object file on disk that matches the name. The object descriptor is @@ -510,7 +496,7 @@ bool rtems_rtl_parse_name (const char* name, * @retval true The file has been found. * @retval false The file could not be located. The RTL error has been set. */ -bool rtems_rtl_obj_find_file (rtems_rtl_obj* obj, const char* name); +bool rtems_rtl_obj_find_file(rtems_rtl_obj* obj, const char* name); /** * Add a section to the object descriptor. @@ -527,22 +513,17 @@ bool rtems_rtl_obj_find_file (rtems_rtl_obj* obj, const char* name); * @retval true The section has been added. * @retval false The section has not been added. See the RTL error. */ -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); +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); /** * Erase the object file descriptor's sections. * * @param obj The object file's descriptor. */ -void rtems_rtl_obj_erase_sections (rtems_rtl_obj* obj); +void rtems_rtl_obj_erase_sections(rtems_rtl_obj* obj); /** * Find the section given a name. @@ -552,8 +533,8 @@ void rtems_rtl_obj_erase_sections (rtems_rtl_obj* obj); * @retval NULL The section was not found. * @return rtems_rtl_obj_sect_t* The named section. */ -rtems_rtl_obj_sect* rtems_rtl_obj_find_section (const rtems_rtl_obj* obj, - const char* name); +rtems_rtl_obj_sect* rtems_rtl_obj_find_section(const rtems_rtl_obj* obj, + const char* name); /** * Find a section given a section's index number. @@ -563,8 +544,8 @@ rtems_rtl_obj_sect* rtems_rtl_obj_find_section (const rtems_rtl_obj* obj, * @retval NULL The section was not found. * @return rtems_rtl_obj_sect_t* The found section. */ -rtems_rtl_obj_sect* rtems_rtl_obj_find_section_by_index (const rtems_rtl_obj* obj, - int index); +rtems_rtl_obj_sect* +rtems_rtl_obj_find_section_by_index(const rtems_rtl_obj* obj, int index); /** * Find a section given a section's mask. The index is the section after which @@ -578,9 +559,9 @@ rtems_rtl_obj_sect* rtems_rtl_obj_find_section_by_index (const rtems_rtl_obj* ob * @retval NULL The section was not found. * @return rtems_rtl_obj_sect_t* The found section. */ -rtems_rtl_obj_sect* rtems_rtl_obj_find_section_by_mask (const rtems_rtl_obj* obj, - int index, - uint32_t mask); +rtems_rtl_obj_sect* rtems_rtl_obj_find_section_by_mask(const rtems_rtl_obj* obj, + int index, + uint32_t mask); /** * Allocate a table for dependent objects. @@ -590,14 +571,14 @@ rtems_rtl_obj_sect* rtems_rtl_obj_find_section_by_mask (const rtems_rtl_obj* obj * @retval true The table was allocated. * @retval false The alloction failed. */ -bool rtems_rtl_obj_alloc_dependents (rtems_rtl_obj* obj, size_t dependents); +bool rtems_rtl_obj_alloc_dependents(rtems_rtl_obj* obj, size_t dependents); /** * Erase the object file descriptor's dependents. * * @param obj The object file's descriptor. */ -void rtems_rtl_obj_erase_dependents (rtems_rtl_obj* obj); +void rtems_rtl_obj_erase_dependents(rtems_rtl_obj* obj); /** * Add an object file to the dependents table. @@ -607,7 +588,7 @@ void rtems_rtl_obj_erase_dependents (rtems_rtl_obj* obj); * @retval true The dependent has been added to the table. * @retval false There is no space in the table. */ -bool rtems_rtl_obj_add_dependent (rtems_rtl_obj* obj, rtems_rtl_obj* dependent); +bool rtems_rtl_obj_add_dependent(rtems_rtl_obj* obj, rtems_rtl_obj* dependent); /** * Remove dependencies. This decrements the dependent object file references. @@ -616,7 +597,7 @@ bool rtems_rtl_obj_add_dependent (rtems_rtl_obj* obj, rtems_rtl_obj* dependent); * @retval true The dependencies have been removed. * @retval false There is no space in the table. */ -bool rtems_rtl_obj_remove_dependencies (rtems_rtl_obj* obj); +bool rtems_rtl_obj_remove_dependencies(rtems_rtl_obj* obj); /** * Iterate over the module dependenices. @@ -627,9 +608,9 @@ bool rtems_rtl_obj_remove_dependencies (rtems_rtl_obj* obj); * @retval true The iterator handler returned true. * @retval false The iterator handler returned false. */ -bool rtems_rtl_obj_iterate_dependents (rtems_rtl_obj* obj, - rtems_rtl_obj_depends_iterator iterator, - void* data); +bool rtems_rtl_obj_iterate_dependents(rtems_rtl_obj* obj, + rtems_rtl_obj_depends_iterator iterator, + void* data); /** * The text section size. Only use once all the sections has been added. It @@ -639,7 +620,7 @@ bool rtems_rtl_obj_iterate_dependents (rtems_rtl_obj* obj, * @param obj The object file's descriptor. * @return size_t The size of the text area of the object file. */ -size_t rtems_rtl_obj_text_size (const rtems_rtl_obj* obj); +size_t rtems_rtl_obj_text_size(const rtems_rtl_obj* obj); /** * The text section alignment for the object file. Only use once all the @@ -650,9 +631,10 @@ size_t rtems_rtl_obj_text_size (const rtems_rtl_obj* obj); * 1. If 0 or 1 then there is no alignment. * * @param obj The object file's descriptor. - * @return uint32_t The alignment. Can be 0 or 1 for not aligned or the alignment. + * @return uint32_t The alignment. Can be 0 or 1 for not aligned or the + * alignment. */ -uint32_t rtems_rtl_obj_text_alignment (const rtems_rtl_obj* obj); +uint32_t rtems_rtl_obj_text_alignment(const rtems_rtl_obj* obj); /** * The const section size. Only use once all the sections has been added. It @@ -662,7 +644,7 @@ uint32_t rtems_rtl_obj_text_alignment (const rtems_rtl_obj* obj); * @param obj The object file's descriptor. * @return size_t The size of the const area of the object file. */ -size_t rtems_rtl_obj_const_size (const rtems_rtl_obj* obj); +size_t rtems_rtl_obj_const_size(const rtems_rtl_obj* obj); /** * The const section alignment for the object file. Only use once all the @@ -673,9 +655,10 @@ size_t rtems_rtl_obj_const_size (const rtems_rtl_obj* obj); * 1. If 0 or 1 then there is no alignment. * * @param obj The object file's descriptor. - * @return uint32_t The alignment. Can be 0 or 1 for not aligned or the alignment. + * @return uint32_t The alignment. Can be 0 or 1 for not aligned or the + * alignment. */ -uint32_t rtems_rtl_obj_const_alignment (const rtems_rtl_obj* obj); +uint32_t rtems_rtl_obj_const_alignment(const rtems_rtl_obj* obj); /** * The eh section size. Only use once all the sections has been added. It @@ -684,7 +667,7 @@ uint32_t rtems_rtl_obj_const_alignment (const rtems_rtl_obj* obj); * @param obj The object file's descriptor. * @return size_t The size of the bss area of the object file. */ -size_t rtems_rtl_obj_eh_size (const rtems_rtl_obj* obj); +size_t rtems_rtl_obj_eh_size(const rtems_rtl_obj* obj); /** * The eh section alignment for the object file. Only use once all the sections @@ -695,9 +678,10 @@ size_t rtems_rtl_obj_eh_size (const rtems_rtl_obj* obj); * 1. If 0 or 1 then there is no alignment. * * @param obj The object file's descriptor. - * @return uint32_t The alignment. Can be 0 or 1 for not aligned or the alignment. + * @return uint32_t The alignment. Can be 0 or 1 for not aligned or the + * alignment. */ -uint32_t rtems_rtl_obj_eh_alignment (const rtems_rtl_obj* obj); +uint32_t rtems_rtl_obj_eh_alignment(const rtems_rtl_obj* obj); /** * The data section size. Only use once all the sections has been added. It @@ -707,7 +691,7 @@ uint32_t rtems_rtl_obj_eh_alignment (const rtems_rtl_obj* obj); * @param obj The object file's descriptor. * @return size_t The size of the data area of the object file. */ -size_t rtems_rtl_obj_data_size (const rtems_rtl_obj* obj); +size_t rtems_rtl_obj_data_size(const rtems_rtl_obj* obj); /** * The data section alignment for the object file. Only use once all the @@ -718,9 +702,10 @@ size_t rtems_rtl_obj_data_size (const rtems_rtl_obj* obj); * 1. If 0 or 1 then there is no alignment. * * @param obj The object file's descriptor. - * @return uint32_t The alignment. Can be 0 or 1 for not aligned or the alignment. + * @return uint32_t The alignment. Can be 0 or 1 for not aligned or the + * alignment. */ -uint32_t rtems_rtl_obj_data_alignment (const rtems_rtl_obj* obj); +uint32_t rtems_rtl_obj_data_alignment(const rtems_rtl_obj* obj); /** * The bss section size. Only use once all the sections has been added. It @@ -729,7 +714,7 @@ uint32_t rtems_rtl_obj_data_alignment (const rtems_rtl_obj* obj); * @param obj The object file's descriptor. * @return size_t The size of the bss area of the object file. */ -size_t rtems_rtl_obj_bss_size (const rtems_rtl_obj* obj); +size_t rtems_rtl_obj_bss_size(const rtems_rtl_obj* obj); /** * The bss section alignment for the object file. Only use once all the @@ -740,9 +725,10 @@ size_t rtems_rtl_obj_bss_size (const rtems_rtl_obj* obj); * 1. If 0 or 1 then there is no alignment. * * @param obj The object file's descriptor. - * @return uint32_t The alignment. Can be 0 or 1 for not aligned or the alignment. + * @return uint32_t The alignment. Can be 0 or 1 for not aligned or the + * alignment. */ -uint32_t rtems_rtl_obj_bss_alignment (const rtems_rtl_obj* obj); +uint32_t rtems_rtl_obj_bss_alignment(const rtems_rtl_obj* obj); /** * The trampoline size. @@ -750,7 +736,7 @@ uint32_t rtems_rtl_obj_bss_alignment (const rtems_rtl_obj* obj); * @param obj The object file's descriptor. * @return size_t The size of the trampoline memory of the object file. */ -size_t rtems_rtl_obj_tramp_size (const rtems_rtl_obj* obj); +size_t rtems_rtl_obj_tramp_size(const rtems_rtl_obj* obj); /** * The trampolinme alignment for the architecture. @@ -758,9 +744,10 @@ size_t rtems_rtl_obj_tramp_size (const rtems_rtl_obj* obj); * This is implemented and set in the architecture backend. * * @param obj The object file's descriptor. - * @return uint32_t The alignment. Can be 0 or 1 for not aligned or the alignment. + * @return uint32_t The alignment. Can be 0 or 1 for not aligned or the + * alignment. */ -uint32_t rtems_rtl_obj_tramp_alignment (const rtems_rtl_obj* obj); +uint32_t rtems_rtl_obj_tramp_alignment(const rtems_rtl_obj* obj); /** * Relocate the object file. The object file's section are parsed for any @@ -773,17 +760,15 @@ uint32_t rtems_rtl_obj_tramp_alignment (const rtems_rtl_obj* obj); * @retval true The object file was relocated. * @retval false The relocation failed. The RTL error is set. */ -bool rtems_rtl_obj_relocate (rtems_rtl_obj* obj, - int fd, - rtems_rtl_obj_sect_handler handler, - void* data); +bool rtems_rtl_obj_relocate(rtems_rtl_obj* obj, int fd, + rtems_rtl_obj_sect_handler handler, void* data); /** * Synchronize caches to make code visible to CPU(s) * * @param obj The object file's descriptor. */ -void rtems_rtl_obj_synchronize_cache (rtems_rtl_obj* obj); +void rtems_rtl_obj_synchronize_cache(rtems_rtl_obj* obj); /** * Relocate an object file's unresolved reference. @@ -793,8 +778,8 @@ void rtems_rtl_obj_synchronize_cache (rtems_rtl_obj* obj); * @retval true The object file record was relocated. * @retval false The relocation failed. The RTL error is set. */ -bool rtems_rtl_obj_relocate_unresolved (rtems_rtl_unresolv_reloc* reloc, - rtems_rtl_obj_sym* sym); +bool rtems_rtl_obj_relocate_unresolved(rtems_rtl_unresolv_reloc* reloc, + rtems_rtl_obj_sym* sym); /** * Load the symbols from the object file. Only the exported or public symbols @@ -807,10 +792,8 @@ bool rtems_rtl_obj_relocate_unresolved (rtems_rtl_unresolv_reloc* reloc, * @retval true The object file's symbol where loaded. * @retval false The symbol loading failed. The RTL error is set. */ -bool rtems_rtl_obj_load_symbols (rtems_rtl_obj* obj, - int fd, - rtems_rtl_obj_sect_handler handler, - void* data); +bool rtems_rtl_obj_load_symbols(rtems_rtl_obj* obj, int fd, + rtems_rtl_obj_sect_handler handler, void* data); /** * Allocate the sections. If a handler is provided (not NULL) it is called for @@ -823,10 +806,9 @@ bool rtems_rtl_obj_load_symbols (rtems_rtl_obj* obj, * @retval true The object has been sucessfully loaded. * @retval false The load failed. The RTL error has been set. */ -bool rtems_rtl_obj_alloc_sections (rtems_rtl_obj* obj, - int fd, - rtems_rtl_obj_sect_handler handler, - void* data); +bool rtems_rtl_obj_alloc_sections(rtems_rtl_obj* obj, int fd, + rtems_rtl_obj_sect_handler handler, + void* data); /** * Resize the sections. @@ -835,7 +817,7 @@ bool rtems_rtl_obj_alloc_sections (rtems_rtl_obj* obj, * @retval true The object has been sucessfully loaded. * @retval false The load failed. The RTL error has been set. */ -bool rtems_rtl_obj_resize_sections (rtems_rtl_obj* obj); +bool rtems_rtl_obj_resize_sections(rtems_rtl_obj* obj); /** * Load the sections that have been allocated memory in the target. The bss @@ -849,17 +831,16 @@ bool rtems_rtl_obj_resize_sections (rtems_rtl_obj* obj); * @retval true The object has been sucessfully loaded. * @retval false The load failed. The RTL error has been set. */ -bool rtems_rtl_obj_load_sections (rtems_rtl_obj* obj, - int fd, - rtems_rtl_obj_sect_handler handler, - void* data); +bool rtems_rtl_obj_load_sections(rtems_rtl_obj* obj, int fd, + rtems_rtl_obj_sect_handler handler, + void* data); /** * Does the object have constructors to run? * * @return bool True if there are constructors to run. */ -bool rtems_rtl_obj_ctors_to_run (rtems_rtl_obj* obj); +bool rtems_rtl_obj_ctors_to_run(rtems_rtl_obj* obj); /** * Invoke the constructors the object has. Constructors are a table of pointers @@ -869,14 +850,14 @@ bool rtems_rtl_obj_ctors_to_run (rtems_rtl_obj* obj); * * @param obj The object file's descriptor. */ -void rtems_rtl_obj_run_ctors (rtems_rtl_obj* obj); +void rtems_rtl_obj_run_ctors(rtems_rtl_obj* obj); /** * Does the object have destructors to run? * * @return bool True if there are destructors to run. */ -bool rtems_rtl_obj_dtors_to_run (rtems_rtl_obj* obj); +bool rtems_rtl_obj_dtors_to_run(rtems_rtl_obj* obj); /** * Invoke the destructors the object has. Destructors are a table of pointers @@ -886,28 +867,28 @@ bool rtems_rtl_obj_dtors_to_run (rtems_rtl_obj* obj); * * @param obj The object file's descriptor. */ -void rtems_rtl_obj_run_dtors (rtems_rtl_obj* obj); +void rtems_rtl_obj_run_dtors(rtems_rtl_obj* obj); /** * Get the object file reference count. * * @retval int The object file's reference count. */ -size_t rtems_rtl_obj_get_reference (rtems_rtl_obj* obj); +size_t rtems_rtl_obj_get_reference(rtems_rtl_obj* obj); /** * Increment the object file reference count. * * @param obj The object file's descriptor. */ -void rtems_rtl_obj_inc_reference (rtems_rtl_obj* obj); +void rtems_rtl_obj_inc_reference(rtems_rtl_obj* obj); /** * Decrement the object file reference count. * * @param obj The object file's descriptor. */ -void rtems_rtl_obj_dec_reference (rtems_rtl_obj* obj); +void rtems_rtl_obj_dec_reference(rtems_rtl_obj* obj); /** * Is the object file orphaned? An orphaned object file is not locked, has no @@ -915,7 +896,7 @@ void rtems_rtl_obj_dec_reference (rtems_rtl_obj* obj); * * @param obj The object file's descriptor. */ -bool rtems_rtl_obj_orphaned (rtems_rtl_obj* obj); +bool rtems_rtl_obj_orphaned(rtems_rtl_obj* obj); /** * Load the object file, reading all sections into memory, symbols and @@ -925,7 +906,7 @@ bool rtems_rtl_obj_orphaned (rtems_rtl_obj* obj); * @retval true The object file has been loaded. * @retval false The load failed. The RTL error has been set. */ -bool rtems_rtl_obj_load (rtems_rtl_obj* obj); +bool rtems_rtl_obj_load(rtems_rtl_obj* obj); /** * Unload the object file, erasing all symbols and releasing all memory. @@ -934,7 +915,7 @@ bool rtems_rtl_obj_load (rtems_rtl_obj* obj); * @retval true The object file has been unloaded. * @retval false The unload failed. The RTL error has been set. */ -bool rtems_rtl_obj_unload (rtems_rtl_obj* obj); +bool rtems_rtl_obj_unload(rtems_rtl_obj* obj); #ifdef __cplusplus } diff --git a/cpukit/include/rtems/rtl/rtl-shell.h b/cpukit/include/rtems/rtl/rtl-shell.h index 9fcf476138..3442c9903a 100644 --- a/cpukit/include/rtems/rtl/rtl-shell.h +++ b/cpukit/include/rtems/rtl/rtl-shell.h @@ -32,7 +32,7 @@ * @brief RTEMS Run-Time Linker ELF Shell Support. */ -#if !defined (_RTEMS_RTL_SHELL_H_) +#if !defined(_RTEMS_RTL_SHELL_H_) #define _RTEMS_RTL_SHELL_H_ #include @@ -49,33 +49,34 @@ extern "C" { * @retval 0 No error. * @return int The exit code. */ -int rtems_rtl_shell_command (int argc, char* argv[]); +int rtems_rtl_shell_command(int argc, char* argv[]); /** * List object files. */ -int rtems_rtl_shell_list (const rtems_printer* printer, int argc, char* argv[]); +int rtems_rtl_shell_list(const rtems_printer* printer, int argc, char* argv[]); /** * Symbols. */ -int rtems_rtl_shell_sym (const rtems_printer* printer, int argc, char* argv[]); +int rtems_rtl_shell_sym(const rtems_printer* printer, int argc, char* argv[]); /** * Object files. */ -int rtems_rtl_shell_object (const rtems_printer* printer, int argc, char* argv[]); - +int rtems_rtl_shell_object(const rtems_printer* printer, int argc, + char* argv[]); /** * Archive files. */ -int rtems_rtl_shell_archive (const rtems_printer* printer, int argc, char* argv[]); +int rtems_rtl_shell_archive(const rtems_printer* printer, int argc, + char* argv[]); /** * Call text symbol. */ -int rtems_rtl_shell_call (const rtems_printer* printer, int argc, char* argv[]); +int rtems_rtl_shell_call(const rtems_printer* printer, int argc, char* argv[]); #ifdef __cplusplus } diff --git a/cpukit/include/rtems/rtl/rtl-sym.h b/cpukit/include/rtems/rtl/rtl-sym.h index 7c5bc1b15f..cb630baa71 100644 --- a/cpukit/include/rtems/rtl/rtl-sym.h +++ b/cpukit/include/rtems/rtl/rtl-sym.h @@ -32,11 +32,11 @@ * @brief RTEMS Run-Time Linker Object File Symbol Table. */ -#if !defined (_RTEMS_RTL_SYM_H_) +#if !defined(_RTEMS_RTL_SYM_H_) #define _RTEMS_RTL_SYM_H_ -#include #include "rtl-obj-fwd.h" +#include #ifdef __cplusplus extern "C" { @@ -45,21 +45,19 @@ extern "C" { /** * An object file symbol. */ -typedef struct rtems_rtl_obj_sym -{ - rtems_chain_node node; /**< The node's link in the chain. */ - const char* name; /**< The symbol's name. */ - void* value; /**< The value of the symbol. */ - uint32_t data; /**< Format specific data. */ +typedef struct rtems_rtl_obj_sym { + rtems_chain_node node; /**< The node's link in the chain. */ + const char* name; /**< The symbol's name. */ + void* value; /**< The value of the symbol. */ + uint32_t data; /**< Format specific data. */ } rtems_rtl_obj_sym; /** * Table of symbols stored in a hash table. */ -typedef struct rtems_rtl_symbols -{ +typedef struct rtems_rtl_symbols { rtems_chain_control* buckets; - size_t nbuckets; + size_t nbuckets; } rtems_rtl_symbols; /** @@ -72,9 +70,8 @@ typedef size_t (*rtems_rtl_tls_offset_func)(void); * A TLS symbol offset entry. It is used with an exported symbol table * to find a TSL table offset for a variable at runtime. */ -typedef struct rtems_rtl_tls_offset -{ - size_t index; /** exported symbol table index */ +typedef struct rtems_rtl_tls_offset { + size_t index; /** exported symbol table index */ rtems_rtl_tls_offset_func offset; /** TLS offset function */ } rtems_rtl_tls_offset; @@ -87,15 +84,14 @@ typedef struct rtems_rtl_tls_offset * @retval false The symbol table could not created. The RTL * error has the error. */ -bool rtems_rtl_symbol_table_open (rtems_rtl_symbols* symbols, - size_t buckets); +bool rtems_rtl_symbol_table_open(rtems_rtl_symbols* symbols, size_t buckets); /** * Close the table and erase the hash table. * * @param symbols Close the symbol table. */ -void rtems_rtl_symbol_table_close (rtems_rtl_symbols* symbols); +void rtems_rtl_symbol_table_close(rtems_rtl_symbols* symbols); /** * Insert a symbol into a symbol table. @@ -103,8 +99,8 @@ void rtems_rtl_symbol_table_close (rtems_rtl_symbols* symbols); * @param symbols Symbol table * @param symbols Symbol to add */ -void rtems_rtl_symbol_global_insert (rtems_rtl_symbols* symbols, - rtems_rtl_obj_sym* symbol); +void rtems_rtl_symbol_global_insert(rtems_rtl_symbols* symbols, + rtems_rtl_obj_sym* symbol); /** * Add a table of exported symbols to the symbol table. @@ -129,11 +125,10 @@ void rtems_rtl_symbol_global_insert (rtems_rtl_symbols* symbols, * @param tls_offsets The TLS offsets table. If NULL none provided. * @param tls_size The number TLS offset entries in the table. */ -bool rtems_rtl_symbol_global_add (rtems_rtl_obj* obj, - const unsigned char* esyms, - unsigned int size, - const rtems_rtl_tls_offset* tls_offsets, - unsigned int tls_size); +bool rtems_rtl_symbol_global_add(rtems_rtl_obj* obj, const unsigned char* esyms, + unsigned int size, + const rtems_rtl_tls_offset* tls_offsets, + unsigned int tls_size); /** * Find a symbol given the symbol label in the global symbol table. @@ -142,7 +137,7 @@ bool rtems_rtl_symbol_global_add (rtems_rtl_obj* obj, * @retval NULL No symbol found. * @return rtems_rtl_obj_sym* Reference to the symbol. */ -rtems_rtl_obj_sym* rtems_rtl_symbol_global_find (const char* name); +rtems_rtl_obj_sym* rtems_rtl_symbol_global_find(const char* name); /** * Sort an object file's local and global symbol table. This needs to @@ -151,7 +146,7 @@ rtems_rtl_obj_sym* rtems_rtl_symbol_global_find (const char* name); * * @param obj The object file to sort. */ -void rtems_rtl_symbol_obj_sort (rtems_rtl_obj* obj); +void rtems_rtl_symbol_obj_sort(rtems_rtl_obj* obj); /** * Find a symbol given the symbol label in the local object file. @@ -161,29 +156,29 @@ void rtems_rtl_symbol_obj_sort (rtems_rtl_obj* obj); * @retval NULL No symbol found. * @return rtems_rtl_obj_sym* Reference to the symbol. */ -rtems_rtl_obj_sym* rtems_rtl_symbol_obj_find (rtems_rtl_obj* obj, - const char* name); +rtems_rtl_obj_sym* rtems_rtl_symbol_obj_find(rtems_rtl_obj* obj, + const char* name); /** * Add the object file's symbols to the global table. * * @param obj The object file the symbols are to be added. */ -void rtems_rtl_symbol_obj_add (rtems_rtl_obj* obj); +void rtems_rtl_symbol_obj_add(rtems_rtl_obj* obj); /** * Erase the object file's local symbols. * * @param obj The object file the local symbols are to be erased from. */ -void rtems_rtl_symbol_obj_erase_local (rtems_rtl_obj* obj); +void rtems_rtl_symbol_obj_erase_local(rtems_rtl_obj* obj); /** * Erase the object file's symbols. * * @param obj The object file the symbols are to be erased from. */ -void rtems_rtl_symbol_obj_erase (rtems_rtl_obj* obj); +void rtems_rtl_symbol_obj_erase(rtems_rtl_obj* obj); #ifdef __cplusplus } diff --git a/cpukit/include/rtems/rtl/rtl-trace.h b/cpukit/include/rtems/rtl/rtl-trace.h index 9f99c78ad9..bdb36252cb 100644 --- a/cpukit/include/rtems/rtl/rtl-trace.h +++ b/cpukit/include/rtems/rtl/rtl-trace.h @@ -32,7 +32,7 @@ * @brief RTEMS Run-Time Linker ELF Trace Support. */ -#if !defined (_RTEMS_RTL_TRACE_H_) +#if !defined(_RTEMS_RTL_TRACE_H_) #define _RTEMS_RTL_TRACE_H_ #ifdef __cplusplus @@ -57,27 +57,27 @@ typedef uint32_t rtems_rtl_trace_mask; /** * List of tracing bits for the various parts of the link editor. */ -#define RTEMS_RTL_TRACE_DETAIL (1UL << 0) -#define RTEMS_RTL_TRACE_WARNING (1UL << 1) -#define RTEMS_RTL_TRACE_LOAD (1UL << 2) -#define RTEMS_RTL_TRACE_UNLOAD (1UL << 3) -#define RTEMS_RTL_TRACE_SECTION (1UL << 4) -#define RTEMS_RTL_TRACE_SYMBOL (1UL << 5) -#define RTEMS_RTL_TRACE_RELOC (1UL << 6) -#define RTEMS_RTL_TRACE_GLOBAL_SYM (1UL << 7) -#define RTEMS_RTL_TRACE_LOAD_SECT (1UL << 8) -#define RTEMS_RTL_TRACE_ALLOCATOR (1UL << 9) -#define RTEMS_RTL_TRACE_UNRESOLVED (1UL << 10) -#define RTEMS_RTL_TRACE_CACHE (1UL << 11) -#define RTEMS_RTL_TRACE_ARCHIVES (1UL << 12) -#define RTEMS_RTL_TRACE_ARCHIVE_SYMS (1UL << 13) -#define RTEMS_RTL_TRACE_DEPENDENCY (1UL << 14) -#define RTEMS_RTL_TRACE_BIT_ALLOC (1UL << 15) -#define RTEMS_RTL_TRACE_COMP (1UL << 16) -#define RTEMS_RTL_TRACE_ALL (0xffffffffUL & ~(RTEMS_RTL_TRACE_CACHE | \ - RTEMS_RTL_TRACE_COMP | \ - RTEMS_RTL_TRACE_GLOBAL_SYM | \ - RTEMS_RTL_TRACE_ARCHIVE_SYMS)) +#define RTEMS_RTL_TRACE_DETAIL (1UL << 0) +#define RTEMS_RTL_TRACE_WARNING (1UL << 1) +#define RTEMS_RTL_TRACE_LOAD (1UL << 2) +#define RTEMS_RTL_TRACE_UNLOAD (1UL << 3) +#define RTEMS_RTL_TRACE_SECTION (1UL << 4) +#define RTEMS_RTL_TRACE_SYMBOL (1UL << 5) +#define RTEMS_RTL_TRACE_RELOC (1UL << 6) +#define RTEMS_RTL_TRACE_GLOBAL_SYM (1UL << 7) +#define RTEMS_RTL_TRACE_LOAD_SECT (1UL << 8) +#define RTEMS_RTL_TRACE_ALLOCATOR (1UL << 9) +#define RTEMS_RTL_TRACE_UNRESOLVED (1UL << 10) +#define RTEMS_RTL_TRACE_CACHE (1UL << 11) +#define RTEMS_RTL_TRACE_ARCHIVES (1UL << 12) +#define RTEMS_RTL_TRACE_ARCHIVE_SYMS (1UL << 13) +#define RTEMS_RTL_TRACE_DEPENDENCY (1UL << 14) +#define RTEMS_RTL_TRACE_BIT_ALLOC (1UL << 15) +#define RTEMS_RTL_TRACE_COMP (1UL << 16) +#define RTEMS_RTL_TRACE_ALL \ + (0xffffffffUL & \ + ~(RTEMS_RTL_TRACE_CACHE | RTEMS_RTL_TRACE_COMP | \ + RTEMS_RTL_TRACE_GLOBAL_SYM | RTEMS_RTL_TRACE_ARCHIVE_SYMS)) /** * Call to check if this part is bring traced. If RTEMS_RTL_TRACE is defined to @@ -88,7 +88,7 @@ typedef uint32_t rtems_rtl_trace_mask; * @retval false Do not trace. */ #if RTEMS_RTL_TRACE -bool rtems_rtl_trace (rtems_rtl_trace_mask mask); +bool rtems_rtl_trace(rtems_rtl_trace_mask mask); #else #define rtems_rtl_trace(_m) (0) #endif @@ -100,7 +100,7 @@ bool rtems_rtl_trace (rtems_rtl_trace_mask mask); * @return The previous mask. */ #if RTEMS_RTL_TRACE -rtems_rtl_trace_mask rtems_rtl_trace_set_mask (rtems_rtl_trace_mask mask); +rtems_rtl_trace_mask rtems_rtl_trace_set_mask(rtems_rtl_trace_mask mask); #else #define rtems_rtl_trace_set_mask(_m) #endif @@ -112,7 +112,7 @@ rtems_rtl_trace_mask rtems_rtl_trace_set_mask (rtems_rtl_trace_mask mask); * @return The previous mask. */ #if RTEMS_RTL_TRACE -rtems_rtl_trace_mask rtems_rtl_trace_clear_mask (rtems_rtl_trace_mask mask); +rtems_rtl_trace_mask rtems_rtl_trace_clear_mask(rtems_rtl_trace_mask mask); #else #define rtems_rtl_trace_clear_mask(_m) #endif @@ -121,9 +121,8 @@ rtems_rtl_trace_mask rtems_rtl_trace_clear_mask (rtems_rtl_trace_mask mask); * Add shell trace shell command. */ #if RTEMS_RTL_TRACE -int rtems_rtl_trace_shell_command (const rtems_printer* printer, - int argc, - char* argv[]); +int rtems_rtl_trace_shell_command(const rtems_printer* printer, int argc, + char* argv[]); #endif #ifdef __cplusplus diff --git a/cpukit/include/rtems/rtl/rtl-unresolved.h b/cpukit/include/rtems/rtl/rtl-unresolved.h index beff6ff4c4..d6f7372f95 100644 --- a/cpukit/include/rtems/rtl/rtl-unresolved.h +++ b/cpukit/include/rtems/rtl/rtl-unresolved.h @@ -68,12 +68,12 @@ * # Additional format specific data. */ -#if !defined (_RTEMS_RTL_UNRESOLVED_H_) +#if !defined(_RTEMS_RTL_UNRESOLVED_H_) #define _RTEMS_RTL_UNRESOLVED_H_ +#include "rtl-obj-fwd.h" #include #include -#include "rtl-obj-fwd.h" #ifdef __cplusplus extern "C" { @@ -88,20 +88,22 @@ typedef uint32_t rtems_rtl_word; /** * The types of records in the blocks. */ -typedef enum rtems_rtl_unresolved_rtype -{ - rtems_rtl_unresolved_empty = 0, /**< The records is empty. Must always be 0 */ +typedef enum rtems_rtl_unresolved_rtype { + rtems_rtl_unresolved_empty = 0, /**< The records is empty. Must always be 0 */ rtems_rtl_unresolved_symbol = 1, /**< The record is a symbol. */ rtems_rtl_unresolved_reloc = 2, /**< The record is a relocation record. */ - rtems_rtl_trampoline_reloc = 3 /**< The record is a trampoline relocation record. */ + rtems_rtl_trampoline_reloc = + 3 /**< The record is a trampoline relocation record. */ } rtems_rtl_unresolved_rtype; /** * Unresolved external symbol flags. */ -#define RTEMS_RTL_UNRESOLV_SYM_SEARCH_ARCHIVE (1 << 0) /**< Search the archive. */ -#define RTEMS_RTL_UNRESOLV_SYM_HAS_ERROR (1 << 1) /**< The symbol load - * has an error. */ +#define RTEMS_RTL_UNRESOLV_SYM_SEARCH_ARCHIVE \ + (1 << 0) /**< Search the archive. */ +#define RTEMS_RTL_UNRESOLV_SYM_HAS_ERROR \ + (1 << 1) /**< The symbol load \ + * has an error. */ /** * Unresolved externals symbols. The symbols are reference counted and separate @@ -111,35 +113,32 @@ typedef enum rtems_rtl_unresolved_rtype * The name is extended in the allocator of the record in the unresolved data * block. The 10 is a minimum that is added to by joining more than one record. */ -typedef struct rtems_rtl_unresolv_symbol -{ - uint16_t refs; /**< The number of references to this name. */ - uint16_t flags; /**< Flags to manage the symbol. */ - uint16_t length; /**< The length of this name. */ - const char name[]; /**< The symbol name. */ +typedef struct rtems_rtl_unresolv_symbol { + uint16_t refs; /**< The number of references to this name. */ + uint16_t flags; /**< Flags to manage the symbol. */ + uint16_t length; /**< The length of this name. */ + const char name[]; /**< The symbol name. */ } rtems_rtl_unresolv_symbol; /** * Unresolved externals symbols require the relocation records to be held * and referenced. */ -typedef struct rtems_rtl_unresolv_reloc -{ - rtems_rtl_obj* obj; /**< The relocation's object file. */ - uint16_t flags; /**< Format specific flags. */ - uint16_t name; /**< The symbol's name. */ - uint16_t sect; /**< The target section. */ - rtems_rtl_word rel[3]; /**< Relocation record. */ +typedef struct rtems_rtl_unresolv_reloc { + rtems_rtl_obj* obj; /**< The relocation's object file. */ + uint16_t flags; /**< Format specific flags. */ + uint16_t name; /**< The symbol's name. */ + uint16_t sect; /**< The target section. */ + rtems_rtl_word rel[3]; /**< Relocation record. */ } rtems_rtl_unresolv_reloc; /** * Trampolines require the relocation records to be held */ -typedef struct rtems_rtl_tramp_reloc -{ +typedef struct rtems_rtl_tramp_reloc { rtems_rtl_obj* obj; /**< The relocation's object file. */ - uint16_t flags; /**< Format specific flags. */ - uint16_t sect; /**< The target section. */ + uint16_t flags; /**< Format specific flags. */ + uint16_t sect; /**< The target section. */ rtems_rtl_word symvalue; /**< The symbol's value. */ rtems_rtl_word rel[3]; /**< Relocation record. */ } rtems_rtl_tramp_reloc; @@ -147,35 +146,31 @@ typedef struct rtems_rtl_tramp_reloc /** * Unresolved externals records. */ -typedef struct rtems_rtl_unresolv_rec -{ +typedef struct rtems_rtl_unresolv_rec { rtems_rtl_unresolved_rtype type; - union - { - rtems_rtl_unresolv_symbol name; /**< The symbol, or */ - rtems_rtl_unresolv_reloc reloc; /**< The relocation record. */ - rtems_rtl_tramp_reloc tramp; /**< The trampoline relocation record. */ + union { + rtems_rtl_unresolv_symbol name; /**< The symbol, or */ + rtems_rtl_unresolv_reloc reloc; /**< The relocation record. */ + rtems_rtl_tramp_reloc tramp; /**< The trampoline relocation record. */ } rec; } rtems_rtl_unresolv_rec; /** * Unresolved blocks. */ -typedef struct rtems_rtl_unresolv_block -{ - rtems_chain_node link; /**< Blocks are chained. */ - uint32_t recs; /**< The number of records in the block. */ +typedef struct rtems_rtl_unresolv_block { + rtems_chain_node link; /**< Blocks are chained. */ + uint32_t recs; /**< The number of records in the block. */ rtems_rtl_unresolv_rec rec[]; /**< The records. More follow. */ } rtems_rtl_unresolv_block; /** * Unresolved table holds the names and relocations. */ -typedef struct rtems_rtl_unresolved -{ - uint32_t marker; /**< Block marker. */ - size_t block_recs; /**< The records per blocks allocated. */ - rtems_chain_control blocks; /**< List of blocks. */ +typedef struct rtems_rtl_unresolved { + uint32_t marker; /**< Block marker. */ + size_t block_recs; /**< The records per blocks allocated. */ + rtems_chain_control blocks; /**< List of blocks. */ } rtems_rtl_unresolved; /** @@ -186,8 +181,8 @@ typedef struct rtems_rtl_unresolved * @retval true The iterator has finished. * @retval false The iterator has not finished. Keep iterating. */ -typedef bool rtems_rtl_unresolved_iterator (rtems_rtl_unresolv_rec* rec, - void* data); +typedef bool rtems_rtl_unresolved_iterator(rtems_rtl_unresolv_rec* rec, + void* data); /** * Open an unresolved relocation table. @@ -198,21 +193,21 @@ typedef bool rtems_rtl_unresolved_iterator (rtems_rtl_unresolv_rec* rec, * @retval false The unresolved relocation table could not created. The RTL * error has the error. */ -bool rtems_rtl_unresolved_table_open (rtems_rtl_unresolved* unresolved, - size_t block_records); +bool rtems_rtl_unresolved_table_open(rtems_rtl_unresolved* unresolved, + size_t block_records); /** * Close the table and erase the blocks. * * @param unreolved Close the unresolved table. */ -void rtems_rtl_unresolved_table_close (rtems_rtl_unresolved* unresolved); +void rtems_rtl_unresolved_table_close(rtems_rtl_unresolved* unresolved); /** * Iterate over the table of unresolved entries. */ -bool rtems_rtl_unresolved_iterate (rtems_rtl_unresolved_iterator iterator, - void* data); +bool rtems_rtl_unresolved_iterate(rtems_rtl_unresolved_iterator iterator, + void* data); /** * Add a relocation to the list of unresolved relocations. @@ -226,16 +221,14 @@ bool rtems_rtl_unresolved_iterate (rtems_rtl_unresolved_iterator iterator, * @retval true The relocation has been added. * @retval false The relocation could not be added. */ -bool rtems_rtl_unresolved_add (rtems_rtl_obj* obj, - const uint16_t flags, - const char* name, - const uint16_t sect, - const rtems_rtl_word* rel); +bool rtems_rtl_unresolved_add(rtems_rtl_obj* obj, const uint16_t flags, + const char* name, const uint16_t sect, + const rtems_rtl_word* rel); /** * Resolve the unresolved symbols. */ -void rtems_rtl_unresolved_resolve (void); +void rtems_rtl_unresolved_resolve(void); /** * Remove a relocation from the list of unresolved relocations. @@ -245,21 +238,20 @@ void rtems_rtl_unresolved_resolve (void); * @param esyms The exported symbol table. * @param size The size of the table in bytes. */ -bool rtems_rtl_unresolved_remove (rtems_rtl_obj* obj, - const char* name, - const uint16_t sect, - const rtems_rtl_word* rel); +bool rtems_rtl_unresolved_remove(rtems_rtl_obj* obj, const char* name, + const uint16_t sect, + const rtems_rtl_word* rel); /** * Set all symbols to be archive searchable. This is done when the available * archives have been refreshed and there are new archives to search for. */ -void rtems_rtl_unresolved_set_archive_search (void); +void rtems_rtl_unresolved_set_archive_search(void); /** * Dump the RTL unresolved data. */ -void rtems_rtl_unresolved_dump (void); +void rtems_rtl_unresolved_dump(void); #ifdef __cplusplus } diff --git a/cpukit/include/rtems/rtl/rtl.h b/cpukit/include/rtems/rtl/rtl.h index eeec10d4c8..e851972bd0 100644 --- a/cpukit/include/rtems/rtl/rtl.h +++ b/cpukit/include/rtems/rtl/rtl.h @@ -35,7 +35,7 @@ * This is the POSIX interface to run-time loading of code into RTEMS. */ -#if !defined (_RTEMS_RTL_H_) +#if !defined(_RTEMS_RTL_H_) #define _RTEMS_RTL_H_ #include @@ -45,9 +45,9 @@ #include #include #include -#include #include #include +#include #include #include @@ -76,12 +76,12 @@ extern "C" { * Macros to glue two tokens. */ #ifdef __STDC__ -#define RTL_XGLUE(a,b) a##b +#define RTL_XGLUE(a, b) a##b #else -#define RTL_XGLUE(a,b) a/**/b +#define RTL_XGLUE(a, b) a /**/ b #endif -#define RTL_GLUE(a,b) RTL_XGLUE(a,b) +#define RTL_GLUE(a, b) RTL_XGLUE(a, b) /** * The number of buckets in the global symbol table. @@ -107,7 +107,7 @@ extern struct r_debug _rtld_debug; * Debugger break function. Call when debugging to have it read the _rtld_debug * variable. */ -void _rtld_debug_state (void); +void _rtld_debug_state(void); /** * The type of constructor/destructor function. @@ -122,23 +122,22 @@ typedef void (*rtems_rtl_cdtor)(void); * actual symbols are part of the object's structure. If this is a problem we * could look at a hash table per object file. */ -struct rtems_rtl_data -{ - rtems_recursive_mutex lock; /**< The RTL lock */ - rtems_rtl_alloc_data allocator; /**< The allocator data. */ - rtems_chain_control objects; /**< List if loaded object files. */ - rtems_chain_control pending; /**< Listof object files needing work. */ - const char* paths; /**< Search paths for archives. */ - rtems_rtl_symbols globals; /**< Global symbol table. */ - rtems_rtl_archives archives; /**< Archive search and loader. */ - rtems_rtl_unresolved unresolved; /**< Unresolved symbols. */ - rtems_rtl_obj* base; /**< Base object file. */ - rtems_rtl_obj_cache symbols; /**< Symbols object file cache. */ - rtems_rtl_obj_cache strings; /**< Strings object file cache. */ - rtems_rtl_obj_cache relocs; /**< Relocations object file cache. */ - rtems_rtl_obj_comp decomp; /**< The decompression compressor. */ - int last_errno; /**< Last error number. */ - char last_error[64]; /**< Last error string. */ +struct rtems_rtl_data { + rtems_recursive_mutex lock; /**< The RTL lock */ + rtems_rtl_alloc_data allocator; /**< The allocator data. */ + rtems_chain_control objects; /**< List if loaded object files. */ + rtems_chain_control pending; /**< Listof object files needing work. */ + const char* paths; /**< Search paths for archives. */ + rtems_rtl_symbols globals; /**< Global symbol table. */ + rtems_rtl_archives archives; /**< Archive search and loader. */ + rtems_rtl_unresolved unresolved; /**< Unresolved symbols. */ + rtems_rtl_obj* base; /**< Base object file. */ + rtems_rtl_obj_cache symbols; /**< Symbols object file cache. */ + rtems_rtl_obj_cache strings; /**< Strings object file cache. */ + rtems_rtl_obj_cache relocs; /**< Relocations object file cache. */ + rtems_rtl_obj_comp decomp; /**< The decompression compressor. */ + int last_errno; /**< Last error number. */ + char last_error[64]; /**< Last error string. */ }; /** @@ -147,7 +146,7 @@ struct rtems_rtl_data * @return rtems_rtl_data* The RTL data after being locked. * @retval NULL The RTL data is not initialised. */ -rtems_rtl_data* rtems_rtl_data_unprotected (void); +rtems_rtl_data* rtems_rtl_data_unprotected(void); /** * Get the RTL global symbol table with out locking. This call assumes @@ -156,7 +155,7 @@ rtems_rtl_data* rtems_rtl_data_unprotected (void); * @return rtems_rtl_symbols* The RTL global symbols after being locked. * @retval NULL The RTL data is not initialised. */ -rtems_rtl_symbols* rtems_rtl_global_symbols (void); +rtems_rtl_symbols* rtems_rtl_global_symbols(void); /** * Get the RTL last error string with out locking. This call assumes the RTL is @@ -165,7 +164,7 @@ rtems_rtl_symbols* rtems_rtl_global_symbols (void); * @return const char* The RTL's laste error. * @retval NULL The RTL data is not initialised. */ -const char* rtems_rtl_last_error_unprotected (void); +const char* rtems_rtl_last_error_unprotected(void); /** * Get the RTL objects table with out locking. This call assumes the RTL @@ -174,7 +173,7 @@ const char* rtems_rtl_last_error_unprotected (void); * @return rtems_chain_control* The RTL objects chain. * @retval NULL The RTL data is not initialised. */ -rtems_chain_control* rtems_rtl_objects_unprotected (void); +rtems_chain_control* rtems_rtl_objects_unprotected(void); /** * Get the RTL pending with out locking. This call assumes the RTL is locked. @@ -182,7 +181,7 @@ rtems_chain_control* rtems_rtl_objects_unprotected (void); * @return rtems_chain_control* The RTL pending list control. * @retval NULL The RTL data is not initialised. */ -rtems_chain_control* rtems_rtl_pending_unprotected (void); +rtems_chain_control* rtems_rtl_pending_unprotected(void); /** * Get the RTL unresolved table with out locking. This call assumes the RTL @@ -191,7 +190,7 @@ rtems_chain_control* rtems_rtl_pending_unprotected (void); * @return rtems_rtl_unresolv* The RTL unresolved symbols and reloc records. * @retval NULL The RTL data is not initialised. */ -rtems_rtl_unresolved* rtems_rtl_unresolved_unprotected (void); +rtems_rtl_unresolved* rtems_rtl_unresolved_unprotected(void); /** * Get the RTL archives with out locking. This call assumes the RTL is locked. @@ -199,7 +198,7 @@ rtems_rtl_unresolved* rtems_rtl_unresolved_unprotected (void); * @return rtems_rtl_archives* The RTL acrhives. * @retval NULL The RTL data is not initialised. */ -rtems_rtl_archives* rtems_rtl_archives_unprotected (void); +rtems_rtl_archives* rtems_rtl_archives_unprotected(void); /** * Get the RTL symbols, strings, or relocations object file caches. This call @@ -212,14 +211,14 @@ rtems_rtl_archives* rtems_rtl_archives_unprotected (void); * @param relocs Pointer to the location to set the cache into. Returns NULL * is rtl is not initialised. If NULL is passed in no value set. */ -void rtems_rtl_obj_caches (rtems_rtl_obj_cache** symbols, - rtems_rtl_obj_cache** strings, - rtems_rtl_obj_cache** relocs); +void rtems_rtl_obj_caches(rtems_rtl_obj_cache** symbols, + rtems_rtl_obj_cache** strings, + rtems_rtl_obj_cache** relocs); /** * Flush all the object file caches. */ -void rtems_rtl_obj_caches_flush (void); +void rtems_rtl_obj_caches_flush(void); /** * Get the RTL decompressor setting for the cache and the offset in the file @@ -230,11 +229,9 @@ void rtems_rtl_obj_caches_flush (void); * @param cache The cache to read the file with. Saves needing an extrs buffer. * @param offset The offset in the file the compressed stream starts. */ -void rtems_rtl_obj_decompress (rtems_rtl_obj_comp** decomp, - rtems_rtl_obj_cache* cache, - int fd, - int compression, - off_t offset); +void rtems_rtl_obj_decompress(rtems_rtl_obj_comp** decomp, + rtems_rtl_obj_cache* cache, int fd, + int compression, off_t offset); /** * Update the mask in the object files. You can clear flags and then set @@ -244,7 +241,7 @@ void rtems_rtl_obj_decompress (rtems_rtl_obj_comp** decomp, * @param clear The flag's clear mask, a 0 does not clear any flags. * @param set The flag's set mask, a 0 does not set any flags. */ -void rtems_rtl_obj_update_flags (uint32_t clear, uint32_t set); +void rtems_rtl_obj_update_flags(uint32_t clear, uint32_t set); /** * Lock the Run-time Linker. @@ -253,12 +250,12 @@ void rtems_rtl_obj_update_flags (uint32_t clear, uint32_t set); * @retval NULL The RTL data could not be initialised or locked. Typically this * means the lock could not be created. */ -rtems_rtl_data* rtems_rtl_lock (void); +rtems_rtl_data* rtems_rtl_lock(void); /** * Unlock the Run-time Linker. */ -void rtems_rtl_unlock (void); +void rtems_rtl_unlock(void); /** * Check a pointer is a valid object file descriptor returning the pointer as @@ -269,7 +266,7 @@ void rtems_rtl_unlock (void); * @param handle Pointer to the object file to be validated. * @return rtl_obj* The object file descriptor. NULL is returned if invalid. */ -rtems_rtl_obj* rtems_rtl_check_handle (void* handle); +rtems_rtl_obj* rtems_rtl_check_handle(void* handle); /** * Find the object given a file name. @@ -278,7 +275,7 @@ rtems_rtl_obj* rtems_rtl_check_handle (void* handle); * @retval NULL No object file with that name found. * @return rtems_rtl_obj* The object file descriptor. */ -rtems_rtl_obj* rtems_rtl_find_obj (const char* name); +rtems_rtl_obj* rtems_rtl_find_obj(const char* name); /** * Find the object file a symbol is exported from. @@ -287,7 +284,7 @@ rtems_rtl_obj* rtems_rtl_find_obj (const char* name); * @retval NULL No object file found. * @return rtems_rtl_obj* Reference to the symbol. */ -rtems_rtl_obj* rtems_rtl_find_obj_with_symbol (const rtems_rtl_obj_sym* sym); +rtems_rtl_obj* rtems_rtl_find_obj_with_symbol(const rtems_rtl_obj_sym* sym); /** * Load an object file into memory relocating it. It will not be resolved @@ -318,9 +315,10 @@ rtems_rtl_obj* rtems_rtl_find_obj_with_symbol (const rtems_rtl_obj_sym* sym); * * @param name The name of the object file. * @param mode The mode of the load as defined by the dlopen call. - * @return rtl_obj* The object file descriptor. NULL is returned if the load fails. + * @return rtl_obj* The object file descriptor. NULL is returned if the load + * fails. */ -rtems_rtl_obj* rtems_rtl_load_object (const char* name, int mode); +rtems_rtl_obj* rtems_rtl_load_object(const char* name, int mode); /** * Unload an object file. This only happens when the user count is 0. @@ -331,7 +329,7 @@ rtems_rtl_obj* rtems_rtl_load_object (const char* name, int mode); * @retval true The object file has been unloaded. * @retval false The object file could not be unloaded. */ -bool rtems_rtl_unload_object (rtems_rtl_obj* obj); +bool rtems_rtl_unload_object(rtems_rtl_obj* obj); /** * Load an object file. This is the user accessable interface to unloading an @@ -339,9 +337,10 @@ bool rtems_rtl_unload_object (rtems_rtl_obj* obj); * * @param name The name of the object file. * @param mode The mode of the load as defined by the dlopen call. - * @return rtl_obj* The object file descriptor. NULL is returned if the load fails. + * @return rtl_obj* The object file descriptor. NULL is returned if the load + * fails. */ -rtems_rtl_obj* rtems_rtl_load (const char* name, int mode); +rtems_rtl_obj* rtems_rtl_load(const char* name, int mode); /** * Unload an object file. This is the user accessable interface to unloading an @@ -353,7 +352,7 @@ rtems_rtl_obj* rtems_rtl_load (const char* name, int mode); * @retval true The object file has been unloaded. * @retval false The object file could not be unloaded. */ -bool rtems_rtl_unload (rtems_rtl_obj* obj); +bool rtems_rtl_unload(rtems_rtl_obj* obj); /** * Get the last error message clearing it. This operation locks the run time @@ -365,7 +364,7 @@ bool rtems_rtl_unload (rtems_rtl_obj* obj); * @param max_message The maximum message that can be copied. * @return int The last error number. */ -int rtems_rtl_get_error (char* message, size_t max_message); +int rtems_rtl_get_error(char* message, size_t max_message); /** * Append the path to the search path. @@ -374,7 +373,7 @@ int rtems_rtl_get_error (char* message, size_t max_message); * @retval false The path could not be appended. * @retval true The path was appended. */ -bool rtems_rtl_path_append (const char* path); +bool rtems_rtl_path_append(const char* path); /** * Prepend the path to the search path. @@ -384,7 +383,7 @@ bool rtems_rtl_path_append (const char* path); * @retval true The path was prepended. */ -bool rtems_rtl_path_prepend (const char* path); +bool rtems_rtl_path_prepend(const char* path); /** * Add an exported symbol table to the global symbol table. This call is @@ -396,10 +395,10 @@ bool rtems_rtl_path_prepend (const char* path); * @param tls_offsets The TLS offsets table. If NULL none provided. * @param tls_size The number TLS offset entries in the table. */ -void rtems_rtl_base_sym_global_add (const unsigned char* esyms, - unsigned int count, - const rtems_rtl_tls_offset* tls_offsets, - unsigned int tls_size); +void rtems_rtl_base_sym_global_add(const unsigned char* esyms, + unsigned int count, + const rtems_rtl_tls_offset* tls_offsets, + unsigned int tls_size); /** * Return the object file descriptor for the base image. The object file @@ -410,7 +409,7 @@ void rtems_rtl_base_sym_global_add (const unsigned char* esyms, * @return rtl_obj* The object file descriptor for the base image. NULL is * returned if the load fails. */ -rtems_rtl_obj* rtems_rtl_baseimage (void); +rtems_rtl_obj* rtems_rtl_baseimage(void); #ifdef __cplusplus } diff --git a/cpukit/libdl/dlfcn-shell.c b/cpukit/libdl/dlfcn-shell.c index 882d069b3d..3d7be98bb4 100644 --- a/cpukit/libdl/dlfcn-shell.c +++ b/cpukit/libdl/dlfcn-shell.c @@ -47,75 +47,57 @@ #include #include -static void* -convert_ascii_to_voidp (const char* arg) -{ - if (strcmp (arg, "base") == 0) +static void* convert_ascii_to_voidp(const char* arg) { + if (strcmp(arg, "base") == 0) return RTLD_DEFAULT; - return (void*) strtoul (arg, NULL, 16); + return (void*)strtoul(arg, NULL, 16); } -int -shell_dlopen (int argc, char* argv[]) -{ +int shell_dlopen(int argc, char* argv[]) { int arg; - for (arg = 1; arg < argc; arg++) - { - void* handle = dlopen (argv[arg], RTLD_NOW | RTLD_GLOBAL); - if (handle) - { - int unresolved; + for (arg = 1; arg < argc; arg++) { + void* handle = dlopen(argv[arg], RTLD_NOW | RTLD_GLOBAL); + if (handle) { + int unresolved; char* message = "loaded"; - if (dlinfo (handle, RTLD_DI_UNRESOLVED, &unresolved) < 0) + if (dlinfo(handle, RTLD_DI_UNRESOLVED, &unresolved) < 0) message = "dlinfo error checking unresolved status"; else if (unresolved) message = "has unresolved externals"; - printf ("handle: %p %s\n", handle, message); - } - else - printf ("error: %s\n", dlerror ()); + printf("handle: %p %s\n", handle, message); + } else + printf("error: %s\n", dlerror()); } return 0; } -int -shell_dlclose (int argc, char* argv[]) -{ - (void) argc; - (void) argv; +int shell_dlclose(int argc, char* argv[]) { + (void)argc; + (void)argv; return 0; } -static bool -lookup_dlsym (void** value, int argc, char* argv[]) -{ - if (argc >= 3) - { - void* handle = convert_ascii_to_voidp (argv[1]); - if (handle) - { - *value = dlsym (handle, argv[2]); +static bool lookup_dlsym(void** value, int argc, char* argv[]) { + if (argc >= 3) { + void* handle = convert_ascii_to_voidp(argv[1]); + if (handle) { + *value = dlsym(handle, argv[2]); if (*value) return true; else - printf ("error: invalid handle or symbol\n"); - } - else - printf ("error: invalid handle"); - } - else - printf ("error: requires handle and symbol name\n"); + printf("error: invalid handle or symbol\n"); + } else + printf("error: invalid handle"); + } else + printf("error: requires handle and symbol name\n"); return false; } -int -shell_dlsym (int argc, char* argv[]) -{ +int shell_dlsym(int argc, char* argv[]) { void* value; - if (lookup_dlsym (&value, argc, argv)) - { - printf ("%s = %p\n", argv[2], value); + if (lookup_dlsym(&value, argc, argv)) { + printf("%s = %p\n", argv[2], value); return 0; } return -1; @@ -123,17 +105,14 @@ shell_dlsym (int argc, char* argv[]) typedef int (*call_p)(int argc, char* argv[]); -int -shell_dlcall (int argc, char* argv[]) -{ +int shell_dlcall(int argc, char* argv[]) { void* value; - if (lookup_dlsym (&value, argc, argv)) - { + if (lookup_dlsym(&value, argc, argv)) { call_p call = value; - int r; - printf ("(*%p)(%d, ....)\n", value, argc - 3); - r = call (argc - 3, argv + 3); - printf ("return %d\n", r); + int r; + printf("(*%p)(%d, ....)\n", value, argc - 3); + r = call(argc - 3, argv + 3); + printf("return %d\n", r); return 0; } return -1; diff --git a/cpukit/libdl/dlfcn.c b/cpukit/libdl/dlfcn.c index bc485f5b98..dcca1fe2c1 100644 --- a/cpukit/libdl/dlfcn.c +++ b/cpukit/libdl/dlfcn.c @@ -35,13 +35,11 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include #include #include +#include -static rtems_rtl_obj* -dl_get_obj_from_handle (void* handle) -{ +static rtems_rtl_obj* dl_get_obj_from_handle(void* handle) { rtems_rtl_obj* obj; /* @@ -53,133 +51,117 @@ dl_get_obj_from_handle (void* handle) */ if ((handle == RTLD_DEFAULT) || (handle == RTLD_SELF)) - obj = rtems_rtl_baseimage (); + obj = rtems_rtl_baseimage(); else - obj = rtems_rtl_check_handle (handle); + obj = rtems_rtl_check_handle(handle); return obj; } -void* -dlopen (const char* name, int mode) -{ +void* dlopen(const char* name, int mode) { rtems_rtl_obj* obj = NULL; - if (!rtems_rtl_lock ()) + if (!rtems_rtl_lock()) return NULL; _rtld_debug.r_state = RT_ADD; - _rtld_debug_state (); + _rtld_debug_state(); if (name) - obj = rtems_rtl_load (name, mode); + obj = rtems_rtl_load(name, mode); else - obj = rtems_rtl_baseimage (); + obj = rtems_rtl_baseimage(); _rtld_debug.r_state = RT_CONSISTENT; _rtld_debug_state(); - rtems_rtl_unlock (); + rtems_rtl_unlock(); return obj; } -int -dlclose (void* handle) -{ +int dlclose(void* handle) { rtems_rtl_obj* obj; - int r; + int r; - if (!rtems_rtl_lock ()) + if (!rtems_rtl_lock()) return -1; - obj = rtems_rtl_check_handle (handle); - if (!obj) - { - rtems_rtl_unlock (); + obj = rtems_rtl_check_handle(handle); + if (!obj) { + rtems_rtl_unlock(); return -1; } _rtld_debug.r_state = RT_DELETE; - _rtld_debug_state (); + _rtld_debug_state(); - r = rtems_rtl_unload (obj) ? 0 : -1; + r = rtems_rtl_unload(obj) ? 0 : -1; _rtld_debug.r_state = RT_CONSISTENT; - _rtld_debug_state (); + _rtld_debug_state(); - rtems_rtl_unlock (); + rtems_rtl_unlock(); return r; } -void* -dlsym (void* handle, const char *symbol) -{ - rtems_rtl_obj* obj; +void* dlsym(void* handle, const char* symbol) { + rtems_rtl_obj* obj; rtems_rtl_obj_sym* sym = NULL; - void* symval = NULL; + void* symval = NULL; - if (!rtems_rtl_lock ()) + if (!rtems_rtl_lock()) return NULL; /* * If the handle is "default" search the global symbol table. */ - if (handle == RTLD_DEFAULT) - { - sym = rtems_rtl_symbol_global_find (symbol); - } - else - { - obj = dl_get_obj_from_handle (handle); + if (handle == RTLD_DEFAULT) { + sym = rtems_rtl_symbol_global_find(symbol); + } else { + obj = dl_get_obj_from_handle(handle); if (obj) - sym = rtems_rtl_symbol_obj_find (obj, symbol); + sym = rtems_rtl_symbol_obj_find(obj, symbol); } if (sym) symval = sym->value; - rtems_rtl_unlock (); + rtems_rtl_unlock(); return symval; } -const char* -dlerror (void) -{ +const char* dlerror(void) { static char msg[64]; - int eno; - eno = rtems_rtl_get_error (msg, sizeof (msg)); + int eno; + eno = rtems_rtl_get_error(msg, sizeof(msg)); if (eno == 0) return NULL; return msg; } -int -dlinfo (void* handle, int request, void* p) -{ +int dlinfo(void* handle, int request, void* p) { rtems_rtl_obj* obj; - int rc = -1; + int rc = -1; - if (!rtems_rtl_lock () || !p) + if (!rtems_rtl_lock() || !p) return -1; - obj = dl_get_obj_from_handle (handle); - if (obj) - { - switch (request) - { - case RTLD_DI_UNRESOLVED: - *((int*) p) = rtems_rtl_obj_unresolved (obj) ? 1 : 0; - rc = 0; - break; - default: - break; + obj = dl_get_obj_from_handle(handle); + if (obj) { + switch (request) { + case RTLD_DI_UNRESOLVED: + *((int*)p) = rtems_rtl_obj_unresolved(obj) ? 1 : 0; + rc = 0; + break; + default: + break; } } - rtems_rtl_unlock (); + rtems_rtl_unlock(); return rc; } diff --git a/cpukit/libdl/rap-shell.c b/cpukit/libdl/rap-shell.c index 2a6fc436f4..891227bb20 100644 --- a/cpukit/libdl/rap-shell.c +++ b/cpukit/libdl/rap-shell.c @@ -44,86 +44,65 @@ #include #include -#include #include +#include -static void -shell_rap_command_help (void) -{ - printf ("usage: rap [cmd] [arg]\n" \ - "Commands and options:\n" \ - "ls: List the loaded applications (also list)\n" \ - "ld: Load an application (also load)\n" \ - "un: Unload an application (also unload)\n"); +static void shell_rap_command_help(void) { + printf("usage: rap [cmd] [arg]\n" + "Commands and options:\n" + "ls: List the loaded applications (also list)\n" + "ld: Load an application (also load)\n" + "un: Unload an application (also unload)\n"); } -static void -shell_rap_get_error (const char* what) -{ +static void shell_rap_get_error(const char* what) { char message[64]; - int error; - error = rtems_rap_get_error (message, sizeof (message)); - printf ("error: %s: (%d) %s\n", what, error, message); + int error; + error = rtems_rap_get_error(message, sizeof(message)); + printf("error: %s: (%d) %s\n", what, error, message); } -static bool -shell_rap_list_handler (void* handle) -{ - printf (" %-10p %-10p %-s\n", - handle, rtems_rap_dl_handle (handle), rtems_rap_name (handle)); +static bool shell_rap_list_handler(void* handle) { + printf(" %-10p %-10p %-s\n", handle, rtems_rap_dl_handle(handle), + rtems_rap_name(handle)); return true; } -static int -shell_rap_list (int argc, char* argv[]) -{ - (void) argc; - (void) argv; +static int shell_rap_list(int argc, char* argv[]) { + (void)argc; + (void)argv; - printf (" App DL Handle Name\n"); - return rtems_rap_iterate (shell_rap_list_handler) ? 0 : 1; + printf(" App DL Handle Name\n"); + return rtems_rap_iterate(shell_rap_list_handler) ? 0 : 1; } -static int -shell_rap_load (int argc, char* argv[]) -{ +static int shell_rap_load(int argc, char* argv[]) { int r = 0; - if (argc == 0) - { - printf ("error: no application name\n"); + if (argc == 0) { + printf("error: no application name\n"); return 0; } - if (rtems_rap_load (argv[0], 0, argc - 1, (const char**) (argv + 1))) - printf ("%s loaded\n", argv[0]); - else - { + if (rtems_rap_load(argv[0], 0, argc - 1, (const char**)(argv + 1))) + printf("%s loaded\n", argv[0]); + else { r = 1; - shell_rap_get_error ("loading"); + shell_rap_get_error("loading"); } return r; } -int -shell_rap (int argc, char* argv[]) -{ - if (argc == 1) - { - shell_rap_command_help (); +int shell_rap(int argc, char* argv[]) { + if (argc == 1) { + shell_rap_command_help(); return 0; } - if ((strcmp (argv[1], "ls") == 0) || - (strcmp (argv[1], "list") == 0)) - { - return shell_rap_list (argc - 2, argv + 2); - } - else if ((strcmp (argv[1], "ld") == 0) || - (strcmp (argv[1], "load") == 0)) - { - return shell_rap_load (argc - 2, argv + 2); + if ((strcmp(argv[1], "ls") == 0) || (strcmp(argv[1], "list") == 0)) { + return shell_rap_list(argc - 2, argv + 2); + } else if ((strcmp(argv[1], "ld") == 0) || (strcmp(argv[1], "load") == 0)) { + return shell_rap_load(argc - 2, argv + 2); } - printf ("error: invalid command: %s\n", argv[1]); + printf("error: invalid command: %s\n", argv[1]); return 0; } - diff --git a/cpukit/libdl/rap.c b/cpukit/libdl/rap.c index 1a93721aec..5999f08069 100644 --- a/cpukit/libdl/rap.c +++ b/cpukit/libdl/rap.c @@ -41,8 +41,8 @@ #include #include -#include #include +#include #include #include @@ -57,39 +57,37 @@ * The global RAP data. This structure is allocated on the heap when the first * call to location an application and is never released. */ -typedef struct rtems_rap_data_s -{ - pthread_once_t once; - rtems_mutex lock; /**< The RAP lock id */ - rtems_chain_control apps; /**< List if loaded application. */ - int last_errno; /**< Last error number. */ - char last_error[64]; /**< Last error string. */ +typedef struct rtems_rap_data_s { + pthread_once_t once; + rtems_mutex lock; /**< The RAP lock id */ + rtems_chain_control apps; /**< List if loaded application. */ + int last_errno; /**< Last error number. */ + char last_error[64]; /**< Last error string. */ } rtems_rap_data; /** * The RAP file data. This structure is allocated on the heap when a file is * loaded. */ -typedef struct rtems_rap_app -{ - rtems_chain_node node; /**< The node's link in the chain. */ - const char* name; /**< The file name */ - void* handle; /**< The dlopen handle. */ +typedef struct rtems_rap_app { + rtems_chain_node node; /**< The node's link in the chain. */ + const char* name; /**< The file name */ + void* handle; /**< The dlopen handle. */ } rtems_rap_app; /** * RTL entry. */ #if (RTL_GLUE(__USER_LABEL_PREFIX__, 1) == RTL_GLUE(_, 1)) - #define RTL_ENTRY_POINT "_rtems" +#define RTL_ENTRY_POINT "_rtems" #else - #define RTL_ENTRY_POINT "rtems" +#define RTL_ENTRY_POINT "rtems" #endif /** * Static RAP data is returned to the user when the loader is locked. */ -static rtems_rap_data rap_ = { .once = PTHREAD_ONCE_INIT }; +static rtems_rap_data rap_ = {.once = PTHREAD_ONCE_INIT}; /** * Verbose level for the RAP loader. @@ -104,82 +102,66 @@ typedef int (*rtems_rap_entry)(int argc, const char* argv[]); /** * Forward decl. */ -static void rtems_rap_unlock (void); +static void rtems_rap_unlock(void); -static void -rtems_rap_data_init (void) -{ +static void rtems_rap_data_init(void) { /* * Create the RAP lock. */ - rtems_mutex_init (&rap_.lock, "RAP"); + rtems_mutex_init(&rap_.lock, "RAP"); /* * Initialise the objects list and create any required services. */ - rtems_chain_initialize_empty (&rap_.apps); + rtems_chain_initialize_empty(&rap_.apps); } -static rtems_rap_data* -rtems_rap_lock (void) -{ - pthread_once (&rap_.once, rtems_rap_data_init); - rtems_mutex_lock (&rap_.lock); +static rtems_rap_data* rtems_rap_lock(void) { + pthread_once(&rap_.once, rtems_rap_data_init); + rtems_mutex_lock(&rap_.lock); return &rap_; } -static void -rtems_rap_unlock (void) -{ - rtems_mutex_unlock (&rap_.lock); +static void rtems_rap_unlock(void) { + rtems_mutex_unlock(&rap_.lock); } -static rtems_rap_app* -rtems_rap_check_handle (void* handle) -{ - rtems_rap_app* app; +static rtems_rap_app* rtems_rap_check_handle(void* handle) { + rtems_rap_app* app; rtems_chain_node* node; app = handle; - node = rtems_chain_first (&rap_.apps); + node = rtems_chain_first(&rap_.apps); - while (!rtems_chain_is_tail (&rap_.apps, node)) - { - rtems_rap_app* check = (rtems_rap_app*) node; + while (!rtems_chain_is_tail(&rap_.apps, node)) { + rtems_rap_app* check = (rtems_rap_app*)node; if (check == app) return app; - node = rtems_chain_next (node); + node = rtems_chain_next(node); } return NULL; } -static rtems_rap_app* -rtems_rap_app_alloc (void) -{ - rtems_rap_app* app = malloc (sizeof (rtems_rap_app)); - memset (app, 0, sizeof (rtems_rap_app)); - rtems_chain_append (&rap_.apps, &app->node); +static rtems_rap_app* rtems_rap_app_alloc(void) { + rtems_rap_app* app = malloc(sizeof(rtems_rap_app)); + memset(app, 0, sizeof(rtems_rap_app)); + rtems_chain_append(&rap_.apps, &app->node); return app; } -static void -rtems_rap_app_free (rtems_rap_app* app) -{ - if (app->handle) - { - dlclose (app->handle); +static void rtems_rap_app_free(rtems_rap_app* app) { + if (app->handle) { + dlclose(app->handle); app->handle = NULL; } - if (!rtems_chain_is_node_off_chain (&app->node)) - rtems_chain_extract (&app->node); + if (!rtems_chain_is_node_off_chain(&app->node)) + rtems_chain_extract(&app->node); } -static bool -rtems_rap_match_name (rtems_rap_app* app, const char* name) -{ +static bool rtems_rap_match_name(rtems_rap_app* app, const char* name) { const char* a; /* @@ -187,23 +169,19 @@ rtems_rap_match_name (rtems_rap_app* app, const char* name) * there is at least one delimiter in the name. */ - if (strncmp (app->name, name, strlen (name)) == 0) + if (strncmp(app->name, name, strlen(name)) == 0) return true; - a = app->name + strlen (app->name) - 1; + a = app->name + strlen(app->name) - 1; - while (a >= app->name) - { - if (rtems_filesystem_is_delimiter (*a)) - { + while (a >= app->name) { + if (rtems_filesystem_is_delimiter(*a)) { const char* n = name; ++a; - while (*a && *n) - { - if (*a == '.') - { + while (*a && *n) { + if (*a == '.') { if (*n == '\0') return true; } @@ -221,225 +199,194 @@ rtems_rap_match_name (rtems_rap_app* app, const char* name) return false; } -static void -rtems_rap_get_rtl_error (void) -{ +static void rtems_rap_get_rtl_error(void) { rap_.last_errno = - rtems_rtl_get_error (rap_.last_error, sizeof (rap_.last_error)); + rtems_rtl_get_error(rap_.last_error, sizeof(rap_.last_error)); } -static void -rtems_rap_set_error (int error, const char* format, ...) -{ - rtems_rap_data* rap = rtems_rap_lock (); - va_list ap; - va_start (ap, format); +static void rtems_rap_set_error(int error, const char* format, ...) { + rtems_rap_data* rap = rtems_rap_lock(); + va_list ap; + va_start(ap, format); rap->last_errno = error; - vsnprintf (rap->last_error, sizeof (rap->last_error), format, ap); - rtems_rap_unlock (); - va_end (ap); + vsnprintf(rap->last_error, sizeof(rap->last_error), format, ap); + rtems_rap_unlock(); + va_end(ap); } -bool -rtems_rap_load (const char* name, int mode, int argc, const char* argv[]) -{ - rtems_rap_data* rap = rtems_rap_lock (); +bool rtems_rap_load(const char* name, int mode, int argc, const char* argv[]) { + rtems_rap_data* rap = rtems_rap_lock(); if (!rap) return false; if (rap_verbose) - printf ("rap: loading '%s'\n", name); + printf("rap: loading '%s'\n", name); /* * See if the app has already been loaded. */ - if (!rtems_rap_find (name)) - { - rtems_rap_app* app; + if (!rtems_rap_find(name)) { + rtems_rap_app* app; rtems_rap_entry init; rtems_rap_entry fini; - size_t size = 0; - int r; + size_t size = 0; + int r; /* * Allocate a new application descriptor and attempt to load it. */ - app = rtems_rap_app_alloc (); - if (app == NULL) - { - rtems_rap_set_error (ENOMEM, "no memory for application"); - rtems_rap_unlock (); + app = rtems_rap_app_alloc(); + if (app == NULL) { + rtems_rap_set_error(ENOMEM, "no memory for application"); + rtems_rap_unlock(); return false; } /* * Find the file in the file system using the search path. */ - if (!rtems_rtl_find_file (name, getenv ("PATH"), &app->name, &size)) - { - rtems_rap_set_error (ENOENT, "file not found"); - rtems_rap_app_free (app); - rtems_rap_unlock (); + if (!rtems_rtl_find_file(name, getenv("PATH"), &app->name, &size)) { + rtems_rap_set_error(ENOENT, "file not found"); + rtems_rap_app_free(app); + rtems_rap_unlock(); return false; } - app->handle = dlopen (app->name, RTLD_NOW | mode); - if (!app->handle) - { - rtems_rap_get_rtl_error (); - rtems_rap_app_free (app); - rtems_rap_unlock (); + app->handle = dlopen(app->name, RTLD_NOW | mode); + if (!app->handle) { + rtems_rap_get_rtl_error(); + rtems_rap_app_free(app); + rtems_rap_unlock(); return false; } - init = dlsym (app->handle, RTL_ENTRY_POINT); - if (!init) - { - rtems_rap_get_rtl_error (); - rtems_rap_app_free (app); - rtems_rap_unlock (); + init = dlsym(app->handle, RTL_ENTRY_POINT); + if (!init) { + rtems_rap_get_rtl_error(); + rtems_rap_app_free(app); + rtems_rap_unlock(); return false; } - fini = dlsym (app->handle, RTL_ENTRY_POINT); - if (!fini) - { - rtems_rap_get_rtl_error (); - rtems_rap_app_free (app); - rtems_rap_unlock (); + fini = dlsym(app->handle, RTL_ENTRY_POINT); + if (!fini) { + rtems_rap_get_rtl_error(); + rtems_rap_app_free(app); + rtems_rap_unlock(); return false; } - r = init (argc, argv); - if (r != 0) - { - rtems_rap_set_error (r, "init call failure"); - rtems_rap_app_free (app); - rtems_rap_unlock (); + r = init(argc, argv); + if (r != 0) { + rtems_rap_set_error(r, "init call failure"); + rtems_rap_app_free(app); + rtems_rap_unlock(); return false; } } - rtems_rap_unlock (); + rtems_rap_unlock(); return true; } -bool -rtems_rap_unload (const char* name) -{ - rtems_rap_app* app; +bool rtems_rap_unload(const char* name) { + rtems_rap_app* app; rtems_rap_entry fini; - int r; + int r; - rtems_rap_lock (); + rtems_rap_lock(); - app = rtems_rap_find (name); + app = rtems_rap_find(name); if (rap_verbose) - printf ("rap: unloading '%s'\n", name); + printf("rap: unloading '%s'\n", name); - if (!app) - { - rtems_rap_set_error (ENOENT, "invalid handle"); - rtems_rap_unlock (); + if (!app) { + rtems_rap_set_error(ENOENT, "invalid handle"); + rtems_rap_unlock(); return false; } - fini = dlsym (app->handle, RTL_ENTRY_POINT); - if (!fini) - { - rtems_rap_get_rtl_error (); - rtems_rap_unlock (); + fini = dlsym(app->handle, RTL_ENTRY_POINT); + if (!fini) { + rtems_rap_get_rtl_error(); + rtems_rap_unlock(); return false; } - r = fini (0, NULL); - if (r != 0) - { - rtems_rap_set_error (r, "fini failure"); - rtems_rap_unlock (); + r = fini(0, NULL); + if (r != 0) { + rtems_rap_set_error(r, "fini failure"); + rtems_rap_unlock(); return false; } - rtems_rap_app_free (app); - rtems_rap_unlock (); + rtems_rap_app_free(app); + rtems_rap_unlock(); return true; } -void* -rtems_rap_find (const char* name) -{ - rtems_rap_data* rap = rtems_rap_lock (); +void* rtems_rap_find(const char* name) { + rtems_rap_data* rap = rtems_rap_lock(); rtems_chain_node* node; - node = rtems_chain_first (&rap->apps); + node = rtems_chain_first(&rap->apps); - while (!rtems_chain_is_tail (&rap->apps, node)) - { - rtems_rap_app* app = (rtems_rap_app*) node; - if (rtems_rap_match_name (app, name)) - { - rtems_rap_unlock (); + while (!rtems_chain_is_tail(&rap->apps, node)) { + rtems_rap_app* app = (rtems_rap_app*)node; + if (rtems_rap_match_name(app, name)) { + rtems_rap_unlock(); return app; } - node = rtems_chain_next (node); + node = rtems_chain_next(node); } - rtems_rap_unlock (); + rtems_rap_unlock(); return NULL; } -bool -rtems_rap_iterate (rtems_rap_iterator iterator) -{ - rtems_rap_data* rap = rtems_rap_lock (); +bool rtems_rap_iterate(rtems_rap_iterator iterator) { + rtems_rap_data* rap = rtems_rap_lock(); rtems_chain_node* node; - bool result = true; + bool result = true; - node = rtems_chain_first (&rap->apps); + node = rtems_chain_first(&rap->apps); - while (!rtems_chain_is_tail (&rap->apps, node)) - { - rtems_rap_app* app = (rtems_rap_app*) node; - result = iterator (app); + while (!rtems_chain_is_tail(&rap->apps, node)) { + rtems_rap_app* app = (rtems_rap_app*)node; + result = iterator(app); if (!result) break; - node = rtems_chain_next (node); + node = rtems_chain_next(node); } - rtems_rap_unlock (); + rtems_rap_unlock(); return result; } -const char* -rtems_rap_name (void* handle) -{ - rtems_rap_app* app = rtems_rap_check_handle (handle); +const char* rtems_rap_name(void* handle) { + rtems_rap_app* app = rtems_rap_check_handle(handle); if (app) return app->name; return NULL; } -void* -rtems_rap_dl_handle (void* handle) -{ - rtems_rap_app* app = rtems_rap_check_handle (handle); +void* rtems_rap_dl_handle(void* handle) { + rtems_rap_app* app = rtems_rap_check_handle(handle); if (app) return app->handle; return NULL; } -int -rtems_rap_get_error (char* message, size_t max_message) -{ - rtems_rap_data* rap = rtems_rap_lock (); - int last_errno = rap->last_errno; - strlcpy (message, rap->last_error, max_message); - rtems_rap_unlock (); +int rtems_rap_get_error(char* message, size_t max_message) { + rtems_rap_data* rap = rtems_rap_lock(); + int last_errno = rap->last_errno; + strlcpy(message, rap->last_error, max_message); + rtems_rap_unlock(); return last_errno; } diff --git a/cpukit/libdl/rtl-alloc-heap.c b/cpukit/libdl/rtl-alloc-heap.c index 520c37a4de..004906ff1e 100644 --- a/cpukit/libdl/rtl-alloc-heap.c +++ b/cpukit/libdl/rtl-alloc-heap.c @@ -39,33 +39,28 @@ #include -void -rtems_rtl_alloc_heap (rtems_rtl_alloc_cmd cmd, - rtems_rtl_alloc_tag tag, - void** address, - size_t size) -{ - (void) tag; +void rtems_rtl_alloc_heap(rtems_rtl_alloc_cmd cmd, rtems_rtl_alloc_tag tag, + void** address, size_t size) { + (void)tag; - switch (cmd) - { - case RTEMS_RTL_ALLOC_NEW: - *address = malloc (size); - break; - case RTEMS_RTL_ALLOC_DEL: - free (*address); - *address = NULL; - break; - case RTEMS_RTL_ALLOC_RESIZE: - *address = realloc (*address, size); - break; - case RTEMS_RTL_ALLOC_LOCK: - _RTEMS_Lock_allocator(); - break; - case RTEMS_RTL_ALLOC_UNLOCK: - _RTEMS_Unlock_allocator(); - break; - default: - break; + switch (cmd) { + case RTEMS_RTL_ALLOC_NEW: + *address = malloc(size); + break; + case RTEMS_RTL_ALLOC_DEL: + free(*address); + *address = NULL; + break; + case RTEMS_RTL_ALLOC_RESIZE: + *address = realloc(*address, size); + break; + case RTEMS_RTL_ALLOC_LOCK: + _RTEMS_Lock_allocator(); + break; + case RTEMS_RTL_ALLOC_UNLOCK: + _RTEMS_Unlock_allocator(); + break; + default: + break; } } diff --git a/cpukit/libdl/rtl-alloc-heap.h b/cpukit/libdl/rtl-alloc-heap.h index e3990b9f70..041efc8c7a 100644 --- a/cpukit/libdl/rtl-alloc-heap.h +++ b/cpukit/libdl/rtl-alloc-heap.h @@ -33,7 +33,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#if !defined (_RTEMS_RTL_ALLOC_HEAP_H_) +#if !defined(_RTEMS_RTL_ALLOC_HEAP_H_) #define _RTEMS_RTL_ALLOC_HEAP_H_ #include @@ -55,10 +55,8 @@ extern "C" { * @param size The size of the allocation if an allocation request and * not used if deleting or freeing a previous allocation. */ -void rtems_rtl_alloc_heap(rtems_rtl_alloc_cmd cmd, - rtems_rtl_alloc_tag tag, - void** address, - size_t size); +void rtems_rtl_alloc_heap(rtems_rtl_alloc_cmd cmd, rtems_rtl_alloc_tag tag, + void** address, size_t size); #ifdef __cplusplus } diff --git a/cpukit/libdl/rtl-allocator.c b/cpukit/libdl/rtl-allocator.c index 5519ea69a8..4e0558dd87 100644 --- a/cpukit/libdl/rtl-allocator.c +++ b/cpukit/libdl/rtl-allocator.c @@ -36,86 +36,71 @@ #include #include -#include #include "rtl-alloc-heap.h" #include +#include /** * Tags as symbols for tracing. */ #if RTEMS_RTL_TRACE -static const char* tag_labels[6] = -{ - "OBJECT", - "SYMBOL", - "EXTERNAL", - "READ", - "READ_WRITE", - "READ_EXEC", +static const char* tag_labels[6] = { + "OBJECT", "SYMBOL", "EXTERNAL", "READ", "READ_WRITE", "READ_EXEC", }; #define rtems_rtl_trace_tag_label(_l) tag_labels[_l] #else #define rtems_rtl_trace_tag_label(_l) "" #endif -void -rtems_rtl_alloc_initialise (rtems_rtl_alloc_data* data) -{ +void rtems_rtl_alloc_initialise(rtems_rtl_alloc_data* data) { size_t c; data->allocator = rtems_rtl_alloc_heap; for (c = 0; c < RTEMS_RTL_ALLOC_TAGS; ++c) - rtems_chain_initialize_empty (&data->indirects[c]); + rtems_chain_initialize_empty(&data->indirects[c]); } -void* -rtems_rtl_alloc_new (rtems_rtl_alloc_tag tag, size_t size, bool zero) -{ - rtems_rtl_data* rtl = rtems_rtl_lock (); - void* address = NULL; +void* rtems_rtl_alloc_new(rtems_rtl_alloc_tag tag, size_t size, bool zero) { + rtems_rtl_data* rtl = rtems_rtl_lock(); + void* address = NULL; /* * Obtain memory from the allocator. The address field is set by the * allocator. */ if (rtl != NULL) - rtl->allocator.allocator (RTEMS_RTL_ALLOC_NEW, tag, &address, size); + rtl->allocator.allocator(RTEMS_RTL_ALLOC_NEW, tag, &address, size); - rtems_rtl_unlock (); + rtems_rtl_unlock(); - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ALLOCATOR)) - printf ("rtl: alloc: new: %s addr=%p size=%zu\n", - rtems_rtl_trace_tag_label (tag), address, size); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ALLOCATOR)) + printf("rtl: alloc: new: %s addr=%p size=%zu\n", + rtems_rtl_trace_tag_label(tag), address, size); /* * Only zero the memory if asked to and the allocation was successful. */ if (address != NULL && zero) - memset (address, 0, size); + memset(address, 0, size); return address; } -void -rtems_rtl_alloc_del (rtems_rtl_alloc_tag tag, void* address) -{ - rtems_rtl_data* rtl = rtems_rtl_lock (); +void rtems_rtl_alloc_del(rtems_rtl_alloc_tag tag, void* address) { + rtems_rtl_data* rtl = rtems_rtl_lock(); - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ALLOCATOR)) - printf ("rtl: alloc: del: %s addr=%p\n", - rtems_rtl_trace_tag_label (tag), address); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ALLOCATOR)) + printf("rtl: alloc: del: %s addr=%p\n", rtems_rtl_trace_tag_label(tag), + address); if (rtl != NULL && address != NULL) - rtl->allocator.allocator (RTEMS_RTL_ALLOC_DEL, tag, &address, 0); + rtl->allocator.allocator(RTEMS_RTL_ALLOC_DEL, tag, &address, 0); - rtems_rtl_unlock (); + rtems_rtl_unlock(); } -void* rtems_rtl_alloc_resize (rtems_rtl_alloc_tag tag, - void* address, - size_t size, - bool zero) -{ - rtems_rtl_data* rtl = rtems_rtl_lock (); +void* rtems_rtl_alloc_resize(rtems_rtl_alloc_tag tag, void* address, + size_t size, bool zero) { + rtems_rtl_data* rtl = rtems_rtl_lock(); const void* prev_address = address; /* @@ -123,14 +108,15 @@ void* rtems_rtl_alloc_resize (rtems_rtl_alloc_tag tag, * by the allocator and may change. */ if (rtl != NULL) - rtl->allocator.allocator (RTEMS_RTL_ALLOC_RESIZE, tag, &address, size); + rtl->allocator.allocator(RTEMS_RTL_ALLOC_RESIZE, tag, &address, size); - rtems_rtl_unlock (); + rtems_rtl_unlock(); - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ALLOCATOR)) - printf ("rtl: alloc: resize: %s%s prev-addr=%p addr=%p size=%zu\n", - rtems_rtl_trace_tag_label (tag), prev_address == address ? "" : " MOVED", - prev_address, address, size); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ALLOCATOR)) + printf("rtl: alloc: resize: %s%s prev-addr=%p addr=%p size=%zu\n", + rtems_rtl_trace_tag_label(tag), + prev_address == address ? "" : " MOVED", prev_address, address, + size); /* * Only zero the memory if asked to and the resize was successful. We @@ -138,232 +124,179 @@ void* rtems_rtl_alloc_resize (rtems_rtl_alloc_tag tag, * because we do not have the original size. */ if (address != NULL && zero) - memset (address, 0, size); + memset(address, 0, size); return address; } -void -rtems_rtl_alloc_wr_enable (rtems_rtl_alloc_tag tag, void* address) -{ - rtems_rtl_data* rtl = rtems_rtl_lock (); +void rtems_rtl_alloc_wr_enable(rtems_rtl_alloc_tag tag, void* address) { + rtems_rtl_data* rtl = rtems_rtl_lock(); - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ALLOCATOR)) - printf ("rtl: alloc: wr-enable: addr=%p\n", address); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ALLOCATOR)) + printf("rtl: alloc: wr-enable: addr=%p\n", address); if (rtl != NULL && address != NULL) - rtl->allocator.allocator (RTEMS_RTL_ALLOC_WR_ENABLE, - tag, - address, - 0); + rtl->allocator.allocator(RTEMS_RTL_ALLOC_WR_ENABLE, tag, address, 0); - rtems_rtl_unlock (); + rtems_rtl_unlock(); } -void -rtems_rtl_alloc_lock (void) -{ - rtems_rtl_data* rtl = rtems_rtl_lock (); +void rtems_rtl_alloc_lock(void) { + rtems_rtl_data* rtl = rtems_rtl_lock(); - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ALLOCATOR)) - printf ("rtl: alloc: lock\n"); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ALLOCATOR)) + printf("rtl: alloc: lock\n"); if (rtl != NULL) - rtl->allocator.allocator (RTEMS_RTL_ALLOC_LOCK, - RTEMS_RTL_ALLOC_OBJECT, /* should be ignored */ - NULL, - 0); + rtl->allocator.allocator(RTEMS_RTL_ALLOC_LOCK, + RTEMS_RTL_ALLOC_OBJECT, /* should be ignored */ + NULL, 0); - rtems_rtl_unlock (); + rtems_rtl_unlock(); } +void rtems_rtl_alloc_unlock(void) { + rtems_rtl_data* rtl = rtems_rtl_lock(); -void -rtems_rtl_alloc_unlock (void) -{ - rtems_rtl_data* rtl = rtems_rtl_lock (); - - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ALLOCATOR)) - printf ("rtl: alloc: unlock\n"); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ALLOCATOR)) + printf("rtl: alloc: unlock\n"); if (rtl != NULL) - rtl->allocator.allocator (RTEMS_RTL_ALLOC_UNLOCK, - RTEMS_RTL_ALLOC_OBJECT, /* should be ignored */ - NULL, - 0); + rtl->allocator.allocator(RTEMS_RTL_ALLOC_UNLOCK, + RTEMS_RTL_ALLOC_OBJECT, /* should be ignored */ + NULL, 0); - rtems_rtl_unlock (); + rtems_rtl_unlock(); } -void -rtems_rtl_alloc_wr_disable (rtems_rtl_alloc_tag tag, void* address) -{ - rtems_rtl_data* rtl = rtems_rtl_lock (); +void rtems_rtl_alloc_wr_disable(rtems_rtl_alloc_tag tag, void* address) { + rtems_rtl_data* rtl = rtems_rtl_lock(); - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ALLOCATOR)) - printf ("rtl: alloc: wr-disable: addr=%p\n", address); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ALLOCATOR)) + printf("rtl: alloc: wr-disable: addr=%p\n", address); if (rtl != NULL && address != NULL) - rtl->allocator.allocator (RTEMS_RTL_ALLOC_WR_DISABLE, - tag, - address, - 0); + rtl->allocator.allocator(RTEMS_RTL_ALLOC_WR_DISABLE, tag, address, 0); - rtems_rtl_unlock (); + rtems_rtl_unlock(); } -rtems_rtl_allocator -rtems_rtl_alloc_hook (rtems_rtl_allocator handler) -{ - rtems_rtl_data* rtl = rtems_rtl_lock (); +rtems_rtl_allocator rtems_rtl_alloc_hook(rtems_rtl_allocator handler) { + rtems_rtl_data* rtl = rtems_rtl_lock(); rtems_rtl_allocator previous = rtl->allocator.allocator; rtl->allocator.allocator = handler; - rtems_rtl_unlock (); + rtems_rtl_unlock(); return previous; } -void -rtems_rtl_alloc_indirect_new (rtems_rtl_alloc_tag tag, - rtems_rtl_ptr* handle, - size_t size) -{ - rtems_rtl_data* rtl = rtems_rtl_lock (); +void rtems_rtl_alloc_indirect_new(rtems_rtl_alloc_tag tag, + rtems_rtl_ptr* handle, size_t size) { + rtems_rtl_data* rtl = rtems_rtl_lock(); - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ALLOCATOR)) - { - if (!rtems_rtl_ptr_null (handle)) - printf ("rtl: alloc: inew: %s handle=%p: not null\n", - rtems_rtl_trace_tag_label (tag), handle); - printf ("rtl: alloc: inew: %s handle=%p size=%zd\n", - rtems_rtl_trace_tag_label (tag), handle, size); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ALLOCATOR)) { + if (!rtems_rtl_ptr_null(handle)) + printf("rtl: alloc: inew: %s handle=%p: not null\n", + rtems_rtl_trace_tag_label(tag), handle); + printf("rtl: alloc: inew: %s handle=%p size=%zd\n", + rtems_rtl_trace_tag_label(tag), handle, size); } - if (rtl) - { + if (rtl) { rtems_rtl_alloc_data* allocator = &rtl->allocator; - handle->pointer = rtems_rtl_alloc_new (tag, size, false); - if (!rtems_rtl_ptr_null (handle)) - rtems_chain_append_unprotected (&allocator->indirects[tag], - &handle->node); + handle->pointer = rtems_rtl_alloc_new(tag, size, false); + if (!rtems_rtl_ptr_null(handle)) + rtems_chain_append_unprotected(&allocator->indirects[tag], &handle->node); } - rtems_rtl_unlock (); + rtems_rtl_unlock(); } -void -rtems_rtl_alloc_indirect_del (rtems_rtl_alloc_tag tag, - rtems_rtl_ptr* handle) -{ - rtems_rtl_data* rtl = rtems_rtl_lock (); +void rtems_rtl_alloc_indirect_del(rtems_rtl_alloc_tag tag, + rtems_rtl_ptr* handle) { + rtems_rtl_data* rtl = rtems_rtl_lock(); - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ALLOCATOR)) - { - if (rtems_rtl_ptr_null (handle)) - printf ("rtl: alloc: idel: %s handle=%p: is null\n", - rtems_rtl_trace_tag_label (tag), handle); - printf ("rtl: alloc: idel: %s handle=%p\n", - rtems_rtl_trace_tag_label (tag), handle); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ALLOCATOR)) { + if (rtems_rtl_ptr_null(handle)) + printf("rtl: alloc: idel: %s handle=%p: is null\n", + rtems_rtl_trace_tag_label(tag), handle); + printf("rtl: alloc: idel: %s handle=%p\n", rtems_rtl_trace_tag_label(tag), + handle); } - if (rtl && !rtems_rtl_ptr_null (handle)) - { - rtems_chain_extract_unprotected (&handle->node); - rtems_rtl_alloc_del (tag, &handle->pointer); + if (rtl && !rtems_rtl_ptr_null(handle)) { + rtems_chain_extract_unprotected(&handle->node); + rtems_rtl_alloc_del(tag, &handle->pointer); } } -rtems_rtl_alloc_tag -rtems_rtl_alloc_text_tag (void) -{ +rtems_rtl_alloc_tag rtems_rtl_alloc_text_tag(void) { return RTEMS_RTL_ALLOC_READ_EXEC; } -rtems_rtl_alloc_tag -rtems_rtl_alloc_const_tag (void) -{ +rtems_rtl_alloc_tag rtems_rtl_alloc_const_tag(void) { return RTEMS_RTL_ALLOC_READ; } -rtems_rtl_alloc_tag -rtems_rtl_alloc_eh_tag (void) -{ +rtems_rtl_alloc_tag rtems_rtl_alloc_eh_tag(void) { return RTEMS_RTL_ALLOC_READ; } -rtems_rtl_alloc_tag -rtems_rtl_alloc_data_tag (void) -{ +rtems_rtl_alloc_tag rtems_rtl_alloc_data_tag(void) { return RTEMS_RTL_ALLOC_READ_WRITE; } -rtems_rtl_alloc_tag -rtems_rtl_alloc_bss_tag (void) -{ +rtems_rtl_alloc_tag rtems_rtl_alloc_bss_tag(void) { return RTEMS_RTL_ALLOC_READ_WRITE; } -bool -rtems_rtl_alloc_module_new (void** text_base, size_t text_size, - void** const_base, size_t const_size, - void** eh_base, size_t eh_size, - void** data_base, size_t data_size, - void** bss_base, size_t bss_size) -{ +bool rtems_rtl_alloc_module_new(void** text_base, size_t text_size, + void** const_base, size_t const_size, + void** eh_base, size_t eh_size, + void** data_base, size_t data_size, + void** bss_base, size_t bss_size) { *text_base = *const_base = *data_base = *bss_base = NULL; - if (data_size != 0) - { - *data_base = rtems_rtl_alloc_new (rtems_rtl_alloc_data_tag (), - data_size, false); - if (*data_base == NULL) - { - rtems_rtl_alloc_module_del (text_base, const_base, eh_base, - data_base, bss_base); + if (data_size != 0) { + *data_base = + rtems_rtl_alloc_new(rtems_rtl_alloc_data_tag(), data_size, false); + if (*data_base == NULL) { + rtems_rtl_alloc_module_del(text_base, const_base, eh_base, data_base, + bss_base); return false; } } - if (bss_size != 0) - { - *bss_base = rtems_rtl_alloc_new (rtems_rtl_alloc_bss_tag (), - bss_size, false); - if (*bss_base == NULL) - { - rtems_rtl_alloc_module_del (text_base, const_base, eh_base, - data_base, bss_base); + if (bss_size != 0) { + *bss_base = rtems_rtl_alloc_new(rtems_rtl_alloc_bss_tag(), bss_size, false); + if (*bss_base == NULL) { + rtems_rtl_alloc_module_del(text_base, const_base, eh_base, data_base, + bss_base); return false; } } - if (eh_size != 0) - { - *eh_base = rtems_rtl_alloc_new (rtems_rtl_alloc_eh_tag (), - eh_size, false); - if (*eh_base == NULL) - { - rtems_rtl_alloc_module_del (text_base, const_base, eh_base, - data_base, bss_base); + if (eh_size != 0) { + *eh_base = rtems_rtl_alloc_new(rtems_rtl_alloc_eh_tag(), eh_size, false); + if (*eh_base == NULL) { + rtems_rtl_alloc_module_del(text_base, const_base, eh_base, data_base, + bss_base); return false; } } - if (const_size != 0) - { - *const_base = rtems_rtl_alloc_new (rtems_rtl_alloc_const_tag (), - const_size, false); - if (*const_base == NULL) - { - rtems_rtl_alloc_module_del (text_base, const_base, eh_base, - data_base, bss_base); + if (const_size != 0) { + *const_base = + rtems_rtl_alloc_new(rtems_rtl_alloc_const_tag(), const_size, false); + if (*const_base == NULL) { + rtems_rtl_alloc_module_del(text_base, const_base, eh_base, data_base, + bss_base); return false; } } - if (text_size != 0) - { - *text_base = rtems_rtl_alloc_new (rtems_rtl_alloc_text_tag (), - text_size, false); - if (*text_base == NULL) - { + if (text_size != 0) { + *text_base = + rtems_rtl_alloc_new(rtems_rtl_alloc_text_tag(), text_size, false); + if (*text_base == NULL) { return false; } } @@ -371,59 +304,47 @@ rtems_rtl_alloc_module_new (void** text_base, size_t text_size, return true; } -bool -rtems_rtl_alloc_module_resize (void** text_base, size_t text_size, - void** const_base, size_t const_size, - void** eh_base, size_t eh_size, - void** data_base, size_t data_size, - void** bss_base, size_t bss_size) -{ - if (data_size != 0) - { - *data_base = rtems_rtl_alloc_resize (rtems_rtl_alloc_data_tag (), - *data_base, data_size, false); - if (*data_base == NULL) - { +bool rtems_rtl_alloc_module_resize(void** text_base, size_t text_size, + void** const_base, size_t const_size, + void** eh_base, size_t eh_size, + void** data_base, size_t data_size, + void** bss_base, size_t bss_size) { + if (data_size != 0) { + *data_base = rtems_rtl_alloc_resize(rtems_rtl_alloc_data_tag(), *data_base, + data_size, false); + if (*data_base == NULL) { return false; } } - if (bss_size != 0) - { - *bss_base = rtems_rtl_alloc_resize (rtems_rtl_alloc_bss_tag (), - *bss_base, bss_size, false); - if (*bss_base == NULL) - { + if (bss_size != 0) { + *bss_base = rtems_rtl_alloc_resize(rtems_rtl_alloc_bss_tag(), *bss_base, + bss_size, false); + if (*bss_base == NULL) { return false; } } - if (eh_size != 0) - { - *eh_base = rtems_rtl_alloc_resize (rtems_rtl_alloc_eh_tag (), - *eh_base, eh_size, false); - if (*eh_base == NULL) - { + if (eh_size != 0) { + *eh_base = rtems_rtl_alloc_resize(rtems_rtl_alloc_eh_tag(), *eh_base, + eh_size, false); + if (*eh_base == NULL) { return false; } } - if (const_size != 0) - { - *const_base = rtems_rtl_alloc_resize (rtems_rtl_alloc_const_tag (), - *const_base, const_size, false); - if (*const_base == NULL) - { + if (const_size != 0) { + *const_base = rtems_rtl_alloc_resize(rtems_rtl_alloc_const_tag(), + *const_base, const_size, false); + if (*const_base == NULL) { return false; } } - if (text_size != 0) - { - *text_base = rtems_rtl_alloc_resize (rtems_rtl_alloc_text_tag (), - *text_base, text_size, false); - if (*text_base == NULL) - { + if (text_size != 0) { + *text_base = rtems_rtl_alloc_resize(rtems_rtl_alloc_text_tag(), *text_base, + text_size, false); + if (*text_base == NULL) { return false; } } @@ -431,17 +352,13 @@ rtems_rtl_alloc_module_resize (void** text_base, size_t text_size, return true; } -void -rtems_rtl_alloc_module_del (void** text_base, - void** const_base, - void** eh_base, - void** data_base, - void** bss_base) -{ - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_READ_WRITE, *bss_base); - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_READ_WRITE, *data_base); - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_READ, *eh_base); - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_READ, *const_base); - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_READ_EXEC, *text_base); +void rtems_rtl_alloc_module_del(void** text_base, void** const_base, + void** eh_base, void** data_base, + void** bss_base) { + rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_READ_WRITE, *bss_base); + rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_READ_WRITE, *data_base); + rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_READ, *eh_base); + rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_READ, *const_base); + rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_READ_EXEC, *text_base); *text_base = *const_base = *eh_base = *data_base = *bss_base = NULL; } diff --git a/cpukit/libdl/rtl-archive.c b/cpukit/libdl/rtl-archive.c index 0e79a86b89..5656698ae2 100644 --- a/cpukit/libdl/rtl-archive.c +++ b/cpukit/libdl/rtl-archive.c @@ -47,33 +47,31 @@ #include -#include #include "rtl-chain-iterator.h" -#include -#include "rtl-string.h" #include "rtl-error.h" +#include "rtl-string.h" +#include +#include /** * Archive headers. */ -#define RTEMS_RTL_AR_IDENT "!\n" -#define RTEMS_RTL_AR_IDENT_SIZE (sizeof (RTEMS_RTL_AR_IDENT) - 1) -#define RTEMS_RTL_AR_FHDR_BASE RTEMS_RTL_AR_IDENT_SIZE -#define RTEMS_RTL_AR_FNAME (0) +#define RTEMS_RTL_AR_IDENT "!\n" +#define RTEMS_RTL_AR_IDENT_SIZE (sizeof(RTEMS_RTL_AR_IDENT) - 1) +#define RTEMS_RTL_AR_FHDR_BASE RTEMS_RTL_AR_IDENT_SIZE +#define RTEMS_RTL_AR_FNAME (0) #define RTEMS_RTL_AR_FNAME_SIZE (16) -#define RTEMS_RTL_AR_SIZE (48) -#define RTEMS_RTL_AR_SIZE_SIZE (10) -#define RTEMS_RTL_AR_MAGIC (58) +#define RTEMS_RTL_AR_SIZE (48) +#define RTEMS_RTL_AR_SIZE_SIZE (10) +#define RTEMS_RTL_AR_MAGIC (58) #define RTEMS_RTL_AR_MAGIC_SIZE (2) -#define RTEMS_RTL_AR_FHDR_SIZE (60) +#define RTEMS_RTL_AR_FHDR_SIZE (60) /** * Read a 32bit value from the symbol table. */ -static unsigned int -rtems_rtl_archive_read_32 (void* data) -{ - uint8_t* b = (uint8_t*) data; +static unsigned int rtems_rtl_archive_read_32(void* data) { + uint8_t* b = (uint8_t*)data; unsigned int v = b[0]; v = (v << 8) | b[1]; v = (v << 8) | b[2]; @@ -81,20 +79,15 @@ rtems_rtl_archive_read_32 (void* data) return v; } -static void -rtems_rtl_archive_set_error (int num, const char* text) -{ - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: error: %3d: %s\n", num, text); +static void rtems_rtl_archive_set_error(int num, const char* text) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: error: %3d: %s\n", num, text); } -static uint64_t -rtems_rtl_scan_decimal (const uint8_t* string, size_t len) -{ +static uint64_t rtems_rtl_scan_decimal(const uint8_t* string, size_t len) { uint64_t value = 0; - while (len && (*string != ' ')) - { + while (len && (*string != ' ')) { value *= 10; value += *string - '0'; ++string; @@ -104,12 +97,11 @@ rtems_rtl_scan_decimal (const uint8_t* string, size_t len) return value; } -static bool -rtems_rtl_seek_read (int fd, off_t off, size_t len, uint8_t* buffer) -{ - if (lseek (fd, off, SEEK_SET) < 0) +static bool rtems_rtl_seek_read(int fd, off_t off, size_t len, + uint8_t* buffer) { + if (lseek(fd, off, SEEK_SET) < 0) return false; - if (read (fd, buffer, len) != (ssize_t)len) + if (read(fd, buffer, len) != (ssize_t)len) return false; return true; } @@ -117,69 +109,56 @@ rtems_rtl_seek_read (int fd, off_t off, size_t len, uint8_t* buffer) /** * Archive iterator. */ -typedef bool (*rtems_rtl_archive_iterator) (rtems_rtl_archive* archive, - void* data); +typedef bool (*rtems_rtl_archive_iterator)(rtems_rtl_archive* archive, + void* data); /** * Chain iterator data. */ -typedef struct rtems_rtl_archive_chain_data -{ - void* data; /**< User's data. */ - rtems_rtl_archive_iterator iterator; /**< The actual iterator. */ +typedef struct rtems_rtl_archive_chain_data { + void* data; /**< User's data. */ + rtems_rtl_archive_iterator iterator; /**< The actual iterator. */ } rtems_rtl_archive_chain_data; -static bool -rtems_rtl_archive_node_iterator (rtems_chain_node* node, void* data) -{ - rtems_rtl_archive* archive; +static bool rtems_rtl_archive_node_iterator(rtems_chain_node* node, + void* data) { + rtems_rtl_archive* archive; rtems_rtl_archive_chain_data* chain_data; - archive = (rtems_rtl_archive*) node; - chain_data = (rtems_rtl_archive_chain_data*) data; - return chain_data->iterator (archive, chain_data->data); + archive = (rtems_rtl_archive*)node; + chain_data = (rtems_rtl_archive_chain_data*)data; + return chain_data->iterator(archive, chain_data->data); } static void -rtems_rtl_archive_iterate_archives (rtems_rtl_archives* archives, - rtems_rtl_archive_iterator iterator, - void* data) -{ - rtems_rtl_archive_chain_data chain_data = { - .data = data, - .iterator = iterator - }; - rtems_rtl_chain_iterate (&archives->archives, - rtems_rtl_archive_node_iterator, - &chain_data); +rtems_rtl_archive_iterate_archives(rtems_rtl_archives* archives, + rtems_rtl_archive_iterator iterator, + void* data) { + rtems_rtl_archive_chain_data chain_data = {.data = data, + .iterator = iterator}; + rtems_rtl_chain_iterate(&archives->archives, rtems_rtl_archive_node_iterator, + &chain_data); } -static bool -rtems_rtl_rchive_name_end (const char c) -{ +static bool rtems_rtl_rchive_name_end(const char c) { return c == '\0' || c == '\n' || c == '/'; } -static const char* -rtems_rtl_archive_dup_name (const char* name) -{ +static const char* rtems_rtl_archive_dup_name(const char* name) { size_t len = 0; - char* dup; - while (!rtems_rtl_rchive_name_end (name[len])) + char* dup; + while (!rtems_rtl_rchive_name_end(name[len])) ++len; - dup = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, len + 1, true); + dup = rtems_rtl_alloc_new(RTEMS_RTL_ALLOC_OBJECT, len + 1, true); if (dup != NULL) - memcpy (dup, name, len); + memcpy(dup, name, len); return dup; } -static bool -rtems_rtl_archive_match_name (const char* file_name, const char* name) -{ - if (name != NULL) - { - while (!rtems_rtl_rchive_name_end (*file_name) && - !rtems_rtl_rchive_name_end (*name) && *file_name == *name) - { +static bool rtems_rtl_archive_match_name(const char* file_name, + const char* name) { + if (name != NULL) { + while (!rtems_rtl_rchive_name_end(*file_name) && + !rtems_rtl_rchive_name_end(*name) && *file_name == *name) { ++file_name; ++name; } @@ -190,44 +169,32 @@ rtems_rtl_archive_match_name (const char* file_name, const char* name) return false; } -static bool -rtems_rtl_archive_set_flags (rtems_rtl_archive* archive, void* data) -{ - uint32_t mask = *((uint32_t*) data); +static bool rtems_rtl_archive_set_flags(rtems_rtl_archive* archive, + void* data) { + uint32_t mask = *((uint32_t*)data); archive->flags |= mask; return true; } -typedef struct rtems_rtl_archive_find_data -{ +typedef struct rtems_rtl_archive_find_data { rtems_rtl_archive* archive; - const char* path; + const char* path; } rtems_rtl_archive_find_data; -static bool -rtems_rtl_archive_finder (rtems_rtl_archive* archive, void* data) -{ +static bool rtems_rtl_archive_finder(rtems_rtl_archive* archive, void* data) { rtems_rtl_archive_find_data* find; - find = (rtems_rtl_archive_find_data*) data; - if (strcmp (find->path, archive->name) == 0) - { + find = (rtems_rtl_archive_find_data*)data; + if (strcmp(find->path, archive->name) == 0) { find->archive = archive; return false; } return true; } -static rtems_rtl_archive* -rtems_rtl_archive_find (rtems_rtl_archives* archives, - const char* path) -{ - rtems_rtl_archive_find_data find = { - .archive = NULL, - .path = path - }; - rtems_rtl_archive_iterate_archives (archives, - rtems_rtl_archive_finder, - &find); +static rtems_rtl_archive* rtems_rtl_archive_find(rtems_rtl_archives* archives, + const char* path) { + rtems_rtl_archive_find_data find = {.archive = NULL, .path = path}; + rtems_rtl_archive_iterate_archives(archives, rtems_rtl_archive_finder, &find); return find.archive; } @@ -253,77 +220,62 @@ rtems_rtl_archive_find (rtems_rtl_archives* archives, * Note: The loading of an object file from an archive uses an offset in the * file name to speed the loading. */ -typedef struct rtems_rtl_archive_obj_data -{ - const char* symbol; /**< The symbol to search for. */ - rtems_rtl_archive* archive; /**< The archive the symbol is found - * in. */ - off_t offset; /**< The offset in the archive if found - * else 0 */ +typedef struct rtems_rtl_archive_obj_data { + const char* symbol; /**< The symbol to search for. */ + rtems_rtl_archive* archive; /**< The archive the symbol is found + * in. */ + off_t offset; /**< The offset in the archive if found + * else 0 */ } rtems_rtl_archive_obj_data; -static int -rtems_rtl_archive_symbol_compare (const void* a, const void* b) -{ +static int rtems_rtl_archive_symbol_compare(const void* a, const void* b) { const rtems_rtl_archive_symbol* sa; const rtems_rtl_archive_symbol* sb; - sa = (const rtems_rtl_archive_symbol*) a; - sb = (const rtems_rtl_archive_symbol*) b; - return strcmp (sa->label, sb->label); + sa = (const rtems_rtl_archive_symbol*)a; + sb = (const rtems_rtl_archive_symbol*)b; + return strcmp(sa->label, sb->label); } -static bool -rtems_rtl_archive_obj_finder (rtems_rtl_archive* archive, void* data) -{ +static bool rtems_rtl_archive_obj_finder(rtems_rtl_archive* archive, + void* data) { const rtems_rtl_archive_symbols* symbols = &archive->symbols; - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: finder: %s: entries: %zu\n", - archive->name, symbols->entries); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: finder: %s: entries: %zu\n", archive->name, + symbols->entries); /* * Make sure there is a valid symbol table. */ - if (symbols->base != NULL) - { + if (symbols->base != NULL) { /* * Perform a linear search if there is no sorted symbol table. */ - rtems_rtl_archive_obj_data* search = (rtems_rtl_archive_obj_data*) data; - if (symbols->symbols == NULL) - { + rtems_rtl_archive_obj_data* search = (rtems_rtl_archive_obj_data*)data; + if (symbols->symbols == NULL) { const char* symbol = symbols->names; - size_t entry; - for (entry = 0; entry < symbols->entries; ++entry) - { - if (strcmp (search->symbol, symbol) == 0) - { + size_t entry; + for (entry = 0; entry < symbols->entries; ++entry) { + if (strcmp(search->symbol, symbol) == 0) { search->archive = archive; search->offset = - rtems_rtl_archive_read_32 (symbols->base + ((entry + 1) * 4)); + rtems_rtl_archive_read_32(symbols->base + ((entry + 1) * 4)); return false; } - symbol += strlen (symbol) + 1; + symbol += strlen(symbol) + 1; } - } - else - { - rtems_rtl_archive_symbol* match; - const rtems_rtl_archive_symbol key = { - .entry = -1, - .label = search->symbol - }; - match = bsearch (&key, - symbols->symbols, - symbols->entries, - sizeof (symbols->symbols[0]), - rtems_rtl_archive_symbol_compare); - if (match != NULL) - { - search->archive = archive; - search->offset = - rtems_rtl_archive_read_32 (symbols->base + (match->entry * 4)); - return false; + } else { + rtems_rtl_archive_symbol* match; + const rtems_rtl_archive_symbol key = {.entry = -1, + .label = search->symbol}; + match = bsearch(&key, symbols->symbols, symbols->entries, + sizeof(symbols->symbols[0]), + rtems_rtl_archive_symbol_compare); + if (match != NULL) { + search->archive = archive; + search->offset = + rtems_rtl_archive_read_32(symbols->base + (match->entry * 4)); + return false; } } } @@ -334,89 +286,73 @@ rtems_rtl_archive_obj_finder (rtems_rtl_archive* archive, void* data) return true; } -static rtems_rtl_archive* -rtems_rtl_archive_new (rtems_rtl_archives* archives, - const char* path, - const char* name) -{ - (void) archives; +static rtems_rtl_archive* rtems_rtl_archive_new(rtems_rtl_archives* archives, + const char* path, + const char* name) { + (void)archives; rtems_rtl_archive* archive; - size_t path_size; - size_t size; + size_t path_size; + size_t size; /* * Handle the case of the path being just '/', do not create '//'. */ - path_size = strlen (path); - size = sizeof(rtems_rtl_archive) + path_size + strlen (name) + 1; + path_size = strlen(path); + size = sizeof(rtems_rtl_archive) + path_size + strlen(name) + 1; if (path_size > 1) ++size; - archive = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, size, true); - if (archive == NULL) - { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: new: %s: no memory\n", name); - } - else - { + archive = rtems_rtl_alloc_new(RTEMS_RTL_ALLOC_OBJECT, size, true); + if (archive == NULL) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: new: %s: no memory\n", name); + } else { char* aname; - archive->name = ((const char*) archive) + sizeof(rtems_rtl_archive); - aname = (char*) archive->name; - strcpy (aname, path); + archive->name = ((const char*)archive) + sizeof(rtems_rtl_archive); + aname = (char*)archive->name; + strcpy(aname, path); if (path_size > 1) - strcat (aname, "/"); - strcat (aname, name); - rtems_chain_set_off_chain (&archive->node); + strcat(aname, "/"); + strcat(aname, name); + rtems_chain_set_off_chain(&archive->node); archive->flags |= RTEMS_RTL_ARCHIVE_LOAD; } return archive; } -static void -rtems_rtl_archive_del (rtems_rtl_archive* archive) -{ - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: del: %s\n", archive->name); - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_SYMBOL, archive->symbols.base); - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_SYMBOL, archive->symbols.symbols); - if (!rtems_chain_is_node_off_chain (&archive->node)) - rtems_chain_extract (&archive->node); - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, archive); +static void rtems_rtl_archive_del(rtems_rtl_archive* archive) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: del: %s\n", archive->name); + rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_SYMBOL, archive->symbols.base); + rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_SYMBOL, archive->symbols.symbols); + if (!rtems_chain_is_node_off_chain(&archive->node)) + rtems_chain_extract(&archive->node); + rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_OBJECT, archive); } -static rtems_rtl_archive* -rtems_rtl_archive_get (rtems_rtl_archives* archives, - const char* path, - const char* name) -{ +static rtems_rtl_archive* rtems_rtl_archive_get(rtems_rtl_archives* archives, + const char* path, + const char* name) { rtems_rtl_archive* archive; /* * Getting a new archive turns the path and name into a single path the stat * function can use. No matter how you try some memory is needed so it is * easier to get a new archive object and delete it if it exists. */ - archive = rtems_rtl_archive_new (archives, path, name); - if (archive != NULL) - { + archive = rtems_rtl_archive_new(archives, path, name); + if (archive != NULL) { struct stat sb; - if (stat (archive->name, &sb) == 0) - { - if (S_ISREG (sb.st_mode)) - { + if (stat(archive->name, &sb) == 0) { + if (S_ISREG(sb.st_mode)) { rtems_rtl_archive* find_archive; - find_archive = rtems_rtl_archive_find (archives, archive->name); - if (find_archive == NULL) - { - rtems_chain_append (&archives->archives, &archive->node); - } - else - { - rtems_rtl_archive_del (archive); + find_archive = rtems_rtl_archive_find(archives, archive->name); + if (find_archive == NULL) { + rtems_chain_append(&archives->archives, &archive->node); + } else { + rtems_rtl_archive_del(archive); archive = find_archive; } archive->flags &= ~RTEMS_RTL_ARCHIVE_REMOVE; - if (archive->mtime != sb.st_mtime) - { + if (archive->mtime != sb.st_mtime) { archive->flags |= RTEMS_RTL_ARCHIVE_LOAD; archive->size = sb.st_size; archive->mtime = sb.st_mtime; @@ -427,86 +363,77 @@ rtems_rtl_archive_get (rtems_rtl_archives* archives, return archive; } -static bool -rtems_rtl_archives_load_config (rtems_rtl_archives* archives) -{ +static bool rtems_rtl_archives_load_config(rtems_rtl_archives* archives) { struct stat sb; - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: config load: %s\n", archives->config_name); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: config load: %s\n", archives->config_name); if (archives->config_name == NULL) return false; - if (stat (archives->config_name, &sb) < 0) - { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: no config: %s\n", archives->config_name); + if (stat(archives->config_name, &sb) < 0) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: no config: %s\n", archives->config_name); return false; } /* * If the configuration has change reload it. */ - if (sb.st_mtime != archives->config_mtime) - { - int fd; + if (sb.st_mtime != archives->config_mtime) { + int fd; ssize_t r; - char* s; - bool in_comment; + char* s; + bool in_comment; archives->config_mtime = sb.st_mtime; - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, (void*) archives->config); + rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_OBJECT, (void*)archives->config); archives->config_length = 0; archives->config = - rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, sb.st_size + 1, true); - if (archives->config == NULL) - { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: no memory for config\n"); + rtems_rtl_alloc_new(RTEMS_RTL_ALLOC_OBJECT, sb.st_size + 1, true); + if (archives->config == NULL) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: no memory for config\n"); return false; } - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: config load: read %s\n", archives->config_name); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: config load: read %s\n", archives->config_name); - fd = open (archives->config_name, O_RDONLY); - if (fd < 0) - { - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, (void*) archives->config); + fd = open(archives->config_name, O_RDONLY); + if (fd < 0) { + rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_OBJECT, (void*)archives->config); archives->config = NULL; archives->config_length = 0; - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: config open error: %s\n", strerror (errno)); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: config open error: %s\n", strerror(errno)); return false; } - r = read (fd, (void*) archives->config, sb.st_size); - if (r < 0) - { - close (fd); - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, (void*) archives->config); + r = read(fd, (void*)archives->config, sb.st_size); + if (r < 0) { + close(fd); + rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_OBJECT, (void*)archives->config); archives->config = NULL; archives->config_length = 0; - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: config read error: %s\n", strerror (errno)); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: config read error: %s\n", strerror(errno)); return false; } - close (fd); + close(fd); archives->config_length = r; /* * Remove comments. */ - s = (char*) archives->config; + s = (char*)archives->config; in_comment = false; - for (r = 0; r < archives->config_length; ++r, ++s) - { + for (r = 0; r < archives->config_length; ++r, ++s) { if (*s == '#') in_comment = true; - if (in_comment) - { + if (in_comment) { if (*s == '\n') in_comment = false; *s = '\0'; @@ -516,9 +443,8 @@ rtems_rtl_archives_load_config (rtems_rtl_archives* archives) /* * Create lines by turning '\r' and '\n' to '\0'. */ - s = (char*) archives->config; - for (r = 0; r < archives->config_length; ++r, ++s) - { + s = (char*)archives->config; + for (r = 0; r < archives->config_length; ++r, ++s) { if (*s == '\r' || *s == '\n') *s = '\0'; } @@ -526,26 +452,20 @@ rtems_rtl_archives_load_config (rtems_rtl_archives* archives) /* * Remove leading and trailing white space. */ - s = (char*) archives->config; + s = (char*)archives->config; r = 0; - while (r < archives->config_length) - { - if (s[r] == '\0') - { + while (r < archives->config_length) { + if (s[r] == '\0') { ++r; - } - else - { - size_t ls = strlen (&s[r]); + } else { + size_t ls = strlen(&s[r]); size_t b = 0; - while (b < ls && isspace ((unsigned char) s[r + b])) - { + while (b < ls && isspace((unsigned char)s[r + b])) { s[r + b] = '\0'; ++b; } b = ls - 1; - while (b > 0 && isspace ((unsigned char) s[r + b])) - { + while (b > 0 && isspace((unsigned char)s[r + b])) { s[r + b] = '\0'; --b; } @@ -553,18 +473,15 @@ rtems_rtl_archives_load_config (rtems_rtl_archives* archives) } } - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) { int line = 1; - printf ("rtl: archive: config:\n"); + printf("rtl: archive: config:\n"); r = 0; - while (r < archives->config_length) - { + while (r < archives->config_length) { const char* cs = &archives->config[r]; - size_t len = strlen (cs); - if (len > 0) - { - printf (" %3d: %s\n", line, cs); + size_t len = strlen(cs); + if (len > 0) { + printf(" %3d: %s\n", line, cs); ++line; } r += len + 1; @@ -575,108 +492,87 @@ rtems_rtl_archives_load_config (rtems_rtl_archives* archives) return true; } -void -rtems_rtl_archives_open (rtems_rtl_archives* archives, const char* config) -{ - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: open: %s\n", config); - memset (archives, 0, sizeof (rtems_rtl_archives)); - archives->config_name = rtems_rtl_strdup (config); - rtems_chain_initialize_empty (&archives->archives); +void rtems_rtl_archives_open(rtems_rtl_archives* archives, const char* config) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: open: %s\n", config); + memset(archives, 0, sizeof(rtems_rtl_archives)); + archives->config_name = rtems_rtl_strdup(config); + rtems_chain_initialize_empty(&archives->archives); } -void -rtems_rtl_archives_close (rtems_rtl_archives* archives) -{ +void rtems_rtl_archives_close(rtems_rtl_archives* archives) { rtems_chain_node* node; - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: close: count=%zu\n", - rtems_chain_node_count_unprotected (&archives->archives)); - node = rtems_chain_first (&archives->archives); - while (!rtems_chain_is_tail (&archives->archives, node)) - { - rtems_rtl_archive* archive = (rtems_rtl_archive*) node; - rtems_chain_node* next_node = rtems_chain_next (node); - rtems_rtl_archive_del (archive); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: close: count=%zu\n", + rtems_chain_node_count_unprotected(&archives->archives)); + node = rtems_chain_first(&archives->archives); + while (!rtems_chain_is_tail(&archives->archives, node)) { + rtems_rtl_archive* archive = (rtems_rtl_archive*)node; + rtems_chain_node* next_node = rtems_chain_next(node); + rtems_rtl_archive_del(archive); node = next_node; } - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, (void*) archives->config); - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, archives); + rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_OBJECT, (void*)archives->config); + rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_OBJECT, archives); } -static void -rtems_rtl_archives_remove (rtems_rtl_archives* archives) -{ - rtems_chain_node* node = rtems_chain_first (&archives->archives); - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: refresh: remove: checking %zu archive(s)\n", - rtems_chain_node_count_unprotected (&archives->archives)); - while (!rtems_chain_is_tail (&archives->archives, node)) - { - rtems_rtl_archive* archive = (rtems_rtl_archive*) node; - rtems_chain_node* next_node = rtems_chain_next (node); - if ((archive->flags & RTEMS_RTL_ARCHIVE_REMOVE) != 0) - { +static void rtems_rtl_archives_remove(rtems_rtl_archives* archives) { + rtems_chain_node* node = rtems_chain_first(&archives->archives); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: refresh: remove: checking %zu archive(s)\n", + rtems_chain_node_count_unprotected(&archives->archives)); + while (!rtems_chain_is_tail(&archives->archives, node)) { + rtems_rtl_archive* archive = (rtems_rtl_archive*)node; + rtems_chain_node* next_node = rtems_chain_next(node); + if ((archive->flags & RTEMS_RTL_ARCHIVE_REMOVE) != 0) { archive->flags &= ~RTEMS_RTL_ARCHIVE_REMOVE; if ((archive->flags & RTEMS_RTL_ARCHIVE_USER_LOAD) == 0) - rtems_rtl_archive_del (archive); + rtems_rtl_archive_del(archive); } node = next_node; } } -static bool -rtems_rtl_archive_loader (rtems_rtl_archive* archive, void* data) -{ - int* loaded = (int*) data; +static bool rtems_rtl_archive_loader(rtems_rtl_archive* archive, void* data) { + int* loaded = (int*)data; - if ((archive->flags & RTEMS_RTL_ARCHIVE_LOAD) != 0) - { - int fd; - off_t offset = 0; - size_t size = 0; + if ((archive->flags & RTEMS_RTL_ARCHIVE_LOAD) != 0) { + int fd; + off_t offset = 0; + size_t size = 0; const char* name = "/"; - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: loader: %s\n", archive->name); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: loader: %s\n", archive->name); - fd = open (archive->name, O_RDONLY); - if (fd < 0) - { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: loader: open error: %s: %s\n", - archive->name, strerror (errno)); - rtems_rtl_archive_set_error (errno, "opening archive file"); + fd = open(archive->name, O_RDONLY); + if (fd < 0) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: loader: open error: %s: %s\n", archive->name, + strerror(errno)); + rtems_rtl_archive_set_error(errno, "opening archive file"); return true; } - if (rtems_rtl_obj_archive_find_obj (fd, - archive->size, - &name, - &offset, - &size, - &archive->enames, - rtems_rtl_archive_set_error)) - { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: loader: symbols: off=0x%08jx size=%zu\n", - offset, size); + if (rtems_rtl_obj_archive_find_obj(fd, archive->size, &name, &offset, &size, + &archive->enames, + rtems_rtl_archive_set_error)) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: loader: symbols: off=0x%08jx size=%zu\n", offset, + size); /* * Reallocate the symbol table memory if it has changed size. * Note, an updated library may have the same symbol table. */ - if (archive->symbols.size != size) - { - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_SYMBOL, archive->symbols.base); - archive->symbols.base = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_SYMBOL, - size, - false); - if (archive->symbols.base == NULL) - { - close (fd); - memset (&archive->symbols, 0, sizeof (archive->symbols)); - rtems_rtl_archive_set_error (ENOMEM, "symbol table memory"); + if (archive->symbols.size != size) { + rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_SYMBOL, archive->symbols.base); + archive->symbols.base = + rtems_rtl_alloc_new(RTEMS_RTL_ALLOC_SYMBOL, size, false); + if (archive->symbols.base == NULL) { + close(fd); + memset(&archive->symbols, 0, sizeof(archive->symbols)); + rtems_rtl_archive_set_error(ENOMEM, "symbol table memory"); return true; } } @@ -684,12 +580,11 @@ rtems_rtl_archive_loader (rtems_rtl_archive* archive, void* data) /* * Read the symbol table into memory and hold. */ - if (!rtems_rtl_seek_read (fd, offset, size, archive->symbols.base)) - { - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_SYMBOL, archive->symbols.base); - close (fd); - memset (&archive->symbols, 0, sizeof (archive->symbols)); - rtems_rtl_archive_set_error (errno, "reading symbols"); + if (!rtems_rtl_seek_read(fd, offset, size, archive->symbols.base)) { + rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_SYMBOL, archive->symbols.base); + close(fd); + memset(&archive->symbols, 0, sizeof(archive->symbols)); + rtems_rtl_archive_set_error(errno, "reading symbols"); return true; } @@ -698,66 +593,59 @@ rtems_rtl_archive_loader (rtems_rtl_archive* archive, void* data) * value so the alloc size does not overflow (Coverity 1442636). */ archive->symbols.entries = - rtems_rtl_archive_read_32 (archive->symbols.base); - if (archive->symbols.entries >= (SIZE_MAX / sizeof (rtems_rtl_archive_symbol))) - { - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_SYMBOL, archive->symbols.base); - close (fd); - memset (&archive->symbols, 0, sizeof (archive->symbols)); - rtems_rtl_archive_set_error (errno, "too many symbols"); + rtems_rtl_archive_read_32(archive->symbols.base); + if (archive->symbols.entries >= + (SIZE_MAX / sizeof(rtems_rtl_archive_symbol))) { + rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_SYMBOL, archive->symbols.base); + close(fd); + memset(&archive->symbols, 0, sizeof(archive->symbols)); + rtems_rtl_archive_set_error(errno, "too many symbols"); return true; } - archive->symbols.size = size; - archive->symbols.names = archive->symbols.base; + archive->symbols.size = size; + archive->symbols.names = archive->symbols.base; archive->symbols.names += (archive->symbols.entries + 1) * 4; /* * Create a sorted symbol table. */ - size = archive->symbols.entries * sizeof (rtems_rtl_archive_symbol); + size = archive->symbols.entries * sizeof(rtems_rtl_archive_symbol); archive->symbols.symbols = - rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_SYMBOL, size, true); - if (archive->symbols.symbols != NULL) - { + rtems_rtl_alloc_new(RTEMS_RTL_ALLOC_SYMBOL, size, true); + if (archive->symbols.symbols != NULL) { const char* symbol = archive->symbols.names; - size_t e; - for (e = 0; e < archive->symbols.entries; ++e) - { + size_t e; + for (e = 0; e < archive->symbols.entries; ++e) { archive->symbols.symbols[e].entry = e + 1; archive->symbols.symbols[e].label = symbol; - symbol += strlen (symbol) + 1; + symbol += strlen(symbol) + 1; } - qsort (archive->symbols.symbols, - archive->symbols.entries, - sizeof (rtems_rtl_archive_symbol), - rtems_rtl_archive_symbol_compare); + qsort(archive->symbols.symbols, archive->symbols.entries, + sizeof(rtems_rtl_archive_symbol), + rtems_rtl_archive_symbol_compare); } - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: loader: symbols: " \ - "base=%p entries=%zu names=%p (0x%08x) symbols=%p\n", - archive->symbols.base, - archive->symbols.entries, - archive->symbols.names, - (unsigned int) (archive->symbols.entries + 1) * 4, - archive->symbols.symbols); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: loader: symbols: " + "base=%p entries=%zu names=%p (0x%08x) symbols=%p\n", + archive->symbols.base, archive->symbols.entries, + archive->symbols.names, + (unsigned int)(archive->symbols.entries + 1) * 4, + archive->symbols.symbols); - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVE_SYMS) && - archive->symbols.entries > 0) - { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVE_SYMS) && + archive->symbols.entries > 0) { size_t e; - printf ("rtl: archive: symbols: %s\n", archive->name ); - for (e = 0; e < archive->symbols.entries; ++e) - { - printf(" %6zu: %6zu %s\n", e + 1, - archive->symbols.symbols[e].entry, + printf("rtl: archive: symbols: %s\n", archive->name); + for (e = 0; e < archive->symbols.entries; ++e) { + printf(" %6zu: %6zu %s\n", e + 1, archive->symbols.symbols[e].entry, archive->symbols.symbols[e].label); } } } - close (fd); + close(fd); archive->flags &= ~RTEMS_RTL_ARCHIVE_LOAD; @@ -767,29 +655,24 @@ rtems_rtl_archive_loader (rtems_rtl_archive* archive, void* data) return true; } -static bool -rtems_rtl_archives_load (rtems_rtl_archives* archives) -{ +static bool rtems_rtl_archives_load(rtems_rtl_archives* archives) { int loaded = 0; - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: archive: load\n"); - rtems_rtl_archive_iterate_archives (archives, - rtems_rtl_archive_loader, - &loaded); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: archive: load\n"); + rtems_rtl_archive_iterate_archives(archives, rtems_rtl_archive_loader, + &loaded); return loaded > 0; } -bool -rtems_rtl_archives_refresh (rtems_rtl_archives* archives) -{ - ssize_t config_path = 0; +bool rtems_rtl_archives_refresh(rtems_rtl_archives* archives) { + ssize_t config_path = 0; uint32_t flags = RTEMS_RTL_ARCHIVE_REMOVE; /* * Reload the configuration file if it has not been loaded or has been * updated. */ - if (!rtems_rtl_archives_load_config (archives)) + if (!rtems_rtl_archives_load_config(archives)) return false; /* @@ -797,42 +680,38 @@ rtems_rtl_archives_refresh (rtems_rtl_archives* archives) * is ccnfigured and found teh remove flags is cleared. At the of the * refresh end remove any archives with this flag still set. */ - rtems_rtl_archive_iterate_archives (archives, - rtems_rtl_archive_set_flags, - &flags); + rtems_rtl_archive_iterate_archives(archives, rtems_rtl_archive_set_flags, + &flags); - while (config_path < archives->config_length) - { + while (config_path < archives->config_length) { const char* dirname = &archives->config[config_path]; - char* basename; - const char root[2] = { '/', '\0' }; - DIR* dir; + char* basename; + const char root[2] = {'/', '\0'}; + DIR* dir; - if (*dirname == '\0') - { + if (*dirname == '\0') { ++config_path; continue; } - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: refresh: %s\n", dirname); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: refresh: %s\n", dirname); - config_path += strlen (dirname); + config_path += strlen(dirname); /* * Relative paths do not work in the config. Must be absolute. */ - if (dirname[0] != '/') - { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: refresh: relative paths ignored: %s\n", dirname); + if (dirname[0] != '/') { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: refresh: relative paths ignored: %s\n", dirname); continue; } /* * Scan the parent directory of the glob path matching file names. */ - basename = strrchr (dirname, '/'); + basename = strrchr(dirname, '/'); if (basename == NULL) continue; @@ -842,43 +721,39 @@ rtems_rtl_archives_refresh (rtems_rtl_archives* archives) *basename = '\0'; ++basename; - dir = opendir (dirname); + dir = opendir(dirname); - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: refresh: %s %sfound\n", - dirname, dir == NULL ? ": not " : ""); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: refresh: %s %sfound\n", dirname, + dir == NULL ? ": not " : ""); - if (dir != NULL) - { - while (true) - { - struct dirent entry; + if (dir != NULL) { + while (true) { + struct dirent entry; struct dirent* result = NULL; - if (readdir_r (dir, &entry, &result) != 0) - { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: refresh: readdir error\n"); + if (readdir_r(dir, &entry, &result) != 0) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: refresh: readdir error\n"); break; } if (result == NULL) break; - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: refresh: checking: %s (pattern: %s)\n", - entry.d_name, basename); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: refresh: checking: %s (pattern: %s)\n", + entry.d_name, basename); - if (fnmatch (basename, entry.d_name, 0) == 0) - { + if (fnmatch(basename, entry.d_name, 0) == 0) { rtems_rtl_archive* archive; - archive = rtems_rtl_archive_get (archives, dirname, entry.d_name); - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: refresh: %s: %sfound\n", - entry.d_name, archive == NULL ? ": not " : ""); + archive = rtems_rtl_archive_get(archives, dirname, entry.d_name); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: refresh: %s: %sfound\n", entry.d_name, + archive == NULL ? ": not " : ""); } } - closedir (dir); + closedir(dir); } --basename; @@ -888,7 +763,7 @@ rtems_rtl_archives_refresh (rtems_rtl_archives* archives) /* * Remove all archives flagged to be removed. */ - rtems_rtl_archives_remove (archives); + rtems_rtl_archives_remove(archives); /* * Load any new archives. If any are loaded set the archive search flag in @@ -896,34 +771,29 @@ rtems_rtl_archives_refresh (rtems_rtl_archives* archives) * search flag avoids searching for symbols we know are not in the known * archives, */ - if (rtems_rtl_archives_load (archives)) - rtems_rtl_unresolved_set_archive_search (); + if (rtems_rtl_archives_load(archives)) + rtems_rtl_unresolved_set_archive_search(); return true; } -bool -rtems_rtl_archive_load (rtems_rtl_archives* archives, const char* name) -{ - if (archives != NULL) - { +bool rtems_rtl_archive_load(rtems_rtl_archives* archives, const char* name) { + if (archives != NULL) { rtems_rtl_archive* archive; - int loaded = 0; + int loaded = 0; - archive = rtems_rtl_archive_get (archives, "", name); - if (archive == NULL) - { - rtems_rtl_set_error (ENOENT, "archive not found"); + archive = rtems_rtl_archive_get(archives, "", name); + if (archive == NULL) { + rtems_rtl_set_error(ENOENT, "archive not found"); return false; } archive->flags |= RTEMS_RTL_ARCHIVE_USER_LOAD; - rtems_rtl_archive_loader (archive, &loaded); - if (loaded == 0) - { - rtems_rtl_archive_del (archive); - rtems_rtl_set_error (ENOENT, "archive load falied"); + rtems_rtl_archive_loader(archive, &loaded); + if (loaded == 0) { + rtems_rtl_archive_del(archive); + rtems_rtl_set_error(ENOENT, "archive load falied"); } return true; @@ -932,166 +802,138 @@ rtems_rtl_archive_load (rtems_rtl_archives* archives, const char* name) } rtems_rtl_archive_search -rtems_rtl_archive_obj_load (rtems_rtl_archives* archives, - const char* symbol, - bool load) -{ - rtems_rtl_obj* obj; +rtems_rtl_archive_obj_load(rtems_rtl_archives* archives, const char* symbol, + bool load) { + rtems_rtl_obj* obj; rtems_chain_control* pending; - int fd; - size_t archive_count; + int fd; + size_t archive_count; rtems_rtl_archive_obj_data search = { - .symbol = symbol, - .archive = NULL, - .offset = 0 - }; + .symbol = symbol, .archive = NULL, .offset = 0}; - archive_count = rtems_chain_node_count_unprotected (&archives->archives); + archive_count = rtems_chain_node_count_unprotected(&archives->archives); - if (archive_count == 0) - { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: load: no archives\n"); + if (archive_count == 0) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: load: no archives\n"); return rtems_rtl_archive_search_no_config; } - pending = rtems_rtl_pending_unprotected (); - if (pending == NULL) - { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: load: no pending list\n"); + pending = rtems_rtl_pending_unprotected(); + if (pending == NULL) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: load: no pending list\n"); return rtems_rtl_archive_search_not_found; } - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: load: searching %zu archives\n", archive_count); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: load: searching %zu archives\n", archive_count); - rtems_rtl_archive_iterate_archives (archives, - rtems_rtl_archive_obj_finder, - &search); + rtems_rtl_archive_iterate_archives(archives, rtems_rtl_archive_obj_finder, + &search); - if (search.archive == NULL) - { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: load: not found: %s\n", symbol); + if (search.archive == NULL) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: load: not found: %s\n", symbol); return rtems_rtl_archive_search_not_found; } - if (!load) - { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: load: found (no load): %s\n", symbol); + if (!load) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: load: found (no load): %s\n", symbol); return rtems_rtl_archive_search_found; } - obj = rtems_rtl_obj_alloc (); - if (obj == NULL) - { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: alloc: no memory: %s\n", - search.archive->name); + obj = rtems_rtl_obj_alloc(); + if (obj == NULL) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: alloc: no memory: %s\n", search.archive->name); return rtems_rtl_archive_search_error; } - obj->aname = rtems_rtl_strdup (search.archive->name); + obj->aname = rtems_rtl_strdup(search.archive->name); - fd = open (obj->aname, O_RDONLY); - if (fd < 0) - { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: load: open error: %s: %s\n", - obj->aname, strerror (errno)); - rtems_rtl_obj_free (obj); + fd = open(obj->aname, O_RDONLY); + if (fd < 0) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: load: open error: %s: %s\n", obj->aname, + strerror(errno)); + rtems_rtl_obj_free(obj); return rtems_rtl_archive_search_error; } obj->oname = NULL; obj->ooffset = search.offset; - if (!rtems_rtl_obj_archive_find_obj (fd, - search.archive->size, - &obj->oname, - &obj->ooffset, - &obj->fsize, - &search.archive->enames, - rtems_rtl_archive_set_error)) - { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: load: load error: %s:%s\n", - obj->aname, obj->oname); - close (fd); - rtems_rtl_obj_free (obj); + if (!rtems_rtl_obj_archive_find_obj( + fd, search.archive->size, &obj->oname, &obj->ooffset, &obj->fsize, + &search.archive->enames, rtems_rtl_archive_set_error)) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: load: load error: %s:%s\n", obj->aname, obj->oname); + close(fd); + rtems_rtl_obj_free(obj); return rtems_rtl_archive_search_error; } - obj->fname = rtems_rtl_strdup (obj->aname); + obj->fname = rtems_rtl_strdup(obj->aname); obj->ooffset -= RTEMS_RTL_AR_FHDR_SIZE; obj->fsize = search.archive->size; - close (fd); + close(fd); - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: loading: %s:%s@0x%08jx size:%zu\n", - obj->aname, obj->oname, obj->ooffset, obj->fsize); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: loading: %s:%s@0x%08jx size:%zu\n", obj->aname, + obj->oname, obj->ooffset, obj->fsize); - rtems_chain_append (pending, &obj->link); + rtems_chain_append(pending, &obj->link); - if (!rtems_rtl_obj_load (obj)) - { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: loading: error: %s:%s@0x%08jx: %s\n", - obj->aname, obj->oname, obj->ooffset, - rtems_rtl_last_error_unprotected ()); - rtems_chain_extract (&obj->link); - rtems_rtl_obj_free (obj); - rtems_rtl_obj_caches_flush (); + if (!rtems_rtl_obj_load(obj)) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: loading: error: %s:%s@0x%08jx: %s\n", obj->aname, + obj->oname, obj->ooffset, rtems_rtl_last_error_unprotected()); + rtems_chain_extract(&obj->link); + rtems_rtl_obj_free(obj); + rtems_rtl_obj_caches_flush(); return rtems_rtl_archive_search_error; } - rtems_rtl_obj_caches_flush (); + rtems_rtl_obj_caches_flush(); - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: loading: loaded: %s:%s@0x%08jx\n", - obj->aname, obj->oname, obj->ooffset); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: loading: loaded: %s:%s@0x%08jx\n", obj->aname, + obj->oname, obj->ooffset); return rtems_rtl_archive_search_loaded; } -bool -rtems_rtl_obj_archive_find_obj (int fd, - size_t fsize, - const char** name, - off_t* ooffset, - size_t* osize, - off_t* extended_file_names, - rtems_rtl_archive_error error) -{ +bool rtems_rtl_obj_archive_find_obj(int fd, size_t fsize, const char** name, + off_t* ooffset, size_t* osize, + off_t* extended_file_names, + rtems_rtl_archive_error error) { uint8_t header[RTEMS_RTL_AR_FHDR_SIZE]; - bool scanning; + bool scanning; - if (name == NULL) - { - error (errno, "invalid object name"); + if (name == NULL) { + error(errno, "invalid object name"); *ooffset = 0; *osize = 0; return false; } - if (rtems_rtl_trace (RTEMS_RTL_TRACE_ARCHIVES)) - printf ("rtl: archive: find obj: %s @ 0x%08jx\n", *name, *ooffset); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_ARCHIVES)) + printf("rtl: archive: find obj: %s @ 0x%08jx\n", *name, *ooffset); - if (read (fd, &header[0], RTEMS_RTL_AR_IDENT_SIZE) != RTEMS_RTL_AR_IDENT_SIZE) - { - error (errno, "reading archive identifer"); + if (read(fd, &header[0], RTEMS_RTL_AR_IDENT_SIZE) != + RTEMS_RTL_AR_IDENT_SIZE) { + error(errno, "reading archive identifer"); *ooffset = 0; *osize = 0; return false; } - if (memcmp (header, RTEMS_RTL_AR_IDENT, RTEMS_RTL_AR_IDENT_SIZE) != 0) - { - error (EINVAL, "invalid archive identifer"); + if (memcmp(header, RTEMS_RTL_AR_IDENT, RTEMS_RTL_AR_IDENT_SIZE) != 0) { + error(EINVAL, "invalid archive identifer"); *ooffset = 0; *osize = 0; return false; @@ -1120,11 +962,9 @@ rtems_rtl_obj_archive_find_obj (int fd, if (*ooffset != 0) scanning = false; - else - { - if (*name == NULL) - { - error (errno, "invalid object name and archive offset"); + else { + if (*name == NULL) { + error(errno, "invalid object name and archive offset"); *ooffset = 0; *osize = 0; return false; @@ -1134,27 +974,24 @@ rtems_rtl_obj_archive_find_obj (int fd, *osize = 0; } - while (*ooffset < (int64_t)fsize) - { + while (*ooffset < (int64_t)fsize) { /* * Clean up any existing data. */ - memset (header, 0, sizeof (header)); + memset(header, 0, sizeof(header)); - if (!rtems_rtl_seek_read (fd, *ooffset, RTEMS_RTL_AR_FHDR_SIZE, &header[0])) - { - error (errno, "seek/read archive file header"); + if (!rtems_rtl_seek_read(fd, *ooffset, RTEMS_RTL_AR_FHDR_SIZE, + &header[0])) { + error(errno, "seek/read archive file header"); *ooffset = 0; *osize = 0; return false; } if ((header[RTEMS_RTL_AR_MAGIC] != 0x60) || - (header[RTEMS_RTL_AR_MAGIC + 1] != 0x0a)) - { - if (scanning) - { - error (EINVAL, "invalid archive file header"); + (header[RTEMS_RTL_AR_MAGIC + 1] != 0x0a)) { + if (scanning) { + error(EINVAL, "invalid archive file header"); *ooffset = 0; *osize = 0; return false; @@ -1168,137 +1005,127 @@ rtems_rtl_obj_archive_find_obj (int fd, /* * The archive header is always aligned to an even address. */ - *osize = (rtems_rtl_scan_decimal (&header[RTEMS_RTL_AR_SIZE], - RTEMS_RTL_AR_SIZE_SIZE) + 1) & ~1; + *osize = (rtems_rtl_scan_decimal(&header[RTEMS_RTL_AR_SIZE], + RTEMS_RTL_AR_SIZE_SIZE) + + 1) & + ~1; /* * Check for the GNU extensions. */ - if (header[0] == '/') - { + if (header[0] == '/') { const char* name_ = *name; off_t extended_off; - switch (header[1]) - { - case ' ': - /* - * SVR4/GNU Symbols table. Nothing more to do. - */ - *ooffset += RTEMS_RTL_AR_FHDR_SIZE; + switch (header[1]) { + case ' ': + /* + * SVR4/GNU Symbols table. Nothing more to do. + */ + *ooffset += RTEMS_RTL_AR_FHDR_SIZE; + return true; + case '/': + /* + * Extended file names table. Remember. If asked to find this file + * return the result. + */ + *extended_file_names = *ooffset + RTEMS_RTL_AR_FHDR_SIZE; + if (name_[0] == '/' && name_[1] == '/') { + *ooffset = *ooffset + RTEMS_RTL_AR_FHDR_SIZE; return true; - case '/': - /* - * Extended file names table. Remember. If asked to find this file - * return the result. - */ - *extended_file_names = *ooffset + RTEMS_RTL_AR_FHDR_SIZE; - if (name_[0] == '/' && name_[1] == '/') - { - *ooffset = *ooffset + RTEMS_RTL_AR_FHDR_SIZE; - return true; - } - break; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - /* - * Offset into the extended file name table. If we do not have the - * offset to the extended file name table find it. - */ - extended_off = - rtems_rtl_scan_decimal (&header[1], RTEMS_RTL_AR_FNAME_SIZE); + } + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + /* + * Offset into the extended file name table. If we do not have the + * offset to the extended file name table find it. + */ + extended_off = + rtems_rtl_scan_decimal(&header[1], RTEMS_RTL_AR_FNAME_SIZE); - if (*extended_file_names == 0) - { - off_t off = RTEMS_RTL_AR_IDENT_SIZE; - while (*extended_file_names == 0) - { - off_t esize; + if (*extended_file_names == 0) { + off_t off = RTEMS_RTL_AR_IDENT_SIZE; + while (*extended_file_names == 0) { + off_t esize; - if (!rtems_rtl_seek_read (fd, off, - RTEMS_RTL_AR_FHDR_SIZE, &header[0])) - { - error (errno, "seeking/reading archive ext file name header"); - *ooffset = 0; - *osize = 0; - return false; - } - - if ((header[RTEMS_RTL_AR_MAGIC] != 0x60) || - (header[RTEMS_RTL_AR_MAGIC + 1] != 0x0a)) - { - error (errno, "invalid archive file header"); - *ooffset = 0; - *osize = 0; - return false; - } - - if ((header[0] == '/') && (header[1] == '/')) - { - *extended_file_names = off + RTEMS_RTL_AR_FHDR_SIZE; - break; - } - - esize = - (rtems_rtl_scan_decimal (&header[RTEMS_RTL_AR_SIZE], - RTEMS_RTL_AR_SIZE_SIZE) + 1) & ~1; - off += esize + RTEMS_RTL_AR_FHDR_SIZE; - } - } - - if (*extended_file_names != 0) - { - /* - * We know the offset in the archive to the extended file. Read the - * name from the table and compare with the name we are after. - */ - #define RTEMS_RTL_MAX_FILE_SIZE (256) - char ename[RTEMS_RTL_MAX_FILE_SIZE]; - - if (!rtems_rtl_seek_read (fd, *extended_file_names + extended_off, - RTEMS_RTL_MAX_FILE_SIZE, (uint8_t*) &ename[0])) - { - error (errno, "invalid archive ext file seek/read"); + if (!rtems_rtl_seek_read(fd, off, RTEMS_RTL_AR_FHDR_SIZE, + &header[0])) { + error(errno, "seeking/reading archive ext file name header"); *ooffset = 0; *osize = 0; return false; } - /* - * If there is no name memory the user is asking us to return the - * name in the archive at the offset. - */ - if (*name == NULL) - *name = rtems_rtl_archive_dup_name (ename); - if (rtems_rtl_archive_match_name (*name, ename)) - { - *ooffset += RTEMS_RTL_AR_FHDR_SIZE; - return true; + if ((header[RTEMS_RTL_AR_MAGIC] != 0x60) || + (header[RTEMS_RTL_AR_MAGIC + 1] != 0x0a)) { + error(errno, "invalid archive file header"); + *ooffset = 0; + *osize = 0; + return false; } + + if ((header[0] == '/') && (header[1] == '/')) { + *extended_file_names = off + RTEMS_RTL_AR_FHDR_SIZE; + break; + } + + esize = (rtems_rtl_scan_decimal(&header[RTEMS_RTL_AR_SIZE], + RTEMS_RTL_AR_SIZE_SIZE) + + 1) & + ~1; + off += esize + RTEMS_RTL_AR_FHDR_SIZE; } - break; - default: + } + + if (*extended_file_names != 0) { +/* + * We know the offset in the archive to the extended file. Read the + * name from the table and compare with the name we are after. + */ +#define RTEMS_RTL_MAX_FILE_SIZE (256) + char ename[RTEMS_RTL_MAX_FILE_SIZE]; + + if (!rtems_rtl_seek_read(fd, *extended_file_names + extended_off, + RTEMS_RTL_MAX_FILE_SIZE, + (uint8_t*)&ename[0])) { + error(errno, "invalid archive ext file seek/read"); + *ooffset = 0; + *osize = 0; + return false; + } + /* - * Ignore the file because we do not know what it it. + * If there is no name memory the user is asking us to return the + * name in the archive at the offset. */ - break; + if (*name == NULL) + *name = rtems_rtl_archive_dup_name(ename); + if (rtems_rtl_archive_match_name(*name, ename)) { + *ooffset += RTEMS_RTL_AR_FHDR_SIZE; + return true; + } + } + break; + default: + /* + * Ignore the file because we do not know what it it. + */ + break; } - } - else - { - const char* ename = (const char*) &header[RTEMS_RTL_AR_FNAME]; + } else { + const char* ename = (const char*)&header[RTEMS_RTL_AR_FNAME]; if (*name == NULL) - *name = rtems_rtl_archive_dup_name (ename); - if (rtems_rtl_archive_match_name (*name, ename)) - { + *name = rtems_rtl_archive_dup_name(ename); + if (rtems_rtl_archive_match_name(*name, ename)) { *ooffset += RTEMS_RTL_AR_FHDR_SIZE; return true; } @@ -1307,9 +1134,8 @@ rtems_rtl_obj_archive_find_obj (int fd, *ooffset += *osize + RTEMS_RTL_AR_FHDR_SIZE; } - error (ENOENT, "object file not found"); + error(ENOENT, "object file not found"); *ooffset = 0; *osize = 0; return false; - } diff --git a/cpukit/libdl/rtl-bit-alloc.c b/cpukit/libdl/rtl-bit-alloc.c index 1472e168a7..3201596fa3 100644 --- a/cpukit/libdl/rtl-bit-alloc.c +++ b/cpukit/libdl/rtl-bit-alloc.c @@ -46,87 +46,65 @@ #include #include -#include #include "rtl-bit-alloc.h" #include "rtl-error.h" +#include #include -#define BITS_PER_WORD (sizeof (uint32_t) * 8) +#define BITS_PER_WORD (sizeof(uint32_t) * 8) -static size_t -bit_blocks (rtems_rtl_bit_alloc* balloc, size_t size) -{ +static size_t bit_blocks(rtems_rtl_bit_alloc* balloc, size_t size) { if (size == 0) return 0; return ((size - 1) / balloc->block_size) + 1; } -static size_t -bit_word (size_t bit) -{ +static size_t bit_word(size_t bit) { return bit / BITS_PER_WORD; } -static size_t -bit_offset (size_t bit) -{ - return bit % (sizeof (uint32_t) * 8); +static size_t bit_offset(size_t bit) { + return bit % (sizeof(uint32_t) * 8); } -static uint32_t -bit_mask (size_t bit) -{ - return 1 << bit_offset (bit); +static uint32_t bit_mask(size_t bit) { + return 1 << bit_offset(bit); } -static void -bit_set (rtems_rtl_bit_alloc* balloc, size_t start, size_t bits) -{ +static void bit_set(rtems_rtl_bit_alloc* balloc, size_t start, size_t bits) { size_t b; for (b = start; b < (start + bits); ++b) - balloc->bits[bit_word (b)] |= bit_mask (b); + balloc->bits[bit_word(b)] |= bit_mask(b); } -static void -bit_clear (rtems_rtl_bit_alloc* balloc, size_t start, size_t bits) -{ +static void bit_clear(rtems_rtl_bit_alloc* balloc, size_t start, size_t bits) { size_t b; for (b = start; b < (start + bits); ++b) - balloc->bits[bit_word (b)] &= ~bit_mask (b); + balloc->bits[bit_word(b)] &= ~bit_mask(b); } -static ssize_t -bit_find_clear (rtems_rtl_bit_alloc* balloc, size_t blocks) -{ +static ssize_t bit_find_clear(rtems_rtl_bit_alloc* balloc, size_t blocks) { size_t base = 0; size_t clear = 0; size_t b; - for (b = 0; b < balloc->blocks; ++b) - { - if (balloc->bits[b] != 0xffffffff) - { + for (b = 0; b < balloc->blocks; ++b) { + if (balloc->bits[b] != 0xffffffff) { uint32_t word = balloc->bits[b]; - size_t o; - for (o = 0; o < BITS_PER_WORD; ++o, word >>= 1) - { - if ((word & 1) == 0) - { + size_t o; + for (o = 0; o < BITS_PER_WORD; ++o, word >>= 1) { + if ((word & 1) == 0) { if (clear == 0) base = (b * BITS_PER_WORD) + o; ++clear; if (clear == blocks) return base; - } - else - { + } else { clear = 0; base = 0; } } - } - else - { + } else { clear = 0; base = 0; } @@ -135,83 +113,75 @@ bit_find_clear (rtems_rtl_bit_alloc* balloc, size_t blocks) return -1; } -rtems_rtl_bit_alloc* -rtems_rtl_bit_alloc_open (void* base, size_t size, size_t block_size, size_t used) -{ +rtems_rtl_bit_alloc* rtems_rtl_bit_alloc_open(void* base, size_t size, + size_t block_size, size_t used) { rtems_rtl_bit_alloc* balloc; - const size_t base_size = base == NULL ? size : 0;; - const size_t blocks = (size / block_size) / BITS_PER_WORD; - const size_t bit_bytes = blocks * sizeof(uint32_t); + const size_t base_size = base == NULL ? size : 0; + ; + const size_t blocks = (size / block_size) / BITS_PER_WORD; + const size_t bit_bytes = blocks * sizeof(uint32_t); - if (rtems_rtl_trace (RTEMS_RTL_TRACE_BIT_ALLOC)) - printf ("rtl: balloc: open: base=%p size=%zu" \ - " block-size=%zu blocks=%zu used=%zu\n", - base, size, block_size, blocks, used); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_BIT_ALLOC)) + printf("rtl: balloc: open: base=%p size=%zu" + " block-size=%zu blocks=%zu used=%zu\n", + base, size, block_size, blocks, used); - if (size == 0) - { - rtems_rtl_set_error (ENOMEM, "bit allocator size is 0"); + if (size == 0) { + rtems_rtl_set_error(ENOMEM, "bit allocator size is 0"); return NULL; } - if (used > size) - { - rtems_rtl_set_error (ENOMEM, "bad bit allocator used value"); + if (used > size) { + rtems_rtl_set_error(ENOMEM, "bad bit allocator used value"); return NULL; } - balloc = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, - sizeof (rtems_rtl_bit_alloc) + bit_bytes + base_size, - true); - if (balloc == NULL) - { - rtems_rtl_set_error (ENOMEM, "not bit allocator memory"); + balloc = rtems_rtl_alloc_new( + RTEMS_RTL_ALLOC_OBJECT, + sizeof(rtems_rtl_bit_alloc) + bit_bytes + base_size, true); + if (balloc == NULL) { + rtems_rtl_set_error(ENOMEM, "not bit allocator memory"); return NULL; } - balloc->base = - base == NULL ? ((void*) balloc) + sizeof (rtems_rtl_bit_alloc) + bit_bytes: base; + balloc->base = base == NULL + ? ((void*)balloc) + sizeof(rtems_rtl_bit_alloc) + bit_bytes + : base; balloc->size = size; - balloc->bits = ((void*) balloc) + sizeof (rtems_rtl_bit_alloc); + balloc->bits = ((void*)balloc) + sizeof(rtems_rtl_bit_alloc); balloc->block_size = block_size; balloc->blocks = blocks; - bit_set (balloc, 0, bit_blocks (balloc, used)); + bit_set(balloc, 0, bit_blocks(balloc, used)); return balloc; } -void -rtems_rtl_bit_alloc_close (rtems_rtl_bit_alloc* balloc) -{ - if (rtems_rtl_trace (RTEMS_RTL_TRACE_BIT_ALLOC)) - printf ("rtl: balloc: close: base=%p size=%zu\n", - balloc->base, balloc->size); - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, balloc); +void rtems_rtl_bit_alloc_close(rtems_rtl_bit_alloc* balloc) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_BIT_ALLOC)) + printf("rtl: balloc: close: base=%p size=%zu\n", balloc->base, + balloc->size); + rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_OBJECT, balloc); } -void* -rtems_rtl_bit_alloc_balloc (rtems_rtl_bit_alloc* balloc, size_t size) -{ - size_t blocks = bit_blocks (balloc, size); - ssize_t block = bit_find_clear (balloc, blocks); +void* rtems_rtl_bit_alloc_balloc(rtems_rtl_bit_alloc* balloc, size_t size) { + size_t blocks = bit_blocks(balloc, size); + ssize_t block = bit_find_clear(balloc, blocks); if (block < 0) return NULL; - if (rtems_rtl_trace (RTEMS_RTL_TRACE_BIT_ALLOC)) - printf ("rtl: balloc: balloc: size=%zu blocks=%zu block=%zi\n", - size, blocks, block); - bit_set (balloc, block, blocks); - return (void*) (balloc->base + (block * balloc->block_size)); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_BIT_ALLOC)) + printf("rtl: balloc: balloc: size=%zu blocks=%zu block=%zi\n", size, blocks, + block); + bit_set(balloc, block, blocks); + return (void*)(balloc->base + (block * balloc->block_size)); } -void -rtems_rtl_bit_alloc_bfree (rtems_rtl_bit_alloc* balloc, void* addr, size_t size) -{ - const uint8_t* a = (const uint8_t*) addr; - if (addr != NULL && a >= balloc->base && a < balloc->base + balloc->size) - { - size_t block = bit_blocks (balloc, a - balloc->base); - size_t blocks = bit_blocks (balloc, size); - bit_clear (balloc, block, blocks); +void rtems_rtl_bit_alloc_bfree(rtems_rtl_bit_alloc* balloc, void* addr, + size_t size) { + const uint8_t* a = (const uint8_t*)addr; + if (addr != NULL && a >= balloc->base && a < balloc->base + balloc->size) { + size_t block = bit_blocks(balloc, a - balloc->base); + size_t blocks = bit_blocks(balloc, size); + bit_clear(balloc, block, blocks); } } diff --git a/cpukit/libdl/rtl-bit-alloc.h b/cpukit/libdl/rtl-bit-alloc.h index 9b4e6c31fb..c05be36edb 100644 --- a/cpukit/libdl/rtl-bit-alloc.h +++ b/cpukit/libdl/rtl-bit-alloc.h @@ -33,7 +33,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#if !defined (_RTEMS_RTL_BIT_ALLOC_H_) +#if !defined(_RTEMS_RTL_BIT_ALLOC_H_) #define _RTEMS_RTL_BIT_ALLOC_H_ #include @@ -46,13 +46,12 @@ extern "C" { /** * Bit Allocator data */ -typedef struct rtems_rtl_bit_alloc -{ - uint8_t* base; /**< The memory being allocated. */ - size_t size; /**< The number of bytes of memory being managed. */ - uint32_t* bits; /**< The bit map indicating which blocks are allocated. */ - size_t block_size; /**< The size of a block, the minimum allocation unit. */ - size_t blocks; /**< The number of blocks in the memory. */ +typedef struct rtems_rtl_bit_alloc { + uint8_t* base; /**< The memory being allocated. */ + size_t size; /**< The number of bytes of memory being managed. */ + uint32_t* bits; /**< The bit map indicating which blocks are allocated. */ + size_t block_size; /**< The size of a block, the minimum allocation unit. */ + size_t blocks; /**< The number of blocks in the memory. */ } rtems_rtl_bit_alloc; /** @@ -65,10 +64,8 @@ typedef struct rtems_rtl_bit_alloc * @param used The amount of memory already in use in bytes. * @retval rtems_rtl_bit_alloc The bit allocator structure. */ -rtems_rtl_bit_alloc* rtems_rtl_bit_alloc_open (void* base, - size_t size, - size_t block_size, - size_t used); +rtems_rtl_bit_alloc* rtems_rtl_bit_alloc_open(void* base, size_t size, + size_t block_size, size_t used); /** * Close the bit allocator. @@ -76,7 +73,7 @@ rtems_rtl_bit_alloc* rtems_rtl_bit_alloc_open (void* base, * @param balloc The allocator to close. */ -void rtems_rtl_bit_alloc_close (rtems_rtl_bit_alloc* balloc); +void rtems_rtl_bit_alloc_close(rtems_rtl_bit_alloc* balloc); /** * Allocate a piece of memory being managed. The size is in bytes are is rounded @@ -87,13 +84,14 @@ void rtems_rtl_bit_alloc_close (rtems_rtl_bit_alloc* balloc); * @return void* The memory if the allocation is successful else NULL if there * is no more memory. */ -void* rtems_rtl_bit_alloc_balloc (rtems_rtl_bit_alloc* balloc, size_t size); +void* rtems_rtl_bit_alloc_balloc(rtems_rtl_bit_alloc* balloc, size_t size); /** - * Free an allocated memory block. The size is required because the allocator does not - * contain any state information. + * Free an allocated memory block. The size is required because the allocator + * does not contain any state information. */ -void rtems_rtl_bit_alloc_bfree (rtems_rtl_bit_alloc* balloc, void* addr, size_t size); +void rtems_rtl_bit_alloc_bfree(rtems_rtl_bit_alloc* balloc, void* addr, + size_t size); #ifdef __cplusplus } diff --git a/cpukit/libdl/rtl-chain-iterator.c b/cpukit/libdl/rtl-chain-iterator.c index 8a5b54b262..b55fcb09a1 100644 --- a/cpukit/libdl/rtl-chain-iterator.c +++ b/cpukit/libdl/rtl-chain-iterator.c @@ -41,16 +41,12 @@ #include "rtl-chain-iterator.h" -bool -rtems_rtl_chain_iterate (rtems_chain_control* chain, - rtems_chain_iterator iterator, - void* data) -{ - rtems_chain_node* node = rtems_chain_first (chain); - while (!rtems_chain_is_tail (chain, node)) - { - rtems_chain_node* next_node = rtems_chain_next (node); - if (!iterator (node, data)) +bool rtems_rtl_chain_iterate(rtems_chain_control* chain, + rtems_chain_iterator iterator, void* data) { + rtems_chain_node* node = rtems_chain_first(chain); + while (!rtems_chain_is_tail(chain, node)) { + rtems_chain_node* next_node = rtems_chain_next(node); + if (!iterator(node, data)) return false; node = next_node; } @@ -60,20 +56,16 @@ rtems_rtl_chain_iterate (rtems_chain_control* chain, /** * Count iterator. */ -static bool -rtems_rtl_count_iterator (rtems_chain_node* node, void* data) -{ - (void) node; +static bool rtems_rtl_count_iterator(rtems_chain_node* node, void* data) { + (void)node; int* count = data; ++(*count); return true; } -int -rtems_rtl_chain_count (rtems_chain_control* chain) -{ +int rtems_rtl_chain_count(rtems_chain_control* chain) { int count = 0; - rtems_rtl_chain_iterate (chain, rtems_rtl_count_iterator, &count); + rtems_rtl_chain_iterate(chain, rtems_rtl_count_iterator, &count); return count; } diff --git a/cpukit/libdl/rtl-chain-iterator.h b/cpukit/libdl/rtl-chain-iterator.h index 8304fe1a24..2f67bac60d 100644 --- a/cpukit/libdl/rtl-chain-iterator.h +++ b/cpukit/libdl/rtl-chain-iterator.h @@ -33,7 +33,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#if !defined (_RTEMS_RTL_CHAIN_ITERATOR_H_) +#if !defined(_RTEMS_RTL_CHAIN_ITERATOR_H_) #define _RTEMS_RTL_CHAIN_ITERATOR_H_ #ifdef __cplusplus @@ -45,7 +45,7 @@ extern "C" { /** * Chain iterator handler. */ -typedef bool (*rtems_chain_iterator) (rtems_chain_node* node, void* data); +typedef bool (*rtems_chain_iterator)(rtems_chain_node* node, void* data); /** * Iterate a chain of nodes invoking the iterator handler. Supply a data @@ -59,10 +59,8 @@ typedef bool (*rtems_chain_iterator) (rtems_chain_node* node, void* data); * @retval true The whole chain was iterated over. * @retval false The iterator returned false. */ -bool -rtems_rtl_chain_iterate (rtems_chain_control* chain, - rtems_chain_iterator iterator, - void* data); +bool rtems_rtl_chain_iterate(rtems_chain_control* chain, + rtems_chain_iterator iterator, void* data); /** * Count the number of nodes on the chain. @@ -70,7 +68,7 @@ rtems_rtl_chain_iterate (rtems_chain_control* chain, * @param chain The chain to count the nodes of. * @return int The number of nodes. */ -int rtems_rtl_chain_count (rtems_chain_control* chain); +int rtems_rtl_chain_count(rtems_chain_control* chain); #ifdef __cplusplus } diff --git a/cpukit/libdl/rtl-debugger.c b/cpukit/libdl/rtl-debugger.c index dd23078cf5..865328edbb 100644 --- a/cpukit/libdl/rtl-debugger.c +++ b/cpukit/libdl/rtl-debugger.c @@ -46,48 +46,41 @@ #include "config.h" #endif -#include #include -#include -#include #include +#include +#include +#include -struct r_debug _rtld_debug; +struct r_debug _rtld_debug; -void -_rtld_debug_state (void) -{ +void _rtld_debug_state(void) { /* * Empty. GDB only needs to hit this location. */ } -int -_rtld_linkmap_add (rtems_rtl_obj* obj) -{ +int _rtld_linkmap_add(rtems_rtl_obj* obj) { struct link_map* l = obj->linkmap; struct link_map* prev; - uint32_t obj_num = obj->obj_num; - size_t i; + uint32_t obj_num = obj->obj_num; + size_t i; - if (rtems_rtl_trace (RTEMS_RTL_TRACE_DETAIL)) - printf ("rtl: linkmap_add\n"); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_DETAIL)) + printf("rtl: linkmap_add\n"); - for (i = 0; i < obj_num; ++i) - { + for (i = 0; i < obj_num; ++i) { l[i].sec_addr[rap_text] = obj->text_base; l[i].sec_addr[rap_const] = obj->const_base; l[i].sec_addr[rap_data] = obj->data_base; l[i].sec_addr[rap_bss] = obj->bss_base; } - if (_rtld_debug.r_map == NULL) - { + if (_rtld_debug.r_map == NULL) { _rtld_debug.r_map = l; - } - else - { - for (prev = _rtld_debug.r_map; prev->l_next != NULL; prev = prev->l_next); + } else { + for (prev = _rtld_debug.r_map; prev->l_next != NULL; prev = prev->l_next) + ; l->l_prev = prev; prev->l_next = l; } @@ -95,9 +88,7 @@ _rtld_linkmap_add (rtems_rtl_obj* obj) return true; } -void -_rtld_linkmap_delete (rtems_rtl_obj* obj) -{ +void _rtld_linkmap_delete(rtems_rtl_obj* obj) { struct link_map* l = obj->linkmap; /* @@ -105,13 +96,10 @@ _rtld_linkmap_delete (rtems_rtl_obj* obj) */ struct link_map* e = l + obj->obj_num - 1; - if (l->l_prev == NULL) - { + if (l->l_prev == NULL) { if ((_rtld_debug.r_map = e->l_next) != NULL) - _rtld_debug.r_map->l_prev = NULL; - } - else - { + _rtld_debug.r_map->l_prev = NULL; + } else { if ((l->l_prev->l_next = e->l_next) != NULL) e->l_next->l_prev = l->l_prev; } diff --git a/cpukit/libdl/rtl-elf.c b/cpukit/libdl/rtl-elf.c index 411c27972e..47dd9e9092 100644 --- a/cpukit/libdl/rtl-elf.c +++ b/cpukit/libdl/rtl-elf.c @@ -42,138 +42,116 @@ #include #include #include +#include #include #include -#include #include -#include #include "rtl-elf.h" #include "rtl-error.h" -#include #include "rtl-trampoline.h" #include "rtl-unwind.h" +#include #include +#include /** * The offsets in the reloc words. */ #define REL_R_OFFSET (0) -#define REL_R_INFO (1) +#define REL_R_INFO (1) #define REL_R_ADDEND (2) /** * The ELF format signature. */ -static rtems_rtl_loader_format elf_sig = -{ - .label = "ELF", - .flags = RTEMS_RTL_FMT_ELF -}; +static rtems_rtl_loader_format elf_sig = {.label = "ELF", + .flags = RTEMS_RTL_FMT_ELF}; -static const char* -rtems_rtl_elf_sym_type_label (Elf_Byte st_info) -{ +static const char* rtems_rtl_elf_sym_type_label(Elf_Byte st_info) { const char* label; - switch (ELF_ST_TYPE (st_info)) - { - case STT_NOTYPE: - label = "STT_NOTYPE"; - break; - case STT_OBJECT: - label = "STT_OBJECT"; - break; - case STT_FUNC: - label = "STT_FUNC"; - break; - case STT_SECTION: - label = "STT_SECTION"; - break; - case STT_FILE: - label = "STT_FILE"; - break; - case STT_COMMON: - label = "STT_COMMON"; - break; - case STT_TLS: - label = "STT_TLS"; - break; - default: - label = "unknown"; - break; + switch (ELF_ST_TYPE(st_info)) { + case STT_NOTYPE: + label = "STT_NOTYPE"; + break; + case STT_OBJECT: + label = "STT_OBJECT"; + break; + case STT_FUNC: + label = "STT_FUNC"; + break; + case STT_SECTION: + label = "STT_SECTION"; + break; + case STT_FILE: + label = "STT_FILE"; + break; + case STT_COMMON: + label = "STT_COMMON"; + break; + case STT_TLS: + label = "STT_TLS"; + break; + default: + label = "unknown"; + break; } return label; } -static const char* -rtems_rtl_elf_sym_bind_label (Elf_Byte st_info) -{ +static const char* rtems_rtl_elf_sym_bind_label(Elf_Byte st_info) { const char* label; - switch (ELF_ST_BIND (st_info)) - { - case STB_LOCAL: - label = "STB_LOCAL"; - break; - case STB_GLOBAL: - label = "STB_GLOBAL"; - break; - case STB_WEAK: - label = "STB_WEAK"; - break; - default: - label = "unknown"; - break; + switch (ELF_ST_BIND(st_info)) { + case STB_LOCAL: + label = "STB_LOCAL"; + break; + case STB_GLOBAL: + label = "STB_GLOBAL"; + break; + case STB_WEAK: + label = "STB_WEAK"; + break; + default: + label = "unknown"; + break; } return label; } -static bool -rtems_rtl_elf_machine_check (Elf_Ehdr* ehdr) -{ +static bool rtems_rtl_elf_machine_check(Elf_Ehdr* ehdr) { /* * This code is determined by the NetBSD machine headers. */ - switch (ehdr->e_machine) - { - ELFDEFNNAME (MACHDEP_ID_CASES) - default: - return false; + switch (ehdr->e_machine) { + ELFDEFNNAME(MACHDEP_ID_CASES) + default: + return false; } return true; } -static const char* -rtems_rtl_elf_separated_section (const char* name) -{ +static const char* rtems_rtl_elf_separated_section(const char* name) { struct { const char* label; - size_t len; + size_t len; } prefix[] = { - #define SEPARATED_PREFIX(_p) { _p, sizeof (_p) - 1 } - SEPARATED_PREFIX (".text."), - SEPARATED_PREFIX (".rel.text."), - SEPARATED_PREFIX (".data."), - SEPARATED_PREFIX (".rel.data."), - SEPARATED_PREFIX (".rodata."), - SEPARATED_PREFIX (".rel.rodata.") - }; - const size_t prefixes = sizeof (prefix) / sizeof (prefix[0]); - size_t p; - for (p = 0; p < prefixes; ++p) - { - if (strncmp (name, prefix[p].label, prefix[p].len) == 0) +#define SEPARATED_PREFIX(_p) {_p, sizeof(_p) - 1} + SEPARATED_PREFIX(".text."), SEPARATED_PREFIX(".rel.text."), + SEPARATED_PREFIX(".data."), SEPARATED_PREFIX(".rel.data."), + SEPARATED_PREFIX(".rodata."), SEPARATED_PREFIX(".rel.rodata.")}; + const size_t prefixes = sizeof(prefix) / sizeof(prefix[0]); + size_t p; + for (p = 0; p < prefixes; ++p) { + if (strncmp(name, prefix[p].label, prefix[p].len) == 0) return name + prefix[p].len; } return NULL; } -static bool -rtems_rtl_elf_find_symbol (rtems_rtl_obj* obj, - const Elf_Sym* sym, - const char* symname, - rtems_rtl_obj_sym** symbol, - Elf_Word* value) -{ +static bool rtems_rtl_elf_find_symbol(rtems_rtl_obj* obj, const Elf_Sym* sym, + const char* symname, + rtems_rtl_obj_sym** symbol, + Elf_Word* value) { rtems_rtl_obj_sect* sect; /* @@ -188,28 +166,26 @@ rtems_rtl_elf_find_symbol (rtems_rtl_obj* obj, * linker for the base image and by the TLS allocator for loaded * modules. There is no section and no absolute base. */ - if (ELF_ST_BIND (sym->st_info) == STB_GLOBAL || - sym->st_shndx == SHN_COMMON || - ELF_ST_TYPE (sym->st_info) == STT_TLS) - { + if (ELF_ST_BIND(sym->st_info) == STB_GLOBAL || sym->st_shndx == SHN_COMMON || + ELF_ST_TYPE(sym->st_info) == STT_TLS) { /* * Search the object file then the global table for the symbol. */ - *symbol = rtems_rtl_symbol_obj_find (obj, symname); + *symbol = rtems_rtl_symbol_obj_find(obj, symname); if (!*symbol) return false; - *value = (Elf_Addr)(uintptr_t) (*symbol)->value; + *value = (Elf_Addr)(uintptr_t)(*symbol)->value; return true; } *symbol = NULL; - sect = rtems_rtl_obj_find_section_by_index (obj, sym->st_shndx); + sect = rtems_rtl_obj_find_section_by_index(obj, sym->st_shndx); if (!sect) return false; - *value = sym->st_value + (Elf_Addr)(uintptr_t) sect->base; + *value = sym->st_value + (Elf_Addr)(uintptr_t)sect->base; return true; } @@ -217,80 +193,68 @@ rtems_rtl_elf_find_symbol (rtems_rtl_obj* obj, /** * Relocation worker routine. */ -typedef bool (*rtems_rtl_elf_reloc_handler)(rtems_rtl_obj* obj, - bool is_rela, - void* relbuf, - rtems_rtl_obj_sect* targetsect, - rtems_rtl_obj_sym* symbol, - Elf_Sym* sym, - const char* symname, - Elf_Word symvalue, - bool resolved, - void* data); +typedef bool (*rtems_rtl_elf_reloc_handler)( + rtems_rtl_obj* obj, bool is_rela, void* relbuf, + rtems_rtl_obj_sect* targetsect, rtems_rtl_obj_sym* symbol, Elf_Sym* sym, + const char* symname, Elf_Word symvalue, bool resolved, void* data); /** * Relocation parser data. */ -typedef struct -{ +typedef struct { size_t dependents; /**< The number of dependent object files. */ size_t unresolved; /**< The number of unresolved symbols. */ } rtems_rtl_elf_reloc_data; -static bool -rtems_rtl_elf_reloc_parser (rtems_rtl_obj* obj, - bool is_rela, - void* relbuf, - rtems_rtl_obj_sect* targetsect, - rtems_rtl_obj_sym* symbol, - Elf_Sym* sym, - const char* symname, - Elf_Word symvalue, - bool resolved, - void* data) -{ - rtems_rtl_elf_reloc_data* rd = (rtems_rtl_elf_reloc_data*) data; - rtems_rtl_word rel_words[3]; - rtems_rtl_elf_rel_status rs; +static bool rtems_rtl_elf_reloc_parser(rtems_rtl_obj* obj, bool is_rela, + void* relbuf, + rtems_rtl_obj_sect* targetsect, + rtems_rtl_obj_sym* symbol, Elf_Sym* sym, + const char* symname, Elf_Word symvalue, + bool resolved, void* data) { + rtems_rtl_elf_reloc_data* rd = (rtems_rtl_elf_reloc_data*)data; + rtems_rtl_word rel_words[3]; + rtems_rtl_elf_rel_status rs; /* * TLS are not parsed. */ - if (ELF_ST_TYPE (sym->st_info) == STT_TLS) { + if (ELF_ST_TYPE(sym->st_info) == STT_TLS) { return true; } /* * Check the reloc record to see if a trampoline is needed. */ - if (is_rela) - { - const Elf_Rela* rela = (const Elf_Rela*) relbuf; - if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) - printf ("rtl: rela tramp: sym: %c:%s(%d)=%08jx type:%d off:%08jx addend:%d\n", - ELF_ST_BIND (sym->st_info) == STB_GLOBAL || - ELF_ST_BIND (sym->st_info) == STB_WEAK ? 'G' : 'L', - symname, (int) ELF_R_SYM (rela->r_info), - (uintmax_t) symvalue, (int) ELF_R_TYPE (rela->r_info), - (uintmax_t) rela->r_offset, (int) rela->r_addend); - rs = rtems_rtl_elf_relocate_rela_tramp (obj, rela, targetsect, - symname, sym->st_info, symvalue); + if (is_rela) { + const Elf_Rela* rela = (const Elf_Rela*)relbuf; + if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC)) + printf( + "rtl: rela tramp: sym: %c:%s(%d)=%08jx type:%d off:%08jx addend:%d\n", + ELF_ST_BIND(sym->st_info) == STB_GLOBAL || + ELF_ST_BIND(sym->st_info) == STB_WEAK + ? 'G' + : 'L', + symname, (int)ELF_R_SYM(rela->r_info), (uintmax_t)symvalue, + (int)ELF_R_TYPE(rela->r_info), (uintmax_t)rela->r_offset, + (int)rela->r_addend); + rs = rtems_rtl_elf_relocate_rela_tramp(obj, rela, targetsect, symname, + sym->st_info, symvalue); rel_words[REL_R_OFFSET] = rela->r_offset; rel_words[REL_R_INFO] = rela->r_info; rel_words[REL_R_ADDEND] = rela->r_addend; - } - else - { - const Elf_Rel* rel = (const Elf_Rel*) relbuf; - if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) - printf ("rtl: rel tramp: sym: %c:%s(%d)=%08jx type:%d off:%08jx\n", - ELF_ST_BIND (sym->st_info) == STB_GLOBAL || - ELF_ST_BIND (sym->st_info) == STB_WEAK ? 'G' : 'L', - symname, (int) ELF_R_SYM (rel->r_info), - (uintmax_t) symvalue, (int) ELF_R_TYPE (rel->r_info), - (uintmax_t) rel->r_offset); - rs = rtems_rtl_elf_relocate_rel_tramp (obj, rel, targetsect, - symname, sym->st_info, symvalue); + } else { + const Elf_Rel* rel = (const Elf_Rel*)relbuf; + if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC)) + printf("rtl: rel tramp: sym: %c:%s(%d)=%08jx type:%d off:%08jx\n", + ELF_ST_BIND(sym->st_info) == STB_GLOBAL || + ELF_ST_BIND(sym->st_info) == STB_WEAK + ? 'G' + : 'L', + symname, (int)ELF_R_SYM(rel->r_info), (uintmax_t)symvalue, + (int)ELF_R_TYPE(rel->r_info), (uintmax_t)rel->r_offset); + rs = rtems_rtl_elf_relocate_rel_tramp(obj, rel, targetsect, symname, + sym->st_info, symvalue); rel_words[REL_R_OFFSET] = rel->r_offset; rel_words[REL_R_INFO] = rel->r_info; rel_words[REL_R_ADDEND] = 0; @@ -299,33 +263,31 @@ rtems_rtl_elf_reloc_parser (rtems_rtl_obj* obj, if (rs == rtems_rtl_elf_rel_failure) return false; - if (rs == rtems_rtl_elf_rel_tramp_cache || rs == rtems_rtl_elf_rel_tramp_add) - { - uint32_t flags = (is_rela ? 1 : 0) | (resolved ? 0 : 1 << 1) | (sym->st_info << 8); - if (!rtems_rtl_trampoline_add (obj, flags, - targetsect->section, symvalue, rel_words)) + if (rs == rtems_rtl_elf_rel_tramp_cache || + rs == rtems_rtl_elf_rel_tramp_add) { + uint32_t flags = + (is_rela ? 1 : 0) | (resolved ? 0 : 1 << 1) | (sym->st_info << 8); + if (!rtems_rtl_trampoline_add(obj, flags, targetsect->section, symvalue, + rel_words)) return false; } /* * Handle any dependencies if there is a valid symbol. */ - if (symname != NULL) - { + if (symname != NULL) { /* * Find the symbol's object file. It cannot be NULL so ignore that result * if returned, it means something is corrupted. We are in an iterator. */ - rtems_rtl_obj* sobj = rtems_rtl_find_obj_with_symbol (symbol); - if (sobj != NULL) - { + rtems_rtl_obj* sobj = rtems_rtl_find_obj_with_symbol(symbol); + if (sobj != NULL) { /* * A dependency is not the base kernel image or itself. Tag the object as * having been visited so we count it only once. */ - if (sobj != rtems_rtl_baseimage () && obj != sobj && - (sobj->flags & RTEMS_RTL_OBJ_RELOC_TAG) == 0) - { + if (sobj != rtems_rtl_baseimage() && obj != sobj && + (sobj->flags & RTEMS_RTL_OBJ_RELOC_TAG) == 0) { sobj->flags |= RTEMS_RTL_OBJ_RELOC_TAG; ++rd->dependents; } @@ -335,121 +297,94 @@ rtems_rtl_elf_reloc_parser (rtems_rtl_obj* obj, return true; } -static bool -rtems_rtl_elf_reloc_relocator (rtems_rtl_obj* obj, - bool is_rela, - void* relbuf, - rtems_rtl_obj_sect* targetsect, - rtems_rtl_obj_sym* symbol, - Elf_Sym* sym, - const char* symname, - Elf_Word symvalue, - bool resolved, - void* data) -{ - (void) data; +static bool rtems_rtl_elf_reloc_relocator( + rtems_rtl_obj* obj, bool is_rela, void* relbuf, + rtems_rtl_obj_sect* targetsect, rtems_rtl_obj_sym* symbol, Elf_Sym* sym, + const char* symname, Elf_Word symvalue, bool resolved, void* data) { + (void)data; - const Elf_Rela* rela = (const Elf_Rela*) relbuf; - const Elf_Rel* rel = (const Elf_Rel*) relbuf; + const Elf_Rela* rela = (const Elf_Rela*)relbuf; + const Elf_Rel* rel = (const Elf_Rel*)relbuf; - if (!resolved) - { - uint16_t flags = 0; + if (!resolved) { + uint16_t flags = 0; rtems_rtl_word rel_words[3]; - if (is_rela) - { + if (is_rela) { flags = 1; rel_words[REL_R_OFFSET] = rela->r_offset; rel_words[REL_R_INFO] = rela->r_info; rel_words[REL_R_ADDEND] = rela->r_addend; - } - else - { + } else { rel_words[REL_R_OFFSET] = rel->r_offset; rel_words[REL_R_INFO] = rel->r_info; rel_words[REL_R_ADDEND] = 0; } - if (!rtems_rtl_unresolved_add (obj, - flags, - symname, - targetsect->section, - rel_words)) + if (!rtems_rtl_unresolved_add(obj, flags, symname, targetsect->section, + rel_words)) return false; ++obj->unresolved; - } - else - { - rtems_rtl_obj* sobj; + } else { + rtems_rtl_obj* sobj; rtems_rtl_elf_rel_status rs; - if (is_rela) - { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) - printf ("rtl: rela: sym:%s(%d)=%08jx type:%d off:%08jx addend:%d\n", - symname, (int) ELF_R_SYM (rela->r_info), - (uintmax_t) symvalue, (int) ELF_R_TYPE (rela->r_info), - (uintmax_t) rela->r_offset, (int) rela->r_addend); - rs = rtems_rtl_elf_relocate_rela (obj, rela, targetsect, - symname, sym->st_info, symvalue); + if (is_rela) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC)) + printf("rtl: rela: sym:%s(%d)=%08jx type:%d off:%08jx addend:%d\n", + symname, (int)ELF_R_SYM(rela->r_info), (uintmax_t)symvalue, + (int)ELF_R_TYPE(rela->r_info), (uintmax_t)rela->r_offset, + (int)rela->r_addend); + rs = rtems_rtl_elf_relocate_rela(obj, rela, targetsect, symname, + sym->st_info, symvalue); if (rs != rtems_rtl_elf_rel_no_error) return false; - } - else - { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) - printf ("rtl: rel: sym:%s(%d)=%08jx type:%d off:%08jx\n", - symname, (int) ELF_R_SYM (rel->r_info), - (uintmax_t) symvalue, (int) ELF_R_TYPE (rel->r_info), - (uintmax_t) rel->r_offset); - rs = rtems_rtl_elf_relocate_rel (obj, rel, targetsect, - symname, sym->st_info, symvalue); + } else { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC)) + printf("rtl: rel: sym:%s(%d)=%08jx type:%d off:%08jx\n", symname, + (int)ELF_R_SYM(rel->r_info), (uintmax_t)symvalue, + (int)ELF_R_TYPE(rel->r_info), (uintmax_t)rel->r_offset); + rs = rtems_rtl_elf_relocate_rel(obj, rel, targetsect, symname, + sym->st_info, symvalue); if (rs != rtems_rtl_elf_rel_no_error) return false; } - sobj = rtems_rtl_find_obj_with_symbol (symbol); + sobj = rtems_rtl_find_obj_with_symbol(symbol); - if (rtems_rtl_trace (RTEMS_RTL_TRACE_DEPENDENCY)) - printf ("rtl: depend: %s -> %s:%s\n", - obj->oname, - sobj == NULL ? "not-found" : sobj->oname, - symname); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_DEPENDENCY)) + printf("rtl: depend: %s -> %s:%s\n", obj->oname, + sobj == NULL ? "not-found" : sobj->oname, symname); - if (sobj != NULL) - { - if (rtems_rtl_obj_add_dependent (obj, sobj)) - rtems_rtl_obj_inc_reference (sobj); + if (sobj != NULL) { + if (rtems_rtl_obj_add_dependent(obj, sobj)) + rtems_rtl_obj_inc_reference(sobj); } } return true; } -static bool -rtems_rtl_elf_relocate_worker (rtems_rtl_obj* obj, - int fd, - rtems_rtl_obj_sect* sect, - rtems_rtl_elf_reloc_handler handler, - void* data) -{ +static bool rtems_rtl_elf_relocate_worker(rtems_rtl_obj* obj, int fd, + rtems_rtl_obj_sect* sect, + rtems_rtl_elf_reloc_handler handler, + void* data) { rtems_rtl_obj_cache* symbols; rtems_rtl_obj_cache* strings; rtems_rtl_obj_cache* relocs; - rtems_rtl_obj_sect* targetsect; - rtems_rtl_obj_sect* symsect; - rtems_rtl_obj_sect* strtab; - bool is_rela; - size_t reloc_size; - size_t reloc; + rtems_rtl_obj_sect* targetsect; + rtems_rtl_obj_sect* symsect; + rtems_rtl_obj_sect* strtab; + bool is_rela; + size_t reloc_size; + size_t reloc; /* * First check if the section the relocations are for exists. If it does not * exist ignore these relocations. They are most probably debug sections. */ - targetsect = rtems_rtl_obj_find_section_by_index (obj, sect->info); + targetsect = rtems_rtl_obj_find_section_by_index(obj, sect->info); if (!targetsect) return true; @@ -460,53 +395,50 @@ rtems_rtl_elf_relocate_worker (rtems_rtl_obj* obj, if ((targetsect->flags & RTEMS_RTL_OBJ_SECT_LOAD) == 0) return true; - - rtems_rtl_obj_caches (&symbols, &strings, &relocs); + rtems_rtl_obj_caches(&symbols, &strings, &relocs); if (!symbols || !strings || !relocs) return false; - symsect = rtems_rtl_obj_find_section (obj, ".symtab"); - if (!symsect) - { - rtems_rtl_set_error (EINVAL, "no .symtab section"); + symsect = rtems_rtl_obj_find_section(obj, ".symtab"); + if (!symsect) { + rtems_rtl_set_error(EINVAL, "no .symtab section"); return false; } - strtab = rtems_rtl_obj_find_section (obj, ".strtab"); - if (!strtab) - { - rtems_rtl_set_error (EINVAL, "no .strtab section"); + strtab = rtems_rtl_obj_find_section(obj, ".strtab"); + if (!strtab) { + rtems_rtl_set_error(EINVAL, "no .strtab section"); return false; } - if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) - printf ("rtl: relocation: %s, syms:%s\n", sect->name, symsect->name); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC)) + printf("rtl: relocation: %s, syms:%s\n", sect->name, symsect->name); /* * Handle the different relocation record types. */ - is_rela = ((sect->flags & RTEMS_RTL_OBJ_SECT_RELA) == - RTEMS_RTL_OBJ_SECT_RELA) ? true : false; - reloc_size = is_rela ? sizeof (Elf_Rela) : sizeof (Elf_Rel); + is_rela = ((sect->flags & RTEMS_RTL_OBJ_SECT_RELA) == RTEMS_RTL_OBJ_SECT_RELA) + ? true + : false; + reloc_size = is_rela ? sizeof(Elf_Rela) : sizeof(Elf_Rel); - for (reloc = 0; reloc < (sect->size / reloc_size); ++reloc) - { - uint8_t relbuf[reloc_size]; - const Elf_Rela* rela = (const Elf_Rela*) relbuf; - const Elf_Rel* rel = (const Elf_Rel*) relbuf; + for (reloc = 0; reloc < (sect->size / reloc_size); ++reloc) { + uint8_t relbuf[reloc_size]; + const Elf_Rela* rela = (const Elf_Rela*)relbuf; + const Elf_Rel* rel = (const Elf_Rel*)relbuf; rtems_rtl_obj_sym* symbol = NULL; - Elf_Sym sym; - const char* symname = NULL; - off_t off; - Elf_Word rel_type; - Elf_Word symvalue = 0; - bool resolved; + Elf_Sym sym; + const char* symname = NULL; + off_t off; + Elf_Word rel_type; + Elf_Word symvalue = 0; + bool resolved; off = obj->ooffset + sect->offset + (reloc * reloc_size); - if (!rtems_rtl_obj_cache_read_byval (relocs, fd, off, - &relbuf[0], reloc_size)) + if (!rtems_rtl_obj_cache_read_byval(relocs, fd, off, &relbuf[0], + reloc_size)) return false; /* @@ -514,31 +446,27 @@ rtems_rtl_elf_relocate_worker (rtems_rtl_obj* obj, */ if (is_rela) off = (obj->ooffset + symsect->offset + - (ELF_R_SYM (rela->r_info) * sizeof (sym))); + (ELF_R_SYM(rela->r_info) * sizeof(sym))); else off = (obj->ooffset + symsect->offset + - (ELF_R_SYM (rel->r_info) * sizeof (sym))); + (ELF_R_SYM(rel->r_info) * sizeof(sym))); - if (!rtems_rtl_obj_cache_read_byval (symbols, fd, off, - &sym, sizeof (sym))) + if (!rtems_rtl_obj_cache_read_byval(symbols, fd, off, &sym, sizeof(sym))) return false; /* * Only need the name of the symbol if global or a common symbol. */ - if (ELF_ST_TYPE (sym.st_info) == STT_OBJECT || - ELF_ST_TYPE (sym.st_info) == STT_COMMON || - ELF_ST_TYPE (sym.st_info) == STT_FUNC || - ELF_ST_TYPE (sym.st_info) == STT_NOTYPE || - ELF_ST_TYPE (sym.st_info) == STT_TLS || - sym.st_shndx == SHN_COMMON) - { + if (ELF_ST_TYPE(sym.st_info) == STT_OBJECT || + ELF_ST_TYPE(sym.st_info) == STT_COMMON || + ELF_ST_TYPE(sym.st_info) == STT_FUNC || + ELF_ST_TYPE(sym.st_info) == STT_NOTYPE || + ELF_ST_TYPE(sym.st_info) == STT_TLS || sym.st_shndx == SHN_COMMON) { size_t len; off = obj->ooffset + strtab->offset + sym.st_name; len = RTEMS_RTL_ELF_STRING_MAX; - if (!rtems_rtl_obj_cache_read (strings, fd, off, - (void**) &symname, &len)) + if (!rtems_rtl_obj_cache_read(strings, fd, off, (void**)&symname, &len)) return false; } @@ -555,17 +483,14 @@ rtems_rtl_elf_relocate_worker (rtems_rtl_obj* obj, resolved = true; - if (rtems_rtl_elf_rel_resolve_sym (rel_type)) - resolved = rtems_rtl_elf_find_symbol (obj, - &sym, symname, - &symbol, &symvalue); + if (rtems_rtl_elf_rel_resolve_sym(rel_type)) + resolved = + rtems_rtl_elf_find_symbol(obj, &sym, symname, &symbol, &symvalue); if (symname != NULL && strlen(symname) == 0) resolved = true; - if (!handler (obj, - is_rela, relbuf, targetsect, - symbol, &sym, symname, symvalue, resolved, - data)) + if (!handler(obj, is_rela, relbuf, targetsect, symbol, &sym, symname, + symvalue, resolved, data)) return false; } @@ -578,96 +503,77 @@ rtems_rtl_elf_relocate_worker (rtems_rtl_obj* obj, return true; } -static bool -rtems_rtl_elf_relocs_parser (rtems_rtl_obj* obj, - int fd, - rtems_rtl_obj_sect* sect, - void* data) -{ - bool r = rtems_rtl_elf_relocate_worker (obj, fd, sect, - rtems_rtl_elf_reloc_parser, data); +static bool rtems_rtl_elf_relocs_parser(rtems_rtl_obj* obj, int fd, + rtems_rtl_obj_sect* sect, void* data) { + bool r = rtems_rtl_elf_relocate_worker(obj, fd, sect, + rtems_rtl_elf_reloc_parser, data); return r; } -static bool -rtems_rtl_elf_relocs_locator (rtems_rtl_obj* obj, - int fd, - rtems_rtl_obj_sect* sect, - void* data) -{ - return rtems_rtl_elf_relocate_worker (obj, fd, sect, - rtems_rtl_elf_reloc_relocator, data); +static bool rtems_rtl_elf_relocs_locator(rtems_rtl_obj* obj, int fd, + rtems_rtl_obj_sect* sect, void* data) { + return rtems_rtl_elf_relocate_worker(obj, fd, sect, + rtems_rtl_elf_reloc_relocator, data); } -bool -rtems_rtl_obj_relocate_unresolved (rtems_rtl_unresolv_reloc* reloc, - rtems_rtl_obj_sym* sym) -{ - rtems_rtl_obj_sect* sect; - bool is_rela; - Elf_Word symvalue; - rtems_rtl_obj* sobj; +bool rtems_rtl_obj_relocate_unresolved(rtems_rtl_unresolv_reloc* reloc, + rtems_rtl_obj_sym* sym) { + rtems_rtl_obj_sect* sect; + bool is_rela; + Elf_Word symvalue; + rtems_rtl_obj* sobj; rtems_rtl_elf_rel_status rs; is_rela = reloc->flags & 1; - sect = rtems_rtl_obj_find_section_by_index (reloc->obj, reloc->sect); - if (!sect) - { - rtems_rtl_set_error (ENOEXEC, "unresolved sect not found"); + sect = rtems_rtl_obj_find_section_by_index(reloc->obj, reloc->sect); + if (!sect) { + rtems_rtl_set_error(ENOEXEC, "unresolved sect not found"); return false; } - symvalue = (Elf_Word) (intptr_t) sym->value; - if (is_rela) - { + symvalue = (Elf_Word)(intptr_t)sym->value; + if (is_rela) { Elf_Rela rela; rela.r_offset = reloc->rel[REL_R_OFFSET]; rela.r_info = reloc->rel[REL_R_INFO]; rela.r_addend = reloc->rel[REL_R_ADDEND]; - if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) - printf ("rtl: rela: sym:%d type:%d off:%08jx addend:%d\n", - (int) ELF_R_SYM (rela.r_info), (int) ELF_R_TYPE (rela.r_info), - (uintmax_t) rela.r_offset, (int) rela.r_addend); - rs = rtems_rtl_elf_relocate_rela (reloc->obj, &rela, sect, - sym->name, sym->data, symvalue); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC)) + printf("rtl: rela: sym:%d type:%d off:%08jx addend:%d\n", + (int)ELF_R_SYM(rela.r_info), (int)ELF_R_TYPE(rela.r_info), + (uintmax_t)rela.r_offset, (int)rela.r_addend); + rs = rtems_rtl_elf_relocate_rela(reloc->obj, &rela, sect, sym->name, + sym->data, symvalue); if (rs != rtems_rtl_elf_rel_no_error) return false; - } - else - { + } else { Elf_Rel rel; rel.r_offset = reloc->rel[REL_R_OFFSET]; rel.r_info = reloc->rel[REL_R_INFO]; - if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) - printf ("rtl: rel: sym:%d type:%d off:%08jx\n", - (int) ELF_R_SYM (rel.r_info), (int) ELF_R_TYPE (rel.r_info), - (uintmax_t) rel.r_offset); - rs = rtems_rtl_elf_relocate_rel (reloc->obj, &rel, sect, - sym->name, sym->data, symvalue); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC)) + printf("rtl: rel: sym:%d type:%d off:%08jx\n", (int)ELF_R_SYM(rel.r_info), + (int)ELF_R_TYPE(rel.r_info), (uintmax_t)rel.r_offset); + rs = rtems_rtl_elf_relocate_rel(reloc->obj, &rel, sect, sym->name, + sym->data, symvalue); if (rs != rtems_rtl_elf_rel_no_error) return false; } - if (reloc->obj->unresolved > 0) - { + if (reloc->obj->unresolved > 0) { --reloc->obj->unresolved; if (reloc->obj->unresolved == 0) reloc->obj->flags &= ~RTEMS_RTL_OBJ_UNRESOLVED; } - sobj = rtems_rtl_find_obj_with_symbol (sym); + sobj = rtems_rtl_find_obj_with_symbol(sym); - if (rtems_rtl_trace (RTEMS_RTL_TRACE_DEPENDENCY)) - printf ("rtl: depend: %s -> %s:%s\n", - reloc->obj->oname, - sobj == NULL ? "not-found" : sobj->oname, - sym->name); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_DEPENDENCY)) + printf("rtl: depend: %s -> %s:%s\n", reloc->obj->oname, + sobj == NULL ? "not-found" : sobj->oname, sym->name); - if (sobj != NULL) - { - if (rtems_rtl_obj_add_dependent (reloc->obj, sobj)) - rtems_rtl_obj_inc_reference (sobj); + if (sobj != NULL) { + if (rtems_rtl_obj_add_dependent(reloc->obj, sobj)) + rtems_rtl_obj_inc_reference(sobj); } return true; @@ -676,23 +582,18 @@ rtems_rtl_obj_relocate_unresolved (rtems_rtl_unresolv_reloc* reloc, /** * Common symbol iterator data. */ -typedef struct -{ - size_t size; /**< The size of the common section */ +typedef struct { + size_t size; /**< The size of the common section */ uint32_t alignment; /**< The alignment of the common section. */ } rtems_rtl_elf_common_data; -static bool -rtems_rtl_elf_common (rtems_rtl_obj* obj, - int fd, - rtems_rtl_obj_sect* sect, - void* data) -{ - rtems_rtl_elf_common_data* common = (rtems_rtl_elf_common_data*) data; - rtems_rtl_obj_cache* symbols; - size_t sym; +static bool rtems_rtl_elf_common(rtems_rtl_obj* obj, int fd, + rtems_rtl_obj_sect* sect, void* data) { + rtems_rtl_elf_common_data* common = (rtems_rtl_elf_common_data*)data; + rtems_rtl_obj_cache* symbols; + size_t sym; - rtems_rtl_obj_caches (&symbols, NULL, NULL); + rtems_rtl_obj_caches(&symbols, NULL, NULL); if (!symbols) return false; @@ -701,27 +602,25 @@ rtems_rtl_elf_common (rtems_rtl_obj* obj, * Find the number size of the common section by finding all symbols that * reference the SHN_COMMON section. */ - for (sym = 0; sym < (sect->size / sizeof (Elf_Sym)); ++sym) - { + for (sym = 0; sym < (sect->size / sizeof(Elf_Sym)); ++sym) { Elf_Sym symbol; - off_t off; + off_t off; - off = obj->ooffset + sect->offset + (sym * sizeof (symbol)); + off = obj->ooffset + sect->offset + (sym * sizeof(symbol)); - if (!rtems_rtl_obj_cache_read_byval (symbols, fd, off, - &symbol, sizeof (symbol))) + if (!rtems_rtl_obj_cache_read_byval(symbols, fd, off, &symbol, + sizeof(symbol))) return false; if ((symbol.st_shndx == SHN_COMMON) && - ((ELF_ST_TYPE (symbol.st_info) == STT_OBJECT) || - (ELF_ST_TYPE (symbol.st_info) == STT_COMMON))) - { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_SYMBOL)) - printf ("rtl: com:elf:%-2zd bind:%-2d type:%-2d size:%d value:%d name:%d\n", - sym, (int) ELF_ST_BIND (symbol.st_info), - (int) ELF_ST_TYPE (symbol.st_info), - (int) symbol.st_size, (int) symbol.st_value, - (int) symbol.st_name); + ((ELF_ST_TYPE(symbol.st_info) == STT_OBJECT) || + (ELF_ST_TYPE(symbol.st_info) == STT_COMMON))) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_SYMBOL)) + printf( + "rtl: com:elf:%-2zd bind:%-2d type:%-2d size:%d value:%d name:%d\n", + sym, (int)ELF_ST_BIND(symbol.st_info), + (int)ELF_ST_TYPE(symbol.st_info), (int)symbol.st_size, + (int)symbol.st_value, (int)symbol.st_name); /* * If the size is zero this is the first entry, it defines the common * section's aligment. The symbol's value is the alignment. @@ -729,7 +628,7 @@ rtems_rtl_elf_common (rtems_rtl_obj* obj, if (common->size == 0) common->alignment = symbol.st_value; common->size += - rtems_rtl_obj_align (common->size, symbol.st_value) + symbol.st_size; + rtems_rtl_obj_align(common->size, symbol.st_value) + symbol.st_size; } } @@ -739,79 +638,72 @@ rtems_rtl_elf_common (rtems_rtl_obj* obj, /** * Struct to handle trampoline reloc recs in the unresolved table. */ -typedef struct rtems_rtl_tramp_data -{ - bool failure; +typedef struct rtems_rtl_tramp_data { + bool failure; rtems_rtl_obj* obj; - size_t count; - size_t total; + size_t count; + size_t total; } rtems_rtl_tramp_data; -static bool -rtems_rtl_elf_tramp_resolve_reloc (rtems_rtl_unresolv_rec* rec, - void* data) -{ - rtems_rtl_tramp_data* td = (rtems_rtl_tramp_data*) data; - if (rec->type == rtems_rtl_trampoline_reloc) - { +static bool rtems_rtl_elf_tramp_resolve_reloc(rtems_rtl_unresolv_rec* rec, + void* data) { + rtems_rtl_tramp_data* td = (rtems_rtl_tramp_data*)data; + if (rec->type == rtems_rtl_trampoline_reloc) { const rtems_rtl_tramp_reloc* tramp = &rec->rec.tramp; ++td->total; - if (tramp->obj == td->obj) - { + if (tramp->obj == td->obj) { const rtems_rtl_obj_sect* targetsect; - Elf_Byte st_info; - Elf_Word symvalue; - rtems_rtl_elf_rel_status rs; - bool* failure = (bool*) data; - const bool is_rela = (tramp->flags & 1) == 1; - const bool unresolved = (tramp->flags & (1 << 1)) != 0; + Elf_Byte st_info; + Elf_Word symvalue; + rtems_rtl_elf_rel_status rs; + bool* failure = (bool*)data; + const bool is_rela = (tramp->flags & 1) == 1; + const bool unresolved = (tramp->flags & (1 << 1)) != 0; ++td->count; - targetsect = rtems_rtl_obj_find_section_by_index (tramp->obj, tramp->sect); + targetsect = rtems_rtl_obj_find_section_by_index(tramp->obj, tramp->sect); st_info = tramp->flags >> 8; symvalue = tramp->symvalue; - if (is_rela) - { - Elf_Rela rela = { - .r_offset = tramp->rel[REL_R_OFFSET], - .r_info = tramp->rel[REL_R_INFO], - .r_addend = tramp->rel[REL_R_ADDEND] - }; - if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) - printf ("rtl: rela tramp: check: %c(%d)=%08jx type:%d off:%08jx addend:%d\n", - ELF_ST_BIND (st_info) == STB_GLOBAL || - ELF_ST_BIND (st_info) == STB_WEAK ? 'G' : 'L', - (int) ELF_R_SYM (rela.r_info), - (uintmax_t) symvalue, (int) ELF_R_TYPE (rela.r_info), - (uintmax_t) rela.r_offset, (int) rela.r_addend); - rs = rtems_rtl_elf_relocate_rela_tramp (tramp->obj, &rela, targetsect, - NULL, st_info, symvalue); - } - else - { - Elf_Rel rel = { - .r_offset = tramp->rel[REL_R_OFFSET], - .r_info = tramp->rel[REL_R_INFO], - }; - if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) - printf ("rtl: rel tramp: check: %c(%d)=%08jx type:%d off:%08jx\n", - ELF_ST_BIND (st_info) == STB_GLOBAL || - ELF_ST_BIND (st_info) == STB_WEAK ? 'G' : 'L', - (int) ELF_R_SYM (rel.r_info), - (uintmax_t) symvalue, (int) ELF_R_TYPE (rel.r_info), - (uintmax_t) rel.r_offset); - rs = rtems_rtl_elf_relocate_rel_tramp (tramp->obj, &rel, targetsect, + if (is_rela) { + Elf_Rela rela = {.r_offset = tramp->rel[REL_R_OFFSET], + .r_info = tramp->rel[REL_R_INFO], + .r_addend = tramp->rel[REL_R_ADDEND]}; + if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC)) + printf("rtl: rela tramp: check: %c(%d)=%08jx type:%d off:%08jx " + "addend:%d\n", + ELF_ST_BIND(st_info) == STB_GLOBAL || + ELF_ST_BIND(st_info) == STB_WEAK + ? 'G' + : 'L', + (int)ELF_R_SYM(rela.r_info), (uintmax_t)symvalue, + (int)ELF_R_TYPE(rela.r_info), (uintmax_t)rela.r_offset, + (int)rela.r_addend); + rs = rtems_rtl_elf_relocate_rela_tramp(tramp->obj, &rela, targetsect, NULL, st_info, symvalue); + } else { + Elf_Rel rel = { + .r_offset = tramp->rel[REL_R_OFFSET], + .r_info = tramp->rel[REL_R_INFO], + }; + if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC)) + printf("rtl: rel tramp: check: %c(%d)=%08jx type:%d off:%08jx\n", + ELF_ST_BIND(st_info) == STB_GLOBAL || + ELF_ST_BIND(st_info) == STB_WEAK + ? 'G' + : 'L', + (int)ELF_R_SYM(rel.r_info), (uintmax_t)symvalue, + (int)ELF_R_TYPE(rel.r_info), (uintmax_t)rel.r_offset); + rs = rtems_rtl_elf_relocate_rel_tramp(tramp->obj, &rel, targetsect, + NULL, st_info, symvalue); } if (unresolved || rs == rtems_rtl_elf_rel_tramp_add) ++tramp->obj->tramp_slots; - if (rs == rtems_rtl_elf_rel_failure) - { + if (rs == rtems_rtl_elf_rel_failure) { *failure = true; return true; } @@ -821,37 +713,35 @@ rtems_rtl_elf_tramp_resolve_reloc (rtems_rtl_unresolv_rec* rec, return false; } -static bool -rtems_rtl_elf_find_trampolines (rtems_rtl_obj* obj, size_t unresolved) -{ - rtems_rtl_tramp_data td = { 0 }; +static bool rtems_rtl_elf_find_trampolines(rtems_rtl_obj* obj, + size_t unresolved) { + rtems_rtl_tramp_data td = {0}; td.obj = obj; /* * See which relocs are out of range and need a trampoline. */ - rtems_rtl_unresolved_iterate (rtems_rtl_elf_tramp_resolve_reloc, &td); + rtems_rtl_unresolved_iterate(rtems_rtl_elf_tramp_resolve_reloc, &td); if (td.failure) return false; - rtems_rtl_trampoline_remove (obj); + rtems_rtl_trampoline_remove(obj); obj->tramp_relocs = obj->tramp_slots; - if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) - printf ("rtl: tramp:elf: tramps: slots:%zu count:%zu total:%zu\n", - obj->tramp_relocs, td.count, td.total); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC)) + printf("rtl: tramp:elf: tramps: slots:%zu count:%zu total:%zu\n", + obj->tramp_relocs, td.count, td.total); /* * Add on enough space to handle the unresolved externals that need to be * resolved at some point in time. They could all require fixups and * trampolines. */ obj->tramp_slots += unresolved; - if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) - printf ("rtl: tramp:elf: slots:%zu (%zu)\n", - obj->tramp_slots, obj->tramp_slots * obj->tramp_slot_size); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC)) + printf("rtl: tramp:elf: slots:%zu (%zu)\n", obj->tramp_slots, + obj->tramp_slots * obj->tramp_slot_size); return true; } -static bool -rtems_rtl_elf_dependents (rtems_rtl_obj* obj, rtems_rtl_elf_reloc_data* reloc) -{ +static bool rtems_rtl_elf_dependents(rtems_rtl_obj* obj, + rtems_rtl_elf_reloc_data* reloc) { /* * If there are dependencies and no unresolved externals allocate and size * the dependency table to the number of dependent object files. If there are @@ -859,44 +749,38 @@ rtems_rtl_elf_dependents (rtems_rtl_obj* obj, rtems_rtl_elf_reloc_data* reloc) * in time so use dynamic allocation to allocate the block size number of * entries when the entries are added. */ - if (reloc->dependents > 0 && reloc->unresolved == 0) - { - if (!rtems_rtl_obj_alloc_dependents (obj, reloc->dependents)) + if (reloc->dependents > 0 && reloc->unresolved == 0) { + if (!rtems_rtl_obj_alloc_dependents(obj, reloc->dependents)) return false; } return true; } -static bool -rtems_rtl_elf_symbols_load (rtems_rtl_obj* obj, - int fd, - rtems_rtl_obj_sect* sect, - void* data) -{ - (void) data; +static bool rtems_rtl_elf_symbols_load(rtems_rtl_obj* obj, int fd, + rtems_rtl_obj_sect* sect, void* data) { + (void)data; rtems_rtl_obj_cache* symbols; rtems_rtl_obj_cache* strings; - rtems_rtl_obj_sect* strtab; - int locals; - int local_string_space; - rtems_rtl_obj_sym* lsym; - char* lstring; - int globals; - int global_string_space; - rtems_rtl_obj_sym* gsym; - char* gstring; - size_t common_offset; - size_t sym; + rtems_rtl_obj_sect* strtab; + int locals; + int local_string_space; + rtems_rtl_obj_sym* lsym; + char* lstring; + int globals; + int global_string_space; + rtems_rtl_obj_sym* gsym; + char* gstring; + size_t common_offset; + size_t sym; - strtab = rtems_rtl_obj_find_section (obj, ".strtab"); - if (!strtab) - { - rtems_rtl_set_error (EINVAL, "no .strtab section"); + strtab = rtems_rtl_obj_find_section(obj, ".strtab"); + if (!strtab) { + rtems_rtl_set_error(EINVAL, "no .strtab section"); return false; } - rtems_rtl_obj_caches (&symbols, &strings, NULL); + rtems_rtl_obj_caches(&symbols, &strings, NULL); if (!symbols || !strings) return false; @@ -906,28 +790,27 @@ rtems_rtl_elf_symbols_load (rtems_rtl_obj* obj, * needed. Also check for duplicate symbols. */ - globals = 0; + globals = 0; global_string_space = 0; - locals = 0; - local_string_space = 0; + locals = 0; + local_string_space = 0; - for (sym = 0; sym < (sect->size / sizeof (Elf_Sym)); ++sym) - { - Elf_Sym symbol; - off_t off; + for (sym = 0; sym < (sect->size / sizeof(Elf_Sym)); ++sym) { + Elf_Sym symbol; + off_t off; const char* name; - size_t len; + size_t len; - off = obj->ooffset + sect->offset + (sym * sizeof (symbol)); + off = obj->ooffset + sect->offset + (sym * sizeof(symbol)); - if (!rtems_rtl_obj_cache_read_byval (symbols, fd, off, - &symbol, sizeof (symbol))) + if (!rtems_rtl_obj_cache_read_byval(symbols, fd, off, &symbol, + sizeof(symbol))) return false; off = obj->ooffset + strtab->offset + symbol.st_name; len = RTEMS_RTL_ELF_STRING_MAX; - if (!rtems_rtl_obj_cache_read (strings, fd, off, (void**) &name, &len)) + if (!rtems_rtl_obj_cache_read(strings, fd, off, (void**)&name, &len)) return false; /* @@ -936,41 +819,35 @@ rtems_rtl_elf_symbols_load (rtems_rtl_obj* obj, * object file has been loaded. Undefined symbols are NOTYPE so for locals * we need to make sure there is a valid seciton. */ - if (rtems_rtl_trace (RTEMS_RTL_TRACE_SYMBOL)) - printf ("rtl: sym:elf:%-4zd name:%-4d: %-20s: bind:%-2d:%-12s " \ - "type:%-2d:%-10s sect:%-5d size:%-5d value:%d\n", - sym, (int) symbol.st_name, name, - (int) ELF_ST_BIND (symbol.st_info), - rtems_rtl_elf_sym_bind_label (symbol.st_info), - (int) ELF_ST_TYPE (symbol.st_info), - rtems_rtl_elf_sym_type_label (symbol.st_info), - symbol.st_shndx, - (int) symbol.st_size, - (int) symbol.st_value); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_SYMBOL)) + printf("rtl: sym:elf:%-4zd name:%-4d: %-20s: bind:%-2d:%-12s " + "type:%-2d:%-10s sect:%-5d size:%-5d value:%d\n", + sym, (int)symbol.st_name, name, (int)ELF_ST_BIND(symbol.st_info), + rtems_rtl_elf_sym_bind_label(symbol.st_info), + (int)ELF_ST_TYPE(symbol.st_info), + rtems_rtl_elf_sym_type_label(symbol.st_info), symbol.st_shndx, + (int)symbol.st_size, (int)symbol.st_value); /* * If a duplicate forget it. */ - if (rtems_rtl_symbol_global_find (name)) + if (rtems_rtl_symbol_global_find(name)) continue; if ((symbol.st_shndx != 0) && - ((ELF_ST_TYPE (symbol.st_info) == STT_OBJECT) || - (ELF_ST_TYPE (symbol.st_info) == STT_COMMON) || - (ELF_ST_TYPE (symbol.st_info) == STT_FUNC) || - (ELF_ST_TYPE (symbol.st_info) == STT_NOTYPE))) - { + ((ELF_ST_TYPE(symbol.st_info) == STT_OBJECT) || + (ELF_ST_TYPE(symbol.st_info) == STT_COMMON) || + (ELF_ST_TYPE(symbol.st_info) == STT_FUNC) || + (ELF_ST_TYPE(symbol.st_info) == STT_NOTYPE))) { /* * There needs to be a valid section for the symbol. */ rtems_rtl_obj_sect* symsect; - symsect = rtems_rtl_obj_find_section_by_index (obj, symbol.st_shndx); - if (symsect != NULL) - { - if ((ELF_ST_BIND (symbol.st_info) == STB_GLOBAL) || - (ELF_ST_BIND (symbol.st_info) == STB_WEAK)) - { + symsect = rtems_rtl_obj_find_section_by_index(obj, symbol.st_shndx); + if (symsect != NULL) { + if ((ELF_ST_BIND(symbol.st_info) == STB_GLOBAL) || + (ELF_ST_BIND(symbol.st_info) == STB_WEAK)) { /* * If there is a globally exported symbol already present and this * symbol is not weak raise check if the object file being loaded is @@ -983,66 +860,56 @@ rtems_rtl_elf_symbols_load (rtems_rtl_obj* obj, * or weak. We accept the first weak symbol we find and make it * globally exported. */ - if (rtems_rtl_symbol_global_find (name) && - (ELF_ST_BIND (symbol.st_info) != STB_WEAK)) - { - if (!rtems_rtl_obj_aname_valid (obj)) - { - rtems_rtl_set_error (ENOMEM, "duplicate global symbol: %s", name); + if (rtems_rtl_symbol_global_find(name) && + (ELF_ST_BIND(symbol.st_info) != STB_WEAK)) { + if (!rtems_rtl_obj_aname_valid(obj)) { + rtems_rtl_set_error(ENOMEM, "duplicate global symbol: %s", name); return false; } - } - else - { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_SYMBOL)) - printf ("rtl: sym:elf:%-4zd name:%-4d: %-20s: global\n", - sym, (int) symbol.st_name, name); + } else { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_SYMBOL)) + printf("rtl: sym:elf:%-4zd name:%-4d: %-20s: global\n", sym, + (int)symbol.st_name, name); ++globals; - global_string_space += strlen (name) + 1; + global_string_space += strlen(name) + 1; } - } - else if (ELF_ST_BIND (symbol.st_info) == STB_LOCAL) - { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_SYMBOL)) - printf ("rtl: sym:elf:%-4zd name:%-4d: %-20s: local\n", - sym, (int) symbol.st_name, name); + } else if (ELF_ST_BIND(symbol.st_info) == STB_LOCAL) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_SYMBOL)) + printf("rtl: sym:elf:%-4zd name:%-4d: %-20s: local\n", sym, + (int)symbol.st_name, name); ++locals; - local_string_space += strlen (name) + 1; + local_string_space += strlen(name) + 1; } } } } - if (locals) - { - obj->local_size = locals * sizeof (rtems_rtl_obj_sym) + local_string_space; - obj->local_table = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_SYMBOL, - obj->local_size, true); - if (!obj->local_table) - { + if (locals) { + obj->local_size = locals * sizeof(rtems_rtl_obj_sym) + local_string_space; + obj->local_table = + rtems_rtl_alloc_new(RTEMS_RTL_ALLOC_SYMBOL, obj->local_size, true); + if (!obj->local_table) { obj->local_size = 0; - rtems_rtl_set_error (ENOMEM, "no memory for obj local syms"); + rtems_rtl_set_error(ENOMEM, "no memory for obj local syms"); return false; } obj->local_syms = locals; } - if (globals) - { - obj->global_size = globals * sizeof (rtems_rtl_obj_sym) + global_string_space; - obj->global_table = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_SYMBOL, - obj->global_size, true); - if (!obj->global_table) - { - if (locals) - { - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_SYMBOL, obj->local_table); + if (globals) { + obj->global_size = + globals * sizeof(rtems_rtl_obj_sym) + global_string_space; + obj->global_table = + rtems_rtl_alloc_new(RTEMS_RTL_ALLOC_SYMBOL, obj->global_size, true); + if (!obj->global_table) { + if (locals) { + rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_SYMBOL, obj->local_table); obj->local_size = 0; obj->local_syms = 0; } obj->global_size = 0; - rtems_rtl_set_error (ENOMEM, "no memory for obj global syms"); + rtems_rtl_set_error(ENOMEM, "no memory for obj global syms"); return false; } @@ -1050,35 +917,30 @@ rtems_rtl_elf_symbols_load (rtems_rtl_obj* obj, } lsym = obj->local_table; - lstring = - (((char*) obj->local_table) + (locals * sizeof (rtems_rtl_obj_sym))); + lstring = (((char*)obj->local_table) + (locals * sizeof(rtems_rtl_obj_sym))); gsym = obj->global_table; gstring = - (((char*) obj->global_table) + (globals * sizeof (rtems_rtl_obj_sym))); + (((char*)obj->global_table) + (globals * sizeof(rtems_rtl_obj_sym))); common_offset = 0; - for (sym = 0; sym < (sect->size / sizeof (Elf_Sym)); ++sym) - { + for (sym = 0; sym < (sect->size / sizeof(Elf_Sym)); ++sym) { Elf_Sym symbol; - off_t off; - size_t len; + off_t off; + size_t len; - off = obj->ooffset + sect->offset + (sym * sizeof (symbol)); + off = obj->ooffset + sect->offset + (sym * sizeof(symbol)); - if (!rtems_rtl_obj_cache_read_byval (symbols, fd, off, - &symbol, sizeof (symbol))) - { - if (obj->local_syms) - { - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_SYMBOL, obj->local_table); + if (!rtems_rtl_obj_cache_read_byval(symbols, fd, off, &symbol, + sizeof(symbol))) { + if (obj->local_syms) { + rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_SYMBOL, obj->local_table); obj->local_table = NULL; obj->local_size = 0; obj->local_syms = 0; } - if (obj->global_syms) - { - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_SYMBOL, obj->global_table); + if (obj->global_syms) { + rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_SYMBOL, obj->global_table); obj->global_table = NULL; obj->global_syms = 0; obj->global_size = 0; @@ -1087,61 +949,54 @@ rtems_rtl_elf_symbols_load (rtems_rtl_obj* obj, } if ((symbol.st_shndx != 0) && - ((ELF_ST_TYPE (symbol.st_info) == STT_OBJECT) || - (ELF_ST_TYPE (symbol.st_info) == STT_COMMON) || - (ELF_ST_TYPE (symbol.st_info) == STT_FUNC) || - (ELF_ST_TYPE (symbol.st_info) == STT_NOTYPE)) && - ((ELF_ST_BIND (symbol.st_info) == STB_GLOBAL) || - (ELF_ST_BIND (symbol.st_info) == STB_WEAK) || - (ELF_ST_BIND (symbol.st_info) == STB_LOCAL))) - { + ((ELF_ST_TYPE(symbol.st_info) == STT_OBJECT) || + (ELF_ST_TYPE(symbol.st_info) == STT_COMMON) || + (ELF_ST_TYPE(symbol.st_info) == STT_FUNC) || + (ELF_ST_TYPE(symbol.st_info) == STT_NOTYPE)) && + ((ELF_ST_BIND(symbol.st_info) == STB_GLOBAL) || + (ELF_ST_BIND(symbol.st_info) == STB_WEAK) || + (ELF_ST_BIND(symbol.st_info) == STB_LOCAL))) { rtems_rtl_obj_sect* symsect; /* * There needs to be a valid section for the symbol. */ - symsect = rtems_rtl_obj_find_section_by_index (obj, symbol.st_shndx); + symsect = rtems_rtl_obj_find_section_by_index(obj, symbol.st_shndx); - if (symsect != NULL) - { - rtems_rtl_obj_sym* osym; - char* string; - Elf_Word value; - const char* name; + if (symsect != NULL) { + rtems_rtl_obj_sym* osym; + char* string; + Elf_Word value; + const char* name; off = obj->ooffset + strtab->offset + symbol.st_name; len = RTEMS_RTL_ELF_STRING_MAX; - if (!rtems_rtl_obj_cache_read (strings, fd, off, (void**) &name, &len)) + if (!rtems_rtl_obj_cache_read(strings, fd, off, (void**)&name, &len)) return false; /* * If a duplicate forget it. */ - if (rtems_rtl_symbol_global_find (name)) + if (rtems_rtl_symbol_global_find(name)) continue; - if ((ELF_ST_BIND (symbol.st_info) == STB_GLOBAL) || - (ELF_ST_BIND (symbol.st_info) == STB_WEAK)) - { - size_t slen = strlen (name) + 1; - if ((gstring + slen) > (char*) obj->global_table + obj->global_size) + if ((ELF_ST_BIND(symbol.st_info) == STB_GLOBAL) || + (ELF_ST_BIND(symbol.st_info) == STB_WEAK)) { + size_t slen = strlen(name) + 1; + if ((gstring + slen) > (char*)obj->global_table + obj->global_size) string = NULL; - else - { + else { osym = gsym; string = gstring; gstring += slen; ++gsym; } - } - else - { - size_t slen = strlen (name) + 1; - if ((lstring + slen) > (char*) obj->local_table + obj->local_size) + } else { + size_t slen = strlen(name) + 1; + if ((lstring + slen) > (char*)obj->local_table + obj->local_size) string = NULL; - else - { + else { osym = lsym; string = lstring; lstring += slen; @@ -1152,55 +1007,49 @@ rtems_rtl_elf_symbols_load (rtems_rtl_obj* obj, /* * See if the loading has overflowed the allocated tables. */ - if (string == NULL) - { - if (obj->local_syms) - { - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_SYMBOL, obj->local_table); + if (string == NULL) { + if (obj->local_syms) { + rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_SYMBOL, obj->local_table); obj->local_table = NULL; obj->local_size = 0; obj->local_syms = 0; } - if (obj->global_syms) - { - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_SYMBOL, obj->global_table); + if (obj->global_syms) { + rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_SYMBOL, obj->global_table); obj->global_table = NULL; obj->global_syms = 0; obj->global_size = 0; } - rtems_rtl_set_error (ENOMEM, "syms overlow, parsing/loading size mismatch"); + rtems_rtl_set_error(ENOMEM, + "syms overlow, parsing/loading size mismatch"); return false; } /* * Allocate any common symbols in the common section. */ - if (symbol.st_shndx == SHN_COMMON) - { - size_t value_off = rtems_rtl_obj_align (common_offset, - symbol.st_value); + if (symbol.st_shndx == SHN_COMMON) { + size_t value_off = + rtems_rtl_obj_align(common_offset, symbol.st_value); common_offset = value_off + symbol.st_size; value = value_off; - } - else - { + } else { value = symbol.st_value; } - rtems_chain_set_off_chain (&osym->node); - memcpy (string, name, strlen (name) + 1); + rtems_chain_set_off_chain(&osym->node); + memcpy(string, name, strlen(name) + 1); osym->name = string; - osym->value = (void*) (intptr_t) value; + osym->value = (void*)(intptr_t)value; osym->data = symbol.st_shndx; - if (rtems_rtl_trace (RTEMS_RTL_TRACE_SYMBOL)) - printf ("rtl: sym:add:%-4zd name:%-4d: %-20s: bind:%-2d " \ - "type:%-2d val:%-8p sect:%-3d size:%d\n", - sym, (int) symbol.st_name, osym->name, - (int) ELF_ST_BIND (symbol.st_info), - (int) ELF_ST_TYPE (symbol.st_info), - osym->value, symbol.st_shndx, - (int) symbol.st_size); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_SYMBOL)) + printf("rtl: sym:add:%-4zd name:%-4d: %-20s: bind:%-2d " + "type:%-2d val:%-8p sect:%-3d size:%d\n", + sym, (int)symbol.st_name, osym->name, + (int)ELF_ST_BIND(symbol.st_info), + (int)ELF_ST_TYPE(symbol.st_info), osym->value, symbol.st_shndx, + (int)symbol.st_size); } } } @@ -1208,113 +1057,92 @@ rtems_rtl_elf_symbols_load (rtems_rtl_obj* obj, return true; } -static bool -rtems_rtl_elf_symbols_locate (rtems_rtl_obj* obj, - int fd, - rtems_rtl_obj_sect* sect, - void* data) -{ - (void) fd; - (void) sect; - (void) data; +static bool rtems_rtl_elf_symbols_locate(rtems_rtl_obj* obj, int fd, + rtems_rtl_obj_sect* sect, void* data) { + (void)fd; + (void)sect; + (void)data; size_t sym; - for (sym = 0; sym < obj->local_syms; ++sym) - { - rtems_rtl_obj_sym* osym = &obj->local_table[sym]; - rtems_rtl_obj_sect* symsect; - symsect = rtems_rtl_obj_find_section_by_index (obj, osym->data); - if (symsect) - { - osym->value += (intptr_t) symsect->base; - if (rtems_rtl_trace (RTEMS_RTL_TRACE_SYMBOL)) - printf ("rtl: sym:locate:local :%-4zd name: %-20s val:%-8p sect:%-3d (%s, %p)\n", - sym, osym->name, osym->value, osym->data, - symsect->name, symsect->base); - } + for (sym = 0; sym < obj->local_syms; ++sym) { + rtems_rtl_obj_sym* osym = &obj->local_table[sym]; + rtems_rtl_obj_sect* symsect; + symsect = rtems_rtl_obj_find_section_by_index(obj, osym->data); + if (symsect) { + osym->value += (intptr_t)symsect->base; + if (rtems_rtl_trace(RTEMS_RTL_TRACE_SYMBOL)) + printf("rtl: sym:locate:local :%-4zd name: %-20s val:%-8p sect:%-3d " + "(%s, %p)\n", + sym, osym->name, osym->value, osym->data, symsect->name, + symsect->base); + } } - for (sym = 0; sym < obj->global_syms; ++sym) - { - rtems_rtl_obj_sym* osym = &obj->global_table[sym]; - rtems_rtl_obj_sect* symsect; - symsect = rtems_rtl_obj_find_section_by_index (obj, osym->data); - if (symsect) - { - osym->value += (intptr_t) symsect->base; - if (rtems_rtl_trace (RTEMS_RTL_TRACE_SYMBOL)) - printf ("rtl: sym:locate:global:%-4zd name: %-20s val:%-8p sect:%-3d (%s, %p)\n", - sym, osym->name, osym->value, osym->data, - symsect->name, symsect->base); - } + for (sym = 0; sym < obj->global_syms; ++sym) { + rtems_rtl_obj_sym* osym = &obj->global_table[sym]; + rtems_rtl_obj_sect* symsect; + symsect = rtems_rtl_obj_find_section_by_index(obj, osym->data); + if (symsect) { + osym->value += (intptr_t)symsect->base; + if (rtems_rtl_trace(RTEMS_RTL_TRACE_SYMBOL)) + printf("rtl: sym:locate:global:%-4zd name: %-20s val:%-8p sect:%-3d " + "(%s, %p)\n", + sym, osym->name, osym->value, osym->data, symsect->name, + symsect->base); + } } if (obj->global_size) - rtems_rtl_symbol_obj_add (obj); + rtems_rtl_symbol_obj_add(obj); return true; } -static bool -rtems_rtl_elf_arch_alloc (rtems_rtl_obj* obj, - int fd, - rtems_rtl_obj_sect* sect, - void* data) -{ - (void) fd; - (void) data; +static bool rtems_rtl_elf_arch_alloc(rtems_rtl_obj* obj, int fd, + rtems_rtl_obj_sect* sect, void* data) { + (void)fd; + (void)data; - if (rtems_rtl_obj_sect_is_arch_alloc (sect)) - return rtems_rtl_elf_arch_section_alloc (obj, sect); + if (rtems_rtl_obj_sect_is_arch_alloc(sect)) + return rtems_rtl_elf_arch_section_alloc(obj, sect); return true; } -static bool -rtems_rtl_elf_arch_free (rtems_rtl_obj* obj) -{ +static bool rtems_rtl_elf_arch_free(rtems_rtl_obj* obj) { int index = -1; - while (true) - { + while (true) { rtems_rtl_obj_sect* sect; - sect = rtems_rtl_obj_find_section_by_mask (obj, - index, - RTEMS_RTL_OBJ_SECT_ARCH_ALLOC); + sect = rtems_rtl_obj_find_section_by_mask(obj, index, + RTEMS_RTL_OBJ_SECT_ARCH_ALLOC); if (sect == NULL) break; - if (!rtems_rtl_elf_arch_section_free (obj, sect)) + if (!rtems_rtl_elf_arch_section_free(obj, sect)) return false; index = sect->section; } return true; } -static bool -rtems_rtl_elf_loader (rtems_rtl_obj* obj, - int fd, - rtems_rtl_obj_sect* sect, - void* data) -{ - (void) data; +static bool rtems_rtl_elf_loader(rtems_rtl_obj* obj, int fd, + rtems_rtl_obj_sect* sect, void* data) { + (void)data; uint8_t* base_offset; - size_t len; + size_t len; - if (lseek (fd, obj->ooffset + sect->offset, SEEK_SET) < 0) - { - rtems_rtl_set_error (errno, "section load seek failed"); + if (lseek(fd, obj->ooffset + sect->offset, SEEK_SET) < 0) { + rtems_rtl_set_error(errno, "section load seek failed"); return false; } base_offset = sect->base; len = sect->size; - while (len) - { - ssize_t r = read (fd, base_offset, len); - if (r <= 0) - { - rtems_rtl_set_error (errno, "section load read failed"); + while (len) { + ssize_t r = read(fd, base_offset, len); + if (r <= 0) { + rtems_rtl_set_error(errno, "section load read failed"); return false; } base_offset += r; @@ -1324,17 +1152,16 @@ rtems_rtl_elf_loader (rtems_rtl_obj* obj, return true; } -static bool -rtems_rtl_elf_parse_sections (rtems_rtl_obj* obj, int fd, Elf_Ehdr* ehdr) -{ +static bool rtems_rtl_elf_parse_sections(rtems_rtl_obj* obj, int fd, + Elf_Ehdr* ehdr) { rtems_rtl_obj_cache* sects; rtems_rtl_obj_cache* strings; - int section; - off_t sectstroff; - off_t off; - Elf_Shdr shdr; + int section; + off_t sectstroff; + off_t off; + Elf_Shdr shdr; - rtems_rtl_obj_caches (§s, &strings, NULL); + rtems_rtl_obj_caches(§s, &strings, NULL); if (!sects || !strings) return false; @@ -1344,145 +1171,136 @@ rtems_rtl_elf_parse_sections (rtems_rtl_obj* obj, int fd, Elf_Ehdr* ehdr) */ off = obj->ooffset + ehdr->e_shoff + (ehdr->e_shstrndx * ehdr->e_shentsize); - if (!rtems_rtl_obj_cache_read_byval (sects, fd, off, &shdr, sizeof (shdr))) + if (!rtems_rtl_obj_cache_read_byval(sects, fd, off, &shdr, sizeof(shdr))) return false; - if (shdr.sh_type != SHT_STRTAB) - { - rtems_rtl_set_error (EINVAL, "bad .sectstr section type"); + if (shdr.sh_type != SHT_STRTAB) { + rtems_rtl_set_error(EINVAL, "bad .sectstr section type"); return false; } sectstroff = obj->ooffset + shdr.sh_offset; - for (section = 0; section < ehdr->e_shnum; ++section) - { - char* name; - size_t len; + for (section = 0; section < ehdr->e_shnum; ++section) { + char* name; + size_t len; uint32_t flags; /* * Make sure section is at least 32bits to avoid 16-bit overflow errors. */ - off = obj->ooffset + ehdr->e_shoff + (((uint32_t) section) * ehdr->e_shentsize); + off = obj->ooffset + ehdr->e_shoff + + (((uint32_t)section) * ehdr->e_shentsize); - if (rtems_rtl_trace (RTEMS_RTL_TRACE_DETAIL)) - printf ("rtl: section header: %2d: offset=%d\n", section, (int) off); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_DETAIL)) + printf("rtl: section header: %2d: offset=%d\n", section, (int)off); - if (!rtems_rtl_obj_cache_read_byval (sects, fd, off, &shdr, sizeof (shdr))) + if (!rtems_rtl_obj_cache_read_byval(sects, fd, off, &shdr, sizeof(shdr))) return false; len = RTEMS_RTL_ELF_STRING_MAX; - if (!rtems_rtl_obj_cache_read (strings, fd, - sectstroff + shdr.sh_name, - (void**) &name, &len)) + if (!rtems_rtl_obj_cache_read(strings, fd, sectstroff + shdr.sh_name, + (void**)&name, &len)) return false; - if (rtems_rtl_trace (RTEMS_RTL_TRACE_DETAIL)) - printf ("rtl: section: %2d: name=%s type=%d flags=%08x link=%d info=%d\n", - section, name, (int) shdr.sh_type, (unsigned int) shdr.sh_flags, - (int) shdr.sh_link, (int) shdr.sh_info); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_DETAIL)) + printf("rtl: section: %2d: name=%s type=%d flags=%08x link=%d info=%d\n", + section, name, (int)shdr.sh_type, (unsigned int)shdr.sh_flags, + (int)shdr.sh_link, (int)shdr.sh_info); flags = 0; - switch (shdr.sh_type) - { - case SHT_NULL: - /* - * Ignore. - */ - break; + switch (shdr.sh_type) { + case SHT_NULL: + /* + * Ignore. + */ + break; - case SHT_PROGBITS: - /* - * There are 2 program bits sections. One is the program text and the - * other is the program data. The program text is flagged - * alloc/executable and the program data is flagged alloc/writable. - */ - if ((shdr.sh_flags & SHF_ALLOC) == SHF_ALLOC) - { - if ((shdr.sh_flags & SHF_EXECINSTR) == SHF_EXECINSTR) - flags = RTEMS_RTL_OBJ_SECT_TEXT | RTEMS_RTL_OBJ_SECT_LOAD; - else if ((shdr.sh_flags & SHF_WRITE) == SHF_WRITE) - flags = RTEMS_RTL_OBJ_SECT_DATA | RTEMS_RTL_OBJ_SECT_LOAD; - else - flags = RTEMS_RTL_OBJ_SECT_CONST | RTEMS_RTL_OBJ_SECT_LOAD; - } - break; + case SHT_PROGBITS: + /* + * There are 2 program bits sections. One is the program text and the + * other is the program data. The program text is flagged + * alloc/executable and the program data is flagged alloc/writable. + */ + if ((shdr.sh_flags & SHF_ALLOC) == SHF_ALLOC) { + if ((shdr.sh_flags & SHF_EXECINSTR) == SHF_EXECINSTR) + flags = RTEMS_RTL_OBJ_SECT_TEXT | RTEMS_RTL_OBJ_SECT_LOAD; + else if ((shdr.sh_flags & SHF_WRITE) == SHF_WRITE) + flags = RTEMS_RTL_OBJ_SECT_DATA | RTEMS_RTL_OBJ_SECT_LOAD; + else + flags = RTEMS_RTL_OBJ_SECT_CONST | RTEMS_RTL_OBJ_SECT_LOAD; + } + break; - case SHT_NOBITS: - /* - * There is 1 NOBIT section which is the .bss section. There is nothing - * but a definition as the .bss is just a clear region of memory. - */ - if ((shdr.sh_flags & (SHF_ALLOC | SHF_WRITE)) == (SHF_ALLOC | SHF_WRITE)) - flags = RTEMS_RTL_OBJ_SECT_BSS | RTEMS_RTL_OBJ_SECT_ZERO; - break; + case SHT_NOBITS: + /* + * There is 1 NOBIT section which is the .bss section. There is nothing + * but a definition as the .bss is just a clear region of memory. + */ + if ((shdr.sh_flags & (SHF_ALLOC | SHF_WRITE)) == (SHF_ALLOC | SHF_WRITE)) + flags = RTEMS_RTL_OBJ_SECT_BSS | RTEMS_RTL_OBJ_SECT_ZERO; + break; - case SHT_RELA: - flags = RTEMS_RTL_OBJ_SECT_RELA | RTEMS_RTL_OBJ_SECT_LOAD; - break; + case SHT_RELA: + flags = RTEMS_RTL_OBJ_SECT_RELA | RTEMS_RTL_OBJ_SECT_LOAD; + break; - case SHT_REL: - /* - * The sh_link holds the section index for the symbol table. The sh_info - * holds the section index the relocations apply to. - */ - flags = RTEMS_RTL_OBJ_SECT_REL | RTEMS_RTL_OBJ_SECT_LOAD; - break; + case SHT_REL: + /* + * The sh_link holds the section index for the symbol table. The sh_info + * holds the section index the relocations apply to. + */ + flags = RTEMS_RTL_OBJ_SECT_REL | RTEMS_RTL_OBJ_SECT_LOAD; + break; - case SHT_SYMTAB: - flags = RTEMS_RTL_OBJ_SECT_SYM; - break; + case SHT_SYMTAB: + flags = RTEMS_RTL_OBJ_SECT_SYM; + break; - case SHT_STRTAB: - flags = RTEMS_RTL_OBJ_SECT_STR; - break; + case SHT_STRTAB: + flags = RTEMS_RTL_OBJ_SECT_STR; + break; - case SHT_INIT_ARRAY: - /* - * Constructors are text and need to be loaded. - */ - flags = (RTEMS_RTL_OBJ_SECT_CTOR | - RTEMS_RTL_OBJ_SECT_TEXT | - RTEMS_RTL_OBJ_SECT_LOAD); - break; + case SHT_INIT_ARRAY: + /* + * Constructors are text and need to be loaded. + */ + flags = (RTEMS_RTL_OBJ_SECT_CTOR | RTEMS_RTL_OBJ_SECT_TEXT | + RTEMS_RTL_OBJ_SECT_LOAD); + break; - case SHT_FINI_ARRAY: - /* - * Destructors are text and need to be loaded. - */ - flags = (RTEMS_RTL_OBJ_SECT_DTOR | - RTEMS_RTL_OBJ_SECT_TEXT | - RTEMS_RTL_OBJ_SECT_LOAD); - break; + case SHT_FINI_ARRAY: + /* + * Destructors are text and need to be loaded. + */ + flags = (RTEMS_RTL_OBJ_SECT_DTOR | RTEMS_RTL_OBJ_SECT_TEXT | + RTEMS_RTL_OBJ_SECT_LOAD); + break; - default: - /* - * See if there are architecture specific flags? - */ - flags = rtems_rtl_elf_section_flags (obj, &shdr); - if (flags == 0) - { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_WARNING)) - printf ("rtl: unsupported section: %2d: type=%02d flags=%02x\n", - section, (int) shdr.sh_type, (int) shdr.sh_flags); - } - break; + default: + /* + * See if there are architecture specific flags? + */ + flags = rtems_rtl_elf_section_flags(obj, &shdr); + if (flags == 0) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_WARNING)) + printf("rtl: unsupported section: %2d: type=%02d flags=%02x\n", + section, (int)shdr.sh_type, (int)shdr.sh_flags); + } + break; } - if (flags != 0) - { + if (flags != 0) { /* * If the object file is part of a library check the section's name. If it * starts with '.text.*' see if the last part is a global symbol. If a * global symbol exists we have to assume the symbol in the archive is a * duplicate can can be ignored. */ - if (rtems_rtl_obj_aname_valid (obj)) - { - const char* symname = rtems_rtl_elf_separated_section (name); - if (symname != NULL && rtems_rtl_symbol_global_find (symname)) + if (rtems_rtl_obj_aname_valid(obj)) { + const char* symname = rtems_rtl_elf_separated_section(name); + if (symname != NULL && rtems_rtl_symbol_global_find(symname)) flags &= ~RTEMS_RTL_OBJ_SECT_LOAD; } @@ -1496,13 +1314,12 @@ rtems_rtl_elf_parse_sections (rtems_rtl_obj* obj, int fd, Elf_Ehdr* ehdr) /* * Some architexctures have a named PROGBIT section for INIT/FINI. */ - if (strcmp (".ctors", name) == 0) + if (strcmp(".ctors", name) == 0) flags |= RTEMS_RTL_OBJ_SECT_CTOR; - if (strcmp (".dtors", name) == 0) + if (strcmp(".dtors", name) == 0) flags |= RTEMS_RTL_OBJ_SECT_DTOR; - if (rtems_rtl_elf_unwind_parse (obj, name, flags)) - { + if (rtems_rtl_elf_unwind_parse(obj, name, flags)) { flags &= ~(RTEMS_RTL_OBJ_SECT_TEXT | RTEMS_RTL_OBJ_SECT_CONST); flags |= RTEMS_RTL_OBJ_SECT_EH; } @@ -1510,23 +1327,22 @@ rtems_rtl_elf_parse_sections (rtems_rtl_obj* obj, int fd, Elf_Ehdr* ehdr) /* * Architecture specific parsing. Modified or extends the flags. */ - flags = rtems_rtl_elf_arch_parse_section (obj, section, name, &shdr, flags); - if (flags == 0) - { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_WARNING)) - printf ("rtl: unsupported section: %2d: type=%02d flags=%02x\n", - section, (int) shdr.sh_type, (int) shdr.sh_flags); - rtems_rtl_set_error (ENOMEM, "invalid architecture section: %s", name); + flags = + rtems_rtl_elf_arch_parse_section(obj, section, name, &shdr, flags); + if (flags == 0) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_WARNING)) + printf("rtl: unsupported section: %2d: type=%02d flags=%02x\n", + section, (int)shdr.sh_type, (int)shdr.sh_flags); + rtems_rtl_set_error(ENOMEM, "invalid architecture section: %s", name); return false; } /* * Add the section. */ - if (!rtems_rtl_obj_add_section (obj, section, name, - shdr.sh_size, shdr.sh_offset, - shdr.sh_addralign, shdr.sh_link, - shdr.sh_info, flags)) + if (!rtems_rtl_obj_add_section(obj, section, name, shdr.sh_size, + shdr.sh_offset, shdr.sh_addralign, + shdr.sh_link, shdr.sh_info, flags)) return false; } } @@ -1534,103 +1350,90 @@ rtems_rtl_elf_parse_sections (rtems_rtl_obj* obj, int fd, Elf_Ehdr* ehdr) return true; } -static bool -rtems_rtl_elf_add_common (rtems_rtl_obj* obj, size_t size, uint32_t alignment) -{ - if (size > 0) - { - if (!rtems_rtl_obj_add_section (obj, SHN_COMMON, ".common.rtems.rtl", - size, 0, alignment, 0, 0, - RTEMS_RTL_OBJ_SECT_BSS | RTEMS_RTL_OBJ_SECT_ZERO)) +static bool rtems_rtl_elf_add_common(rtems_rtl_obj* obj, size_t size, + uint32_t alignment) { + if (size > 0) { + if (!rtems_rtl_obj_add_section( + obj, SHN_COMMON, ".common.rtems.rtl", size, 0, alignment, 0, 0, + RTEMS_RTL_OBJ_SECT_BSS | RTEMS_RTL_OBJ_SECT_ZERO)) return false; } return true; } -bool -rtems_rtl_elf_file_check (rtems_rtl_obj* obj, int fd) -{ +bool rtems_rtl_elf_file_check(rtems_rtl_obj* obj, int fd) { rtems_rtl_obj_cache* header; - Elf_Ehdr ehdr; + Elf_Ehdr ehdr; - rtems_rtl_obj_caches (&header, NULL, NULL); + rtems_rtl_obj_caches(&header, NULL, NULL); - if (!rtems_rtl_obj_cache_read_byval (header, fd, obj->ooffset, - &ehdr, sizeof (ehdr))) + if (!rtems_rtl_obj_cache_read_byval(header, fd, obj->ooffset, &ehdr, + sizeof(ehdr))) return false; /* * Check we have a valid ELF file. */ - if ((memcmp (ELFMAG, ehdr.e_ident, SELFMAG) != 0) - || ehdr.e_ident[EI_CLASS] != ELFCLASS) - { + if ((memcmp(ELFMAG, ehdr.e_ident, SELFMAG) != 0) || + ehdr.e_ident[EI_CLASS] != ELFCLASS) { return false; } - if ((ehdr.e_ident[EI_VERSION] != EV_CURRENT) - || (ehdr.e_version != EV_CURRENT) - || (ehdr.e_ident[EI_DATA] != ELFDEFNNAME (MACHDEP_ENDIANNESS))) - { + if ((ehdr.e_ident[EI_VERSION] != EV_CURRENT) || + (ehdr.e_version != EV_CURRENT) || + (ehdr.e_ident[EI_DATA] != ELFDEFNNAME(MACHDEP_ENDIANNESS))) { return false; } return true; } -static bool -rtems_rtl_elf_load_linkmap (rtems_rtl_obj* obj) -{ +static bool rtems_rtl_elf_load_linkmap(rtems_rtl_obj* obj) { rtems_chain_control* sections = NULL; - rtems_chain_node* node = NULL; - int sec_num = 0; - section_detail* sd; - int i = 0; - size_t m; + rtems_chain_node* node = NULL; + int sec_num = 0; + section_detail* sd; + int i = 0; + size_t m; /* * The section masks to add to the linkmap. */ - const uint32_t sect_mask[] = { - RTEMS_RTL_OBJ_SECT_TEXT | RTEMS_RTL_OBJ_SECT_LOAD, - RTEMS_RTL_OBJ_SECT_CONST | RTEMS_RTL_OBJ_SECT_LOAD, - RTEMS_RTL_OBJ_SECT_DATA | RTEMS_RTL_OBJ_SECT_LOAD, - RTEMS_RTL_OBJ_SECT_BSS - }; - const size_t sect_masks = sizeof (sect_mask) / sizeof (sect_mask[0]); + const uint32_t sect_mask[] = { + RTEMS_RTL_OBJ_SECT_TEXT | RTEMS_RTL_OBJ_SECT_LOAD, + RTEMS_RTL_OBJ_SECT_CONST | RTEMS_RTL_OBJ_SECT_LOAD, + RTEMS_RTL_OBJ_SECT_DATA | RTEMS_RTL_OBJ_SECT_LOAD, + RTEMS_RTL_OBJ_SECT_BSS}; + const size_t sect_masks = sizeof(sect_mask) / sizeof(sect_mask[0]); /* * Caculate the size of sections' name. */ - for (m = 0; m < sect_masks; ++m) - { + for (m = 0; m < sect_masks; ++m) { sections = &obj->sections; - node = rtems_chain_first (sections); - while (!rtems_chain_is_tail (sections, node)) - { - rtems_rtl_obj_sect* sect = (rtems_rtl_obj_sect*) node; - const uint32_t mask = sect_mask[m]; - if ((sect->size != 0) && ((sect->flags & mask) == mask)) - { + node = rtems_chain_first(sections); + while (!rtems_chain_is_tail(sections, node)) { + rtems_rtl_obj_sect* sect = (rtems_rtl_obj_sect*)node; + const uint32_t mask = sect_mask[m]; + if ((sect->size != 0) && ((sect->flags & mask) == mask)) { ++sec_num; } - node = rtems_chain_next (node); + node = rtems_chain_next(node); } } obj->obj_num = 1; - obj->linkmap = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, - sizeof(struct link_map) + - sec_num * sizeof (section_detail), true); - if (!obj->linkmap) - { - rtems_rtl_set_error (ENOMEM, "no memory for obj linkmap"); + obj->linkmap = rtems_rtl_alloc_new( + RTEMS_RTL_ALLOC_OBJECT, + sizeof(struct link_map) + sec_num * sizeof(section_detail), true); + if (!obj->linkmap) { + rtems_rtl_set_error(ENOMEM, "no memory for obj linkmap"); return false; } obj->linkmap->name = obj->oname; obj->linkmap->sec_num = sec_num; - obj->linkmap->sec_detail = (section_detail*) (obj->linkmap + 1); + obj->linkmap->sec_detail = (section_detail*)(obj->linkmap + 1); obj->linkmap->rpathlen = 0; obj->linkmap->rpath = NULL; obj->linkmap->l_next = NULL; @@ -1642,122 +1445,107 @@ rtems_rtl_elf_load_linkmap (rtems_rtl_obj* obj) sd = obj->linkmap->sec_detail; - for (m = 0; m < sect_masks; ++m) - { + for (m = 0; m < sect_masks; ++m) { sections = &obj->sections; - node = rtems_chain_first (sections); - while (!rtems_chain_is_tail (sections, node)) - { - rtems_rtl_obj_sect* sect = (rtems_rtl_obj_sect*) node; - const uint32_t mask = sect_mask[m]; + node = rtems_chain_first(sections); + while (!rtems_chain_is_tail(sections, node)) { + rtems_rtl_obj_sect* sect = (rtems_rtl_obj_sect*)node; + const uint32_t mask = sect_mask[m]; - if ((sect->size != 0) && ((sect->flags & mask) == mask)) - { + if ((sect->size != 0) && ((sect->flags & mask) == mask)) { sd[i].name = sect->name; sd[i].size = sect->size; - if ((mask & RTEMS_RTL_OBJ_SECT_TEXT) != 0) - { + if ((mask & RTEMS_RTL_OBJ_SECT_TEXT) != 0) { sd[i].rap_id = rap_text; sd[i].offset = sect->base - obj->text_base; } - if ((mask & RTEMS_RTL_OBJ_SECT_CONST) != 0) - { + if ((mask & RTEMS_RTL_OBJ_SECT_CONST) != 0) { sd[i].rap_id = rap_const; sd[i].offset = sect->base - obj->const_base; } - if ((mask & RTEMS_RTL_OBJ_SECT_DATA) != 0) - { + if ((mask & RTEMS_RTL_OBJ_SECT_DATA) != 0) { sd[i].rap_id = rap_data; sd[i].offset = sect->base - obj->data_base; } - if ((mask & RTEMS_RTL_OBJ_SECT_BSS) != 0) - { + if ((mask & RTEMS_RTL_OBJ_SECT_BSS) != 0) { sd[i].rap_id = rap_bss; sd[i].offset = sect->base - obj->bss_base; } ++i; } - node = rtems_chain_next (node); + node = rtems_chain_next(node); } } return true; } -bool -rtems_rtl_elf_file_load (rtems_rtl_obj* obj, int fd) -{ - rtems_rtl_obj_cache* header; - Elf_Ehdr ehdr; - rtems_rtl_elf_reloc_data relocs = { 0 }; - rtems_rtl_elf_common_data common = { 0 }; +bool rtems_rtl_elf_file_load(rtems_rtl_obj* obj, int fd) { + rtems_rtl_obj_cache* header; + Elf_Ehdr ehdr; + rtems_rtl_elf_reloc_data relocs = {0}; + rtems_rtl_elf_common_data common = {0}; - rtems_rtl_obj_caches (&header, NULL, NULL); + rtems_rtl_obj_caches(&header, NULL, NULL); - if (!rtems_rtl_obj_cache_read_byval (header, fd, obj->ooffset, - &ehdr, sizeof (ehdr))) + if (!rtems_rtl_obj_cache_read_byval(header, fd, obj->ooffset, &ehdr, + sizeof(ehdr))) return false; /* * Check we have a valid ELF file. */ - if ((memcmp (ELFMAG, ehdr.e_ident, SELFMAG) != 0) - || ehdr.e_ident[EI_CLASS] != ELFCLASS) - { - rtems_rtl_set_error (EINVAL, "invalid ELF file format"); + if ((memcmp(ELFMAG, ehdr.e_ident, SELFMAG) != 0) || + ehdr.e_ident[EI_CLASS] != ELFCLASS) { + rtems_rtl_set_error(EINVAL, "invalid ELF file format"); return false; } - if ((ehdr.e_ident[EI_VERSION] != EV_CURRENT) - || (ehdr.e_version != EV_CURRENT) - || (ehdr.e_ident[EI_DATA] != ELFDEFNNAME (MACHDEP_ENDIANNESS))) - { - rtems_rtl_set_error (EINVAL, "unsupported ELF file version"); + if ((ehdr.e_ident[EI_VERSION] != EV_CURRENT) || + (ehdr.e_version != EV_CURRENT) || + (ehdr.e_ident[EI_DATA] != ELFDEFNNAME(MACHDEP_ENDIANNESS))) { + rtems_rtl_set_error(EINVAL, "unsupported ELF file version"); return false; } - if (!rtems_rtl_elf_machine_check (&ehdr)) - { - rtems_rtl_set_error (EINVAL, "unsupported machine type"); + if (!rtems_rtl_elf_machine_check(&ehdr)) { + rtems_rtl_set_error(EINVAL, "unsupported machine type"); return false; } - if (ehdr.e_type == ET_DYN) - { - rtems_rtl_set_error (EINVAL, "unsupported ELF file type"); + if (ehdr.e_type == ET_DYN) { + rtems_rtl_set_error(EINVAL, "unsupported ELF file type"); return false; } - if (ehdr.e_phentsize != 0) - { - rtems_rtl_set_error (EINVAL, "ELF file contains program headers"); + if (ehdr.e_phentsize != 0) { + rtems_rtl_set_error(EINVAL, "ELF file contains program headers"); return false; } - if (ehdr.e_shentsize != sizeof (Elf_Shdr)) - { - rtems_rtl_set_error (EINVAL, "invalid ELF section header size"); + if (ehdr.e_shentsize != sizeof(Elf_Shdr)) { + rtems_rtl_set_error(EINVAL, "invalid ELF section header size"); return false; } /* * Set the format's architecture's maximum tramp size. */ - obj->tramp_slot_size = rtems_rtl_elf_relocate_tramp_max_size (); + obj->tramp_slot_size = rtems_rtl_elf_relocate_tramp_max_size(); /* * Parse the section information first so we have the memory map of the object * file and the memory allocated. Any further allocations we make to complete * the load will not fragment the memory. */ - if (!rtems_rtl_elf_parse_sections (obj, fd, &ehdr)) + if (!rtems_rtl_elf_parse_sections(obj, fd, &ehdr)) return false; /* * Set the entry point if there is one. */ - obj->entry = (void*)(uintptr_t) ehdr.e_entry; + obj->entry = (void*)(uintptr_t)ehdr.e_entry; /* * Load the symbol table. @@ -1767,93 +1555,86 @@ rtems_rtl_elf_file_load (rtems_rtl_obj* obj, int fd) * 2. Add up the common. * 3. The load the symbols. */ - if (!rtems_rtl_obj_load_symbols (obj, fd, rtems_rtl_elf_common, &common)) + if (!rtems_rtl_obj_load_symbols(obj, fd, rtems_rtl_elf_common, &common)) return false; - if (!rtems_rtl_elf_add_common (obj, common.size, common.alignment)) + if (!rtems_rtl_elf_add_common(obj, common.size, common.alignment)) return false; - if (!rtems_rtl_obj_load_symbols (obj, fd, rtems_rtl_elf_symbols_load, &ehdr)) + if (!rtems_rtl_obj_load_symbols(obj, fd, rtems_rtl_elf_symbols_load, &ehdr)) return false; /* * Parse the relocation records. It lets us know how many dependents * and fixup trampolines there are. */ - if (!rtems_rtl_obj_relocate (obj, fd, rtems_rtl_elf_relocs_parser, &relocs)) + if (!rtems_rtl_obj_relocate(obj, fd, rtems_rtl_elf_relocs_parser, &relocs)) return false; /* * Lock the allocator so the section memory and the trampoline memory are as * clock as possible. */ - rtems_rtl_alloc_lock (); + rtems_rtl_alloc_lock(); /* * Allocate the sections. */ - if (!rtems_rtl_obj_alloc_sections (obj, fd, rtems_rtl_elf_arch_alloc, &ehdr)) + if (!rtems_rtl_obj_alloc_sections(obj, fd, rtems_rtl_elf_arch_alloc, &ehdr)) return false; - if (!rtems_rtl_elf_dependents (obj, &relocs)) + if (!rtems_rtl_elf_dependents(obj, &relocs)) return false; - if (!rtems_rtl_elf_find_trampolines (obj, relocs.unresolved)) + if (!rtems_rtl_elf_find_trampolines(obj, relocs.unresolved)) return false; /* * Resize the sections to allocate the trampoline memory as part of * the text section. */ - if (rtems_rtl_obj_has_trampolines (obj)) - { - if (!rtems_rtl_obj_resize_sections (obj)) + if (rtems_rtl_obj_has_trampolines(obj)) { + if (!rtems_rtl_obj_resize_sections(obj)) return false; } - if (!rtems_rtl_obj_load_symbols (obj, fd, rtems_rtl_elf_symbols_locate, &ehdr)) + if (!rtems_rtl_obj_load_symbols(obj, fd, rtems_rtl_elf_symbols_locate, &ehdr)) return false; /* * Unlock the allocator. */ - rtems_rtl_alloc_unlock (); + rtems_rtl_alloc_unlock(); /* * Load the sections and symbols and then relocation to the base address. */ - if (!rtems_rtl_obj_load_sections (obj, fd, rtems_rtl_elf_loader, &ehdr)) + if (!rtems_rtl_obj_load_sections(obj, fd, rtems_rtl_elf_loader, &ehdr)) return false; /* * Fix up the relocations. */ - if (!rtems_rtl_obj_relocate (obj, fd, rtems_rtl_elf_relocs_locator, &ehdr)) + if (!rtems_rtl_obj_relocate(obj, fd, rtems_rtl_elf_relocs_locator, &ehdr)) return false; - rtems_rtl_symbol_obj_erase_local (obj); + rtems_rtl_symbol_obj_erase_local(obj); - if (!rtems_rtl_elf_load_linkmap (obj)) - { + if (!rtems_rtl_elf_load_linkmap(obj)) { return false; } - if (!rtems_rtl_elf_unwind_register (obj)) - { + if (!rtems_rtl_elf_unwind_register(obj)) { return false; } return true; } -bool -rtems_rtl_elf_file_unload (rtems_rtl_obj* obj) -{ - rtems_rtl_elf_arch_free (obj); - rtems_rtl_elf_unwind_deregister (obj); +bool rtems_rtl_elf_file_unload(rtems_rtl_obj* obj) { + rtems_rtl_elf_arch_free(obj); + rtems_rtl_elf_unwind_deregister(obj); return true; } -rtems_rtl_loader_format* -rtems_rtl_elf_file_sig (void) -{ +rtems_rtl_loader_format* rtems_rtl_elf_file_sig(void) { return &elf_sig; } diff --git a/cpukit/libdl/rtl-elf.h b/cpukit/libdl/rtl-elf.h index 0476c1ecd7..9e71ec5cd4 100644 --- a/cpukit/libdl/rtl-elf.h +++ b/cpukit/libdl/rtl-elf.h @@ -33,7 +33,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#if !defined (_RTEMS_RTL_ELF_H_) +#if !defined(_RTEMS_RTL_ELF_H_) #define _RTEMS_RTL_ELF_H_ #include @@ -74,22 +74,21 @@ extern "C" { /** * ELF Relocation status codes. */ -typedef enum rtems_rtl_elf_rel_status -{ - rtems_rtl_elf_rel_no_error, /**< There is no error processing the record. */ - rtems_rtl_elf_rel_failure, /**< There was a failure processing the record. */ - rtems_rtl_elf_rel_tramp_cache, /**< The reloc record may need a trampoliine. */ +typedef enum rtems_rtl_elf_rel_status { + rtems_rtl_elf_rel_no_error, /**< There is no error processing the record. */ + rtems_rtl_elf_rel_failure, /**< There was a failure processing the record. */ + rtems_rtl_elf_rel_tramp_cache, /**< The reloc record may need a trampoliine. + */ rtems_rtl_elf_rel_tramp_add /**< Add a trampoliine. */ } rtems_rtl_elf_rel_status; /** * Relocation trampoline relocation data. */ -typedef struct rtems_rtl_mdreloc_trmap -{ - bool parsing; /**< The reloc records are being parsed. */ - void* tampolines; /**< The trampoline memory. */ - size_t size; /**< The trampoline size. */ +typedef struct rtems_rtl_mdreloc_trmap { + bool parsing; /**< The reloc records are being parsed. */ + void* tampolines; /**< The trampoline memory. */ + size_t size; /**< The trampoline size. */ } rtems_rtl_mdreloc_tramp; /** @@ -108,8 +107,8 @@ typedef struct rtems_rtl_mdreloc_trmap * @retval 0 Unknown or unsupported flags. * @retval uint32_t RTL object file flags. */ -uint32_t rtems_rtl_elf_section_flags (const rtems_rtl_obj* obj, - const Elf_Shdr* shdr); +uint32_t rtems_rtl_elf_section_flags(const rtems_rtl_obj* obj, + const Elf_Shdr* shdr); /** * Architecture specific handler to parse the section and add any flags that @@ -122,11 +121,10 @@ uint32_t rtems_rtl_elf_section_flags (const rtems_rtl_obj* obj, * @param flags The standard ELF parsed flags. * @retval uint32_t Extra RTL object file flags. */ -uint32_t rtems_rtl_elf_arch_parse_section (const rtems_rtl_obj* obj, - int section, - const char* name, - const Elf_Shdr* shdr, - const uint32_t flags); +uint32_t rtems_rtl_elf_arch_parse_section(const rtems_rtl_obj* obj, int section, + const char* name, + const Elf_Shdr* shdr, + const uint32_t flags); /** * Architecture specific handler to allocate a section. Some sections are @@ -136,8 +134,8 @@ uint32_t rtems_rtl_elf_arch_parse_section (const rtems_rtl_obj* obj, * @param sect The section data. * @retval true The allocator was successful. */ -bool rtems_rtl_elf_arch_section_alloc (const rtems_rtl_obj* obj, - rtems_rtl_obj_sect* sect); +bool rtems_rtl_elf_arch_section_alloc(const rtems_rtl_obj* obj, + rtems_rtl_obj_sect* sect); /** * Architecture specific handler to free a section. Some sections are @@ -147,8 +145,8 @@ bool rtems_rtl_elf_arch_section_alloc (const rtems_rtl_obj* obj, * @param sect The section data. * @retval true The allocator was successful. */ -bool rtems_rtl_elf_arch_section_free (const rtems_rtl_obj* obj, - rtems_rtl_obj_sect* sect); +bool rtems_rtl_elf_arch_section_free(const rtems_rtl_obj* obj, + rtems_rtl_obj_sect* sect); /** * Architecture specific handler to check is a relocation record's type is @@ -158,7 +156,7 @@ bool rtems_rtl_elf_arch_section_free (const rtems_rtl_obj* obj, * @retval true The relocation record require symbol resolution. * @retval false The relocation record does not require symbol resolution. */ -bool rtems_rtl_elf_rel_resolve_sym (Elf_Word type); +bool rtems_rtl_elf_rel_resolve_sym(Elf_Word type); /** * Architecture specific relocation maximum trampoline size. A trampoline entry @@ -166,7 +164,7 @@ bool rtems_rtl_elf_rel_resolve_sym (Elf_Word type); * * @return size_t The maximum size of a trampoline for this architecture. */ -size_t rtems_rtl_elf_relocate_tramp_max_size (void); +size_t rtems_rtl_elf_relocate_tramp_max_size(void); /** * Architecture specific relocation trampoline handler compiled in for a @@ -181,12 +179,9 @@ size_t rtems_rtl_elf_relocate_tramp_max_size (void); * @param symvalue If a symbol is referenced, this is the symbols value. * @retval rtems_rtl_elf_rel_status The result of the trampoline parsing. */ -rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rel_tramp (rtems_rtl_obj* obj, - const Elf_Rel* rel, - const rtems_rtl_obj_sect* sect, - const char* symname, - const Elf_Byte syminfo, - const Elf_Word symvalue); +rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rel_tramp( + rtems_rtl_obj* obj, const Elf_Rel* rel, const rtems_rtl_obj_sect* sect, + const char* symname, const Elf_Byte syminfo, const Elf_Word symvalue); /** * Architecture specific relocation handler compiled in for a specific @@ -201,12 +196,9 @@ rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rel_tramp (rtems_rtl_obj* * @param symvalue If a symbol is referenced, this is the symbols value. * @retval rtems_rtl_elf_rel_status The result of the trampoline parsing. */ -rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rela_tramp (rtems_rtl_obj* obj, - const Elf_Rela* rela, - const rtems_rtl_obj_sect* sect, - const char* symname, - const Elf_Byte syminfo, - const Elf_Word symvalue); +rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rela_tramp( + rtems_rtl_obj* obj, const Elf_Rela* rela, const rtems_rtl_obj_sect* sect, + const char* symname, const Elf_Byte syminfo, const Elf_Word symvalue); /** * Architecture specific relocation handler compiled in for a specific @@ -221,12 +213,10 @@ rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rela_tramp (rtems_rtl_obj* * @param symvalue If a symbol is referenced, this is the symbols value. * @retval rtems_rtl_elf_rel_status The result of the trampoline parsing. */ -rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rel (rtems_rtl_obj* obj, - const Elf_Rel* rel, - const rtems_rtl_obj_sect* sect, - const char* symname, - const Elf_Byte syminfo, - const Elf_Word symvalue); +rtems_rtl_elf_rel_status +rtems_rtl_elf_relocate_rel(rtems_rtl_obj* obj, const Elf_Rel* rel, + const rtems_rtl_obj_sect* sect, const char* symname, + const Elf_Byte syminfo, const Elf_Word symvalue); /** * Architecture specific relocation handler compiled in for a specific @@ -241,12 +231,10 @@ rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rel (rtems_rtl_obj* o * @param symvalue If a symbol is referenced, this is the symbols value. * @retval rtems_rtl_elf_rel_status The result of the trampoline parsing. */ -rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rela (rtems_rtl_obj* obj, - const Elf_Rela* rela, - const rtems_rtl_obj_sect* sect, - const char* symname, - const Elf_Byte syminfo, - const Elf_Word symvalue); +rtems_rtl_elf_rel_status +rtems_rtl_elf_relocate_rela(rtems_rtl_obj* obj, const Elf_Rela* rela, + const rtems_rtl_obj_sect* sect, const char* symname, + const Elf_Byte syminfo, const Elf_Word symvalue); /** * The ELF format check handler. @@ -254,7 +242,7 @@ rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rela (rtems_rtl_obj* * @param obj The object being checked. * @param fd The file descriptor. */ -bool rtems_rtl_elf_file_check (rtems_rtl_obj* obj, int fd); +bool rtems_rtl_elf_file_check(rtems_rtl_obj* obj, int fd); /** * The ELF format load handler. @@ -262,21 +250,21 @@ bool rtems_rtl_elf_file_check (rtems_rtl_obj* obj, int fd); * @param obj The object to load. * @param fd The file descriptor. */ -bool rtems_rtl_elf_file_load (rtems_rtl_obj* obj, int fd); +bool rtems_rtl_elf_file_load(rtems_rtl_obj* obj, int fd); /** * The ELF format unload handler. * * @param obj The object to unload. */ -bool rtems_rtl_elf_file_unload (rtems_rtl_obj* obj); +bool rtems_rtl_elf_file_unload(rtems_rtl_obj* obj); /** * The ELF format signature handler. * * @return rtems_rtl_loader_format* The format's signature. */ -rtems_rtl_loader_format* rtems_rtl_elf_file_sig (void); +rtems_rtl_loader_format* rtems_rtl_elf_file_sig(void); #ifdef __cplusplus } diff --git a/cpukit/libdl/rtl-error.c b/cpukit/libdl/rtl-error.c index b3234031d7..1a5503b6cc 100644 --- a/cpukit/libdl/rtl-error.c +++ b/cpukit/libdl/rtl-error.c @@ -38,35 +38,30 @@ #endif #include +#include #include #include -#include -#include #include "rtl-error.h" +#include -void -rtems_rtl_set_error (int error, const char* format, ...) -{ - rtems_rtl_data* rtl = rtems_rtl_lock (); - va_list ap; - va_start (ap, format); +void rtems_rtl_set_error(int error, const char* format, ...) { + rtems_rtl_data* rtl = rtems_rtl_lock(); + va_list ap; + va_start(ap, format); rtl->last_errno = error; - vsnprintf (rtl->last_error, sizeof (rtl->last_error), format, ap); - rtems_rtl_unlock (); - va_end (ap); + vsnprintf(rtl->last_error, sizeof(rtl->last_error), format, ap); + rtems_rtl_unlock(); + va_end(ap); } -int -rtems_rtl_get_error (char* message, size_t max_message) -{ - rtems_rtl_data* rtl = rtems_rtl_lock (); - if (rtl != NULL) - { +int rtems_rtl_get_error(char* message, size_t max_message) { + rtems_rtl_data* rtl = rtems_rtl_lock(); + if (rtl != NULL) { int last_errno = rtl->last_errno; rtl->last_errno = 0; - strlcpy (message, rtl->last_error, max_message); - rtems_rtl_unlock (); + strlcpy(message, rtl->last_error, max_message); + rtems_rtl_unlock(); return last_errno; } diff --git a/cpukit/libdl/rtl-error.h b/cpukit/libdl/rtl-error.h index 38268c3bae..42c457c5f9 100644 --- a/cpukit/libdl/rtl-error.h +++ b/cpukit/libdl/rtl-error.h @@ -33,7 +33,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#if !defined (_RTEMS_RTL_ERROR_H_) +#if !defined(_RTEMS_RTL_ERROR_H_) #define _RTEMS_RTL_ERROR_H_ #ifdef __cplusplus @@ -41,7 +41,7 @@ extern "C" { #endif /* __cplusplus */ #if __GNUC__ -#define RTEMS_RTL_PRINTF_ATTR __attribute__((__format__(__printf__,2,3))) +#define RTEMS_RTL_PRINTF_ATTR __attribute__((__format__(__printf__, 2, 3))) #else #define RTEMS_RTL_PRINTF_ATTR #endif @@ -55,7 +55,8 @@ extern "C" { * @param format The error format string. * @param ... The variable arguments that depend on the format string. */ -void rtems_rtl_set_error (int error, const char* format, ...) RTEMS_RTL_PRINTF_ATTR; +void rtems_rtl_set_error(int error, const char* format, + ...) RTEMS_RTL_PRINTF_ATTR; #ifdef __cplusplus } diff --git a/cpukit/libdl/rtl-find-file.c b/cpukit/libdl/rtl-find-file.c index 7821355fd9..8891d4e992 100644 --- a/cpukit/libdl/rtl-find-file.c +++ b/cpukit/libdl/rtl-find-file.c @@ -40,53 +40,45 @@ #include #include #include -#include #include +#include #include #include #include -#include -#include "rtl-find-file.h" #include "rtl-error.h" +#include "rtl-find-file.h" #include "rtl-string.h" #include +#include #if WAF_BUILD #define rtems_filesystem_is_delimiter rtems_filesystem_is_separator #endif -bool -rtems_rtl_find_file (const char* name, - const char* paths, - const char** file_name, - size_t* size) -{ +bool rtems_rtl_find_file(const char* name, const char* paths, + const char** file_name, size_t* size) { struct stat sb; *file_name = NULL; *size = 0; - if (rtems_filesystem_is_delimiter (name[0]) || (name[0] == '.')) - { - if (stat (name, &sb) == 0) - *file_name = rtems_rtl_strdup (name); - } - else if (paths) - { + if (rtems_filesystem_is_delimiter(name[0]) || (name[0] == '.')) { + if (stat(name, &sb) == 0) + *file_name = rtems_rtl_strdup(name); + } else if (paths) { const char* start; const char* end; - int len; - char* fname; + int len; + char* fname; start = paths; - end = start + strlen (paths); - len = strlen (name); + end = start + strlen(paths); + len = strlen(name); - while (!*file_name && (start != end)) - { - const char* delimiter = strchr (start, ':'); + while (!*file_name && (start != end)) { + const char* delimiter = strchr(start, ':'); if (delimiter == NULL) delimiter = end; @@ -96,23 +88,22 @@ rtems_rtl_find_file (const char* name, * path then see if the stat call works. */ - fname = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, - (delimiter - start) + 1 + len + 1, true); - if (!fname) - { - rtems_rtl_set_error (ENOMEM, "no memory searching for file"); + fname = rtems_rtl_alloc_new(RTEMS_RTL_ALLOC_OBJECT, + (delimiter - start) + 1 + len + 1, true); + if (!fname) { + rtems_rtl_set_error(ENOMEM, "no memory searching for file"); return false; } - memcpy (fname, start, delimiter - start); + memcpy(fname, start, delimiter - start); fname[delimiter - start] = '/'; - memcpy (fname + (delimiter - start) + 1, name, len); + memcpy(fname + (delimiter - start) + 1, name, len); - if (rtems_rtl_trace (RTEMS_RTL_TRACE_LOAD)) - printf ("rtl: find-file: path: %s\n", fname); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_LOAD)) + printf("rtl: find-file: path: %s\n", fname); - if (stat (fname, &sb) < 0) - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, fname); + if (stat(fname, &sb) < 0) + rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_OBJECT, fname); else *file_name = fname; diff --git a/cpukit/libdl/rtl-find-file.h b/cpukit/libdl/rtl-find-file.h index b4cd9f6c84..f7b00e6c16 100644 --- a/cpukit/libdl/rtl-find-file.h +++ b/cpukit/libdl/rtl-find-file.h @@ -33,7 +33,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#if !defined (_RTEMS_RTL_FIND_FILE_H_) +#if !defined(_RTEMS_RTL_FIND_FILE_H_) #define _RTEMS_RTL_FIND_FILE_H_ #include @@ -53,10 +53,8 @@ extern "C" { * @retval true The file was found. * @retval false The file was not found. */ -bool rtems_rtl_find_file (const char* name, - const char* paths, - const char** file_name, - size_t* size); +bool rtems_rtl_find_file(const char* name, const char* paths, + const char** file_name, size_t* size); #ifdef __cplusplus } diff --git a/cpukit/libdl/rtl-mdreloc-aarch64.c b/cpukit/libdl/rtl-mdreloc-aarch64.c index 1ce4240021..ca0dd677e6 100644 --- a/cpukit/libdl/rtl-mdreloc-aarch64.c +++ b/cpukit/libdl/rtl-mdreloc-aarch64.c @@ -67,64 +67,58 @@ __RCSID("$NetBSD: mdreloc.c,v 1.14 2020/06/16 21:01:30 joerg Exp $"); #endif /* not lint */ -#include -#include #include #include -#include +#include #include +#include +#include -#include #include "rtl-elf.h" #include "rtl-error.h" #include +#include #include -#include "rtl-unwind.h" #include "rtl-unwind-dw2.h" +#include "rtl-unwind.h" struct tls_data { - size_t td_tlsindex; - Elf_Addr td_tlsoffs; + size_t td_tlsindex; + Elf_Addr td_tlsoffs; }; rtems_rtl_elf_rel_status -rtems_rtl_elf_reloc_rela ( - rtems_rtl_obj* obj, - const Elf_Rela* rela, - const rtems_rtl_obj_sect* sect, - const char* symname, - const Elf_Byte syminfo, - const Elf_Word symvalue, - const bool parsing -); +rtems_rtl_elf_reloc_rela(rtems_rtl_obj* obj, const Elf_Rela* rela, + const rtems_rtl_obj_sect* sect, const char* symname, + const Elf_Byte syminfo, const Elf_Word symvalue, + const bool parsing); -#define __BITS(hi,lo) ((~((~(Elf_Addr)0)<<((hi)+1)))&((~(Elf_Addr)0)<<(lo))) +#define __BITS(hi, lo) \ + ((~((~(Elf_Addr)0) << ((hi) + 1))) & ((~(Elf_Addr)0) << (lo))) #define WIDTHMASK(w) (0xffffffffffffffffUL >> (64 - (w))) -static inline bool -checkoverflow(Elf_Addr addr, int bitwidth, Elf_Addr targetaddr, - const char *bitscale, void *where, Elf64_Addr off) -{ +static inline bool checkoverflow(Elf_Addr addr, int bitwidth, + Elf_Addr targetaddr, const char* bitscale, + void* where, Elf64_Addr off) { const Elf_Addr mask = ~__BITS(bitwidth - 1, 0); if (((addr & mask) != 0) && ((addr & mask) != mask)) { printf("kobj_reloc: Relocation 0x%" PRIxPTR " too far from %p" - " (base+0x%jx) for %dbit%s\n", - (uintptr_t)targetaddr, where, off, bitwidth, bitscale); + " (base+0x%jx) for %dbit%s\n", + (uintptr_t)targetaddr, where, off, bitwidth, bitscale); return true; } return false; } -static inline bool -checkalign(Elf_Addr addr, int alignbyte, void *where, Elf64_Addr off) -{ +static inline bool checkalign(Elf_Addr addr, int alignbyte, void* where, + Elf64_Addr off) { if ((addr & (alignbyte - 1)) != 0) { printf("kobj_reloc: Relocation 0x%" PRIxPTR " unaligned at %p" - " (base+0x%jx). must be aligned %d\n", - (uintptr_t)addr, where, off, alignbyte); + " (base+0x%jx). must be aligned %d\n", + (uintptr_t)addr, where, off, alignbyte); return true; } return false; @@ -136,9 +130,7 @@ checkalign(Elf_Addr addr, int alignbyte, void *where, Elf64_Addr off) */ #define ALLOW_UNTESTED_RELOCS 1 -static void* -set_veneer(void* trampoline, Elf_Addr target) -{ +static void* set_veneer(void* trampoline, Elf_Addr target) { /* * http://shell-storm.org/online/Online-Assembler-and-Disassembler/ * @@ -146,470 +138,406 @@ set_veneer(void* trampoline, Elf_Addr target) * br x9 * */ - uint64_t* tramp = (uint64_t*) trampoline; + uint64_t* tramp = (uint64_t*)trampoline; #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ *tramp++ = 0xd61f012058000049; #else *tramp++ = 0xd61f012058000049; /* not tested */ #endif - *tramp++ = (uint64_t) target; + *tramp++ = (uint64_t)target; return tramp; } -static size_t -get_veneer_size(int type) -{ - (void) type; +static size_t get_veneer_size(int type) { + (void)type; return 16; } -uint32_t rtems_rtl_obj_tramp_alignment (const rtems_rtl_obj* obj) -{ - (void) obj; +uint32_t rtems_rtl_obj_tramp_alignment(const rtems_rtl_obj* obj) { + (void)obj; return sizeof(uint64_t); } -size_t -rtems_rtl_elf_relocate_tramp_max_size (void) -{ +size_t rtems_rtl_elf_relocate_tramp_max_size(void) { return 16; } -uint32_t -rtems_rtl_elf_section_flags (const rtems_rtl_obj* obj, - const Elf_Shdr* shdr) -{ - (void) obj; - (void) shdr; +uint32_t rtems_rtl_elf_section_flags(const rtems_rtl_obj* obj, + const Elf_Shdr* shdr) { + (void)obj; + (void)shdr; return 0; } -uint32_t -rtems_rtl_elf_arch_parse_section (const rtems_rtl_obj* obj, - int section, - const char* name, - const Elf_Shdr* shdr, - const uint32_t flags) -{ - (void) obj; - (void) section; - (void) name; - (void) shdr; +uint32_t rtems_rtl_elf_arch_parse_section(const rtems_rtl_obj* obj, int section, + const char* name, + const Elf_Shdr* shdr, + const uint32_t flags) { + (void)obj; + (void)section; + (void)name; + (void)shdr; return flags; } -bool -rtems_rtl_elf_arch_section_alloc (const rtems_rtl_obj* obj, - rtems_rtl_obj_sect* sect) -{ - (void) obj; - (void) sect; +bool rtems_rtl_elf_arch_section_alloc(const rtems_rtl_obj* obj, + rtems_rtl_obj_sect* sect) { + (void)obj; + (void)sect; return false; } -bool -rtems_rtl_elf_arch_section_free (const rtems_rtl_obj* obj, - rtems_rtl_obj_sect* sect) -{ - (void) obj; - (void) sect; +bool rtems_rtl_elf_arch_section_free(const rtems_rtl_obj* obj, + rtems_rtl_obj_sect* sect) { + (void)obj; + (void)sect; return false; } -bool -rtems_rtl_elf_rel_resolve_sym (Elf_Word type) -{ - (void) type; +bool rtems_rtl_elf_rel_resolve_sym(Elf_Word type) { + (void)type; return true; } rtems_rtl_elf_rel_status -rtems_rtl_elf_reloc_rela (rtems_rtl_obj* obj, - const Elf_Rela* rela, - const rtems_rtl_obj_sect* sect, - const char* symname, - const Elf_Byte syminfo, - const Elf_Word symvalue, - const bool parsing) -{ - (void) symname; - (void) syminfo; +rtems_rtl_elf_reloc_rela(rtems_rtl_obj* obj, const Elf_Rela* rela, + const rtems_rtl_obj_sect* sect, const char* symname, + const Elf_Byte syminfo, const Elf_Word symvalue, + const bool parsing) { + (void)symname; + (void)syminfo; - Elf64_Addr *where; - Elf32_Addr *where32; - Elf_Addr off = rela->r_offset; - Elf_Addr target; - Elf_Addr raddr; - uint32_t *insn, immhi, immlo, shift; + Elf64_Addr* where; + Elf32_Addr* where32; + Elf_Addr off = rela->r_offset; + Elf_Addr target; + Elf_Addr raddr; + uint32_t *insn, immhi, immlo, shift; - where = (Elf_Addr *)(sect->base + rela->r_offset); - where32 = (void *)where; + where = (Elf_Addr*)(sect->base + rela->r_offset); + where32 = (void*)where; - insn = (uint32_t *)where; + insn = (uint32_t*)where; /* * S - the address of the symbol * A - the addend of the reolcation * P - the address of the place being relocated (derived from r_offset) - * Page(expr) - the page address of the expression expr, defined as (expr & ~0xFFF). - * TPREL(expr) - the thread pointer offset of the expression expr + * Page(expr) - the page address of the expression expr, defined as (expr & + * ~0xFFF). TPREL(expr) - the thread pointer offset of the expression expr */ switch (ELF_R_TYPE(rela->r_info)) { - case R_TYPE(NONE): - if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) { - printf ("rtl: NONE %p in %s\n", where, rtems_rtl_obj_oname (obj)); - } + case R_TYPE(NONE): + if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC)) { + printf("rtl: NONE %p in %s\n", where, rtems_rtl_obj_oname(obj)); + } + break; + + case R_TYPE(ABS64): /* word S + A */ + case R_TYPE(GLOB_DAT): /* word S + A */ + if (!parsing) { + target = (Elf_Addr)symvalue + rela->r_addend; + + if (*where != target) + *where = target; + + if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC)) + printf("rtl: reloc 64/GLOB_DAT in %s --> %p in %s\n", sect->name, + (void*)(uintptr_t)*where, rtems_rtl_obj_oname(obj)); + } + break; + + /* + * If S is a normal symbol, resolves to the difference between the static + * link address of S and the execution address of S. If S is the null symbol + * (ELF symbol index 0), resolves to the difference between the static link + * address of P and the execution address of P. + */ + case R_TYPE(RELATIVE): /* Delta(S) + A */ + if (!parsing) { + *where = (Elf_Addr)(uintptr_t)(sect->base + rela->r_addend); + if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC)) + printf("rtl: reloc RELATIVE in %s --> %p in %s\n", sect->name, + (void*)(uintptr_t)*where, rtems_rtl_obj_oname(obj)); + } + break; + + case R_TYPE(COPY): + /* + * These are deferred until all other relocations have + * been done. All we do here is make sure that the + * COPY relocation is not in a shared library. They + * are allowed only in executable files. + */ + printf("rtl: reloc COPY (please report)\n"); + break; + + case R_AARCH64_ADD_TPREL_HI12: /* TPREL(S + A) */ + case R_AARCH64_ADD_TPREL_LO12: + case R_AARCH64_ADD_TPREL_LO12_NC: + uint32_t of_check = 0; + switch (ELF_R_TYPE(rela->r_info)) { + case R_AARCH64_ADD_TPREL_LO12: + of_check = 212; + /* fallthrough */ + case R_AARCH64_ADD_TPREL_LO12_NC: + shift = 0; break; - - case R_TYPE(ABS64): /* word S + A */ - case R_TYPE(GLOB_DAT): /* word S + A */ - if (!parsing) { - target = (Elf_Addr)symvalue + rela->r_addend; - - if (*where != target) - *where = target; - - if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) - printf ("rtl: reloc 64/GLOB_DAT in %s --> %p in %s\n", - sect->name, (void *)(uintptr_t)*where, - rtems_rtl_obj_oname (obj)); - } + case R_AARCH64_ADD_TPREL_HI12: + of_check = 224; + shift = 12; break; + default: + printf("illegal rtype: %" PRIu64 "\n", ELF_R_TYPE(rela->r_info)); + break; + } + + if (!parsing) { + target = (Elf_Addr)symvalue; + target >>= shift; + target &= WIDTHMASK(12); + if (of_check && target >= of_check) { + return rtems_rtl_elf_rel_failure; + } + *insn = htole32((le32toh(*insn) & ~__BITS(21, 10)) | (target << 10)); + } + break; + + case R_AARCH64_ADD_ABS_LO12_NC: /* S + A */ + case R_AARCH64_LDST8_ABS_LO12_NC: + case R_AARCH_LDST16_ABS_LO12_NC: + case R_AARCH_LDST32_ABS_LO12_NC: + case R_AARCH_LDST64_ABS_LO12_NC: + case R_AARCH64_LDST128_ABS_LO12_NC: + switch (ELF_R_TYPE(rela->r_info)) { + case R_AARCH64_ADD_ABS_LO12_NC: + case R_AARCH64_LDST8_ABS_LO12_NC: + shift = 0; + break; + case R_AARCH_LDST16_ABS_LO12_NC: + shift = 1; + break; + case R_AARCH_LDST32_ABS_LO12_NC: + shift = 2; + break; + case R_AARCH_LDST64_ABS_LO12_NC: + shift = 3; + break; + case R_AARCH64_LDST128_ABS_LO12_NC: + shift = 4; + break; + default: + printf("illegal rtype: %" PRIu64 "\n", ELF_R_TYPE(rela->r_info)); + break; + } /* - * If S is a normal symbol, resolves to the difference between the static - * link address of S and the execution address of S. If S is the null symbol - * (ELF symbol index 0), resolves to the difference between the static link - * address of P and the execution address of P. + * S + A + * e.g.) add x0,x0,#:lo12:+ + * ldrb w0,[x0,#:lo12:+] + * ldrh w0,[x0,#:lo12:+] + * ldr w0,[x0,#:lo12:+] + * ldr x0,[x0,#:lo12:+] */ - case R_TYPE(RELATIVE): /* Delta(S) + A */ - if (!parsing) { - *where = (Elf_Addr)(uintptr_t)(sect->base + rela->r_addend); - if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) - printf ("rtl: reloc RELATIVE in %s --> %p in %s\n", - sect->name, (void *)(uintptr_t)*where, - rtems_rtl_obj_oname (obj)); + if (!parsing) { + target = (Elf_Addr)symvalue + rela->r_addend; + if (checkalign(target, 1 << shift, where, off)) { + printf("rtl: reloc checkalign failed in %s --> %p in %s\n", sect->name, + (void*)(uintptr_t)*where, rtems_rtl_obj_oname(obj)); + printf("ELF_R_TYPE is : %" PRIu64 "\n", ELF_R_TYPE(rela->r_info)); + break; } - break; + target &= WIDTHMASK(12); + target >>= shift; + *insn = htole32((le32toh(*insn) & ~__BITS(21, 10)) | (target << 10)); + } + break; - case R_TYPE(COPY): - /* - * These are deferred until all other relocations have - * been done. All we do here is make sure that the - * COPY relocation is not in a shared library. They - * are allowed only in executable files. - */ - printf("rtl: reloc COPY (please report)\n"); - break; + case R_AARCH64_ADR_PREL_PG_HI21: + /* + * Page(S + A) - Page(P) + * e.g.) adrp x0,+ + */ + if (!parsing) { + target = (Elf_Addr)symvalue + rela->r_addend; + target = target >> 12; + raddr = target << 12; + target -= (uintptr_t)where >> 12; - case R_AARCH64_ADD_TPREL_HI12: /* TPREL(S + A) */ - case R_AARCH64_ADD_TPREL_LO12: - case R_AARCH64_ADD_TPREL_LO12_NC: - uint32_t of_check = 0; - switch (ELF_R_TYPE(rela->r_info)) { - case R_AARCH64_ADD_TPREL_LO12: - of_check = 212; - /* fallthrough */ - case R_AARCH64_ADD_TPREL_LO12_NC: - shift = 0; - break; - case R_AARCH64_ADD_TPREL_HI12: - of_check = 224; - shift = 12; - break; - default: - printf("illegal rtype: %" PRIu64 "\n", ELF_R_TYPE(rela->r_info)); - break; + if (checkoverflow(target, 21, raddr, " x 4k", where, off)) { + printf("]] %d\n", __LINE__); + return rtems_rtl_elf_rel_failure; } - if (!parsing) { - target = (Elf_Addr)symvalue; - target >>= shift; - target &= WIDTHMASK(12); - if (of_check && target >= of_check) { - return rtems_rtl_elf_rel_failure; - } - *insn = htole32( - (le32toh(*insn) & ~__BITS(21,10)) | (target << 10)); - } - break; + immlo = target & WIDTHMASK(2); + immhi = (target >> 2) & WIDTHMASK(19); + *insn = htole32((le32toh(*insn) & ~(__BITS(30, 29) | __BITS(23, 5))) | + (immlo << 29) | (immhi << 5)); + } + break; - case R_AARCH64_ADD_ABS_LO12_NC: /* S + A */ - case R_AARCH64_LDST8_ABS_LO12_NC: - case R_AARCH_LDST16_ABS_LO12_NC: - case R_AARCH_LDST32_ABS_LO12_NC: - case R_AARCH_LDST64_ABS_LO12_NC: - case R_AARCH64_LDST128_ABS_LO12_NC: - switch (ELF_R_TYPE(rela->r_info)) { - case R_AARCH64_ADD_ABS_LO12_NC: - case R_AARCH64_LDST8_ABS_LO12_NC: - shift = 0; - break; - case R_AARCH_LDST16_ABS_LO12_NC: - shift = 1; - break; - case R_AARCH_LDST32_ABS_LO12_NC: - shift = 2; - break; - case R_AARCH_LDST64_ABS_LO12_NC: - shift = 3; - break; - case R_AARCH64_LDST128_ABS_LO12_NC: - shift = 4; - break; - default: - printf("illegal rtype: %" PRIu64 "\n", ELF_R_TYPE(rela->r_info)); - break; + case R_AARCH_JUMP26: + case R_AARCH_CALL26: + /* + * S + A - P + * e.g.) b + + * bl + + */ + if (parsing && sect->base == 0) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC)) + printf("rtl: JUMP26/PC26/CALL tramp cache\n"); + return rtems_rtl_elf_rel_tramp_cache; + } + + raddr = (Elf_Addr)symvalue + rela->r_addend; + target = raddr - (uintptr_t)where; + + if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC)) + printf("rtl: JUMP26/PC26/CALL: insn=%p where=%p target=%p raddr=%p " + "parsing=%d\n", + insn, (void*)where, (void*)(uintptr_t)target, + (void*)(uintptr_t)raddr, parsing); + + if (checkalign(target, 4, where, off)) { + return rtems_rtl_elf_rel_failure; + } + + target = (intptr_t)target >> 2; + + if (((Elf_Sword)target > 0x1FFFFFF) || ((Elf_Sword)target < -0x2000000)) { + Elf_Word tramp_addr; + size_t tramp_size = get_veneer_size(ELF_R_TYPE(rela->r_info)); + + if (parsing) { + if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC)) + printf("rtl: JUMP26/PC26/CALL tramp add\n"); + return rtems_rtl_elf_rel_tramp_add; } - /* - * S + A - * e.g.) add x0,x0,#:lo12:+ - * ldrb w0,[x0,#:lo12:+] - * ldrh w0,[x0,#:lo12:+] - * ldr w0,[x0,#:lo12:+] - * ldr x0,[x0,#:lo12:+] - */ - if (!parsing) { - target = (Elf_Addr)symvalue + rela->r_addend; - if (checkalign(target, 1 << shift, where, off)) { - printf ("rtl: reloc checkalign failed in %s --> %p in %s\n", - sect->name, (void *)(uintptr_t)*where, - rtems_rtl_obj_oname (obj)); - printf("ELF_R_TYPE is : %" PRIu64 "\n", ELF_R_TYPE(rela->r_info)); - break; - } - target &= WIDTHMASK(12); - target >>= shift; - *insn = htole32( - (le32toh(*insn) & ~__BITS(21,10)) | (target << 10)); - } - break; - - case R_AARCH64_ADR_PREL_PG_HI21: - /* - * Page(S + A) - Page(P) - * e.g.) adrp x0,+ - */ - if (!parsing) { - target = (Elf_Addr)symvalue + rela->r_addend; - target = target >> 12; - raddr = target << 12; - target -= (uintptr_t)where >> 12; - - if (checkoverflow(target, 21, raddr, " x 4k", where, off)) { - printf("]] %d\n", __LINE__); - return rtems_rtl_elf_rel_failure; - } - - immlo = target & WIDTHMASK(2); - immhi = (target >> 2) & WIDTHMASK(19); - *insn = htole32((le32toh(*insn) & - ~(__BITS(30,29) | __BITS(23,5))) | - (immlo << 29) | (immhi << 5)); - } - break; - - case R_AARCH_JUMP26: - case R_AARCH_CALL26: - /* - * S + A - P - * e.g.) b + - * bl + - */ - if (parsing && sect->base == 0) { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) - printf ("rtl: JUMP26/PC26/CALL tramp cache\n"); - return rtems_rtl_elf_rel_tramp_cache; + if (!rtems_rtl_obj_has_tramp_space(obj, tramp_size)) { + rtems_rtl_set_error( + EINVAL, "%s: CALL/JUMP26: overflow: no tramp memory", sect->name); + return rtems_rtl_elf_rel_failure; } + tramp_addr = ((Elf_Addr)(uintptr_t)obj->tramp_brk) | (symvalue & 1); + obj->tramp_brk = set_veneer(obj->tramp_brk, symvalue); + target = tramp_addr + rela->r_addend - (uintptr_t)where; + target = (uintptr_t)target >> 2; + } + + if (checkoverflow(target, 26, raddr, " word", where, off)) { + return rtems_rtl_elf_rel_failure; + } + + if (!parsing) { + target &= WIDTHMASK(26); + *insn = htole32((le32toh(*insn) & ~__BITS(25, 0)) | target); + } + + break; + + case R_AARCH64_PREL32: + /* + * S + A - P + * e.g.) 1: .word +-1b + */ + if (!parsing) { raddr = (Elf_Addr)symvalue + rela->r_addend; target = raddr - (uintptr_t)where; - - if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) - printf ( - "rtl: JUMP26/PC26/CALL: insn=%p where=%p target=%p raddr=%p parsing=%d\n", - insn, (void*) where, (void*)(uintptr_t) target, (void*)(uintptr_t) raddr, - parsing - ); - - if (checkalign(target, 4, where, off)) { + if (checkoverflow(target, 32, raddr, "", where, off)) { + printf("]] %d\n", __LINE__); return rtems_rtl_elf_rel_failure; } + *where32 = target; + } + break; - target = (intptr_t)target >> 2; + case R_TYPE(TLSDESC): + printf("rtl: reloc TLSDESC in %s --> %p in %s\n", sect->name, + (void*)(uintptr_t)*where, rtems_rtl_obj_oname(obj)); + break; - if (((Elf_Sword)target > 0x1FFFFFF) || ((Elf_Sword)target < -0x2000000)) { - Elf_Word tramp_addr; - size_t tramp_size = get_veneer_size(ELF_R_TYPE(rela->r_info)); + case R_TLS_TYPE(TLS_DTPREL): + printf("rtl: reloc TLS_DTPREL in %s --> %p in %s\n", sect->name, + (void*)(uintptr_t)*where, rtems_rtl_obj_oname(obj)); + break; + case R_TLS_TYPE(TLS_DTPMOD): + printf("rtl: reloc TLS_DTPMOD in %s --> %p in %s\n", sect->name, + (void*)(uintptr_t)*where, rtems_rtl_obj_oname(obj)); + break; - if (parsing) { - if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) - printf ("rtl: JUMP26/PC26/CALL tramp add\n"); - return rtems_rtl_elf_rel_tramp_add; - } + case R_TLS_TYPE(TLS_TPREL): + printf("rtl: reloc TLS_TPREL in %s --> %p in %s\n", sect->name, + (void*)(uintptr_t)*where, rtems_rtl_obj_oname(obj)); + break; - if (!rtems_rtl_obj_has_tramp_space (obj, tramp_size)) { - rtems_rtl_set_error (EINVAL, - "%s: CALL/JUMP26: overflow: no tramp memory", - sect->name); - return rtems_rtl_elf_rel_failure; - } - - tramp_addr = ((Elf_Addr)(uintptr_t) obj->tramp_brk) | (symvalue & 1); - obj->tramp_brk = set_veneer(obj->tramp_brk, symvalue); - target = tramp_addr + rela->r_addend - (uintptr_t)where; - target = (uintptr_t)target >> 2; - } - - if (checkoverflow(target, 26, raddr, " word", where, off)) { - return rtems_rtl_elf_rel_failure; - } - - if (!parsing) { - target &= WIDTHMASK(26); - *insn = htole32((le32toh(*insn) & ~__BITS(25,0)) | target); - } - - break; - - case R_AARCH64_PREL32: - /* - * S + A - P - * e.g.) 1: .word +-1b - */ - if (!parsing) { - raddr = (Elf_Addr)symvalue + rela->r_addend; - target = raddr - (uintptr_t)where; - if (checkoverflow(target, 32, raddr, "", where, off)) { - printf("]] %d\n", __LINE__); - return rtems_rtl_elf_rel_failure; - } - *where32 = target; - } - break; - - case R_TYPE(TLSDESC): - printf ("rtl: reloc TLSDESC in %s --> %p in %s\n", - sect->name, (void *)(uintptr_t)*where, - rtems_rtl_obj_oname (obj)); - break; - - case R_TLS_TYPE(TLS_DTPREL): - printf ("rtl: reloc TLS_DTPREL in %s --> %p in %s\n", - sect->name, (void *)(uintptr_t)*where, - rtems_rtl_obj_oname (obj)); - break; - case R_TLS_TYPE(TLS_DTPMOD): - printf ("rtl: reloc TLS_DTPMOD in %s --> %p in %s\n", - sect->name, (void *)(uintptr_t)*where, - rtems_rtl_obj_oname (obj)); - break; - - case R_TLS_TYPE(TLS_TPREL): - printf ("rtl: reloc TLS_TPREL in %s --> %p in %s\n", - sect->name, (void *)(uintptr_t)*where, - rtems_rtl_obj_oname (obj)); - break; - - default: - printf ("rtl: Unsupported relocation type (%" PRIu64 - ") in %s --> %p in %s\n", - ELF_R_TYPE(rela->r_info), sect->name, (void *)where, - rtems_rtl_obj_oname (obj)); - return rtems_rtl_elf_rel_failure; + default: + printf("rtl: Unsupported relocation type (%" PRIu64 + ") in %s --> %p in %s\n", + ELF_R_TYPE(rela->r_info), sect->name, (void*)where, + rtems_rtl_obj_oname(obj)); + return rtems_rtl_elf_rel_failure; } return rtems_rtl_elf_rel_no_error; } -rtems_rtl_elf_rel_status -rtems_rtl_elf_relocate_rela_tramp (rtems_rtl_obj* obj, - const Elf_Rela* rela, - const rtems_rtl_obj_sect* sect, - const char* symname, - const Elf_Byte syminfo, - const Elf_Word symvalue) -{ - return rtems_rtl_elf_reloc_rela (obj, - rela, - sect, - symname, - syminfo, - symvalue, - true); +rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rela_tramp( + rtems_rtl_obj* obj, const Elf_Rela* rela, const rtems_rtl_obj_sect* sect, + const char* symname, const Elf_Byte syminfo, const Elf_Word symvalue) { + return rtems_rtl_elf_reloc_rela(obj, rela, sect, symname, syminfo, symvalue, + true); } rtems_rtl_elf_rel_status -rtems_rtl_elf_relocate_rela (rtems_rtl_obj* obj, - const Elf_Rela* rela, - const rtems_rtl_obj_sect* sect, - const char* symname, - const Elf_Byte syminfo, - const Elf_Word symvalue) -{ - return rtems_rtl_elf_reloc_rela (obj, - rela, - sect, - symname, - syminfo, - symvalue, - false); +rtems_rtl_elf_relocate_rela(rtems_rtl_obj* obj, const Elf_Rela* rela, + const rtems_rtl_obj_sect* sect, const char* symname, + const Elf_Byte syminfo, const Elf_Word symvalue) { + return rtems_rtl_elf_reloc_rela(obj, rela, sect, symname, syminfo, symvalue, + false); } -rtems_rtl_elf_rel_status -rtems_rtl_elf_relocate_rel_tramp (rtems_rtl_obj* obj, - const Elf_Rel* rel, - const rtems_rtl_obj_sect* sect, - const char* symname, - const Elf_Byte syminfo, - const Elf_Word symvalue) -{ - (void) obj; - (void) rel; - (void) sect; - (void) symname; - (void) syminfo; - (void) symvalue; +rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rel_tramp( + rtems_rtl_obj* obj, const Elf_Rel* rel, const rtems_rtl_obj_sect* sect, + const char* symname, const Elf_Byte syminfo, const Elf_Word symvalue) { + (void)obj; + (void)rel; + (void)sect; + (void)symname; + (void)syminfo; + (void)symvalue; - rtems_rtl_set_error (EINVAL, "rela type record not supported"); + rtems_rtl_set_error(EINVAL, "rela type record not supported"); return rtems_rtl_elf_rel_failure; } rtems_rtl_elf_rel_status -rtems_rtl_elf_relocate_rel (rtems_rtl_obj* obj, - const Elf_Rel* rel, - const rtems_rtl_obj_sect* sect, - const char* symname, - const Elf_Byte syminfo, - const Elf_Word symvalue) -{ - (void) obj; - (void) rel; - (void) sect; - (void) symname; - (void) syminfo; - (void) symvalue; +rtems_rtl_elf_relocate_rel(rtems_rtl_obj* obj, const Elf_Rel* rel, + const rtems_rtl_obj_sect* sect, const char* symname, + const Elf_Byte syminfo, const Elf_Word symvalue) { + (void)obj; + (void)rel; + (void)sect; + (void)symname; + (void)syminfo; + (void)symvalue; - rtems_rtl_set_error (EINVAL, "rela type record not supported"); + rtems_rtl_set_error(EINVAL, "rela type record not supported"); return rtems_rtl_elf_rel_failure; } -bool -rtems_rtl_elf_unwind_parse (const rtems_rtl_obj* obj, - const char* name, - uint32_t flags) { - return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags); +bool rtems_rtl_elf_unwind_parse(const rtems_rtl_obj* obj, const char* name, + uint32_t flags) { + return rtems_rtl_elf_unwind_dw2_parse(obj, name, flags); } -bool -rtems_rtl_elf_unwind_register (rtems_rtl_obj* obj) { - return rtems_rtl_elf_unwind_dw2_register (obj); +bool rtems_rtl_elf_unwind_register(rtems_rtl_obj* obj) { + return rtems_rtl_elf_unwind_dw2_register(obj); } -bool -rtems_rtl_elf_unwind_deregister (rtems_rtl_obj* obj) { - return rtems_rtl_elf_unwind_dw2_deregister (obj); +bool rtems_rtl_elf_unwind_deregister(rtems_rtl_obj* obj) { + return rtems_rtl_elf_unwind_dw2_deregister(obj); } diff --git a/cpukit/libdl/rtl-mdreloc-arm.c b/cpukit/libdl/rtl-mdreloc-arm.c index 6bf68967cc..9080bace53 100644 --- a/cpukit/libdl/rtl-mdreloc-arm.c +++ b/cpukit/libdl/rtl-mdreloc-arm.c @@ -10,14 +10,14 @@ #include #include #include -#include #include +#include -#include #include "rtl-elf.h" #include "rtl-error.h" -#include #include "rtl-unwind-arm.h" +#include +#include /* * Set to 1 to allow untested relocations. If you tested one and it @@ -29,14 +29,11 @@ * It is possible for the compiler to emit relocations for unaligned data. * We handle this situation with these inlines. */ -#define RELOC_ALIGNED_P(x) \ - (((uintptr_t)(x) & (sizeof(void *) - 1)) == 0) +#define RELOC_ALIGNED_P(x) (((uintptr_t)(x) & (sizeof(void*) - 1)) == 0) -#define SHT_ARM_EXIDX 0x70000001 /* Section holds ARM unwind info. */ +#define SHT_ARM_EXIDX 0x70000001 /* Section holds ARM unwind info. */ -static inline Elf_Addr -load_ptr(void *where) -{ +static inline Elf_Addr load_ptr(void* where) { Elf_Addr res; memcpy(&res, where, sizeof(res)); @@ -44,9 +41,7 @@ load_ptr(void *where) return (res); } -static inline void -store_ptr(void *where, Elf_Addr val) -{ +static inline void store_ptr(void* where, Elf_Addr val) { memcpy(where, &val, sizeof(val)); } @@ -54,42 +49,35 @@ store_ptr(void *where, Elf_Addr val) * The address of Thumb function symbols is it's real address plus one. * This is done by compiler, thus do not consider symtype here. */ -static inline int -isThumb(Elf_Word symvalue) -{ +static inline int isThumb(Elf_Word symvalue) { if ((symvalue & 0x1) == 0x1) return true; - else return false; + else + return false; } -static inline Elf_SOff -sign_extend31(Elf_Addr val) -{ +static inline Elf_SOff sign_extend31(Elf_Addr val) { if (0x40000000 & val) - val = ~((Elf_Addr)0x7fffffff) | (0x7fffffff & val); + val = ~((Elf_Addr)0x7fffffff) | (0x7fffffff & val); return 0x7fffffff & val; } -static void* -set_arm_veneer(void* trampoline, Elf_Addr target) -{ +static void* set_arm_veneer(void* trampoline, Elf_Addr target) { /* * ARM mode: * ldr pc, [pc, #-4] */ - uint32_t* tramp = (uint32_t*) trampoline; + uint32_t* tramp = (uint32_t*)trampoline; #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ *tramp++ = 0xe51ff004; #else *tramp++ = 0xe51ff004; /* not tested */ #endif - *tramp++ = (uint32_t) target; + *tramp++ = (uint32_t)target; return tramp; } -static void* -set_veneer(void* trampoline, Elf_Addr target) -{ +static void* set_veneer(void* trampoline, Elf_Addr target) { /* * http://shell-storm.org/online/Online-Assembler-and-Disassembler/ * @@ -98,22 +86,20 @@ set_veneer(void* trampoline, Elf_Addr target) * */ #if defined(__thumb__) - uint32_t* tramp = (uint32_t*) trampoline; - #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + uint32_t* tramp = (uint32_t*)trampoline; +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ *tramp++ = 0xf000f8df; - #else +#else *tramp++ = 0xf8dff000; /* not tested */ - #endif - *tramp++ = (uint32_t) target; +#endif + *tramp++ = (uint32_t)target; return tramp; #else return set_arm_veneer(trampoline, target); #endif } -static void* -set_thumb_bx_veneer(void* trampoline, Elf_Addr target) -{ +static void* set_thumb_bx_veneer(void* trampoline, Elf_Addr target) { /* * http://shell-storm.org/online/Online-Assembler-and-Disassembler/ * @@ -123,42 +109,35 @@ set_thumb_bx_veneer(void* trampoline, Elf_Addr target) * .word target * */ - uint16_t* tramp = (uint16_t*) trampoline; + uint16_t* tramp = (uint16_t*)trampoline; /* ldr.w r12, [pc, 4]*/ *tramp++ = 0xf8df; *tramp++ = 0xc002; /* bx r12 */ *tramp++ = 0x4760; - *tramp++ = (uint16_t) target & 0xffff; - *tramp++ = (uint16_t) ((target >> 16) & 0xffff); + *tramp++ = (uint16_t)target & 0xffff; + *tramp++ = (uint16_t)((target >> 16) & 0xffff); return tramp; } -static size_t -get_veneer_size(int type) -{ - (void) type; +static size_t get_veneer_size(int type) { + (void)type; /* BX veneers need 10 bytes */ return 10; } -uint32_t rtems_rtl_obj_tramp_alignment (const rtems_rtl_obj* obj) -{ - (void) obj; +uint32_t rtems_rtl_obj_tramp_alignment(const rtems_rtl_obj* obj) { + (void)obj; return sizeof(uint32_t); } -size_t -rtems_rtl_elf_relocate_tramp_max_size (void) -{ +size_t rtems_rtl_elf_relocate_tramp_max_size(void) { return 8; } -uint32_t -rtems_rtl_elf_section_flags (const rtems_rtl_obj* obj, - const Elf_Shdr* shdr) -{ - (void) obj; +uint32_t rtems_rtl_elf_section_flags(const rtems_rtl_obj* obj, + const Elf_Shdr* shdr) { + (void)obj; uint32_t flags = 0; if (shdr->sh_type == SHT_ARM_EXIDX) @@ -166,529 +145,487 @@ rtems_rtl_elf_section_flags (const rtems_rtl_obj* obj, return flags; } -uint32_t -rtems_rtl_elf_arch_parse_section (const rtems_rtl_obj* obj, - int section, - const char* name, - const Elf_Shdr* shdr, - const uint32_t flags) -{ - (void) obj; - (void) section; - (void) name; - (void) shdr; +uint32_t rtems_rtl_elf_arch_parse_section(const rtems_rtl_obj* obj, int section, + const char* name, + const Elf_Shdr* shdr, + const uint32_t flags) { + (void)obj; + (void)section; + (void)name; + (void)shdr; return flags; } -bool -rtems_rtl_elf_arch_section_alloc (const rtems_rtl_obj* obj, - rtems_rtl_obj_sect* sect) -{ - (void) obj; - (void) sect; +bool rtems_rtl_elf_arch_section_alloc(const rtems_rtl_obj* obj, + rtems_rtl_obj_sect* sect) { + (void)obj; + (void)sect; return false; } -bool -rtems_rtl_elf_arch_section_free (const rtems_rtl_obj* obj, - rtems_rtl_obj_sect* sect) -{ - (void) obj; - (void) sect; +bool rtems_rtl_elf_arch_section_free(const rtems_rtl_obj* obj, + rtems_rtl_obj_sect* sect) { + (void)obj; + (void)sect; return false; } -bool -rtems_rtl_elf_rel_resolve_sym (Elf_Word type) -{ - (void) type; +bool rtems_rtl_elf_rel_resolve_sym(Elf_Word type) { + (void)type; return true; } -rtems_rtl_elf_rel_status -rtems_rtl_elf_relocate_rela_tramp (rtems_rtl_obj* obj, - const Elf_Rela* rela, - const rtems_rtl_obj_sect* sect, - const char* symname, - const Elf_Byte syminfo, - const Elf_Word symvalue) -{ - (void) obj; - (void) rela; - (void) sect; - (void) symname; - (void) syminfo; - (void) symvalue; - rtems_rtl_set_error (EINVAL, "rela type record not supported"); +rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rela_tramp( + rtems_rtl_obj* obj, const Elf_Rela* rela, const rtems_rtl_obj_sect* sect, + const char* symname, const Elf_Byte syminfo, const Elf_Word symvalue) { + (void)obj; + (void)rela; + (void)sect; + (void)symname; + (void)syminfo; + (void)symvalue; + rtems_rtl_set_error(EINVAL, "rela type record not supported"); return rtems_rtl_elf_rel_failure; } rtems_rtl_elf_rel_status -rtems_rtl_elf_relocate_rela (rtems_rtl_obj* obj, - const Elf_Rela* rela, - const rtems_rtl_obj_sect* sect, - const char* symname, - const Elf_Byte syminfo, - const Elf_Word symvalue) -{ - (void) obj; - (void) rela; - (void) sect; - (void) symname; - (void) syminfo; - (void) symvalue; - rtems_rtl_set_error (EINVAL, "rela type record not supported"); +rtems_rtl_elf_relocate_rela(rtems_rtl_obj* obj, const Elf_Rela* rela, + const rtems_rtl_obj_sect* sect, const char* symname, + const Elf_Byte syminfo, const Elf_Word symvalue) { + (void)obj; + (void)rela; + (void)sect; + (void)symname; + (void)syminfo; + (void)symvalue; + rtems_rtl_set_error(EINVAL, "rela type record not supported"); return rtems_rtl_elf_rel_failure; } static rtems_rtl_elf_rel_status -rtems_rtl_elf_reloc_rel (rtems_rtl_obj* obj, - const Elf_Rel* rel, - const rtems_rtl_obj_sect* sect, - const char* symname, - const Elf_Byte syminfo, - const Elf_Word symvalue, - const bool parsing) -{ - (void) symname; - (void) syminfo; +rtems_rtl_elf_reloc_rel(rtems_rtl_obj* obj, const Elf_Rel* rel, + const rtems_rtl_obj_sect* sect, const char* symname, + const Elf_Byte syminfo, const Elf_Word symvalue, + const bool parsing) { + (void)symname; + (void)syminfo; - Elf_Addr *where; + Elf_Addr* where; Elf_Addr tmp; Elf_Word insn, addend; Elf_Word sign, i1, i2; uint16_t lower_insn, upper_insn; - where = (Elf_Addr *)(sect->base + rel->r_offset); + where = (Elf_Addr*)(sect->base + rel->r_offset); switch (ELF_R_TYPE(rel->r_info)) { - case R_TYPE(NONE): - if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) { - printf ("rtl: NONE %p in %s\n", where, rtems_rtl_obj_oname (obj)); - } - break; + case R_TYPE(NONE): + if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC)) { + printf("rtl: NONE %p in %s\n", where, rtems_rtl_obj_oname(obj)); + } + break; - case R_TYPE(CALL): /* BL/BLX */ - case R_TYPE(JUMP24): /* B/BL */ - if (parsing) - { - addend = 0; - } + case R_TYPE(CALL): /* BL/BLX */ + case R_TYPE(JUMP24): /* B/BL */ + if (parsing) { + addend = 0; + } else { + insn = *where; + + if (insn & 0x00800000) + addend = insn | 0xff000000; else - { - insn = *where; + addend = insn & 0x00ffffff; - if (insn & 0x00800000) - addend = insn | 0xff000000; - else addend = insn & 0x00ffffff; - - if (isThumb(symvalue)) { - if ((insn & 0xfe000000) == 0xfa000000); /* Already blx */ - else { - if ((insn & 0xff000000) == 0xeb000000) { /* BL