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

Add the aarch64-apple-darwin target #74541

Merged
merged 2 commits into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@ version = "0.1.0"

[[package]]
name = "cc"
version = "1.0.57"
version = "1.0.58"
alexcrichton marked this conversation as resolved.
Show resolved Hide resolved
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fde55d2a2bfaa4c9668bbc63f531fbdeee3ffe188f4662511ce2c22b3eedebe"
checksum = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518"
dependencies = [
"jobserver",
]
Expand Down Expand Up @@ -1576,9 +1576,9 @@ checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"

[[package]]
name = "libc"
version = "0.2.71"
version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49"
checksum = "bd7d4bd64732af4bf3a67f367c27df8520ad7e230c5817b8ff485864d80242b9"
dependencies = [
"rustc-std-workspace-core",
]
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_llvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ static-libstdcpp = []
emscripten = []

[dependencies]
libc = "0.2"
libc = "0.2.73"

[build-dependencies]
build_helper = { path = "../build_helper" }
cc = "1.0.1"
cc = "1.0.58"
30 changes: 30 additions & 0 deletions src/librustc_target/spec/aarch64_apple_darwin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult};

pub fn target() -> TargetResult {
let mut base = super::apple_base::opts();
base.cpu = "apple-a12".to_string();
devsnek marked this conversation as resolved.
Show resolved Hide resolved
base.max_atomic_width = Some(128);
base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-arch".to_string(), "arm64".to_string()]);

base.link_env_remove.extend(super::apple_base::macos_link_env_remove());

// Clang automatically chooses a more specific target based on
// MACOSX_DEPLOYMENT_TARGET. To enable cross-language LTO to work
// correctly, we do too.
let arch = "aarch64";
let llvm_target = super::apple_base::macos_llvm_target(&arch);

Ok(Target {
llvm_target,
target_endian: "little".to_string(),
target_pointer_width: "64".to_string(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

% cat size.c
#include <stdio.h>

int main() {
  printf("%zu\n", sizeof(void *));
  return 0;
}

% cc size.c

% file a.out
a.out: Mach-O 64-bit executable arm64

% ./a.out
8

target_c_int_width: "32".to_string(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

% cat size.c
#include <stdio.h>

int main() {
  printf("%zu\n", sizeof(int));
  return 0;
}

% cc size.c

% file a.out
a.out: Mach-O 64-bit executable arm64

% ./a.out
4

Copy link
Member

@jyn514 jyn514 Jul 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might also want printf("%zu %zu\n", sizeof(int*), sizeof(int (*)()));. Not that I expect it to be anything other than 8 bytes. Whoops, that was your next comment!

data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".to_string(),
Copy link
Member Author

@shepmaster shepmaster Jul 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was copied from LLVM.

arch: arch.to_string(),
target_os: "macos".to_string(),
target_env: String::new(),
target_vendor: "apple".to_string(),
linker_flavor: LinkerFlavor::Gcc,
options: TargetOptions { target_mcount: "\u{1}mcount".to_string(), ..base },
})
}
1 change: 1 addition & 0 deletions src/librustc_target/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ supported_targets! {
("i686-unknown-haiku", i686_unknown_haiku),
("x86_64-unknown-haiku", x86_64_unknown_haiku),

("aarch64-apple-darwin", aarch64_apple_darwin),
("x86_64-apple-darwin", x86_64_apple_darwin),
("i686-apple-darwin", i686_apple_darwin),

Expand Down
5 changes: 4 additions & 1 deletion src/librustc_target/spec/x86_64_apple_darwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ pub fn target() -> TargetResult {
base.cpu = "core2".to_string();
base.max_atomic_width = Some(128); // core2 support cmpxchg16b
base.eliminate_frame_pointer = false;
base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-m64".to_string()]);
base.pre_link_args.insert(
LinkerFlavor::Gcc,
vec!["-m64".to_string(), "-arch".to_string(), "x86_64".to_string()],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These additions allow cross-compiling from aarch64 back to x86_64.

);
base.link_env_remove.extend(super::apple_base::macos_link_env_remove());
base.stack_probes = true;

Expand Down