This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] Add configure flag to enable gnu hash style by default.
- From: Romain Geissler <romain dot geissler at gmail dot com>
- To: binutils at sourceware dot org
- Cc: Romain Geissler <romain dot geissler at gmail dot com>
- Date: Wed, 12 Jul 2017 21:50:07 +0000
- Subject: [PATCH] Add configure flag to enable gnu hash style by default.
- Authentication-results: sourceware.org; auth=none
Hi,
This small patch adds a new --with-default-hash-style={sysv|gnu|both} configure option
and switches the default hash-style to "gnu" rather than "sysv" for the ELF linker. glibc
has support for GNU hash style for a long time.
Tested without regression on x86-64 for the ld part. I could not properly test the gold
part since the testsuite fails with or without my patch, as reported in PR 21090. I hope
gold has no regressions.
Cheers,
Romain
ld/ChangeLog
2017-07-12 Romain Geissler <romain.geissler@gmail.com>
* configure.ac: Add --with-default-hash-style option.
* ldmain.c (main): Set link_info.emit_hash to DEFAULT_EMIT_SYSV_HASH.
Set link_info.emit_gnu_hash to DEFAULT_EMIT_GNU_HASH.
* configure: Regenerate.
* config.in: Regenerate.
* testsuite/config/default.exp (ld_elf_shared_opt): Pass
--hash-style=sysv to ELF linker.
gold/ChangeLog
2017-07-12 Romain Geissler <romain.geissler@gmail.com>
* configure.ac: Add --with-default-hash-style option.
* options.h (hash_style): Use DEFAULT_HASH_STYLE as default value.
* configure: Regenerate.
* config.in: Regenerate.
---
gold/config.in | 3 +++
gold/configure | 24 ++++++++++++++++++++++
gold/configure.ac | 15 ++++++++++++++
gold/options.h | 2 +-
ld/config.in | 6 ++++++
ld/configure | 45 +++++++++++++++++++++++++++++++++++++++--
ld/configure.ac | 30 +++++++++++++++++++++++++++
ld/ldmain.c | 3 ++-
ld/testsuite/config/default.exp | 4 ++--
9 files changed, 126 insertions(+), 6 deletions(-)
diff --git a/gold/config.in b/gold/config.in
index d9f7b76f29..5855fcac94 100644
--- a/gold/config.in
+++ b/gold/config.in
@@ -10,6 +10,9 @@
/* Define if building universal (internal helper macro) */
#undef AC_APPLE_UNIVERSAL_BUILD
+/* Set the default --hash-style value */
+#undef DEFAULT_HASH_STYLE
+
/* Define to 1 if you want to enable -z relro in ELF linker by default. */
#undef DEFAULT_LD_Z_RELRO
diff --git a/gold/configure b/gold/configure
index cb020be5fc..769837610a 100755
--- a/gold/configure
+++ b/gold/configure
@@ -797,6 +797,7 @@ enable_threads
enable_plugins
enable_relro
enable_targets
+with_default_hash_style
with_lib_path
enable_dependency_tracking
enable_nls
@@ -1459,6 +1460,8 @@ 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-default-hash-style={sysv,gnu,both}
+ use this default hash style
--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
@@ -3410,6 +3413,27 @@ if test -n "$enable_targets"; then
done
fi
+# Decide which "--hash-style" to use by default
+ac_default_hash_style=unset
+# Provide a configure time option to override our default.
+
+# Check whether --with-default-hash-style was given.
+if test "${with_default_hash_style+set}" = set; then :
+ withval=$with_default_hash_style; case "${with_default_hash_style}" in
+ sysv | gnu | both) ac_default_hash_style="${with_default_hash_style}" ;;
+ *) as_fn_error "bad value ${with_default_hash_style} for with-default-hash-style option" "$LINENO" 5 ;;
+esac
+else
+ ac_default_hash_style=gnu
+fi
+
+
+
+cat >>confdefs.h <<_ACEOF
+#define DEFAULT_HASH_STYLE "$ac_default_hash_style"
+_ACEOF
+
+
# See which specific instantiations we need.
targetobjs=
all_targets=
diff --git a/gold/configure.ac b/gold/configure.ac
index cbe3380423..ec208421bf 100644
--- a/gold/configure.ac
+++ b/gold/configure.ac
@@ -161,6 +161,21 @@ if test -n "$enable_targets"; then
done
fi
+# Decide which "--hash-style" to use by default
+ac_default_hash_style=unset
+# Provide a configure time option to override our default.
+AC_ARG_WITH([default-hash-style],
+ AS_HELP_STRING([--with-default-hash-style={sysv,gnu,both}],
+ [use this default hash style]),
+[case "${with_default_hash_style}" in
+ sysv | gnu | both) ac_default_hash_style="${with_default_hash_style}" ;;
+ *) AC_MSG_ERROR([bad value ${with_default_hash_style} for with-default-hash-style option]) ;;
+esac], [ac_default_hash_style=gnu])
+
+AC_DEFINE_UNQUOTED([DEFAULT_HASH_STYLE],
+ ["$ac_default_hash_style"],
+ [Set the default --hash-style value])
+
# See which specific instantiations we need.
targetobjs=
all_targets=
diff --git a/gold/options.h b/gold/options.h
index c7c032bbd7..e67f6ed172 100644
--- a/gold/options.h
+++ b/gold/options.h
@@ -925,7 +925,7 @@ class General_options
N_("Min fraction of empty buckets in dynamic hash"),
N_("FRACTION"));
- DEFINE_enum(hash_style, options::TWO_DASHES, '\0', "sysv",
+ DEFINE_enum(hash_style, options::TWO_DASHES, '\0', DEFAULT_HASH_STYLE,
N_("Dynamic hash style"), N_("[sysv,gnu,both]"),
{"sysv", "gnu", "both"});
diff --git a/ld/config.in b/ld/config.in
index 5d91380ec2..a846743da6 100644
--- a/ld/config.in
+++ b/ld/config.in
@@ -7,6 +7,12 @@
#endif
#define __CONFIG_H__ 1
+/* Define to 1 if you want to emit gnu hash in the ELF linker by default. */
+#undef DEFAULT_EMIT_GNU_HASH
+
+/* Define to 1 if you want to emit sysv hash in the ELF linker by default. */
+#undef DEFAULT_EMIT_SYSV_HASH
+
/* Define if you want compressed debug sections by default. */
#undef DEFAULT_FLAG_COMPRESS_DEBUG
diff --git a/ld/configure b/ld/configure
index 640902b858..dd93fd3d7c 100755
--- a/ld/configure
+++ b/ld/configure
@@ -790,6 +790,7 @@ enable_got
enable_compressed_debug_sections
enable_new_dtags
enable_relro
+with_default_hash_style
enable_werror
enable_build_warnings
enable_nls
@@ -1463,6 +1464,8 @@ Optional Packages:
--with-gnu-ld assume the C compiler uses GNU ld [default=no]
--with-lib-path=dir1:dir2... set default LIB_PATH
--with-sysroot=DIR Search for usr/lib et al within DIR.
+ --with-default-hash-style={sysv,gnu,both}
+ use this default hash style
Some influential environment variables:
CC C compiler command
@@ -11722,7 +11725,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 11725 "configure"
+#line 11728 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -11828,7 +11831,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 11831 "configure"
+#line 11834 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -15564,6 +15567,32 @@ if test "${enable_relro+set}" = set; then :
esac
fi
+# Decide which "--hash-style" to use by default
+ac_default_emit_sysv_hash=unset
+ac_default_emit_gnu_hash=unset
+# Provide a configure time option to override our default.
+
+# Check whether --with-default-hash-style was given.
+if test "${with_default_hash_style+set}" = set; then :
+ withval=$with_default_hash_style; case "${with_default_hash_style}" in
+ sysv | gnu | both) default_hash_style="${with_default_hash_style}" ;;
+ *) as_fn_error "bad value ${with_default_hash_style} for with-default-hash-style option" "$LINENO" 5 ;;
+esac
+else
+ default_hash_style=gnu
+fi
+
+
+case "${default_hash_style}" in
+ sysv | both) ac_default_emit_sysv_hash=1 ;;
+ *) ac_default_emit_sysv_hash=0 ;;
+esac
+
+case "${default_hash_style}" in
+ gnu | both) ac_default_emit_gnu_hash=1 ;;
+ *) ac_default_emit_gnu_hash=0 ;;
+esac
+
# Set the 'development' global.
. $srcdir/../bfd/development.sh
@@ -17228,6 +17257,18 @@ _ACEOF
+cat >>confdefs.h <<_ACEOF
+#define DEFAULT_EMIT_SYSV_HASH $ac_default_emit_sysv_hash
+_ACEOF
+
+
+
+cat >>confdefs.h <<_ACEOF
+#define DEFAULT_EMIT_GNU_HASH $ac_default_emit_gnu_hash
+_ACEOF
+
+
+
diff --git a/ld/configure.ac b/ld/configure.ac
index ffe80185b1..64951eb1cc 100644
--- a/ld/configure.ac
+++ b/ld/configure.ac
@@ -177,6 +177,28 @@ AC_ARG_ENABLE(relro,
no) ac_default_ld_z_relro=0 ;;
esac])dnl
+# Decide which "--hash-style" to use by default
+ac_default_emit_sysv_hash=unset
+ac_default_emit_gnu_hash=unset
+# Provide a configure time option to override our default.
+AC_ARG_WITH([default-hash-style],
+ AS_HELP_STRING([--with-default-hash-style={sysv,gnu,both}],
+ [use this default hash style]),
+[case "${with_default_hash_style}" in
+ sysv | gnu | both) default_hash_style="${with_default_hash_style}" ;;
+ *) AC_MSG_ERROR([bad value ${with_default_hash_style} for with-default-hash-style option]) ;;
+esac], [default_hash_style=gnu])
+
+case "${default_hash_style}" in
+ sysv | both) ac_default_emit_sysv_hash=1 ;;
+ *) ac_default_emit_sysv_hash=0 ;;
+esac
+
+case "${default_hash_style}" in
+ gnu | both) ac_default_emit_gnu_hash=1 ;;
+ *) ac_default_emit_gnu_hash=0 ;;
+esac
+
AM_BINUTILS_WARNINGS
AM_LC_MESSAGES
@@ -408,6 +430,14 @@ AC_DEFINE_UNQUOTED(DEFAULT_LD_Z_RELRO,
$ac_default_ld_z_relro,
[Define to 1 if you want to enable -z relro in ELF linker by default.])
+AC_DEFINE_UNQUOTED([DEFAULT_EMIT_SYSV_HASH],
+ [$ac_default_emit_sysv_hash],
+ [Define to 1 if you want to emit sysv hash in the ELF linker by default.])
+
+AC_DEFINE_UNQUOTED([DEFAULT_EMIT_GNU_HASH],
+ [$ac_default_emit_gnu_hash],
+ [Define to 1 if you want to emit gnu hash in the ELF linker by default.])
+
AC_SUBST(elf_list_options)
AC_SUBST(elf_shlib_list_options)
AC_SUBST(elf_plt_unwind_list_options)
diff --git a/ld/ldmain.c b/ld/ldmain.c
index ee5ab1166a..b7fe362765 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -282,7 +282,8 @@ main (int argc, char **argv)
link_info.keep_memory = TRUE;
link_info.combreloc = TRUE;
link_info.strip_discarded = TRUE;
- link_info.emit_hash = TRUE;
+ link_info.emit_hash = DEFAULT_EMIT_SYSV_HASH;
+ link_info.emit_gnu_hash = DEFAULT_EMIT_GNU_HASH;
link_info.callbacks = &link_callbacks;
link_info.input_bfds_tail = &link_info.input_bfds;
/* SVR4 linkers seem to set DT_INIT and DT_FINI based on magic _init
diff --git a/ld/testsuite/config/default.exp b/ld/testsuite/config/default.exp
index f5cb188478..ac356ec76f 100644
--- a/ld/testsuite/config/default.exp
+++ b/ld/testsuite/config/default.exp
@@ -76,8 +76,8 @@ if {[file exists tmpdir/libpath.exp]} {
}
}
-# Many ELF testcases expect that "-z relro" is off.
-set ld_elf_shared_opt "-z norelro"
+# Many ELF testcases expect that "-z relro" is off and "sysv" hash style is used.
+set ld_elf_shared_opt "-z norelro --hash-style=sysv"
# The "make check" target in the Makefile passes in
# "CC=$(CC_FOR_TARGET)". But, if the user invokes runtest directly
--
2.11.0