diff mbox series

[uclibc-ng-devel] arm: elf-fdpic.h: avoid void pointer subtraction

Message ID 20231020171900.1654392-2-ben.wolsieffer@hefring.com
State Accepted
Headers show
Series [uclibc-ng-devel] arm: elf-fdpic.h: avoid void pointer subtraction | expand

Commit Message

Ben Wolsieffer Oct. 20, 2023, 5:19 p.m. UTC
elf-fdpic.h is included by link.h. When a C++ program includes <link.h>,
we get the following build failure:

<...>/usr/include/bits/elf-fdpic.h: In function ‘void* __reloc_pointer(void*, const elf32_fdpic_loadmap*)’:
<...>/usr/include/bits/elf-fdpic.h:94:54: error: invalid use of ‘void’
   94 |       unsigned long offset = p - (void*)map->segs[c].p_vaddr;
      |                                                      ^~~~~~~

void pointer addition and subtraction is not allowed in C++ as it has
undetermined size, however in C with language extension it is possible
because sizeof void is treated as one byte.

This patch was previously applied to Blackfin, FR-V and C6x, but not
ARM.

Signed-off-by: Ben Wolsieffer <ben.wolsieffer@hefring.com>
---
 libc/sysdeps/linux/arm/bits/elf-fdpic.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Waldemar Brodkorb Nov. 7, 2023, 12:30 p.m. UTC | #1
Hi Ben,

I committed and pushed your patch,

best regards
 Waldemar

Ben Wolsieffer wrote,

> elf-fdpic.h is included by link.h. When a C++ program includes <link.h>,
> we get the following build failure:
> 
> <...>/usr/include/bits/elf-fdpic.h: In function ‘void* __reloc_pointer(void*, const elf32_fdpic_loadmap*)’:
> <...>/usr/include/bits/elf-fdpic.h:94:54: error: invalid use of ‘void’
>    94 |       unsigned long offset = p - (void*)map->segs[c].p_vaddr;
>       |                                                      ^~~~~~~
> 
> void pointer addition and subtraction is not allowed in C++ as it has
> undetermined size, however in C with language extension it is possible
> because sizeof void is treated as one byte.
> 
> This patch was previously applied to Blackfin, FR-V and C6x, but not
> ARM.
> 
> Signed-off-by: Ben Wolsieffer <ben.wolsieffer@hefring.com>
> ---
>  libc/sysdeps/linux/arm/bits/elf-fdpic.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libc/sysdeps/linux/arm/bits/elf-fdpic.h b/libc/sysdeps/linux/arm/bits/elf-fdpic.h
> index 3d6db54af..f2ef9aeca 100644
> --- a/libc/sysdeps/linux/arm/bits/elf-fdpic.h
> +++ b/libc/sysdeps/linux/arm/bits/elf-fdpic.h
> @@ -91,7 +91,7 @@ __reloc_pointer (void *p,
>        /* This should be computed as part of the pointer comparison
>  	 above, but we want to use the carry in the comparison, so we
>  	 can't convert it to an integer type beforehand.  */
> -      unsigned long offset = p - (void*)map->segs[c].p_vaddr;
> +      unsigned long offset = (char*)p - (char*)map->segs[c].p_vaddr;
>        /* We only check for one-past-the-end for the last segment,
>  	 assumed to be the data segment, because other cases are
>  	 ambiguous in the absence of padding between segments, and
> -- 
> 2.42.0
> 
> _______________________________________________
> devel mailing list -- devel@uclibc-ng.org
> To unsubscribe send an email to devel-leave@uclibc-ng.org
diff mbox series

Patch

diff --git a/libc/sysdeps/linux/arm/bits/elf-fdpic.h b/libc/sysdeps/linux/arm/bits/elf-fdpic.h
index 3d6db54af..f2ef9aeca 100644
--- a/libc/sysdeps/linux/arm/bits/elf-fdpic.h
+++ b/libc/sysdeps/linux/arm/bits/elf-fdpic.h
@@ -91,7 +91,7 @@  __reloc_pointer (void *p,
       /* This should be computed as part of the pointer comparison
 	 above, but we want to use the carry in the comparison, so we
 	 can't convert it to an integer type beforehand.  */
-      unsigned long offset = p - (void*)map->segs[c].p_vaddr;
+      unsigned long offset = (char*)p - (char*)map->segs[c].p_vaddr;
       /* We only check for one-past-the-end for the last segment,
 	 assumed to be the data segment, because other cases are
 	 ambiguous in the absence of padding between segments, and