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 aarch64-*-windows-gnu* support #65

Merged
merged 3 commits into from
Apr 2, 2022

Conversation

mati865
Copy link
Contributor

@mati865 mati865 commented Mar 28, 2022

Rust PR for the target: rust-lang/rust#94872

First commit disables linking psm_s when it's absent since assembly is not compiled.

psm/build.rs Outdated
@@ -34,6 +34,7 @@ fn find_assembly(
Some(("src/arch/aarch_aapcs64.s", false))
}
}
("aarch64", _, "windows", _) => None,
Copy link
Member

Choose a reason for hiding this comment

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

This fails to include support for informational methods (stack direction, pointer.) https://github.com/rust-lang/stacker/blob/master/psm/src/arch/aarch_aapcs64.s should be contain a suitable implementation of these functions.

Why not generalize the match above to match gnu too?

        ("aarch64", _, "windows", _) => {
            if masm {
                Some(("src/arch/aarch64_armasm.asm", false))
            } else {
                Some(("src/arch/aarch_aapcs64.s", false))
            }
        }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OOTB it using this assembly with Clang fails with:

  running: "aarch64-w64-mingw32-clang" "-O3" "-ffunction-sections" "-fdata-sections" "--target=aarch64-pc-windows-gnullvm" "-ffunction-sections" "-fdata-sections" "--target=aarch64-pc-windows-gnullvm" "-xassembler-with-cpp" "-DCFG_TARGET_OS_windows" "-DCFG_TARGET_ARCH_aarch64" "-DCFG_TARGET_ENV_gnu" "-o" "/home/mateusz/Projects/rust/build/x86_64-unknown-linux-gnu/stage0-rustc/aarch64-pc-windows-gnullvm/release/build/psm-e1f284177df4f4bb/out/src/arch/aarch_aapcs64.o" "-c" "src/arch/aarch_aapcs64.s"
  cargo:warning=src/arch/aarch_aapcs64.s:24:7: error: expected absolute expression
  cargo:warning=.type rust_psm_stack_direction,@function
  cargo:warning=      ^
  cargo:warning=src/arch/aarch_aapcs64.s:31:1: error: unknown directive
  cargo:warning=.size rust_psm_stack_direction,.rust_psm_stack_direction_end-rust_psm_stack_direction
  cargo:warning=^
  cargo:warning=src/arch/aarch_aapcs64.s:37:7: error: expected absolute expression
  cargo:warning=.type rust_psm_stack_pointer,@function
  cargo:warning=      ^
  cargo:warning=src/arch/aarch_aapcs64.s:44:1: error: unknown directive
  cargo:warning=.size rust_psm_stack_pointer,.rust_psm_stack_pointer_end-rust_psm_stack_pointer
  cargo:warning=^
  cargo:warning=src/arch/aarch_aapcs64.s:50:7: error: expected absolute expression
  cargo:warning=.type rust_psm_replace_stack,@function
  cargo:warning=      ^
  cargo:warning=src/arch/aarch_aapcs64.s:58:1: error: unknown directive
  cargo:warning=.size rust_psm_replace_stack,.rust_psm_replace_stack_end-rust_psm_replace_stack
  cargo:warning=^
  cargo:warning=src/arch/aarch_aapcs64.s:64:7: error: expected absolute expression
  cargo:warning=.type rust_psm_on_stack,@function
  cargo:warning=      ^
  cargo:warning=src/arch/aarch_aapcs64.s:84:1: error: unknown directive
  cargo:warning=.size rust_psm_on_stack,.rust_psm_on_stack_end-rust_psm_on_stack
  cargo:warning=^

Makes me wonder what assembler was used with msvc toolchain when masm is unavailable.

Managed to cross compile Rust with this change to aarch_aapcs64.s:

#define GLOBL(fnname) .globl fnname
#define TYPE(fnname)
#define FUNCTION(fnname) fnname
#define SIZE(fnname,endlabel)

I don't have AArch64 Windows to test it though, should I ask somebody to test Rust with this change for me and update PR if it works?

Copy link
Member

Choose a reason for hiding this comment

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

Hm, I wonder if this a limitation of the LLVM's built-in assembler.

I don't have AArch64 Windows to test it though, should I ask somebody to test Rust with this change for me and update PR if it works?

I don't anticipate such a change to affect the behaviour of this library during a “normal” operation, but I could see it having an effect on generation of unwind tables… Since we aren't looking to support actual segmented stacks in psm on windows without Fibers, I think it is fine to make the proposed change (especially because the .type and .size directives are applicable for COFF output anyway)

Copy link
Member

Choose a reason for hiding this comment

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

Makes me wonder what assembler was used with msvc toolchain when masm is unavailable.

This configuration is largely untested ^^. The only non-msvc target actually tested is x86*windows-gnu.

@mati865 mati865 changed the title Add aarch64-*-windows-gnu* support (without assembly) Add aarch64-*-windows-gnu* support Mar 30, 2022
@nagisa nagisa merged commit 47839e7 into rust-lang:master Apr 2, 2022
@nagisa
Copy link
Member

nagisa commented Apr 2, 2022

Thanks!

@mati865 mati865 deleted the llvm-mingw-aarch64-target branch April 2, 2022 22:05
@ognevny
Copy link

ognevny commented Nov 10, 2024

it still fails with aarch64-pc-windows-gnullvm

The following warnings were emitted during compilation:
  
  warning: [email protected]: src/arch/aarch_aapcs64.s:38:1: error: unrecognized instruction mnemonic
  warning: [email protected]: END_FUNCTION(rust_psm_stack_direction)
  warning: [email protected]: ^
  warning: [email protected]: src/arch/aarch_aapcs64.s:50:1: error: unrecognized instruction mnemonic
  warning: [email protected]: END_FUNCTION(rust_psm_stack_pointer)
  warning: [email protected]: ^
  warning: [email protected]: src/arch/aarch_aapcs64.s:63:1: error: unrecognized instruction mnemonic
  warning: [email protected]: END_FUNCTION(rust_psm_replace_stack)
  warning: [email protected]: ^
  warning: [email protected]: src/arch/aarch_aapcs64.s:88:1: error: unrecognized instruction mnemonic
  warning: [email protected]: END_FUNCTION(rust_psm_on_stack)
  warning: [email protected]: ^
  
  error: failed to run custom build command for `psm v0.1.23`
  
  Caused by:
    process didn't exit successfully: `C:\M\B\src\build-CLANGARM64\target\release\build\psm-e25b9c9131bed33c\build-script-build` (exit code: 1)
    --- stdout
    OPT_LEVEL = Some(3)
    OUT_DIR = Some(C:\M\B\src\build-CLANGARM64\target\release\build\psm-633ad2b7f2604f10\out)
    TARGET = Some(aarch64-pc-windows-gnullvm)
    HOST = Some(aarch64-pc-windows-gnullvm)
    cargo:rerun-if-env-changed=CC_aarch64-pc-windows-gnullvm
    CC_aarch64-pc-windows-gnullvm = None
    cargo:rerun-if-env-changed=CC_aarch64_pc_windows_gnullvm
    CC_aarch64_pc_windows_gnullvm = None
    cargo:rerun-if-env-changed=HOST_CC
    HOST_CC = None
    cargo:rerun-if-env-changed=CC
    CC = Some(clang)
    cargo:rerun-if-env-changed=CC_KNOWN_WRAPPER_CUSTOM
    CC_KNOWN_WRAPPER_CUSTOM = None
    RUSTC_WRAPPER = None
    cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
    cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
    CRATE_CC_NO_DEFAULTS = None
    DEBUG = Some(false)
    cargo:rerun-if-env-changed=CFLAGS_aarch64-pc-windows-gnullvm
    CFLAGS_aarch64-pc-windows-gnullvm = None
    cargo:rerun-if-env-changed=CFLAGS_aarch64_pc_windows_gnullvm
    CFLAGS_aarch64_pc_windows_gnullvm = None
    cargo:rerun-if-env-changed=HOST_CFLAGS
    HOST_CFLAGS = None
    cargo:rerun-if-env-changed=CFLAGS
    CFLAGS = Some(-O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wp,-D__USE_MINGW_ANSI_STDIO=1)
    cargo:rerun-if-env-changed=CC_SHELL_ESCAPED_FLAGS
    CC_SHELL_ESCAPED_FLAGS = None
    cargo:rustc-check-cfg=cfg(switchable_stack,asm,link_asm)
    cargo:rustc-cfg=asm
    cargo:rustc-cfg=link_asm
    cargo:warning=src/arch/aarch_aapcs64.s:38:1: error: unrecognized instruction mnemonic
    cargo:warning=END_FUNCTION(rust_psm_stack_direction)
    cargo:warning=^
    cargo:warning=src/arch/aarch_aapcs64.s:50:1: error: unrecognized instruction mnemonic
    cargo:warning=END_FUNCTION(rust_psm_stack_pointer)
    cargo:warning=^
    cargo:warning=src/arch/aarch_aapcs64.s:63:1: error: unrecognized instruction mnemonic
    cargo:warning=END_FUNCTION(rust_psm_replace_stack)
    cargo:warning=^
    cargo:warning=src/arch/aarch_aapcs64.s:88:1: error: unrecognized instruction mnemonic
    cargo:warning=END_FUNCTION(rust_psm_on_stack)
    cargo:warning=^
  
    --- stderr
  
  
    error occurred: Command "clang" "-O3" "-ffunction-sections" "-fdata-sections" "--target=aarch64-pc-windows-gnu" "-O2" "-pipe" "-Wp,-D_FORTIFY_SOURCE=2" "-fstack-protector-strong" "-Wp,-D__USE_MINGW_ANSI_STDIO=1" "-xassembler-with-cpp" "-DCFG_TARGET_OS_windows" "-DCFG_TARGET_ARCH_aarch64" "-DCFG_TARGET_ENV_gnu" "-o" "C:\\M\\B\\src\\build-CLANGARM64\\target\\release\\build\\psm-633ad2b7f2604f10\\out\\e4479bd7784abb10-aarch_aapcs64.o" "-c" "src/arch/aarch_aapcs64.s" with args clang did not execute successfully (status code exit code: 1).

@mati865
Copy link
Contributor Author

mati865 commented Nov 10, 2024

Maybe a regression from f7f1e58?

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

Successfully merging this pull request may close these issues.

3 participants