rustix icon indicating copy to clipboard operation
rustix copied to clipboard

loongarch64: error[E0425]: cannot find value `MADV_SOFT_OFFLINE` in module `c`

Open strophy opened this issue 7 months ago • 2 comments

I'm attempting to add loongarch64 support to the https://github.com/bytecodealliance/wasmtime package under Alpine Linux 3.21. rustix is a dependency of this package, and causes the following build error:

error[E0425]: cannot find value `MADV_SOFT_OFFLINE` in module `c`
   --> /home/buildozer/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustix-1.0.3/src/backend/libc/mm/types.rs:408:36
    |
408 |     LinuxSoftOffline = bitcast!(c::MADV_SOFT_OFFLINE),
    |                                    ^^^^^^^^^^^^^^^^^ not found in `c`
    |
help: consider importing this constant
    |
1   + use linux_raw_sys::general::MADV_SOFT_OFFLINE;
    |
help: if you import `MADV_SOFT_OFFLINE`, refer to it directly
    |
408 -     LinuxSoftOffline = bitcast!(c::MADV_SOFT_OFFLINE),
408 +     LinuxSoftOffline = bitcast!(MADV_SOFT_OFFLINE),
    |

I have tried updating to 1.0.7 without success, so I forked the rustix repo and tried depending on a branch with the following naive patch:

diff --git a/src/backend/libc/mm/types.rs b/src/backend/libc/mm/types.rs
index 0b99e3c48..75ba79bd3 100644
--- a/src/backend/libc/mm/types.rs
+++ b/src/backend/libc/mm/types.rs
@@ -402,7 +402,8 @@ pub enum Advice {
             target_arch = "mips",
             target_arch = "mips32r6",
             target_arch = "mips64",
-            target_arch = "mips64r6"
+            target_arch = "mips64r6",
+            target_arch = "loongarch64"
         ))
     ))]
     LinuxSoftOffline = bitcast!(c::MADV_SOFT_OFFLINE),

This resolves the issue for me, and I have no other errors building wasmtime. Is this an appropriate patch to merge here, should I open a PR? Or is the lack of MADV_SOFT_OFFLINE exclusive to musl libc and not GNU libc? Is this related to the stalled loongarch64 enabling work at https://github.com/bytecodealliance/rustix/pull/1086?

Ping @zhaixiaojuan and @sunfishcode

strophy avatar May 06 '25 16:05 strophy

It seems that some symbols are missing in rust-lang/libc for LoongArch with musl. I'll fix them later. In the meantime, could you switch to using the linux-raw backend instead?

heiher avatar May 07 '25 02:05 heiher

It looks like you fixed the issue in rust-lang/libc versions 0.2.173 and higher, thanks! Is the next step to bump the libc dependency here? Should I make a PR?

strophy avatar Jul 15 '25 09:07 strophy