FS#75722 - [arm-none-eabi-gcc] 12.2.0 link errors in libstdc++ (random.cc)

Attached to Project: Community Packages
Opened by Vladimir Chistyakov (b1ackviking) - Monday, 29 August 2022, 05:46 GMT
Last edited by Toolybird (Toolybird) - Saturday, 22 October 2022, 21:06 GMT
Task Type Bug Report
Category Packages
Status Closed
Assigned To No-one
Architecture All
Severity Medium
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:

The libstdc++ fails to link with `int getentropy(void *buffer, size_t length)` when using `std::random_device` in the code. The issue comes from newlib: it declares, but not defines, the `getentropy()` function. The upstream GCC has already added fixes to the build scripts to detect and fix this issue (see the upstream bug report). However, the packaged version still contains references to the undefined `getentropy()` symbol.


Additional info:
* package version(s): 12.1.0, 12.2.0
* link to upstream bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103166

Steps to reproduce:

Given the following simple program:
```cpp
#include <random>
int main() { return static_cast<int>(std::random_device{}()); }
```

Compiling it with: arm-none-eabi-g++ -specs=nosys.specs main.cpp

Gives the following error message:
```
➜ getentropy arm-none-eabi-g++ -specs=nosys.specs main.cpp
/usr/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/lib/libstdc++.a(random.o): in function `std::(anonymous namespace)::__libc_getentropy(void*)':
/build/arm-none-eabi-gcc/src/gcc-12.2.0/libstdc++-v3/src/c++11/random.cc:179: undefined reference to `getentropy'
/usr/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/lib/libstdc++.a(random.o): in function `std::random_device::_M_init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/build/arm-none-eabi-gcc/src/gcc-12.2.0/libstdc++-v3/src/c++11/random.cc:452: undefined reference to `getentropy'
/usr/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/12.2.0/../../../../arm-none-eabi/lib/libc.a(lib_a-arc4random.o): in function `_rs_stir':
/build/arm-none-eabi-newlib/src/build-newlib/arm-none-eabi/newlib/libc/stdlib/../../../../../newlib-4.2.0.20211231/newlib/libc/stdlib/arc4random.c:89: undefined reference to `getentropy'
collect2: error: ld returned 1 exit status
```
This task depends upon

Closed by  Toolybird (Toolybird)
Saturday, 22 October 2022, 21:06 GMT
Reason for closing:  No response
Additional comments about closing:  It's also an upstream issue.
Comment by Toolybird (Toolybird) - Monday, 29 August 2022, 07:44 GMT
So, IIUC the fixes are included in 12.2.0 but they don't work for this target? Do you have a proposed solution? This would greatly increase the chances of a fixed Arch pkg. If newlib needs fixing then maybe you should be reporting this upstream to newlib?
Comment by Vladimir Chistyakov (b1ackviking) - Monday, 29 August 2022, 08:36 GMT
>So, IIUC the fixes are included in 12.2.0 but they don't work for this target?
I think it is the case, although I am definitely not an expert in this area. My understanding is that the patch added to the GCC in the mentioned upstream bug report should detect presence/absence of the getentropy() implementation, but it does not work for some reason.

>Do you have a proposed solution?
No, I am trying to investigate the problem further at the moment.

>If newlib needs fixing then maybe you should be reporting this upstream to newlib?
Yes, I am going to report the issue to newlib maintainers and try to submit a patch with a stub implementation of getentropy() if there are no objections from their side.
Comment by Toolybird (Toolybird) - Friday, 23 September 2022, 06:27 GMT
Any luck with this? I just noticed this thread [1] which I believe is the same issue.

[1] https://sourceware.org/pipermail/newlib/2022/019916.html

Loading...