llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.29k stars 12.11k forks source link

[MC] Assembly emission removes `.arch`/`.arch_extension` directives #117221

Open zyedidia opened 4 days ago

zyedidia commented 4 days ago

Here is an example program that uses .arch in inline assembly to enable LSE instructions:

int main() {
    asm volatile (
        ".arch armv8-a+lse\n"
        "casal x0, x1, [x2]\n"
    );
    return 0;
}

If compiled with clang -c test.c it works fine, but if I first emit to assembly and then attempt to compile, it no longer succeeds:

$ clang -S test.c
$ clang -c test.s
test.s:14:2: error: instruction requires: lse
        casal   x0, x1, [x2]
        ^

The generated assembly does not include the .arch directive, causing the instruction to be illegal.

//APP
casal   x0, x1, [x2]

//NO_APP

A similar issue exists for .arch_directive

Example:

asm volatile (
    ".arch_extension lse\n"
    "casal x0, x1, [x2]\n"
);

Thanks!

zyedidia commented 4 days ago

I noticed that using -fno-integrated-as causes the directive to be emitted, so perhaps the fix could reuse whatever code is enabling that (or is the current behavior actually desired for some reason?).