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

target arm64e-apple-darwin removing functions #131811

Closed
ds-ep opened this issue Oct 17, 2024 · 6 comments
Closed

target arm64e-apple-darwin removing functions #131811

ds-ep opened this issue Oct 17, 2024 · 6 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug.

Comments

@ds-ep
Copy link

ds-ep commented Oct 17, 2024

I tried this code:

use ctor::ctor;

#[ctor]
fn testAAAA() {
    println!("TEST123");
    panic!();
}

pub fn test123() {
    println!("TEST123");
}

I expected to see this happen:
without specifying a target everything works fine (using cargo +nightly build)

Instead, this happened:
when i specify arm64e-apple-darwin (using: cargo +nightly build -Z build-std --target arm64e-apple-darwin) my function seems to be removed.

compiling both as dylib

Meta

rustc --version --verbose:

binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: aarch64-apple-darwin
release: 1.81.0
LLVM version: 18.1.7

From aarch64-apple-darwin build in ghidra
Image
whereas on the arm64e build there is no functions at all :|
Image

CC @arttet

@ds-ep ds-ep added the C-bug Category: This is a bug. label Oct 17, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 17, 2024
@saethlin saethlin added the A-linkage Area: linking into static, shared libraries and binaries label Oct 17, 2024
@bjorn3
Copy link
Member

bjorn3 commented Oct 17, 2024

This is probably #130085. You can try linking using lld or downgrading to XCode 14 or lower. The issue I think this is only happens with the linker of XCode 15.

@ds-ep
Copy link
Author

ds-ep commented Oct 17, 2024

@bjorn3 I have xcode 16 btw, issue still exists. I tried using lld but then the output is arm64 not arm64e, and as far as im aware lld does not support arg -arch arm64e yet

@bjorn3
Copy link
Member

bjorn3 commented Oct 17, 2024

I think your options for now are limited to downgrading to XCode 14 or trying to compile rustc against Apple's LLVM fork (https://github.com/swiftlang/llvm-project). XCode 14 should be compatible with the arm64e abi in upstream LLVM, and using Apple's LLVM fork should make rustc able to emit the new arm64e abi.

@arttet
Copy link
Contributor

arttet commented Oct 17, 2024

Hey @ds-ep,

I believe this is connected to the issue.

$ clang --version
Homebrew clang version 19.1.2
Target: x86_64-apple-darwin24.0.0
Thread model: posix
InstalledDir: /usr/local/Cellar/llvm/19.1.2/bin
$ echo "int main() { return 0; }" > foo.c
$ clang -o llvm_foo.o -c foo.c --target=arm64e-apple-darwin
$ clang -o llvm_foo llvm_foo.o --target=arm64e-apple-darwin -fuse-ld=lld
$ file llvm_foo
llvm_foo: Mach-O 64-bit executable arm64

So, there are significant differences between Apple's LLVM and the upstream LLVM.

@arttet
Copy link
Contributor

arttet commented Oct 18, 2024

This is also the known issue. We have to force using XCode 14. It seems that Apple's LLVM is not compatible with Rust and requires many patches.

@ds-ep
Copy link
Author

ds-ep commented Oct 18, 2024

For anyone coming across this on MacOS 15 where Xcode 14 is not compatible and will refuse to install. you can download CL tools for xcode 14 here: https://developer.apple.com/download/all/ and use that.

@ds-ep ds-ep closed this as completed Oct 18, 2024
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 19, 2024
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 C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

6 participants