Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ESP32] Linker error for esp_fill_random when using C++ <random> RNG (IDFGH-14312) #15103

Open
3 tasks done
MayaPosch opened this issue Dec 27, 2024 · 3 comments
Open
3 tasks done
Labels
Status: Opened Issue is new Type: Bug bugs in IDF

Comments

@MayaPosch
Copy link

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v5.3.2

Operating System used.

Windows

How did you build your project?

Command line with CMake

If you are using Windows, please specify command line type.

CMD

What is the expected behavior?

I expected the code to compile and link, as the only significant change was adding an RNG using the standard C++ header.

What is the actual behavior?

Instead I get the linker error: [..]components/newlib/random.c:31:(.text.getrandom+0x18): undefined reference to 'esp_fill_random'

Steps to reproduce.

  1. Add the C++ <random> header.
  2. Set up a new RNG:
std::random_device rd;
std::mt19937 gen(rd());
  1. Try to compile code.
  2. Observe the linker error: [..]components/newlib/random.c:31:(.text.getrandom+0x18): undefined reference to 'esp_fill_random'

Build or installation Logs.

D:/Dev/Espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/newlib/libnewlib.a(random.c.obj): in function `getrandom':
D:/Dev/Espressif/frameworks/esp-idf-v5.2.2/components/newlib/random.c:31:(.text.getrandom+0x18): undefined reference to `esp_fill_random'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

More Information.

I upgraded from ESP-IDF v5.2.2 to the current stable (v5.3.2, in the same folder), without changes to the error.

@MayaPosch MayaPosch added the Type: Bug bugs in IDF label Dec 27, 2024
@github-actions github-actions bot changed the title [ESP32] Linker error for esp_fill_random when using C++ <random> RNG [ESP32] Linker error for esp_fill_random when using C++ <random> RNG (IDFGH-14312) Dec 27, 2024
@espressif-bot espressif-bot added the Status: Opened Issue is new label Dec 27, 2024
@igrr
Copy link
Member

igrr commented Dec 27, 2024

Thanks for the report @MayaPosch! We have an issue open for this in the internal tracker, but haven't yet addressed it unfortunately. Sometimes this issue manifests in ::getrandom itself not being found at link time. The root cause is related to how the dependencies between libstdc++ library, "newlib" and "esp_hw_support" components are set up.

The workaround for the time being is to force esp_fill_random to be considered for inclusion into the binary by the linker, for example by adding

target_link_libraries(${COMPONENT_LIB} PUBLIC "-Wl,-u esp_fill_random")

to one of your components' CMakeLists.txt files.

@MayaPosch
Copy link
Author

Thank you, I can confirm that the workaround allows the code to link at least. I'll be running some tests to hopefully confirm that it fully fixes the issue for now.

Is there any projection for when this issue is expected to fixed in an upcoming ESP-IDF release?

@igrr
Copy link
Member

igrr commented Dec 27, 2024

Will try to get this fixed before v5.3.3, however I don't yet have an estimate of the date the release will be ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

3 participants