This is the mail archive of the 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]

[build] Use -z ignore instead of --as-needed on Solaris

While the Solaris linker doesn't support the --as-needed/--no-as-needed
options (yet), it long has provided the equivalent -z ignore/-z record
options.  This patch makes use of them, avoiding unnecessary
dependencies on

Bootstrapped without regressions on i386-pc-solaris2.11 (and checking
that many dependencies on in runtime libraries are gone
that were flagged as unused by ldd -u) and x86_64-unknown-linux-gnu
(gcc/specs unchanged, make check still running).

Ok for mainline if it passes?


2013-04-05  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	* (gcc_cv_ld_as_needed): Set
	gcc_cv_ld_as_needed_option, gcc_cv_no_as_needed_option.
	Use -z ignore, -z record on *-*-solaris2*.
	(HAVE_LD_AS_NEEDED): Update comment.
	* configure: Regenerate.
	* Regenerate.
	* gcc.c (init_gcc_specs) [USE_LD_AS_NEEDED]: Use
	* config/sol2.h [HAVE_LD_AS_NEEDED] (USE_LD_AS_NEEDED): Define.
	* doc/ (USE_LD_AS_NEEDED): Allow for --as-needed
	equivalents.  Fix markup.
	* doc/tm.texi: Regenerate.

# HG changeset patch
# Parent 602ad5b6c5e29819082e386836c33220c78ae4b7
Use -z ignore instead of --as-needed on Solaris

diff --git a/gcc/config/sol2.h b/gcc/config/sol2.h
--- a/gcc/config/sol2.h
+++ b/gcc/config/sol2.h
@@ -181,6 +181,11 @@ along with GCC; see the file COPYING3.  
    %(link_arch) \
    %{Qy:} %{!Qn:-Qy}"
+/* Use --as-needed/-z ignore -lgcc_s for eh support.  */
+#define USE_LD_AS_NEEDED 1
 #ifdef USE_GLD
 /* Solaris 11 build 135+ implements dl_iterate_phdr.  GNU ld needs
    --eh-frame-hdr to create the required .eh_frame_hdr sections.  */
diff --git a/gcc/ b/gcc/
--- a/gcc/
+++ b/gcc/
@@ -4538,6 +4538,8 @@ AC_MSG_RESULT($gcc_cv_ld_eh_gc_sections_
 AC_CACHE_CHECK(linker --as-needed support,
 if test $in_tree_ld = yes ; then
   if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 16 -o "$gcc_cv_gld_major_version" -gt 2 \
      && test $in_tree_ld_is_elf = yes; then
@@ -4547,12 +4549,25 @@ elif test x$gcc_cv_ld != x; then
 	# Check if linker supports --as-needed and --no-as-needed options
 	if $gcc_cv_ld --help 2>/dev/null | grep as-needed > /dev/null; then
+	else
+	  case "$target" in
+	    # Solaris 2 ld always supports -z ignore/-z record.
+	    *-*-solaris2*)
+	      gcc_cv_ld_as_needed=yes
+	      gcc_cv_ld_as_needed_option="-z ignore"
+	      gcc_cv_ld_no_as_needed_option="-z record"
+	      ;;
+	  esac
 if test x"$gcc_cv_ld_as_needed" = xyes; then
-[Define if your linker supports --as-needed and --no-as-needed options.])
+[Define if your linker supports --as-needed/--no-as-needed or equivalent options.])
+	AC_DEFINE_UNQUOTED(LD_AS_NEEDED_OPTION, "$gcc_cv_ld_as_needed_option",
+[Define to the linker option to ignore unused dependencies.])
+	AC_DEFINE_UNQUOTED(LD_NO_AS_NEEDED_OPTION, "$gcc_cv_ld_no_as_needed_option",
+[Define to the linker option to keep unused dependencies.])
 case "$target:$tm_file" in
diff --git a/gcc/doc/ b/gcc/doc/
--- a/gcc/doc/
+++ b/gcc/doc/
@@ -260,7 +260,8 @@ line, but, unlike @code{LIBGCC_SPEC}, it
 A macro that controls the modifications to @code{LIBGCC_SPEC}
 mentioned in @code{REAL_LIBGCC_SPEC}.  If nonzero, a spec will be
-generated that uses --as-needed and the shared libgcc in place of the
+generated that uses @option{--as-needed} or equivalent options and the
+shared @file{libgcc} in place of the
 static exception handler library, when linking without any of
 @code{-static}, @code{-static-libgcc}, or @code{-shared-libgcc}.
 @end defmac
diff --git a/gcc/gcc.c b/gcc/gcc.c
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -1361,7 +1361,8 @@ init_gcc_specs (struct obstack *obstack,
-		static_name, " --as-needed ", shared_name, " --no-as-needed"
+		static_name, " " LD_AS_NEEDED_OPTION " ",
+		shared_name, " " LD_NO_AS_NEEDED_OPTION
 		shared_name, "%{!shared: ", static_name, "}"
Rainer Orth, Center for Biotechnology, Bielefeld University

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