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]

Better relocation handling for nonstandard --libdirs


Configure allows --libdir to be defined to something other than
${exec_prefix}/lib.  --libdir=${prefix}/lib is actually a useful
setting for cross compilers; only target data goes into --libdir,
and the data is conceptually shared rather than host-specific.
Host stuff goes in --libexecdir instead.

Unfortunately, relocation doesn't work an install tree that contains
both gcc and binutils if gcc's --libdir was not the standard setting.
Binutils uses a tooldir of

   ${exec_prefix}/<target>

with binaries in the bin/ subdirectory and linker scripts in the
lib/ subdirectory.  This tooldir value is hard-coded; it is not
user-configurable.

However, gcc computes the binutils tooldir as:

   ${libsubdir}/${unlibsubdir}/../<target>
                ^^^^^^^^^^^^^^^^^^
where the underlined portion coming from TOOLDIR_BASE_PREFIX.
This "../" hard-codes the assumption that --libdir is a direct
descendant of --exec-prefix.

Also, configure has code that tries to go from --libdir to --prefix.
Like the TOOLDIR_BASE_PREFIX setting, this code assumes that --libdir
is a subdirectory of --exec-prefix.  However, the sed expressions are
based on the _Makefile expansion of_ ${exec_prefix}, so this seems
unnecessarily restrictive.

This patch therefore introduces two new makefile variables:
${libsubdir_to_prefix} and ${prefix_to_exec_prefix}.  The former is
derived from the old configure code, but uses the expansion of ${prefix}
instead of the expansion of ${exec_prefix}.  The latter is new, and is
simply obtained by removing the expansion of ${prefix} from the expansion
of ${exec_prefix}.

Bootstrapped & regression-tested on x86_64-linux-gnu.  Also tested
on i586-wrs-vxworks with --libdir=${prefix}/lib.  OK to install?

Richard


gcc/
	* configure.ac (gcc_gxx_include_dir): Use $(libsubdir_to_prefix).
	(gcc_tooldir): Likewise.
	* configure: Regenerate.
	* Makefile.in (libsubdir_to_prefix): New variable, based on the
	old configure.ac gcc_tooldir setting.
	(prefix_to_exec_prefix): New variable.
	(DRIVER_DEFINES): Use $(libsubdir_to_prefix)$(prefix_to_exec_prefix)
	rather than $(unlibsubdir)/../ to derive TOOLDIR_BASE_PREFIX.

Index: gcc/configure.ac
===================================================================
--- gcc/configure.ac	(revision 124214)
+++ gcc/configure.ac	(working copy)
@@ -142,7 +142,7 @@ if test x${gcc_gxx_include_dir} = x; the
        libstdcxx_incdir="$target_alias/$libstdcxx_incdir"
     fi
 changequote(<<, >>)dnl
-    gcc_gxx_include_dir="\$(libsubdir)/\$(unlibsubdir)/..\`echo \$(exec_prefix) | sed -e 's|^\$(prefix)||' -e 's|/[^/]*|/..|g'\`/$libstdcxx_incdir"
+    gcc_gxx_include_dir="\$(libsubdir)/\$(libsubdir_to_prefix)$libstdcxx_incdir"
 changequote([, ])dnl
   fi
 fi
@@ -3678,42 +3678,7 @@ if test "x$subdirs" != x; then
 fi
 echo "source ${srcdir}/gdbinit.in" >> .gdbinit
 
-# If $(exec_prefix) exists and is not the same as $(prefix), then compute an
-# absolute path for gcc_tooldir based on inserting the number of up-directory
-# movements required to get from $(exec_prefix) to $(prefix) into the basic
-# $(libsubdir)/@(unlibsubdir) based path.
-# Don't set gcc_tooldir to tooldir since that's only passed in by the toplevel
-# make and thus we'd get different behavior depending on where we built the
-# sources.
-if test x$exec_prefix = xNONE -o x$exec_prefix = x$prefix; then
-    gcc_tooldir='$(libsubdir)/$(unlibsubdir)/../$(target_noncanonical)'
-else
-changequote(<<, >>)dnl
-# An explanation of the sed strings:
-#  -e 's|^\$(prefix)||'   matches and eliminates 'prefix' from 'exec_prefix'
-#  -e 's|/$||'            match a trailing forward slash and eliminates it
-#  -e 's|^[^/]|/|'        forces the string to start with a forward slash (*)
-#  -e 's|/[^/]*|../|g'    replaces each occurrence of /<directory> with ../
-#
-# (*) Note this pattern overwrites the first character of the string
-# with a forward slash if one is not already present.  This is not a
-# problem because the exact names of the sub-directories concerned is
-# unimportant, just the number of them matters.
-#
-# The practical upshot of these patterns is like this:
-#
-#  prefix     exec_prefix        result
-#  ------     -----------        ------
-#   /foo        /foo/bar          ../
-#   /foo/       /foo/bar          ../
-#   /foo        /foo/bar/         ../
-#   /foo/       /foo/bar/         ../
-#   /foo        /foo/bar/ugg      ../../
-#
-    dollar='$$'
-    gcc_tooldir="\$(libsubdir)/\$(unlibsubdir)/\`echo \$(exec_prefix) | sed -e 's|^\$(prefix)||' -e 's|/\$(dollar)||' -e 's|^[^/]|/|' -e 's|/[^/]*|../|g'\`\$(target_noncanonical)"
-changequote([, ])dnl
-fi
+gcc_tooldir='$(libsubdir)/$(libsubdir_to_prefix)$(target_noncanonical)'
 AC_SUBST(gcc_tooldir)
 AC_SUBST(dollar)
 
Index: gcc/Makefile.in
===================================================================
--- gcc/Makefile.in	(revision 124214)
+++ gcc/Makefile.in	(working copy)
@@ -461,6 +461,36 @@ libexecdir = @libexecdir@
 libsubdir = $(libdir)/gcc/$(target_noncanonical)/$(version)
 # Directory in which the compiler finds executables
 libexecsubdir = $(libexecdir)/gcc/$(target_noncanonical)/$(version)
+# $(prefix), expressed as a path relative to $(libsubdir).
+#
+# An explanation of the sed strings:
+#  -e 's|^$(prefix)||'   matches and eliminates 'prefix' from 'exec_prefix'
+#  -e 's|/$$||'          match a trailing forward slash and eliminates it
+#  -e 's|^[^/]|/|'       forces the string to start with a forward slash (*)
+#  -e 's|/[^/]*|../|g'   replaces each occurrence of /<directory> with ../
+#
+# (*) Note this pattern overwrites the first character of the string
+# with a forward slash if one is not already present.  This is not a
+# problem because the exact names of the sub-directories concerned is
+# unimportant, just the number of them matters.
+#
+# The practical upshot of these patterns is like this:
+#
+#  prefix     exec_prefix        result
+#  ------     -----------        ------
+#   /foo        /foo/bar          ../
+#   /foo/       /foo/bar          ../
+#   /foo        /foo/bar/         ../
+#   /foo/       /foo/bar/         ../
+#   /foo        /foo/bar/ugg      ../../
+libsubdir_to_prefix = \
+  $(unlibsubdir)/`echo "$(libdir)" | \
+    sed -e 's|^$(prefix)||' -e 's|/$$||' -e 's|^[^/]|/|' \
+        -e 's|/[^/]*|../|g'`
+# $(exec_prefix), expressed as a path relative to $(prefix).
+prefix_to_exec_prefix = \
+  `echo "$(exec_prefix)" | \
+   sed -e 's|^$(prefix)||' -e 's|^/||' -e '/./s|$$|/|'`
 # Used to produce a relative $(gcc_tooldir) in gcc.o
 unlibsubdir = ../../..
 # Directory in which to find other cross-compilation tools and headers.
@@ -1776,7 +1806,7 @@ DRIVER_DEFINES = \
   -DDEFAULT_TARGET_VERSION=\"$(version)\" \
   -DDEFAULT_TARGET_MACHINE=\"$(target_noncanonical)\" \
   -DSTANDARD_BINDIR_PREFIX=\"$(bindir)/\" \
-  -DTOOLDIR_BASE_PREFIX=\"$(unlibsubdir)/../\" \
+  -DTOOLDIR_BASE_PREFIX=\"$(libsubdir_to_prefix)$(prefix_to_exec_prefix)\" \
   @TARGET_SYSTEM_ROOT_DEFINE@ \
   $(VALGRIND_DRIVER_DEFINES) \
   `test "X$${SHLIB_LINK}" = "X" || test "@enable_shared@" != "yes" || echo "-DENABLE_SHARED_LIBGCC"` \


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