Help compiling Rust for the Solaris 10 x86_64 target

I am attempting to compile Rust for the Solaris 10 x86_64 target, which I know is not supported by Rust on any tier. I am attempting to compile using a custom target.

My current approach is trying to cross-compile for the target using a Linux x86_64 host.

I already confirmed that cross-compiling a minimal no-std program was successful.

I built a gcc cross-compiler that can cross-compile for Solaris 10 x86_64 targets. I copied the amd64 system libraries off of a Solaris 10 machine into my Linux host. When I attempt to compile, I get the following error:

$ PATH="/opt/cross/bin:$PATH" cargo +nightly build -Z build-std=core,alloc,panic_abort,std --target ../solaris-10-x86_64.json)
   Compiling minimal-main v0.1.0 (/home/shane/src/rust-sun-custom-target/minimal-main)
error: linking with `/home/shane/src/rust-sun-custom-target/ld-wrapper.sh` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="<snip>" VSLANG="1033" "/home/shane/src/rust-sun-custom-target/ld-wrapper.sh" "-L/opt/cross/solaris-libs/lib/amd64" "-L/opt/cross/solaris-libs/opt/csw/lib/amd64" "-L/opt/cross/solaris-libs/lib/secure/amd64" "-L/opt/cross/solaris-libs/usr/lib/amd64" "-L/opt/cross/solaris-libs/lib" "-L/opt/cross/solaris-libs/usr/lib" "-L/opt/cross/solaris-libs/var/lib" "-rpath-link" "/opt/cross/solaris-libs/lib/amd64" "-rpath-link" "/opt/cross/solaris-libs/opt/csw/lib/amd64" "-rpath-link" "/opt/cross/solaris-libs/lib/secure/amd64" "-rpath-link" "/opt/cross/solaris-libs/usr/lib/amd64" "-rpath-link" "/opt/cross/solaris-libs/lib" "-rpath-link" "/opt/cross/solaris-libs/usr/lib" "-rpath-link" "/opt/cross/solaris-libs/var/lib" "/tmp/rustceSOTOE/symbols.o" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/minimal_main-3a1a44c6c44e6668.2foysi09r9hd290362e33qs8l.rcgu.o" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/minimal_main-3a1a44c6c44e6668.6azxfbnqaz6e9uy0sle5qt3ez.rcgu.o" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/minimal_main-3a1a44c6c44e6668.asnxhovgcys1a616j4um5h72t.rcgu.o" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/minimal_main-3a1a44c6c44e6668.b1upercwivj1qr0xt6x44l7nx.rcgu.o" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/minimal_main-3a1a44c6c44e6668.bv187j3jf4j2x0uc9yvuc55xm.rcgu.o" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/minimal_main-3a1a44c6c44e6668.c40tjotnne6zd3b4a0dii09f8.rcgu.o" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/minimal_main-3a1a44c6c44e6668.1m2ffc3n28xlxvp0n90bzvj7i.rcgu.o" "-Wl,-z,ignore" "-L" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps" "-L" "/home/shane/src/rust-sun-custom-target/minimal-main/target/debug/deps" "-L" "/home/shane/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/solaris-10-x86_64/lib" "-Wl,-Bstatic" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/libstd-1a5d125c60e9c99c.rlib" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/libpanic_abort-43e9823e098c7b8a.rlib" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/libobject-b348d484e5512fbf.rlib" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/libmemchr-c748fa9ff77e9f9f.rlib" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/libaddr2line-e6d5d44e19a0a33d.rlib" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/libgimli-7ce67da7116153bc.rlib" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/librustc_demangle-f3ee5afe00e9fd1a.rlib" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/libstd_detect-a9a2d9dd81919a2a.rlib" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/libhashbrown-863911d0cb1da10d.rlib" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/librustc_std_workspace_alloc-994a4fc93875a0b5.rlib" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/libminiz_oxide-f0bc9e1ee54428cd.rlib" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/libadler-26159fc1fafb9ff8.rlib" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/libunwind-d195e39c52541eee.rlib" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/libcfg_if-5f84924717a3a4ba.rlib" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/liblibc-4840b6b1d68c4666.rlib" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/liballoc-03368c7baa1c735b.rlib" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/librustc_std_workspace_core-3e2e834ebf4e67f3.rlib" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/libcore-c3d93fbedd7583ca.rlib" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/libcompiler_builtins-b51756432b792ef3.rlib" "-Wl,-Bdynamic" "-lsocket" "-lposix4" "-lpthread" "-lresolv" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lsendfile" "-llgrp" "-L" "/home/shane/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/solaris-10-x86_64/lib" "-o" "/home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/minimal_main-3a1a44c6c44e6668" "-nodefaultlibs"
  = note: x86_64-solaris2.11-ld: warning: cannot find entry symbol _start; defaulting to 0000000000403840
          x86_64-solaris2.11-ld: /home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/libstd-1a5d125c60e9c99c.rlib(std-1a5d125c60e9c99c.std.21af7469e5956b01-cgu.02.rcgu.o): in function `std::sys::pal::unix::rand::imp::getrandom':
          /home/shane/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/pal/unix/rand.rs:71:(.text._ZN3std3sys3pal4unix4rand3imp9getrandom17h1765b76bbe0dc541E+0x1f): undefined reference to `getrandom'
          x86_64-solaris2.11-ld: /home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/libstd-1a5d125c60e9c99c.rlib(std-1a5d125c60e9c99c.std.21af7469e5956b01-cgu.09.rcgu.o): in function `<std::sys::pal::unix::fs::Dir as core::ops::drop::Drop>::drop':
          /home/shane/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/pal/unix/fs.rs:866:(.text._ZN70_$LT$std..sys..pal..unix..fs..Dir$u20$as$u20$core..ops..drop..Drop$GT$4drop17h5238e760e3c4ae82E+0x18): undefined reference to `dirfd'
          x86_64-solaris2.11-ld: /home/shane/src/rust-sun-custom-target/minimal-main/target/solaris-10-x86_64/debug/deps/libstd-1a5d125c60e9c99c.rlib(std-1a5d125c60e9c99c.std.21af7469e5956b01-cgu.09.rcgu.o): in function `std::sys::pal::unix::alloc::aligned_malloc':
          /home/shane/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/pal/unix/alloc.rs:84:(.text._ZN3std3sys3pal4unix5alloc14aligned_malloc17h6d5a0e04adebb49fE+0x5b): undefined reference to `posix_memalign'

/home/shane/src/rust-sun-custom-target/ld-wrapper.sh is a smaller wrapper script around x86_64-solaris2.11-ld (I would include a pastebin link to the script, but I am limited to only two links per post as a new user). The script just filters out some flags that Rust tries to pass to the linker that are not compatible with the linker, specifically the following:

  • -Wl,-z,ignore
  • -Wl,-Bstatic
  • -Wl,-Bdynamic
  • -nodefaultlibs

gcc version: x86_64-solaris2.11-gcc (GCC) 9.5.0
x86_64-solaris2.11-ld version: GNU ld (GNU Binutils) 2.42

TL;DR: The three symbols that the linker fails to find are getrandom, dirfd, and posix_memalign. The linker also warns that it cannot find entry symbol _start. As can be seen from my cargo command above, I am trying to compile core, alloc, panic_abort, and std.

Since this post is already getting really long, I will focus on the missing getrandom symbol.

I see that the getrandom system call is supported in Solaris 11, which is supported by Rust. As far as I can tell, Solaris 10 does not have a getrandom system call (man getrandom outputs No manual entry for getrandom on my Solaris 10 system). I see that the Rust source code's getrandom function for solaris/illumos and some other targets is implemented here.

My custom target file is available here.

I have a few questions:

  1. In order to cross-compile for Solaris 10, would it be advisable to fork Rust, and replace parts, like the getrandom implementation, with code that will successfully compile for the Solaris 10 target? Or is there a better way to cross-compile for Solaris 10?
  2. Is there a better alternative way to build for Solaris 10?
  3. Is there any other advice for building for Solaris 10 or other custom targets in general?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.