Search code examples
cgccassemblydirectiveinline-assembly

What does "#APP" in the assembly file generated by compiler mean?


I wrote the following code:

// a.c
#include <stdlib.h>
#include <sys/syscall.h>
#include <unistd.h>

_Noreturn void _start()
{
    register int syscall_num asm ("rax") = __NR_exit;
    register int exit_code   asm ("rdi") = 0;

    // The actual syscall to exit
    asm volatile ("syscall"
        : /* no output Operands */
        : "r" (syscall_num), "r" (exit_code));
}

And then compiled it using clang-7 -Oz -pipe -flto -c a.c and used llc-7 -filetype=asm a.o to turn it into an human-readable assembly file a.o.s:

    .text
    .file   "a.c"
    .globl  _start                  # -- Begin function _start
    .type   _start,@function
_start:                                 # @_start
    .cfi_startproc
# %bb.0:
    pushq   $60
    .cfi_adjust_cfa_offset 8
    popq    %rax
    .cfi_adjust_cfa_offset -8
    xorl    %edi, %edi
    #APP
    syscall
    #NO_APP
    retq
.Lfunc_end0:
    .size   _start, .Lfunc_end0-_start
    .cfi_endproc
                                        # -- End function

    .ident  "clang version 7.0.1-svn348686-1~exp1~20181211133235.57 (branches/release_70)"
    .section    ".note.GNU-stack","",@progbits

In the assembly above, the directive #APP appears before syscall, which is the assembly I wrote and the directive #NO_APP appears right after it.

I know it must have something to do with the use of asm, like to prevent it from being optimized out, but I can't find any documentation of it after googling.

Thanks advanced.


Solution

  • Historically at least, the compiler told as it could use a fast-parsing mode for parsing pure compiler output, switching back for full parsing for blocks from inline-asm. There should be a #APP somewhere early in the file that enters this mode. The #NO_APP switches out of this mode.

    I'm not sure as does anything with that hint anymore, so it may not even look for #NO_APP at all, and just treat it like any other comment.

    In practice, it delimits the block of text that came from the inline asm template, vs. compiler generated asm. It doesn't do anything beyond that, and if you're hand-editing the asm for some reason, it's totally find to remove it.