RTEMS CPU Kit with SuperCore  4.11.3
Macros | Functions
rtl.c File Reference

RTEMS Run-Time Link Editor. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <rtems/libio_.h>
#include <rtems/rtl/rtl.h>
#include "rtl-allocator.h"
#include "rtl-error.h"
#include "rtl-string.h"
#include "rtl-trace.h"
Include dependency graph for rtl.c:

Macros

#define RTEMS_MUTEX_ATTRIBS
 Semaphore configuration to create a mutex. More...
 
#define RTEMS_RTL_ELF_SYMBOL_CACHE   (2048)
 Symbol table cache size. More...
 
#define RTEMS_RTL_ELF_STRING_CACHE   (2048)
 String table cache size.
 
#define RTEMS_RTL_ELF_RELOC_CACHE   (2048)
 Relocations table cache size.
 
#define RTEMS_RTL_COMP_OUTPUT   (2048)
 Decompression output buffer.
 

Functions

void rtems_rtl_base_global_syms_init (void)
 Define a default base global symbol loader function that is weak so a real table can be linked in when the user wants one.
 
rtems_rtl_data_trtems_rtl_data (void)
 Get the RTL data with out locking. More...
 
rtems_rtl_symbols_trtems_rtl_global_symbols (void)
 Get the RTL global symbol table with out locking. More...
 
rtems_rtl_unresolved_trtems_rtl_unresolved (void)
 Get the RTL resolved table with out locking. More...
 
void rtems_rtl_obj_caches (rtems_rtl_obj_cache_t **symbols, rtems_rtl_obj_cache_t **strings, rtems_rtl_obj_cache_t **relocs)
 Get the RTL symbols, strings, or relocations object file caches. More...
 
void rtems_rtl_obj_caches_flush (void)
 Flush all the object file caches.
 
void rtems_rtl_obj_comp (rtems_rtl_obj_comp_t **decomp, rtems_rtl_obj_cache_t *cache, int fd, int compression, off_t offset)
 Get the RTL decompressor setting the cache and the offset in the file the compressed stream starts. More...
 
rtems_rtl_data_trtems_rtl_lock (void)
 Lock the Run-time Linker. More...
 
bool rtems_rtl_unlock (void)
 Unlock the Run-time Linker. More...
 
rtems_rtl_obj_trtems_rtl_check_handle (void *handle)
 Check a pointer is a valid object file descriptor returning the pointer as that type. More...
 
rtems_rtl_obj_trtems_rtl_find_obj (const char *name)
 Find the object given a file name. More...
 
rtems_rtl_obj_trtems_rtl_load_object (const char *name, int mode)
 Load an object file into memory relocating it. More...
 
bool rtems_rtl_unload_object (rtems_rtl_obj_t *obj)
 Unload an object file. More...
 
void rtems_rtl_run_ctors (rtems_rtl_obj_t *obj)
 Run any constructor functions the object file may contain. More...
 
bool rtems_rtl_path_append (const char *path)
 Append the path to the search path. More...
 
bool rtems_rtl_path_prepend (const char *path)
 Prepend the path to the search path. More...
 
void rtems_rtl_base_sym_global_add (const unsigned char *esyms, unsigned int size)
 Add an exported symbol table to the global symbol table. More...
 
rtems_rtl_obj_trtems_rtl_baseimage (void)
 Return the object file descriptor for the base image. More...
 

Detailed Description

RTEMS Run-Time Link Editor.

This is the RTL implementation.

Macro Definition Documentation

◆ RTEMS_MUTEX_ATTRIBS

#define RTEMS_MUTEX_ATTRIBS
Value:
RTEMS_INHERIT_PRIORITY | RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL)
#define RTEMS_BINARY_SEMAPHORE
This attribute constant indicates that the Classic API Semaphore instance created will be a proper bi...
Definition: attr.h:106
#define RTEMS_PRIORITY
This is the attribute constant which reflects that blocking tasks will be managed using task priority...
Definition: attr.h:70
#define RTEMS_NO_PRIORITY_CEILING
This attribute constant indicates that the Classic API Semaphore instance created will NOT use the Pr...
Definition: attr.h:132
#define RTEMS_LOCAL
This is the attribute constant to indicate local resource.
Definition: attr.h:53

Semaphore configuration to create a mutex.

◆ RTEMS_RTL_ELF_SYMBOL_CACHE

#define RTEMS_RTL_ELF_SYMBOL_CACHE   (2048)

Symbol table cache size.

They can be big so the cache needs space to work.

Function Documentation

◆ rtems_rtl_base_sym_global_add()

void rtems_rtl_base_sym_global_add ( const unsigned char *  esyms,
unsigned int  count 
)

Add an exported symbol table to the global symbol table.

This call is normally used by an object file when loaded that contains a global symbol table.

Parameters
esymsThe exported symbol table.
countThe size of the exported symbol table.

◆ rtems_rtl_baseimage()

rtems_rtl_obj_t* rtems_rtl_baseimage ( void  )

Return the object file descriptor for the base image.

The object file descriptor returned is created when the run time linker is initialised.

Assumes the RTL has been locked.

Returns
rtl_obj* The object file descriptor for the base image. NULL is returned if the load fails.

◆ rtems_rtl_check_handle()

rtems_rtl_obj_t* rtems_rtl_check_handle ( void *  handle)

Check a pointer is a valid object file descriptor returning the pointer as that type.

Assumes the RTL has been locked.

Parameters
handlePointer to the object file to be validated.
Returns
rtl_obj* The object file descriptor. NULL is returned if invalid.

References rtems_rtl_data_s::objects, rtems_chain_first(), and rtems_chain_is_tail().

◆ rtems_rtl_data()

rtems_rtl_data_t* rtems_rtl_data ( void  )

Get the RTL data with out locking.

This call assumes the RTL is locked.

Returns
rtems_rtl_data_t* The RTL data after being locked.
Return values
NULLThe RTL data is not initialised.

◆ rtems_rtl_find_obj()

rtems_rtl_obj_t* rtems_rtl_find_obj ( const char *  name)

Find the object given a file name.

Parameters
nameThe name of the object file.
Return values
NULLNo object file with that name found.
Returns
rtems_rtl_obj_t* The object file descriptor.

References rtems_rtl_data_s::objects, rtems_chain_first(), rtems_chain_is_tail(), and rtems_rtl_parse_name().

◆ rtems_rtl_global_symbols()

rtems_rtl_symbols_t* rtems_rtl_global_symbols ( void  )

Get the RTL global symbol table with out locking.

This call assmes the RTL is locked.

Returns
rtems_rtl_symbols_t* The RTL global symbols after being locked.
Return values
NULLThe RTL data is not initialised.

References rtems_rtl_data_s::globals, and rtems_rtl_set_error().

Referenced by rtems_rtl_symbol_global_find().

◆ rtems_rtl_load_object()

rtems_rtl_obj_t* rtems_rtl_load_object ( const char *  name,
int  mode 
)

Load an object file into memory relocating it.

It will not be resolved against other symbols in other object files or the base image.

The name can be a file name for an object file or it can be encoded to reference an archive of object modules (static library). This encoding is specific to RTEMS and allows dependences to specify an archive without the searching overhead normally incurred by linkers locating object files in an archive. The file name format rules are:

  1. Absolute file references a specific object file in the architecture specific location on the file system.
  2. Relative file references an object format file in the search path.
  3. Absolute archive and file reference to a specific location in the file system. The archive and file are encoded as 'archive:file [@offset]' where 'archive' is a valid file at the absolute path in the file system, and 'file' is a contained in the archive, and optionally an offset to the 'file' in the 'archive'. If no offset is provided the archive is searched.
  4. Relative archive and file in the search path. The encoding is the same as described in item 3 of this list.

Assumes the RTL has been locked.

Parameters
nameThe name of the object file.
modeThe mode of the load as defined by the dlopen call.
Returns
rtl_obj* The object file descriptor. NULL is returned if the load fails.

References rtems_rtl_trace().

◆ rtems_rtl_lock()

rtems_rtl_data_t* rtems_rtl_lock ( void  )

Lock the Run-time Linker.

Returns
rtems_rtl_data_t* The RTL data after being locked.
Return values
NULLThe RTL data could not be initialised or locked. Typically this means the lock could not be created.

◆ rtems_rtl_obj_caches()

void rtems_rtl_obj_caches ( rtems_rtl_obj_cache_t **  symbols,
rtems_rtl_obj_cache_t **  strings,
rtems_rtl_obj_cache_t **  relocs 
)

Get the RTL symbols, strings, or relocations object file caches.

This call assmes the RTL is locked.

Parameters
symbolsPointer to the location to set the cache into. Returns NULL is rtl is not initialised. If NULL is passed in no value set.
stringsPointer to the location to set the cache into. Returns NULL is rtl is not initialised. If NULL is passed in no value set.
relocsPointer to the location to set the cache into. Returns NULL is rtl is not initialised. If NULL is passed in no value set.

References rtems_rtl_data_s::relocs, rtems_rtl_data_s::strings, and rtems_rtl_data_s::symbols.

Referenced by rtems_rtl_elf_file_check(), rtems_rtl_elf_file_load(), and rtems_rtl_rap_file_load().

◆ rtems_rtl_obj_comp()

void rtems_rtl_obj_comp ( rtems_rtl_obj_comp_t **  decomp,
rtems_rtl_obj_cache_t cache,
int  fd,
int  compression,
off_t  offset 
)

Get the RTL decompressor setting the cache and the offset in the file the compressed stream starts.

This call assmes the RTL is locked.

Parameters
decompPointer to the location to set the compressor into. Returns NULL is rtl is not initialised.
cacheThe cache to read the file with. Saves needing an extrs buffer.
offsetThe offset in the file the compressed stream starts.

References rtems_rtl_data_s::decomp, and rtems_rtl_obj_comp_set().

◆ rtems_rtl_path_append()

bool rtems_rtl_path_append ( const char *  path)

Append the path to the search path.

Parameters
pathThe path to append.
Return values
falseThe path could not be appended.
trueThe path was appended.

◆ rtems_rtl_path_prepend()

bool rtems_rtl_path_prepend ( const char *  path)

Prepend the path to the search path.

Parameters
pathThe path to prepend.
Return values
falseThe path could not be prepended.
trueThe path was prepended.

◆ rtems_rtl_run_ctors()

void rtems_rtl_run_ctors ( rtems_rtl_obj_t obj)

Run any constructor functions the object file may contain.

This call assumes the linker is unlocked.

Parameters
objThe object file.

References rtems_rtl_obj_run_ctors().

◆ rtems_rtl_unload_object()

bool rtems_rtl_unload_object ( rtems_rtl_obj_t obj)

Unload an object file.

This only happens when the user count is 0.

Assumes the RTL has been locked.

Parameters
objThe object file descriptor.
Return values
trueThe object file has been unloaded.
falseThe object file could not be unloaded.

References rtems_rtl_trace().

◆ rtems_rtl_unlock()

bool rtems_rtl_unlock ( void  )

Unlock the Run-time Linker.

Returns
True The RTL is unlocked.
False The RTL could not be unlocked. Not much you can do.

References rtems_rtl_data_s::lock, rtems_semaphore_release(), and RTEMS_SUCCESSFUL.

◆ rtems_rtl_unresolved()

rtems_rtl_unresolved_t* rtems_rtl_unresolved ( void  )

Get the RTL resolved table with out locking.

This call assmes the RTL is locked.

Returns
rtems_rtl_unresolv_t* The RTL unresolved symbols and reloc records.
Return values
NULLThe RTL data is not initialised.

References rtems_rtl_set_error(), and rtems_rtl_data_s::unresolved.

Referenced by rtems_rtl_unresolved_interate(), and rtems_rtl_unresolved_remove().