__BUILTIN_OBJECT_SIZE(3) | Library Functions Manual | __BUILTIN_OBJECT_SIZE(3) |
__builtin_object_size
—
__builtin_object_size
(void
*ptr, int type);
__builtin_object_size
() function is a
gcc(1) built-in function that
returns the size of the ptr object if known at compile
time and the object does not have any side effects.
__builtin_object_size
() function returns:
(size_t)-1
0
and
1
.(size_t)0
2
and
3
.If the size of the object is known, then the
__builtin_object_size
() function returns the maximum
size of all the objects that the compiler knows that they can be pointed to
by ptr when type
& 2 == 0
, and the minimum size when
type & 2 != 0
.
__builtin_object_size
() appeared in GCC 4.1.
Note that currently the object size calculation pass is only done at -O1 or above, meaning that this function always returns -1 when the optimizer is off.
There are some discussions about always doing the object size pass, but the issue is that without the optimization pass data sizes are not going to be correct.
For that reason currently code fortification (size-checked replacement functions) is disabled when optimization is off.
July 18, 2012 | NetBSD 9.2 |