Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linker fails to link rlibs on arm64_32-apple-watchos #103508

Closed
thomcc opened this issue Oct 25, 2022 · 9 comments
Closed

Linker fails to link rlibs on arm64_32-apple-watchos #103508

thomcc opened this issue Oct 25, 2022 · 9 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries O-watchos Operating System: watchOS T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@thomcc
Copy link
Member

thomcc commented Oct 25, 2022

In rust-random/getrandom#317 I tried to add watchOS and tvOS support to getrandom. During this process, I tried to do a cargo test --no-run build for watchOS, which gave me a long error output, seemingly indicating that the linker was ignoring rlibs:

$ cargo test --no-run --target=arm64_32-apple-watchos --features=std -Zbuild-std
   Compiling compiler_builtins v0.1.82
   Compiling core v0.0.0 (/Users/thom/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core)
   Compiling libc v0.2.135
   Compiling cc v1.0.73
   Compiling memchr v2.5.0
   Compiling std v0.0.0 (/Users/thom/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std)
   Compiling libc v0.2.134
   Compiling unwind v0.0.0 (/Users/thom/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/unwind)
   Compiling rustc-std-workspace-core v1.99.0 (/Users/thom/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling alloc v0.0.0 (/Users/thom/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc)
   Compiling cfg-if v0.1.10
   Compiling adler v0.2.3
   Compiling cfg-if v1.0.0
   Compiling rustc-demangle v0.1.21
   Compiling rustc-std-workspace-alloc v1.99.0 (/Users/thom/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/rustc-std-workspace-alloc)
   Compiling panic_abort v0.0.0 (/Users/thom/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/panic_abort)
   Compiling panic_unwind v0.0.0 (/Users/thom/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/panic_unwind)
   Compiling gimli v0.25.0
   Compiling miniz_oxide v0.4.0
   Compiling hashbrown v0.12.3
   Compiling std_detect v0.1.5 (/Users/thom/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/stdarch/crates/std_detect)
   Compiling object v0.26.2
   Compiling addr2line v0.16.0
   Compiling rustc-std-workspace-std v1.99.0 (/Users/thom/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/rustc-std-workspace-std)
   Compiling proc_macro v0.0.0 (/Users/thom/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/proc_macro)
   Compiling unicode-width v0.1.10
   Compiling getopts v0.2.21
   Compiling test v0.0.0 (/Users/thom/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/test)
   Compiling getrandom v0.2.8 (/Users/thom/src/getrandom)
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-arch" "arm64_32" "/var/folders/rw/gsmfnk2s12d34hywmktc28q40000gn/T/rustcNYxOPt/symbols.o" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/rdrand-b52dd97b5239a0b7.2ork2r0rcxk94nbd.rcgu.o" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/rdrand-b52dd97b5239a0b7.4jje0c9039g88kgo.rcgu.o" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/rdrand-b52dd97b5239a0b7.4pecv3q9ri5hy0zd.rcgu.o" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/rdrand-b52dd97b5239a0b7.b3n7dwxrwzxbdcp.rcgu.o" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/rdrand-b52dd97b5239a0b7.lsfs3nk3c01pk5.rcgu.o" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/rdrand-b52dd97b5239a0b7.rqzkfwxeqxih7xp.rcgu.o" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/rdrand-b52dd97b5239a0b7.3saglnyvx5ikb5f6.rcgu.o" "-L" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps" "-L" "/Users/thom/src/getrandom/target/debug/deps" "-L" "/Users/thom/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/arm64_32-apple-watchos/lib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libtest-e8407cf03fd58926.rlib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libgetopts-5e24c94c3b28df0e.rlib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libunicode_width-418a066791e771b4.rlib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/librustc_std_workspace_std-1b2a72518ff8604b.rlib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libstd-c164cc8175dfef3f.rlib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libpanic_unwind-91156a10bf4dd4e5.rlib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libobject-76bf7c072cc6ff68.rlib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libmemchr-3c9deff40f724412.rlib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libaddr2line-cd2dc24440645334.rlib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libgimli-817e0acbb0be0869.rlib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/librustc_demangle-dd4d413b6a90232b.rlib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libstd_detect-309d48fe36d039a2.rlib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libcfg_if-52e3d2adfc8cb734.rlib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libhashbrown-1527b3242773f09f.rlib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libminiz_oxide-e6feb1ffc6ec23e3.rlib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libadler-819cfeddc3afb6c4.rlib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/librustc_std_workspace_alloc-53a6423750846103.rlib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libunwind-56369296e40eca8b.rlib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libcfg_if-68520f3f6d145118.rlib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/liblibc-427814d894d71fdc.rlib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/liballoc-ce9b80b9f986a4d6.rlib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/librustc_std_workspace_core-599d32924b1c01f2.rlib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libcore-d8712872fdd20492.rlib" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libcompiler_builtins-1125f1819af83722.rlib" "-lSystem" "-lobjc" "-framework" "Security" "-framework" "Foundation" "-lc" "-lm" "-isysroot" "/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS9.0.sdk" "-Wl,-syslibroot" "/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS9.0.sdk" "-L" "/Users/thom/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/arm64_32-apple-watchos/lib" "-o" "/Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/rdrand-b52dd97b5239a0b7" "-Wl,-dead_strip" "-nodefaultlibs"
  = note: ld: warning: directory not found for option '-L/Users/thom/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/arm64_32-apple-watchos/lib'
          ld: warning: directory not found for option '-L/Users/thom/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/arm64_32-apple-watchos/lib'
          ld: warning: ignoring file /var/folders/rw/gsmfnk2s12d34hywmktc28q40000gn/T/rustcNYxOPt/symbols.o, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libunicode_width-418a066791e771b4.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/librustc_std_workspace_std-1b2a72518ff8604b.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libpanic_unwind-91156a10bf4dd4e5.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libmemchr-3c9deff40f724412.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libaddr2line-cd2dc24440645334.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libobject-76bf7c072cc6ff68.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libstd_detect-309d48fe36d039a2.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libcfg_if-52e3d2adfc8cb734.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libtest-e8407cf03fd58926.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libgimli-817e0acbb0be0869.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libhashbrown-1527b3242773f09f.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/librustc_std_workspace_alloc-53a6423750846103.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libunwind-56369296e40eca8b.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libcfg_if-68520f3f6d145118.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libminiz_oxide-e6feb1ffc6ec23e3.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/librustc_std_workspace_core-599d32924b1c01f2.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/liblibc-427814d894d71fdc.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libcompiler_builtins-1125f1819af83722.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libstd-c164cc8175dfef3f.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libgetopts-5e24c94c3b28df0e.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/librustc_demangle-dd4d413b6a90232b.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libadler-819cfeddc3afb6c4.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/liballoc-ce9b80b9f986a4d6.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          ld: warning: ignoring file /Users/thom/src/getrandom/target/arm64_32-apple-watchos/debug/deps/libcore-d8712872fdd20492.rlib, building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64
          Undefined symbols for architecture arm64_32:
            "std::rt::lang_start_internal::h0a6997aae5e7685a", referenced from:
                std::rt::lang_start::h57ca5847e0db6f0d in rdrand-b52dd97b5239a0b7.4pecv3q9ri5hy0zd.rcgu.o
            "core::hint::black_box::h02254acf856e3b06", referenced from:
                std::sys_common::backtrace::__rust_begin_short_backtrace::h185210fb7a6c39f0 in rdrand-b52dd97b5239a0b7.2ork2r0rcxk94nbd.rcgu.o
            "test::test_main_static::hc3a2eb5568ebf3fc", referenced from:
                rdrand::main::h700cce9a9d899f8f in rdrand-b52dd97b5239a0b7.b3n7dwxrwzxbdcp.rcgu.o
            "_rust_eh_personality", referenced from:
                Dwarf Exception Unwind Info (__eh_frame) in rdrand-b52dd97b5239a0b7.2ork2r0rcxk94nbd.rcgu.o
                Dwarf Exception Unwind Info (__eh_frame) in rdrand-b52dd97b5239a0b7.4jje0c9039g88kgo.rcgu.o
          ld: symbol(s) not found for architecture arm64_32
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

This seems to indicate that we aren't invoking the linker correctly on arm64_32-apple-watchos, or that it doesn't understand rlibs for some other reason. This is on macOS 13.0 and the SDKs from XCode 14.0.1. Perhaps that is related? I'm not sure.

CC @vladimir-ea, @deg4uss3r (listed as owners of that target on https://doc.rust-lang.org/nightly/rustc/platform-support/apple-watchos.html)

@thomcc thomcc added A-linkage Area: linking into static, shared libraries and binaries T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. O-watchos Operating System: watchOS labels Oct 25, 2022
@thomcc
Copy link
Member Author

thomcc commented Oct 25, 2022

The -sim targets work, including aarch64-apple-watchos-sim, which hints that perhaps the arm64_32 arch is being mishandled somewhere.

@vladimir-ea
Copy link
Contributor

"building for watchOS-arm64_32 but attempting to link with file built for unknown-arm64" does seem to indicate something awry somewhere.

I had getrandom building ok some time ago. This was the change I had made: vladimir-ea/getrandom@da2e815 (there was also the same change on the 0.1 version).

in your changes what is the apple_other.rs that you include instead of ios.rs?

@vladimir-ea
Copy link
Contributor

Also, has stdlib support of watchos been merged yet?

@thomcc
Copy link
Member Author

thomcc commented Oct 25, 2022

Also, has stdlib support of watchos been merged yet?

Yes, but it still requires nightly and -Zbuild-std due to not shipping watchOS builds via rustup.

in your changes what is the apple_other.rs that you include instead of ios.rs?

It's completely identical to ios.rs, just renamed. It's basically what you did. I don't believe the issue is with the getrandom patch (after all, the simulator targets work).

@vladimir-ea
Copy link
Contributor

Does armv7k-apple-watchos work? I will see if I can reproduce

@vladimir-ea
Copy link
Contributor

vladimir-ea commented Oct 25, 2022

So definitely something is broken, I can no longer build target on current Rust master (rust % ./x.py b library/std --target arm64_32-apple-watchos).

I am not sure what the problem is, but I think it might be due to library/backtrace or library/unwind. These moved to submodules at some point during the progress of the watchos changes and it looks like something there might be brok. Grep those repos for 'ios' - there are a number of places where 'watchos' is not covered.

I will try to look further, but about to start 5 days of vacation...

@thomcc
Copy link
Member Author

thomcc commented Oct 25, 2022

I am not sure what the problem is, but I think it might be due to library/backtrace or library/unwind

I suspect this is unrelated given that the simulators work, and many of the errors pointing to a different thing. I do agree that probably backtrace needs some adjustment though, and will work on that after work.

I will try to look further, but about to start 5 days of vacation...

Enjoy your vacation, thanks for responding.

@vladimir-ea
Copy link
Contributor

@thomcc This was a bit of a 'wild goose chase' but I finally found out what the issue is: #104361.

@kadiwa4
Copy link
Contributor

kadiwa4 commented Feb 19, 2024

#104361 was merged and it claimed to fix this. Can this be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries O-watchos Operating System: watchOS T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants