[RFC] libdl: Make Elf_Sym::st_other available

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Feb 27 07:46:58 UTC 2024


The 64-bit PowerPC ELFv2 relocation support needs access to the
Elf_Sym::st_other symbol information.  The machine-specific relocation handler
had only access to the Elf_Sym::st_info symbol information.  This change
extends the 8-bit syminfo parameter to 16-bit and uses the additional
8-bits to provide Elf_Sym::st_other.  Another approach could be to pass
a pointer to an Elf_Sym object instead of symname, syminfo, and
symvalue.

Update #4996.
---
 cpukit/libdl/rtl-elf.c             | 12 ++++++------
 cpukit/libdl/rtl-elf.h             |  8 ++++----
 cpukit/libdl/rtl-mdreloc-powerpc.c | 10 +++++-----
 3 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/cpukit/libdl/rtl-elf.c b/cpukit/libdl/rtl-elf.c
index dddf9aceab..cf56929198 100644
--- a/cpukit/libdl/rtl-elf.c
+++ b/cpukit/libdl/rtl-elf.c
@@ -275,7 +275,7 @@ rtems_rtl_elf_reloc_parser (rtems_rtl_obj*      obj,
               (uintmax_t) symvalue, (int) ELF_R_TYPE (rela->r_info),
               (uintmax_t) rela->r_offset, (int) rela->r_addend);
     rs = rtems_rtl_elf_relocate_rela_tramp (obj, rela, targetsect,
-                                            symname, sym->st_info, symvalue);
+                                            symname, (sym->st_other << 8) | sym->st_info, symvalue);
     rel_words[REL_R_OFFSET] = rela->r_offset;
     rel_words[REL_R_INFO] = rela->r_info;
     rel_words[REL_R_ADDEND] = rela->r_addend;
@@ -392,7 +392,7 @@ rtems_rtl_elf_reloc_relocator (rtems_rtl_obj*      obj,
                 (uintmax_t) symvalue, (int) ELF_R_TYPE (rela->r_info),
                 (uintmax_t) rela->r_offset, (int) rela->r_addend);
       rs = rtems_rtl_elf_relocate_rela (obj, rela, targetsect,
-                                        symname, sym->st_info, symvalue);
+                                        symname, (sym->st_other << 8) | sym->st_info, symvalue);
       if (rs != rtems_rtl_elf_rel_no_error)
         return false;
     }
@@ -404,7 +404,7 @@ rtems_rtl_elf_reloc_relocator (rtems_rtl_obj*      obj,
                 (uintmax_t) symvalue, (int) ELF_R_TYPE (rel->r_info),
                 (uintmax_t) rel->r_offset);
       rs = rtems_rtl_elf_relocate_rel (obj, rel, targetsect,
-                                       symname, sym->st_info, symvalue);
+                                       symname, (sym->st_other << 8) | sym->st_info, symvalue);
       if (rs != rtems_rtl_elf_rel_no_error)
         return false;
     }
@@ -1217,7 +1217,7 @@ rtems_rtl_elf_symbols_load (rtems_rtl_obj*      obj,
         memcpy (string, name, strlen (name) + 1);
         osym->name = string;
         osym->value = (void*) (intptr_t) value;
-        osym->data = symbol.st_shndx;
+        osym->data = (symbol.st_other << 8) | symbol.st_shndx;
 
         if (rtems_rtl_trace (RTEMS_RTL_TRACE_SYMBOL))
           printf ("rtl: sym:add:%-4d name:%-4d: %-20s: bind:%-2d " \
@@ -1246,7 +1246,7 @@ rtems_rtl_elf_symbols_locate (rtems_rtl_obj*      obj,
   {
       rtems_rtl_obj_sym*  osym = &obj->local_table[sym];
       rtems_rtl_obj_sect* symsect;
-      symsect = rtems_rtl_obj_find_section_by_index (obj, osym->data);
+      symsect = rtems_rtl_obj_find_section_by_index (obj, osym->data & 0xff);
       if (symsect)
       {
         osym->value += (intptr_t) symsect->base;
@@ -1261,7 +1261,7 @@ rtems_rtl_elf_symbols_locate (rtems_rtl_obj*      obj,
   {
       rtems_rtl_obj_sym*  osym = &obj->global_table[sym];
       rtems_rtl_obj_sect* symsect;
-      symsect = rtems_rtl_obj_find_section_by_index (obj, osym->data);
+      symsect = rtems_rtl_obj_find_section_by_index (obj, osym->data & 0xff);
       if (symsect)
       {
         osym->value += (intptr_t) symsect->base;
diff --git a/cpukit/libdl/rtl-elf.h b/cpukit/libdl/rtl-elf.h
index 0476c1ecd7..98b460e6f4 100644
--- a/cpukit/libdl/rtl-elf.h
+++ b/cpukit/libdl/rtl-elf.h
@@ -185,7 +185,7 @@ rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rel_tramp (rtems_rtl_obj*
                                                            const Elf_Rel*            rel,
                                                            const rtems_rtl_obj_sect* sect,
                                                            const char*               symname,
-                                                           const Elf_Byte            syminfo,
+                                                           const Elf_Half            syminfo,
                                                            const Elf_Word            symvalue);
 
 /**
@@ -205,7 +205,7 @@ rtems_rtl_elf_rel_status  rtems_rtl_elf_relocate_rela_tramp (rtems_rtl_obj*
                                                              const Elf_Rela*           rela,
                                                              const rtems_rtl_obj_sect* sect,
                                                              const char*               symname,
-                                                             const Elf_Byte            syminfo,
+                                                             const Elf_Half            syminfo,
                                                              const Elf_Word            symvalue);
 
 /**
@@ -225,7 +225,7 @@ rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rel (rtems_rtl_obj*            o
                                                      const Elf_Rel*            rel,
                                                      const rtems_rtl_obj_sect* sect,
                                                      const char*               symname,
-                                                     const Elf_Byte            syminfo,
+                                                     const Elf_Half            syminfo,
                                                      const Elf_Word            symvalue);
 
 /**
@@ -245,7 +245,7 @@ rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rela (rtems_rtl_obj*
                                                       const Elf_Rela*           rela,
                                                       const rtems_rtl_obj_sect* sect,
                                                       const char*               symname,
-                                                      const Elf_Byte            syminfo,
+                                                      const Elf_Half            syminfo,
                                                       const Elf_Word            symvalue);
 
 /**
diff --git a/cpukit/libdl/rtl-mdreloc-powerpc.c b/cpukit/libdl/rtl-mdreloc-powerpc.c
index 09e4f49a19..b8962c5689 100644
--- a/cpukit/libdl/rtl-mdreloc-powerpc.c
+++ b/cpukit/libdl/rtl-mdreloc-powerpc.c
@@ -262,7 +262,7 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj*            obj,
                           const Elf_Rela*           rela,
                           const rtems_rtl_obj_sect* sect,
                           const char*               symname,
-                          const Elf_Byte            syminfo,
+                          const Elf_Half            syminfo,
                           const Elf_Word            symvalue,
                           const bool                parsing)
 {
@@ -667,7 +667,7 @@ rtems_rtl_elf_relocate_rela_tramp (rtems_rtl_obj*            obj,
                                    const Elf_Rela*           rela,
                                    const rtems_rtl_obj_sect* sect,
                                    const char*               symname,
-                                   const Elf_Byte            syminfo,
+                                   const Elf_Half            syminfo,
                                    const Elf_Word            symvalue)
 {
   return rtems_rtl_elf_reloc_rela (obj,
@@ -684,7 +684,7 @@ rtems_rtl_elf_relocate_rela (rtems_rtl_obj*            obj,
                              const Elf_Rela*           rela,
                              const rtems_rtl_obj_sect* sect,
                              const char*               symname,
-                             const Elf_Byte            syminfo,
+                             const Elf_Half            syminfo,
                              const Elf_Word            symvalue)
 {
   return rtems_rtl_elf_reloc_rela (obj,
@@ -701,7 +701,7 @@ rtems_rtl_elf_relocate_rel_tramp (rtems_rtl_obj*            obj,
                                   const Elf_Rel*            rel,
                                   const rtems_rtl_obj_sect* sect,
                                   const char*               symname,
-                                  const Elf_Byte            syminfo,
+                                  const Elf_Half            syminfo,
                                   const Elf_Word            symvalue)
 {
   (void) obj;
@@ -719,7 +719,7 @@ rtems_rtl_elf_relocate_rel (rtems_rtl_obj*            obj,
                             const Elf_Rel*            rel,
                             const rtems_rtl_obj_sect* sect,
                             const char*               symname,
-                            const Elf_Byte            syminfo,
+                            const Elf_Half            syminfo,
                             const Elf_Word            symvalue)
 {
   (void) obj;
-- 
2.35.3



More information about the devel mailing list