* [PATCH 2/3] rust,libstd-rs: Fix build with latest musl
2022-12-29 7:12 [PATCH 1/3] rust: Do not use open64 on musl in getrandom crate Khem Raj
@ 2022-12-29 7:12 ` Khem Raj
2022-12-29 7:12 ` [PATCH 3/3] rust-llvm: Fix build on " Khem Raj
1 sibling, 0 replies; 3+ messages in thread
From: Khem Raj @ 2022-12-29 7:12 UTC (permalink / raw)
To: openembedded-core; +Cc: Khem Raj
newer musl do not provide lfs64 functions anymore since off_t is always
64bit on musl using normal functions would suffice
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
...-Do-not-use-LFS64-on-linux-with-musl.patch | 168 ++++++++++++++++++
meta/recipes-devtools/rust/rust-source.inc | 5 +
2 files changed, 173 insertions(+)
create mode 100644 meta/recipes-devtools/rust/files/0001-Do-not-use-LFS64-on-linux-with-musl.patch
diff --git a/meta/recipes-devtools/rust/files/0001-Do-not-use-LFS64-on-linux-with-musl.patch b/meta/recipes-devtools/rust/files/0001-Do-not-use-LFS64-on-linux-with-musl.patch
new file mode 100644
index 0000000000..da72665bbd
--- /dev/null
+++ b/meta/recipes-devtools/rust/files/0001-Do-not-use-LFS64-on-linux-with-musl.patch
@@ -0,0 +1,168 @@
+From 3ecce665198e3420d70139d86ed22e74804c9379 Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Wed, 28 Dec 2022 22:35:55 -0800
+Subject: [PATCH] Do not use LFS64 on linux with musl
+
+glibc is providing open64 and other lfs64 functions but musl aliases
+them to normal equivalents since off_t is always 64-bit on musl,
+therefore check for target env along when target OS is linux before
+using open64, this is more available. Latest Musl has made these
+namespace changes [1]
+
+[1] https://git.musl-libc.org/cgit/musl/commit/?id=246f1c811448f37a44b41cd8df8d0ef9736d95f4
+
+Upstream-Status: Submitted [https://github.com/rust-lang/rust/pull/106246]
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+ library/std/src/os/linux/fs.rs | 9 ++++++++-
+ library/std/src/sys/unix/fd.rs | 14 ++++++++++----
+ library/std/src/sys/unix/fs.rs | 27 ++++++++++++++++++++-------
+ 3 files changed, 38 insertions(+), 12 deletions(-)
+
+diff --git a/library/std/src/os/linux/fs.rs b/library/std/src/os/linux/fs.rs
+index 479bbcc17a8..ab0b2a3eda3 100644
+--- a/library/std/src/os/linux/fs.rs
++++ b/library/std/src/os/linux/fs.rs
+@@ -329,7 +329,14 @@ pub trait MetadataExt {
+ impl MetadataExt for Metadata {
+ #[allow(deprecated)]
+ fn as_raw_stat(&self) -> &raw::stat {
+- unsafe { &*(self.as_inner().as_inner() as *const libc::stat64 as *const raw::stat) }
++ #[cfg(target_env = "musl")]
++ unsafe {
++ &*(self.as_inner().as_inner() as *const libc::stat as *const raw::stat)
++ }
++ #[cfg(not(target_env = "musl"))]
++ unsafe {
++ &*(self.as_inner().as_inner() as *const libc::stat64 as *const raw::stat)
++ }
+ }
+ fn st_dev(&self) -> u64 {
+ self.as_inner().as_inner().st_dev as u64
+diff --git a/library/std/src/sys/unix/fd.rs b/library/std/src/sys/unix/fd.rs
+index dbaa3c33e2e..5d31557bd11 100644
+--- a/library/std/src/sys/unix/fd.rs
++++ b/library/std/src/sys/unix/fd.rs
+@@ -115,9 +115,12 @@ pub fn read_to_end(&self, buf: &mut Vec<u8>) -> io::Result<usize> {
+ }
+
+ pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
+- #[cfg(not(any(target_os = "linux", target_os = "android")))]
++ #[cfg(not(any(
++ all(target_os = "linux", not(target_env = "musl")),
++ target_os = "android"
++ )))]
+ use libc::pread as pread64;
+- #[cfg(any(target_os = "linux", target_os = "android"))]
++ #[cfg(any(all(target_os = "linux", not(target_env = "musl")), target_os = "android"))]
+ use libc::pread64;
+
+ unsafe {
+@@ -181,9 +184,12 @@ pub fn is_write_vectored(&self) -> bool {
+ }
+
+ pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
+- #[cfg(not(any(target_os = "linux", target_os = "android")))]
++ #[cfg(not(any(
++ all(target_os = "linux", not(target_env = "musl")),
++ target_os = "android"
++ )))]
+ use libc::pwrite as pwrite64;
+- #[cfg(any(target_os = "linux", target_os = "android"))]
++ #[cfg(any(all(target_os = "linux", not(target_env = "musl")), target_os = "android"))]
+ use libc::pwrite64;
+
+ unsafe {
+diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs
+index aea0c26ee8b..e7be4729ca6 100644
+--- a/library/std/src/sys/unix/fs.rs
++++ b/library/std/src/sys/unix/fs.rs
+@@ -45,19 +45,24 @@
+ all(target_os = "linux", target_env = "gnu")
+ ))]
+ use libc::c_char;
+-#[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "android"))]
++#[cfg(any(
++ all(target_os = "linux", not(target_env = "musl")),
++ target_os = "emscripten",
++ target_os = "android"
++))]
+ use libc::dirfd;
+-#[cfg(any(target_os = "linux", target_os = "emscripten"))]
++#[cfg(any(not(target_env = "musl"), target_os = "emscripten"))]
+ use libc::fstatat64;
+ #[cfg(any(
+ target_os = "android",
+ target_os = "solaris",
+ target_os = "fuchsia",
+ target_os = "redox",
+- target_os = "illumos"
++ target_os = "illumos",
++ target_env = "musl"
+ ))]
+ use libc::readdir as readdir64;
+-#[cfg(target_os = "linux")]
++#[cfg(all(target_os = "linux", not(target_env = "musl")))]
+ use libc::readdir64;
+ #[cfg(any(target_os = "emscripten", target_os = "l4re"))]
+ use libc::readdir64_r;
+@@ -77,7 +82,13 @@
+ dirent as dirent64, fstat as fstat64, fstatat as fstatat64, ftruncate64, lseek64,
+ lstat as lstat64, off64_t, open as open64, stat as stat64,
+ };
++#[cfg(target_env = "musl")]
++use libc::{
++ dirent as dirent64, fstat as fstat64, ftruncate as ftruncate64, lseek as lseek64,
++ lstat as lstat64, off_t as off64_t, open as open64, stat as stat64,
++};
+ #[cfg(not(any(
++ target_env = "musl",
+ target_os = "linux",
+ target_os = "emscripten",
+ target_os = "l4re",
+@@ -87,7 +98,7 @@
+ dirent as dirent64, fstat as fstat64, ftruncate as ftruncate64, lseek as lseek64,
+ lstat as lstat64, off_t as off64_t, open as open64, stat as stat64,
+ };
+-#[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "l4re"))]
++#[cfg(any(not(target_env = "musl"), target_os = "emscripten", target_os = "l4re"))]
+ use libc::{dirent64, fstat64, ftruncate64, lseek64, lstat64, off64_t, open64, stat64};
+
+ pub use crate::sys_common::fs::try_exists;
+@@ -260,6 +271,7 @@ unsafe impl Sync for Dir {}
+ #[cfg(any(
+ target_os = "android",
+ target_os = "linux",
++ not(target_env = "musl"),
+ target_os = "solaris",
+ target_os = "illumos",
+ target_os = "fuchsia",
+@@ -292,6 +304,7 @@ struct dirent64_min {
+ }
+
+ #[cfg(not(any(
++ target_env = "musl",
+ target_os = "android",
+ target_os = "linux",
+ target_os = "solaris",
+@@ -745,7 +758,7 @@ pub fn file_name(&self) -> OsString {
+ }
+
+ #[cfg(all(
+- any(target_os = "linux", target_os = "emscripten", target_os = "android"),
++ any(not(target_env = "musl"), target_os = "emscripten", target_os = "android"),
+ not(miri)
+ ))]
+ pub fn metadata(&self) -> io::Result<FileAttr> {
+@@ -769,7 +782,7 @@ pub fn metadata(&self) -> io::Result<FileAttr> {
+ }
+
+ #[cfg(any(
+- not(any(target_os = "linux", target_os = "emscripten", target_os = "android")),
++ not(any(not(target_env = "musl"), target_os = "emscripten", target_os = "android")),
+ miri
+ ))]
+ pub fn metadata(&self) -> io::Result<FileAttr> {
+--
+2.39.0
+
diff --git a/meta/recipes-devtools/rust/rust-source.inc b/meta/recipes-devtools/rust/rust-source.inc
index f94d616d26..643494b37e 100644
--- a/meta/recipes-devtools/rust/rust-source.inc
+++ b/meta/recipes-devtools/rust/rust-source.inc
@@ -2,8 +2,13 @@ RUST_VERSION ?= "${@d.getVar('PV').split('-')[0]}"
SRC_URI += "https://static.rust-lang.org/dist/rustc-${RUST_VERSION}-src.tar.xz;name=rust"
SRC_URI[rust.sha256sum] = "0dc176e34fae9871f855a6ba4cb30fa19d69c5b4428d29281a07419c4950715c"
+SRC_URI:append:class-target:pn-libstd-rs = "\
+ file://0001-Do-not-use-LFS64-on-linux-with-musl.patch;patchdir=../.. \
+"
+
SRC_URI:append:class-target:pn-rust = " \
file://getrandom-open64.patch \
+ file://0001-Do-not-use-LFS64-on-linux-with-musl.patch \
file://hardcodepaths.patch \
file://crossbeam_atomic.patch"
SRC_URI:append:class-nativesdk:pn-nativesdk-rust = " file://hardcodepaths.patch"
--
2.39.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 3/3] rust-llvm: Fix build on latest musl
2022-12-29 7:12 [PATCH 1/3] rust: Do not use open64 on musl in getrandom crate Khem Raj
2022-12-29 7:12 ` [PATCH 2/3] rust,libstd-rs: Fix build with latest musl Khem Raj
@ 2022-12-29 7:12 ` Khem Raj
1 sibling, 0 replies; 3+ messages in thread
From: Khem Raj @ 2022-12-29 7:12 UTC (permalink / raw)
To: openembedded-core; +Cc: Khem Raj
latest musl has removed lfs64 functions
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
...e-64bit-off_t-on-32bit-glibc-systems.patch | 79 +++++++++++++++++++
.../recipes-devtools/rust/rust-llvm_1.66.0.bb | 3 +-
2 files changed, 81 insertions(+), 1 deletion(-)
create mode 100644 meta/recipes-devtools/rust/rust-llvm/0035-cmake-Enable-64bit-off_t-on-32bit-glibc-systems.patch
diff --git a/meta/recipes-devtools/rust/rust-llvm/0035-cmake-Enable-64bit-off_t-on-32bit-glibc-systems.patch b/meta/recipes-devtools/rust/rust-llvm/0035-cmake-Enable-64bit-off_t-on-32bit-glibc-systems.patch
new file mode 100644
index 0000000000..fe98e3e4c0
--- /dev/null
+++ b/meta/recipes-devtools/rust/rust-llvm/0035-cmake-Enable-64bit-off_t-on-32bit-glibc-systems.patch
@@ -0,0 +1,79 @@
+From cd2fa12d715929642513fc441287c402f4560096 Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Sun, 25 Dec 2022 15:13:41 -0800
+Subject: [PATCH] build: Enable 64bit off_t on 32bit glibc systems
+
+Pass -D_FILE_OFFSET_BITS=64 to compiler flags on 32bit glibc based
+systems. This will make sure that 64bit versions of LFS functions are
+used e.g. lseek will behave same as lseek64. Also revert [1] partially
+because this added a cmake test to detect lseek64 but then forgot to
+pass the needed macro during actual compile, this test was incomplete too
+since libc implementations like musl has 64-bit off_t by default on 32-bit
+systems and does not bundle -D_LARGEFILE64_SOURCE [2] under -D_GNU_SOURCE
+like glibc, which means the compile now fails on musl because the cmake
+check passes but we do not have _LARGEFILE64_SOURCE defined. Moreover,
+Using the *64 function was transitional anyways so use
+-D_FILE_OFFSET_BITS=64 instead
+
+[1] https://github.com/llvm/llvm-project/commit/8db7e5e4eed4c4e697dc3164f2c9351d8c3e942b
+[2] https://git.musl-libc.org/cgit/musl/commit/?id=25e6fee27f4a293728dd15b659170e7b9c7db9bc
+
+Upstream-Status: Submitted [https://reviews.llvm.org/D139752]
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+ llvm/cmake/config-ix.cmake | 8 +++++---
+ llvm/include/llvm/Config/config.h.cmake | 3 ---
+ llvm/lib/Support/raw_ostream.cpp | 2 --
+ llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn | 2 --
+ utils/bazel/llvm-project-overlay/llvm/config.bzl | 1 -
+ .../llvm/include/llvm/Config/config.h | 3 ---
+ utils/bazel/llvm_configs/config.h.cmake | 3 ---
+ 7 files changed, 5 insertions(+), 17 deletions(-)
+
+--- a/llvm/cmake/config-ix.cmake
++++ b/llvm/cmake/config-ix.cmake
+@@ -284,9 +284,6 @@ check_symbol_exists(futimes sys/time.h H
+ if( HAVE_SIGNAL_H AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*" AND NOT APPLE )
+ check_symbol_exists(sigaltstack signal.h HAVE_SIGALTSTACK)
+ endif()
+-set(CMAKE_REQUIRED_DEFINITIONS "-D_LARGEFILE64_SOURCE")
+-check_symbol_exists(lseek64 "sys/types.h;unistd.h" HAVE_LSEEK64)
+-set(CMAKE_REQUIRED_DEFINITIONS "")
+ check_symbol_exists(mallctl malloc_np.h HAVE_MALLCTL)
+ check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)
+ check_symbol_exists(mallinfo2 malloc.h HAVE_MALLINFO2)
+@@ -350,6 +347,11 @@ check_symbol_exists(__GLIBC__ stdio.h LL
+ if( LLVM_USING_GLIBC )
+ add_definitions( -D_GNU_SOURCE )
+ list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
++# enable 64bit off_t on 32bit systems using glibc
++ if (CMAKE_SIZEOF_VOID_P EQUAL 4)
++ add_compile_definitions(_FILE_OFFSET_BITS=64)
++ list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64")
++ endif()
+ endif()
+ # This check requires _GNU_SOURCE
+ if (NOT PURE_WINDOWS)
+--- a/llvm/include/llvm/Config/config.h.cmake
++++ b/llvm/include/llvm/Config/config.h.cmake
+@@ -128,9 +128,6 @@
+ /* Define to 1 if you have the <link.h> header file. */
+ #cmakedefine HAVE_LINK_H ${HAVE_LINK_H}
+
+-/* Define to 1 if you have the `lseek64' function. */
+-#cmakedefine HAVE_LSEEK64 ${HAVE_LSEEK64}
+-
+ /* Define to 1 if you have the <mach/mach.h> header file. */
+ #cmakedefine HAVE_MACH_MACH_H ${HAVE_MACH_MACH_H}
+
+--- a/llvm/lib/Support/raw_ostream.cpp
++++ b/llvm/lib/Support/raw_ostream.cpp
+@@ -804,8 +804,6 @@ uint64_t raw_fd_ostream::seek(uint64_t o
+ flush();
+ #ifdef _WIN32
+ pos = ::_lseeki64(FD, off, SEEK_SET);
+-#elif defined(HAVE_LSEEK64)
+- pos = ::lseek64(FD, off, SEEK_SET);
+ #else
+ pos = ::lseek(FD, off, SEEK_SET);
+ #endif
diff --git a/meta/recipes-devtools/rust/rust-llvm_1.66.0.bb b/meta/recipes-devtools/rust/rust-llvm_1.66.0.bb
index 4cf244bb67..4cc57d12ae 100644
--- a/meta/recipes-devtools/rust/rust-llvm_1.66.0.bb
+++ b/meta/recipes-devtools/rust/rust-llvm_1.66.0.bb
@@ -10,7 +10,8 @@ require rust-source.inc
SRC_URI += "file://0002-llvm-allow-env-override-of-exe-path.patch;striplevel=2 \
file://0001-AsmMatcherEmitter-sort-ClassInfo-lists-by-name-as-we.patch;striplevel=2 \
- file://0003-llvm-fix-include-benchmarks.patch;striplevel=2"
+ file://0003-llvm-fix-include-benchmarks.patch;striplevel=2 \
+ file://0035-cmake-Enable-64bit-off_t-on-32bit-glibc-systems.patch;striplevel=2"
S = "${RUSTSRC}/src/llvm-project/llvm"
--
2.39.0
^ permalink raw reply related [flat|nested] 3+ messages in thread