This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
How to control GCC builtin functions optimization
- From: Cao jin <caoj dot fnst at cn dot fujitsu dot com>
- To: <gcc-help at gcc dot gnu dot org>
- Cc: <gcc at gcc dot gnu dot org>
- Date: Fri, 11 Jan 2019 11:03:35 +0800
- Subject: How to control GCC builtin functions optimization
Hi,
(pls CC me when replying because I am not subscriber)
I met an interesting phenomenon when looking into linux kernel
compilation, it can be simply summarized as following: in
arch/x86/boot/compressed, memcpy is defined as __builtin_memcpy, while
also implemented as a function. But when using memcpy, in some case GCC
optimize it to inline code, in other case GCC just emit a call to
self-defined memcpy function. This can be confirmed according to the
symbol table via `nm bluh.o`.
The compiling flags is, for example:
cmd_arch/x86/boot/compressed/pgtable_64.o := gcc
-Wp,-MD,arch/x86/boot/compressed/.pgtable_64.o.d -nostdinc -isystem
/usr/lib/gcc/x86_64-redhat-linux/8/include -I./arch/x86/include
-I./arch/x86/include/gene rated -I./include
-I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi
-I./include/uapi -I./include/generated/uapi -include
./include/linux/kconfig.h -include ./include/linux/compiler_types.h
-D__KERNEL__ -DCONFIG_CC_STACKPROTECTOR -m64 -O2 -fno-strict-aliasing
-fPIE -DDISABLE_BRANCH_PROFILING -mcmodel=small -mno-mmx -mno-sse
-ffreestanding -fno-stack-protector -DKBUILD_BASENAME='"pgtable_64"'
-DKBUILD_MODNAME='"pgtable_64"' -c -o
arch/x86/boot/compressed/pgtable_64.o arch/x86/boot/compressed/pgtable_64.c
Now the questions is: from code-reading, it is kind of non-intuitive, is
there any explicit way to control the optimization behavior accurately?
--
Sincerely,
Cao jin