Changeset 327e45da in rtems


Ignore:
Timestamp:
May 14, 2019, 12:34:32 AM (6 weeks ago)
Author:
Chris Johns <chrisj@…>
Branches:
master
Children:
10251b3
Parents:
5fa893e
git-author:
Chris Johns <chrisj@…> (05/14/19 00:34:32)
git-committer:
Chris Johns <chrisj@…> (05/21/19 23:28:06)
Message:

libdl: Sort object file symbols and use a binary search to find

  • Replace the linear object file symbol search with a binary search.
  • Sort the object file symbols after loading.

Closes #3748

Location:
cpukit
Files:
3 edited

Legend:

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

    r5fa893e r327e45da  
    9898
    9999/**
     100 * Sort an object file's local and global symbol table. This needs to
     101 * be done before calling @ref rtems_rtl_symbol_obj_find as it
     102 * performs a binary search on the tables.
     103 *
     104 * @param obj The object file to sort.
     105 */
     106void rtems_rtl_symbol_obj_sort (rtems_rtl_obj* obj);
     107
     108/**
    100109 * Find a symbol given the symbol label in the local object file.
    101110 *
  • cpukit/libdl/rtl-obj.c

    r5fa893e r327e45da  
    915915{
    916916  uint32_t mask = RTEMS_RTL_OBJ_SECT_SYM;
    917   return rtems_rtl_obj_section_handler (mask, obj, fd, handler, data);
     917  bool     ok;
     918  ok = rtems_rtl_obj_section_handler (mask, obj, fd, handler, data);
     919  if (ok)
     920    rtems_rtl_symbol_obj_sort (obj);
     921  return ok;
    918922}
    919923
  • cpukit/libdl/rtl-sym.c

    r5fa893e r327e45da  
    201201}
    202202
     203static int
     204rtems_rtl_symbol_obj_compare (const void* a, const void* b)
     205{
     206  const rtems_rtl_obj_sym* sa;
     207  const rtems_rtl_obj_sym* sb;
     208  sa = (const rtems_rtl_obj_sym*) a;
     209  sb = (const rtems_rtl_obj_sym*) b;
     210  return strcmp (sa->name, sb->name);
     211}
     212
     213void
     214rtems_rtl_symbol_obj_sort (rtems_rtl_obj* obj)
     215{
     216  qsort (obj->local_table,
     217         obj->local_syms,
     218         sizeof (rtems_rtl_obj_sym),
     219         rtems_rtl_symbol_obj_compare);
     220  qsort (obj->global_table,
     221         obj->global_syms,
     222         sizeof (rtems_rtl_obj_sym),
     223         rtems_rtl_symbol_obj_compare);
     224}
     225
    203226rtems_rtl_obj_sym*
    204227rtems_rtl_symbol_obj_find (rtems_rtl_obj* obj, const char* name)
    205228{
    206   rtems_rtl_obj_sym* sym;
    207   size_t             s;
    208229  /*
    209230   * Check the object file's symbols first. If not found search the
     
    212233  if (obj->local_syms)
    213234  {
    214     for (s = 0, sym = obj->local_table; s < obj->local_syms; ++s, ++sym)
    215       if (strcmp (name, sym->name) == 0)
    216         return sym;
     235    rtems_rtl_obj_sym* match;
     236    rtems_rtl_obj_sym  key = { 0 };
     237    key.name = name;
     238    match = bsearch (&key, obj->local_table,
     239                     obj->local_syms,
     240                     sizeof (rtems_rtl_obj_sym),
     241                     rtems_rtl_symbol_obj_compare);
     242    if (match != NULL)
     243      return match;
    217244  }
    218245  if (obj->global_syms)
    219246  {
    220     for (s = 0, sym = obj->global_table; s < obj->global_syms; ++s, ++sym)
    221       if (strcmp (name, sym->name) == 0)
    222         return sym;
     247    rtems_rtl_obj_sym* match;
     248    rtems_rtl_obj_sym  key = { 0 };
     249    key.name = name;
     250    match = bsearch (&key, obj->global_table,
     251                     obj->global_syms,
     252                     sizeof (rtems_rtl_obj_sym),
     253                     rtems_rtl_symbol_obj_compare);
     254    if (match != NULL)
     255      return match;
    223256  }
    224257  return rtems_rtl_symbol_global_find (name);
Note: See TracChangeset for help on using the changeset viewer.