# Simulation problem with stdlib

**URL:** <https://discourse.grlib.community/t/simulation-problem-with-stdlib/172>\
**Category:** NOEL-V\
**Created:** [8 July 2021 07:32 UTC](https://discourse.grlib.community/t/simulation-problem-with-stdlib/172 "2021-07-08T07:32:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mehdy](https://avatars.discourse-cdn.com/v4/letter/m/eada6e/32.png) [@mehdy](https://discourse.grlib.community/u/mehdy)\
**Post date:** [8 July 2021 07:32 UTC](https://discourse.grlib.community/t/simulation-problem-with-stdlib/172/1 "2021-07-08T07:32:20Z")

</div>

Hello,

I want to implement some programs using the stdlib library, and then simulating it using modelsim. It compil just fine with the gaisler toolchain, but when i run the simulation, malloc() always return NULL and rand( return the following error message :

```
assertion "REENT malloc succeeded" failed: file "/opt/ncc-1.0.0-gcc/src/ncc-1.0.0/newlib/newlib/libc/stdlib/random.c", line 76

```

I haven’t tested all the fonction included from stdlib.h, but some seem to function, like atoi().

I think I do not use the right option when compiling, but I do not know which option I am not using correctly. When compiling, I use the same option as the example program (when using make soft) :

```auto
riscv-gaisler-elf-gcc -I./../../software/noelv/systest -Isw -mcmodel=medany -static -std=gnu99 -O2 -march=rv64imafd -mabi=lp64d -Wl,--no-gc-sections -nostdlib -T./../../software/noelv/systest/prom.link ./../../software/noelv/systest/prom.S -o prom.elf
riscv-gaisler-elf-objcopy --srec-len=16 --srec-forceS3 --gap-fill=0 --remove-section=.comment --remove-section=.riscv.attributes -O srec prom.elf prom.srec
riscv-gaisler-elf-gcc -I./../../software/noelv/systest -Isw -mcmodel=medany -static -std=gnu99 -O2 -march=rv64imafd -mabi=lp64d -Wl,--no-gc-sections -c ./../../software/noelv/systest/report_device.c
riscv-gaisler-elf-ar -cr libnoeltests.a
riscv-gaisler-elf-gcc -I./../../software/noelv/systest -Isw -mcmodel=medany -static -std=gnu99 -O0 -march=rv64imafd -mabi=lp64d -Wl,--no-gc-sections report_device.o -L./ libnoeltests.a -qbsp=2020q4 test_perso/hello.c -o systest.elf
riscv-gaisler-elf-objcopy --srec-len=16 --srec-forceS3 --gap-fill=0 --remove-section=.comment --remove-section=.riscv.attributes -O srec systest.elf ram.srec

```

If you have compiled programs using stdlib, especially function like malloc() or rand(), could you tell me the way to make it work for me ? For information, I use the noelv\_generic design with the single-issued GPP64 configuration.

---

<div class="post-metadata">

**Author:** ![emanfredi12](https://avatars.discourse-cdn.com/v4/letter/e/e480ec/32.png) [@emanfredi12](https://discourse.grlib.community/u/emanfredi12)\
**Post date:** [15 November 2024 23:04 UTC](https://discourse.grlib.community/t/simulation-problem-with-stdlib/172/2 "2024-11-15T23:04:52Z")

</div>

Hi, sorry for replying to this old post, but I ran into the same problem, did you manage to solve it? Thanks in advance.  
Enrico
