Hi,

A small set of fixes and a cleanup. Tested on x86-64 and i386.

This contains:
 
- Evaluate syscall() arguments before they reach the arch macros. The
  __nolibc_syscallN() macros drop their arguments into local register
  variables, which GCC does not guarantee to survive a function call,
  so an argument such as strlen(msg) clobbers the registers that were
  already set up and the wrong syscall is made. Reproduced with gcc on
  i386 and x86-64 at -O0, -O1, -O2, -O3 and -Os.
 
- Avoid signed overflow in abs(), labs() and llabs(): negate in the
  corresponding unsigned type, so passing the type minimum no longer
  invokes undefined behavior. The value is still not representable in
  the result type, so the minimum is returned unchanged. Under the:

    -fsanitize=undefined -fsanitize-trap=all

  flags the selftests are built with, the old code did not merely
  return an unspecified answer, it died with SIGILL (thrown by ud2).
 
- Add an abs() range test walking abs(), labs() and llabs() over the
  interesting points of their argument type: the minimum, the minimum
  plus one, an ordinary negative value, zero and the maximum.
 
- Remove the dead __ARCH_WANT_SYS_OLD_SELECT from arch-x86.h and
  arch-arm.h. It lost its last user when select() was reimplemented on
  top of pselect6 for every architecture.
 
Patches 1 and 2 are fixes. Patch 3 is the selftest that covers patch 2,
and patch 4 is a pure cleanup.

Signed-off-by: Ammar Faizi <[email protected]>
---

Ammar Faizi (4):
  tools/nolibc: evaluate syscall() arguments before the arch macros
  tools/nolibc: stdlib: avoid signed overflow in abs() and friends
  selftests/nolibc: add abs() range test
  tools/nolibc: remove dead __ARCH_WANT_SYS_OLD_SELECT

 tools/include/nolibc/arch-arm.h              |  3 -
 tools/include/nolibc/arch-x86.h              |  3 -
 tools/include/nolibc/stdlib.h                | 12 +++-
 tools/include/nolibc/sys/syscall.h           | 72 +++++++++++++++++++-
 tools/testing/selftests/nolibc/nolibc-test.c | 47 +++++++++++++
 5 files changed, 127 insertions(+), 10 deletions(-)


base-commit: 070cf03f5ec454eec9c42827ee9f3c0b3fad09f1
-- 
Ammar Faizi


Reply via email to