[PATCH 06/13] rust: remove unused macro module_init!

Paolo Bonzini posted 13 patches 4 days, 8 hours ago
There is a newer version of this series
[PATCH 06/13] rust: remove unused macro module_init!
Posted by Paolo Bonzini 4 days, 8 hours ago
Registering the object is now done by the #[derive(Object)] macro.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/qemu-api/src/definitions.rs | 43 --------------------------------
 1 file changed, 43 deletions(-)

diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitions.rs
index 49ac59af123..73ef9a52c1b 100644
--- a/rust/qemu-api/src/definitions.rs
+++ b/rust/qemu-api/src/definitions.rs
@@ -27,49 +27,6 @@ pub trait Class {
     >;
 }
 
-#[macro_export]
-macro_rules! module_init {
-    ($func:expr, $type:expr) => {
-        #[used]
-        #[cfg_attr(target_os = "linux", link_section = ".ctors")]
-        #[cfg_attr(target_os = "macos", link_section = "__DATA,__mod_init_func")]
-        #[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")]
-        pub static LOAD_MODULE: extern "C" fn() = {
-            extern "C" fn __load() {
-                unsafe {
-                    $crate::bindings::register_module_init(Some($func), $type);
-                }
-            }
-
-            __load
-        };
-    };
-    (qom: $func:ident => $body:block) => {
-        // NOTE: To have custom identifiers for the ctor func we need to either supply
-        // them directly as a macro argument or create them with a proc macro.
-        #[used]
-        #[cfg_attr(target_os = "linux", link_section = ".ctors")]
-        #[cfg_attr(target_os = "macos", link_section = "__DATA,__mod_init_func")]
-        #[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")]
-        pub static LOAD_MODULE: extern "C" fn() = {
-            extern "C" fn __load() {
-                unsafe extern "C" fn $func() {
-                    $body
-                }
-
-                unsafe {
-                    $crate::bindings::register_module_init(
-                        Some($func),
-                        $crate::bindings::module_init_type::MODULE_INIT_QOM,
-                    );
-                }
-            }
-
-            __load
-        };
-    };
-}
-
 #[macro_export]
 macro_rules! type_info {
     ($t:ty) => {
-- 
2.46.2
Re: [PATCH 06/13] rust: remove unused macro module_init!
Posted by Junjie Mao 1 day, 13 hours ago
Paolo Bonzini <pbonzini@redhat.com> writes:

> Registering the object is now done by the #[derive(Object)] macro.

The module_init! macro is still necessary when a device needs more logic
(in addition to a single type registration) in module init. That is not
rare among the devices in C we have today.

Manos and I had a conversation on this. He mentioned that he had a
second Rust device that needs this macro [1].

[1] https://lore.kernel.org/qemu-devel/itblf.by425lac4ow@linaro.org/

--
Best Regards
Junjie Mao

>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  rust/qemu-api/src/definitions.rs | 43 --------------------------------
>  1 file changed, 43 deletions(-)
Re: [PATCH 06/13] rust: remove unused macro module_init!
Posted by Paolo Bonzini 1 day, 12 hours ago
Il lun 21 ott 2024, 12:19 Junjie Mao <junjie.mao@hotmail.com> ha scritto:

>
> Paolo Bonzini <pbonzini@redhat.com> writes:
>
> > Registering the object is now done by the #[derive(Object)] macro.
>
> The module_init! macro is still necessary when a device needs more logic
> (in addition to a single type registration) in module init. That is not
> rare among the devices in C we have today.
>
> Manos and I had a conversation on this. He mentioned that he had a
> second Rust device that needs this macro [1].
>

Ok, I will change derive(Object) to use module_init! instead. What matters
is that module_init! is also fixed to not use the .ctors section.

Paolo


> [1] https://lore.kernel.org/qemu-devel/itblf.by425lac4ow@linaro.org/
>
> --
> Best Regards
> Junjie Mao
>
> >
> > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> > ---
> >  rust/qemu-api/src/definitions.rs | 43 --------------------------------
> >  1 file changed, 43 deletions(-)
>
>