This is an automated email from the ASF dual-hosted git repository.

Seven-Streams pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm-tirx.git


The following commit(s) were added to refs/heads/main by this push:
     new a8f52e0db [FIX][RUST] Run register_ops! blocks at DLL load on Windows 
(#89)
a8f52e0db is described below

commit a8f52e0db14d01764976611418347fae6c769b6a
Author: Linzhang Li <[email protected]>
AuthorDate: Mon Oct 26 16:04:47 2026 -0400

    [FIX][RUST] Run register_ops! blocks at DLL load on Windows (#89)
    
    Since #42, a `register_ops!` block runs when its library loads: the
    macro places a pointer to
    `__register_at_load` in the section of initializers that the loader
    calls, `.init_array` on Linux
    and `__DATA,__mod_init_func` on macOS. Windows had no such section, so a
    DLL registered its
    operators only when something called `tirx_register_ops`, and the
    Windows job of `main` fails the
    two tests that load a library without calling it
    
    
([run](https://github.com/apache/tvm-tirx/actions/runs/40376480521/job/121760803022)):
    
    ```
    FAILED 
tests/python/ir/test_op_rust.py::test_a_library_registers_its_operators_when_python_loads_it
    FAILED 
tests/python/ir/test_op_rust.py::test_a_block_that_fails_when_its_library_loads_is_reported
    AttributeError: Check failed: (op.has_value()) is false: Operator 
tirx.example_clamp is not registered
    ```
    
    The pointer now also goes in `.CRT$XCU` on Windows, whose initializers
    the CRT calls when a DLL
    loads, as `ctor` does.
---
 rust/src/ir/op_def.rs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/rust/src/ir/op_def.rs b/rust/src/ir/op_def.rs
index db244c1a3..bd5adec79 100644
--- a/rust/src/ir/op_def.rs
+++ b/rust/src/ir/op_def.rs
@@ -715,6 +715,7 @@ macro_rules! register_ops {
             #[used]
             #[cfg_attr(target_os = "linux", link_section = ".init_array")]
             #[cfg_attr(target_os = "macos", link_section = 
"__DATA,__mod_init_func")]
+            #[cfg_attr(windows, link_section = ".CRT$XCU")]
             static REGISTER_AT_LOAD: extern "C" fn() = 
$crate::ir::__register_at_load;
         };
     };

Reply via email to