[4.11 PATCH] libcsupport/newlib: Call newlib's __sinit to force reent initialisation

Chris Johns chrisj at rtems.org
Wed Feb 19 04:57:07 UTC 2020


On 18/2/20 7:33 pm, Sebastian Huber wrote:
> On 18/02/2020 01:25, chrisj at rtems.org wrote:
>> From: Chris Johns <chrisj at rtems.org>
>>
>> - Newlib overtites any FILE pointers set in stdin, stdout or stderr.
>>
>> Closes #3870
>> ---
>>   cpukit/libcsupport/src/newlibc_reent.c | 5 ++++-
>>   1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/cpukit/libcsupport/src/newlibc_reent.c
>> b/cpukit/libcsupport/src/newlibc_reent.c
>> index 430157cf0f..6dc0b1eeaa 100644
>> --- a/cpukit/libcsupport/src/newlibc_reent.c
>> +++ b/cpukit/libcsupport/src/newlibc_reent.c
>> @@ -44,7 +44,10 @@ bool newlib_create_hook(
>>     }
>>   #endif
>>   -  _REENT_INIT_PTR((creating_task->libc_reent)); /* GCC extension: structure
>> constants */
>> +  extern void __sinit (struct _reent *s);
>> +  struct _reent *reent = (struct _reent *) creating_task->libc_reent;
>> +  _REENT_INIT_PTR((reent)); /* GCC extension: structure constants */
>> +  __sinit( reent );
>>       return true;
>>   }
> 
> It would be good to test if this has the side-effect that now every thread
> delete closes the file descriptors 0, 1, and 2.

On 4.11 this does not happen. I added to libtests/newlib01 ...

diff --git a/testsuites/libtests/newlib01/init.c
b/testsuites/libtests/newlib01/init.c
index f9d39368d2..a8e5b3926c 100644
--- a/testsuites/libtests/newlib01/init.c
+++ b/testsuites/libtests/newlib01/init.c
@@ -245,6 +245,10 @@ static void test(void)
   int rv;
   rtems_resource_snapshot snapshot;

+  rtems_test_assert(fileno(stdout) >= 0);
+  rtems_test_assert(fileno(stdin) >= 0);
+  rtems_test_assert(fileno(stderr) >= 0);
+
   ctx->main_task_id = rtems_task_self();

   rtems_resource_snapshot_take(&snapshot);
@@ -275,6 +279,10 @@ static void test(void)
   sc = rtems_task_delete(ctx->worker_task_id);
   rtems_test_assert(sc == RTEMS_SUCCESSFUL);

+  rtems_test_assert(fileno(stdout) >= 0);
+  rtems_test_assert(fileno(stdin) >= 0);
+  rtems_test_assert(fileno(stderr) >= 0);
+
   rv = unlink(&file_path[0]);
   rtems_test_assert(rv == 0);

... after the `rtems_task_delete` call. The fileno call does not return -1.

The worker_task in newlib01 has different pointers and fd numbers for it's
stdout, stdin and stderr and `fprintf(stdout, "...");` does not appear on the
console while it does in the `test()` body. I am not sure about this. The change
to add `__sinit` does not change this, it is the same in or out.

I have also tested a large app on 4.11 with v2 of the joel script patch I will
post soon and it is working fine. I can repeat telnet to a Zynq target, run a
joel script then exit telnet and everything on the console is fine.

Chris


More information about the devel mailing list