https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114441
Bug ID: 114441 Summary: Relocation issues when compiling with -O1,-O2,and -Os Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: njuwy at smail dot nju.edu.cn Target Milestone: --- The source file is: root@ubuntu:~/test/111# cat 222.cpp #include <stdio.h> int a[1][1][1][1][1]; short b[6268435456]; void c() { for (size_t d;;) for (size_t e;;) for (size_t f;;) for (size_t g;;) for (size_t i = 0; i < 16; ++i) a[d][e][f][g][i] = 2; } main() {} The version of g++: root@ubuntu:~/test/111# /root/software/IP-gcc/gcc-trunk/bin/g++ -v Using built-in specs. COLLECT_GCC=/root/software/IP-gcc/gcc-trunk/bin/g++ COLLECT_LTO_WRAPPER=/root/software/IP-gcc/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/14.0.1/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../configure --prefix=/root/software/IP-gcc/gcc-trunk --enable-languages=c,c++ --disable-multilib Thread model: posix Supported LTO compression algorithms: zlib gcc version 14.0.1 20240318 (experimental) (GCC) The issue I had when compiling at different optimization level.At the -O0 and -O3 optimization level, the compilation proceeded without any errors, but any attempt to compile with other three optimization levels (-01, -O2 and -Os) resulted in relocation-related errors, which is also present in exsiting releases: root@ubuntu:~/test/111# /root/software/IP-gcc/gcc-trunk/bin/g++ 222.cpp -o test -w -O0 root@ubuntu:~/test/111# /root/software/IP-gcc/gcc-trunk/bin/g++ 222.cpp -o test -w -O3 root@ubuntu:~/test/111# /root/software/IP-gcc/gcc-trunk/bin/g++ 222.cpp -o test -w -O1 /tmp/ccizb4WS.o: In function `c()': 222.cpp:(.text+0xd): relocation truncated to fit: R_X86_64_32S against symbol `a' defined in .bss section in /tmp/ccizb4WS.o collect2: error: ld returned 1 exit status root@ubuntu:~/test/111# /root/software/IP-gcc/gcc-trunk/bin/g++ 222.cpp -o test -w -O2 /tmp/cchi03vq.o: In function `c()': 222.cpp:(.text+0x13): relocation truncated to fit: R_X86_64_32S against symbol `a' defined in .bss section in /tmp/cchi03vq.o collect2: error: ld returned 1 exit status root@ubuntu:~/test/111# /root/software/IP-gcc/gcc-trunk/bin/g++ 222.cpp -o test -w -Os /tmp/ccHbxau8.o: In function `c()': 222.cpp:(.text+0x7): relocation truncated to fit: R_X86_64_32S against symbol `a' defined in .bss section in /tmp/ccHbxau8.o collect2: error: ld returned 1 exit status