[2/2] ARC: elf: make type safe

Message ID 20210720205800.1056218-3-vgupta@synopsys.com
State New
Headers show
Series
  • ARC fixes/updates
Related show

Commit Message

H.J. Lu via Libc-alpha July 20, 2021, 8:58 p.m.
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>

---
 sysdeps/arc/dl-machine.h | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

-- 
2.25.1

Comments

H.J. Lu via Libc-alpha July 21, 2021, 8:17 p.m. | #1
On 7/20/21 1:58 PM, Vineet Gupta via Libc-alpha wrote:
> Signed-off-by: Vineet Gupta <vgupta@synopsys.com>


Committed !

> ---

>   sysdeps/arc/dl-machine.h | 23 ++++++++++-------------

>   1 file changed, 10 insertions(+), 13 deletions(-)

> 

> diff --git a/sysdeps/arc/dl-machine.h b/sysdeps/arc/dl-machine.h

> index 60b49af0d5ca..e6ce7f0ff6d9 100644

> --- a/sysdeps/arc/dl-machine.h

> +++ b/sysdeps/arc/dl-machine.h

> @@ -86,7 +86,7 @@

>   

>   /* Return nonzero iff ELF header is compatible with the running host.  */

>   static inline int

> -elf_machine_matches_host (const Elf32_Ehdr *ehdr)

> +elf_machine_matches_host (const ElfW(Ehdr) *ehdr)

>   {

>     return (ehdr->e_machine == EM_ARCV2		 /* ARC HS.  */

>   	  || ehdr->e_machine == EM_ARC_COMPACT); /* ARC 700.  */

> @@ -124,7 +124,7 @@ static inline int

>   __attribute__ ((always_inline))

>   elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)

>   {

> -  extern void _dl_runtime_resolve (Elf32_Word);

> +  extern void _dl_runtime_resolve (void);

>   

>     if (l->l_info[DT_JMPREL] && lazy)

>       {

> @@ -202,7 +202,7 @@ __start:								\n\

>   /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.  */

>   #define ELF_MACHINE_JMP_SLOT  R_ARC_JUMP_SLOT

>   

> -/* ARC uses Elf32_Rela relocations.  */

> +/* ARC uses Rela relocations.  */

>   #define ELF_MACHINE_NO_REL 1

>   #define ELF_MACHINE_NO_RELA 0

>   

> @@ -211,19 +211,14 @@ __start:								\n\

>   static inline ElfW(Addr)

>   elf_machine_fixup_plt (struct link_map *map, lookup_t t,

>   		       const ElfW(Sym) *refsym, const ElfW(Sym) *sym,

> -		       const Elf32_Rela *reloc,

> +		       const ElfW(Rela) *reloc,

>   		       ElfW(Addr) *reloc_addr, ElfW(Addr) value)

>   {

>     return *reloc_addr = value;

>   }

>   

>   /* Return the final value of a plt relocation.  */

> -static inline ElfW(Addr)

> -elf_machine_plt_value (struct link_map *map, const Elf32_Rela *reloc,

> -                       ElfW(Addr) value)

> -{

> -  return value;

> -}

> +#define elf_machine_plt_value(map, reloc, value) (value)

>   

>   /* Names of the architecture-specific auditing callback functions.  */

>   #define ARCH_LA_PLTENTER arc_gnu_pltenter

> @@ -239,8 +234,9 @@ elf_machine_rela (struct link_map *map, const ElfW(Rela) *reloc,

>                     const ElfW(Sym) *sym, const struct r_found_version *version,

>                     void *const reloc_addr_arg, int skip_ifunc)

>   {

> +  ElfW(Addr) r_info = reloc->r_info;

> +  const unsigned long int r_type = ELFW (R_TYPE) (r_info);

>     ElfW(Addr) *const reloc_addr = reloc_addr_arg;

> -  const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);

>   

>     if (__glibc_unlikely (r_type == R_ARC_RELATIVE))

>       *reloc_addr += map->l_addr;

> @@ -334,11 +330,12 @@ elf_machine_lazy_rel (struct link_map *map, ElfW(Addr) l_addr,

>                         const ElfW(Rela) *reloc, int skip_ifunc)

>   {

>     ElfW(Addr) *const reloc_addr = (void *) (l_addr + reloc->r_offset);

> +  const unsigned int r_type = ELFW (R_TYPE) (reloc->r_info);

>   

> -  if (ELF32_R_TYPE (reloc->r_info) == R_ARC_JUMP_SLOT)

> +  if (r_type == R_ARC_JUMP_SLOT)

>       *reloc_addr += l_addr;

>     else

> -    _dl_reloc_bad_type (map, ELF32_R_TYPE (reloc->r_info), 1);

> +    _dl_reloc_bad_type (map, r_type, 1);

>   }

>   

>   #endif /* RESOLVE_MAP */

>

Patch

diff --git a/sysdeps/arc/dl-machine.h b/sysdeps/arc/dl-machine.h
index 60b49af0d5ca..e6ce7f0ff6d9 100644
--- a/sysdeps/arc/dl-machine.h
+++ b/sysdeps/arc/dl-machine.h
@@ -86,7 +86,7 @@ 
 
 /* Return nonzero iff ELF header is compatible with the running host.  */
 static inline int
-elf_machine_matches_host (const Elf32_Ehdr *ehdr)
+elf_machine_matches_host (const ElfW(Ehdr) *ehdr)
 {
   return (ehdr->e_machine == EM_ARCV2		 /* ARC HS.  */
 	  || ehdr->e_machine == EM_ARC_COMPACT); /* ARC 700.  */
@@ -124,7 +124,7 @@  static inline int
 __attribute__ ((always_inline))
 elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
 {
-  extern void _dl_runtime_resolve (Elf32_Word);
+  extern void _dl_runtime_resolve (void);
 
   if (l->l_info[DT_JMPREL] && lazy)
     {
@@ -202,7 +202,7 @@  __start:								\n\
 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.  */
 #define ELF_MACHINE_JMP_SLOT  R_ARC_JUMP_SLOT
 
-/* ARC uses Elf32_Rela relocations.  */
+/* ARC uses Rela relocations.  */
 #define ELF_MACHINE_NO_REL 1
 #define ELF_MACHINE_NO_RELA 0
 
@@ -211,19 +211,14 @@  __start:								\n\
 static inline ElfW(Addr)
 elf_machine_fixup_plt (struct link_map *map, lookup_t t,
 		       const ElfW(Sym) *refsym, const ElfW(Sym) *sym,
-		       const Elf32_Rela *reloc,
+		       const ElfW(Rela) *reloc,
 		       ElfW(Addr) *reloc_addr, ElfW(Addr) value)
 {
   return *reloc_addr = value;
 }
 
 /* Return the final value of a plt relocation.  */
-static inline ElfW(Addr)
-elf_machine_plt_value (struct link_map *map, const Elf32_Rela *reloc,
-                       ElfW(Addr) value)
-{
-  return value;
-}
+#define elf_machine_plt_value(map, reloc, value) (value)
 
 /* Names of the architecture-specific auditing callback functions.  */
 #define ARCH_LA_PLTENTER arc_gnu_pltenter
@@ -239,8 +234,9 @@  elf_machine_rela (struct link_map *map, const ElfW(Rela) *reloc,
                   const ElfW(Sym) *sym, const struct r_found_version *version,
                   void *const reloc_addr_arg, int skip_ifunc)
 {
+  ElfW(Addr) r_info = reloc->r_info;
+  const unsigned long int r_type = ELFW (R_TYPE) (r_info);
   ElfW(Addr) *const reloc_addr = reloc_addr_arg;
-  const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
 
   if (__glibc_unlikely (r_type == R_ARC_RELATIVE))
     *reloc_addr += map->l_addr;
@@ -334,11 +330,12 @@  elf_machine_lazy_rel (struct link_map *map, ElfW(Addr) l_addr,
                       const ElfW(Rela) *reloc, int skip_ifunc)
 {
   ElfW(Addr) *const reloc_addr = (void *) (l_addr + reloc->r_offset);
+  const unsigned int r_type = ELFW (R_TYPE) (reloc->r_info);
 
-  if (ELF32_R_TYPE (reloc->r_info) == R_ARC_JUMP_SLOT)
+  if (r_type == R_ARC_JUMP_SLOT)
     *reloc_addr += l_addr;
   else
-    _dl_reloc_bad_type (map, ELF32_R_TYPE (reloc->r_info), 1);
+    _dl_reloc_bad_type (map, r_type, 1);
 }
 
 #endif /* RESOLVE_MAP */