Skip to content

Commit

Permalink
Merge pull request #2144 from saschagrunert/s390x-musl
Browse files Browse the repository at this point in the history
Build s390x binaries using musl libc
  • Loading branch information
openshift-merge-bot[bot] authored Apr 24, 2024
2 parents 0294515 + ef35ef8 commit 65763db
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 6 deletions.
90 changes: 90 additions & 0 deletions conmon-rs/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,93 @@
pub mod conmon_capnp {
include!(concat!(env!("OUT_DIR"), "/proto/conmon_capnp.rs"));
}

/// Workaround for rustc bug: https://github.com/rust-lang/rust/issues/47493
///
/// It shouldn't even be possible to reach this function, thanks to panic=abort,
/// but libcore is compiled with unwinding enabled and that ends up making unreachable
/// references to this.
#[cfg(all(target_os = "linux", target_arch = "s390x", target_env = "musl"))]
mod unwind {
#[no_mangle]
unsafe extern "C" fn _Unwind_Backtrace() {
unimplemented!("_Unwind_Backtrace")
}
#[no_mangle]
unsafe extern "C" fn _Unwind_DeleteException() {
unimplemented!("_Unwind_DeleteException")
}
#[no_mangle]
unsafe extern "C" fn _Unwind_GetDataRelBase() {
unimplemented!("_Unwind_GetDataRelBase")
}
#[no_mangle]
unsafe extern "C" fn _Unwind_GetIP() {
unimplemented!("_Unwind_GetIP")
}
#[no_mangle]
unsafe extern "C" fn _Unwind_GetIPInfo() {
unimplemented!("_Unwind_GetIPInfo")
}
#[no_mangle]
unsafe extern "C" fn _Unwind_GetLanguageSpecificData() {
unimplemented!("_Unwind_GetLanguageSpecificData")
}
#[no_mangle]
unsafe extern "C" fn _Unwind_GetRegionStart() {
unimplemented!("_Unwind_GetRegionStart")
}
#[no_mangle]
unsafe extern "C" fn _Unwind_GetTextRelBase() {
unimplemented!("_Unwind_GetTextRelBase")
}
#[no_mangle]
unsafe extern "C" fn _Unwind_RaiseException() {
unimplemented!("_Unwind_RaiseException")
}
#[no_mangle]
unsafe extern "C" fn _Unwind_Resume() {
unimplemented!("_Unwind_Resume")
}
#[no_mangle]
unsafe extern "C" fn _Unwind_SetGR() {
unimplemented!("_Unwind_SetGR")
}
#[no_mangle]
unsafe extern "C" fn _Unwind_SetIP() {
unimplemented!("_Unwind_SetIP")
}
#[no_mangle]
unsafe extern "C" fn _Unwind_FindEnclosingFunction() {
unimplemented!("_Unwind_FindEnclosingFunction")
}
#[no_mangle]
unsafe extern "C" fn _Unwind_GetCFA() {
unimplemented!("_Unwind_GetCFA")
}
#[cfg(target_arch = "arm")]
#[no_mangle]
unsafe extern "C" fn _Unwind_VRS_Get() {
unimplemented!("_Unwind_VRS_Get")
}
#[cfg(target_arch = "arm")]
#[no_mangle]
unsafe extern "C" fn _Unwind_VRS_Set() {
unimplemented!("_Unwind_VRS_Set")
}
#[cfg(target_arch = "arm")]
#[no_mangle]
unsafe extern "C" fn __aeabi_unwind_cpp_pr0() {
unimplemented!("__aeabi_unwind_cpp_pr0")
}
#[cfg(target_arch = "arm")]
#[no_mangle]
unsafe extern "C" fn __aeabi_unwind_cpp_pr1() {
unimplemented!("__aeabi_unwind_cpp_pr1")
}
#[cfg(target_arch = "arm")]
#[no_mangle]
unsafe extern "C" fn __gnu_unwind_frame() {
unimplemented!("__gnu_unwind_frame")
}
}
5 changes: 4 additions & 1 deletion nix/default-s390x.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
(import ./nixpkgs.nix {
crossSystem = {
config = "s390x-unknown-linux-gnu";
# TODO: Switch back to glibc when
# https://github.com/NixOS/nixpkgs/issues/306473
# is resolved.
config = "s390x-unknown-linux-musl";
};
overlays = [ (import ./overlay.nix) ];
}).callPackage ./derivation.nix
Expand Down
20 changes: 16 additions & 4 deletions nix/derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,25 @@ with pkgs; rustPlatform.buildRustPackage {
capnproto
protobuf
];
buildInputs = [
glibc
glibc.static
];
buildInputs =
if stdenv.hostPlatform.isMusl then [
libunwind
] else [
glibc
glibc.static
];
RUSTFLAGS = [
"-Ctarget-feature=+crt-static"
] ++ lib.optionals stdenv.hostPlatform.isMusl [
"-Cpanic=abort"
"-Clink-args=-nostartfiles"
"-Clink-args=-L${libunwind}/lib"
];
# Patch nix v0.27.1 for musl
preBuild = lib.optionalString stdenv.hostPlatform.isMusl ''
sed -i 's;target_arch = "s390x";target_arch = "s390x" , not(target_env = "musl");g' \
/build/cargo-vendor-dir/nix-0.27.1/src/sys/statfs.rs
'';
stripAllList = [ "bin" ];
cargoLock = {
lockFile = lib.cleanSource ./.. + "/Cargo.lock";
Expand Down
4 changes: 3 additions & 1 deletion nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ let
static = import ./static.nix;
in
self: super:
{ }
{
libunwind = (static super.libunwind);
}

0 comments on commit 65763db

Please sign in to comment.