cpukit/libdl: reformat to LLVM style

Fixes #5344.
This commit is contained in:
Gedare Bloom
2026-02-05 08:50:43 -06:00
committed by Joel Sherrill
parent 6de3352acb
commit 0603a5789e
66 changed files with 7105 additions and 9329 deletions
+4 -4
View File
@@ -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
+1 -1
View File
@@ -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
+9 -9
View File
@@ -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 <rtems.h>
@@ -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
}
+36 -40
View File
@@ -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 <stdbool.h>
@@ -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
}
+41 -49
View File
@@ -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 <rtems.h>
@@ -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
}
+1 -1
View File
@@ -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
+33 -43
View File
@@ -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
}
+16 -23
View File
@@ -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 <fcntl.h>
@@ -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
}
+19 -25
View File
@@ -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 <rtems/rtl/rtl-obj-cache.h>
@@ -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
}
+1 -1
View File
@@ -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
File diff suppressed because it is too large Load Diff
+9 -8
View File
@@ -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 <rtems/print.h>
@@ -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
}
+26 -31
View File
@@ -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 <rtems.h>
#include "rtl-obj-fwd.h"
#include <rtems.h>
#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
}
+27 -28
View File
@@ -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
+53 -61
View File
@@ -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 <rtems.h>
#include <rtems/chain.h>
#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
}
+58 -59
View File
@@ -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 <link.h>
@@ -45,9 +45,9 @@
#include <rtems/rtl/rtl-allocator.h>
#include <rtems/rtl/rtl-archive.h>
#include <rtems/rtl/rtl-fwd.h>
#include <rtems/rtl/rtl-obj.h>
#include <rtems/rtl/rtl-obj-cache.h>
#include <rtems/rtl/rtl-obj-comp.h>
#include <rtems/rtl/rtl-obj.h>
#include <rtems/rtl/rtl-sym.h>
#include <rtems/rtl/rtl-unresolved.h>
@@ -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
}
+34 -55
View File
@@ -47,75 +47,57 @@
#include <dlfcn.h>
#include <rtems/rtl/dlfcn-shell.h>
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;
+46 -64
View File
@@ -35,13 +35,11 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdint.h>
#include <dlfcn.h>
#include <rtems/rtl/rtl.h>
#include <stdint.h>
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;
}
+34 -55
View File
@@ -44,86 +44,65 @@
#include <stdlib.h>
#include <string.h>
#include <rtems/rtl/rap.h>
#include <rtems/rtl/rap-shell.h>
#include <rtems/rtl/rap.h>
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;
}
+136 -189
View File
File diff suppressed because it is too large Load Diff
+22 -27
View File
@@ -39,33 +39,28 @@
#include <rtems/score/apimutex.h>
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;
}
}
+3 -5
View File
@@ -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 <rtems/rtl/rtl-allocator.h>
@@ -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
}
File diff suppressed because it is too large Load Diff
+515 -689
View File
File diff suppressed because it is too large Load Diff
+64 -94
View File
@@ -46,87 +46,65 @@
#include <stdio.h>
#include <string.h>
#include <rtems/rtl/rtl-allocator.h>
#include "rtl-bit-alloc.h"
#include "rtl-error.h"
#include <rtems/rtl/rtl-allocator.h>
#include <rtems/rtl/rtl-trace.h>
#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);
}
}
+15 -17
View File
@@ -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 <rtems/rtl/rtl-fwd.h>
@@ -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
}
+10 -18
View File
@@ -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;
}
+5 -7
View File
@@ -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
}
+19 -31
View File
@@ -46,48 +46,41 @@
#include "config.h"
#endif
#include <stdio.h>
#include <link.h>
#include <rtems/rtl/rtl.h>
#include <rtems/rtl/rtl-trace.h>
#include <rtems/rtl/rtl-obj-fwd.h>
#include <rtems/rtl/rtl-trace.h>
#include <rtems/rtl/rtl.h>
#include <stdio.h>
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;
}
+726 -945
View File
File diff suppressed because it is too large Load Diff
+40 -52
View File
@@ -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 <rtems/rtl/rtl-fwd.h>
@@ -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
}
+14 -19
View File
@@ -38,35 +38,30 @@
#endif
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <rtems/rtl/rtl.h>
#include "rtl-error.h"
#include <rtems/rtl/rtl.h>
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;
}
+4 -3
View File
@@ -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
}
+25 -34
View File
@@ -40,53 +40,45 @@
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <rtems/libio_.h>
#include <rtems/rtl/rtl.h>
#include "rtl-find-file.h"
#include "rtl-error.h"
#include "rtl-find-file.h"
#include "rtl-string.h"
#include <rtems/rtl/rtl-trace.h>
#include <rtems/rtl/rtl.h>
#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;
+3 -5
View File
@@ -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 <rtems.h>
@@ -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
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+112 -153
View File
@@ -9,221 +9,180 @@
#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <rtems/rtl/rtl.h>
#include "rtl-elf.h"
#include "rtl-error.h"
#include <rtems/rtl/rtl-trace.h>
#include "rtl-unwind.h"
#include "rtl-unwind-dw2.h"
#include "rtl-unwind.h"
#include <rtems/rtl/rtl-trace.h>
#include <rtems/rtl/rtl.h>
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;
}
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) {
/*
* Disable by returning 0.
*/
return 0;
}
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* 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_elf_relocate_rela(rtems_rtl_obj* obj, const Elf_Rela* 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");
return rtems_rtl_elf_rel_failure;
}
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;
return rtems_rtl_elf_rel_no_error;
}
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) symname;
(void) syminfo;
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)symname;
(void)syminfo;
Elf_Addr target = 0;
Elf_Addr target = 0;
Elf_Addr* where;
Elf_Addr tmp;
Elf_Addr tmp;
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):
break;
case R_TYPE(NONE):
break;
case R_TYPE(PC32):
target = (Elf_Addr) symvalue;
*where += target - (Elf_Addr)where;
case R_TYPE(PC32):
target = (Elf_Addr)symvalue;
*where += target - (Elf_Addr)where;
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
printf ("rtl: reloc PC32 in %s --> %p (%p @ %p) in %s\n",
sect->name, (void*) symvalue,
(void *)*where, where, rtems_rtl_obj_oname (obj));
break;
if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC))
printf("rtl: reloc PC32 in %s --> %p (%p @ %p) in %s\n", sect->name,
(void*)symvalue, (void*)*where, where, rtems_rtl_obj_oname(obj));
break;
case R_TYPE(GOT32):
case R_TYPE(32):
case R_TYPE(GLOB_DAT):
target = (Elf_Addr) symvalue;
case R_TYPE(GOT32):
case R_TYPE(32):
case R_TYPE(GLOB_DAT):
target = (Elf_Addr)symvalue;
tmp = target + *where;
if (*where != tmp)
*where = tmp;
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
printf ("rtl: reloc 32/GLOB_DAT in %s --> %p @ %p in %s\n",
sect->name, (void *)*where, where,
rtems_rtl_obj_oname (obj));
break;
tmp = target + *where;
if (*where != tmp)
*where = tmp;
if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC))
printf("rtl: reloc 32/GLOB_DAT in %s --> %p @ %p in %s\n", sect->name,
(void*)*where, where, rtems_rtl_obj_oname(obj));
break;
case R_TYPE(RELATIVE):
*where += (Elf_Addr)sect->base;
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
printf ("rtl: reloc RELATIVE in %s --> %p @ %p\n",
rtems_rtl_obj_oname (obj), (void *)*where, where);
break;
case R_TYPE(RELATIVE):
*where += (Elf_Addr)sect->base;
if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC))
printf("rtl: reloc RELATIVE in %s --> %p @ %p\n",
rtems_rtl_obj_oname(obj), (void*)*where, where);
break;
case R_TYPE(COPY):
printf ("rtl: reloc COPY (please report)\n");
break;
case R_TYPE(COPY):
printf("rtl: reloc COPY (please report)\n");
break;
default:
printf ("rtl: reloc unknown: sym = %i, type = %" PRIu32 ", offset = %p, "
"contents = %p\n",
(int) ELF_R_SYM(rel->r_info), (uint32_t) ELF_R_TYPE(rel->r_info),
(void *)rel->r_offset, (void *)*where);
rtems_rtl_set_error (EINVAL,
"%s: Unsupported relocation type %" PRIu32 " "
"in non-PLT relocations",
sect->name, (uint32_t) ELF_R_TYPE(rel->r_info));
return rtems_rtl_elf_rel_failure;
default:
printf("rtl: reloc unknown: sym = %i, type = %" PRIu32 ", offset = %p, "
"contents = %p\n",
(int)ELF_R_SYM(rel->r_info), (uint32_t)ELF_R_TYPE(rel->r_info),
(void*)rel->r_offset, (void*)*where);
rtems_rtl_set_error(EINVAL,
"%s: Unsupported relocation type %" PRIu32 " "
"in non-PLT relocations",
sect->name, (uint32_t)ELF_R_TYPE(rel->r_info));
return rtems_rtl_elf_rel_failure;
}
return rtems_rtl_elf_rel_no_error;
}
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);
}
+131 -171
View File
@@ -37,237 +37,197 @@
#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <rtems/rtl/rtl.h>
#include "rtl-elf.h"
#include "rtl-error.h"
#include <rtems/rtl/rtl-trace.h>
#include "rtl-unwind.h"
#include "rtl-unwind-dw2.h"
#include "rtl-unwind.h"
#include <rtems/rtl/rtl-trace.h>
#include <rtems/rtl/rtl.h>
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) {
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)
{
bool rtems_rtl_elf_rel_resolve_sym(Elf_Word type) {
return true;
}
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) {
/*
* Disable by returning 0.
*/
return 0;
}
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_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;
return rtems_rtl_elf_rel_no_error;
}
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)
{
Elf_Addr *where;
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) {
Elf_Addr* where;
Elf32_Word tmp;
Elf32_Word insn;
where = (Elf_Addr *)(sect->base + rela->r_offset);
where = (Elf_Addr*)(sect->base + rela->r_offset);
switch (ELF_R_TYPE(rela->r_info)) {
case R_TYPE(NONE):
break;
case R_TYPE(NONE):
break;
case R_TYPE(HI16):
insn = *where;
/* orhi/mvhi instruction
* 31--------26|25-21|20-16|15----0|
* |0 1 1 1 1 0 |rY |rX |imm16 |
*/
if (0x1e == (insn >> 26)) {
insn &= 0xffff0000;
insn |= ((symvalue + rela->r_addend) >> 16);
*where = insn;
}
break;
case R_TYPE(HI16):
insn = *where;
/* orhi/mvhi instruction
* 31--------26|25-21|20-16|15----0|
* |0 1 1 1 1 0 |rY |rX |imm16 |
*/
if (0x1e == (insn >> 26)) {
insn &= 0xffff0000;
insn |= ((symvalue + rela->r_addend) >> 16);
*where = insn;
}
break;
case R_TYPE(LO16):
insn = *where;
/* ori instruction
* 31--------26|25-21|20-16|15----0|
* |0 0 1 1 1 0 |rY |rX |imm16 |
*/
if (0xe == (insn >> 26)) {
insn &= 0xffff0000;
insn |= ((symvalue + rela->r_addend) & 0xffff);
*where = insn;
}
break;
case R_TYPE(LO16):
insn = *where;
/* ori instruction
* 31--------26|25-21|20-16|15----0|
* |0 0 1 1 1 0 |rY |rX |imm16 |
*/
if (0xe == (insn >> 26)) {
insn &= 0xffff0000;
insn |= ((symvalue + rela->r_addend) & 0xffff);
*where = insn;
}
break;
case R_TYPE(CALL):
insn = *where;
/*
* calli instruction
* 31-------26|25---0|
* |1 1 1 1 1 0|imm26 |
* Syntax: call imm26
* Operation: ra = pc + 4; pc = pc + sign_extend(imm26<<2)
*/
if (0x3e == (insn >> 26)) {
Elf_Sword imm26 = symvalue +rela->r_addend - (Elf_Addr)where;
imm26 = (imm26 >> 2) & 0x3ffffff;
insn = 0xf8000000 + imm26;
*where = insn;
}
break;
case R_TYPE(CALL):
insn = *where;
/*
* calli instruction
* 31-------26|25---0|
* |1 1 1 1 1 0|imm26 |
* Syntax: call imm26
* Operation: ra = pc + 4; pc = pc + sign_extend(imm26<<2)
*/
if (0x3e == (insn >> 26)) {
Elf_Sword imm26 = symvalue + rela->r_addend - (Elf_Addr)where;
imm26 = (imm26 >> 2) & 0x3ffffff;
insn = 0xf8000000 + imm26;
*where = insn;
}
break;
case R_TYPE(BRANCH):
insn = *where;
tmp = symvalue + rela->r_addend - (Elf_Addr)where;
tmp = (Elf32_Sword)tmp >> 2;
if (((Elf32_Sword)tmp > 0x7fff) || ((Elf32_Sword)tmp < -0x8000)){
printf("BRANCH Overflow\n");
return rtems_rtl_elf_rel_failure;
}
*where = (*where & 0xffff0000) | (tmp & 0xffff);
break;
case R_TYPE(32):
*where = symvalue + rela->r_addend;
break;
default:
rtems_rtl_set_error (EINVAL, "rela type record not supported");
printf("Unsupported reloc types\n");
case R_TYPE(BRANCH):
insn = *where;
tmp = symvalue + rela->r_addend - (Elf_Addr)where;
tmp = (Elf32_Sword)tmp >> 2;
if (((Elf32_Sword)tmp > 0x7fff) || ((Elf32_Sword)tmp < -0x8000)) {
printf("BRANCH Overflow\n");
return rtems_rtl_elf_rel_failure;
}
*where = (*where & 0xffff0000) | (tmp & 0xffff);
break;
case R_TYPE(32):
*where = symvalue + rela->r_addend;
break;
default:
rtems_rtl_set_error(EINVAL, "rela type record not supported");
printf("Unsupported reloc types\n");
return rtems_rtl_elf_rel_failure;
}
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) {
printf("rela relocation type is %ld\n", ELF_R_TYPE(rela->r_info));
printf("relocated address 0x%08lx\n", (Elf_Addr)where);
if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC)) {
printf("rela relocation type is %ld\n", ELF_R_TYPE(rela->r_info));
printf("relocated address 0x%08lx\n", (Elf_Addr)where);
}
return rtems_rtl_elf_rel_no_error;
}
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) rela;
(void) sect;
(void) symname;
(void) syminfo;
(void) symvalue;
rtems_rtl_set_error (EINVAL, "rel type record not supported");
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)rela;
(void)sect;
(void)symname;
(void)syminfo;
(void)symvalue;
rtems_rtl_set_error(EINVAL, "rel 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) rela;
(void) sect;
(void) symname;
(void) syminfo;
(void) symvalue;
rtems_rtl_set_error (EINVAL, "rela type record not supported");
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)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;
}
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);
}
+106 -148
View File
@@ -8,128 +8,103 @@
#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <rtems/rtl/rtl.h>
#include "rtl-elf.h"
#include "rtl-error.h"
#include <rtems/rtl/rtl-trace.h>
#include "rtl-unwind.h"
#include "rtl-unwind-dw2.h"
#include "rtl-unwind.h"
#include <rtems/rtl/rtl-trace.h>
#include <rtems/rtl/rtl.h>
static inline int overflow_8_check(int value)
{
static inline int overflow_8_check(int value) {
if ((value & 0xffffff00) && (~value & 0xffffff80))
return true;
return false;
}
static inline int overflow_16_check(int value)
{
static inline int overflow_16_check(int value) {
if ((value & 0xffff0000) && (~value & 0xffff8000))
return true;
return false;
}
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;
}
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) {
/*
* Disable by returning 0.
*/
return 0;
}
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_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;
return rtems_rtl_elf_rel_no_error;
}
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) symname;
(void) syminfo;
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)symname;
(void)syminfo;
Elf_Addr target = 0;
Elf_Addr target = 0;
Elf_Addr* where;
Elf_Word tmp;
Elf_Word tmp;
where = (Elf_Addr *)(sect->base + rela->r_offset);
where = (Elf_Addr*)(sect->base + rela->r_offset);
switch (ELF_R_TYPE(rela->r_info)) {
case R_TYPE(NONE):
@@ -140,12 +115,12 @@ rtems_rtl_elf_relocate_rela (rtems_rtl_obj* obj,
if (overflow_8_check(tmp))
return rtems_rtl_elf_rel_failure;
*(uint8_t *)where = tmp;
*(uint8_t*)where = tmp;
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
printf ("rtl: reloc R_TYPE_8/PC8 in %s --> %p (%p) in %s\n",
sect->name, (void*) (symvalue + rela->r_addend),
(void *)*where, rtems_rtl_obj_oname (obj));
if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC))
printf("rtl: reloc R_TYPE_8/PC8 in %s --> %p (%p) in %s\n", sect->name,
(void*)(symvalue + rela->r_addend), (void*)*where,
rtems_rtl_obj_oname(obj));
break;
case R_TYPE(PC16):
@@ -155,40 +130,39 @@ rtems_rtl_elf_relocate_rela (rtems_rtl_obj* obj,
*(uint16_t*)where = tmp;
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
printf ("rtl: reloc R_TYPE_16/PC16 in %s --> %p (%p) in %s\n",
sect->name, (void*) (symvalue + rela->r_addend),
(void *)*where, rtems_rtl_obj_oname (obj));
if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC))
printf("rtl: reloc R_TYPE_16/PC16 in %s --> %p (%p) in %s\n", sect->name,
(void*)(symvalue + rela->r_addend), (void*)*where,
rtems_rtl_obj_oname(obj));
break;
case R_TYPE(PC32):
target = (Elf_Addr) symvalue + rela->r_addend;
target = (Elf_Addr)symvalue + rela->r_addend;
*where += target - (Elf_Addr)where;
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
printf ("rtl: reloc PC32 in %s --> %p (%p) in %s\n",
sect->name, (void*) (symvalue + rela->r_addend),
(void *)*where, rtems_rtl_obj_oname (obj));
if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC))
printf("rtl: reloc PC32 in %s --> %p (%p) in %s\n", sect->name,
(void*)(symvalue + rela->r_addend), (void*)*where,
rtems_rtl_obj_oname(obj));
break;
case R_TYPE(GOT32):
case R_TYPE(32):
case R_TYPE(GLOB_DAT):
target = (Elf_Addr) symvalue + rela->r_addend;
target = (Elf_Addr)symvalue + rela->r_addend;
if (*where != target)
*where = target;
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
printf ("rtl: reloc 32/GLOB_DAT in %s --> %p in %s\n",
sect->name, (void *)*where,
rtems_rtl_obj_oname (obj));
if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC))
printf("rtl: reloc 32/GLOB_DAT in %s --> %p in %s\n", sect->name,
(void*)*where, rtems_rtl_obj_oname(obj));
break;
case R_TYPE(RELATIVE):
*where += (Elf_Addr) sect->base + rela->r_addend;
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
printf ("rtl: reloc RELATIVE in %s --> %p\n",
rtems_rtl_obj_oname (obj), (void *)*where);
*where += (Elf_Addr)sect->base + rela->r_addend;
if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC))
printf("rtl: reloc RELATIVE in %s --> %p\n", rtems_rtl_obj_oname(obj),
(void*)*where);
break;
case R_TYPE(COPY):
@@ -198,76 +172,60 @@ rtems_rtl_elf_relocate_rela (rtems_rtl_obj* obj,
* COPY relocation is not in a shared library. They
* are allowed only in executable files.
*/
printf ("rtl: reloc COPY (please report)\n");
printf("rtl: reloc COPY (please report)\n");
break;
default:
printf ("rtl: reloc unknown: sym = %u, type = %u, offset = %p, "
"contents = %p\n",
ELF_R_SYM(rela->r_info), (uint32_t) ELF_R_TYPE(rela->r_info),
(void *)rela->r_offset, (void *)*where);
rtems_rtl_set_error (EINVAL,
"%s: Unsupported relocation type %d "
"in non-PLT relocations",
sect->name, (uint32_t) ELF_R_TYPE(rela->r_info));
printf("rtl: reloc unknown: sym = %u, type = %u, offset = %p, "
"contents = %p\n",
ELF_R_SYM(rela->r_info), (uint32_t)ELF_R_TYPE(rela->r_info),
(void*)rela->r_offset, (void*)*where);
rtems_rtl_set_error(EINVAL,
"%s: Unsupported relocation type %d "
"in non-PLT relocations",
sect->name, (uint32_t)ELF_R_TYPE(rela->r_info));
return rtems_rtl_elf_rel_failure;
}
return rtems_rtl_elf_rel_no_error;
}
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, "rel type record not supported");
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, "rel 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_set_error (EINVAL, "rel type record not supported");
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, "rel 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);
}
+136 -180
View File
@@ -29,132 +29,117 @@
#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <rtems/rtl/rtl.h>
#include "rtl-elf.h"
#include "rtl-error.h"
#include <rtems/rtl/rtl-trace.h>
#include "rtl-unwind.h"
#include "rtl-unwind-dw2.h"
#include "rtl-unwind.h"
#include <rtems/rtl/rtl-trace.h>
#include <rtems/rtl/rtl.h>
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) {
bool rtems_rtl_elf_rel_resolve_sym(Elf_Word type) {
return type != 0;
}
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) {
/*
* Disable by returning 0.
*/
return 0;
}
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;
return rtems_rtl_elf_rel_no_error;
}
static void write16le(void *loc, uint16_t val) {
*((uint16_t *) loc) = val;
static void write16le(void* loc, uint16_t val) {
*((uint16_t*)loc) = val;
}
static void write32le(void *loc, uint32_t val) {
*((uint32_t *) loc) = val;
static void write32le(void* loc, uint32_t val) {
*((uint32_t*)loc) = val;
}
static uint16_t read16le(void *loc) {
return *((uint16_t *) loc);
static uint16_t read16le(void* loc) {
return *((uint16_t*)loc);
}
static uint32_t read32le(void *loc) {
return *((uint32_t *) loc);
static uint32_t read32le(void* loc) {
return *((uint32_t*)loc);
}
/*
* If reviewing / debugging the following links are helpful.
* Relocations table
* https://github.com/bminor/binutils-gdb/blob/master/include/elf/microblaze.h
* Relocations implementations
* https://github.com/bminor/binutils-gdb/blob/master/bfd/elf32-microblaze.c
* Xilinx microblaze reference
* https://docs.amd.com/r/2024.2-English/ug984-vivado-microblaze-ref/Relocations
* There is some disagreement between microblaze reference, and the binutils reference.
* 5 R_MICROBLAZE_32_PCREL_LO vs RELOC_NUMBER (R_MICROBLAZE_64, 5)
*
*/
* If reviewing / debugging the following links are helpful.
* Relocations table
* https://github.com/bminor/binutils-gdb/blob/master/include/elf/microblaze.h
* Relocations implementations
* https://github.com/bminor/binutils-gdb/blob/master/bfd/elf32-microblaze.c
* Xilinx microblaze reference
* https://docs.amd.com/r/2024.2-English/ug984-vivado-microblaze-ref/Relocations
* There is some disagreement between microblaze reference, and the binutils
* reference. 5 R_MICROBLAZE_32_PCREL_LO vs RELOC_NUMBER (R_MICROBLAZE_64, 5)
*
*/
static 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;
Elf_Word *where;
Elf_Word* where;
Elf_Word addend = (Elf_Word)rela->r_addend;
Elf_Addr target;
where = (Elf_Addr *)(sect->base + rela->r_offset);
where = (Elf_Addr*)(sect->base + rela->r_offset);
/* Target value */
target = (Elf_Addr)symvalue + addend;
@@ -171,53 +156,50 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj* obj,
case R_TYPE(64):
/* Set the lower 16 bits of where to the upper 16 bits of target */
write16le(where,
(read16le(where) & 0xFFFF0000) | (target >> 16));
write16le(where, (read16le(where) & 0xFFFF0000) | (target >> 16));
/* Set the lower 16 bits of where + 4 to the lower 16 bits of target */
write16le(where + 1,
(read16le(where + 1) & 0xFFFF0000) | (target & 0xFFFF));
break;
case R_TYPE(32):
{
uintptr_t addr = (uintptr_t)where;
if ((uintptr_t)where & 3) {
/* `where` is not aligned to a 4-byte boundary. */
uintptr_t addr_down = addr & ~3;
uintptr_t addr_up = (addr + 3) & ~3;
case R_TYPE(32): {
uintptr_t addr = (uintptr_t)where;
if ((uintptr_t)where & 3) {
/* `where` is not aligned to a 4-byte boundary. */
uintptr_t addr_down = addr & ~3;
uintptr_t addr_up = (addr + 3) & ~3;
uint32_t value_down = read32le((void*)addr_down);
uint32_t value_up = read32le((void*)addr_up);
uint32_t value_down = read32le((void*)addr_down);
uint32_t value_up = read32le((void*)addr_up);
/*
* Calculate how many bytes `where` is offset from the previous 4-byte
* boundary.
*/
unsigned offset = addr & 3;
/*
* Calculate how many bytes `where` is offset from the previous 4-byte
* boundary.
*/
unsigned offset = addr & 3;
/*
* Combine `target` with `value_down` and `value_up` to form the new
* values to write.
*/
uint32_t new_value_down = (value_down & ((1 << (offset * 8)) - 1)) |
(target << (offset * 8));
uint32_t new_value_up = (value_up & ~((1 << (offset * 8)) - 1)) |
(target >> ((4 - offset) * 8));
/*
* Combine `target` with `value_down` and `value_up` to form the new
* values to write.
*/
uint32_t new_value_down =
(value_down & ((1 << (offset * 8)) - 1)) | (target << (offset * 8));
uint32_t new_value_up = (value_up & ~((1 << (offset * 8)) - 1)) |
(target >> ((4 - offset) * 8));
write32le((void*)addr_down, new_value_down);
write32le((void*)addr_up, new_value_up);
} else {
write32le(where, target);
}
write32le((void*)addr_down, new_value_down);
write32le((void*)addr_up, new_value_up);
} else {
write32le(where, target);
}
break;
} break;
case R_TYPE(32_PCREL):
write32le(where, pcrel_val);
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
printf ("rtl: R_MICROBLAZE_32_PCREL %p @ %p in %s\n",
(void *) * (where), where, rtems_rtl_obj_oname (obj));
if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC))
printf("rtl: R_MICROBLAZE_32_PCREL %p @ %p in %s\n", (void*)*(where),
where, rtems_rtl_obj_oname(obj));
break;
case R_TYPE(64_PCREL):
@@ -226,15 +208,14 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj* obj,
*/
pcrel_val -= 4;
/* Set the lower 16 bits of where to the upper 16 bits of target */
write16le(where,
(read16le(where) & 0xFFFF0000) | (pcrel_val >> 16));
write16le(where, (read16le(where) & 0xFFFF0000) | (pcrel_val >> 16));
/* Set the lower 16 bits of where + 4 to the lower 16 bits of target */
write16le(where + 1,
(read16le(where + 1) & 0xFFFF0000) | (pcrel_val & 0xFFFF));
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
printf ("rtl: R_MICROBLAZE_64_PCREL %p @ %p in %s\n",
(void *) * (where), where, rtems_rtl_obj_oname (obj));
if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC))
printf("rtl: R_MICROBLAZE_64_PCREL %p @ %p in %s\n", (void*)*(where),
where, rtems_rtl_obj_oname(obj));
break;
case R_TYPE(32_PCREL_LO):
@@ -269,21 +250,20 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj* obj,
break;
*/
/* GNU vtable metadata relocs: ignore like binutils.
/* GNU vtable metadata relocs: ignore like binutils.
* Place holder incase needed, untested.
*/
*/
/* case 11: R_MICROBLAZE_GNU_VTINHERIT */
/* case 12: R_MICROBLAZE_GNU_VTENTRY
/* case 12: R_MICROBLAZE_GNU_VTENTRY
break;
*/
default:
rtems_rtl_set_error (EINVAL,
"%s: unsupported relocation type %u "
"at 0x%lx (sym %s) in non-PLT relocations",
sect->name,
(unsigned int) ELF_R_TYPE (rela->r_info),
(unsigned long) rela->r_offset,
symname != NULL ? symname : "<local>");
rtems_rtl_set_error(EINVAL,
"%s: unsupported relocation type %u "
"at 0x%lx (sym %s) in non-PLT relocations",
sect->name, (unsigned int)ELF_R_TYPE(rela->r_info),
(unsigned long)rela->r_offset,
symname != NULL ? symname : "<local>");
return rtems_rtl_elf_rel_failure;
}
@@ -291,69 +271,45 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj* obj,
}
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_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_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) {
(void)obj;
(void)rel;
(void)sect;
(void)symname;
(void)syminfo;
(void)symvalue;
(void) obj;
(void) rel;
(void) sect;
(void) symname;
(void) syminfo;
(void) symvalue;
rtems_rtl_set_error (EINVAL, "rel type record not supported");
rtems_rtl_set_error(EINVAL, "rel 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);
}
File diff suppressed because it is too large Load Diff
+108 -146
View File
@@ -33,217 +33,179 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <rtems/rtl/rtl.h>
#include "rtl-elf.h"
#include "rtl-error.h"
#include <rtems/rtl/rtl-trace.h>
#include "rtl-unwind.h"
#include "rtl-unwind-dw2.h"
#include "rtl-unwind.h"
#include <rtems/rtl/rtl-trace.h>
#include <rtems/rtl/rtl.h>
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;
}
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) {
/*
* Disable by returning 0.
*/
return 0;
}
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_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;
return rtems_rtl_elf_rel_no_error;
}
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) symname;
(void) syminfo;
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)symname;
(void)syminfo;
Elf_Addr *where;
Elf_Addr* where;
Elf_Sword tmp;
where = (Elf_Addr *)(sect->base + rela->r_offset);
where = (Elf_Addr*)(sect->base + rela->r_offset);
/* Handle the not 4byte aligned address carefully */
switch (ELF_R_TYPE(rela->r_info)) {
case R_TYPE(NONE):
break;
case R_TYPE(NONE):
break;
case R_TYPE(32):
*(uint16_t *)where = ((symvalue + rela->r_addend) >> 16) & 0xffff;
*((uint16_t *)where + 1) = (symvalue + rela->r_addend) & 0xffff;
case R_TYPE(32):
*(uint16_t*)where = ((symvalue + rela->r_addend) >> 16) & 0xffff;
*((uint16_t*)where + 1) = (symvalue + rela->r_addend) & 0xffff;
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) {
printf("*where 0x%04x%04x\n", *((uint16_t *)where + 1), *(uint16_t *)where);
}
break;
if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC)) {
printf("*where 0x%04x%04x\n", *((uint16_t*)where + 1), *(uint16_t*)where);
}
break;
case R_TYPE(PCREL10):
/* beq, bge, bgeu, bgt, bgtu, ble, bleu, blt, bltu, bne */
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) {
printf("*where %x\n", *(uint16_t *)where);
printf("symvalue - where %x\n", (int)(symvalue - (Elf_Word)where));
}
tmp = (symvalue + rela->r_addend - ((Elf_Word)where + 2)); /* pc is the next instruction */
tmp = (Elf_Sword)tmp >> 1;
if (((Elf32_Sword)tmp > 0x1ff) || ((Elf32_Sword)tmp < -(Elf32_Sword)0x200)){
printf("Overflow for PCREL10: %d exceed -0x200:0x1ff\n", tmp);
return rtems_rtl_elf_rel_failure;
}
*(uint16_t *)where = (*(uint16_t *)where & 0xfc00) | (tmp & 0x3ff);
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) {
printf("*where 0x%04x\n", *(uint16_t *)where);
}
break;
default:
rtems_rtl_set_error (EINVAL, "rela type record not supported");
printf("Unsupported reloc types\n");
case R_TYPE(PCREL10):
/* beq, bge, bgeu, bgt, bgtu, ble, bleu, blt, bltu, bne */
if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC)) {
printf("*where %x\n", *(uint16_t*)where);
printf("symvalue - where %x\n", (int)(symvalue - (Elf_Word)where));
}
tmp = (symvalue + rela->r_addend -
((Elf_Word)where + 2)); /* pc is the next instruction */
tmp = (Elf_Sword)tmp >> 1;
if (((Elf32_Sword)tmp > 0x1ff) ||
((Elf32_Sword)tmp < -(Elf32_Sword)0x200)) {
printf("Overflow for PCREL10: %d exceed -0x200:0x1ff\n", tmp);
return rtems_rtl_elf_rel_failure;
}
*(uint16_t*)where = (*(uint16_t*)where & 0xfc00) | (tmp & 0x3ff);
if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC)) {
printf("*where 0x%04x\n", *(uint16_t*)where);
}
break;
default:
rtems_rtl_set_error(EINVAL, "rela type record not supported");
printf("Unsupported reloc types\n");
return rtems_rtl_elf_rel_failure;
}
return rtems_rtl_elf_rel_no_error;
}
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, "rel type record not supported");
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, "rel 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_set_error (EINVAL, "rel type record not supported");
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, "rel 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);
}
File diff suppressed because it is too large Load Diff
+117 -167
View File
@@ -39,88 +39,76 @@
#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <rtems/rtl/rtl.h>
#include "rtl-elf.h"
#include "rtl-error.h"
#include <rtems/rtl/rtl-trace.h>
#include "rtl-unwind.h"
#include "rtl-unwind-dw2.h"
#include "rtl-unwind.h"
#include <rtems/rtl/rtl-trace.h>
#include <rtems/rtl/rtl.h>
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;
}
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) {
/*
* Disable by returning 0.
*/
return 0;
}
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;
return rtems_rtl_elf_rel_no_error;
}
@@ -130,50 +118,47 @@ static uint32_t extractBits(uint64_t v, uint32_t begin, uint32_t end) {
}
static int64_t SignExtend64(uint64_t val, unsigned bits) {
return (int64_t )(((int64_t) (val << (64 - bits))) >> (64 - bits));
return (int64_t)(((int64_t)(val << (64 - bits))) >> (64 - bits));
}
static void write16le(void *loc, uint16_t val) {
*((uint16_t *) loc) = val;
static void write16le(void* loc, uint16_t val) {
*((uint16_t*)loc) = val;
}
static void write32le(void *loc, uint32_t val) {
*((uint32_t *) loc) = val;
static void write32le(void* loc, uint32_t val) {
*((uint32_t*)loc) = val;
}
static void write64le(void *loc, uint64_t val) {
*((uint64_t *) loc) = val;
static void write64le(void* loc, uint64_t val) {
*((uint64_t*)loc) = val;
}
static uint16_t read16le(void *loc) {
return *((uint16_t *) loc);
static uint16_t read16le(void* loc) {
return *((uint16_t*)loc);
}
static uint32_t read32le(void *loc) {
return *((uint32_t *) loc);
static uint32_t read32le(void* loc) {
return *((uint32_t*)loc);
}
static uint64_t read64le(void *loc) {
return *((uint64_t *) loc);
static uint64_t read64le(void* loc) {
return *((uint64_t*)loc);
}
static 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;
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;
Elf_Addr *where;
Elf_Addr* where;
char bits = (sizeof(Elf_Word) * 8);
where = (Elf_Addr *)(sect->base + rela->r_offset);
where = (Elf_Addr*)(sect->base + rela->r_offset);
// Final PCREL value
Elf_Word pcrel_val = symvalue - ((Elf_Word)(uintptr_t) where);
Elf_Word pcrel_val = symvalue - ((Elf_Word)(uintptr_t)where);
if (syminfo == STT_SECTION) {
return rtems_rtl_elf_rel_no_error;
@@ -197,8 +182,7 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj* obj,
insn |= imm8 | imm4_3 | imm7_6 | imm2_1 | imm5;
write16le(where, insn);
}
break;
} break;
case R_TYPE(RVC_JUMP): {
uint16_t insn = ((*where) & 0xFFFF) & 0xE003;
@@ -213,8 +197,7 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj* obj,
insn |= imm11 | imm4 | imm9_8 | imm10 | imm6 | imm7 | imm3_1 | imm5;
write16le(where, insn);
}
break;
} break;
case R_TYPE(RVC_LUI): {
int64_t imm = SignExtend64(symvalue + 0x800, bits) >> 12;
@@ -225,8 +208,7 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj* obj,
uint16_t imm16_12 = extractBits(symvalue + 0x800, 16, 12) << 2;
write16le(where, (read16le(where) & 0xEF83) | imm17 | imm16_12);
}
}
break;
} break;
case R_TYPE(JAL): {
uint32_t insn = read32le(where) & 0xFFF;
@@ -237,8 +219,7 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj* obj,
insn |= imm20 | imm10_1 | imm11 | imm19_12;
write32le(where, insn);
}
break;
} break;
case R_TYPE(BRANCH): {
@@ -250,8 +231,7 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj* obj,
insn |= imm12 | imm10_5 | imm4_1 | imm11;
write32le(where, insn);
}
break;
} break;
case R_TYPE(64):
write64le(where, symvalue);
@@ -261,10 +241,10 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj* obj,
break;
case R_TYPE(SET6):
*((uint8_t *) where) = (*where & 0xc0) | (symvalue & 0x3f);
*((uint8_t*)where) = (*where & 0xc0) | (symvalue & 0x3f);
break;
case R_TYPE(SET8):
*((uint8_t *) where) = symvalue;
*((uint8_t*)where) = symvalue;
break;
case R_TYPE(SET16):
write16le(where, symvalue);
@@ -274,7 +254,7 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj* obj,
break;
case R_TYPE(ADD8):
*((uint8_t *) where) = *((uint8_t *) where) + symvalue;
*((uint8_t*)where) = *((uint8_t*)where) + symvalue;
break;
case R_TYPE(ADD16):
write16le(where, read16le(where) + symvalue);
@@ -287,10 +267,11 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj* obj,
break;
case R_TYPE(SUB6):
*((uint8_t *) where) = (*where & 0xc0) | (((*where & 0x3f) - symvalue) & 0x3f);
*((uint8_t*)where) =
(*where & 0xc0) | (((*where & 0x3f) - symvalue) & 0x3f);
break;
case R_TYPE(SUB8):
*((uint8_t *) where) = *((uint8_t *) where) - symvalue;
*((uint8_t*)where) = *((uint8_t*)where) - symvalue;
break;
case R_TYPE(SUB16):
write16le(where, read16le(where) - symvalue);
@@ -305,34 +286,30 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj* obj,
case R_TYPE(32_PCREL): {
write32le(where, pcrel_val);
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
printf ("rtl: R_RISCV_32_PCREL %p @ %p in %s\n",
(void *) * (where), where, rtems_rtl_obj_oname (obj));
if (rtems_rtl_trace(RTEMS_RTL_TRACE_RELOC))
printf("rtl: R_RISCV_32_PCREL %p @ %p in %s\n", (void*)*(where), where,
rtems_rtl_obj_oname(obj));
}
break;
} break;
case R_TYPE(PCREL_HI20): {
int64_t hi = SignExtend64(pcrel_val + 0x800, bits); //pcrel_val + 0x800;
int64_t hi = SignExtend64(pcrel_val + 0x800, bits); // pcrel_val + 0x800;
write32le(where, (read32le(where) & 0xFFF) | (hi & 0xFFFFF000));
}
break;
} break;
case R_TYPE(GOT_HI20):
case R_TYPE(HI20): {
uint64_t hi = symvalue + 0x800;
write32le(where, (read32le(where) & 0xFFF) | (hi & 0xFFFFF000));
}
break;
} break;
case R_TYPE(PCREL_LO12_I): {
uint64_t hi = (pcrel_val + 0x800) >> 12;
uint64_t lo = pcrel_val - (hi << 12);
write32le(where, (read32le(where) & 0xFFFFF) | ((lo & 0xFFF) << 20));
}
break;
} break;
case R_TYPE(LO12_I): {
@@ -340,8 +317,7 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj* obj,
uint64_t lo = symvalue - (hi << 12);
write32le(where, (read32le(where) & 0xFFFFF) | ((lo & 0xFFF) << 20));
}
break;
} break;
case R_TYPE(PCREL_LO12_S): {
uint64_t hi = (pcrel_val + 0x800) >> 12;
@@ -350,8 +326,7 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj* obj,
uint32_t imm4_0 = extractBits(lo, 4, 0) << 7;
write32le(where, (read32le(where) & 0x1FFF07F) | imm11_5 | imm4_0);
}
break;
} break;
case R_TYPE(LO12_S): {
uint64_t hi = (symvalue + 0x800) >> 12;
@@ -359,8 +334,7 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj* obj,
uint32_t imm11_5 = extractBits(lo, 11, 5) << 25;
uint32_t imm4_0 = extractBits(lo, 4, 0) << 7;
write32le(where, (read32le(where) & 0x1FFF07F) | imm11_5 | imm4_0);
}
break;
} break;
case R_TYPE(CALL_PLT):
case R_TYPE(CALL): {
@@ -368,15 +342,15 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj* obj,
write32le(where, (read32le(where) & 0xFFF) | (hi & 0xFFFFF000));
int64_t hi20 = SignExtend64(pcrel_val + 0x800, bits);
int64_t lo = pcrel_val - (hi20 << 12);
write32le(((char *) where) + 4, (read32le(((char *) where) + 4) & 0xFFFFF) | ((lo & 0xFFF) << 20));
}
break;
write32le(((char*)where) + 4,
(read32le(((char*)where) + 4) & 0xFFFFF) | ((lo & 0xFFF) << 20));
} break;
default:
rtems_rtl_set_error (EINVAL,
"%s: Unsupported relocation type %u "
"in non-PLT relocations",
sect->name, (uint32_t) ELF_R_TYPE(rela->r_info));
rtems_rtl_set_error(EINVAL,
"%s: Unsupported relocation type %u "
"in non-PLT relocations",
sect->name, (uint32_t)ELF_R_TYPE(rela->r_info));
return rtems_rtl_elf_rel_failure;
}
@@ -384,68 +358,44 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj* obj,
}
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_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_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_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_set_error (EINVAL, "rel type record not supported");
rtems_rtl_set_error(EINVAL, "rel 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);
}
File diff suppressed because it is too large Load Diff
+77 -110
View File
@@ -39,111 +39,91 @@
#endif
#include <errno.h>
#include <inttypes.h>
#include <rtems/inttypes.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <inttypes.h>
#include <rtems/inttypes.h>
#include "rtl-error.h"
#include <rtems/rtl/rtl-allocator.h>
#include <rtems/rtl/rtl-obj-cache.h>
#include "rtl-error.h"
#include <rtems/rtl/rtl-trace.h>
bool
rtems_rtl_obj_cache_open (rtems_rtl_obj_cache* cache, size_t size)
{
cache->fd = -1;
bool rtems_rtl_obj_cache_open(rtems_rtl_obj_cache* cache, size_t size) {
cache->fd = -1;
cache->file_size = 0;
cache->offset = 0;
cache->size = size;
cache->level = 0;
cache->buffer = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, size, false);
if (!cache->buffer)
{
rtems_rtl_set_error (ENOMEM, "no memory for cache buffer");
cache->offset = 0;
cache->size = size;
cache->level = 0;
cache->buffer = rtems_rtl_alloc_new(RTEMS_RTL_ALLOC_OBJECT, size, false);
if (!cache->buffer) {
rtems_rtl_set_error(ENOMEM, "no memory for cache buffer");
return false;
}
return true;
}
void
rtems_rtl_obj_cache_close (rtems_rtl_obj_cache* cache)
{
if (rtems_rtl_trace (RTEMS_RTL_TRACE_CACHE))
printf ("rtl: cache: %2d: close\n", cache->fd);
rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, cache->buffer);
cache->buffer = NULL;
cache->fd = -1;
void rtems_rtl_obj_cache_close(rtems_rtl_obj_cache* cache) {
if (rtems_rtl_trace(RTEMS_RTL_TRACE_CACHE))
printf("rtl: cache: %2d: close\n", cache->fd);
rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_OBJECT, cache->buffer);
cache->buffer = NULL;
cache->fd = -1;
cache->file_size = 0;
cache->level = 0;
cache->level = 0;
}
void
rtems_rtl_obj_cache_flush (rtems_rtl_obj_cache* cache)
{
if (rtems_rtl_trace (RTEMS_RTL_TRACE_CACHE))
printf ("rtl: cache: %2d: flush\n", cache->fd);
cache->fd = -1;
void rtems_rtl_obj_cache_flush(rtems_rtl_obj_cache* cache) {
if (rtems_rtl_trace(RTEMS_RTL_TRACE_CACHE))
printf("rtl: cache: %2d: flush\n", cache->fd);
cache->fd = -1;
cache->file_size = 0;
cache->offset = 0;
cache->level = 0;
cache->offset = 0;
cache->level = 0;
}
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) {
struct stat sb;
if (rtems_rtl_trace (RTEMS_RTL_TRACE_CACHE))
printf ("rtl: cache: %2d: fd=%d offset=%" PRIdoff_t " length=%zu area=[%"
PRIdoff_t ",%" PRIdoff_t "] cache=[%" PRIdoff_t ",%" PRIdoff_t "] size=%zu\n",
fd, cache->fd, offset, *length,
offset, offset + *length,
cache->offset, cache->offset + cache->level,
cache->file_size);
if (rtems_rtl_trace(RTEMS_RTL_TRACE_CACHE))
printf("rtl: cache: %2d: fd=%d offset=%" PRIdoff_t
" length=%zu area=[%" PRIdoff_t ",%" PRIdoff_t "] cache=[%" PRIdoff_t
",%" PRIdoff_t "] size=%zu\n",
fd, cache->fd, offset, *length, offset, offset + *length,
cache->offset, cache->offset + cache->level, cache->file_size);
if (*length > cache->size)
{
rtems_rtl_set_error (EINVAL, "read size larger than cache size");
if (*length > cache->size) {
rtems_rtl_set_error(EINVAL, "read size larger than cache size");
return false;
}
if (cache->fd == fd)
{
if (offset >= (int64_t)cache->file_size)
{
rtems_rtl_set_error (EINVAL, "offset past end of file: offset=%i size=%i",
(int) offset, (int) cache->file_size);
if (cache->fd == fd) {
if (offset >= (int64_t)cache->file_size) {
rtems_rtl_set_error(EINVAL, "offset past end of file: offset=%i size=%i",
(int)offset, (int)cache->file_size);
return false;
}
/*
* We sometimes are asked to read strings of a length we do not know.
*/
if ((offset + *length) > cache->file_size)
{
if ((offset + *length) > cache->file_size) {
*length = cache->file_size - offset;
if (rtems_rtl_trace (RTEMS_RTL_TRACE_CACHE))
printf ("rtl: cache: %2d: truncate length=%d\n", fd, (int) *length);
if (rtems_rtl_trace(RTEMS_RTL_TRACE_CACHE))
printf("rtl: cache: %2d: truncate length=%d\n", fd, (int)*length);
}
}
while (true)
{
while (true) {
size_t buffer_offset = 0;
size_t buffer_read = cache->size;
/*
* Is the data in the cache for this file ?
*/
if (fd == cache->fd)
{
if (fd == cache->fd) {
/*
* Do not read past the end of the file.
*/
@@ -154,12 +134,11 @@ rtems_rtl_obj_cache_read (rtems_rtl_obj_cache* cache,
* Is any part of the data in the cache ?
*/
if ((offset >= cache->offset) &&
(offset < (int64_t)(cache->offset + cache->level)))
{
(offset < (int64_t)(cache->offset + cache->level))) {
size_t size;
buffer_offset = offset - cache->offset;
size = cache->level - buffer_offset;
size = cache->level - buffer_offset;
/*
* Return the location of the data in the cache.
@@ -172,19 +151,20 @@ rtems_rtl_obj_cache_read (rtems_rtl_obj_cache* cache,
if (*length <= size)
return true;
if (rtems_rtl_trace (RTEMS_RTL_TRACE_CACHE))
printf ("rtl: cache: %2d: copy-down: buffer_offset=%d size=%d level=%d\n",
fd, (int) buffer_offset, (int) size, (int) cache->level);
if (rtems_rtl_trace(RTEMS_RTL_TRACE_CACHE))
printf(
"rtl: cache: %2d: copy-down: buffer_offset=%d size=%d level=%d\n",
fd, (int)buffer_offset, (int)size, (int)cache->level);
/*
* Copy down the data in the buffer and then fill the remaining space
* with as much data we are able to read.
*/
memmove (cache->buffer, cache->buffer + buffer_offset, size);
memmove(cache->buffer, cache->buffer + buffer_offset, size);
cache->offset = offset;
cache->level = size;
buffer_read = cache->size - cache->level;
cache->level = size;
buffer_read = cache->size - cache->level;
buffer_offset = size;
/*
@@ -195,17 +175,15 @@ rtems_rtl_obj_cache_read (rtems_rtl_obj_cache* cache,
}
}
if (rtems_rtl_trace (RTEMS_RTL_TRACE_CACHE))
printf ("rtl: cache: %2d: seek: offset=%" PRIdoff_t " buffer_offset=%zu"
" read=%zu cache=[%" PRIdoff_t ",%" PRIdoff_t "] "
"dist=%" PRIdoff_t "\n",
fd, offset + buffer_offset, buffer_offset, buffer_read,
offset, offset + buffer_read,
(cache->file_size - offset));
if (rtems_rtl_trace(RTEMS_RTL_TRACE_CACHE))
printf("rtl: cache: %2d: seek: offset=%" PRIdoff_t " buffer_offset=%zu"
" read=%zu cache=[%" PRIdoff_t ",%" PRIdoff_t "] "
"dist=%" PRIdoff_t "\n",
fd, offset + buffer_offset, buffer_offset, buffer_read, offset,
offset + buffer_read, (cache->file_size - offset));
if (lseek (fd, offset + buffer_offset, SEEK_SET) < 0)
{
rtems_rtl_set_error (errno, "file seek failed");
if (lseek(fd, offset + buffer_offset, SEEK_SET) < 0) {
rtems_rtl_set_error(errno, "file seek failed");
return false;
}
@@ -217,23 +195,19 @@ rtems_rtl_obj_cache_read (rtems_rtl_obj_cache* cache,
cache->level = buffer_offset + buffer_read;
while (buffer_read)
{
int r = read (fd, cache->buffer + buffer_offset, buffer_read);
if (r < 0)
{
rtems_rtl_set_error (errno, "file read failed");
while (buffer_read) {
int r = read(fd, cache->buffer + buffer_offset, buffer_read);
if (r < 0) {
rtems_rtl_set_error(errno, "file read failed");
return false;
}
if ((r == 0) && buffer_read)
{
if (rtems_rtl_trace (RTEMS_RTL_TRACE_CACHE))
printf ("rtl: cache: %2d: read: past end by=%d\n", fd, (int) buffer_read);
if ((r == 0) && buffer_read) {
if (rtems_rtl_trace(RTEMS_RTL_TRACE_CACHE))
printf("rtl: cache: %2d: read: past end by=%d\n", fd,
(int)buffer_read);
cache->level = cache->level - buffer_read;
buffer_read = 0;
}
else
{
} else {
buffer_read -= r;
buffer_offset += r;
}
@@ -241,13 +215,11 @@ rtems_rtl_obj_cache_read (rtems_rtl_obj_cache* cache,
cache->offset = offset;
if (cache->fd != fd)
{
if (cache->fd != fd) {
cache->fd = fd;
if (fstat (cache->fd, &sb) < 0)
{
rtems_rtl_set_error (errno, "file stat failed");
if (fstat(cache->fd, &sb) < 0) {
rtems_rtl_set_error(errno, "file stat failed");
return false;
}
@@ -258,19 +230,14 @@ rtems_rtl_obj_cache_read (rtems_rtl_obj_cache* cache,
return false;
}
bool
rtems_rtl_obj_cache_read_byval (rtems_rtl_obj_cache* cache,
int fd,
off_t offset,
void* buffer,
size_t length)
{
void* cbuffer = 0;
bool rtems_rtl_obj_cache_read_byval(rtems_rtl_obj_cache* cache, int fd,
off_t offset, void* buffer, size_t length) {
void* cbuffer = 0;
size_t len = length;
bool ok = rtems_rtl_obj_cache_read (cache, fd, offset, &cbuffer, &len);
bool ok = rtems_rtl_obj_cache_read(cache, fd, offset, &cbuffer, &len);
if (ok && (len != length))
ok = false;
if (ok)
memcpy (buffer, cbuffer, length);
memcpy(buffer, cbuffer, length);
return ok;
}
+73 -98
View File
@@ -39,44 +39,38 @@
#endif
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <inttypes.h>
#include <rtems/inttypes.h>
#include <string.h>
#include <unistd.h>
#include "rtl-error.h"
#include <rtems/rtl/rtl-allocator.h>
#include <rtems/rtl/rtl-obj-comp.h>
#include "rtl-error.h"
#include <rtems/rtl/rtl-trace.h>
#include "fastlz.h"
#include <stdio.h>
bool
rtems_rtl_obj_comp_open (rtems_rtl_obj_comp* comp,
size_t size)
{
comp->cache = NULL;
bool rtems_rtl_obj_comp_open(rtems_rtl_obj_comp* comp, size_t size) {
comp->cache = NULL;
comp->fd = -1;
comp->compression = RTEMS_RTL_COMP_LZ77;
comp->offset = 0;
comp->size = size;
comp->level = 0;
comp->buffer = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, size, false);
if (!comp->buffer)
{
rtems_rtl_set_error (ENOMEM, "no memory for compressor buffer");
comp->size = size;
comp->level = 0;
comp->buffer = rtems_rtl_alloc_new(RTEMS_RTL_ALLOC_OBJECT, size, false);
if (!comp->buffer) {
rtems_rtl_set_error(ENOMEM, "no memory for compressor buffer");
return false;
}
comp->read = 0;
return true;
}
void
rtems_rtl_obj_comp_close (rtems_rtl_obj_comp* comp)
{
rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, comp->buffer);
void rtems_rtl_obj_comp_close(rtems_rtl_obj_comp* comp) {
rtems_rtl_alloc_del(RTEMS_RTL_ALLOC_OBJECT, comp->buffer);
comp->cache = NULL;
comp->fd = -1;
comp->compression = RTEMS_RTL_COMP_LZ77;
@@ -86,13 +80,9 @@ rtems_rtl_obj_comp_close (rtems_rtl_obj_comp* comp)
comp->read = 0;
}
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) {
comp->cache = cache;
comp->fd = fd;
comp->compression = compression;
@@ -101,54 +91,43 @@ rtems_rtl_obj_comp_set (rtems_rtl_obj_comp* comp,
comp->read = 0;
}
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) {
uint8_t* bin = buffer;
if (!comp->cache)
{
rtems_rtl_set_error (EINVAL, "not open");
if (!comp->cache) {
rtems_rtl_set_error(EINVAL, "not open");
return false;
}
if (rtems_rtl_trace (RTEMS_RTL_TRACE_COMP))
printf ("rtl: comp: %2d: fd=%d length=%zu level=%zu offset=%" PRIdoff_t " area=[%"
PRIdoff_t ",%" PRIdoff_t "] read=%" PRIu32 " size=%zu\n",
comp->fd, comp->cache->fd, length, comp->level, comp->offset,
comp->offset, comp->offset + length,
comp->read, comp->size);
if (rtems_rtl_trace(RTEMS_RTL_TRACE_COMP))
printf("rtl: comp: %2d: fd=%d length=%zu level=%zu offset=%" PRIdoff_t
" area=[%" PRIdoff_t ",%" PRIdoff_t "] read=%" PRIu32 " size=%zu\n",
comp->fd, comp->cache->fd, length, comp->level, comp->offset,
comp->offset, comp->offset + length, comp->read, comp->size);
if (comp->fd != comp->cache->fd)
{
if (comp->fd != comp->cache->fd) {
comp->level = 0;
}
while (length)
{
while (length) {
size_t buffer_level;
buffer_level = length > comp->level ? comp->level : length;
if (buffer_level)
{
if (rtems_rtl_trace (RTEMS_RTL_TRACE_COMP))
printf ("rtl: comp: copy: length=%zu\n",
buffer_level);
if (buffer_level) {
if (rtems_rtl_trace(RTEMS_RTL_TRACE_COMP))
printf("rtl: comp: copy: length=%zu\n", buffer_level);
memcpy (bin, comp->buffer, buffer_level);
memcpy(bin, comp->buffer, buffer_level);
if ((comp->level - buffer_level) != 0)
{
if (rtems_rtl_trace (RTEMS_RTL_TRACE_COMP))
printf ("rtl: comp: copy-down: level=%zu length=%zu\n",
comp->level, comp->level - buffer_level);
memmove (comp->buffer,
comp->buffer + buffer_level,
if ((comp->level - buffer_level) != 0) {
if (rtems_rtl_trace(RTEMS_RTL_TRACE_COMP))
printf("rtl: comp: copy-down: level=%zu length=%zu\n", comp->level,
comp->level - buffer_level);
memmove(comp->buffer, comp->buffer + buffer_level,
comp->level - buffer_level);
}
bin += buffer_level;
@@ -157,72 +136,68 @@ rtems_rtl_obj_comp_read (rtems_rtl_obj_comp* comp,
comp->read += buffer_level;
}
if (length)
{
if (length) {
uint8_t* input = NULL;
uint16_t block_size;
size_t in_length = sizeof (block_size);
int decompressed;
size_t in_length = sizeof(block_size);
int decompressed;
if (rtems_rtl_trace (RTEMS_RTL_TRACE_COMP))
printf ("rtl: comp: read block-size: offset=%" PRIdoff_t "\n",
comp->offset);
if (rtems_rtl_trace(RTEMS_RTL_TRACE_COMP))
printf("rtl: comp: read block-size: offset=%" PRIdoff_t "\n",
comp->offset);
if (!rtems_rtl_obj_cache_read (comp->cache, comp->fd, comp->offset,
(void**) &input, &in_length))
if (!rtems_rtl_obj_cache_read(comp->cache, comp->fd, comp->offset,
(void**)&input, &in_length))
return false;
block_size = (input[0] << 8) | input[1];
comp->offset += sizeof (block_size);
comp->offset += sizeof(block_size);
in_length = block_size;
if (rtems_rtl_trace (RTEMS_RTL_TRACE_COMP))
printf ("rtl: comp: read block: offset=%" PRIdoff_t " size=%u\n",
comp->offset, block_size);
if (rtems_rtl_trace(RTEMS_RTL_TRACE_COMP))
printf("rtl: comp: read block: offset=%" PRIdoff_t " size=%u\n",
comp->offset, block_size);
if (!rtems_rtl_obj_cache_read (comp->cache, comp->fd, comp->offset,
(void**) &input, &in_length))
if (!rtems_rtl_obj_cache_read(comp->cache, comp->fd, comp->offset,
(void**)&input, &in_length))
return false;
if (in_length != block_size)
{
rtems_rtl_set_error (EIO, "compressed read failed: bs=%u in=%zu",
block_size, in_length);
if (in_length != block_size) {
rtems_rtl_set_error(EIO, "compressed read failed: bs=%u in=%zu",
block_size, in_length);
return false;
}
switch (comp->compression)
{
case RTEMS_RTL_COMP_NONE:
memcpy (comp->buffer, input, in_length);
decompressed = in_length;
break;
switch (comp->compression) {
case RTEMS_RTL_COMP_NONE:
memcpy(comp->buffer, input, in_length);
decompressed = in_length;
break;
case RTEMS_RTL_COMP_LZ77:
decompressed = fastlz_decompress (input, in_length,
comp->buffer, comp->size);
if (decompressed == 0)
{
rtems_rtl_set_error (EBADF, "decompression failed");
return false;
}
break;
default:
rtems_rtl_set_error (EINVAL, "bad compression type");
case RTEMS_RTL_COMP_LZ77:
decompressed =
fastlz_decompress(input, in_length, comp->buffer, comp->size);
if (decompressed == 0) {
rtems_rtl_set_error(EBADF, "decompression failed");
return false;
}
break;
default:
rtems_rtl_set_error(EINVAL, "bad compression type");
return false;
}
comp->offset += block_size;
comp->level = decompressed;
if (rtems_rtl_trace (RTEMS_RTL_TRACE_COMP))
printf ("rtl: comp: expand: offset=%" PRIdoff_t \
" level=%zu read=%" PRIu32 "\n",
comp->offset, comp->level, comp->read);
if (rtems_rtl_trace(RTEMS_RTL_TRACE_COMP))
printf("rtl: comp: expand: offset=%" PRIdoff_t
" level=%zu read=%" PRIu32 "\n",
comp->offset, comp->level, comp->read);
}
}
+527 -796
View File
File diff suppressed because it is too large Load Diff
+354 -474
View File
File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More