From 5500232a8989ecad90a44a1051896ad9b53d6732 Mon Sep 17 00:00:00 2001 From: Ryan Long Date: Mon, 8 Aug 2022 09:23:48 -0500 Subject: libdl: Refactor shared code in ARM and AArch64 rtl-mdreloc-arm.c was used as the basis for rtl-mdreloc-aarch64.c. This lead to some code being shared by the two files. The code was consolidated into rtl-unwind-arm.c. Closes #4686 --- cpukit/libdl/rtl-mdreloc-aarch64.c | 81 +------------------------------------- cpukit/libdl/rtl-mdreloc-arm.c | 79 +------------------------------------ cpukit/libdl/rtl-unwind-arm.c | 65 ++++++++++++++++++++++++++++++ cpukit/libdl/rtl-unwind-arm.h | 46 ++++++++++++++++++++++ spec/build/cpukit/objdlaarch64.yml | 1 + spec/build/cpukit/objdlarm.yml | 1 + 6 files changed, 115 insertions(+), 158 deletions(-) create mode 100644 cpukit/libdl/rtl-unwind-arm.c create mode 100644 cpukit/libdl/rtl-unwind-arm.h diff --git a/cpukit/libdl/rtl-mdreloc-aarch64.c b/cpukit/libdl/rtl-mdreloc-aarch64.c index 41147e285c..c60ecb31c9 100644 --- a/cpukit/libdl/rtl-mdreloc-aarch64.c +++ b/cpukit/libdl/rtl-mdreloc-aarch64.c @@ -73,16 +73,12 @@ __RCSID("$NetBSD: mdreloc.c,v 1.14 2020/06/16 21:01:30 joerg Exp $"); #include #include #include -#include #include #include "rtl-elf.h" #include "rtl-error.h" #include -#include "rtl-unwind.h" - -typedef unsigned _Unwind_Word __attribute__((__mode__(__word__))); -typedef _Unwind_Word _uw; +#include "rtl-unwind-arm.h" struct tls_data { size_t td_tlsindex; @@ -522,78 +518,3 @@ rtems_rtl_elf_relocate_rel (rtems_rtl_obj* obj, rtems_rtl_set_error (EINVAL, "rela type record not supported"); return rtems_rtl_elf_rel_failure; } - -bool -rtems_rtl_elf_unwind_parse (const rtems_rtl_obj* obj, - const char* name, - uint32_t flags) -{ - /* - * We location the EH sections in section flags. - */ - return false; -} - -bool -rtems_rtl_elf_unwind_register (rtems_rtl_obj* obj) -{ - return true; -} - -bool -rtems_rtl_elf_unwind_deregister (rtems_rtl_obj* obj) -{ - obj->loader = NULL; - return true; -} - -/* An exception index table entry. */ -typedef struct __EIT_entry -{ - _uw fnoffset; - _uw content; -} __EIT_entry; - -/* The exception index table location in the base module */ -extern __EIT_entry __exidx_start; -extern __EIT_entry __exidx_end; - -/* - * A weak reference is in libgcc, provide a real version and provide a way to - * manage loaded modules. - * - * Passed in the return address and a reference to the number of records - * found. We set the start of the exidx data and the number of records. - */ -_Unwind_Ptr __gnu_Unwind_Find_exidx (_Unwind_Ptr return_address, - int* nrec) __attribute__ ((__noinline__, - __used__, - __noclone__)); - -_Unwind_Ptr __gnu_Unwind_Find_exidx (_Unwind_Ptr return_address, - int* nrec) -{ - rtems_rtl_data* rtl; - rtems_chain_node* node; - __EIT_entry* exidx_start = &__exidx_start; - __EIT_entry* exidx_end = &__exidx_end; - - rtl = rtems_rtl_lock (); - - node = rtems_chain_first (&rtl->objects); - while (!rtems_chain_is_tail (&rtl->objects, node)) { - rtems_rtl_obj* obj = (rtems_rtl_obj*) node; - if (rtems_rtl_obj_text_inside (obj, (void*) return_address)) { - exidx_start = (__EIT_entry*) obj->eh_base; - exidx_end = (__EIT_entry*) (obj->eh_base + obj->eh_size); - break; - } - node = rtems_chain_next (node); - } - - rtems_rtl_unlock (); - - *nrec = exidx_end - exidx_start; - - return (_Unwind_Ptr) exidx_start; -} diff --git a/cpukit/libdl/rtl-mdreloc-arm.c b/cpukit/libdl/rtl-mdreloc-arm.c index 4950dcdab1..fbfd42dc58 100644 --- a/cpukit/libdl/rtl-mdreloc-arm.c +++ b/cpukit/libdl/rtl-mdreloc-arm.c @@ -12,14 +12,12 @@ #include #include #include -#include -#include #include #include "rtl-elf.h" #include "rtl-error.h" #include -#include "rtl-unwind.h" +#include "rtl-unwind-arm.h" /* * Set to 1 to allow untested relocations. If you tested one and it @@ -597,78 +595,3 @@ rtems_rtl_elf_relocate_rel (rtems_rtl_obj* obj, symvalue, false); } - -bool -rtems_rtl_elf_unwind_parse (const rtems_rtl_obj* obj, - const char* name, - uint32_t flags) -{ - /* - * We location the EH sections in section flags. - */ - return false; -} - -bool -rtems_rtl_elf_unwind_register (rtems_rtl_obj* obj) -{ - return true; -} - -bool -rtems_rtl_elf_unwind_deregister (rtems_rtl_obj* obj) -{ - obj->loader = NULL; - return true; -} - -/* An exception index table entry. */ -typedef struct __EIT_entry -{ - _uw fnoffset; - _uw content; -} __EIT_entry; - -/* The exception index table location in the base module */ -extern __EIT_entry __exidx_start; -extern __EIT_entry __exidx_end; - -/* - * A weak reference is in libgcc, provide a real version and provide a way to - * manage loaded modules. - * - * Passed in the return address and a reference to the number of records - * found. We set the start of the exidx data and the number of records. - */ -_Unwind_Ptr __gnu_Unwind_Find_exidx (_Unwind_Ptr return_address, - int* nrec) __attribute__ ((__noinline__, - __used__, - __noclone__)); - -_Unwind_Ptr __gnu_Unwind_Find_exidx (_Unwind_Ptr return_address, - int* nrec) -{ - rtems_rtl_data* rtl; - rtems_chain_node* node; - __EIT_entry* exidx_start = &__exidx_start; - __EIT_entry* exidx_end = &__exidx_end; - - rtl = rtems_rtl_lock (); - - node = rtems_chain_first (&rtl->objects); - while (!rtems_chain_is_tail (&rtl->objects, node)) { - rtems_rtl_obj* obj = (rtems_rtl_obj*) node; - if (rtems_rtl_obj_text_inside (obj, (void*) return_address)) { - exidx_start = (__EIT_entry*) obj->eh_base; - exidx_end = (__EIT_entry*) (obj->eh_base + obj->eh_size); - break; - } - node = rtems_chain_next (node); - } - - rtems_rtl_unlock (); - - *nrec = exidx_end - exidx_start; - - return (_Unwind_Ptr) exidx_start; -} diff --git a/cpukit/libdl/rtl-unwind-arm.c b/cpukit/libdl/rtl-unwind-arm.c new file mode 100644 index 0000000000..35361fe8d5 --- /dev/null +++ b/cpukit/libdl/rtl-unwind-arm.c @@ -0,0 +1,65 @@ +#include "rtl-unwind-arm.h" + +bool +rtems_rtl_elf_unwind_parse (const rtems_rtl_obj* obj, + const char* name, + uint32_t flags) +{ + /* + * We location the EH sections in section flags. + */ + return false; +} + +bool +rtems_rtl_elf_unwind_register (rtems_rtl_obj* obj) +{ + return true; +} + +bool +rtems_rtl_elf_unwind_deregister (rtems_rtl_obj* obj) +{ + obj->loader = NULL; + return true; +} + +/* + * A weak reference is in libgcc, provide a real version and provide a way to + * manage loaded modules. + * + * Passed in the return address and a reference to the number of records + * found. We set the start of the exidx data and the number of records. + */ +_Unwind_Ptr __gnu_Unwind_Find_exidx (_Unwind_Ptr return_address, + int* nrec) __attribute__ ((__noinline__, + __used__, + __noclone__)); + +_Unwind_Ptr __gnu_Unwind_Find_exidx (_Unwind_Ptr return_address, + int* nrec) +{ + rtems_rtl_data* rtl; + rtems_chain_node* node; + __EIT_entry* exidx_start = &__exidx_start; + __EIT_entry* exidx_end = &__exidx_end; + + rtl = rtems_rtl_lock (); + + node = rtems_chain_first (&rtl->objects); + while (!rtems_chain_is_tail (&rtl->objects, node)) { + rtems_rtl_obj* obj = (rtems_rtl_obj*) node; + if (rtems_rtl_obj_text_inside (obj, (void*) return_address)) { + exidx_start = (__EIT_entry*) obj->eh_base; + exidx_end = (__EIT_entry*) (obj->eh_base + obj->eh_size); + break; + } + node = rtems_chain_next (node); + } + + rtems_rtl_unlock (); + + *nrec = exidx_end - exidx_start; + + return (_Unwind_Ptr) exidx_start; +} diff --git a/cpukit/libdl/rtl-unwind-arm.h b/cpukit/libdl/rtl-unwind-arm.h new file mode 100644 index 0000000000..08a2660560 --- /dev/null +++ b/cpukit/libdl/rtl-unwind-arm.h @@ -0,0 +1,46 @@ +#include + +#include +#include "rtl-unwind.h" + +typedef unsigned _Unwind_Word __attribute__((__mode__(__word__))); +typedef _Unwind_Word _uw; + +bool +rtems_rtl_elf_unwind_parse (const rtems_rtl_obj* obj, + const char* name, + uint32_t flags); + +bool +rtems_rtl_elf_unwind_register (rtems_rtl_obj* obj); + +bool +rtems_rtl_elf_unwind_deregister (rtems_rtl_obj* obj); + +/* An exception index table entry. */ +typedef struct __EIT_entry +{ + _uw fnoffset; + _uw content; +} __EIT_entry; + +/* The exception index table location in the base module */ +extern __EIT_entry __exidx_start; +extern __EIT_entry __exidx_end; + +/* + * A weak reference is in libgcc, provide a real version and provide a way to + * manage loaded modules. + * + * Passed in the return address and a reference to the number of records + * found. We set the start of the exidx data and the number of records. + */ +_Unwind_Ptr +__gnu_Unwind_Find_exidx (_Unwind_Ptr return_address, + int* nrec) __attribute__ ((__noinline__, + __used__, + __noclone__)); + +_Unwind_Ptr +__gnu_Unwind_Find_exidx (_Unwind_Ptr return_address, + int* nrec); diff --git a/spec/build/cpukit/objdlaarch64.yml b/spec/build/cpukit/objdlaarch64.yml index 2909a902f2..1715eefd3a 100644 --- a/spec/build/cpukit/objdlaarch64.yml +++ b/spec/build/cpukit/objdlaarch64.yml @@ -12,4 +12,5 @@ install: [] links: [] source: - cpukit/libdl/rtl-mdreloc-aarch64.c +- cpukit/libdl/rtl-unwind-arm.c type: build diff --git a/spec/build/cpukit/objdlarm.yml b/spec/build/cpukit/objdlarm.yml index 6edb3653f2..f3e1d37668 100644 --- a/spec/build/cpukit/objdlarm.yml +++ b/spec/build/cpukit/objdlarm.yml @@ -12,4 +12,5 @@ install: [] links: [] source: - cpukit/libdl/rtl-mdreloc-arm.c +- cpukit/libdl/rtl-unwind-arm.c type: build -- cgit v1.2.3