Bug 15600 - cargo fails to build for riscv64 target
Summary: cargo fails to build for riscv64 target
Status: RESOLVED FIXED
Alias: None
Product: OE-Core
Classification: Build System, Metadata & Runtime
Component: core (show other bugs)
Version: 5.1
Hardware: Other other
: Medium+ normal
Target Milestone: 5.2 M1
Assignee: Harish Sadineni
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2024-09-19 23:36 UTC by Khem Raj
Modified: 2024-11-25 05:50 UTC (History)
5 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: Regression (Used to work)
Verified:
Documentation change: No (bug/feature does not impact docs)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Khem Raj 2024-09-19 23:36:26 UTC
Compiling 1.79 version of cargo fails to build, also note that I am using meta-clang and TOOLCHAIN = "clang" is set in local.conf

below is the error.

error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
   --> /usr/src/debug/cargo/1.79.0/rustc-1.79.0-src/vendor/dbus-0.9.7/src/ffidisp/connection.rs:298:50
    |
298 |         if r == -1 { Err(e) } else { Ok(unsafe { mem::transmute(r) }) }
    |                                                  ^^^^^^^^^^^^^^
    |
    = note: source type: `i32` (32 bits)
    = note: target type: `DBusRequestNameReply` (64 bits)

error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
   --> /usr/src/debug/cargo/1.79.0/rustc-1.79.0-src/vendor/dbus-0.9.7/src/ffidisp/connection.rs:306:50
    |
306 |         if r == -1 { Err(e) } else { Ok(unsafe { mem::transmute(r) }) }
    |                                                  ^^^^^^^^^^^^^^
    |
    = note: source type: `i32` (32 bits)
    = note: target type: `DBusReleaseNameReply` (64 bits)
Comment 1 Randy MacLeod 2024-09-20 12:56:48 UTC
Sundeep, this is blocking Khem so can you take a look ASAP.
Comment 2 Sundeep Kokkonda 2024-09-24 10:34:51 UTC
Sure, we will check and update here.
Comment 3 Harish Sadineni 2024-10-04 09:51:18 UTC
Referring to the discussion in this GitHub issue from bellow links , we have opted to use transmute_copy instead of transmute to resolve the issue.
https://github.com/rust-lang/rust/issues/61956#issuecomment-506520426
https://github.com/rust-lang/rust/issues/61956#issuecomment-503626904

proposed fix:
--- a/vendor/dbus-0.9.7/src/ffidisp/connection.rs 
+++ b/vendor/dbus-0.9.7/src/ffidisp/connection.rs
@@ -295,7 +295,7 @@
         let mut e = Error::empty();
         let n = to_c_str(name);
         let r = unsafe { ffi::dbus_bus_request_name(self.conn(), n.as_ptr(), flags, e.get_mut()) };
-        if r == -1 { Err(e) } else { Ok(unsafe { mem::transmute(r) }) }
+        if r == -1 { Err(e) } else { Ok(unsafe { mem::transmute_copy(&r) }) }
     }

     /// Release a name.
@@ -303,7 +303,7 @@
         let mut e = Error::empty();
         let n = to_c_str(name);
         let r = unsafe { ffi::dbus_bus_release_name(self.conn(), n.as_ptr(), e.get_mut()) };
-        if r == -1 { Err(e) } else { Ok(unsafe { mem::transmute(r) }) }
+        if r == -1 { Err(e) } else { Ok(unsafe { mem::transmute_copy(&r) }) }
     }

     /// Add a match rule to match messages on the message bus.
	 

However we are currently experiencing bellow failure when running "bitbake core-image-minimal" with toolchain as clang, regardless of the implementation of the above fix
| Makefile:184: *** Your linker does not support creating PIEs, opensbi requires this..  Stop.
| ERROR: oe_runmake failed
Comment 4 Randy MacLeod 2024-10-23 14:43:38 UTC
Please explain why switching from transmute() to transmute_copy() as a generic patch would be required to fix a build error that seems to *only* affect riscv64 when using clang. This seems like a bad idea or at least one that requires a clear explanation.
Comment 5 Harish Sadineni 2024-11-25 05:50:10 UTC
This issue is fixed with patch from following commit:
https://git.openembedded.org/openembedded-core/commit/?id=b9df8cd8b29064d115dab3bfd1ea14f94a5c0238