Re: [PATCH] samples/cdtest: Test execeptions during system init

2022-07-14 Thread Chris Johns


On 14/7/2022 4:02 pm, Sebastian Huber wrote:
> On 14/07/2022 02:31, Chris Johns wrote:
>> On 13/7/2022 6:42 pm, Sebastian Huber wrote:
>>> On 01/07/2022 12:02, Sebastian Huber wrote:
 +static void early_exception()
 +{
 +    try
 +    {
 +  throw "early exception";
 +    }
 +    catch( const char *e )
 +    {
 +  rtems_test_assert(strcmp(e, "early exception") == 0);
 +  throw "early exception 2";
 +    }
 +}
 +
 +static void test_exceptions_during_system_init()
 +{
 +    TEST_BEGIN();
 +
 +    try
 +    {
 +  early_exception();
 +    }
 +    catch( const char *e )
 +    {
 +  rtems_test_assert(strcmp(e, "early exception 2") == 0);
 +    }
 +}
 +
 +RTEMS_SYSINIT_ITEM(
 +    test_exceptions_during_system_init,
 +    RTEMS_SYSINIT_IDLE_THREADS,
 +    RTEMS_SYSINIT_ORDER_LAST
 +);
>>>
>>> Actually, on targets which use the DWARF2 unwinder (for example sparc), this
>>> doesn't work since the exception frames are no yet registered.
>>
>> Is the result a terminate with an unknown type of exception of something 
>> else?
> 
> It is a failed gcc_assert() in the unwinder code. Depending on the GCC 
> options,
> this results in a __builtin_trap().

That is what Kinsey reported so it is the same issue. I will then see that on
the Versal which is good.

>> Kinsey is reporting an issue with aarch64 and cdtest on discord.
> 
> Yes, it seems ARM changed the exception implementation for aarch64 to use what
> everyone else uses. So we essentially have:
> 
> #if defined(__arm__)
> #define CAN_DO_EXCEPTIONS_DURING_SYSINIT
> #endif
> 

OK

>>
>> What mechanism is being used to initialise the unwinder support?
> 
> It is the C runtime initialization done during global construction.
> 

Is this then our problem?

>>
>> With libdl the unwind tables are registered as part of the loading.
>>
>>> They are
>>> registered during global construction. This also means that C++ exceptions 
>>> can
>>> only be used once the global construction completed on these targets.
>>
>> Has this always been the case?
> 
> Yes, but there was no test which used the C++ exceptions during system
> initialization until recently.

Ah thanks.

>> It is part of the well documented RAII principle
>> so we need this to work.
> 
> Probably the only thing we can do is to document this constraint somewhere.

An open ticket?

Chris
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH] samples/cdtest: Test execeptions during system init

2022-07-14 Thread Sebastian Huber

On 14/07/2022 02:31, Chris Johns wrote:

On 13/7/2022 6:42 pm, Sebastian Huber wrote:

On 01/07/2022 12:02, Sebastian Huber wrote:

+static void early_exception()
+{
+    try
+    {
+  throw "early exception";
+    }
+    catch( const char *e )
+    {
+  rtems_test_assert(strcmp(e, "early exception") == 0);
+  throw "early exception 2";
+    }
+}
+
+static void test_exceptions_during_system_init()
+{
+    TEST_BEGIN();
+
+    try
+    {
+  early_exception();
+    }
+    catch( const char *e )
+    {
+  rtems_test_assert(strcmp(e, "early exception 2") == 0);
+    }
+}
+
+RTEMS_SYSINIT_ITEM(
+    test_exceptions_during_system_init,
+    RTEMS_SYSINIT_IDLE_THREADS,
+    RTEMS_SYSINIT_ORDER_LAST
+);


Actually, on targets which use the DWARF2 unwinder (for example sparc), this
doesn't work since the exception frames are no yet registered.


Is the result a terminate with an unknown type of exception of something else?


It is a failed gcc_assert() in the unwinder code. Depending on the GCC 
options, this results in a __builtin_trap().



Kinsey is reporting an issue with aarch64 and cdtest on discord.


Yes, it seems ARM changed the exception implementation for aarch64 to 
use what everyone else uses. So we essentially have:


#if defined(__arm__)
#define CAN_DO_EXCEPTIONS_DURING_SYSINIT
#endif



What mechanism is being used to initialise the unwinder support?


It is the C runtime initialization done during global construction.



With libdl the unwind tables are registered as part of the loading.


They are
registered during global construction. This also means that C++ exceptions can
only be used once the global construction completed on these targets.


Has this always been the case?


Yes, but there was no test which used the C++ exceptions during system 
initialization until recently.



It is part of the well documented RAII principle
so we need this to work.


Probably the only thing we can do is to document this constraint somewhere.

--
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.hu...@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/
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH] samples/cdtest: Test execeptions during system init

2022-07-13 Thread Chris Johns
On 13/7/2022 6:42 pm, Sebastian Huber wrote:
> On 01/07/2022 12:02, Sebastian Huber wrote:
>> +static void early_exception()
>> +{
>> +    try
>> +    {
>> +  throw "early exception";
>> +    }
>> +    catch( const char *e )
>> +    {
>> +  rtems_test_assert(strcmp(e, "early exception") == 0);
>> +  throw "early exception 2";
>> +    }
>> +}
>> +
>> +static void test_exceptions_during_system_init()
>> +{
>> +    TEST_BEGIN();
>> +
>> +    try
>> +    {
>> +  early_exception();
>> +    }
>> +    catch( const char *e )
>> +    {
>> +  rtems_test_assert(strcmp(e, "early exception 2") == 0);
>> +    }
>> +}
>> +
>> +RTEMS_SYSINIT_ITEM(
>> +    test_exceptions_during_system_init,
>> +    RTEMS_SYSINIT_IDLE_THREADS,
>> +    RTEMS_SYSINIT_ORDER_LAST
>> +);
> 
> Actually, on targets which use the DWARF2 unwinder (for example sparc), this
> doesn't work since the exception frames are no yet registered. 

Is the result a terminate with an unknown type of exception of something else?
Kinsey is reporting an issue with aarch64 and cdtest on discord.

What mechanism is being used to initialise the unwinder support?

With libdl the unwind tables are registered as part of the loading.

> They are
> registered during global construction. This also means that C++ exceptions can
> only be used once the global construction completed on these targets.

Has this always been the case? It is part of the well documented RAII principle
so we need this to work.

Chris
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH] samples/cdtest: Test execeptions during system init

2022-07-13 Thread Sebastian Huber

On 01/07/2022 12:02, Sebastian Huber wrote:

+static void early_exception()
+{
+try
+{
+  throw "early exception";
+}
+catch( const char *e )
+{
+  rtems_test_assert(strcmp(e, "early exception") == 0);
+  throw "early exception 2";
+}
+}
+
+static void test_exceptions_during_system_init()
+{
+TEST_BEGIN();
+
+try
+{
+  early_exception();
+}
+catch( const char *e )
+{
+  rtems_test_assert(strcmp(e, "early exception 2") == 0);
+}
+}
+
+RTEMS_SYSINIT_ITEM(
+test_exceptions_during_system_init,
+RTEMS_SYSINIT_IDLE_THREADS,
+RTEMS_SYSINIT_ORDER_LAST
+);


Actually, on targets which use the DWARF2 unwinder (for example sparc), 
this doesn't work since the exception frames are no yet registered. They 
are registered during global construction. This also means that C++ 
exceptions can only be used once the global construction completed on 
these targets.


--
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.hu...@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/
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH] samples/cdtest: Test execeptions during system init

2022-07-03 Thread Chris Johns
OK

Thanks
Chris

On 1/7/2022 8:02 pm, Sebastian Huber wrote:
> Update #4668.
> Update #4672.
> ---
>  testsuites/samples/cdtest/main.cc | 44 ---
>  1 file changed, 35 insertions(+), 9 deletions(-)
> 
> diff --git a/testsuites/samples/cdtest/main.cc 
> b/testsuites/samples/cdtest/main.cc
> index 894e404ba1..44cdaf84bb 100644
> --- a/testsuites/samples/cdtest/main.cc
> +++ b/testsuites/samples/cdtest/main.cc
> @@ -25,9 +25,11 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  #include 
>  #include 
> +#include 
>  #include 
>  
>  #ifdef RTEMS_TEST_IO_STREAM
> @@ -44,13 +46,6 @@ extern rtems_task main_task(rtems_task_argument);
>  
>  static int num_inst = 0;
>  
> -static void check_begin_of_test(void)
> -{
> -  if ( num_inst == 0 ) {
> -TEST_BEGIN();
> -  }
> -}
> -
>  static void check_end_of_test(void)
>  {
>if ( num_inst == 0 ) {
> @@ -62,7 +57,6 @@ class AClass {
>  public:
>AClass(const char *p = "LOCAL" ) : ptr( p )
>  {
> -check_begin_of_test();
>  num_inst++;
>  printf(
>"%s: Hey I'm in base class constructor number %d for %p.\n",
> @@ -104,7 +98,6 @@ class BClass : public AClass {
>  public:
>BClass(const char *p = "LOCAL" ) : AClass( p )
>  {
> -check_begin_of_test();
>  num_inst++;
>  printf(
>"%s: Hey I'm in derived class constructor number %d for %p.\n",
> @@ -244,3 +237,36 @@ rtems_task main_task(
>  printf( "Global Dtors should be called after this line\n" );
>  exit(0);
>  }
> +
> +static void early_exception()
> +{
> +try
> +{
> +  throw "early exception";
> +}
> +catch( const char *e )
> +{
> +  rtems_test_assert(strcmp(e, "early exception") == 0);
> +  throw "early exception 2";
> +}
> +}
> +
> +static void test_exceptions_during_system_init()
> +{
> +TEST_BEGIN();
> +
> +try
> +{
> +  early_exception();
> +}
> +catch( const char *e )
> +{
> +  rtems_test_assert(strcmp(e, "early exception 2") == 0);
> +}
> +}
> +
> +RTEMS_SYSINIT_ITEM(
> +test_exceptions_during_system_init,
> +RTEMS_SYSINIT_IDLE_THREADS,
> +RTEMS_SYSINIT_ORDER_LAST
> +);
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH] samples/cdtest: Test execeptions during system init

2022-07-01 Thread Sebastian Huber
Update #4668.
Update #4672.
---
 testsuites/samples/cdtest/main.cc | 44 ---
 1 file changed, 35 insertions(+), 9 deletions(-)

diff --git a/testsuites/samples/cdtest/main.cc 
b/testsuites/samples/cdtest/main.cc
index 894e404ba1..44cdaf84bb 100644
--- a/testsuites/samples/cdtest/main.cc
+++ b/testsuites/samples/cdtest/main.cc
@@ -25,9 +25,11 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
+#include 
 #include 
 
 #ifdef RTEMS_TEST_IO_STREAM
@@ -44,13 +46,6 @@ extern rtems_task main_task(rtems_task_argument);
 
 static int num_inst = 0;
 
-static void check_begin_of_test(void)
-{
-  if ( num_inst == 0 ) {
-TEST_BEGIN();
-  }
-}
-
 static void check_end_of_test(void)
 {
   if ( num_inst == 0 ) {
@@ -62,7 +57,6 @@ class AClass {
 public:
   AClass(const char *p = "LOCAL" ) : ptr( p )
 {
-check_begin_of_test();
 num_inst++;
 printf(
   "%s: Hey I'm in base class constructor number %d for %p.\n",
@@ -104,7 +98,6 @@ class BClass : public AClass {
 public:
   BClass(const char *p = "LOCAL" ) : AClass( p )
 {
-check_begin_of_test();
 num_inst++;
 printf(
   "%s: Hey I'm in derived class constructor number %d for %p.\n",
@@ -244,3 +237,36 @@ rtems_task main_task(
 printf( "Global Dtors should be called after this line\n" );
 exit(0);
 }
+
+static void early_exception()
+{
+try
+{
+  throw "early exception";
+}
+catch( const char *e )
+{
+  rtems_test_assert(strcmp(e, "early exception") == 0);
+  throw "early exception 2";
+}
+}
+
+static void test_exceptions_during_system_init()
+{
+TEST_BEGIN();
+
+try
+{
+  early_exception();
+}
+catch( const char *e )
+{
+  rtems_test_assert(strcmp(e, "early exception 2") == 0);
+}
+}
+
+RTEMS_SYSINIT_ITEM(
+test_exceptions_during_system_init,
+RTEMS_SYSINIT_IDLE_THREADS,
+RTEMS_SYSINIT_ORDER_LAST
+);
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel