glibc/misc/sys
Siddhesh Poyarekar c43c579612 Introduce _FORTIFY_SOURCE=3
Introduce a new _FORTIFY_SOURCE level of 3 to enable additional
fortifications that may have a noticeable performance impact, allowing
more fortification coverage at the cost of some performance.

With llvm 9.0 or later, this will replace the use of
__builtin_object_size with __builtin_dynamic_object_size.

__builtin_dynamic_object_size
-----------------------------

__builtin_dynamic_object_size is an LLVM builtin that is similar to
__builtin_object_size.  In addition to what __builtin_object_size
does, i.e. replace the builtin call with a constant object size,
__builtin_dynamic_object_size will replace the call site with an
expression that evaluates to the object size, thus expanding its
applicability.  In practice, __builtin_dynamic_object_size evaluates
these expressions through malloc/calloc calls that it can associate
with the object being evaluated.

A simple motivating example is below; -D_FORTIFY_SOURCE=2 would miss
this and emit memcpy, but -D_FORTIFY_SOURCE=3 with the help of
__builtin_dynamic_object_size is able to emit __memcpy_chk with the
allocation size expression passed into the function:

void *copy_obj (const void *src, size_t alloc, size_t copysize)
{
  void *obj = malloc (alloc);
  memcpy (obj, src, copysize);
  return obj;
}

Limitations
-----------

If the object was allocated elsewhere that the compiler cannot see, or
if it was allocated in the function with a function that the compiler
does not recognize as an allocator then __builtin_dynamic_object_size
also returns -1.

Further, the expression used to compute object size may be non-trivial
and may potentially incur a noticeable performance impact.  These
fortifications are hence enabled at a new _FORTIFY_SOURCE level to
allow developers to make a choice on the tradeoff according to their
environment.
2020-12-31 16:55:21 +05:30
..
auxv.h Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
cdefs.h Introduce _FORTIFY_SOURCE=3 2020-12-31 16:55:21 +05:30
dir.h Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
file.h Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
ioctl.h Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
mman.h Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
param.h Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
queue.h [BZ #5779] 2008-03-05 05:50:39 +00:00
select.h Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
single_threaded.h Add the __libc_single_threaded variable 2020-07-06 11:15:58 +02:00
syslog.h Rename __LONG_DOUBLE_USES_FLOAT128 to __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI 2020-04-30 08:52:08 -05:00
sysmacros.h Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
uio.h Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
xattr.h Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00