This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: LDFLAGS handling in V3


The libstdc++ Makefiles use LDFLAGS when linking libraries:

  CXXLINK = $(LIBTOOL) --tag CXX --mode=link $(CXX) \
	  $(OPT_LDFLAGS) $(SECTION_LDFLAGS) $(AM_CXXFLAGS) $(LDFLAGS) -o $@

Like CFLAGS, etc., LDFLAGS is passed down from the top-level Makefile,
where it is called LDFLAGS_FOR_TARGET.

However, since the linker is actually libtool, rather than the
ordinary linker, I think that the LDFLAGS should be prefixed with
"-Wl,".  Otherwise, libtool will disregard some, but not all, of the
flags provided, and will invoke the linker (well, "xgcc") without all
of the options.  (An example of an option which libtool will ignore is
"--sysroot".)  I guess that libtool could be made to recognize more
options and know that they are for the linker, as well as the
compiler, but it seems better just to bullet-proof the Makefiles.  You
could also argue that the user should just put "-Wl," explicitly into
LDFLAGS/LDFLAGS_FOR_TARGET when running "make", but that wouldn't work
at the top level if you had some target subdirectories using libtool
and others using "ld" directly.

Here's a proposed patch, tested on x86_64-unknown-linux-gnu.  I'm not
planning on checking this in unless its approved, as I'm not confident
that everyone would agree with the logic above.  Thoughts?

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2005-07-27  Mark Mitchell  <mark@codesourcery.com>

	* src/Makefile.am (LIBTOOLLDFLAGS): New variable.
	(CXXLINK): Use it.
	* libsupc++/Makefile.am (LIBTOOLLDFLAGS): New variable.
	(CXXLINK): Use it.

Index: src/Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/Makefile.am,v
retrieving revision 1.149
diff -c -5 -p -r1.149 Makefile.am
*** src/Makefile.am	17 Jun 2005 07:33:53 -0000	1.149
--- src/Makefile.am	27 Jul 2005 21:26:46 -0000
*************** AM_CXXFLAGS = \
*** 203,220 ****
  # CXXLINK, just after $(LIBTOOL), so that libtool doesn't have to
  # attempt to infer which configuration to use
  LTCXXCOMPILE = $(LIBTOOL) --tag CXX --mode=compile $(CXX) $(INCLUDES) \
  	       $(AM_CPPFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(AM_CXXFLAGS)
  
  # 3) We'd have a problem when building the shared libstdc++ object if
  # the rules automake generates would be used.  We cannot allow g++ to
  # be used since this would add -lstdc++ to the link line which of
  # course is problematic at this point.  So, we get the top-level
  # directory to configure libstdc++-v3 to use gcc as the C++
  # compilation driver.
  CXXLINK = $(LIBTOOL) --tag CXX --mode=link $(CXX) \
! 	  $(OPT_LDFLAGS) $(SECTION_LDFLAGS) $(AM_CXXFLAGS) $(LDFLAGS) -o $@
  
  
  # Added bits to build debug library.
  if GLIBCXX_BUILD_DEBUG
  all-local: build_debug
--- 202,224 ----
  # CXXLINK, just after $(LIBTOOL), so that libtool doesn't have to
  # attempt to infer which configuration to use
  LTCXXCOMPILE = $(LIBTOOL) --tag CXX --mode=compile $(CXX) $(INCLUDES) \
  	       $(AM_CPPFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(AM_CXXFLAGS)
  
+ # The LDFLAGS we receive from the top-level Makefile are designed directly 
+ # for the linker, so we must tell libtool to pass them along explicitly.
+ LIBTOOLLDFLAGS = `for ldflag in $(LDFLAGS); do echo "-Wl,$$ldflag"; done`
+ 
  # 3) We'd have a problem when building the shared libstdc++ object if
  # the rules automake generates would be used.  We cannot allow g++ to
  # be used since this would add -lstdc++ to the link line which of
  # course is problematic at this point.  So, we get the top-level
  # directory to configure libstdc++-v3 to use gcc as the C++
  # compilation driver.
  CXXLINK = $(LIBTOOL) --tag CXX --mode=link $(CXX) \
! 	  $(OPT_LDFLAGS) $(SECTION_LDFLAGS) $(AM_CXXFLAGS) \
! 	  $(LIBTOOLLDFLAGS) -o $@
  
  
  # Added bits to build debug library.
  if GLIBCXX_BUILD_DEBUG
  all-local: build_debug
Index: libsupc++/Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/Makefile.am,v
retrieving revision 1.51
diff -c -5 -p -r1.51 Makefile.am
*** libsupc++/Makefile.am	28 Jun 2005 19:52:24 -0000	1.51
--- libsupc++/Makefile.am	27 Jul 2005 21:26:46 -0000
*************** cp-demangle.o: cp-demangle.c
*** 136,154 ****
  # CXX undo the affect of disable-shared.
  LTCXXCOMPILE = $(LIBTOOL) --tag CXX --tag disable-shared \
  	       --mode=compile $(CXX) $(TOPLEVEL_INCLUDES) \
  	       $(AM_CPPFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(AM_CXXFLAGS)
  
  # 3) We'd have a problem when building the shared libstdc++ object if
  # the rules automake generates would be used.  We cannot allow g++ to
  # be used since this would add -lstdc++ to the link line which of
  # course is problematic at this point.  So, we get the top-level
  # directory to configure libstdc++-v3 to use gcc as the C++
  # compilation driver.
  CXXLINK = $(LIBTOOL) --tag CXX --tag disable-shared \
  	  --mode=link $(CXX) \
! 	  $(OPT_LDFLAGS) $(SECTION_LDFLAGS) $(AM_CXXFLAGS) $(LDFLAGS) -o $@
  
  # We have to have rules modified from the default to counteract SUN make
  # prepending each of $(glibcxxinstall_HEADERS) with VPATH below.
  install-glibcxxinstallHEADERS: $(glibcxxinstall_HEADERS)
  	@$(NORMAL_INSTALL)
--- 136,159 ----
  # CXX undo the affect of disable-shared.
  LTCXXCOMPILE = $(LIBTOOL) --tag CXX --tag disable-shared \
  	       --mode=compile $(CXX) $(TOPLEVEL_INCLUDES) \
  	       $(AM_CPPFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(AM_CXXFLAGS)
  
+ # The LDFLAGS we receive from the top-level Makefile are designed directly 
+ # for the linker, so we must tell libtool to pass them along explicitly.
+ LIBTOOLLDFLAGS = `for ldflag in $(LDFLAGS); do echo "-Wl,$$ldflag"; done`
+ 
  # 3) We'd have a problem when building the shared libstdc++ object if
  # the rules automake generates would be used.  We cannot allow g++ to
  # be used since this would add -lstdc++ to the link line which of
  # course is problematic at this point.  So, we get the top-level
  # directory to configure libstdc++-v3 to use gcc as the C++
  # compilation driver.
  CXXLINK = $(LIBTOOL) --tag CXX --tag disable-shared \
  	  --mode=link $(CXX) \
! 	  $(OPT_LDFLAGS) $(SECTION_LDFLAGS) $(AM_CXXFLAGS) \
!           $(LIBTOOLLDFLAGS) -o $@
  
  # We have to have rules modified from the default to counteract SUN make
  # prepending each of $(glibcxxinstall_HEADERS) with VPATH below.
  install-glibcxxinstallHEADERS: $(glibcxxinstall_HEADERS)
  	@$(NORMAL_INSTALL)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]