Bug 115158 - pru: undefined reference to _getentropy after r15-518-g99b1daae18c095
Summary: pru: undefined reference to _getentropy after r15-518-g99b1daae18c095
Status: CLOSED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 14.0
: P3 normal
Target Milestone: ---
Assignee: Dimitar Dimitrov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-05-19 17:18 UTC by Dimitar Dimitrov
Modified: 2024-05-28 18:10 UTC (History)
0 users

See Also:
Host:
Target: pru
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-05-19 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dimitar Dimitrov 2024-05-19 17:18:26 UTC
Commit r15-518-g99b1daae18c095 appears to have uncovered a latent issue in the PRU backend. Many C++ test cases started failing due to a missing symbol:

/home/dinux/projects/pru/testbot-workspace/pru-opt/pru/bin/ld: /home/dinux/projects/pru/testbot-workspace/pru-opt/lib/gcc/pru/15.0.0/../../../../pru/lib/libc.a(libc_a-getentropyr.o): in function `_getentropy_r':
/home/dinux/projects/pru/testbot-workspace/newlib/newlib/libc/reent/getentropyr.c:47:(.text._getentropy_r+0x28): undefined reference to `_getentropy'   
collect2: error: ld returned 1 exit status
compiler exited with status 1
FAIL: g++.dg/coroutines/torture/func-params-08.C (test for excess errors)

Indeed, that syscall has not been defined by PRU's libgloss. Naive solutions would be to either enable -gc-sections by default for PRU, or define the getentropy syscall for PRU in newlib.

I'm filing this bug report because I'd like to investigate a bit why it used to work before.
Comment 1 Andrew Pinski 2024-05-19 20:53:19 UTC
Hmm, _GLIBCXX_HAVE_GETENTROPY maybe should not defined for PRU while configuring libstdc++ ...
Comment 2 Dimitar Dimitrov 2024-05-20 17:53:58 UTC
Before r15-518-g99b1daae18c095, getentropy usage is disabled, as expected:
   pru-gcc-build/pru/libstdc++-v3/include/pru/bits/c++config.h:/* #undef _GLIBCXX_HAVE_GETENTROPY */

With r15-518-g99b1daae18c095, the generated code appears to be slightly bigger (similar to PR115144). The "hello world" check in config/no-executables.m4 has been already close to the default IMEM limit of 8K, so the link now begins to fail due to IMEM region overflow. Thus the configure script switches to "gcc_no_link=yes".

Newlib does not gate the getentropy() function declaration. Hence a simple compile check succeeds and erroneously enables it for libstdc++:
  pru-gcc-build/pru/libstdc++-v3/include/pru/bits/c++config.h:#define _GLIBCXX_HAVE_GETENTROPY 1

As a fix, I plan to increase the IMEM size in the default linker script.
Comment 4 Dimitar Dimitrov 2024-05-28 18:10:15 UTC
Closing