PLD linux carries a patch which uses a "naked" function instead of a toplevel asm function to allow the compiler to properly track the function.
http://git.pld-linux.org/?p=packages/kicad.git;f=lto.patch;h=ad2c2f023eb7ffeefef2c1fd4cff1fdc9f6b3156;hb=HEAD
I have tried it, and it works fine. The resulting assembly is (almost) the same as the plain assembly, you can try it with the following code:
$> cat ./test.cpp --- void foo(int* a, char b) __attribute__ ((naked, aligned(4))); void foo(int* a, char b) { asm volatile("mov $1, %eax;"); } --- $> gcc -S ./test.cpp; gcc -c ./test.cpp; cat ./test.s; objdump -d ./test.o --- .file "test.cpp" .text .align 4 .globl foo .type foo, @function foo: .LFB0: .cfi_startproc #APP # 5 "./test.cpp" 1 mov $1, %eax; # 0 "" 2 #NO_APP nop ud2 .cfi_endproc .LFE0: .size foo, .-foo .ident "GCC: (SUSE Linux) 9.1.1 20190703 [gcc-9-branch revision 273008]" .section .note.GNU-stack,"",@progbit --- 0000000000000000 <foo>: 0: b8 01 00 00 00 mov $0x1,%eax 5: 90 nop 6: 0f 0b ud2 ---
The only difference is the added nop,ud2. ud2 is the guaranteed intel illegal instruction, but as the code is not reached (last asm instruction is "hlt" respectively "jmp"), this does not matter.
The corresponding GCC BR is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57703
PLD linux carries a patch which uses a "naked" function instead of a toplevel asm function to allow the compiler to properly track the function.
http:// git.pld- linux.org/ ?p=packages/ kicad.git; f=lto.patch; h=ad2c2f023eb7f feefef2c1fd4cff 1fdc9f6b3156; hb=HEAD
I have tried it, and it works fine. The resulting assembly is (almost) the same as the plain assembly, you can try it with the following code:
$> cat ./test.cpp
.cfi_startproc
.cfi_endproc stack," ",@progbit
---
void foo(int* a, char b) __attribute__ ((naked, aligned(4)));
void foo(int* a, char b)
{
asm volatile("mov $1, %eax;");
}
---
$> gcc -S ./test.cpp; gcc -c ./test.cpp; cat ./test.s; objdump -d ./test.o
---
.file "test.cpp"
.text
.align 4
.globl foo
.type foo, @function
foo:
.LFB0:
#APP
# 5 "./test.cpp" 1
mov $1, %eax;
# 0 "" 2
#NO_APP
nop
ud2
.LFE0:
.size foo, .-foo
.ident "GCC: (SUSE Linux) 9.1.1 20190703 [gcc-9-branch revision 273008]"
.section .note.GNU-
---
0000000000000000 <foo>:
0: b8 01 00 00 00 mov $0x1,%eax
5: 90 nop
6: 0f 0b ud2
---
The only difference is the added nop,ud2. ud2 is the guaranteed intel illegal instruction, but as the code is not reached (last asm instruction is "hlt" respectively "jmp"), this does not matter.
The corresponding GCC BR is https:/ /gcc.gnu. org/bugzilla/ show_bug. cgi?id= 57703