Opened 7 months ago

Closed 5 months ago

#25977 closed defect (fixed)

Cross-compiling tor rust for macOS is broken

Reported by: gk Owned by:
Priority: Medium Milestone: Tor: 0.3.4.x-final
Component: Core Tor/Tor Version:
Severity: Normal Keywords: rust build 034-must
Cc: teor Actual Points:
Parent ID: #25779 Points:
Reviewer: catalyst Sponsor:

Description

Using our cross-compile setup for compiling tor with Rust support for macOS results in a build failure. It seems the macOS cross-compile Rust support is missing:

  CCLD     src/tools/tor-resolve
/var/tmp/dist/macosx-toolchain/cctools/bin/x86_64-apple-darwin10-ranlib: file: src/or/libtor.a(protover.o) has no symbols
ld: warning: ignoring file ./src/rust/target/release/libtor_rust.a, file was built for archive which is not the architecture being linked (x86_64)
ld: warning: ignoring file ./src/rust/target/release/libtor_rust.a, file was built for archive which is not the architecture being linked (x86_64)
/var/tmp/dist/macosx-toolchain/cctools/bin/x86_64-apple-darwin10-ranlib: file: src/or/libtor-testing.a(src_or_libtor_testing_a-protover.o) has no symbols
x86_64-apple-darwin10-ranlib: file: src/or/libtor.a(protover.o) has no symbols
  CCLD     src/test/test-child
  CCLD     src/test/test-switch-id
x86_64-apple-darwin10-ranlib: file: src/or/libtor-testing.a(src_or_libtor_testing_a-protover.o) has no symbols
  CCLD     src/test/test-timers
  CCLD     src/test/test-ntor-cl
ld: warning: ignoring file ./src/rust/target/release/libtor_rust.a, file was built for archive which is not the architecture being linked (x86_64)
ld: warning: ignoring file ./src/rust/target/release/libtor_rust.a, file was built for archive which is not the architecture being linked (x86_64)
  CCLD     src/test/test-hs-ntor-cl
ld: warning: ignoring file ./src/rust/target/release/libtor_rust.a, file was built for archive which is not the architecture being linked (x86_64)
  CCLD     src/test/test-bt-cl
  CCLD     src/test/fuzz/fuzz-consensus
ld: warning: ignoring file ./src/rust/target/release/libtor_rust.a, file was built for archive which is not the architecture being linked (x86_64)
ld: warning: ignoring file ./src/rust/target/release/libtor_rust.a, file was built for archive which is not the architecture being linked (x86_64)
  CCLD     src/test/fuzz/fuzz-descriptor
  CCLD     src/test/fuzz/fuzz-diff
ld: warning: ignoring file ./src/rust/target/release/libtor_rust.a, file was built for archive which is not the architecture being linked (x86_64)
ld: warning: ignoring file ./src/rust/target/release/libtor_rust.a, file was built for archive which is not the architecture being linked (x86_64)
  CCLD     src/test/fuzz/fuzz-diff-apply
ld: warning: ignoring file ./src/rust/target/release/libtor_rust.a, file was built for archive which is not the architecture being linked (x86_64)
  CCLD     src/test/fuzz/fuzz-extrainfo
  CCLD     src/test/fuzz/fuzz-hsdescv2
ld: warning: ignoring file ./src/rust/target/release/libtor_rust.a, file was built for archive which is not the architecture being linked (x86_64)
ld: warning: ignoring file ./src/rust/target/release/libtor_rust.a, file was built for archive which is not the architecture being linked (x86_64)
  CCLD     src/test/fuzz/fuzz-hsdescv3
  CCLD     src/test/fuzz/fuzz-http
ld: warning: ignoring file ./src/rust/target/release/libtor_rust.a, file was built for archive which is not the architecture being linked (x86_64)
ld: warning: ignoring file ./src/rust/target/release/libtor_rust.a, file was built for archive which is not the architecture being linked (x86_64)
  CCLD     src/test/fuzz/fuzz-http-connect
  CCLD     src/test/fuzz/fuzz-iptsv2
ld: warning: ignoring file ./src/rust/target/release/libtor_rust.a, file was built for archive which is not the architecture being linked (x86_64)
ld: warning: ignoring file ./src/rust/target/release/libtor_rust.a, file was built for archive which is not the architecture being linked (x86_64)
Undefined symbols for architecture x86_64:
  "_protocol_list_supports_protocol_or_later", referenced from:
      _summarize_protover_flags in libtor-testing.a(src_or_libtor_testing_a-routerparse.o)
  "_protocol_list_supports_protocol", referenced from:
      _summarize_protover_flags in libtor-testing.a(src_or_libtor_testing_a-routerparse.o)
ld: symbol(s) not found for architecture x86_64
clang-3.8: error: linker command failed with exit code 1 (use -v to see invocation)
Makefile:4715: recipe for target 'src/test/fuzz/fuzz-descriptor' failed
make[1]: *** [src/test/fuzz/fuzz-descriptor] Error 1
make[1]: *** Waiting for unfinished jobs....
Undefined symbols for architecture x86_64:
  "_protocol_list_supports_protocol_or_later", referenced from:
      _summarize_protover_flags in libtor-testing.a(src_or_libtor_testing_a-routerparse.o)
  "_protocol_list_supports_protocol", referenced from:
      _summarize_protover_flags in libtor-testing.a(src_or_libtor_testing_a-routerparse.o)
ld: symbol(s) not found for architecture x86_64
clang-3.8: error: linker command failed with exit code 1 (use -v to see invocation)
Makefile:4705: recipe for target 'src/test/fuzz/fuzz-consensus' failed
make[1]: *** [src/test/fuzz/fuzz-consensus] Error 1
Undefined symbols for architecture x86_64:
  "_protover_get_supported_protocols", referenced from:
      _router_build_fresh_descriptor in libtor-testing.a(src_or_libtor_testing_a-router.o)
  "_protocol_list_supports_protocol_or_later", referenced from:
Undefined symbols for architecture x86_64:
  "_protover_get_supported_protocols", referenced from:
      _router_build_fresh_descriptor in libtor-testing.a(src_or_libtor_testing_a-router.o)
      _summarize_protover_flags in libtor-testing.a(src_or_libtor_testing_a-routerparse.o)
  "_protover_all_supported", referenced from:
      _handle_missing_protocol_warning_impl in libtor-testing.a(src_or_libtor_testing_a-networkstatus.o)
  "_protocol_list_supports_protocol_or_later", referenced from:
      _summarize_protover_flags in libtor-testing.a(src_or_libtor_testing_a-routerparse.o)
  "_protocol_list_supports_protocol", referenced from:
  "_protover_all_supported", referenced from:
      _summarize_protover_flags in libtor-testing.a(src_or_libtor_testing_a-routerparse.o)
      _handle_missing_protocol_warning_impl in libtor-testing.a(src_or_libtor_testing_a-networkstatus.o)
  "_protocol_list_supports_protocol", referenced from:
ld: symbol(s) not found for architecture x86_64
      _summarize_protover_flags in libtor-testing.a(src_or_libtor_testing_a-routerparse.o)
clang-3.8: error: linker command failed with exit code 1 (use -v to see invocation)
Makefile:4785: recipe for target 'src/test/fuzz/fuzz-http-connect' failed
make[1]: *** [src/test/fuzz/fuzz-http-connect] Error 1
ld: symbol(s) not found for architecture x86_64
clang-3.8: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [src/test/fuzz/fuzz-http] Error 1
Makefile:4775: recipe for target 'src/test/fuzz/fuzz-http' failed
make[1]: Leaving directory '/var/tmp/build/tor-master'
make: *** [all] Error 2

Child Tickets

Change History (15)

comment:1 Changed 7 months ago by nickm

Keywords: build added
Milestone: Tor: 0.3.4.x-final

comment:2 Changed 6 months ago by isis

I think we need to be setting RUSTFLAGS+=" -C target-cpu=x86-64" and the host triple should be x86_64-apple-darwin.

Last edited 6 months ago by isis (previous) (diff)

comment:3 Changed 6 months ago by teor

It looks like you're cross-compiling rust for macOS i686 (32-bit) or the host Linux machine, but cross-compiling C for macOS x86_64 (64-bit).

That's why the linker gives you architecture errors.

If you are using rustup, you can override toolchains for a build directory using:

rustup override set x86_64-apple-darwin

Alternately, you could install just that toolchain.

Last edited 6 months ago by teor (previous) (diff)

comment:4 Changed 6 months ago by teor

Status: newneeds_information

comment:5 in reply to:  3 Changed 6 months ago by gk

Status: needs_informationnew

Replying to teor:

It looks like you're cross-compiling rust for macOS i686 (32-bit) or the host Linux machine, but cross-compiling C for macOS x86_64 (64-bit).

I don't think we are cross-compiling rust for i686. We are compiling it in a 64-bit environment configuring it with

--enable-local-rust --enable-vendor --enable-extended --release-channel=stable --sysconfdir=etc --target=x86_64-apple-darwin --set=target.x86_64-apple-darwin.cc=x86_64-apple-darwin-clang

FWIW: It compiles Firefox ESR 60 code fine.

comment:6 Changed 6 months ago by teor

Status: newneeds_information

Ok, well, the error logs show some architectural mismatch. So we need to know what architecture the C and Rust object files are to help you further.

Please run "file" on one of the C (libtor-testing.a) and one of the Rust (libtor_rust.a) files in the linker error messages.
It might also help to check the timestamps on the lib files: are you sure they're not left over from an earlier build?

Please also run the following Rust commands to determine the actual target triple being used:

rustc --version --verbose
cargo --version --verbose
rustup target list

Some of these commands might not be present, depending on how you installed rust.

Please also provide the cargo command-line that make produces.
It should be something like:

cargo build --target x86_64-apple-darwin

But I wonder if the target is missing from the cargo command line.

comment:7 in reply to:  6 Changed 6 months ago by gk

Status: needs_informationnew

Replying to teor:

Ok, well, the error logs show some architectural mismatch. So we need to know what architecture the C and Rust object files are to help you further.

Please run "file" on one of the C (libtor-testing.a) and one of the Rust (libtor_rust.a) files in the linker error messages.

file src_or_libtor_testing_a-routerparse.o
src_or_libtor_testing_a-routerparse.o: Mach-O 64-bit x86_64 object, flags:<|SUBSECTIONS_VIA_SYMBOLS>

file tor_rust-2a73b8dbec958119.crate.allocator.rcgu.o
tor_rust-2a73b8dbec958119.crate.allocator.rcgu.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped

It might also help to check the timestamps on the lib files: are you sure they're not left over from an earlier build?

Yes, I am. That's inside our tor-browser-build environment which uses clean docker containers for each new build.

Please also run the following Rust commands to determine the actual target triple being used:

rustc --version --verbose
cargo --version --verbose
rustup target list
debug-tor$ rustc --version --verbose
rustc 1.25.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.25.0
LLVM version: 6.0
debug-tor$ cargo --version --verbose
cargo 0.26.0
release: 0.26.0

There is no rustup available.

Some of these commands might not be present, depending on how you installed rust.

Please also provide the cargo command-line that make produces.
It should be something like:

cargo build --target x86_64-apple-darwin

But I wonder if the target is missing from the cargo command line.

That seems to be the case:

make  all-am
make[1]: Entering directory '/var/tmp/build/tor-d7bbfd0f6217'
( cd "/var/tmp/build/tor-d7bbfd0f6217/src/rust" ; \
	CARGO_TARGET_DIR="/var/tmp/build/tor-d7bbfd0f6217/src/rust/target" \
	CARGO_HOME="/var/tmp/build/tor-d7bbfd0f6217/src/rust" \
	cargo build --release  \
        --frozen \
                --manifest-path "/var/tmp/build/tor-d7bbfd0f6217/src/rust/tor_rust/Cargo.toml" )

comment:8 Changed 6 months ago by teor

Keywords: 034-must added

comment:9 Changed 6 months ago by teor

Status: newneeds_review

The patch in #25895 should solve this issue if you pass the LLVM target triple to Tor's configure.

But whatever Tor Browser is doing at build time to set the default rustc target isn't working for cargo. So maybe you can fix it on your end.

comment:10 Changed 6 months ago by dgoulet

Reviewer: nickm

comment:11 Changed 6 months ago by dgoulet

Reviewer: nickmcatalyst

comment:12 Changed 6 months ago by catalyst

Status: needs_reviewneeds_revision

Sibling ticket #25895 is in needs_revision.

comment:13 Changed 6 months ago by catalyst

Status: needs_revisionneeds_review

comment:14 Changed 6 months ago by catalyst

Status: needs_reviewmerge_ready

Sibling ticket #25895 is merge_ready.

comment:15 Changed 5 months ago by nickm

Resolution: fixed
Status: merge_readyclosed

seems reasonable to me. Merged to 0.3.4 and forward!

Note: See TracTickets for help on using tickets.