Skip to content

Commit

Permalink
First work on aarch64-pc-windows-gnu
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisameling committed Jan 2, 2022
1 parent f7934f6 commit 07e12c9
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 28 deletions.
137 changes: 137 additions & 0 deletions aarch64-pc-windows-gnu.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
{
"abi-return-struct-as-int": true,
"allows-weak-linkage": false,
"arch": "aarch64",
"crt-objects-fallback": "mingw",
"data-layout": "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128",
"dll-prefix": "",
"dll-suffix": ".dll",
"dynamic-linking": true,
"eh-frame-header": false,
"emit-debug-gdb-scripts": false,
"env": "gnu",
"exe-suffix": ".exe",
"executables": true,
"is-builtin": false,
"is-like-windows": true,
"late-link-args-dynamic": {
"gcc": [
"-l:libunwind.dll.a"
],
"ld.lld": [
"-l:libunwind.dll.a"
]
},
"late-link-args-static": {
"gcc": [
"-l:libunwind.a"
],
"ld.lld": [
"-l:libunwind.a"
]
},
"linker": "aarch64-w64-mingw32-clang",
"llvm-target": "aarch64-pc-windows-gnu",
"max-atomic-width": 64,
"no-default-libraries": false,
"os": "windows",
"post-link-objects": {
"dynamic-dylib": [
"rsend.o"
],
"dynamic-nopic-exe": [
"rsend.o"
],
"dynamic-pic-exe": [
"rsend.o"
],
"static-dylib": [
"rsend.o"
],
"static-nopic-exe": [
"rsend.o"
],
"static-pic-exe": [
"rsend.o"
]
},
"post-link-objects-fallback": {
"dynamic-dylib": [
"rsend.o"
],
"dynamic-nopic-exe": [
"rsend.o"
],
"dynamic-pic-exe": [
"rsend.o"
],
"static-dylib": [
"rsend.o"
],
"static-nopic-exe": [
"rsend.o"
],
"static-pic-exe": [
"rsend.o"
]
},
"pre-link-args": {
"gcc": [
"-fno-use-linker-plugin",
"-Wl,--dynamicbase",
"-Wl,--disable-auto-image-base"
]
},
"pre-link-objects": {
"dynamic-dylib": [
"rsbegin.o"
],
"dynamic-nopic-exe": [
"rsbegin.o"
],
"dynamic-pic-exe": [
"rsbegin.o"
],
"static-dylib": [
"rsbegin.o"
],
"static-nopic-exe": [
"rsbegin.o"
],
"static-pic-exe": [
"rsbegin.o"
]
},
"pre-link-objects-fallback": {
"dynamic-dylib": [
"dllcrt2.o",
"rsbegin.o"
],
"dynamic-nopic-exe": [
"crt2.o",
"rsbegin.o"
],
"dynamic-pic-exe": [
"crt2.o",
"rsbegin.o"
],
"static-dylib": [
"dllcrt2.o",
"rsbegin.o"
],
"static-nopic-exe": [
"crt2.o",
"rsbegin.o"
],
"static-pic-exe": [
"crt2.o",
"rsbegin.o"
]
},
"requires-uwtable": true,
"target-family": [
"windows"
],
"target-pointer-width": "64",
"vendor": "pc"
}
18 changes: 18 additions & 0 deletions compiler/rustc_target/src/spec/aarch64_pc_windows_gnu.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use crate::spec::{LinkerFlavor, Target};

pub fn target() -> Target {
let mut base = super::windows_gnu_base::opts();
let gcc_pre_link_args = base.pre_link_args.entry(LinkerFlavor::Gcc).or_default();
gcc_pre_link_args.push("-march=armv8-a".to_string());
base.max_atomic_width = Some(64);
base.linker = Some("aarch64-w64-mingw32-clang".to_string());

Target {
llvm_target: "aarch64-pc-windows-gnu".to_string(),
pointer_width: 64,
data_layout: "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128"
.to_string(),
arch: "aarch64".to_string(),
options: base,
}
}
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ supported_targets! {

("x86_64-unknown-illumos", x86_64_unknown_illumos),

("aarch64-pc-windows-gnu", aarch64_pc_windows_gnu),
("x86_64-pc-windows-gnu", x86_64_pc_windows_gnu),
("i686-pc-windows-gnu", i686_pc_windows_gnu),
("i686-uwp-windows-gnu", i686_uwp_windows_gnu),
Expand Down
30 changes: 4 additions & 26 deletions compiler/rustc_target/src/spec/windows_gnu_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,13 @@ pub fn opts() -> TargetOptions {
],
);

let mut late_link_args = LinkArgs::new();
let mut late_link_args_dynamic = LinkArgs::new();
let mut late_link_args_static = LinkArgs::new();
// Order of `late_link_args*` was found through trial and error to work with various
// mingw-w64 versions (not tested on the CI). It's expected to change from time to time.
let mingw_libs = vec![
"-lmsvcrt".to_string(),
"-lmingwex".to_string(),
"-lmingw32".to_string(),
"-lgcc".to_string(), // alas, mingw* libraries above depend on libgcc
// mingw's msvcrt is a weird hybrid import library and static library.
// And it seems that the linker fails to use import symbols from msvcrt
// that are required from functions in msvcrt in certain cases. For example
// `_fmode` that is used by an implementation of `__p__fmode` in x86_64.
// The library is purposely listed twice to fix that.
//
// See https://github.com/rust-lang/rust/pull/47483 for some more details.
"-lmsvcrt".to_string(),
"-luser32".to_string(),
"-lkernel32".to_string(),
];
late_link_args.insert(LinkerFlavor::Gcc, mingw_libs.clone());
late_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), mingw_libs);
let dynamic_unwind_libs = vec![
// If any of our crates are dynamically linked then we need to use
// the shared libgcc_s-dw2-1.dll. This is required to support
// unwinding across DLL boundaries.
"-lgcc_s".to_string(),
"-l:libunwind.dll.a".to_string(),
];
late_link_args_dynamic.insert(LinkerFlavor::Gcc, dynamic_unwind_libs.clone());
late_link_args_dynamic.insert(LinkerFlavor::Lld(LldFlavor::Ld), dynamic_unwind_libs);
Expand All @@ -53,8 +32,7 @@ pub fn opts() -> TargetOptions {
// binaries to be redistributed without the libgcc_s-dw2-1.dll
// dependency, but unfortunately break unwinding across DLL
// boundaries when unwinding across FFI boundaries.
"-lgcc_eh".to_string(),
"-l:libpthread.a".to_string(),
"-l:libunwind.a".to_string(),
];
late_link_args_static.insert(LinkerFlavor::Gcc, static_unwind_libs.clone());
late_link_args_static.insert(LinkerFlavor::Lld(LldFlavor::Ld), static_unwind_libs);
Expand All @@ -64,7 +42,8 @@ pub fn opts() -> TargetOptions {
env: "gnu".to_string(),
vendor: "pc".to_string(),
// FIXME(#13846) this should be enabled for windows
function_sections: false,
function_sections: true,
no_default_libraries: false,
linker: Some("gcc".to_string()),
dynamic_linking: true,
executables: true,
Expand All @@ -80,7 +59,6 @@ pub fn opts() -> TargetOptions {
pre_link_objects_fallback: crt_objects::pre_mingw_fallback(),
post_link_objects_fallback: crt_objects::post_mingw_fallback(),
crt_objects_fallback: Some(CrtObjectsFallback::Mingw),
late_link_args,
late_link_args_dynamic,
late_link_args_static,
abi_return_struct_as_int: true,
Expand Down
Binary file added missing-libs-hack/libgcc.a
Binary file not shown.
Binary file added missing-libs-hack/libgcc_eh.a
Binary file not shown.
Binary file added missing-libs-hack/libgcc_s.a
Binary file not shown.
6 changes: 6 additions & 0 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,12 @@ def download_toolchain(self, stage0=True, rustc_channel=None):
with output(self.rustc_stamp(stage0)) as rust_stamp:
rust_stamp.write(key)

gcc_libs_hack = '{}/missing-libs-hack'.format(self.rust_root)
gcc_libs_hack_dest = '{}/rustlib/{}/lib'.format(lib_dir, self.build)
shutil.copy(gcc_libs_hack + '/libgcc.a', gcc_libs_hack_dest)
shutil.copy(gcc_libs_hack + '/libgcc_eh.a', gcc_libs_hack_dest)
shutil.copy(gcc_libs_hack + '/libgcc_s.a', gcc_libs_hack_dest)

if self.rustfmt() and self.rustfmt().startswith(bin_root) and (
not os.path.exists(self.rustfmt())
or self.program_out_of_date(
Expand Down
6 changes: 4 additions & 2 deletions src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,16 @@ fn make_win_dist(
"i686-w64-mingw32-gcc.exe"
} else if target == "x86_64-pc-windows-gnu" {
"x86_64-w64-mingw32-gcc.exe"
} else if target == "aarch64-pc-windows-gnu" {
"aarch64-w64-mingw32-gcc.exe"
} else {
"gcc.exe"
};
let target_tools = [compiler, "ld.exe", "dlltool.exe", "libwinpthread-1.dll"];
let mut rustc_dlls = vec!["libwinpthread-1.dll"];
if target.starts_with("i686-") {
rustc_dlls.push("libgcc_s_dw2-1.dll");
} else {
} else if target.starts_with("x86_64-") {
rustc_dlls.push("libgcc_s_seh-1.dll");
}

Expand All @@ -182,7 +184,7 @@ fn make_win_dist(
"libm.a",
"libmingw32.a",
"libmingwex.a",
"libstdc++.a",
//"libstdc++.a",
"libiconv.a",
"libmoldname.a",
"libpthread.a",
Expand Down
1 change: 1 addition & 0 deletions src/build_helper/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ pub fn gnu_target(target: &str) -> &str {
"x86_64-pc-windows-msvc" => "x86_64-pc-win32",
"i686-pc-windows-gnu" => "i686-w64-mingw32",
"x86_64-pc-windows-gnu" => "x86_64-w64-mingw32",
"aarch64-pc-windows-gnu" => "aarch64-w64-mingw32",
s => s,
}
}
Expand Down

0 comments on commit 07e12c9

Please sign in to comment.