https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114441

--- Comment #3 from Yang Wang <njuwy at smail dot nju.edu.cn> ---
(In reply to Andrew Pinski from comment #1)
> This is not a GCC bug, 
> 
> You need to use -mcmodel=large if you have huge statically allocated arrays.
> 
> The default -mcmodel=medium does not support more than 2GB size arrays
> 
> See
>  https://gcc.gnu.org/onlinedocs/gcc-13.2.0/gcc/x86-Options.html#index-
> mcmodel_003dlarge-3

Thanks for your reply! Indeed, the compilation was successful when either the
-mcmodel=medium or -mcmodel=large was enabled. However, I'm still curious why
it can be compiled successfully at the -O3 optimization level when the default
-mcmodel=small is enabled? As far as I know, the -O3 optimization level is the
highest.


root@ubuntu:~/test/111# /root/software/IP-gcc/gcc-trunk/bin/g++ 222.cpp -o test
-w -mcmodel=medium -O0

root@ubuntu:~/test/111# /root/software/IP-gcc/gcc-trunk/bin/g++ 222.cpp -o test
-w -mcmodel=medium -O3

root@ubuntu:~/test/111# /root/software/IP-gcc/gcc-trunk/bin/g++ 222.cpp -o test
-w -mcmodel=medium -O1

root@ubuntu:~/test/111# /root/software/IP-gcc/gcc-trunk/bin/g++ 222.cpp -o test
-w -mcmodel=medium -O2

root@ubuntu:~/test/111# /root/software/IP-gcc/gcc-trunk/bin/g++ 222.cpp -o test
-w -mcmodel=medium -Os

root@ubuntu:~/test/111# /root/software/IP-gcc/gcc-trunk/bin/g++ 222.cpp -o test
-w -mcmodel=small -O0

root@ubuntu:~/test/111# /root/software/IP-gcc/gcc-trunk/bin/g++ 222.cpp -o test
-w -mcmodel=small -O3

root@ubuntu:~/test/111# /root/software/IP-gcc/gcc-trunk/bin/g++ 222.cpp -o test
-w -mcmodel=small -O1
/tmp/ccdtPXUH.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/ccdtPXUH.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 -mcmodel=small -O2
/tmp/ccbjzODN.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/ccbjzODN.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 -mcmodel=small -Os
/tmp/ccUUdbLp.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/ccUUdbLp.o
collect2: error: ld returned 1 exit status

Reply via email to