https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91420
--- Comment #2 from Andrew Waterman <andrew at sifive dot com> --- The RISC-V code models currently in existence place a 2 GiB limit on the extent of the statically linked portion of a binary. Rather than a bug, I would describe this as a limitation of the existing code models, which we should eventually lift by introducing larger code models. Note that it's possible to get similar errors on other architecture/code model combinations. Here's an example from x86-64 with the "kernel" code model: $ g++ -mcmodel=kernel -O2 riscv_cpp_test.c tmp/ccEm3wfH.o: In function `main': test.c:(.text.startup+0x20): relocation truncated to fit: R_X86_64_32S against `.LC0' collect2: error: ld returned 1 exit status On Sun, Aug 11, 2019 at 7:47 PM bmeng.cn at gmail dot com <gcc-bugzi...@gcc.gnu.org> wrote: > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91420 > > Bug ID: 91420 > Summary: relocation truncated to fit: R_RISCV_HI20 against > `.LC0' with GCC 8.2/8.3 on RISC-V > Product: gcc > Version: 8.2.0 > Status: UNCONFIRMED > Severity: normal > Priority: P3 > Component: c++ > Assignee: unassigned at gcc dot gnu.org > Reporter: bmeng.cn at gmail dot com > Target Milestone: --- > > Created attachment 46700 > --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46700&action=edit > test case > > Please use attached test case "riscv_cpp_test.c" to trigger the bug. > > $ riscv64-unknown-linux-gnu-g++ -O2 riscv_cpp_test.c > /tmp/ccCpODP4.o: In function `.L0 ': > riscv_cpp_test.c:(.text.startup+0x4): relocation truncated to fit: > R_RISCV_HI20 > against `.LC0' > /share/toolchains/riscv/lib/gcc/riscv64-unknown-linux-gnu/8.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: > final link failed: Symbol needs debug section which does not exist > collect2: error: ld returned 1 exit status > > Workaround: using "-O0" makes the linking procedure happy. > > $ riscv64-unknown-linux-gnu-g++ -O0 riscv_cpp_test.c