[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 07/13] rust: modernize #[derive(Object)] for ELF platforms
From: |
Paolo Bonzini |
Subject: |
[PATCH 07/13] rust: modernize #[derive(Object)] for ELF platforms |
Date: |
Fri, 18 Oct 2024 16:42:59 +0200 |
Some newer ABI implementations do not provide .ctors; and while
some linkers rewrite .ctors into .init_array, not all of them do.
Use the newer .init_array ABI, which works more reliably, and
apply it to all non-Apple, non-Windows platforms.
This is similar to how the ctor crate operates; without this change,
"#[derive(Object)]" does not work on Fedora 41.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
rust/qemu-api-macros/src/lib.rs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/rust/qemu-api-macros/src/lib.rs b/rust/qemu-api-macros/src/lib.rs
index 59aba592d9a..be8874caea1 100644
--- a/rust/qemu-api-macros/src/lib.rs
+++ b/rust/qemu-api-macros/src/lib.rs
@@ -16,8 +16,8 @@ pub fn derive_object(input: TokenStream) -> TokenStream {
let expanded = quote! {
#[allow(non_upper_case_globals)]
#[used]
- #[cfg_attr(target_os = "linux", link_section = ".ctors")]
- #[cfg_attr(target_os = "macos", link_section =
"__DATA,__mod_init_func")]
+ #[cfg_attr(not(any(target_vendor = "apple", target_os = "windows")),
link_section = ".init_array")]
+ #[cfg_attr(target_vendor = "apple", link_section =
"__DATA,__mod_init_func")]
#[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")]
pub static #module_static: extern "C" fn() = {
extern "C" fn __register() {
--
2.46.2
- [PATCH 00/13] rust: miscellaneous cleanups + QOM integration tests, Paolo Bonzini, 2024/10/18
- [PATCH 01/13] meson: import rust module into a global variable, Paolo Bonzini, 2024/10/18
- [PATCH 02/13] meson: remove repeated search for rust_root_crate.sh, Paolo Bonzini, 2024/10/18
- [PATCH 03/13] meson: pass rustc_args when building all crates, Paolo Bonzini, 2024/10/18
- [PATCH 04/13] rust: do not use --no-size_t-is-usize, Paolo Bonzini, 2024/10/18
- [PATCH 05/13] rust: remove uses of #[no_mangle], Paolo Bonzini, 2024/10/18
- [PATCH 06/13] rust: remove unused macro module_init!, Paolo Bonzini, 2024/10/18
- [PATCH 07/13] rust: modernize #[derive(Object)] for ELF platforms,
Paolo Bonzini <=
- [PATCH 08/13] rust: build integration test for the qemu_api crate, Paolo Bonzini, 2024/10/18
- [PATCH 09/13] rust: clean up define_property macro, Paolo Bonzini, 2024/10/18