Our software, running on the RX72N and compiled with e2studio 2021-04 with RX CCRX Compiler v3.03 is migrating to FreeRTOS. Previous software wasn't running on an OS. It was a 'simple' while (1) without tasks. There were some interrupts, but nothing else.
While checking all the project settings I saw the flag 'Generate re-entrant library (-reent)' in the Library Generator -> Object settings.
I was wondering, is it necessary to turn on this flag because several tasks are running now that can all call, for example, sprintf()?
In the CC-RX compiler user manual v3.03.00, chapter 7.3 a list is given which library functions are reentrant and which not:
[Reentrant column O: Reentrant X: Non-reentrant D: Sets the errno variable]
We example use the sprintf() function in multiple tasks.
When turning on the flag the following linker errors were given:
<see first reply, somehow I couldn't post the linker errors included in this post>
So to summarize my question(s):
1. It is needed to turn on the flag 'Generate re-entrant library (-reent)' if we are using FreeRTOS?
2. If it is needed, how can I solve the linker errors?
Here example of the linker errors I receive. Somehow I cannot post the list completely here:
E0562310:Undefined external symbol "_wait_sem" referenced in "freopen"E0562310:Undefined external symbol "_errno_addr" referenced in "printf"E0562310:Undefined external symbol "_signal_sem" referenced in "printf"
I am not sure if it is necessary to turn on the 'Generate re-entrant library' flag. I hope you can wait for our forum experts to share their ideas about this issue. For the meantime you might want to check these old threads with the similar linker error: E0562310:Undefined external symbol (1), E0562310:Undefined external symbol (2), CS+ project occur E0562310:Undefined external symbol.
SaiRenesasRulz Forum Moderator
https://renesasrulz.com/ https://academy.renesas.com/ en-support.renesas.com/knowledgeBase
Thank you for the old threads. Unfortunately I cannot use it to solve the problem. The undefined external symbols are related to the library. Only when making it re-entrant the errors occur. I still don't know how to solve this.
Also, first question if a re-entrant library is needed is still unanswered. Hope someone can advice us.
I still don't have an answer from an expert, while it is a very important issue for us. Can someone help us directly or is there another way to contact Renesas about this question?
In the CC-RX user's manual there is the following table.
So, if the re-entrant option is used then the specified low-level routines must be defined by the user.
If you search the manual for wait_sem you will find some example code for these functions. The example code uses an array for the semaphores. As you are using FreeRTOS I would implement wait_sem and signal_sem using FreeRTOS semaphores. You will need 4 semaphores. One each for malloc, strtok, _Files and mbrlen. Depending on the success of the wait_sem and signal_sem operations the below errno values should be set.
Thank you for this answer. It's clear why the linker errors occur and we will read this part of the manual.
However, it doesn't answer my first question. Should/must we generate a re-entrant library when using FreeRTOS with multiple tasks that use, for example, sprintf() functions?
We don't use malloc, strtok, fopen, mbrlen, _Files directly, but I don't know what, for example, sprintf() uses.
Yes, I believe you should use the re-entrant library in your case when using sprintf() in more than one task. I don't have access to the sprintf() source code in CCRX but I know in other compilers it calls malloc() so I don't expect it is different. The functions which need protection for re-entrancy are often called elsewhere.
Thank you for the information. We will investigate it further.