https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90912
--- Comment #3 from Witold Krecicki <wpk at culm dot net> --- It seems to be a bad interaction between GCC and Solaris linker, with GNU ld it works correctly on all optimization levels - gcc -v below. Unfortunately gcc shipped with Solaris is using Solaris linker. ``` Using built-in specs. COLLECT_GCC=/usr/gcc/9-gnuld/bin/gcc COLLECT_LTO_WRAPPER=/usr/gcc/9-gnuld/lib/gcc/x86_64-pc-solaris2.11/9.1.0/lto-wrapper Target: x86_64-pc-solaris2.11 Configured with: ../configure --prefix=/usr/gcc/9-gnuld --mandir=/usr/gcc/9-gnuld/share/man --bindir=/usr/gcc/9-gnuld/bin --sbindir=/usr/gcc/9-gnuld/sbin --libdir=/usr/gcc/9-gnuld/lib --infodir=/usr/gcc/9-gnuld/share/info --libexecdir=/usr/gcc/9-gnuld/lib --enable-languages=c,c++,fortran,objc --enable-shared --enable-initfini-array --disable-rpath --with-system-zlib --with-build-config=no --with-gmp-include=/usr/include --with-mpfr-include=/usr/include --with-gnu-ld=/usr/gnu/bin/ld --with-ld=/usr/gnu/bin/ld --with-gnu-as --with-as=/usr/gnu/bin/as --disable-bootstrap 'BOOT_CFLAGS=-g -O2' x86_64-pc-solaris2.11 Thread model: posix gcc version 9.1.0 (GCC) COLLECT_GCC_OPTIONS='-v' '-O2' '-fPIC' '-mtune=generic' '-march=x86-64' /usr/gcc/9-gnuld/lib/gcc/x86_64-pc-solaris2.11/9.1.0/cc1 -quiet -v tls-test.c -quiet -dumpbase tls-test.c -mtune=generic -march=x86-64 -auxbase tls-test -O2 -version -fPIC -o /var/tmp//ccFCnhKb.s GNU C17 (GCC) version 9.1.0 (x86_64-pc-solaris2.11) compiled by GNU C version 9.1.0, GMP version 6.1.2, MPFR version 3.1.5, MPC version 1.0.3, isl version isl-0.18-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/usr/local/include" ignoring nonexistent directory "/usr/gcc/9-gnuld/lib/gcc/x86_64-pc-solaris2.11/9.1.0/../../../../x86_64-pc-solaris2.11/include" #include "..." search starts here: #include <...> search starts here: /usr/gcc/9-gnuld/lib/gcc/x86_64-pc-solaris2.11/9.1.0/include /usr/gcc/9-gnuld/include /usr/gcc/9-gnuld/lib/gcc/x86_64-pc-solaris2.11/9.1.0/include-fixed /usr/include End of search list. GNU C17 (GCC) version 9.1.0 (x86_64-pc-solaris2.11) compiled by GNU C version 9.1.0, GMP version 6.1.2, MPFR version 3.1.5, MPC version 1.0.3, isl version isl-0.18-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 8d00c2a77a592f334e9eb5693e454f4c COLLECT_GCC_OPTIONS='-v' '-O2' '-fPIC' '-mtune=generic' '-march=x86-64' /usr/gnu/bin/as -v -V -Qy -s --64 -o /var/tmp//cciW7WLb.o /var/tmp//ccFCnhKb.s GNU assembler version 2.30 (x86_64-pc-solaris2.11) using BFD version (GNU Binutils) 2.30 COMPILER_PATH=/usr/gcc/9-gnuld/lib/gcc/x86_64-pc-solaris2.11/9.1.0/:/usr/gcc/9-gnuld/lib/gcc/x86_64-pc-solaris2.11/9.1.0/:/usr/gcc/9-gnuld/lib/gcc/x86_64-pc-solaris2.11/:/usr/gcc/9-gnuld/lib/gcc/x86_64-pc-solaris2.11/9.1.0/:/usr/gcc/9-gnuld/lib/gcc/x86_64-pc-solaris2.11/:/usr/ccs/bin/ LIBRARY_PATH=/usr/gcc/9-gnuld/lib/gcc/x86_64-pc-solaris2.11/9.1.0/:/usr/gcc/9-gnuld/lib/gcc/x86_64-pc-solaris2.11/9.1.0/../../../amd64/:/lib/amd64/:/usr/lib/amd64/:/usr/gcc/9-gnuld/lib/gcc/x86_64-pc-solaris2.11/9.1.0/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-v' '-O2' '-fPIC' '-mtune=generic' '-march=x86-64' /usr/gcc/9-gnuld/lib/gcc/x86_64-pc-solaris2.11/9.1.0/collect2 -plugin /usr/gcc/9-gnuld/lib/gcc/x86_64-pc-solaris2.11/9.1.0/liblto_plugin.so -plugin-opt=/usr/gcc/9-gnuld/lib/gcc/x86_64-pc-solaris2.11/9.1.0/lto-wrapper -plugin-opt=-fresolution=/var/tmp//cce7p_6a.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh --eh-frame-hdr -V -m elf_x86_64_sol2 -Y P,/lib/amd64:/usr/lib/amd64 -Qy /usr/lib/amd64/crt1.o /usr/gcc/9-gnuld/lib/gcc/x86_64-pc-solaris2.11/9.1.0/crtp.o /usr/lib/amd64/crti.o /usr/lib/amd64/values-Xa.o /usr/lib/amd64/values-xpg6.o /usr/gcc/9-gnuld/lib/gcc/x86_64-pc-solaris2.11/9.1.0/crtbegin.o -L/usr/gcc/9-gnuld/lib/gcc/x86_64-pc-solaris2.11/9.1.0 -L/usr/gcc/9-gnuld/lib/gcc/x86_64-pc-solaris2.11/9.1.0/../../../amd64 -L/lib/amd64 -L/usr/lib/amd64 -L/usr/gcc/9-gnuld/lib/gcc/x86_64-pc-solaris2.11/9.1.0/../../.. /var/tmp//cciW7WLb.o -lgcc -lgcc_eh -lc -lgcc -lgcc_eh /usr/gcc/9-gnuld/lib/gcc/x86_64-pc-solaris2.11/9.1.0/crtend.o /usr/lib/amd64/crtn.o GNU ld (GNU Binutils) 2.30 Supported emulations: elf_x86_64_sol2 elf_x86_64 elf_i386_sol2 elf_i386_ldso elf_i386 elf_iamcu elf_l1om elf_k1om COLLECT_GCC_OPTIONS='-v' '-O2' '-fPIC' '-mtune=generic' '-march=x86-64' ```