[PATCH 2/2] cpukit/libdl: Resolve size mismatch warnings

Chris Johns chrisj at rtems.org
Wed Apr 5 01:46:32 UTC 2023


OK to the libdl patch

Chris

On 5/4/2023 7:33 am, Kinsey Moore wrote:
> Resolve warnings about mismatched pointer and integer sizes in AArch64
> libdl when building with the ILP32 ABI.
> ---
>  cpukit/libdl/rtl-elf.c             |  4 ++--
>  cpukit/libdl/rtl-mdreloc-aarch64.c | 31 +++++++++++++++---------------
>  cpukit/libdl/rtl-rap.c             |  4 ++--
>  3 files changed, 20 insertions(+), 19 deletions(-)
> 
> diff --git a/cpukit/libdl/rtl-elf.c b/cpukit/libdl/rtl-elf.c
> index 8a21c5df73..5754070518 100644
> --- a/cpukit/libdl/rtl-elf.c
> +++ b/cpukit/libdl/rtl-elf.c
> @@ -192,7 +192,7 @@ rtems_rtl_elf_find_symbol (rtems_rtl_obj*      obj,
>      if (!*symbol)
>        return false;
>  
> -    *value = (Elf_Addr) (*symbol)->value;
> +    *value = (Elf_Addr)(uintptr_t) (*symbol)->value;
>      return true;
>    }
>  
> @@ -202,7 +202,7 @@ rtems_rtl_elf_find_symbol (rtems_rtl_obj*      obj,
>    if (!sect)
>      return false;
>  
> -  *value = sym->st_value + (Elf_Addr) sect->base;
> +  *value = sym->st_value + (Elf_Addr)(uintptr_t) sect->base;
>  
>    return true;
>  }
> diff --git a/cpukit/libdl/rtl-mdreloc-aarch64.c b/cpukit/libdl/rtl-mdreloc-aarch64.c
> index e44238e636..25057ce9d7 100644
> --- a/cpukit/libdl/rtl-mdreloc-aarch64.c
> +++ b/cpukit/libdl/rtl-mdreloc-aarch64.c
> @@ -107,7 +107,7 @@ checkoverflow(Elf_Addr addr, int bitwidth, Elf_Addr targetaddr,
>    const Elf_Addr mask = ~__BITS(bitwidth - 1, 0);
>  
>    if (((addr & mask) != 0) && ((addr & mask) != mask)) {
> -    printf("kobj_reloc: Relocation 0x%jx too far from %p"
> +    printf("kobj_reloc: Relocation 0x%" PRIxPTR " too far from %p"
>          " (base+0x%jx) for %dbit%s\n",
>          (uintptr_t)targetaddr, where, off, bitwidth, bitscale);
>      return true;
> @@ -120,7 +120,7 @@ static inline bool
>  checkalign(Elf_Addr addr, int alignbyte, void *where, Elf64_Addr off)
>  {
>    if ((addr & (alignbyte - 1)) != 0) {
> -    printf("kobj_reloc: Relocation 0x%jx unaligned at %p"
> +    printf("kobj_reloc: Relocation 0x%" PRIxPTR " unaligned at %p"
>          " (base+0x%jx). must be aligned %d\n",
>          (uintptr_t)addr, where, off, alignbyte);
>      return true;
> @@ -257,7 +257,7 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj*            obj,
>  
>          if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
>            printf ("rtl: reloc 64/GLOB_DAT in %s --> %p in %s\n",
> -                  sect->name, (void *)*where,
> +                  sect->name, (void *)(uintptr_t)*where,
>                    rtems_rtl_obj_oname (obj));
>        }
>        break;
> @@ -270,10 +270,10 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj*            obj,
>       */
>      case R_TYPE(RELATIVE):  /* Delta(S) + A */
>        if (!parsing) {
> -        *where = (Elf_Addr)(sect->base + rela->r_addend);
> +        *where = (Elf_Addr)(uintptr_t)(sect->base + rela->r_addend);
>          if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
>            printf ("rtl: reloc RELATIVE in %s --> %p in %s\n",
> -                  sect->name, (void *)*where,
> +                  sect->name, (void *)(uintptr_t)*where,
>                    rtems_rtl_obj_oname (obj));
>        }
>        break;
> @@ -304,7 +304,7 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj*            obj,
>            shift = 12;
>            break;
>          default:
> -          printf("illegal rtype: %ld\n", ELF_R_TYPE(rela->r_info));
> +          printf("illegal rtype: %" PRIu64 "\n", ELF_R_TYPE(rela->r_info));
>            break;
>        }
>  
> @@ -344,7 +344,7 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj*            obj,
>            shift = 3;
>            break;
>          default:
> -          printf("illegal rtype: %ld\n", ELF_R_TYPE(rela->r_info));
> +          printf("illegal rtype: %" PRIu64 "\n", ELF_R_TYPE(rela->r_info));
>            break;
>        }
>  
> @@ -360,9 +360,9 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj*            obj,
>          target = (Elf_Addr)symvalue + rela->r_addend;
>          if (checkalign(target, 1 << shift, where, off)) {
>            printf ("rtl: reloc checkalign failed in %s --> %p in %s\n",
> -                  sect->name, (void *)*where,
> +                  sect->name, (void *)(uintptr_t)*where,
>                    rtems_rtl_obj_oname (obj));
> -          printf("ELF_R_TYPE is : %ld\n", ELF_R_TYPE(rela->r_info));
> +          printf("ELF_R_TYPE is : %" PRIu64 "\n", ELF_R_TYPE(rela->r_info));
>            break;
>          }
>          target &= WIDTHMASK(12);
> @@ -433,7 +433,7 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj*            obj,
>            return rtems_rtl_elf_rel_failure;
>          }
>  
> -        tramp_addr = ((Elf_Addr) obj->tramp_brk) | (symvalue & 1);
> +        tramp_addr = ((Elf_Addr)(uintptr_t)obj->tramp_brk) | (symvalue & 1);
>          obj->tramp_brk = set_veneer(obj->tramp_brk, symvalue);
>  
>          target = tramp_addr + rela->r_addend - (uintptr_t)where;
> @@ -468,29 +468,30 @@ rtems_rtl_elf_reloc_rela (rtems_rtl_obj*            obj,
>  
>      case R_TYPE(TLSDESC):
>        printf ("rtl: reloc TLSDESC in %s --> %p in %s\n",
> -              sect->name, (void *)*where,
> +              sect->name, (void *)(uintptr_t)*where,
>                rtems_rtl_obj_oname (obj));
>        break;
>  
>      case R_TLS_TYPE(TLS_DTPREL):
>        printf ("rtl: reloc TLS_DTPREL in %s --> %p in %s\n",
> -              sect->name, (void *)*where,
> +              sect->name, (void *)(uintptr_t)*where,
>                rtems_rtl_obj_oname (obj));
>        break;
>      case R_TLS_TYPE(TLS_DTPMOD):
>        printf ("rtl: reloc TLS_DTPMOD in %s --> %p in %s\n",
> -              sect->name, (void *)*where,
> +              sect->name, (void *)(uintptr_t)*where,
>                rtems_rtl_obj_oname (obj));
>        break;
>  
>      case R_TLS_TYPE(TLS_TPREL):
>        printf ("rtl: reloc TLS_TPREL in %s --> %p in %s\n",
> -              sect->name, (void *)*where,
> +              sect->name, (void *)(uintptr_t)*where,
>                rtems_rtl_obj_oname (obj));
>        break;
>  
>      default:
> -      printf ("rtl: Unsupported relocation type (%ld) in %s --> %p in %s\n",
> +      printf ("rtl: Unsupported relocation type (%" PRIu64
> +              ") in %s --> %p in %s\n",
>                ELF_R_TYPE(rela->r_info), sect->name, (void *)where,
>                rtems_rtl_obj_oname (obj));
>        return rtems_rtl_elf_rel_failure;
> diff --git a/cpukit/libdl/rtl-rap.c b/cpukit/libdl/rtl-rap.c
> index f8e2b18f43..3fd1428bf2 100644
> --- a/cpukit/libdl/rtl-rap.c
> +++ b/cpukit/libdl/rtl-rap.c
> @@ -350,7 +350,7 @@ rtems_rtl_rap_relocate (rtems_rtl_rap* rap, rtems_rtl_obj* obj)
>            return false;
>          }
>  
> -        symvalue = (Elf_Addr) symsect->base + addend;
> +        symvalue = (Elf_Addr)(uintptr_t) symsect->base + addend;
>        }
>        else if (rtems_rtl_elf_rel_resolve_sym (type))
>        {
> @@ -390,7 +390,7 @@ rtems_rtl_rap_relocate (rtems_rtl_rap* rap, rtems_rtl_obj* obj)
>            return false;
>          }
>  
> -        symvalue = (Elf_Addr) symbol->value;
> +        symvalue = (Elf_Addr)(uintptr_t) symbol->value;
>        }
>  
>        if (is_rela)


More information about the devel mailing list