* [PATCH] Use __builtin_trap() for abort() if inhibit_libc
@ 2021-08-17 8:41 Sebastian Huber
2021-08-19 16:08 ` Jeff Law
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Sebastian Huber @ 2021-08-17 8:41 UTC (permalink / raw)
To: gcc-patches
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 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gcc/tsystem.h b/gcc/tsystem.h
index e1e6a96a4f48..5c72c69ff3ed 100644
--- a/gcc/tsystem.h
+++ b/gcc/tsystem.h
@@ -59,7 +59,7 @@ extern int atexit (void (*)(void));
#endif
#ifndef abort
-extern void abort (void) __attribute__ ((__noreturn__));
+#define abort() __builtin_trap ()
#endif
#ifndef strlen
--
2.26.2
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Use __builtin_trap() for abort() if inhibit_libc
2021-08-17 8:41 [PATCH] Use __builtin_trap() for abort() if inhibit_libc Sebastian Huber
@ 2021-08-19 16:08 ` Jeff Law
2021-08-30 10:11 ` Christophe Lyon
2023-07-22 2:29 ` Andrew Pinski
2 siblings, 0 replies; 7+ messages in thread
From: Jeff Law @ 2021-08-19 16:08 UTC (permalink / raw)
To: Sebastian Huber, gcc-patches
On 8/17/2021 2:41 AM, Sebastian Huber wrote:
> 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.
OK.
Jeff
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Use __builtin_trap() for abort() if inhibit_libc
2021-08-17 8:41 [PATCH] Use __builtin_trap() for abort() if inhibit_libc Sebastian Huber
2021-08-19 16:08 ` Jeff Law
@ 2021-08-30 10:11 ` Christophe Lyon
2021-08-30 10:54 ` Sebastian Huber
2023-07-22 2:29 ` Andrew Pinski
2 siblings, 1 reply; 7+ messages in thread
From: Christophe Lyon @ 2021-08-30 10:11 UTC (permalink / raw)
To: Sebastian Huber; +Cc: GCC Patches
Hi,
On Tue, Aug 17, 2021 at 10:43 AM Sebastian Huber <
sebastian.huber@embedded-brains.de> wrote:
> 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.
>
This causes a build failure on arm:
In file included from /libgcc/config/arm/unwind-arm.c:144:
/libgcc/unwind-arm-common.inc:55:24: error: macro "abort" passed 1
arguments, but takes just 0
55 | extern void abort (void);
This small patch should fix it:
diff --git a/libgcc/unwind-arm-common.inc b/libgcc/unwind-arm-common.inc
index c9b70c10d4f..77ec02ec811 100644
--- a/libgcc/unwind-arm-common.inc
+++ b/libgcc/unwind-arm-common.inc
@@ -50,10 +50,6 @@
#define ARM_SIGCONTEXT_R0 0xc
#endif
-/* We add a prototype for abort here to avoid creating a dependency on
- target headers. */
-extern void abort (void);
-
/* Definitions for C++ runtime support routines. We make these weak
declarations to avoid pulling in libsupc++ unnecessarily. */
typedef unsigned char bool;
Christophe
> ---
> gcc/tsystem.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gcc/tsystem.h b/gcc/tsystem.h
> index e1e6a96a4f48..5c72c69ff3ed 100644
> --- a/gcc/tsystem.h
> +++ b/gcc/tsystem.h
> @@ -59,7 +59,7 @@ extern int atexit (void (*)(void));
> #endif
>
> #ifndef abort
> -extern void abort (void) __attribute__ ((__noreturn__));
> +#define abort() __builtin_trap ()
> #endif
>
> #ifndef strlen
> --
> 2.26.2
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Use __builtin_trap() for abort() if inhibit_libc
2021-08-30 10:11 ` Christophe Lyon
@ 2021-08-30 10:54 ` Sebastian Huber
2021-08-30 11:44 ` Richard Biener
0 siblings, 1 reply; 7+ messages in thread
From: Sebastian Huber @ 2021-08-30 10:54 UTC (permalink / raw)
To: Christophe Lyon; +Cc: GCC Patches
Hello Christophe,
it seems there are a couple of more abort() declarations:
libgcc/unwind-arm-common.inc:extern void abort (void);
libgcc/config/c6x/pr-support.c:extern void abort (void);
libgcc/config/arm/pr-support.c:extern void abort (void);
libgcc/config/arm/linux-atomic-64bit.c:extern void abort (void);
libgcc/fp-bit.c: external to abort if abort is not used by the
function, and the stubs
libgcc/fp-bit.c:extern void abort (void);
I will prepare a patch.
--
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.huber@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax: +49-89-18 94 741 - 08
Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Use __builtin_trap() for abort() if inhibit_libc
2021-08-30 10:54 ` Sebastian Huber
@ 2021-08-30 11:44 ` Richard Biener
2021-08-30 11:50 ` Sebastian Huber
0 siblings, 1 reply; 7+ messages in thread
From: Richard Biener @ 2021-08-30 11:44 UTC (permalink / raw)
To: Sebastian Huber; +Cc: Christophe Lyon, GCC Patches
On Mon, Aug 30, 2021 at 12:55 PM Sebastian Huber
<sebastian.huber@embedded-brains.de> wrote:
>
> Hello Christophe,
>
> it seems there are a couple of more abort() declarations:
>
> libgcc/unwind-arm-common.inc:extern void abort (void);
> libgcc/config/c6x/pr-support.c:extern void abort (void);
> libgcc/config/arm/pr-support.c:extern void abort (void);
> libgcc/config/arm/linux-atomic-64bit.c:extern void abort (void);
> libgcc/fp-bit.c: external to abort if abort is not used by the
> function, and the stubs
> libgcc/fp-bit.c:extern void abort (void);
>
> I will prepare a patch.
Less likley to break might be to simply wrap 'abort'
in parentheses to avoid macro expansion?
> --
> embedded brains GmbH
> Herr Sebastian HUBER
> Dornierstr. 4
> 82178 Puchheim
> Germany
> email: sebastian.huber@embedded-brains.de
> phone: +49-89-18 94 741 - 16
> fax: +49-89-18 94 741 - 08
>
> Registergericht: Amtsgericht München
> Registernummer: HRB 157899
> Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
> Unsere Datenschutzerklärung finden Sie hier:
> https://embedded-brains.de/datenschutzerklaerung/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Use __builtin_trap() for abort() if inhibit_libc
2021-08-30 11:44 ` Richard Biener
@ 2021-08-30 11:50 ` Sebastian Huber
0 siblings, 0 replies; 7+ messages in thread
From: Sebastian Huber @ 2021-08-30 11:50 UTC (permalink / raw)
To: Richard Biener; +Cc: Christophe Lyon, GCC Patches
On 30/08/2021 13:44, Richard Biener wrote:
> On Mon, Aug 30, 2021 at 12:55 PM Sebastian Huber
> <sebastian.huber@embedded-brains.de> wrote:
>> Hello Christophe,
>>
>> it seems there are a couple of more abort() declarations:
>>
>> libgcc/unwind-arm-common.inc:extern void abort (void);
>> libgcc/config/c6x/pr-support.c:extern void abort (void);
>> libgcc/config/arm/pr-support.c:extern void abort (void);
>> libgcc/config/arm/linux-atomic-64bit.c:extern void abort (void);
>> libgcc/fp-bit.c: external to abort if abort is not used by the
>> function, and the stubs
>> libgcc/fp-bit.c:extern void abort (void);
>>
>> I will prepare a patch.
> Less likley to break might be to simply wrap 'abort'
> in parentheses to avoid macro expansion?
I think the abort declaration in libgcc/unwind-arm-common.inc is the
only problematic spot since unwind-arm-common.inc includes tsystem.h.
--
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.huber@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax: +49-89-18 94 741 - 08
Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Use __builtin_trap() for abort() if inhibit_libc
2021-08-17 8:41 [PATCH] Use __builtin_trap() for abort() if inhibit_libc Sebastian Huber
2021-08-19 16:08 ` Jeff Law
2021-08-30 10:11 ` Christophe Lyon
@ 2023-07-22 2:29 ` Andrew Pinski
2 siblings, 0 replies; 7+ messages in thread
From: Andrew Pinski @ 2023-07-22 2:29 UTC (permalink / raw)
To: Sebastian Huber; +Cc: gcc-patches
On Tue, Aug 17, 2021 at 1:43 AM Sebastian Huber
<sebastian.huber@embedded-brains.de> wrote:
>
> 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.
This also breaks sometimes compiling of emutls.c on some targets like uclibc ...
See https://gcc.gnu.org/PR110775 for some more details there.
Thanks,
Andrew
>
> gcc/
>
> * tsystem.h (abort): Define abort() if inhibit_libc is defined and it
> is not already defined.
> ---
> gcc/tsystem.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gcc/tsystem.h b/gcc/tsystem.h
> index e1e6a96a4f48..5c72c69ff3ed 100644
> --- a/gcc/tsystem.h
> +++ b/gcc/tsystem.h
> @@ -59,7 +59,7 @@ extern int atexit (void (*)(void));
> #endif
>
> #ifndef abort
> -extern void abort (void) __attribute__ ((__noreturn__));
> +#define abort() __builtin_trap ()
> #endif
>
> #ifndef strlen
> --
> 2.26.2
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-07-22 2:29 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-17 8:41 [PATCH] Use __builtin_trap() for abort() if inhibit_libc Sebastian Huber
2021-08-19 16:08 ` Jeff Law
2021-08-30 10:11 ` Christophe Lyon
2021-08-30 10:54 ` Sebastian Huber
2021-08-30 11:44 ` Richard Biener
2021-08-30 11:50 ` Sebastian Huber
2023-07-22 2:29 ` Andrew Pinski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).