https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106501
Bug ID: 106501
Summary: libstdc++ is built without -fPIC despite --with-pic
Product: gcc
Version: 12.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: skunk at iskunk dot org
Target Milestone: ---
Host: x86_64-pc-linux-gnu
Target: x86_64-pc-linux-gnu
Build: x86_64-pc-linux-gnu
I bootstrapped GCC 12.1.0 with the following options:
--disable-shared
--disable-nls
--enable-version-specific-runtime-libs
--with-pic
--disable-multilib
--with-arch=opteron
--disable-libsanitizer
--disable-libcc1
--enable-languages=c,c++,lto
Notable is the combination of "--disable-shared --with-pic", with the intention
of having all the GCC support libraries be statically linkable when building
executables, shared libraries, etc.
Once the bootstrap was complete, I used the new GCC to build a current version
of GDB. That build failed with
CXXLD libinproctrace.so
/usr/bin/ld:
/opt/sfw/bin/../lib/gcc/x86_64-pc-linux-gnu/12.1.0/libstdc++.a(class_type_info.o):
relocation R_X86_64_32S against `_ZTVN10__cxxabiv117__class_type_infoE' can not
be used when making a shared object; recompile with -fPIC
/opt/sfw/bin/../lib/gcc/x86_64-pc-linux-gnu/12.1.0/libstdc++.a: could not read
symbols: Bad value
collect2: error: ld returned 1 exit status
gmake[2]: *** [Makefile:383: libinproctrace.so] Error 1
gmake[2]: Leaving directory '/tmp/gdb-12.1-build/gdbserver'
gmake[1]: *** [Makefile:11743: all-gdbserver] Error 2
gmake[1]: Leaving directory '/tmp/gdb-12.1-build'
gmake: *** [Makefile:1001: all] Error 2
I checked the build log for GCC. None of the compile lines for
class_type_info.o include the -fPIC option (i.e. "fgrep class_type_info.o
gcc12-build-log.txt | grep -c PIC" yields 0).
The --with-pic option should cause all libraries to be built with -fPIC, even
when they are built as static archives. It is possible that libstdc++ is not
the only library that was built incorrectly; it is only the one I noticed.
Related: bug #66955, bug #67128