From 1e03698b68534d0da2b1aeddfc93551e1d5dd8d4 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 1 Mar 2022 03:35:26 +0100 Subject: [PATCH 1/6] Initial assembly test setup --- Cargo.toml | 1 + tests/Cargo.toml | 6 + .../test_msg_send_zero_cost/Cargo.toml | 11 ++ tests/assembly/test_msg_send_zero_cost/lib.rs | 9 ++ tests/build.rs | 3 + tests/src/bin/test_assembly.rs | 122 ++++++++++++++++++ 6 files changed, 152 insertions(+) create mode 100644 tests/assembly/test_msg_send_zero_cost/Cargo.toml create mode 100644 tests/assembly/test_msg_send_zero_cost/lib.rs create mode 100644 tests/src/bin/test_assembly.rs diff --git a/Cargo.toml b/Cargo.toml index 0dfd40efa..47ad4dc92 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,4 +7,5 @@ members = [ "block2", "block-sys", "tests", + "tests/assembly/*", ] diff --git a/tests/Cargo.toml b/tests/Cargo.toml index f51bd605d..f65187d8e 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -18,6 +18,7 @@ build = "build.rs" # # Also, they're slower than most tests. ui = ["trybuild"] +assembly = ["cargo_metadata"] [dependencies] block2 = { path = "../block2" } @@ -29,9 +30,14 @@ objc2-foundation = { path = "../objc2-foundation" } # Put here instead of dev-dependencies because we want to make it optional trybuild = { version = "1.0", optional = true } +cargo_metadata = { version = "0.14", optional = true } [build-dependencies] cc = "1.0" [dev-dependencies] paste = "1.0" + +[[bin]] +name = "test_assembly" +required-features = ["assembly"] diff --git a/tests/assembly/test_msg_send_zero_cost/Cargo.toml b/tests/assembly/test_msg_send_zero_cost/Cargo.toml new file mode 100644 index 000000000..7b4b713b4 --- /dev/null +++ b/tests/assembly/test_msg_send_zero_cost/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "test_msg_send_zero_cost" +version = "0.1.0" +edition = "2018" +publish = false + +[lib] +path = "lib.rs" + +[dependencies] +objc2 = { path = "../../../objc2" } diff --git a/tests/assembly/test_msg_send_zero_cost/lib.rs b/tests/assembly/test_msg_send_zero_cost/lib.rs new file mode 100644 index 000000000..9a29a4af4 --- /dev/null +++ b/tests/assembly/test_msg_send_zero_cost/lib.rs @@ -0,0 +1,9 @@ +//! Test that the inner part of msg_send! is inlined into an objc_msgSend + +use objc2::runtime::{Object, Sel}; +use objc2::MessageReceiver; + +#[no_mangle] +pub fn handle(obj: &Object, sel: Sel) -> *mut Object { + unsafe { MessageReceiver::send_message(&obj, sel, ()).unwrap() } +} diff --git a/tests/build.rs b/tests/build.rs index 2271e764a..ed907b019 100644 --- a/tests/build.rs +++ b/tests/build.rs @@ -22,5 +22,8 @@ fn main() { builder.flag(flag); } + // For assembly tests + println!("cargo:rustc-env=TARGET={}", env::var("TARGET").unwrap()); + builder.compile("libencode_utils.a"); } diff --git a/tests/src/bin/test_assembly.rs b/tests/src/bin/test_assembly.rs new file mode 100644 index 000000000..463793b27 --- /dev/null +++ b/tests/src/bin/test_assembly.rs @@ -0,0 +1,122 @@ +//! A helper script for testing the assembly output. +//! +//! Similar to `trybuild` and `compiletest`, except specialized to our setup! + +use cargo_metadata::Message; +use std::env; +use std::env::args; +use std::fmt::Write; +use std::fs; +use std::io; +use std::path::Path; +use std::process::{Command, Stdio}; + +fn strip_section(data: &str, section: &str) -> String { + let mut res = String::with_capacity(data.len()); + let mut in_removed_section = false; + for line in data.lines() { + // This only works for the __LLVM sections we're interested in + if line == "" { + in_removed_section = false; + } + if line.trim().starts_with(".section") { + in_removed_section = line.contains(section); + } + if !in_removed_section { + res.push_str(line); + } else { + write!(res, "; Stripped {section} line").unwrap(); + } + res.push('\n'); + } + res +} + +fn read_assembly>(path: P) -> io::Result { + let s = fs::read_to_string(path)?; + let workspace_dir = Path::new(env!("CARGO_MANIFEST_DIR")) + .parent() + .unwrap() + .as_os_str() + .to_str() + .unwrap(); + let s = s.replace(workspace_dir, "$WORKSPACE"); + // We remove the __LLVM,__bitcode and __LLVM,__cmdline sections because + // they're uninteresting for out use-case. + // + // See https://github.com/rust-lang/rust/blob/1.59.0/compiler/rustc_codegen_llvm/src/back/write.rs#L978-L1074 + Ok(strip_section(&s, "__LLVM")) +} + +fn main() { + let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR")); + let should_overwrite = option_env!("TEST_OVERWRITE").is_some(); + let host = env!("TARGET"); + + for entry in manifest_dir.join("assembly").read_dir().unwrap() { + let package_path = entry.unwrap().path(); + let package = package_path.file_name().unwrap().to_str().unwrap(); + + println!("Testing {package}."); + + let result = Command::new(std::env::var("CARGO").unwrap_or("cargo".into())) + // .arg("+nightly") + // .arg("-Zbuild-std") + // .arg("-vv") + .arg("rustc") + .arg(format!("--package={package}")) + .args(args().skip(2)) + .arg("--release") + .arg("--message-format=json-render-diagnostics") + .arg("--") + .arg("--emit=asm") + .stdout(Stdio::piped()) + .stderr(Stdio::inherit()) + .output() + .unwrap(); + + let artifact = Message::parse_stream(&*result.stdout) + .find_map(|message| { + if let Message::CompilerArtifact(artifact) = message.unwrap() { + // Brittle! + if artifact.target.name == package && artifact.filenames.len() == 2 { + let path = artifact.filenames[1].clone(); + let stem = path.file_stem().unwrap().strip_prefix("lib").unwrap(); + return Some(path.with_file_name(format!("{stem}.s"))); + } + } + None + }) + .unwrap_or_else(|| { + panic!( + "Could not find package data:\n{}", + String::from_utf8_lossy(&result.stdout) + ) + }); + + // Very brittle! + let target = artifact + .components() + .map(|component| component.as_str()) + .skip_while(|&component| component != "target") + .skip(1) + .next() + .unwrap_or(host); + + println!("Target {target}."); + + let expected_file = package_path.join("expected").join(format!("{target}.s")); + + let actual = read_assembly(&artifact).unwrap(); + if should_overwrite { + fs::write(expected_file, actual).unwrap(); + } else if let Ok(expected) = read_assembly(expected_file) { + if expected != actual { + eprintln!("\n===Expected===\n{}\n===Actual===\n{}", expected, actual); + panic!("Expected and actual did not match."); + } + } else { + panic!("Missing assembly output for target {}:\n{}", target, actual); + } + } +} From daab1785f70b750d555442cde123053cf9f41835 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 1 Mar 2022 03:35:46 +0100 Subject: [PATCH 2/6] Add assembly test results --- .../expected/aarch64-apple-darwin.s | 10 ++++++++++ .../expected/aarch64-apple-ios-sim.s | 20 +++++++++++++++++++ .../expected/aarch64-apple-ios.s | 20 +++++++++++++++++++ .../expected/armv7-apple-ios.s | 10 ++++++++++ .../expected/armv7s-apple-ios.s | 12 +++++++++++ .../expected/i386-apple-ios.s | 16 +++++++++++++++ .../expected/i686-apple-darwin.s | 16 +++++++++++++++ .../expected/x86_64-apple-darwin.s | 16 +++++++++++++++ .../expected/x86_64-apple-ios.s | 16 +++++++++++++++ 9 files changed, 136 insertions(+) create mode 100644 tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-darwin.s create mode 100644 tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-ios-sim.s create mode 100644 tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-ios.s create mode 100644 tests/assembly/test_msg_send_zero_cost/expected/armv7-apple-ios.s create mode 100644 tests/assembly/test_msg_send_zero_cost/expected/armv7s-apple-ios.s create mode 100644 tests/assembly/test_msg_send_zero_cost/expected/i386-apple-ios.s create mode 100644 tests/assembly/test_msg_send_zero_cost/expected/i686-apple-darwin.s create mode 100644 tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-darwin.s create mode 100644 tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-ios.s diff --git a/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-darwin.s b/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-darwin.s new file mode 100644 index 000000000..8a0997d2f --- /dev/null +++ b/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-darwin.s @@ -0,0 +1,10 @@ + .section __TEXT,__text,regular,pure_instructions + .build_version macos, 11, 0 + .globl _handle + .p2align 2 +_handle: + .cfi_startproc + b _objc_msgSend + .cfi_endproc + +.subsections_via_symbols diff --git a/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-ios-sim.s b/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-ios-sim.s new file mode 100644 index 000000000..f32a19a28 --- /dev/null +++ b/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-ios-sim.s @@ -0,0 +1,20 @@ + .section __TEXT,__text,regular,pure_instructions + .build_version iossimulator, 14, 0 + .globl _handle + .p2align 2 +_handle: + .cfi_startproc + b _objc_msgSend + .cfi_endproc + +; Stripped __LLVM line +; Stripped __LLVM line +; Stripped __LLVM line +; Stripped __LLVM line + +; Stripped __LLVM line +; Stripped __LLVM line +; Stripped __LLVM line +; Stripped __LLVM line + +.subsections_via_symbols diff --git a/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-ios.s b/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-ios.s new file mode 100644 index 000000000..057d6c451 --- /dev/null +++ b/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-ios.s @@ -0,0 +1,20 @@ + .section __TEXT,__text,regular,pure_instructions + .ios_version_min 7, 0 + .globl _handle + .p2align 2 +_handle: + .cfi_startproc + b _objc_msgSend + .cfi_endproc + +; Stripped __LLVM line +; Stripped __LLVM line +; Stripped __LLVM line +; Stripped __LLVM line + +; Stripped __LLVM line +; Stripped __LLVM line +; Stripped __LLVM line +; Stripped __LLVM line + +.subsections_via_symbols diff --git a/tests/assembly/test_msg_send_zero_cost/expected/armv7-apple-ios.s b/tests/assembly/test_msg_send_zero_cost/expected/armv7-apple-ios.s new file mode 100644 index 000000000..f9b43ae49 --- /dev/null +++ b/tests/assembly/test_msg_send_zero_cost/expected/armv7-apple-ios.s @@ -0,0 +1,10 @@ + .section __TEXT,__text,regular,pure_instructions + .ios_version_min 7, 0 + .syntax unified + .globl _handle + .p2align 2 + .code 32 +_handle: + b _objc_msgSend + +.subsections_via_symbols diff --git a/tests/assembly/test_msg_send_zero_cost/expected/armv7s-apple-ios.s b/tests/assembly/test_msg_send_zero_cost/expected/armv7s-apple-ios.s new file mode 100644 index 000000000..abb037871 --- /dev/null +++ b/tests/assembly/test_msg_send_zero_cost/expected/armv7s-apple-ios.s @@ -0,0 +1,12 @@ + .section __TEXT,__text,regular,pure_instructions + .syntax unified + .globl _handle + .p2align 2 + .code 32 +_handle: + push {r7, lr} + mov r7, sp + bl _objc_msgSend + pop {r7, pc} + +.subsections_via_symbols diff --git a/tests/assembly/test_msg_send_zero_cost/expected/i386-apple-ios.s b/tests/assembly/test_msg_send_zero_cost/expected/i386-apple-ios.s new file mode 100644 index 000000000..0e1cb2eb6 --- /dev/null +++ b/tests/assembly/test_msg_send_zero_cost/expected/i386-apple-ios.s @@ -0,0 +1,16 @@ + .section __TEXT,__text,regular,pure_instructions + .ios_version_min 7, 0 + .globl _handle + .p2align 4, 0x90 +_handle: + .cfi_startproc + pushl %ebp + .cfi_def_cfa_offset 8 + .cfi_offset %ebp, -8 + movl %esp, %ebp + .cfi_def_cfa_register %ebp + popl %ebp + jmp _objc_msgSend + .cfi_endproc + +.subsections_via_symbols diff --git a/tests/assembly/test_msg_send_zero_cost/expected/i686-apple-darwin.s b/tests/assembly/test_msg_send_zero_cost/expected/i686-apple-darwin.s new file mode 100644 index 000000000..d938bcd61 --- /dev/null +++ b/tests/assembly/test_msg_send_zero_cost/expected/i686-apple-darwin.s @@ -0,0 +1,16 @@ + .section __TEXT,__text,regular,pure_instructions + .macosx_version_min 10, 7 + .globl _handle + .p2align 4, 0x90 +_handle: + .cfi_startproc + pushl %ebp + .cfi_def_cfa_offset 8 + .cfi_offset %ebp, -8 + movl %esp, %ebp + .cfi_def_cfa_register %ebp + popl %ebp + jmp _objc_msgSend + .cfi_endproc + +.subsections_via_symbols diff --git a/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-darwin.s b/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-darwin.s new file mode 100644 index 000000000..ec167d1a7 --- /dev/null +++ b/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-darwin.s @@ -0,0 +1,16 @@ + .section __TEXT,__text,regular,pure_instructions + .macosx_version_min 10, 7 + .globl _handle + .p2align 4, 0x90 +_handle: + .cfi_startproc + pushq %rbp + .cfi_def_cfa_offset 16 + .cfi_offset %rbp, -16 + movq %rsp, %rbp + .cfi_def_cfa_register %rbp + popq %rbp + jmp _objc_msgSend + .cfi_endproc + +.subsections_via_symbols diff --git a/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-ios.s b/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-ios.s new file mode 100644 index 000000000..a51b1a77d --- /dev/null +++ b/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-ios.s @@ -0,0 +1,16 @@ + .section __TEXT,__text,regular,pure_instructions + .ios_version_min 7, 0 + .globl _handle + .p2align 4, 0x90 +_handle: + .cfi_startproc + pushq %rbp + .cfi_def_cfa_offset 16 + .cfi_offset %rbp, -16 + movq %rsp, %rbp + .cfi_def_cfa_register %rbp + popq %rbp + jmp _objc_msgSend + .cfi_endproc + +.subsections_via_symbols From 1a9163a3645942e5f3d85a7d65bae5e1b48bf1d4 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 28 Feb 2022 01:03:04 +0100 Subject: [PATCH 3/6] Run assembly tests in CI --- .github/workflows/ci.yml | 60 +++++++++++-------- .../test_msg_send_zero_cost/Cargo.toml | 2 + 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 80a54dc5c..93316f243 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,7 +60,7 @@ jobs: rust: toolchain: nightly # Run on nightly to help find regressions - args: --features tests/ui + test-args: --features tests/ui - name: Build macOS 32bit os: macos-10.15 target: i686-apple-darwin @@ -77,14 +77,15 @@ jobs: - name: Test GNUStep os: ubuntu-latest target: x86_64-unknown-linux-gnu - features: gnustep-1-9 - args: --features gnustep-1-9 + host-args: --features block-sys/gnustep-1-9,objc-sys/gnustep-1-9 + args: --features block-sys/gnustep-1-9,objc-sys/gnustep-1-9 - name: Test GNUStep 32bit os: ubuntu-latest target: i686-unknown-linux-gnu cflags: -m32 configureflags: --target=x86-pc-linux-gnu - args: --features gnustep-1-9 + host-args: --features block-sys/gnustep-1-9,objc-sys/gnustep-1-9 + args: --features block-sys/gnustep-1-9,objc-sys/gnustep-1-9 - name: Test iOS simulator x86 64bit os: macos-11 target: x86_64-apple-ios @@ -270,28 +271,6 @@ jobs: if: matrix.dinghy && steps.extern-cache.outputs.cache-hit != 'true' run: cargo install cargo-dinghy --version=^0.4 --root=$HOME/extern --target=x86_64-apple-darwin - - name: Run Cargo Dinghy - if: matrix.dinghy - run: | - # Launch the simulator - xcrun simctl list runtimes - RUNTIME_ID=$(xcrun simctl list runtimes | grep iOS | cut -d ' ' -f 7 | tail -1) - export SIM_ID=$(xcrun simctl create My-iphone7 com.apple.CoreSimulator.SimDeviceType.iPhone-7 $RUNTIME_ID) - xcrun simctl boot $SIM_ID - - # Build - cargo dinghy build - - # Run tests - cargo dinghy --device=$SIM_ID test --no-default-features - # Enable a few features. We're doing it this way because cargo dingy - # doesn't support specifying features from a workspace. - sed -i -e '/\[features\]/a\ - default = ["exception", "verify_message", "catch_all"] - ' objc2/Cargo.toml - cargo dinghy --device=$SIM_ID test - cargo dinghy --device=$SIM_ID test --release - - name: Build if: ${{ !matrix.dinghy }} uses: actions-rs/cargo@v1 @@ -343,3 +322,32 @@ jobs: command: test # Not using --all-features because that would enable e.g. gnustep args: --features ${{ env.FEATURES }},${{ env.UNSTABLE_FEATURES }} ${{ env.TESTARGS }} + + - name: Run assembly tests + shell: bash + run: + export HOST_TARGET=$(rustc -vV | grep host | cut -f2 -d' ') + + cargo run ${{ matrix.host-args }} --features assembly --target=$HOST_TARGET test_assembly ${{ matrix.args }} + + - name: Run Cargo Dinghy + if: matrix.dinghy + run: | + # Launch the simulator + xcrun simctl list runtimes + RUNTIME_ID=$(xcrun simctl list runtimes | grep iOS | cut -d ' ' -f 7 | tail -1) + export SIM_ID=$(xcrun simctl create My-iphone7 com.apple.CoreSimulator.SimDeviceType.iPhone-7 $RUNTIME_ID) + xcrun simctl boot $SIM_ID + + # Build + cargo dinghy build + + # Run tests + cargo dinghy --device=$SIM_ID test --no-default-features + # Enable a few features. We're doing it this way because cargo dingy + # doesn't support specifying features from a workspace. + sed -i -e '/\[features\]/a\ + default = ["exception", "verify_message", "catch_all"] + ' objc2/Cargo.toml + cargo dinghy --device=$SIM_ID test + cargo dinghy --device=$SIM_ID test --release diff --git a/tests/assembly/test_msg_send_zero_cost/Cargo.toml b/tests/assembly/test_msg_send_zero_cost/Cargo.toml index 7b4b713b4..a25ae18f9 100644 --- a/tests/assembly/test_msg_send_zero_cost/Cargo.toml +++ b/tests/assembly/test_msg_send_zero_cost/Cargo.toml @@ -9,3 +9,5 @@ path = "lib.rs" [dependencies] objc2 = { path = "../../../objc2" } +objc-sys = { path = "../../../objc-sys" } +block-sys = { path = "../../../block-sys" } From ec943d4f7ef17a5fc2d2fce0a869d30920e3ab7a Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 1 Mar 2022 04:00:38 +0100 Subject: [PATCH 4/6] Use intel syntax --- .../test_msg_send_zero_cost/expected/i386-apple-ios.s | 11 ++++++----- .../expected/i686-apple-darwin.s | 11 ++++++----- .../expected/x86_64-apple-darwin.s | 11 ++++++----- .../expected/x86_64-apple-ios.s | 11 ++++++----- tests/src/bin/test_assembly.rs | 1 + 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/tests/assembly/test_msg_send_zero_cost/expected/i386-apple-ios.s b/tests/assembly/test_msg_send_zero_cost/expected/i386-apple-ios.s index 0e1cb2eb6..06f868be7 100644 --- a/tests/assembly/test_msg_send_zero_cost/expected/i386-apple-ios.s +++ b/tests/assembly/test_msg_send_zero_cost/expected/i386-apple-ios.s @@ -1,15 +1,16 @@ .section __TEXT,__text,regular,pure_instructions .ios_version_min 7, 0 + .intel_syntax noprefix .globl _handle .p2align 4, 0x90 _handle: .cfi_startproc - pushl %ebp + push ebp .cfi_def_cfa_offset 8 - .cfi_offset %ebp, -8 - movl %esp, %ebp - .cfi_def_cfa_register %ebp - popl %ebp + .cfi_offset ebp, -8 + mov ebp, esp + .cfi_def_cfa_register ebp + pop ebp jmp _objc_msgSend .cfi_endproc diff --git a/tests/assembly/test_msg_send_zero_cost/expected/i686-apple-darwin.s b/tests/assembly/test_msg_send_zero_cost/expected/i686-apple-darwin.s index d938bcd61..dd3c7e387 100644 --- a/tests/assembly/test_msg_send_zero_cost/expected/i686-apple-darwin.s +++ b/tests/assembly/test_msg_send_zero_cost/expected/i686-apple-darwin.s @@ -1,15 +1,16 @@ .section __TEXT,__text,regular,pure_instructions .macosx_version_min 10, 7 + .intel_syntax noprefix .globl _handle .p2align 4, 0x90 _handle: .cfi_startproc - pushl %ebp + push ebp .cfi_def_cfa_offset 8 - .cfi_offset %ebp, -8 - movl %esp, %ebp - .cfi_def_cfa_register %ebp - popl %ebp + .cfi_offset ebp, -8 + mov ebp, esp + .cfi_def_cfa_register ebp + pop ebp jmp _objc_msgSend .cfi_endproc diff --git a/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-darwin.s b/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-darwin.s index ec167d1a7..ed4543e5e 100644 --- a/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-darwin.s +++ b/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-darwin.s @@ -1,15 +1,16 @@ .section __TEXT,__text,regular,pure_instructions .macosx_version_min 10, 7 + .intel_syntax noprefix .globl _handle .p2align 4, 0x90 _handle: .cfi_startproc - pushq %rbp + push rbp .cfi_def_cfa_offset 16 - .cfi_offset %rbp, -16 - movq %rsp, %rbp - .cfi_def_cfa_register %rbp - popq %rbp + .cfi_offset rbp, -16 + mov rbp, rsp + .cfi_def_cfa_register rbp + pop rbp jmp _objc_msgSend .cfi_endproc diff --git a/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-ios.s b/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-ios.s index a51b1a77d..c25defca4 100644 --- a/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-ios.s +++ b/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-ios.s @@ -1,15 +1,16 @@ .section __TEXT,__text,regular,pure_instructions .ios_version_min 7, 0 + .intel_syntax noprefix .globl _handle .p2align 4, 0x90 _handle: .cfi_startproc - pushq %rbp + push rbp .cfi_def_cfa_offset 16 - .cfi_offset %rbp, -16 - movq %rsp, %rbp - .cfi_def_cfa_register %rbp - popq %rbp + .cfi_offset rbp, -16 + mov rbp, rsp + .cfi_def_cfa_register rbp + pop rbp jmp _objc_msgSend .cfi_endproc diff --git a/tests/src/bin/test_assembly.rs b/tests/src/bin/test_assembly.rs index 463793b27..00996daac 100644 --- a/tests/src/bin/test_assembly.rs +++ b/tests/src/bin/test_assembly.rs @@ -70,6 +70,7 @@ fn main() { .arg("--message-format=json-render-diagnostics") .arg("--") .arg("--emit=asm") + .arg("-Cllvm-args=--x86-asm-syntax=intel") .stdout(Stdio::piped()) .stderr(Stdio::inherit()) .output() From ac70160ed3396c1946b98af36b5c404d891e3373 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 1 Mar 2022 04:55:41 +0100 Subject: [PATCH 5/6] Strip unnecessary info from expected assembly output --- .../expected/aarch64-apple-darwin.s | 3 --- .../expected/aarch64-apple-ios-sim.s | 13 ++--------- .../expected/aarch64-apple-ios.s | 13 ++--------- .../expected/i386-apple-ios.s | 6 ----- .../expected/i686-apple-darwin.s | 6 ----- .../expected/x86_64-apple-darwin.s | 6 ----- .../expected/x86_64-apple-ios.s | 6 ----- tests/src/bin/test_assembly.rs | 22 +++++++++++++++---- 8 files changed, 22 insertions(+), 53 deletions(-) diff --git a/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-darwin.s b/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-darwin.s index 8a0997d2f..b195a041a 100644 --- a/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-darwin.s +++ b/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-darwin.s @@ -1,10 +1,7 @@ .section __TEXT,__text,regular,pure_instructions - .build_version macos, 11, 0 .globl _handle .p2align 2 _handle: - .cfi_startproc b _objc_msgSend - .cfi_endproc .subsections_via_symbols diff --git a/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-ios-sim.s b/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-ios-sim.s index f32a19a28..d73fd4f2a 100644 --- a/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-ios-sim.s +++ b/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-ios-sim.s @@ -1,20 +1,11 @@ .section __TEXT,__text,regular,pure_instructions - .build_version iossimulator, 14, 0 .globl _handle .p2align 2 _handle: - .cfi_startproc b _objc_msgSend - .cfi_endproc -; Stripped __LLVM line -; Stripped __LLVM line -; Stripped __LLVM line -; Stripped __LLVM line +; Stripped __LLVM section -; Stripped __LLVM line -; Stripped __LLVM line -; Stripped __LLVM line -; Stripped __LLVM line +; Stripped __LLVM section .subsections_via_symbols diff --git a/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-ios.s b/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-ios.s index 057d6c451..d73fd4f2a 100644 --- a/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-ios.s +++ b/tests/assembly/test_msg_send_zero_cost/expected/aarch64-apple-ios.s @@ -1,20 +1,11 @@ .section __TEXT,__text,regular,pure_instructions - .ios_version_min 7, 0 .globl _handle .p2align 2 _handle: - .cfi_startproc b _objc_msgSend - .cfi_endproc -; Stripped __LLVM line -; Stripped __LLVM line -; Stripped __LLVM line -; Stripped __LLVM line +; Stripped __LLVM section -; Stripped __LLVM line -; Stripped __LLVM line -; Stripped __LLVM line -; Stripped __LLVM line +; Stripped __LLVM section .subsections_via_symbols diff --git a/tests/assembly/test_msg_send_zero_cost/expected/i386-apple-ios.s b/tests/assembly/test_msg_send_zero_cost/expected/i386-apple-ios.s index 06f868be7..f20f298e7 100644 --- a/tests/assembly/test_msg_send_zero_cost/expected/i386-apple-ios.s +++ b/tests/assembly/test_msg_send_zero_cost/expected/i386-apple-ios.s @@ -1,17 +1,11 @@ .section __TEXT,__text,regular,pure_instructions - .ios_version_min 7, 0 .intel_syntax noprefix .globl _handle .p2align 4, 0x90 _handle: - .cfi_startproc push ebp - .cfi_def_cfa_offset 8 - .cfi_offset ebp, -8 mov ebp, esp - .cfi_def_cfa_register ebp pop ebp jmp _objc_msgSend - .cfi_endproc .subsections_via_symbols diff --git a/tests/assembly/test_msg_send_zero_cost/expected/i686-apple-darwin.s b/tests/assembly/test_msg_send_zero_cost/expected/i686-apple-darwin.s index dd3c7e387..f20f298e7 100644 --- a/tests/assembly/test_msg_send_zero_cost/expected/i686-apple-darwin.s +++ b/tests/assembly/test_msg_send_zero_cost/expected/i686-apple-darwin.s @@ -1,17 +1,11 @@ .section __TEXT,__text,regular,pure_instructions - .macosx_version_min 10, 7 .intel_syntax noprefix .globl _handle .p2align 4, 0x90 _handle: - .cfi_startproc push ebp - .cfi_def_cfa_offset 8 - .cfi_offset ebp, -8 mov ebp, esp - .cfi_def_cfa_register ebp pop ebp jmp _objc_msgSend - .cfi_endproc .subsections_via_symbols diff --git a/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-darwin.s b/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-darwin.s index ed4543e5e..cd046e70f 100644 --- a/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-darwin.s +++ b/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-darwin.s @@ -1,17 +1,11 @@ .section __TEXT,__text,regular,pure_instructions - .macosx_version_min 10, 7 .intel_syntax noprefix .globl _handle .p2align 4, 0x90 _handle: - .cfi_startproc push rbp - .cfi_def_cfa_offset 16 - .cfi_offset rbp, -16 mov rbp, rsp - .cfi_def_cfa_register rbp pop rbp jmp _objc_msgSend - .cfi_endproc .subsections_via_symbols diff --git a/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-ios.s b/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-ios.s index c25defca4..cd046e70f 100644 --- a/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-ios.s +++ b/tests/assembly/test_msg_send_zero_cost/expected/x86_64-apple-ios.s @@ -1,17 +1,11 @@ .section __TEXT,__text,regular,pure_instructions - .ios_version_min 7, 0 .intel_syntax noprefix .globl _handle .p2align 4, 0x90 _handle: - .cfi_startproc push rbp - .cfi_def_cfa_offset 16 - .cfi_offset rbp, -16 mov rbp, rsp - .cfi_def_cfa_register rbp pop rbp jmp _objc_msgSend - .cfi_endproc .subsections_via_symbols diff --git a/tests/src/bin/test_assembly.rs b/tests/src/bin/test_assembly.rs index 00996daac..73653571f 100644 --- a/tests/src/bin/test_assembly.rs +++ b/tests/src/bin/test_assembly.rs @@ -11,6 +11,13 @@ use std::io; use std::path::Path; use std::process::{Command, Stdio}; +fn strip_lines(data: &str, starts_with: &str) -> String { + data.lines() + .filter(|line| !line.trim_start().starts_with(starts_with)) + .collect::>() + .join("\n") +} + fn strip_section(data: &str, section: &str) -> String { let mut res = String::with_capacity(data.len()); let mut in_removed_section = false; @@ -20,14 +27,17 @@ fn strip_section(data: &str, section: &str) -> String { in_removed_section = false; } if line.trim().starts_with(".section") { - in_removed_section = line.contains(section); + if line.contains(section) { + in_removed_section = true; + write!(res, "; Stripped {section} section\n").unwrap(); + } else { + in_removed_section = false; + } } if !in_removed_section { res.push_str(line); - } else { - write!(res, "; Stripped {section} line").unwrap(); + res.push('\n'); } - res.push('\n'); } res } @@ -41,6 +51,10 @@ fn read_assembly>(path: P) -> io::Result { .to_str() .unwrap(); let s = s.replace(workspace_dir, "$WORKSPACE"); + let s = strip_lines(&s, ".cfi_"); + let s = strip_lines(&s, ".macosx_version_"); + let s = strip_lines(&s, ".ios_version_"); + let s = strip_lines(&s, ".build_version"); // We remove the __LLVM,__bitcode and __LLVM,__cmdline sections because // they're uninteresting for out use-case. // From a644265218b96a3e7320d0c54f8538a011ea59b2 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 1 Mar 2022 04:59:32 +0100 Subject: [PATCH 6/6] Don't run assembly tests on GNUStep --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 93316f243..d933a705c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -324,6 +324,10 @@ jobs: args: --features ${{ env.FEATURES }},${{ env.UNSTABLE_FEATURES }} ${{ env.TESTARGS }} - name: Run assembly tests + # Not run on GNUStep yet since a lot of function labels are mangled and + # not inlined (and hence quite hard to match on, at some point we'll + # need to find a solution to that). + if: ${{ !contains(matrix.os, 'ubuntu') }} shell: bash run: export HOST_TARGET=$(rustc -vV | grep host | cut -f2 -d' ')