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

--- Comment #4 from Jason Vas Dias <jason.vas.dias at gmail dot com> ---
Thanks for having a look at this, Richard .

Yes, "some weirdness" is definitely going on -
but I'd like to determine precisely which "weirdness". 

This occurred when building my new LFS system's system compiler
for the first time, with a GCC-5.2.0 instance built for RHEL-6,
whose installation directories were all mounted with the 'bind'
option ( /usr/lib/gcc/x86_64-redhat-linux/5.2.0 ,
 /usr/libexec/gcc/x86_64-redhat-linux/5.2.0 , etc. )
and where $PATH picked up all gcc binaries from a 
'bin/' directory containing links like :
   gcc -> /${path_to_rhel6_usr_bin}/gcc5.2.0 
   ... etc.

My configure options were :

/usr/os_src/gcc-5.3.0/configure --prefix=/usr --libdir=/usr/lib64
--enable-shared \
  --enable-languages=all \
  --enable-bootstrap \
  --enable-multilib \
  --with-cpu-64=haswell \
  --with-cpu-32=atom \
  --with-arch-64=x86-64 \
  --with-tune-64=haswell \
  --with-arch-32=i686 \
  --with-tune-32=atom \
  --enable-targets=all \
  --enable-threads=posix \
  --enable-lto \
  --enable-serial-configure \
  --enable-checking=release \
  --with-stage1-ldflags='-L/usr/lib64 -L/usr/local/lib64 -L/usr/lib32
-L/usr/local/lib32
-Wl,-R,/usr/lib64:/usr/local/lib64:/usr/lib32:/usr/local/lib32' \
  --with-gmp=/usr   --with-gmp-lib=/usr/lib64 \
  --with-mpfr=/usr  --with-mpfr-lib=/usr/lib64 \
  --with-mpc=/usr   --with-mpc-lib=/usr/lib64 \
  --with-isl=/usr   --with-isl-lib=/usr/lib64 \
  --with-cloog=/usr --with-cloog-lib=/usr/lib64 \
  --with-gnu-ld \
  --with-gnu-as \
  --enable-linker-build-id \
  --disable-libunwind-exceptions \
  --disable-nls \
  --enable-version-specific-runtime-libs \
  --enable-__cxa_atexit \
  --without-x \
  --disable-gtk-cairo \
  --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre \
  --enable-libgcj-multifile \
  --with-ecj-jar=/usr/share/java/eclipse-ecj.jar \
  --with-system-zlib \
  --enable-java-home \
  --with-arch-directory=x86_64 \
  --disable-libjava-multilib \
  --build=x86_64-pc-linux-gnu \
  --host=x86_64-pc-linux-gnu


I had to radically modify the ./gcc/Makefile of the build directory 
to add '-static-libstdc++ -lstdc++' to EVERY executable's link command ,
finally the 'make' completed with 0 exit status, and 'make DESTDIR=... install' 
created the installation directory , and the test suite passed (with some
expected failures - details on request). 

The translated gcc/Makefile.in produced a gcc/Makefile containing  :

LDFLAGS = -static-libstdc++ -static-libgcc

Note: no -lstdc++ - I think the '-static-libstdc++' option on its own
does NOT imply '-lstdc++' - you have to add it to actually link against
libstdc++.a .

So that is what I did , modifying the above lines:

NEEDS_STDCXX = -static-libstdc++ -lstdc++
LDFLAGS = -static-libgcc $(NEEDS_STDCXX)

and I had to add this into many other places where an executable
is being produced and LDFLAGS is not referenced:

...
ALL_LINKERFLAGS = $(ALL_CXXFLAGS) -static-libgcc $(NEEDS_STDCXX)
...

# For stage1 and when cross-compiling use the build libcpp which is
# built with NLS disabled.  For stage2+ use the host library and
# its dependencies.
ifeq ($(build_objdir),$(build_libobjdir))
BUILD_CPPLIB = $(build_libobjdir)/libcpp/libcpp.a
else
BUILD_CPPLIB = $(CPPLIB) $(LIBIBERTY) 
build/genmatch$(build_exeext): BUILD_LIBDEPS += $(LIBINTL_DEP) $(LIBICONV_DEP) 
build/genmatch$(build_exeext): BUILD_LIBS += $(LIBINTL) $(LIBICONV)
$(NEEDS_STDCXX)
endif

...


I suggest making the gcc/Makefile.in / $TOPDIR/{configure.ac,Makefile.am}
add '-lstdc++' every time it writes '-static-libstdc++' to the Makefile ,
eg. $TOPDIR/configure.ac @ line 1376:

# Check whether -static-libstdc++ -static-libgcc is supported.
have_static_libs=no
if test "$GCC" = yes; then
  saved_LDFLAGS="$LDFLAGS"

  LDFLAGS="$LDFLAGS -static-libstdc++ -static-libgcc"
#                                                   ^- add ' -lstdc++' here

@ line 1718:

[stage1_ldflags=
 # In stage 1, default to linking libstdc++ and libgcc statically with GCC
 # if supported.  But if the user explicitly specified the libraries to use,
 # trust that they are doing what they want.
 if test "$stage1_libs" = "" -a "$have_static_libs" = yes; then
   stage1_ldflags="-static-libstdc++ -static-libgcc"
 #                                                 ^- add ' -lstdc++' here

 fi])


@ line 1741:

[poststage1_ldflags=
 # In stages 2 and 3, default to linking libstdc++ and libgcc
 # statically.  But if the user explicitly specified the libraries to
 # use, trust that they are doing what they want.
 if test "$poststage1_libs" = ""; then
   poststage1_ldflags="-static-libstdc++ -static-libgcc"
 #                                                     ^- add ' -lstdc++' here
 fi])


I can't put my finger on the component that is meant to add '-lstdc++' 
to the poststage1_ldflags if not above modified lines ATM - what is meant
to be doing this ?

I will try building with the configure.ac so modified next time.

This problem has not occurred building gcc-5.2.0 or previous GCC releases .

Reply via email to