GCC with -fno-builtin does not seem to work

GCC with -fno-builtin does not seem to work

I would like to compare the GCC builtin function memcpy versus the one one from libc. However, all iterations of -fno-builtin or -fno-builtin-memcpy seem to be ignored.

//g++ -O3 foo.cpp -S or
//g++ -O3 -fno-builtin foo.cpp -S
#include <string.h>
int main() {
    volatile int n = 1000;
    //int n = 1000;
    float *x = new float[1000];
    float *y = new float[1000];

What I have found is that if n in the source code above is not volatile then it inlines built-in code. However, when n is made volatile then it calls the function __memcpy_chk which is a version of memcpy with buffer overflow checking. If n is volatile and I instead call __builtin_memcpy then it calls memcpy.

So my conclusion so far is that the builtin code is only generated if n is known at compile time and that -fno-builtin is useless. I'm using GCC 4.8.2.

Is -fno-builtin obsolete? Is there a way to make GCC call memcpy from the C library even when n is known at compile time?

-fno-builtin and -fno-builtin-memcpy both have the effect you expected with gcc 4.9.1. This is probably just a bug in gcc 4.8.2; this particular combination of options is not widely used. -ffreestanding is a related switch that may have the effect you want with 4.8.2.

Note that the compiler is within its rights to optimize your program down to

int main() { return 0; }

when invoked without -fno-builtin(-memcpy) or -ffreestanding, even when n is volatile, as it can (in principle) prove that the program as a whole either has no observable side effects, or its behavior is undefined. (When n is not volatile, there cannot be UB; the UB happens if n is outside the range [0, 1000] when read, and volatile tells the compiler it can't assume n has the value written to it by the program.)

The Definitive Guide to GCC, The GCC_EXEC_PREFIX environment variable does not seem to work under Cygwin. I am unclear if this is a function of Cygwin's emulation environment or a  If your code meets those two requirements (and you don't use -fno-builtin) GCC will use the builtin memcpy. I don't know of a way to force it to use builtin for larger sizes. To disable builtins you can use -fno-builtin. However, -fno-builtin only seems to work for GCC 4.9.x. Edit: To use the builtins with -std=c99 use __builtin_memcpy. I just

Note: because you're compiling C++ code, I'm not 100% sure if this applies.

The C standard requires all library functions (unless explicitly indicated otherwise) have an address and can be the operand of the & address operator. This is because it allows some/most functions to be implemented as a functional macro, but should still behave like an actual variable/function in certain cases. To avoid the macro version of it, you just need something between the memcpy token and the ( token (as @Zach pointed out, whitespace is insufficient):

(memcpy)(y, x, ...)

This forces the use of the actual function, which should avoid any sort of builtin macro definition.

It's also possible (read: likely) that the -O3 optimization scans for certain function calls (such as memcpy) and replaces them with builtin calls, regardless of -fno-builtin.

The “Resource Curse” in the Persian Gulf, As you have no doubt begun to appreciate by now, if you want GCC to do something, Some work by defining directories or prefixes to use when searching for NOTE The GCC EXEC_PREFIX environment variable does not seem to 101  How to use compiler builtin functions without Standard C library. Ask Question Asked 5 years, 3 months ago. GCC with -fno-builtin does not seem to work. 1.

Most likely part of your problem is with glibc, not gcc. You didn't specify, but you are probably using Ubuntu, which defines -D_FORTIFY_SOURCE=2 by default. This prompts the glibc headers to provide an inline definition of memcpy that forwards to __memcpy_chk.

Foreign Economic Trends and Their Implications for the United States, While GCC states have tasked themselves with integrating women in the Bahrain, and the UAE do not seem to restrict the hours women can work, and Kuwait  -fno-builtin Don't recognize built-in functions that do not begin with ‘ __builtin_ ’ as prefix. See Other built-in functions provided by GCC , for details of the functions affected, including those which are not built-in functions when -ansi or -std options for strict ISO C conformance are used because they do not have an ISO standard meaning.

Evolution of U.S. Counterterrorism Policy, The GCC is also working towards a common external tariff and free-trade within calls, which often do not seem justified by the work performed by contractors. Certain Changes We Don't Want to Make This section lists changes that people frequently request, but which we do not make because we think GCC is better without them. Checking the number and type of arguments to a function which has an old-fashioned definition and no prototype.

Railway Carmen's Journal, And we feel at this point that it is Iran which does not seem to want to bring the war and attacks against GCC diplomats reinforce our desire to work with you to​  The bytecode files are versioned and there is a strict version check, so bytecode files generated in one version of GCC will not work with an older/newer version of GCC. Link time optimization does not play well with generating debugging information. Combining -flto with -g is currently experimental and expected to produce wrong results.

Installing GCC: Configuration - GNU Project, Our work along these lines does not seem to be lagging, which is surely $1; Queen and Crescent Lodge No 362, G. C. C.'s picture, $1; Brittania Lodge No. 6.59 Other Built-in Functions Provided by GCC. GCC provides a large number of built-in functions other than the ones mentioned above. Some of these are for internal use in the processing of exceptions or variable-length argument lists and are not documented here because they may change from time to time; we do not recommend general use of these functions.