Changeset 4408603 in rtems


Ignore:
Timestamp:
Jan 9, 2019, 11:14:11 AM (5 weeks ago)
Author:
Chris Johns <chrisj@…>
Branches:
master
Children:
d8c70ba6
Parents:
a7c6176
git-author:
Chris Johns <chrisj@…> (01/09/19 11:14:11)
git-committer:
Chris Johns <chrisj@…> (02/08/19 23:06:34)
Message:

libdl: Fix the support for constructors and desctructors.

  • Fix the handling of pending objects.
  • Add a constructor flags in objects to track then being called.

Closes #2921

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/rtems/rtl/rtl-obj.h

    ra7c6176 r4408603  
    169169                                             *   parsing. */
    170170#define RTEMS_RTL_OBJ_DEP_VISITED  (1 << 4) /**< Dependency loop detection. */
     171#define RTEMS_RTL_OBJ_CTOR_RUN     (1 << 5) /**< Constructors have been called. */
    171172
    172173/**
  • cpukit/libdl/rtl-elf.c

    ra7c6176 r4408603  
    994994        break;
    995995
     996      case SHT_INIT_ARRAY:
     997        /*
     998         * Constructors are text and need to be loaded.
     999         */
     1000        flags = (RTEMS_RTL_OBJ_SECT_CTOR |
     1001                 RTEMS_RTL_OBJ_SECT_TEXT |
     1002                 RTEMS_RTL_OBJ_SECT_LOAD);
     1003        break;
     1004
     1005      case SHT_FINI_ARRAY:
     1006        /*
     1007         * Destructors are text and need to be loaded.
     1008         */
     1009        flags = (RTEMS_RTL_OBJ_SECT_DTOR |
     1010                 RTEMS_RTL_OBJ_SECT_TEXT |
     1011                 RTEMS_RTL_OBJ_SECT_LOAD);
     1012        break;
     1013
    9961014      default:
    9971015        /*
     
    10201038        flags |= RTEMS_RTL_OBJ_SECT_LINK;
    10211039
     1040      /*
     1041       * Some architexctures support a named PROGBIT section for INIT/FINI.
     1042       */
    10221043      len = RTEMS_RTL_ELF_STRING_MAX;
    10231044      if (!rtems_rtl_obj_cache_read (strings, fd,
  • cpukit/libdl/rtl-mdreloc-arm.c

    ra7c6176 r4408603  
    88
    99#include <errno.h>
     10#include <inttypes.h>
    1011#include <stdio.h>
    1112#include <string.h>
     
    194195    case R_TYPE(GLOB_DAT):  /* word32 (S + A) | T */
    195196    case R_TYPE(PREL31):    /* word32 (S + A) | T - P */
     197    case R_TYPE(TARGET1):   /* Equivalent to ABS32 */
    196198    case R_TYPE(TARGET2):   /* Equivalent to REL32 */
    197199      if (__predict_true(RELOC_ALIGNED_P(where))) {
     
    250252
    251253    case R_TYPE(THM_JUMP24):
    252       /* same to THM_CALL; insn b.w */
    253     case R_TYPE(THM_CALL):
     254      /* same as THM_PC22; insn b.w */
     255    case R_TYPE(THM_PC22):
    254256      upper_insn = *(uint16_t *)where;
    255257      lower_insn = *((uint16_t *)where + 1);
     
    323325
    324326      if (((Elf_Sword)tmp > 0x7ffffe) || ((Elf_Sword)tmp < -0x800000)) {
    325         rtems_rtl_set_error (EINVAL, "%s: Overflow %ld "
     327        rtems_rtl_set_error (EINVAL, "%s: Overflow %" PRIu32 " "
    326328                             "THM_JUMP19 relocations",
    327329                             sect->name, (uint32_t) ELF_R_TYPE(rel->r_info));
     
    343345
    344346    default:
    345       printf ("rtl: reloc unknown: sym = %lu, type = %lu, offset = %p, "
     347      printf ("rtl: reloc unknown: sym = %" PRIu32 ", type = %" PRIu32 ", offset = %p, "
    346348              "contents = %p\n",
    347349              ELF_R_SYM(rel->r_info), (uint32_t) ELF_R_TYPE(rel->r_info),
    348350              (void *)rel->r_offset, (void *)*where);
    349351      rtems_rtl_set_error (EINVAL,
    350                            "%s: Unsupported relocation type %ld "
     352                           "%s: Unsupported relocation type %" PRIu32 " "
    351353                           "in non-PLT relocations",
    352354                           sect->name, (uint32_t) ELF_R_TYPE(rel->r_info));
  • cpukit/libdl/rtl-unresolved.c

    ra7c6176 r4408603  
    182182    {
    183183      if (rtems_rtl_trace (RTEMS_RTL_TRACE_UNRESOLVED))
    184         printf ("rtl: unresolv: resolve reloc: %s\n", rd->name_rec->rec.name.name);
     184        printf ("rtl: unresolv: resolve reloc: %s\n",
     185                rd->name_rec->rec.name.name);
    185186
    186187      rtems_rtl_obj_relocate_unresolved (&rec->rec.reloc, rd->sym);
     
    194195      {
    195196        pending = rtems_rtl_pending_unprotected ();
     197        rtems_chain_extract (&rec->rec.reloc.obj->link);
    196198        rtems_chain_append (pending, &rec->rec.reloc.obj->link);
    197199      }
  • cpukit/libdl/rtl.c

    ra7c6176 r4408603  
    513513    }
    514514
     515    rtems_chain_append (&rtl->pending, &obj->link);
     516
    515517    /*
    516518     * Find the file in the file system using the search path. The fname field
     
    524526    }
    525527
    526     rtems_chain_append (&rtl->pending, &obj->link);
    527 
    528528    if (!rtems_rtl_obj_load (obj))
    529529    {
     
    532532      rtems_rtl_obj_caches_flush ();
    533533      return NULL;
     534    }
     535
     536    /*
     537     * If there are unresolved externals remove from the pending queue and place
     538     * on the objects list until the symbols are resolved.
     539     */
     540    if (obj->unresolved != 0)
     541    {
     542      rtems_chain_extract (&obj->link);
     543      rtems_chain_append (&rtl->objects, &obj->link);
    534544    }
    535545
     
    573583    while (!rtems_chain_is_tail (&rtl->pending, node))
    574584    {
    575       rtems_rtl_obj* obj = (rtems_rtl_obj*) node;
     585      rtems_rtl_obj* pobj = (rtems_rtl_obj*) node;
    576586
    577587      /*
     
    579589       * RTL's objects list.
    580590       */
    581       node = rtems_chain_next (&obj->link);
    582       rtems_chain_extract (&obj->link);
    583       rtems_chain_append (&rtl->objects, &obj->link);
     591      node = rtems_chain_next (&pobj->link);
     592      rtems_chain_extract (&pobj->link);
     593      rtems_chain_append (&rtl->objects, &pobj->link);
    584594
    585595      /*
    586596       * Make sure the object file and cache is synchronized.
    587597       */
    588       rtems_rtl_obj_synchronize_cache (obj);
    589 
    590       /*
    591        * Run any local constructors if this is the first user because the
    592        * object file will have just been loaded. Unlock the linker to avoid any
    593        * dead locks if the object file needs to load files or update the symbol
    594        * table. We also do not want a constructor to unload this object file.
    595        */
    596       if (obj->users == 1)
    597       {
    598         obj->flags |= RTEMS_RTL_OBJ_LOCKED;
     598      rtems_rtl_obj_synchronize_cache (pobj);
     599
     600      /*
     601       * Run any local constructors if they have not been run. Unlock the linker
     602       * to avoid any dead locks if the object file needs to load files or
     603       * update the symbol table. We also do not want a constructor to unload
     604       * this object file.
     605       */
     606      if ((pobj->flags & RTEMS_RTL_OBJ_CTOR_RUN) == 0)
     607      {
     608        pobj->flags |= RTEMS_RTL_OBJ_LOCKED | RTEMS_RTL_OBJ_CTOR_RUN;
    599609        rtems_rtl_unlock ();
    600         rtems_rtl_obj_run_ctors (obj);
     610        rtems_rtl_obj_run_ctors (pobj);
    601611        rtems_rtl_lock ();
    602         obj->flags &= ~RTEMS_RTL_OBJ_LOCKED;
     612        pobj->flags &= ~RTEMS_RTL_OBJ_LOCKED;
    603613      }
    604614    }
     
    624634
    625635  /*
    626    * Move the object file from the objects list to the pending list if unloaded.
     636   * The object file cannot be unloaded if it is referenced.
    627637   */
    628638  if (rtems_rtl_obj_get_reference (obj) > 0)
     
    650660    rtems_chain_control unloading;
    651661    rtems_chain_node*   node;
     662    bool                orphaned_found = true;
     663    int                 loop = 0;
    652664
    653665    /*
    654      * Remove the orphaned object files from the objects list. This makes the
    655      * list private and any changes in any desctructors will effect the run.
     666     * Remove the orphaned object files from the objects list. The unloading is
     667     * private so any changes in any desctructors will not effect the list as it
     668     * is being iterated over.
     669     *
     670     * To avoid maintaining a complex tree loop while oprhans are still be found.
    656671     */
     672
    657673    rtems_chain_initialize_empty (&unloading);
    658674
    659     node = rtems_chain_first (&rtl->objects);
    660     while (!rtems_chain_is_tail (&rtl->objects, node))
    661     {
    662       rtems_chain_node* next_node = rtems_chain_next (node);
    663       rtems_rtl_obj* uobj = (rtems_rtl_obj*) node;
    664       if (rtems_rtl_trace (RTEMS_RTL_TRACE_UNLOAD))
    665         printf ("rtl: unload object: %s: %s\n",
    666                 rtems_rtl_obj_oname (obj),
    667                 rtems_rtl_obj_orphaned (uobj) ? "orphaned" : "inuse");
    668       if (rtems_rtl_obj_orphaned (uobj))
    669       {
    670         rtems_rtl_obj_remove_dependencies (uobj);
    671         rtems_chain_extract (&uobj->link);
    672         rtems_chain_append (&unloading, &uobj->link);
    673         uobj->flags |= RTEMS_RTL_OBJ_LOCKED;
    674       }
    675       node = next_node;
     675    while (orphaned_found)
     676    {
     677      orphaned_found = false;
     678      ++loop;
     679      node = rtems_chain_first (&rtl->objects);
     680      while (!rtems_chain_is_tail (&rtl->objects, node))
     681      {
     682        rtems_chain_node* next_node = rtems_chain_next (node);
     683        rtems_rtl_obj* uobj = (rtems_rtl_obj*) node;
     684        if (rtems_rtl_trace (RTEMS_RTL_TRACE_UNLOAD))
     685          printf ("rtl: unload object: %3i: %9s: %s\n",
     686                  loop,
     687                  rtems_rtl_obj_orphaned (uobj) ? "orphaned" : "inuse",
     688                  rtems_rtl_obj_oname (uobj));
     689        if (rtems_rtl_obj_orphaned (uobj))
     690        {
     691          orphaned_found = true;
     692          rtems_rtl_obj_remove_dependencies (uobj);
     693          rtems_chain_extract (&uobj->link);
     694          rtems_chain_append (&unloading, &uobj->link);
     695          uobj->flags |= RTEMS_RTL_OBJ_LOCKED;
     696        }
     697        node = next_node;
     698      }
    676699    }
    677700
     
    685708    {
    686709      rtems_rtl_obj* uobj = (rtems_rtl_obj*) node;
    687       rtems_rtl_obj_run_dtors (uobj);
     710      if ((uobj->flags & RTEMS_RTL_OBJ_CTOR_RUN) != 0)
     711      {
     712        rtems_rtl_obj_run_dtors (uobj);
     713        uobj->flags &= ~RTEMS_RTL_OBJ_CTOR_RUN;
     714      }
    688715      node = rtems_chain_next (node);
    689716    }
  • cpukit/score/cpu/arm/include/machine/elf_machdep.h

    ra7c6176 r4408603  
    1 /*      $NetBSD: elf_machdep.h,v 1.8 2009/05/30 05:56:52 skrll Exp $    */
     1/*      $NetBSD: elf_machdep.h,v 1.19 2017/11/06 03:47:45 christos Exp $        */
     2
     3#ifndef _ARM_ELF_MACHDEP_H_
     4#define _ARM_ELF_MACHDEP_H_
    25
    36#if defined(__ARMEB__)
     
    2528#define EF_ARM_OLD_ABI          0x00000100
    2629#define EF_ARM_SOFT_FLOAT       0x00000200
     30#define EF_ARM_BE8              0x00800000
    2731#define EF_ARM_EABIMASK         0xff000000
     32#define EF_ARM_EABI_VER1        0x01000000
     33#define EF_ARM_EABI_VER2        0x02000000
     34#define EF_ARM_EABI_VER3        0x03000000
     35#define EF_ARM_EABI_VER4        0x04000000
     36#define EF_ARM_EABI_VER5        0x05000000
    2837
    2938#define ELF32_MACHDEP_ID_CASES                                          \
     
    3342#define ELF32_MACHDEP_ID        EM_ARM
    3443
     44#define KERN_ELFSIZE            32
    3545#define ARCH_ELFSIZE            32      /* MD native binary size */
    3646
     
    4757#define R_ARM_ABS8              8
    4858#define R_ARM_SBREL32           9
    49 #define R_ARM_THM_CALL  10
     59#define R_ARM_THM_PC22          10
    5060#define R_ARM_THM_PC8           11
    5161#define R_ARM_AMP_VCALL9        12
     
    6979#define R_ARM_GOT32             26
    7080#define R_ARM_PLT32             27
    71 #define R_ARM_CALL        28
    72 #define R_ARM_JUMP24      29
     81#define R_ARM_CALL              28
     82#define R_ARM_JUMP24            29
    7383#define R_ARM_THM_JUMP24        30
    74 #define R_ARM_BASE_ABS          31
    75 
     84#define R_ARM_BASE_ABS          31
    7685#define R_ARM_ALU_PCREL_7_0     32
    7786#define R_ARM_ALU_PCREL_15_8    33
     
    7988#define R_ARM_ALU_SBREL_11_0    35
    8089#define R_ARM_ALU_SBREL_19_12   36
    81 #define R_ARM_ALU_SBREL_27_20   37
    82 #define R_ARM_V4BX        40
    83 #define R_ARM_TARGET2     41
    84 #define R_ARM_PREL31      42
    85 
    86 #define R_ARM_MOVW_ABS_NC     43
    87 #define R_ARM_MOVT_ABS        44
    88 
    89 #define R_ARM_THM_MOVW_ABS_NC 47
    90 #define R_ARM_THM_MOVT_ABS    48
    91 
    92 #define R_ARM_THM_JUMP19      51
     90#define R_ARM_ALU_SBREL_27_20   37      // depcreated
     91#define R_ARM_TARGET1           38
     92#define R_ARM_SBREL31           39      // deprecated
     93#define R_ARM_V4BX              40
     94#define R_ARM_TARGET2           41
     95#define R_ARM_PREL31            42
     96#define R_ARM_MOVW_ABS_NC       43
     97#define R_ARM_MOVT_ABS          44
     98#define R_ARM_MOVW_PREL_NC      45
     99#define R_ARM_MOVT_PREL         46
     100#define R_ARM_THM_MOVW_ABS_NC   47
     101#define R_ARM_THM_MOVT_ABS      48
     102#define R_ARM_THM_MOVW_PREL_NC  49
     103#define R_ARM_THM_MOVT_PREL     50
     104#define R_ARM_THM_JUMP19        51
    93105
    94106/* 96-111 are reserved to G++. */
    95107#define R_ARM_GNU_VTENTRY       100
    96108#define R_ARM_GNU_VTINHERIT     101
    97 #define R_ARM_THM_JUMP11                102
    98 #define R_ARM_THM_JUMP8         103
     109#define R_ARM_THM_PC11          102
     110#define R_ARM_THM_PC9           103
    99111
    100112/* More TLS relocations */
     
    109121
    110122/* 112-127 are reserved for private experiments. */
     123
     124#define R_ARM_IRELATIVE         160
    111125
    112126#define R_ARM_RXPC25            249
     
    125139#define PF_ARM_ENTRY            0x80000000
    126140
     141/* Processor specific program header types */
     142#define PT_ARM_EXIDX            (PT_LOPROC + 1)
     143
    127144/* Processor specific section header flags */
    128145#define SHF_ENTRYSECT           0x10000000
     
    131148/* Processor specific symbol types */
    132149#define STT_ARM_TFUNC           STT_LOPROC
     150
     151#ifdef _KERNEL
     152#ifdef ELFSIZE
     153#define ELF_MD_PROBE_FUNC       ELFNAME2(arm_netbsd,probe)
     154#define ELF_MD_COREDUMP_SETUP   ELFNAME2(arm_netbsd,coredump_setup)
     155#endif
     156
     157struct exec_package;
     158
     159int arm_netbsd_elf32_probe(struct lwp *, struct exec_package *, void *, char *,
     160        vaddr_t *);
     161void arm_netbsd_elf32_coredump_setup(struct lwp *, void *);
     162#endif
     163
     164#endif /* _ARM_ELF_MACHDEP_H_ */
  • testsuites/libtests/dl08/dl-load.c

    ra7c6176 r4408603  
    127127  dl_load_dump ();
    128128
    129   printf ("\n\n\nRunning rtems_main_o1:\n\n");
     129  printf ("Running rtems_main_o1:\n");
    130130  if (dl_call (o1, "rtems_main_o1"))
    131131    return 1;
Note: See TracChangeset for help on using the changeset viewer.