Skip to content

Test inline asm support on CI #1397

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

Merged
merged 3 commits into from
Oct 8, 2023
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
2 changes: 1 addition & 1 deletion scripts/setup_rust_fork.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e

./y.sh build --no-unstable-features
./y.sh build

echo "[SETUP] Rust fork"
git clone https://github.com/rust-lang/rust.git || true
Expand Down
13 changes: 5 additions & 8 deletions scripts/test_rustc_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@ pushd rust
command -v rg >/dev/null 2>&1 || cargo install ripgrep

rm -r tests/ui/{unsized-locals/,lto/,linkage*} || true
for test in $(rg --files-with-matches "lto|// needs-asm-support" tests/{codegen-units,ui,incremental}); do
for test in $(rg --files-with-matches "lto" tests/{codegen-units,ui,incremental}); do
rm $test
done

for test in tests/run-make/**/Makefile; do
if rg "# needs-asm-support" $test >/dev/null; then
rm -r $(dirname $test)
fi
done

for test in $(rg -i --files-with-matches "//(\[\w+\])?~[^\|]*\s*ERR|// error-pattern:|// build-fail|// run-fail|-Cllvm-args" tests/ui); do
rm $test
done
Expand All @@ -36,8 +30,9 @@ rm tests/ui/parser/unclosed-delimiter-in-dep.rs # submodule contains //~ERROR
rm -r tests/run-make/comment-section # cg_clif doesn't yet write the .comment section

# requires stack unwinding
# FIXME add needs-unwind to this test
# FIXME add needs-unwind to these tests
rm -r tests/run-make/libtest-junit
rm tests/ui/asm/may_unwind.rs

# extra warning about -Cpanic=abort for proc macros
rm tests/ui/proc-macro/crt-static.rs
Expand Down Expand Up @@ -78,6 +73,8 @@ rm -r tests/run-make/symbols-include-type-name # --emit=asm not supported
rm -r tests/run-make/target-specs # i686 not supported by Cranelift
rm -r tests/run-make/mismatching-target-triples # same
rm -r tests/run-make/use-extern-for-plugins # same
rm tests/ui/asm/x86_64/issue-82869.rs # vector regs in inline asm not yet supported
rm tests/ui/asm/x86_64/issue-96797.rs # const and sym inline asm operands don't work entirely correctly

# requires LTO
rm -r tests/run-make/cdylib
Expand Down
46 changes: 39 additions & 7 deletions src/inline_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_middle::mir::InlineAsmOperand;
use rustc_span::sym;
use rustc_target::asm::*;
use target_lexicon::BinaryFormat;

use crate::prelude::*;

Expand Down Expand Up @@ -43,7 +44,9 @@ pub(crate) fn codegen_inline_asm<'tcx>(
) {
// FIXME add .eh_frame unwind info directives

if !template.is_empty() {
if !template.is_empty()
&& (cfg!(not(feature = "inline_asm")) || fx.tcx.sess.target.is_like_windows)
{
// Used by panic_abort
if template[0] == InlineAsmTemplatePiece::String("int $$0x29".to_string()) {
fx.bcx.ins().trap(TrapCode::User(1));
Expand Down Expand Up @@ -589,11 +592,29 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> {
}

fn generate_asm_wrapper(&self, asm_name: &str) -> String {
let binary_format = crate::target_triple(self.tcx.sess).binary_format;

let mut generated_asm = String::new();
writeln!(generated_asm, ".globl {}", asm_name).unwrap();
writeln!(generated_asm, ".type {},@function", asm_name).unwrap();
writeln!(generated_asm, ".section .text.{},\"ax\",@progbits", asm_name).unwrap();
writeln!(generated_asm, "{}:", asm_name).unwrap();
match binary_format {
BinaryFormat::Elf => {
writeln!(generated_asm, ".globl {}", asm_name).unwrap();
writeln!(generated_asm, ".type {},@function", asm_name).unwrap();
writeln!(generated_asm, ".section .text.{},\"ax\",@progbits", asm_name).unwrap();
writeln!(generated_asm, "{}:", asm_name).unwrap();
}
BinaryFormat::Macho => {
writeln!(generated_asm, ".globl _{}", asm_name).unwrap();
writeln!(generated_asm, "_{}:", asm_name).unwrap();
}
BinaryFormat::Coff => {
writeln!(generated_asm, ".globl {}", asm_name).unwrap();
writeln!(generated_asm, "{}:", asm_name).unwrap();
}
_ => self
.tcx
.sess
.fatal(format!("Unsupported binary format for inline asm: {binary_format:?}")),
}

let is_x86 = matches!(self.arch, InlineAsmArch::X86 | InlineAsmArch::X86_64);

Expand Down Expand Up @@ -690,8 +711,19 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> {
if is_x86 {
generated_asm.push_str(".att_syntax\n");
}
writeln!(generated_asm, ".size {name}, .-{name}", name = asm_name).unwrap();
generated_asm.push_str(".text\n");

match binary_format {
BinaryFormat::Elf => {
writeln!(generated_asm, ".size {name}, .-{name}", name = asm_name).unwrap();
generated_asm.push_str(".text\n");
}
BinaryFormat::Macho | BinaryFormat::Coff => {}
_ => self
.tcx
.sess
.fatal(format!("Unsupported binary format for inline asm: {binary_format:?}")),
}

generated_asm.push_str("\n\n");

generated_asm
Expand Down