内敛函数强制
#include<stdio.h>
static inline __attribute__((noinline)) void fun1();
static inline __attribute__((always_inline)) void fun2();
static inline __attribute__((noinline)) void fun1(){
printf("77");
}
static inline __attribute__((always_inline)) void fun2()
{
printf("66");
}
void main(void){
fun1();
fun2();
}
对上面文件进行编译,后使用objdump反编译进行查看,可以看到
fun1和fun2的区别,将fun1的__attribute__((noinline))
删除结果也是相同的,但是不会报错。
$ gcc -g inline.c -o inline.o
//使用noinline会报错但是不会影响编译
$ objdump inline.o -S -j .text
/*
000000000000064a <fun1>://noinline函数在外
#include<stdio.h>
static inline __attribute__((noinline)) void fun1();
static inline __attribute__((always_inline)) void fun2();
static inline __attribute__((noinline)) void fun1(){
64a: 55 push %rbp
64b: 48 89 e5 mov %rsp,%rbp
printf("77");
64e: 48 8d 3d bf 00 00 00 lea 0xbf(%rip),%rdi # 714 <_IO_stdin_used+0x4>
655: b8 00 00 00 00 mov $0x0,%eax
65a: e8 c1 fe ff ff callq 520 <printf@plt>
}
65f: 90 nop
660: 5d pop %rbp
661: c3 retq
0000000000000662 <main>:
static inline __attribute__((always_inline)) void fun2()
{
printf("66");
}
void main(void){
662: 55 push %rbp
663: 48 89 e5 mov %rsp,%rbp
fun1();
666: b8 00 00 00 00 mov $0x0,%eax
66b: e8 da ff ff ff callq 64a <fun1>
printf("66");
670: 48 8d 3d a0 00 00 00 lea 0xa0(%rip),%rdi # 717 <_IO_stdin_used+0x7>
677: b8 00 00 00 00 mov $0x0,%eax
67c: e8 9f fe ff ff callq 520 <printf@plt>
fun2();
}
681: 90 nop
682: 5d pop %rbp
683: c3 retq
684: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
68b: 00 00 00
68e: 66 90 xchg %ax,%ax
fun2函数在main函数内