Patchwork [google] Add --with-runtime-root-prefix to specify a prefix for the dynamic linker

login
register
mail settings
Submitter Simon Baldwin
Date Jan. 26, 2011, 6:26 p.m.
Message ID <20110126182634.9420C1C6C80@hpgntab-ubiq73.eem.corp.google.com>
Download mbox | patch
Permalink /patch/80538/
State New
Headers show

Comments

Simon Baldwin - Jan. 26, 2011, 6:26 p.m.
Add --with-runtime-root-prefix to specify a prefix for the dynamic linker.

Using --with-runtime-root-prefix allows control over the path to the dynamic
linker for cases where the default needs to be permanently overridden.

Targeted for the google/integration branch.

gcc/ChangeLog.google:
2011-01-26  Simon Baldwin  <simonb@google.com>

	* configure.ac: Add --with-runtime-root-prefix option.
	* configure: Rebuild from configure.ac.
	* Makefile.in: Support --with-runtime-root-prefix.
	* doc/install.texi: Document --with-runtime-root-prefix.
	* gcc/config/linux.h: Add runtime root prefix to dynamic linker path.
	* gcc/config/i386/linux.h: Ditto.
	* gcc/config/i386/linux64.h: Ditto.

Google ref: 38881, 37500, 24189, 12980
Richard Guenther - Jan. 26, 2011, 7:27 p.m.
On Wed, Jan 26, 2011 at 7:26 PM, Simon Baldwin <simonb@google.com> wrote:
> Add --with-runtime-root-prefix to specify a prefix for the dynamic linker.
>
> Using --with-runtime-root-prefix allows control over the path to the dynamic
> linker for cases where the default needs to be permanently overridden.
>
> Targeted for the google/integration branch.

Does this have the same effect as adding a -Wl,-rpath=/path to the linker
line?  If so we have a local patch that allows amending link_spec from
an external file, which would sound more flexible.

Richard.

> gcc/ChangeLog.google:
> 2011-01-26  Simon Baldwin  <simonb@google.com>
>
>        * configure.ac: Add --with-runtime-root-prefix option.
>        * configure: Rebuild from configure.ac.
>        * Makefile.in: Support --with-runtime-root-prefix.
>        * doc/install.texi: Document --with-runtime-root-prefix.
>        * gcc/config/linux.h: Add runtime root prefix to dynamic linker path.
>        * gcc/config/i386/linux.h: Ditto.
>        * gcc/config/i386/linux64.h: Ditto.
>
> Google ref: 38881, 37500, 24189, 12980
>
>
> Index: gcc/doc/install.texi
> ===================================================================
> --- gcc/doc/install.texi        (revision 169295)
> +++ gcc/doc/install.texi        (working copy)
> @@ -874,6 +874,18 @@ ideas of what it is for.  People use it
>  install part of GCC@.  Perhaps they make this assumption because
>  installing GCC creates the directory.
>
> +@item --with-runtime-root-prefix=@var{dirname}
> +Specifies that @var{dirname} is to be used as a prefix before paths
> +to files used at runtime, such as the path to the dynamic linker.
> +For instance, if the dynamic linker is normally @file{/lib/ld.so} and
> +this option is given as:
> +@smallexample
> +--with-runtime-root-prefix=/other
> +@end smallexample
> +then the compiler will cause compiled executables to use
> +@file{/other/lib/ld.so} as their dynamic linker at runtime.  This option
> +is currently only supported by some targets, notably Linux.
> +
>  @item --with-native-system-header-dir=@var{dirname}
>  Specifies that @var{dirname} is the directory that contains native system
>  header files, rather than @file{/usr/include}. This option is most useful
> Index: gcc/configure
> ===================================================================
> --- gcc/configure       (revision 169295)
> +++ gcc/configure       (working copy)
> @@ -759,6 +759,7 @@ CONFIGURE_SPECS
>  CROSS_SYSTEM_HEADER_DIR
>  TARGET_SYSTEM_ROOT_DEFINE
>  TARGET_SYSTEM_ROOT
> +RUNTIME_ROOT_PREFIX_DEFINE
>  NATIVE_SYSTEM_HEADER_DIR
>  enable_shared
>  enable_fixed_point
> @@ -881,6 +882,7 @@ enable_objc_gc
>  with_dwarf2
>  enable_shared
>  with_native_system_header_dir
> +with_runtime_root_prefix
>  with_build_sysroot
>  with_sysroot
>  with_specs
> @@ -1648,6 +1650,10 @@ Optional Packages:
>   --with-native-system-header-dir=dir
>                           use dir as the directory to look for standard
>                           system header files in.  Defaults to /usr/include.
> +  --with-runtime-root-prefix=prefix
> +                          prepend prefix to paths used by the compiler to
> +                          name the dynamic linker and other files used at
> +                          runtime.  Defaults to empty (no prefix).
>   --with-build-sysroot=sysroot
>                           use sysroot as the system root during the build
>   --with-sysroot=DIR Search for usr/lib, usr/include, et al, within DIR.
> @@ -7084,6 +7090,23 @@ NATIVE_SYSTEM_HEADER_DIR=$native_system_
>
>
>
> +# Check whether --with-runtime-root-prefix was given.
> +if test "${with_runtime_root_prefix+set}" = set; then :
> +  withval=$with_runtime_root_prefix;
> + case ${with_runtime_root_prefix} in
> + yes|no) as_fn_error "bad value ${withval} given for runtime root prefix" "$LINENO" 5 ;;
> + /*) ;;
> + *) as_fn_error "${withval} should be an absolute directory" "$LINENO" 5 ;;
> + esac
> + RUNTIME_ROOT_PREFIX_DEFINE="-DRUNTIME_ROOT_PREFIX=\\\"${withval}\\\""
> +
> +else
> +  RUNTIME_ROOT_PREFIX_DEFINE=""
> +fi
> +
> +
> +
> +
>  # Check whether --with-build-sysroot was given.
>  if test "${with_build_sysroot+set}" = set; then :
>   withval=$with_build_sysroot;
> @@ -17539,7 +17562,7 @@ else
>   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
>   lt_status=$lt_dlunknown
>   cat > conftest.$ac_ext <<_LT_EOF
> -#line 17542 "configure"
> +#line 17565 "configure"
>  #include "confdefs.h"
>
>  #if HAVE_DLFCN_H
> @@ -17645,7 +17668,7 @@ else
>   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
>   lt_status=$lt_dlunknown
>   cat > conftest.$ac_ext <<_LT_EOF
> -#line 17648 "configure"
> +#line 17671 "configure"
>  #include "confdefs.h"
>
>  #if HAVE_DLFCN_H
> Index: gcc/configure.ac
> ===================================================================
> --- gcc/configure.ac    (revision 169295)
> +++ gcc/configure.ac    (working copy)
> @@ -726,6 +726,21 @@ AC_ARG_WITH([native-system-header-dir],
>  ], [native_system_header_dir=/usr/include])
>  AC_SUBST(NATIVE_SYSTEM_HEADER_DIR, $native_system_header_dir)
>
> +AC_ARG_WITH([runtime-root-prefix],
> +  [  --with-runtime-root-prefix=prefix
> +                          prepend prefix to paths used by the compiler to
> +                          name the dynamic linker and other files used at
> +                          runtime.  Defaults to empty (no prefix).],
> +[
> + case ${with_runtime_root_prefix} in
> + yes|no) AC_MSG_ERROR([bad value ${withval} given for runtime root prefix]) ;;
> + /*) ;;
> + *) AC_MSG_ERROR([${withval} should be an absolute directory]) ;;
> + esac
> + RUNTIME_ROOT_PREFIX_DEFINE="-DRUNTIME_ROOT_PREFIX=\\\"${withval}\\\""
> +], [RUNTIME_ROOT_PREFIX_DEFINE=""])
> +AC_SUBST(RUNTIME_ROOT_PREFIX_DEFINE)
> +
>  AC_ARG_WITH(build-sysroot,
>   [  --with-build-sysroot=sysroot
>                           use sysroot as the system root during the build])
> Index: gcc/Makefile.in
> ===================================================================
> --- gcc/Makefile.in     (revision 169295)
> +++ gcc/Makefile.in     (working copy)
> @@ -2201,6 +2201,7 @@ DRIVER_DEFINES = \
>   -DDEFAULT_TARGET_MACHINE=\"$(target_noncanonical)\" \
>   -DSTANDARD_BINDIR_PREFIX=\"$(bindir)/\" \
>   -DTOOLDIR_BASE_PREFIX=\"$(libsubdir_to_prefix)$(prefix_to_exec_prefix)\" \
> +  @RUNTIME_ROOT_PREFIX_DEFINE@ \
>   @TARGET_SYSTEM_ROOT_DEFINE@ \
>   $(VALGRIND_DRIVER_DEFINES) \
>   `test "X$${SHLIB_LINK}" = "X" || test "@enable_shared@" != "yes" || echo "-DENABLE_SHARED_LIBGCC"` \
> Index: gcc/config/linux.h
> ===================================================================
> --- gcc/config/linux.h  (revision 169294)
> +++ gcc/config/linux.h  (working copy)
> @@ -74,12 +74,15 @@ see the files COPYING3 and COPYING.RUNTI
>    GLIBC_DYNAMIC_LINKER must be defined for each target using them, or
>    GLIBC_DYNAMIC_LINKER32 and GLIBC_DYNAMIC_LINKER64 for targets
>    supporting both 32-bit and 64-bit compilation.  */
> -#define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
> -#define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0"
> -#define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0"
> -#define BIONIC_DYNAMIC_LINKER "/system/bin/linker"
> -#define BIONIC_DYNAMIC_LINKER32 "/system/bin/linker"
> -#define BIONIC_DYNAMIC_LINKER64 "/system/bin/linker64"
> +#ifndef RUNTIME_ROOT_PREFIX
> +#define RUNTIME_ROOT_PREFIX ""
> +#endif
> +#define UCLIBC_DYNAMIC_LINKER RUNTIME_ROOT_PREFIX "/lib/ld-uClibc.so.0"
> +#define UCLIBC_DYNAMIC_LINKER32 RUNTIME_ROOT_PREFIX "/lib/ld-uClibc.so.0"
> +#define UCLIBC_DYNAMIC_LINKER64 RUNTIME_ROOT_PREFIX "/lib/ld64-uClibc.so.0"
> +#define BIONIC_DYNAMIC_LINKER RUNTIME_ROOT_PREFIX "/system/bin/linker"
> +#define BIONIC_DYNAMIC_LINKER32 RUNTIME_ROOT_PREFIX "/system/bin/linker"
> +#define BIONIC_DYNAMIC_LINKER64 RUNTIME_ROOT_PREFIX "/system/bin/linker64"
>
>  #define LINUX_DYNAMIC_LINKER                                           \
>   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER,  \
> Index: gcc/config/i386/linux.h
> ===================================================================
> --- gcc/config/i386/linux.h     (revision 169294)
> +++ gcc/config/i386/linux.h     (working copy)
> @@ -92,7 +92,10 @@ along with GCC; see the file COPYING3.
>
>  /* These macros may be overridden in k*bsd-gnu.h and i386/k*bsd-gnu.h. */
>  #define LINK_EMULATION "elf_i386"
> -#define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
> +#ifndef RUNTIME_ROOT_PREFIX
> +#define RUNTIME_ROOT_PREFIX ""
> +#endif
> +#define GLIBC_DYNAMIC_LINKER RUNTIME_ROOT_PREFIX "/lib/ld-linux.so.2"
>
>  #undef  ASM_SPEC
>  #define ASM_SPEC \
> Index: gcc/config/i386/linux64.h
> ===================================================================
> --- gcc/config/i386/linux64.h   (revision 169294)
> +++ gcc/config/i386/linux64.h   (working copy)
> @@ -59,8 +59,11 @@ see the files COPYING3 and COPYING.RUNTI
>    When the -shared link option is used a final link is not being
>    done.  */
>
> -#define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
> -#define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
> +#ifndef RUNTIME_ROOT_PREFIX
> +#define RUNTIME_ROOT_PREFIX ""
> +#endif
> +#define GLIBC_DYNAMIC_LINKER32 RUNTIME_ROOT_PREFIX "/lib/ld-linux.so.2"
> +#define GLIBC_DYNAMIC_LINKER64 RUNTIME_ROOT_PREFIX "/lib64/ld-linux-x86-64.so.2"
>
>  #if TARGET_64BIT_DEFAULT
>  #define SPEC_32 "m32"
>
Ollie Wild - Jan. 26, 2011, 7:43 p.m.
On Wed, Jan 26, 2011 at 1:27 PM, Richard Guenther
<richard.guenther@gmail.com> wrote:
>
> Does this have the same effect as adding a -Wl,-rpath=/path to the linker
> line?  If so we have a local patch that allows amending link_spec from
> an external file, which would sound more flexible.

No, this modifies the path to the dynamic linker (the INTERP header in
an ELF executable).  This is independent of any RPATH headers.

Ollie
Diego Novillo - Jan. 26, 2011, 8:28 p.m.
On Wed, Jan 26, 2011 at 13:26, Simon Baldwin <simonb@google.com> wrote:

> 2011-01-26  Simon Baldwin  <simonb@google.com>
>
>        * configure.ac: Add --with-runtime-root-prefix option.
>        * configure: Rebuild from configure.ac.
>        * Makefile.in: Support --with-runtime-root-prefix.
>        * doc/install.texi: Document --with-runtime-root-prefix.
>        * gcc/config/linux.h: Add runtime root prefix to dynamic linker path.
>        * gcc/config/i386/linux.h: Ditto.
>        * gcc/config/i386/linux64.h: Ditto.

OK.


Diego.

Patch

Index: gcc/doc/install.texi
===================================================================
--- gcc/doc/install.texi	(revision 169295)
+++ gcc/doc/install.texi	(working copy)
@@ -874,6 +874,18 @@  ideas of what it is for.  People use it 
 install part of GCC@.  Perhaps they make this assumption because
 installing GCC creates the directory.
 
+@item --with-runtime-root-prefix=@var{dirname}
+Specifies that @var{dirname} is to be used as a prefix before paths
+to files used at runtime, such as the path to the dynamic linker.
+For instance, if the dynamic linker is normally @file{/lib/ld.so} and
+this option is given as:
+@smallexample
+--with-runtime-root-prefix=/other
+@end smallexample
+then the compiler will cause compiled executables to use
+@file{/other/lib/ld.so} as their dynamic linker at runtime.  This option
+is currently only supported by some targets, notably Linux.
+
 @item --with-native-system-header-dir=@var{dirname}
 Specifies that @var{dirname} is the directory that contains native system
 header files, rather than @file{/usr/include}. This option is most useful
Index: gcc/configure
===================================================================
--- gcc/configure	(revision 169295)
+++ gcc/configure	(working copy)
@@ -759,6 +759,7 @@  CONFIGURE_SPECS
 CROSS_SYSTEM_HEADER_DIR
 TARGET_SYSTEM_ROOT_DEFINE
 TARGET_SYSTEM_ROOT
+RUNTIME_ROOT_PREFIX_DEFINE
 NATIVE_SYSTEM_HEADER_DIR
 enable_shared
 enable_fixed_point
@@ -881,6 +882,7 @@  enable_objc_gc
 with_dwarf2
 enable_shared
 with_native_system_header_dir
+with_runtime_root_prefix
 with_build_sysroot
 with_sysroot
 with_specs
@@ -1648,6 +1650,10 @@  Optional Packages:
   --with-native-system-header-dir=dir
                           use dir as the directory to look for standard
                           system header files in.  Defaults to /usr/include.
+  --with-runtime-root-prefix=prefix
+                          prepend prefix to paths used by the compiler to
+                          name the dynamic linker and other files used at
+                          runtime.  Defaults to empty (no prefix).
   --with-build-sysroot=sysroot
                           use sysroot as the system root during the build
   --with-sysroot=DIR Search for usr/lib, usr/include, et al, within DIR.
@@ -7084,6 +7090,23 @@  NATIVE_SYSTEM_HEADER_DIR=$native_system_
 
 
 
+# Check whether --with-runtime-root-prefix was given.
+if test "${with_runtime_root_prefix+set}" = set; then :
+  withval=$with_runtime_root_prefix;
+ case ${with_runtime_root_prefix} in
+ yes|no) as_fn_error "bad value ${withval} given for runtime root prefix" "$LINENO" 5 ;;
+ /*) ;;
+ *) as_fn_error "${withval} should be an absolute directory" "$LINENO" 5 ;;
+ esac
+ RUNTIME_ROOT_PREFIX_DEFINE="-DRUNTIME_ROOT_PREFIX=\\\"${withval}\\\""
+
+else
+  RUNTIME_ROOT_PREFIX_DEFINE=""
+fi
+
+
+
+
 # Check whether --with-build-sysroot was given.
 if test "${with_build_sysroot+set}" = set; then :
   withval=$with_build_sysroot;
@@ -17539,7 +17562,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 17542 "configure"
+#line 17565 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -17645,7 +17668,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 17648 "configure"
+#line 17671 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
Index: gcc/configure.ac
===================================================================
--- gcc/configure.ac	(revision 169295)
+++ gcc/configure.ac	(working copy)
@@ -726,6 +726,21 @@  AC_ARG_WITH([native-system-header-dir],
 ], [native_system_header_dir=/usr/include])
 AC_SUBST(NATIVE_SYSTEM_HEADER_DIR, $native_system_header_dir)
 
+AC_ARG_WITH([runtime-root-prefix],
+  [  --with-runtime-root-prefix=prefix
+                          prepend prefix to paths used by the compiler to
+                          name the dynamic linker and other files used at
+                          runtime.  Defaults to empty (no prefix).],
+[
+ case ${with_runtime_root_prefix} in
+ yes|no) AC_MSG_ERROR([bad value ${withval} given for runtime root prefix]) ;;
+ /*) ;;
+ *) AC_MSG_ERROR([${withval} should be an absolute directory]) ;;
+ esac
+ RUNTIME_ROOT_PREFIX_DEFINE="-DRUNTIME_ROOT_PREFIX=\\\"${withval}\\\""
+], [RUNTIME_ROOT_PREFIX_DEFINE=""])
+AC_SUBST(RUNTIME_ROOT_PREFIX_DEFINE)
+
 AC_ARG_WITH(build-sysroot, 
   [  --with-build-sysroot=sysroot
                           use sysroot as the system root during the build])
Index: gcc/Makefile.in
===================================================================
--- gcc/Makefile.in	(revision 169295)
+++ gcc/Makefile.in	(working copy)
@@ -2201,6 +2201,7 @@  DRIVER_DEFINES = \
   -DDEFAULT_TARGET_MACHINE=\"$(target_noncanonical)\" \
   -DSTANDARD_BINDIR_PREFIX=\"$(bindir)/\" \
   -DTOOLDIR_BASE_PREFIX=\"$(libsubdir_to_prefix)$(prefix_to_exec_prefix)\" \
+  @RUNTIME_ROOT_PREFIX_DEFINE@ \
   @TARGET_SYSTEM_ROOT_DEFINE@ \
   $(VALGRIND_DRIVER_DEFINES) \
   `test "X$${SHLIB_LINK}" = "X" || test "@enable_shared@" != "yes" || echo "-DENABLE_SHARED_LIBGCC"` \
Index: gcc/config/linux.h
===================================================================
--- gcc/config/linux.h	(revision 169294)
+++ gcc/config/linux.h	(working copy)
@@ -74,12 +74,15 @@  see the files COPYING3 and COPYING.RUNTI
    GLIBC_DYNAMIC_LINKER must be defined for each target using them, or
    GLIBC_DYNAMIC_LINKER32 and GLIBC_DYNAMIC_LINKER64 for targets
    supporting both 32-bit and 64-bit compilation.  */
-#define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
-#define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0"
-#define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0"
-#define BIONIC_DYNAMIC_LINKER "/system/bin/linker"
-#define BIONIC_DYNAMIC_LINKER32 "/system/bin/linker"
-#define BIONIC_DYNAMIC_LINKER64 "/system/bin/linker64"
+#ifndef RUNTIME_ROOT_PREFIX
+#define RUNTIME_ROOT_PREFIX ""
+#endif
+#define UCLIBC_DYNAMIC_LINKER RUNTIME_ROOT_PREFIX "/lib/ld-uClibc.so.0"
+#define UCLIBC_DYNAMIC_LINKER32 RUNTIME_ROOT_PREFIX "/lib/ld-uClibc.so.0"
+#define UCLIBC_DYNAMIC_LINKER64 RUNTIME_ROOT_PREFIX "/lib/ld64-uClibc.so.0"
+#define BIONIC_DYNAMIC_LINKER RUNTIME_ROOT_PREFIX "/system/bin/linker"
+#define BIONIC_DYNAMIC_LINKER32 RUNTIME_ROOT_PREFIX "/system/bin/linker"
+#define BIONIC_DYNAMIC_LINKER64 RUNTIME_ROOT_PREFIX "/system/bin/linker64"
 
 #define LINUX_DYNAMIC_LINKER						\
   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER,	\
Index: gcc/config/i386/linux.h
===================================================================
--- gcc/config/i386/linux.h	(revision 169294)
+++ gcc/config/i386/linux.h	(working copy)
@@ -92,7 +92,10 @@  along with GCC; see the file COPYING3.  
 
 /* These macros may be overridden in k*bsd-gnu.h and i386/k*bsd-gnu.h. */
 #define LINK_EMULATION "elf_i386"
-#define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
+#ifndef RUNTIME_ROOT_PREFIX
+#define RUNTIME_ROOT_PREFIX ""
+#endif
+#define GLIBC_DYNAMIC_LINKER RUNTIME_ROOT_PREFIX "/lib/ld-linux.so.2"
 
 #undef  ASM_SPEC
 #define ASM_SPEC \
Index: gcc/config/i386/linux64.h
===================================================================
--- gcc/config/i386/linux64.h	(revision 169294)
+++ gcc/config/i386/linux64.h	(working copy)
@@ -59,8 +59,11 @@  see the files COPYING3 and COPYING.RUNTI
    When the -shared link option is used a final link is not being
    done.  */
 
-#define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
-#define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
+#ifndef RUNTIME_ROOT_PREFIX
+#define RUNTIME_ROOT_PREFIX ""
+#endif
+#define GLIBC_DYNAMIC_LINKER32 RUNTIME_ROOT_PREFIX "/lib/ld-linux.so.2"
+#define GLIBC_DYNAMIC_LINKER64 RUNTIME_ROOT_PREFIX "/lib64/ld-linux-x86-64.so.2"
 
 #if TARGET_64BIT_DEFAULT
 #define SPEC_32 "m32"