Merge pull request #1397 from bjorn3/inline_asm_tweaks

Test inline asm support on CI
This commit is contained in:
bjorn3 2023-10-08 13:21:53 +02:00 committed by GitHub
commit cc5db2c1c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 16 deletions

View file

@ -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

View file

@ -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
@ -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
@ -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

View file

@ -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::*;
@ -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));
@ -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);
@ -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