From 38934e7b6b3467758cb9a3a436f1c181a4a03bb8 Mon Sep 17 00:00:00 2001 From: ian Date: Thu, 3 Nov 2011 04:32:00 +0000 Subject: [PATCH] * configure.ac: Add --with-lib-path option. Define LIB_PATH and NATIVE_LINKER. * Makefile.am (AM_CPPFLAGS): Define TOOLLIBDIR. * options.cc (General_options::finalize): Use library search path from configure script if specified. If not native and no sysroot, only search TOOLLIBDIR. * options.h (Search_directory::Search_directory): Change name to const std::string&. (General_options::add_to_library_path_with_sysroot): Change arg to const std::string&. * configure, Makefile.in, config.in: Rebuild. --- gold/ChangeLog | 14 ++++++++++++++ gold/Makefile.am | 2 +- gold/Makefile.in | 2 +- gold/config.in | 6 ++++++ gold/configure | 25 +++++++++++++++++++++++++ gold/configure.ac | 14 ++++++++++++++ gold/options.cc | 39 +++++++++++++++++++++++++++------------ gold/options.h | 4 ++-- 8 files changed, 90 insertions(+), 16 deletions(-) diff --git a/gold/ChangeLog b/gold/ChangeLog index eb87996d1f..aac3aa0f49 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,17 @@ +2011-11-02 Ian Lance Taylor + + * configure.ac: Add --with-lib-path option. Define LIB_PATH and + NATIVE_LINKER. + * Makefile.am (AM_CPPFLAGS): Define TOOLLIBDIR. + * options.cc (General_options::finalize): Use library search path + from configure script if specified. If not native and no sysroot, + only search TOOLLIBDIR. + * options.h (Search_directory::Search_directory): Change name to + const std::string&. + (General_options::add_to_library_path_with_sysroot): Change arg to + const std::string&. + * configure, Makefile.in, config.in: Rebuild. + 2011-11-02 Matthew Gretton-Dann * arm.cc (Target_arm::may_use_v5t_interworking): Check whether diff --git a/gold/Makefile.am b/gold/Makefile.am index c1c3588ef0..d121ac444c 100644 --- a/gold/Makefile.am +++ b/gold/Makefile.am @@ -15,7 +15,7 @@ AM_CPPFLAGS = \ -I$(srcdir) -I$(srcdir)/../include -I$(srcdir)/../elfcpp \ -DLOCALEDIR="\"$(datadir)/locale\"" \ -DBINDIR="\"$(bindir)\"" -DTOOLBINDIR="\"$(tooldir)/bin\"" \ - @INCINTL@ + -DTOOLLIBDIR="\"$(tooldir)/lib\"" @INCINTL@ LIBIBERTY = ../libiberty/libiberty.a diff --git a/gold/Makefile.in b/gold/Makefile.in index ff6d7c281c..0fa739ad3f 100644 --- a/gold/Makefile.in +++ b/gold/Makefile.in @@ -369,7 +369,7 @@ AM_CPPFLAGS = \ -I$(srcdir) -I$(srcdir)/../include -I$(srcdir)/../elfcpp \ -DLOCALEDIR="\"$(datadir)/locale\"" \ -DBINDIR="\"$(bindir)\"" -DTOOLBINDIR="\"$(tooldir)/bin\"" \ - @INCINTL@ + -DTOOLLIBDIR="\"$(tooldir)/lib\"" @INCINTL@ LIBIBERTY = ../libiberty/libiberty.a @PLUGINS_TRUE@LIBDL = -ldl diff --git a/gold/config.in b/gold/config.in index 86113763d9..2854620ec9 100644 --- a/gold/config.in +++ b/gold/config.in @@ -165,6 +165,12 @@ /* Define to 1 if you have the header file. */ #undef HAVE_ZLIB_H +/* Default library search path */ +#undef LIB_PATH + +/* Whether configured as a native linker */ +#undef NATIVE_LINKER + /* Name of package */ #undef PACKAGE diff --git a/gold/configure b/gold/configure index 708f540a23..3dddec67c2 100755 --- a/gold/configure +++ b/gold/configure @@ -775,6 +775,7 @@ enable_gold enable_threads enable_plugins enable_targets +with_lib_path enable_dependency_tracking enable_nls enable_werror @@ -1435,6 +1436,7 @@ Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-sysroot=DIR search for usr/lib et al within DIR + --with-lib-path=dir1:dir2... set default LIB_PATH --with-gold-ldflags=FLAGS additional link flags for gold --with-gold-ldadd=LIBS additional libraries for gold @@ -3535,6 +3537,29 @@ cat >>confdefs.h <<_ACEOF _ACEOF + +# Check whether --with-lib-path was given. +if test "${with_lib_path+set}" = set; then : + withval=$with_lib_path; case "$withval" in + yes) LIB_PATH='"/lib:/usr/lib"' ;; + no) LIB_PATH='""' ;; + *) LIB_PATH='"'"$withval"'"' ;; + esac +else + LIB_PATH='"::DEFAULT::"' +fi + + +cat >>confdefs.h <<_ACEOF +#define LIB_PATH $LIB_PATH +_ACEOF + +if test "x$target_alias" = "x" -o "x$host_alias" = "x$target_alias"; then + +$as_echo "#define NATIVE_LINKER 1" >>confdefs.h + +fi + if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}nm", so it can be a program name with args. set dummy ${ac_tool_prefix}nm; ac_word=$2 diff --git a/gold/configure.ac b/gold/configure.ac index 905dbaf1c7..1b46f4a852 100644 --- a/gold/configure.ac +++ b/gold/configure.ac @@ -238,6 +238,20 @@ AC_DEFINE_UNQUOTED(GOLD_DEFAULT_BIG_ENDIAN, $default_big_endian, AC_DEFINE_UNQUOTED(GOLD_DEFAULT_OSABI, $default_osabi, [Default OSABI code]) +AC_ARG_WITH(lib-path, +[ --with-lib-path=dir1:dir2... set default LIB_PATH], +[case "$withval" in + yes) LIB_PATH='"/lib:/usr/lib"' ;; + no) LIB_PATH='""' ;; + *) LIB_PATH='"'"$withval"'"' ;; + esac], +[LIB_PATH='"::DEFAULT::"']) +AC_DEFINE_UNQUOTED(LIB_PATH, $LIB_PATH, + [Default library search path]) +if test "x$target_alias" = "x" -o "x$host_alias" = "x$target_alias"; then + AC_DEFINE(NATIVE_LINKER, 1, [Whether configured as a native linker]) +fi + AC_CHECK_TOOL(NM, nm) AC_PROG_CC diff --git a/gold/options.cc b/gold/options.cc index dcf6ba71ac..64a8539d2f 100644 --- a/gold/options.cc +++ b/gold/options.cc @@ -1121,33 +1121,48 @@ General_options::finalize() program_name); #endif + std::string libpath; if (this->user_set_Y()) { - std::string s = this->Y(); - if (s.compare(0, 2, "P,") == 0) - s.erase(0, 2); + libpath = this->Y(); + if (libpath.compare(0, 2, "P,") == 0) + libpath.erase(0, 2); + } + else if (!this->nostdlib()) + { +#ifndef NATIVE_LINKER +#define NATIVE_LINKER 0 +#endif + const char* p = LIB_PATH; + if (strcmp(p, "::DEFAULT::") != 0) + libpath = p; + else if (NATIVE_LINKER + || this->user_set_sysroot() + || *TARGET_SYSTEM_ROOT != '\0') + { + this->add_to_library_path_with_sysroot("/lib"); + this->add_to_library_path_with_sysroot("/usr/lib"); + } + else + this->add_to_library_path_with_sysroot(TOOLLIBDIR); + } + if (!libpath.empty()) + { size_t pos = 0; size_t next_pos; do { - next_pos = s.find(':', pos); + next_pos = libpath.find(':', pos); size_t len = (next_pos == std::string::npos ? next_pos : next_pos - pos); if (len != 0) - this->add_to_library_path_with_sysroot(s.substr(pos, len).c_str()); + this->add_to_library_path_with_sysroot(libpath.substr(pos, len)); pos = next_pos + 1; } while (next_pos != std::string::npos); } - else if (!this->nostdlib()) - { - // Even if they don't specify it, we add -L /lib and -L /usr/lib. - // FIXME: We should only do this when configured in native mode. - this->add_to_library_path_with_sysroot("/lib"); - this->add_to_library_path_with_sysroot("/usr/lib"); - } // Parse the contents of -retain-symbols-file into a set. if (this->retain_symbols_file()) diff --git a/gold/options.h b/gold/options.h index 8876a1eedd..534df26623 100644 --- a/gold/options.h +++ b/gold/options.h @@ -543,7 +543,7 @@ class Search_directory { } // This is the usual constructor. - Search_directory(const char* name, bool put_in_sysroot) + Search_directory(const std::string& name, bool put_in_sysroot) : name_(name), put_in_sysroot_(put_in_sysroot), is_in_sysroot_(false) { if (this->name_.empty()) @@ -1463,7 +1463,7 @@ class General_options // These are called by finalize() to set up the search-path correctly. void - add_to_library_path_with_sysroot(const char* arg) + add_to_library_path_with_sysroot(const std::string& arg) { this->add_search_directory_to_library_path(Search_directory(arg, true)); } // Apply any sysroot to the directory lists. -- 2.11.0