Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 21994

Is there any motivation of using GCC __builtin_object_size at source code level?

$
0
0

I know this is not new, but recently I came across the topic of GCC __builtin_object_size() function. For what I read from the documentation, it states that the intended use can be as follows:

The intended use can be e.g.

#undef memcpy
#define bos0(dest) __builtin_object_size (dest, 0)
#define memcpy(dest, src, n) \
  __builtin___memcpy_chk (dest, src, n, bos0 (dest))

char *volatile p;
char buf[10];
/* It is unknown what object p points to, so this is optimized
   into plain memcpy - no checking is possible.  */
memcpy (p, "abcde", n);

... // more codes

Is there any advantage of directly using it at the source code level instead of enabling the D_FORTIFY_SOURCE flag when compiling? Are there actually real life examples that benefit from the use of __builtin_object_size()?


Viewing all articles
Browse latest Browse all 21994

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>