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

openssl-sys can't find openssl@3 only when run remotely crosscompiling x86_64 on arm64 #2229

Closed
jackfarzan opened this issue Apr 29, 2024 · 13 comments

Comments

@jackfarzan
Copy link

jackfarzan commented Apr 29, 2024

I'm cross-compiling iOS x86_64 on Mac M1 with OpenSSL@3.

	rustup target add x86_64-apple-ios
	IPHONEOS_DEPLOYMENT_TARGET=15.0 cargo build \
		--target=x86_64-apple-ios \
		--release \
		--no-default-features

The command works as expected when executed manually, but if I try to execute the build remotely via Ansible, I get a linking error.

      = note: Undefined symbols for architecture x86_64:
                "_opendir$INODE64", referenced from:
                    _OPENSSL_DIR_read in libopenssl_sys-400c31d8c0f7b518.rlib(libcrypto-lib-o_dir.o)
                "_readdir$INODE64", referenced from:
                    _OPENSSL_DIR_read in libopenssl_sys-400c31d8c0f7b518.rlib(libcrypto-lib-o_dir.o)
              ld: symbol(s) not found for architecture x86_64
              clang: error: linker command failed with exit code 1 (use -v to see invocation)

How can I further troubleshoot this issue?

Using:

[[package]]
name = "openssl-sys"
version = "0.9.101"
@jackfarzan jackfarzan changed the title openssl-sys can't find openssl@3 only when run by ansible openssl-sys can't find openssl@3 only when run remotely crosscompiling x86_64 on arm64 Apr 29, 2024
@sfackler
Copy link
Owner

Homebrew does not install a version of OpenSSL built for iOS.

@sfackler
Copy link
Owner

I am not familiar enough with how the x86_64 iOS emulator target works to know if it shouldn't be working at all, but I am totally unsurprised that it wouldn't work.

We probably shouldn't even be looking for homebrew when not targeting macOS tbh.

@jackfarzan
Copy link
Author

It seems like there's been a major miscommunication between another engineer and I as we've been working on this. Will need to straighten things out with them first, will report back here if there's still an issue. Thanks for your response!

@jackfarzan
Copy link
Author

jackfarzan commented Apr 30, 2024

Ok, I've cleared up that it's not OpenSSL, I've removed brew-installed OpenSSLs and get the same error. The issue is specifically with cross-compiling for x86_64 on an ARM machine in a remote scripted setting. My guess there is some dependency missing from the PATH in the Ansible environment that is preventing this from running correctly there, since the cross-compilation works fine when I build manually. What could be missing here?

@jackfarzan
Copy link
Author

I just tried to run this on an x86_64 Mac - ie no longer cross-compiling - and have encountered the same exact error:

      = note: Undefined symbols for architecture x86_64:
                "_opendir$INODE64", referenced from:
                    _OPENSSL_DIR_read in libopenssl_sys-e6ef6c0b2f836fec.rlib(libcrypto-lib-o_dir.o)
                "_readdir$INODE64", referenced from:
                    _OPENSSL_DIR_read in libopenssl_sys-e6ef6c0b2f836fec.rlib(libcrypto-lib-o_dir.o)
              ld: symbol(s) not found for architecture x86_64
              clang: error: linker command failed with exit code 1 (use -v to see invocation)
              ```

@sfackler
Copy link
Owner

Where is the OpenSSL it's using coming from?

@jackfarzan
Copy link
Author

jackfarzan commented May 1, 2024

this is the only openssl installed on the x86_64 system:

% which openssl
/usr/local/bin/openssl
% openssl --version
OpenSSL 3.3.0 9 Apr 2024 (Library: OpenSSL 3.3.0 9 Apr 2024)

and on arm64:

% which openssl
/usr/bin/openssl
% openssl version
LibreSSL 3.3.6

@sfackler
Copy link
Owner

sfackler commented May 2, 2024

You're going to need a version of OpenSSL built for your target. This can be done for you by enabling the vendored Cargo feature. I'm not sure if you'd need to do any extra configuration to make the cross compilation work - I think Apple's Clang can target it automatically?

@jackfarzan
Copy link
Author

I'll try adding the vendored flag and see if I make any progress. Can you think of any reasons why it would work when run as a human user, but not via Ansible/python wrapper? I didn't see any obvious env var differences.

@sfackler
Copy link
Owner

sfackler commented May 5, 2024

The only differences would be in the overall environment (env vars, things that are installed, etc).

@jackfarzan
Copy link
Author

jackfarzan commented May 7, 2024

Thanks. I'm not able to reproduce the error when running manually when setting Path variables to be the same, and dependencies that I'm aware of seem to be available in both environments. I'm back to thinking this is an Ansible issue, so I'll do some more digging and will report back if needed.

@Skepfyr
Copy link
Collaborator

Skepfyr commented May 8, 2024

Staring at the error message you're getting, it looks like you have a valid version of OpenSSL, but it can't find the "_opendir$INODE64" or "_readdir$INODE64" which I'd expect to find in libc (libSystem? I don't know macOS). I suspect you're missing something libc related, although I'd expect those symbols to be dynamically linked so I'm not entirely sure what's up.

@jackfarzan
Copy link
Author

Reporting back - seems like the issue is something is setting SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk, and that's causing the intel build to fail. Will have to resolve that separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants