diff mbox series

[v3,19/19] qom: Require TypeInfo::class_data points to const data

Message ID 20250212213249.45574-20-philmd@linaro.org
State New
Headers show
Series qom: Constify class_data | expand

Commit Message

Philippe Mathieu-Daudé Feb. 12, 2025, 9:32 p.m. UTC
All TypeInfo::class_data point to const data.
Enforce that in the structure, so future class_data
stays in .rodata.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/qom/object.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Richard Henderson Feb. 12, 2025, 10:11 p.m. UTC | #1
On 2/12/25 13:32, Philippe Mathieu-Daudé wrote:
> All TypeInfo::class_data point to const data.
> Enforce that in the structure, so future class_data
> stays in .rodata.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   include/qom/object.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/qom/object.h b/include/qom/object.h
> index 1d5b0337242..31adc2ef174 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -488,7 +488,7 @@ struct TypeInfo
>   
>       void (*class_init)(ObjectClass *klass, const void *data);
>       void (*class_base_init)(ObjectClass *klass, const void *data);
> -    const void *class_data;
> +    const void *const class_data;
>   
>       const InterfaceInfo *interfaces;
>   };


This doesn't do what you think it does.
I'm surprised it compiles.


r~
Philippe Mathieu-Daudé Feb. 18, 2025, 4:51 p.m. UTC | #2
On 12/2/25 23:11, Richard Henderson wrote:
> On 2/12/25 13:32, Philippe Mathieu-Daudé wrote:
>> All TypeInfo::class_data point to const data.
>> Enforce that in the structure, so future class_data
>> stays in .rodata.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>>   include/qom/object.h | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/include/qom/object.h b/include/qom/object.h
>> index 1d5b0337242..31adc2ef174 100644
>> --- a/include/qom/object.h
>> +++ b/include/qom/object.h
>> @@ -488,7 +488,7 @@ struct TypeInfo
>>       void (*class_init)(ObjectClass *klass, const void *data);
>>       void (*class_base_init)(ObjectClass *klass, const void *data);
>> -    const void *class_data;
>> +    const void *const class_data;
>>       const InterfaceInfo *interfaces;
>>   };
> 
> 
> This doesn't do what you think it does.

Per cdecl(1):

const void *class_data;
// declare class_data as pointer to const void

const void *const class_data;
// declare class_data as const pointer to const void

> I'm surprised it compiles.

I had to add the previous and virtio-pci patches to make it compile.

How should be what I'm looking for, or how should I describe it?

Thanks,

Phil.
diff mbox series

Patch

diff --git a/include/qom/object.h b/include/qom/object.h
index 1d5b0337242..31adc2ef174 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -488,7 +488,7 @@  struct TypeInfo
 
     void (*class_init)(ObjectClass *klass, const void *data);
     void (*class_base_init)(ObjectClass *klass, const void *data);
-    const void *class_data;
+    const void *const class_data;
 
     const InterfaceInfo *interfaces;
 };