diff mbox series

[v2,1/4] compiler.h: Introduce absolute_pointer macro

Message ID 20210915035227.630204-2-linux@roeck-us.net (mailing list archive)
State Not Applicable
Headers show
Series Introduce and use absolute_pointer macro | expand

Commit Message

Guenter Roeck Sept. 15, 2021, 3:52 a.m. UTC
absolute_pointer() disassociates a pointer from its originating symbol
type and context. Use it to prevent compiler warnings/errors such as

drivers/net/ethernet/i825xx/82596.c: In function 'i82596_probe':
./arch/m68k/include/asm/string.h:72:25: error:
	'__builtin_memcpy' reading 6 bytes from a region of size 0
		[-Werror=stringop-overread]

Such warnings may be reported by gcc 11.x for string and memory operations
on fixed addresses.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
v2: No change

 include/linux/compiler.h | 2 ++
 1 file changed, 2 insertions(+)

Comments

Geert Uytterhoeven Sept. 15, 2021, 7:07 a.m. UTC | #1
On Wed, Sep 15, 2021 at 5:52 AM Guenter Roeck <linux@roeck-us.net> wrote:
> absolute_pointer() disassociates a pointer from its originating symbol
> type and context. Use it to prevent compiler warnings/errors such as
>
> drivers/net/ethernet/i825xx/82596.c: In function 'i82596_probe':
> ./arch/m68k/include/asm/string.h:72:25: error:
>         '__builtin_memcpy' reading 6 bytes from a region of size 0
>                 [-Werror=stringop-overread]
>
> Such warnings may be reported by gcc 11.x for string and memory operations
> on fixed addresses.
>
> Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>

Gr{oetje,eeting}s,

                        Geert
Geert Uytterhoeven Sept. 15, 2021, 7:13 a.m. UTC | #2
Hi Günter,

On Wed, Sep 15, 2021 at 5:52 AM Guenter Roeck <linux@roeck-us.net> wrote:
> absolute_pointer() disassociates a pointer from its originating symbol
> type and context. Use it to prevent compiler warnings/errors such as
>
> drivers/net/ethernet/i825xx/82596.c: In function 'i82596_probe':
> ./arch/m68k/include/asm/string.h:72:25: error:
>         '__builtin_memcpy' reading 6 bytes from a region of size 0
>                 [-Werror=stringop-overread]
>
> Such warnings may be reported by gcc 11.x for string and memory operations
> on fixed addresses.
>
> Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
> v2: No change
>
>  include/linux/compiler.h | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/include/linux/compiler.h b/include/linux/compiler.h
> index b67261a1e3e9..3d5af56337bd 100644
> --- a/include/linux/compiler.h
> +++ b/include/linux/compiler.h
> @@ -188,6 +188,8 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
>      (typeof(ptr)) (__ptr + (off)); })
>  #endif
>
> +#define absolute_pointer(val)  RELOC_HIDE((void *)(val), 0)

I guess we're not worried about "val" being evaluated multiple
times inside RELOC_HIDE(), as this is mainly intended for constants?

Gr{oetje,eeting}s,

                        Geert
Guenter Roeck Sept. 15, 2021, 2:03 p.m. UTC | #3
On 9/15/21 12:13 AM, Geert Uytterhoeven wrote:
> Hi Günter,
> 
> On Wed, Sep 15, 2021 at 5:52 AM Guenter Roeck <linux@roeck-us.net> wrote:
>> absolute_pointer() disassociates a pointer from its originating symbol
>> type and context. Use it to prevent compiler warnings/errors such as
>>
>> drivers/net/ethernet/i825xx/82596.c: In function 'i82596_probe':
>> ./arch/m68k/include/asm/string.h:72:25: error:
>>          '__builtin_memcpy' reading 6 bytes from a region of size 0
>>                  [-Werror=stringop-overread]
>>
>> Such warnings may be reported by gcc 11.x for string and memory operations
>> on fixed addresses.
>>
>> Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
>> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
>> ---
>> v2: No change
>>
>>   include/linux/compiler.h | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/include/linux/compiler.h b/include/linux/compiler.h
>> index b67261a1e3e9..3d5af56337bd 100644
>> --- a/include/linux/compiler.h
>> +++ b/include/linux/compiler.h
>> @@ -188,6 +188,8 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
>>       (typeof(ptr)) (__ptr + (off)); })
>>   #endif
>>
>> +#define absolute_pointer(val)  RELOC_HIDE((void *)(val), 0)
> 
> I guess we're not worried about "val" being evaluated multiple
> times inside RELOC_HIDE(), as this is mainly intended for constants?
> 

No, we are not. It is quite similar to RELOC_HIDE() in that regard.

Guenter
diff mbox series

Patch

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index b67261a1e3e9..3d5af56337bd 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -188,6 +188,8 @@  void ftrace_likely_update(struct ftrace_likely_data *f, int val,
     (typeof(ptr)) (__ptr + (off)); })
 #endif
 
+#define absolute_pointer(val)	RELOC_HIDE((void *)(val), 0)
+
 #ifndef OPTIMIZER_HIDE_VAR
 /* Make the optimizer believe the variable can be manipulated arbitrarily. */
 #define OPTIMIZER_HIDE_VAR(var)						\