[v2,0/2] _FORTIFY_SOURCE=3 improvements

Message ID 20211020052434.1221167-1-siddhesh@sourceware.org
Headers
Series _FORTIFY_SOURCE=3 improvements |

Message

Siddhesh Poyarekar Oct. 20, 2021, 5:24 a.m. UTC
  This patchset changes the layout of fortified functions to make them
_FORTIFY_SOURCE=3 friendly and at the same time, continue working the
same for _FORTIFY_SOURCE=2 and lower.  At a high level it makes sure
that no branches are emitted at compile time and only one of either the
regular or _chk version of the function is called.  The conditions are
also reworked to make them more readable and foldable even in cases
where the compiler doesn't know the exact values of the operation length
and size, but can make decisions based on ranges of their values.

The changeset also adds some _FORTIFY_SOURCE=3 testing coverage on
compilers that are able to set that fortification level.

Changes from v1:

- Committed access attribute related patch
- Updated macros to fold the sign check into a single macro

Siddhesh Poyarekar (2):
  Make sure that the fortified function conditionals are constant
  debug: Add tests for _FORTIFY_SOURCE=3

 debug/Makefile        |  13 ++-
 debug/tst-chk1.c      | 102 +++++++++++---------
 debug/tst-chk7.c      |   2 +
 debug/tst-chk8.cc     |   2 +
 io/bits/poll2.h       |  27 ++----
 libio/bits/stdio2.h   | 106 +++++++++-----------
 misc/sys/cdefs.h      |  47 +++++++++
 posix/bits/unistd.h   | 174 ++++++++-------------------------
 socket/bits/socket2.h |  34 +++----
 stdlib/bits/stdlib.h  |  57 ++++-------
 wcsmbs/bits/wchar2.h  | 219 ++++++++++++------------------------------
 11 files changed, 295 insertions(+), 488 deletions(-)
 create mode 100644 debug/tst-chk7.c
 create mode 100644 debug/tst-chk8.cc
  

Comments

Siddhesh Poyarekar Oct. 20, 2021, 2:28 p.m. UTC | #1
On 10/20/21 10:54, Siddhesh Poyarekar via Libc-alpha wrote:
> This patchset changes the layout of fortified functions to make them
> _FORTIFY_SOURCE=3 friendly and at the same time, continue working the
> same for _FORTIFY_SOURCE=2 and lower.  At a high level it makes sure
> that no branches are emitted at compile time and only one of either the
> regular or _chk version of the function is called.  The conditions are
> also reworked to make them more readable and foldable even in cases
> where the compiler doesn't know the exact values of the operation length
> and size, but can make decisions based on ranges of their values.
> 
> The changeset also adds some _FORTIFY_SOURCE=3 testing coverage on
> compilers that are able to set that fortification level.
> 
> Changes from v1:
> 
> - Committed access attribute related patch
> - Updated macros to fold the sign check into a single macro

I'll be backporting this series to 2.34 unless there are any objections.

Thanks,
Siddhesh