Index: gcc/doc/install.texi =================================================================== --- gcc/doc/install.texi (revision 193063) +++ gcc/doc/install.texi (working copy) @@ -762,6 +762,44 @@ from the full GCC manuals, which are pro are derived by an automatic conversion process from parts of the full manual.) +@item --with-extra-prefix=@var{prefix} +Specify an additional prefix for finding executables, libraries, and +startfiles when the compiler is run. By default no extra +prefixes are used. This option sets the options +@option{--with-extra-exec-prefix=}, +@option{--with-extra-startfiles-prefix=}, +and @option{--with-extra-rpath-prefix=} if they are not specified. + +@item --with-extra-exec-prefix=@var{prefixes} +Specify additional prefixes for finding executables when the compiler +is run. Each prefix is separated by the standard path sepator +(usually colon, @option{:}). By default no extra prefixes are used. + +@item --with-extra-startfile-prefix=@var{prefixes} +Specify additional prefixes for finding libraries, and startfiles when +the compiler is run. Each prefix is separated by the standard path +sepator (usually colon, @option{:}). By default no extra prefixes are +used. + +On powerpc64-linux systems, the dynamic linker will be searched for in +the directories specified by the prefixed, that is used instead of the +standard system dynamic linker. + +In addition on powerpc64-linux systems, if the user used static +linking, as well as the @option{-mcpu=} option, the linker will be +told to search in appropriate directories for libraries that are built +for that particular machine. If dynamic linking is used, these cpu +tuned libraries will not be searched, since the dynamic linker will +load the appropriate cpu tuned library, based on the system that is +executing the code. + +@item --with-extra-rpath-prefix=@var{prefixes} +Specify additional directories for finding shared libraries when +the compiler is run. Each prefix is separated by the standard path +sepator (usually colon, @option{:}). By default no extra prefixes are +used. If this option is used, each of the directories if they exist +will be specified to the linker via the @option{-rpath=} option. + @item --with-gxx-include-dir=@var{dirname} Specify the installation directory for G++ header files. The default depends Index: gcc/configure =================================================================== --- gcc/configure (revision 193063) +++ gcc/configure (working copy) @@ -893,6 +893,10 @@ with_multilib_list enable_rpath with_libiconv_prefix enable_sjlj_exceptions +with_extra_prefix +with_extra_exec_prefix +with_extra_startfile_prefix +with_extra_rpath_prefix enable_secureplt enable_leading_mingw64_underscores enable_cld @@ -1659,6 +1663,18 @@ Optional Packages: --with-gnu-ld assume the C compiler uses GNU ld default=no --with-libiconv-prefix[=DIR] search for libiconv in DIR/include and DIR/lib --without-libiconv-prefix don't search for libiconv in includedir and libdir + --with-extra-prefix={prefixes} + Add extra prefixes to the list of locations to + search for all files + --with-extra-exec-prefix={prefixes} + Add extra prefixes to the list of locations to + search for executables + --with-extra-startfile-prefix={prefix} + Add extra prefixes to the list of locations to + search for startfiles + --with-extra-rpath-prefix={prefixes} + Specify prefixes to pass to the linker via + -rpath=dir to locate shared libraries --with-pic try to use only PIC/non-PIC objects [default=use both] --with-gnu-ld assume the C compiler uses GNU ld [default=no] @@ -11322,6 +11338,78 @@ case "$LIBINTL" in *$LIBICONV*) LIBICONV= ;; esac + +# Check whether --with-extra-prefix was given. +if test "${with_extra_prefix+set}" = set; then : + withval=$with_extra_prefix; EXTRA_PREFIX="$withval" +else + EXTRA_PREFIX='' +fi + + + +# Check whether --with-extra-exec-prefix was given. +if test "${with_extra_exec_prefix+set}" = set; then : + withval=$with_extra_exec_prefix; EXTRA_EXEC_PREFIX="$withval" +else + if test x"${EXTRA_PREFIX}" != x; then + EXTRA_EXEC_PREFIX="`echo ${EXTRA_PREFIX} | sed 's/:/\\/bin:/g'`/bin" + else + EXTRA_EXEC_PREFIX="" + fi +fi + + +if test x"${EXTRA_EXEC_PREFIX}" != x; then + +cat >>confdefs.h <<_ACEOF +#define CONFIGURE_EXEC_PREFIX "$EXTRA_EXEC_PREFIX" +_ACEOF + +fi + + +# Check whether --with-extra-startfile-prefix was given. +if test "${with_extra_startfile_prefix+set}" = set; then : + withval=$with_extra_startfile_prefix; EXTRA_STARTFILE_PREFIX="$withval" +else + if test x"${EXTRA_PREFIX}" != x; then + EXTRA_STARTFILE_PREFIX="`echo ${EXTRA_PREFIX} | sed 's/:/\\/lib:/g'`/lib" + else + EXTRA_STARTFILE_PREFIX="" + fi +fi + + +if test x"${EXTRA_STARTFILE_PREFIX}" != x; then + +cat >>confdefs.h <<_ACEOF +#define CONFIGURE_STARTFILE_PREFIX "$EXTRA_STARTFILE_PREFIX" +_ACEOF + +fi + + +# Check whether --with-extra-rpath-prefix was given. +if test "${with_extra_rpath_prefix+set}" = set; then : + withval=$with_extra_rpath_prefix; EXTRA_RPATH_PREFIX="$withval" +else + if test x"${EXTRA_PREFIX}" != x; then + EXTRA_RPATH_PREFIX="${prefix}/lib:`echo ${EXTRA_PREFIX} | sed 's/:/\\/lib:/g'`/lib" + else + EXTRA_RPATH_PREFIX="" + fi +fi + + +if test x"${EXTRA_RPATH_PREFIX}" != x; then + +cat >>confdefs.h <<_ACEOF +#define CONFIGURE_RPATH_PREFIX "$EXTRA_RPATH_PREFIX" +_ACEOF + +fi + # Check whether --enable-secureplt was given. if test "${enable_secureplt+set}" = set; then : enableval=$enable_secureplt; Index: gcc/gcc.c =================================================================== --- gcc/gcc.c (revision 193063) +++ gcc/gcc.c (working copy) @@ -202,6 +202,8 @@ static int access_check (const char *, i static char *find_a_file (const struct path_prefix *, const char *, int, bool); static void add_prefix (struct path_prefix *, const char *, const char *, int, int, int); +static void add_multiple_prefix (struct path_prefix *, const char *, + const char *, int, int, int); static void add_sysrooted_prefix (struct path_prefix *, const char *, const char *, int, int, int); static char *skip_whitespace (char *); @@ -261,12 +263,15 @@ static const char *remove_outfile_spec_f static const char *version_compare_spec_function (int, const char **); static const char *include_spec_function (int, const char **); static const char *find_file_spec_function (int, const char **); +static const char *find_dynamic_linker_spec_function (int, const char **); static const char *find_plugindir_spec_function (int, const char **); static const char *print_asm_header_spec_function (int, const char **); static const char *compare_debug_dump_opt_spec_function (int, const char **); static const char *compare_debug_self_opt_spec_function (int, const char **); static const char *compare_debug_auxbase_opt_spec_function (int, const char **); static const char *pass_through_libs_spec_func (int, const char **); +static const char *extra_rpath_dirs_spec_function (int, const char **); +const char *extra_cpu_dirs_spec_function (int, const char **); /* The Specs Language @@ -656,6 +661,16 @@ proper position among the other output f #endif +#ifndef LINK_RPATH_DIRS_SPEC +#ifdef CONFIGURE_RPATH_PREFIX +/* Add extra -rpath= options if configured. */ +#define LINK_RPATH_DIRS_SPEC \ + "%{!nostdlib:%{!nodefaultlibs:%{!static: %:extra-rpath-dirs()}}}" +#else +#define LINK_RPATH_DIRS_SPEC +#endif +#endif + /* -u* was put back because both BSD and SysV seem to support it. */ /* %{static:} simply prevents an error message if the target machine doesn't handle -static. */ @@ -669,6 +684,7 @@ proper position among the other output f #define LINK_COMMAND_SPEC "\ %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\ %(linker) " \ + LINK_RPATH_DIRS_SPEC \ LINK_PLUGIN_SPEC \ "%{flto|flto=*:% option. `dir' is found through find_file, that is the -print-file-name gcc program option. */ @@ -8380,3 +8379,208 @@ pass_through_libs_spec_func (int argc, c } return prepended; } + +#define IS_STD_DIR(PATH,STD) (strncmp (PATH, STD, sizeof (STD)-1) == 0) + +#ifdef CONFIGURE_RPATH_PREFIX + +static const char config_rpath[] = CONFIGURE_RPATH_PREFIX; + +/* Common code for extra_rpath_dirs_spec_function and + extra_cpu_dirs_spec_function to build up a list of -rpath= or -L + options, based on the extra rpath directories that were configured in. */ + +static char * +build_rpath_or_cpu_dirs (const char *rpath_dirs, + const char *prefix, + const char *subdir) +{ + char *ret = NULL; + char *tmpstr, *endp, *prev_dir; + size_t rpath_len = strlen (rpath_dirs); + size_t subdir_len = (subdir) ? strlen (subdir) : 0; + size_t mlib_len = (multilib_os_dir) ? strlen (multilib_os_dir) : 0; + bool mlib_updir; + size_t i; + + mlib_updir = (DIR_SEPARATOR == '/' + && mlib_len > sizeof ("../") - 1 + && multilib_os_dir[0] == '.' + && multilib_os_dir[1] == '.' + && multilib_os_dir[2] == '/'); + + endp = tmpstr = XALLOCAVEC (char, rpath_len + subdir_len + mlib_len + 4); + prev_dir = NULL; + for (i = 0; i <= rpath_len; i++) + { + int ch = rpath_dirs[i]; + if (ch != PATH_SEPARATOR && ch != '\0') + { + *endp++ = ch; + if (ch == DIR_SEPARATOR) + prev_dir = endp; + } + else if (endp > tmpstr) + { + /* Add current multlib directory. Convert /lib/../lib64 into + /lib64. */ + if (mlib_len > 0) + { + if (mlib_updir && prev_dir) + { + memcpy (prev_dir, multilib_os_dir + 3, mlib_len - 3); + endp = prev_dir + mlib_len - 3; + } + else + { + *endp = DIR_SEPARATOR; + memcpy (endp+1, multilib_os_dir, mlib_len); + endp += mlib_len + 1; + } + } + + /* Look for machine specific subdir? */ + if (subdir) + { + *endp = DIR_SEPARATOR; + memcpy (endp+1, subdir, subdir_len); + endp += subdir_len + 1; + } + + endp[0] = DIR_SEPARATOR; + endp[1] = '.'; + endp[2] = '\0'; + + if (is_directory (tmpstr, false)) + { + *endp = '\0'; + if (ret) + ret = reconcat (ret, ret, " ", prefix, tmpstr, NULL); + else + ret = concat (prefix, tmpstr, NULL); + } + + endp = tmpstr; + } + } + + return ret; +} + +/* %:extra-rpath-dirs spec function. If we have alternate rpath directories + (install lib directory + alternate startfile prefix directories), build a + string with all of the directories that are found with appropriate -rpath + options for the linker. If the LD_RUN_PATH environment variable is + specified, include this into the -rpath arguments, since LD_RUN_PATH is + only used if -rpath is not specified. */ + +static const char * +extra_rpath_dirs_spec_function (int argc, const char **argv ATTRIBUTE_UNUSED) +{ + static const char path_sep[2] = { PATH_SEPARATOR, '\0' }; + const char *ld_run_path = getenv ("LD_RUN_PATH"); + const char *ret; + + if (argc != 0) + abort (); + + if (ld_run_path) + { + char *new_rpath = concat (config_rpath, path_sep, ld_run_path, NULL); + ret = build_rpath_or_cpu_dirs (new_rpath, "-rpath=", NULL); + free (new_rpath); + } + else + ret = build_rpath_or_cpu_dirs (config_rpath, "-rpath=", NULL); + + return ret; +} + +/* %:extra-cpu-dirs spec function. If we have alternate rpath directories, + search them to see if there are subdirectories that hold the static + libraries built for a particular machines, and return appropriate -L + to those directories. */ + +const char * +extra_cpu_dirs_spec_function (int argc, const char **argv) +{ + if (argc != 1) + abort (); + + return build_rpath_or_cpu_dirs (config_rpath, "-L", argv[0]); +} + +/* %:find-dynamic-linker spec function. Find the dynamic linker if we have + extra search paths configured. */ + +static const char * +find_dynamic_linker_spec_function (int argc, const char **argv) +{ + const char *file; + char *tmpstr; + char *endp; + char *prev_dir; + size_t len; + size_t i; + int ch; + + if (argc < 1) + abort (); + + file = argv[0]; + len = strlen (file); + gcc_assert (file[0] == DIR_SEPARATOR); + + endp = tmpstr = XALLOCAVEC (char, ARRAY_SIZE (config_rpath) + len + 1); + prev_dir = NULL; + for (i = 0; i <= ARRAY_SIZE (config_rpath); i++) + { + ch = config_rpath[i]; + if (ch != PATH_SEPARATOR && ch != '\0') + { + if (ch == DIR_SEPARATOR) + prev_dir = endp; + + *endp++ = ch; + } + else if (endp > tmpstr) + { + *endp = '\0'; + if (prev_dir && strncmp (prev_dir, "/lib", sizeof ("/lib")-1) == 0) + endp = prev_dir; + memcpy (endp, file, len); + endp[len] = '\0'; + if (access (tmpstr, X_OK) == 0) + return xstrdup (tmpstr); + + endp = tmpstr; + } + } + + return xstrdup (file); +} + +#else +const char * +extra_rpath_dirs_spec_function (int argc ATTRIBUTE_UNUSED, + const char **argv ATTRIBUTE_UNUSED) +{ + return NULL; +} + +const char * +extra_cpu_dirs_spec_function (int argc ATTRIBUTE_UNUSED, + const char **argv ATTRIBUTE_UNUSED) +{ + return NULL; +} + +static const char * +find_dynamic_linker_spec_function (int argc, const char **argv) +{ + if (argc != 1) + abort (); + + return xstrdup (argv[0]); +} +#endif Index: gcc/gcc.h =================================================================== --- gcc/gcc.h (revision 193063) +++ gcc/gcc.h (working copy) @@ -37,6 +37,7 @@ extern int do_spec (const char *); extern void record_temp_file (const char *, int, int); extern void pfatal_with_name (const char *) ATTRIBUTE_NORETURN; extern void set_input (const char *); +extern const char *extra_cpu_dirs_spec_function (int, const char **); /* Spec files linked with gcc.c must provide definitions for these. */ Index: gcc/config.in =================================================================== --- gcc/config.in (revision 193063) +++ gcc/config.in (working copy) @@ -2035,3 +2035,20 @@ #undef vfork #endif + +/* Define extra executable prefixes at configure time. */ +#ifndef USED_FOR_TARGET +#undef CONFIGURE_EXEC_PREFIX +#endif + + +/* Define extra startfile prefixes at configure time. */ +#ifndef USED_FOR_TARGET +#undef CONFIGURE_STARTFILE_PREFIX +#endif + + +/* Define extra rpath prefixes at configure time. */ +#ifndef USED_FOR_TARGET +#undef CONFIGURE_RPATH_PREFIX +#endif Index: gcc/configure.ac =================================================================== --- gcc/configure.ac (revision 193063) +++ gcc/configure.ac (working copy) @@ -1584,6 +1584,57 @@ case "$LIBINTL" in *$LIBICONV*) LIBICONV= ;; esac +AC_ARG_WITH([extra-prefix], +[AC_HELP_STRING([--with-extra-prefix={prefixes}], + [Add extra prefixes to the list of locations to search for all files])], + [EXTRA_PREFIX="$withval"], + [EXTRA_PREFIX='']) + +AC_ARG_WITH([extra-exec-prefix], +[AC_HELP_STRING([--with-extra-exec-prefix={prefixes}], + [Add extra prefixes to the list of locations to search for executables])], + [EXTRA_EXEC_PREFIX="$withval"], + [if test x"${EXTRA_PREFIX}" != x; then + EXTRA_EXEC_PREFIX="`echo ${EXTRA_PREFIX} | sed 's/:/\\/bin:/g'`/bin" + else + EXTRA_EXEC_PREFIX="" + fi]) + +if test x"${EXTRA_EXEC_PREFIX}" != x; then + AC_DEFINE_UNQUOTED(CONFIGURE_EXEC_PREFIX, "$EXTRA_EXEC_PREFIX", + [Extra executable prefixes]) +fi + +AC_ARG_WITH([extra-startfile-prefix], +[AC_HELP_STRING([--with-extra-startfile-prefix={prefix}], + [Add extra prefixes to the list of locations to search for startfiles])], + [EXTRA_STARTFILE_PREFIX="$withval"], + [if test x"${EXTRA_PREFIX}" != x; then + EXTRA_STARTFILE_PREFIX="`echo ${EXTRA_PREFIX} | sed 's/:/\\/lib:/g'`/lib" + else + EXTRA_STARTFILE_PREFIX="" + fi]) + +if test x"${EXTRA_STARTFILE_PREFIX}" != x; then + AC_DEFINE_UNQUOTED(CONFIGURE_STARTFILE_PREFIX, "$EXTRA_STARTFILE_PREFIX", + [Extra startfile prefix]) +fi + +AC_ARG_WITH([extra-rpath-prefix], +[AC_HELP_STRING([--with-extra-rpath-prefix={prefixes}], + [Specify prefixes to pass to the linker via -rpath=dir to locate shared libraries])], + [EXTRA_RPATH_PREFIX="$withval"], + [if test x"${EXTRA_PREFIX}" != x; then + EXTRA_RPATH_PREFIX="${prefix}/lib:`echo ${EXTRA_PREFIX} | sed 's/:/\\/lib:/g'`/lib" + else + EXTRA_RPATH_PREFIX="" + fi]) + +if test x"${EXTRA_RPATH_PREFIX}" != x; then + AC_DEFINE_UNQUOTED(CONFIGURE_RPATH_PREFIX, "$EXTRA_RPATH_PREFIX", + [Extra rpath prefix]) +fi + AC_ARG_ENABLE(secureplt, [AS_HELP_STRING([--enable-secureplt], [enable -msecure-plt by default for PowerPC])],