Skip to content

Commit

Permalink
init: declare _libc_init as constructor
Browse files Browse the repository at this point in the history
This allows constructor handling mechanism in dynamic linker.

JIRA: RTOS-664
  • Loading branch information
badochov committed Sep 2, 2024
1 parent 94c36aa commit 2310ddd
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion misc/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,21 @@ extern void _init_array(void);
extern void _pthread_init(void);


void _libc_init(void)
static int _libc_initialized;


/* _libc_init is called twice once explicitely in crt0 and once during constructor handling.
* If libc is linked statically first it is called explicitely and then during constructor handling.
* If libc is linked dynamically first it is called by the constructor handling mechanism in dynamic linker,
* to allow constructors from other objects to call libc functions.
*/
__attribute__((constructor)) void _libc_init(void)
{
if (_libc_initialized != 0) {
return;
}
_libc_initialized = 1;

_atexit_init();
_errno_init();
_malloc_init();
Expand Down

0 comments on commit 2310ddd

Please sign in to comment.