2月
20
同一 asm 句内に定義がある場合はいいのですが、別の asm 句に定義があると処理できません。
同一 asm 句内に定義がある場合
[umezawa@metis:ttys000 ~]$ cat macro1.c
int main(int argc, char** argv)
{
asm volatile(
".macro THENOP\n"
"nop\n"
".endm\n"
"THENOP":);
return 0;
}
[umezawa@metis:ttys000 ~]$ clang -S -o- macro1.c
.section __TEXT,__text,regular,pure_instructions
.macosx_version_min 10, 12
.globl _main
.align 4, 0x90
_main: ## @main
.cfi_startproc
## BB#0:
pushq %rbp
Ltmp0:
.cfi_def_cfa_offset 16
Ltmp1:
.cfi_offset %rbp, -16
movq %rsp, %rbp
Ltmp2:
.cfi_def_cfa_register %rbp
movl $0, -4(%rbp)
movl %edi, -8(%rbp)
movq %rsi, -16(%rbp)
## InlineAsm Start
nop
## InlineAsm End
xorl %eax, %eax
popq %rbp
retq
.cfi_endproc
.subsections_via_symbols
別の asm 句内に定義がある場合
[umezawa@metis:ttys000 ~]$ cat macro2.c
int main(int argc, char** argv)
{
asm volatile(
".macro THENOP\n"
"nop\n"
".endm\n":);
asm volatile(
"THENOP":);
return 0;
}
[umezawa@metis:ttys000 ~]$ clang -c macro2.c
macro2.c:8:3: error: invalid instruction mnemonic 'thenop'
"THENOP":);
^
:1:2: note: instantiated into assembly here
THENOP
^~~~~~
1 error generated.
これで何が困るかと言うと、複数の関数内で使いたいマクロを記述できないわけです。もう Clang でインラインアセンブラを使おうとするのはやめといた方がいいんじゃないかという気がしてくる。
よくもまあこんな状態で “In general, Clang is highly compatible with the GCC inline assembly extensions” などと(ry
no comment untill now