Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • aports aports
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Graph
    • Compare
  • Issues 663
    • Issues 663
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 325
    • Merge requests 325
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • alpinealpine
  • aportsaports
  • Merge requests
  • !43593

community/gcc-cross-embedded: fix use of libstdc++ with newlib

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Sören Tempel requested to merge nmeum/aports:newlib-g++-getentropy into master Jan 26, 2023
  • Overview 3
  • Commits 1
  • Pipelines 3
  • Changes 2

Without this patch, linking any C++ software against libstdc++ fails with an undefined reference to getentropy(3). This is due to the fact that newlib declares a getentropy function prototype without providing the symbol. This causes libstdc++ to, incorrectly, assume that getentropy is available while it is not.

Without this patch:

$ cat hello_world.cpp
#include <iostream>

int
main(void)
{
        std::cout << "Hello, World!" << std::endl;
        return 0;
}
$ riscv-none-elf-g++ -o test test.cpp -march=rv32i -mabi=ilp32
/usr/lib/gcc/riscv-none-elf/12.2.0/../../../../riscv-none-elf/bin/ld: /usr/lib/gcc/riscv-none-elf/12.2.0/../../../../riscv-none-elf/lib/rv32i/ilp32/libstdc++.a(random.o): in function `.L0 ':
random.cc:(.text._ZNSt12_GLOBAL__N_117__libc_getentropyEPv+0x10): undefined reference to `getentropy'
/usr/lib/gcc/riscv-none-elf/12.2.0/../../../../riscv-none-elf/bin/ld: /usr/lib/gcc/riscv-none-elf/12.2.0/../../../../riscv-none-elf/lib/rv32i/ilp32/libstdc++.a(random.o): in function `.L23':
random.cc:(.text._ZNSt13random_device7_M_initERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x78): undefined reference to `getentropy'
/usr/lib/gcc/riscv-none-elf/12.2.0/../../../../riscv-none-elf/bin/ld: /usr/lib/gcc/riscv-none-elf/12.2.0/../../../../riscv-none-elf/lib/rv32i/ilp32/libc.a(lib_a-arc4random.o): in function `_rs_stir':
arc4random.c:(.text._rs_stir+0x20): undefined reference to `getentropy'
collect2: error: ld returned 1 exit status

This commit fixes the issue by backporting a non-upstreamed GCC fix from the SDK for the Zephyr operating system. With this patch applied, libstdc++ does not attempt to use getentropy and hence the binary links fine.

See: https://github.com/zephyrproject-rtos/gcc/pull/8

Edited Jan 26, 2023 by Sören Tempel
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: newlib-g++-getentropy