我想对一些代码进行优化,以便string.h .h中的所有函数都是内联的。我上x86_64了。
我尝试过-O3,-minline-all-stringops,当我执行"nm a.out“时,它显示它正在调用glibc版本。
我和gcc -S确认过了,我看到了那些电话。
我遗漏了什么?H中有几十个#ifdef _SOME_SETTING_,而bits3.h显示了内联版本,但我不知道如何到达那里。
例如:
$ cat test.c
#include <string.h>
main() {
char *a, *b;
strcpy(b,a);
}
/*
When compiled with:
gcc -minline-all-stringops -O6 -I. -S -o test.S test.c
Produces:
.file "test.c"
.text
.p2align 4,,15
.globl main
.type main, @function
main:
.LFB12:
.cfi_startproc
subq $8, %rsp
.cfi_def_cfa_offset 16
xorl %esi, %esi
xorl %edi, %edi
call strcpy
addq $8, %rsp
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE12:
.size main, .-main
.ident "GCC: (GNU) 4.5.1 20100924 (Red Hat 4.5.1-4)"
.section .note.GNU-stack,"",@progbits
*/发布于 2011-03-04 07:07:43
如果函数实现不在头文件和单独的编译单元中,则不能内联它,除非您有一个可以执行LTCG的编译器。
听起来你需要自己编写实现。
https://stackoverflow.com/questions/5187735
复制相似问题