Changeset d2e31f7 in rtems


Ignore:
Timestamp:
Mar 28, 2017, 6:23:05 AM (2 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
4.11
Children:
09cbe71
Parents:
d51538bd
git-author:
Chris Johns <chrisj@…> (03/28/17 06:23:05)
git-committer:
Chris Johns <chrisj@…> (04/04/17 03:26:01)
Message:

libdl: Back port C++ exception throw and catch from 4.12.

Closes #2956.

Files:
25 added
37 edited

Legend:

Unmodified
Added
Removed
  • cpukit/Makefile.am

    rd51538bd rd2e31f7  
    9191include_rtems_rtl_HEADERS += libdl/rtl-fwd.h libdl/rtl-obj.h libdl/rtl-obj-cache.h
    9292include_rtems_rtl_HEADERS += libdl/rtl-obj-comp.h libdl/rtl-unresolved.h
    93 include_rtems_rtl_HEADERS += libdl/rtl-indirect-ptr.h libdl/rtl-sym.h
     93include_rtems_rtl_HEADERS += libdl/rtl-indirect-ptr.h libdl/rtl-sym.h libdl/rtl-trace.h
    9494include_rtems_rtl_HEADERS += libdl/rap.h libdl/rap-shell.h
    9595endif
  • cpukit/libdl/Makefile.am

    rd51538bd rd2e31f7  
    2626  rtl-sym.c \
    2727  rtl-trace.c \
     28  rtl-unwind-dw2.c \
    2829  rtl-unresolved.c
    2930
  • cpukit/libdl/dlfcn.c

    rd51538bd rd2e31f7  
    131131  static char msg[64];
    132132  rtems_rtl_get_error (msg, sizeof (msg));
    133         return msg;
     133  return msg;
    134134}
    135135
  • cpukit/libdl/include/arch/arm/machine/elf_machdep.h

    rd51538bd rd2e31f7  
    8181#define R_ARM_ALU_SBREL_27_20   37
    8282#define R_ARM_V4BX        40
    83 #define R_ARM_PREL31      41
     83#define R_ARM_TARGET2     41
     84#define R_ARM_PREL31      42
    8485
    8586#define R_ARM_MOVW_ABS_NC     43
  • cpukit/libdl/include/sys/exec_elf.h

    rd51538bd rd2e31f7  
    460460#define SHF_ALLOC       0x2             /* Section occupies memory */
    461461#define SHF_EXECINSTR   0x4             /* Section contains executable insns */
     462#define SHF_MERGE       0x10            /* Section contains data that can be merged */
     463#define SHF_STRINGS     0x20            /* Section contains null-terminated strings */
     464#define SHF_INFO_LINK   0x40            /* Section header's sh_info holds table index */
     465#define SHF_LINK_ORDER  0x80            /* Section has special ordering requirements */
    462466
    463467#define SHF_MASKOS      0x0f000000      /* Operating system specific values */
     
    950954
    951955/*
    952  * These constants are used for Elf32_Verdef struct's version number. 
     956 * These constants are used for Elf32_Verdef struct's version number.
    953957 */
    954958#define VER_DEF_NONE            0
     
    956960
    957961/*
    958  * These constants are used for Elf32_Verdef struct's vd_flags. 
     962 * These constants are used for Elf32_Verdef struct's vd_flags.
    959963 */
    960964#define VER_FLG_BASE            0x1
     
    968972
    969973/*
    970  * These constants are used for Elf32_Verneed struct's version number. 
     974 * These constants are used for Elf32_Verneed struct's version number.
    971975 */
    972976#define VER_NEED_NONE           0
  • cpukit/libdl/rap.c

    rd51538bd rd2e31f7  
    2020#endif
    2121
     22#include <stdarg.h>
    2223#include <stdlib.h>
    2324#include <stdio.h>
  • cpukit/libdl/rtl-allocator.c

    rd51538bd rd2e31f7  
    153153rtems_rtl_alloc_module_new (void** text_base, size_t text_size,
    154154                            void** const_base, size_t const_size,
     155                            void** eh_base, size_t eh_size,
    155156                            void** data_base, size_t data_size,
    156157                            void** bss_base, size_t bss_size)
     
    174175    if (!*const_base)
    175176    {
    176       rtems_rtl_alloc_module_del (text_base, const_base, data_base, bss_base);
     177      rtems_rtl_alloc_module_del (text_base, const_base, eh_base,
     178                                  data_base, bss_base);
     179      return false;
     180    }
     181  }
     182
     183  if (eh_size)
     184  {
     185    *eh_base = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_READ,
     186                                    eh_size, false);
     187    if (!*eh_base)
     188    {
     189      rtems_rtl_alloc_module_del (text_base, const_base, eh_base,
     190                                  data_base, bss_base);
    177191      return false;
    178192    }
     
    185199    if (!*data_base)
    186200    {
    187       rtems_rtl_alloc_module_del (text_base, const_base, data_base, bss_base);
     201      rtems_rtl_alloc_module_del (text_base, const_base, eh_base,
     202                                  data_base, bss_base);
    188203      return false;
    189204    }
     
    196211    if (!*bss_base)
    197212    {
    198       rtems_rtl_alloc_module_del (text_base, const_base, data_base, bss_base);
     213      rtems_rtl_alloc_module_del (text_base, const_base, eh_base,
     214                                  data_base, bss_base);
    199215      return false;
    200216    }
     
    207223rtems_rtl_alloc_module_del (void** text_base,
    208224                            void** const_base,
     225                            void** eh_base,
    209226                            void** data_base,
    210227                            void** bss_base)
     
    212229  rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_READ_WRITE, *bss_base);
    213230  rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_READ_WRITE, *data_base);
     231  rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_READ, *eh_base);
    214232  rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_READ, *const_base);
    215233  rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_READ_EXEC, *text_base);
    216   *text_base = *const_base = *data_base = *bss_base = NULL;
    217 }
     234  *text_base = *const_base = *eh_base = *data_base = *bss_base = NULL;
     235}
  • cpukit/libdl/rtl-allocator.h

    rd51538bd rd2e31f7  
    147147 * @param const_base Pointer to the const base pointer.
    148148 * @param const_size The size of the read only section.
     149 * @param eh_base Pointer to the eh base pointer.
     150 * @param eh_size The size of the eh section.
    149151 * @param data_base Pointer to the data base pointer.
    150152 * @param data_size The size of the read/write secton.
     
    156158bool rtems_rtl_alloc_module_new (void** text_base, size_t text_size,
    157159                                 void** const_base, size_t const_size,
     160                                 void** eh_base, size_t eh_size,
    158161                                 void** data_base, size_t data_size,
    159162                                 void** bss_base, size_t bss_size);
     
    164167 * @param text_base Pointer to the text base pointer.
    165168 * @param const_base Pointer to the const base pointer.
     169 * @param eh_base Pointer to the eh base pointer.
    166170 * @param data_base Pointer to the data base pointer.
    167171 * @param bss_base Pointer to the bss base pointer.
    168172 */
    169173void rtems_rtl_alloc_module_del (void** text_base, void** const_base,
    170                                  void** data_base, void** bss_base);
     174                                 void** eh_base, void** data_base,
     175                                 void** bss_base);
    171176
    172177#ifdef __cplusplus
  • cpukit/libdl/rtl-debugger.c

    rd51538bd rd2e31f7  
    4646_rtld_linkmap_add (rtems_rtl_obj_t* obj)
    4747{
    48   struct link_map* l = (struct link_map*)obj->detail;
     48  struct link_map* l = obj->linkmap;
    4949  struct link_map* prev;
    50   uint32_t obj_num = obj->obj_num;
    51   int i;
     50  uint32_t         obj_num = obj->obj_num;
     51  int              i;
    5252
    5353  if (rtems_rtl_trace (RTEMS_RTL_TRACE_DETAIL))
     
    7979_rtld_linkmap_delete (rtems_rtl_obj_t* obj)
    8080{
    81   struct link_map* l = (struct link_map*)obj->detail;
    82   /* link_maps are allocated together if not 1 */
     81  struct link_map* l = obj->linkmap;
     82  /*
     83   *  link_maps are allocated together if not 1
     84   */
    8385  struct link_map* e = l + obj->obj_num - 1;
    8486
     
    9193    return;
    9294  }
     95
    9396  if ((l->l_prev->l_next = e->l_next) != NULL)
    9497    e->l_next->l_prev = l->l_prev;
    95   return;
    9698}
  • cpukit/libdl/rtl-elf.c

    rd51538bd rd2e31f7  
    3131#include "rtl-error.h"
    3232#include "rtl-trace.h"
     33#include "rtl-unwind.h"
    3334#include "rtl-unresolved.h"
    3435
     
    170171      return false;
    171172
     173    /*
     174     * Read the symbol details.
     175     */
    172176    if (is_rela)
    173177      off = (obj->ooffset + symsect->offset +
     
    247251      {
    248252        if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
    249           printf ("rtl: rela: sym:%s(%-2d)=%08lx type:%-2d off:%08lx addend:%d\n",
     253          printf ("rtl: rela: sym:%s(%d)=%08lx type:%d off:%08lx addend:%d\n",
    250254                  symname, (int) ELF_R_SYM (rela->r_info), symvalue,
    251255                  (int) ELF_R_TYPE (rela->r_info), rela->r_offset, (int) rela->r_addend);
     
    257261      {
    258262        if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
    259           printf ("rtl: rel: sym:%s(%-2d)=%08lx type:%-2d off:%08lx\n",
     263          printf ("rtl: rel: sym:%s(%d)=%08lx type:%d off:%08lx\n",
    260264                  symname, (int) ELF_R_SYM (rel->r_info), symvalue,
    261265                  (int) ELF_R_TYPE (rel->r_info), rel->r_offset);
     
    301305    rela.r_addend = reloc->rel[REL_R_ADDEND];
    302306    if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
    303           printf ("rtl: rela: sym:%-2d type:%-2d off:%08lx addend:%d\n",
     307          printf ("rtl: rela: sym:%d type:%d off:%08lx addend:%d\n",
    304308                  (int) ELF_R_SYM (rela.r_info), (int) ELF_R_TYPE (rela.r_info),
    305309                  rela.r_offset, (int) rela.r_addend);
     
    314318    rel.r_info = reloc->rel[REL_R_INFO];
    315319    if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
    316       printf ("rtl: rel: sym:%-2d type:%-2d off:%08lx\n",
     320      printf ("rtl: rel: sym:%d type:%d off:%08lx\n",
    317321              (int) ELF_R_SYM (rel.r_info), (int) ELF_R_TYPE (rel.r_info),
    318322              rel.r_offset);
     
    653657    flags = 0;
    654658
     659    if (rtems_rtl_trace (RTEMS_RTL_TRACE_DETAIL))
     660      printf ("rtl: section: %2d: type=%d flags=%08x link=%d info=%d\n",
     661              section, (int) shdr.sh_type, (unsigned int) shdr.sh_flags,
     662              (int) shdr.sh_link, (int) shdr.sh_info);
     663
    655664    switch (shdr.sh_type)
    656665    {
     
    708717
    709718      default:
    710         if (rtems_rtl_trace (RTEMS_RTL_TRACE_WARNING))
    711           printf ("rtl: unsupported section: %2d: type=%02d flags=%02x\n",
    712                   section, (int) shdr.sh_type, (int) shdr.sh_flags);
     719        /*
     720         * See if there are architecture specific flags?
     721         */
     722        flags = rtems_rtl_elf_section_flags (obj, &shdr);
     723        if (flags == 0)
     724        {
     725          if (rtems_rtl_trace (RTEMS_RTL_TRACE_WARNING))
     726            printf ("rtl: unsupported section: %2d: type=%02d flags=%02x\n",
     727                    section, (int) shdr.sh_type, (int) shdr.sh_flags);
     728        }
    713729        break;
    714730    }
     
    718734      char*  name;
    719735      size_t len;
     736
     737      /*
     738       * If link ordering this section must appear in the same order in memory
     739       * as the linked-to section relative to the sections it loads with.
     740       */
     741      if ((shdr.sh_flags & SHF_LINK_ORDER) != 0)
     742        flags |= RTEMS_RTL_OBJ_SECT_LINK;
    720743
    721744      len = RTEMS_RTL_ELF_STRING_MAX;
     
    730753        flags |= RTEMS_RTL_OBJ_SECT_DTOR;
    731754
     755      if (rtems_rtl_elf_unwind_parse (obj, name, flags))
     756      {
     757        flags &= ~(RTEMS_RTL_OBJ_SECT_TEXT | RTEMS_RTL_OBJ_SECT_CONST);
     758        flags |= RTEMS_RTL_OBJ_SECT_EH;
     759      }
     760
    732761      if (!rtems_rtl_obj_add_section (obj, section, name,
    733762                                      shdr.sh_size, shdr.sh_offset,
     
    772801}
    773802
    774 bool rtems_rtl_elf_load_details (rtems_rtl_obj_t* obj)
     803static bool
     804rtems_rtl_elf_load_linkmap (rtems_rtl_obj_t* obj)
    775805{
    776806  rtems_chain_control* sections = NULL;
    777807  rtems_chain_node*    node = NULL;
    778808  size_t               mask = 0;
    779   struct link_map*     l = NULL;
    780809  int                  sec_num = 0;
     810  section_detail*      sd;
    781811  int                  i = 0;
    782812
    783   /* caculate the size of sections' name. */
     813  /*
     814   * Caculate the size of sections' name.
     815   */
    784816
    785817  for (mask = RTEMS_RTL_OBJ_SECT_TEXT;
     
    792824    {
    793825      rtems_rtl_obj_sect_t* sect = (rtems_rtl_obj_sect_t*) node;
    794 
    795826      if ((sect->size != 0) && ((sect->flags & mask) != 0))
    796827      {
     
    802833
    803834  obj->obj_num = 1;
    804   obj->detail = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT,
    805                                      sizeof(struct link_map) +
    806                                      sec_num * sizeof (section_detail), true);
    807   if (!obj->detail)
    808   {
    809     rtems_rtl_set_error (ENOMEM, "no memory for obj global syms");
    810     return false;
    811   }
    812 
    813   l = (struct link_map*) obj->detail;
    814   l->name = obj->oname;
    815   l->sec_num = sec_num;
    816   l->sec_detail = (section_detail*) (l + 1);
    817   l->rpathlen = 0;
    818   l->rpath = NULL;
    819   l->l_next = NULL;
    820   l->l_prev = NULL;
    821   l->sec_addr[rap_text] = obj->text_base;
    822   l->sec_addr[rap_const] = obj->const_base;
    823   l->sec_addr[rap_data] = obj->data_base;
    824   l->sec_addr[rap_bss] = obj->bss_base;
    825 
    826 
    827   section_detail* sd = l->sec_detail;
     835  obj->linkmap = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT,
     836                                      sizeof(struct link_map) +
     837                                      sec_num * sizeof (section_detail), true);
     838  if (!obj->linkmap)
     839  {
     840    rtems_rtl_set_error (ENOMEM, "no memory for obj linkmap");
     841    return false;
     842  }
     843
     844  obj->linkmap->name = obj->oname;
     845  obj->linkmap->sec_num = sec_num;
     846  obj->linkmap->sec_detail = (section_detail*) (obj->linkmap + 1);
     847  obj->linkmap->rpathlen = 0;
     848  obj->linkmap->rpath = NULL;
     849  obj->linkmap->l_next = NULL;
     850  obj->linkmap->l_prev = NULL;
     851  obj->linkmap->sec_addr[rap_text] = obj->text_base;
     852  obj->linkmap->sec_addr[rap_const] = obj->const_base;
     853  obj->linkmap->sec_addr[rap_data] = obj->data_base;
     854  obj->linkmap->sec_addr[rap_bss] = obj->bss_base;
     855
     856  sd = obj->linkmap->sec_detail;
    828857  sections = &obj->sections;
    829858  node = rtems_chain_first (sections);
     859
    830860  for (mask = RTEMS_RTL_OBJ_SECT_TEXT;
    831861       mask <= RTEMS_RTL_OBJ_SECT_BSS;
     
    949979  rtems_rtl_symbol_obj_erase_local (obj);
    950980
    951   if (!rtems_rtl_elf_load_details (obj))
    952   {
    953     return false;
    954   }
    955 
     981  if (!rtems_rtl_elf_load_linkmap (obj))
     982  {
     983    return false;
     984  }
     985
     986  if (!rtems_rtl_elf_unwind_register (obj))
     987  {
     988    return false;
     989  }
     990
     991  return true;
     992}
     993
     994bool
     995rtems_rtl_elf_file_unload (rtems_rtl_obj_t* obj)
     996{
     997  rtems_rtl_elf_unwind_deregister (obj);
    956998  return true;
    957999}
  • cpukit/libdl/rtl-elf.h

    rd51538bd rd2e31f7  
    5454 */
    5555#define RTEMS_RTL_ELF_STRING_MAX (256)
     56
     57/**
     58 * Architecture specific handler to translate unknown section flags to RTL
     59 * section flags.
     60 *
     61 * @param obj The object file being relocated.
     62 * @param shdr The ELF section header.
     63 * @retval 0 Unknown or unsupported flags.
     64 * @retval uint32_t RTL object file flags.
     65 */
     66uint32_t rtems_rtl_elf_section_flags (const rtems_rtl_obj_t* obj,
     67                                      const Elf_Shdr*        shdr);
    5668
    5769/**
     
    138150
    139151/**
    140  * The ELF file details handler.
    141  *
    142  * @param obj Load the details of the obj.
    143  */
    144 bool rtems_rtl_elf_load_details (rtems_rtl_obj_t* obj);
    145 
    146 /**
    147152 * The ELF format load handler.
    148153 *
     
    151156 */
    152157bool rtems_rtl_elf_file_load (rtems_rtl_obj_t* obj, int fd);
     158
     159/**
     160 * The ELF format unload handler.
     161 *
     162 * @param obj The object to unload.
     163 */
     164bool rtems_rtl_elf_file_unload (rtems_rtl_obj_t* obj);
    153165
    154166/**
  • cpukit/libdl/rtl-error.c

    rd51538bd rd2e31f7  
    1818#endif
    1919
     20#include <errno.h>
    2021#include <stdio.h>
    2122#include <stdarg.h>
     
    4041{
    4142  rtems_rtl_data_t* rtl = rtems_rtl_lock ();
    42   int               last_errno = rtl->last_errno;
    43   strncpy (message, rtl->last_error, sizeof (rtl->last_error));
    44   rtems_rtl_unlock ();
    45   return last_errno;
     43  if (rtl != NULL)
     44  {
     45    int last_errno = rtl->last_errno;
     46    strncpy (message, rtl->last_error, sizeof (rtl->last_error));
     47    rtems_rtl_unlock ();
     48    return last_errno;
     49  }
     50
     51  strncpy(message, "RTL init error", max_message);
     52
     53  return EIO;
    4654}
    47 
  • cpukit/libdl/rtl-mdreloc-arm.c

    rd51538bd rd2e31f7  
    1111#include <sys/types.h>
    1212#include <sys/stat.h>
     13#include <unwind.h>
     14#include <unwind-arm-common.h>
    1315
    1416#include <rtems/rtl/rtl.h>
     
    1618#include "rtl-error.h"
    1719#include "rtl-trace.h"
     20#include "rtl-unwind.h"
    1821
    1922/*
     
    2427        (((uintptr_t)(x) & (sizeof(void *) - 1)) == 0)
    2528
     29#define SHT_ARM_EXIDX  0x70000001 /* Section holds ARM unwind info. */
     30
    2631static inline Elf_Addr
    2732load_ptr(void *where)
     
    5358}
    5459
     60static inline Elf_SOff
     61sign_extend31(Elf_Addr val)
     62{
     63  if (0x40000000 & val)
     64    val =  ~((Elf_Addr)0x7fffffff) | (0x7fffffff & val);
     65  return 0x7fffffff & val;
     66}
     67
     68uint32_t
     69rtems_rtl_elf_section_flags (const rtems_rtl_obj_t* obj,
     70                             const Elf_Shdr*        shdr)
     71{
     72  uint32_t flags = 0;
     73  if (shdr->sh_type == SHT_ARM_EXIDX)
     74    flags = RTEMS_RTL_OBJ_SECT_EH | RTEMS_RTL_OBJ_SECT_LOAD;
     75  return flags;
     76}
     77
    5578bool
    5679rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
     
    88111
    89112  switch (ELF_R_TYPE(rel->r_info)) {
    90                 case R_TYPE(NONE):
    91                         break;
     113    case R_TYPE(NONE):
     114      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) {
     115        printf ("rtl: NONE %p in %s\n", where, rtems_rtl_obj_oname (obj));
     116      }
     117      break;
    92118
    93119    case R_TYPE(CALL):    /* BL/BLX */
     
    166192    case R_TYPE(ABS32):     /* word32 (S + A) | T */
    167193    case R_TYPE(GLOB_DAT):  /* word32 (S + A) | T */
     194    case R_TYPE(PREL31):    /* word32 (S + A) | T - P */
     195    case R_TYPE(TARGET2):   /* Equivalent to REL32 */
    168196      if (__predict_true(RELOC_ALIGNED_P(where))) {
    169197        tmp = *where + symvalue;
    170198        if (isThumb(symvalue))
    171199          tmp |= 1;
    172         if (ELF_R_TYPE(rel->r_info) == R_TYPE(REL32))
     200        if (ELF_R_TYPE(rel->r_info) == R_TYPE(REL32) ||
     201            ELF_R_TYPE(rel->r_info) == R_TYPE(TARGET2))
    173202          tmp -= (Elf_Addr)where;
     203        else if (ELF_R_TYPE(rel->r_info) == R_TYPE(PREL31))
     204          tmp = sign_extend31(tmp - (Elf_Addr)where);
    174205        *where = tmp;
    175206      } else {
     
    177208        if (isThumb(symvalue))
    178209          tmp |= 1;
    179         if (ELF_R_TYPE(rel->r_info) == R_TYPE(REL32))
     210        if (ELF_R_TYPE(rel->r_info) == R_TYPE(REL32) ||
     211            ELF_R_TYPE(rel->r_info) == R_TYPE(TARGET2))
    180212          tmp -= (Elf_Addr)where;
     213        else if (ELF_R_TYPE(rel->r_info) == R_TYPE(PREL31))
     214          tmp = sign_extend31(tmp - (Elf_Addr)where);
    181215        store_ptr(where, tmp);
    182216      }
    183217
    184218      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
    185         printf ("rtl: REL32/ABS32/GLOB_DAT %p @ %p in %s",
     219        printf ("rtl: REL32/ABS32/GLOB_DAT/PREL31/TARGET2 %p @ %p in %s\n",
    186220                (void *)tmp, where, rtems_rtl_obj_oname (obj));
    187221      break;
     
    307341      break;
    308342
    309                 default:
     343    default:
    310344      printf ("rtl: reloc unknown: sym = %lu, type = %lu, offset = %p, "
    311345              "contents = %p\n",
     
    316350                           "in non-PLT relocations",
    317351                           sect->name, (uint32_t) ELF_R_TYPE(rel->r_info));
    318                         return false;
     352      return false;
    319353  }
    320354
    321         return true;
    322 }
    323 
     355  return true;
     356}
     357
     358bool
     359rtems_rtl_elf_unwind_parse (const rtems_rtl_obj_t* obj,
     360                            const char*            name,
     361                            uint32_t               flags)
     362{
     363  /*
     364   * We location the EH sections in section flags.
     365   */
     366  return false;
     367}
     368
     369bool
     370rtems_rtl_elf_unwind_register (rtems_rtl_obj_t* obj)
     371{
     372  return true;
     373}
     374
     375bool
     376rtems_rtl_elf_unwind_deregister (rtems_rtl_obj_t* obj)
     377{
     378  obj->loader = NULL;
     379  return true;
     380}
     381
     382/* An exception index table entry.  */
     383typedef struct __EIT_entry
     384{
     385  _uw fnoffset;
     386  _uw content;
     387} __EIT_entry;
     388
     389/* The exception index table location in the base module */
     390extern __EIT_entry __exidx_start;
     391extern __EIT_entry __exidx_end;
     392
     393/*
     394 * A weak reference is in libgcc, provide a real version and provide a way to
     395 * manage loaded modules.
     396 *
     397 * Passed in the return address and a reference to the number of records
     398 * found. We set the start of the exidx data and the number of records.
     399 */
     400_Unwind_Ptr __gnu_Unwind_Find_exidx (_Unwind_Ptr return_address,
     401                                     int*        nrec) __attribute__ ((__noinline__,
     402                                                                       __used__,
     403                                                                       __noclone__));
     404
     405_Unwind_Ptr __gnu_Unwind_Find_exidx (_Unwind_Ptr return_address,
     406                                     int*        nrec)
     407{
     408  rtems_rtl_data_t* rtl;
     409  rtems_chain_node* node;
     410  __EIT_entry*      exidx_start = &__exidx_start;
     411  __EIT_entry*      exidx_end = &__exidx_end;
     412
     413  rtl = rtems_rtl_lock ();
     414
     415  node = rtems_chain_first (&rtl->objects);
     416  while (!rtems_chain_is_tail (&rtl->objects, node)) {
     417    rtems_rtl_obj_t* obj = (rtems_rtl_obj_t*) node;
     418    if (rtems_rtl_obj_text_inside (obj, (void*) return_address)) {
     419      exidx_start = (__EIT_entry*) obj->eh_base;
     420      exidx_end = (__EIT_entry*) (obj->eh_base + obj->eh_size);
     421      break;
     422    }
     423    node = rtems_chain_next (node);
     424  }
     425
     426  rtems_rtl_unlock ();
     427
     428  *nrec = exidx_end - exidx_start;
     429
     430  return (_Unwind_Ptr) exidx_start;
     431}
  • cpukit/libdl/rtl-mdreloc-bfin.c

    rd51538bd rd2e31f7  
    77#include "rtl-error.h"
    88#include "rtl-trace.h"
     9#include "rtl-unwind.h"
     10#include "rtl-unwind-dw2.h"
     11
     12uint32_t
     13rtems_rtl_elf_section_flags (const rtems_rtl_obj_t* obj,
     14                             const Elf_Shdr*        shdr)
     15{
     16  return 0;
     17}
    918
    1019bool
     
    114123  return false;
    115124}
     125
     126bool
     127rtems_rtl_elf_unwind_parse (const rtems_rtl_obj_t* obj,
     128                            const char*            name,
     129                            uint32_t               flags)
     130{
     131  return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags);
     132}
     133
     134bool
     135rtems_rtl_elf_unwind_register (rtems_rtl_obj_t* obj)
     136{
     137  return rtems_rtl_elf_unwind_dw2_register (obj);
     138}
     139
     140bool
     141rtems_rtl_elf_unwind_deregister (rtems_rtl_obj_t* obj)
     142{
     143  return rtems_rtl_elf_unwind_dw2_deregister (obj);
     144}
  • cpukit/libdl/rtl-mdreloc-h8300.c

    rd51538bd rd2e31f7  
    1010#include "rtl-error.h"
    1111#include "rtl-trace.h"
     12#include "rtl-unwind.h"
     13#include "rtl-unwind-dw2.h"
     14
     15uint32_t
     16rtems_rtl_elf_section_flags (const rtems_rtl_obj_t* obj,
     17                             const Elf_Shdr*        shdr)
     18{
     19  return 0;
     20}
    1221
    1322bool
     
    100109  return false;
    101110}
     111
     112bool
     113rtems_rtl_elf_unwind_parse (const rtems_rtl_obj_t* obj,
     114                            const char*            name,
     115                            uint32_t               flags)
     116{
     117  return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags);
     118}
     119
     120bool
     121rtems_rtl_elf_unwind_register (rtems_rtl_obj_t* obj)
     122{
     123  return rtems_rtl_elf_unwind_dw2_register (obj);
     124}
     125
     126bool
     127rtems_rtl_elf_unwind_deregister (rtems_rtl_obj_t* obj)
     128{
     129  return rtems_rtl_elf_unwind_dw2_deregister (obj);
     130}
  • cpukit/libdl/rtl-mdreloc-i386.c

    rd51538bd rd2e31f7  
    1616#include "rtl-error.h"
    1717#include "rtl-trace.h"
     18#include "rtl-unwind.h"
     19#include "rtl-unwind-dw2.h"
     20
     21uint32_t
     22rtems_rtl_elf_section_flags (const rtems_rtl_obj_t* obj,
     23                             const Elf_Shdr*        shdr)
     24{
     25  return 0;
     26}
    1827
    1928bool
     
    102111  return true;
    103112}
     113
     114bool
     115rtems_rtl_elf_unwind_parse (const rtems_rtl_obj_t* obj,
     116                            const char*            name,
     117                            uint32_t               flags)
     118{
     119  return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags);
     120}
     121
     122bool
     123rtems_rtl_elf_unwind_register (rtems_rtl_obj_t* obj)
     124{
     125  return rtems_rtl_elf_unwind_dw2_register (obj);
     126}
     127
     128bool
     129rtems_rtl_elf_unwind_deregister (rtems_rtl_obj_t* obj)
     130{
     131  return rtems_rtl_elf_unwind_dw2_deregister (obj);
     132}
  • cpukit/libdl/rtl-mdreloc-lm32.c

    rd51538bd rd2e31f7  
    1010#include "rtl-error.h"
    1111#include "rtl-trace.h"
     12#include "rtl-unwind.h"
     13#include "rtl-unwind-dw2.h"
     14
     15uint32_t
     16rtems_rtl_elf_section_flags (const rtems_rtl_obj_t* obj,
     17                             const Elf_Shdr*        shdr)
     18{
     19  return 0;
     20}
    1221
    1322bool
     
    119128  return false;
    120129}
     130
     131bool
     132rtems_rtl_elf_unwind_parse (const rtems_rtl_obj_t* obj,
     133                            const char*            name,
     134                            uint32_t               flags)
     135{
     136  return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags);
     137}
     138
     139bool
     140rtems_rtl_elf_unwind_register (rtems_rtl_obj_t* obj)
     141{
     142  return rtems_rtl_elf_unwind_dw2_register (obj);
     143}
     144
     145bool
     146rtems_rtl_elf_unwind_deregister (rtems_rtl_obj_t* obj)
     147{
     148  return rtems_rtl_elf_unwind_dw2_deregister (obj);
     149}
  • cpukit/libdl/rtl-mdreloc-m68k.c

    rd51538bd rd2e31f7  
    1616#include "rtl-error.h"
    1717#include "rtl-trace.h"
     18#include "rtl-unwind.h"
     19#include "rtl-unwind-dw2.h"
    1820
    1921static inline int overflow_8_check(int value)
     
    2931    return true;
    3032  return false;
     33}
     34
     35uint32_t
     36rtems_rtl_elf_section_flags (const rtems_rtl_obj_t* obj,
     37                             const Elf_Shdr*        shdr)
     38{
     39  return 0;
    3140}
    3241
     
    147156  return false;
    148157}
     158
     159bool
     160rtems_rtl_elf_unwind_parse (const rtems_rtl_obj_t* obj,
     161                            const char*            name,
     162                            uint32_t               flags)
     163{
     164  return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags);
     165}
     166
     167bool
     168rtems_rtl_elf_unwind_register (rtems_rtl_obj_t* obj)
     169{
     170  return rtems_rtl_elf_unwind_dw2_register (obj);
     171}
     172
     173bool
     174rtems_rtl_elf_unwind_deregister (rtems_rtl_obj_t* obj)
     175{
     176  return rtems_rtl_elf_unwind_dw2_deregister (obj);
     177}
  • cpukit/libdl/rtl-mdreloc-mips.c

    rd51538bd rd2e31f7  
    1010#include "rtl-error.h"
    1111#include "rtl-trace.h"
     12#include "rtl-unwind.h"
     13#include "rtl-unwind-dw2.h"
     14
     15uint32_t
     16rtems_rtl_elf_section_flags (const rtems_rtl_obj_t* obj,
     17                             const Elf_Shdr*        shdr)
     18{
     19  return 0;
     20}
    1221
    1322bool
     
    189198  return true;
    190199}
     200
     201bool
     202rtems_rtl_elf_unwind_parse (const rtems_rtl_obj_t* obj,
     203                            const char*            name,
     204                            uint32_t               flags)
     205{
     206  return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags);
     207}
     208
     209bool
     210rtems_rtl_elf_unwind_register (rtems_rtl_obj_t* obj)
     211{
     212  return rtems_rtl_elf_unwind_dw2_register (obj);
     213}
     214
     215bool
     216rtems_rtl_elf_unwind_deregister (rtems_rtl_obj_t* obj)
     217{
     218  return rtems_rtl_elf_unwind_dw2_deregister (obj);
     219}
  • cpukit/libdl/rtl-mdreloc-moxie.c

    rd51538bd rd2e31f7  
    1111#include "rtl-error.h"
    1212#include "rtl-trace.h"
     13#include "rtl-unwind.h"
     14#include "rtl-unwind-dw2.h"
     15
     16uint32_t
     17rtems_rtl_elf_section_flags (const rtems_rtl_obj_t* obj,
     18                             const Elf_Shdr*        shdr)
     19{
     20  return 0;
     21}
    1322
    1423bool
     
    8796  return false;
    8897}
     98
     99bool
     100rtems_rtl_elf_unwind_parse (const rtems_rtl_obj_t* obj,
     101                            const char*            name,
     102                            uint32_t               flags)
     103{
     104  return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags);
     105}
     106
     107bool
     108rtems_rtl_elf_unwind_register (rtems_rtl_obj_t* obj)
     109{
     110  return rtems_rtl_elf_unwind_dw2_register (obj);
     111}
     112
     113bool
     114rtems_rtl_elf_unwind_deregister (rtems_rtl_obj_t* obj)
     115{
     116  return rtems_rtl_elf_unwind_dw2_deregister (obj);
     117}
  • cpukit/libdl/rtl-mdreloc-powerpc.c

    rd51538bd rd2e31f7  
    1616#include "rtl-error.h"
    1717#include "rtl-trace.h"
     18#include "rtl-unwind.h"
     19#include "rtl-unwind-dw2.h"
    1820
    1921#define ha(x) ((((u_int32_t)(x) & 0x8000) ? \
     
    2123#define l(x) ((u_int32_t)(x) & 0xffff)
    2224
     25uint32_t
     26rtems_rtl_elf_section_flags (const rtems_rtl_obj_t* obj,
     27                             const Elf_Shdr*        shdr)
     28{
     29  return 0;
     30}
    2331
    2432bool
     
    157165        printf ("rtl: REL32 %p @ %p in %s\n",
    158166                (void *)*where, where, rtems_rtl_obj_oname (obj));
     167      break;
     168
     169    case R_TYPE(SDAREL16):
     170      /*
     171       * A sign-extended 16 bit value relative to _SDA_BASE_, for use with
     172       * small data items.
     173       */
     174      mask = 0xffff;
     175      tmp = *((Elf32_Half*) where);
     176      tmp &= ~mask;
     177      tmp |= (symvalue + rela->r_addend - (Elf_Addr)where) & mask;
     178      *((Elf32_Half*) where) = tmp;
     179      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
     180        printf ("rtl: SDAREL16 %p @ %p in %s\n",
     181                (void *) (uintptr_t) *((Elf32_Half*) where),
     182                where, rtems_rtl_obj_oname (obj));
    159183      break;
    160184
     
    184208  return false;
    185209}
     210
     211bool
     212rtems_rtl_elf_unwind_parse (const rtems_rtl_obj_t* obj,
     213                            const char*            name,
     214                            uint32_t               flags)
     215{
     216  return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags);
     217}
     218
     219bool
     220rtems_rtl_elf_unwind_register (rtems_rtl_obj_t* obj)
     221{
     222  return rtems_rtl_elf_unwind_dw2_register (obj);
     223}
     224
     225bool
     226rtems_rtl_elf_unwind_deregister (rtems_rtl_obj_t* obj)
     227{
     228  return rtems_rtl_elf_unwind_dw2_deregister (obj);
     229}
  • cpukit/libdl/rtl-mdreloc-sparc.c

    rd51538bd rd2e31f7  
    4242#include "rtl-error.h"
    4343#include "rtl-trace.h"
     44#include "rtl-unwind.h"
     45#include "rtl-unwind-dw2.h"
    4446
    4547/*
     
    129131#define RELOC_VALUE_BITMASK(t)  (reloc_target_bitmask[t])
    130132
     133uint32_t
     134rtems_rtl_elf_section_flags (const rtems_rtl_obj_t* obj,
     135                             const Elf_Shdr*        shdr)
     136{
     137  return 0;
     138}
     139
    131140bool
    132141rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
     
    145154  Elf_Addr *where;
    146155  Elf_Word type, value, mask;
     156  Elf_Addr tmp = 0;
    147157
    148158  where = (Elf_Addr *) (sect->base + rela->r_offset);
     
    220230
    221231  if (RELOC_UNALIGNED(type)) {
    222     /* Handle unaligned relocations. */
    223     Elf_Addr tmp = 0;
    224     char *ptr = (char *)where;
     232    /*
     233     * Handle unaligned relocations.
     234     */
     235    char *ptr = (char*) where;
    225236    int i, size = RELOC_TARGET_SIZE (type) / 8;
    226237
    227238    /* Read it in one byte at a time. */
    228     for (i=0; i<size; i++)
     239    for (i = size - 1; i >= 0; i--)
    229240      tmp = (tmp << 8) | ptr[i];
    230241
     
    233244
    234245    /* Write it back out. */
    235     for (i=0; i<size; i++)
    236       ptr[i] = ((tmp >> (8*i)) & 0xff);
    237 
     246    for (i = size - 1; i >= 0; i--, tmp >>= 8)
     247      ptr[i] = tmp & 0xff;
    238248  } else {
    239249    *where &= ~mask;
    240250    *where |= value;
     251    tmp = *where;
    241252  }
    242253
    243254  if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
    244255    printf ("rtl: %s %p @ %p in %s\n",
    245             reloc_names[type], (void *)*where, where, rtems_rtl_obj_oname (obj));
    246 
     256            reloc_names[ELF_R_TYPE(rela->r_info)],
     257            (void *)tmp, where, rtems_rtl_obj_oname (obj));
    247258
    248259  return true;
     
    260271  return false;
    261272}
     273
     274bool
     275rtems_rtl_elf_unwind_parse (const rtems_rtl_obj_t* obj,
     276                            const char*            name,
     277                            uint32_t               flags)
     278{
     279  return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags);
     280}
     281
     282bool
     283rtems_rtl_elf_unwind_register (rtems_rtl_obj_t* obj)
     284{
     285  return rtems_rtl_elf_unwind_dw2_register (obj);
     286}
     287
     288bool
     289rtems_rtl_elf_unwind_deregister (rtems_rtl_obj_t* obj)
     290{
     291  return rtems_rtl_elf_unwind_dw2_deregister (obj);
     292}
  • cpukit/libdl/rtl-mdreloc-v850.c

    rd51538bd rd2e31f7  
    1111#include "rtl-error.h"
    1212#include "rtl-trace.h"
     13#include "rtl-unwind.h"
     14#include "rtl-unwind-dw2.h"
     15
     16uint32_t
     17rtems_rtl_elf_section_flags (const rtems_rtl_obj_t* obj,
     18                             const Elf_Shdr*        shdr)
     19{
     20  return 0;
     21}
    1322
    1423bool
     
    96105  return false;
    97106}
     107
     108bool
     109rtems_rtl_elf_unwind_parse (const rtems_rtl_obj_t* obj,
     110                            const char*            name,
     111                            uint32_t               flags)
     112{
     113  return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags);
     114}
     115
     116bool
     117rtems_rtl_elf_unwind_register (rtems_rtl_obj_t* obj)
     118{
     119  return rtems_rtl_elf_unwind_dw2_register (obj);
     120}
     121
     122bool
     123rtems_rtl_elf_unwind_deregister (rtems_rtl_obj_t* obj)
     124{
     125  return rtems_rtl_elf_unwind_dw2_deregister (obj);
     126}
  • cpukit/libdl/rtl-obj.c

    rd51538bd rd2e31f7  
    5050 * The table of supported loader formats.
    5151 */
    52 static rtems_rtl_loader_table_t loaders[RTEMS_RTL_ELF_LOADER_COUNT +
    53                                         RTEMS_RTL_RAP_LOADER_COUNT] =
     52#define RTEMS_RTL_LOADERS (RTEMS_RTL_ELF_LOADER_COUNT + RTEMS_RTL_RAP_LOADER_COUNT)
     53static const rtems_rtl_loader_table_t loaders[RTEMS_RTL_LOADERS] =
    5454{
    5555#if RTEMS_RTL_RAP_LOADER
    56   { rtems_rtl_rap_file_check, rtems_rtl_rap_file_load, rtems_rtl_rap_file_sig },
     56  { .check     = rtems_rtl_rap_file_check,
     57    .load      = rtems_rtl_rap_file_load,
     58    .unload    = rtems_rtl_rap_file_unload,
     59    .unload    = rtems_rtl_rap_file_unload,
     60    .signature = rtems_rtl_rap_file_sig },
    5761#endif
    5862#if RTEMS_RTL_ELF_LOADER
    59   { rtems_rtl_elf_file_check, rtems_rtl_elf_file_load, rtems_rtl_elf_file_sig },
     63  { .check     = rtems_rtl_elf_file_check,
     64    .load      = rtems_rtl_elf_file_load,
     65    .unload    = rtems_rtl_elf_file_unload,
     66    .signature = rtems_rtl_elf_file_sig },
    6067#endif
    6168};
     
    7380     */
    7481    rtems_chain_initialize_empty (&obj->sections);
     82    /*
     83     * No valid format.
     84     */
     85    obj->format = -1;
    7586  }
    7687  return obj;
     
    98109  if (!rtems_chain_is_node_off_chain (&obj->link))
    99110    rtems_chain_extract (&obj->link);
    100   rtems_rtl_alloc_module_del (&obj->text_base, &obj->const_base,
     111  rtems_rtl_alloc_module_del (&obj->text_base, &obj->const_base, &obj->eh_base,
    101112                              &obj->data_base, &obj->bss_base);
    102113  rtems_rtl_symbol_obj_erase (obj);
     
    104115  if (obj->sec_num)
    105116    free (obj->sec_num);
    106   if (obj->detail)
    107     rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, (void*)obj->detail);
     117  if (obj->linkmap)
     118    rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, (void*) obj->linkmap);
    108119  rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, obj);
    109120  return true;
     
    239250rtems_rtl_sect_align (size_t offset, uint32_t alignment)
    240251{
    241   if ((alignment > 1) && ((offset & ~alignment) != 0))
     252  if ((alignment > 1) && ((offset & (alignment - 1)) != 0))
    242253    offset = (offset + alignment) & ~(alignment - 1);
    243254  return offset;
     
    265276
    266277static size_t
    267 rtems_rtl_obj_section_size (rtems_rtl_obj_t* obj, uint32_t mask)
     278rtems_rtl_obj_section_size (const rtems_rtl_obj_t* obj, uint32_t mask)
    268279{
    269280  rtems_rtl_obj_sect_summer_t summer;
    270281  summer.mask = mask;
    271282  summer.size = 0;
    272   rtems_rtl_chain_iterate (&obj->sections,
     283  rtems_rtl_chain_iterate ((rtems_chain_control*) &obj->sections,
    273284                           rtems_rtl_obj_sect_summer,
    274285                           &summer);
     
    303314
    304315static size_t
    305 rtems_rtl_obj_section_alignment (rtems_rtl_obj_t* obj, uint32_t mask)
     316rtems_rtl_obj_section_alignment (const rtems_rtl_obj_t* obj, uint32_t mask)
    306317{
    307318  rtems_rtl_obj_sect_aligner_t aligner;
    308319  aligner.mask = mask;
    309320  aligner.alignment = 0;
    310   rtems_rtl_chain_iterate (&obj->sections,
     321  rtems_rtl_chain_iterate ((rtems_chain_control*) &obj->sections,
    311322                           rtems_rtl_obj_sect_aligner,
    312323                           &aligner);
     
    402413                           uint32_t         flags)
    403414{
    404   rtems_rtl_obj_sect_t* sect = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT,
    405                                                     sizeof (rtems_rtl_obj_sect_t), true);
    406   if (!sect)
    407   {
    408     rtems_rtl_set_error (ENOMEM, "adding allocated section");
    409     return false;
    410   }
    411   sect->section = section;
    412   sect->name = rtems_rtl_strdup (name);
    413   sect->size = size;
    414   sect->offset = offset;
    415   sect->alignment = alignment;
    416   sect->link = link;
    417   sect->info = info;
    418   sect->flags = flags;
    419   sect->base = NULL;
    420   rtems_chain_append (&obj->sections, &sect->node);
    421 
    422   if (rtems_rtl_trace (RTEMS_RTL_TRACE_SECTION))
    423     printf ("rtl: sect: %-2d: %s\n", section, name);
     415  if (size > 0)
     416  {
     417    rtems_rtl_obj_sect_t* sect = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT,
     418                                                      sizeof (rtems_rtl_obj_sect_t),
     419                                                      true);
     420    if (!sect)
     421    {
     422      rtems_rtl_set_error (ENOMEM, "adding allocated section");
     423      return false;
     424    }
     425    sect->section = section;
     426    sect->name = rtems_rtl_strdup (name);
     427    sect->size = size;
     428    sect->offset = offset;
     429    sect->alignment = alignment;
     430    sect->link = link;
     431    sect->info = info;
     432    sect->flags = flags;
     433    sect->base = NULL;
     434    rtems_chain_append (&obj->sections, &sect->node);
     435
     436    if (rtems_rtl_trace (RTEMS_RTL_TRACE_SECTION))
     437      printf ("rtl: sect: %-2d: %s (%zu)\n", section, name, size);
     438  }
    424439
    425440  return true;
     
    465480
    466481rtems_rtl_obj_sect_t*
    467 rtems_rtl_obj_find_section (rtems_rtl_obj_t* obj, const char* name)
     482rtems_rtl_obj_find_section (const rtems_rtl_obj_t* obj,
     483                            const char*            name)
    468484{
    469485  rtems_rtl_obj_sect_finder_t match;
    470486  match.sect = NULL;
    471487  match.name = name;
    472   rtems_rtl_chain_iterate (&obj->sections,
     488  rtems_rtl_chain_iterate ((rtems_chain_control*) &obj->sections,
    473489                           rtems_rtl_obj_sect_match_name,
    474490                           &match);
     
    490506
    491507rtems_rtl_obj_sect_t*
    492 rtems_rtl_obj_find_section_by_index (rtems_rtl_obj_t* obj, int index)
     508rtems_rtl_obj_find_section_by_index (const rtems_rtl_obj_t* obj,
     509                                     int                    index)
    493510{
    494511  rtems_rtl_obj_sect_finder_t match;
    495512  match.sect = NULL;
    496513  match.index = index;
    497   rtems_rtl_chain_iterate (&obj->sections,
     514  rtems_rtl_chain_iterate ((rtems_chain_control*) &obj->sections,
    498515                           rtems_rtl_obj_sect_match_index,
    499516                           &match);
     
    502519
    503520size_t
    504 rtems_rtl_obj_text_size (rtems_rtl_obj_t* obj)
     521rtems_rtl_obj_text_size (const rtems_rtl_obj_t* obj)
    505522{
    506523  return rtems_rtl_obj_section_size (obj, RTEMS_RTL_OBJ_SECT_TEXT);
     
    508525
    509526uint32_t
    510 rtems_rtl_obj_text_alignment (rtems_rtl_obj_t* obj)
     527rtems_rtl_obj_text_alignment (const rtems_rtl_obj_t* obj)
    511528{
    512529  return rtems_rtl_obj_section_alignment (obj, RTEMS_RTL_OBJ_SECT_TEXT);
     
    514531
    515532size_t
    516 rtems_rtl_obj_const_size (rtems_rtl_obj_t* obj)
     533rtems_rtl_obj_const_size (const rtems_rtl_obj_t* obj)
    517534{
    518535  return rtems_rtl_obj_section_size (obj, RTEMS_RTL_OBJ_SECT_CONST);
     
    520537
    521538uint32_t
    522 rtems_rtl_obj_const_alignment (rtems_rtl_obj_t* obj)
     539rtems_rtl_obj_eh_alignment (const rtems_rtl_obj_t* obj)
     540{
     541  return rtems_rtl_obj_section_alignment (obj, RTEMS_RTL_OBJ_SECT_EH);
     542}
     543
     544size_t
     545rtems_rtl_obj_eh_size (const rtems_rtl_obj_t* obj)
     546{
     547  return rtems_rtl_obj_section_size (obj, RTEMS_RTL_OBJ_SECT_EH);
     548}
     549
     550uint32_t
     551rtems_rtl_obj_const_alignment (const rtems_rtl_obj_t* obj)
    523552{
    524553  return rtems_rtl_obj_section_alignment (obj, RTEMS_RTL_OBJ_SECT_CONST);
     
    526555
    527556size_t
    528 rtems_rtl_obj_data_size (rtems_rtl_obj_t* obj)
     557rtems_rtl_obj_data_size (const rtems_rtl_obj_t* obj)
    529558{
    530559  return rtems_rtl_obj_section_size (obj, RTEMS_RTL_OBJ_SECT_DATA);
     
    532561
    533562uint32_t
    534 rtems_rtl_obj_data_alignment (rtems_rtl_obj_t* obj)
     563rtems_rtl_obj_data_alignment (const rtems_rtl_obj_t* obj)
    535564{
    536565  return rtems_rtl_obj_section_alignment (obj, RTEMS_RTL_OBJ_SECT_DATA);
     
    538567
    539568size_t
    540 rtems_rtl_obj_bss_size (rtems_rtl_obj_t* obj)
     569rtems_rtl_obj_bss_size (const rtems_rtl_obj_t* obj)
    541570{
    542571  return rtems_rtl_obj_section_size (obj, RTEMS_RTL_OBJ_SECT_BSS);
     
    544573
    545574uint32_t
    546 rtems_rtl_obj_bss_alignment (rtems_rtl_obj_t* obj)
     575rtems_rtl_obj_bss_alignment (const rtems_rtl_obj_t* obj)
    547576{
    548577  return rtems_rtl_obj_section_alignment (obj, RTEMS_RTL_OBJ_SECT_BSS);
     
    573602rtems_rtl_obj_sect_sync_handler (rtems_chain_node* node, void* data)
    574603{
    575   rtems_rtl_obj_sect_t*   sect = (rtems_rtl_obj_sect_t*) node;
     604  rtems_rtl_obj_sect_t*          sect = (rtems_rtl_obj_sect_t*) node;
    576605  rtems_rtl_obj_sect_sync_ctx_t* sync_ctx = data;
    577   uintptr_t old_end;
    578   uintptr_t new_start;
    579 
    580   if ( !(sect->flags & sync_ctx->mask) || !sect->size)
     606  uintptr_t                      old_end;
     607  uintptr_t                      new_start;
     608
     609  if ((sect->flags & sync_ctx->mask) == 0 || sect->size == 0)
    581610    return true;
    582611
    583   if (sync_ctx->end_va == sync_ctx->start_va) {
     612  if (sync_ctx->end_va == sync_ctx->start_va)
     613  {
    584614    sync_ctx->start_va = sect->base;
    585   } else {
    586     old_end = (uintptr_t)sync_ctx->end_va & ~(sync_ctx->cache_line_size - 1);
    587     new_start = (uintptr_t)sect->base & ~(sync_ctx->cache_line_size - 1);
    588     if ( (sect->base <  sync_ctx->start_va) ||
    589          (new_start - old_end > sync_ctx->cache_line_size) ) {
     615  }
     616  else
     617  {
     618    old_end = (uintptr_t) sync_ctx->end_va & ~(sync_ctx->cache_line_size - 1);
     619    new_start = (uintptr_t) sect->base & ~(sync_ctx->cache_line_size - 1);
     620    if ((sect->base <  sync_ctx->start_va) ||
     621        (new_start - old_end > sync_ctx->cache_line_size))
     622    {
    590623      rtems_cache_instruction_sync_after_code_change(sync_ctx->start_va,
    591624                             sync_ctx->end_va - sync_ctx->start_va + 1);
     
    600633
    601634void
    602 rtems_rtl_obj_synchronize_cache (rtems_rtl_obj_t*    obj)
     635rtems_rtl_obj_synchronize_cache (rtems_rtl_obj_t* obj)
    603636{
    604637  rtems_rtl_obj_sect_sync_ctx_t sync_ctx;
     
    611644  sync_ctx.mask = RTEMS_RTL_OBJ_SECT_TEXT | RTEMS_RTL_OBJ_SECT_CONST |
    612645                  RTEMS_RTL_OBJ_SECT_DATA | RTEMS_RTL_OBJ_SECT_BSS |
    613                   RTEMS_RTL_OBJ_SECT_EXEC;
     646                  RTEMS_RTL_OBJ_SECT_EH   | RTEMS_RTL_OBJ_SECT_EXEC;
    614647
    615648  sync_ctx.start_va = 0;
     
    633666  uint32_t mask = RTEMS_RTL_OBJ_SECT_SYM;
    634667  return rtems_rtl_obj_section_handler (mask, obj, fd, handler, data);
     668}
     669
     670static int
     671rtems_rtl_obj_sections_linked_to_order (rtems_rtl_obj_t* obj,
     672                                        int              section,
     673                                        uint32_t         visited_mask)
     674{
     675  rtems_chain_control* sections = &obj->sections;
     676  rtems_chain_node*    node = rtems_chain_first (sections);
     677  /*
     678   * Find the section being linked-to. If the linked-to link field is 0 we have
     679   * the end and the section's order is the position we are after.
     680   */
     681  while (!rtems_chain_is_tail (sections, node))
     682  {
     683    rtems_rtl_obj_sect_t* sect = (rtems_rtl_obj_sect_t*) node;
     684    if (sect->section == section)
     685    {
     686      const uint32_t mask = sect->flags & RTEMS_RTL_OBJ_SECT_TYPES;
     687      int            order = 0;
     688      if (sect->link != 0)
     689      {
     690        /*
     691         * Have we already visited this type of section? Avoid nesting for
     692         * ever.
     693         */
     694        if ((sect->flags & visited_mask) != 0)
     695        {
     696          rtems_rtl_set_error (errno, "section link loop");
     697          return -1;
     698        }
     699        return rtems_rtl_obj_sections_linked_to_order (obj,
     700                                                       sect->link,
     701                                                       visited_mask | mask);
     702      }
     703      node = rtems_chain_first (sections);
     704      while (!rtems_chain_is_tail (sections, node))
     705      {
     706        sect = (rtems_rtl_obj_sect_t*) node;
     707        if ((sect->flags & mask) == mask)
     708        {
     709          if (sect->section == section)
     710            return order;
     711          ++order;
     712        }
     713        node = rtems_chain_next (node);
     714      }
     715    }
     716    node = rtems_chain_next (node);
     717  }
     718  rtems_rtl_set_error (errno, "section link not found");
     719  return -1;
     720}
     721
     722static void
     723rtems_rtl_obj_sections_link_order (uint32_t mask, rtems_rtl_obj_t* obj)
     724{
     725  rtems_chain_control* sections = &obj->sections;
     726  rtems_chain_node*    node = rtems_chain_first (sections);
     727  int                  order = 0;
     728  while (!rtems_chain_is_tail (sections, node))
     729  {
     730    rtems_rtl_obj_sect_t* sect = (rtems_rtl_obj_sect_t*) node;
     731    if ((sect->flags & mask) == mask)
     732    {
     733      /*
     734       * If the section is linked in order find the linked-to section's order
     735       * and move the section in the section list to
     736       */
     737      if (sect->link == 0)
     738        sect->load_order = order++;
     739      else
     740      {
     741        sect->load_order =
     742          rtems_rtl_obj_sections_linked_to_order (obj,
     743                                                  sect->link,
     744                                                  mask);
     745      }
     746    }
     747    node = rtems_chain_next (node);
     748  }
    635749}
    636750
     
    647761  size_t               base_offset = 0;
    648762  bool                 first = true;
     763  int                  order = 0;
     764
    649765  while (!rtems_chain_is_tail (sections, node))
    650766  {
     
    653769    if ((sect->size != 0) && ((sect->flags & mask) != 0))
    654770    {
    655       if (!first)
    656         base_offset = rtems_rtl_sect_align (base_offset, sect->alignment);
    657 
    658       sect->base = base + base_offset;
    659 
    660       if (rtems_rtl_trace (RTEMS_RTL_TRACE_LOAD_SECT))
    661         printf ("rtl: loading: %s -> %8p (%zi)\n",
    662                 sect->name, sect->base, sect->size);
    663 
    664       if ((sect->flags & RTEMS_RTL_OBJ_SECT_LOAD) == RTEMS_RTL_OBJ_SECT_LOAD)
     771      if (sect->load_order == order)
    665772      {
    666         if (!handler (obj, fd, sect, data))
     773        if (!first)
     774          base_offset = rtems_rtl_sect_align (base_offset, sect->alignment);
     775
     776        first = false;
     777
     778        sect->base = base + base_offset;
     779
     780        if (rtems_rtl_trace (RTEMS_RTL_TRACE_LOAD_SECT))
     781          printf ("rtl: loading:%2d: %s -> %8p (s:%zi f:%04lx a:%lu l:%02d)\n",
     782                  order, sect->name, sect->base, sect->size,
     783                  sect->flags, sect->alignment, sect->link);
     784
     785        if ((sect->flags & RTEMS_RTL_OBJ_SECT_LOAD) == RTEMS_RTL_OBJ_SECT_LOAD)
     786        {
     787          if (!handler (obj, fd, sect, data))
     788          {
     789            sect->base = 0;
     790            return false;
     791          }
     792        }
     793        else if ((sect->flags & RTEMS_RTL_OBJ_SECT_ZERO) == RTEMS_RTL_OBJ_SECT_ZERO)
     794        {
     795          memset (base + base_offset, 0, sect->size);
     796        }
     797        else
    667798        {
    668799          sect->base = 0;
     800          rtems_rtl_set_error (errno, "section has no load/clear op");
    669801          return false;
    670802        }
     803
     804        base_offset += sect->size;
     805
     806        ++order;
     807
     808        node = rtems_chain_first (sections);
     809        continue;
    671810      }
    672       else if ((sect->flags & RTEMS_RTL_OBJ_SECT_ZERO) == RTEMS_RTL_OBJ_SECT_ZERO)
    673       {
    674         memset (base + base_offset, 0, sect->size);
    675       }
    676       else
    677       {
    678         sect->base = 0;
    679         rtems_rtl_set_error (errno, "section has no load op");
    680         return false;
    681       }
    682 
    683       base_offset += sect->size;
    684       first = false;
    685811    }
    686812
     
    699825  size_t text_size;
    700826  size_t const_size;
     827  size_t eh_size;
    701828  size_t data_size;
    702829  size_t bss_size;
    703830
    704831  text_size  = rtems_rtl_obj_text_size (obj) + rtems_rtl_obj_const_alignment (obj);
    705   const_size = rtems_rtl_obj_const_size (obj) + rtems_rtl_obj_data_alignment (obj);
     832  const_size = rtems_rtl_obj_const_size (obj) + rtems_rtl_obj_eh_alignment (obj);
     833  eh_size    = rtems_rtl_obj_eh_size (obj) + rtems_rtl_obj_data_alignment (obj);
    706834  data_size  = rtems_rtl_obj_data_size (obj) + rtems_rtl_obj_bss_alignment (obj);
    707835  bss_size   = rtems_rtl_obj_bss_size (obj);
     836
     837  /*
     838   * Set the sizes held in the object data. We need this for a fast reference.
     839   */
     840  obj->text_size = text_size;
     841  obj->eh_size   = eh_size;
     842  obj->bss_size  = bss_size;
    708843
    709844  /*
     
    713848  if (!rtems_rtl_alloc_module_new (&obj->text_base, text_size,
    714849                                   &obj->const_base, const_size,
     850                                   &obj->eh_base, eh_size,
    715851                                   &obj->data_base, data_size,
    716852                                   &obj->bss_base, bss_size))
     
    721857  }
    722858
    723   obj->exec_size = text_size + const_size + data_size + bss_size;
     859  obj->exec_size = text_size + const_size + eh_size + data_size + bss_size;
    724860
    725861  if (rtems_rtl_trace (RTEMS_RTL_TRACE_LOAD_SECT))
     
    729865    printf ("rtl: load sect: const - b:%p s:%zi a:%" PRIu32 "\n",
    730866            obj->const_base, const_size, rtems_rtl_obj_const_alignment (obj));
     867    printf ("rtl: load sect: eh    - b:%p s:%zi a:%" PRIu32 "\n",
     868            obj->eh_base, eh_size, rtems_rtl_obj_eh_alignment (obj));
    731869    printf ("rtl: load sect: data  - b:%p s:%zi a:%" PRIu32 "\n",
    732870            obj->data_base, data_size, rtems_rtl_obj_data_alignment (obj));
     
    734872            obj->bss_base, bss_size, rtems_rtl_obj_bss_alignment (obj));
    735873  }
     874
     875  /*
     876   * Determine the load order.
     877   */
     878  rtems_rtl_obj_sections_link_order (RTEMS_RTL_OBJ_SECT_TEXT,  obj);
     879  rtems_rtl_obj_sections_link_order (RTEMS_RTL_OBJ_SECT_CONST, obj);
     880  rtems_rtl_obj_sections_link_order (RTEMS_RTL_OBJ_SECT_EH,    obj);
     881  rtems_rtl_obj_sections_link_order (RTEMS_RTL_OBJ_SECT_DATA,  obj);
    736882
    737883  /*
     
    743889      !rtems_rtl_obj_sections_loader (RTEMS_RTL_OBJ_SECT_CONST,
    744890                                      obj, fd, obj->const_base, handler, data) ||
     891      !rtems_rtl_obj_sections_loader (RTEMS_RTL_OBJ_SECT_EH,
     892                                      obj, fd, obj->eh_base, handler, data) ||
    745893      !rtems_rtl_obj_sections_loader (RTEMS_RTL_OBJ_SECT_DATA,
    746894                                      obj, fd, obj->data_base, handler, data) ||
     
    748896                                      obj, fd, obj->bss_base, handler, data))
    749897  {
    750     rtems_rtl_alloc_module_del (&obj->text_base, &obj->const_base,
     898    rtems_rtl_alloc_module_del (&obj->text_base, &obj->const_base, &obj->eh_base,
    751899                                &obj->data_base, &obj->bss_base);
    752900    obj->exec_size = 0;
     
    9731121             */
    9741122#define RTEMS_RTL_MAX_FILE_SIZE (256)
    975             char  name[RTEMS_RTL_MAX_FILE_SIZE];
     1123            char name[RTEMS_RTL_MAX_FILE_SIZE];
    9761124
    9771125            if (!rtems_rtl_seek_read (fd, extended_file_names + extended_off,
     
    10171165}
    10181166
    1019 bool
     1167static bool
    10201168rtems_rtl_obj_file_load (rtems_rtl_obj_t* obj, int fd)
    10211169{
     
    10251173  {
    10261174    if (loaders[l].check (obj, fd))
     1175    {
     1176      obj->format = l;
    10271177      return loaders[l].load (obj, fd);
     1178    }
    10281179  }
    10291180
    10301181  rtems_rtl_set_error (ENOENT, "no format loader found");
     1182  return false;
     1183}
     1184
     1185static bool
     1186rtems_rtl_obj_file_unload (rtems_rtl_obj_t* obj)
     1187{
     1188  if (obj->format >= 0 && obj->format < RTEMS_RTL_LOADERS)
     1189      return loaders[obj->format].unload (obj);
    10311190  return false;
    10321191}
     
    10581217    if (!rtems_rtl_obj_archive_find (obj, fd))
    10591218    {
    1060       rtems_rtl_obj_caches_flush ();
    10611219      close (fd);
    10621220      return false;
     
    10651223
    10661224  /*
    1067    * Call the format specific loader. Currently this is a call to the ELF
    1068    * loader. This call could be changed to allow probes then calls if more than
    1069    * one format is supported.
     1225   * Call the format specific loader.
    10701226   */
    10711227  if (!rtems_rtl_obj_file_load (obj, fd))
    10721228  {
    1073     rtems_rtl_obj_caches_flush ();
    10741229    close (fd);
    10751230    return false;
     
    10811236    return false;
    10821237  }
    1083 
    1084   rtems_rtl_obj_caches_flush ();
    10851238
    10861239  close (fd);
     
    10931246{
    10941247  _rtld_linkmap_delete(obj);
    1095   rtems_rtl_symbol_obj_erase (obj);
    1096   return rtems_rtl_obj_free (obj);
    1097 }
     1248  rtems_rtl_obj_file_unload (obj);
     1249  return true;
     1250}
  • cpukit/libdl/rtl-obj.h

    rd51538bd rd2e31f7  
    5757
    5858/**
    59  * The type of the format loader handler. This handler loads the specific
     59 * The type of the format loader load handler. This handler loads the specific
    6060 * format.
    6161 */
     
    6363
    6464/**
    65  * The type of the format loader handler. This handler loads the specific
    66  * format.
     65 * The type of the format loader unload handler. This handler unloads the
     66 * specific format.
     67 */
     68typedef bool (*rtems_rtl_loader_unload) (rtems_rtl_obj_t* obj);
     69
     70/**
     71 * The type of the format loader signature handler. This handler checks the
     72 * format signature.
    6773 */
    6874typedef rtems_rtl_loader_format_t* (*rtems_rtl_loader_sig) (void);
     
    7379typedef struct rtems_rtl_loader_table_s
    7480{
    75   rtems_rtl_loader_check check;     /**< The check handler. */
    76   rtems_rtl_loader_load  load;      /**< The loader. */
    77   rtems_rtl_loader_sig   signature; /**< The loader's signature. */
     81  rtems_rtl_loader_check  check;     /**< The check handler. */
     82  rtems_rtl_loader_load   load;      /**< The loader. */
     83  rtems_rtl_loader_unload unload;    /**< The unloader. */
     84  rtems_rtl_loader_sig    signature; /**< The loader's signature. */
    7885} rtems_rtl_loader_table_t;
    7986
     
    8592#define RTEMS_RTL_OBJ_SECT_DATA  (1 << 2)  /**< Section holds program data. */
    8693#define RTEMS_RTL_OBJ_SECT_BSS   (1 << 3)  /**< Section holds program bss. */
    87 #define RTEMS_RTL_OBJ_SECT_REL   (1 << 4)  /**< Section holds relocation records. */
    88 #define RTEMS_RTL_OBJ_SECT_RELA  (1 << 5)  /**< Section holds relocation addend
     94#define RTEMS_RTL_OBJ_SECT_EH    (1 << 4)  /**< Section holds exception data. */
     95#define RTEMS_RTL_OBJ_SECT_REL   (1 << 5)  /**< Section holds relocation records. */
     96#define RTEMS_RTL_OBJ_SECT_RELA  (1 << 6)  /**< Section holds relocation addend
    8997                                            *   records. */
    90 #define RTEMS_RTL_OBJ_SECT_SYM   (1 << 6)  /**< Section holds symbols. */
    91 #define RTEMS_RTL_OBJ_SECT_STR   (1 << 7)  /**< Section holds strings. */
    92 #define RTEMS_RTL_OBJ_SECT_ALLOC (1 << 8)  /**< Section allocates runtime memory. */
    93 #define RTEMS_RTL_OBJ_SECT_LOAD  (1 << 9)  /**< Section is loaded from object file. */
    94 #define RTEMS_RTL_OBJ_SECT_WRITE (1 << 10) /**< Section is writable, ie data. */
    95 #define RTEMS_RTL_OBJ_SECT_EXEC  (1 << 11) /**< Section is executable. */
    96 #define RTEMS_RTL_OBJ_SECT_ZERO  (1 << 12) /**< Section is preset to zero. */
    97 #define RTEMS_RTL_OBJ_SECT_CTOR  (1 << 13) /**< Section contains constructors. */
    98 #define RTEMS_RTL_OBJ_SECT_DTOR  (1 << 14) /**< Section contains destructors. */
     98#define RTEMS_RTL_OBJ_SECT_SYM   (1 << 7)  /**< Section holds symbols. */
     99#define RTEMS_RTL_OBJ_SECT_STR   (1 << 8)  /**< Section holds strings. */
     100#define RTEMS_RTL_OBJ_SECT_ALLOC (1 << 9)  /**< Section allocates runtime memory. */
     101#define RTEMS_RTL_OBJ_SECT_LOAD  (1 << 10) /**< Section is loaded from object file. */
     102#define RTEMS_RTL_OBJ_SECT_WRITE (1 << 11) /**< Section is writable, ie data. */
     103#define RTEMS_RTL_OBJ_SECT_EXEC  (1 << 12) /**< Section is executable. */
     104#define RTEMS_RTL_OBJ_SECT_ZERO  (1 << 13) /**< Section is preset to zero. */
     105#define RTEMS_RTL_OBJ_SECT_LINK  (1 << 14) /**< Section is link-ordered. */
     106#define RTEMS_RTL_OBJ_SECT_CTOR  (1 << 15) /**< Section contains constructors. */
     107#define RTEMS_RTL_OBJ_SECT_DTOR  (1 << 16) /**< Section contains destructors. */
     108#define RTEMS_RTL_OBJ_SECT_LOCD  (1 << 17) /**< Section has been located. */
     109
     110/**
     111 * Section types mask.
     112 */
     113#define RTEMS_RTL_OBJ_SECT_TYPES (RTEMS_RTL_OBJ_SECT_TEXT | \
     114                                  RTEMS_RTL_OBJ_SECT_CONST | \
     115                                  RTEMS_RTL_OBJ_SECT_DATA | \
     116                                  RTEMS_RTL_OBJ_SECT_BSS | \
     117                                  RTEMS_RTL_OBJ_SECT_EH)
    99118
    100119/**
     
    110129  size_t           size;        /**< The size of the section in memory. */
    111130  off_t            offset;      /**< Offset into the object file. Relative to
    112                                  * the start of the object file. */
     131                                 *   the start of the object file. */
    113132  uint32_t         alignment;   /**< Alignment of this section. */
    114133  int              link;        /**< Section link field. */
     
    117136  void*            base;        /**< The base address of the section in
    118137                                 *   memory. */
     138  int              load_order;  /**< Order we load sections. */
    119139};
    120140
     
    136156  uint32_t             flags;        /**< The status of the object file. */
    137157  uint32_t             users;        /**< References to the object file. */
     158  int                  format;       /**< The format of the object file. */
    138159  const char*          fname;        /**< The file name for the object. */
    139160  const char*          oname;        /**< The object file name. Can be
     
    154175  uint32_t             unresolved;   /**< The number of unresolved relocations. */
    155176  void*                text_base;    /**< The base address of the text section
    156                                       * in memory. */
     177                                      *   in memory. */
     178  size_t               text_size;     /**< The size of the text section. */
    157179  void*                const_base;   /**< The base address of the const section
    158                                       * in memory. */
     180                                      *   in memory. */
     181  void*                eh_base;      /**< The base address of the eh section
     182                                      *   in memory. */
     183  size_t               eh_size;      /**< The size of the eh section. */
    159184  void*                data_base;    /**< The base address of the data section
    160                                       * in memory. */
     185                                      *   in memory. */
    161186  void*                bss_base;     /**< The base address of the bss section
    162                                       * in memory. */
     187                                      *   in memory. */
    163188  size_t               bss_size;     /**< The size of the bss section. */
    164189  size_t               exec_size;    /**< The amount of executable memory
    165                                       * allocated */
     190                                      *   allocated */
    166191  void*                entry;        /**< The entry point of the module. */
    167192  uint32_t             checksum;     /**< The checksum of the text sections. A
    168                                       * zero means do not checksum. */
    169   void*                detail;       /**< The file details. It contains the elf file
    170                                       * detail, mainly including elf file name,
    171                                       * section offset, section size, which
    172                                       * elf this section belongs to.*/
     193                                      *   zero means do not checksum. */
    173194  uint32_t*            sec_num;      /**< The sec nums of each obj. */
    174195  uint32_t             obj_num;      /**< The count of elf files in an rtl obj. */
    175196  struct link_map*     linkmap;      /**< For GDB. */
     197  void*                loader;       /**< The file details specific to a loader. */
    176198};
    177199
     
    259281
    260282/**
     283 * Is the address inside the text section?
     284 *
     285 * @param obj The object file.
     286 * @return bool There is an archive name
     287 */
     288static inline bool rtems_rtl_obj_text_inside (const rtems_rtl_obj_t* obj,
     289                                              const void*            address)
     290{
     291  return
     292    (address >= obj->text_base) &&
     293    (address < (obj->text_base + obj->text_size));
     294}
     295
     296/**
    261297 * Allocate an object structure on the heap.
    262298 *
     
    299335                           const char** oname,
    300336                           off_t*       ooffset);
    301 
    302 /**
    303  * Load the object file.
    304  *
    305  * @param obj The object file's descriptor.
    306  * @param fd The file descriptor.
    307  * @param load_syms Load symbols.
    308  * @param load_dep Load dependent object files.
    309  * @retval true The load was successful.
    310  * @retval false The load failed. The RTL error has been set.
    311  */
    312 bool rtems_rtl_obj_file_load (rtems_rtl_obj_t* obj, int fd);
    313337
    314338/**
     
    372396 * @return rtems_rtl_obj_sect_t* The named section.
    373397 */
    374 rtems_rtl_obj_sect_t* rtems_rtl_obj_find_section (rtems_rtl_obj_t* obj,
    375                                                   const char*      name);
     398rtems_rtl_obj_sect_t* rtems_rtl_obj_find_section (const rtems_rtl_obj_t* obj,
     399                                                  const char*            name);
    376400
    377401/**
     
    383407 * @return rtems_rtl_obj_sect_t* The found section.
    384408 */
    385 rtems_rtl_obj_sect_t* rtems_rtl_obj_find_section_by_index (rtems_rtl_obj_t* obj,
    386                                                            int              index);
    387 
    388 /**
    389  * The text size of the object file. Only use once all the sections has been
    390  * added. It includes alignments between sections that are part of the object's
    391  * text area. The consts sections are included in this section.
     409rtems_rtl_obj_sect_t* rtems_rtl_obj_find_section_by_index (const rtems_rtl_obj_t* obj,
     410                                                           int                    index);
     411
     412/**
     413 * The text section size. Only use once all the sections has been added. It
     414 * includes alignments between sections that are part of the object's text
     415 * area. The consts sections are included in this section.
    392416 *
    393417 * @param obj The object file's descriptor.
    394418 * @return size_t The size of the text area of the object file.
    395419 */
    396 size_t rtems_rtl_obj_text_size (rtems_rtl_obj_t* obj);
    397 
    398 /**
    399  * The text section alignment of the object file. Only use once all the
     420size_t rtems_rtl_obj_text_size (const rtems_rtl_obj_t* obj);
     421
     422/**
     423 * The text section alignment for the object file. Only use once all the
    400424 * sections has been added. The section alignment is the alignment of the first
    401425 * text type section loaded the text section.
     
    407431 * @return uint32_t The alignment. Can be 0 or 1 for not aligned or the alignment.
    408432 */
    409 uint32_t rtems_rtl_obj_text_alignment (rtems_rtl_obj_t* obj);
    410 
    411 /**
    412  * The const size of the object file. Only use once all the sections has been
    413  * added. It includes alignments between sections that are part of the object's
    414  * const area. The consts sections are included in this section.
     433uint32_t rtems_rtl_obj_text_alignment (const rtems_rtl_obj_t* obj);
     434
     435/**
     436 * The const section size. Only use once all the sections has been added. It
     437 * includes alignments between sections that are part of the object's const
     438 * area. The consts sections are included in this section.
    415439 *
    416440 * @param obj The object file's descriptor.
    417441 * @return size_t The size of the const area of the object file.
    418442 */
    419 size_t rtems_rtl_obj_const_size (rtems_rtl_obj_t* obj);
    420 
    421 /**
    422  * The const section alignment of the object file. Only use once all the
     443size_t rtems_rtl_obj_const_size (const rtems_rtl_obj_t* obj);
     444
     445/**
     446 * The const section alignment for the object file. Only use once all the
    423447 * sections has been added. The section alignment is the alignment of the first
    424448 * const type section loaded the const section.
     
    430454 * @return uint32_t The alignment. Can be 0 or 1 for not aligned or the alignment.
    431455 */
    432 uint32_t rtems_rtl_obj_const_alignment (rtems_rtl_obj_t* obj);
    433 
    434 /**
    435  * The data size of the object file. Only use once all the sections has been
    436  * added. It includes alignments between sections that are part of the object's
    437  * data area.
     456uint32_t rtems_rtl_obj_const_alignment (const rtems_rtl_obj_t* obj);
     457
     458/**
     459 * The eh section size. Only use once all the sections has been added. It
     460 * includes alignments between sections that are part of the object's bss area.
     461 *
     462 * @param obj The object file's descriptor.
     463 * @return size_t The size of the bss area of the object file.
     464 */
     465size_t rtems_rtl_obj_eh_size (const rtems_rtl_obj_t* obj);
     466
     467/**
     468 * The eh section alignment for the object file. Only use once all the sections
     469 * has been added. The section alignment is the alignment of the first bss type
     470 * section loaded the bss section.
     471 *
     472 * You can assume the alignment is a positive integral power of 2 if not 0 or
     473 * 1. If 0 or 1 then there is no alignment.
     474 *
     475 * @param obj The object file's descriptor.
     476 * @return uint32_t The alignment. Can be 0 or 1 for not aligned or the alignment.
     477 */
     478uint32_t rtems_rtl_obj_eh_alignment (const rtems_rtl_obj_t* obj);
     479
     480/**
     481 * The data section size. Only use once all the sections has been added. It
     482 * includes alignments between sections that are part of the object's data
     483 * area.
    438484 *
    439485 * @param obj The object file's descriptor.
    440486 * @return size_t The size of the data area of the object file.
    441487 */
    442 size_t rtems_rtl_obj_data_size (rtems_rtl_obj_t* obj);
    443 
    444 /**
    445  * The data section alignment of the object file. Only use once all the
     488size_t rtems_rtl_obj_data_size (const rtems_rtl_obj_t* obj);
     489
     490/**
     491 * The data section alignment for the object file. Only use once all the
    446492 * sections has been added. The section alignment is the alignment of the first
    447493 * data type section loaded the data section.
     
    453499 * @return uint32_t The alignment. Can be 0 or 1 for not aligned or the alignment.
    454500 */
    455 uint32_t rtems_rtl_obj_data_alignment (rtems_rtl_obj_t* obj);
    456 
    457 /**
    458  * The bss size of the object file. Only use once all the sections has been
    459  * added. It includes alignments between sections that are part of the object's
    460  * bss area.
     501uint32_t rtems_rtl_obj_data_alignment (const rtems_rtl_obj_t* obj);
     502
     503/**
     504 * The bss section size. Only use once all the sections has been added. It
     505 * includes alignments between sections that are part of the object's bss area.
    461506 *
    462507 * @param obj The object file's descriptor.
    463508 * @return size_t The size of the bss area of the object file.
    464509 */
    465 size_t rtems_rtl_obj_bss_size (rtems_rtl_obj_t* obj);
    466 
    467 /**
    468  * The bss section alignment of the object file. Only use once all the
     510size_t rtems_rtl_obj_bss_size (const rtems_rtl_obj_t* obj);
     511
     512/**
     513 * The bss section alignment for the object file. Only use once all the
    469514 * sections has been added. The section alignment is the alignment of the first
    470515 * bss type section loaded the bss section.
     
    476521 * @return uint32_t The alignment. Can be 0 or 1 for not aligned or the alignment.
    477522 */
    478 uint32_t rtems_rtl_obj_bss_alignment (rtems_rtl_obj_t* obj);
     523uint32_t rtems_rtl_obj_bss_alignment (const rtems_rtl_obj_t* obj);
    479524
    480525/**
  • cpukit/libdl/rtl-rap.c

    rd51538bd rd2e31f7  
    428428
    429429/**
    430  * The structure of obj->detail is
     430 * The structure of obj->linkmap is:
    431431 *
    432432 * |object_detail(0..obj_num)|section_detail(0..sec_num[0..obj_num])|
     
    435435 */
    436436static bool
    437 rtems_rtl_rap_load_details (rtems_rtl_rap_t* rap, rtems_rtl_obj_t* obj)
    438 {
     437rtems_rtl_rap_load_linkmap (rtems_rtl_rap_t* rap, rtems_rtl_obj_t* obj)
     438{
     439  void*            detail;
    439440  struct link_map* tmp1;
    440   section_detail* tmp2;
    441   uint32_t obj_detail_size;
    442   uint32_t pos = 0;
    443   int i,j;
     441  section_detail*  tmp2;
     442  uint32_t         obj_detail_size;
     443  uint32_t         pos = 0;
     444  int              i;
     445  int              j;
    444446
    445447  obj_detail_size = sizeof (struct link_map) * obj->obj_num;
     
    450452  }
    451453
    452   obj->detail = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT,
    453                                      obj_detail_size + rap->strtable_size, true);
    454 
    455   if (!obj->detail)
     454  detail = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT,
     455                                obj_detail_size + rap->strtable_size, true);
     456
     457  if (!detail)
    456458  {
    457459    rap->strtable_size = 0;
     
    460462  }
    461463
    462   rap->strtable = obj->detail + obj_detail_size;
    463 
    464   /* Read the obj names and section names */
    465   if (!rtems_rtl_obj_comp_read (rap->decomp, rap->strtable,
     464  rap->strtable = detail + obj_detail_size;
     465
     466  /*
     467   *  Read the obj names and section names
     468   */
     469  if (!rtems_rtl_obj_comp_read (rap->decomp,
     470                                rap->strtable,
    466471                                rap->strtable_size))
    467472  {
    468     rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, obj->detail);
    469     return false;
    470   }
     473    rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, detail);
     474    return false;
     475  }
     476
     477  obj->linkmap = (struct link_map*) detail;
    471478
    472479  if (rtems_rtl_trace (RTEMS_RTL_TRACE_DETAIL))
     
    490497  for (i = 0; i < obj->obj_num; ++i)
    491498  {
    492     tmp1 = (struct link_map*) (obj->detail) + i;
     499    tmp1 = obj->linkmap + i;
    493500    tmp1->name = rap->strtable + pos;
    494501    tmp1->sec_num = obj->sec_num[i];
     
    510517  }
    511518
    512   tmp2 =(section_detail*) ((struct link_map*) (obj->detail) + obj->obj_num);
     519  tmp2 = (section_detail*) (obj->linkmap + obj->obj_num);
    513520
    514521  for (i = 0; i < obj->obj_num; ++i)
     
    516523    if (rtems_rtl_trace (RTEMS_RTL_TRACE_DETAIL))
    517524    {
    518       printf ("File %d: %s\n", i, ((struct link_map*) obj->detail + i)->name);
    519       printf ("Section: %d sections\n",(unsigned int) obj->sec_num[i]);
    520     }
    521 
    522     ((struct link_map*)obj->detail + i)->sec_detail = tmp2;
     525      printf ("File %d: %s\n", i, (obj->linkmap + i)->name);
     526      printf ("Section: %d sections\n", (unsigned int) obj->sec_num[i]);
     527    }
     528
     529    obj->linkmap[i].sec_detail = tmp2;
    523530
    524531    for (j = 0; j < obj->sec_num[i]; ++j)
     
    533540          !rtems_rtl_rap_read_uint32 (rap->decomp, &size))
    534541      {
    535         rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_SYMBOL, obj->detail);
     542        rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_SYMBOL, obj->linkmap);
     543        obj->linkmap = NULL;
    536544        return false;
    537545      }
     
    908916      printf ("rtl: rap: details: obj_num=%lu\n", obj->obj_num);
    909917
    910     if (!rtems_rtl_rap_load_details (&rap, obj))
     918    if (!rtems_rtl_rap_load_linkmap (&rap, obj))
    911919      return false;
    912920  }
     
    976984}
    977985
     986bool
     987rtems_rtl_rap_file_unload (rtems_rtl_obj_t* obj)
     988{
     989  (void) obj;
     990  return true;
     991}
     992
    978993rtems_rtl_loader_format_t*
    979994rtems_rtl_rap_file_sig (void)
  • cpukit/libdl/rtl-rap.h

    rd51538bd rd2e31f7  
    4242
    4343/**
     44 * The RAP format unload handler.
     45 *
     46 * @param obj The object to unload.
     47 */
     48bool rtems_rtl_rap_file_unload (rtems_rtl_obj_t* obj);
     49
     50/**
    4451 * The RAP format signature handler.
    4552 *
  • cpukit/libdl/rtl-shell.c

    rd51538bd rd2e31f7  
    2626 *  so we can't rely on prerdefines.
    2727 */
    28 #if defined(__m32r__) || defined(__moxie__)
     28#if defined(__moxie__)
    2929#define PRIdoff_t PRIo32
    3030#else
  • cpukit/libdl/rtl.c

    rd51538bd rd2e31f7  
    6363 */
    6464static rtems_rtl_data_t* rtl;
     65static bool              rtl_data_init;
    6566
    6667/**
     
    9495      rtems_status_code sc;
    9596      rtems_id          lock;
     97
     98      /*
     99       * We cannot set an error in this code because there is no RTL data to
     100       * hold it.
     101       */
     102
     103      if (rtl_data_init)
     104      {
     105        rtems_libio_unlock ();
     106        return false;
     107      }
     108
     109      rtl_data_init = true;
    96110
    97111      /*
     
    101115      if (!rtl)
    102116      {
     117        rtems_libio_unlock ();
    103118        errno = ENOMEM;
    104119        return false;
     
    121136      {
    122137        free (rtl);
     138        rtems_libio_unlock ();
    123139        return false;
    124140      }
     
    129145        rtems_semaphore_delete (lock);
    130146        free (rtl);
     147        rtems_libio_unlock ();
    131148        return false;
    132149      }
     
    144161        rtems_semaphore_delete (lock);
    145162        free (rtl);
     163        rtems_libio_unlock ();
    146164        return false;
    147165      }
     
    153171        rtems_semaphore_delete (lock);
    154172        free (rtl);
     173        rtems_libio_unlock ();
    155174        return false;
    156175      }
     
    163182        rtems_semaphore_delete (lock);
    164183        free (rtl);
     184        rtems_libio_unlock ();
    165185        return false;
    166186      }
     
    174194        rtems_semaphore_delete (lock);
    175195        free (rtl);
     196        rtems_libio_unlock ();
    176197        return false;
    177198      }
     
    186207        rtems_semaphore_delete (lock);
    187208        free (rtl);
     209        rtems_libio_unlock ();
    188210        return false;
    189211      }
     
    199221        rtems_semaphore_delete (lock);
    200222        free (rtl);
     223        rtems_libio_unlock ();
    201224        return false;
    202225      }
     
    213236        rtems_semaphore_delete (lock);
    214237        free (rtl);
     238        rtems_libio_unlock ();
    215239        return false;
    216240      }
     
    289313
    290314void
    291 rtems_rtl_obj_caches_flush ()
     315rtems_rtl_obj_caches_flush (void)
    292316{
    293317  if (rtl)
     
    439463    {
    440464      rtems_rtl_obj_free (obj);
     465      rtems_rtl_obj_caches_flush ();
    441466      return NULL;
    442467    }
     
    447472    {
    448473      rtems_rtl_obj_free (obj);
     474      rtems_rtl_obj_caches_flush ();
    449475      return NULL;
    450476    }
     477
     478    rtems_rtl_obj_caches_flush ();
    451479
    452480    rtems_rtl_unresolved_resolve ();
     
    515543
    516544    ok = rtems_rtl_obj_unload (obj);
     545
     546    rtems_rtl_obj_free (obj);
     547    rtems_rtl_obj_caches_flush ();
    517548  }
    518549
  • cpukit/libdl/rtl.h

    rd51538bd rd2e31f7  
    113113
    114114/**
    115  * Get the RTL data with out locking. This call assmes the RTL is locked.
     115 * Get the RTL data with out locking. This call assumes the RTL is locked.
    116116 *
    117117 * @return rtems_rtl_data_t* The RTL data after being locked.
  • cpukit/preinstall.am

    rd51538bd rd2e31f7  
    213213PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtl/rtl-sym.h
    214214
     215$(PROJECT_INCLUDE)/rtems/rtl/rtl-trace.h: libdl/rtl-trace.h $(PROJECT_INCLUDE)/rtems/rtl/$(dirstamp)
     216        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtl/rtl-trace.h
     217PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtl/rtl-trace.h
     218
    215219$(PROJECT_INCLUDE)/rtems/rtl/rap.h: libdl/rap.h $(PROJECT_INCLUDE)/rtems/rtl/$(dirstamp)
    216220        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtl/rap.h
  • testsuites/libtests/Makefile.am

    rd51538bd rd2e31f7  
    4545
    4646if DLTESTS
    47 _SUBDIRS += dl01 dl02
     47_SUBDIRS += dl01 dl02 dl03 dl04 dl05
    4848endif
    4949
  • testsuites/libtests/configure.ac

    rd51538bd rd2e31f7  
    128128dl01/Makefile
    129129dl02/Makefile
     130dl03/Makefile
     131dl04/Makefile
     132dl05/Makefile
    130133dumpbuf01/Makefile
    131134ftp01/Makefile
  • testsuites/libtests/dl01/dl01.scn

    rd51538bd rd2e31f7  
     1
     2
    13*** BEGIN OF TEST libdl (RTL) 1 ***
    24load: /dl-o1.o
    3 handle: 0x2137d8 loaded
    4 Loaded module: argc:2
    5 [../../../../../../../../rtems.master/c/src/../../testsuites/libtests/dl01/dl-o1.c]
     5handle: 0x2048cf0 loaded
     6Loaded module: argc:2 [/opt/work/chris/rtems/kernel/rtems.git/c/src/../../testsuites/libtests/dl01/dl-o1.c]
    67  0: Line 1
    78  1: Line 2
    8 Loaded module: argc:3
    9 [../../../../../../../../rtems.master/c/src/../../testsuites/libtests/dl01/dl-o1.c]
     9Loaded module: argc:3 [/opt/work/chris/rtems/kernel/rtems.git/c/src/../../testsuites/libtests/dl01/dl-o1.c]
    1010  0: Call 2, line 1
    1111  1: Call 2, line 2
    1212  2: Call 2, line 3
    13 handle: 0x2137d8 closed
     13handle: 0x2048cf0 closed
    1414*** END OF TEST libdl (RTL) 1 ***
  • testsuites/libtests/dl01/init.c

    rd51538bd rd2e31f7  
    7474#define CONFIGURE_EXTRA_TASK_STACKS (8 * 1024)
    7575
     76#define CONFIGURE_MAXIMUM_SEMAPHORES 1
     77
    7678#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
    7779
     
    8183
    8284#include <rtems/confdefs.h>
    83 
  • testsuites/libtests/dl02/dl02.scn

    rd51538bd rd2e31f7  
     1
     2
    13*** BEGIN OF TEST libdl (RTL) 2 ***
    24load: /dl-o1.o
    3 handle: 0x2150d0 has unresolved externals
     5handle: 0x204da80 has unresolved externals
    46load: /dl-o2.o
    5 handle: 0x215838 loaded
    6 Loaded module: argc:4
    7 [../../../../../../../../rtems.master/c/src/../../testsuites/libtests/dl02/dl-o1.c]
     7handle: 0x204ea98 loaded
     8Loaded module: argc:4 [/opt/work/chris/rtems/kernel/rtems.git/c/src/../../testsuites/libtests/dl02/dl-o1.c]
    89  0: 1
    910  1: 2
    1011  2: 3
    1112  3: 4
    12 Loaded module: argc:4
    13 [../../../../../../../../rtems.master/c/src/../../testsuites/libtests/dl02/dl-o2.c]
     13Loaded module: argc:4 [/opt/work/chris/rtems/kernel/rtems.git/c/src/../../testsuites/libtests/dl02/dl-o2.c]
    1414  0: 1
    1515  1: 2
     
    1818dl_o1_callback: string in dl_o2
    1919rtems_main: callback count: 3
    20 handle: 0x2150d0 closed
    21 handle: 0x215838 closed
     20handle: 0x204da80 closed
     21handle: 0x204ea98 closed
    2222*** END OF TEST libdl (RTL) 2 ***
  • testsuites/libtests/dl02/init.c

    rd51538bd rd2e31f7  
    7474#define CONFIGURE_EXTRA_TASK_STACKS (8 * 1024)
    7575
     76#define CONFIGURE_MAXIMUM_SEMAPHORES 1
     77
    7678#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
    7779
Note: See TracChangeset for help on using the changeset viewer.