From 39c6919bb5237832eb9c50010f3d2b89fb33398f Mon Sep 17 00:00:00 2001 From: iains Date: Sun, 11 Dec 2016 16:01:35 +0000 Subject: [Darwin] Back-port fix for PR71767. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc/ 2016-12-11 Iain Sandoe Backport from mainline 2016-11-27 Iain Sandoe PR target/71767 * config/darwin-sections.def (picbase_thunk_section): New. * config/darwin.c (darwin_init_sections): Set up picbase thunk section. (darwin_rodata_section, darwin_objc2_section, machopic_select_section, darwin_asm_declare_constant_name, darwin_emit_weak_or_comdat, darwin_function_section): Don’t use coalesced with newer linkers. (darwin_override_options): Decide on usage of coalesed sections on the basis of the target linker version. * config/darwin.h (MIN_LD64_NO_COAL_SECTS): New. * config/darwin.opt (mtarget-linker): New. * config/i386/i386.c (ix86_code_end): Do not force the thunks into a coalesced section, instead use a thunks section. Backport from mainline 2016-11-28 Iain Sandoe PR target/71767 * configure.ac (with_ld64): Use portable method to extract the major part of the version number. * configure: Regenerated. Backport from mainline 2016-11-27 Iain Sandoe PR target/71767 * configure.ac (with-ld64): New var, set for Darwin, set on detection of ld64, gcc_cv_ld64_export_dynamic: New, New test. * config/darwin.h: Use LD64_HAS_DYNAMIC export. DEF_LD64: New, define. * config/darwin10.h(DEF_LD64): Update for this target version. * config/darwin12.h(LINK_GCC_C_SEQUENCE_SPEC): Remove rdynamic test. (DEF_LD64): Update for this target version. * configure: Regenerated. * config.in: Regenerated. Backport from mainline 2016-11-27 Iain Sandoe PR target/71767 * config/darwin.c (imachopic_indirection_name): Make data section indirections linker-visible. * config/darwin.h (ASM_GENERATE_INTERNAL_LABEL): Make local constant labels linker-visible. gcc/testsuite/ 2016-12-11 Iain Sandoe Backport from mainline 2016-11-27 Dominique d'Humieres Iain Sandoe PR target/71767 * g++.dg/abi/key2.C: Adjust for changed Darwin sections and linker-visible symbols. * g++.dg/torture/darwin-cfstring-3.C: Likewise. * gcc.dg/const-uniq-1.c: Likewise. * gcc.dg/torture/darwin-cfstring-3.c: Likewise. * gcc.target/i386/pr70799-1.c: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-6-branch@243524 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 50 ++++++++++ gcc/config.in | 12 +++ gcc/config/darwin-sections.def | 5 + gcc/config/darwin.c | 114 +++++++++++++++++------ gcc/config/darwin.h | 30 +++++- gcc/config/darwin.opt | 6 ++ gcc/config/darwin10.h | 5 + gcc/config/darwin12.h | 7 +- gcc/config/i386/i386.c | 2 +- gcc/configure | 76 ++++++++++++++- gcc/configure.ac | 60 ++++++++++++ gcc/testsuite/ChangeLog | 14 +++ gcc/testsuite/g++.dg/abi/key2.C | 1 + gcc/testsuite/g++.dg/torture/darwin-cfstring-3.C | 4 +- gcc/testsuite/gcc.dg/const-uniq-1.c | 2 +- gcc/testsuite/gcc.dg/torture/darwin-cfstring-3.c | 4 +- 16 files changed, 350 insertions(+), 42 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7d78c39c225..5eb4bad303a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,53 @@ +2016-12-11 Iain Sandoe + + Backport from mainline + 2016-11-27 Iain Sandoe + + PR target/71767 + * config/darwin-sections.def (picbase_thunk_section): New. + * config/darwin.c (darwin_init_sections): Set up picbase thunk + section. (darwin_rodata_section, darwin_objc2_section, + machopic_select_section, darwin_asm_declare_constant_name, + darwin_emit_weak_or_comdat, darwin_function_section): Don’t use + coalesced with newer linkers. + (darwin_override_options): Decide on usage of coalesed sections + on the basis of the target linker version. + * config/darwin.h (MIN_LD64_NO_COAL_SECTS): New. + * config/darwin.opt (mtarget-linker): New. + * config/i386/i386.c (ix86_code_end): Do not force the thunks into + a coalesced section, instead use a thunks section. + + Backport from mainline + 2016-11-28 Iain Sandoe + + PR target/71767 + * configure.ac (with_ld64): Use portable method to extract the + major part of the version number. + * configure: Regenerated. + + Backport from mainline + 2016-11-27 Iain Sandoe + + PR target/71767 + * configure.ac (with-ld64): New var, set for Darwin, set on + detection of ld64, gcc_cv_ld64_export_dynamic: New, New test. + * config/darwin.h: Use LD64_HAS_DYNAMIC export. DEF_LD64: New, + define. + * config/darwin10.h(DEF_LD64): Update for this target version. + * config/darwin12.h(LINK_GCC_C_SEQUENCE_SPEC): Remove rdynamic + test. (DEF_LD64): Update for this target version. + * configure: Regenerated. + * config.in: Regenerated. + + Backport from mainline + 2016-11-27 Iain Sandoe + + PR target/71767 + * config/darwin.c (imachopic_indirection_name): Make data + section indirections linker-visible. + * config/darwin.h (ASM_GENERATE_INTERNAL_LABEL): Make local + constant labels linker-visible. + 2016-12-09 Thomas Preud'homme Backport from mainline diff --git a/gcc/config.in b/gcc/config.in index 86bd5b0dd53..cda0e281587 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -1908,6 +1908,18 @@ #endif +/* Define to 1 if ld64 supports '-export_dynamic'. */ +#ifndef USED_FOR_TARGET +#undef LD64_HAS_EXPORT_DYNAMIC +#endif + + +/* Define to ld64 version. */ +#ifndef USED_FOR_TARGET +#undef LD64_VERSION +#endif + + /* Define to the linker option to ignore unused dependencies. */ #ifndef USED_FOR_TARGET #undef LD_AS_NEEDED_OPTION diff --git a/gcc/config/darwin-sections.def b/gcc/config/darwin-sections.def index cbf3e41e9ac..8a7e985c85f 100644 --- a/gcc/config/darwin-sections.def +++ b/gcc/config/darwin-sections.def @@ -31,6 +31,11 @@ along with GCC; see the file COPYING3. If not see DEF_SECTION (text_coal_section, SECTION_CODE|SECTION_NO_ANCHOR, ".section __TEXT,__textcoal_nt,coalesced,pure_instructions", 0) +/* We define a picbase thunks section separately, so that we can override the + def to be '.text' for versions of ld64 that handle coalescing. */ +DEF_SECTION (picbase_thunk_section, SECTION_CODE|SECTION_NO_ANCHOR, + ".section __TEXT,__textcoal_nt,coalesced,pure_instructions", 0) + DEF_SECTION (text_hot_section, SECTION_CODE, ".section __TEXT,__text_hot,regular,pure_instructions", 0) DEF_SECTION (text_cold_section, SECTION_CODE, diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index 0055d805441..fd27cdfb950 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -96,6 +96,10 @@ int darwin_running_cxx; /* Some code-gen now depends on OS major version numbers (at least). */ int generating_for_darwin_version ; +/* For older linkers we need to emit special sections (marked 'coalesced') for + for weak or single-definition items. */ +static bool ld_uses_coal_sects = false; + /* Section names. */ section * darwin_sections[NUM_DARWIN_SECTIONS]; @@ -219,6 +223,11 @@ darwin_init_sections (void) readonly_data_section = darwin_sections[const_section]; exception_section = darwin_sections[darwin_exception_section]; eh_frame_section = darwin_sections[darwin_eh_frame_section]; + + /* If our linker is new enough to coalesce weak symbols, then we + can just put picbase_thunks into the text section. */ + if (! ld_uses_coal_sects ) + darwin_sections[picbase_thunk_section] = text_section; } int @@ -473,7 +482,31 @@ indirection_hasher::equal (machopic_indirection *s, const char *k) } /* Return the name of the non-lazy pointer (if STUB_P is false) or - stub (if STUB_B is true) corresponding to the given name. */ + stub (if STUB_B is true) corresponding to the given name. + + If we have a situation like: + +global_weak_symbol: + .... +Lnon_weak_local: + .... + + ld64 will be unable to split this into two atoms (because the "L" makes + the second symbol 'invisible'). This means that legitimate direct accesses + to the second symbol will appear to be non-allowed direct accesses to an + atom of type weak, global which are not allowed. + + To avoid this, we make the indirections have a leading 'l' (lower-case L) + which has a special meaning: linker can see this and use it to determine + atoms, but it is not placed into the final symbol table. + + The implementation here is somewhat heavy-handed in that it will also mark + indirections to the __IMPORT,__pointers section the same way which is + really unnecessary, since ld64 _can_ split those into atoms as they are + fixed size. FIXME: determine if this is a penalty worth extra code to + fix. + +*/ const char * machopic_indirection_name (rtx sym_ref, bool stub_p) @@ -484,6 +517,7 @@ machopic_indirection_name (rtx sym_ref, bool stub_p) machopic_indirection *p; bool needs_quotes; const char *suffix; + char L_or_l = 'L'; const char *prefix = user_label_prefix; const char *quote = ""; tree id; @@ -518,9 +552,13 @@ machopic_indirection_name (rtx sym_ref, bool stub_p) if (stub_p) suffix = STUB_SUFFIX; else - suffix = NON_LAZY_POINTER_SUFFIX; + { + suffix = NON_LAZY_POINTER_SUFFIX; + /* Let the linker see this. */ + L_or_l = 'l'; + } - buffer = XALLOCAVEC (char, strlen ("&L") + buffer = XALLOCAVEC (char, 2 /* strlen ("&L") or ("&l") */ + strlen (prefix) + namelen + strlen (suffix) @@ -528,7 +566,7 @@ machopic_indirection_name (rtx sym_ref, bool stub_p) + 1 /* '\0' */); /* Construct the name of the non-lazy pointer or stub. */ - sprintf (buffer, "&%sL%s%s%s%s", quote, prefix, name, suffix, quote); + sprintf (buffer, "&%s%c%s%s%s%s", quote, L_or_l, prefix, name, suffix, quote); if (!machopic_indirections) machopic_indirections = hash_table::create_ggc (37); @@ -1217,9 +1255,9 @@ darwin_mark_decl_preserved (const char *name) } static section * -darwin_rodata_section (int weak, bool zsize) +darwin_rodata_section (int use_coal, bool zsize) { - return (weak + return (use_coal ? darwin_sections[const_coal_section] : (zsize ? darwin_sections[zobj_const_section] : darwin_sections[const_section])); @@ -1388,7 +1426,8 @@ darwin_objc2_section (tree decl ATTRIBUTE_UNUSED, tree meta, section * base) return darwin_sections[objc2_image_info_section]; else if (!strncmp (p, "V2_EHTY", 7)) - return darwin_sections[data_coal_section]; + return ld_uses_coal_sects ? darwin_sections[data_coal_section] + : data_section; else if (!strncmp (p, "V2_CSTR", 7)) return darwin_sections[objc2_constant_string_object_section]; @@ -1487,21 +1526,23 @@ machopic_select_section (tree decl, int reloc, unsigned HOST_WIDE_INT align) { - bool zsize, one, weak, ro; + bool zsize, one, weak, use_coal, ro; section *base_section = NULL; weak = (DECL_P (decl) && DECL_WEAK (decl) && !lookup_attribute ("weak_import", DECL_ATTRIBUTES (decl))); - zsize = (DECL_P (decl) + zsize = (DECL_P (decl) && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == CONST_DECL) && tree_to_uhwi (DECL_SIZE_UNIT (decl)) == 0); - one = DECL_P (decl) + one = DECL_P (decl) && TREE_CODE (decl) == VAR_DECL && DECL_COMDAT_GROUP (decl); + use_coal = (weak || one) && ld_uses_coal_sects; + ro = TREE_READONLY (decl) || TREE_CONSTANT (decl) ; switch (categorize_decl_for_section (decl, reloc)) @@ -1512,7 +1553,7 @@ machopic_select_section (tree decl, case SECCAT_RODATA: case SECCAT_SRODATA: - base_section = darwin_rodata_section (weak, zsize); + base_section = darwin_rodata_section (use_coal, zsize); break; case SECCAT_RODATA_MERGE_STR: @@ -1534,7 +1575,7 @@ machopic_select_section (tree decl, case SECCAT_DATA_REL_RO_LOCAL: case SECCAT_SDATA: case SECCAT_TDATA: - if (weak || one) + if (use_coal) { if (ro) base_section = darwin_sections[const_data_coal_section]; @@ -1563,7 +1604,7 @@ machopic_select_section (tree decl, case SECCAT_BSS: case SECCAT_SBSS: case SECCAT_TBSS: - if (weak || one) + if (use_coal) base_section = darwin_sections[data_coal_section]; else { @@ -2259,14 +2300,18 @@ darwin_asm_declare_constant_name (FILE *file, const char *name, static void darwin_emit_weak_or_comdat (FILE *fp, tree decl, const char *name, unsigned HOST_WIDE_INT size, + bool use_coal, unsigned int align) { - /* Since the sections used here are coalesed, they will not be eligible - for section anchors, and therefore we don't need to break that out. */ + /* Since the sections used here are coalesced, they will not be eligible + for section anchors, and therefore we don't need to break that out. + CHECKME: for modern linker on PowerPC. */ if (TREE_READONLY (decl) || TREE_CONSTANT (decl)) - switch_to_section (darwin_sections[const_data_coal_section]); + switch_to_section (use_coal ? darwin_sections[const_data_coal_section] + : darwin_sections[const_data_section]); else - switch_to_section (darwin_sections[data_coal_section]); + switch_to_section (use_coal ? darwin_sections[data_coal_section] + : data_section); /* To be consistent, we'll allow darwin_asm_declare_object_name to assemble the align info for zero-sized items... but do it here otherwise. */ @@ -2485,7 +2530,7 @@ fprintf (fp, "# albss: %s (%lld,%d) ro %d cst %d stat %d com %d" { /* Weak or COMDAT objects are put in mergeable sections. */ darwin_emit_weak_or_comdat (fp, decl, name, size, - DECL_ALIGN (decl)); + ld_uses_coal_sects, DECL_ALIGN (decl)); return; } @@ -2599,7 +2644,7 @@ fprintf (fp, "# adcom: %s (%lld,%d) ro %d cst %d stat %d com %d pub %d" { /* Weak or COMDAT objects are put in mergable sections. */ darwin_emit_weak_or_comdat (fp, decl, name, size, - DECL_ALIGN (decl)); + ld_uses_coal_sects, DECL_ALIGN (decl)); return; } @@ -2669,7 +2714,7 @@ fprintf (fp, "# adloc: %s (%lld,%d) ro %d cst %d stat %d one %d pub %d" { /* Weak or COMDAT objects are put in mergable sections. */ darwin_emit_weak_or_comdat (fp, decl, name, size, - DECL_ALIGN (decl)); + ld_uses_coal_sects, DECL_ALIGN (decl)); return; } @@ -3051,6 +3096,12 @@ darwin_override_options (void) /* Earlier versions are not specifically accounted, until required. */ } + /* Older Darwin ld could not coalesce weak entities without them being + placed in special sections. */ + if (darwin_target_linker + && (strverscmp (darwin_target_linker, MIN_LD64_NO_COAL_SECTS) < 0)) + ld_uses_coal_sects = true; + /* In principle, this should be c-family only. However, we really need to set sensible defaults for LTO as well, since the section selection stuff should check for correctness re. the ABI. TODO: check and provide the @@ -3576,12 +3627,13 @@ darwin_function_section (tree decl, enum node_frequency freq, bool startup, bool exit) { /* Decide if we need to put this in a coalescable section. */ - bool weak = (decl + bool weak = (decl && DECL_WEAK (decl) && (!DECL_ATTRIBUTES (decl) || !lookup_attribute ("weak_import", DECL_ATTRIBUTES (decl)))); + bool use_coal = weak && ld_uses_coal_sects; /* If there is a specified section name, we should not be trying to override. */ if (decl && DECL_SECTION_NAME (decl) != NULL) @@ -3589,8 +3641,8 @@ darwin_function_section (tree decl, enum node_frequency freq, /* We always put unlikely executed stuff in the cold section. */ if (freq == NODE_FREQUENCY_UNLIKELY_EXECUTED) - return (weak) ? darwin_sections[text_cold_coal_section] - : darwin_sections[text_cold_section]; + return (use_coal) ? darwin_sections[text_cold_coal_section] + : darwin_sections[text_cold_section]; /* If we have LTO *and* feedback information, then let LTO handle the function ordering, it makes a better job (for normal, hot, @@ -3600,23 +3652,23 @@ darwin_function_section (tree decl, enum node_frequency freq, /* Non-cold startup code should go to startup subsection. */ if (startup) - return (weak) ? darwin_sections[text_startup_coal_section] - : darwin_sections[text_startup_section]; + return (use_coal) ? darwin_sections[text_startup_coal_section] + : darwin_sections[text_startup_section]; /* Similarly for exit. */ if (exit) - return (weak) ? darwin_sections[text_exit_coal_section] - : darwin_sections[text_exit_section]; + return (use_coal) ? darwin_sections[text_exit_coal_section] + : darwin_sections[text_exit_section]; /* Place hot code. */ if (freq == NODE_FREQUENCY_HOT) - return (weak) ? darwin_sections[text_hot_coal_section] - : darwin_sections[text_hot_section]; + return (use_coal) ? darwin_sections[text_hot_coal_section] + : darwin_sections[text_hot_section]; /* Otherwise, default to the 'normal' non-reordered sections. */ default_function_sections: - return (weak) ? darwin_sections[text_coal_section] - : text_section; + return (use_coal) ? darwin_sections[text_coal_section] + : text_section; } /* When a function is partitioned between sections, we need to insert a label diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index 0277cf2238b..3cfb876813e 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 " %= 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/config/i386/i386.c b/gcc/config/i386/i386.c index 93f6470d412..9cbc4ccf4c1 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -11050,7 +11050,7 @@ ix86_code_end (void) #if TARGET_MACHO if (TARGET_MACHO) { - switch_to_section (darwin_sections[text_coal_section]); + switch_to_section (darwin_sections[picbase_thunk_section]); fputs ("\t.weak_definition\t", asm_out_file); assemble_name (asm_out_file, name); fputs ("\n\t.private_extern\t", asm_out_file); diff --git a/gcc/configure b/gcc/configure index 40418310b03..3f91d011a8f 100755 --- a/gcc/configure +++ b/gcc/configure @@ -3631,6 +3631,11 @@ else fi +case $target in + *darwin*) ld64_flag=yes;; # Darwin can only use a ld64-compatible linker. + *) ld64_flag=no;; +esac + # With pre-defined ld # Check whether --with-ld was given. @@ -3643,6 +3648,8 @@ if test x"${DEFAULT_LINKER+set}" = x"set"; then as_fn_error "cannot execute: $DEFAULT_LINKER: check --with-ld or env. var. DEFAULT_LINKER" "$LINENO" 5 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 cat >>confdefs.h <<_ACEOF @@ -18453,7 +18460,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 18456 "configure" +#line 18463 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -18559,7 +18566,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 18562 "configure" +#line 18569 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -28069,6 +28076,71 @@ _ACEOF { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_ld_compress_debug" >&5 $as_echo "$gcc_cv_ld_compress_debug" >&6; } +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 often 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 + { $as_echo "$as_me:${as_lineno-$LINENO}: checking ld64 specified version" >&5 +$as_echo_n "checking ld64 specified version... " >&6; } + gcc_cv_ld64_major=`echo "$gcc_cv_ld64_version" | sed -e 's/\..*//'` + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_ld64_major" >&5 +$as_echo "$gcc_cv_ld64_major" >&6; } + 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. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking linker version" >&5 +$as_echo_n "checking linker version... " >&6; } + 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 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_ld64_version" >&5 +$as_echo "$gcc_cv_ld64_version" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking linker for -export_dynamic support" >&5 +$as_echo_n "checking linker for -export_dynamic support... " >&6; } + 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 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_ld64_export_dynamic" >&5 +$as_echo "$gcc_cv_ld64_export_dynamic" >&6; } + fi + + if test x"${gcc_cv_ld64_version}" != x; then + +cat >>confdefs.h <<_ACEOF +#define LD64_VERSION "${gcc_cv_ld64_version}" +_ACEOF + + fi + + +cat >>confdefs.h <<_ACEOF +#define LD64_HAS_EXPORT_DYNAMIC $gcc_cv_ld64_export_dynamic +_ACEOF + +fi + # -------- # UNSORTED # -------- diff --git a/gcc/configure.ac b/gcc/configure.ac index d426791ae6d..4475e5c338e 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -271,6 +271,11 @@ AC_ARG_WITH(gnu-ld, gnu_ld_flag="$with_gnu_ld", gnu_ld_flag=no) +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)])], @@ -280,6 +285,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.]) @@ -5148,6 +5155,59 @@ 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 often 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 specified version) + gcc_cv_ld64_major=`echo "$gcc_cv_ld64_version" | sed -e 's/\..*//'` + 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 # -------- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 21b6839c592..97148591382 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,17 @@ +2016-12-11 Iain Sandoe + + Backport from mainline + 2016-11-27 Dominique d'Humieres + Iain Sandoe + + PR target/71767 + * g++.dg/abi/key2.C: Adjust for changed Darwin sections and + linker-visible symbols. + * g++.dg/torture/darwin-cfstring-3.C: Likewise. + * gcc.dg/const-uniq-1.c: Likewise. + * gcc.dg/torture/darwin-cfstring-3.c: Likewise. + * gcc.target/i386/pr70799-1.c: Likewise. + 2016-12-09 Thomas Preud'homme Backport from mainline diff --git a/gcc/testsuite/g++.dg/abi/key2.C b/gcc/testsuite/g++.dg/abi/key2.C index 0d1347aaaa0..c79b3b2a20c 100644 --- a/gcc/testsuite/g++.dg/abi/key2.C +++ b/gcc/testsuite/g++.dg/abi/key2.C @@ -2,6 +2,7 @@ // PR darwin/25908 // { dg-do compile { target *-*-darwin* } } +// { dg-options "-mtarget-linker 85.2" } // { dg-final { scan-assembler ".globl __ZTV1f\\n .weak_definition __ZTV1f(\\n .section __DATA,__const_coal,coalesced)?\\n .align" } } // { dg-final { scan-assembler ".globl __ZTS1f\\n .weak_definition __ZTS1f\\n .section __TEXT,__const_coal,coalesced" } } // { dg-final { scan-assembler ".globl __ZTI1f\\n .weak_definition __ZTI1f(\\n .section __DATA,__const_coal,coalesced)?\\n .align" } } diff --git a/gcc/testsuite/g++.dg/torture/darwin-cfstring-3.C b/gcc/testsuite/g++.dg/torture/darwin-cfstring-3.C index 2d755ec8dd0..ee4b385b17f 100644 --- a/gcc/testsuite/g++.dg/torture/darwin-cfstring-3.C +++ b/gcc/testsuite/g++.dg/torture/darwin-cfstring-3.C @@ -24,7 +24,7 @@ void foo(void) { s0 = s1; } -/* { dg-final { scan-assembler "\\.long\[ \\t\]+___CFConstantStringClassReference\n\[ \\t\]*\\.long\[ \\t\]+1992\n\[ \\t\]*\\.long\[ \\t\]+LC.*\n\[ \\t\]*\\.long\[ \\t\]+4\n" { target { *-*-darwin* && { ! lp64 } } } } } */ -/* { dg-final { scan-assembler "\\.long\[ \\t\]+___CFConstantStringClassReference\n\[ \\t\]*\\.long\[ \\t\]+1992\n\[ \\t\]*\\.long\[ \\t\]+LC.*\n\[ \\t\]*\\.long\[ \\t\]+10\n" { target { *-*-darwin* && { ! lp64 } } } } } */ +/* { dg-final { scan-assembler "\\.long\[ \\t\]+___CFConstantStringClassReference\n\[ \\t\]*\\.long\[ \\t\]+1992\n\[ \\t\]*\\.long\[ \\t\]+\[lL\]C.*\n\[ \\t\]*\\.long\[ \\t\]+4\n" { target { *-*-darwin* && { ! lp64 } } } } } */ +/* { dg-final { scan-assembler "\\.long\[ \\t\]+___CFConstantStringClassReference\n\[ \\t\]*\\.long\[ \\t\]+1992\n\[ \\t\]*\\.long\[ \\t\]+\[lL\]C.*\n\[ \\t\]*\\.long\[ \\t\]+10\n" { target { *-*-darwin* && { ! lp64 } } } } } */ /* { dg-final { scan-assembler ".quad\t___CFConstantStringClassReference\n\t.long\t1992\n\t.space 4\n\t.quad\t.*\n\t.quad\t4\n" { target { *-*-darwin* && { lp64 } } } } } */ /* { dg-final { scan-assembler ".quad\t___CFConstantStringClassReference\n\t.long\t1992\n\t.space 4\n\t.quad\t.*\n\t.quad\t10\n" { target { *-*-darwin* && { lp64 } } } } } */ diff --git a/gcc/testsuite/gcc.dg/const-uniq-1.c b/gcc/testsuite/gcc.dg/const-uniq-1.c index 2cb4f8a56cd..0e0718bf505 100644 --- a/gcc/testsuite/gcc.dg/const-uniq-1.c +++ b/gcc/testsuite/gcc.dg/const-uniq-1.c @@ -20,4 +20,4 @@ int lookup2 (int i) return a[i+1]; } -/* { dg-final { scan-tree-dump-times "L\\\$?C\\\.*0" 2 "gimple" } } */ +/* { dg-final { scan-tree-dump-times "\[lL\]\\\$?C\\\.*0" 2 "gimple" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/darwin-cfstring-3.c b/gcc/testsuite/gcc.dg/torture/darwin-cfstring-3.c index 2d755ec8dd0..ee4b385b17f 100644 --- a/gcc/testsuite/gcc.dg/torture/darwin-cfstring-3.c +++ b/gcc/testsuite/gcc.dg/torture/darwin-cfstring-3.c @@ -24,7 +24,7 @@ void foo(void) { s0 = s1; } -/* { dg-final { scan-assembler "\\.long\[ \\t\]+___CFConstantStringClassReference\n\[ \\t\]*\\.long\[ \\t\]+1992\n\[ \\t\]*\\.long\[ \\t\]+LC.*\n\[ \\t\]*\\.long\[ \\t\]+4\n" { target { *-*-darwin* && { ! lp64 } } } } } */ -/* { dg-final { scan-assembler "\\.long\[ \\t\]+___CFConstantStringClassReference\n\[ \\t\]*\\.long\[ \\t\]+1992\n\[ \\t\]*\\.long\[ \\t\]+LC.*\n\[ \\t\]*\\.long\[ \\t\]+10\n" { target { *-*-darwin* && { ! lp64 } } } } } */ +/* { dg-final { scan-assembler "\\.long\[ \\t\]+___CFConstantStringClassReference\n\[ \\t\]*\\.long\[ \\t\]+1992\n\[ \\t\]*\\.long\[ \\t\]+\[lL\]C.*\n\[ \\t\]*\\.long\[ \\t\]+4\n" { target { *-*-darwin* && { ! lp64 } } } } } */ +/* { dg-final { scan-assembler "\\.long\[ \\t\]+___CFConstantStringClassReference\n\[ \\t\]*\\.long\[ \\t\]+1992\n\[ \\t\]*\\.long\[ \\t\]+\[lL\]C.*\n\[ \\t\]*\\.long\[ \\t\]+10\n" { target { *-*-darwin* && { ! lp64 } } } } } */ /* { dg-final { scan-assembler ".quad\t___CFConstantStringClassReference\n\t.long\t1992\n\t.space 4\n\t.quad\t.*\n\t.quad\t4\n" { target { *-*-darwin* && { lp64 } } } } } */ /* { dg-final { scan-assembler ".quad\t___CFConstantStringClassReference\n\t.long\t1992\n\t.space 4\n\t.quad\t.*\n\t.quad\t10\n" { target { *-*-darwin* && { lp64 } } } } } */ -- cgit v1.2.1