This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH fix PR71767 2/4 : Darwin configury] Arrange for ld64 to be detected as Darwin's linker
- From: Iain Sandoe <iain_sandoe at mentor dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Jeff Law <law at redhat dot com>
- Date: Sun, 6 Nov 2016 11:39:00 -0800
- Subject: [PATCH fix PR71767 2/4 : Darwin configury] Arrange for ld64 to be detected as Darwin's linker
- Authentication-results: sourceware.org; auth=none
Hi Folks,
This is an initial patch in a series that converts Darwin's configury to detect ld64 features, rather than the current process of hard-coding them on target system version.
This adds an option --with-ld64[=version] that allows the configurer to specify that the Darwin ld64 linker is in use. If the version is given then that will be used to determine the capabilities of the linker in native and canadian crosses. For Darwin targets this flag will default to "on", since such targets require an ld64-compatible linker.
If a DEFAULT_LINKER is set via --with-ld= then this will also be tested to see if it is ld64.
The ld64 version is determined (unless overridden by --with-ld64=version) and this is exported for use in setting a default value for -mtarget-linker (needed for run-time code-gen changes to section choices).
In this initial patch, support for -rdynamic is converted to be detected at config time, or by the ld64 version if that is explicitly given (as an example of usage).
OK for trunk?
OK for open branches?
Iain
gcc/
2016-11-06 Iain Sandoe <iain@codesourcery.com>
PR target/71767
* configure.ac (with-ld64): New arg-with. gcc_ld64_version: New,
new test. gcc_cv_ld64_export_dynamic: New, New test.
* configure: Regenerate.
* config.in: Likewise.
* darwin.h: Use LD64_HAS_DYNAMIC export. DEF_LD64: New, define.
* darwin10.h(DEF_LD64): Update for this target version.
* darwin12.h(LINK_GCC_C_SEQUENCE_SPEC): Remove rdynamic test.
(DEF_LD64): Update for this target version.
---
gcc/config/darwin.h | 16 ++++++++++-
gcc/config/darwin10.h | 5 ++++
gcc/config/darwin12.h | 7 ++++-
gcc/configure.ac | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 100 insertions(+), 2 deletions(-)
diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
index 045f70b..541bcb3 100644
--- a/gcc/config/darwin.h
+++ b/gcc/config/darwin.h
@@ -165,6 +165,12 @@ extern GTY(()) int darwin_ms_struct;
specifying the handling of options understood by generic Unix
linkers, and for positional arguments like libraries. */
+#if LD64_HAS_EXPORT_DYNAMIC
+#define DARWIN_EXPORT_DYNAMIC " %{rdynamic:-export_dynamic}"
+#else
+#define DARWIN_EXPORT_DYNAMIC " %{rdynamic: %nrdynamic is not supported}"
+#endif
+
#define LINK_COMMAND_SPEC_A \
"%{!fdump=*:%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
%(linker)" \
@@ -185,7 +191,9 @@ extern GTY(()) int darwin_ms_struct;
%{!nostdlib:%{!nodefaultlibs:\
%{%:sanitize(address): -lasan } \
%{%:sanitize(undefined): -lubsan } \
- %(link_ssp) %(link_gcc_c_sequence)\
+ %(link_ssp) \
+ " DARWIN_EXPORT_DYNAMIC " %<rdynamic \
+ %(link_gcc_c_sequence) \
}}\
%{!nostdlib:%{!nostartfiles:%E}} %{T*} %{F*} }}}}}}}"
@@ -932,4 +940,10 @@ extern void darwin_driver_init (unsigned int *,struct cl_decoded_option **);
fall-back default. */
#define DEF_MIN_OSX_VERSION "10.5"
+#ifndef LD64_VERSION
+#define LD64_VERSION "85.2"
+#else
+#define DEF_LD64 LD64_VERSION
+#endif
+
#endif /* CONFIG_DARWIN_H */
diff --git a/gcc/config/darwin10.h b/gcc/config/darwin10.h
index 5829d78..a81fbdc 100644
--- a/gcc/config/darwin10.h
+++ b/gcc/config/darwin10.h
@@ -32,3 +32,8 @@ along with GCC; see the file COPYING3. If not see
#undef DEF_MIN_OSX_VERSION
#define DEF_MIN_OSX_VERSION "10.6"
+
+#ifndef LD64_VERSION
+#undef DEF_LD64
+#define DEF_LD64 "97.7"
+#endif
diff --git a/gcc/config/darwin12.h b/gcc/config/darwin12.h
index e366982..f88e2a4 100644
--- a/gcc/config/darwin12.h
+++ b/gcc/config/darwin12.h
@@ -21,10 +21,15 @@ along with GCC; see the file COPYING3. If not see
#undef LINK_GCC_C_SEQUENCE_SPEC
#define LINK_GCC_C_SEQUENCE_SPEC \
"%:version-compare(>= 10.6 mmacosx-version-min= -no_compact_unwind) \
- %{rdynamic:-export_dynamic} %{!static:%{!static-libgcc: \
+ %{!static:%{!static-libgcc: \
%:version-compare(>= 10.6 mmacosx-version-min= -lSystem) } } \
%{fno-pic|fno-PIC|fno-pie|fno-PIE|fapple-kext|mkernel|static|mdynamic-no-pic: \
%:version-compare(>= 10.7 mmacosx-version-min= -no_pie) } %G %L"
#undef DEF_MIN_OSX_VERSION
#define DEF_MIN_OSX_VERSION "10.8"
+
+#ifndef LD64_VERSION
+#undef DEF_LD64
+#define DEF_LD64 "236.4"
+#endif
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 338956f..1783a39 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -274,6 +274,26 @@ AC_ARG_WITH(gnu-ld,
gnu_ld_flag="$with_gnu_ld",
gnu_ld_flag=no)
+# With ld64; try to support native and canadian crosses by allowing the
+# configurer to specify the minium ld64 version expected.
+AC_ARG_WITH(ld64,
+[AS_HELP_STRING([[--with-ld64[=VERS]]],
+[arrange to work with Darwin's ld64; assume that the version is >= VERS if given])],
+[case "${withval}" in
+ no | yes)
+ ld64_flag="${withval}"
+ gcc_cv_ld64_version=
+ ;;
+ *)
+ ld64_flag=yes
+ gcc_cv_ld64_version="${withval}";;
+esac],
+[gcc_cv_ld64_version=
+case $target in
+ *darwin*) ld64_flag=yes;; # Darwin can only use a ld64-compatible linker.
+ *) ld64_flag=no;;
+esac])
+
# With pre-defined ld
AC_ARG_WITH(ld,
[AS_HELP_STRING([--with-ld], [arrange to use the specified ld (full pathname)])],
@@ -283,6 +303,8 @@ if test x"${DEFAULT_LINKER+set}" = x"set"; then
AC_MSG_ERROR([cannot execute: $DEFAULT_LINKER: check --with-ld or env. var. DEFAULT_LINKER])
elif $DEFAULT_LINKER -v < /dev/null 2>&1 | grep GNU > /dev/null; then
gnu_ld_flag=yes
+ elif $DEFAULT_LINKER -v < /dev/null 2>&1 | grep ld64- > /dev/null; then
+ ld64_flag=yes
fi
AC_DEFINE_UNQUOTED(DEFAULT_LINKER,"$DEFAULT_LINKER",
[Define to enable the use of a default linker.])
@@ -5254,6 +5276,58 @@ AC_DEFINE_UNQUOTED(LD_COMPRESS_DEBUG_OPTION, "$gcc_cv_ld_compress_debug_option",
[Define to the linker option to enable compressed debug sections.])
AC_MSG_RESULT($gcc_cv_ld_compress_debug)
+if test x"$ld64_flag" = x"yes"; then
+
+ # Set defaults for possibly untestable items.
+ gcc_cv_ld64_export_dynamic=0
+
+ if test "$build" = "$host"; then
+ darwin_try_test=1
+ else
+ darwin_try_test=0
+ fi
+ # On Darwin, because of FAT library support, it is usually possible to execute
+ # exes from compatible archs even when the host differs from the build system.
+ case "$build","$host" in
+ x86_64-*-darwin*,i?86-*-darwin* | powerpc64*-*-darwin*,powerpc*-*-darwin*)
+ darwin_try_test=1;;
+ *) ;;
+ esac
+
+ # If the configurer specified a minimum ld64 version to be supported, then use
+ # that to determine feature support.
+ if test x"${gcc_cv_ld64_version}" != x; then
+ AC_MSG_CHECKING(ld64 major version)
+ IFS=. read gcc_cv_ld64_major gcc_cv_ld64_minor <<< "${gcc_cv_ld64_version}"
+ AC_MSG_RESULT($gcc_cv_ld64_major)
+ if test "$gcc_cv_ld64_major" -ge 236; then
+ gcc_cv_ld64_export_dynamic=1
+ fi
+ elif test -x "$gcc_cv_ld" -a "$darwin_try_test" -eq 1; then
+ # If the version was not specified, try to find it.
+ AC_MSG_CHECKING(linker version)
+ if test x"${gcc_cv_ld64_version}" = x; then
+ gcc_cv_ld64_version=`$gcc_cv_ld -v 2>&1 | grep ld64 | sed s/.*ld64-// | awk '{print $1}'`
+ fi
+ AC_MSG_RESULT($gcc_cv_ld64_version)
+
+ AC_MSG_CHECKING(linker for -export_dynamic support)
+ gcc_cv_ld64_export_dynamic=1
+ if $gcc_cv_ld -export_dynamic < /dev/null 2>&1 | grep 'unknown option' > /dev/null; then
+ gcc_cv_ld64_export_dynamic=0
+ fi
+ AC_MSG_RESULT($gcc_cv_ld64_export_dynamic)
+ fi
+
+ if test x"${gcc_cv_ld64_version}" != x; then
+ AC_DEFINE_UNQUOTED(LD64_VERSION, "${gcc_cv_ld64_version}",
+ [Define to ld64 version.])
+ fi
+
+ AC_DEFINE_UNQUOTED(LD64_HAS_EXPORT_DYNAMIC, $gcc_cv_ld64_export_dynamic,
+ [Define to 1 if ld64 supports '-export_dynamic'.])
+fi
+
# --------
# UNSORTED
# --------
--
2.8.1