Rollup merge of #137816 - folkertdev:naked-asm-xcoff, r=Noratrieb

attempt to support `BinaryFormat::Xcoff` in `naked_asm!`

Fixes https://github.com/rust-lang/rust/issues/137219

So, the inline assembly support for xcoff is extremely limited. The LLVM [XCOFFAsmParser](1b25c0c4da/llvm/lib/MC/MCParser/XCOFFAsmParser.cpp) does not support many of the attributes that LLVM itself emits, and that should exist based on [the assembler docs](https://www.ibm.com/docs/en/ssw_aix_71/assembler/assembler_pdf.pdf). It also does accept some that should not exist based on those docs.

So, I've tried to do the best I can given those limitations. At least it's better than emitting the directives for elf and having that fail somewhere deep in LLVM. Given that inline assembly for this target is incomplete (under `asm_experimental_arch`), I think that's OK (and again I don't see how we can do better given the limitations in LLVM).

r? ```@Noratrieb``` (given that you reviewed https://github.com/rust-lang/rust/pull/136637)

It seems reasonable to ping the [`powerpc64-ibm-aix` target maintainers](https://doc.rust-lang.org/rustc/platform-support/aix.html), hopefully they have thoughts too: ```@daltenty``` ```@gilamn5tr```
This commit is contained in:
Matthias Krüger 2025-03-13 11:28:20 +01:00 committed by GitHub
commit 762acf53cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 76 additions and 9 deletions

View file

@ -0,0 +1,35 @@
//@ revisions: elfv1-be aix
//@ add-core-stubs
//@ assembly-output: emit-asm
//
//@[elfv1-be] compile-flags: --target powerpc64-unknown-linux-gnu
//@[elfv1-be] needs-llvm-components: powerpc
//
//@[aix] compile-flags: --target powerpc64-ibm-aix
//@[aix] needs-llvm-components: powerpc
#![crate_type = "lib"]
#![feature(no_core, naked_functions, asm_experimental_arch, f128, linkage, fn_align)]
#![no_core]
// tests that naked functions work for the `powerpc64-ibm-aix` target.
//
// This target is special because it uses the XCOFF binary format
// It is tested alongside an elf powerpc target to pin down commonalities and differences.
//
// https://doc.rust-lang.org/rustc/platform-support/aix.html
// https://www.ibm.com/docs/en/aix/7.2?topic=formats-xcoff-object-file-format
extern crate minicore;
use minicore::*;
// elfv1-be: .p2align 2
// aix: .align 2
// CHECK: .globl blr
// CHECK-LABEL: blr:
// CHECK: blr
#[no_mangle]
#[naked]
unsafe extern "C" fn blr() {
naked_asm!("blr")
}