Skip to content

Commit cc5db2c

Browse files
authored
Merge pull request rust-lang#1397 from bjorn3/inline_asm_tweaks
Test inline asm support on CI
2 parents 8109344 + 2672876 commit cc5db2c

File tree

3 files changed

+45
-16
lines changed

3 files changed

+45
-16
lines changed

scripts/setup_rust_fork.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
./y.sh build --no-unstable-features
4+
./y.sh build
55

66
echo "[SETUP] Rust fork"
77
git clone https://github.com/rust-lang/rust.git || true

scripts/test_rustc_tests.sh

+5-8
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,10 @@ pushd rust
1111
command -v rg >/dev/null 2>&1 || cargo install ripgrep
1212

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

18-
for test in tests/run-make/**/Makefile; do
19-
if rg "# needs-asm-support" $test >/dev/null; then
20-
rm -r $(dirname $test)
21-
fi
22-
done
23-
2418
for test in $(rg -i --files-with-matches "//(\[\w+\])?~[^\|]*\s*ERR|// error-pattern:|// build-fail|// run-fail|-Cllvm-args" tests/ui); do
2519
rm $test
2620
done
@@ -36,8 +30,9 @@ rm tests/ui/parser/unclosed-delimiter-in-dep.rs # submodule contains //~ERROR
3630
rm -r tests/run-make/comment-section # cg_clif doesn't yet write the .comment section
3731

3832
# requires stack unwinding
39-
# FIXME add needs-unwind to this test
33+
# FIXME add needs-unwind to these tests
4034
rm -r tests/run-make/libtest-junit
35+
rm tests/ui/asm/may_unwind.rs
4136

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

8279
# requires LTO
8380
rm -r tests/run-make/cdylib

src/inline_asm.rs

+39-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
66
use rustc_middle::mir::InlineAsmOperand;
77
use rustc_span::sym;
88
use rustc_target::asm::*;
9+
use target_lexicon::BinaryFormat;
910

1011
use crate::prelude::*;
1112

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

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

591594
fn generate_asm_wrapper(&self, asm_name: &str) -> String {
595+
let binary_format = crate::target_triple(self.tcx.sess).binary_format;
596+
592597
let mut generated_asm = String::new();
593-
writeln!(generated_asm, ".globl {}", asm_name).unwrap();
594-
writeln!(generated_asm, ".type {},@function", asm_name).unwrap();
595-
writeln!(generated_asm, ".section .text.{},\"ax\",@progbits", asm_name).unwrap();
596-
writeln!(generated_asm, "{}:", asm_name).unwrap();
598+
match binary_format {
599+
BinaryFormat::Elf => {
600+
writeln!(generated_asm, ".globl {}", asm_name).unwrap();
601+
writeln!(generated_asm, ".type {},@function", asm_name).unwrap();
602+
writeln!(generated_asm, ".section .text.{},\"ax\",@progbits", asm_name).unwrap();
603+
writeln!(generated_asm, "{}:", asm_name).unwrap();
604+
}
605+
BinaryFormat::Macho => {
606+
writeln!(generated_asm, ".globl _{}", asm_name).unwrap();
607+
writeln!(generated_asm, "_{}:", asm_name).unwrap();
608+
}
609+
BinaryFormat::Coff => {
610+
writeln!(generated_asm, ".globl {}", asm_name).unwrap();
611+
writeln!(generated_asm, "{}:", asm_name).unwrap();
612+
}
613+
_ => self
614+
.tcx
615+
.sess
616+
.fatal(format!("Unsupported binary format for inline asm: {binary_format:?}")),
617+
}
597618

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

@@ -690,8 +711,19 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> {
690711
if is_x86 {
691712
generated_asm.push_str(".att_syntax\n");
692713
}
693-
writeln!(generated_asm, ".size {name}, .-{name}", name = asm_name).unwrap();
694-
generated_asm.push_str(".text\n");
714+
715+
match binary_format {
716+
BinaryFormat::Elf => {
717+
writeln!(generated_asm, ".size {name}, .-{name}", name = asm_name).unwrap();
718+
generated_asm.push_str(".text\n");
719+
}
720+
BinaryFormat::Macho | BinaryFormat::Coff => {}
721+
_ => self
722+
.tcx
723+
.sess
724+
.fatal(format!("Unsupported binary format for inline asm: {binary_format:?}")),
725+
}
726+
695727
generated_asm.push_str("\n\n");
696728

697729
generated_asm

0 commit comments

Comments
 (0)