This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
GCC Internals: built-in functions?
- From: Amittai Aviram <amittai dot aviram at yale dot edu>
- To: gcc-help at gcc dot gnu dot org
- Date: Sun, 30 Jan 2011 15:45:16 -0500
- Subject: GCC Internals: built-in functions?
On this GCC Internals page
http://en.wikibooks.org/wiki/GNU_C_Compiler_Internals/GNU_C_Compiler_Architecture_3_4
I found the following in the "GCC Initialization" section:
"GCC built-in functions are the functions that are evaluated at compile time. For example, if the size argument of a strcpy() function is a constant then GCC replaces the function call with the required number of assignments."
I was curious about this, so I tried compiling to assembly (-S) a very simple program:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
char s1[0x10];
char * s0 = "HELLO";
strcpy(s1, s0);
printf("%s %s\n", s0, s1);
return EXIT_SUCCESS;
}
But the resulting assembly code simply calls strcpy with the two arguments, just as I would have expected had I not read the above sentence:
movq $.LC0, -40(%rbp)
movq -40(%rbp), %rdx
leaq -32(%rbp), %rax
movq %rdx, %rsi
movq %rax, %rdi
call strcpy
(Here, .LC0 labels the string "HELLO".)
So what does that sentence actually mean and what am I missing? Thanks!
Amittai Aviram
PhD Student in Computer Science
Yale University
646 483 2639
amittai.aviram@yale.edu
http://www.amittai.com