Use __builtin_trap() for abort() if inhibit_libc
commitcaf81d3b57501b1f58dcd9b1ef9d7b4bc76f4ab1
authorSebastian Huber <sebastian.huber@embedded-brains.de>
Tue, 17 Aug 2021 07:53:43 +0000 (17 09:53 +0200)
committerSebastian Huber <sebastian.huber@embedded-brains.de>
Mon, 30 Aug 2021 08:37:17 +0000 (30 10:37 +0200)
treeac89ea89ed72239296b4134b36135a6630b15245
parentd7e56b084d0b230ae5ee280f569d679fa0f09f4d
Use __builtin_trap() for abort() if inhibit_libc

abort() is used in gcc_assert() and gcc_unreachable() which is used by target
libraries such as libgcov.a.  This patch changes the abort() definition under
certain conditions.  If inhibit_libc is defined and abort is not already
defined, then abort() is defined to __builtin_trap().

The inhibit_libc define is usually defined if GCC is built for targets running
in embedded systems which may optionally use a C standard library.  If
inhibit_libc is defined, then there may be still a full featured abort()
available.  abort() is a heavy weight function which depends on signals and
file streams.  For statically linked applications, this means that a dependency
on gcc_assert() pulls in the support for signals and file streams.  This could
prevent using gcov to test low end targets for example.  Using __builtin_trap()
avoids these dependencies if the target implements a "trap" instruction.  The
application or operating system could use a trap handler to react to failed GCC
runtime checks which caused a trap.

gcc/

* tsystem.h (abort): Define abort() if inhibit_libc is defined and it
is not already defined.
gcc/tsystem.h