diff --git a/10.9-libcxx/stable/main/finkinfo/languages/gcc12-13.0.info b/10.9-libcxx/stable/main/finkinfo/languages/gcc12-13.0.info new file mode 100644 index 00000000000..ff3506457c0 --- /dev/null +++ b/10.9-libcxx/stable/main/finkinfo/languages/gcc12-13.0.info @@ -0,0 +1,315 @@ +Info2: << +Package: gcc12 +Version: 12.4.0 +Revision: 1 +Type: gccver (12) +Distribution: 13.0 +Source: mirror:gnu:gcc/gcc-%v/gcc-%v.tar.xz +Source-Checksum: SHA256(704f652604ccbccb14bdabf3478c9511c89788b12cb3bbffded37341916a9175) +PatchFile: %n.patch +PatchFile-MD5: cfbfeced5b822b29092e90b5c4d85456 +PatchScript: << + #!/bin/sh -ev + patch -p1 < %{PatchFile} + # don't update live infodoc dir + find . -name Makefile.in | xargs perl -pi -e 's/install-info --version/false/g' +<< +NoSetCPPFLAGS: True +NoSetLDFLAGS: True +UseMaxBuildJobs: True +Conflicts: << + gcc5, gcc6, gcc7, gcc8, + gcc9, + gcc10, + gcc11, + gcc12, + gcc13, + gcc14 +<< +Replaces: << + gcc5, gcc6, gcc7, gcc8, + gcc9, + gcc10, + gcc11, + gcc12, + gcc13, + gcc14 +<< +Depends: << + %N-compiler (= %v-%r) +<< +BuildDepends: << + fink (>= 0.32), + fink-package-precedence, + gettext-tools, + gmp5 (>= 6.1.2-1), + install-info, + isl22, + libgettext8-dev, + libiconv-dev, + libmpc3 (>= 1.0.3-1), + libmpfr6, + x11-dev +<< +ConfigureParams: << + --prefix=%p/lib/gcc%type_num[gccver] \ + --mandir=%p/share/man \ + --infodir=%p/lib/gcc%type_num[gccver]/info \ + --enable-languages=c,c++,fortran,lto,objc,obj-c++ \ + --with-gmp=%p \ + --with-libiconv-prefix=%p \ + --with-isl=%p \ + --with-mpc=%p \ + --with-system-zlib \ + --program-suffix=-fsf-%type_num[gccver] \ + --disable-multilib \ + --enable-stage1-checking \ + ${USE_SYSROOT} \ + --with-pkgversion="Fink %n %v-%r" \ + --with-bugurl="https://github.com/fink/fink-distributions/issues" +<< +InfoTest: << + TestDepends: << + autogen, + dejagnu, + ( "%m" != "arm64" ) apple-gdb + << + TestScript: << + #!/bin/bash -ev + if [ "%m" = "arm64" ]; then + echo "The gcc testsuite requires Apple's gdb, which is not available on this architecture." + exit 0 + elif [ $UID = 0 ]; then + if [ -e /usr/bin/csrutil && `csrutil status | grep -c disabled` ]; then + cd ../darwin_objdir; make -k check RUNTESTFLAGS="--target_board=unix'{-m64}'" || : + else + echo "The gcc testsuite must be run with SIP disabled or package installed." + exit 0 + fi + else + echo "The gcc testsuite must be run as root due to its use of gdb." + exit 0 + fi + << +<< +InfoDocs: gcc.info gfortran.info cpp.info gccinstall.info libgomp.info cppinternals.info gccint.info +CompileScript: << + #!/bin/bash -ev + set +x + if [ -e /usr/local/lib/libgmp.a ] || [ -e /usr/local/lib/libgmp.dylib ]; then + echo "-----WARNING-----WARNING-----WARNING-----" + echo "You seem to have GMP installed in /usr/local." + echo "This is known to cause %N to fail to build." + echo "Please move aside /usr/local and try again." + echo "-----WARNING-----WARNING-----WARNING-----" + exit 1 + else + echo "Good, /usr/local/lib/libgmp* not present." + fi + set -x + ulimit -s `ulimit -s` + mkdir ../darwin_objdir + cd ../darwin_objdir + # build doesn't play well with GNU-make + # unsupported option '-static-libgcc' + export MAKE=/usr/bin/make + # Only need sysroot on 10.14+ because /usr/include has been removed + OSX_MAJOR_VERSION=`sw_vers -productVersion | cut -d. -f1-2` + if dpkg --compare-versions "$OSX_MAJOR_VERSION" ge "10.14"; then + # Get the unversioned SDK path + SDK_PATH=`dirname $(xcrun --sdk macosx --show-sdk-path)`/MacOSX.sdk + # This should really be --with-build-sysroot but that's not getting propagated through the entire build process. + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79885 + export USE_SYSROOT="--with-sysroot=${SDK_PATH}" + fi + # check for incompatible clang ( 6.0 << bad-clang << 7.2) + clangvers=`clang --version | cut -d\ -f4` + $(`dpkg --compare-versions $clangvers '>>' 6.0`) && $(`dpkg --compare-versions $clangvers '<<' 7.2`) && clangcheck='y' + if [ "$clangcheck" = "y" ]; then + ../gcc-%v/configure %c --with-build-config=bootstrap-debug + else + ../gcc-%v/configure %c + fi + # Use bootstrap-lean to reduce disk usage. + # Note that this causes plugin testsuite failures + # since the plugin headers must come from prev-gcc. + # make bootstrap-lean + make bootstrap + fink-package-precedence --prohibit-bdep=%n . +<< +InstallScript: << + #!/bin/sh -ev + darwinvers=`uname -r` + cd ../darwin_objdir + make -j 1 install DESTDIR=%d + mkdir -p %i/bin + + # Add symlinks to recreate previous naming of executables in %p/bin + # as well as %p/lib/gcc%type_num[gccver]/bin and new -fsf-%type_num[gccver] naming in %p/bin. + binfiles="gcc g++ c++ cpp gcov" + for binfile in $binfiles ; do + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/$binfile-%type_num[gccver] + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-%type_num[gccver] + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-fsf-%type_num[gccver] + done + binfiles="gfortran" + for binfile in $binfiles ; do + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/$binfile + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-fsf-%type_num[gccver] + done + + # Remove unsupported executables + binfiles="gcc-ar gcc-nm gcc-ranlib" + for binfile in $binfiles ; do + rm -f %i/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/*-apple-darwin${darwinvers}-$binfile-fsf-%type_num[gccver] + done + + # Add symlinks for manpages under old names. + man1files="cpp g++ gcc gcov" + for man1file in $man1files ; do + ln -s $man1file-fsf-%type_num[gccver].1 %i/share/man/man1/$man1file-%type_num[gccver].1 + done + man1files="gfortran" + for man1file in $man1files ; do + ln -s $man1file-fsf-%type_num[gccver].1 %i/share/man/man1/$man1file.1 + done + + # Rename manpages with -fsf-%type_num[gccver] suffix and create symlinks to old names. + man7files="fsf-funding gfdl gpl" + for man7file in $man7files ; do + mv %i/share/man/man7/$man7file.7 %i/share/man/man7/$man7file-fsf-%type_num[gccver].7 + ln -s $man7file-fsf-%type_num[gccver].7 %i/share/man/man7/$man7file.7 + done + + # Add dir for installed info files, and link them to %i/share/info. + # the %i/lib/gcc%type_num[gccver]/info/* files will go into the -compiler package + # and the files in %i/share/info go into the main package, this allows + # the info files for specific compiler versions to be accessed with + # e.g. `info -d /fink_install_dir/lib/gcc%type_num[gccver]/info gcc', but the "main" info files will + # be available for the install gccXX package in %p/share/info, as usual + install -d -m 755 %i/share/info + for infofile in $(find %i/lib/gcc%type_num[gccver]/info -name '*.info*'); do + infobase=$(basename $infofile) + case $infofile in + *info) %p/bin/install-info --infodir=%i/lib/gcc%type_num[gccver]/info ${infofile} ;; + esac + ln -s %p/lib/gcc%type_num[gccver]/info/$infobase %i/share/info/$infobase + done + + # remove build path from .la files + perl -pi -e "s, \-L[^ ']*/%n-%v-%r/darwin_objdir/[^ ']*,,g" `find %i/lib/gcc%type_num[gccver]/lib -name '*.la'` + if [ "%m" = "arm64" ]; then + arch=aarch64 + else + arch=%m + fi + + # @rpath install_names are required for aarch64 build, but break some linked binaries + # - enforce actual install paths here; take care to update the cross-referenced dylibs. + cd %d + for dylib in .%p/lib/gcc%type_num[gccver]/lib/lib*.[0-9].dylib; do + install_name_tool -id ${dylib#.} $dylib + install_name_tool -change @rpath/libgcc_s.1.1.dylib %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib \ + -change @rpath/libstdc++.6.dylib %p/lib/gcc%type_num[gccver]/lib/libstdc++.6.dylib \ + -change @rpath/libquadmath.0.dylib %p/lib/gcc%type_num[gccver]/lib/libquadmath.0.dylib $dylib + done + otool -L .%p/lib/gcc%type_num[gccver]/lib/lib*.[0-9].dylib | grep '@rpath' && exit 2 + + cp %b/gcc/config/darwin-sections.def %i/lib/gcc%type_num[gccver]/lib/gcc/${arch}-apple-darwin${darwinvers}/%v/plugin/include/config +<< +SplitOff: << + Package: %N-shlibs + Replaces: << + gcc4 (<= 20050130-4), + gfortran-shlibs + << + Provides: << + gfortran-shlibs + << + Description: Shared libraries for %N + DocFiles: gcc/COPYING gcc/COPYING.LIB + Files: << + lib/gcc%type_num[gccver]/lib/libgfortran.5*.dylib + lib/gcc%type_num[gccver]/lib/libstdc++.6*.dylib + lib/gcc%type_num[gccver]/lib/libgcc_s.1*.dylib + lib/gcc%type_num[gccver]/lib/libitm.1*.dylib + lib/gcc%type_num[gccver]/lib/libssp.0*.dylib + lib/gcc%type_num[gccver]/lib/libobjc-gnu.4*.dylib + lib/gcc%type_num[gccver]/lib/libgomp.1*.dylib + lib/gcc%type_num[gccver]/lib/libquadmath.0*.dylib + lib/gcc%type_num[gccver]/lib/libatomic.1*.dylib + << + Shlibs: << + %p/lib/gcc%type_num[gccver]/lib/libgfortran.5.dylib 6.0.0 %n (>= 12.0.0-1) + %p/lib/gcc%type_num[gccver]/lib/libstdc++.6.dylib 7.0.0 %n (>= 12.0.0-1) + ( "%m" = "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib 1.0.0 %n (>= 12.0.0-1) + ( "%m" != "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.dylib 1.0.0 %n (>= 12.0.0-1) + ( "%m" != "arm64" ) !%p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib + %p/lib/gcc%type_num[gccver]/lib/libitm.1.dylib 2.0.0 %n (>= 12.0.0-1) + %p/lib/gcc%type_num[gccver]/lib/libssp.0.dylib 1.0.0 %n (>= 12.0.0-1) + %p/lib/gcc%type_num[gccver]/lib/libobjc-gnu.4.dylib 5.0.0 %n (>= 12.0.0-1) + %p/lib/gcc%type_num[gccver]/lib/libgomp.1.dylib 2.0.0 %n (>= 12.0.0-1) + %p/lib/gcc%type_num[gccver]/lib/libquadmath.0.dylib 1.0.0 %n (>= 12.0.0-1) + %p/lib/gcc%type_num[gccver]/lib/libatomic.1.dylib 4.0.0 %n (>= 12.0.0-1) + << +<< +SplitOff2: << + Package: %N-compiler + Depends: << + gmp5-shlibs (>= 6.1.2-1), + isl22-shlibs, + libgettext8-shlibs, + libgmpxx5-shlibs (>= 6.1.2-1), + libiconv, + libmpc3-shlibs (>= 1.0.3-1), + libmpfr6-shlibs, + %N-shlibs (= %v-%r) + << + BuildDependsOnly: False + Description: Compiler Binaries for gcc%type_num[gccver] + DocFiles: gcc/COPYING gcc/COPYING.LIB gcc/ChangeLog gcc/ABOUT-GCC-NLS gcc/README.Portability + Files: << + bin/*-fsf-%type_num[gccver] + lib/gcc%type_num[gccver] + share/man/man1/*-fsf-%type_num[gccver].1 + share/man/man7/*-fsf-%type_num[gccver].7 + << +<< +License: GPL +Description: GNU Compiler Collection Version %type_num[gccver] +DescDetail: << + GCC, the GNU Compiler Collection, includes front ends for + C, C++, Objective-C, Objective-C++, Fortran and Ada. + . + C, C++, Objective C and Fortran are included in this package. + . + The C and C++ compilers are named gcc-12 and g++-12 to avoid + conflicts with gcc and g++ installed by the Apple Developer Tools. +<< +DescPackaging: << + Build with -fsf-%type_num[gccver] suffix and place non-overlapping files into new gcc%type_num[gccver]-compiler + package which can co-exist with other gccXX-compiler packages. Overlapping files + are left in main gcc%type_num[gccver] package which still conflicts with other gccXX packages. + + macOS10.14 no longer supports building 32bit libraries, so must disable multilib. + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87030 + + We use --with-sysroot to find the hidden system-headers in case /usr/include is not + populated. Ideally want --with-build-sysroot because we only need the headers to build + gcc and that should not impact the end product, but then anything using gccX will + need to add it's own -isysroot flag. + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79885 + + Homebrew patches for arm64/aarch64 build and macOS 13 from + https://github.com/Homebrew/formula-patches/blob/master/gcc/gcc-%v.diff + - libasan.* and libsubsan.* currently not built on darwin22+ - see + https://github.com/iains/gcc-darwin-arm64/commit/e722a1f4 + and missing from the 13.0 package until resolved. + There are both "1" and "1.1" versions of libgcc_s.dylib now, but only "1.1" on arm64. + Manual fixes of @rpath install_names required for aarch64 build to maintain downstream + package compatibility. +<< +Homepage: http://gcc.gnu.org/ +Maintainer: None +<< diff --git a/10.9-libcxx/stable/main/finkinfo/languages/gcc12-arm.patch b/10.9-libcxx/stable/main/finkinfo/languages/gcc12-arm.patch deleted file mode 100644 index bcaade28c15..00000000000 --- a/10.9-libcxx/stable/main/finkinfo/languages/gcc12-arm.patch +++ /dev/null @@ -1,14243 +0,0 @@ -diff --git a/Makefile.def b/Makefile.def -index 72d58549645..25b8563a808 100644 ---- a/Makefile.def -+++ b/Makefile.def -@@ -47,7 +47,8 @@ host_modules= { module= fixincludes; bootstrap=true; - host_modules= { module= flex; no_check_cross= true; }; - host_modules= { module= gas; bootstrap=true; }; - host_modules= { module= gcc; bootstrap=true; -- extra_make_flags="$(EXTRA_GCC_FLAGS)"; }; -+ extra_make_flags="$(EXTRA_GCC_FLAGS)"; -+ extra_configure_flags='--enable-pie-tools=@enable_pie_tools@'; }; - host_modules= { module= gmp; lib_path=.libs; bootstrap=true; - // Work around in-tree gmp configure bug with missing flex. - extra_configure_flags='--disable-shared LEX="touch lex.yy.c"'; -diff --git a/Makefile.in b/Makefile.in -index 593495e1650..807c5947895 100644 ---- a/Makefile.in -+++ b/Makefile.in -@@ -112,6 +112,9 @@ GCC_SHLIB_SUBDIR = @GCC_SHLIB_SUBDIR@ - # If the build should make suitable code for shared host resources. - host_shared = @host_shared@ - -+# If we should build compilers and supporting tools as PIE. -+enable_pie_tools = @enable_pie_tools@ -+ - # Build programs are put under this directory. - BUILD_SUBDIR = @build_subdir@ - # This is set by the configure script to the arguments to use when configuring -@@ -12012,7 +12015,7 @@ configure-gcc: - $$s/$$module_srcdir/configure \ - --srcdir=$${topdir}/$$module_srcdir \ - $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ -- --target=${target_alias} \ -+ --target=${target_alias} --enable-pie-tools=@enable_pie_tools@ \ - || exit 1 - @endif gcc - -@@ -12047,7 +12050,8 @@ configure-stage1-gcc: - $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ - --target=${target_alias} \ - \ -- $(STAGE1_CONFIGURE_FLAGS) -+ $(STAGE1_CONFIGURE_FLAGS) \ -+ --enable-pie-tools=@enable_pie_tools@ - @endif gcc-bootstrap - - .PHONY: configure-stage2-gcc maybe-configure-stage2-gcc -@@ -12080,7 +12084,8 @@ configure-stage2-gcc: - $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ - --target=${target_alias} \ - --with-build-libsubdir=$(HOST_SUBDIR) \ -- $(STAGE2_CONFIGURE_FLAGS) -+ $(STAGE2_CONFIGURE_FLAGS) \ -+ --enable-pie-tools=@enable_pie_tools@ - @endif gcc-bootstrap - - .PHONY: configure-stage3-gcc maybe-configure-stage3-gcc -@@ -12113,7 +12118,8 @@ configure-stage3-gcc: - $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ - --target=${target_alias} \ - --with-build-libsubdir=$(HOST_SUBDIR) \ -- $(STAGE3_CONFIGURE_FLAGS) -+ $(STAGE3_CONFIGURE_FLAGS) \ -+ --enable-pie-tools=@enable_pie_tools@ - @endif gcc-bootstrap - - .PHONY: configure-stage4-gcc maybe-configure-stage4-gcc -@@ -12146,7 +12152,8 @@ configure-stage4-gcc: - $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ - --target=${target_alias} \ - --with-build-libsubdir=$(HOST_SUBDIR) \ -- $(STAGE4_CONFIGURE_FLAGS) -+ $(STAGE4_CONFIGURE_FLAGS) \ -+ --enable-pie-tools=@enable_pie_tools@ - @endif gcc-bootstrap - - .PHONY: configure-stageprofile-gcc maybe-configure-stageprofile-gcc -@@ -12179,7 +12186,8 @@ configure-stageprofile-gcc: - $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ - --target=${target_alias} \ - --with-build-libsubdir=$(HOST_SUBDIR) \ -- $(STAGEprofile_CONFIGURE_FLAGS) -+ $(STAGEprofile_CONFIGURE_FLAGS) \ -+ --enable-pie-tools=@enable_pie_tools@ - @endif gcc-bootstrap - - .PHONY: configure-stagetrain-gcc maybe-configure-stagetrain-gcc -@@ -12212,7 +12220,8 @@ configure-stagetrain-gcc: - $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ - --target=${target_alias} \ - --with-build-libsubdir=$(HOST_SUBDIR) \ -- $(STAGEtrain_CONFIGURE_FLAGS) -+ $(STAGEtrain_CONFIGURE_FLAGS) \ -+ --enable-pie-tools=@enable_pie_tools@ - @endif gcc-bootstrap - - .PHONY: configure-stagefeedback-gcc maybe-configure-stagefeedback-gcc -@@ -12245,7 +12254,8 @@ configure-stagefeedback-gcc: - $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ - --target=${target_alias} \ - --with-build-libsubdir=$(HOST_SUBDIR) \ -- $(STAGEfeedback_CONFIGURE_FLAGS) -+ $(STAGEfeedback_CONFIGURE_FLAGS) \ -+ --enable-pie-tools=@enable_pie_tools@ - @endif gcc-bootstrap - - .PHONY: configure-stageautoprofile-gcc maybe-configure-stageautoprofile-gcc -@@ -12278,7 +12288,8 @@ configure-stageautoprofile-gcc: - $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ - --target=${target_alias} \ - --with-build-libsubdir=$(HOST_SUBDIR) \ -- $(STAGEautoprofile_CONFIGURE_FLAGS) -+ $(STAGEautoprofile_CONFIGURE_FLAGS) \ -+ --enable-pie-tools=@enable_pie_tools@ - @endif gcc-bootstrap - - .PHONY: configure-stageautofeedback-gcc maybe-configure-stageautofeedback-gcc -@@ -12311,7 +12322,8 @@ configure-stageautofeedback-gcc: - $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ - --target=${target_alias} \ - --with-build-libsubdir=$(HOST_SUBDIR) \ -- $(STAGEautofeedback_CONFIGURE_FLAGS) -+ $(STAGEautofeedback_CONFIGURE_FLAGS) \ -+ --enable-pie-tools=@enable_pie_tools@ - @endif gcc-bootstrap - - -diff --git a/Makefile.tpl b/Makefile.tpl -index ef58fac2b9a..925da105c18 100644 ---- a/Makefile.tpl -+++ b/Makefile.tpl -@@ -115,6 +115,9 @@ GCC_SHLIB_SUBDIR = @GCC_SHLIB_SUBDIR@ - # If the build should make suitable code for shared host resources. - host_shared = @host_shared@ - -+# If we should build compilers and supporting tools as PIE. -+enable_pie_tools = @enable_pie_tools@ -+ - # Build programs are put under this directory. - BUILD_SUBDIR = @build_subdir@ - # This is set by the configure script to the arguments to use when configuring -diff --git a/config/mh-darwin b/config/mh-darwin -index b72835ae953..bb4112773c9 100644 ---- a/config/mh-darwin -+++ b/config/mh-darwin -@@ -11,7 +11,8 @@ - # non-bootstrapped compiler), later stages will be built by GCC which supports - # the required flags. - --# We cannot use mdynamic-no-pic when building shared host resources. -+# We cannot use mdynamic-no-pic when building shared host resources, or for PIE -+# tool executables, which also enables host-shared. - - ifeq (${host_shared},no) - BOOTSTRAP_TOOL_CAN_USE_MDYNAMIC_NO_PIC := $(shell \ -diff --git a/configure b/configure -index 5dcaab14ae9..c690bbec82b 100755 ---- a/configure -+++ b/configure -@@ -685,6 +685,7 @@ get_gcc_base_ver - extra_host_zlib_configure_flags - extra_host_libiberty_configure_flags - stage1_languages -+enable_pie_tools - host_shared - extra_linker_plugin_flags - extra_linker_plugin_configure_flags -@@ -830,6 +831,7 @@ enable_lto - enable_linker_plugin_configure_flags - enable_linker_plugin_flags - enable_host_shared -+enable_pie_tools - enable_stage1_languages - enable_objc_gc - with_target_bdw_gc -@@ -1558,6 +1560,8 @@ Optional Features: - additional flags for configuring and building linker - plugins [none] - --enable-host-shared build host code as shared libraries -+ --enable-pie-tools build Position Independent Executables for the -+ compilers and other tools - --enable-stage1-languages[=all] - choose additional languages to build during stage1. - Mostly useful for compiler development -@@ -8410,6 +8414,20 @@ else - fi - fi - -+case $target in -+ *-darwin2* | *-darwin1[56789]*) -+ # For these versions, we default to using embedded rpaths. -+ if test "x$enable_darwin_at_rpath" != "xno"; then -+ poststage1_ldflags="$poststage1_ldflags -nodefaultrpaths" -+ fi -+ ;; -+ *-darwin*) -+ # For these versions, we only use embedded rpaths on demand. -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ poststage1_ldflags="$poststage1_ldflags -nodefaultrpaths" -+ fi -+ ;; -+esac - - - # GCC GRAPHITE dependency isl. -@@ -8663,6 +8681,42 @@ else - fi - - -+# Check whether --enable-pie-tools was given. -+# Checked early because it can affect host make fragments. -+# Check whether --enable-pie-tools was given. -+if test "${enable_pie_tools+set}" = set; then : -+ enableval=$enable_pie_tools; enable_pie_tools=$enableval -+ case $target in -+ aarch64-*-darwin1[1-9]*) -+ if test x$enable_pie_tools != xyes ; then -+ echo configure.ac: warning: aarch64-darwin must use PIE, pie-tools setting ignored. 1>&2 -+ enable_pie_tools=yes -+ host_shared=yes -+ fi ;; -+ *) ;; -+ esac -+else -+ case $target in -+ # PIE is the default for macOS 10.7+ so reflect that in the configure. -+ # However, we build 32b toolchains mdynamic-no-pic by default which is -+ # not compatible with PIE. -+ x86_64-*-darwin1[1-9]* | *-*-darwin2*) enable_pie_tools=yes ;; -+ *) enable_pie_tools=no ;; -+ esac -+fi -+ -+ -+case $target in -+ *-*-darwin*) -+ if test x$enable_pie_tools = xyes && test x$host_shared != xyes ; then -+ echo configure.ac: warning: for Darwin PIE requires PIC code, switching host-shared on 1>&2 -+ host_shared=yes -+ fi ;; -+ *) ;; -+esac -+ -+ -+ - - # By default, C and C++ are the only stage 1 languages. - stage1_languages=,c, -diff --git a/configure.ac b/configure.ac -index 85977482aee..72bd20fda66 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -1827,6 +1827,20 @@ AC_ARG_WITH(boot-ldflags, - if test "$poststage1_libs" = ""; then - poststage1_ldflags="-static-libstdc++ -static-libgcc" - fi]) -+case $target in -+ *-darwin2* | *-darwin1[[56789]]*) -+ # For these versions, we default to using embedded rpaths. -+ if test "x$enable_darwin_at_rpath" != "xno"; then -+ poststage1_ldflags="$poststage1_ldflags -nodefaultrpaths" -+ fi -+ ;; -+ *-darwin*) -+ # For these versions, we only use embedded rpaths on demand. -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ poststage1_ldflags="$poststage1_ldflags -nodefaultrpaths" -+ fi -+ ;; -+esac - AC_SUBST(poststage1_ldflags) - - # GCC GRAPHITE dependency isl. -@@ -1931,7 +1945,41 @@ AC_ARG_ENABLE(host-shared, - x86_64-*-darwin* | aarch64-*-darwin*) host_shared=yes ;; - *) host_shared=no ;; - esac]) -+ -+# Check whether --enable-pie-tools was given. -+# Checked early because it can affect host make fragments. -+AC_ARG_ENABLE(pie-tools, -+[AS_HELP_STRING([--enable-pie-tools], -+ [build Position Independent Executables for the compilers and other tools])], -+[enable_pie_tools=$enableval -+ case $target in -+ aarch64-*-darwin1[[1-9]]*) -+ if test x$enable_pie_tools != xyes ; then -+ echo configure.ac: warning: aarch64-darwin must use PIE, pie-tools setting ignored. 1>&2 -+ enable_pie_tools=yes -+ host_shared=yes -+ fi ;; -+ *) ;; -+ esac], -+[case $target in -+ # PIE is the default for macOS 10.7+ so reflect that in the configure. -+ # However, we build 32b toolchains mdynamic-no-pic by default which is -+ # not compatible with PIE. -+ x86_64-*-darwin1[[1-9]]* | *-*-darwin2*) enable_pie_tools=yes ;; -+ *) enable_pie_tools=no ;; -+ esac]) -+ -+case $target in -+ *-*-darwin*) -+ if test x$enable_pie_tools = xyes && test x$host_shared != xyes ; then -+ echo configure.ac: warning: for Darwin PIE requires PIC code, switching host-shared on 1>&2 -+ host_shared=yes -+ fi ;; -+ *) ;; -+esac -+ - AC_SUBST(host_shared) -+AC_SUBST([enable_pie_tools]) - - # By default, C and C++ are the only stage 1 languages. - stage1_languages=,c, -diff --git a/contrib/compare-debug b/contrib/compare-debug -index cf80ae32695..678a897c931 100755 ---- a/contrib/compare-debug -+++ b/contrib/compare-debug -@@ -60,9 +60,19 @@ trap 'rm -f "$1.$suf1" "$2.$suf2"' 0 1 2 15 - case `uname -s` in - Darwin) - # The strip command on darwin does not remove all debug info. -- # Fortunately, we can use ld to do it instead. -- ld -S -r -no_uuid "$1" -o "$1.$suf1" -- ld -S -r -no_uuid "$2" -o "$2.$suf2" -+ # Fortunately, we can use ld to do it instead, but even ld on earlier -+ # system versions can be fussy about what it finds - make sure we use -+ # a ld that understands coalesced sections. -+ case `uname -r` in -+ 8*) -+ ld64 -S -r -no_uuid "$1" -o "$1.$suf1" -+ ld64 -S -r -no_uuid "$2" -o "$2.$suf2" -+ ;; -+ *) -+ ld -S -r -no_uuid "$1" -o "$1.$suf1" -+ ld -S -r -no_uuid "$2" -o "$2.$suf2" -+ ;; -+ esac - ;; - *) - cp "$1" "$1.$suf1" -diff --git a/fixincludes/configure b/fixincludes/configure -index 6e2d67b655b..b3bca666a4d 100755 ---- a/fixincludes/configure -+++ b/fixincludes/configure -@@ -2644,7 +2644,7 @@ ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. - - # _LT_DARWIN_LINKER_FEATURES - # -------------------------- --# Checks for linker and compiler features on darwin -+# Checks for linker and compiler features on Darwin / macOS / iOS - - - # _LT_SYS_MODULE_PATH_AIX -diff --git a/gcc/Makefile.in b/gcc/Makefile.in -index 31ff95500c9..255a10c2ce8 100644 ---- a/gcc/Makefile.in -+++ b/gcc/Makefile.in -@@ -270,11 +270,15 @@ COMPILER += $(CET_HOST_FLAGS) - NO_PIE_CFLAGS = @NO_PIE_CFLAGS@ - NO_PIE_FLAG = @NO_PIE_FLAG@ - --# We don't want to compile the compilers with -fPIE, it make PCH fail. -+ifneq (@enable_pie_tools@,yes) -+# Build and link the compilers and tools without PIE. - COMPILER += $(NO_PIE_CFLAGS) -- --# Link with -no-pie since we compile the compiler with -fno-PIE. - LINKER += $(NO_PIE_FLAG) -+else -+# FIXME these need to be configured. -+COMPILER += -fPIE -+LINKER += -pie -+endif - - # Like LINKER, but use a mutex for serializing front end links. - ifeq (@DO_LINK_MUTEX@,true) -@@ -407,6 +411,7 @@ ifeq ($(enable_plugin),yes) - endif - - enable_host_shared = @enable_host_shared@ -+enable_default_pie = @enable_default_pie@ - - enable_as_accelerator = @enable_as_accelerator@ - -@@ -1153,6 +1158,8 @@ LANG_MAKEFRAGS = @all_lang_makefrags@ - # Used by gcc/jit/Make-lang.in - LD_VERSION_SCRIPT_OPTION = @ld_version_script_option@ - LD_SONAME_OPTION = @ld_soname_option@ -+@ENABLE_DARWIN_AT_RPATH_TRUE@DARWIN_RPATH = @rpath -+@ENABLE_DARWIN_AT_RPATH_FALSE@DARWIN_RPATH = ${libdir} - - # Flags to pass to recursive makes. - # CC is set by configure. -@@ -1942,9 +1949,12 @@ cs-tconfig.h: Makefile - $(SHELL) $(srcdir)/mkconfig.sh tconfig.h - - cs-tm.h: Makefile -- TARGET_CPU_DEFAULT="$(target_cpu_default)" \ -- HEADERS="$(tm_include_list)" DEFINES="$(tm_defines)" \ -- $(SHELL) $(srcdir)/mkconfig.sh tm.h -+@ENABLE_DARWIN_AT_RPATH_FALSE@ TARGET_CPU_DEFAULT="$(target_cpu_default)" \ -+@ENABLE_DARWIN_AT_RPATH_FALSE@ HEADERS="$(tm_include_list)" DEFINES="$(tm_defines)" \ -+@ENABLE_DARWIN_AT_RPATH_FALSE@ $(SHELL) $(srcdir)/mkconfig.sh tm.h -+@ENABLE_DARWIN_AT_RPATH_TRUE@ TARGET_CPU_DEFAULT="$(target_cpu_default)" \ -+@ENABLE_DARWIN_AT_RPATH_TRUE@ HEADERS="$(tm_include_list)" DEFINES="$(tm_defines) DARWIN_AT_RPATH=1" \ -+@ENABLE_DARWIN_AT_RPATH_TRUE@ $(SHELL) $(srcdir)/mkconfig.sh tm.h - - cs-tm_p.h: Makefile - TARGET_CPU_DEFAULT="" \ -@@ -4116,6 +4126,9 @@ site.exp: ./config.status Makefile - echo "set COMPAT_OPTIONS \"$(COMPAT_OPTIONS)\"" >> ./site.tmp; \ - else true; \ - fi -+ @if test "x@enable_darwin_at_rpath@" = "xyes" ; then \ -+ echo "set ENABLE_DARWIN_AT_RPATH 1" >> ./site.tmp; \ -+ fi - @echo "## All variables above are generated by configure. Do Not Edit ##" >> ./site.tmp - @cat ./site.tmp > site.exp - @cat site.bak | sed \ -diff --git a/gcc/aclocal.m4 b/gcc/aclocal.m4 -index 6be36df5190..126e09bbcd1 100644 ---- a/gcc/aclocal.m4 -+++ b/gcc/aclocal.m4 -@@ -12,6 +12,56 @@ - # PARTICULAR PURPOSE. - - m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])]) -+# AM_CONDITIONAL -*- Autoconf -*- -+ -+# Copyright (C) 1997-2017 Free Software Foundation, Inc. -+# -+# This file is free software; the Free Software Foundation -+# gives unlimited permission to copy and/or distribute it, -+# with or without modifications, as long as this notice is preserved. -+ -+# AM_CONDITIONAL(NAME, SHELL-CONDITION) -+# ------------------------------------- -+# Define a conditional. -+AC_DEFUN([AM_CONDITIONAL], -+[AC_PREREQ([2.52])dnl -+ m4_if([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], -+ [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl -+AC_SUBST([$1_TRUE])dnl -+AC_SUBST([$1_FALSE])dnl -+_AM_SUBST_NOTMAKE([$1_TRUE])dnl -+_AM_SUBST_NOTMAKE([$1_FALSE])dnl -+m4_define([_AM_COND_VALUE_$1], [$2])dnl -+if $2; then -+ $1_TRUE= -+ $1_FALSE='#' -+else -+ $1_TRUE='#' -+ $1_FALSE= -+fi -+AC_CONFIG_COMMANDS_PRE( -+[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then -+ AC_MSG_ERROR([[conditional "$1" was never defined. -+Usually this means the macro was only invoked conditionally.]]) -+fi])]) -+ -+# Copyright (C) 2006-2017 Free Software Foundation, Inc. -+# -+# This file is free software; the Free Software Foundation -+# gives unlimited permission to copy and/or distribute it, -+# with or without modifications, as long as this notice is preserved. -+ -+# _AM_SUBST_NOTMAKE(VARIABLE) -+# --------------------------- -+# Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in. -+# This macro is traced by Automake. -+AC_DEFUN([_AM_SUBST_NOTMAKE]) -+ -+# AM_SUBST_NOTMAKE(VARIABLE) -+# -------------------------- -+# Public sister of _AM_SUBST_NOTMAKE. -+AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)]) -+ - m4_include([../libtool.m4]) - m4_include([../ltoptions.m4]) - m4_include([../ltsugar.m4]) -diff --git a/gcc/ada/Makefile.rtl b/gcc/ada/Makefile.rtl -index aaf853e3a2a..b20218310f3 100644 ---- a/gcc/ada/Makefile.rtl -+++ b/gcc/ada/Makefile.rtl -@@ -2822,6 +2822,15 @@ ifeq ($(strip $(filter-out darwin%,$(target_os))),) - TOOLS_TARGET_PAIRS = indepsw.adb 8 * 1024 * 1024) -+ { -+ emit_move_insn (tmp_reg, gen_rtx_HIGH (mode, sym)); -+ emit_insn (gen_add_losym (dest, tmp_reg, sym)); -+ /* FIXME: add the SI option if/when we support ilp32. */ -+ emit_insn (gen_adddi3 (dest, dest, off)); -+ return; -+ } -+ /* else small enough positive offset is OK. */ -+ } - emit_move_insn (tmp_reg, gen_rtx_HIGH (mode, copy_rtx (imm))); - emit_insn (gen_add_losym (dest, tmp_reg, imm)); - return; -@@ -4598,6 +4621,7 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm, - return; - } - -+ case SYMBOL_MO_SMALL_GOT: - case SYMBOL_SMALL_GOT_4G: - emit_insn (gen_rtx_SET (dest, imm)); - return; -@@ -6659,6 +6683,7 @@ aarch64_expand_mov_immediate (rtx dest, rtx imm) - case SYMBOL_SMALL_TLSIE: - case SYMBOL_SMALL_GOT_28K: - case SYMBOL_SMALL_GOT_4G: -+ case SYMBOL_MO_SMALL_GOT: - case SYMBOL_TINY_GOT: - case SYMBOL_TINY_TLSIE: - if (const_offset != 0) -@@ -6672,6 +6697,7 @@ aarch64_expand_mov_immediate (rtx dest, rtx imm) - /* FALLTHRU */ - - case SYMBOL_SMALL_ABSOLUTE: -+ case SYMBOL_MO_SMALL_PCR: - case SYMBOL_TINY_ABSOLUTE: - case SYMBOL_TLSLE12: - case SYMBOL_TLSLE24: -@@ -7251,6 +7277,7 @@ aarch64_return_in_memory (const_tree type, const_tree fndecl ATTRIBUTE_UNUSED) - gcc_unreachable (); - } - -+#if !TARGET_MACHO - static bool - aarch64_vfp_is_call_candidate (cumulative_args_t pcum_v, machine_mode mode, - const_tree type, int *nregs) -@@ -7260,6 +7287,7 @@ aarch64_vfp_is_call_candidate (cumulative_args_t pcum_v, machine_mode mode, - &pcum->aapcs_vfp_rmode, - nregs, NULL, pcum->silent_p); - } -+#endif - - /* Given MODE and TYPE of a function argument, return the alignment in - bits. The idea is to suppress any stronger alignment requested by -@@ -7343,6 +7371,13 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) - return; - - pcum->aapcs_arg_processed = true; -+ if (TARGET_MACHO) -+ { -+ /* Set suitable defaults for queries. */ -+ pcum->darwinpcs_arg_boundary -+ = aarch64_function_arg_alignment (mode, type, &abi_break); -+ pcum->darwinpcs_arg_padding = BITS_PER_UNIT; -+ } - - pure_scalable_type_info pst_info; - if (type && pst_info.analyze_registers (type)) -@@ -7399,13 +7434,29 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) - /* No frontends can create types with variable-sized modes, so we - shouldn't be asked to pass or return them. */ - size = GET_MODE_SIZE (mode).to_constant (); -+ -+ if (TARGET_MACHO) -+ /* Since we can pack things on the stack, we need the unrounded size. */ -+ pcum->darwinpcs_stack_bytes = size; -+ - size = ROUND_UP (size, UNITS_PER_WORD); - - allocate_ncrn = (type) ? !(FLOAT_TYPE_P (type)) : !FLOAT_MODE_P (mode); -+ bool is_ha = false; -+#if !TARGET_MACHO - allocate_nvrn = aarch64_vfp_is_call_candidate (pcum_v, - mode, - type, - &nregs); -+#else -+ /* We care if the value is a homogenous aggregate when laying out the stack, -+ so use this call directly. */ -+ allocate_nvrn -+ = aarch64_vfp_is_call_or_return_candidate (mode, type, -+ &pcum->aapcs_vfp_rmode, -+ &nregs, &is_ha, -+ pcum->silent_p); -+#endif - gcc_assert (!sve_p || !allocate_nvrn); - - /* allocate_ncrn may be false-positive, but allocate_nvrn is quite reliable. -@@ -7420,7 +7471,13 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) - if (!pcum->silent_p && !TARGET_FLOAT) - aarch64_err_no_fpadvsimd (mode); - -- if (nvrn + nregs <= NUM_FP_ARG_REGS) -+ if (TARGET_MACHO -+ && !arg.named) -+ { -+ pcum->aapcs_nextnvrn = NUM_FP_ARG_REGS; -+ goto on_stack; -+ } -+ else if (nvrn + nregs <= NUM_FP_ARG_REGS) - { - pcum->aapcs_nextnvrn = nvrn + nregs; - if (!aarch64_composite_type_p (type, mode)) -@@ -7450,6 +7507,7 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) - } - pcum->aapcs_reg = par; - } -+ pcum->darwinpcs_stack_bytes = 0; - return; - } - else -@@ -7466,10 +7524,18 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) - /* C6 - C9. though the sign and zero extension semantics are - handled elsewhere. This is the case where the argument fits - entirely general registers. */ -+ - if (allocate_ncrn && (ncrn + nregs <= NUM_ARG_REGS)) - { - gcc_assert (nregs == 0 || nregs == 1 || nregs == 2); - -+ if (TARGET_MACHO -+ && !arg.named) -+ { -+ pcum->aapcs_nextncrn = NUM_ARG_REGS; -+ goto on_stack; -+ } -+ - /* C.8 if the argument has an alignment of 16 then the NGRN is - rounded up to the next even number. */ - if (nregs == 2 -@@ -7479,7 +7545,9 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) - alignment nregs should be > 2 and therefore it should be - passed by reference rather than value. */ - && (aarch64_function_arg_alignment (mode, type, &abi_break) -- == 16 * BITS_PER_UNIT)) -+ == 16 * BITS_PER_UNIT) -+ /* Darwin PCS deletes rule C.8. */ -+ && !TARGET_MACHO) - { - if (abi_break && warn_psabi && currently_expanding_gimple_stmt) - inform (input_location, "parameter passing for argument of type " -@@ -7525,8 +7593,8 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) - } - pcum->aapcs_reg = par; - } -- - pcum->aapcs_nextncrn = ncrn + nregs; -+ pcum->darwinpcs_stack_bytes = 0; - return; - } - -@@ -7536,10 +7604,87 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) - /* The argument is passed on stack; record the needed number of words for - this argument and align the total size if necessary. */ - on_stack: -- pcum->aapcs_stack_words = size / UNITS_PER_WORD; - -- if (aarch64_function_arg_alignment (mode, type, &abi_break) -- == 16 * BITS_PER_UNIT) -+ unsigned int align = aarch64_function_arg_alignment (mode, type, &abi_break); -+ -+ if (TARGET_MACHO) -+ { -+ /* Darwin does not round up the allocation for smaller entities to 8 -+ bytes. It only requires the natural alignment for these. -+ -+ but we don't do this for: -+ * unnamed parms in variadic functions -+ * complex types -+ * unions -+ * aggregates (except for homogeneous ones which are handles as the -+ enclosed type). -+ each entry starts a new slot. -+ -+ 16 byte entities are naturally aligned on the stack. -+ There was no darwinpcs for GCC 9, so neither the implementation -+ change nor the warning should fire here (i.e. we do not need to check -+ if 16byte entities alter the stack size). */ -+ -+gcc_checking_assert (arg.named == pcum->named_p); -+ pcum->darwinpcs_arg_padding = BITS_PER_UNIT; -+ if (!pcum->named_p -+ || TREE_CODE (type) == COMPLEX_TYPE -+ || (TREE_CODE (type) == RECORD_TYPE -+ && !is_ha && !SCALAR_FLOAT_MODE_P (pcum->aapcs_vfp_rmode)) -+ || TREE_CODE (type) == UNION_TYPE) -+ { -+ pcum->aapcs_stack_words = size / UNITS_PER_WORD; -+ pcum->darwinpcs_sub_word_offset = 0; -+ pcum->darwinpcs_sub_word_pos = 0; -+ pcum->darwinpcs_arg_boundary = MAX (align, PARM_BOUNDARY); -+ if (!pcum->named_p) -+ pcum->darwinpcs_arg_padding = PARM_BOUNDARY; -+ return; -+ } -+ -+ /* Updated sub-word offset aligned for the new object. -+ We are looking for the case that the new object will fit after some -+ existing object(s) in the same stack slot. In that case, we do not -+ need to add any more stack space for it. */ -+ int new_off -+ = ROUND_UP (pcum->darwinpcs_sub_word_pos, align / BITS_PER_UNIT); -+ -+ if (new_off >= UNITS_PER_WORD) -+ { -+ /* That exceeds a stack slot, start a new one. */ -+ pcum->darwinpcs_sub_word_offset = 0; -+ pcum->darwinpcs_sub_word_pos = 0; -+ new_off = 0; -+ } -+ /* This is the end of the new object. */ -+ int new_pos = new_off + pcum->darwinpcs_stack_bytes; -+ -+ if (pcum->darwinpcs_sub_word_pos == 0) -+ /* New stack slot, just allocate one or more words, and note where -+ the next arg will start. */ -+ pcum->aapcs_stack_words = size / UNITS_PER_WORD; -+ else if (new_pos <= UNITS_PER_WORD) -+ /* Old stack slot, object starts at new_off and goes to new_pos, we do -+ not add any stack space. */ -+ pcum->darwinpcs_sub_word_offset = new_off; -+ pcum->darwinpcs_sub_word_pos = new_pos; -+ pcum->darwinpcs_arg_boundary = align; -+ if (pcum->last_named_p && new_pos > 0) -+ { -+ /* Round the last named arg to the start of the next stack slot. */ -+ if (new_pos <= 4) -+ pcum->darwinpcs_arg_padding = PARM_BOUNDARY; -+ else if (new_pos <= 6) -+ pcum->darwinpcs_arg_padding = 4 * BITS_PER_UNIT; -+ else if (pcum->darwinpcs_sub_word_pos <= 7) -+ pcum->darwinpcs_arg_padding = 2 * BITS_PER_UNIT; -+ } -+ return; -+ } -+ -+ /* size was already rounded up to PARM_BOUNDARY. */ -+ pcum->aapcs_stack_words = size / UNITS_PER_WORD; -+ if (align == 16 * BITS_PER_UNIT) - { - int new_size = ROUND_UP (pcum->aapcs_stack_size, 16 / UNITS_PER_WORD); - if (pcum->aapcs_stack_size != new_size) -@@ -7592,7 +7737,28 @@ aarch64_init_cumulative_args (CUMULATIVE_ARGS *pcum, - pcum->aapcs_arg_processed = false; - pcum->aapcs_stack_words = 0; - pcum->aapcs_stack_size = 0; -+ pcum->darwinpcs_stack_bytes = 0; -+ pcum->darwinpcs_sub_word_offset = 0; -+ pcum->darwinpcs_sub_word_pos = 0; -+ pcum->darwinpcs_arg_boundary = BITS_PER_UNIT; -+ pcum->darwinpcs_arg_padding = BITS_PER_UNIT; -+ /* If we have been invoked for incoming args, then n_named will have been -+ set to -1, but we should have a function decl - so pick up the named -+ count from that. If that fails, and we end up with -1, this effectively -+ corresponds to assuming that there is an arbitrary number of named -+ args. */ -+ pcum->darwinpcs_n_named = n_named; -+ if (n_named == (unsigned)-1 && fndecl) -+ { -+ tree fnt = TREE_TYPE (fndecl); -+ if (fnt && TYPE_ARG_TYPES (fnt)) -+ pcum->darwinpcs_n_named = list_length (TYPE_ARG_TYPES (fnt)); -+ } -+ pcum->darwinpcs_n_args_processed = 0; -+ pcum->named_p = pcum->darwinpcs_n_named != 0; -+ pcum->last_named_p = pcum->darwinpcs_n_named == 1; - pcum->silent_p = silent_p; -+ pcum->aapcs_vfp_rmode = VOIDmode; - - if (!silent_p - && !TARGET_FLOAT -@@ -7631,8 +7797,10 @@ aarch64_function_arg_advance (cumulative_args_t pcum_v, - || pcum->pcs_variant == ARM_PCS_SVE) - { - aarch64_layout_arg (pcum_v, arg); -- gcc_assert ((pcum->aapcs_reg != NULL_RTX) -- != (pcum->aapcs_stack_words != 0)); -+ pcum->darwinpcs_n_args_processed++; -+ gcc_assert (TARGET_MACHO -+ || (pcum->aapcs_reg != NULL_RTX) -+ != (pcum->aapcs_stack_words != 0)); - pcum->aapcs_arg_processed = false; - pcum->aapcs_ncrn = pcum->aapcs_nextncrn; - pcum->aapcs_nvrn = pcum->aapcs_nextnvrn; -@@ -7640,6 +7808,12 @@ aarch64_function_arg_advance (cumulative_args_t pcum_v, - pcum->aapcs_stack_size += pcum->aapcs_stack_words; - pcum->aapcs_stack_words = 0; - pcum->aapcs_reg = NULL_RTX; -+ pcum->darwinpcs_arg_boundary = BITS_PER_UNIT; -+ pcum->darwinpcs_arg_padding = BITS_PER_UNIT; -+ pcum->named_p -+ = pcum->darwinpcs_n_args_processed < pcum->darwinpcs_n_named; -+ pcum->last_named_p -+ = pcum->darwinpcs_n_args_processed + 1 == pcum->darwinpcs_n_named; - } - } - -@@ -7650,12 +7824,15 @@ aarch64_function_arg_regno_p (unsigned regno) - || (FP_REGNUM_P (regno) && regno < V0_REGNUM + NUM_FP_ARG_REGS)); - } - --/* Implement FUNCTION_ARG_BOUNDARY. Every parameter gets at least -- PARM_BOUNDARY bits of alignment, but will be given anything up -- to STACK_BOUNDARY bits if the type requires it. This makes sure -- that both before and after the layout of each argument, the Next -- Stacked Argument Address (NSAA) will have a minimum alignment of -- 8 bytes. */ -+/* Implement FUNCTION_ARG_BOUNDARY. -+ For AAPCS64, Every parameter gets at least PARM_BOUNDARY bits of -+ alignment, but will be given anything up to STACK_BOUNDARY bits -+ if the type requires it. This makes sure that both before and after -+ the layout of each argument, the Next Stacked Argument Address (NSAA) -+ will have a minimum alignment of 8 bytes. -+ -+ For darwinpcs, this is only called to lower va_arg entries which are -+ always aligned as for AAPCS64. */ - - static unsigned int - aarch64_function_arg_boundary (machine_mode mode, const_tree type) -@@ -7663,6 +7840,71 @@ aarch64_function_arg_boundary (machine_mode mode, const_tree type) - unsigned int abi_break; - unsigned int alignment = aarch64_function_arg_alignment (mode, type, - &abi_break); -+#if TARGET_MACHO -+ /* This can only work for unnamed args. */ -+ machine_mode comp_mode = VOIDmode; -+ int nregs; -+ bool is_ha; -+ aarch64_vfp_is_call_or_return_candidate (mode, type, &comp_mode, &nregs, -+ &is_ha, /*silent*/true); -+ if (TREE_CODE (type) == COMPLEX_TYPE -+ || (TREE_CODE (type) == RECORD_TYPE -+ && !is_ha && !SCALAR_FLOAT_MODE_P (comp_mode)) -+ || TREE_CODE (type) == UNION_TYPE) -+ return MIN (MAX (alignment, PARM_BOUNDARY), STACK_BOUNDARY); -+ return MIN (alignment, STACK_BOUNDARY); -+#else -+ alignment = MIN (MAX (alignment, PARM_BOUNDARY), STACK_BOUNDARY); -+ if (abi_break & warn_psabi) -+ { -+ abi_break = MIN (MAX (abi_break, PARM_BOUNDARY), STACK_BOUNDARY); -+ if (alignment != abi_break && !TARGET_MACHO) -+ inform (input_location, "parameter passing for argument of type " -+ "%qT changed in GCC 9.1", type); -+ } -+ -+ return alignment; -+#endif -+} -+ -+/* For Darwin, we want to use the arg boundary computed when laying out the -+ function arg, to cope with items packed on the stack and the different -+ rules applied to unnamed parms. */ -+ -+static unsigned int -+aarch64_function_arg_boundary_ca (machine_mode mode ATTRIBUTE_UNUSED, -+ const_tree type ATTRIBUTE_UNUSED, -+ cumulative_args_t ca ATTRIBUTE_UNUSED) -+{ -+ unsigned int abi_break; -+ unsigned int alignment = aarch64_function_arg_alignment (mode, type, -+ &abi_break); -+#if TARGET_MACHO -+ CUMULATIVE_ARGS *pcum = get_cumulative_args (ca); -+gcc_checking_assert (pcum->aapcs_arg_processed); -+ -+ bool named_p = pcum->darwinpcs_n_args_processed < pcum->darwinpcs_n_named; -+gcc_checking_assert (named_p == pcum->named_p); -+ machine_mode comp_mode = VOIDmode; -+ int nregs; -+ bool is_ha; -+ aarch64_vfp_is_call_or_return_candidate (mode, type, &comp_mode, &nregs, -+ &is_ha, /*silent*/true); -+ bool no_pack = (TREE_CODE (type) == COMPLEX_TYPE -+ || (TREE_CODE (type) == RECORD_TYPE -+ && !is_ha && !SCALAR_FLOAT_MODE_P (comp_mode)) -+ || TREE_CODE (type) == UNION_TYPE); -+ -+ bool in_regs = (pcum->aapcs_reg != NULL_RTX); -+ -+ if ((named_p && !no_pack) || in_regs) -+ ; /* Leave the alignment as natural. */ -+ else -+ alignment = MAX (alignment, PARM_BOUNDARY); -+gcc_checking_assert (alignment == pcum->darwinpcs_arg_boundary); -+ return MIN (alignment, STACK_BOUNDARY); -+ -+#else - alignment = MIN (MAX (alignment, PARM_BOUNDARY), STACK_BOUNDARY); - if (abi_break & warn_psabi) - { -@@ -7673,6 +7915,44 @@ aarch64_function_arg_boundary (machine_mode mode, const_tree type) - } - - return alignment; -+#endif -+} -+ -+/* Implement TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA for darwinpcs which allows -+ non-standard passing of byte-aligned items [D.2]. This is done by pulling -+ the values out of the cumulative args struct. */ -+ -+static unsigned int -+aarch64_function_arg_round_boundary_ca (machine_mode mode ATTRIBUTE_UNUSED, -+ const_tree type ATTRIBUTE_UNUSED, -+ cumulative_args_t ca) -+{ -+ CUMULATIVE_ARGS *pcum = get_cumulative_args (ca); -+gcc_checking_assert (pcum->aapcs_arg_processed); -+ bool named_p = pcum->darwinpcs_n_args_processed < pcum->darwinpcs_n_named; -+gcc_checking_assert (named_p == pcum->named_p); -+ bool last_named_p = pcum->darwinpcs_n_args_processed + 1 == pcum->darwinpcs_n_named; -+gcc_checking_assert (last_named_p == pcum->last_named_p); -+ -+ unsigned boundary = BITS_PER_UNIT; -+ if (last_named_p && pcum->darwinpcs_sub_word_pos > 0) -+ { -+ /* Round the last named arg to the start of the next stack slot. */ -+ if (pcum->darwinpcs_sub_word_pos <= 4) -+ boundary = PARM_BOUNDARY; -+ else if (pcum->darwinpcs_sub_word_pos <= 6) -+ boundary = 4 * BITS_PER_UNIT; -+ else if (pcum->darwinpcs_sub_word_pos <= 7) -+ boundary = 2 * BITS_PER_UNIT; -+ } -+ else if (named_p) -+ /* Named args are naturally aligned, but with no rounding. */ -+ ; -+ else -+ /* un-named args are rounded to fill slots. */ -+ boundary = PARM_BOUNDARY; -+gcc_checking_assert (boundary == pcum->darwinpcs_arg_padding); -+ return boundary; - } - - /* Implement TARGET_GET_RAW_RESULT_MODE and TARGET_GET_RAW_ARG_MODE. */ -@@ -10848,6 +11128,7 @@ aarch64_classify_address (struct aarch64_address_info *info, - /* load literal: pc-relative constant pool entry. Only supported - for SI mode or larger. */ - info->type = ADDRESS_SYMBOLIC; -+ info->offset = NULL_RTX; - - if (!load_store_pair_p - && GET_MODE_SIZE (mode).is_constant (&const_size) -@@ -10855,6 +11136,7 @@ aarch64_classify_address (struct aarch64_address_info *info, - { - poly_int64 offset; - rtx sym = strip_offset_and_salt (x, &offset); -+ - return ((LABEL_REF_P (sym) - || (SYMBOL_REF_P (sym) - && CONSTANT_POOL_ADDRESS_P (sym) -@@ -10872,10 +11154,13 @@ aarch64_classify_address (struct aarch64_address_info *info, - poly_int64 offset; - HOST_WIDE_INT const_offset; - rtx sym = strip_offset_and_salt (info->offset, &offset); -+ - if (SYMBOL_REF_P (sym) - && offset.is_constant (&const_offset) - && (aarch64_classify_symbol (sym, const_offset) -- == SYMBOL_SMALL_ABSOLUTE)) -+ == SYMBOL_SMALL_ABSOLUTE -+ || aarch64_classify_symbol (sym, const_offset) -+ == SYMBOL_MO_SMALL_PCR)) - { - /* The symbol and offset must be aligned to the access size. */ - unsigned int align; -@@ -10925,6 +11210,55 @@ aarch64_address_valid_for_prefetch_p (rtx x, bool strict_p) - if (!res) - return false; - -+ /* For ELF targets using GAS, we emit prfm unconditionally; GAS will alter -+ the instruction to pick the prfum form where possible (i.e. when the -+ offset is in the range -256..255) and fall back to prfm otherwise. -+ We can reject cases where the offset exceeds the range usable by both -+ insns [-256..32760], or for offsets > 255 when the value is not divisible -+ by 8. -+ For Mach-O (Darwin) where the assembler uses the LLVM back end, that does -+ not yet do the substitution, so we must reject all prfum cases. */ -+ if (addr.offset) -+ { -+ HOST_WIDE_INT offs = INTVAL (addr.offset); -+ if (offs < -256) /* Out of range for both prfum and prfm. */ -+ return false; -+ if (offs > 32760) /* Out of range for prfm. */ -+ return false; -+ if (offs & 0x07) /* We cannot use prfm. */ -+ { -+ if (offs > 255) /* Out of range for prfum. */ -+ return false; -+ if (TARGET_MACHO) -+ return false; -+ } -+ if (TARGET_MACHO && offs < 0) -+ return false; -+ } -+ -+ /* ... except writeback forms. */ -+ return addr.type != ADDRESS_REG_WB; -+} -+ -+/* Return true if the address X is valid for a PRFUM instruction. -+ STRICT_P is true if we should do strict checking with -+ aarch64_classify_address. */ -+ -+bool -+aarch64_address_valid_for_unscaled_prefetch_p (rtx x, bool strict_p) -+{ -+ struct aarch64_address_info addr; -+ -+ /* PRFUM accepts the same addresses as DImode, but constrained to a range -+ -256..255. */ -+ bool res = aarch64_classify_address (&addr, x, DImode, strict_p); -+ if (!res) -+ return false; -+ -+ if (addr.offset && ((INTVAL (addr.offset) > 255) -+ || (INTVAL (addr.offset) < -256))) -+ return false; -+ - /* ... except writeback forms. */ - return addr.type != ADDRESS_REG_WB; - } -@@ -11609,6 +11943,144 @@ sizetochar (int size) - } - } - -+static void -+output_macho_postfix_expr (FILE *file, rtx x, const char *postfix) -+{ -+ char buf[256]; -+ -+ restart: -+ switch (GET_CODE (x)) -+ { -+ case PC: -+ putc ('.', file); -+ break; -+ -+ case SYMBOL_REF: -+ if (SYMBOL_REF_DECL (x)) -+ assemble_external (SYMBOL_REF_DECL (x)); -+ assemble_name (file, XSTR (x, 0)); -+ fprintf (file, "@%s", postfix); -+ break; -+ -+ case LABEL_REF: -+ x = label_ref_label (x); -+ /* Fall through. */ -+ case CODE_LABEL: -+ ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x)); -+ assemble_name (file, buf); -+ fprintf (file, "@%s", postfix); -+ break; -+ -+ case CONST_INT: -+ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x)); -+ break; -+ -+ case CONST: -+ /* This used to output parentheses around the expression, -+ but that does not work on the 386 (either ATT or BSD assembler). */ -+ output_macho_postfix_expr (file, XEXP (x, 0), postfix); -+ break; -+ -+ case CONST_WIDE_INT: -+ /* We do not know the mode here so we have to use a round about -+ way to build a wide-int to get it printed properly. */ -+ { -+ wide_int w = wide_int::from_array (&CONST_WIDE_INT_ELT (x, 0), -+ CONST_WIDE_INT_NUNITS (x), -+ CONST_WIDE_INT_NUNITS (x) -+ * HOST_BITS_PER_WIDE_INT, -+ false); -+ print_decs (w, file); -+ } -+ break; -+ -+ case CONST_DOUBLE: -+ if (CONST_DOUBLE_AS_INT_P (x)) -+ { -+ /* We can use %d if the number is one word and positive. */ -+ if (CONST_DOUBLE_HIGH (x)) -+ fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX, -+ (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (x), -+ (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (x)); -+ else if (CONST_DOUBLE_LOW (x) < 0) -+ fprintf (file, HOST_WIDE_INT_PRINT_HEX, -+ (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (x)); -+ else -+ fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x)); -+ } -+ else -+ /* We can't handle floating point constants; -+ PRINT_OPERAND must handle them. */ -+ output_operand_lossage ("floating constant misused"); -+ break; -+ -+ case CONST_FIXED: -+ fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_FIXED_VALUE_LOW (x)); -+ break; -+ -+ case PLUS: -+ /* Some assemblers need integer constants to appear last (eg masm). */ -+ if (CONST_INT_P (XEXP (x, 0))) -+ { -+ output_macho_postfix_expr (file, XEXP (x, 1), postfix); -+ if (INTVAL (XEXP (x, 0)) >= 0) -+ fprintf (file, "+"); -+ output_addr_const (file, XEXP (x, 0)); -+ } -+ else -+ { -+ output_macho_postfix_expr (file, XEXP (x, 0), postfix); -+ if (!CONST_INT_P (XEXP (x, 1)) -+ || INTVAL (XEXP (x, 1)) >= 0) -+ fprintf (file, "+"); -+ output_addr_const (file, XEXP (x, 1)); -+ } -+ break; -+ -+ case MINUS: -+ /* Avoid outputting things like x-x or x+5-x, -+ since some assemblers can't handle that. */ -+ x = simplify_subtraction (x); -+ if (GET_CODE (x) != MINUS) -+ goto restart; -+ -+ output_macho_postfix_expr (file, XEXP (x, 0), postfix); -+ fprintf (file, "-"); -+ if ((CONST_INT_P (XEXP (x, 1)) && INTVAL (XEXP (x, 1)) >= 0) -+ || GET_CODE (XEXP (x, 1)) == PC -+ || GET_CODE (XEXP (x, 1)) == SYMBOL_REF) -+ output_addr_const (file, XEXP (x, 1)); -+ else -+ { -+ fputs (targetm.asm_out.open_paren, file); -+ output_addr_const (file, XEXP (x, 1)); -+ fputs (targetm.asm_out.close_paren, file); -+ } -+ break; -+ -+ case ZERO_EXTEND: -+ case SIGN_EXTEND: -+ case SUBREG: -+ case TRUNCATE: -+ output_addr_const (file, XEXP (x, 0)); -+ break; -+ -+ case UNSPEC: -+ if (XINT (x, 1) == UNSPEC_SALT_ADDR) -+ { -+ output_macho_postfix_expr (file, XVECEXP (x, 0, 0), postfix); -+ break; -+ } -+ /* FALLTHROUGH */ -+ default: -+ if (targetm.asm_out.output_addr_const_extra (file, x)) -+ break; -+ -+ output_operand_lossage ("invalid expression as operand"); -+ } -+ -+} -+ - /* Print operand X to file F in a target specific manner according to CODE. - The acceptable formatting commands given by CODE are: - 'c': An integer or symbol address without a preceding # -@@ -11677,6 +12149,12 @@ aarch64_print_operand (FILE *f, rtx x, int code) - } - break; - -+ case 'K': -+ output_macho_postfix_expr (f, x, "PAGEOFF"); -+ break; -+ case 'O': -+ output_macho_postfix_expr (f, x, "GOTPAGEOFF"); -+ break; - case 'e': - { - x = unwrap_const_vec_duplicate (x); -@@ -12000,7 +12478,7 @@ aarch64_print_operand (FILE *f, rtx x, int code) - case 'A': - if (GET_CODE (x) == HIGH) - x = XEXP (x, 0); -- -+#if !TARGET_MACHO - switch (aarch64_classify_symbolic_expression (x)) - { - case SYMBOL_SMALL_GOT_4G: -@@ -12031,9 +12509,29 @@ aarch64_print_operand (FILE *f, rtx x, int code) - break; - } - output_addr_const (asm_out_file, x); -+#endif -+#if TARGET_MACHO -+ // FIXME update classify symbolic expression to handle macho. -+ switch (aarch64_classify_symbolic_expression (x)) -+ { -+ case SYMBOL_MO_SMALL_PCR: -+ output_macho_postfix_expr (asm_out_file, x, "PAGE"); -+// asm_fprintf (asm_out_file, "@PAGE;mopcr"); -+ break; -+ case SYMBOL_MO_SMALL_GOT: -+ output_macho_postfix_expr (asm_out_file, x, "GOTPAGE"); -+// asm_fprintf (asm_out_file, "@GOTPAGE;mosg"); -+ break; -+ default: -+ output_macho_postfix_expr (asm_out_file, x, "BLEAH"); -+// asm_fprintf (asm_out_file, "@BLEAH"); -+ break; -+ } -+#endif - break; - - case 'L': -+#if !TARGET_MACHO - switch (aarch64_classify_symbolic_expression (x)) - { - case SYMBOL_SMALL_GOT_4G: -@@ -12071,10 +12569,12 @@ aarch64_print_operand (FILE *f, rtx x, int code) - default: - break; - } -+#endif - output_addr_const (asm_out_file, x); - break; - - case 'G': -+#if !TARGET_MACHO - switch (aarch64_classify_symbolic_expression (x)) - { - case SYMBOL_TLSLE24: -@@ -12083,6 +12583,7 @@ aarch64_print_operand (FILE *f, rtx x, int code) - default: - break; - } -+#endif - output_addr_const (asm_out_file, x); - break; - -@@ -12232,8 +12733,14 @@ aarch64_print_address_internal (FILE *f, machine_mode mode, rtx x, - break; - - case ADDRESS_LO_SUM: -+#if TARGET_MACHO -+ asm_fprintf (f, "[%s, #", reg_names [REGNO (addr.base)]); -+ output_macho_postfix_expr (f, addr.offset, "PAGEOFF"); -+// output_addr_const (f, addr.offset); -+#else - asm_fprintf (f, "[%s, #:lo12:", reg_names [REGNO (addr.base)]); - output_addr_const (f, addr.offset); -+#endif - asm_fprintf (f, "]"); - return true; - -@@ -12703,6 +13210,8 @@ aarch64_asm_output_labelref (FILE* f, const char *name) - asm_fprintf (f, "%U%s", name); - } - -+#if !TARGET_MACHO -+ - static void - aarch64_elf_asm_constructor (rtx symbol, int priority) - { -@@ -12742,6 +13251,7 @@ aarch64_elf_asm_destructor (rtx symbol, int priority) - assemble_aligned_integer (POINTER_BYTES, symbol); - } - } -+#endif - - const char* - aarch64_output_casesi (rtx *operands) -@@ -15048,15 +15558,17 @@ aarch64_init_builtins () - { - aarch64_general_init_builtins (); - aarch64_sve::init_builtins (); --#ifdef SUBTARGET_INIT_BUILTINS -- SUBTARGET_INIT_BUILTINS; --#endif -+ aarch64_init_subtarget_builtins (); - } - - /* Implement TARGET_FOLD_BUILTIN. */ - static tree - aarch64_fold_builtin (tree fndecl, int nargs, tree *args, bool) - { -+#ifdef SUBTARGET_FOLD_BUILTIN -+ if (tree res = SUBTARGET_FOLD_BUILTIN (fndecl, nargs, args, false)) -+ return res; -+#endif - unsigned int code = DECL_MD_FUNCTION_CODE (fndecl); - unsigned int subcode = code >> AARCH64_BUILTIN_SHIFT; - tree type = TREE_TYPE (TREE_TYPE (fndecl)); -@@ -18326,10 +18838,14 @@ initialize_aarch64_code_model (struct gcc_options *opts) - } - break; - case AARCH64_CMODEL_LARGE: -- if (opts->x_flag_pic) -+ if (TARGET_MACHO) -+ /* We need to implement fPIC here (arm64_32 also accepts the large -+ model). */ -+ ; -+ else if (opts->x_flag_pic) - sorry ("code model %qs with %<-f%s%>", "large", - opts->x_flag_pic > 1 ? "PIC" : "pic"); -- if (opts->x_aarch64_abi == AARCH64_ABI_ILP32) -+ else if (opts->x_aarch64_abi == AARCH64_ABI_ILP32) - sorry ("code model %qs not supported in ilp32 mode", "large"); - break; - case AARCH64_CMODEL_TINY_PIC: -@@ -19252,7 +19768,9 @@ aarch64_classify_symbol (rtx x, HOST_WIDE_INT offset) - case AARCH64_CMODEL_SMALL_SPIC: - case AARCH64_CMODEL_SMALL_PIC: - case AARCH64_CMODEL_SMALL: -- return SYMBOL_SMALL_ABSOLUTE; -+ return TARGET_MACHO -+ ? SYMBOL_MO_SMALL_PCR -+ : SYMBOL_SMALL_ABSOLUTE; - - default: - gcc_unreachable (); -@@ -19288,10 +19806,22 @@ aarch64_classify_symbol (rtx x, HOST_WIDE_INT offset) - - return SYMBOL_TINY_ABSOLUTE; - -- - case AARCH64_CMODEL_SMALL_SPIC: - case AARCH64_CMODEL_SMALL_PIC: - case AARCH64_CMODEL_SMALL: -+#if TARGET_MACHO -+ if (TARGET_MACHO) -+ { -+ /* Constant pool addresses are always TU-local and PC- -+ relative. We indirect common, external and weak -+ symbols (but weak only if not hidden). */ -+ if (!CONSTANT_POOL_ADDRESS_P (x) -+ && (MACHO_SYMBOL_MUST_INDIRECT_P (x) -+ || !aarch64_symbol_binds_local_p (x))) -+ return SYMBOL_MO_SMALL_GOT; -+ } -+ else -+#endif - if ((flag_pic || SYMBOL_REF_WEAK (x)) - && !aarch64_symbol_binds_local_p (x)) - return aarch64_cmodel == AARCH64_CMODEL_SMALL_SPIC -@@ -19303,7 +19833,8 @@ aarch64_classify_symbol (rtx x, HOST_WIDE_INT offset) - || offset_within_block_p (x, offset))) - return SYMBOL_FORCE_TO_MEM; - -- return SYMBOL_SMALL_ABSOLUTE; -+ return TARGET_MACHO ? SYMBOL_MO_SMALL_PCR -+ : SYMBOL_SMALL_ABSOLUTE; - - case AARCH64_CMODEL_LARGE: - /* This is alright even in PIC code as the constant -@@ -19433,7 +19964,10 @@ static GTY(()) tree va_list_type; - void *__vr_top; - int __gr_offs; - int __vr_offs; -- }; */ -+ }; -+ -+ darwinpcs uses 'char *' for the va_list (in common with other platform -+ ports). */ - - static tree - aarch64_build_builtin_va_list (void) -@@ -19441,6 +19975,13 @@ aarch64_build_builtin_va_list (void) - tree va_list_name; - tree f_stack, f_grtop, f_vrtop, f_groff, f_vroff; - -+ /* darwinpcs uses a simple char * for this. */ -+ if (TARGET_MACHO) -+ { -+ va_list_type = build_pointer_type (char_type_node); -+ return va_list_type; -+ } -+ - /* Create the type. */ - va_list_type = lang_hooks.types.make_type (RECORD_TYPE); - /* Give it the required name. */ -@@ -19512,6 +20053,13 @@ aarch64_expand_builtin_va_start (tree valist, rtx nextarg ATTRIBUTE_UNUSED) - int vr_save_area_size = cfun->va_list_fpr_size; - int vr_offset; - -+ /* darwinpcs uses the default, char * va_list impl. */ -+ if (TARGET_MACHO) -+ { -+ std_expand_builtin_va_start (valist, nextarg); -+ return; -+ } -+ - cum = &crtl->args.info; - if (cfun->va_list_gpr_size) - gr_save_area_size = MIN ((NUM_ARG_REGS - cum->aapcs_ncrn) * UNITS_PER_WORD, -@@ -19602,6 +20150,9 @@ aarch64_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p, - HOST_WIDE_INT size, rsize, adjust, align; - tree t, u, cond1, cond2; - -+ if (TARGET_MACHO) -+ return std_gimplify_va_arg_expr (valist, type, pre_p, post_p); -+ - indirect_p = pass_va_arg_by_reference (type); - if (indirect_p) - type = build_pointer_type (type); -@@ -19786,8 +20337,18 @@ aarch64_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p, - field_ptr_t = double_ptr_type_node; - break; - case E_TFmode: -- field_t = long_double_type_node; -- field_ptr_t = long_double_ptr_type_node; -+ if (TARGET_MACHO) -+ { -+ /* Darwin has __float128, and long double is the same as -+ double. */ -+ field_t = float128_type_node; -+ field_ptr_t = aarch64_float128_ptr_type_node; -+ } -+ else -+ { -+ field_t = long_double_type_node; -+ field_ptr_t = long_double_ptr_type_node; -+ } - break; - case E_HFmode: - field_t = aarch64_fp16_type_node; -@@ -19858,6 +20419,9 @@ aarch64_setup_incoming_varargs (cumulative_args_t cum_v, - int gr_saved = cfun->va_list_gpr_size; - int vr_saved = cfun->va_list_fpr_size; - -+ if (TARGET_MACHO) -+ return default_setup_incoming_varargs (cum_v, arg, pretend_size, no_rtl); -+ - /* The caller has advanced CUM up to, but not beyond, the last named - argument. Advance a local copy of CUM past the last "real" named - argument, to find out how many registers are left over. */ -@@ -20685,6 +21249,12 @@ aarch64_autovectorize_vector_modes (vector_modes *modes, bool) - static const char * - aarch64_mangle_type (const_tree type) - { -+ /* The darwinpcs ABI documents say that "__va_list" has to be -+ mangled as char *. */ -+ if (TARGET_MACHO -+ && lang_hooks.types_compatible_p (CONST_CAST_TREE (type), va_list_type)) -+ return "Pc"; -+ - /* The AArch64 ABI documents say that "__va_list" has to be - mangled as if it is in the "std" namespace. */ - if (lang_hooks.types_compatible_p (CONST_CAST_TREE (type), va_list_type)) -@@ -20699,6 +21269,10 @@ aarch64_mangle_type (const_tree type) - return "Dh"; - } - -+ /* TFmode is __float128 for Darwin. */ -+ if (TARGET_MACHO && TYPE_MODE (type) == TFmode) -+ return "g"; -+ - /* Mangle AArch64-specific internal types. TYPE_NAME is non-NULL_TREE for - builtin types. */ - if (TYPE_NAME (type) != NULL) -@@ -21389,7 +21963,8 @@ aarch64_mov_operand_p (rtx x, machine_mode mode) - - /* GOT accesses are valid moves. */ - if (SYMBOL_REF_P (x) -- && aarch64_classify_symbolic_expression (x) == SYMBOL_SMALL_GOT_4G) -+ && (aarch64_classify_symbolic_expression (x) == SYMBOL_SMALL_GOT_4G -+ || aarch64_classify_symbolic_expression (x) == SYMBOL_MO_SMALL_GOT)) - return true; - - if (SYMBOL_REF_P (x) && mode == DImode && CONSTANT_ADDRESS_P (x)) -@@ -22549,7 +23124,9 @@ aarch64_declare_function_name (FILE *stream, const char* name, - aarch64_asm_output_variant_pcs (stream, fndecl, name); - - /* Don't forget the type directive for ELF. */ -+#ifdef ASM_OUTPUT_TYPE_DIRECTIVE - ASM_OUTPUT_TYPE_DIRECTIVE (stream, name, "function"); -+#endif - ASM_OUTPUT_LABEL (stream, name); - - cfun->machine->label_is_assembled = true; -@@ -22584,12 +23161,17 @@ aarch64_print_patchable_function_entry (FILE *file, - /* Implement ASM_OUTPUT_DEF_FROM_DECLS. Output .variant_pcs for aliases. */ - - void --aarch64_asm_output_alias (FILE *stream, const tree decl, const tree target) -+aarch64_asm_output_alias (FILE *stream, const tree decl, -+ const tree target ATTRIBUTE_UNUSED) - { - const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0); -+#ifdef ASM_OUTPUT_DEF - const char *value = IDENTIFIER_POINTER (target); -+#endif - aarch64_asm_output_variant_pcs (stream, decl, name); -+#ifdef ASM_OUTPUT_DEF - ASM_OUTPUT_DEF (stream, name, value); -+#endif - } - - /* Implement ASM_OUTPUT_EXTERNAL. Output .variant_pcs for undefined -@@ -23213,6 +23795,16 @@ aarch64_output_simd_mov_immediate (rtx const_vector, unsigned width, - } - - gcc_assert (CONST_INT_P (info.u.mov.value)); -+ unsigned HOST_WIDE_INT value = UINTVAL (info.u.mov.value); -+ -+ /* We have signed chars which can result in a sign-extended 8bit value -+ which is then emitted as an unsigned hex value, and the LLVM back end -+ assembler rejects that as being too big. */ -+ if (TARGET_MACHO && (known_eq (GET_MODE_BITSIZE (info.elt_mode), 8))) -+ { -+ unsigned HOST_WIDE_INT mask = (1U << GET_MODE_BITSIZE (info.elt_mode))-1; -+ value &= mask; -+ } - - if (which == AARCH64_CHECK_MOV) - { -@@ -23221,16 +23813,16 @@ aarch64_output_simd_mov_immediate (rtx const_vector, unsigned width, - ? "msl" : "lsl"); - if (lane_count == 1) - snprintf (templ, sizeof (templ), "%s\t%%d0, " HOST_WIDE_INT_PRINT_HEX, -- mnemonic, UINTVAL (info.u.mov.value)); -+ mnemonic, value); - else if (info.u.mov.shift) - snprintf (templ, sizeof (templ), "%s\t%%0.%d%c, " - HOST_WIDE_INT_PRINT_HEX ", %s %d", mnemonic, lane_count, -- element_char, UINTVAL (info.u.mov.value), shift_op, -+ element_char, value, shift_op, - info.u.mov.shift); - else - snprintf (templ, sizeof (templ), "%s\t%%0.%d%c, " - HOST_WIDE_INT_PRINT_HEX, mnemonic, lane_count, -- element_char, UINTVAL (info.u.mov.value)); -+ element_char, value); - } - else - { -@@ -23239,12 +23831,12 @@ aarch64_output_simd_mov_immediate (rtx const_vector, unsigned width, - if (info.u.mov.shift) - snprintf (templ, sizeof (templ), "%s\t%%0.%d%c, #" - HOST_WIDE_INT_PRINT_DEC ", %s #%d", mnemonic, lane_count, -- element_char, UINTVAL (info.u.mov.value), "lsl", -+ element_char, value, "lsl", - info.u.mov.shift); - else - snprintf (templ, sizeof (templ), "%s\t%%0.%d%c, #" - HOST_WIDE_INT_PRINT_DEC, mnemonic, lane_count, -- element_char, UINTVAL (info.u.mov.value)); -+ element_char, value); - } - return templ; - } -@@ -26355,12 +26947,12 @@ aarch64_libgcc_floating_mode_supported_p (scalar_float_mode mode) - } - - /* Implement TARGET_SCALAR_MODE_SUPPORTED_P - return TRUE -- if MODE is HFmode, and punt to the generic implementation otherwise. */ -+ if MODE is HFmode, or TFmode on Mach-O, and punt to the generic implementation otherwise. */ - - static bool - aarch64_scalar_mode_supported_p (scalar_mode mode) - { -- return (mode == HFmode -+ return (mode == HFmode || (mode == TFmode && TARGET_MACHO) - ? true - : default_scalar_mode_supported_p (mode)); - } -@@ -27118,19 +27710,37 @@ aarch64_sls_emit_shared_blr_thunks (FILE *out_file) - continue; - - const char *name = indirect_symbol_names[regnum]; -- switch_to_section (get_named_section (decl, NULL, 0)); -+ /* If the target uses a unique section for this switch to it. */ -+ if (DECL_SECTION_NAME (decl)) -+ switch_to_section (get_named_section (decl, NULL, 0)); -+ else -+ switch_to_section (text_section); - ASM_OUTPUT_ALIGN (out_file, 2); -- targetm.asm_out.globalize_label (out_file, name); -+ if (!TARGET_MACHO) -+ targetm.asm_out.globalize_label (out_file, name); -+#ifdef ASM_OUTPUT_TYPE_DIRECTIVE -+ ASM_OUTPUT_TYPE_DIRECTIVE (out_file, name, "function"); -+#endif -+ if (TARGET_MACHO) -+ { -+#ifdef ASM_WEAKEN_DECL -+ if (DECL_WEAK (decl)) -+ ASM_WEAKEN_DECL (out_file, decl, name, 0); -+ else -+#endif -+ targetm.asm_out.globalize_decl_name (out_file, decl); -+ } - /* Only emits if the compiler is configured for an assembler that can - handle visibility directives. */ - targetm.asm_out.assemble_visibility (decl, VISIBILITY_HIDDEN); -- ASM_OUTPUT_TYPE_DIRECTIVE (out_file, name, "function"); - ASM_OUTPUT_LABEL (out_file, name); - aarch64_sls_emit_function_stub (out_file, regnum); - /* Use the most conservative target to ensure it can always be used by any - function in the translation unit. */ - asm_fprintf (out_file, "\tdsb\tsy\n\tisb\n"); -+#ifdef ASM_DECLARE_FUNCTION_SIZE - ASM_DECLARE_FUNCTION_SIZE (out_file, name, decl); -+#endif - } - } - -@@ -27323,6 +27933,15 @@ aarch64_run_selftests (void) - #undef TARGET_ASM_ALIGNED_SI_OP - #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t" - -+#if TARGET_MACHO -+#undef TARGET_ASM_UNALIGNED_HI_OP -+#define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t" -+#undef TARGET_ASM_UNALIGNED_SI_OP -+#define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t" -+#undef TARGET_ASM_UNALIGNED_DI_OP -+#define TARGET_ASM_UNALIGNED_DI_OP "\t.quad\t" -+#endif -+ - #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK - #define TARGET_ASM_CAN_OUTPUT_MI_THUNK \ - hook_bool_const_tree_hwi_hwi_const_tree_true -@@ -27409,6 +28028,12 @@ aarch64_run_selftests (void) - #undef TARGET_FUNCTION_ARG_BOUNDARY - #define TARGET_FUNCTION_ARG_BOUNDARY aarch64_function_arg_boundary - -+#undef TARGET_FUNCTION_ARG_BOUNDARY_CA -+#define TARGET_FUNCTION_ARG_BOUNDARY_CA aarch64_function_arg_boundary_ca -+ -+#undef TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA -+#define TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA aarch64_function_arg_round_boundary_ca -+ - #undef TARGET_FUNCTION_ARG_PADDING - #define TARGET_FUNCTION_ARG_PADDING aarch64_function_arg_padding - -@@ -27736,7 +28361,7 @@ aarch64_libgcc_floating_mode_supported_p - - /* The architecture reserves bits 0 and 1 so use bit 2 for descriptors. */ - #undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS --#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 4 -+#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS AARCH64_CUSTOM_FUNCTION_TEST - - #undef TARGET_HARD_REGNO_NREGS - #define TARGET_HARD_REGNO_NREGS aarch64_hard_regno_nregs -diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h -index 359b6e8561f..db5fe441b36 100644 ---- a/gcc/config/aarch64/aarch64.h -+++ b/gcc/config/aarch64/aarch64.h -@@ -58,6 +58,10 @@ - #define TARGET_SIMD (!TARGET_GENERAL_REGS_ONLY && AARCH64_ISA_SIMD) - #define TARGET_FLOAT (!TARGET_GENERAL_REGS_ONLY && AARCH64_ISA_FP) - -+/* If this is non-zero then generated code of the object format, ABI and -+ assembler syntax used by Darwin (Mach-O) platforms. */ -+#define TARGET_MACHO 0 -+ - #define UNITS_PER_WORD 8 - - #define UNITS_PER_VREG 16 -@@ -135,6 +139,12 @@ - /* Heap alignment (same as BIGGEST_ALIGNMENT and STACK_BOUNDARY). */ - #define MALLOC_ABI_ALIGNMENT 128 - -+/* We will and with this value to test if a custom function descriptor needs -+ a static chain. The function boundary must the adjusted so that the bit -+ this represents is no longer part of the address. 0 Disables the custom -+ function descriptors. */ -+#define AARCH64_CUSTOM_FUNCTION_TEST 4 -+ - /* Defined by the ABI */ - #define WCHAR_TYPE "unsigned int" - #define WCHAR_TYPE_SIZE 32 -@@ -1025,6 +1035,24 @@ typedef struct - aapcs_reg == NULL_RTX. */ - int aapcs_stack_size; /* The total size (in words, per 8 byte) of the - stack arg area so far. */ -+ -+ /* In the darwinpcs, items smaller than one word are packed onto the stack -+ naturally aligned. Unnamed parameters passed in a variadic call are, -+ however, aligned the same way as the AAPCS64. This means that we need to -+ pad the last named arg to the next parm boundary (and hence notice when -+ we are processing that arg). */ -+ int darwinpcs_stack_bytes; /* If the argument is passed on the stack, this -+ the byte-size. */ -+ int darwinpcs_sub_word_offset;/* This is the offset of this arg within a word -+ when placing smaller items for darwinpcs. */ -+ int darwinpcs_sub_word_pos; /* The next byte available within the word for -+ darwinpcs. */ -+ unsigned darwinpcs_arg_boundary; /* The computed argument boundary. */ -+ unsigned darwinpcs_arg_padding; /* The computed argument padding. */ -+ unsigned darwinpcs_n_named; /* Number of named arguments. */ -+ unsigned darwinpcs_n_args_processed; /* Processed so far. */ -+ bool named_p; /* Is this arg named? */ -+ bool last_named_p; /* Is this the last named arg? */ - bool silent_p; /* True if we should act silently, rather than - raise an error for invalid calls. */ - } CUMULATIVE_ARGS; -@@ -1309,8 +1337,13 @@ extern const char *host_detect_local_cpu (int argc, const char **argv); - #define ASM_CPU_SPEC \ - MCPU_TO_MARCH_SPEC - -+#ifndef SUBTARGET_EXTRA_SPECS -+#define SUBTARGET_EXTRA_SPECS -+#endif -+ - #define EXTRA_SPECS \ -- { "asm_cpu_spec", ASM_CPU_SPEC } -+ { "asm_cpu_spec", ASM_CPU_SPEC }, \ -+ SUBTARGET_EXTRA_SPECS - - #define ASM_OUTPUT_POOL_EPILOGUE aarch64_asm_output_pool_epilogue - -@@ -1324,6 +1357,10 @@ extern GTY(()) tree aarch64_fp16_ptr_type_node; - extern GTY(()) tree aarch64_bf16_type_node; - extern GTY(()) tree aarch64_bf16_ptr_type_node; - -+/* A pointer to the user-visible __float128 (on Mach-O). Defined in -+ aarch64-builtins.c. */ -+extern GTY(()) tree aarch64_float128_ptr_type_node; -+ - /* The generic unwind code in libgcc does not initialize the frame pointer. - So in order to unwind a function using a frame pointer, the very first - function that is unwound must save the frame pointer. That way the frame -diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md -index 34b8059b45b..c356d3048b5 100644 ---- a/gcc/config/aarch64/aarch64.md -+++ b/gcc/config/aarch64/aarch64.md -@@ -303,6 +303,7 @@ - UNSPEC_TAG_SPACE ; Translate address to MTE tag address space. - UNSPEC_LD1RO - UNSPEC_SALT_ADDR -+ UNSPEC_MACHOPIC_OFFSET - ]) - - (define_c_enum "unspecv" [ -@@ -849,6 +850,37 @@ - [(set_attr "type" "load_4")] - ) - -+(define_insn "prefetch_unscaled" -+ [(prefetch (match_operand:DI 0 "aarch64_unscaled_prefetch_operand" "Du") -+ (match_operand:QI 1 "const_int_operand" "") -+ (match_operand:QI 2 "const_int_operand" ""))] -+ "" -+ { -+ const char * pftype[2][4] = -+ { -+ {"prfum\\tPLDL1STRM, %0", -+ "prfum\\tPLDL3KEEP, %0", -+ "prfum\\tPLDL2KEEP, %0", -+ "prfum\\tPLDL1KEEP, %0"}, -+ {"prfum\\tPSTL1STRM, %0", -+ "prfum\\tPSTL3KEEP, %0", -+ "prfum\\tPSTL2KEEP, %0", -+ "prfum\\tPSTL1KEEP, %0"}, -+ }; -+ -+ int locality = INTVAL (operands[2]); -+ -+ gcc_assert (IN_RANGE (locality, 0, 3)); -+ -+ /* PRFUM accepts the same addresses as a 64-bit LDR so wrap -+ the address into a DImode MEM so that aarch64_print_operand knows -+ how to print it. */ -+ operands[0] = gen_rtx_MEM (DImode, operands[0]); -+ return pftype[INTVAL(operands[1])][locality]; -+ } -+ [(set_attr "type" "load_4")] -+) -+ - (define_insn "trap" - [(trap_if (const_int 1) (const_int 8))] - "" -@@ -1286,7 +1318,7 @@ - ldr\\t%s0, %1 - str\\t%w1, %0 - str\\t%s1, %0 -- adrp\\t%x0, %A1\;ldr\\t%w0, [%x0, %L1] -+ * return TARGET_MACHO ? \"adrp\\t%x0, %A1\;ldr\\t%w0, [%x0, %O1]\" : \"adrp\\t%x0, %A1\;ldr\\t%w0, [%x0, %L1]\"; - adr\\t%x0, %c1 - adrp\\t%x0, %A1 - fmov\\t%s0, %w1 -@@ -1325,7 +1357,7 @@ - ldr\\t%d0, %1 - str\\t%x1, %0 - str\\t%d1, %0 -- * return TARGET_ILP32 ? \"adrp\\t%0, %A1\;ldr\\t%w0, [%0, %L1]\" : \"adrp\\t%0, %A1\;ldr\\t%0, [%0, %L1]\"; -+ * return TARGET_ILP32 ? (TARGET_MACHO ? \"adrp\\t%0, %A1\;ldr\\t%w0, [%0, %O1]\" : \"adrp\\t%0, %A1\;ldr\\t%w0, [%0, %L1]\") : (TARGET_MACHO ? \"adrp\\t%0, %A1\;ldr\\t%0, [%0, %O1]\" : \"adrp\\t%0, %A1\;ldr\\t%0, [%0, %L1]\"); - adr\\t%x0, %c1 - adrp\\t%x0, %A1 - fmov\\t%d0, %x1 -@@ -6857,7 +6889,10 @@ - (lo_sum:P (match_operand:P 1 "register_operand" "r") - (match_operand 2 "aarch64_valid_symref" "S")))] - "" -- "add\\t%0, %1, :lo12:%c2" -+ { return TARGET_MACHO -+ ? "add\\t%0, %1, %K2;momd" -+ : "add\\t%0, %1, :lo12:%c2"; -+ } - [(set_attr "type" "alu_imm")] - ) - -diff --git a/gcc/config/aarch64/aarch64.opt b/gcc/config/aarch64/aarch64.opt -index 92220b26ee2..15ec719ca2d 100644 ---- a/gcc/config/aarch64/aarch64.opt -+++ b/gcc/config/aarch64/aarch64.opt -@@ -152,6 +152,13 @@ Enum(aarch64_abi) String(ilp32) Value(AARCH64_ABI_ILP32) - EnumValue - Enum(aarch64_abi) String(lp64) Value(AARCH64_ABI_LP64) - -+EnumValue -+Enum(aarch64_abi) String(darwinpcs) Value(AARCH64_ABI_LP64) -+ -+m64 -+Target RejectNegative Alias(mabi=, darwinpcs) -+On Darwin for compatibility with other platform variants. -+ - mpc-relative-literal-loads - Target Save Var(pcrelative_literal_loads) Init(2) Save - PC relative literal loads. -diff --git a/gcc/config/aarch64/constraints.md b/gcc/config/aarch64/constraints.md -index ee7587cca16..cb73a2daae8 100644 ---- a/gcc/config/aarch64/constraints.md -+++ b/gcc/config/aarch64/constraints.md -@@ -158,7 +158,9 @@ - A constraint that matches a small GOT access." - (and (match_code "const,symbol_ref") - (match_test "aarch64_classify_symbolic_expression (op) -- == SYMBOL_SMALL_GOT_4G"))) -+ == SYMBOL_SMALL_GOT_4G -+ || aarch64_classify_symbolic_expression (op) -+ == SYMBOL_MO_SMALL_GOT"))) - - (define_constraint "Uss" - "@internal -@@ -490,6 +492,11 @@ - An address valid for a prefetch instruction." - (match_test "aarch64_address_valid_for_prefetch_p (op, true)")) - -+(define_address_constraint "Du" -+ "@internal -+ An address valid for a prefetch instruction with an unscaled offset." -+ (match_test "aarch64_address_valid_for_unscaled_prefetch_p (op, true)")) -+ - (define_constraint "vgb" - "@internal - A constraint that matches an immediate offset valid for SVE LD1B -diff --git a/gcc/config/aarch64/darwin.h b/gcc/config/aarch64/darwin.h -new file mode 100644 -index 00000000000..2a855c11efa ---- /dev/null -+++ b/gcc/config/aarch64/darwin.h -@@ -0,0 +1,280 @@ -+/* Target definitions for Arm64/Aarch64 running on macOS/iOS. -+ -+Copyright The GNU Toolchain Authors. -+Contributed by Iain Sandoe. -+ -+This file is part of GCC. -+ -+GCC is free software; you can redistribute it and/or modify -+it under the terms of the GNU General Public License as published by -+the Free Software Foundation; either version 3, or (at your option) -+any later version. -+ -+GCC is distributed in the hope that it will be useful, -+but WITHOUT ANY WARRANTY; without even the implied warranty of -+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+GNU General Public License for more details. -+ -+You should have received a copy of the GNU General Public License -+along with GCC; see the file COPYING3. If not see -+. */ -+ -+/* Enable Mach-O bits in generic Aarch64 code. */ -+#undef TARGET_MACHO -+#define TARGET_MACHO 1 -+ -+#undef DARWIN_ARM64 -+#define DARWIN_ARM64 1 -+ -+/* FIXME FIXME FIXME - these are mostly guesses right now. */ -+ -+/* FIXME: this is only used in generic code in darwin.c. */ -+#undef TARGET_64BIT -+#define TARGET_64BIT 1 -+ -+#undef PTRDIFF_TYPE -+#define PTRDIFF_TYPE "long int" -+ -+/* NOTE that arm64_32 is a valid thing and corresponds to darwinpcs -+ and TARGET_ILP32, but we are not implementing that for now. */ -+#define TARGET_OS_CPP_BUILTINS() \ -+ do { \ -+ builtin_define ("__LITTLE_ENDIAN__"); \ -+ builtin_define ("__arm64"); \ -+ builtin_define ("__arm64__"); \ -+ darwin_cpp_builtins (pfile); \ -+ } while (0) -+ -+/* In Darwin's arm64 ABI, chars are signed, for consistency with other Darwin -+ architectures. */ -+ -+#undef DEFAULT_SIGNED_CHAR -+#define DEFAULT_SIGNED_CHAR 1 -+ -+#undef LONG_DOUBLE_TYPE_SIZE -+#define LONG_DOUBLE_TYPE_SIZE 64 -+ -+/* Disable custom function descriptors on Darwin, it breaks ABI. */ -+#undef AARCH64_CUSTOM_FUNCTION_TEST -+#define AARCH64_CUSTOM_FUNCTION_TEST 0 -+ -+/* Non-PIE executables are forbidden by the aarch64-darwin security model; -+ remove the option from link-lines since they just produce a warning from -+ ld64 and are then ignored anyway. */ -+#undef DARWIN_NOPIE_SPEC -+#define DARWIN_NOPIE_SPEC \ -+" %insn); -diff --git a/gcc/config/aarch64/predicates.md b/gcc/config/aarch64/predicates.md -index c308015ac2c..cd88f93ca2d 100644 ---- a/gcc/config/aarch64/predicates.md -+++ b/gcc/config/aarch64/predicates.md -@@ -261,9 +261,24 @@ - (define_predicate "aarch64_prefetch_operand" - (match_test "aarch64_address_valid_for_prefetch_p (op, false)")) - -+(define_predicate "aarch64_unscaled_prefetch_operand" -+ (match_test "aarch64_address_valid_for_unscaled_prefetch_p (op, false)")) -+ - (define_predicate "aarch64_valid_symref" - (match_code "const, symbol_ref, label_ref") - { -+ if (TARGET_MACHO) -+ { -+ rtx x = op; -+ rtx offset; -+ split_const (x, &x, &offset); -+ if (GET_CODE (x) == CONST) -+ x = XEXP (x, 0); -+ if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_SALT_ADDR) -+ x = XVECEXP (x, 0, 0); -+ if (SYMBOL_REF_P (x) && INTVAL (offset) < 0) -+ return false; -+ } - return (aarch64_classify_symbolic_expression (op) - != SYMBOL_FORCE_TO_MEM); - }) -diff --git a/gcc/config/aarch64/t-aarch64-darwin b/gcc/config/aarch64/t-aarch64-darwin -new file mode 100644 -index 00000000000..a8bfcffad78 ---- /dev/null -+++ b/gcc/config/aarch64/t-aarch64-darwin -@@ -0,0 +1,25 @@ -+# Machine description for AArch64 architecture. -+# Copyright (C) 2020 Free Software Foundation, Inc. -+# -+# This file is part of GCC. -+# -+# GCC is free software; you can redistribute it and/or modify it -+# under the terms of the GNU General Public License as published by -+# the Free Software Foundation; either version 3, or (at your option) -+# any later version. -+# -+# GCC is distributed in the hope that it will be useful, but -+# WITHOUT ANY WARRANTY; without even the implied warranty of -+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -+# General Public License for more details. -+# -+# You should have received a copy of the GNU General Public License -+# along with GCC; see the file COPYING3. If not see -+# . -+ -+LIB1ASMSRC = aarch64/lib1funcs.asm -+LIB1ASMFUNCS = _aarch64_sync_cache_range -+ -+# FIXME - figure out what multilib provisions we should make for -+# a) arm64e -+# b) arm64_32 -diff --git a/gcc/config/darwin-driver.cc b/gcc/config/darwin-driver.cc -index 00287f3d5ec..6df85f57bb4 100644 ---- a/gcc/config/darwin-driver.cc -+++ b/gcc/config/darwin-driver.cc -@@ -268,14 +268,21 @@ darwin_driver_init (unsigned int *decoded_options_count, - bool seenX86_64 = false; - bool seenPPC = false; - bool seenPPC64 = false; -+#if !DARWIN_ARM64 -+ bool seenArm64 = false; - bool seenM32 = false; - bool seenM64 = false; - bool appendM32 = false; - bool appendM64 = false; -+#endif - const char *vers_string = NULL; - bool seen_version_min = false; - bool seen_sysroot_p = false; - bool noexport_p = true; -+#ifdef RPATH_SETS_NODEFAULT -+ bool seen_rpath_p = false; -+ bool seen_nodefaultrpaths_p = false; -+#endif - - for (i = 1; i < *decoded_options_count; i++) - { -@@ -296,6 +303,12 @@ darwin_driver_init (unsigned int *decoded_options_count, - seenPPC = true; - else if (!strcmp ((*decoded_options)[i].arg, "ppc64")) - seenPPC64 = true; -+ else if (!strcmp ((*decoded_options)[i].arg, "arm64")) -+#if !DARWIN_ARM64 -+ seenArm64 = true; -+#else -+ ; /* We accept the option, but don't need to act on it. */ -+#endif - else - error ("this compiler does not support %qs", - (*decoded_options)[i].arg); -@@ -309,7 +322,7 @@ darwin_driver_init (unsigned int *decoded_options_count, - --i; - --*decoded_options_count; - break; -- -+#if !DARWIN_ARM64 - case OPT_m32: - seenM32 = true; - break; -@@ -317,6 +330,7 @@ darwin_driver_init (unsigned int *decoded_options_count, - case OPT_m64: - seenM64 = true; - break; -+#endif - - case OPT_mmacosx_version_min_: - seen_version_min = true; -@@ -349,8 +363,16 @@ darwin_driver_init (unsigned int *decoded_options_count, - gcc_checking_assert ((*decoded_options)[i].arg); - if (startswith ((*decoded_options)[i].arg, "-exported_symbol")) - noexport_p = false; -+#ifdef RPATH_SETS_NODEFAULT -+ else if (strncmp ((*decoded_options)[i].arg, "-rpath", 6) == 0) -+ seen_rpath_p = true; -+#endif - break; - -+#ifdef RPATH_SETS_NODEFAULT -+ case OPT_nodefaultrpaths: -+ seen_nodefaultrpaths_p = true; -+#endif - default: - break; - } -@@ -366,6 +388,9 @@ darwin_driver_init (unsigned int *decoded_options_count, - if (seenPPC || seenPPC64) - warning (0, "this compiler does not support PowerPC" - " (%<-arch%> option ignored)"); -+ else if (seenArm64) -+ warning (0, "this compiler does not support Arm64" -+ " (%<-arch%> option ignored)"); - if (seenX86) - { - if (seenX86_64 || seenM64) -@@ -389,6 +414,9 @@ darwin_driver_init (unsigned int *decoded_options_count, - if (seenX86 || seenX86_64) - warning (0, "this compiler does not support x86" - " (%<-arch%> option ignored)"); -+ else if (seenArm64) -+ warning (0, "this compiler does not support Arm64" -+ " (%<-arch%> option ignored)"); - if (seenPPC) - { - if (seenPPC64 || seenM64) -@@ -408,12 +436,20 @@ darwin_driver_init (unsigned int *decoded_options_count, - if (! seenM64) /* Add -m64 if the User didn't. */ - appendM64 = true; - } -+#elif DARWIN_ARM64 -+ if (seenPPC || seenPPC64) -+ warning (0, "this compiler does not support PowerPC" -+ " (%<-arch%> option ignored)"); -+ if (seenX86 || seenX86_64) -+ warning (0, "this compiler does not support x86" -+ " (%<-arch%> option ignored)"); - #endif - - /* If there is nothing else on the command line, do not add sysroot etc. */ - if (*decoded_options_count <= 1) - return; - -+#if !DARWIN_ARM64 - if (appendM32 || appendM64) - { - ++*decoded_options_count; -@@ -423,6 +459,7 @@ darwin_driver_init (unsigned int *decoded_options_count, - generate_option (appendM32 ? OPT_m32 : OPT_m64, NULL, 1, CL_DRIVER, - &(*decoded_options)[*decoded_options_count - 1]); - } -+#endif - - if (!seen_sysroot_p) - { -@@ -490,4 +527,16 @@ darwin_driver_init (unsigned int *decoded_options_count, - generate_option (OPT_nodefaultexport, NULL, 1, CL_DRIVER, - &(*decoded_options)[*decoded_options_count - 1]); - } -+ -+#ifdef RPATH_SETS_NODEFAULT -+ if (seen_rpath_p && !seen_nodefaultrpaths_p) -+ { -+ ++*decoded_options_count; -+ *decoded_options = XRESIZEVEC (struct cl_decoded_option, -+ *decoded_options, -+ *decoded_options_count); -+ generate_option (OPT_nodefaultrpaths, NULL, 1, CL_DRIVER, -+ &(*decoded_options)[*decoded_options_count - 1]); -+ } -+#endif - } -diff --git a/gcc/config/darwin.cc b/gcc/config/darwin.cc -index f065a13d73d..7cd684c6abe 100644 ---- a/gcc/config/darwin.cc -+++ b/gcc/config/darwin.cc -@@ -118,7 +118,7 @@ static bool ld_init_term_start_labels = false; - section * darwin_sections[NUM_DARWIN_SECTIONS]; - - /* While we transition to using in-tests instead of ifdef'd code. */ --#if !HAVE_lo_sum -+#if !HAVE_lo_sum || DARWIN_ARM64 - #define gen_macho_high(m,a,b) (a) - #define gen_macho_low(m,a,b,c) (a) - #endif -@@ -1052,6 +1052,7 @@ machopic_legitimize_pic_address (rtx orig, machine_mode mode, rtx reg) - return pic_ref; - } - -+#if !DARWIN_ARM64 - /* Callbacks to output the stub or non-lazy pointers. - Each works on the item in *SLOT,if it has been used. - DATA is the FILE* for assembly output. -@@ -1207,6 +1208,7 @@ machopic_finish (FILE *out_file) - machopic_indirections->traverse_noresize - (out_file); - } -+#endif - - int - machopic_operand_p (rtx op) -@@ -1936,6 +1938,8 @@ darwin_label_is_anonymous_local_objc_name (const char *name) - } - else if (startswith ((const char *)p, "ClassMethods")) - return false; -+ else if (startswith ((const char *)p, "ClassProtocols")) -+ return false; - else if (startswith ((const char *)p, "Instance")) - { - if (p[8] == 'I' || p[8] == 'M') -@@ -2238,6 +2242,8 @@ darwin_emit_except_table_label (FILE *file) - rtx - darwin_make_eh_symbol_indirect (rtx orig, bool ARG_UNUSED (pubvis)) - { -+ if (DARWIN_ARM64) -+ return orig; - if (DARWIN_PPC == 0 && TARGET_64BIT) - return orig; - -@@ -3058,7 +3064,12 @@ darwin_file_end (void) - fprintf (asm_out_file, "\t.long\t0\n\t.long\t%u\n", flags); - } - -+#if !DARWIN_ARM64 - machopic_finish (asm_out_file); -+#else -+ gcc_checking_assert (!machopic_indirections); -+#endif -+ - if (flag_apple_kext) - { - /* These sections are only used for kernel code. */ -diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h -index 51e257dc698..13ba6e61474 100644 ---- a/gcc/config/darwin.h -+++ b/gcc/config/darwin.h -@@ -42,6 +42,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see - - #define DARWIN_X86 0 - #define DARWIN_PPC 0 -+#define DARWIN_ARM64 0 - - #define OBJECT_FORMAT_MACHO 1 - -@@ -296,6 +297,31 @@ extern GTY(()) int darwin_ms_struct; - #define DARWIN_CC1_SPEC \ - "% 10.11 mmacosx-version-min= -lgcc_s.1.1) \ -+ %:version-compare(>= 10.11 mmacosx-version-min= -lemutls_w) " -+#endif -+ -+/* We might elect to add a path even when this compiler does not use embedded -+ run paths, so that we can use libraries from an alternate compiler that is -+ using embedded runpaths. */ -+#if DARWIN_DO_EXTRA_RPATH -+# define DARWIN_EXTRA_RPATH \ -+"%{!r:%{!nostdlib:%{!nodefaultrpaths:\ -+ %:version-compare(>= 10.5 mmacosx-version-min= -rpath) \ -+ %:version-compare(>= 10.5 mmacosx-version-min= " DARWIN_ADD_RPATH ") \ -+ }}}" -+#else -+# define DARWIN_EXTRA_RPATH "" -+#endif -+ - #define SUBSUBTARGET_OVERRIDE_OPTIONS \ - do { \ - darwin_override_options (); \ -@@ -387,7 +413,9 @@ extern GTY(()) int darwin_ms_struct; - DARWIN_NOPIE_SPEC \ - DARWIN_RDYNAMIC \ - DARWIN_NOCOMPACT_UNWIND \ -- "}}}}}}} %= 10.6, the unwinder *still* comes from libSystem and -- we find the emutls impl from lemutls_w. In either case, the builtins etc. -- are linked from -lgcc. -- -- When we have specified shared-libgcc or any case that might require -- exceptions, we pull the libgcc content (including emulated tls) from -- -lgcc_s.1 in GCC and the unwinder from /usr/lib/libgcc_s.1 for < 10.6 and -- libSystem for >= 10.6 respectively. -- Otherwise, we just link the emutls/builtins from convenience libs. -- -- If we need exceptions, prior to 10.3.9, then we have to link the static -- eh lib, since there's no shared version on the system. -- -- In all cases, libgcc_s.1 will be installed with the compiler, or any app -- built using it, so we can link the builtins and emutls shared on all. -- - We have to work around that DYLD_XXXX are disabled in macOS 10.11+ which - means that any bootstrap trying to use a shared libgcc with a bumped SO- - name will fail. This means that we do not accept shared libgcc for these -- versions. -+ versions, unless we have embedded run paths enabled, in which case the -+ compiler will add the appropriate path to find the library. -+ -+ For -static-libgcc: < 10.6, use the unwinder in libgcc_eh (and find -+ the emultls impl. there too). - - For -static-libgcc: >= 10.6, the unwinder *still* comes from libSystem and - we find the emutls impl from lemutls_w. In either case, the builtins etc. - are linked from -lgcc. --> -+ - Otherwise, we just link the shared version of gcc_s.1.1 and pick up - exceptions: - * Prior to 10.3.9, then we have to link the static eh lib, since there -@@ -502,6 +515,10 @@ extern GTY(()) int darwin_ms_struct; - - In all cases, libgcc_s.1.1 will be installed with the compiler, or any app - built using it, so we can link the builtins and emutls shared on all. -+ -+ On most Darwin systems (other than Arm64) we will also install a legacy -+ support libgcc_s.1.dylib to support executables linked with libgcc_ext by -+ earlier GCC versions. - */ - #undef REAL_LIBGCC_SPEC - #define REAL_LIBGCC_SPEC \ -@@ -509,8 +526,7 @@ extern GTY(()) int darwin_ms_struct; - %:version-compare(!> 10.6 mmacosx-version-min= -lgcc_eh) \ - %:version-compare(>= 10.6 mmacosx-version-min= -lemutls_w); \ - shared-libgcc|fexceptions|fobjc-exceptions|fgnu-runtime: \ -- %:version-compare(!> 10.11 mmacosx-version-min= -lgcc_s.1.1) \ -- %:version-compare(>= 10.11 mmacosx-version-min= -lemutls_w) \ -+ " DARWIN_SHARED_LIBGCC " \ - %:version-compare(!> 10.3.9 mmacosx-version-min= -lgcc_eh) \ - %:version-compare(>< 10.3.9 10.5 mmacosx-version-min= -lgcc_s.10.4) \ - %:version-compare(>< 10.5 10.6 mmacosx-version-min= -lgcc_s.10.5); \ -@@ -545,7 +561,8 @@ extern GTY(()) int darwin_ms_struct; - { "darwin_crt2", DARWIN_CRT2_SPEC }, \ - { "darwin_crt3", DARWIN_CRT3_SPEC }, \ - { "darwin_dylib1", DARWIN_DYLIB1_SPEC }, \ -- { "darwin_bundle1", DARWIN_BUNDLE1_SPEC }, -+ { "darwin_bundle1", DARWIN_BUNDLE1_SPEC }, \ -+ { "darwin_rpaths", DARWIN_RPATH_SPEC }, - - #define DARWIN_CRT1_SPEC \ - "%:version-compare(!> 10.5 mmacosx-version-min= -lcrt1.o) \ -@@ -571,6 +588,17 @@ extern GTY(()) int darwin_ms_struct; - "%{!static:%:version-compare(< 10.6 mmacosx-version-min= -lbundle1.o) \ - %{fgnu-tm: -lcrttms.o}}" - -+#if DARWIN_AT_RPATH -+/* A default rpath, that picks up dependent libraries installed in the same -+ director as one being loaded. */ -+#define DARWIN_RPATH_SPEC \ -+ "%:version-compare(>= 10.5 mmacosx-version-min= -rpath) \ -+ %:version-compare(>= 10.5 mmacosx-version-min= @loader_path) \ -+ %P " -+#else -+#define DARWIN_RPATH_SPEC "" -+#endif -+ - #ifdef HAVE_AS_MMACOSX_VERSION_MIN_OPTION - /* Emit macosx version (but only major). */ - #define ASM_MMACOSX_VERSION_MIN_SPEC \ -diff --git a/gcc/config/darwin.opt b/gcc/config/darwin.opt -index cc7d14c2e4d..b1cb8464d57 100644 ---- a/gcc/config/darwin.opt -+++ b/gcc/config/darwin.opt -@@ -237,6 +237,10 @@ nodefaultexport - Driver RejectNegative - Do not add a default symbol exports to modules or dynamic libraries. - -+nodefaultrpaths -+Driver RejectNegative -+Do not add default run paths (for the compiler library directories) to executables, modules or dynamic libraries. -+ - nofixprebinding - Driver RejectNegative - (Obsolete after 10.3.9) Set MH_NOPREFIXBINDING, in an executable. -diff --git a/gcc/config/i386/darwin.h b/gcc/config/i386/darwin.h -index a55f6b2b874..36a32867281 100644 ---- a/gcc/config/i386/darwin.h -+++ b/gcc/config/i386/darwin.h -@@ -308,3 +308,10 @@ along with GCC; see the file COPYING3. If not see - #define CLEAR_INSN_CACHE(beg, end) \ - extern void sys_icache_invalidate(void *start, size_t len); \ - sys_icache_invalidate ((beg), (size_t)((end)-(beg))) -+ -+/* Disable custom function descriptors for Darwin when we have off-stack -+ trampolines. */ -+#undef X86_CUSTOM_FUNCTION_TEST -+#define X86_CUSTOM_FUNCTION_TEST \ -+ (!flag_off_stack_trampolines && !flag_trampolines) ? 1 : 0 -+ -diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc -index 9dd9fa68722..5cd4b5c0592 100644 ---- a/gcc/config/i386/i386.cc -+++ b/gcc/config/i386/i386.cc -@@ -24698,7 +24698,7 @@ ix86_libgcc_floating_mode_supported_p - #define TARGET_HARD_REGNO_SCRATCH_OK ix86_hard_regno_scratch_ok - - #undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS --#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 1 -+#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS X86_CUSTOM_FUNCTION_TEST - - #undef TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID - #define TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID ix86_addr_space_zero_address_valid -diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h -index 363082ba47b..5f56d7abf65 100644 ---- a/gcc/config/i386/i386.h -+++ b/gcc/config/i386/i386.h -@@ -746,6 +746,12 @@ extern const char *host_detect_local_cpu (int argc, const char **argv); - /* Minimum allocation boundary for the code of a function. */ - #define FUNCTION_BOUNDARY 8 - -+/* We will and with this value to test if a custom function descriptor needs -+ a static chain. The function boundary must the adjusted so that the bit -+ this represents is no longer part of the address. 0 Disables the custom -+ function descriptors. */ -+#define X86_CUSTOM_FUNCTION_TEST 1 -+ - /* C++ stores the virtual bit in the lowest bit of function pointers. */ - #define TARGET_PTRMEMFUNC_VBIT_LOCATION ptrmemfunc_vbit_in_pfn - -diff --git a/gcc/configure b/gcc/configure -index 5ce0557719a..dbc127c59cb 100755 ---- a/gcc/configure -+++ b/gcc/configure -@@ -634,6 +634,7 @@ LIBOBJS - CET_HOST_FLAGS - NO_PIE_FLAG - NO_PIE_CFLAGS -+enable_pie_tools - enable_default_pie - PICFLAG - enable_host_shared -@@ -740,6 +741,8 @@ ORIGINAL_PLUGIN_LD_FOR_TARGET - gcc_cv_ld - ORIGINAL_AS_FOR_TARGET - gcc_cv_as -+ENABLE_DARWIN_AT_RPATH_FALSE -+ENABLE_DARWIN_AT_RPATH_TRUE - enable_fast_install - objdir - OTOOL64 -@@ -1000,6 +1003,8 @@ enable_static - with_pic - enable_fast_install - enable_libtool_lock -+enable_darwin_at_rpath -+with_darwin_extra_rpath - enable_ld - enable_gold - with_plugin_ld -@@ -1030,6 +1035,7 @@ with_linker_hash_style - with_diagnostics_color - with_diagnostics_urls - enable_default_pie -+enable_pie_tools - enable_cet - enable_s390_excess_float_precision - ' -@@ -1733,6 +1739,8 @@ Optional Features: - --enable-fast-install[=PKGS] - optimize for fast installation [default=yes] - --disable-libtool-lock avoid locking (might break parallel builds) -+ --enable-darwin-at-path install libraries with @rpath/library-name, requires -+ rpaths to be added to executables - --enable-ld[=ARG] build ld [ARG={default,yes,no}] - --enable-gold[=ARG] build gold [ARG={default,yes,no}] - --enable-gnu-indirect-function -@@ -1790,6 +1798,8 @@ Optional Features: - --disable-libquadmath-support - disable libquadmath support for Fortran - --enable-default-pie enable Position Independent Executable as default -+ --enable-pie-tools build Position Independent Executables for the -+ compilers and other tools - --enable-cet enable Intel CET in host libraries [default=auto] - --enable-s390-excess-float-precision - on s390 targets, evaluate float with double -@@ -1850,6 +1860,9 @@ Optional Packages: - --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] -+ --with-darwin-extra-rpath=[ARG] -+ Specify a runpath directory, additional to those -+ provided by the compiler - --with-plugin-ld=[ARG] specify the plugin linker - --with-glibc-version=M.N - assume GCC used with glibc version M.N or later -@@ -3766,15 +3779,24 @@ if test x${gcc_gxx_libcxx_include_dir} != x; then - $as_echo "#define ENABLE_STDLIB_OPTION 1" >>confdefs.h - - else -- $as_echo "#define ENABLE_STDLIB_OPTION 0" >>confdefs.h -+ case $target in -+ *-darwin1[1-9]* | *-darwin2*) -+ # Default this on for Darwin versions which default to libcxx. -+ $as_echo "#define ENABLE_STDLIB_OPTION 1" >>confdefs.h - -+ ;; -+ *) -+ $as_echo "#define ENABLE_STDLIB_OPTION 0" >>confdefs.h -+ -+ ;; -+ esac - fi --# ??? This logic must match libstdc++-v3/acinclude.m4:GLIBCXX_EXPORT_INSTALL_INFO. -+ - if test x${gcc_gxx_libcxx_include_dir} = x; then -+ libcxx_incdir='include/c++/v1' - if test x${enable_version_specific_runtime_libs} = xyes; then -- gcc_gxx_libcxx_include_dir='${libsubdir}/libc++_include/c++/v1' -+ gcc_gxx_libcxx_include_dir='${libsubdir}/$libcxx_incdir' - else -- libcxx_incdir='libc++_include/c++/$(version)/v1' - if test x$host != x$target; then - libcxx_incdir="$target_alias/$libcxx_incdir" - fi -@@ -17867,6 +17889,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc=no - hardcode_direct=no - hardcode_automatic=yes -@@ -17884,10 +17947,19 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - - else - ld_shlibs=no -@@ -19673,7 +19745,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 19676 "configure" -+#line 19748 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -19779,7 +19851,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 19782 "configure" -+#line 19854 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -20655,6 +20727,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc_CXX=no - hardcode_direct_CXX=no - hardcode_automatic_CXX=yes -@@ -20672,12 +20785,25 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - if test "$lt_cv_apple_cc_single_mod" != "yes"; then -- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring${_lt_dsymutil}" -+ else -+ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" -+ fi - archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" - fi - -@@ -23028,6 +23154,35 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu - - - -+ if test x$enable_darwin_at_rpath = xyes; then -+ ENABLE_DARWIN_AT_RPATH_TRUE= -+ ENABLE_DARWIN_AT_RPATH_FALSE='#' -+else -+ ENABLE_DARWIN_AT_RPATH_TRUE='#' -+ ENABLE_DARWIN_AT_RPATH_FALSE= -+fi -+ -+DARWIN_DO_EXTRA_RPATH=0 -+ -+# Check whether --with-darwin-extra-rpath was given. -+if test "${with_darwin_extra_rpath+set}" = set; then : -+ withval=$with_darwin_extra_rpath; if test x"$withval" != x; then -+ DARWIN_ADD_RPATH="$withval" -+ DARWIN_DO_EXTRA_RPATH=1 -+ fi -+fi -+ -+ -+cat >>confdefs.h <<_ACEOF -+#define DARWIN_DO_EXTRA_RPATH $DARWIN_DO_EXTRA_RPATH -+_ACEOF -+ -+ -+cat >>confdefs.h <<_ACEOF -+#define DARWIN_ADD_RPATH "$DARWIN_ADD_RPATH" -+_ACEOF -+ -+ - # Identify the assembler which will work hand-in-glove with the newly - # built GCC, so that we can examine its features. This is the assembler - # which will be driven by the driver program. -@@ -32429,6 +32584,22 @@ $as_echo "#define ENABLE_DEFAULT_PIE 1" >>confdefs.h - fi - - -+# Check whether --enable-pie-tools was given; this is passed automatically -+# from the top level where it has already been validated. -+# Check whether --enable-pie-tools was given. -+if test "${enable_pie_tools+set}" = set; then : -+ enableval=$enable_pie_tools; enable_pie_tools=$enableval -+else -+ enable_pie_tools=no -+fi -+ -+if test x$enable_pie_tools = xyes ; then -+ -+$as_echo "#define ENABLE_PIE_TOOLS 1" >>confdefs.h -+ -+fi -+ -+ - # Check if -fno-PIE works. - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -fno-PIE option" >&5 - $as_echo_n "checking for -fno-PIE option... " >&6; } -@@ -32966,6 +33137,10 @@ LTLIBOBJS=$ac_ltlibobjs - - - -+if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then -+ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. -+Usually this means the macro was only invoked conditionally." "$LINENO" 5 -+fi - - : "${CONFIG_STATUS=./config.status}" - ac_write_fail=0 -diff --git a/gcc/configure.ac b/gcc/configure.ac -index 23bee7010a3..2d9159989e4 100644 ---- a/gcc/configure.ac -+++ b/gcc/configure.ac -@@ -249,14 +249,22 @@ if test x${gcc_gxx_libcxx_include_dir} != x; then - AC_DEFINE(ENABLE_STDLIB_OPTION, 1, - [Define if the -stdlib= option should be enabled.]) - else -- AC_DEFINE(ENABLE_STDLIB_OPTION, 0) -+ case $target in -+ *-darwin1[[1-9]]* | *-darwin2*) -+ # Default this on for Darwin versions which default to libcxx. -+ AC_DEFINE(ENABLE_STDLIB_OPTION, 1) -+ ;; -+ *) -+ AC_DEFINE(ENABLE_STDLIB_OPTION, 0) -+ ;; -+ esac - fi --# ??? This logic must match libstdc++-v3/acinclude.m4:GLIBCXX_EXPORT_INSTALL_INFO. -+ - if test x${gcc_gxx_libcxx_include_dir} = x; then -+ libcxx_incdir='include/c++/v1' - if test x${enable_version_specific_runtime_libs} = xyes; then -- gcc_gxx_libcxx_include_dir='${libsubdir}/libc++_include/c++/v1' -+ gcc_gxx_libcxx_include_dir='${libsubdir}/$libcxx_incdir' - else -- libcxx_incdir='libc++_include/c++/$(version)/v1' - if test x$host != x$target; then - libcxx_incdir="$target_alias/$libcxx_incdir" - fi -@@ -2559,6 +2567,21 @@ AC_PROG_LIBTOOL - AC_SUBST(objdir) - AC_SUBST(enable_fast_install) - -+AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) -+DARWIN_DO_EXTRA_RPATH=0 -+AC_ARG_WITH(darwin-extra-rpath, -+[AS_HELP_STRING( -+ [[--with-darwin-extra-rpath=[ARG]]], -+ [Specify a runpath directory, additional to those provided by the compiler])], -+[if test x"$withval" != x; then -+ DARWIN_ADD_RPATH="$withval" -+ DARWIN_DO_EXTRA_RPATH=1 -+ fi]) -+AC_DEFINE_UNQUOTED(DARWIN_DO_EXTRA_RPATH, $DARWIN_DO_EXTRA_RPATH, -+ [Should add an extra runpath directory]) -+AC_DEFINE_UNQUOTED(DARWIN_ADD_RPATH, "$DARWIN_ADD_RPATH", -+ [Specify a runpath directory, additional to those provided by the compiler]) -+ - # Identify the assembler which will work hand-in-glove with the newly - # built GCC, so that we can examine its features. This is the assembler - # which will be driven by the driver program. -@@ -7646,6 +7669,19 @@ if test x$enable_default_pie = xyes ; then - fi - AC_SUBST([enable_default_pie]) - -+# Check whether --enable-pie-tools was given; this is passed automatically -+# from the top level where it has already been validated. -+AC_ARG_ENABLE(pie-tools, -+[AS_HELP_STRING([--enable-pie-tools], -+ [build Position Independent Executables for the compilers and other tools])], -+[enable_pie_tools=$enableval], -+[enable_pie_tools=no]) -+if test x$enable_pie_tools = xyes ; then -+ AC_DEFINE(ENABLE_PIE_TOOLS, 1, -+ [Define if you build Position Independent Executables for the compilers and other tools.]) -+fi -+AC_SUBST([enable_pie_tools]) -+ - # Check if -fno-PIE works. - AC_CACHE_CHECK([for -fno-PIE option], - [gcc_cv_c_no_fpie], -diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc -index d7e9980ff1e..ff2a1f6665f 100644 ---- a/gcc/cp/decl2.cc -+++ b/gcc/cp/decl2.cc -@@ -3653,9 +3653,8 @@ get_tls_init_fn (tree var) - if (!flag_extern_tls_init && DECL_EXTERNAL (var)) - return NULL_TREE; - -- /* If the variable is internal, or if we can't generate aliases, -- call the local init function directly. */ -- if (!TREE_PUBLIC (var) || !TARGET_SUPPORTS_ALIASES) -+ /* If the variable is internal call the local init function directly. */ -+ if (!TREE_PUBLIC (var)) - return get_local_tls_init_fn (DECL_SOURCE_LOCATION (var)); - - tree sname = mangle_tls_init_fn (var); -@@ -4801,22 +4800,24 @@ handle_tls_init (void) - finish_expr_stmt (cp_build_modify_expr (loc, guard, NOP_EXPR, - boolean_true_node, - tf_warning_or_error)); -+ auto_vec direct_calls; - for (; vars; vars = TREE_CHAIN (vars)) - { - tree var = TREE_VALUE (vars); - tree init = TREE_PURPOSE (vars); - one_static_initialization_or_destruction (var, init, true); - -- /* Output init aliases even with -fno-extern-tls-init. */ -- if (TARGET_SUPPORTS_ALIASES && TREE_PUBLIC (var)) -+ /* Output inits even with -fno-extern-tls-init. -+ We save the list here and output either an alias or a stub function -+ below. */ -+ if (TREE_PUBLIC (var)) - { -- tree single_init_fn = get_tls_init_fn (var); -+ tree single_init_fn = get_tls_init_fn (var); - if (single_init_fn == NULL_TREE) - continue; -- cgraph_node *alias -- = cgraph_node::get_create (fn)->create_same_body_alias -- (single_init_fn, fn); -- gcc_assert (alias != NULL); -+ if (single_init_fn == fn) -+ continue; -+ direct_calls.safe_push (single_init_fn); - } - } - -@@ -4824,6 +4825,30 @@ handle_tls_init (void) - finish_if_stmt (if_stmt); - finish_function_body (body); - expand_or_defer_fn (finish_function (/*inline_p=*/false)); -+ -+ /* For each TLS var that we have an init function, we either emit an alias -+ between that and the tls_init, or a stub function that just calls the -+ tls_init. */ -+ while (!direct_calls.is_empty()) -+ { -+ tree single_init_fn = direct_calls.pop (); -+ if (TARGET_SUPPORTS_ALIASES) -+ { -+ cgraph_node *alias -+ = cgraph_node::get_create (fn)->create_same_body_alias -+ (single_init_fn, fn); -+ gcc_assert (alias != NULL); -+ } -+ else -+ { -+ start_preparsed_function (single_init_fn, NULL_TREE, SF_PRE_PARSED); -+ tree body = begin_function_body (); -+ tree r = build_call_expr (fn, 0); -+ finish_expr_stmt (r); -+ finish_function_body (body); -+ expand_or_defer_fn (finish_function (/*inline_p=*/false)); -+ } -+ } - } - - /* We're at the end of compilation, so generate any mangling aliases that -diff --git a/gcc/cp/g++spec.cc b/gcc/cp/g++spec.cc -index 8174d652776..2e1e06e6ac9 100644 ---- a/gcc/cp/g++spec.cc -+++ b/gcc/cp/g++spec.cc -@@ -222,7 +222,12 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, - - case OPT_static_libstdc__: - library = library >= 0 ? 2 : library; -+#ifdef HAVE_LD_STATIC_DYNAMIC -+ /* Remove -static-libstdc++ from the command only if target supports -+ LD_STATIC_DYNAMIC. When not supported, it is left in so that a -+ back-end target can use outfile substitution. */ - args[i] |= SKIPOPT; -+#endif - break; - - case OPT_stdlib_: -diff --git a/gcc/cumulative-args.h b/gcc/cumulative-args.h -new file mode 100644 -index 00000000000..b60928e37f9 ---- /dev/null -+++ b/gcc/cumulative-args.h -@@ -0,0 +1,20 @@ -+#ifndef GCC_CUMULATIVE_ARGS_H -+#define GCC_CUMULATIVE_ARGS_H -+ -+#if CHECKING_P -+ -+struct cumulative_args_t { void *magic; void *p; }; -+ -+#else /* !CHECKING_P */ -+ -+/* When using a GCC build compiler, we could use -+ __attribute__((transparent_union)) to get cumulative_args_t function -+ arguments passed like scalars where the ABI would mandate a less -+ efficient way of argument passing otherwise. However, that would come -+ at the cost of less type-safe !CHECKING_P compilation. */ -+ -+union cumulative_args_t { void *p; }; -+ -+#endif /* !CHECKING_P */ -+ -+#endif /* GCC_CUMULATIVE_ARGS_H */ -diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi -index ff6c338bedb..55c8ba8969f 100644 ---- a/gcc/doc/invoke.texi -+++ b/gcc/doc/invoke.texi -@@ -670,6 +670,7 @@ Objective-C and Objective-C++ Dialects}. - @gccoptlist{-fcall-saved-@var{reg} -fcall-used-@var{reg} @gol - -ffixed-@var{reg} -fexceptions @gol - -fnon-call-exceptions -fdelete-dead-exceptions -funwind-tables @gol -+-foff-stack-trampolines @gol - -fasynchronous-unwind-tables @gol - -fno-gnu-unique @gol - -finhibit-size-directive -fcommon -fno-ident @gol -@@ -680,6 +681,7 @@ Objective-C and Objective-C++ Dialects}. - -fverbose-asm -fpack-struct[=@var{n}] @gol - -fleading-underscore -ftls-model=@var{model} @gol - -fstack-reuse=@var{reuse_level} @gol -+-fstack-use-cumulative-args @gol - -ftrampolines -ftrapv -fwrapv @gol - -fvisibility=@r{[}default@r{|}internal@r{|}hidden@r{|}protected@r{]} @gol - -fstrict-volatile-bitfields -fsync-libcalls} -@@ -17071,6 +17073,17 @@ the behavior of older compilers in which temporaries' stack space is - not reused, the aggressive stack reuse can lead to runtime errors. This - option is used to control the temporary stack reuse optimization. - -+@item -fstack-use-cumulative-args -+@opindex fstack_use_cumulative_args -+This option instructs the compiler to use the -+@code{cumulative_args_t}-based stack layout target hooks, -+@code{TARGET_FUNCTION_ARG_BOUNDARY_CA} and -+@code{TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA}. If a given target does -+not define these hooks, the default behaviour is to fallback to using -+the standard non-@code{_CA} variants instead. Certain targets (such as -+AArch64 Darwin) require using the more advanced @code{_CA}-based -+hooks: For these targets this option should be enabled by default. -+ - @item -ftrapv - @opindex ftrapv - This option generates traps for signed overflow on addition, subtraction, -@@ -17129,6 +17142,19 @@ instructions. It does not allow exceptions to be thrown from - arbitrary signal handlers such as @code{SIGALRM}. This enables - @option{-fexceptions}. - -+@item -foff-stack-trampolines -+@opindex foff-stack-trampolines -+Certain platforms (such as the Apple M1) do not permit an executable -+stack. Generate calls to @code{__builtin_nested_func_ptr_created} and -+@code{__builtin_nested_func_ptr_deleted} in order to allocate and -+deallocate trampoline space on the executable heap. Please note that -+these functions are implemented in libgcc, and will not be compiled in -+unless you provide @option{--enable-off-stack-trampolines} when -+building gcc. @emph{PLEASE NOTE}: The trampolines are @emph{not} -+guaranteed to be correctly deallocated if you @code{setjmp}, -+instantiate nested functions, and then @code{longjmp} back to a state -+prior to having allocated those nested functions. -+ - @item -fdelete-dead-exceptions - @opindex fdelete-dead-exceptions - Consider that instructions that may throw exceptions but don't otherwise -diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi -index c5006afc00d..366360612e3 100644 ---- a/gcc/doc/tm.texi -+++ b/gcc/doc/tm.texi -@@ -4322,6 +4322,16 @@ with the specified mode and type. The default hook returns - @code{PARM_BOUNDARY} for all arguments. - @end deftypefn - -+@deftypefn {Target Hook} {unsigned int} TARGET_FUNCTION_ARG_BOUNDARY_CA (machine_mode @var{mode}, const_tree @var{type}, cumulative_args_t @var{ca}) -+This is the @code{cumulative_args_t}-based version of -+@code{TARGET_FUNCTION_ARG_BOUNDARY}. Define this hook if you need more -+fine-grained control over argument alignment, e.g. depending on whether -+it is a named argument or not, or any other criteria that you choose to -+place in the @var{ca} structure. -+ -+The default hook will call @code{TARGET_FUNCTION_ARG_BOUNDARY}. -+@end deftypefn -+ - @deftypefn {Target Hook} {unsigned int} TARGET_FUNCTION_ARG_ROUND_BOUNDARY (machine_mode @var{mode}, const_tree @var{type}) - Normally, the size of an argument is rounded up to @code{PARM_BOUNDARY}, - which is the default value for this hook. You can define this hook to -@@ -4329,6 +4339,16 @@ return a different value if an argument size must be rounded to a larger - value. - @end deftypefn - -+@deftypefn {Target Hook} {unsigned int} TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA (machine_mode @var{mode}, const_tree @var{type}, cumulative_args_t @var{ca}) -+This is the @code{cumulative_args_t}-based version of -+@code{TARGET_FUNCTION_ARG_ROUND_BOUNDARY}. Define this hook if you need more -+fine-grained control over argument size rounding, e.g. depending on whether -+it is a named argument or not, or any other criteria that you choose to -+place in the @var{ca} structure. -+ -+The default hook will call @code{TARGET_FUNCTION_ARG_ROUND_BOUNDARY}. -+@end deftypefn -+ - @defmac FUNCTION_ARG_REGNO_P (@var{regno}) - A C expression that is nonzero if @var{regno} is the number of a hard - register in which function arguments are sometimes passed. This does -diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in -index f869ddd5e5b..2c9f0f0bf14 100644 ---- a/gcc/doc/tm.texi.in -+++ b/gcc/doc/tm.texi.in -@@ -3330,8 +3330,12 @@ required. - - @hook TARGET_FUNCTION_ARG_BOUNDARY - -+@hook TARGET_FUNCTION_ARG_BOUNDARY_CA -+ - @hook TARGET_FUNCTION_ARG_ROUND_BOUNDARY - -+@hook TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA -+ - @defmac FUNCTION_ARG_REGNO_P (@var{regno}) - A C expression that is nonzero if @var{regno} is the number of a hard - register in which function arguments are sometimes passed. This does -diff --git a/gcc/function.cc b/gcc/function.cc -index ad0096a43ef..e5044a60741 100644 ---- a/gcc/function.cc -+++ b/gcc/function.cc -@@ -2445,7 +2445,10 @@ assign_parm_find_data_types (struct assign_parm_data_all *all, tree parm, - else if (DECL_CHAIN (parm)) - data->arg.named = 1; /* Not the last non-variadic parm. */ - else if (targetm.calls.strict_argument_naming (all->args_so_far)) -- data->arg.named = 1; /* Only variadic ones are unnamed. */ -+ { -+ data->arg.named = 1; /* Only variadic ones are unnamed. */ -+ data->arg.last_named = 1; -+ } - else - data->arg.named = 0; /* Treat as variadic. */ - -@@ -2502,6 +2505,7 @@ assign_parms_setup_varargs (struct assign_parm_data_all *all, - - function_arg_info last_named_arg = data->arg; - last_named_arg.named = true; -+ last_named_arg.last_named = true; - targetm.calls.setup_incoming_varargs (all->args_so_far, last_named_arg, - &varargs_pretend_bytes, no_rtl); - -@@ -2610,7 +2614,9 @@ assign_parm_find_entry_rtl (struct assign_parm_data_all *all, - - locate_and_pad_parm (data->arg.mode, data->arg.type, in_regs, - all->reg_parm_stack_space, -- entry_parm ? data->partial : 0, current_function_decl, -+ entry_parm ? data->partial : 0, -+ all->args_so_far, -+ current_function_decl, - &all->stack_args_size, &data->locate); - - /* Update parm_stack_boundary if this parameter is passed in the -@@ -3924,7 +3930,8 @@ gimplify_parameters (gimple_seq *cleanup) - if (data.arg.pass_by_reference) - { - tree type = TREE_TYPE (data.arg.type); -- function_arg_info orig_arg (type, data.arg.named); -+ function_arg_info orig_arg (type, data.arg.named, -+ data.arg.last_named); - if (reference_callee_copied (&all.args_so_far_v, orig_arg)) - { - tree local, t; -@@ -4027,6 +4034,7 @@ gimplify_parameters (gimple_seq *cleanup) - void - locate_and_pad_parm (machine_mode passed_mode, tree type, int in_regs, - int reg_parm_stack_space, int partial, -+ cumulative_args_t ca, - tree fndecl ATTRIBUTE_UNUSED, - struct args_size *initial_offset_ptr, - struct locate_and_pad_arg_data *locate) -@@ -4064,9 +4072,23 @@ locate_and_pad_parm (machine_mode passed_mode, tree type, int in_regs, - ? arg_size_in_bytes (type) - : size_int (GET_MODE_SIZE (passed_mode))); - where_pad = targetm.calls.function_arg_padding (passed_mode, type); -- boundary = targetm.calls.function_arg_boundary (passed_mode, type); -- round_boundary = targetm.calls.function_arg_round_boundary (passed_mode, -- type); -+ -+ if (flag_stack_use_cumulative_args) -+ { -+ boundary = targetm.calls.function_arg_boundary_ca (passed_mode, -+ type, -+ ca); -+ round_boundary = targetm.calls.function_arg_round_boundary_ca -+ (passed_mode, type, ca); -+ } -+ else -+ { -+ boundary = targetm.calls.function_arg_boundary (passed_mode, -+ type); -+ round_boundary = targetm.calls.function_arg_round_boundary -+ (passed_mode, type); -+ } -+ - locate->where_pad = where_pad; - - /* Alignment can't exceed MAX_SUPPORTED_STACK_ALIGNMENT. */ -diff --git a/gcc/function.h b/gcc/function.h -index 098613766be..009a9dc1c44 100644 ---- a/gcc/function.h -+++ b/gcc/function.h -@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3. If not see - #ifndef GCC_FUNCTION_H - #define GCC_FUNCTION_H - -+#include "cumulative-args.h" - - /* Stack of pending (incomplete) sequences saved by `start_sequence'. - Each element describes one pending sequence. -@@ -661,6 +662,7 @@ extern int aggregate_value_p (const_tree, const_tree); - extern bool use_register_for_decl (const_tree); - extern gimple_seq gimplify_parameters (gimple_seq *); - extern void locate_and_pad_parm (machine_mode, tree, int, int, int, -+ cumulative_args_t, - tree, struct args_size *, - struct locate_and_pad_arg_data *); - extern void generate_setjmp_warnings (void); -diff --git a/gcc/gcc.cc b/gcc/gcc.cc -index bb07cc244e3..a16c1e4372b 100644 ---- a/gcc/gcc.cc -+++ b/gcc/gcc.cc -@@ -572,6 +572,7 @@ or with constant text in a single argument. - %l process LINK_SPEC as a spec. - %L process LIB_SPEC as a spec. - %M Output multilib_os_dir. -+ %P Output a RUNPATH_OPTION for each directory in startfile_prefixes. - %G process LIBGCC_SPEC as a spec. - %R Output the concatenation of target_system_root and - target_sysroot_suffix. -@@ -1191,6 +1192,10 @@ proper position among the other output files. */ - # define SYSROOT_HEADERS_SUFFIX_SPEC "" - #endif - -+#ifndef RUNPATH_OPTION -+# define RUNPATH_OPTION "-rpath" -+#endif -+ - static const char *asm_debug = ASM_DEBUG_SPEC; - static const char *asm_debug_option = ASM_DEBUG_OPTION_SPEC; - static const char *cpp_spec = CPP_SPEC; -@@ -5895,6 +5900,7 @@ struct spec_path_info { - size_t append_len; - bool omit_relative; - bool separate_options; -+ bool realpaths; - }; - - static void * -@@ -5904,6 +5910,16 @@ spec_path (char *path, void *data) - size_t len = 0; - char save = 0; - -+ /* The path must exist; we want to resolve it to the realpath so that this -+ can be embedded as a runpath. */ -+ if (info->realpaths) -+ path = lrealpath (path); -+ -+ /* However, if we failed to resolve it - perhaps because there was a bogus -+ -B option on the command line, then punt on this entry. */ -+ if (!path) -+ return NULL; -+ - if (info->omit_relative && !IS_ABSOLUTE_PATH (path)) - return NULL; - -@@ -6135,6 +6151,22 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part) - info.omit_relative = false; - #endif - info.separate_options = false; -+ info.realpaths = false; -+ -+ for_each_path (&startfile_prefixes, true, 0, spec_path, &info); -+ } -+ break; -+ -+ case 'P': -+ { -+ struct spec_path_info info; -+ -+ info.option = RUNPATH_OPTION; -+ info.append_len = 0; -+ info.omit_relative = false; -+ info.separate_options = true; -+ /* We want to embed the actual paths that have the libraries. */ -+ info.realpaths = true; - - for_each_path (&startfile_prefixes, true, 0, spec_path, &info); - } -@@ -6461,6 +6493,7 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part) - info.append_len = strlen (info.append); - info.omit_relative = false; - info.separate_options = true; -+ info.realpaths = false; - - for_each_path (&include_prefixes, false, info.append_len, - spec_path, &info); -diff --git a/gcc/ginclude/stddef.h b/gcc/ginclude/stddef.h -index 79e296d4a66..a9caa0467ba 100644 ---- a/gcc/ginclude/stddef.h -+++ b/gcc/ginclude/stddef.h -@@ -427,9 +427,8 @@ typedef struct { - /* _Float128 is defined as a basic type, so max_align_t must be - sufficiently aligned for it. This code must work in C++, so we - use __float128 here; that is only available on some -- architectures, but only on i386 is extra alignment needed for -- __float128. */ --#ifdef __i386__ -+ architectures. */ -+#if defined(__i386__) || (__APPLE__ && __aarch64__) - __float128 __max_align_f128 __attribute__((__aligned__(__alignof(__float128)))); - #endif - } max_align_t; -diff --git a/gcc/jit/Make-lang.in b/gcc/jit/Make-lang.in -index 6e10abfd0ac..5a39342068d 100644 ---- a/gcc/jit/Make-lang.in -+++ b/gcc/jit/Make-lang.in -@@ -43,6 +43,7 @@ - LIBGCCJIT_VERSION_NUM = 0 - LIBGCCJIT_MINOR_NUM = 0 - LIBGCCJIT_RELEASE_NUM = 1 -+COMMA := , - - ifneq (,$(findstring mingw,$(target))) - LIBGCCJIT_FILENAME = libgccjit-$(LIBGCCJIT_VERSION_NUM).dll -@@ -59,22 +60,18 @@ LIBGCCJIT_AGE = 1 - LIBGCCJIT_BASENAME = libgccjit - - LIBGCCJIT_SONAME = \ -- ${libdir}/$(LIBGCCJIT_BASENAME).$(LIBGCCJIT_VERSION_NUM).dylib -+ $(DARWIN_RPATH)/$(LIBGCCJIT_BASENAME).$(LIBGCCJIT_VERSION_NUM).dylib - LIBGCCJIT_FILENAME = $(LIBGCCJIT_BASENAME).$(LIBGCCJIT_VERSION_NUM).dylib - LIBGCCJIT_LINKER_NAME = $(LIBGCCJIT_BASENAME).dylib - --# Conditionalize the use of the LD_VERSION_SCRIPT_OPTION and --# LD_SONAME_OPTION depending if configure found them, using $(if) --# We have to define a COMMA here, otherwise the commas in the "true" --# result are treated as separators by the $(if). --COMMA := , --LIBGCCJIT_VERSION_SCRIPT_OPTION = \ -- $(if $(LD_VERSION_SCRIPT_OPTION),\ -- -Wl$(COMMA)$(LD_VERSION_SCRIPT_OPTION)$(COMMA)$(srcdir)/jit/libgccjit.map) -+# TODO: translate the libgccjit.map into a form usable by Darwin's linker and -+# then check for linker support for -exported_symbols_list=. Omitting this -+# means that all symbols in the libgccjit library will be visible. -+LIBGCCJIT_VERSION_SCRIPT_OPTION = - --LIBGCCJIT_SONAME_OPTION = \ -- $(if $(LD_SONAME_OPTION), \ -- -Wl$(COMMA)$(LD_SONAME_OPTION)$(COMMA)$(LIBGCCJIT_SONAME)) -+# This is a work-around fix for cross-compilation where the target linker -+# is ld and the host is ld64. -+LIBGCCJIT_SONAME_OPTION = -Wl,-install_name,$(LIBGCCJIT_SONAME) - - LIBGCCJIT_SONAME_SYMLINK = $(LIBGCCJIT_FILENAME) - LIBGCCJIT_LINKER_NAME_SYMLINK = $(LIBGCCJIT_LINKER_NAME) -@@ -98,7 +95,6 @@ LIBGCCJIT_SONAME_SYMLINK = $(LIBGCCJIT_SONAME) - # LD_SONAME_OPTION depending if configure found them, using $(if) - # We have to define a COMMA here, otherwise the commas in the "true" - # result are treated as separators by the $(if). --COMMA := , - LIBGCCJIT_VERSION_SCRIPT_OPTION = \ - $(if $(LD_VERSION_SCRIPT_OPTION),\ - -Wl$(COMMA)$(LD_VERSION_SCRIPT_OPTION)$(COMMA)$(srcdir)/jit/libgccjit.map) -diff --git a/gcc/objc/objc-next-runtime-abi-02.cc b/gcc/objc/objc-next-runtime-abi-02.cc -index e50ca6e89f5..9ea63b189c7 100644 ---- a/gcc/objc/objc-next-runtime-abi-02.cc -+++ b/gcc/objc/objc-next-runtime-abi-02.cc -@@ -1033,6 +1033,7 @@ next_runtime_abi_02_protocol_decl (tree p) - else - decl = start_var_decl (objc_v2_protocol_template, buf); - OBJCMETA (decl, objc_meta, meta_protocol); -+ DECL_PRESERVE_P (decl) = 1; - return decl; - } - -@@ -2115,8 +2116,8 @@ build_v2_classrefs_table (void) - expr = convert (objc_class_type, build_fold_addr_expr (expr)); - } - /* The runtime wants this, even if it appears unused, so we must force the -- output. -- DECL_PRESERVE_P (decl) = 1; */ -+ output. */ -+ DECL_PRESERVE_P (decl) = 1; - finish_var_decl (decl, expr); - } - } -@@ -2318,6 +2319,7 @@ build_v2_protocol_list_address_table (void) - expr = convert (objc_protocol_type, build_fold_addr_expr (ref->refdecl)); - OBJCMETA (decl, objc_meta, meta_label_protocollist); - finish_var_decl (decl, expr); -+ DECL_PRESERVE_P (decl) = 1; - } - - /* TODO: delete the vec. */ -diff --git a/gcc/target.def b/gcc/target.def -index d85adf36a39..5eb1fdce24e 100644 ---- a/gcc/target.def -+++ b/gcc/target.def -@@ -4967,6 +4967,18 @@ with the specified mode and type. The default hook returns\n\ - unsigned int, (machine_mode mode, const_tree type), - default_function_arg_boundary) - -+DEFHOOK -+(function_arg_boundary_ca, -+ "This is the @code{cumulative_args_t}-based version of\n\ -+@code{TARGET_FUNCTION_ARG_BOUNDARY}. Define this hook if you need more\n\ -+fine-grained control over argument alignment, e.g. depending on whether\n\ -+it is a named argument or not, or any other criteria that you choose to\n\ -+place in the @var{ca} structure.\n\ -+\n\ -+The default hook will call @code{TARGET_FUNCTION_ARG_BOUNDARY}.", -+ unsigned int, (machine_mode mode, const_tree type, cumulative_args_t ca), -+ default_function_arg_boundary_ca) -+ - DEFHOOK - (function_arg_round_boundary, - "Normally, the size of an argument is rounded up to @code{PARM_BOUNDARY},\n\ -@@ -4976,6 +4988,18 @@ value.", - unsigned int, (machine_mode mode, const_tree type), - default_function_arg_round_boundary) - -+DEFHOOK -+(function_arg_round_boundary_ca, -+ "This is the @code{cumulative_args_t}-based version of\n\ -+@code{TARGET_FUNCTION_ARG_ROUND_BOUNDARY}. Define this hook if you need more\n\ -+fine-grained control over argument size rounding, e.g. depending on whether\n\ -+it is a named argument or not, or any other criteria that you choose to\n\ -+place in the @var{ca} structure.\n\ -+\n\ -+The default hook will call @code{TARGET_FUNCTION_ARG_ROUND_BOUNDARY}.", -+ unsigned int, (machine_mode mode, const_tree type, cumulative_args_t ca), -+ default_function_arg_round_boundary_ca) -+ - /* Return the diagnostic message string if function without a prototype - is not allowed for this 'val' argument; NULL otherwise. */ - DEFHOOK -diff --git a/gcc/target.h b/gcc/target.h -index d6fa6931499..40c3da87656 100644 ---- a/gcc/target.h -+++ b/gcc/target.h -@@ -51,22 +51,7 @@ - #include "insn-codes.h" - #include "tm.h" - #include "hard-reg-set.h" -- --#if CHECKING_P -- --struct cumulative_args_t { void *magic; void *p; }; -- --#else /* !CHECKING_P */ -- --/* When using a GCC build compiler, we could use -- __attribute__((transparent_union)) to get cumulative_args_t function -- arguments passed like scalars where the ABI would mandate a less -- efficient way of argument passing otherwise. However, that would come -- at the cost of less type-safe !CHECKING_P compilation. */ -- --union cumulative_args_t { void *p; }; -- --#endif /* !CHECKING_P */ -+#include "cumulative-args.h" - - /* Types of memory operation understood by the "by_pieces" infrastructure. - Used by the TARGET_USE_BY_PIECES_INFRASTRUCTURE_P target hook and -diff --git a/gcc/targhooks.cc b/gcc/targhooks.cc -index 399d6f874dc..9d554adcb45 100644 ---- a/gcc/targhooks.cc -+++ b/gcc/targhooks.cc -@@ -850,6 +850,14 @@ default_function_arg_boundary (machine_mode mode ATTRIBUTE_UNUSED, - return PARM_BOUNDARY; - } - -+unsigned int -+default_function_arg_boundary_ca (machine_mode mode ATTRIBUTE_UNUSED, -+ const_tree type ATTRIBUTE_UNUSED, -+ cumulative_args_t ca ATTRIBUTE_UNUSED) -+{ -+ return default_function_arg_boundary (mode, type); -+} -+ - unsigned int - default_function_arg_round_boundary (machine_mode mode ATTRIBUTE_UNUSED, - const_tree type ATTRIBUTE_UNUSED) -@@ -857,6 +865,14 @@ default_function_arg_round_boundary (machine_mode mode ATTRIBUTE_UNUSED, - return PARM_BOUNDARY; - } - -+unsigned int -+default_function_arg_round_boundary_ca (machine_mode mode ATTRIBUTE_UNUSED, -+ const_tree type ATTRIBUTE_UNUSED, -+ cumulative_args_t ca ATTRIBUTE_UNUSED) -+{ -+ return default_function_arg_round_boundary (mode, type); -+} -+ - void - hook_void_bitmap (bitmap regs ATTRIBUTE_UNUSED) - { -diff --git a/gcc/targhooks.h b/gcc/targhooks.h -index ecce55ebe79..ba110ade58b 100644 ---- a/gcc/targhooks.h -+++ b/gcc/targhooks.h -@@ -154,6 +154,12 @@ extern unsigned int default_function_arg_boundary (machine_mode, - const_tree); - extern unsigned int default_function_arg_round_boundary (machine_mode, - const_tree); -+extern unsigned int default_function_arg_boundary_ca (machine_mode, -+ const_tree, -+ cumulative_args_t ca); -+extern unsigned int default_function_arg_round_boundary_ca (machine_mode, -+ const_tree, -+ cumulative_args_t ca); - extern bool hook_bool_const_rtx_commutative_p (const_rtx, int); - extern rtx default_function_value (const_tree, const_tree, bool); - extern HARD_REG_SET default_zero_call_used_regs (HARD_REG_SET); -diff --git a/gcc/testsuite/g++.dg/abi/aarch64_guard1.C b/gcc/testsuite/g++.dg/abi/aarch64_guard1.C -index e2669a89fbf..52be32decc6 100644 ---- a/gcc/testsuite/g++.dg/abi/aarch64_guard1.C -+++ b/gcc/testsuite/g++.dg/abi/aarch64_guard1.C -@@ -12,5 +12,6 @@ int *foo () - return &x; - } - --// { dg-final { scan-assembler _ZGVZ3foovE1x,8,8 } } -+// { dg-final { scan-assembler _ZGVZ3foovE1x,8,8 { target { ! *-*-darwin* } } } } -+// { dg-final { scan-assembler __DATA,__bss,__ZGVZ3foovE1x,8,3 { target *-*-darwin* } } } - // { dg-final { scan-tree-dump "& 1" "original" } } -diff --git a/gcc/testsuite/g++.dg/abi/arm_va_list.C b/gcc/testsuite/g++.dg/abi/arm_va_list.C -index 4f6f3a46da4..ff9fd8bcf0d 100644 ---- a/gcc/testsuite/g++.dg/abi/arm_va_list.C -+++ b/gcc/testsuite/g++.dg/abi/arm_va_list.C -@@ -8,8 +8,10 @@ - // #include - typedef __builtin_va_list va_list; - --// { dg-final { scan-assembler "\n_Z1fPSt9__va_list:" } } -+// { dg-final { scan-assembler "\n_Z1fPSt9__va_list:" { target { ! *-*-darwin* } } } } -+// { dg-final { scan-assembler "\n__Z1fPPc:" { target *-*-darwin* } } } - void f(va_list*) {} - --// { dg-final { scan-assembler "\n_Z1gSt9__va_listS_:" } } -+// { dg-final { scan-assembler "\n_Z1gSt9__va_listS_:" { target { ! *-*-darwin* } } } } -+// { dg-final { scan-assembler "\n__Z1gPcS_:" { target *-*-darwin* } } } - void g(va_list, va_list) {} -diff --git a/gcc/testsuite/g++.dg/cpp0x/pr106435-b.cc b/gcc/testsuite/g++.dg/cpp0x/pr106435-b.cc -new file mode 100644 -index 00000000000..4f581694177 ---- /dev/null -+++ b/gcc/testsuite/g++.dg/cpp0x/pr106435-b.cc -@@ -0,0 +1,17 @@ -+// PR c++/106435 -+#include "pr106435.h" -+ -+//#include -+ -+Foo::Foo() { -+ ++num_calls; -+// std::cout << "Foo::Foo(this=" << this << ")\n"; -+} -+ -+int Foo::func() { -+// std::cout << "Foo::func(this=" << this << ")\n"; -+ return num_calls; -+} -+ -+thread_local Foo Bar::foo; -+thread_local Foo Bar::baz; -diff --git a/gcc/testsuite/g++.dg/cpp0x/pr106435.C b/gcc/testsuite/g++.dg/cpp0x/pr106435.C -new file mode 100644 -index 00000000000..d600976f9f9 ---- /dev/null -+++ b/gcc/testsuite/g++.dg/cpp0x/pr106435.C -@@ -0,0 +1,20 @@ -+// PR c++/106435 -+// { dg-do run { target c++11 } } -+// { dg-additional-sources "pr106435-b.cc" } -+ -+#include "pr106435.h" -+ -+int num_calls = 0; -+ -+extern "C" __attribute__((__noreturn__)) void abort(); -+ -+thread_local Foo Bar::bat; -+ -+int main() { -+ int v = Bar::foo.func(); -+ if (v != 2) -+ abort(); -+ v = Bar::bat.func(); -+ if (v != 3) -+ abort(); -+} -diff --git a/gcc/testsuite/g++.dg/cpp0x/pr106435.h b/gcc/testsuite/g++.dg/cpp0x/pr106435.h -new file mode 100644 -index 00000000000..240de1ee9a9 ---- /dev/null -+++ b/gcc/testsuite/g++.dg/cpp0x/pr106435.h -@@ -0,0 +1,14 @@ -+// PR c++/106435 -+#pragma once -+ -+extern int num_calls; -+struct Foo { -+ Foo(); -+ int func(); -+}; -+ -+struct Bar { -+ thread_local static Foo foo; -+ thread_local static Foo baz; -+ thread_local static Foo bat; -+}; -diff --git a/gcc/testsuite/g++.dg/ext/arm-bf16/bf16-mangle-aarch64-1.C b/gcc/testsuite/g++.dg/ext/arm-bf16/bf16-mangle-aarch64-1.C -index 5426a1814b8..a017ce8ce5f 100644 ---- a/gcc/testsuite/g++.dg/ext/arm-bf16/bf16-mangle-aarch64-1.C -+++ b/gcc/testsuite/g++.dg/ext/arm-bf16/bf16-mangle-aarch64-1.C -@@ -2,12 +2,12 @@ - - /* Test mangling */ - --/* { dg-final { scan-assembler "\t.global\t_Z1fPu6__bf16" } } */ -+/* { dg-final { scan-assembler {\t.globa?l[ \t]_?_Z1fPu6__bf16} } } */ - void f (__bf16 *x) { } - --/* { dg-final { scan-assembler "\t.global\t_Z1gPu6__bf16S_" } } */ -+/* { dg-final { scan-assembler {\t.globa?l[ \t]_?_Z1gPu6__bf16S_} } } */ - void g (__bf16 *x, __bf16 *y) { } - --/* { dg-final { scan-assembler "\t.global\t_ZN1SIu6__bf16u6__bf16E1iE" } } */ -+/* { dg-final { scan-assembler {\t.globa?l[ \t]_?_ZN1SIu6__bf16u6__bf16E1iE} } } */ - template struct S { static int i; }; - template <> int S<__bf16, __bf16>::i = 3; -diff --git a/gcc/testsuite/g++.dg/torture/darwin-cfstring-3.C b/gcc/testsuite/g++.dg/torture/darwin-cfstring-3.C -index ee4b385b17f..eabb3b517a4 100644 ---- a/gcc/testsuite/g++.dg/torture/darwin-cfstring-3.C -+++ b/gcc/testsuite/g++.dg/torture/darwin-cfstring-3.C -@@ -26,5 +26,5 @@ void foo(void) { - - /* { 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 } } } } } */ -+/* { dg-final { scan-assembler {.(quad|xword)\t___CFConstantStringClassReference\n\t.(long|word)\t1992\n\t.space 4\n\t.(quad|xword)\t.*\n\t.(quad|xword)\t4\n} { target { *-*-darwin* && { lp64 } } } } } */ -+/* { dg-final { scan-assembler {.(quad|xword)\t___CFConstantStringClassReference\n\t.(long|word)\t1992\n\t.space 4\n\t.(quad|xword)\t.*\n\t.(quad|xword)\t10\n} { target { *-*-darwin* && { lp64 } } } } } */ -diff --git a/gcc/testsuite/g++.target/aarch64/no_unique_address_1.C b/gcc/testsuite/g++.target/aarch64/no_unique_address_1.C -index 5fc68ea5d6d..5faf915fa54 100644 ---- a/gcc/testsuite/g++.target/aarch64/no_unique_address_1.C -+++ b/gcc/testsuite/g++.target/aarch64/no_unique_address_1.C -@@ -1,5 +1,5 @@ - /* { dg-options "-std=c++11 -O -foptimize-sibling-calls -fpeephole2" } */ --/* { dg-final { check-function-bodies "**" "" "" { target lp64 } } } */ -+/* { dg-final { check-function-bodies "**" "" "" { target { lp64 && { ! aarch64*-*-darwin* } } } } } */ - - struct X { }; - struct Y { int : 0; }; -diff --git a/gcc/testsuite/g++.target/aarch64/no_unique_address_2.C b/gcc/testsuite/g++.target/aarch64/no_unique_address_2.C -index f0717133ccd..322ec127c79 100644 ---- a/gcc/testsuite/g++.target/aarch64/no_unique_address_2.C -+++ b/gcc/testsuite/g++.target/aarch64/no_unique_address_2.C -@@ -1,5 +1,5 @@ - /* { dg-options "-std=c++17 -O -foptimize-sibling-calls -fpeephole2" } */ --/* { dg-final { check-function-bodies "**" "" "" { target lp64 } } } */ -+/* { dg-final { check-function-bodies "**" "" "" { target { lp64 && { ! aarch64*-*-darwin* } } } } } */ - - struct X { }; - struct Y { int : 0; }; -diff --git a/gcc/testsuite/g++.target/aarch64/sve/aarch64-sve.exp b/gcc/testsuite/g++.target/aarch64/sve/aarch64-sve.exp -index 03a6537a53e..d4c2052dc59 100644 ---- a/gcc/testsuite/g++.target/aarch64/sve/aarch64-sve.exp -+++ b/gcc/testsuite/g++.target/aarch64/sve/aarch64-sve.exp -@@ -25,6 +25,11 @@ if {![istarget aarch64*-*-*] } then { - return - } - -+# Darwin doesn't support sve -+if { [istarget *-*-darwin*] } then { -+ return -+} -+ - # Load support procs. - load_lib g++-dg.exp - -diff --git a/gcc/testsuite/g++.target/aarch64/sve/acle/aarch64-sve-acle-asm.exp b/gcc/testsuite/g++.target/aarch64/sve/acle/aarch64-sve-acle-asm.exp -index 38140413a97..559e1f37c68 100644 ---- a/gcc/testsuite/g++.target/aarch64/sve/acle/aarch64-sve-acle-asm.exp -+++ b/gcc/testsuite/g++.target/aarch64/sve/acle/aarch64-sve-acle-asm.exp -@@ -24,6 +24,11 @@ if { ![istarget aarch64*-*-*] } { - return - } - -+# Darwin doesn't support sve -+if { [istarget *-*-darwin*] } then { -+ return -+} -+ - # Load support procs. - load_lib g++-dg.exp - -diff --git a/gcc/testsuite/g++.target/aarch64/sve/acle/aarch64-sve-acle.exp b/gcc/testsuite/g++.target/aarch64/sve/acle/aarch64-sve-acle.exp -index d1887eb8087..c9fee945c52 100644 ---- a/gcc/testsuite/g++.target/aarch64/sve/acle/aarch64-sve-acle.exp -+++ b/gcc/testsuite/g++.target/aarch64/sve/acle/aarch64-sve-acle.exp -@@ -25,6 +25,11 @@ if {![istarget aarch64*-*-*] } { - return - } - -+# Darwin doesn't support sve -+if { [istarget *-*-darwin*] } then { -+ return -+} -+ - # Load support procs. - load_lib g++-dg.exp - -diff --git a/gcc/testsuite/g++.target/aarch64/sve2/acle/aarch64-sve2-acle-asm.exp b/gcc/testsuite/g++.target/aarch64/sve2/acle/aarch64-sve2-acle-asm.exp -index 78e8ecae729..e22ef5f0876 100644 ---- a/gcc/testsuite/g++.target/aarch64/sve2/acle/aarch64-sve2-acle-asm.exp -+++ b/gcc/testsuite/g++.target/aarch64/sve2/acle/aarch64-sve2-acle-asm.exp -@@ -24,6 +24,11 @@ if { ![istarget aarch64*-*-*] } { - return - } - -+# Darwin doesn't support sve -+if { [istarget *-*-darwin*] } then { -+ return -+} -+ - # Load support procs. - load_lib g++-dg.exp - -diff --git a/gcc/testsuite/gcc.dg/builtin-apply2.c b/gcc/testsuite/gcc.dg/builtin-apply2.c -index 0f350f4ac16..d1e70b3a3e5 100644 ---- a/gcc/testsuite/gcc.dg/builtin-apply2.c -+++ b/gcc/testsuite/gcc.dg/builtin-apply2.c -@@ -1,7 +1,7 @@ - /* { dg-do run } */ - /* { dg-require-effective-target untyped_assembly } */ - /* { dg-skip-if "Variadic funcs have all args on stack. Normal funcs have args in registers." { "avr-*-* nds32*-*-* amdgcn-*-*" } } */ --/* { dg-skip-if "Variadic funcs use different argument passing from normal funcs." { "csky*-*-* riscv*-*-* or1k*-*-* msp430-*-* pru-*-* loongarch*-*-*" } } */ -+/* { dg-skip-if "Variadic funcs use different argument passing from normal funcs." { "csky*-*-* riscv*-*-* or1k*-*-* msp430-*-* pru-*-* loongarch*-*-* aarch64-apple-darwin*" } } */ - /* { dg-skip-if "Variadic funcs use Base AAPCS. Normal funcs use VFP variant." { arm*-*-* && arm_hf_eabi } } */ - - /* PR target/12503 */ -diff --git a/gcc/testsuite/gcc.dg/cwsc1.c b/gcc/testsuite/gcc.dg/cwsc1.c -index e793e26116a..7d8b472bdf6 100644 ---- a/gcc/testsuite/gcc.dg/cwsc1.c -+++ b/gcc/testsuite/gcc.dg/cwsc1.c -@@ -6,7 +6,11 @@ - #elif defined(__i386__) - # define CHAIN "%ecx" - #elif defined(__aarch64__) --# define CHAIN "x18" -+# if defined(__APPLE__) -+# define CHAIN "x16" -+# else -+# define CHAIN "x18" -+# endif - #elif defined(__alpha__) - # define CHAIN "$1" - #elif defined(__arm__) -diff --git a/gcc/testsuite/gcc.dg/darwin-segaddr.c b/gcc/testsuite/gcc.dg/darwin-segaddr.c -index 526db77bd9c..fcc324b3031 100644 ---- a/gcc/testsuite/gcc.dg/darwin-segaddr.c -+++ b/gcc/testsuite/gcc.dg/darwin-segaddr.c -@@ -1,7 +1,8 @@ - /* Check that -segaddr gets through and works. */ - /* { dg-do run { target *-*-darwin* } } */ - /* { dg-options "-O0 -segaddr __TEST 0x200000 -fno-pie" { target { *-*-darwin* && { ! lp64 } } } } */ --/* { dg-options "-O0 -segaddr __TEST 0x110000000 -fno-pie" { target { *-*-darwin* && lp64 } } } */ -+/* { dg-options "-O0 -segaddr __TEST 0x110000000 -fno-pie" { target { *-*-darwin[1456789]* && lp64 } } } */ -+/* { dg-options "-O0 -segaddr __TEST 0x110000000 " { target { *-*-darwin2* && lp64 } } } */ - - extern void abort (); - -diff --git a/gcc/testsuite/gcc.dg/pr26427.c b/gcc/testsuite/gcc.dg/pr26427.c -index add13ca209e..2c09f28195d 100644 ---- a/gcc/testsuite/gcc.dg/pr26427.c -+++ b/gcc/testsuite/gcc.dg/pr26427.c -@@ -1,4 +1,4 @@ --/* { dg-warning "this target does not support" "" {target *86*-*-darwin* } 0 } */ -+/* { dg-warning "this target does not support" "" {target *86*-*-darwin* aarch64-*-darwin* } 0 } */ - /* { dg-do run { target { *-*-darwin* } } } */ - /* { dg-options { -fsection-anchors -O } } */ - /* PR target/26427 */ -diff --git a/gcc/testsuite/gcc.dg/pubtypes-2.c b/gcc/testsuite/gcc.dg/pubtypes-2.c -index 116e3489bc0..b3d1231ad44 100644 ---- a/gcc/testsuite/gcc.dg/pubtypes-2.c -+++ b/gcc/testsuite/gcc.dg/pubtypes-2.c -@@ -2,7 +2,8 @@ - /* { dg-options "-O0 -gdwarf-2 -dA" } */ - /* { dg-skip-if "Unmatchable assembly" { mmix-*-* } } */ - /* { dg-final { scan-assembler "__debug_pubtypes" } } */ --/* { dg-final { scan-assembler {long+[ \t]+0x14d+[ \t]+[#;]+[ \t]+Pub Info Length} } } */ -+/* { dg-final { scan-assembler {long+[ \t]+0x14d+[ \t]+[#;]+[ \t]+Pub Info Length} { target { ! aarch64-*-darwin* } } } } */ -+/* { dg-final { scan-assembler {long+[ \t]+0x163+[ \t]+[#;]+[ \t]+Pub Info Length} { target aarch64-*-darwin* } } } */ - /* { dg-final { scan-assembler "used_struct\\\\0\"+\[ \t\]+\[#;]+\[ \t\]+external name" } } */ - /* { dg-final { scan-assembler-not "unused_struct\\\\0\"+\[ \t\]+\[#;]+\[ \t\]+external name" } } */ - -diff --git a/gcc/testsuite/gcc.dg/pubtypes-3.c b/gcc/testsuite/gcc.dg/pubtypes-3.c -index 3fb3468fb00..950a9ba72fc 100644 ---- a/gcc/testsuite/gcc.dg/pubtypes-3.c -+++ b/gcc/testsuite/gcc.dg/pubtypes-3.c -@@ -2,7 +2,8 @@ - /* { dg-options "-O0 -gdwarf-2 -dA" } */ - /* { dg-skip-if "Unmatchable assembly" { mmix-*-* } } */ - /* { dg-final { scan-assembler "__debug_pubtypes" } } */ --/* { dg-final { scan-assembler {long+[ \t]+0x14d+[ \t]+[#;]+[ \t]+Pub Info Length} } } */ -+/* { dg-final { scan-assembler {long+[ \t]+0x14d+[ \t]+[#;]+[ \t]+Pub Info Length} { target { ! aarch64-*-darwin* } } } } */ -+/* { dg-final { scan-assembler {long+[ \t]+0x163+[ \t]+[#;]+[ \t]+Pub Info Length} { target aarch64-*-darwin* } } } */ - /* { dg-final { scan-assembler "used_struct\\\\0\"+\[ \t\]+\[#;]+\[ \t\]+external name" } } */ - /* { dg-final { scan-assembler-not "unused_struct\\\\0\"+\[ \t\]+\[#;]+\[ \t\]+external name" } } */ - /* { dg-final { scan-assembler-not "\"list_name_type\\\\0\"+\[ \t\]+\[#;]+\[ \t\]+external name" } } */ -diff --git a/gcc/testsuite/gcc.dg/pubtypes-4.c b/gcc/testsuite/gcc.dg/pubtypes-4.c -index 83fba8dfabc..7250771587b 100644 ---- a/gcc/testsuite/gcc.dg/pubtypes-4.c -+++ b/gcc/testsuite/gcc.dg/pubtypes-4.c -@@ -2,7 +2,8 @@ - /* { dg-options "-O0 -gdwarf-2 -dA" } */ - /* { dg-skip-if "Unmatchable assembly" { mmix-*-* } } */ - /* { dg-final { scan-assembler "__debug_pubtypes" } } */ --/* { dg-final { scan-assembler {long+[ \t]+0x184+[ \t]+[#;]+[ \t]+Pub Info Length} } } */ -+/* { dg-final { scan-assembler {long+[ \t]+0x184+[ \t]+[#;]+[ \t]+Pub Info Length} { target { ! aarch64-*-darwin* } } } } */ -+/* { dg-final { scan-assembler {long+[ \t]+0x19a+[ \t]+[#;]+[ \t]+Pub Info Length} { target aarch64-*-darwin* } } } */ - /* { dg-final { scan-assembler "used_struct\\\\0\"+\[ \t\]+\[#;]+\[ \t\]+external name" } } */ - /* { dg-final { scan-assembler-not "unused_struct\\\\0\"+\[ \t\]+\[#;]+\[ \t\]+external name" } } */ - /* { dg-final { scan-assembler "\"list_name_type\\\\0\"+\[ \t\]+\[#;]+\[ \t\]+external name" } } */ -diff --git a/gcc/testsuite/gcc.dg/rtl/aarch64/big-endian-cse-1.c b/gcc/testsuite/gcc.dg/rtl/aarch64/big-endian-cse-1.c -index 1559a489f25..aa2da0cbca5 100644 ---- a/gcc/testsuite/gcc.dg/rtl/aarch64/big-endian-cse-1.c -+++ b/gcc/testsuite/gcc.dg/rtl/aarch64/big-endian-cse-1.c -@@ -1,4 +1,5 @@ - /* { dg-do compile { target aarch64*-*-* } } */ -+/* { dg-skip-if "Darwin platforms do not support big-endian arm64" *-*-darwin* } */ - /* { dg-require-effective-target lp64 } */ - /* { dg-options "-O3 -mbig-endian" } */ - -diff --git a/gcc/testsuite/gcc.dg/tls/pr78796.c b/gcc/testsuite/gcc.dg/tls/pr78796.c -index 038e5366e41..31e03dd419c 100644 ---- a/gcc/testsuite/gcc.dg/tls/pr78796.c -+++ b/gcc/testsuite/gcc.dg/tls/pr78796.c -@@ -1,7 +1,7 @@ - /* PR target/78796 */ - /* { dg-do run } */ - /* { dg-options "-O2" } */ --/* { dg-additional-options "-mcmodel=large" { target aarch64-*-* } } */ -+/* { dg-additional-options "-mcmodel=large" { target { { aarch64-*-* } && { ! aarch64-*-darwin* } } } } */ - /* { dg-require-effective-target tls_runtime } */ - /* { dg-add-options tls } */ - -diff --git a/gcc/testsuite/gcc.dg/torture/darwin-cfstring-3.c b/gcc/testsuite/gcc.dg/torture/darwin-cfstring-3.c -index ee4b385b17f..eabb3b517a4 100644 ---- a/gcc/testsuite/gcc.dg/torture/darwin-cfstring-3.c -+++ b/gcc/testsuite/gcc.dg/torture/darwin-cfstring-3.c -@@ -26,5 +26,5 @@ void foo(void) { - - /* { 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 } } } } } */ -+/* { dg-final { scan-assembler {.(quad|xword)\t___CFConstantStringClassReference\n\t.(long|word)\t1992\n\t.space 4\n\t.(quad|xword)\t.*\n\t.(quad|xword)\t4\n} { target { *-*-darwin* && { lp64 } } } } } */ -+/* { dg-final { scan-assembler {.(quad|xword)\t___CFConstantStringClassReference\n\t.(long|word)\t1992\n\t.space 4\n\t.(quad|xword)\t.*\n\t.(quad|xword)\t10\n} { target { *-*-darwin* && { lp64 } } } } } */ -diff --git a/gcc/testsuite/gcc.dg/torture/stackalign/builtin-apply-2.c b/gcc/testsuite/gcc.dg/torture/stackalign/builtin-apply-2.c -index 552ca1433f4..16643ceb198 100644 ---- a/gcc/testsuite/gcc.dg/torture/stackalign/builtin-apply-2.c -+++ b/gcc/testsuite/gcc.dg/torture/stackalign/builtin-apply-2.c -@@ -9,7 +9,7 @@ - /* arm_hf_eabi: Variadic funcs use Base AAPCS. Normal funcs use VFP variant. - avr: Variadic funcs don't pass arguments in registers, while normal funcs - do. */ --/* { dg-skip-if "Variadic funcs use different argument passing from normal funcs" { arm_hf_eabi || { csky*-*-* avr-*-* riscv*-*-* or1k*-*-* msp430-*-* amdgcn-*-* pru-*-* loongarch*-*-* } } } */ -+/* { dg-skip-if "Variadic funcs use different argument passing from normal funcs" { arm_hf_eabi || { csky*-*-* avr-*-* riscv*-*-* or1k*-*-* msp430-*-* amdgcn-*-* pru-*-* loongarch*-*-* aarch64-apple-darwin* } } } */ - /* { dg-skip-if "Variadic funcs have all args on stack. Normal funcs have args in registers." { nds32*-*-* } { v850*-*-* } } */ - /* { dg-require-effective-target untyped_assembly } */ - -diff --git a/gcc/testsuite/gcc.dg/tree-ssa/stdarg-2.c b/gcc/testsuite/gcc.dg/tree-ssa/stdarg-2.c -index 0224997f18a..3684cffdc64 100644 ---- a/gcc/testsuite/gcc.dg/tree-ssa/stdarg-2.c -+++ b/gcc/testsuite/gcc.dg/tree-ssa/stdarg-2.c -@@ -25,9 +25,9 @@ f1 (int i, ...) - /* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save 0 GPR units and 0 FPR units" "stdarg" { target { powerpc*-*-linux* && ilp32 } } } } */ - /* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save 0 GPR units and 0 FPR units" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save 0 GPR units and 0 FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save 0 GPR units and 0 FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save 0 GPR units and 0 FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ - /* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save 0 GPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && ia32 } } } } */ --/* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save 0 GPR units" "stdarg" { target ia64-*-* } } } */ -+/* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save 0 GPR units" "stdarg" { target ia64-*-* aarch64-apple-darwin* } } } */ - /* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save 0 GPR units" "stdarg" { target { powerpc*-*-* && lp64 } } } } */ - - void -@@ -46,9 +46,9 @@ f2 (int i, ...) - /* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save \[148\] GPR units and 0 FPR units" "stdarg" { target { powerpc*-*-linux* && ilp32 } } } } */ - /* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save 8 GPR units and 1" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save 1 GPR units and 0 FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save 8 GPR units and 0 FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save 8 GPR units and 0 FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ - /* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save \[148\] GPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && ia32 } } } } */ --/* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save \[148\] GPR units" "stdarg" { target ia64-*-* } } } */ -+/* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save \[148\] GPR units" "stdarg" { target ia64-*-* aarch64-apple-darwin* } } } */ - /* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save \[148\] GPR units" "stdarg" { target { powerpc*-*-* && lp64 } } } } */ - - void -@@ -62,10 +62,10 @@ f3 (int i, ...) - /* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save 0 GPR units and \[1-9\]\[0-9\]* FPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && { ! { ia32 || llp64 } } } } } } */ - /* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save 0 GPR units and \[1-9\]\[0-9\]* FPR units" "stdarg" { target { powerpc*-*-linux* && { powerpc_fprs && ilp32 } } } } } */ - /* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save 0 GPR units and 1 FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save 0 GPR units and 16 FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save 0 GPR units and 16 FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ - /* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save 8 GPR units and 2" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save \[1-9\]\[0-9\]* GPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && ia32 } } } } */ --/* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save \[1-9\]\[0-9\]* GPR units" "stdarg" { target ia64-*-* } } } */ -+/* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save \[1-9\]\[0-9\]* GPR units" "stdarg" { target ia64-*-* aarch64-apple-darwin* } } } */ - /* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save \[1-9\]\[0-9\]* GPR units" "stdarg" { target { powerpc*-*-* && lp64 } } } } */ - - void -@@ -81,9 +81,9 @@ f4 (int i, ...) - /* { dg-final { scan-tree-dump "f4: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target { powerpc*-*-linux* && ilp32 } } } } */ - /* { dg-final { scan-tree-dump "f4: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f4: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f4: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f4: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ - /* { dg-final { scan-tree-dump "f4: va_list escapes 1, needs to save all GPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && ia32 } } } } */ --/* { dg-final { scan-tree-dump "f4: va_list escapes 1, needs to save all GPR units" "stdarg" { target ia64-*-* } } } */ -+/* { dg-final { scan-tree-dump "f4: va_list escapes 1, needs to save all GPR units" "stdarg" { target ia64-*-* aarch64-apple-darwin* } } } */ - /* { dg-final { scan-tree-dump "f4: va_list escapes 1, needs to save all GPR units" "stdarg" { target { powerpc*-*-* && lp64 } } } } */ - - void -@@ -100,9 +100,9 @@ f5 (int i, ...) - /* { dg-final { scan-tree-dump "f5: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target { powerpc*-*-linux* && ilp32 } } } } */ - /* { dg-final { scan-tree-dump "f5: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f5: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f5: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f5: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ - /* { dg-final { scan-tree-dump "f5: va_list escapes 1, needs to save all GPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && ia32 } } } } */ --/* { dg-final { scan-tree-dump "f5: va_list escapes 1, needs to save all GPR units" "stdarg" { target ia64-*-* } } } */ -+/* { dg-final { scan-tree-dump "f5: va_list escapes 1, needs to save all GPR units" "stdarg" { target ia64-*-* aarch64-apple-darwin* } } } */ - /* { dg-final { scan-tree-dump "f5: va_list escapes 1, needs to save all GPR units" "stdarg" { target { powerpc*-*-* && lp64 } } } } */ - - void -@@ -121,9 +121,9 @@ f6 (int i, ...) - /* { dg-final { scan-tree-dump "f6: va_list escapes 0, needs to save (3|12|24) GPR units and 0 FPR units" "stdarg" { target { powerpc*-*-linux* && ilp32 } } } } */ - /* { dg-final { scan-tree-dump "f6: va_list escapes 0, needs to save 24 GPR units and 1" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f6: va_list escapes 0, needs to save 3 GPR units and 0 FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f6: va_list escapes 0, needs to save 24 GPR units and 0 FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f6: va_list escapes 0, needs to save 24 GPR units and 0 FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ - /* { dg-final { scan-tree-dump "f6: va_list escapes 0, needs to save (3|12|24) GPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && ia32 } } } } */ --/* { dg-final { scan-tree-dump "f6: va_list escapes 0, needs to save (3|12|24) GPR units" "stdarg" { target ia64-*-* } } } */ -+/* { dg-final { scan-tree-dump "f6: va_list escapes 0, needs to save (3|12|24) GPR units" "stdarg" { target ia64-*-* aarch64-apple-darwin* } } } */ - /* { dg-final { scan-tree-dump "f6: va_list escapes 0, needs to save (3|12|24) GPR units" "stdarg" { target { powerpc*-*-* && lp64 } } } } */ - - void -@@ -139,9 +139,9 @@ f7 (int i, ...) - /* { dg-final { scan-tree-dump "f7: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target { powerpc*-*-linux* && ilp32 } } } } */ - /* { dg-final { scan-tree-dump "f7: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f7: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f7: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f7: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ - /* { dg-final { scan-tree-dump "f7: va_list escapes 1, needs to save all GPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && ia32 } } } } */ --/* { dg-final { scan-tree-dump "f7: va_list escapes 1, needs to save all GPR units" "stdarg" { target ia64-*-* } } } */ -+/* { dg-final { scan-tree-dump "f7: va_list escapes 1, needs to save all GPR units" "stdarg" { target ia64-*-* aarch64-apple-darwin* } } } */ - /* { dg-final { scan-tree-dump "f7: va_list escapes 1, needs to save all GPR units" "stdarg" { target { powerpc*-*-* && lp64 } } } } */ - - void -@@ -159,9 +159,9 @@ f8 (int i, ...) - /* { dg-final { scan-tree-dump "f8: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target { powerpc*-*-linux* && ilp32 } } } } */ - /* { dg-final { scan-tree-dump "f8: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f8: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f8: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f8: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ - /* { dg-final { scan-tree-dump "f8: va_list escapes 1, needs to save all GPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && ia32 } } } } */ --/* { dg-final { scan-tree-dump "f8: va_list escapes 1, needs to save all GPR units" "stdarg" { target ia64-*-* } } } */ -+/* { dg-final { scan-tree-dump "f8: va_list escapes 1, needs to save all GPR units" "stdarg" { target ia64-*-* aarch64-apple-darwin* } } } */ - /* { dg-final { scan-tree-dump "f8: va_list escapes 1, needs to save all GPR units" "stdarg" { target { powerpc*-*-* && lp64 } } } } */ - - void -@@ -177,9 +177,9 @@ f9 (int i, ...) - /* { dg-final { scan-tree-dump "f9: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target { powerpc*-*-linux* && ilp32 } } } } */ - /* { dg-final { scan-tree-dump "f9: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f9: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f9: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f9: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ - /* { dg-final { scan-tree-dump "f9: va_list escapes 1, needs to save all GPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && ia32 } } } } */ --/* { dg-final { scan-tree-dump "f9: va_list escapes 1, needs to save all GPR units" "stdarg" { target ia64-*-* } } } */ -+/* { dg-final { scan-tree-dump "f9: va_list escapes 1, needs to save all GPR units" "stdarg" { target ia64-*-* aarch64-apple-darwin* } } } */ - /* { dg-final { scan-tree-dump "f9: va_list escapes 1, needs to save all GPR units" "stdarg" { target { powerpc*-*-* && lp64 } } } } */ - - void -@@ -197,9 +197,9 @@ f10 (int i, ...) - /* { dg-final { scan-tree-dump "f10: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target { powerpc*-*-linux* && ilp32 } } } } */ - /* { dg-final { scan-tree-dump "f10: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f10: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f10: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f10: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ - /* { dg-final { scan-tree-dump "f10: va_list escapes 1, needs to save all GPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && ia32 } } } } */ --/* { dg-final { scan-tree-dump "f10: va_list escapes 1, needs to save all GPR units" "stdarg" { target ia64-*-* } } } */ -+/* { dg-final { scan-tree-dump "f10: va_list escapes 1, needs to save all GPR units" "stdarg" { target ia64-*-* aarch64-apple-darwin* } } } */ - /* { dg-final { scan-tree-dump "f10: va_list escapes 1, needs to save all GPR units" "stdarg" { target { powerpc*-*-* && lp64 } } } } */ - - void -@@ -218,9 +218,9 @@ f11 (int i, ...) - /* { dg-final { scan-tree-dump "f11: va_list escapes 0, needs to save (3|12|24) GPR units and 0 FPR units" "stdarg" { target { powerpc*-*-linux* && ilp32 } } } } */ - /* { dg-final { scan-tree-dump "f11: va_list escapes 0, needs to save 24 GPR units and 1" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f11: va_list escapes 0, needs to save 3 GPR units and 0 FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f11: va_list escapes 0, needs to save 24 GPR units and 0 FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f11: va_list escapes 0, needs to save 24 GPR units and 0 FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ - /* { dg-final { scan-tree-dump "f11: va_list escapes 0, needs to save (3|12|24) GPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && ia32 } } } } */ --/* { dg-final { scan-tree-dump "f11: va_list escapes 0, needs to save (3|12|24) GPR units" "stdarg" { target ia64-*-* } } } */ -+/* { dg-final { scan-tree-dump "f11: va_list escapes 0, needs to save (3|12|24) GPR units" "stdarg" { target ia64-*-* aarch64-apple-darwin* } } } */ - /* { dg-final { scan-tree-dump "f11: va_list escapes 0, needs to save (3|12|24) GPR units" "stdarg" { target { powerpc*-*-* && lp64 } } } } */ - - void -@@ -239,9 +239,9 @@ f12 (int i, ...) - /* { dg-final { scan-tree-dump "f12: va_list escapes 0, needs to save 0 GPR units and \[1-9\]\[0-9\]* FPR units" "stdarg" { target { powerpc*-*-linux* && { powerpc_fprs && ilp32 } } } } } */ - /* { dg-final { scan-tree-dump "f12: va_list escapes 0, needs to save 24 GPR units and 2" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f12: va_list escapes 0, needs to save 0 GPR units and 3 FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f12: va_list escapes 0, needs to save 0 GPR units and 48 FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f12: va_list escapes 0, needs to save 0 GPR units and 48 FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ - /* { dg-final { scan-tree-dump "f12: va_list escapes 0, needs to save \[1-9]\[0-9\]* GPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && ia32 } } } } */ --/* { dg-final { scan-tree-dump "f12: va_list escapes 0, needs to save \[1-9]\[0-9\]* GPR units" "stdarg" { target ia64-*-* } } } */ -+/* { dg-final { scan-tree-dump "f12: va_list escapes 0, needs to save \[1-9]\[0-9\]* GPR units" "stdarg" { target ia64-*-* aarch64-apple-darwin* } } } */ - /* { dg-final { scan-tree-dump "f12: va_list escapes 0, needs to save \[1-9]\[0-9\]* GPR units" "stdarg" { target { powerpc*-*-* && lp64 } } } } */ - - void -@@ -260,9 +260,9 @@ f13 (int i, ...) - /* { dg-final { scan-tree-dump "f13: va_list escapes 0, needs to save 0 GPR units and \[1-9\]\[0-9\]* FPR units" "stdarg" { target { powerpc*-*-linux* && { powerpc_fprs && ilp32 } } } } } */ - /* { dg-final { scan-tree-dump "f13: va_list escapes 0, needs to save 24 GPR units and 2" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f13: va_list escapes 0, needs to save 0 GPR units and 3 FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f13: va_list escapes 0, needs to save 0 GPR units and 48 FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f13: va_list escapes 0, needs to save 0 GPR units and 48 FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ - /* { dg-final { scan-tree-dump "f13: va_list escapes 0, needs to save \[1-9]\[0-9\]* GPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && ia32 } } } } */ --/* { dg-final { scan-tree-dump "f13: va_list escapes 0, needs to save \[1-9]\[0-9\]* GPR units" "stdarg" { target ia64-*-* } } } */ -+/* { dg-final { scan-tree-dump "f13: va_list escapes 0, needs to save \[1-9]\[0-9\]* GPR units" "stdarg" { target ia64-*-* aarch64-apple-darwin* } } } */ - /* { dg-final { scan-tree-dump "f13: va_list escapes 0, needs to save \[1-9]\[0-9\]* GPR units" "stdarg" { target { powerpc*-*-* && lp64 } } } } */ - - void -@@ -281,9 +281,9 @@ f14 (int i, ...) - /* { dg-final { scan-tree-dump "f14: va_list escapes 0, needs to save \[148\] GPR units and \[1-9\]\[0-9\]* FPR units" "stdarg" { target { powerpc*-*-linux* && { powerpc_fprs && ilp32 } } } } } */ - /* { dg-final { scan-tree-dump "f14: va_list escapes 0, needs to save 24 GPR units and 3" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f14: va_list escapes 0, needs to save 1 GPR units and 2 FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f14: va_list escapes 0, needs to save 8 GPR units and 32 FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f14: va_list escapes 0, needs to save 8 GPR units and 32 FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ - /* { dg-final { scan-tree-dump "f14: va_list escapes 0, needs to save \[1-9]\[0-9\]* GPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && ia32 } } } } */ --/* { dg-final { scan-tree-dump "f14: va_list escapes 0, needs to save \[1-9]\[0-9\]* GPR units" "stdarg" { target ia64-*-* } } } */ -+/* { dg-final { scan-tree-dump "f14: va_list escapes 0, needs to save \[1-9]\[0-9\]* GPR units" "stdarg" { target ia64-*-* aarch64-apple-darwin* } } } */ - /* { dg-final { scan-tree-dump "f14: va_list escapes 0, needs to save \[1-9]\[0-9\]* GPR units" "stdarg" { target { powerpc*-*-* && lp64 } } } } */ - - inline void __attribute__((always_inline)) -@@ -305,11 +305,11 @@ f15 (int i, ...) - /* { dg-final { scan-tree-dump "f15: va_list escapes 0, needs to save \[148\] GPR units and \[1-9\]\[0-9\]* FPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && { ! { ia32 || llp64 } } } } } } */ - /* { dg-final { scan-tree-dump "f15: va_list escapes 0, needs to save \[148\] GPR units and \[1-9\]\[0-9\]* FPR units" "stdarg" { target { powerpc*-*-linux* && { powerpc_fprs && ilp32 } } } } } */ - /* { dg-final { scan-tree-dump "f15: va_list escapes 0, needs to save 1 GPR units and 2 FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f15: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f15: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ - - /* We may be able to improve upon this after fixing PR66010/PR66013. */ - /* { dg-final { scan-tree-dump "f15: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target alpha*-*-linux* } } } */ - - /* { dg-final { scan-tree-dump-not "f15: va_list escapes 0, needs to save 0 GPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && ia32 } } } } */ --/* { dg-final { scan-tree-dump-not "f15: va_list escapes 0, needs to save 0 GPR units" "stdarg" { target ia64-*-* } } } */ -+/* { dg-final { scan-tree-dump-not "f15: va_list escapes 0, needs to save 0 GPR units" "stdarg" { target ia64-*-* aarch64-apple-darwin* } } } */ - /* { dg-final { scan-tree-dump-not "f15: va_list escapes 0, needs to save 0 GPR units" "stdarg" { target { powerpc*-*-* && lp64 } } } } */ -diff --git a/gcc/testsuite/gcc.dg/tree-ssa/stdarg-4.c b/gcc/testsuite/gcc.dg/tree-ssa/stdarg-4.c -index 1a637d6efe4..77cdf384df4 100644 ---- a/gcc/testsuite/gcc.dg/tree-ssa/stdarg-4.c -+++ b/gcc/testsuite/gcc.dg/tree-ssa/stdarg-4.c -@@ -27,9 +27,9 @@ f1 (int i, ...) - /* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save all GPR units and 0 FPR units" "stdarg" { target { powerpc*-*-linux* && ilp32 } } } } */ - /* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save all GPR units and 1" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save all GPR units and 0 FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save all GPR units and 0 FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save all GPR units and 0 FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ - /* { dg-final { scan-tree-dump "f1: va_list escapes \[01\], needs to save all GPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && ia32 } } } } */ --/* { dg-final { scan-tree-dump "f1: va_list escapes \[01\], needs to save all GPR units" "stdarg" { target ia64-*-* } } } */ -+/* { dg-final { scan-tree-dump "f1: va_list escapes \[01\], needs to save all GPR units" "stdarg" { target ia64-*-* aarch64-apple-darwin* } } } */ - /* { dg-final { scan-tree-dump "f1: va_list escapes \[01\], needs to save all GPR units" "stdarg" { target { powerpc*-*-* && lp64 } } } } */ - - void -@@ -45,9 +45,9 @@ f2 (int i, ...) - /* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save 0 GPR units and all FPR units" "stdarg" { target { powerpc*-*-linux* && { powerpc_fprs && ilp32 } } } } } */ - /* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save all GPR units and 2" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save 0 GPR units and all FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save 0 GPR units and all FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save 0 GPR units and all FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ - /* { dg-final { scan-tree-dump "f2: va_list escapes \[01\], needs to save all GPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && ia32 } } } } */ --/* { dg-final { scan-tree-dump "f2: va_list escapes \[01\], needs to save all GPR units" "stdarg" { target ia64-*-* } } } */ -+/* { dg-final { scan-tree-dump "f2: va_list escapes \[01\], needs to save all GPR units" "stdarg" { target ia64-*-* aarch64-apple-darwin* } } } */ - /* { dg-final { scan-tree-dump "f2: va_list escapes \[01\], needs to save all GPR units" "stdarg" { target { powerpc*-*-* && lp64 } } } } */ - - /* Here va_arg can be executed at most as many times as va_start. -@@ -69,9 +69,9 @@ f3 (int i, ...) - /* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save \[148\] GPR units and 0 FPR units" "stdarg" { target { powerpc*-*-linux* && ilp32 } } } } */ - /* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save 8 GPR units and 1" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save 1 GPR units and 0 FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save 8 GPR units and 0 FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save 8 GPR units and 0 FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ - /* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save \[148\] GPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && ia32 } } } } */ --/* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save \[148\] GPR units" "stdarg" { target ia64-*-* } } } */ -+/* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save \[148\] GPR units" "stdarg" { target ia64-*-* aarch64-apple-darwin* } } } */ - /* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save \[148\] GPR units" "stdarg" { target { powerpc*-*-* && lp64 } } } } */ - - void -@@ -91,7 +91,7 @@ f4 (int i, ...) - /* { dg-final { scan-tree-dump "f4: va_list escapes 0, needs to save 0 GPR units and \[1-9\]\[0-9\]* FPR units" "stdarg" { target { powerpc*-*-linux* && { powerpc_fprs && ilp32 } } } } } */ - /* { dg-final { scan-tree-dump "f4: va_list escapes 0, needs to save 8 GPR units and 2" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f4: va_list escapes 0, needs to save 0 GPR units and 1 FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f4: va_list escapes 0, needs to save 0 GPR units and 16 FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f4: va_list escapes 0, needs to save 0 GPR units and 16 FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ - /* { dg-final { scan-tree-dump "f4: va_list escapes 0, needs to save \[148\] GPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && ia32 } } } } */ --/* { dg-final { scan-tree-dump "f4: va_list escapes 0, needs to save \[148\] GPR units" "stdarg" { target ia64-*-* } } } */ -+/* { dg-final { scan-tree-dump "f4: va_list escapes 0, needs to save \[148\] GPR units" "stdarg" { target ia64-*-* aarch64-apple-darwin* } } } */ - /* { dg-final { scan-tree-dump "f4: va_list escapes 0, needs to save \[148\] GPR units" "stdarg" { target { powerpc*-*-* && lp64 } } } } */ -diff --git a/gcc/testsuite/gcc.dg/tree-ssa/stdarg-5.c b/gcc/testsuite/gcc.dg/tree-ssa/stdarg-5.c -index c8ad4fe320d..b0484f2f053 100644 ---- a/gcc/testsuite/gcc.dg/tree-ssa/stdarg-5.c -+++ b/gcc/testsuite/gcc.dg/tree-ssa/stdarg-5.c -@@ -25,7 +25,8 @@ f1 (int i, ...) - /* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save 0 GPR units and 0 FPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && { ! { ia32 || llp64 } } } } } } */ - /* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save all GPR units and 1" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save all GPR units and 0 FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save all GPR units and 0 FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save all GPR units and 0 FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ -+/* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save all GPR units" "stdarg" { target aarch64-apple-darwin* } } } */ - - void - f2 (int i, ...) -@@ -39,7 +40,8 @@ f2 (int i, ...) - /* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save all GPR units and all FPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && { ! { ia32 || llp64 } } } } } } */ - /* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save all GPR units and 1" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save all GPR units and 0 FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save all GPR units and 0 FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save all GPR units and 0 FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ -+/* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save all GPR units" "stdarg" { target aarch64-apple-darwin* } } } */ - - /* Here va_arg can be executed at most as many times as va_start. */ - void -@@ -58,7 +60,8 @@ f3 (int i, ...) - /* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save 0 GPR units and 0 FPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && { ! { ia32 || llp64 } } } } } } */ - /* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save 32 GPR units and 1" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save 1 GPR units and 0 FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save 8 GPR units and 0 FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save 8 GPR units and 0 FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ -+/* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save 8 GPR units" "stdarg" { target aarch64-apple-darwin* } } } */ - - void - f4 (int i, ...) -@@ -77,7 +80,8 @@ f4 (int i, ...) - /* { dg-final { scan-tree-dump "f4: va_list escapes 0, needs to save 16 GPR units and 16 FPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && { ! { ia32 || llp64 } } } } } } */ - /* { dg-final { scan-tree-dump "f4: va_list escapes 0, needs to save 24 GPR units and 1" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f4: va_list escapes 0, needs to save 2 GPR units and 0 FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f4: va_list escapes 0, needs to save 24 GPR units and 0 FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f4: va_list escapes 0, needs to save 24 GPR units and 0 FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ -+/* { dg-final { scan-tree-dump "f4: va_list escapes 0, needs to save 24 GPR units" "stdarg" { target aarch64-apple-darwin* } } } */ - - void - f5 (int i, ...) -@@ -92,7 +96,8 @@ f5 (int i, ...) - /* { dg-final { scan-tree-dump "f5: va_list escapes 0, needs to save 16 GPR units and 0 FPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && { ! { ia32 || llp64 } } } } } } */ - /* { dg-final { scan-tree-dump "f5: va_list escapes 0, needs to save 32 GPR units and 1" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f5: va_list escapes 0, needs to save (4|2) GPR units and 0 FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f5: va_list escapes 0, needs to save 16 GPR units and 0 FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f5: va_list escapes 0, needs to save 16 GPR units and 0 FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ -+/* { dg-final { scan-tree-dump "f5: va_list escapes 0, needs to save 16 GPR units" "stdarg" { target aarch64-apple-darwin* } } } */ - - void - f6 (int i, ...) -@@ -107,7 +112,8 @@ f6 (int i, ...) - /* { dg-final { scan-tree-dump "f6: va_list escapes 0, needs to save 8 GPR units and 32 FPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && { ! { ia32 || llp64 } } } } } } */ - /* { dg-final { scan-tree-dump "f6: va_list escapes 0, needs to save 32 GPR units and 3" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f6: va_list escapes 0, needs to save (3|2) GPR units and 0 FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f6: va_list escapes 0, needs to save 8 GPR units and 32 FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f6: va_list escapes 0, needs to save 8 GPR units and 32 FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ -+/* { dg-final { scan-tree-dump "f6: va_list escapes 0, needs to save 24 GPR units" "stdarg" { target aarch64-apple-darwin* } } } */ - - void - f7 (int i, ...) -@@ -122,4 +128,5 @@ f7 (int i, ...) - /* { dg-final { scan-tree-dump "f7: va_list escapes 0, needs to save 0 GPR units and 64 FPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && { ! { ia32 || llp64 } } } } } } */ - /* { dg-final { scan-tree-dump "f7: va_list escapes 0, needs to save 32 GPR units and 2" "stdarg" { target alpha*-*-linux* } } } */ - /* { dg-final { scan-tree-dump "f7: va_list escapes 0, needs to save 2 GPR units and 0 FPR units" "stdarg" { target s390*-*-linux* } } } */ --/* { dg-final { scan-tree-dump "f7: va_list escapes 0, needs to save 0 GPR units and 64 FPR units" "stdarg" { target aarch64*-*-* } } } */ -+/* { dg-final { scan-tree-dump "f7: va_list escapes 0, needs to save 0 GPR units and 64 FPR units" "stdarg" { target { { aarch64*-*-* } && { ! aarch64-apple-darwin* } } } } } */ -+/* { dg-final { scan-tree-dump "f7: va_list escapes 0, needs to save 32 GPR units" "stdarg" { target aarch64-apple-darwin* } } } */ -diff --git a/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp b/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp -index 3e652c483c7..34907929bda 100644 ---- a/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp -+++ b/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp -@@ -25,6 +25,11 @@ if { ![istarget aarch64*-*-*] } then { - return - } - -+if { [istarget *-*-darwin*] } then { -+ # darwinpcs and mach-o will need different test mechanisms. -+ return -+} -+ - torture-init - set-torture-options $C_TORTURE_OPTIONS - set additional_flags "-W -Wall -Wno-abi" -diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bf16_dup.c b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bf16_dup.c -index c42c7acbbe9..76917a6ff5b 100644 ---- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bf16_dup.c -+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bf16_dup.c -@@ -1,4 +1,5 @@ - /* { dg-do assemble { target { aarch64*-*-* } } } */ -+/* { dg-require-effective-target aarch64_asm_bf16_ok } */ - /* { dg-require-effective-target arm_v8_2a_bf16_neon_ok } */ - /* { dg-options "-O2" } */ - /* { dg-add-options arm_v8_2a_bf16_neon } */ -diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bf16_get.c b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bf16_get.c -index 2193753ffbb..d29b222b032 100644 ---- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bf16_get.c -+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bf16_get.c -@@ -1,4 +1,5 @@ - /* { dg-do assemble { target { aarch64*-*-* } } } */ -+/* { dg-require-effective-target aarch64_asm_bf16_ok } */ - /* { dg-require-effective-target arm_v8_2a_bf16_neon_ok } */ - /* { dg-add-options arm_v8_2a_bf16_neon } */ - /* { dg-additional-options "-save-temps" } */ -diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bf16_reinterpret.c b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bf16_reinterpret.c -index f5adf40c648..4e3a3d94416 100644 ---- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bf16_reinterpret.c -+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bf16_reinterpret.c -@@ -1,4 +1,5 @@ - /* { dg-do assemble { target { aarch64*-*-* } } } */ -+/* { dg-require-effective-target aarch64_asm_bf16_ok } */ - /* { dg-require-effective-target arm_v8_2a_bf16_neon_ok } */ - /* { dg-add-options arm_v8_2a_bf16_neon } */ - /* { dg-additional-options "-save-temps" } */ -diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfcvt-compile.c b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfcvt-compile.c -index 47af7c494d9..a2f415f67b7 100644 ---- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfcvt-compile.c -+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfcvt-compile.c -@@ -1,4 +1,5 @@ - /* { dg-do assemble { target { aarch64*-*-* } } } */ -+/* { dg-require-effective-target aarch64_asm_bf16_ok } */ - /* { dg-require-effective-target arm_v8_2a_bf16_neon_ok } */ - /* { dg-add-options arm_v8_2a_bf16_neon } */ - /* { dg-additional-options "-save-temps" } */ -diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfcvt-nosimd.c b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfcvt-nosimd.c -index a914680937d..c6b2ef3e444 100644 ---- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfcvt-nosimd.c -+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfcvt-nosimd.c -@@ -2,7 +2,7 @@ - /* { dg-skip-if "" { *-*-* } { "-fno-fat-lto-objects" } } */ - /* { dg-require-effective-target aarch64_asm_bf16_ok } */ - /* { dg-additional-options "-save-temps -march=armv8.2-a+bf16+nosimd" } */ --/* { dg-final { check-function-bodies "**" "" {-O[^0]} } } */ -+/* { dg-final { check-function-bodies "**" "" {-O[^0]} { target { ! aarch64*-*-darwin* } } } } */ - - #include - -diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfcvtnq2-untied.c b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfcvtnq2-untied.c -index 4b730e39d4e..fd2abadb457 100644 ---- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfcvtnq2-untied.c -+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfcvtnq2-untied.c -@@ -1,8 +1,9 @@ - /* { dg-do assemble { target { aarch64*-*-* } } } */ -+/* { dg-require-effective-target aarch64_asm_bf16_ok } */ - /* { dg-require-effective-target arm_v8_2a_bf16_neon_ok } */ - /* { dg-add-options arm_v8_2a_bf16_neon } */ - /* { dg-additional-options "-save-temps" } */ --/* { dg-final { check-function-bodies "**" "" {-O[^0]} } } */ -+/* { dg-final { check-function-bodies "**" "" {-O[^0]} { target { ! aarch64*-*-darwin* } } } } */ - /* { dg-skip-if "" { *-*-* } { "-fno-fat-lto-objects" } } */ - - #include -diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfdot-1.c b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfdot-1.c -index ad51507731b..e57053d2193 100644 ---- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfdot-1.c -+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfdot-1.c -@@ -1,8 +1,9 @@ - /* { dg-do assemble { target { aarch64*-*-* } } } */ -+/* { dg-require-effective-target aarch64_asm_bf16_ok } */ - /* { dg-require-effective-target arm_v8_2a_bf16_neon_ok } */ - /* { dg-add-options arm_v8_2a_bf16_neon } */ - /* { dg-additional-options "-save-temps" } */ --/* { dg-final { check-function-bodies "**" "" {-O[^0]} } } */ -+/* { dg-final { check-function-bodies "**" "" {-O[^0]} { target { ! aarch64*-*-darwin* } } } } */ - /* { dg-skip-if "" { *-*-* } { "-fno-fat-lto-objects" } } */ - - #include -diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfdot-2.c b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfdot-2.c -index ae0a953f7b4..9f5669a8974 100644 ---- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfdot-2.c -+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfdot-2.c -@@ -3,7 +3,7 @@ - /* { dg-require-effective-target arm_v8_2a_bf16_neon_ok } */ - /* { dg-add-options arm_v8_2a_bf16_neon } */ - /* { dg-additional-options "-mbig-endian --save-temps" } */ --/* { dg-final { check-function-bodies "**" "" {-O[^0]} } } */ -+/* { dg-final { check-function-bodies "**" "" {-O[^0]} { target { ! aarch64*-*-darwin* } } } } */ - /* { dg-skip-if "" { *-*-* } { "-fno-fat-lto-objects" } } */ - - #include -diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfmlalbt-compile.c b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfmlalbt-compile.c -index 9810e4ba374..315cabd464b 100644 ---- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfmlalbt-compile.c -+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfmlalbt-compile.c -@@ -1,8 +1,9 @@ - /* { dg-do assemble { target { aarch64*-*-* } } } */ -+/* { dg-require-effective-target aarch64_asm_bf16_ok } */ - /* { dg-require-effective-target arm_v8_2a_bf16_neon_ok } */ - /* { dg-add-options arm_v8_2a_bf16_neon } */ - /* { dg-additional-options "-save-temps" } */ --/* { dg-final { check-function-bodies "**" "" "-DCHECK_ASM" } } */ -+/* { dg-final { check-function-bodies "**" "" "-DCHECK_ASM" { target { ! aarch64*-*-darwin* } } } } */ - - #include - -diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfmmla-compile.c b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfmmla-compile.c -index 0aaa69f0037..ddc391b1332 100644 ---- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfmmla-compile.c -+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfmmla-compile.c -@@ -1,8 +1,9 @@ - /* { dg-do assemble { target { aarch64*-*-* } } } */ -+/* { dg-require-effective-target aarch64_asm_bf16_ok } */ - /* { dg-require-effective-target arm_v8_2a_bf16_neon_ok } */ - /* { dg-add-options arm_v8_2a_bf16_neon } */ - /* { dg-additional-options "-save-temps" } */ --/* { dg-final { check-function-bodies "**" "" "-DCHECK_ASM" } } */ -+/* { dg-final { check-function-bodies "**" "" "-DCHECK_ASM" { target { ! aarch64*-*-darwin* } } } } */ - - #include - -diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vdot-3-1.c b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vdot-3-1.c -index ac4f821e771..978eac29815 100644 ---- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vdot-3-1.c -+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vdot-3-1.c -@@ -1,8 +1,9 @@ - /* { dg-do assemble { target { aarch64*-*-* } } } */ -+/* { dg-require-effective-target arm_v8_2a_i8mm_neon_hw } */ - /* { dg-require-effective-target arm_v8_2a_i8mm_ok } */ - /* { dg-add-options arm_v8_2a_i8mm } */ - /* { dg-additional-options "-save-temps" } */ --/* { dg-final { check-function-bodies "**" "" {-O[^0]} } } */ -+/* { dg-final { check-function-bodies "**" "" {-O[^0]} { target { ! aarch64*-*-darwin* } } } } */ - /* { dg-skip-if "" { *-*-* } { "-fno-fat-lto-objects" } } */ - - #include -diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vdot-3-2.c b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vdot-3-2.c -index 61c7c51f5ec..f84ed68e2f7 100644 ---- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vdot-3-2.c -+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vdot-3-2.c -@@ -3,7 +3,7 @@ - /* { dg-require-effective-target arm_v8_2a_i8mm_ok } */ - /* { dg-add-options arm_v8_2a_i8mm } */ - /* { dg-additional-options "-mbig-endian -save-temps" } */ --/* { dg-final { check-function-bodies "**" "" {-O[^0]} } } */ -+/* { dg-final { check-function-bodies "**" "" {-O[^0]} { target { ! aarch64*-*-darwin* } } } } */ - /* { dg-skip-if "" { *-*-* } { "-fno-fat-lto-objects" } } */ - - #include -diff --git a/gcc/testsuite/gcc.target/aarch64/arm_align_max_pwr.c b/gcc/testsuite/gcc.target/aarch64/arm_align_max_pwr.c -index ffa4d229922..38b9ef01eb7 100644 ---- a/gcc/testsuite/gcc.target/aarch64/arm_align_max_pwr.c -+++ b/gcc/testsuite/gcc.target/aarch64/arm_align_max_pwr.c -@@ -19,5 +19,7 @@ dummy () - return result; - } - --/* { dg-final { scan-assembler-times "zero\t4" 2 } } */ --/* { dg-final { scan-assembler "zero\t268435452" } } */ -+/* { dg-final { scan-assembler-times "zero\t4" 2 { target { ! *-*-darwin* } } } } */ -+/* { dg-final { scan-assembler "zero\t268435452" { target { ! *-*-darwin*} } } } */ -+/* { dg-final { scan-assembler-times ".zerofill __DATA,__bss,_y,4,28" 1 { target { *-*-darwin* } } } } */ -+/* { dg-final { scan-assembler-times ".zerofill __DATA,__bss,_x,4,28" 1 { target { *-*-darwin* } } } } */ -diff --git a/gcc/testsuite/gcc.target/aarch64/auto-init-2.c b/gcc/testsuite/gcc.target/aarch64/auto-init-2.c -index 375befd325b..3a0387a5952 100644 ---- a/gcc/testsuite/gcc.target/aarch64/auto-init-2.c -+++ b/gcc/testsuite/gcc.target/aarch64/auto-init-2.c -@@ -12,11 +12,11 @@ enum E { - N3 - }; - --extern void bar (char, short, int, enum E, long, long long, int *, bool); -+extern void bar (unsigned char, short, int, enum E, long, long long, int *, bool); - - void foo() - { -- char temp1; -+ unsigned char temp1; - short temp2; - int temp3; - enum E temp4; -diff --git a/gcc/testsuite/gcc.target/aarch64/auto-init-3.c b/gcc/testsuite/gcc.target/aarch64/auto-init-3.c -index 7008f76b294..85a4e4daeb6 100644 ---- a/gcc/testsuite/gcc.target/aarch64/auto-init-3.c -+++ b/gcc/testsuite/gcc.target/aarch64/auto-init-3.c -@@ -2,13 +2,19 @@ - /* { dg-do compile } */ - /* { dg-options "-ftrivial-auto-var-init=zero -fdump-rtl-expand" } */ - --long double result; -+#ifdef __APPLE__ -+# define TYPE _Float128 -+#else -+# define TYPE long double -+#endif - --long double foo() -+TYPE result; -+ -+TYPE foo() - { - float temp1; - double temp2; -- long double temp3; -+ TYPE temp3; - - result = temp1 + temp2 + temp3; - return result; -diff --git a/gcc/testsuite/gcc.target/aarch64/auto-init-4.c b/gcc/testsuite/gcc.target/aarch64/auto-init-4.c -index 10197045b4c..0c6840ba224 100644 ---- a/gcc/testsuite/gcc.target/aarch64/auto-init-4.c -+++ b/gcc/testsuite/gcc.target/aarch64/auto-init-4.c -@@ -2,13 +2,19 @@ - /* { dg-do compile } */ - /* { dg-options "-O -ftrivial-auto-var-init=pattern -fdump-rtl-expand" } */ - --long double result; -+#ifdef __APPLE__ -+# define TYPE _Float128 -+#else -+# define TYPE long double -+#endif - --long double foo() -+TYPE result; -+ -+TYPE foo() - { - float temp1; - double temp2; -- long double temp3; -+ TYPE temp3; - - result = temp1 + temp2 + temp3; - return result; -diff --git a/gcc/testsuite/gcc.target/aarch64/auto-init-5.c b/gcc/testsuite/gcc.target/aarch64/auto-init-5.c -index ac69ac3df82..0dda3c201d3 100644 ---- a/gcc/testsuite/gcc.target/aarch64/auto-init-5.c -+++ b/gcc/testsuite/gcc.target/aarch64/auto-init-5.c -@@ -2,14 +2,19 @@ - /* { dg-do compile } */ - /* { dg-options "-ftrivial-auto-var-init=zero" } */ - -+#ifdef __APPLE__ -+# define TYPE _Float128 -+#else -+# define TYPE long double -+#endif - --_Complex long double result; -+_Complex TYPE result; - --_Complex long double foo() -+_Complex TYPE foo() - { - _Complex float temp1; - _Complex double temp2; -- _Complex long double temp3; -+ _Complex TYPE temp3; - - result = temp1 + temp2 + temp3; - return result; -diff --git a/gcc/testsuite/gcc.target/aarch64/auto-init-6.c b/gcc/testsuite/gcc.target/aarch64/auto-init-6.c -index 0456c66f496..23323115a11 100644 ---- a/gcc/testsuite/gcc.target/aarch64/auto-init-6.c -+++ b/gcc/testsuite/gcc.target/aarch64/auto-init-6.c -@@ -2,14 +2,19 @@ - /* { dg-do compile } */ - /* { dg-options "-ftrivial-auto-var-init=pattern" } */ - -+#ifdef __APPLE__ -+# define TYPE _Float128 -+#else -+# define TYPE long double -+#endif - --_Complex long double result; -+_Complex TYPE result; - --_Complex long double foo() -+_Complex TYPE foo() - { - _Complex float temp1; - _Complex double temp2; -- _Complex long double temp3; -+ _Complex TYPE temp3; - - result = temp1 + temp2 + temp3; - return result; -diff --git a/gcc/testsuite/gcc.target/aarch64/c-output-template-2.c b/gcc/testsuite/gcc.target/aarch64/c-output-template-2.c -index ced96d04542..86e4f5fa82c 100644 ---- a/gcc/testsuite/gcc.target/aarch64/c-output-template-2.c -+++ b/gcc/testsuite/gcc.target/aarch64/c-output-template-2.c -@@ -6,4 +6,4 @@ test (void) - __asm__ ("@ %c0" : : "S" (test)); - } - --/* { dg-final { scan-assembler "@ test" } } */ -+/* { dg-final { scan-assembler "@ _?test" } } */ -diff --git a/gcc/testsuite/gcc.target/aarch64/c-output-template-3.c b/gcc/testsuite/gcc.target/aarch64/c-output-template-3.c -index 8bde4cbeb0c..4531a381518 100644 ---- a/gcc/testsuite/gcc.target/aarch64/c-output-template-3.c -+++ b/gcc/testsuite/gcc.target/aarch64/c-output-template-3.c -@@ -7,4 +7,4 @@ test (void) - __asm__ ("@ %c0" : : "S" (&test + 4)); - } - --/* { dg-final { scan-assembler "@ test\\+4" } } */ -+/* { dg-final { scan-assembler "@ _?test\\+4" } } */ -diff --git a/gcc/testsuite/gcc.target/aarch64/c-output-template-4.c b/gcc/testsuite/gcc.target/aarch64/c-output-template-4.c -index c5a93915af1..800d52bfab8 100644 ---- a/gcc/testsuite/gcc.target/aarch64/c-output-template-4.c -+++ b/gcc/testsuite/gcc.target/aarch64/c-output-template-4.c -@@ -7,4 +7,4 @@ test (void) - __asm__ ("@ %c0" : : "S" (&test + 4)); - } - --/* { dg-final { scan-assembler "@ test\\+4" } } */ -+/* { dg-final { scan-assembler "@ _?test\\+4" } } */ -diff --git a/gcc/testsuite/gcc.target/aarch64/cpymem-size.c b/gcc/testsuite/gcc.target/aarch64/cpymem-size.c -index 4a6f2495d22..b8ef4745c6d 100644 ---- a/gcc/testsuite/gcc.target/aarch64/cpymem-size.c -+++ b/gcc/testsuite/gcc.target/aarch64/cpymem-size.c -@@ -6,7 +6,7 @@ - /* - ** cpy_127: - ** mov (w|x)2, 127 --** b memcpy -+** b _?memcpy - */ - void - cpy_127 (char *out, char *in) -@@ -17,7 +17,7 @@ cpy_127 (char *out, char *in) - /* - ** cpy_128: - ** mov (w|x)2, 128 --** b memcpy -+** b _?memcpy - */ - void - cpy_128 (char *out, char *in) -diff --git a/gcc/testsuite/gcc.target/aarch64/darwin/aarch64-darwin.exp b/gcc/testsuite/gcc.target/aarch64/darwin/aarch64-darwin.exp -new file mode 100644 -index 00000000000..b0b7f49aede ---- /dev/null -+++ b/gcc/testsuite/gcc.target/aarch64/darwin/aarch64-darwin.exp -@@ -0,0 +1,46 @@ -+# Specific tests for the darwinpcs and codegen. -+# Copyright (C) GNU Toolchain Authors -+# Contributed by Iain Sandoe -+# -+# This file is part of GCC. -+# -+# GCC is free software; you can redistribute it and/or modify it -+# under the terms of the GNU General Public License as published by -+# the Free Software Foundation; either version 3, or (at your option) -+# any later version. -+# -+# GCC is distributed in the hope that it will be useful, but -+# WITHOUT ANY WARRANTY; without even the implied warranty of -+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -+# General Public License for more details. -+# -+# You should have received a copy of the GNU General Public License -+# along with GCC; see the file COPYING3. If not see -+# . */ -+ -+# GCC testsuite that uses the `dg.exp' driver. -+ -+# Exit immediately if this isn't aarch64-darwin. -+ -+if { ![istarget aarch64*-*-darwin*] } then { -+ return -+} -+ -+# Load support procs. -+load_lib gcc-dg.exp -+ -+# If a testcase doesn't have special options, use these. -+global DEFAULT_CFLAGS -+if ![info exists DEFAULT_CFLAGS] then { -+ set DEFAULT_CFLAGS " -ansi -pedantic-errors" -+} -+ -+# Initialize `dg'. -+dg-init -+ -+# Main loop. -+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cCS\]]] \ -+ "" $DEFAULT_CFLAGS -+ -+# All done. -+dg-finish -diff --git a/gcc/testsuite/gcc.target/aarch64/darwin/complex-in-regs.c b/gcc/testsuite/gcc.target/aarch64/darwin/complex-in-regs.c -new file mode 100644 -index 00000000000..974f02ca2ec ---- /dev/null -+++ b/gcc/testsuite/gcc.target/aarch64/darwin/complex-in-regs.c -@@ -0,0 +1,103 @@ -+/* { dg-do compile } */ -+/* we need this for complex and gnu initializers. */ -+/* { dg-options "-std=gnu99 " } */ -+/* We use the sections anchors to make the code easier to match. */ -+/* { dg-additional-options " -O -fsection-anchors -fno-schedule-insns -fno-schedule-insns2 " } */ -+/* { dg-final { check-function-bodies "**" "" "" { target *-*-darwin* } } } */ -+ -+ -+__attribute__((__noinline__)) -+_Complex char -+cc_regs_fun (_Complex char r0, _Complex char r1, -+ _Complex char r2, _Complex char r3, -+ _Complex char r4, _Complex char r5, -+ _Complex char r6, _Complex char r7); -+ -+/* -+**call_cc_regs_fun: -+** ... -+** ldrh w7, \[x0\] -+** ldrh w6, \[x0, 2\] -+** ldrh w5, \[x0, 4\] -+** ldrh w4, \[x0, 6\] -+** ldrh w3, \[x0, 8\] -+** ldrh w2, \[x0, 10\] -+** ldrh w1, \[x0, 12\] -+** ldrh w0, \[x0, 14]\ -+** bl _cc_regs_fun -+** ... -+*/ -+ -+_Complex char -+call_cc_regs_fun (void) -+{ -+ return cc_regs_fun ((_Complex char) (1 + 1i), (_Complex char) (2 + 2i), -+ (_Complex char) (3 + 3i), (_Complex char) (4 + 4i), -+ (_Complex char) (5 + 5i), (_Complex char) (6 + 6i), -+ (_Complex char) (7 + 7i), (_Complex char) (8 + 8i)); -+} -+ -+ -+__attribute__((__noinline__)) -+_Complex short -+cs_regs_fun (_Complex short r0, _Complex short r1, -+ _Complex short r2, _Complex short r3, -+ _Complex short r4, _Complex short r5, -+ _Complex short r6, _Complex short r7); -+ -+/* -+**call_cs_regs_fun: -+** ... -+** ldr w7, \[x0, 16\] -+** ldr w6, \[x0, 20\] -+** ldr w5, \[x0, 24\] -+** ldr w4, \[x0, 28\] -+** ldr w3, \[x0, 32\] -+** ldr w2, \[x0, 36\] -+** ldr w1, \[x0, 40\] -+** ldr w0, \[x0, 44\] -+** bl _cs_regs_fun -+** ... -+*/ -+ -+__attribute__((__noinline__)) -+_Complex short -+call_cs_regs_fun (void) -+{ -+ return cs_regs_fun ((_Complex short) (1 + 1i), (_Complex short) (2 + 2i), -+ (_Complex short) (3 + 3i), (_Complex short) (4 + 4i), -+ (_Complex short) (5 + 5i), (_Complex short) (6 + 6i), -+ (_Complex short) (7 + 7i), (_Complex short) (8 + 8i)); -+} -+ -+__attribute__((__noinline__)) -+_Complex int -+ci_regs_fun (_Complex int r0, _Complex int r1, -+ _Complex int r2, _Complex int r3, -+ _Complex int r4, _Complex int r5, -+ _Complex int r6, _Complex int r7); -+ -+/* -+**call_ci_regs_fun: -+** ... -+** ldr x7, \[x0, 48\] -+** ldr x6, \[x0, 56\] -+** ldr x5, \[x0, 64\] -+** ldr x4, \[x0, 72\] -+** ldr x3, \[x0, 80\] -+** ldr x2, \[x0, 88\] -+** ldr x1, \[x0, 96\] -+** ldr x0, \[x0, 104\] -+** bl _ci_regs_fun -+** ... -+*/ -+ -+__attribute__((__noinline__)) -+_Complex int -+call_ci_regs_fun (void) -+{ -+ return ci_regs_fun ((_Complex int) (1 + 1i), (_Complex int) (2 + 2i), -+ (_Complex int) (3 + 3i), (_Complex int) (4 + 4i), -+ (_Complex int) (5 + 5i), (_Complex int) (6 + 6i), -+ (_Complex int) (7 + 7i), (_Complex int) (8 + 8i)); -+} -diff --git a/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d1.c b/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d1.c -new file mode 100644 -index 00000000000..e2dd574fac7 ---- /dev/null -+++ b/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d1.c -@@ -0,0 +1,54 @@ -+/* { dg-do compile } */ -+/* we need this for the empty struct. */ -+/* { dg-options "-std=gnu99 " } */ -+/* { dg-additional-options "-O -fno-schedule-insns -fno-schedule-insns2 " } */ -+/* { dg-final { check-function-bodies "**" "" "" { target *-*-darwin* } } } */ -+ -+/* Make sure we do no consume any registers in passing zero-sized entities */ -+ -+typedef struct es {} Empty; -+ -+__attribute__((__noinline__)) void -+use_no_regs (int a, Empty b, int c, Empty d, Empty e, int f); -+ -+/* -+**call_use_no_regs: -+** ... -+** mov w2, 3 -+** mov w1, 2 -+** mov w0, 1 -+** bl _use_no_regs -+** ... -+*/ -+ -+__attribute__((__noinline__)) void -+call_use_no_regs (void) -+{ -+ Empty e; -+ use_no_regs (1, e, 2, e, e, 3); -+} -+ -+/* Make sure we consume no stack in passing zero-sized entities. */ -+ -+/* -+**call_use_no_stack: -+** ... -+** mov w[0-9]+, 108 -+** strb w[0-9]+, \[sp, 1\] -+** mov w[0-9]+, 106 -+** strb w[0-9]+, \[sp\] -+** ... -+** bl _use_no_stack -+** ... -+*/ -+ -+__attribute__((__noinline__)) void -+use_no_stack (int a, int b, int c, int d, int e, int f, int g, int h, -+ Empty i, char j, Empty k, char l); -+ -+void -+call_use_no_stack (void) -+{ -+ Empty e; -+ use_no_stack (0, 1, 2, 3, 4, 5, 6, 7, e, 'j', e, 'l'); -+} -diff --git a/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d2-00.c b/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d2-00.c -new file mode 100644 -index 00000000000..bd76856308b ---- /dev/null -+++ b/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d2-00.c -@@ -0,0 +1,126 @@ -+/* { dg-do compile } */ -+/* { dg-additional-options " -O -fno-schedule-insns -fno-schedule-insns2 " } */ -+/* { dg-final { check-function-bodies "**" "" "" { target *-*-darwin* } } } */ -+ -+/* In each case we consume the parm registers with 8 ints, forcing -+ the test values to be spilled to the stack. */ -+ -+/* The important thing here is that the chars are assigned to the stack -+ * with no padding - so that they occupy bytes 0-8. */ -+ -+/* -+**call_char_packing: -+** ... -+** mov w[0-9]+, 113 -+** strb w[0-9]+, \[sp, 8\] -+** mov w[0-9]+, 112 -+** strb w[0-9]+, \[sp, 7\] -+** mov w[0-9]+, 111 -+** strb w[0-9]+, \[sp, 6\] -+** mov w[0-9]+, 110 -+** strb w[0-9]+, \[sp, 5\] -+** mov w[0-9]+, 109 -+** strb w[0-9]+, \[sp, 4\] -+** mov w[0-9]+, 108 -+** strb w[0-9]+, \[sp, 3\] -+** mov w[0-9]+, 107 -+** strb w[0-9]+, \[sp, 2\] -+** mov w[0-9]+, 106 -+** strb w[0-9]+, \[sp, 1\] -+** mov w[0-9]+, 105 -+** strb w[0-9]+, \[sp\] -+** mov w7, 7 -+** mov w6, 6 -+** mov w5, 5 -+** mov w4, 4 -+** mov w3, 3 -+** mov w2, 2 -+** mov w1, 1 -+** mov w0, 0 -+** bl _char_packing -+** ... -+*/ -+ -+__attribute__((__noinline__)) void -+char_packing (int a, int b, int c, int d, int e, int f, int g, int h, -+ char i, char j, char k, char l, -+ char m, char n, char o, char p, -+ char q); -+ -+void call_char_packing (void) -+{ -+ char_packing (0, 1, 2, 3, 4, 5, 6, 7, -+ 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q'); -+} -+ -+/* Here we should occupy the first 7 short words on the stack. */ -+ -+/* -+**call_short_packing: -+** ... -+** mov w[0-9]+, 12 -+** strh w[0-9]+, \[sp, 8\] -+** mov w[0-9]+, 11 -+** strh w[0-9]+, \[sp, 6\] -+** mov w[0-9]+, 10 -+** strh w[0-9]+, \[sp, 4\] -+** mov w[0-9]+, 9 -+** strh w[0-9]+, \[sp, 2\] -+** mov w[0-9]+, 8 -+** strh w[0-9]+, \[sp\] -+** mov w7, 7 -+** mov w6, 6 -+** mov w5, 5 -+** mov w4, 4 -+** mov w3, 3 -+** mov w2, 2 -+** mov w1, 1 -+** mov w0, 0 -+** bl _short_packing -+** ... -+*/ -+ -+__attribute__((__noinline__)) void -+short_packing (int a, int b, int c, int d, int e, int f, int g, int h, -+ short i, short j, short k, short l, -+ short m); -+ -+void call_short_packing (void) -+{ -+ short_packing (0, 1, 2, 3, 4, 5, 6, 7, -+ 8, 9, 10, 11, 12); -+} -+ -+/* Here we should occupy the first 3 ints on the stack. */ -+ -+/* -+**call_int_packing: -+** ... -+** mov w[0-9]+, 10 -+** str w[0-9]+, \[sp, 8\] -+** mov w[0-9]+, 9 -+** str w[0-9]+, \[sp, 4\] -+** mov w[0-9]+, 8 -+** str w[0-9]+, \[sp\] -+** mov w7, 7 -+** mov w6, 6 -+** mov w5, 5 -+** mov w4, 4 -+** mov w3, 3 -+** mov w2, 2 -+** mov w1, 1 -+** mov w0, 0 -+** bl _int_packing -+** ... -+*/ -+ -+__attribute__((__noinline__)) void -+int_packing (int a, int b, int c, int d, int e, int f, int g, int h, -+ int i, int j, int k); -+ -+void call_int_packing (void) -+{ -+ int_packing (0, 1, 2, 3, 4, 5, 6, 7, -+ 8, 9, 10); -+} -+ -diff --git a/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d2-01.c b/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d2-01.c -new file mode 100644 -index 00000000000..d21fd551b4a ---- /dev/null -+++ b/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d2-01.c -@@ -0,0 +1,115 @@ -+/* { dg-do compile } */ -+/* { dg-additional-options " -O -fno-schedule-insns -fno-schedule-insns2 " } */ -+/* { dg-final { check-function-bodies "**" "" "" { target *-*-darwin* } } } */ -+ -+/* In each case we consume the parm registers with 8 ints, forcing -+ the test values to be spilled to the stack. */ -+ -+/* char short char short - everything on 2byte boundaries */ -+ -+/* -+**call_c_s_packing: -+** ... -+** mov w[0-9]+, 109 -+** strb w[0-9]+, \[sp, 8\] -+** mov w[0-9]+, 9 -+** strh w[0-9]+, \[sp, 6\] -+** mov w[0-9]+, 107 -+** strb w[0-9]+, \[sp, 4\] -+** mov w[0-9]+, 8 -+** strh w[0-9]+, \[sp, 2\] -+** mov w[0-9]+, 105 -+** strb w[0-9]+, \[sp\] -+** mov w7, 7 -+** mov w6, 6 -+** mov w5, 5 -+** mov w4, 4 -+** mov w3, 3 -+** mov w2, 2 -+** mov w1, 1 -+** mov w0, 0 -+** bl _c_s_packing -+** ... -+*/ -+ -+__attribute__((__noinline__)) void -+c_s_packing (int a, int b, int c, int d, int e, int f, int g, int h, -+ char i, short j, char k, short l, -+ char m); -+ -+void call_c_s_packing (void) -+{ -+ c_s_packing (0, 1, 2, 3, 4, 5, 6, 7, -+ 'i', 8 , 'k', 9, 'm'); -+} -+ -+/* -+**call_s_c_packing: -+** ... -+** mov w[0-9]+, 109 -+** strb w[0-9]+, \[sp, 7\] -+** mov w[0-9]+, 108 -+** strb w[0-9]+, \[sp, 6\] -+** mov w[0-9]+, 9 -+** strh w[0-9]+, \[sp, 4\] -+** mov w[0-9]+, 106 -+** strb w[0-9]+, \[sp, 2\] -+** mov w[0-9]+, 8 -+** strh w[0-9]+, \[sp\] -+** mov w7, 7 -+** mov w6, 6 -+** mov w5, 5 -+** mov w4, 4 -+** mov w3, 3 -+** mov w2, 2 -+** mov w1, 1 -+** mov w0, 0 -+** bl _s_c_packing -+** ... -+*/ -+ -+__attribute__((__noinline__)) void -+s_c_packing (int a, int b, int c, int d, int e, int f, int g, int h, -+ short i, char j, short k, char l, -+ char m); -+ -+void call_s_c_packing (void) -+{ -+ s_c_packing (0, 1, 2, 3, 4, 5, 6, 7, -+ 8, 'j' , 9, 'l', 'm'); -+} -+ -+/* 0, 2, 4, 0 */ -+ -+/* -+**call_csi_packing: -+** ... -+** mov w[0-9]+, 108 -+** strb w[0-9]+, \[sp, 8\] -+** mov w[0-9]+, 9 -+** str w[0-9]+, \[sp, 4\] -+** mov w[0-9]+, 8 -+** strh w[0-9]+, \[sp, 2\] -+** mov w[0-9]+, 105 -+** strb w[0-9]+, \[sp\] -+** mov w7, 7 -+** mov w6, 6 -+** mov w5, 5 -+** mov w4, 4 -+** mov w3, 3 -+** mov w2, 2 -+** mov w1, 1 -+** mov w0, 0 -+** bl _csi_packing -+** ... -+*/ -+ -+__attribute__((__noinline__)) void -+csi_packing (int a, int b, int c, int d, int e, int f, int g, int h, -+ char i, short j, int k, char l); -+ -+void call_csi_packing (void) -+{ -+ csi_packing (0, 1, 2, 3, 4, 5, 6, 7, -+ 'i', 8 , 9, 'l'); -+} -diff --git a/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d2-02.c b/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d2-02.c -new file mode 100644 -index 00000000000..55e5acdaf41 ---- /dev/null -+++ b/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d2-02.c -@@ -0,0 +1,75 @@ -+/* { dg-do compile } */ -+/* we need this for complex literals. */ -+/* { dg-options "-std=gnu99 " } */ -+/* { dg-additional-options "-O -fsection-anchors -fno-schedule-insns -fno-schedule-insns2 " } */ -+/* { dg-final { check-function-bodies "**" "" "" { target *-*-darwin* } } } */ -+ -+ -+__attribute__((__noinline__)) void -+c_cc_packing (int a, int b, int c, int d, int e, int f, int g, int h, -+ _Complex char i, _Complex char j); -+ -+/* We check that these values are not packed on the stack. -+**call_c_cc_packing: -+** ... -+** ldrh w[0-9]+, \[x[0-9]+\] -+** strh w[0-9]+, \[sp, 8\] -+** ldrh w[0-9]+, \[x[0-9]+, 2\] -+** strh w[0-9]+, \[sp\] -+** ... -+** bl _c_cc_packing -+** ... -+*/ -+ -+void -+call_c_cc_packing (void) -+{ -+ c_cc_packing (0, 1, 2, 3, 4, 5, 6, 7, -+ (_Complex char) (1 + 1i),(_Complex char) (2 + 2i)); -+} -+ -+ -+__attribute__((__noinline__)) void -+c_cs_packing (int a, int b, int c, int d, int e, int f, int g, int h, -+ _Complex short i, _Complex short j); -+ -+/* -+**call_c_cs_packing: -+** ... -+** ldr w[0-9]+, \[x[0-9]+, 4\] -+** str w[0-9]+, \[sp, 8\] -+** ldr w[0-9]+, \[x[0-9]+, 8\] -+** str w[0-9]+, \[sp\] -+** ... -+** bl _c_cs_packing -+** ... -+*/ -+ -+void -+call_c_cs_packing (void) -+{ -+ c_cs_packing (0, 1, 2, 3, 4, 5, 6, 7, -+ (_Complex short) (1 + 1i),(_Complex short) (2 + 2i)); -+} -+ -+void c_ci_packing (int a, int b, int c, int d, int e, int f, int g, int h, -+ _Complex int i, _Complex int j); -+ -+/* -+**call_c_ci_packing: -+** ... -+** ldr x[0-9]+, \[x[0-9]+, 12\] -+** str x[0-9]+, \[sp, 8\] -+** ldr x[0-9]+, \[x[0-9]+, 20\] -+** str x[0-9]+, \[sp\] -+** ... -+** bl _c_ci_packing -+** ... -+*/ -+ -+void -+call_c_ci_packing (void) -+{ -+ c_ci_packing (0, 1, 2, 3, 4, 5, 6, 7, -+ (_Complex int) (1 + 1i),(_Complex int) (2 + 2i)); -+} -diff --git a/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d2-03.c b/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d2-03.c -new file mode 100644 -index 00000000000..b0d2593dfd7 ---- /dev/null -+++ b/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d2-03.c -@@ -0,0 +1,67 @@ -+/* { dg-do compile } */ -+ -+/* { dg-additional-options "-O -fno-schedule-insns -fno-schedule-insns2 " } */ -+/* { dg-final { check-function-bodies "**" "" "" { target *-*-darwin* } } } */ -+ -+typedef union u { char a; short b; } U; -+typedef struct sf { float a; float b; float c;} SF; -+ -+__attribute__((__noinline__)) void -+u_packing (int a, int b, int c, int d, int e, int f, int g, int h, -+ U i, U j); -+ -+/* We check that these values are not packed on the stack. -+**call_u_packing: -+** ... -+** strh w[0-9]+, \[sp, 8\] -+** strh w[0-9]+, \[sp\] -+** ... -+** bl _u_packing -+** ... -+*/ -+ -+void -+call_u_packing (void) -+{ -+ U x = { 'a' }; -+ u_packing (0, 1, 2, 3, 4, 5, 6, 7, x, x); -+} -+ -+/* But a homogeneous float aggregate is treated as if it were the contained -+ floats. */ -+ -+__attribute__((__noinline__)) void -+sf_packing (float a, float b, float c, float d, -+ float e, float f, float g, float h, -+ SF i, SF j); -+ -+/* So the stores to sp+12 and 20 pack the floats onto the stack. -+**call_sf_packing: -+** ... -+** fmov s1, 1.0e\+0 -+** str s1, \[sp, 48\] -+** fmov s2, 2.0e\+0 -+** str s2, \[sp, 52\] -+** mov w[0-9]+, 1077936128 -+** ldr x[0-9]+, \[sp, 48\] -+** str x[0-9]+, \[sp, 12\] -+** str w[0-9]+, \[sp, 20\] -+** str x[0-9]+, \[sp\] -+** str w[0-9]+, \[sp, 8\] -+** fmov s7, 7.0e\+0 -+** fmov s6, 6.0e\+0 -+** fmov s5, 5.0e\+0 -+** fmov s4, 4.0e\+0 -+** fmov s3, 3.0e\+0 -+** movi v0.2s, #0 -+** bl _sf_packing -+** ... -+*/ -+ -+void -+call_sf_packing (void) -+{ -+ SF A = {1.0F, 2.0F, 3.0F}; -+ sf_packing (0.0F, 1.0F, 2.0F, 3.0F, 4.0F, 5.0F, 6.0F, 7.0F, -+ A, A); -+} -diff --git a/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d2-04.c b/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d2-04.c -new file mode 100644 -index 00000000000..33c60c69b78 ---- /dev/null -+++ b/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d2-04.c -@@ -0,0 +1,66 @@ -+/* { dg-do compile } */ -+ -+/* { dg-additional-options "-O -fno-schedule-insns -fno-schedule-insns2 " } */ -+/* { dg-final { check-function-bodies "**" "" "" { target *-*-darwin* } } } */ -+ -+typedef short v2hi __attribute__ ((vector_size (4))); -+typedef int v4si __attribute__ ((vector_size (16))); -+ -+v4si t; -+int al = __alignof__ (t); -+ -+__attribute__((__noinline__)) void -+v2hi_packing (v2hi a, v2hi b, v2hi c, v2hi d, v2hi e, v2hi f, v2hi g, v2hi h, -+ v2hi i, v2hi j); -+ -+/* We check that v2hi is packed on the stack. -+**call_v2hi_packing: -+** ... -+** mov w[0-9]+, 1 -+** movk w[0-9]+, 0x2, lsl 16 -+** str w[0-9]+, \[sp, 4\] -+** str w[0-9]+, \[sp\] -+** mov w7, w[0-9]+ -+** mov w6, w[0-9]+ -+** mov w5, w[0-9]+ -+** mov w4, w[0-9]+ -+** mov w3, w[0-9]+ -+** mov w2, w[0-9]+ -+** mov w1, w[0-9]+ -+** bl _v2hi_packing -+** ... -+*/ -+ -+void -+call_v2hi_packing (void) -+{ -+ v2hi x = {1,2}; -+ v2hi_packing (x, x, x, x, x, x, x, x, x, x); -+} -+ -+ -+__attribute__((__noinline__)) void -+v4si_packing (int r0, int r1, int r2, int r3, int r4, int r5, int r6, int r7, -+ v4si a, v4si b, v4si c, v4si d, v4si e, v4si f, v4si g, v4si h, -+ int stack, v4si i, v4si j); -+ -+/* Test that we align a 16b vector on the stack. -+**call_v4si_packing: -+** ... -+** adrp x0, lC0@PAGE -+** ldr q[0-9]+, \[x[0-9]+, #lC0@PAGEOFF\] -+** str q[0-9]+, \[sp, 32\] -+** str q[0-9]+, \[sp, 16\] -+** mov w[0-9]+, 42 -+** str w[0-9]+, \[sp\] -+** ... -+** bl _v4si_packing -+** ... -+*/ -+ -+void -+call_v4si_packing (void) -+{ -+ v4si x = {3,1,2,4}; -+ v4si_packing (0, 1, 2, 3, 4, 5, 6, 7, x, x, x, x, x, x, x, x, 42, x, x); -+} -diff --git a/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d3.c b/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d3.c -new file mode 100644 -index 00000000000..21c6b696b7c ---- /dev/null -+++ b/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d3.c -@@ -0,0 +1,40 @@ -+/* { dg-do compile } */ -+/* { dg-additional-options "-O " } */ -+/* { dg-final { check-function-bodies "**" "" "" { target *-*-darwin* } } } */ -+ -+/* This will fail, because of issue #74 -+**foo: -+** cmp w0, w1 -+** cset w0, eq -+** ret -+*/ -+ -+__attribute__((__noinline__)) -+int -+foo (char a, unsigned char b) -+{ -+ return a == b ? 1 : 0; -+} -+ -+__attribute__((__noinline__)) -+int -+bar (short a, unsigned short b) -+{ -+ return a == b ? 1 : 0; -+} -+ -+void pop (char *, unsigned char *, short *, unsigned short *); -+ -+int main () -+{ -+ char a; -+ unsigned char b; -+ short c; -+ unsigned short d; -+ int result; -+ pop (&a, &b, &c, &d); -+ -+ result = foo (a, b); -+ result += bar (c, d); -+ return result; -+} -diff --git a/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d4.c b/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d4.c -new file mode 100644 -index 00000000000..2aab48260f4 ---- /dev/null -+++ b/gcc/testsuite/gcc.target/aarch64/darwin/darwinpcs-d4.c -@@ -0,0 +1,62 @@ -+/* { dg-do compile } */ -+/* we need this for __int128. */ -+/* { dg-options "-std=gnu99 " } */ -+/* { dg-additional-options "-O -fno-schedule-insns -fno-schedule-insns2 " } */ -+/* { dg-final { check-function-bodies "**" "" "" { target *-*-darwin* } } } */ -+ -+/* we should use x0, x1 and x2 - not skip x1. -+**foo: -+** eor x0, x0, x1 -+** orr x0, x0, x2 -+** cmp x0, 0 -+** cset w0, eq -+** ret -+*/ -+ -+__attribute__((__noinline__)) -+int -+foo (unsigned long long x,unsigned __int128 y) -+{ -+ return x == y ? 1 : 0; -+} -+ -+/* we should use x0, x1 and x2. -+**bar: -+** eor x2, x2, x0 -+** orr x2, x2, x1 -+** cmp x2, 0 -+** cset w0, eq -+** ret -+*/ -+ -+__attribute__((__noinline__)) -+int -+bar (unsigned __int128 y, unsigned long long x) -+{ -+ return x == y ? 1 : 0; -+} -+ -+int fooo (unsigned long long x, unsigned __int128 y); -+int baro (unsigned __int128 y, unsigned long long x); -+ -+/* we should use x0, x1 and x2 in both calls. -+**main: -+** ... -+** mov x1, 25 -+** mov x2, 0 -+** mov x0, 10 -+** bl _fooo -+** mov x2, 10 -+** mov x0, 25 -+** mov x1, 0 -+** bl _baro -+** ... -+*/ -+ -+int main () -+{ -+ unsigned long long x = 10; -+ unsigned __int128 y = 25; -+ int r = fooo (x, y); -+ r += baro (y, x); -+} -diff --git a/gcc/testsuite/gcc.target/aarch64/darwin/float128-00.c b/gcc/testsuite/gcc.target/aarch64/darwin/float128-00.c -new file mode 100644 -index 00000000000..29aec80fbaa ---- /dev/null -+++ b/gcc/testsuite/gcc.target/aarch64/darwin/float128-00.c -@@ -0,0 +1,38 @@ -+ -+/* we need this for _Float128. */ -+/* { dg-options "-std=gnu99 " } */ -+/* We use the sections anchors to make the code easier to match. */ -+/* { dg-additional-options " -O2 -fsection-anchors " } */ -+/* { dg-final { check-function-bodies "**" "" "" { target *-*-darwin* } } } */ -+ -+/* we should just pass q0 and q1 through -+**foo: -+** ... -+** bl ___addtf3 -+** ... -+*/ -+ -+__attribute__((__noinline__)) -+_Float128 -+foo (_Float128 a, _Float128 b) -+{ -+ return a + b; -+} -+ -+ -+/* we should just load q0 and q1 -+**call_foo: -+** ... -+** ldr q1, \[x[0-9]+\] -+** ... -+** ldr q0, \[x[0-9]+\] -+** b _foo -+** ... -+*/ -+ -+__attribute__((__noinline__)) -+_Float128 -+call_foo (void) -+{ -+ return foo (1.0, 2.0); -+} -diff --git a/gcc/testsuite/gcc.target/aarch64/darwin/homogeneous-aggr.c b/gcc/testsuite/gcc.target/aarch64/darwin/homogeneous-aggr.c -new file mode 100644 -index 00000000000..bee97557a4d ---- /dev/null -+++ b/gcc/testsuite/gcc.target/aarch64/darwin/homogeneous-aggr.c -@@ -0,0 +1,25 @@ -+/* { dg-do compile } */ -+/* { dg-additional-options "-O " } */ -+/* { dg-final { check-function-bodies "**" "" "" { target *-*-darwin* } } } */ -+ -+typedef struct sf { float a; float b; float c;} SF; -+ -+__attribute__((__noinline__)) void -+hmg_f (SF a); -+ -+/* we should use registers for each item -+**call_hmg_f: -+** ... -+** fmov s0, 1.0e\+0 -+** fmov s1, 2.0e\+0 -+** fmov s2, 3.0e\+0 -+** bl _hmg_f -+** ... -+*/ -+ -+void -+call_hmg_f (void) -+{ -+ SF A = { 1.0F, 2.0F, 3.0F }; -+ hmg_f (A); -+} -diff --git a/gcc/testsuite/gcc.target/aarch64/darwin/k+r-00.c b/gcc/testsuite/gcc.target/aarch64/darwin/k+r-00.c -new file mode 100644 -index 00000000000..443fb968811 ---- /dev/null -+++ b/gcc/testsuite/gcc.target/aarch64/darwin/k+r-00.c -@@ -0,0 +1,28 @@ -+/* { dg-do compile } */ -+ -+/* { dg-options "-std=gnu99 " } */ -+/* { dg-additional-options "-O2 -fsection-anchors" } */ -+ -+ -+/* What we care about here is that we get int loads from sp, sp+4 and sp+8. -+ * This code will change when we implement darwinpcs d.3 - since the -+ * promotions will no longer be needed (although they are harmless). -+**test_k_r00: -+** ldrsb w[0-9]+, \[sp, 4\] -+** ldr x[0-9]+, \[sp, 8\] -+** ... -+** ldrsb w[0-9]+, \[sp\] -+** ... -+*/ -+ -+const char * -+test_k_r00 (r0, r1, r2, r3, r4, r5, r6, r7, a, b, c) -+ char r0, r1, r2, r3, r4, r5, r6, r7; -+ char a; -+ char b; -+ const char *c; -+{ -+ if (a > 10 && b < 100) -+ return c; -+ return (char *)0; -+} -diff --git a/gcc/testsuite/gcc.target/aarch64/darwin/tu-accesses-0.c b/gcc/testsuite/gcc.target/aarch64/darwin/tu-accesses-0.c -new file mode 100644 -index 00000000000..ba5cc493bc9 ---- /dev/null -+++ b/gcc/testsuite/gcc.target/aarch64/darwin/tu-accesses-0.c -@@ -0,0 +1,82 @@ -+/* { dg-do compile } */ -+/* { dg-options "-O -fcommon -mno-pc-relative-literal-loads" } */ -+/* { dg-final { check-function-bodies "**" "" "" { target *-*-darwin* } } } */ -+ -+/* This checks that we perform the correct accesses for file-scope vars -+ including GOT indirections. */ -+ -+double gd = 1.0; -+ -+__attribute__((__weak__)) -+double wd = 2.0; -+ -+__attribute__((__visibility__("hidden"))) -+double hd = 3.0; -+ -+__attribute__((__weak__, __visibility__("hidden"))) -+double whd = 4.0; -+ -+extern double ed; -+ -+double cd; -+ -+static double sd = 5.0; -+ -+struct { -+ double a; -+ double b; -+} two_dbls = { 1.0, 42.0 }; -+ -+double arr[3] = { 6.0, 7.0, 8.0 }; -+ -+/* -+**test: -+** adrp x[0-9]+, _gd@PAGE -+** ldr d[0-9]+, \[x[0-9]+, #_gd@PAGEOFF\] -+** adrp x[0-9]+, lC0@PAGE -+** ldr d[0-9]+, \[x[0-9]+, #lC0@PAGEOFF\] -+** fadd d[0-9]+, d[0-9]+, d[0-9]+ -+** adrp x[0-9]+, _wd@GOTPAGE -+** ldr x[0-9]+, \[x[0-9]+, _wd@GOTPAGEOFF\] -+** ldr d[0-9]+, \[x[0-9]+\] -+** fadd d[0-9]+, d[0-9]+, d[0-9]+ -+** adrp x[0-9]+, _hd@PAGE -+** ldr d[0-9]+, \[x[0-9]+, #_hd@PAGEOFF\] -+** fadd d[0-9]+, d[0-9]+, d[0-9]+ -+** adrp x[0-9]+, _whd@PAGE -+** ldr d[0-9]+, \[x[0-9]+, #_whd@PAGEOFF\] -+** fadd d[0-9]+, d[0-9]+, d[0-9]+ -+** adrp x[0-9]+, _ed@GOTPAGE -+** ldr x[0-9]+, \[x[0-9]+, _ed@GOTPAGEOFF\] -+** ldr d[0-9]+, \[x[0-9]+\] -+** fadd d[0-9]+, d[0-9]+, d[0-9]+ -+** adrp x[0-9]+, _cd@GOTPAGE -+** ldr x[0-9]+, \[x[0-9]+, _cd@GOTPAGEOFF\] -+** ldr d[0-9]+, \[x[0-9]+\] -+** fadd d[0-9]+, d[0-9]+, d[0-9]+ -+** fmov d[0-9]+, 5.0e\+0 -+** fadd d[0-9]+, d[0-9]+, d[0-9]+ -+** adrp x[0-9]+, _two_dbls@PAGE\+8 -+** ldr d[0-9]+, \[x[0-9]+, #_two_dbls@PAGEOFF\+8\] -+** fadd d[0-9]+, d[0-9]+, d[0-9]+ -+** adrp x[0-9]+, _arr@PAGE\+16 -+** ldr d[0-9]+, \[x[0-9]+, #_arr@PAGEOFF\+16\] -+** fadd d[0-9]+, d[0-9]+, d[0-9]+ -+** ret -+*/ -+ -+double test (void) -+{ -+ double x = 123456123456123456.0; -+ x += gd; -+ x += wd; -+ x += hd; -+ x += whd; -+ x += ed; -+ x += cd; -+ x += sd; -+ x += two_dbls.b; -+ x += arr[2]; -+ -+ return x; -+} -diff --git a/gcc/testsuite/gcc.target/aarch64/darwin/variadic-00.c b/gcc/testsuite/gcc.target/aarch64/darwin/variadic-00.c -new file mode 100644 -index 00000000000..6420fca11d5 ---- /dev/null -+++ b/gcc/testsuite/gcc.target/aarch64/darwin/variadic-00.c -@@ -0,0 +1,91 @@ -+/* { dg-do compile } */ -+ -+/* We use the sections anchors to make the code easier to match. */ -+/* { dg-additional-options " -O -fsection-anchors -fno-schedule-insns -fno-schedule-insns2 " } */ -+/* { dg-final { check-function-bodies "**" "" "" { target *-*-darwin* } } } */ -+ -+#include -+ -+/* What we care about here is that the load of w0 is from the incoming [SP] -+**fooi: -+** sub sp, sp, #16 -+** add x[0-9]+, sp, 24 -+** str x[0-9]+, \[sp, 8\] -+** ldr w0, \[sp, 16\] -+** ... -+*/ -+ -+__attribute__((__noinline__)) int -+fooi (int a, ...) -+{ -+ int x; -+ va_list ap; -+ va_start(ap, a); -+ x = va_arg(ap, int); -+ va_end(ap); -+ return x; -+} -+ -+__attribute__((__noinline__)) int -+fooo (char a, ...); -+ -+/* -+**call_foo: -+** ... -+** mov w[0-9]+, 42 -+** str w[0-9]+, \[sp\] -+** mov w0, 1 -+** bl _fooo -+** ... -+*/ -+ -+__attribute__((__noinline__)) int -+call_foo (void) -+{ -+ int y = fooo (1, 42); -+ return y; -+} -+ -+/* What we care about here is that the load of w0 is from the incoming [SP+8] -+**bari: -+** sub sp, sp, #16 -+** add x[0-9]+, sp, 32 -+** str x[0-9]+, \[sp, 8\] -+** ldr w0, \[sp, 24\] -+** ... -+*/ -+ -+__attribute__((__noinline__)) int -+bari (int a, int b, int c, int d, int e, int f, int g, int h, -+ int i, ...) -+{ -+ int x; -+ va_list ap; -+ va_start(ap, i); -+ x = va_arg(ap, int); -+ va_end(ap); -+ return x; -+} -+ -+/* -+**call_bar: -+** ... -+** mov w[0-9]+, 42 -+** str w[0-9]+, \[sp, 8\] -+** mov w[0-9]+, 9 -+** str w[0-9]+, \[sp\] -+** ... -+ bl _baro -+** ... -+*/ -+ -+__attribute__((__noinline__)) int -+baro (int a, int b, int c, int d, int e, int f, int g, int h, -+ int i, ...); -+ -+__attribute__((__noinline__)) int -+call_bar (void) -+{ -+ int y = baro (1, 2, 3, 4, 5, 6, 7, 8, 9, 42); -+ return y; -+} -diff --git a/gcc/testsuite/gcc.target/aarch64/darwin/variadic-01.c b/gcc/testsuite/gcc.target/aarch64/darwin/variadic-01.c -new file mode 100644 -index 00000000000..c055aeae580 ---- /dev/null -+++ b/gcc/testsuite/gcc.target/aarch64/darwin/variadic-01.c -@@ -0,0 +1,102 @@ -+/* { dg-do compile } */ -+ -+/* we need this for _Float128. */ -+/* { dg-options "-std=gnu99 " } */ -+/* We use the sections anchors to make the code easier to match. */ -+/* { dg-additional-options " -O2 -fsection-anchors " } */ -+/* { dg-final { check-function-bodies "**" "" "" { target *-*-darwin* } } } */ -+ -+#include -+ -+/* What we care about here is that q0 and q1 are loaded from incoming sp and -+ sp+16. -+**foo: -+** ... -+** ldr q1, \[sp, 32\] -+** ldr q0, \[sp, 48\] -+** ... -+** bl ___addtf3 -+** ... -+*/ -+ -+__attribute__((__noinline__)) -+_Float128 -+foo (int n, ...) -+{ -+ _Float128 a, b; -+ va_list ap; -+ -+ va_start(ap, n); -+ a = va_arg(ap, _Float128); -+ b = va_arg(ap, _Float128); -+ va_end(ap); -+ return a + b; -+} -+ -+/* -+**call_foo: -+** ... -+** str q[0-9]+, \[sp, 16\] -+** ... -+** mov w0, 2 -+** str q[0-9]+, \[sp\] -+** bl _foo -+** ... -+*/ -+ -+__attribute__((__noinline__)) -+_Float128 -+call_foo (void) -+{ -+ return foo (2, (_Float128)1.0, (_Float128)2.0); -+} -+ -+/* What we care about here is that q0 and q1 are loaded from incoming sp and -+ sp+32 (with the int at sp+16). -+**bar: -+** ... -+** ldr w[0-9]+, \[x[0-9]+, 16\] -+** ldr q0, \[x[0-9]+\] -+** ... -+** ldr q1, \[x[0-9]+, 32\] -+** bl ___addtf3 -+** ... -+*/ -+ -+__attribute__((__noinline__)) -+_Float128 -+bar (int n, ...) -+{ -+ _Float128 a, b; -+ va_list ap; -+ -+ va_start(ap, n); -+ a = va_arg(ap, _Float128); -+ n = va_arg(ap, int); -+ if (n != 42) -+ __builtin_abort (); -+ b = va_arg(ap, _Float128); -+ va_end(ap); -+ return a + b; -+} -+ -+/* -+**call_bar: -+** ... -+** str q[0-9]+, \[sp, 32\] -+** ... -+** mov w[0-9]+, 42 -+** str w[0-9]+, \[sp, 16\] -+** mov w0, 2 -+** str q[0-9]+, \[sp\] -+** bl _bar -+** ... -+*/ -+ -+__attribute__((__noinline__)) -+_Float128 -+call_bar (void) -+{ -+ return bar (2, (_Float128)1.0, -+ 42, (_Float128)2.0); -+} -diff --git a/gcc/testsuite/gcc.target/aarch64/darwin/variadic-02.c b/gcc/testsuite/gcc.target/aarch64/darwin/variadic-02.c -new file mode 100644 -index 00000000000..9d796bfc07f ---- /dev/null -+++ b/gcc/testsuite/gcc.target/aarch64/darwin/variadic-02.c -@@ -0,0 +1,104 @@ -+/* { dg-do compile } */ -+ -+/* we need this for __int128. */ -+/* { dg-options "-std=gnu99 " } */ -+/* We use the sections anchors to make the code easier to match. */ -+/* { dg-additional-options " -O2 -fsection-anchors " } */ -+/* { dg-final { check-function-bodies "**" "" "" { target *-*-darwin* } } } */ -+ -+#include -+ -+/* What we care about here is that we load the values from incoming sp and -+ sp + 16. -+**foo: -+** sub sp, sp, #16 -+** ... -+** ldp x[0-9]+, x[0-9]+, \[sp, 16\] -+** ... -+** ldr x[0-9]+, \[sp, 32\] -+** ldr x[0-9]+, \[sp, 40\] -+** ... -+*/ -+ -+__attribute__((__noinline__)) -+__int128 -+foo (int n, ...) -+{ -+ __int128 a, b; -+ va_list ap; -+ -+ va_start(ap, n); -+ a = va_arg(ap, __int128); -+ b = va_arg(ap, __int128); -+ va_end(ap); -+ return a + b; -+} -+ -+/* -+**call_foo: -+** ... -+** stp x[0-9]+, x[0-9]+, \[sp\] -+** mov w0, 2 -+** stp x[0-9]+, x[0-9]+, \[sp, 16\] -+** bl _foo -+** ... -+*/ -+ -+__attribute__((__noinline__)) -+__int128 -+call_foo (void) -+{ -+ return foo (2, (__int128)1, (__int128)2); -+} -+ -+ -+/* sp = one int128, sp+16 = int sp + 32 = other int128 -+**bar: -+** ... -+** sub sp, sp, #16 -+** ... -+** ldp x[0-9]+, x[0-9]+, \[sp, 16\] -+** ... -+** ldr x[0-9]+, \[sp, 48\] -+** ldr x[0-9]+, \[sp, 56\] -+** ... -+*/ -+ -+__attribute__((__noinline__)) -+__int128 -+bar (int n, ...) -+{ -+ __int128 a, b; -+ va_list ap; -+ -+ va_start(ap, n); -+ a = va_arg(ap, __int128); -+ n = va_arg(ap, int); -+ b = va_arg(ap, __int128); -+ va_end(ap); -+ return a + b; -+} -+ -+__attribute__((__noinline__)) -+__int128 -+baro (int n, ...); -+ -+/* -+**call_bar: -+** ... -+** mov w[0-9]+, 42 -+** ... -+** mov w0, 2 -+** stp x[0-9]+, x[0-9]+, \[sp\] -+** str w[0-9]+, \[sp, 16\] -+** stp x[0-9]+, x[0-9]+, \[sp, 32\] -+** bl _baro -+** ... -+*/ -+ -+__attribute__((__noinline__)) -+__int128 -+call_bar (void) -+{ -+ return baro (2, (__int128)1, 42, (__int128)2); -+} -diff --git a/gcc/testsuite/gcc.target/aarch64/dbl_mov_immediate_1.c b/gcc/testsuite/gcc.target/aarch64/dbl_mov_immediate_1.c -index ba6a230457b..cc30dd546f4 100644 ---- a/gcc/testsuite/gcc.target/aarch64/dbl_mov_immediate_1.c -+++ b/gcc/testsuite/gcc.target/aarch64/dbl_mov_immediate_1.c -@@ -41,8 +41,10 @@ double d4(void) - - /* { dg-final { scan-assembler-times "movi\td\[0-9\]+, #?0" 1 } } */ - --/* { dg-final { scan-assembler-times "adrp\tx\[0-9\]+, \.LC\[0-9\]" 2 } } */ --/* { dg-final { scan-assembler-times "ldr\td\[0-9\]+, \\\[x\[0-9\], #:lo12:\.LC\[0-9\]\\\]" 2 } } */ -+/* { dg-final { scan-assembler-times "adrp\tx\[0-9\]+, \.LC\[0-9\]" 2 { target { ! *-*-darwin* } } } } */ -+/* { dg-final { scan-assembler-times "ldr\td\[0-9\]+, \\\[x\[0-9\], #:lo12:\.LC\[0-9\]\\\]" 2 { target { ! *-*-darwin* } } } } */ -+/* { dg-final { scan-assembler-times "adrp\tx\[0-9\]+, lC\[0-9\]@PAGE" 2 { target *-*-darwin* } } } */ -+/* { dg-final { scan-assembler-times "ldr\td\[0-9\]+, \\\[x\[0-9\], #lC\[0-9\]@PAGEOFF\\\]" 2 { target *-*-darwin* } } } */ - - /* { dg-final { scan-assembler-times "fmov\td\[0-9\]+, 1\\\.5e\\\+0" 1 } } */ - -diff --git a/gcc/testsuite/gcc.target/aarch64/dwarf-cfa-reg.c b/gcc/testsuite/gcc.target/aarch64/dwarf-cfa-reg.c -index ae5b3797021..8a691add222 100644 ---- a/gcc/testsuite/gcc.target/aarch64/dwarf-cfa-reg.c -+++ b/gcc/testsuite/gcc.target/aarch64/dwarf-cfa-reg.c -@@ -1,5 +1,6 @@ - /* Verify that CFA register is restored to SP after FP is restored. */ - /* { dg-do compile } */ -+/* { dg-skip-if "no cfi insn support yet" *-*-darwin* } */ - /* { dg-options "-O0 -gdwarf-2" } */ - /* { dg-final { scan-assembler ".cfi_restore 30" } } */ - /* { dg-final { scan-assembler ".cfi_restore 29" } } */ -diff --git a/gcc/testsuite/gcc.target/aarch64/inline-lrint_1.c b/gcc/testsuite/gcc.target/aarch64/inline-lrint_1.c -index 478875ff874..9a2b2e44893 100644 ---- a/gcc/testsuite/gcc.target/aarch64/inline-lrint_1.c -+++ b/gcc/testsuite/gcc.target/aarch64/inline-lrint_1.c -@@ -15,4 +15,4 @@ TEST (fllf, float , long long, l) - - /* { dg-final { scan-assembler-times "frintx\t\[d,s\]\[0-9\]+, \[d,s\]\[0-9\]+" 6 } } */ - /* { dg-final { scan-assembler-times "fcvtzs\tx\[0-9\]+, \[d,s\]\[0-9\]+" 6 } } */ --/* { dg-final { scan-assembler-not "bl" } } */ -+/* { dg-final { scan-assembler-not "bl\t" } } */ -diff --git a/gcc/testsuite/gcc.target/aarch64/ldp_stp_13.c b/gcc/testsuite/gcc.target/aarch64/ldp_stp_13.c -index 9cc3942f153..52c90a92114 100644 ---- a/gcc/testsuite/gcc.target/aarch64/ldp_stp_13.c -+++ b/gcc/testsuite/gcc.target/aarch64/ldp_stp_13.c -@@ -1,4 +1,5 @@ - /* { dg-do compile } */ -+/* { dg-require-effective-target arm_mabi_ilp32 } */ - /* { dg-options "-O2 -mabi=ilp32" } */ - - long long -diff --git a/gcc/testsuite/gcc.target/aarch64/memset-corner-cases-2.c b/gcc/testsuite/gcc.target/aarch64/memset-corner-cases-2.c -index 9ee96f33255..dec73f98506 100644 ---- a/gcc/testsuite/gcc.target/aarch64/memset-corner-cases-2.c -+++ b/gcc/testsuite/gcc.target/aarch64/memset-corner-cases-2.c -@@ -7,7 +7,7 @@ - /* 127 bytes should use libcall for size. - **set127byte: - ** mov x2, 127 --** b memset -+** b _?memset - */ - void __attribute__((__noinline__)) - set127byte (int64_t *src, int c) -@@ -18,7 +18,7 @@ set127byte (int64_t *src, int c) - /* 128 bytes should use libcall for size. - **set128byte: - ** mov x2, 128 --** b memset -+** b _?memset - */ - void __attribute__((__noinline__)) - set128byte (int64_t *src, int c) -diff --git a/gcc/testsuite/gcc.target/aarch64/memset-corner-cases.c b/gcc/testsuite/gcc.target/aarch64/memset-corner-cases.c -index c43f0199adc..733a11e585a 100644 ---- a/gcc/testsuite/gcc.target/aarch64/memset-corner-cases.c -+++ b/gcc/testsuite/gcc.target/aarch64/memset-corner-cases.c -@@ -77,7 +77,7 @@ set256byte (int64_t *src, char c) - **set257byte: - ** mov x2, 257 - ** mov w1, 99 --** b memset -+** b _?memset - */ - void __attribute__((__noinline__)) - set257byte (int64_t *src) -diff --git a/gcc/testsuite/gcc.target/aarch64/no-inline-lrint_1.c b/gcc/testsuite/gcc.target/aarch64/no-inline-lrint_1.c -index d5e9200562c..7f504ad687f 100644 ---- a/gcc/testsuite/gcc.target/aarch64/no-inline-lrint_1.c -+++ b/gcc/testsuite/gcc.target/aarch64/no-inline-lrint_1.c -@@ -14,6 +14,6 @@ TEST (dlld, double, long long, l) - TEST (fllf, float , long long, l) - - /* { dg-final { scan-assembler-times "frintx\t\[d,s\]\[0-9\]+, \[d,s\]\[0-9\]+" 6 } } */ --/* { dg-final { scan-assembler-times "bl\tlrint" 4 } } */ --/* { dg-final { scan-assembler-times "bl\tllrint" 2 } } */ -+/* { dg-final { scan-assembler-times "bl\t_*lrint" 4 } } */ -+/* { dg-final { scan-assembler-times "bl\t_*llrint" 2 } } */ - /* { dg-final { scan-assembler-not "fcvtzs" } } */ -diff --git a/gcc/testsuite/gcc.target/aarch64/pr100518.c b/gcc/testsuite/gcc.target/aarch64/pr100518.c -index 5ca599f5d2e..4e7d6bc7d90 100644 ---- a/gcc/testsuite/gcc.target/aarch64/pr100518.c -+++ b/gcc/testsuite/gcc.target/aarch64/pr100518.c -@@ -1,4 +1,5 @@ - /* { dg-do compile } */ -+/* { dg-require-effective-target arm_mabi_ilp32 } */ - /* { dg-options "-mabi=ilp32 -mstrict-align -O2" } */ - - int unsigned_range_min, unsigned_range_max, a11___trans_tmp_1; -diff --git a/gcc/testsuite/gcc.target/aarch64/pr62308.c b/gcc/testsuite/gcc.target/aarch64/pr62308.c -index 1cf6e212dca..4c1a733e84d 100644 ---- a/gcc/testsuite/gcc.target/aarch64/pr62308.c -+++ b/gcc/testsuite/gcc.target/aarch64/pr62308.c -@@ -1,4 +1,5 @@ - /* { dg-do compile } */ -+/* { dg-skip-if "Darwin platforms do not support big-endian arm64" *-*-darwin* } */ - /* { dg-options "-mbig-endian" } */ - - typedef int __attribute__((vector_size(16))) v4si; -diff --git a/gcc/testsuite/gcc.target/aarch64/pr78255.c b/gcc/testsuite/gcc.target/aarch64/pr78255.c -index b078cf3e1c1..fc5d859ee68 100644 ---- a/gcc/testsuite/gcc.target/aarch64/pr78255.c -+++ b/gcc/testsuite/gcc.target/aarch64/pr78255.c -@@ -1,4 +1,5 @@ - /* { dg-do compile } */ -+/* { dg-skip-if "Darwin platforms do not support tiny" *-*-darwin* } */ - /* { dg-options "-O2 -mcmodel=tiny" } */ - - extern int bar (void *); -diff --git a/gcc/testsuite/gcc.target/aarch64/pr78561.c b/gcc/testsuite/gcc.target/aarch64/pr78561.c -index 048d2d7969f..635214edde1 100644 ---- a/gcc/testsuite/gcc.target/aarch64/pr78561.c -+++ b/gcc/testsuite/gcc.target/aarch64/pr78561.c -@@ -1,4 +1,5 @@ - /* { dg-do compile } */ -+/* { dg-skip-if "Darwin platforms do not support tiny" *-*-darwin* } */ - /* { dg-options "-Og -O3 -mcmodel=tiny" } */ - - int -diff --git a/gcc/testsuite/gcc.target/aarch64/pr80295.c b/gcc/testsuite/gcc.target/aarch64/pr80295.c -index b3866d8d6a9..7a7f127b65f 100644 ---- a/gcc/testsuite/gcc.target/aarch64/pr80295.c -+++ b/gcc/testsuite/gcc.target/aarch64/pr80295.c -@@ -1,4 +1,5 @@ - /* { dg-do compile } */ -+/* { dg-require-effective-target arm_mabi_ilp32 } */ - /* { dg-options "-mabi=ilp32" } */ - - void f (void *b) -diff --git a/gcc/testsuite/gcc.target/aarch64/pr87305.c b/gcc/testsuite/gcc.target/aarch64/pr87305.c -index 8beaa9176e0..c3f98e8eaec 100644 ---- a/gcc/testsuite/gcc.target/aarch64/pr87305.c -+++ b/gcc/testsuite/gcc.target/aarch64/pr87305.c -@@ -1,4 +1,5 @@ - /* { dg-do compile } */ -+/* { dg-skip-if "Darwin platforms do not support big-endian arm64" *-*-darwin* } */ - /* { dg-options "-Ofast -mbig-endian -w" } */ - - int cc; -diff --git a/gcc/testsuite/gcc.target/aarch64/pr92424-1.c b/gcc/testsuite/gcc.target/aarch64/pr92424-1.c -index c413a2c306e..59f7435dc83 100644 ---- a/gcc/testsuite/gcc.target/aarch64/pr92424-1.c -+++ b/gcc/testsuite/gcc.target/aarch64/pr92424-1.c -@@ -1,6 +1,7 @@ - /* { dg-do "compile" } */ - /* { dg-options "-O1" } */ - /* { dg-final { check-function-bodies "**" "" } } */ -+/* { dg-skip-if "unimplemented patchable function entry" *-*-darwin* } */ - - /* Note: this test only checks the instructions in the function bodies, - not the placement of the patch label or nops before the futncion. */ -diff --git a/gcc/testsuite/gcc.target/aarch64/pr94201.c b/gcc/testsuite/gcc.target/aarch64/pr94201.c -index 69176169186..051c742e98e 100644 ---- a/gcc/testsuite/gcc.target/aarch64/pr94201.c -+++ b/gcc/testsuite/gcc.target/aarch64/pr94201.c -@@ -1,4 +1,5 @@ - /* { dg-do compile } */ -+/* { dg-require-effective-target arm_mabi_ilp32 } */ - /* { dg-options "-mcmodel=tiny -mabi=ilp32 -fPIC" } */ - - extern int bar (void *); -diff --git a/gcc/testsuite/gcc.target/aarch64/pr94577.c b/gcc/testsuite/gcc.target/aarch64/pr94577.c -index 6f2d3612c26..6a52e52dc39 100644 ---- a/gcc/testsuite/gcc.target/aarch64/pr94577.c -+++ b/gcc/testsuite/gcc.target/aarch64/pr94577.c -@@ -1,4 +1,5 @@ - /* { dg-do compile } */ -+/* { dg-require-effective-target arm_mabi_ilp32 } */ - /* { dg-options "-mcmodel=large -mabi=ilp32" } */ - - void -diff --git a/gcc/testsuite/gcc.target/aarch64/pr97535.c b/gcc/testsuite/gcc.target/aarch64/pr97535.c -index 7d4db485f1f..6f1ee8035eb 100644 ---- a/gcc/testsuite/gcc.target/aarch64/pr97535.c -+++ b/gcc/testsuite/gcc.target/aarch64/pr97535.c -@@ -13,4 +13,4 @@ void setRaw(const void *raw) - - /* At any optimization level this should be a function call - and not inlined. */ --/* { dg-final { scan-assembler "bl\tmemcpy" } } */ -+/* { dg-final { scan-assembler "bl\t_*memcpy" } } */ -diff --git a/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute-2.c b/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute-2.c -index 8eec6824f37..193c65717ed 100644 ---- a/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute-2.c -+++ b/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute-2.c -@@ -1,5 +1,6 @@ - /* { dg-do compile } */ - /* { dg-options "-Ofast" } */ -+/* { dg-skip-if "no system variant_pcs support" *-*-darwin* } */ - - __attribute__ ((__simd__ ("notinbranch"))) - __attribute__ ((__nothrow__ , __leaf__ , __const__)) -@@ -12,5 +13,5 @@ void bar(double * f, int n) - f[i] = foo(f[i]); - } - --/* { dg-final { scan-assembler-not {\.variant_pcs\tfoo} } } */ --/* { dg-final { scan-assembler-times {\.variant_pcs\t_ZGVnN2v_foo} 1 } } */ -+/* { dg-final { scan-assembler-not {\.variant_pcs\t_?foo} } } */ -+/* { dg-final { scan-assembler-times {\.variant_pcs\t_?_ZGVnN2v_foo} 1 } } */ -diff --git a/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute-3.c b/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute-3.c -index 95f6a6803e8..6fd57735b3a 100644 ---- a/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute-3.c -+++ b/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute-3.c -@@ -1,5 +1,6 @@ - /* { dg-do compile } */ - /* { dg-options "-Ofast" } */ -+/* { dg-skip-if "no system variant_pcs support" *-*-darwin* } */ - - __attribute__ ((__simd__)) - __attribute__ ((__nothrow__ , __leaf__ , __const__)) -@@ -17,8 +18,8 @@ double foo(double x) - return x * x / 3.0; - } - --/* { dg-final { scan-assembler-not {\.variant_pcs\tfoo} } } */ --/* { dg-final { scan-assembler-times {\.variant_pcs\t_ZGVnM1v_foo} 1 } } */ --/* { dg-final { scan-assembler-times {\.variant_pcs\t_ZGVnM2v_foo} 1 } } */ --/* { dg-final { scan-assembler-times {\.variant_pcs\t_ZGVnN1v_foo} 1 } } */ --/* { dg-final { scan-assembler-times {\.variant_pcs\t_ZGVnN2v_foo} 1 } } */ -+/* { dg-final { scan-assembler-not {\.variant_pcs\t_?foo} } } */ -+/* { dg-final { scan-assembler-times {\.variant_pcs\t_?_ZGVnM1v_foo} 1 } } */ -+/* { dg-final { scan-assembler-times {\.variant_pcs\t_?_ZGVnM2v_foo} 1 } } */ -+/* { dg-final { scan-assembler-times {\.variant_pcs\t_?_ZGVnN1v_foo} 1 } } */ -+/* { dg-final { scan-assembler-times {\.variant_pcs\t_?_ZGVnN2v_foo} 1 } } */ -diff --git a/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute.c b/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute.c -index eddcef3597c..62ee482a892 100644 ---- a/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute.c -+++ b/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute.c -@@ -1,5 +1,6 @@ - /* { dg-do compile } */ - /* { dg-options "-Ofast" } */ -+/* { dg-skip-if "no system variant_pcs support" *-*-darwin* } */ - - __attribute__ ((__simd__ ("notinbranch"))) - __attribute__ ((__nothrow__ , __leaf__ , __const__)) -@@ -12,5 +13,5 @@ void foo(double *f, int n) - f[i] = log(f[i]); - } - --/* { dg-final { scan-assembler-not {\.variant_pcs\tlog} } } */ --/* { dg-final { scan-assembler-times {\.variant_pcs\t_ZGVnN2v_log} 1 } } */ -+/* { dg-final { scan-assembler-not {\.variant_pcs\t_?log} } } */ -+/* { dg-final { scan-assembler-times {\.variant_pcs\t_?_ZGVnN2v_log} 1 } } */ -diff --git a/gcc/testsuite/gcc.target/aarch64/stack-check-cfa-1.c b/gcc/testsuite/gcc.target/aarch64/stack-check-cfa-1.c -index 6885894a97e..ebba23c9d02 100644 ---- a/gcc/testsuite/gcc.target/aarch64/stack-check-cfa-1.c -+++ b/gcc/testsuite/gcc.target/aarch64/stack-check-cfa-1.c -@@ -1,6 +1,7 @@ - /* { dg-do compile } */ - /* { dg-options "-O2 -fstack-clash-protection --param stack-clash-protection-guard-size=16 -funwind-tables" } */ - /* { dg-require-effective-target supports_stack_clash_protection } */ -+/* { dg-skip-if "no cfi insn support yet" *-*-darwin* } */ - - #define SIZE 128*1024 - #include "stack-check-prologue.h" -diff --git a/gcc/testsuite/gcc.target/aarch64/stack-check-cfa-2.c b/gcc/testsuite/gcc.target/aarch64/stack-check-cfa-2.c -index 5796a53be06..e15fbd6196c 100644 ---- a/gcc/testsuite/gcc.target/aarch64/stack-check-cfa-2.c -+++ b/gcc/testsuite/gcc.target/aarch64/stack-check-cfa-2.c -@@ -1,6 +1,7 @@ - /* { dg-do compile } */ - /* { dg-options "-O2 -fstack-clash-protection --param stack-clash-protection-guard-size=16 -funwind-tables" } */ - /* { dg-require-effective-target supports_stack_clash_protection } */ -+/* { dg-skip-if "no cfi insn support yet" *-*-darwin* } */ - - #define SIZE 1280*1024 + 512 - #include "stack-check-prologue.h" -diff --git a/gcc/testsuite/gcc.target/aarch64/stack-check-cfa-3.c b/gcc/testsuite/gcc.target/aarch64/stack-check-cfa-3.c -index c4b7bb601c4..ccaf2e6f8cf 100644 ---- a/gcc/testsuite/gcc.target/aarch64/stack-check-cfa-3.c -+++ b/gcc/testsuite/gcc.target/aarch64/stack-check-cfa-3.c -@@ -1,6 +1,7 @@ - /* { dg-do compile } */ - /* { dg-options "-O3 -fopenmp-simd -march=armv8-a+sve -fstack-clash-protection --param stack-clash-protection-guard-size=16 -funwind-tables" } */ - /* { dg-require-effective-target supports_stack_clash_protection } */ -+/* { dg-skip-if "no cfi insn support yet" *-*-darwin* } */ - - #include "stack-check-prologue-16.c" - -diff --git a/gcc/testsuite/gcc.target/aarch64/sve/aarch64-sve.exp b/gcc/testsuite/gcc.target/aarch64/sve/aarch64-sve.exp -index 71dd6687c6b..7a62814edbb 100644 ---- a/gcc/testsuite/gcc.target/aarch64/sve/aarch64-sve.exp -+++ b/gcc/testsuite/gcc.target/aarch64/sve/aarch64-sve.exp -@@ -25,6 +25,11 @@ if {![istarget aarch64*-*-*] } then { - return - } - -+# Darwin doesn't support sve -+if { [istarget *-*-darwin*] } then { -+ return -+} -+ - # Load support procs. - load_lib gcc-dg.exp - -diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/aarch64-sve-acle-asm.exp b/gcc/testsuite/gcc.target/aarch64/sve/acle/aarch64-sve-acle-asm.exp -index a271f1793f4..2da5720d1f3 100644 ---- a/gcc/testsuite/gcc.target/aarch64/sve/acle/aarch64-sve-acle-asm.exp -+++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/aarch64-sve-acle-asm.exp -@@ -24,6 +24,11 @@ if {![istarget aarch64*-*-*] } { - return - } - -+# Darwin doesn't support sve -+if { [istarget *-*-darwin*] } then { -+ return -+} -+ - # Load support procs. - load_lib gcc-dg.exp - -diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/aarch64-sve-acle.exp b/gcc/testsuite/gcc.target/aarch64/sve/acle/aarch64-sve-acle.exp -index ce71c9c1fd4..c7bd136f202 100644 ---- a/gcc/testsuite/gcc.target/aarch64/sve/acle/aarch64-sve-acle.exp -+++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/aarch64-sve-acle.exp -@@ -25,6 +25,11 @@ if {![istarget aarch64*-*-*] } { - return - } - -+# Darwin doesn't support sve -+if { [istarget *-*-darwin*] } then { -+ return -+} -+ - # Load support procs. - load_lib gcc-dg.exp - -diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pcs/aarch64-sve-pcs.exp b/gcc/testsuite/gcc.target/aarch64/sve/pcs/aarch64-sve-pcs.exp -index 83786733f35..9ab68902def 100644 ---- a/gcc/testsuite/gcc.target/aarch64/sve/pcs/aarch64-sve-pcs.exp -+++ b/gcc/testsuite/gcc.target/aarch64/sve/pcs/aarch64-sve-pcs.exp -@@ -25,6 +25,10 @@ if {![istarget aarch64*-*-*] } then { - return - } - -+if { [istarget *-*-darwin*] } then { -+ return -+} -+ - # Load support procs. - load_lib gcc-dg.exp - -diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/aarch64-sve2.exp b/gcc/testsuite/gcc.target/aarch64/sve2/aarch64-sve2.exp -index 60652dbf8fb..010e32132cb 100644 ---- a/gcc/testsuite/gcc.target/aarch64/sve2/aarch64-sve2.exp -+++ b/gcc/testsuite/gcc.target/aarch64/sve2/aarch64-sve2.exp -@@ -25,6 +25,11 @@ if {![istarget aarch64*-*-*] } then { - return - } - -+# Darwin doesn't support sve -+if { [istarget *-*-darwin*] } then { -+ return -+} -+ - # Load support procs. - load_lib gcc-dg.exp - -diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/acle/aarch64-sve2-acle-asm.exp b/gcc/testsuite/gcc.target/aarch64/sve2/acle/aarch64-sve2-acle-asm.exp -index e08cd612190..a7e5f364770 100644 ---- a/gcc/testsuite/gcc.target/aarch64/sve2/acle/aarch64-sve2-acle-asm.exp -+++ b/gcc/testsuite/gcc.target/aarch64/sve2/acle/aarch64-sve2-acle-asm.exp -@@ -24,6 +24,11 @@ if {![istarget aarch64*-*-*] } { - return - } - -+# Darwin doesn't support sve -+if { [istarget *-*-darwin*] } then { -+ return -+} -+ - # Load support procs. - load_lib gcc-dg.exp - -diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/acle/aarch64-sve2-acle.exp b/gcc/testsuite/gcc.target/aarch64/sve2/acle/aarch64-sve2-acle.exp -index f0255967c9d..82092e337f6 100644 ---- a/gcc/testsuite/gcc.target/aarch64/sve2/acle/aarch64-sve2-acle.exp -+++ b/gcc/testsuite/gcc.target/aarch64/sve2/acle/aarch64-sve2-acle.exp -@@ -25,6 +25,11 @@ if {![istarget aarch64*-*-*] } { - return - } - -+# Darwin doesn't support sve -+if { [istarget *-*-darwin*] } then { -+ return -+} -+ - # Load support procs. - load_lib gcc-dg.exp - -diff --git a/gcc/testsuite/gcc.target/aarch64/symbol-range-tiny.c b/gcc/testsuite/gcc.target/aarch64/symbol-range-tiny.c -index fc6a4f3ec78..2d9e94bc625 100644 ---- a/gcc/testsuite/gcc.target/aarch64/symbol-range-tiny.c -+++ b/gcc/testsuite/gcc.target/aarch64/symbol-range-tiny.c -@@ -1,4 +1,5 @@ - /* { dg-do link } */ -+/* { dg-skip-if "no mcmodel tiny" *-*-darwin* } */ - /* { dg-options "-O3 -save-temps -mcmodel=tiny" } */ - - char fixed_regs[0x00080000]; -diff --git a/gcc/testsuite/gcc.target/aarch64/uaddw-3.c b/gcc/testsuite/gcc.target/aarch64/uaddw-3.c -index 39cbd6b6cc2..b4ed187bd2c 100644 ---- a/gcc/testsuite/gcc.target/aarch64/uaddw-3.c -+++ b/gcc/testsuite/gcc.target/aarch64/uaddw-3.c -@@ -1,10 +1,11 @@ - /* { dg-do compile } */ - /* { dg-options "-O3" } */ -+/* { dg-additional-options "-fno-signed-char" { target *-*-darwin* } } */ - - #pragma GCC target "+nosve" - - int --t6(int len, void * dummy, char * __restrict x) -+t6(int len, void * dummy, unsigned char * __restrict x) - { - len = len & ~31; - unsigned short result = 0; -diff --git a/gcc/testsuite/gcc.target/aarch64/vect-cse-codegen.c b/gcc/testsuite/gcc.target/aarch64/vect-cse-codegen.c -index d025e989a1e..f218504c719 100644 ---- a/gcc/testsuite/gcc.target/aarch64/vect-cse-codegen.c -+++ b/gcc/testsuite/gcc.target/aarch64/vect-cse-codegen.c -@@ -6,8 +6,8 @@ - - /* - **test1: --** adrp x[0-9]+, .LC[0-9]+ --** ldr q[0-9]+, \[x[0-9]+, #:lo12:.LC[0-9]+\] -+** adrp x[0-9]+, (.LC[0-9]+|lC[0-9]+@PAGE) -+** ldr q[0-9]+, \[x[0-9]+, #(:lo12:.LC[0-9]+|lC[0-9]+@PAGEOFF)\] - ** add v[0-9]+.2d, v[0-9]+.2d, v[0-9]+.2d - ** str q[0-9]+, \[x[0-9]+\] - ** fmov x[0-9]+, d[0-9]+ -@@ -27,13 +27,14 @@ test1 (uint64_t a, uint64x2_t b, uint64x2_t* rt) - - /* - **test2: --** adrp x[0-9]+, .LC[0-1]+ --** ldr q[0-9]+, \[x[0-9]+, #:lo12:.LC[0-9]+\] -+** adrp x[0-9]+, (.LC[0-1]+|lC[0-1]+@PAGE) -+** ldr q[0-9]+, \[x[0-9]+, #(:lo12:.LC[0-9]+|lC[0-9]+@PAGEOFF)\] - ** add v[0-9]+.2d, v[0-9]+.2d, v[0-9]+.2d - ** str q[0-9]+, \[x[0-9]+\] - ** fmov x[0-9]+, d[0-9]+ - ** orr x[0-9]+, x[0-9]+, x[0-9]+ - ** ret -+ - */ - - uint64_t -@@ -48,8 +49,8 @@ test2 (uint64_t a, uint64x2_t b, uint64x2_t* rt) - - /* - **test3: --** adrp x[0-9]+, .LC[0-9]+ --** ldr q[0-9]+, \[x[0-9]+, #:lo12:.LC[0-9]+\] -+** adrp x[0-9]+, (.LC[0-9]+|lC[0-9]+@PAGE) -+** ldr q[0-9]+, \[x[0-9]+, #(:lo12:.LC[0-9]+|lC[0-9]+@PAGEOFF)\] - ** add v[0-9]+.4s, v[0-9]+.4s, v[0-9]+.4s - ** str q[0-9]+, \[x1\] - ** fmov w[0-9]+, s[0-9]+ -diff --git a/gcc/testsuite/gfortran.dg/coarray/caf.exp b/gcc/testsuite/gfortran.dg/coarray/caf.exp -index 8683a2ab435..e76cb69dcd9 100644 ---- a/gcc/testsuite/gfortran.dg/coarray/caf.exp -+++ b/gcc/testsuite/gfortran.dg/coarray/caf.exp -@@ -28,6 +28,7 @@ - - # Load procedures from common libraries. - load_lib gfortran-dg.exp -+load_lib atomic-dg.exp - - # If a testcase doesn't have special options, use these. - global DEFAULT_FFLAGS -@@ -47,6 +48,7 @@ global gfortran_test_path - global gfortran_aux_module_flags - set gfortran_test_path $srcdir/$subdir - set gfortran_aux_module_flags $DEFAULT_FFLAGS -+ - proc dg-compile-aux-modules { args } { - global gfortran_test_path - global gfortran_aux_module_flags -@@ -69,9 +71,21 @@ proc dg-compile-aux-modules { args } { - } - - # Add -latomic only where supported. Assume built-in support elsewhere. --set maybe_atomic_lib "" - if [check_effective_target_libatomic_available] { -- set maybe_atomic_lib "-latomic" -+ #set maybe_atomic_lib "-latomic" -+ if ![is_remote host] { -+ if [info exists TOOL_OPTIONS] { -+ set maybe_atomic_lib "[atomic_link_flags [get_multilibs ${TOOL_OPTIONS}]]" -+ } else { -+ set maybe_atomic_lib "[atomic_link_flags [get_multilibs]]" -+ } -+ } else { -+ set maybe_atomic_lib "" -+ } -+ set t [get_multilibs] -+ puts "maybe al $maybe_atomic_lib ml $t" -+} else { -+ set maybe_atomic_lib "" - } - - # Main loop. -diff --git a/gcc/testsuite/gfortran.dg/dg.exp b/gcc/testsuite/gfortran.dg/dg.exp -index bd7ad95ad0d..36fc2972b2e 100644 ---- a/gcc/testsuite/gfortran.dg/dg.exp -+++ b/gcc/testsuite/gfortran.dg/dg.exp -@@ -18,6 +18,7 @@ - - # Load support procs. - load_lib gfortran-dg.exp -+load_lib atomic-dg.exp - - # If a testcase doesn't have special options, use these. - global DEFAULT_FFLAGS -@@ -53,12 +54,30 @@ proc dg-compile-aux-modules { args } { - } - } - -+# coarray tests might need libatomic. Assume that it is either not needed or -+# provided by builtins if it's not available. -+if [check_effective_target_libatomic_available] { -+ if ![is_remote host] { -+ if [info exists TOOL_OPTIONS] { -+ set maybe_atomic_lib "[atomic_link_flags [get_multilibs ${TOOL_OPTIONS}]]" -+ } else { -+ set maybe_atomic_lib "[atomic_link_flags [get_multilibs]]" -+ } -+ } else { -+ set maybe_atomic_lib "" -+ } -+ set t [get_multilibs] -+ puts "dg set al $maybe_atomic_lib ml $t" -+} -+ -+puts "DEFAULT_FFLAGS $DEFAULT_FFLAGS" -+ - # Main loop. - gfortran-dg-runtest [lsort \ -- [glob -nocomplain $srcdir/$subdir/*.\[fF\]{,90,95,03,08} ] ] "" $DEFAULT_FFLAGS -+ [glob -nocomplain $srcdir/$subdir/*.\[fF\]{,90,95,03,08} ] ] $maybe_atomic_lib $DEFAULT_FFLAGS - - gfortran-dg-runtest [lsort \ -- [glob -nocomplain $srcdir/$subdir/g77/*.\[fF\] ] ] "" $DEFAULT_FFLAGS -+ [glob -nocomplain $srcdir/$subdir/g77/*.\[fF\] ] ] $maybe_atomic_lib $DEFAULT_FFLAGS - - - # All done. -diff --git a/gcc/testsuite/gfortran.dg/pr95690.f90 b/gcc/testsuite/gfortran.dg/pr95690.f90 -index 47a5df9e894..1afa9d3c467 100644 ---- a/gcc/testsuite/gfortran.dg/pr95690.f90 -+++ b/gcc/testsuite/gfortran.dg/pr95690.f90 -@@ -2,8 +2,8 @@ - module m - contains - subroutine s -- print *, (erfc) ! { dg-error "not a floating constant" "" { target i?86-*-* x86_64-*-* sparc*-*-* cris-*-* } } -- end ! { dg-error "not a floating constant" "" { target { ! "i?86-*-* x86_64-*-* sparc*-*-* cris-*-*" } } } -+ print *, (erfc) ! { dg-error "not a floating constant" "" { target i?86-*-* x86_64-*-* sparc*-*-* cris-*-* aarch64-apple-darwin* } } -+ end ! { dg-error "not a floating constant" "" { target { ! "i?86-*-* x86_64-*-* sparc*-*-* cris-*-* aarch64-apple-darwin*" } } } - function erfc() - end - end -diff --git a/gcc/testsuite/lib/asan-dg.exp b/gcc/testsuite/lib/asan-dg.exp -index 7e0f85dc9b0..88c6ece8caa 100644 ---- a/gcc/testsuite/lib/asan-dg.exp -+++ b/gcc/testsuite/lib/asan-dg.exp -@@ -78,7 +78,7 @@ proc asan_link_flags_1 { paths lib } { - || [file exists "${gccpath}/libsanitizer/${lib}/.libs/lib${lib}.${shlib_ext}"] } { - append flags " -B${gccpath}/libsanitizer/ " - append flags " -B${gccpath}/libsanitizer/${lib}/ " -- append flags " -L${gccpath}/libsanitizer/${lib}/.libs " -+ append flags " -B${gccpath}/libsanitizer/${lib}/.libs " - append ld_library_path ":${gccpath}/libsanitizer/${lib}/.libs" - } - } else { -diff --git a/gcc/testsuite/lib/atomic-dg.exp b/gcc/testsuite/lib/atomic-dg.exp -index 86dcfa674ea..c9244fb6cac 100644 ---- a/gcc/testsuite/lib/atomic-dg.exp -+++ b/gcc/testsuite/lib/atomic-dg.exp -@@ -33,7 +33,7 @@ proc atomic_link_flags { paths } { - if { [file exists "${gccpath}/libatomic/.libs/libatomic.a"] - || [file exists "${gccpath}/libatomic/.libs/libatomic.${shlib_ext}"] } { - append flags " -B${gccpath}/libatomic/ " -- append flags " -L${gccpath}/libatomic/.libs" -+ append flags " -B${gccpath}/libatomic/.libs" - append ld_library_path ":${gccpath}/libatomic/.libs" - } - } else { -diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp -index a80630bb2a8..195611f1f72 100644 ---- a/gcc/testsuite/lib/scanasm.exp -+++ b/gcc/testsuite/lib/scanasm.exp -@@ -763,7 +763,7 @@ proc scan-lto-assembler { args } { - # to function bodies in array RESULT. FILENAME has already been uploaded - # locally where necessary and is known to exist. - --proc parse_function_bodies { filename result } { -+proc parse_ELF_function_bodies { filename result } { - upvar $result up_result - - # Regexp for the start of a function definition (name in \1). -@@ -793,6 +793,44 @@ proc parse_function_bodies { filename result } { - close $fd - } - -+proc parse_MACHO_function_bodies { filename result } { -+ upvar $result up_result -+ -+ # Regexp for the start of a function definition (name in \1). -+ set label {^(_[a-zA-Z_]\S+):$} -+ set start {^LFB[0-9]+} -+ -+ # Regexp for the end of a function definition. -+ set terminator {^LFE[0-9]+} -+ -+ # Regexp for lines that aren't interesting. -+ set fluff {^\s*(?:\.|//|@)} -+ set fluff3 {^L[0-9ACESV]} -+ -+ set fd [open $filename r] -+ set in_function 0 -+ while { [gets $fd line] >= 0 } { -+ if { !$in_function && [regexp $label $line dummy function_name] } { -+ set in_function 1 -+ set function_body "" -+ } elseif { $in_function == 1 } { -+ if { [regexp $start $line] } { -+ set in_function 2 -+ } else { -+ set in_function 0 -+ } -+ } elseif { $in_function == 2 } { -+ if { [regexp $terminator $line] } { -+ set up_result($function_name) $function_body -+ set in_function 0 -+ } elseif { ![regexp $fluff $line] && ![regexp $fluff3 $line] } { -+ append function_body $line "\n" -+ } -+ } -+ } -+ close $fd -+} -+ - # FUNCTIONS is an array that maps function names to function bodies. - # Return true if it contains a definition of function NAME and if - # that definition matches BODY_REGEXP. -@@ -820,6 +858,14 @@ proc check-function-bodies { args } { - error "too many arguments to check-function-bodies" - } - -+ set isELF 1 -+ # some targets have a __USER_LABEL_PREFIX__ -+ set needsULP 0 -+ if { [istarget *-*-darwin*] } { -+ set isELF 0 -+ set needsULP 1 -+ } -+ - if { [llength $args] >= 3 } { - set required_flags [lindex $args 2] - -@@ -876,7 +922,11 @@ proc check-function-bodies { args } { - remote_upload host "$filename" - } - if { [file exists $output_filename] } { -- parse_function_bodies $output_filename functions -+ if { $isELF } { -+ parse_ELF_function_bodies $output_filename functions -+ } else { -+ parse_MACHO_function_bodies $output_filename functions -+ } - set have_bodies 1 - } else { - verbose -log "$testcase: output file does not exist" -@@ -921,6 +971,9 @@ proc check-function-bodies { args } { - if { $xfail_all || [string equal $selector "F"] } { - setup_xfail "*-*-*" - } -+ if { $needsULP } { -+ set function_name "_$function_name" -+ } - set testname "$testcase check-function-bodies $function_name" - if { !$have_bodies } { - unresolved $testname -diff --git a/gcc/testsuite/lib/target-libpath.exp b/gcc/testsuite/lib/target-libpath.exp -index d09cd515d20..280ce390845 100644 ---- a/gcc/testsuite/lib/target-libpath.exp -+++ b/gcc/testsuite/lib/target-libpath.exp -@@ -67,6 +67,7 @@ proc set_ld_library_path_env_vars { } { - global orig_dyld_library_path - global orig_path - global orig_gcc_exec_prefix -+ global ENABLE_DARWIN_AT_RPATH - global env - - # Save the original GCC_EXEC_PREFIX. -@@ -133,6 +134,7 @@ proc set_ld_library_path_env_vars { } { - # - # Doing this is somewhat of a hack as ld_library_path gets repeated in - # SHLIB_PATH and LD_LIBRARY_PATH when unix_load sets these variables. -+ if { ![istarget *-*-darwin*] } { - if { $orig_ld_library_path_saved } { - setenv LD_LIBRARY_PATH "$ld_library_path:$orig_ld_library_path" - } else { -@@ -166,11 +168,23 @@ proc set_ld_library_path_env_vars { } { - } else { - setenv LD_LIBRARY_PATH_64 "$ld_library_path" - } -- if { $orig_dyld_library_path_saved } { -- setenv DYLD_LIBRARY_PATH "$ld_library_path:$orig_dyld_library_path" -- } else { -- setenv DYLD_LIBRARY_PATH "$ld_library_path" - } -+ if { [istarget *-*-darwin*] } { -+ if { [info exists ENABLE_DARWIN_AT_RPATH] || [istarget *-*-darwin1\[5-9\]*] -+ || [istarget *-*-darwin2*] } { -+ # Either we are not using DYLD_LIBRARY_PATH or we're on a version of the -+ # OS for which it is not passed through system exes. -+ if [info exists env(DYLD_LIBRARY_PATH)] { -+ unsetenv DYLD_LIBRARY_PATH -+ } -+ } else { -+ if { $orig_dyld_library_path_saved } { -+ setenv DYLD_LIBRARY_PATH "$ld_library_path:$orig_dyld_library_path" -+ } else { -+ setenv DYLD_LIBRARY_PATH "$ld_library_path" -+ } -+ } -+ } - if { [istarget *-*-cygwin*] || [istarget *-*-mingw*] } { - if { $orig_path_saved } { - setenv PATH "$ld_library_path:$orig_path" -@@ -179,6 +193,7 @@ proc set_ld_library_path_env_vars { } { - } - } - -+ verbose -log "set paths" - verbose -log "LD_LIBRARY_PATH=[getenv LD_LIBRARY_PATH]" - verbose -log "LD_RUN_PATH=[getenv LD_RUN_PATH]" - verbose -log "SHLIB_PATH=[getenv SHLIB_PATH]" -diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp -index 244fe2306f4..75581914d6c 100644 ---- a/gcc/testsuite/lib/target-supports.exp -+++ b/gcc/testsuite/lib/target-supports.exp -@@ -8485,7 +8485,7 @@ proc check_effective_target_section_anchors { } { - return [check_cached_effective_target section_anchors { - expr { [istarget powerpc*-*-*] - || [istarget arm*-*-*] -- || [istarget aarch64*-*-*] }}] -+ || ([istarget aarch64*-*-*] && ![istarget aarch64*-*-darwin*]) }}] - } - - # Return 1 if the target supports atomic operations on "int_128" values. -@@ -11526,6 +11526,15 @@ proc check_effective_target_arm_thumb2_ok_no_arm_v8_1_lob { } { - return 0 - } - -+# Return 1 if this is an ARM target where -mabi=ilp32 can be used. -+ -+proc check_effective_target_arm_mabi_ilp32 { } { -+ return [check_no_compiler_messages_nocache arm_mabi_ilp32 assembly { -+ int main() { return 0; } -+ } "-mabi=ilp32"] -+} -+ -+ - # Returns 1 if the target is using glibc, 0 otherwise. - - proc check_effective_target_glibc { } { -diff --git a/gcc/testsuite/obj-c++.dg/gnu-api-2-class-meta.mm b/gcc/testsuite/obj-c++.dg/gnu-api-2-class-meta.mm -index 92852c3ecea..e0974539ecf 100644 ---- a/gcc/testsuite/obj-c++.dg/gnu-api-2-class-meta.mm -+++ b/gcc/testsuite/obj-c++.dg/gnu-api-2-class-meta.mm -@@ -19,6 +19,7 @@ this behavior may be defined or documented (for example, if class - - /* { dg-do run } */ - /* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */ -+/* { dg-skip-if "API unsupported" { arm64*-*-darwin* aarch64*-*-darwin* } { "-fnext-runtime" } { "" } } */ - /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ - /* { dg-additional-options "-DOBJC_OLD_DISPATCH_PROTOTYPES" { target { *-*-darwin* } } } */ - // { dg-additional-options "-Wno-objc-root-class" } -diff --git a/gcc/testsuite/obj-c++.dg/gnu-api-2-class.mm b/gcc/testsuite/obj-c++.dg/gnu-api-2-class.mm -index f6e3d8d22e0..a23968a89b5 100644 ---- a/gcc/testsuite/obj-c++.dg/gnu-api-2-class.mm -+++ b/gcc/testsuite/obj-c++.dg/gnu-api-2-class.mm -@@ -6,6 +6,7 @@ - - /* { dg-do run } */ - /* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */ -+/* { dg-skip-if "API unsupported" { arm64*-*-darwin* aarch64*-*-darwin* } { "-fnext-runtime" } { "" } } */ - /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ - /* { dg-additional-options "-DOBJC_OLD_DISPATCH_PROTOTYPES" { target { *-*-darwin* } } } */ - // { dg-additional-options "-Wno-objc-root-class" } -diff --git a/gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-4.mm b/gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-4.mm -index 1155db5f83f..e0dd8062373 100644 ---- a/gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-4.mm -+++ b/gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-4.mm -@@ -18,4 +18,4 @@ - - /* { dg-final { scan-assembler ".section __DATA, __cfstring" } } */ - /* { dg-final { scan-assembler ".long\t___CFConstantStringClassReference\n\t.long\t1992\n\t.long\t.*\n\t.long\t19\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\t19\n" { target { *-*-darwin* && { lp64 } } } } } */ -+/* { dg-final { scan-assembler {.(quad|xword)\t___CFConstantStringClassReference\n\t.(long|word)\t1992\n\t.space 4\n\t.(quad|xword)\t.*\n\t.(quad|xword)\t19\n} { target { *-*-darwin* && { lp64 } } } } } */ -diff --git a/gcc/testsuite/obj-c++.dg/torture/strings/const-str-10.mm b/gcc/testsuite/obj-c++.dg/torture/strings/const-str-10.mm -index e1dad124cd6..eb89710d890 100644 ---- a/gcc/testsuite/obj-c++.dg/torture/strings/const-str-10.mm -+++ b/gcc/testsuite/obj-c++.dg/torture/strings/const-str-10.mm -@@ -33,4 +33,4 @@ @interface NSConstantString : NSSimpleCString - /* { dg-final { scan-assembler ".section __OBJC, __cstring_object" { target { *-*-darwin* && { ! lp64 } } } } } */ - /* { dg-final { scan-assembler ".section __DATA, __objc_stringobj" { target { *-*-darwin* && { lp64 } } } } } */ - /* { dg-final { scan-assembler ".long\t__NSConstantStringClassReference\n\t.long\t.*\n\t.long\t5\n\t.data" { target { *-*-darwin* && { ! lp64 } } } } } */ --/* { dg-final { scan-assembler ".quad\t_OBJC_CLASS_._NSConstantString\n\t.quad\t.*\n\t.long\t5\n\t.space" { target { *-*-darwin* && { lp64 } } } } } */ -+/* { dg-final { scan-assembler {.(quad|xword)\t_OBJC_CLASS_._NSConstantString\n\t.(quad|xword)\t.*\n\t.(long|word)\t5\n\t.space} { target { *-*-darwin* && { lp64 } } } } } */ -diff --git a/gcc/testsuite/obj-c++.dg/torture/strings/const-str-11.mm b/gcc/testsuite/obj-c++.dg/torture/strings/const-str-11.mm -index 30a9228a64e..c1b58dc6cb8 100644 ---- a/gcc/testsuite/obj-c++.dg/torture/strings/const-str-11.mm -+++ b/gcc/testsuite/obj-c++.dg/torture/strings/const-str-11.mm -@@ -33,4 +33,4 @@ @interface XStr : XString { - /* { dg-final { scan-assembler ".section __OBJC, __cstring_object" { target { *-*-darwin* && { ! lp64 } } } } } */ - /* { dg-final { scan-assembler ".section __DATA, __objc_stringobj" { target { *-*-darwin* && { lp64 } } } } } */ - /* { dg-final { scan-assembler ".long\t__XStrClassReference\n\t.long\t.*\n\t.long\t5\n\t.data" { target { *-*-darwin* && { ! lp64 } } } } } */ --/* { dg-final { scan-assembler ".quad\t_OBJC_CLASS_._XStr\n\t.quad\t.*\n\t.long\t5\n\t.space" { target { *-*-darwin* && { lp64 } } } } } */ -+/* { dg-final { scan-assembler {.(quad|xword)\t_OBJC_CLASS_._XStr\n\t.(quad|xword)\t.*\n\t.(long|word)\t5\n\t.space} { target { *-*-darwin* && { lp64 } } } } } */ -diff --git a/gcc/testsuite/obj-c++.dg/torture/strings/const-str-9.mm b/gcc/testsuite/obj-c++.dg/torture/strings/const-str-9.mm -index a1a14295e90..8457f46be53 100644 ---- a/gcc/testsuite/obj-c++.dg/torture/strings/const-str-9.mm -+++ b/gcc/testsuite/obj-c++.dg/torture/strings/const-str-9.mm -@@ -25,4 +25,4 @@ @interface NSConstantString: NSObject { - /* { dg-final { scan-assembler ".section __OBJC, __cstring_object" { target { *-*-darwin* && { ! lp64 } } } } } */ - /* { dg-final { scan-assembler ".section __DATA, __objc_stringobj" { target { *-*-darwin* && { lp64 } } } } } */ - /* { dg-final { scan-assembler ".long\t__NSConstantStringClassReference\n\t.long\t.*\n\t.long\t5\n\t.data" { target { *-*-darwin* && { ! lp64 } } } } } */ --/* { dg-final { scan-assembler ".quad\t_OBJC_CLASS_._NSConstantString\n\t.quad\t.*\n\t.long\t5\n\t.space" { target { *-*-darwin* && { lp64 } } } } } */ -+/* { dg-final { scan-assembler {.(quad|xword)\t_OBJC_CLASS_._NSConstantString\n\t.(quad|xword)\t.*\n\t.(long|word)\t5\n\t.space} { target { *-*-darwin* && { lp64 } } } } } */ -diff --git a/gcc/testsuite/objc.dg/gnu-api-2-class-meta.m b/gcc/testsuite/objc.dg/gnu-api-2-class-meta.m -index 6c1c76a87a3..41a48f9c685 100644 ---- a/gcc/testsuite/objc.dg/gnu-api-2-class-meta.m -+++ b/gcc/testsuite/objc.dg/gnu-api-2-class-meta.m -@@ -19,6 +19,7 @@ this behavior may be defined or documented (for example, if class - - /* { dg-do run } */ - /* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */ -+/* { dg-skip-if "API unsupported" { arm64*-*-darwin* aarch64*-*-darwin* } { "-fnext-runtime" } { "" } } */ - /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ - /* { dg-additional-options "-Wno-objc-root-class" } */ - /* { dg-additional-options "-DOBJC_OLD_DISPATCH_PROTOTYPES" { target { *-*-darwin* } } } */ -diff --git a/gcc/testsuite/objc.dg/gnu-api-2-class.m b/gcc/testsuite/objc.dg/gnu-api-2-class.m -index d11dae0e6dc..1386ebc2f99 100644 ---- a/gcc/testsuite/objc.dg/gnu-api-2-class.m -+++ b/gcc/testsuite/objc.dg/gnu-api-2-class.m -@@ -6,6 +6,7 @@ - - /* { dg-do run } */ - /* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */ -+/* { dg-skip-if "API unsupported" { arm64*-*-darwin* aarch64*-*-darwin* } { "-fnext-runtime" } { "" } } */ - /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ - /* { dg-additional-options "-Wno-objc-root-class" } */ - /* { dg-additional-options "-DOBJC_OLD_DISPATCH_PROTOTYPES" { target { *-*-darwin* } } } */ -diff --git a/gcc/testsuite/objc.dg/torture/strings/const-cfstring-4.m b/gcc/testsuite/objc.dg/torture/strings/const-cfstring-4.m -index 1155db5f83f..e0dd8062373 100644 ---- a/gcc/testsuite/objc.dg/torture/strings/const-cfstring-4.m -+++ b/gcc/testsuite/objc.dg/torture/strings/const-cfstring-4.m -@@ -18,4 +18,4 @@ - - /* { dg-final { scan-assembler ".section __DATA, __cfstring" } } */ - /* { dg-final { scan-assembler ".long\t___CFConstantStringClassReference\n\t.long\t1992\n\t.long\t.*\n\t.long\t19\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\t19\n" { target { *-*-darwin* && { lp64 } } } } } */ -+/* { dg-final { scan-assembler {.(quad|xword)\t___CFConstantStringClassReference\n\t.(long|word)\t1992\n\t.space 4\n\t.(quad|xword)\t.*\n\t.(quad|xword)\t19\n} { target { *-*-darwin* && { lp64 } } } } } */ -diff --git a/gcc/testsuite/objc.dg/torture/strings/const-str-10.m b/gcc/testsuite/objc.dg/torture/strings/const-str-10.m -index 6565dc20007..81b0d326c56 100644 ---- a/gcc/testsuite/objc.dg/torture/strings/const-str-10.m -+++ b/gcc/testsuite/objc.dg/torture/strings/const-str-10.m -@@ -34,4 +34,4 @@ @interface NSConstantString : NSSimpleCString - /* { dg-final { scan-assembler ".section __OBJC, __cstring_object" { target { *-*-darwin* && { ! lp64 } } } } } */ - /* { dg-final { scan-assembler ".section __DATA, __objc_stringobj" { target { *-*-darwin* && { lp64 } } } } } */ - /* { dg-final { scan-assembler ".long\t__NSConstantStringClassReference\n\t.long\t.*\n\t.long\t5\n\t.data" { target { *-*-darwin* && { ! lp64 } } } } } */ --/* { dg-final { scan-assembler ".quad\t_OBJC_CLASS_._NSConstantString\n\t.quad\t.*\n\t.long\t5\n\t.space" { target { *-*-darwin* && { lp64 } } } } } */ -+/* { dg-final { scan-assembler {.(quad|xword)\t_OBJC_CLASS_._NSConstantString\n\t.(quad|xword)\t.*\n\t.(long|word)\t5\n\t.space} { target { *-*-darwin* && { lp64 } } } } } */ -diff --git a/gcc/testsuite/objc.dg/torture/strings/const-str-11.m b/gcc/testsuite/objc.dg/torture/strings/const-str-11.m -index 2bdb1531e1d..b044b0fd8c7 100644 ---- a/gcc/testsuite/objc.dg/torture/strings/const-str-11.m -+++ b/gcc/testsuite/objc.dg/torture/strings/const-str-11.m -@@ -33,4 +33,4 @@ @interface XStr : XString { - /* { dg-final { scan-assembler ".section __OBJC, __cstring_object" { target { *-*-darwin* && { ! lp64 } } } } } */ - /* { dg-final { scan-assembler ".section __DATA, __objc_stringobj" { target { *-*-darwin* && { lp64 } } } } } */ - /* { dg-final { scan-assembler ".long\t__XStrClassReference\n\t.long\t.*\n\t.long\t5\n\t.data" { target { *-*-darwin* && { ! lp64 } } } } } */ --/* { dg-final { scan-assembler ".quad\t_OBJC_CLASS_._XStr\n\t.quad\t.*\n\t.long\t5\n\t.space" { target { *-*-darwin* && { lp64 } } } } } */ -+/* { dg-final { scan-assembler {.(quad|xword)\t_OBJC_CLASS_._XStr\n\t.(quad|xword)\t.*\n\t.(long|word)\t5\n\t.space} { target { *-*-darwin* && { lp64 } } } } } */ -diff --git a/gcc/testsuite/objc.dg/torture/strings/const-str-9.m b/gcc/testsuite/objc.dg/torture/strings/const-str-9.m -index 966ea5e498d..d3d2916ed06 100644 ---- a/gcc/testsuite/objc.dg/torture/strings/const-str-9.m -+++ b/gcc/testsuite/objc.dg/torture/strings/const-str-9.m -@@ -25,4 +25,4 @@ @interface NSConstantString: NSObject { - /* { dg-final { scan-assembler ".section __OBJC, __cstring_object" { target { *-*-darwin* && { ! lp64 } } } } } */ - /* { dg-final { scan-assembler ".section __DATA, __objc_stringobj" { target { *-*-darwin* && { lp64 } } } } } */ - /* { dg-final { scan-assembler ".long\t__NSConstantStringClassReference\n\t.long\t.*\n\t.long\t5\n\t.data" { target { *-*-darwin* && { ! lp64 } } } } } */ --/* { dg-final { scan-assembler ".quad\t_OBJC_CLASS_._NSConstantString\n\t.quad\t.*\n\t.long\t5\n\t.space" { target { *-*-darwin* && { lp64 } } } } } */ -+/* { dg-final { scan-assembler {.(quad|xword)\t_OBJC_CLASS_._NSConstantString\n\t.(quad|xword)\t.*\n\t.(long|word)\t5\n\t.space} { target { *-*-darwin* && { lp64 } } } } } */ -diff --git a/gcc/tree-nested.cc b/gcc/tree-nested.cc -index 078ceab3ca3..0308f558036 100644 ---- a/gcc/tree-nested.cc -+++ b/gcc/tree-nested.cc -@@ -611,6 +611,14 @@ get_trampoline_type (struct nesting_info *info) - if (trampoline_type) - return trampoline_type; - -+ /* When trampolines are created off-stack then the only thing we need in the -+ local frame is a single pointer. */ -+ if (flag_off_stack_trampolines) -+ { -+ trampoline_type = build_pointer_type (void_type_node); -+ return trampoline_type; -+ } -+ - align = TRAMPOLINE_ALIGNMENT; - size = TRAMPOLINE_SIZE; - -@@ -2786,17 +2794,27 @@ convert_tramp_reference_op (tree *tp, int *walk_subtrees, void *data) - - /* Compute the address of the field holding the trampoline. */ - x = get_frame_field (info, target_context, x, &wi->gsi); -- x = build_addr (x); -- x = gsi_gimplify_val (info, x, &wi->gsi); - -- /* Do machine-specific ugliness. Normally this will involve -- computing extra alignment, but it can really be anything. */ -- if (descr) -- builtin = builtin_decl_implicit (BUILT_IN_ADJUST_DESCRIPTOR); -+ /* APB: We don't need to do the adjustment calls when using off-stack -+ trampolines, any such adjustment will be done when the off-stack -+ trampoline is created. */ -+ if (!descr && flag_off_stack_trampolines) -+ x = gsi_gimplify_val (info, x, &wi->gsi); - else -- builtin = builtin_decl_implicit (BUILT_IN_ADJUST_TRAMPOLINE); -- call = gimple_build_call (builtin, 1, x); -- x = init_tmp_var_with_call (info, &wi->gsi, call); -+ { -+ x = build_addr (x); -+ -+ x = gsi_gimplify_val (info, x, &wi->gsi); -+ -+ /* Do machine-specific ugliness. Normally this will involve -+ computing extra alignment, but it can really be anything. */ -+ if (descr) -+ builtin = builtin_decl_implicit (BUILT_IN_ADJUST_DESCRIPTOR); -+ else -+ builtin = builtin_decl_implicit (BUILT_IN_ADJUST_TRAMPOLINE); -+ call = gimple_build_call (builtin, 1, x); -+ x = init_tmp_var_with_call (info, &wi->gsi, call); -+ } - - /* Cast back to the proper function type. */ - x = build1 (NOP_EXPR, TREE_TYPE (t), x); -@@ -3375,6 +3393,7 @@ build_init_call_stmt (struct nesting_info *info, tree decl, tree field, - static void - finalize_nesting_tree_1 (struct nesting_info *root) - { -+ gimple_seq cleanup_list = NULL; - gimple_seq stmt_list = NULL; - gimple *stmt; - tree context = root->context; -@@ -3506,9 +3525,48 @@ finalize_nesting_tree_1 (struct nesting_info *root) - if (!field) - continue; - -- x = builtin_decl_implicit (BUILT_IN_INIT_TRAMPOLINE); -- stmt = build_init_call_stmt (root, i->context, field, x); -- gimple_seq_add_stmt (&stmt_list, stmt); -+ if (flag_off_stack_trampolines) -+ { -+ /* We pass a whole bunch of arguments to the builtin function that -+ creates the off-stack trampoline, these are -+ 1. The nested function chain value (that must be passed to the -+ nested function so it can find the function arguments). -+ 2. A pointer to the nested function implementation, -+ 3. The address in the local stack frame where we should write -+ the address of the trampoline. -+ -+ When this code was originally written I just kind of threw -+ everything at the builtin, figuring I'd work out what was -+ actually needed later, I think, the stack pointer could -+ certainly be dropped, arguments #2 and #4 are based off the -+ stack pointer anyway, so #1 doesn't seem to add much value. */ -+ tree arg1, arg2, arg3; -+ -+ gcc_assert (DECL_STATIC_CHAIN (i->context)); -+ arg1 = build_addr (root->frame_decl); -+ arg2 = build_addr (i->context); -+ -+ x = build3 (COMPONENT_REF, TREE_TYPE (field), -+ root->frame_decl, field, NULL_TREE); -+ arg3 = build_addr (x); -+ -+ x = builtin_decl_implicit (BUILT_IN_NESTED_PTR_CREATED); -+ stmt = gimple_build_call (x, 3, arg1, arg2, arg3); -+ gimple_seq_add_stmt (&stmt_list, stmt); -+ -+ /* This call to delete the nested function trampoline is added to -+ the cleanup list, and called when we exit the current scope. */ -+ x = builtin_decl_implicit (BUILT_IN_NESTED_PTR_DELETED); -+ stmt = gimple_build_call (x, 0); -+ gimple_seq_add_stmt (&cleanup_list, stmt); -+ } -+ else -+ { -+ /* Original code to initialise the on stack trampoline. */ -+ x = builtin_decl_implicit (BUILT_IN_INIT_TRAMPOLINE); -+ stmt = build_init_call_stmt (root, i->context, field, x); -+ gimple_seq_add_stmt (&stmt_list, stmt); -+ } - } - } - -@@ -3533,11 +3591,40 @@ finalize_nesting_tree_1 (struct nesting_info *root) - /* If we created initialization statements, insert them. */ - if (stmt_list) - { -- gbind *bind; -- annotate_all_with_location (stmt_list, DECL_SOURCE_LOCATION (context)); -- bind = gimple_seq_first_stmt_as_a_bind (gimple_body (context)); -- gimple_seq_add_seq (&stmt_list, gimple_bind_body (bind)); -- gimple_bind_set_body (bind, stmt_list); -+ if (flag_off_stack_trampolines) -+ { -+ /* Handle the new, off stack trampolines. */ -+ gbind *bind; -+ annotate_all_with_location (stmt_list, DECL_SOURCE_LOCATION (context)); -+ annotate_all_with_location (cleanup_list, DECL_SOURCE_LOCATION (context)); -+ bind = gimple_seq_first_stmt_as_a_bind (gimple_body (context)); -+ gimple_seq_add_seq (&stmt_list, gimple_bind_body (bind)); -+ -+ gimple_seq xxx_list = NULL; -+ -+ if (cleanup_list != NULL) -+ { -+ /* We Maybe shouldn't be creating this try/finally if -fno-exceptions is -+ in use. If this is the case, then maybe we should, instead, be -+ inserting the cleanup code onto every path out of this function? Not -+ yet figured out how we would do this. */ -+ gtry *t = gimple_build_try (stmt_list, cleanup_list, GIMPLE_TRY_FINALLY); -+ gimple_seq_add_stmt (&xxx_list, t); -+ } -+ else -+ xxx_list = stmt_list; -+ -+ gimple_bind_set_body (bind, xxx_list); -+ } -+ else -+ { -+ /* The traditional, on stack trampolines. */ -+ gbind *bind; -+ annotate_all_with_location (stmt_list, DECL_SOURCE_LOCATION (context)); -+ bind = gimple_seq_first_stmt_as_a_bind (gimple_body (context)); -+ gimple_seq_add_seq (&stmt_list, gimple_bind_body (bind)); -+ gimple_bind_set_body (bind, stmt_list); -+ } - } - - /* If a chain_decl was created, then it needs to be registered with -diff --git a/gcc/tree.cc b/gcc/tree.cc -index 4cf3785270b..5cba2ab8171 100644 ---- a/gcc/tree.cc -+++ b/gcc/tree.cc -@@ -9766,6 +9766,23 @@ build_common_builtin_nodes (void) - "__builtin_nonlocal_goto", - ECF_NORETURN | ECF_NOTHROW); - -+ tree ptr_ptr_type_node = build_pointer_type (ptr_type_node); -+ -+ ftype = build_function_type_list (void_type_node, -+ ptr_type_node, // void *chain -+ ptr_type_node, // void *func -+ ptr_ptr_type_node, // void **dst -+ NULL_TREE); -+ local_define_builtin ("__builtin_nested_func_ptr_created", ftype, -+ BUILT_IN_NESTED_PTR_CREATED, -+ "__builtin_nested_func_ptr_created", ECF_NOTHROW); -+ -+ ftype = build_function_type_list (void_type_node, -+ NULL_TREE); -+ local_define_builtin ("__builtin_nested_func_ptr_deleted", ftype, -+ BUILT_IN_NESTED_PTR_DELETED, -+ "__builtin_nested_func_ptr_deleted", ECF_NOTHROW); -+ - ftype = build_function_type_list (void_type_node, - ptr_type_node, ptr_type_node, NULL_TREE); - local_define_builtin ("__builtin_setjmp_setup", ftype, -diff --git a/libada/configure b/libada/configure -index 162d9731f26..9c8b133d817 100755 ---- a/libada/configure -+++ b/libada/configure -@@ -3212,6 +3212,9 @@ case "${host}" in - # sets the default TLS model and affects inlining. - PICFLAG=-fPIC - ;; -+ loongarch*-*-*) -+ PICFLAG=-fpic -+ ;; - mips-sgi-irix6*) - # PIC is the default. - ;; -diff --git a/libatomic/Makefile.am b/libatomic/Makefile.am -index d88515e4a03..3c921f4a86d 100644 ---- a/libatomic/Makefile.am -+++ b/libatomic/Makefile.am -@@ -65,8 +65,13 @@ libatomic_version_script = - libatomic_version_dep = - endif - libatomic_version_info = -version-info $(libtool_VERSION) -+if ENABLE_DARWIN_AT_RPATH -+libatomic_darwin_rpath = -Wc,-nodefaultrpaths -+libatomic_darwin_rpath += -Wl,-rpath,@loader_path -+endif - --libatomic_la_LDFLAGS = $(libatomic_version_info) $(libatomic_version_script) $(lt_host_flags) -+libatomic_la_LDFLAGS = $(libatomic_version_info) $(libatomic_version_script) \ -+ $(lt_host_flags) $(libatomic_darwin_rpath) - libatomic_la_SOURCES = gload.c gstore.c gcas.c gexch.c glfree.c lock.c init.c \ - fenv.c fence.c flag.c - -diff --git a/libatomic/Makefile.in b/libatomic/Makefile.in -index 80d25653dc7..179f9217ad6 100644 ---- a/libatomic/Makefile.in -+++ b/libatomic/Makefile.in -@@ -403,7 +403,12 @@ noinst_LTLIBRARIES = libatomic_convenience.la - @LIBAT_BUILD_VERSIONED_SHLIB_GNU_TRUE@@LIBAT_BUILD_VERSIONED_SHLIB_TRUE@libatomic_version_dep = $(top_srcdir)/libatomic.map - @LIBAT_BUILD_VERSIONED_SHLIB_SUN_TRUE@@LIBAT_BUILD_VERSIONED_SHLIB_TRUE@libatomic_version_dep = libatomic.map-sun - libatomic_version_info = -version-info $(libtool_VERSION) --libatomic_la_LDFLAGS = $(libatomic_version_info) $(libatomic_version_script) $(lt_host_flags) -+@ENABLE_DARWIN_AT_RPATH_TRUE@libatomic_darwin_rpath = \ -+@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ -+@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path -+libatomic_la_LDFLAGS = $(libatomic_version_info) $(libatomic_version_script) \ -+ $(lt_host_flags) $(libatomic_darwin_rpath) -+ - libatomic_la_SOURCES = gload.c gstore.c gcas.c gexch.c glfree.c lock.c init.c \ - fenv.c fence.c flag.c - -diff --git a/libatomic/configure b/libatomic/configure -index 92853dd8a45..935d5559aed 100755 ---- a/libatomic/configure -+++ b/libatomic/configure -@@ -658,6 +658,8 @@ OPT_LDFLAGS - SECTION_LDFLAGS - enable_aarch64_lse - libtool_VERSION -+ENABLE_DARWIN_AT_RPATH_FALSE -+ENABLE_DARWIN_AT_RPATH_TRUE - MAINT - MAINTAINER_MODE_FALSE - MAINTAINER_MODE_TRUE -@@ -803,6 +805,7 @@ with_pic - enable_fast_install - with_gnu_ld - enable_libtool_lock -+enable_darwin_at_rpath - enable_maintainer_mode - enable_symvers - enable_werror -@@ -1452,6 +1455,8 @@ Optional Features: - --enable-fast-install[=PKGS] - optimize for fast installation [default=yes] - --disable-libtool-lock avoid locking (might break parallel builds) -+ --enable-darwin-at-path install libraries with @rpath/library-name, requires -+ rpaths to be added to executables - --enable-maintainer-mode - enable make rules and dependencies not useful (and - sometimes confusing) to the casual installer -@@ -9576,6 +9581,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc=no - hardcode_direct=no - hardcode_automatic=yes -@@ -9593,10 +9639,19 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - - else - ld_shlibs=no -@@ -11382,7 +11437,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 11385 "configure" -+#line 11440 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -11488,7 +11543,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 11491 "configure" -+#line 11546 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -11773,6 +11828,15 @@ fi - - - -+ if test x$enable_darwin_at_rpath = xyes; then -+ ENABLE_DARWIN_AT_RPATH_TRUE= -+ ENABLE_DARWIN_AT_RPATH_FALSE='#' -+else -+ ENABLE_DARWIN_AT_RPATH_TRUE='#' -+ ENABLE_DARWIN_AT_RPATH_FALSE= -+fi -+ -+ - # For libtool versioning info, format is CURRENT:REVISION:AGE - libtool_VERSION=3:0:2 - -@@ -15900,6 +15964,10 @@ if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then - as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 - fi -+if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then -+ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. -+Usually this means the macro was only invoked conditionally." "$LINENO" 5 -+fi - - if test -z "${LIBAT_BUILD_VERSIONED_SHLIB_TRUE}" && test -z "${LIBAT_BUILD_VERSIONED_SHLIB_FALSE}"; then - as_fn_error $? "conditional \"LIBAT_BUILD_VERSIONED_SHLIB\" was never defined. -diff --git a/libatomic/configure.ac b/libatomic/configure.ac -index 5563551aaae..6b9d3085806 100644 ---- a/libatomic/configure.ac -+++ b/libatomic/configure.ac -@@ -156,6 +156,8 @@ AC_SUBST(enable_shared) - AC_SUBST(enable_static) - AM_MAINTAINER_MODE - -+AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) -+ - # For libtool versioning info, format is CURRENT:REVISION:AGE - libtool_VERSION=3:0:2 - AC_SUBST(libtool_VERSION) -diff --git a/libatomic/testsuite/Makefile.in b/libatomic/testsuite/Makefile.in -index 333980ec2c1..8bc70562e5b 100644 ---- a/libatomic/testsuite/Makefile.in -+++ b/libatomic/testsuite/Makefile.in -@@ -262,6 +262,7 @@ target_alias = @target_alias@ - target_cpu = @target_cpu@ - target_os = @target_os@ - target_vendor = @target_vendor@ -+tmake_file = @tmake_file@ - toolexecdir = @toolexecdir@ - toolexeclibdir = @toolexeclibdir@ - top_build_prefix = @top_build_prefix@ -diff --git a/libatomic/testsuite/lib/libatomic.exp b/libatomic/testsuite/lib/libatomic.exp -index 38f3e5673e2..300e5096f79 100644 ---- a/libatomic/testsuite/lib/libatomic.exp -+++ b/libatomic/testsuite/lib/libatomic.exp -@@ -152,6 +152,7 @@ proc libatomic_init { args } { - lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/.." - - if [istarget *-*-darwin*] { -+ lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/.libs" - lappend ALWAYS_CFLAGS "additional_flags=-shared-libgcc" - } - -diff --git a/libbacktrace/Makefile.in b/libbacktrace/Makefile.in -index 08cdd21fb40..8898251161d 100644 ---- a/libbacktrace/Makefile.in -+++ b/libbacktrace/Makefile.in -@@ -15,7 +15,7 @@ - @SET_MAKE@ - - # Makefile.am -- Backtrace Makefile. --# Copyright (C) 2012-2021 Free Software Foundation, Inc. -+# Copyright (C) 2012-2022 Free Software Foundation, Inc. - - # Redistribution and use in source and binary forms, with or without - # modification, are permitted provided that the following conditions are -diff --git a/libbacktrace/backtrace.c b/libbacktrace/backtrace.c -index d28575ec897..cf6491682a7 100644 ---- a/libbacktrace/backtrace.c -+++ b/libbacktrace/backtrace.c -@@ -70,6 +70,13 @@ unwind (struct _Unwind_Context *context, void *vdata) - uintptr_t pc; - int ip_before_insn = 0; - -+#ifdef __APPLE__ -+# undef HAVE_GETIPINFO -+# if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 -+# define HAVE_GETIPINFO 1 -+# endif -+#endif -+ - #ifdef HAVE_GETIPINFO - pc = _Unwind_GetIPInfo (context, &ip_before_insn); - #else -diff --git a/libbacktrace/configure b/libbacktrace/configure -index 17f470a4bec..957095aaf1b 100755 ---- a/libbacktrace/configure -+++ b/libbacktrace/configure -@@ -675,6 +675,8 @@ PIC_FLAG - WARN_FLAGS - EXTRA_FLAGS - BACKTRACE_FILE -+ENABLE_DARWIN_AT_RPATH_FALSE -+ENABLE_DARWIN_AT_RPATH_TRUE - OTOOL64 - OTOOL - LIPO -@@ -799,6 +801,7 @@ with_pic - enable_fast_install - with_gnu_ld - enable_libtool_lock -+enable_darwin_at_rpath - enable_largefile - enable_cet - enable_werror -@@ -1447,6 +1450,8 @@ Optional Features: - --enable-fast-install[=PKGS] - optimize for fast installation [default=yes] - --disable-libtool-lock avoid locking (might break parallel builds) -+ --enable-darwin-at-path install libraries with @rpath/library-name, requires -+ rpaths to be added to executables - --disable-largefile omit support for large files - --enable-cet enable Intel CET in target libraries [default=auto] - --disable-werror disable building with -Werror -@@ -9705,6 +9710,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc=no - hardcode_direct=no - hardcode_automatic=yes -@@ -9722,10 +9768,19 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - - else - ld_shlibs=no -@@ -11511,7 +11566,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 11514 "configure" -+#line 11569 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -11617,7 +11672,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 11620 "configure" -+#line 11675 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -11856,6 +11911,15 @@ CC="$lt_save_CC" - - - -+ if test x$enable_darwin_at_rpath = xyes; then -+ ENABLE_DARWIN_AT_RPATH_TRUE= -+ ENABLE_DARWIN_AT_RPATH_FALSE='#' -+else -+ ENABLE_DARWIN_AT_RPATH_TRUE='#' -+ ENABLE_DARWIN_AT_RPATH_FALSE= -+fi -+ -+ - # Check whether --enable-largefile was given. - if test "${enable_largefile+set}" = set; then : - enableval=$enable_largefile; -@@ -14273,6 +14337,10 @@ if test -z "${HAVE_DWZ_TRUE}" && test -z "${HAVE_DWZ_FALSE}"; then - as_fn_error $? "conditional \"HAVE_DWZ\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 - fi -+if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then -+ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. -+Usually this means the macro was only invoked conditionally." "$LINENO" 5 -+fi - if test -z "${HAVE_ELF_TRUE}" && test -z "${HAVE_ELF_FALSE}"; then - as_fn_error $? "conditional \"HAVE_ELF\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 -diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac -index 597c9705db8..7f89bf33c6b 100644 ---- a/libbacktrace/configure.ac -+++ b/libbacktrace/configure.ac -@@ -84,6 +84,8 @@ AM_CONDITIONAL(HAVE_DWZ, test "$DWZ" != "") - LT_INIT - AM_PROG_LIBTOOL - -+AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) -+ - AC_SYS_LARGEFILE - - backtrace_supported=yes -diff --git a/libbacktrace/simple.c b/libbacktrace/simple.c -index 6a1a1c92a12..811255ab6b5 100644 ---- a/libbacktrace/simple.c -+++ b/libbacktrace/simple.c -@@ -65,6 +65,13 @@ simple_unwind (struct _Unwind_Context *context, void *vdata) - uintptr_t pc; - int ip_before_insn = 0; - -+#ifdef __APPLE__ -+# undef HAVE_GETIPINFO -+# if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 -+# define HAVE_GETIPINFO 1 -+# endif -+#endif -+ - #ifdef HAVE_GETIPINFO - pc = _Unwind_GetIPInfo (context, &ip_before_insn); - #else -diff --git a/libcc1/Makefile.am b/libcc1/Makefile.am -index 6e3a34ff7e2..44d282c7676 100644 ---- a/libcc1/Makefile.am -+++ b/libcc1/Makefile.am -@@ -55,6 +55,10 @@ marshall_c_source = marshall-c.hh - marshall_cxx_source = marshall-cp.hh - - libcc1plugin_la_LDFLAGS = -module -export-symbols $(srcdir)/libcc1plugin.sym -+if ENABLE_DARWIN_AT_RPATH -+libcc1plugin_la_LDFLAGS += -Wc,-nodefaultrpaths -+libcc1plugin_la_LDFLAGS += -Wl,-rpath,@loader_path -+endif - libcc1plugin_la_SOURCES = libcc1plugin.cc context.cc context.hh \ - $(shared_source) $(marshall_c_source) - libcc1plugin.lo_CPPFLAGS = $(CPPFLAGS_FOR_C) -@@ -65,6 +69,10 @@ libcc1plugin_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ - $(CXXFLAGS) $(libcc1plugin_la_LDFLAGS) $(LTLDFLAGS) -o $@ - - libcp1plugin_la_LDFLAGS = -module -export-symbols $(srcdir)/libcp1plugin.sym -+if ENABLE_DARWIN_AT_RPATH -+libcp1plugin_la_LDFLAGS += -Wc,-nodefaultrpaths -+libcp1plugin_la_LDFLAGS += -Wl,-rpath,@loader_path -+endif - libcp1plugin_la_SOURCES = libcp1plugin.cc context.cc context.hh \ - $(shared_source) $(marshall_cxx_source) - libcp1plugin.lo_CPPFLAGS = $(CPPFLAGS_FOR_CXX) -@@ -76,6 +84,10 @@ libcp1plugin_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ - - LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS)) - libcc1_la_LDFLAGS = -module -export-symbols $(srcdir)/libcc1.sym -+if ENABLE_DARWIN_AT_RPATH -+libcc1_la_LDFLAGS += -Wc,-nodefaultrpaths -+libcc1_la_LDFLAGS += -Wl,-rpath,@loader_path -+endif - libcc1_la_SOURCES = findcomp.cc libcc1.cc libcp1.cc \ - compiler.cc compiler.hh names.cc names.hh $(shared_source) \ - $(marshall_c_source) $(marshall_cxx_source) -diff --git a/libcc1/Makefile.in b/libcc1/Makefile.in -index f8f590d71e9..440567a47d2 100644 ---- a/libcc1/Makefile.in -+++ b/libcc1/Makefile.in -@@ -90,6 +90,12 @@ build_triplet = @build@ - host_triplet = @host@ - target_triplet = @target@ - @DARWIN_DYNAMIC_LOOKUP_TRUE@am__append_1 = -Wl,-undefined,dynamic_lookup -+@ENABLE_DARWIN_AT_RPATH_TRUE@am__append_2 = -Wc,-nodefaultrpaths \ -+@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path -+@ENABLE_DARWIN_AT_RPATH_TRUE@am__append_3 = -Wc,-nodefaultrpaths \ -+@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path -+@ENABLE_DARWIN_AT_RPATH_TRUE@am__append_4 = -Wc,-nodefaultrpaths \ -+@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path - subdir = . - ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 - am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \ -@@ -405,7 +411,8 @@ shared_source = callbacks.cc callbacks.hh connection.cc connection.hh \ - - marshall_c_source = marshall-c.hh - marshall_cxx_source = marshall-cp.hh --libcc1plugin_la_LDFLAGS = -module -export-symbols $(srcdir)/libcc1plugin.sym -+libcc1plugin_la_LDFLAGS = -module -export-symbols \ -+ $(srcdir)/libcc1plugin.sym $(am__append_2) - libcc1plugin_la_SOURCES = libcc1plugin.cc context.cc context.hh \ - $(shared_source) $(marshall_c_source) - -@@ -416,7 +423,8 @@ libcc1plugin_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ - $(CXXFLAGS) $(libcc1plugin_la_LDFLAGS) $(LTLDFLAGS) -o $@ - --libcp1plugin_la_LDFLAGS = -module -export-symbols $(srcdir)/libcp1plugin.sym -+libcp1plugin_la_LDFLAGS = -module -export-symbols \ -+ $(srcdir)/libcp1plugin.sym $(am__append_3) - libcp1plugin_la_SOURCES = libcp1plugin.cc context.cc context.hh \ - $(shared_source) $(marshall_cxx_source) - -@@ -428,7 +436,8 @@ libcp1plugin_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ - $(CXXFLAGS) $(libcp1plugin_la_LDFLAGS) $(LTLDFLAGS) -o $@ - - LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS)) --libcc1_la_LDFLAGS = -module -export-symbols $(srcdir)/libcc1.sym -+libcc1_la_LDFLAGS = -module -export-symbols $(srcdir)/libcc1.sym \ -+ $(am__append_4) - libcc1_la_SOURCES = findcomp.cc libcc1.cc libcp1.cc \ - compiler.cc compiler.hh names.cc names.hh $(shared_source) \ - $(marshall_c_source) $(marshall_cxx_source) -diff --git a/libcc1/configure b/libcc1/configure -index 01cfb2806da..42fb85a4047 100755 ---- a/libcc1/configure -+++ b/libcc1/configure -@@ -646,6 +646,8 @@ gcc_version - get_gcc_base_ver - CET_HOST_FLAGS - visibility -+ENABLE_DARWIN_AT_RPATH_FALSE -+ENABLE_DARWIN_AT_RPATH_TRUE - CXXCPP - am__fastdepCXX_FALSE - am__fastdepCXX_TRUE -@@ -787,6 +789,7 @@ with_pic - enable_fast_install - with_gnu_ld - enable_libtool_lock -+enable_darwin_at_rpath - enable_cet - with_gcc_major_version_only - enable_werror_always -@@ -1439,6 +1442,8 @@ Optional Features: - --enable-fast-install[=PKGS] - optimize for fast installation [default=yes] - --disable-libtool-lock avoid locking (might break parallel builds) -+ --enable-darwin-at-path install libraries with @rpath/library-name, requires -+ rpaths to be added to executables - --enable-cet enable Intel CET in host libraries [default=auto] - --enable-werror-always enable -Werror despite compiler version - --enable-plugin enable plugin support -@@ -8971,6 +8976,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc=no - hardcode_direct=no - hardcode_automatic=yes -@@ -8988,10 +9034,19 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - - else - ld_shlibs=no -@@ -10777,7 +10832,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 10780 "configure" -+#line 10835 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -10883,7 +10938,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 10886 "configure" -+#line 10941 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -12165,6 +12220,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc_CXX=no - hardcode_direct_CXX=no - hardcode_automatic_CXX=yes -@@ -12182,12 +12278,25 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - if test "$lt_cv_apple_cc_single_mod" != "yes"; then -- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring${_lt_dsymutil}" -+ else -+ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" -+ fi - archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" - fi - -@@ -14518,6 +14627,14 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ - ac_compiler_gnu=$ac_cv_c_compiler_gnu - - -+ if test x$enable_darwin_at_rpath = xyes; then -+ ENABLE_DARWIN_AT_RPATH_TRUE= -+ ENABLE_DARWIN_AT_RPATH_FALSE='#' -+else -+ ENABLE_DARWIN_AT_RPATH_TRUE='#' -+ ENABLE_DARWIN_AT_RPATH_FALSE= -+fi -+ - - visibility= - if test "$GXX" = yes; then -@@ -15369,6 +15486,10 @@ if test -z "${am__fastdepCXX_TRUE}" && test -z "${am__fastdepCXX_FALSE}"; then - as_fn_error $? "conditional \"am__fastdepCXX\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 - fi -+if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then -+ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. -+Usually this means the macro was only invoked conditionally." "$LINENO" 5 -+fi - if test -z "${DARWIN_DYNAMIC_LOOKUP_TRUE}" && test -z "${DARWIN_DYNAMIC_LOOKUP_FALSE}"; then - as_fn_error $? "conditional \"DARWIN_DYNAMIC_LOOKUP\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 -diff --git a/libcc1/configure.ac b/libcc1/configure.ac -index 36f5a7e09f1..e8d068e0ac4 100644 ---- a/libcc1/configure.ac -+++ b/libcc1/configure.ac -@@ -38,6 +38,7 @@ AM_MAINTAINER_MODE - LT_INIT([disable-static]) - AM_PROG_LIBTOOL - AC_PROG_CXX -+AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) - - visibility= - if test "$GXX" = yes; then -diff --git a/libffi/Makefile.am b/libffi/Makefile.am -index c6d6f849c53..d2ae0c04c7b 100644 ---- a/libffi/Makefile.am -+++ b/libffi/Makefile.am -@@ -214,7 +214,12 @@ libffi.map: $(top_srcdir)/libffi.map.in - $(COMPILE) -D$(TARGET) -DGENERATE_LIBFFI_MAP \ - -E -x assembler-with-cpp -o $@ $(top_srcdir)/libffi.map.in - --libffi_la_LDFLAGS = -no-undefined $(libffi_version_info) $(libffi_version_script) $(LTLDFLAGS) $(AM_LTLDFLAGS) -+if ENABLE_DARWIN_AT_RPATH -+libffi_darwin_rpath = -Wl,-rpath,@loader_path -+endif -+libffi_la_LDFLAGS = -no-undefined $(libffi_version_info) \ -+ $(libffi_version_script) $(LTLDFLAGS) $(AM_LTLDFLAGS) \ -+ $(libffi_darwin_rpath) - libffi_la_DEPENDENCIES = $(libffi_la_LIBADD) $(libffi_version_dep) - - AM_CPPFLAGS = -I. -I$(top_srcdir)/include -Iinclude -I$(top_srcdir)/src -diff --git a/libffi/Makefile.in b/libffi/Makefile.in -index 5524a6a571e..34e77a45d1a 100644 ---- a/libffi/Makefile.in -+++ b/libffi/Makefile.in -@@ -597,7 +597,11 @@ AM_CFLAGS = -Wall -g -fexceptions $(CET_FLAGS) $(am__append_2) - @LIBFFI_BUILD_VERSIONED_SHLIB_GNU_TRUE@@LIBFFI_BUILD_VERSIONED_SHLIB_TRUE@libffi_version_dep = libffi.map - @LIBFFI_BUILD_VERSIONED_SHLIB_SUN_TRUE@@LIBFFI_BUILD_VERSIONED_SHLIB_TRUE@libffi_version_dep = libffi.map-sun - libffi_version_info = -version-info `grep -v '^\#' $(srcdir)/libtool-version` --libffi_la_LDFLAGS = -no-undefined $(libffi_version_info) $(libffi_version_script) $(LTLDFLAGS) $(AM_LTLDFLAGS) -+@ENABLE_DARWIN_AT_RPATH_TRUE@libffi_darwin_rpath = -Wl,-rpath,@loader_path -+libffi_la_LDFLAGS = -no-undefined $(libffi_version_info) \ -+ $(libffi_version_script) $(LTLDFLAGS) $(AM_LTLDFLAGS) \ -+ $(libffi_darwin_rpath) -+ - libffi_la_DEPENDENCIES = $(libffi_la_LIBADD) $(libffi_version_dep) - AM_CPPFLAGS = -I. -I$(top_srcdir)/include -Iinclude -I$(top_srcdir)/src - AM_CCASFLAGS = $(AM_CPPFLAGS) $(CET_FLAGS) -diff --git a/libffi/configure b/libffi/configure -index 575641cca1d..002320ca302 100755 ---- a/libffi/configure -+++ b/libffi/configure -@@ -667,6 +667,8 @@ MAINT - MAINTAINER_MODE_FALSE - MAINTAINER_MODE_TRUE - READELF -+ENABLE_DARWIN_AT_RPATH_FALSE -+ENABLE_DARWIN_AT_RPATH_TRUE - CXXCPP - CPP - OTOOL64 -@@ -810,6 +812,7 @@ with_pic - enable_fast_install - with_gnu_ld - enable_libtool_lock -+enable_darwin_at_rpath - enable_maintainer_mode - enable_pax_emutramp - enable_debug -@@ -1465,6 +1468,8 @@ Optional Features: - --enable-fast-install[=PKGS] - optimize for fast installation [default=yes] - --disable-libtool-lock avoid locking (might break parallel builds) -+ --enable-darwin-at-path install libraries with @rpath/library-name, requires -+ rpaths to be added to executables - --enable-maintainer-mode - enable make rules and dependencies not useful (and - sometimes confusing) to the casual installer -@@ -9766,6 +9771,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc=no - hardcode_direct=no - hardcode_automatic=yes -@@ -9783,10 +9829,19 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - - else - ld_shlibs=no -@@ -11572,7 +11627,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 11575 "configure" -+#line 11630 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -11678,7 +11733,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 11681 "configure" -+#line 11736 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -12554,6 +12609,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc_CXX=no - hardcode_direct_CXX=no - hardcode_automatic_CXX=yes -@@ -12571,12 +12667,25 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - if test "$lt_cv_apple_cc_single_mod" != "yes"; then -- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring${_lt_dsymutil}" -+ else -+ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" -+ fi - archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" - fi - -@@ -14926,6 +15035,14 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu - # Only expand once: - - -+ if test x$enable_darwin_at_rpath = xyes; then -+ ENABLE_DARWIN_AT_RPATH_TRUE= -+ ENABLE_DARWIN_AT_RPATH_FALSE='#' -+else -+ ENABLE_DARWIN_AT_RPATH_TRUE='#' -+ ENABLE_DARWIN_AT_RPATH_FALSE= -+fi -+ - - if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}readelf", so it can be a program name with args. -@@ -17071,6 +17188,10 @@ if test -z "${am__fastdepCCAS_TRUE}" && test -z "${am__fastdepCCAS_FALSE}"; then - as_fn_error $? "conditional \"am__fastdepCCAS\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 - fi -+if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then -+ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. -+Usually this means the macro was only invoked conditionally." "$LINENO" 5 -+fi - if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then - as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 -diff --git a/libffi/configure.ac b/libffi/configure.ac -index 014d89d0423..716f20ae313 100644 ---- a/libffi/configure.ac -+++ b/libffi/configure.ac -@@ -55,6 +55,7 @@ AC_SUBST(CET_FLAGS) - AM_PROG_AS - AM_PROG_CC_C_O - AC_PROG_LIBTOOL -+AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) - - AC_CHECK_TOOL(READELF, readelf) - -diff --git a/libgcc/config.host b/libgcc/config.host -index 8c56fcae5d2..48eed32e195 100644 ---- a/libgcc/config.host -+++ b/libgcc/config.host -@@ -82,7 +82,7 @@ m32c*-*-*) - cpu_type=m32c - tmake_file=t-fdpbit - ;; --aarch64*-*-*) -+aarch64*-*-* | arm64*-*-*) - cpu_type=aarch64 - ;; - alpha*-*-*) -@@ -241,7 +241,46 @@ case ${host} in - ;; - esac - tmake_file="$tmake_file t-slibgcc-darwin" -- extra_parts="crt3.o libd10-uwfef.a crttms.o crttme.o libemutls_w.a" -+ # We are not using libtool to build the libs here, so we need to replicate -+ # a little of the logic around setting Darwin rpaths. Setting an explicit -+ # yes or no is honoured, otherwise we choose a suitable default. -+ # Sadly, this has to be kept in line with the rules in libtool.m4. -+ # This make fragment will override the setting in t-slibgcc-darwin so it -+ # must appear after it. -+ if test "x$enable_darwin_at_rpath" = "x"; then -+ echo "enable_darwin_at_rpath is unset" 1>&2 -+ case ${host} in -+ *-darwin[45678]*) ;; -+ *-darwin9* | *-darwin1[01234]*) ;; # We might default these on later. -+ *-darwin*) -+ echo "but is needed after macOS 10.11 (setting it on)" 1>&2 -+ enable_darwin_at_rpath=yes -+ ;; -+ esac -+ else -+ echo "enable_darwin_at_rpath is '$enable_darwin_at_rpath'" 1>&2 -+ fi -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ tmake_file="$tmake_file t-darwin-rpath " -+ fi -+ case ${host} in -+ *-*-darwin2* | *-*-darwin1[89]* | aarch64*-*-darwin*) -+ tmake_file="t-darwin-min-8 $tmake_file" -+ ;; -+ *-*-darwin9* | *-*-darwin1[0-7]*) -+ tmake_file="t-darwin-min-5 $tmake_file" -+ ;; -+ *-*-darwin[4-8]*) -+ tmake_file="t-darwin-min-1 $tmake_file" -+ ;; -+ *) -+ # Fall back to configuring for the oldest system known to work with -+ # all archs and the current sources. -+ tmake_file="t-darwin-min-5 $tmake_file" -+ echo "Warning: libgcc configured to support macOS 10.5" 1>&2 -+ ;; -+ esac -+ extra_parts="crt3.o crttms.o crttme.o libemutls_w.a" - ;; - *-*-dragonfly*) - tmake_file="$tmake_file t-crtstuff-pic t-libgcc-pic t-eh-dw2-dip" -@@ -384,6 +423,17 @@ aarch64*-*-elf | aarch64*-*-rtems*) - tmake_file="${tmake_file} ${cpu_type}/t-softfp t-softfp t-crtfm" - md_unwind_header=aarch64/aarch64-unwind.h - ;; -+aarch64*-*-darwin*) -+ extra_parts="$extra_parts crtfastmath.o" -+ tmake_file="${tmake_file} ${cpu_type}/t-aarch64" -+ tmake_file="${tmake_file} ${cpu_type}/t-lse " -+ tmake_file="${tmake_file} ${cpu_type}/t-softfp t-softfp " -+ tmake_file="${tmake_file} t-crtfm" -+ md_unwind_header=aarch64/aarch64-unwind.h -+ if test x$off_stack_trampolines = xyes; then -+ tmake_file="${tmake_file} ${cpu_type}/t-heap-trampoline" -+ fi -+ ;; - aarch64*-*-freebsd*) - extra_parts="$extra_parts crtfastmath.o" - tmake_file="${tmake_file} ${cpu_type}/t-aarch64" -@@ -408,6 +458,9 @@ aarch64*-*-linux*) - tmake_file="${tmake_file} ${cpu_type}/t-aarch64" - tmake_file="${tmake_file} ${cpu_type}/t-lse t-slibgcc-libgcc" - tmake_file="${tmake_file} ${cpu_type}/t-softfp t-softfp t-crtfm" -+ if test x$off_stack_trampolines = xyes; then -+ tmake_file="${tmake_file} ${cpu_type}/t-heap-trampoline" -+ fi - ;; - aarch64*-*-vxworks7*) - extra_parts="$extra_parts crtfastmath.o" -@@ -701,12 +754,17 @@ hppa*-*-netbsd*) - i[34567]86-*-darwin*) - tmake_file="$tmake_file i386/t-crtpc t-crtfm i386/t-msabi" - tm_file="$tm_file i386/darwin-lib.h" -+ extra_parts="$extra_parts libd10-uwfef.a " - extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o" - ;; - x86_64-*-darwin*) - tmake_file="$tmake_file i386/t-crtpc t-crtfm i386/t-msabi" - tm_file="$tm_file i386/darwin-lib.h" -+ extra_parts="$extra_parts libd10-uwfef.a " - extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o" -+ if test x$off_stack_trampolines = xyes; then -+ tmake_file="${tmake_file} i386/t-heap-trampoline" -+ fi - ;; - i[34567]86-*-elfiamcu) - tmake_file="$tmake_file i386/t-crtstuff t-softfp-sfdftf i386/32/t-softfp i386/32/t-iamcu i386/t-softfp t-softfp t-dfprules" -@@ -773,6 +831,9 @@ x86_64-*-linux*) - tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules" - tm_file="${tm_file} i386/elf-lib.h" - md_unwind_header=i386/linux-unwind.h -+ if test x$off_stack_trampolines = xyes; then -+ tmake_file="${tmake_file} i386/t-heap-trampoline" -+ fi - ;; - x86_64-*-kfreebsd*-gnu) - extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o" -@@ -1169,12 +1230,14 @@ powerpc-*-darwin*) - # We build the darwin10 EH shim for Rosetta (running on x86 machines). - tm_file="$tm_file i386/darwin-lib.h" - tmake_file="$tmake_file rs6000/t-ppc64-fp rs6000/t-ibm-ldouble" -+ extra_parts="$extra_parts libd10-uwfef.a " - extra_parts="$extra_parts crt2.o crt3_2.o libef_ppc.a dw_ppc.o" - ;; - powerpc64-*-darwin*) - # We build the darwin10 EH shim for Rosetta (running on x86 machines). - tm_file="$tm_file i386/darwin-lib.h" - tmake_file="$tmake_file rs6000/t-darwin64 rs6000/t-ibm-ldouble" -+ extra_parts="$extra_parts libd10-uwfef.a " - extra_parts="$extra_parts crt2.o crt3_2.o libef_ppc.a dw_ppc.o" - ;; - powerpc*-*-freebsd*) -diff --git a/libgcc/config/aarch64/heap-trampoline.c b/libgcc/config/aarch64/heap-trampoline.c -new file mode 100644 -index 00000000000..c8b83681ed7 ---- /dev/null -+++ b/libgcc/config/aarch64/heap-trampoline.c -@@ -0,0 +1,172 @@ -+/* Copyright The GNU Toolchain Authors. */ -+ -+#include -+#include -+#include -+#include -+#include -+#include -+ -+#if __APPLE__ -+/* For pthread_jit_write_protect_np */ -+#include -+#endif -+ -+void *allocate_trampoline_page (void); -+int get_trampolines_per_page (void); -+struct tramp_ctrl_data *allocate_tramp_ctrl (struct tramp_ctrl_data *parent); -+void *allocate_trampoline_page (void); -+ -+void __builtin_nested_func_ptr_created (void *chain, void *func, void **dst); -+void __builtin_nested_func_ptr_deleted (void); -+ -+#if defined(__gnu_linux__) -+static const uint32_t aarch64_trampoline_insns[] = { -+ 0xd503245f, /* hint 34 */ -+ 0x580000b1, /* ldr x17, .+20 */ -+ 0x580000d2, /* ldr x18, .+24 */ -+ 0xd61f0220, /* br x17 */ -+ 0xd5033f9f, /* dsb sy */ -+ 0xd5033fdf /* isb */ -+}; -+ -+#elif __APPLE__ -+static const uint32_t aarch64_trampoline_insns[] = { -+ 0xd503245f, /* hint 34 */ -+ 0x580000b1, /* ldr x17, .+20 */ -+ 0x580000d0, /* ldr x16, .+24 */ -+ 0xd61f0220, /* br x17 */ -+ 0xd5033f9f, /* dsb sy */ -+ 0xd5033fdf /* isb */ -+}; -+ -+#else -+#error "Unsupported AArch64 platform for heap trampolines" -+#endif -+ -+struct aarch64_trampoline { -+ uint32_t insns[6]; -+ void *func_ptr; -+ void *chain_ptr; -+}; -+ -+struct tramp_ctrl_data -+{ -+ struct tramp_ctrl_data *prev; -+ -+ int free_trampolines; -+ -+ /* This will be pointing to an executable mmap'ed page. */ -+ struct aarch64_trampoline *trampolines; -+}; -+ -+int -+get_trampolines_per_page (void) -+{ -+ return getpagesize() / sizeof(struct aarch64_trampoline); -+} -+ -+static _Thread_local struct tramp_ctrl_data *tramp_ctrl_curr = NULL; -+ -+void * -+allocate_trampoline_page (void) -+{ -+ void *page; -+ -+#if defined(__gnu_linux__) -+ page = mmap (0, getpagesize (), PROT_WRITE | PROT_EXEC, -+ MAP_ANON | MAP_PRIVATE, 0, 0); -+#elif __APPLE__ -+ page = mmap (0, getpagesize (), PROT_WRITE | PROT_EXEC, -+ MAP_ANON | MAP_PRIVATE | MAP_JIT, 0, 0); -+#else -+ page = MAP_FAILED; -+#endif -+ -+ return page; -+} -+ -+struct tramp_ctrl_data * -+allocate_tramp_ctrl (struct tramp_ctrl_data *parent) -+{ -+ struct tramp_ctrl_data *p = malloc (sizeof (struct tramp_ctrl_data)); -+ if (p == NULL) -+ return NULL; -+ -+ p->trampolines = allocate_trampoline_page (); -+ -+ if (p->trampolines == MAP_FAILED) -+ return NULL; -+ -+ p->prev = parent; -+ p->free_trampolines = get_trampolines_per_page(); -+ -+ return p; -+} -+ -+void -+__builtin_nested_func_ptr_created (void *chain, void *func, void **dst) -+{ -+ if (tramp_ctrl_curr == NULL) -+ { -+ tramp_ctrl_curr = allocate_tramp_ctrl (NULL); -+ if (tramp_ctrl_curr == NULL) -+ abort (); -+ } -+ -+ if (tramp_ctrl_curr->free_trampolines == 0) -+ { -+ void *tramp_ctrl = allocate_tramp_ctrl (tramp_ctrl_curr); -+ if (!tramp_ctrl) -+ abort (); -+ -+ tramp_ctrl_curr = tramp_ctrl; -+ } -+ -+ struct aarch64_trampoline *trampoline -+ = &tramp_ctrl_curr->trampolines[get_trampolines_per_page () -+ - tramp_ctrl_curr->free_trampolines]; -+ -+#if __APPLE__ -+ /* Disable write protection for the MAP_JIT regions in this thread (see -+ https://developer.apple.com/documentation/apple-silicon/porting-just-in-time-compilers-to-apple-silicon) */ -+ pthread_jit_write_protect_np (0); -+#endif -+ -+ memcpy (trampoline->insns, aarch64_trampoline_insns, -+ sizeof(aarch64_trampoline_insns)); -+ trampoline->func_ptr = func; -+ trampoline->chain_ptr = chain; -+ -+#if __APPLE__ -+ /* Re-enable write protection. */ -+ pthread_jit_write_protect_np (1); -+#endif -+ -+ tramp_ctrl_curr->free_trampolines -= 1; -+ -+ __builtin___clear_cache ((void *)trampoline->insns, -+ ((void *)trampoline->insns + sizeof(trampoline->insns))); -+ -+ *dst = &trampoline->insns; -+} -+ -+void -+__builtin_nested_func_ptr_deleted (void) -+{ -+ if (tramp_ctrl_curr == NULL) -+ abort (); -+ -+ tramp_ctrl_curr->free_trampolines += 1; -+ -+ if (tramp_ctrl_curr->free_trampolines == get_trampolines_per_page ()) -+ { -+ if (tramp_ctrl_curr->prev == NULL) -+ return; -+ -+ munmap (tramp_ctrl_curr->trampolines, getpagesize()); -+ struct tramp_ctrl_data *prev = tramp_ctrl_curr->prev; -+ free (tramp_ctrl_curr); -+ tramp_ctrl_curr = prev; -+ } -+} -diff --git a/libgcc/config/aarch64/lse.S b/libgcc/config/aarch64/lse.S -index 9c29cf08b59..97b68c42cc1 100644 ---- a/libgcc/config/aarch64/lse.S -+++ b/libgcc/config/aarch64/lse.S -@@ -58,7 +58,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see - #endif - - /* Declare the symbol gating the LSE implementations. */ -+#if __ELF__ - .hidden __aarch64_have_lse_atomics -+#else -+ .private_extern __aarch64_have_lse_atomics -+#endif - - /* Turn size and memory model defines into mnemonic fragments. */ - #if SIZE == 1 -@@ -164,6 +168,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see - #define BTI_C hint 34 - - /* Start and end a function. */ -+#if __ELF__ - .macro STARTFN name - .text - .balign 16 -@@ -187,6 +192,29 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see - cbz w(tmp0), \label - .endm - -+#else -+.macro STARTFN name -+ .text -+ .balign 16 -+ .private_extern _\name -+ .cfi_startproc -+_\name: -+ BTI_C -+.endm -+ -+.macro ENDFN name -+ .cfi_endproc -+.endm -+ -+/* Branch to LABEL if LSE is disabled. */ -+.macro JUMP_IF_NOT_LSE label -+ adrp x(tmp0), ___aarch64_have_lse_atomics@PAGE -+ ldrb w(tmp0), [x(tmp0), ___aarch64_have_lse_atomics@PAGEOFF] -+ cbz w(tmp0), \label -+.endm -+ -+#endif -+ - #ifdef L_cas - - STARTFN NAME(cas) -diff --git a/libgcc/config/aarch64/sfp-machine.h b/libgcc/config/aarch64/sfp-machine.h -index be9b42174c4..5dc1827ee3a 100644 ---- a/libgcc/config/aarch64/sfp-machine.h -+++ b/libgcc/config/aarch64/sfp-machine.h -@@ -122,6 +122,27 @@ void __sfp_handle_exceptions (int); - - - /* Define ALIASNAME as a strong alias for NAME. */ -+#if defined __APPLE__ -+/* Mach-O doesn't support aliasing, so we build a secondary function for -+ the alias - we need to do a bit of a dance to find out what the type of -+ the arguments is and then apply that to the secondary function. -+ If these functions ever return anything but CMPtype we need to revisit -+ this... */ -+typedef float alias_HFtype __attribute__ ((mode (HF))); -+typedef float alias_SFtype __attribute__ ((mode (SF))); -+typedef float alias_DFtype __attribute__ ((mode (DF))); -+typedef float alias_TFtype __attribute__ ((mode (TF))); -+#define ALIAS_SELECTOR \ -+ CMPtype (*) (alias_HFtype, alias_HFtype): (alias_HFtype) 0, \ -+ CMPtype (*) (alias_SFtype, alias_SFtype): (alias_SFtype) 0, \ -+ CMPtype (*) (alias_DFtype, alias_DFtype): (alias_DFtype) 0, \ -+ CMPtype (*) (alias_TFtype, alias_TFtype): (alias_TFtype) 0 -+#define strong_alias(name, aliasname) \ -+ CMPtype aliasname (__typeof (_Generic (name, ALIAS_SELECTOR)) a, \ -+ __typeof (_Generic (name, ALIAS_SELECTOR)) b) \ -+ { return name (a, b); } -+#else - # define strong_alias(name, aliasname) _strong_alias(name, aliasname) - # define _strong_alias(name, aliasname) \ - extern __typeof (name) aliasname __attribute__ ((alias (#name))); -+#endif -diff --git a/libgcc/config/aarch64/t-darwin b/libgcc/config/aarch64/t-darwin -new file mode 100644 -index 00000000000..f6ecda7b608 ---- /dev/null -+++ b/libgcc/config/aarch64/t-darwin -@@ -0,0 +1,7 @@ -+# Ensure we have a suitable minimum OS version. -+ -+HOST_LIBGCC2_CFLAGS += -mmacosx-version-min=11.0 -+ -+LIB2_SIDITI_CONV_FUNCS = yes -+ -+BUILD_LIBGCCS1 = -diff --git a/libgcc/config/aarch64/t-heap-trampoline b/libgcc/config/aarch64/t-heap-trampoline -new file mode 100644 -index 00000000000..3f70c2cd0c0 ---- /dev/null -+++ b/libgcc/config/aarch64/t-heap-trampoline -@@ -0,0 +1,20 @@ -+# Copyright The GNU Toolchain Authors. -+ -+# This file is part of GCC. -+# -+# GCC is free software; you can redistribute it and/or modify it -+# under the terms of the GNU General Public License as published by -+# the Free Software Foundation; either version 3, or (at your option) -+# any later version. -+# -+# GCC is distributed in the hope that it will be useful, but -+# WITHOUT ANY WARRANTY; without even the implied warranty of -+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -+# General Public License for more details. -+# -+# You should have received a copy of the GNU General Public License -+# along with GCC; see the file COPYING3. If not see -+# . -+ -+LIB2ADD += $(srcdir)/config/aarch64/heap-trampoline.c -+HOST_LIBGCC2_CFLAGS += -mmacosx-version-min=11.0 -diff --git a/libgcc/config/i386/heap-trampoline.c b/libgcc/config/i386/heap-trampoline.c -new file mode 100644 -index 00000000000..96e13bf828e ---- /dev/null -+++ b/libgcc/config/i386/heap-trampoline.c -@@ -0,0 +1,172 @@ -+/* Copyright The GNU Toolchain Authors. */ -+ -+#include -+#include -+#include -+#include -+#include -+#include -+ -+#if __APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101400 -+/* For pthread_jit_write_protect_np */ -+#include -+#endif -+ -+void *allocate_trampoline_page (void); -+int get_trampolines_per_page (void); -+struct tramp_ctrl_data *allocate_tramp_ctrl (struct tramp_ctrl_data *parent); -+void *allocate_trampoline_page (void); -+ -+void __builtin_nested_func_ptr_created (void *chain, void *func, void **dst); -+void __builtin_nested_func_ptr_deleted (void); -+ -+static const uint8_t trampoline_insns[] = { -+ /* movabs $,%r11 */ -+ 0x49, 0xbb, -+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -+ -+ /* movabs $,%r10 */ -+ 0x49, 0xba, -+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -+ -+ /* rex.WB jmpq *%r11 */ -+ 0x41, 0xff, 0xe3 -+}; -+ -+union ix86_trampoline { -+ uint8_t insns[sizeof(trampoline_insns)]; -+ -+ struct __attribute__((packed)) fields { -+ uint8_t insn_0[2]; -+ void *func_ptr; -+ uint8_t insn_1[2]; -+ void *chain_ptr; -+ uint8_t insn_2[3]; -+ } fields; -+}; -+ -+struct tramp_ctrl_data -+{ -+ struct tramp_ctrl_data *prev; -+ -+ int free_trampolines; -+ -+ /* This will be pointing to an executable mmap'ed page. */ -+ union ix86_trampoline *trampolines; -+}; -+ -+int -+get_trampolines_per_page (void) -+{ -+ return getpagesize() / sizeof(union ix86_trampoline); -+} -+ -+static _Thread_local struct tramp_ctrl_data *tramp_ctrl_curr = NULL; -+ -+void * -+allocate_trampoline_page (void) -+{ -+ void *page; -+ -+#if defined(__gnu_linux__) -+ page = mmap (0, getpagesize (), PROT_WRITE | PROT_EXEC, -+ MAP_ANON | MAP_PRIVATE, 0, 0); -+#elif __APPLE__ -+# if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101400 -+ page = mmap (0, getpagesize (), PROT_WRITE | PROT_EXEC, -+ MAP_ANON | MAP_PRIVATE | MAP_JIT, 0, 0); -+# else -+ page = mmap (0, getpagesize (), PROT_WRITE | PROT_EXEC, -+ MAP_ANON | MAP_PRIVATE, 0, 0); -+# endif -+#else -+ page = MAP_FAILED; -+#endif -+ -+ return page; -+} -+ -+struct tramp_ctrl_data * -+allocate_tramp_ctrl (struct tramp_ctrl_data *parent) -+{ -+ struct tramp_ctrl_data *p = malloc (sizeof (struct tramp_ctrl_data)); -+ if (p == NULL) -+ return NULL; -+ -+ p->trampolines = allocate_trampoline_page (); -+ -+ if (p->trampolines == MAP_FAILED) -+ return NULL; -+ -+ p->prev = parent; -+ p->free_trampolines = get_trampolines_per_page(); -+ -+ return p; -+} -+ -+void -+__builtin_nested_func_ptr_created (void *chain, void *func, void **dst) -+{ -+ if (tramp_ctrl_curr == NULL) -+ { -+ tramp_ctrl_curr = allocate_tramp_ctrl (NULL); -+ if (tramp_ctrl_curr == NULL) -+ abort (); -+ } -+ -+ if (tramp_ctrl_curr->free_trampolines == 0) -+ { -+ void *tramp_ctrl = allocate_tramp_ctrl (tramp_ctrl_curr); -+ if (!tramp_ctrl) -+ abort (); -+ -+ tramp_ctrl_curr = tramp_ctrl; -+ } -+ -+ union ix86_trampoline *trampoline -+ = &tramp_ctrl_curr->trampolines[get_trampolines_per_page () -+ - tramp_ctrl_curr->free_trampolines]; -+ -+#if __APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101400 -+ /* Disable write protection for the MAP_JIT regions in this thread (see -+ https://developer.apple.com/documentation/apple-silicon/porting-just-in-time-compilers-to-apple-silicon) */ -+ pthread_jit_write_protect_np (0); -+#endif -+ -+ memcpy (trampoline->insns, trampoline_insns, -+ sizeof(trampoline_insns)); -+ trampoline->fields.func_ptr = func; -+ trampoline->fields.chain_ptr = chain; -+ -+#if __APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101400 -+ /* Re-enable write protection. */ -+ pthread_jit_write_protect_np (1); -+#endif -+ -+ tramp_ctrl_curr->free_trampolines -= 1; -+ -+ __builtin___clear_cache ((void *)trampoline->insns, -+ ((void *)trampoline->insns + sizeof(trampoline->insns))); -+ -+ *dst = &trampoline->insns; -+} -+ -+void -+__builtin_nested_func_ptr_deleted (void) -+{ -+ if (tramp_ctrl_curr == NULL) -+ abort (); -+ -+ tramp_ctrl_curr->free_trampolines += 1; -+ -+ if (tramp_ctrl_curr->free_trampolines == get_trampolines_per_page ()) -+ { -+ if (tramp_ctrl_curr->prev == NULL) -+ return; -+ -+ munmap (tramp_ctrl_curr->trampolines, getpagesize()); -+ struct tramp_ctrl_data *prev = tramp_ctrl_curr->prev; -+ free (tramp_ctrl_curr); -+ tramp_ctrl_curr = prev; -+ } -+} -diff --git a/libgcc/config/i386/t-heap-trampoline b/libgcc/config/i386/t-heap-trampoline -new file mode 100644 -index 00000000000..76f438d9529 ---- /dev/null -+++ b/libgcc/config/i386/t-heap-trampoline -@@ -0,0 +1,20 @@ -+# Copyright The GNU Toolchain Authors. -+ -+# This file is part of GCC. -+# -+# GCC is free software; you can redistribute it and/or modify it -+# under the terms of the GNU General Public License as published by -+# the Free Software Foundation; either version 3, or (at your option) -+# any later version. -+# -+# GCC is distributed in the hope that it will be useful, but -+# WITHOUT ANY WARRANTY; without even the implied warranty of -+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -+# General Public License for more details. -+# -+# You should have received a copy of the GNU General Public License -+# along with GCC; see the file COPYING3. If not see -+# . -+ -+LIB2ADD += $(srcdir)/config/i386/heap-trampoline.c -+HOST_LIBGCC2_CFLAGS += -mmacosx-version-min=10.8 -diff --git a/libgcc/config/t-darwin b/libgcc/config/t-darwin -index 299d26c2c96..a708583d965 100644 ---- a/libgcc/config/t-darwin -+++ b/libgcc/config/t-darwin -@@ -1,15 +1,15 @@ - # Set this as a minimum (unless overriden by arch t-files) since it's a - # reasonable lowest common denominator that works for all our archs. --HOST_LIBGCC2_CFLAGS += -mmacosx-version-min=10.4 -+HOST_LIBGCC2_CFLAGS += $(DARWIN_MIN_LIB_VERSION) - - crt3.o: $(srcdir)/config/darwin-crt3.c -- $(crt_compile) -mmacosx-version-min=10.4 -c $< -+ $(crt_compile) $(DARWIN_MIN_CRT_VERSION) -c $< - - crttms.o: $(srcdir)/config/darwin-crt-tm.c -- $(crt_compile) -mmacosx-version-min=10.4 -DSTART -c $< -+ $(crt_compile) $(DARWIN_MIN_CRT_VERSION) -DSTART -c $< - - crttme.o: $(srcdir)/config/darwin-crt-tm.c -- $(crt_compile) -mmacosx-version-min=10.4 -DEND -c $< -+ $(crt_compile) $(DARWIN_MIN_CRT_VERSION) -DEND -c $< - - # Make emutls weak so that we can deal with -static-libgcc, override the - # hidden visibility when this is present in libgcc_eh. -@@ -24,7 +24,8 @@ libemutls_w.a: emutls_s.o - $(AR_CREATE_FOR_TARGET) $@ $< - $(RANLIB_FOR_TARGET) $@ - --# Patch to __Unwind_Find_Enclosing_Function for Darwin10. -+# This has to be built for 10.6, even if the toolchain will not target that -+# version - d10-uwfef.o: $(srcdir)/config/darwin10-unwind-find-enc-func.c libgcc_tm.h - $(crt_compile) -mmacosx-version-min=10.6 -c $< - -diff --git a/libgcc/config/t-darwin-min-1 b/libgcc/config/t-darwin-min-1 -new file mode 100644 -index 00000000000..8c2cf8acd39 ---- /dev/null -+++ b/libgcc/config/t-darwin-min-1 -@@ -0,0 +1,3 @@ -+# Support building with -mmacosx-version-min back to 10.1. -+DARWIN_MIN_LIB_VERSION = -mmacosx-version-min=10.4 -+DARWIN_MIN_CRT_VERSION = -mmacosx-version-min=10.1 -diff --git a/libgcc/config/t-darwin-min-4 b/libgcc/config/t-darwin-min-4 -new file mode 100644 -index 00000000000..04e980de4d5 ---- /dev/null -+++ b/libgcc/config/t-darwin-min-4 -@@ -0,0 +1,3 @@ -+# Support building with -mmacosx-version-min back to 10.4. -+DARWIN_MIN_LIB_VERSION = -mmacosx-version-min=10.4 -+DARWIN_MIN_CRT_VERSION = -mmacosx-version-min=10.4 -diff --git a/libgcc/config/t-darwin-min-5 b/libgcc/config/t-darwin-min-5 -new file mode 100644 -index 00000000000..138193151e7 ---- /dev/null -+++ b/libgcc/config/t-darwin-min-5 -@@ -0,0 +1,3 @@ -+# Support building with -mmacosx-version-min back to 10.5. -+DARWIN_MIN_LIB_VERSION = -mmacosx-version-min=10.5 -+DARWIN_MIN_CRT_VERSION = -mmacosx-version-min=10.5 -diff --git a/libgcc/config/t-darwin-min-8 b/libgcc/config/t-darwin-min-8 -new file mode 100644 -index 00000000000..9efc9dc0257 ---- /dev/null -+++ b/libgcc/config/t-darwin-min-8 -@@ -0,0 +1,3 @@ -+# Support building with -mmacosx-version-min back to 10.8. -+DARWIN_MIN_LIB_VERSION = -mmacosx-version-min=10.8 -+DARWIN_MIN_CRT_VERSION = -mmacosx-version-min=10.8 -diff --git a/libgcc/config/t-darwin-rpath b/libgcc/config/t-darwin-rpath -new file mode 100644 -index 00000000000..951539de7aa ---- /dev/null -+++ b/libgcc/config/t-darwin-rpath -@@ -0,0 +1,5 @@ -+# Use @rpath and add a search path to exes and dylibs that depend on this. -+SHLIB_RPATH = @rpath -+ -+# Enable the libgcc_s.1.dylib compatibility lib to find the dependent 1.1.dylib. -+SHLIB_LOADER_PATH = -Wl,-rpath,@loader_path -diff --git a/libgcc/config/t-slibgcc-darwin b/libgcc/config/t-slibgcc-darwin -index a8f69666a82..ee449de32e6 100644 ---- a/libgcc/config/t-slibgcc-darwin -+++ b/libgcc/config/t-slibgcc-darwin -@@ -1,4 +1,4 @@ --# Build a shared libgcc library with the darwin linker. -+# Build a shared libgcc library able to use embedded runpaths. - - SHLIB_SOVERSION = 1.1 - SHLIB_SO_MINVERSION = 1 -@@ -6,7 +6,6 @@ SHLIB_VERSTRING = -compatibility_version $(SHLIB_SO_MINVERSION) \ - -current_version $(SHLIB_SOVERSION) - SHLIB_EXT = .dylib - SHLIB_LC = -lSystem --SHLIB_INSTALL_DIR = $(slibdir) - - SHLIB_MKMAP = $(srcdir)/mkmap-flat.awk - SHLIB_MKMAP_OPTS = -v leading_underscore=1 -@@ -23,11 +22,20 @@ SHLIB_SONAME = @shlib_base_name@$(SHLIB_EXT) - # subdir. The code under MULTIBUILDTOP combines these into a single FAT - # library, that is what we eventually install. - -+# When enable_darwin_at_rpath is true, use @rpath instead of $(slibdir) for -+# this and dylibs that depend on this. So this def must come first and be -+# overridden in a make fragment that depends on the rpath setting. -+SHLIB_RPATH = $(slibdir) -+ -+# Likewise, we only want to add an @loader_path to the shared libs when -+# we have enable_darwin_at_rpath. -+SHLIB_LOADER_PATH = -+ - SHLIB_LINK = $(CC) $(LIBGCC2_CFLAGS) $(LDFLAGS) -dynamiclib -nodefaultlibs \ -- -install_name $(SHLIB_INSTALL_DIR)/$(SHLIB_INSTALL_NAME) \ -+ -install_name $(SHLIB_RPATH)/$(SHLIB_INSTALL_NAME) \ - -single_module -o $(SHLIB_DIR)/$(SHLIB_SONAME) \ - -Wl,-exported_symbols_list,$(SHLIB_MAP) \ -- $(SHLIB_VERSTRING) \ -+ $(SHLIB_VERSTRING) -nodefaultrpaths \ - @multilib_flags@ @shlib_objs@ $(SHLIB_LC) - - # we do our own thing -@@ -63,9 +71,9 @@ EHS_INSTNAME = libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT) - libgcc_ehs$(SHLIB_EXT): $(LIBEHSOBJS) $(extra-parts) - mkdir -p $(MULTIDIR) - $(CC) $(LIBGCC2_CFLAGS) $(LDFLAGS) -dynamiclib -nodefaultlibs \ -- -install_name $(SHLIB_INSTALL_DIR)/$(EHS_INSTNAME) \ -+ -install_name $(SHLIB_RPATH)/$(EHS_INSTNAME) \ - -o $(MULTIDIR)/libgcc_ehs$(SHLIB_EXT) $(SHLIB_VERSTRING) \ -- $(LIBEHSOBJS) $(SHLIB_LC) -+ -nodefaultrpaths $(LIBEHSOBJS) $(SHLIB_LC) - - all: libgcc_ehs$(SHLIB_EXT) - -@@ -121,12 +129,13 @@ libgcc_s.1.dylib: all-multi libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT) \ - cp ../$${mlib}/libgcc/$${mlib}/libgcc_ehs$(SHLIB_EXT) \ - ./libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} || exit 1 ; \ - arch=`$(LIPO) -info libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} | sed -e 's/.*:\ //'` ; \ -- $(CC) -arch $${arch} -nodefaultlibs -dynamiclib \ -+ $(CC) -arch $${arch} -nodefaultlibs -dynamiclib -nodefaultrpaths \ -+ $(SHLIB_LOADER_PATH) \ - -o libgcc_s.1$(SHLIB_EXT)_T_$${mlib} \ - -Wl,-reexport_library,libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} \ - -Wl,-reexport_library,libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} \ -- -install_name $(SHLIB_INSTALL_DIR)/libgcc_s.1.dylib \ -- -compatibility_version 1 -current_version 1 ; \ -+ -install_name $(SHLIB_RPATH)/libgcc_s.1.dylib \ -+ -compatibility_version 1 -current_version 1.1 ; \ - done - $(LIPO) -output libgcc_s.1$(SHLIB_EXT) -create libgcc_s.1$(SHLIB_EXT)_T* - rm libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T* -@@ -140,13 +149,14 @@ libgcc_s.1.dylib: all-multi libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT) - cp ../$${mlib}/libgcc/$${mlib}/libgcc_s$(SHLIB_EXT) \ - ./libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} || exit 1 ; \ - arch=`$(LIPO) -info libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} | sed -e 's/.*:\ //'` ; \ -- $(CC) -arch $${arch} -nodefaultlibs -dynamiclib \ -+ $(CC) -arch $${arch} -nodefaultlibs -dynamiclib -nodefaultrpaths \ -+ $(SHLIB_LOADER_PATH) \ - -o libgcc_s.1$(SHLIB_EXT)_T_$${mlib} \ - -Wl,-reexport_library,libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} \ - -lSystem \ - -Wl,-reexported_symbols_list,$(srcdir)/config/darwin-unwind.ver \ -- -install_name $(SHLIB_INSTALL_DIR)/libgcc_s.1.dylib \ -- -compatibility_version 1 -current_version 1 ; \ -+ -install_name $(SHLIB_RPATH)/libgcc_s.1.dylib \ -+ -compatibility_version 1 -current_version 1.1 ; \ - done - $(LIPO) -output libgcc_s.1$(SHLIB_EXT) -create libgcc_s.1$(SHLIB_EXT)_T* - rm libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T* -diff --git a/libgcc/configure b/libgcc/configure -index 1f9b2ac578b..a5c228bc3a1 100755 ---- a/libgcc/configure -+++ b/libgcc/configure -@@ -630,7 +630,6 @@ LIPO - AR - toolexeclibdir - toolexecdir --enable_gcov - target_subdir - host_subdir - build_subdir -@@ -654,6 +653,8 @@ build_cpu - build - with_aix_soname - enable_vtable_verify -+enable_gcov -+off_stack_trampolines - enable_shared - libgcc_topdir - target_alias -@@ -701,6 +702,8 @@ with_target_subdir - with_cross_host - with_ld - enable_shared -+enable_off_stack_trampolines -+enable_gcov - enable_vtable_verify - with_aix_soname - enable_version_specific_runtime_libs -@@ -708,7 +711,6 @@ with_toolexeclibdir - with_slibdir - enable_maintainer_mode - with_build_libsubdir --enable_gcov - enable_largefile - enable_decimal_float - with_system_libunwind -@@ -1342,12 +1344,15 @@ Optional Features: - --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) - --enable-FEATURE[=ARG] include FEATURE [ARG=yes] - --disable-shared don't provide a shared libgcc -+ --enable-off-stack-trampolines -+ Specify whether to support generating off-stack trampolines -+ -+ --disable-gcov don't provide libgcov and related host tools - --enable-vtable-verify Enable vtable verification feature - --enable-version-specific-runtime-libs Specify that runtime libraries should be installed in a compiler-specific directory - --enable-maintainer-mode - enable make rules and dependencies not useful (and - sometimes confusing) to the casual installer -- --disable-gcov don't provide libgcov and related host tools - --disable-largefile omit support for large files - --enable-decimal-float={no,yes,bid,dpd} - enable decimal float extension to C. Selecting 'bid' -@@ -2252,6 +2257,48 @@ fi - - - -+# Check whether --enable-off-stack-trampolines was given. -+if test "${enable_off_stack_trampolines+set}" = set; then : -+ enableval=$enable_off_stack_trampolines; -+case "$target" in -+ x86_64-*-linux* | x86_64-*-darwin1[4-9]* | x86_64-*-darwin2*) -+ off_stack_trampolines=$enableval -+ ;; -+ aarch64*-*-linux* ) -+ off_stack_trampolines=$enableval -+ ;; -+ aarch64*-*darwin* ) -+ off_stack_trampolines=$enableval -+ ;; -+ *) -+ as_fn_error $? "Configure option --enable-off-stack-trampolines is not supported \ -+for this platform" "$LINENO" 5 -+ off_stack_trampolines=no -+ ;; -+esac -+else -+ -+case "$target" in -+ *-*-darwin2*) -+ off_stack_trampolines=yes -+ ;; -+ *) -+ off_stack_trampolines=no -+ ;; -+esac -+fi -+ -+ -+ -+# Check whether --enable-gcov was given. -+if test "${enable_gcov+set}" = set; then : -+ enableval=$enable_gcov; -+else -+ enable_gcov=yes -+fi -+ -+ -+ - # Check whether --enable-vtable-verify was given. - if test "${enable_vtable_verify+set}" = set; then : - enableval=$enable_vtable_verify; case "$enableval" in -diff --git a/libgcc/configure.ac b/libgcc/configure.ac -index 2fc9d5d7c93..7d11bf00142 100644 ---- a/libgcc/configure.ac -+++ b/libgcc/configure.ac -@@ -68,6 +68,40 @@ AC_ARG_ENABLE(shared, - ], [enable_shared=yes]) - AC_SUBST(enable_shared) - -+AC_ARG_ENABLE([off-stack-trampolines], -+ [AS_HELP_STRING([--enable-off-stack-trampolines] -+ [Specify whether to support generating off-stack trampolines])],[ -+case "$target" in -+ x86_64-*-linux* | x86_64-*-darwin1[[4-9]]* | x86_64-*-darwin2*) -+ off_stack_trampolines=$enableval -+ ;; -+ aarch64*-*-linux* ) -+ off_stack_trampolines=$enableval -+ ;; -+ aarch64*-*darwin* ) -+ off_stack_trampolines=$enableval -+ ;; -+ *) -+ AC_MSG_ERROR([Configure option --enable-off-stack-trampolines is not supported \ -+for this platform]) -+ off_stack_trampolines=no -+ ;; -+esac],[ -+case "$target" in -+ *-*-darwin2*) -+ off_stack_trampolines=yes -+ ;; -+ *) -+ off_stack_trampolines=no -+ ;; -+esac]) -+AC_SUBST(off_stack_trampolines) -+ -+AC_ARG_ENABLE(gcov, -+[ --disable-gcov don't provide libgcov and related host tools], -+[], [enable_gcov=yes]) -+AC_SUBST(enable_gcov) -+ - AC_ARG_ENABLE(vtable-verify, - [ --enable-vtable-verify Enable vtable verification feature ], - [case "$enableval" in -diff --git a/libgcc/libgcc-std.ver.in b/libgcc/libgcc-std.ver.in -index 513ddd0bd0d..fc0b4052a3b 100644 ---- a/libgcc/libgcc-std.ver.in -+++ b/libgcc/libgcc-std.ver.in -@@ -1943,4 +1943,7 @@ GCC_4.8.0 { - GCC_7.0.0 { - __PFX__divmoddi4 - __PFX__divmodti4 -+ -+ __builtin_nested_func_ptr_created -+ __builtin_nested_func_ptr_deleted - } -diff --git a/libgcc/libgcc2.h b/libgcc/libgcc2.h -index fc24ac34502..536e517b62f 100644 ---- a/libgcc/libgcc2.h -+++ b/libgcc/libgcc2.h -@@ -29,6 +29,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see - #pragma GCC visibility push(default) - #endif - -+extern void __builtin_nested_func_ptr_created (void *, void *, void **); -+extern void __builtin_nested_func_ptr_deleted (void); -+ - extern int __gcc_bcmp (const unsigned char *, const unsigned char *, size_t); - extern void __clear_cache (void *, void *); - extern void __eprintf (const char *, const char *, unsigned int, const char *) -diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am -index 5ce0cd7cd05..2073bf6c5ef 100644 ---- a/libgfortran/Makefile.am -+++ b/libgfortran/Makefile.am -@@ -37,6 +37,11 @@ else - version_arg = - version_dep = - endif -+extra_darwin_ldflags_libgfortran = @extra_ldflags_libgfortran@ -+if ENABLE_DARWIN_AT_RPATH -+extra_darwin_ldflags_libgfortran += -Wc,-nodefaultrpaths -+extra_darwin_ldflags_libgfortran += -Wl,-rpath,@loader_path -+endif - - gfor_c_HEADERS = ISO_Fortran_binding.h - gfor_cdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include -@@ -50,7 +55,7 @@ libgfortran_la_LINK = $(LINK) $(libgfortran_la_LDFLAGS) - libgfortran_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ - $(LTLDFLAGS) $(LIBQUADLIB) ../libbacktrace/libbacktrace.la \ - $(HWCAP_LDFLAGS) \ -- $(LIBM) $(extra_ldflags_libgfortran) \ -+ $(LIBM) $(extra_darwin_ldflags_libgfortran) \ - $(version_arg) -Wc,-shared-libgcc - libgfortran_la_DEPENDENCIES = $(version_dep) libgfortran.spec $(LIBQUADLIB_DEP) - -diff --git a/libgfortran/Makefile.in b/libgfortran/Makefile.in -index 7ac6bfba657..52dd5f1819e 100644 ---- a/libgfortran/Makefile.in -+++ b/libgfortran/Makefile.in -@@ -91,8 +91,10 @@ POST_UNINSTALL = : - build_triplet = @build@ - host_triplet = @host@ - target_triplet = @target@ --@LIBGFOR_MINIMAL_TRUE@am__append_1 = -DLIBGFOR_MINIMAL --@LIBGFOR_MINIMAL_FALSE@am__append_2 = \ -+@ENABLE_DARWIN_AT_RPATH_TRUE@am__append_1 = -Wc,-nodefaultrpaths \ -+@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path -+@LIBGFOR_MINIMAL_TRUE@am__append_2 = -DLIBGFOR_MINIMAL -+@LIBGFOR_MINIMAL_FALSE@am__append_3 = \ - @LIBGFOR_MINIMAL_FALSE@io/close.c \ - @LIBGFOR_MINIMAL_FALSE@io/file_pos.c \ - @LIBGFOR_MINIMAL_FALSE@io/format.c \ -@@ -110,7 +112,7 @@ target_triplet = @target@ - @LIBGFOR_MINIMAL_FALSE@io/fbuf.c \ - @LIBGFOR_MINIMAL_FALSE@io/async.c - --@LIBGFOR_MINIMAL_FALSE@am__append_3 = \ -+@LIBGFOR_MINIMAL_FALSE@am__append_4 = \ - @LIBGFOR_MINIMAL_FALSE@intrinsics/access.c \ - @LIBGFOR_MINIMAL_FALSE@intrinsics/c99_functions.c \ - @LIBGFOR_MINIMAL_FALSE@intrinsics/chdir.c \ -@@ -143,9 +145,9 @@ target_triplet = @target@ - @LIBGFOR_MINIMAL_FALSE@intrinsics/umask.c \ - @LIBGFOR_MINIMAL_FALSE@intrinsics/unlink.c - --@IEEE_SUPPORT_TRUE@am__append_4 = ieee/ieee_helper.c --@LIBGFOR_MINIMAL_TRUE@am__append_5 = runtime/minimal.c --@LIBGFOR_MINIMAL_FALSE@am__append_6 = \ -+@IEEE_SUPPORT_TRUE@am__append_5 = ieee/ieee_helper.c -+@LIBGFOR_MINIMAL_TRUE@am__append_6 = runtime/minimal.c -+@LIBGFOR_MINIMAL_FALSE@am__append_7 = \ - @LIBGFOR_MINIMAL_FALSE@runtime/backtrace.c \ - @LIBGFOR_MINIMAL_FALSE@runtime/convert_char.c \ - @LIBGFOR_MINIMAL_FALSE@runtime/environ.c \ -@@ -157,7 +159,7 @@ target_triplet = @target@ - - - # dummy sources for libtool --@onestep_TRUE@am__append_7 = libgfortran_c.c libgfortran_f.f90 -+@onestep_TRUE@am__append_8 = libgfortran_c.c libgfortran_f.f90 - subdir = . - ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 - am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \ -@@ -589,7 +591,7 @@ AMTAR = @AMTAR@ - - # Some targets require additional compiler options for IEEE compatibility. - AM_CFLAGS = @AM_CFLAGS@ -fcx-fortran-rules $(SECTION_FLAGS) \ -- $(IEEE_FLAGS) $(am__append_1) -+ $(IEEE_FLAGS) $(am__append_2) - AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ - AM_FCFLAGS = @AM_FCFLAGS@ $(IEEE_FLAGS) - AR = @AR@ -@@ -748,6 +750,8 @@ gcc_version := $(shell @get_gcc_base_ver@ $(top_srcdir)/../gcc/BASE-VER) - @LIBGFOR_USE_SYMVER_FALSE@version_dep = - @LIBGFOR_USE_SYMVER_GNU_TRUE@@LIBGFOR_USE_SYMVER_TRUE@version_dep = gfortran.ver - @LIBGFOR_USE_SYMVER_SUN_TRUE@@LIBGFOR_USE_SYMVER_TRUE@version_dep = gfortran.ver-sun gfortran.ver -+extra_darwin_ldflags_libgfortran = @extra_ldflags_libgfortran@ \ -+ $(am__append_1) - gfor_c_HEADERS = ISO_Fortran_binding.h - gfor_cdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include - LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS)) \ -@@ -759,7 +763,7 @@ libgfortran_la_LINK = $(LINK) $(libgfortran_la_LDFLAGS) - libgfortran_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ - $(LTLDFLAGS) $(LIBQUADLIB) ../libbacktrace/libbacktrace.la \ - $(HWCAP_LDFLAGS) \ -- $(LIBM) $(extra_ldflags_libgfortran) \ -+ $(LIBM) $(extra_darwin_ldflags_libgfortran) \ - $(version_arg) -Wc,-shared-libgcc - - libgfortran_la_DEPENDENCIES = $(version_dep) libgfortran.spec $(LIBQUADLIB_DEP) -@@ -780,7 +784,7 @@ AM_CPPFLAGS = -iquote$(srcdir)/io -I$(srcdir)/$(MULTISRCTOP)../gcc \ - -I$(MULTIBUILDTOP)../libbacktrace \ - -I../libbacktrace - --gfor_io_src = io/size_from_kind.c $(am__append_2) -+gfor_io_src = io/size_from_kind.c $(am__append_3) - gfor_io_headers = \ - io/io.h \ - io/fbuf.h \ -@@ -802,7 +806,7 @@ gfor_helper_src = intrinsics/associated.c intrinsics/abort.c \ - intrinsics/selected_int_kind.f90 \ - intrinsics/selected_real_kind.f90 intrinsics/trigd.c \ - intrinsics/unpack_generic.c runtime/in_pack_generic.c \ -- runtime/in_unpack_generic.c $(am__append_3) $(am__append_4) -+ runtime/in_unpack_generic.c $(am__append_4) $(am__append_5) - @IEEE_SUPPORT_TRUE@gfor_ieee_helper_src = ieee/ieee_helper.c - @IEEE_SUPPORT_FALSE@gfor_ieee_src = - @IEEE_SUPPORT_TRUE@gfor_ieee_src = \ -@@ -811,8 +815,8 @@ gfor_helper_src = intrinsics/associated.c intrinsics/abort.c \ - @IEEE_SUPPORT_TRUE@ieee/ieee_features.F90 - - gfor_src = runtime/bounds.c runtime/compile_options.c runtime/memory.c \ -- runtime/string.c runtime/select.c $(am__append_5) \ -- $(am__append_6) -+ runtime/string.c runtime/select.c $(am__append_6) \ -+ $(am__append_7) - i_all_c = \ - $(srcdir)/generated/all_l1.c \ - $(srcdir)/generated/all_l2.c \ -@@ -1652,7 +1656,7 @@ intrinsics/random_init.f90 - - BUILT_SOURCES = $(gfor_built_src) $(gfor_built_specific_src) \ - $(gfor_built_specific2_src) $(gfor_misc_specifics) \ -- $(am__append_7) -+ $(am__append_8) - prereq_SRC = $(gfor_src) $(gfor_built_src) $(gfor_io_src) \ - $(gfor_helper_src) $(gfor_ieee_src) $(gfor_io_headers) $(gfor_specific_src) - -diff --git a/libgfortran/configure b/libgfortran/configure -index ae64dca3114..f288af81ff5 100755 ---- a/libgfortran/configure -+++ b/libgfortran/configure -@@ -655,6 +655,8 @@ extra_ldflags_libgfortran - ac_ct_FC - FCFLAGS - FC -+ENABLE_DARWIN_AT_RPATH_FALSE -+ENABLE_DARWIN_AT_RPATH_TRUE - enable_static - enable_shared - lt_host_flags -@@ -824,6 +826,7 @@ enable_static - with_pic - enable_fast_install - enable_libtool_lock -+enable_darwin_at_rpath - enable_largefile - enable_libquadmath_support - with_gcc_major_version_only -@@ -1479,6 +1482,8 @@ Optional Features: - --enable-fast-install[=PKGS] - optimize for fast installation [default=yes] - --disable-libtool-lock avoid locking (might break parallel builds) -+ --enable-darwin-at-path install libraries with @rpath/library-name, requires -+ rpaths to be added to executables - --disable-largefile omit support for large files - --disable-libquadmath-support - disable libquadmath support for Fortran -@@ -10939,6 +10944,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc=no - hardcode_direct=no - hardcode_automatic=yes -@@ -10956,10 +11002,19 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - - else - ld_shlibs=no -@@ -12766,7 +12821,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 12769 "configure" -+#line 12824 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -12872,7 +12927,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 12875 "configure" -+#line 12930 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -13274,6 +13329,14 @@ esac - - - -+ if test x$enable_darwin_at_rpath = xyes; then -+ ENABLE_DARWIN_AT_RPATH_TRUE= -+ ENABLE_DARWIN_AT_RPATH_FALSE='#' -+else -+ ENABLE_DARWIN_AT_RPATH_TRUE='#' -+ ENABLE_DARWIN_AT_RPATH_FALSE= -+fi -+ - #AC_MSG_NOTICE([====== Finished libtool configuration]) ; sleep 10 - - # We need gfortran to compile parts of the library -@@ -14917,6 +14980,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc_FC=no - hardcode_direct_FC=no - hardcode_automatic_FC=yes -@@ -14934,10 +15038,19 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds_FC="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds_FC="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds_FC="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds_FC="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds_FC="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds_FC="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_FC="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_FC="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds_FC="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds_FC="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_FC="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_FC="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - - else - ld_shlibs_FC=no -@@ -16190,9 +16303,10 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu - - - # extra LD Flags which are required for targets -+extra_ldflags_libgfortran= - case "${host}" in -- *-darwin*) -- # Darwin needs -single_module when linking libgfortran -+ *-*-darwin[4567]*) -+ # Earlier Darwin needs -single_module when linking libgfortran - extra_ldflags_libgfortran=-Wl,-single_module - ;; - esac -@@ -28519,6 +28633,10 @@ if test -z "${HAVE_HWCAP_TRUE}" && test -z "${HAVE_HWCAP_FALSE}"; then - as_fn_error $? "conditional \"HAVE_HWCAP\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 - fi -+if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then -+ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. -+Usually this means the macro was only invoked conditionally." "$LINENO" 5 -+fi - if test -z "${LIBGFOR_BUILD_QUAD_TRUE}" && test -z "${LIBGFOR_BUILD_QUAD_FALSE}"; then - as_fn_error $? "conditional \"LIBGFOR_BUILD_QUAD\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 -diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac -index 97cc490cb5e..a21f56648a2 100644 ---- a/libgfortran/configure.ac -+++ b/libgfortran/configure.ac -@@ -282,6 +282,7 @@ LT_LIB_M - ACX_LT_HOST_FLAGS - AC_SUBST(enable_shared) - AC_SUBST(enable_static) -+AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) - #AC_MSG_NOTICE([====== Finished libtool configuration]) ; sleep 10 - - # We need gfortran to compile parts of the library -@@ -290,9 +291,10 @@ FC="$GFORTRAN" - AC_PROG_FC(gfortran) - - # extra LD Flags which are required for targets -+extra_ldflags_libgfortran= - case "${host}" in -- *-darwin*) -- # Darwin needs -single_module when linking libgfortran -+ *-*-darwin[[4567]]*) -+ # Earlier Darwin needs -single_module when linking libgfortran - extra_ldflags_libgfortran=-Wl,-single_module - ;; - esac -diff --git a/libgo/configure b/libgo/configure -index ffe17c9be55..de5c1ac9b3d 100755 ---- a/libgo/configure -+++ b/libgo/configure -@@ -708,6 +708,8 @@ glibgo_toolexecdir - WERROR - WARN_FLAGS - CC_FOR_BUILD -+ENABLE_DARWIN_AT_RPATH_FALSE -+ENABLE_DARWIN_AT_RPATH_TRUE - enable_static - enable_shared - CPP -@@ -11544,7 +11546,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 11547 "configure" -+#line 11549 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -11650,7 +11652,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 11653 "configure" -+#line 11655 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -13779,6 +13781,14 @@ CC="$lt_save_CC" - - - -+ if test x$enable_darwin_at_rpath = xyes; then -+ ENABLE_DARWIN_AT_RPATH_TRUE= -+ ENABLE_DARWIN_AT_RPATH_FALSE='#' -+else -+ ENABLE_DARWIN_AT_RPATH_TRUE='#' -+ ENABLE_DARWIN_AT_RPATH_FALSE= -+fi -+ - - CC_FOR_BUILD=${CC_FOR_BUILD:-gcc} - -@@ -16321,6 +16331,10 @@ if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then - as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 - fi -+if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then -+ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. -+Usually this means the macro was only invoked conditionally." "$LINENO" 5 -+fi - if test -z "${USE_LIBFFI_TRUE}" && test -z "${USE_LIBFFI_FALSE}"; then - as_fn_error $? "conditional \"USE_LIBFFI\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 -diff --git a/libgo/configure.ac b/libgo/configure.ac -index 7e2b98ba67c..7b0222bb620 100644 ---- a/libgo/configure.ac -+++ b/libgo/configure.ac -@@ -53,6 +53,7 @@ AC_LIBTOOL_DLOPEN - AM_PROG_LIBTOOL - AC_SUBST(enable_shared) - AC_SUBST(enable_static) -+AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) - - CC_FOR_BUILD=${CC_FOR_BUILD:-gcc} - AC_SUBST(CC_FOR_BUILD) -diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am -index f8b2a06d63e..81ba6c634fa 100644 ---- a/libgomp/Makefile.am -+++ b/libgomp/Makefile.am -@@ -53,9 +53,14 @@ else - libgomp_version_script = - libgomp_version_dep = - endif -+ - libgomp_version_info = -version-info $(libtool_VERSION) -+if ENABLE_DARWIN_AT_RPATH -+libgomp_darwin_rpath = -Wc,-nodefaultrpaths -+libgomp_darwin_rpath += -Wl,-rpath,@loader_path -+endif - libgomp_la_LDFLAGS = $(libgomp_version_info) $(libgomp_version_script) \ -- $(lt_host_flags) -+ $(lt_host_flags) $(libgomp_darwin_rpath) - libgomp_la_DEPENDENCIES = $(libgomp_version_dep) - libgomp_la_LINK = $(LINK) $(libgomp_la_LDFLAGS) - -diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in -index 6f0cb716135..5cfb149c2ba 100644 ---- a/libgomp/Makefile.in -+++ b/libgomp/Makefile.in -@@ -546,8 +546,11 @@ nodist_toolexeclib_HEADERS = libgomp.spec - @LIBGOMP_BUILD_VERSIONED_SHLIB_GNU_TRUE@@LIBGOMP_BUILD_VERSIONED_SHLIB_TRUE@libgomp_version_dep = libgomp.ver - @LIBGOMP_BUILD_VERSIONED_SHLIB_SUN_TRUE@@LIBGOMP_BUILD_VERSIONED_SHLIB_TRUE@libgomp_version_dep = libgomp.ver-sun - libgomp_version_info = -version-info $(libtool_VERSION) -+@ENABLE_DARWIN_AT_RPATH_TRUE@libgomp_darwin_rpath = \ -+@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ -+@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path - libgomp_la_LDFLAGS = $(libgomp_version_info) $(libgomp_version_script) \ -- $(lt_host_flags) -+ $(lt_host_flags) $(libgomp_darwin_rpath) - - libgomp_la_DEPENDENCIES = $(libgomp_version_dep) - libgomp_la_LINK = $(LINK) $(libgomp_la_LDFLAGS) -diff --git a/libgomp/configure b/libgomp/configure -index 85fdb4d3f48..71b5987dc9a 100755 ---- a/libgomp/configure -+++ b/libgomp/configure -@@ -692,6 +692,8 @@ FC - MAINT - MAINTAINER_MODE_FALSE - MAINTAINER_MODE_TRUE -+ENABLE_DARWIN_AT_RPATH_FALSE -+ENABLE_DARWIN_AT_RPATH_TRUE - enable_static - enable_shared - lt_host_flags -@@ -832,6 +834,7 @@ with_pic - enable_fast_install - with_gnu_ld - enable_libtool_lock -+enable_darwin_at_rpath - enable_maintainer_mode - with_cuda_driver - with_cuda_driver_include -@@ -1493,6 +1496,8 @@ Optional Features: - --enable-fast-install[=PKGS] - optimize for fast installation [default=yes] - --disable-libtool-lock avoid locking (might break parallel builds) -+ --enable-darwin-at-path install libraries with @rpath/library-name, requires -+ rpaths to be added to executables - --enable-maintainer-mode - enable make rules and dependencies not useful (and - sometimes confusing) to the casual installer -@@ -9625,6 +9630,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc=no - hardcode_direct=no - hardcode_automatic=yes -@@ -9642,10 +9688,19 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - - else - ld_shlibs=no -@@ -11431,7 +11486,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 11434 "configure" -+#line 11489 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -11537,7 +11592,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 11540 "configure" -+#line 11595 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -11798,6 +11853,14 @@ esac - - - -+ if test x$enable_darwin_at_rpath = xyes; then -+ ENABLE_DARWIN_AT_RPATH_TRUE= -+ ENABLE_DARWIN_AT_RPATH_FALSE='#' -+else -+ ENABLE_DARWIN_AT_RPATH_TRUE='#' -+ ENABLE_DARWIN_AT_RPATH_FALSE= -+fi -+ - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5 -@@ -13473,6 +13536,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc_FC=no - hardcode_direct_FC=no - hardcode_automatic_FC=yes -@@ -13490,10 +13594,19 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds_FC="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds_FC="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds_FC="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds_FC="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds_FC="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds_FC="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_FC="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_FC="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds_FC="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds_FC="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_FC="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_FC="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - - else - ld_shlibs_FC=no -@@ -17213,6 +17326,10 @@ if test -z "${BUILD_INFO_TRUE}" && test -z "${BUILD_INFO_FALSE}"; then - as_fn_error $? "conditional \"BUILD_INFO\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 - fi -+if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then -+ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. -+Usually this means the macro was only invoked conditionally." "$LINENO" 5 -+fi - if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then - as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 -diff --git a/libgomp/configure.ac b/libgomp/configure.ac -index a9b1f3973f7..654fca1f445 100644 ---- a/libgomp/configure.ac -+++ b/libgomp/configure.ac -@@ -149,6 +149,7 @@ AM_PROG_LIBTOOL - ACX_LT_HOST_FLAGS - AC_SUBST(enable_shared) - AC_SUBST(enable_static) -+AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) - - AM_MAINTAINER_MODE - -diff --git a/libiberty/aclocal.m4 b/libiberty/aclocal.m4 -index 3378316dced..1a00b771fe1 100644 ---- a/libiberty/aclocal.m4 -+++ b/libiberty/aclocal.m4 -@@ -12,10 +12,61 @@ - # PARTICULAR PURPOSE. - - m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])]) -+# AM_CONDITIONAL -*- Autoconf -*- -+ -+# Copyright (C) 1997-2017 Free Software Foundation, Inc. -+# -+# This file is free software; the Free Software Foundation -+# gives unlimited permission to copy and/or distribute it, -+# with or without modifications, as long as this notice is preserved. -+ -+# AM_CONDITIONAL(NAME, SHELL-CONDITION) -+# ------------------------------------- -+# Define a conditional. -+AC_DEFUN([AM_CONDITIONAL], -+[AC_PREREQ([2.52])dnl -+ m4_if([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], -+ [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl -+AC_SUBST([$1_TRUE])dnl -+AC_SUBST([$1_FALSE])dnl -+_AM_SUBST_NOTMAKE([$1_TRUE])dnl -+_AM_SUBST_NOTMAKE([$1_FALSE])dnl -+m4_define([_AM_COND_VALUE_$1], [$2])dnl -+if $2; then -+ $1_TRUE= -+ $1_FALSE='#' -+else -+ $1_TRUE='#' -+ $1_FALSE= -+fi -+AC_CONFIG_COMMANDS_PRE( -+[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then -+ AC_MSG_ERROR([[conditional "$1" was never defined. -+Usually this means the macro was only invoked conditionally.]]) -+fi])]) -+ -+# Copyright (C) 2006-2017 Free Software Foundation, Inc. -+# -+# This file is free software; the Free Software Foundation -+# gives unlimited permission to copy and/or distribute it, -+# with or without modifications, as long as this notice is preserved. -+ -+# _AM_SUBST_NOTMAKE(VARIABLE) -+# --------------------------- -+# Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in. -+# This macro is traced by Automake. -+AC_DEFUN([_AM_SUBST_NOTMAKE]) -+ -+# AM_SUBST_NOTMAKE(VARIABLE) -+# -------------------------- -+# Public sister of _AM_SUBST_NOTMAKE. -+AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)]) -+ - m4_include([../config/acx.m4]) - m4_include([../config/cet.m4]) - m4_include([../config/enable.m4]) - m4_include([../config/no-executables.m4]) -+m4_include([../config/override.m4]) - m4_include([../config/picflag.m4]) - m4_include([../config/warnings.m4]) - m4_include([acinclude.m4]) -diff --git a/libiberty/configure b/libiberty/configure -index 0a797255c70..a346be40cc2 100755 ---- a/libiberty/configure -+++ b/libiberty/configure -@@ -632,6 +632,8 @@ PICFLAG - INSTALL_DATA - INSTALL_SCRIPT - INSTALL_PROGRAM -+ENABLE_DARWIN_AT_RPATH_FALSE -+ENABLE_DARWIN_AT_RPATH_TRUE - OUTPUT_OPTION - NO_MINUS_C_MINUS_O - ac_libiberty_warn_cflags -@@ -2459,6 +2461,9 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu - - - -+ -+ -+ - # This works around the fact that libtool configuration may change LD - # for this particular configuration, but some shells, instead of - # keeping the changes in LD private, export them just because LD is -@@ -5046,6 +5051,15 @@ $as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h - - - -+ if test x$enable_darwin_at_rpath = xyes; then -+ ENABLE_DARWIN_AT_RPATH_TRUE= -+ ENABLE_DARWIN_AT_RPATH_FALSE='#' -+else -+ ENABLE_DARWIN_AT_RPATH_TRUE='#' -+ ENABLE_DARWIN_AT_RPATH_FALSE= -+fi -+ -+ - ac_config_headers="$ac_config_headers config.h:config.in" - - -@@ -5208,6 +5222,9 @@ case "${host}" in - # sets the default TLS model and affects inlining. - PICFLAG=-fPIC - ;; -+ loongarch*-*-*) -+ PICFLAG=-fpic -+ ;; - mips-sgi-irix6*) - # PIC is the default. - ;; -@@ -7837,6 +7854,10 @@ LTLIBOBJS=$ac_ltlibobjs - - - -+if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then -+ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. -+Usually this means the macro was only invoked conditionally." "$LINENO" 5 -+fi - - : "${CONFIG_STATUS=./config.status}" - ac_write_fail=0 -diff --git a/libiberty/configure.ac b/libiberty/configure.ac -index 84a7b378fad..4dad84ea77a 100644 ---- a/libiberty/configure.ac -+++ b/libiberty/configure.ac -@@ -190,6 +190,8 @@ dnl AM_DISABLE_SHARED - dnl When we start using libtool: - dnl AM_PROG_LIBTOOL - -+AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) -+ - dnl When we start using automake: - dnl AM_CONFIG_HEADER(config.h:config.in) - AC_CONFIG_HEADER(config.h:config.in) -diff --git a/libitm/Makefile.am b/libitm/Makefile.am -index 3f31ad30556..a25317b07fe 100644 ---- a/libitm/Makefile.am -+++ b/libitm/Makefile.am -@@ -54,7 +54,12 @@ libitm_version_info = -version-info $(libtool_VERSION) - # want or need libstdc++. - libitm_la_DEPENDENCIES = $(libitm_version_dep) - libitm_la_LINK = $(LINK) $(libitm_la_LDFLAGS) --libitm_la_LDFLAGS = $(libitm_version_info) $(libitm_version_script) -+if ENABLE_DARWIN_AT_RPATH -+libitm_darwin_rpath = -Wc,-nodefaultrpaths -+libitm_darwin_rpath += -Wl,-rpath,@loader_path -+endif -+libitm_la_LDFLAGS = $(libitm_version_info) $(libitm_version_script) \ -+ $(libitm_darwin_rpath) - - libitm_la_SOURCES = \ - aatree.cc alloc.cc alloc_c.cc alloc_cpp.cc barrier.cc beginend.cc \ -diff --git a/libitm/Makefile.in b/libitm/Makefile.in -index 7f53ea9b9db..ed28db45057 100644 ---- a/libitm/Makefile.in -+++ b/libitm/Makefile.in -@@ -481,7 +481,12 @@ libitm_version_info = -version-info $(libtool_VERSION) - # want or need libstdc++. - libitm_la_DEPENDENCIES = $(libitm_version_dep) - libitm_la_LINK = $(LINK) $(libitm_la_LDFLAGS) --libitm_la_LDFLAGS = $(libitm_version_info) $(libitm_version_script) -+@ENABLE_DARWIN_AT_RPATH_TRUE@libitm_darwin_rpath = \ -+@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ -+@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path -+libitm_la_LDFLAGS = $(libitm_version_info) $(libitm_version_script) \ -+ $(libitm_darwin_rpath) -+ - libitm_la_SOURCES = aatree.cc alloc.cc alloc_c.cc alloc_cpp.cc \ - barrier.cc beginend.cc clone.cc eh_cpp.cc local.cc query.cc \ - retry.cc rwlock.cc useraction.cc util.cc sjlj.S tls.cc \ -diff --git a/libitm/config/aarch64/sjlj.S b/libitm/config/aarch64/sjlj.S -index 296cb683a9f..941e886143e 100644 ---- a/libitm/config/aarch64/sjlj.S -+++ b/libitm/config/aarch64/sjlj.S -@@ -57,10 +57,19 @@ - - .text - .align 2 -+#if __ELF__ - .global _ITM_beginTransaction - .type _ITM_beginTransaction, %function - - _ITM_beginTransaction: -+ -+#elif __MACH__ -+ .global __ITM_beginTransaction -+ -+__ITM_beginTransaction: -+ -+#endif -+ - cfi_startproc - CFI_PAC_KEY - PAC_AND_BTI -@@ -84,8 +93,13 @@ _ITM_beginTransaction: - - /* Invoke GTM_begin_transaction with the struct we just built. */ - mov x1, sp -+#if __ELF__ - bl GTM_begin_transaction -- -+#elif __MACH__ -+ bl _GTM_begin_transaction -+#else -+#error "unexpected object format" -+#endif - /* Return; we don't need to restore any of the call-saved regs. */ - ldp x29, x30, [sp], 11*16 - cfi_adjust_cfa_offset(-11*16) -@@ -95,14 +109,23 @@ _ITM_beginTransaction: - CFI_PAC_TOGGLE - ret - cfi_endproc -+#if __ELF__ - .size _ITM_beginTransaction, . - _ITM_beginTransaction -+#endif - - .align 2 -+#if __ELF__ - .global GTM_longjmp - .hidden GTM_longjmp - .type GTM_longjmp, %function - - GTM_longjmp: -+ -+#elif __MACH__ -+ .private_extern _GTM_longjmp -+ -+_GTM_longjmp: -+#endif - /* The first parameter becomes the return value (x0). - The third parameter is ignored for now. */ - cfi_startproc -@@ -126,7 +149,9 @@ GTM_longjmp: - CFI_PAC_TOGGLE - br x30 - cfi_endproc -+#if __ELF__ - .size GTM_longjmp, . - GTM_longjmp -+#endif - - /* GNU_PROPERTY_AARCH64_* macros from elf.h for use in asm code. */ - #define FEATURE_1_AND 0xc0000000 -diff --git a/libitm/configure b/libitm/configure -index 18fc2d3a10a..5beb48a6b99 100755 ---- a/libitm/configure -+++ b/libitm/configure -@@ -660,6 +660,8 @@ libtool_VERSION - MAINT - MAINTAINER_MODE_FALSE - MAINTAINER_MODE_TRUE -+ENABLE_DARWIN_AT_RPATH_FALSE -+ENABLE_DARWIN_AT_RPATH_TRUE - enable_static - enable_shared - CXXCPP -@@ -810,6 +812,7 @@ with_pic - enable_fast_install - with_gnu_ld - enable_libtool_lock -+enable_darwin_at_rpath - enable_maintainer_mode - enable_linux_futex - enable_tls -@@ -1462,6 +1465,8 @@ Optional Features: - --enable-fast-install[=PKGS] - optimize for fast installation [default=yes] - --disable-libtool-lock avoid locking (might break parallel builds) -+ --enable-darwin-at-path install libraries with @rpath/library-name, requires -+ rpaths to be added to executables - --enable-maintainer-mode - enable make rules and dependencies not useful (and - sometimes confusing) to the casual installer -@@ -10252,6 +10257,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc=no - hardcode_direct=no - hardcode_automatic=yes -@@ -10269,10 +10315,19 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - - else - ld_shlibs=no -@@ -12058,7 +12113,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 12061 "configure" -+#line 12116 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -12164,7 +12219,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 12167 "configure" -+#line 12222 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -13040,6 +13095,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc_CXX=no - hardcode_direct_CXX=no - hardcode_automatic_CXX=yes -@@ -13057,12 +13153,25 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - if test "$lt_cv_apple_cc_single_mod" != "yes"; then -- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring${_lt_dsymutil}" -+ else -+ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" -+ fi - archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" - fi - -@@ -15414,6 +15523,14 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu - - - -+ if test x$enable_darwin_at_rpath = xyes; then -+ ENABLE_DARWIN_AT_RPATH_TRUE= -+ ENABLE_DARWIN_AT_RPATH_FALSE='#' -+else -+ ENABLE_DARWIN_AT_RPATH_TRUE='#' -+ ENABLE_DARWIN_AT_RPATH_FALSE= -+fi -+ - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5 -@@ -18172,6 +18289,10 @@ if test -z "${BUILD_INFO_TRUE}" && test -z "${BUILD_INFO_FALSE}"; then - as_fn_error $? "conditional \"BUILD_INFO\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 - fi -+if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then -+ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. -+Usually this means the macro was only invoked conditionally." "$LINENO" 5 -+fi - if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then - as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 -diff --git a/libitm/configure.ac b/libitm/configure.ac -index 78a682376d9..209a025a90e 100644 ---- a/libitm/configure.ac -+++ b/libitm/configure.ac -@@ -157,6 +157,7 @@ AM_CONDITIONAL(BUILD_INFO, test $gcc_cv_prog_makeinfo_modern = "yes") - AM_PROG_LIBTOOL - AC_SUBST(enable_shared) - AC_SUBST(enable_static) -+AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) - - AM_MAINTAINER_MODE - -diff --git a/libitm/configure.tgt b/libitm/configure.tgt -index 06e90973ef3..acaf4f85712 100644 ---- a/libitm/configure.tgt -+++ b/libitm/configure.tgt -@@ -50,7 +50,7 @@ fi - # Map the target cpu to an ARCH sub-directory. At the same time, - # work out any special compilation flags as necessary. - case "${target_cpu}" in -- aarch64*) ARCH=aarch64 ;; -+ aarch64* | arm64*) ARCH=aarch64 ;; - alpha*) ARCH=alpha ;; - rs6000 | powerpc*) - XCFLAGS="${XCFLAGS} -mhtm" -diff --git a/libitm/testsuite/lib/libitm.exp b/libitm/testsuite/lib/libitm.exp -index 6d8e3e71310..906534022eb 100644 ---- a/libitm/testsuite/lib/libitm.exp -+++ b/libitm/testsuite/lib/libitm.exp -@@ -158,6 +158,7 @@ proc libitm_init { args } { - } - - if [istarget *-*-darwin*] { -+ lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/.libs" - lappend ALWAYS_CFLAGS "additional_flags=-shared-libgcc" - } - -diff --git a/libitm/testsuite/libitm.c++/c++.exp b/libitm/testsuite/libitm.c++/c++.exp -index f92aa096104..295c5bd4703 100644 ---- a/libitm/testsuite/libitm.c++/c++.exp -+++ b/libitm/testsuite/libitm.c++/c++.exp -@@ -56,8 +56,10 @@ if { $lang_test_file_found } { - # Gather a list of all tests. - set tests [lsort [glob -nocomplain $srcdir/$subdir/*.C]] - -+ set stdcxxadder "" - if { $blddir != "" } { - set ld_library_path "$always_ld_library_path:${blddir}/${lang_library_path}" -+ set stdcxxadder "-B ${blddir}/${lang_library_path}" - } else { - set ld_library_path "$always_ld_library_path" - } -@@ -72,7 +74,7 @@ if { $lang_test_file_found } { - } - - # Main loop. -- dg-runtest $tests "" $libstdcxx_includes -+ dg-runtest $tests $stdcxxadder $libstdcxx_includes - } - - # All done. -diff --git a/libobjc/configure b/libobjc/configure -index 5d1b424a66d..21ac18723c3 100755 ---- a/libobjc/configure -+++ b/libobjc/configure -@@ -636,6 +636,9 @@ OBJC_BOEHM_GC_LIBS - OBJC_BOEHM_GC_INCLUDES - OBJC_BOEHM_GC - OBJC_GCFLAGS -+extra_ldflags_libobjc -+ENABLE_DARWIN_AT_RPATH_FALSE -+ENABLE_DARWIN_AT_RPATH_TRUE - SET_MAKE - CPP - OTOOL64 -@@ -667,7 +670,6 @@ RANLIB - AR - AS - XCFLAGS --extra_ldflags_libobjc - lt_host_flags - OBJEXT - EXEEXT -@@ -755,6 +757,7 @@ with_pic - enable_fast_install - with_gnu_ld - enable_libtool_lock -+enable_darwin_at_rpath - enable_tls - enable_objc_gc - with_target_bdw_gc -@@ -1392,6 +1395,8 @@ Optional Features: - --enable-fast-install[=PKGS] - optimize for fast installation [default=yes] - --disable-libtool-lock avoid locking (might break parallel builds) -+ --enable-darwin-at-path install libraries with @rpath/library-name, requires -+ rpaths to be added to executables - --enable-tls Use thread-local storage [default=yes] - --enable-objc-gc enable use of Boehm's garbage collector with the GNU - Objective-C runtime -@@ -3430,17 +3435,6 @@ esac - - - --case "${host}" in -- *-darwin*) -- # Darwin needs -single_module when linking libobjc -- extra_ldflags_libobjc='$(lt_host_flags) -Wl,-single_module' -- ;; -- *-cygwin*|*-mingw*) -- # Tell libtool to build DLLs on Windows -- extra_ldflags_libobjc='$(lt_host_flags)' -- ;; --esac -- - - # Add CET specific flags if CET is enabled - -@@ -3466,7 +3460,7 @@ case "$host" in - case "$enable_cet" in - auto) - # Check if target supports multi-byte NOPs -- # and if assembler supports CET insn. -+ # and if compiler and assembler support CET insn. - cet_save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS -fcf-protection" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -@@ -8944,6 +8938,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc=no - hardcode_direct=no - hardcode_automatic=yes -@@ -8961,10 +8996,19 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - - else - ld_shlibs=no -@@ -10771,7 +10815,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 10784 "configure" -+#line 10818 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -10877,7 +10921,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 10890 "configure" -+#line 10924 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -11149,6 +11193,38 @@ $as_echo "no" >&6; } - fi - - -+ if test x$enable_darwin_at_rpath = xyes; then -+ ENABLE_DARWIN_AT_RPATH_TRUE= -+ ENABLE_DARWIN_AT_RPATH_FALSE='#' -+else -+ ENABLE_DARWIN_AT_RPATH_TRUE='#' -+ ENABLE_DARWIN_AT_RPATH_FALSE= -+fi -+ -+ -+# Must come after libtool is initialized. -+case "${host}" in -+ *-darwin[4567]*) -+ # Earlier Darwin versions need -single_module when linking libobjc; they -+ # do not support @rpath. -+ extra_ldflags_libobjc='$(lt_host_flags) -Wl,-single_module' -+ ;; -+ *-darwin*) -+ # Otherwise, single_module is the default and multi-module is ignored and -+ # obsolete. -+ extra_ldflags_libobjc='$(lt_host_flags)' -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ extra_ldflags_libobjc="${extra_ldflags_libobjc} -Wc,-nodefaultrpaths" -+ extra_ldflags_libobjc="${extra_ldflags_libobjc} -Wl,-rpath,@loader_path" -+ fi -+ ;; -+ *-cygwin*|*-mingw*) -+ # Tell libtool to build DLLs on Windows -+ extra_ldflags_libobjc='$(lt_host_flags)' -+ ;; -+esac -+ -+ - # ------- - # Headers - # ------- -@@ -11890,6 +11966,10 @@ if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then - as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 - fi -+if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then -+ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. -+Usually this means the macro was only invoked conditionally." "$LINENO" 5 -+fi - - : "${CONFIG_STATUS=./config.status}" - ac_write_fail=0 -diff --git a/libobjc/configure.ac b/libobjc/configure.ac -index f8f577cfbef..2a9bf1fed4c 100644 ---- a/libobjc/configure.ac -+++ b/libobjc/configure.ac -@@ -147,17 +147,6 @@ m4_rename_force([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS]) - - # extra LD Flags which are required for targets - ACX_LT_HOST_FLAGS --case "${host}" in -- *-darwin*) -- # Darwin needs -single_module when linking libobjc -- extra_ldflags_libobjc='$(lt_host_flags) -Wl,-single_module' -- ;; -- *-cygwin*|*-mingw*) -- # Tell libtool to build DLLs on Windows -- extra_ldflags_libobjc='$(lt_host_flags)' -- ;; --esac --AC_SUBST(extra_ldflags_libobjc) - - # Add CET specific flags if CET is enabled - GCC_CET_FLAGS(CET_FLAGS) -@@ -182,6 +171,31 @@ AM_PROG_CC_C_O - - AC_PROG_MAKE_SET - -+AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) -+ -+# Must come after libtool is initialized. -+case "${host}" in -+ *-darwin[[4567]]*) -+ # Earlier Darwin versions need -single_module when linking libobjc; they -+ # do not support @rpath. -+ extra_ldflags_libobjc='$(lt_host_flags) -Wl,-single_module' -+ ;; -+ *-darwin*) -+ # Otherwise, single_module is the default and multi-module is ignored and -+ # obsolete. -+ extra_ldflags_libobjc='$(lt_host_flags)' -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ extra_ldflags_libobjc="${extra_ldflags_libobjc} -Wc,-nodefaultrpaths" -+ extra_ldflags_libobjc="${extra_ldflags_libobjc} -Wl,-rpath,@loader_path" -+ fi -+ ;; -+ *-cygwin*|*-mingw*) -+ # Tell libtool to build DLLs on Windows -+ extra_ldflags_libobjc='$(lt_host_flags)' -+ ;; -+esac -+AC_SUBST(extra_ldflags_libobjc) -+ - # ------- - # Headers - # ------- -diff --git a/liboffloadmic/configure b/liboffloadmic/configure -index dfa8287fd75..84447cbb7eb 100755 ---- a/liboffloadmic/configure -+++ b/liboffloadmic/configure -@@ -639,6 +639,8 @@ link_offloadmic_host - lt_cv_dlopen_libs - toolexeclibdir - toolexecdir -+ENABLE_DARWIN_AT_RPATH_FALSE -+ENABLE_DARWIN_AT_RPATH_TRUE - CXXCPP - OTOOL64 - OTOOL -@@ -782,6 +784,7 @@ with_pic - enable_fast_install - with_gnu_ld - enable_libtool_lock -+enable_darwin_at_rpath - with_gcc_major_version_only - ' - ac_precious_vars='build_alias -@@ -1434,6 +1437,8 @@ Optional Features: - --enable-fast-install[=PKGS] - optimize for fast installation [default=yes] - --disable-libtool-lock avoid locking (might break parallel builds) -+ --enable-darwin-at-path install libraries with @rpath/library-name, requires -+ rpaths to be added to executables - - Optional Packages: - --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] -@@ -7900,23 +7905,25 @@ _LT_EOF - fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_force_load" >&5 - $as_echo "$lt_cv_ld_force_load" >&6; } -- case $host_os in -- rhapsody* | darwin1.[012]) -+ # Allow for Darwin 4-7 (macOS 10.0-10.3) although these are not expect to -+ # build without first building modern cctools / linker. -+ case $host_cpu-$host_os in -+ *-rhapsody* | *-darwin1.[012]) - _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;; -- darwin1.*) -+ *-darwin1.*) - _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; -- darwin*) # darwin 5.x on -- # if running on 10.5 or later, the deployment target defaults -- # to the OS version, if on x86, and 10.4, the deployment -- # target defaults to 10.4. Don't you love it? -- case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in -- 10.0,*86*-darwin8*|10.0,*-darwin[91]*) -- _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; -+ *-darwin*) -+ # darwin 5.x (macOS 10.1) onwards we only need to adjust when the -+ # deployment target is forced to an earlier version. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in -+ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) -+ ;; - 10.[012][,.]*) -- _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; -- 10.*) -- _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; -- esac -+ _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' -+ ;; -+ *) -+ ;; -+ esac - ;; - esac - if test "$lt_cv_apple_cc_single_mod" = "yes"; then -@@ -9614,6 +9621,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc=no - hardcode_direct=no - hardcode_automatic=yes -@@ -9631,10 +9679,19 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - - else - ld_shlibs=no -@@ -11420,7 +11477,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 11433 "configure" -+#line 11480 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -11526,7 +11583,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 11539 "configure" -+#line 11586 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -12402,6 +12459,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc_CXX=no - hardcode_direct_CXX=no - hardcode_automatic_CXX=yes -@@ -12419,12 +12517,25 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - if test "$lt_cv_apple_cc_single_mod" != "yes"; then -- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring${_lt_dsymutil}" -+ else -+ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" -+ fi - archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" - fi - -@@ -14265,16 +14376,6 @@ freebsd* | dragonfly*) - esac - ;; - --gnu*) -- version_type=linux -- need_lib_prefix=no -- need_version=no -- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' -- soname_spec='${libname}${release}${shared_ext}$major' -- shlibpath_var=LD_LIBRARY_PATH -- hardcode_into_libs=yes -- ;; -- - haiku*) - version_type=linux - need_lib_prefix=no -@@ -14396,7 +14497,7 @@ linux*oldld* | linux*aout* | linux*coff*) - # project, but have not yet been accepted: they are GCC-local changes - # for the time being. (See - # https://lists.gnu.org/archive/html/libtool-patches/2018-05/msg00000.html) --linux* | k*bsd*-gnu | kopensolaris*-gnu | uclinuxfdpiceabi) -+linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu* | uclinuxfdpiceabi) - version_type=linux - need_lib_prefix=no - need_version=no -@@ -14784,6 +14885,15 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu - # Only expand once: - - -+ if test x$enable_darwin_at_rpath = xyes; then -+ ENABLE_DARWIN_AT_RPATH_TRUE= -+ ENABLE_DARWIN_AT_RPATH_FALSE='#' -+else -+ ENABLE_DARWIN_AT_RPATH_TRUE='#' -+ ENABLE_DARWIN_AT_RPATH_FALSE= -+fi -+ -+ - # Forbid libtool to hardcode RPATH, because we want to be able to specify - # library search directory using LD_LIBRARY_PATH - hardcode_into_libs=no -@@ -14999,6 +15109,10 @@ if test -z "${LIBOFFLOADMIC_HOST_TRUE}" && test -z "${LIBOFFLOADMIC_HOST_FALSE}" - as_fn_error $? "conditional \"LIBOFFLOADMIC_HOST\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 - fi -+if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then -+ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. -+Usually this means the macro was only invoked conditionally." "$LINENO" 5 -+fi - - : "${CONFIG_STATUS=./config.status}" - ac_write_fail=0 -diff --git a/liboffloadmic/configure.ac b/liboffloadmic/configure.ac -index f64f182e8ef..b96e7eaf9e3 100644 ---- a/liboffloadmic/configure.ac -+++ b/liboffloadmic/configure.ac -@@ -118,6 +118,8 @@ esac - - AC_LIBTOOL_DLOPEN - AM_PROG_LIBTOOL -+AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) -+ - # Forbid libtool to hardcode RPATH, because we want to be able to specify - # library search directory using LD_LIBRARY_PATH - hardcode_into_libs=no -diff --git a/liboffloadmic/plugin/Makefile.in b/liboffloadmic/plugin/Makefile.in -index 8d5ad0025c2..c53f2d32b3b 100644 ---- a/liboffloadmic/plugin/Makefile.in -+++ b/liboffloadmic/plugin/Makefile.in -@@ -123,10 +123,10 @@ subdir = . - ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 - am__aclocal_m4_deps = $(top_srcdir)/../../config/acx.m4 \ - $(top_srcdir)/../../config/depstand.m4 \ -- $(top_srcdir)/../../config/toolexeclibdir.m4 \ - $(top_srcdir)/../../config/lead-dot.m4 \ - $(top_srcdir)/../../config/multi.m4 \ - $(top_srcdir)/../../config/override.m4 \ -+ $(top_srcdir)/../../config/toolexeclibdir.m4 \ - $(top_srcdir)/../../libtool.m4 \ - $(top_srcdir)/../../ltoptions.m4 \ - $(top_srcdir)/../../ltsugar.m4 \ -diff --git a/liboffloadmic/plugin/aclocal.m4 b/liboffloadmic/plugin/aclocal.m4 -index 9fa1d1216c1..1bb91402f66 100644 ---- a/liboffloadmic/plugin/aclocal.m4 -+++ b/liboffloadmic/plugin/aclocal.m4 -@@ -1169,10 +1169,10 @@ AC_SUBST([am__untar]) - - m4_include([../../config/acx.m4]) - m4_include([../../config/depstand.m4]) --m4_include([../../config/toolexeclibdir.m4]) - m4_include([../../config/lead-dot.m4]) - m4_include([../../config/multi.m4]) - m4_include([../../config/override.m4]) -+m4_include([../../config/toolexeclibdir.m4]) - m4_include([../../libtool.m4]) - m4_include([../../ltoptions.m4]) - m4_include([../../ltsugar.m4]) -diff --git a/liboffloadmic/plugin/configure b/liboffloadmic/plugin/configure -index 0b21d7d4eed..a9416401a65 100755 ---- a/liboffloadmic/plugin/configure -+++ b/liboffloadmic/plugin/configure -@@ -635,6 +635,8 @@ LIBOBJS - get_gcc_base_ver - toolexeclibdir - toolexecdir -+ENABLE_DARWIN_AT_RPATH_FALSE -+ENABLE_DARWIN_AT_RPATH_TRUE - CXXCPP - CPP - OTOOL64 -@@ -778,6 +780,7 @@ with_pic - enable_fast_install - with_gnu_ld - enable_libtool_lock -+enable_darwin_at_rpath - with_gcc_major_version_only - ' - ac_precious_vars='build_alias -@@ -1431,6 +1434,8 @@ Optional Features: - --enable-fast-install[=PKGS] - optimize for fast installation [default=yes] - --disable-libtool-lock avoid locking (might break parallel builds) -+ --enable-darwin-at-path install libraries with @rpath/library-name, requires -+ rpaths to be added to executables - - Optional Packages: - --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] -@@ -7280,23 +7285,25 @@ _LT_EOF - fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_force_load" >&5 - $as_echo "$lt_cv_ld_force_load" >&6; } -- case $host_os in -- rhapsody* | darwin1.[012]) -+ # Allow for Darwin 4-7 (macOS 10.0-10.3) although these are not expect to -+ # build without first building modern cctools / linker. -+ case $host_cpu-$host_os in -+ *-rhapsody* | *-darwin1.[012]) - _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;; -- darwin1.*) -+ *-darwin1.*) - _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; -- darwin*) # darwin 5.x on -- # if running on 10.5 or later, the deployment target defaults -- # to the OS version, if on x86, and 10.4, the deployment -- # target defaults to 10.4. Don't you love it? -- case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in -- 10.0,*86*-darwin8*|10.0,*-darwin[91]*) -- _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; -+ *-darwin*) -+ # darwin 5.x (macOS 10.1) onwards we only need to adjust when the -+ # deployment target is forced to an earlier version. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in -+ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) -+ ;; - 10.[012][,.]*) -- _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; -- 10.*) -- _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; -- esac -+ _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' -+ ;; -+ *) -+ ;; -+ esac - ;; - esac - if test "$lt_cv_apple_cc_single_mod" = "yes"; then -@@ -9261,6 +9268,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc=no - hardcode_direct=no - hardcode_automatic=yes -@@ -9278,10 +9326,19 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - - else - ld_shlibs=no -@@ -11067,7 +11124,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 11080 "configure" -+#line 11127 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -11173,7 +11230,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 11186 "configure" -+#line 11233 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -12049,6 +12106,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc_CXX=no - hardcode_direct_CXX=no - hardcode_automatic_CXX=yes -@@ -12066,12 +12164,25 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - if test "$lt_cv_apple_cc_single_mod" != "yes"; then -- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring${_lt_dsymutil}" -+ else -+ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" -+ fi - archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" - fi - -@@ -13912,16 +14023,6 @@ freebsd* | dragonfly*) - esac - ;; - --gnu*) -- version_type=linux -- need_lib_prefix=no -- need_version=no -- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' -- soname_spec='${libname}${release}${shared_ext}$major' -- shlibpath_var=LD_LIBRARY_PATH -- hardcode_into_libs=yes -- ;; -- - haiku*) - version_type=linux - need_lib_prefix=no -@@ -14043,7 +14144,7 @@ linux*oldld* | linux*aout* | linux*coff*) - # project, but have not yet been accepted: they are GCC-local changes - # for the time being. (See - # https://lists.gnu.org/archive/html/libtool-patches/2018-05/msg00000.html) --linux* | k*bsd*-gnu | kopensolaris*-gnu | uclinuxfdpiceabi) -+linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu* | uclinuxfdpiceabi) - version_type=linux - need_lib_prefix=no - need_version=no -@@ -14431,6 +14532,15 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu - # Only expand once: - - -+ if test x$enable_darwin_at_rpath = xyes; then -+ ENABLE_DARWIN_AT_RPATH_TRUE= -+ ENABLE_DARWIN_AT_RPATH_FALSE='#' -+else -+ ENABLE_DARWIN_AT_RPATH_TRUE='#' -+ ENABLE_DARWIN_AT_RPATH_FALSE= -+fi -+ -+ - # Forbid libtool to hardcode RPATH, because we want to be able to specify - # library search directory using LD_LIBRARY_PATH - hardcode_into_libs=no -@@ -14634,6 +14744,10 @@ if test -z "${PLUGIN_HOST_TRUE}" && test -z "${PLUGIN_HOST_FALSE}"; then - as_fn_error $? "conditional \"PLUGIN_HOST\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 - fi -+if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then -+ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. -+Usually this means the macro was only invoked conditionally." "$LINENO" 5 -+fi - - : "${CONFIG_STATUS=./config.status}" - ac_write_fail=0 -diff --git a/liboffloadmic/plugin/configure.ac b/liboffloadmic/plugin/configure.ac -index cbcd0130d05..3329b03638d 100644 ---- a/liboffloadmic/plugin/configure.ac -+++ b/liboffloadmic/plugin/configure.ac -@@ -134,6 +134,8 @@ esac - - AC_LIBTOOL_DLOPEN - AM_PROG_LIBTOOL -+AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) -+ - # Forbid libtool to hardcode RPATH, because we want to be able to specify - # library search directory using LD_LIBRARY_PATH - hardcode_into_libs=no -diff --git a/libphobos/configure b/libphobos/configure -index 9da06f087d0..9fbb3c91e93 100755 ---- a/libphobos/configure -+++ b/libphobos/configure -@@ -707,6 +707,8 @@ get_gcc_base_ver - phobos_compiler_shared_flag - phobos_compiler_pic_flag - phobos_lt_pic_flag -+ENABLE_DARWIN_AT_RPATH_FALSE -+ENABLE_DARWIN_AT_RPATH_TRUE - enable_static - enable_shared - OTOOL64 -@@ -838,6 +840,7 @@ with_pic - enable_fast_install - with_gnu_ld - enable_libtool_lock -+enable_darwin_at_rpath - with_gcc_major_version_only - enable_werror - with_libatomic -@@ -1490,6 +1493,8 @@ Optional Features: - --enable-fast-install[=PKGS] - optimize for fast installation [default=yes] - --disable-libtool-lock avoid locking (might break parallel builds) -+ --enable-darwin-at-path install libraries with @rpath/library-name, requires -+ rpaths to be added to executables - --enable-werror turns on -Werror [default=no] - --enable-version-specific-runtime-libs - Specify that runtime libraries should be installed -@@ -9944,6 +9949,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc=no - hardcode_direct=no - hardcode_automatic=yes -@@ -9961,10 +10007,19 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - - else - ld_shlibs=no -@@ -11750,7 +11805,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 11753 "configure" -+#line 11808 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -11856,7 +11911,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 11859 "configure" -+#line 11914 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -13381,6 +13436,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc_D=no - hardcode_direct_D=no - hardcode_automatic_D=yes -@@ -13398,10 +13494,19 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds_D="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds_D="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds_D="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds_D="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds_D="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds_D="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_D="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_D="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds_D="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds_D="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_D="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_D="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - - else - ld_shlibs_D=no -@@ -14002,6 +14107,14 @@ CFLAGS=$lt_save_CFLAGS - - - -+ if test x$enable_darwin_at_rpath = xyes; then -+ ENABLE_DARWIN_AT_RPATH_TRUE= -+ ENABLE_DARWIN_AT_RPATH_FALSE='#' -+else -+ ENABLE_DARWIN_AT_RPATH_TRUE='#' -+ ENABLE_DARWIN_AT_RPATH_FALSE= -+fi -+ - - # libtool variables for Phobos shared and position-independent compiles. - # -@@ -15726,6 +15839,10 @@ if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then - as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 - fi -+if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then -+ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. -+Usually this means the macro was only invoked conditionally." "$LINENO" 5 -+fi - if test -z "${DRUNTIME_CPU_AARCH64_TRUE}" && test -z "${DRUNTIME_CPU_AARCH64_FALSE}"; then - as_fn_error $? "conditional \"DRUNTIME_CPU_AARCH64\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 -diff --git a/libphobos/configure.ac b/libphobos/configure.ac -index 31209ba2920..cc372587939 100644 ---- a/libphobos/configure.ac -+++ b/libphobos/configure.ac -@@ -93,6 +93,7 @@ AM_PROG_LIBTOOL - WITH_LOCAL_DRUNTIME([LT_LANG([D])], []) - AC_SUBST(enable_shared) - AC_SUBST(enable_static) -+AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) - - # libtool variables for Phobos shared and position-independent compiles. - # -diff --git a/libphobos/libdruntime/Makefile.am b/libphobos/libdruntime/Makefile.am -index 6ca4012b713..861ec0ebc03 100644 ---- a/libphobos/libdruntime/Makefile.am -+++ b/libphobos/libdruntime/Makefile.am -@@ -128,8 +128,11 @@ ALL_DRUNTIME_SOURCES = $(DRUNTIME_DSOURCES) $(DRUNTIME_CSOURCES) \ - toolexeclib_LTLIBRARIES = libgdruntime.la - libgdruntime_la_SOURCES = $(ALL_DRUNTIME_SOURCES) - libgdruntime_la_LIBTOOLFLAGS = -+if ENABLE_DARWIN_AT_RPATH -+libgdruntime_darwin_rpath = -Wl,-rpath,@loader_path -+endif - libgdruntime_la_LDFLAGS = -Wc,-nophoboslib,-dstartfiles,-B../src,-Bgcc \ -- -version-info $(libtool_VERSION) -+ -version-info $(libtool_VERSION) $(libgdruntime_darwin_rpath) - libgdruntime_la_LIBADD = $(LIBATOMIC) $(LIBBACKTRACE) - libgdruntime_la_DEPENDENCIES = $(DRTSTUFF) - # Also override library link commands: This is not strictly -diff --git a/libphobos/libdruntime/Makefile.in b/libphobos/libdruntime/Makefile.in -index f7f78d71ff7..9f3361c7702 100644 ---- a/libphobos/libdruntime/Makefile.in -+++ b/libphobos/libdruntime/Makefile.in -@@ -805,8 +805,9 @@ ALL_DRUNTIME_SOURCES = $(DRUNTIME_DSOURCES) $(DRUNTIME_CSOURCES) \ - toolexeclib_LTLIBRARIES = libgdruntime.la - libgdruntime_la_SOURCES = $(ALL_DRUNTIME_SOURCES) - libgdruntime_la_LIBTOOLFLAGS = -+@ENABLE_DARWIN_AT_RPATH_TRUE@libgdruntime_darwin_rpath = -Wl,-rpath,@loader_path - libgdruntime_la_LDFLAGS = -Wc,-nophoboslib,-dstartfiles,-B../src,-Bgcc \ -- -version-info $(libtool_VERSION) -+ -version-info $(libtool_VERSION) $(libgdruntime_darwin_rpath) - - libgdruntime_la_LIBADD = $(LIBATOMIC) $(LIBBACKTRACE) - libgdruntime_la_DEPENDENCIES = $(DRTSTUFF) -diff --git a/libphobos/src/Makefile.am b/libphobos/src/Makefile.am -index da7a2004ff8..a47d985c5b7 100644 ---- a/libphobos/src/Makefile.am -+++ b/libphobos/src/Makefile.am -@@ -44,8 +44,11 @@ toolexeclib_DATA = libgphobos.spec - toolexeclib_LTLIBRARIES = libgphobos.la - libgphobos_la_SOURCES = $(ALL_PHOBOS_SOURCES) - libgphobos_la_LIBTOOLFLAGS = -+if ENABLE_DARWIN_AT_RPATH -+libgphobos_darwin_rpath = -Wl,-rpath,@loader_path -+endif - libgphobos_la_LDFLAGS = -Wc,-nophoboslib,-dstartfiles,-B../libdruntime/gcc \ -- -version-info $(libtool_VERSION) -+ -version-info $(libtool_VERSION) $(libgphobos_darwin_rpath) - if ENABLE_LIBDRUNTIME_ONLY - libgphobos_la_LIBADD = ../libdruntime/libgdruntime_convenience.la - else -diff --git a/libphobos/src/Makefile.in b/libphobos/src/Makefile.in -index 6f58fee01ac..212ea2469f2 100644 ---- a/libphobos/src/Makefile.in -+++ b/libphobos/src/Makefile.in -@@ -528,8 +528,9 @@ toolexeclib_DATA = libgphobos.spec - toolexeclib_LTLIBRARIES = libgphobos.la - libgphobos_la_SOURCES = $(ALL_PHOBOS_SOURCES) - libgphobos_la_LIBTOOLFLAGS = -+@ENABLE_DARWIN_AT_RPATH_TRUE@libgphobos_darwin_rpath = -Wl,-rpath,@loader_path - libgphobos_la_LDFLAGS = -Wc,-nophoboslib,-dstartfiles,-B../libdruntime/gcc \ -- -version-info $(libtool_VERSION) -+ -version-info $(libtool_VERSION) $(libgphobos_darwin_rpath) - - @ENABLE_LIBDRUNTIME_ONLY_FALSE@libgphobos_la_LIBADD = \ - @ENABLE_LIBDRUNTIME_ONLY_FALSE@ ../libdruntime/libgdruntime_convenience.la $(LIBZ) -diff --git a/libquadmath/Makefile.am b/libquadmath/Makefile.am -index 35dffb46f6e..4bf4bf6eebc 100644 ---- a/libquadmath/Makefile.am -+++ b/libquadmath/Makefile.am -@@ -36,8 +36,13 @@ endif - - toolexeclib_LTLIBRARIES = libquadmath.la - libquadmath_la_LIBADD = -+ -+if ENABLE_DARWIN_AT_RPATH -+libquadmath_darwin_rpath = -Wc,-nodefaultrpaths -+libquadmath_darwin_rpath += -Wl,-rpath,@loader_path -+endif - libquadmath_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ -- $(version_arg) $(lt_host_flags) -lm -+ $(version_arg) $(lt_host_flags) $(LIBM) $(libquadmath_darwin_rpath) - libquadmath_la_DEPENDENCIES = $(version_dep) $(libquadmath_la_LIBADD) - - nodist_libsubinclude_HEADERS = quadmath.h quadmath_weak.h -diff --git a/libquadmath/Makefile.in b/libquadmath/Makefile.in -index 8c011212258..b59aac7f1ac 100644 ---- a/libquadmath/Makefile.in -+++ b/libquadmath/Makefile.in -@@ -355,6 +355,7 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ - INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ - LD = @LD@ - LDFLAGS = @LDFLAGS@ -+LIBM = @LIBM@ - LIBOBJS = @LIBOBJS@ - LIBS = @LIBS@ - LIBTOOL = @LIBTOOL@ -@@ -463,8 +464,10 @@ AUTOMAKE_OPTIONS = foreign info-in-builddir - @BUILD_LIBQUADMATH_TRUE@@LIBQUAD_USE_SYMVER_SUN_TRUE@@LIBQUAD_USE_SYMVER_TRUE@version_dep = quadmath.map-sun - @BUILD_LIBQUADMATH_TRUE@toolexeclib_LTLIBRARIES = libquadmath.la - @BUILD_LIBQUADMATH_TRUE@libquadmath_la_LIBADD = -+@BUILD_LIBQUADMATH_TRUE@@ENABLE_DARWIN_AT_RPATH_TRUE@libquadmath_darwin_rpath = -Wc,-nodefaultrpaths \ -+@BUILD_LIBQUADMATH_TRUE@@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path - @BUILD_LIBQUADMATH_TRUE@libquadmath_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ --@BUILD_LIBQUADMATH_TRUE@ $(version_arg) $(lt_host_flags) -lm -+@BUILD_LIBQUADMATH_TRUE@ $(version_arg) $(lt_host_flags) $(LIBM) $(libquadmath_darwin_rpath) - - @BUILD_LIBQUADMATH_TRUE@libquadmath_la_DEPENDENCIES = $(version_dep) $(libquadmath_la_LIBADD) - @BUILD_LIBQUADMATH_TRUE@nodist_libsubinclude_HEADERS = quadmath.h quadmath_weak.h -diff --git a/libquadmath/configure b/libquadmath/configure -index b3ee64f9c7d..23a99be108f 100755 ---- a/libquadmath/configure -+++ b/libquadmath/configure -@@ -644,11 +644,14 @@ LIBQUAD_USE_SYMVER_GNU_FALSE - LIBQUAD_USE_SYMVER_GNU_TRUE - LIBQUAD_USE_SYMVER_FALSE - LIBQUAD_USE_SYMVER_TRUE -+LIBM - toolexeclibdir - toolexecdir - MAINT - MAINTAINER_MODE_FALSE - MAINTAINER_MODE_TRUE -+ENABLE_DARWIN_AT_RPATH_FALSE -+ENABLE_DARWIN_AT_RPATH_TRUE - enable_static - enable_shared - lt_host_flags -@@ -785,6 +788,7 @@ with_pic - enable_fast_install - with_gnu_ld - enable_libtool_lock -+enable_darwin_at_rpath - enable_maintainer_mode - with_toolexeclibdir - enable_symvers -@@ -1435,6 +1439,8 @@ Optional Features: - --enable-fast-install[=PKGS] - optimize for fast installation [default=yes] - --disable-libtool-lock avoid locking (might break parallel builds) -+ --enable-darwin-at-path install libraries with @rpath/library-name, requires -+ rpaths to be added to executables - --enable-maintainer-mode - enable make rules and dependencies not useful (and - sometimes confusing) to the casual installer -@@ -8979,6 +8985,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc=no - hardcode_direct=no - hardcode_automatic=yes -@@ -8996,10 +9043,19 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - - else - ld_shlibs=no -@@ -10806,7 +10862,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 10819 "configure" -+#line 10865 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -10912,7 +10968,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 10925 "configure" -+#line 10971 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -11173,6 +11229,14 @@ esac - - - -+ if test x$enable_darwin_at_rpath = xyes; then -+ ENABLE_DARWIN_AT_RPATH_TRUE= -+ ENABLE_DARWIN_AT_RPATH_FALSE='#' -+else -+ ENABLE_DARWIN_AT_RPATH_TRUE='#' -+ ENABLE_DARWIN_AT_RPATH_FALSE= -+fi -+ - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5 -@@ -12137,6 +12201,148 @@ esac - - - -+LIBM= -+case $host in -+*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-haiku* | *-*-pw32* | *-*-darwin*) -+ # These system don't have libm, or don't need it -+ ;; -+*-ncr-sysv4.3*) -+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for _mwvalidcheckl in -lmw" >&5 -+$as_echo_n "checking for _mwvalidcheckl in -lmw... " >&6; } -+if ${ac_cv_lib_mw__mwvalidcheckl+:} false; then : -+ $as_echo_n "(cached) " >&6 -+else -+ ac_check_lib_save_LIBS=$LIBS -+LIBS="-lmw $LIBS" -+if test x$gcc_no_link = xyes; then -+ as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5 -+fi -+cat confdefs.h - <<_ACEOF >conftest.$ac_ext -+/* end confdefs.h. */ -+ -+/* Override any GCC internal prototype to avoid an error. -+ Use char because int might match the return type of a GCC -+ builtin and then its argument prototype would still apply. */ -+#ifdef __cplusplus -+extern "C" -+#endif -+char _mwvalidcheckl (); -+int -+main () -+{ -+return _mwvalidcheckl (); -+ ; -+ return 0; -+} -+_ACEOF -+if ac_fn_c_try_link "$LINENO"; then : -+ ac_cv_lib_mw__mwvalidcheckl=yes -+else -+ ac_cv_lib_mw__mwvalidcheckl=no -+fi -+rm -f core conftest.err conftest.$ac_objext \ -+ conftest$ac_exeext conftest.$ac_ext -+LIBS=$ac_check_lib_save_LIBS -+fi -+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_mw__mwvalidcheckl" >&5 -+$as_echo "$ac_cv_lib_mw__mwvalidcheckl" >&6; } -+if test "x$ac_cv_lib_mw__mwvalidcheckl" = xyes; then : -+ LIBM="-lmw" -+fi -+ -+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for cos in -lm" >&5 -+$as_echo_n "checking for cos in -lm... " >&6; } -+if ${ac_cv_lib_m_cos+:} false; then : -+ $as_echo_n "(cached) " >&6 -+else -+ ac_check_lib_save_LIBS=$LIBS -+LIBS="-lm $LIBS" -+if test x$gcc_no_link = xyes; then -+ as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5 -+fi -+cat confdefs.h - <<_ACEOF >conftest.$ac_ext -+/* end confdefs.h. */ -+ -+/* Override any GCC internal prototype to avoid an error. -+ Use char because int might match the return type of a GCC -+ builtin and then its argument prototype would still apply. */ -+#ifdef __cplusplus -+extern "C" -+#endif -+char cos (); -+int -+main () -+{ -+return cos (); -+ ; -+ return 0; -+} -+_ACEOF -+if ac_fn_c_try_link "$LINENO"; then : -+ ac_cv_lib_m_cos=yes -+else -+ ac_cv_lib_m_cos=no -+fi -+rm -f core conftest.err conftest.$ac_objext \ -+ conftest$ac_exeext conftest.$ac_ext -+LIBS=$ac_check_lib_save_LIBS -+fi -+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_m_cos" >&5 -+$as_echo "$ac_cv_lib_m_cos" >&6; } -+if test "x$ac_cv_lib_m_cos" = xyes; then : -+ LIBM="$LIBM -lm" -+fi -+ -+ ;; -+*) -+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for cos in -lm" >&5 -+$as_echo_n "checking for cos in -lm... " >&6; } -+if ${ac_cv_lib_m_cos+:} false; then : -+ $as_echo_n "(cached) " >&6 -+else -+ ac_check_lib_save_LIBS=$LIBS -+LIBS="-lm $LIBS" -+if test x$gcc_no_link = xyes; then -+ as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5 -+fi -+cat confdefs.h - <<_ACEOF >conftest.$ac_ext -+/* end confdefs.h. */ -+ -+/* Override any GCC internal prototype to avoid an error. -+ Use char because int might match the return type of a GCC -+ builtin and then its argument prototype would still apply. */ -+#ifdef __cplusplus -+extern "C" -+#endif -+char cos (); -+int -+main () -+{ -+return cos (); -+ ; -+ return 0; -+} -+_ACEOF -+if ac_fn_c_try_link "$LINENO"; then : -+ ac_cv_lib_m_cos=yes -+else -+ ac_cv_lib_m_cos=no -+fi -+rm -f core conftest.err conftest.$ac_objext \ -+ conftest$ac_exeext conftest.$ac_ext -+LIBS=$ac_check_lib_save_LIBS -+fi -+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_m_cos" >&5 -+$as_echo "$ac_cv_lib_m_cos" >&6; } -+if test "x$ac_cv_lib_m_cos" = xyes; then : -+ LIBM="-lm" -+fi -+ -+ ;; -+esac -+ -+ -+ - for ac_header in fenv.h langinfo.h locale.h wchar.h wctype.h limits.h ctype.h printf.h errno.h - do : - as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -@@ -13031,7 +13237,7 @@ case "$host" in - case "$enable_cet" in - auto) - # Check if target supports multi-byte NOPs -- # and if assembler supports CET insn. -+ # and if compiler and assembler support CET insn. - cet_save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS -fcf-protection" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -@@ -13397,6 +13603,10 @@ if test -z "${BUILD_INFO_TRUE}" && test -z "${BUILD_INFO_FALSE}"; then - as_fn_error $? "conditional \"BUILD_INFO\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 - fi -+if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then -+ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. -+Usually this means the macro was only invoked conditionally." "$LINENO" 5 -+fi - if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then - as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 -diff --git a/libquadmath/configure.ac b/libquadmath/configure.ac -index eec4084a45f..94a3f2179e9 100644 ---- a/libquadmath/configure.ac -+++ b/libquadmath/configure.ac -@@ -59,6 +59,7 @@ AM_PROG_LIBTOOL - ACX_LT_HOST_FLAGS - AC_SUBST(enable_shared) - AC_SUBST(enable_static) -+AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) - - AM_MAINTAINER_MODE - -@@ -121,6 +122,8 @@ esac - AC_SUBST(toolexecdir) - AC_SUBST(toolexeclibdir) - -+AC_CHECK_LIBM -+ - AC_CHECK_HEADERS(fenv.h langinfo.h locale.h wchar.h wctype.h limits.h ctype.h printf.h errno.h) - LIBQUAD_CHECK_MATH_H_SIGNGAM - -diff --git a/libsanitizer/Makefile.in b/libsanitizer/Makefile.in -index aab88deb6e8..65e7f2e9553 100644 ---- a/libsanitizer/Makefile.in -+++ b/libsanitizer/Makefile.in -@@ -345,7 +345,6 @@ pdfdir = @pdfdir@ - prefix = @prefix@ - program_transform_name = @program_transform_name@ - psdir = @psdir@ --runstatedir = @runstatedir@ - sbindir = @sbindir@ - sharedstatedir = @sharedstatedir@ - srcdir = @srcdir@ -diff --git a/libsanitizer/asan/Makefile.am b/libsanitizer/asan/Makefile.am -index 4f802f723d6..223d3e07816 100644 ---- a/libsanitizer/asan/Makefile.am -+++ b/libsanitizer/asan/Makefile.am -@@ -60,7 +60,12 @@ libasan_la_LIBADD += $(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la - endif - libasan_la_LIBADD += $(LIBSTDCXX_RAW_CXX_LDFLAGS) - --libasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libasan) -+if ENABLE_DARWIN_AT_RPATH -+libasan_darwin_rpath = -Wc,-nodefaultrpaths -+libasan_darwin_rpath += -Wl,-rpath,@loader_path -+endif -+libasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ -+ $(link_libasan) $(libasan_darwin_rpath) - - libasan_preinit.o: asan_preinit.o - cp $< $@ -diff --git a/libsanitizer/asan/Makefile.in b/libsanitizer/asan/Makefile.in -index 2476fbc5a26..e88e5e0b0a7 100644 ---- a/libsanitizer/asan/Makefile.in -+++ b/libsanitizer/asan/Makefile.in -@@ -399,7 +399,6 @@ pdfdir = @pdfdir@ - prefix = @prefix@ - program_transform_name = @program_transform_name@ - psdir = @psdir@ --runstatedir = @runstatedir@ - sbindir = @sbindir@ - sharedstatedir = @sharedstatedir@ - srcdir = @srcdir@ -@@ -466,7 +465,12 @@ libasan_la_LIBADD = \ - $(top_builddir)/sanitizer_common/libsanitizer_common.la \ - $(top_builddir)/lsan/libsanitizer_lsan.la $(am__append_2) \ - $(am__append_3) $(LIBSTDCXX_RAW_CXX_LDFLAGS) --libasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libasan) -+@ENABLE_DARWIN_AT_RPATH_TRUE@libasan_darwin_rpath = \ -+@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ -+@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path -+libasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ -+ $(link_libasan) $(libasan_darwin_rpath) -+ - - # Work around what appears to be a GNU make bug handling MAKEFLAGS - # values defined in terms of make variables, as is the case for CC and -diff --git a/libsanitizer/configure b/libsanitizer/configure -index 771b135573a..dfd99e34288 100755 ---- a/libsanitizer/configure -+++ b/libsanitizer/configure -@@ -666,6 +666,8 @@ LSAN_SUPPORTED_FALSE - LSAN_SUPPORTED_TRUE - TSAN_SUPPORTED_FALSE - TSAN_SUPPORTED_TRUE -+ENABLE_DARWIN_AT_RPATH_FALSE -+ENABLE_DARWIN_AT_RPATH_TRUE - enable_static - enable_shared - CXXCPP -@@ -817,6 +819,7 @@ with_pic - enable_fast_install - with_gnu_ld - enable_libtool_lock -+enable_darwin_at_rpath - enable_werror - with_gcc_major_version_only - enable_cet -@@ -1471,6 +1474,8 @@ Optional Features: - --enable-fast-install[=PKGS] - optimize for fast installation [default=yes] - --disable-libtool-lock avoid locking (might break parallel builds) -+ --enable-darwin-at-path install libraries with @rpath/library-name, requires -+ rpaths to be added to executables - --disable-werror disable building with -Werror - --enable-cet enable Intel CET in target libraries [default=auto] - -@@ -10553,6 +10558,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc=no - hardcode_direct=no - hardcode_automatic=yes -@@ -10570,10 +10616,19 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - - else - ld_shlibs=no -@@ -12359,7 +12414,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 12362 "configure" -+#line 12417 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -12465,7 +12520,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 12468 "configure" -+#line 12523 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -13341,6 +13396,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc_CXX=no - hardcode_direct_CXX=no - hardcode_automatic_CXX=yes -@@ -13358,12 +13454,25 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - if test "$lt_cv_apple_cc_single_mod" != "yes"; then -- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring${_lt_dsymutil}" -+ else -+ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" -+ fi - archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" - fi - -@@ -15763,6 +15872,15 @@ esac - - - -+ if test x$enable_darwin_at_rpath = xyes; then -+ ENABLE_DARWIN_AT_RPATH_TRUE= -+ ENABLE_DARWIN_AT_RPATH_FALSE='#' -+else -+ ENABLE_DARWIN_AT_RPATH_TRUE='#' -+ ENABLE_DARWIN_AT_RPATH_FALSE= -+fi -+ -+ - # The cast to long int works around a bug in the HP C Compiler - # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects - # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. -@@ -17152,6 +17270,10 @@ if test -z "${am__fastdepCCAS_TRUE}" && test -z "${am__fastdepCCAS_FALSE}"; then - as_fn_error $? "conditional \"am__fastdepCCAS\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 - fi -+if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then -+ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. -+Usually this means the macro was only invoked conditionally." "$LINENO" 5 -+fi - if test -z "${TSAN_SUPPORTED_TRUE}" && test -z "${TSAN_SUPPORTED_FALSE}"; then - as_fn_error $? "conditional \"TSAN_SUPPORTED\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 -diff --git a/libsanitizer/configure.ac b/libsanitizer/configure.ac -index 7f1ef3979c4..3549b904c62 100644 ---- a/libsanitizer/configure.ac -+++ b/libsanitizer/configure.ac -@@ -85,6 +85,8 @@ esac - AC_SUBST(enable_shared) - AC_SUBST(enable_static) - -+AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) -+ - AC_CHECK_SIZEOF([void *]) - - if test "${multilib}" = "yes"; then -diff --git a/libsanitizer/hwasan/Makefile.am b/libsanitizer/hwasan/Makefile.am -index e12c0a0ce71..4061078c734 100644 ---- a/libsanitizer/hwasan/Makefile.am -+++ b/libsanitizer/hwasan/Makefile.am -@@ -46,7 +46,11 @@ libhwasan_la_LIBADD += $(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la - endif - libhwasan_la_LIBADD += $(LIBSTDCXX_RAW_CXX_LDFLAGS) - --libhwasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libhwasan) -+if ENABLE_DARWIN_AT_RPATH -+libhwasan_darwin_rpath = -nodefaultrpaths -Wl,-rpath,@loader_path/ -+endif -+libhwasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ -+ $(link_libhwasan) $(libhwasan_darwin_rpath) - - # Work around what appears to be a GNU make bug handling MAKEFLAGS - # values defined in terms of make variables, as is the case for CC and -diff --git a/libsanitizer/hwasan/Makefile.in b/libsanitizer/hwasan/Makefile.in -index 67553f3979d..d20f2dc6eef 100644 ---- a/libsanitizer/hwasan/Makefile.in -+++ b/libsanitizer/hwasan/Makefile.in -@@ -387,7 +387,6 @@ pdfdir = @pdfdir@ - prefix = @prefix@ - program_transform_name = @program_transform_name@ - psdir = @psdir@ --runstatedir = @runstatedir@ - sbindir = @sbindir@ - sharedstatedir = @sharedstatedir@ - srcdir = @srcdir@ -@@ -442,7 +441,10 @@ libhwasan_la_SOURCES = $(hwasan_files) - libhwasan_la_LIBADD = \ - $(top_builddir)/sanitizer_common/libsanitizer_common.la \ - $(am__append_1) $(am__append_2) $(LIBSTDCXX_RAW_CXX_LDFLAGS) --libhwasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libhwasan) -+@ENABLE_DARWIN_AT_RPATH_TRUE@libhwasan_darwin_rpath = -nodefaultrpaths -Wl,-rpath,@loader_path/ -+libhwasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ -+ $(link_libhwasan) $(libhwasan_darwin_rpath) -+ - - # Work around what appears to be a GNU make bug handling MAKEFLAGS - # values defined in terms of make variables, as is the case for CC and -diff --git a/libsanitizer/interception/Makefile.in b/libsanitizer/interception/Makefile.in -index bce788aeea7..85dd386de47 100644 ---- a/libsanitizer/interception/Makefile.in -+++ b/libsanitizer/interception/Makefile.in -@@ -317,7 +317,6 @@ pdfdir = @pdfdir@ - prefix = @prefix@ - program_transform_name = @program_transform_name@ - psdir = @psdir@ --runstatedir = @runstatedir@ - sbindir = @sbindir@ - sharedstatedir = @sharedstatedir@ - srcdir = @srcdir@ -diff --git a/libsanitizer/libbacktrace/Makefile.in b/libsanitizer/libbacktrace/Makefile.in -index ece4f11a855..c0243fa4aab 100644 ---- a/libsanitizer/libbacktrace/Makefile.in -+++ b/libsanitizer/libbacktrace/Makefile.in -@@ -367,7 +367,6 @@ pdfdir = @pdfdir@ - prefix = @prefix@ - program_transform_name = @program_transform_name@ - psdir = @psdir@ --runstatedir = @runstatedir@ - sbindir = @sbindir@ - sharedstatedir = @sharedstatedir@ - srcdir = @srcdir@ -diff --git a/libsanitizer/lsan/Makefile.am b/libsanitizer/lsan/Makefile.am -index 6ff28ff5eea..7701b0e18cf 100644 ---- a/libsanitizer/lsan/Makefile.am -+++ b/libsanitizer/lsan/Makefile.am -@@ -41,8 +41,12 @@ if LIBBACKTRACE_SUPPORTED - liblsan_la_LIBADD += $(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la - endif - liblsan_la_LIBADD += $(LIBSTDCXX_RAW_CXX_LDFLAGS) --liblsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_liblsan) -- -+if ENABLE_DARWIN_AT_RPATH -+liblsan_darwin_rpath = -Wc,-nodefaultrpaths -+liblsan_darwin_rpath += -Wl,-rpath,@loader_path -+endif -+liblsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ -+ $(link_liblsan) $(liblsan_darwin_rpath) - liblsan_preinit.o: lsan_preinit.o - cp $< $@ - -diff --git a/libsanitizer/lsan/Makefile.in b/libsanitizer/lsan/Makefile.in -index 857f244cd86..078edf01fda 100644 ---- a/libsanitizer/lsan/Makefile.in -+++ b/libsanitizer/lsan/Makefile.in -@@ -362,7 +362,6 @@ pdfdir = @pdfdir@ - prefix = @prefix@ - program_transform_name = @program_transform_name@ - psdir = @psdir@ --runstatedir = @runstatedir@ - sbindir = @sbindir@ - sharedstatedir = @sharedstatedir@ - srcdir = @srcdir@ -@@ -414,7 +413,12 @@ liblsan_la_LIBADD = \ - $(top_builddir)/sanitizer_common/libsanitizer_common.la \ - $(top_builddir)/interception/libinterception.la \ - $(am__append_1) $(LIBSTDCXX_RAW_CXX_LDFLAGS) --liblsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_liblsan) -+@ENABLE_DARWIN_AT_RPATH_TRUE@liblsan_darwin_rpath = \ -+@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ -+@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path -+liblsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ -+ $(link_liblsan) $(liblsan_darwin_rpath) -+ - - # Work around what appears to be a GNU make bug handling MAKEFLAGS - # values defined in terms of make variables, as is the case for CC and -@@ -789,7 +793,6 @@ uninstall-am: uninstall-nodist_toolexeclibHEADERS \ - - .PRECIOUS: Makefile - -- - liblsan_preinit.o: lsan_preinit.o - cp $< $@ - -diff --git a/libsanitizer/sanitizer_common/Makefile.in b/libsanitizer/sanitizer_common/Makefile.in -index c4b009fed83..e5e1c1d51fe 100644 ---- a/libsanitizer/sanitizer_common/Makefile.in -+++ b/libsanitizer/sanitizer_common/Makefile.in -@@ -354,7 +354,6 @@ pdfdir = @pdfdir@ - prefix = @prefix@ - program_transform_name = @program_transform_name@ - psdir = @psdir@ --runstatedir = @runstatedir@ - sbindir = @sbindir@ - sharedstatedir = @sharedstatedir@ - srcdir = @srcdir@ -diff --git a/libsanitizer/tsan/Makefile.am b/libsanitizer/tsan/Makefile.am -index ae588a67df6..47ee50bee1a 100644 ---- a/libsanitizer/tsan/Makefile.am -+++ b/libsanitizer/tsan/Makefile.am -@@ -58,7 +58,11 @@ libtsan_la_LIBADD += $(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la - libtsan_la_DEPENDENCIES +=$(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la - endif - libtsan_la_LIBADD += $(LIBSTDCXX_RAW_CXX_LDFLAGS) --libtsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libtsan) -+if ENABLE_DARWIN_AT_RPATH -+libtsan_darwin_rpath = -nodefaultrpaths -Wl,-rpath,@loader_path/ -+endif -+libtsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ -+ $(link_libtsan) $(libtsan_darwin_rpath) - - libtsan_preinit.o: tsan_preinit.o - cp $< $@ -diff --git a/libsanitizer/tsan/Makefile.in b/libsanitizer/tsan/Makefile.in -index 538d2e8eb68..d6efff71e2f 100644 ---- a/libsanitizer/tsan/Makefile.in -+++ b/libsanitizer/tsan/Makefile.in -@@ -391,7 +391,6 @@ pdfdir = @pdfdir@ - prefix = @prefix@ - program_transform_name = @program_transform_name@ - psdir = @psdir@ --runstatedir = @runstatedir@ - sbindir = @sbindir@ - sharedstatedir = @sharedstatedir@ - srcdir = @srcdir@ -@@ -466,7 +465,10 @@ libtsan_la_DEPENDENCIES = \ - $(top_builddir)/sanitizer_common/libsanitizer_common.la \ - $(top_builddir)/interception/libinterception.la \ - $(TSAN_TARGET_DEPENDENT_OBJECTS) $(am__append_2) --libtsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libtsan) -+@ENABLE_DARWIN_AT_RPATH_TRUE@libtsan_darwin_rpath = -nodefaultrpaths -Wl,-rpath,@loader_path/ -+libtsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ -+ $(link_libtsan) $(libtsan_darwin_rpath) -+ - - # Work around what appears to be a GNU make bug handling MAKEFLAGS - # values defined in terms of make variables, as is the case for CC and -diff --git a/libsanitizer/ubsan/Makefile.am b/libsanitizer/ubsan/Makefile.am -index d480f26adc0..7769b3437e4 100644 ---- a/libsanitizer/ubsan/Makefile.am -+++ b/libsanitizer/ubsan/Makefile.am -@@ -36,7 +36,12 @@ if LIBBACKTRACE_SUPPORTED - libubsan_la_LIBADD += $(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la - endif - libubsan_la_LIBADD += $(LIBSTDCXX_RAW_CXX_LDFLAGS) --libubsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libubsan) -+if ENABLE_DARWIN_AT_RPATH -+libubsan_darwin_rpath = -Wc,-nodefaultrpaths -+libubsan_darwin_rpath += -Wl,-rpath,@loader_path -+endif -+libubsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ -+ $(link_libubsan) $(libubsan_darwin_rpath) - - # Use special rules for files that require RTTI support. - ubsan_handlers_cxx.% ubsan_type_hash.% ubsan_type_hash_itanium.% : AM_CXXFLAGS += -frtti -diff --git a/libsanitizer/ubsan/Makefile.in b/libsanitizer/ubsan/Makefile.in -index 497e0338696..7e51480e970 100644 ---- a/libsanitizer/ubsan/Makefile.in -+++ b/libsanitizer/ubsan/Makefile.in -@@ -356,7 +356,6 @@ pdfdir = @pdfdir@ - prefix = @prefix@ - program_transform_name = @program_transform_name@ - psdir = @psdir@ --runstatedir = @runstatedir@ - sbindir = @sbindir@ - sharedstatedir = @sharedstatedir@ - srcdir = @srcdir@ -@@ -401,7 +400,12 @@ libubsan_la_SOURCES = $(ubsan_files) - libubsan_la_LIBADD = \ - $(top_builddir)/sanitizer_common/libsanitizer_common.la \ - $(am__append_1) $(am__append_2) $(LIBSTDCXX_RAW_CXX_LDFLAGS) --libubsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libubsan) -+@ENABLE_DARWIN_AT_RPATH_TRUE@libubsan_darwin_rpath = \ -+@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ -+@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path -+libubsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ -+ $(link_libubsan) $(libubsan_darwin_rpath) -+ - - # Work around what appears to be a GNU make bug handling MAKEFLAGS - # values defined in terms of make variables, as is the case for CC and -diff --git a/libssp/Makefile.am b/libssp/Makefile.am -index 945dc3c8336..d2a92b3aed1 100644 ---- a/libssp/Makefile.am -+++ b/libssp/Makefile.am -@@ -49,8 +49,12 @@ libssp_la_SOURCES = \ - vsnprintf-chk.c vsprintf-chk.c - libssp_la_LIBADD = - libssp_la_DEPENDENCIES = $(version_dep) $(libssp_la_LIBADD) -+if ENABLE_DARWIN_AT_RPATH -+libssp_darwin_rpath = -Wc,-nodefaultrpaths -+libssp_darwin_rpath += -Wl,-rpath,@loader_path -+endif - libssp_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ -- $(version_arg) $(lt_host_flags) -+ $(version_arg) $(lt_host_flags) $(libssp_darwin_rpath) - - libssp_nonshared_la_SOURCES = \ - ssp-local.c -diff --git a/libssp/Makefile.in b/libssp/Makefile.in -index bc8a0dc2b28..1cf86361b96 100644 ---- a/libssp/Makefile.in -+++ b/libssp/Makefile.in -@@ -376,8 +376,11 @@ libssp_la_SOURCES = \ - - libssp_la_LIBADD = - libssp_la_DEPENDENCIES = $(version_dep) $(libssp_la_LIBADD) -+@ENABLE_DARWIN_AT_RPATH_TRUE@libssp_darwin_rpath = \ -+@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ -+@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path - libssp_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ -- $(version_arg) $(lt_host_flags) -+ $(version_arg) $(lt_host_flags) $(libssp_darwin_rpath) - - libssp_nonshared_la_SOURCES = \ - ssp-local.c -diff --git a/libssp/configure b/libssp/configure -index 10ba209bde8..5d62fef54a1 100755 ---- a/libssp/configure -+++ b/libssp/configure -@@ -636,6 +636,8 @@ LIBOBJS - get_gcc_base_ver - toolexeclibdir - toolexecdir -+ENABLE_DARWIN_AT_RPATH_FALSE -+ENABLE_DARWIN_AT_RPATH_TRUE - enable_static - enable_shared - lt_host_flags -@@ -781,6 +783,7 @@ with_pic - enable_fast_install - with_gnu_ld - enable_libtool_lock -+enable_darwin_at_rpath - with_toolexeclibdir - with_gcc_major_version_only - ' -@@ -1426,6 +1429,8 @@ Optional Features: - --enable-fast-install[=PKGS] - optimize for fast installation [default=yes] - --disable-libtool-lock avoid locking (might break parallel builds) -+ --enable-darwin-at-path install libraries with @rpath/library-name, requires -+ rpaths to be added to executables - - Optional Packages: - --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] -@@ -4338,7 +4343,7 @@ case "$host" in - case "$enable_cet" in - auto) - # Check if target supports multi-byte NOPs -- # and if assembler supports CET insn. -+ # and if compiler and assembler support CET insn. - cet_save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS -fcf-protection" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -@@ -9165,6 +9170,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc=no - hardcode_direct=no - hardcode_automatic=yes -@@ -9182,10 +9228,19 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - - else - ld_shlibs=no -@@ -10992,7 +11047,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 11005 "configure" -+#line 11050 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -11098,7 +11153,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 11111 "configure" -+#line 11156 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -11376,6 +11431,15 @@ fi - - - -+ if test x$enable_darwin_at_rpath = xyes; then -+ ENABLE_DARWIN_AT_RPATH_TRUE= -+ ENABLE_DARWIN_AT_RPATH_FALSE='#' -+else -+ ENABLE_DARWIN_AT_RPATH_TRUE='#' -+ ENABLE_DARWIN_AT_RPATH_FALSE= -+fi -+ -+ - # Calculate toolexeclibdir - # Also toolexecdir, though it's only used in toolexeclibdir - case ${version_specific_libs} in -@@ -11585,6 +11649,10 @@ if test -z "${LIBSSP_USE_SYMVER_SUN_TRUE}" && test -z "${LIBSSP_USE_SYMVER_SUN_F - as_fn_error $? "conditional \"LIBSSP_USE_SYMVER_SUN\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 - fi -+if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then -+ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. -+Usually this means the macro was only invoked conditionally." "$LINENO" 5 -+fi - - : "${CONFIG_STATUS=./config.status}" - ac_write_fail=0 -diff --git a/libssp/configure.ac b/libssp/configure.ac -index f30f81c54f6..90778e2355d 100644 ---- a/libssp/configure.ac -+++ b/libssp/configure.ac -@@ -165,6 +165,8 @@ AC_SUBST(enable_static) - - GCC_WITH_TOOLEXECLIBDIR - -+AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) -+ - # Calculate toolexeclibdir - # Also toolexecdir, though it's only used in toolexeclibdir - case ${version_specific_libs} in -diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure -index eac60392121..bdaa160dac6 100755 ---- a/libstdc++-v3/configure -+++ b/libstdc++-v3/configure -@@ -786,6 +786,8 @@ GLIBCXX_HOSTED_TRUE - glibcxx_compiler_shared_flag - glibcxx_compiler_pic_flag - glibcxx_lt_pic_flag -+ENABLE_DARWIN_AT_RPATH_FALSE -+ENABLE_DARWIN_AT_RPATH_TRUE - enable_static - enable_shared - lt_host_flags -@@ -921,6 +923,7 @@ with_pic - enable_fast_install - with_gnu_ld - enable_libtool_lock -+enable_darwin_at_rpath - enable_hosted_libstdcxx - enable_libstdcxx_verbose - enable_libstdcxx_pch -@@ -1608,6 +1611,8 @@ Optional Features: - --enable-fast-install[=PKGS] - optimize for fast installation [default=yes] - --disable-libtool-lock avoid locking (might break parallel builds) -+ --enable-darwin-at-path install libraries with @rpath/library-name, requires -+ rpaths to be added to executables - --disable-hosted-libstdcxx - only build freestanding C++ runtime support - --disable-libstdcxx-verbose -@@ -10364,6 +10369,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc=no - hardcode_direct=no - hardcode_automatic=yes -@@ -10381,10 +10427,19 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - - else - ld_shlibs=no -@@ -12191,7 +12246,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 12194 "configure" -+#line 12249 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -12297,7 +12352,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 12300 "configure" -+#line 12355 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -13179,6 +13234,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc_CXX=no - hardcode_direct_CXX=no - hardcode_automatic_CXX=yes -@@ -13196,12 +13292,25 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - if test "$lt_cv_apple_cc_single_mod" != "yes"; then -- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring${_lt_dsymutil}" -+ else -+ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" -+ fi - archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" - fi - -@@ -15578,6 +15687,14 @@ esac - - - -+ if test x$enable_darwin_at_rpath = xyes; then -+ ENABLE_DARWIN_AT_RPATH_TRUE= -+ ENABLE_DARWIN_AT_RPATH_FALSE='#' -+else -+ ENABLE_DARWIN_AT_RPATH_TRUE='#' -+ ENABLE_DARWIN_AT_RPATH_FALSE= -+fi -+ - - if test "$enable_vtable_verify" = yes; then - predep_objects_CXX="${predep_objects_CXX} ${glibcxx_builddir}/../libgcc/vtv_start.o" -@@ -15981,7 +16098,7 @@ $as_echo "$glibcxx_cv_atomic_long_long" >&6; } - # Fake what AC_TRY_COMPILE does. - - cat > conftest.$ac_ext << EOF --#line 15984 "configure" -+#line 16101 "configure" - int main() - { - typedef bool atomic_type; -@@ -16016,7 +16133,7 @@ $as_echo "$glibcxx_cv_atomic_bool" >&6; } - rm -f conftest* - - cat > conftest.$ac_ext << EOF --#line 16019 "configure" -+#line 16136 "configure" - int main() - { - typedef short atomic_type; -@@ -16051,7 +16168,7 @@ $as_echo "$glibcxx_cv_atomic_short" >&6; } - rm -f conftest* - - cat > conftest.$ac_ext << EOF --#line 16054 "configure" -+#line 16171 "configure" - int main() - { - // NB: _Atomic_word not necessarily int. -@@ -16087,7 +16204,7 @@ $as_echo "$glibcxx_cv_atomic_int" >&6; } - rm -f conftest* - - cat > conftest.$ac_ext << EOF --#line 16090 "configure" -+#line 16207 "configure" - int main() - { - typedef long long atomic_type; -@@ -16243,7 +16360,7 @@ $as_echo "mutex" >&6; } - # unnecessary for this test. - - cat > conftest.$ac_ext << EOF --#line 16246 "configure" -+#line 16363 "configure" - int main() - { - _Decimal32 d1; -@@ -16285,7 +16402,7 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu - # unnecessary for this test. - - cat > conftest.$ac_ext << EOF --#line 16288 "configure" -+#line 16405 "configure" - template - struct same - { typedef T2 type; }; -@@ -79038,6 +79155,10 @@ if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then - as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 - fi -+if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then -+ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. -+Usually this means the macro was only invoked conditionally." "$LINENO" 5 -+fi - if test -z "${GLIBCXX_HOSTED_TRUE}" && test -z "${GLIBCXX_HOSTED_FALSE}"; then - as_fn_error $? "conditional \"GLIBCXX_HOSTED\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 -diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac -index e59bcdb2944..f3dda5a4ff9 100644 ---- a/libstdc++-v3/configure.ac -+++ b/libstdc++-v3/configure.ac -@@ -99,6 +99,7 @@ AM_PROG_LIBTOOL - ACX_LT_HOST_FLAGS - AC_SUBST(enable_shared) - AC_SUBST(enable_static) -+AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) - - if test "$enable_vtable_verify" = yes; then - predep_objects_CXX="${predep_objects_CXX} ${glibcxx_builddir}/../libgcc/vtv_start.o" -diff --git a/libstdc++-v3/configure.host b/libstdc++-v3/configure.host -index ec32980aa0d..da5b1578d91 100644 ---- a/libstdc++-v3/configure.host -+++ b/libstdc++-v3/configure.host -@@ -234,11 +234,6 @@ case "${host_os}" in - darwin8 | darwin8.* ) - # For 8+ compatibility is better if not -flat_namespace. - OPT_LDFLAGS="${OPT_LDFLAGS} -Wl,-single_module" -- case "${host_cpu}" in -- i[34567]86 | x86_64) -- OPTIMIZE_CXXFLAGS="${OPTIMIZE_CXXFLAGS} -fvisibility-inlines-hidden" -- ;; -- esac - os_include_dir="os/bsd/darwin" - ;; - darwin*) -diff --git a/libstdc++-v3/src/Makefile.am b/libstdc++-v3/src/Makefile.am -index 9c3f4aca655..016d68ecd5f 100644 ---- a/libstdc++-v3/src/Makefile.am -+++ b/libstdc++-v3/src/Makefile.am -@@ -133,8 +133,13 @@ libstdc___la_DEPENDENCIES = \ - $(top_builddir)/src/c++17/libc++17convenience.la \ - $(top_builddir)/src/c++20/libc++20convenience.la - -+if ENABLE_DARWIN_AT_RPATH -+libstdc___darwin_rpath = -Wc,-nodefaultrpaths -+libstdc___darwin_rpath += -Wl,-rpath,@loader_path -+endif -+ - libstdc___la_LDFLAGS = \ -- -version-info $(libtool_VERSION) ${version_arg} -lm -+ -version-info $(libtool_VERSION) ${version_arg} -lm $(libstdc___darwin_rpath) - - libstdc___la_LINK = $(CXXLINK) $(libstdc___la_LDFLAGS) $(lt_host_flags) - -diff --git a/libstdc++-v3/src/Makefile.in b/libstdc++-v3/src/Makefile.in -index 4a06f6cfec1..0dc6c9650fc 100644 ---- a/libstdc++-v3/src/Makefile.in -+++ b/libstdc++-v3/src/Makefile.in -@@ -546,8 +546,11 @@ libstdc___la_DEPENDENCIES = \ - $(top_builddir)/src/c++17/libc++17convenience.la \ - $(top_builddir)/src/c++20/libc++20convenience.la - -+@ENABLE_DARWIN_AT_RPATH_TRUE@libstdc___darwin_rpath = \ -+@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ -+@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path - libstdc___la_LDFLAGS = \ -- -version-info $(libtool_VERSION) ${version_arg} -lm -+ -version-info $(libtool_VERSION) ${version_arg} -lm $(libstdc___darwin_rpath) - - libstdc___la_LINK = $(CXXLINK) $(libstdc___la_LDFLAGS) $(lt_host_flags) - @GLIBCXX_LDBL_ALT128_COMPAT_FALSE@@GLIBCXX_LDBL_COMPAT_TRUE@LTCXXCOMPILE64 = $(LTCXXCOMPILE) -diff --git a/libtool.m4 b/libtool.m4 -index 17f8e5f3074..5452de03793 100644 ---- a/libtool.m4 -+++ b/libtool.m4 -@@ -1039,6 +1039,45 @@ _LT_EOF - m4_defun([_LT_DARWIN_LINKER_FEATURES], - [ - m4_require([_LT_REQUIRED_DARWIN_CHECKS]) -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ AC_ARG_ENABLE([darwin-at-rpath], -+ AS_HELP_STRING([--enable-darwin-at-path], -+ [install libraries with @rpath/library-name, requires rpaths to be added to executables]), -+ [if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[[45678]]*|UNSET,rhapsody*|10.[[01234]][[,.]]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&AS_MESSAGE_LOG_FD -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi], -+ [case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[[45678]]*|UNSET,rhapsody*|10.[[01234]][[,.]]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[[56789]]*|UNSET,darwin2*|10.1[[123456789]][[,.]]*|1[[123456789]].*[[,.]]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&AS_MESSAGE_LOG_FD -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ ]) -+ - _LT_TAGVAR(archive_cmds_need_lc, $1)=no - _LT_TAGVAR(hardcode_direct, $1)=no - _LT_TAGVAR(hardcode_automatic, $1)=yes -@@ -1056,13 +1095,26 @@ m4_defun([_LT_DARWIN_LINKER_FEATURES], - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&AS_MESSAGE_LOG_FD -+ _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&AS_MESSAGE_LOG_FD -+ _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - m4_if([$1], [CXX], - [ if test "$lt_cv_apple_cc_single_mod" != "yes"; then -- _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring${_lt_dsymutil}" -+ else -+ _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" -+ fi - _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" - fi - ],[]) -@@ -4203,6 +4255,7 @@ _LT_TAGDECL([link_static_flag], [lt_prog_compiler_static], [1], - [Compiler flag to prevent dynamic linking]) - ])# _LT_COMPILER_PIC - -+_LT_TAGVAR(enable_darwin_at_rpath, $1)=no - - # _LT_LINKER_SHLIBS([TAGNAME]) - # ---------------------------- -@@ -6441,7 +6494,6 @@ fi # test "$_lt_caught_CXX_error" != yes - AC_LANG_POP - ])# _LT_LANG_CXX_CONFIG - -- - # _LT_SYS_HIDDEN_LIBDEPS([TAGNAME]) - # --------------------------------- - # Figure out "hidden" library dependencies from verbose -diff --git a/libvtv/configure b/libvtv/configure -index d64b4af5c6b..4280e3b20a9 100755 ---- a/libvtv/configure -+++ b/libvtv/configure -@@ -640,6 +640,8 @@ VTV_CYGMIN_FALSE - VTV_CYGMIN_TRUE - XCFLAGS - libtool_VERSION -+ENABLE_DARWIN_AT_RPATH_FALSE -+ENABLE_DARWIN_AT_RPATH_TRUE - enable_static - enable_shared - lt_host_flags -@@ -797,6 +799,7 @@ with_pic - enable_fast_install - with_gnu_ld - enable_libtool_lock -+enable_darwin_at_rpath - enable_cet - with_gcc_major_version_only - ' -@@ -1446,6 +1449,8 @@ Optional Features: - --enable-fast-install[=PKGS] - optimize for fast installation [default=yes] - --disable-libtool-lock avoid locking (might break parallel builds) -+ --enable-darwin-at-path install libraries with @rpath/library-name, requires -+ rpaths to be added to executables - --enable-cet enable Intel CET in target libraries [default=auto] - - Optional Packages: -@@ -10448,6 +10453,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc=no - hardcode_direct=no - hardcode_automatic=yes -@@ -10465,10 +10511,19 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - - else - ld_shlibs=no -@@ -12254,7 +12309,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 12267 "configure" -+#line 12312 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -12360,7 +12415,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 12373 "configure" -+#line 12418 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -13236,6 +13291,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc_CXX=no - hardcode_direct_CXX=no - hardcode_automatic_CXX=yes -@@ -13253,12 +13349,25 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - if test "$lt_cv_apple_cc_single_mod" != "yes"; then -- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring${_lt_dsymutil}" -+ else -+ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" -+ fi - archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" - fi - -@@ -15099,16 +15208,6 @@ freebsd* | dragonfly*) - esac - ;; - --gnu*) -- version_type=linux -- need_lib_prefix=no -- need_version=no -- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' -- soname_spec='${libname}${release}${shared_ext}$major' -- shlibpath_var=LD_LIBRARY_PATH -- hardcode_into_libs=yes -- ;; -- - haiku*) - version_type=linux - need_lib_prefix=no -@@ -15230,7 +15329,7 @@ linux*oldld* | linux*aout* | linux*coff*) - # project, but have not yet been accepted: they are GCC-local changes - # for the time being. (See - # https://lists.gnu.org/archive/html/libtool-patches/2018-05/msg00000.html) --linux* | k*bsd*-gnu | kopensolaris*-gnu | uclinuxfdpiceabi) -+linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu* | uclinuxfdpiceabi) - version_type=linux - need_lib_prefix=no - need_version=no -@@ -15642,6 +15741,14 @@ esac - - - -+ if test x$enable_darwin_at_rpath = xyes; then -+ ENABLE_DARWIN_AT_RPATH_TRUE= -+ ENABLE_DARWIN_AT_RPATH_FALSE='#' -+else -+ ENABLE_DARWIN_AT_RPATH_TRUE='#' -+ ENABLE_DARWIN_AT_RPATH_FALSE= -+fi -+ - - # For libtool versioning info, format is CURRENT:REVISION:AGE - libtool_VERSION=1:0:0 -@@ -15672,7 +15779,7 @@ case "$host" in - case "$enable_cet" in - auto) - # Check if target supports multi-byte NOPs -- # and if assembler supports CET insn. -+ # and if compiler and assembler support CET insn. - cet_save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS -fcf-protection" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -@@ -15987,6 +16094,10 @@ if test -z "${am__fastdepCXX_TRUE}" && test -z "${am__fastdepCXX_FALSE}"; then - as_fn_error $? "conditional \"am__fastdepCXX\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 - fi -+if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then -+ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. -+Usually this means the macro was only invoked conditionally." "$LINENO" 5 -+fi - if test -z "${VTV_CYGMIN_TRUE}" && test -z "${VTV_CYGMIN_FALSE}"; then - as_fn_error $? "conditional \"VTV_CYGMIN\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 -diff --git a/libvtv/configure.ac b/libvtv/configure.ac -index f3b937e4b10..50aaadbb3a3 100644 ---- a/libvtv/configure.ac -+++ b/libvtv/configure.ac -@@ -153,6 +153,7 @@ AM_PROG_LIBTOOL - ACX_LT_HOST_FLAGS - AC_SUBST(enable_shared) - AC_SUBST(enable_static) -+AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) - - # For libtool versioning info, format is CURRENT:REVISION:AGE - libtool_VERSION=1:0:0 -diff --git a/lto-plugin/configure b/lto-plugin/configure -index b820accfd65..8faa13c4a8b 100755 ---- a/lto-plugin/configure -+++ b/lto-plugin/configure -@@ -634,6 +634,8 @@ LTLIBOBJS - LIBOBJS - target_noncanonical - lt_host_flags -+ENABLE_DARWIN_AT_RPATH_FALSE -+ENABLE_DARWIN_AT_RPATH_TRUE - OTOOL64 - OTOOL - LIPO -@@ -785,6 +787,7 @@ with_pic - enable_fast_install - with_gnu_ld - enable_libtool_lock -+enable_darwin_at_rpath - ' - ac_precious_vars='build_alias - host_alias -@@ -1430,6 +1433,8 @@ Optional Features: - --enable-fast-install[=PKGS] - optimize for fast installation [default=yes] - --disable-libtool-lock avoid locking (might break parallel builds) -+ --enable-darwin-at-path install libraries with @rpath/library-name, requires -+ rpaths to be added to executables - - Optional Packages: - --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] -@@ -10275,6 +10280,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc=no - hardcode_direct=no - hardcode_automatic=yes -@@ -10292,10 +10338,19 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - - else - ld_shlibs=no -@@ -12081,7 +12136,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 12084 "configure" -+#line 12139 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -12187,7 +12242,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 12190 "configure" -+#line 12245 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -12424,6 +12479,14 @@ CC="$lt_save_CC" - # Only expand once: - - -+ if test x$enable_darwin_at_rpath = xyes; then -+ ENABLE_DARWIN_AT_RPATH_TRUE= -+ ENABLE_DARWIN_AT_RPATH_FALSE='#' -+else -+ ENABLE_DARWIN_AT_RPATH_TRUE='#' -+ ENABLE_DARWIN_AT_RPATH_FALSE= -+fi -+ - - - -@@ -12670,6 +12733,10 @@ if test -z "${LTO_PLUGIN_USE_SYMVER_SUN_TRUE}" && test -z "${LTO_PLUGIN_USE_SYMV - as_fn_error $? "conditional \"LTO_PLUGIN_USE_SYMVER_SUN\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 - fi -+if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then -+ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. -+Usually this means the macro was only invoked conditionally." "$LINENO" 5 -+fi - - : "${CONFIG_STATUS=./config.status}" - ac_write_fail=0 -diff --git a/lto-plugin/configure.ac b/lto-plugin/configure.ac -index bc5b618a495..317596288b2 100644 ---- a/lto-plugin/configure.ac -+++ b/lto-plugin/configure.ac -@@ -88,6 +88,7 @@ AM_CONDITIONAL(LTO_PLUGIN_USE_SYMVER_GNU, [test "x$lto_plugin_use_symver" = xgnu - AM_CONDITIONAL(LTO_PLUGIN_USE_SYMVER_SUN, [test "x$lto_plugin_use_symver" = xsun]) - - AM_PROG_LIBTOOL -+AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) - ACX_LT_HOST_FLAGS - AC_SUBST(target_noncanonical) - AC_TYPE_INT64_T -diff --git a/zlib/configure b/zlib/configure -index f489f31bc70..f7adce0db2c 100755 ---- a/zlib/configure -+++ b/zlib/configure -@@ -639,6 +639,8 @@ TARGET_LIBRARY_FALSE - TARGET_LIBRARY_TRUE - toolexeclibdir - toolexecdir -+ENABLE_DARWIN_AT_RPATH_FALSE -+ENABLE_DARWIN_AT_RPATH_TRUE - CPP - OTOOL64 - OTOOL -@@ -776,6 +778,7 @@ with_pic - enable_fast_install - with_gnu_ld - enable_libtool_lock -+enable_darwin_at_rpath - with_toolexeclibdir - enable_host_shared - ' -@@ -1419,6 +1422,8 @@ Optional Features: - --enable-fast-install[=PKGS] - optimize for fast installation [default=yes] - --disable-libtool-lock avoid locking (might break parallel builds) -+ --enable-darwin-at-path install libraries with @rpath/library-name, requires -+ rpaths to be added to executables - --enable-host-shared build host code as shared libraries - - Optional Packages: -@@ -4169,7 +4174,7 @@ case "$host" in - case "$enable_cet" in - auto) - # Check if target supports multi-byte NOPs -- # and if assembler supports CET insn. -+ # and if compiler and assembler support CET insn. - cet_save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS -fcf-protection" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -@@ -8908,6 +8913,47 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - darwin* | rhapsody*) - - -+ -+ # Publish an arg to allow the user to select that Darwin host (and target) -+ # libraries should be given install-names like @rpath/libfoo.dylib. This -+ # requires that the user of the library then adds an 'rpath' to the DSO that -+ # needs access. -+ # NOTE: there are defaults below, for systems that support rpaths. The person -+ # configuring can override the defaults for any system version that supports -+ # them - they are, however, forced off for system versions without support. -+ # Check whether --enable-darwin-at-rpath was given. -+if test "${enable_darwin_at_rpath+set}" = set; then : -+ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then -+ # This is not supported before macOS 10.5 / Darwin9. -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ echo "WARNING: Darwin @rpath library names are incompatible with macOS versions earlier than 10.5 (rpaths disabled)" 1>&5 -+ enable_darwin_at_rpath=no -+ ;; -+ esac -+ fi -+else -+ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in -+ # As above, before 10.5 / Darwin9 this does not work. -+ UNSET,darwin[45678]*|UNSET,rhapsody*|10.[01234][,.]*) -+ enable_darwin_at_rpath=no -+ ;; -+ -+ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use -+ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key -+ # system executables (e.g. /bin/sh). Force rpaths on for these systems. -+ UNSET,darwin1[56789]*|UNSET,darwin2*|10.1[123456789][,.]*|1[123456789].*[,.]* ) -+ echo "@rpath library names are needed on macOS versions later than 10.11 (rpaths enabled)" 1>&5 -+ enable_darwin_at_rpath=yes -+ ;; -+ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can -+ # work with either DYLD_LIBRARY_PATH or embedded rpaths. -+ -+ esac -+ -+fi -+ -+ - archive_cmds_need_lc=no - hardcode_direct=no - hardcode_automatic=yes -@@ -8925,10 +8971,19 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi - esac - if test "$_lt_dar_can_shared" = "yes"; then - output_verbose_link_cmd=func_echo_all -- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -- module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -- module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ if test "x$enable_darwin_at_rpath" = "xyes"; then -+ echo "using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name @rpath/\$soname \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ else -+ echo "NOT using Darwin @rpath" 1>&5 -+ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" -+ module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" -+ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" -+ module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" -+ fi - - else - ld_shlibs=no -@@ -10735,7 +10790,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 10748 "configure" -+#line 10793 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -10841,7 +10896,7 @@ else - lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 - lt_status=$lt_dlunknown - cat > conftest.$ac_ext <<_LT_EOF --#line 10854 "configure" -+#line 10899 "configure" - #include "confdefs.h" - - #if HAVE_DLFCN_H -@@ -11078,6 +11133,14 @@ CC="$lt_save_CC" - # Only expand once: - - -+ if test x$enable_darwin_at_rpath = xyes; then -+ ENABLE_DARWIN_AT_RPATH_TRUE= -+ ENABLE_DARWIN_AT_RPATH_FALSE='#' -+else -+ ENABLE_DARWIN_AT_RPATH_TRUE='#' -+ ENABLE_DARWIN_AT_RPATH_FALSE= -+fi -+ - - # Find CPP now so that any conditional tests below won't do it and - # thereby make the resulting definitions conditional. -@@ -11708,6 +11771,10 @@ if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then - as_fn_error $? "conditional \"am__fastdepCC\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 - fi -+if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then -+ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. -+Usually this means the macro was only invoked conditionally." "$LINENO" 5 -+fi - if test -z "${TARGET_LIBRARY_TRUE}" && test -z "${TARGET_LIBRARY_FALSE}"; then - as_fn_error $? "conditional \"TARGET_LIBRARY\" was never defined. - Usually this means the macro was only invoked conditionally." "$LINENO" 5 -diff --git a/zlib/configure.ac b/zlib/configure.ac -index be1cfe29651..2327d003a05 100644 ---- a/zlib/configure.ac -+++ b/zlib/configure.ac -@@ -64,6 +64,7 @@ GCC_CET_FLAGS(CET_FLAGS) - AC_SUBST(CET_FLAGS) - - AC_PROG_LIBTOOL -+AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) - - # Find CPP now so that any conditional tests below won't do it and - # thereby make the resulting definitions conditional. diff --git a/10.9-libcxx/stable/main/finkinfo/languages/gcc12.info b/10.9-libcxx/stable/main/finkinfo/languages/gcc12.info index 039fdfab41e..5eadaafee45 100644 --- a/10.9-libcxx/stable/main/finkinfo/languages/gcc12.info +++ b/10.9-libcxx/stable/main/finkinfo/languages/gcc12.info @@ -1,17 +1,16 @@ Info2: << Package: gcc12 -Version: 12.2.0 -Revision: 3 +Version: 12.4.0 +Revision: 1 Type: gccver (12) +Distribution: 10.9, 10.10, 10.11, 10.12, 10.13, 10.14, 10.14.5, 10.15, 11.0, 11.3, 12.0 Source: mirror:gnu:gcc/gcc-%v/gcc-%v.tar.xz -Source-Checksum: SHA256(e549cf9cf3594a00e27b6589d4322d70e0720cdd213f39beb4181e06926230ff) -#PatchFile: %n.patch -#PatchFile-MD5: bf4bd5d40bff74246c2b445f62d4597f -PatchFile4: %n-arm.patch -PatchFile4-MD5: 507fd663384c93910bfecb1671df0edc +Source-Checksum: SHA256(704f652604ccbccb14bdabf3478c9511c89788b12cb3bbffded37341916a9175) +PatchFile: %n.patch +PatchFile-MD5: cfbfeced5b822b29092e90b5c4d85456 PatchScript: << #!/bin/sh -ev - patch -p1 < %{PatchFile4} + patch -p1 < %{PatchFile} # don't update live infodoc dir find . -name Makefile.in | xargs perl -pi -e 's/install-info --version/false/g' << @@ -72,21 +71,25 @@ ConfigureParams: << InfoTest: << TestDepends: << autogen, - dejagnu + dejagnu, + ( "%m" != "arm64" ) apple-gdb << TestScript: << - #!/bin/bash -ev - if [ $UID = 0 ]; then + #!/bin/bash -ev + if [ "%m" = "arm64" ]; then + echo "The gcc testsuite requires Apple's gdb, which is not available on this architecture." + exit 0 + elif [ $UID = 0 ]; then if [ -e /usr/bin/csrutil && `csrutil status | grep -c disabled` ]; then - cd ../darwin_objdir; make -k check RUNTESTFLAGS="--target_board=unix'{-m64}'" || : + cd ../darwin_objdir; make -k check RUNTESTFLAGS="--target_board=unix'{-m64}'" || : else echo "The gcc testsuite must be run with SIP disabled or package installed." exit 0 fi - else - echo "The gcc testsuite must be run as root due to its use of gdb." - exit 0 - fi + else + echo "The gcc testsuite must be run as root due to its use of gdb." + exit 0 + fi << << InfoDocs: gcc.info gfortran.info cpp.info gccinstall.info libgomp.info cppinternals.info gccint.info @@ -196,7 +199,7 @@ InstallScript: << # remove build path from .la files perl -pi -e "s, \-L[^ ']*/%n-%v-%r/darwin_objdir/[^ ']*,,g" `find %i/lib/gcc%type_num[gccver]/lib -name '*.la'` - if [ "%m" = "arm" ]; then + if [ "%m" = "arm64" ]; then arch=aarch64 else arch=%m @@ -238,23 +241,23 @@ SplitOff: << lib/gcc%type_num[gccver]/lib/libgomp.1*.dylib lib/gcc%type_num[gccver]/lib/libquadmath.0*.dylib lib/gcc%type_num[gccver]/lib/libatomic.1*.dylib - ( "%m" != "arm" ) lib/gcc%type_num[gccver]/lib/libasan.8*.dylib - ( "%m" != "arm" ) lib/gcc%type_num[gccver]/lib/libubsan.1*.dylib + ( "%m" != "arm64" ) lib/gcc%type_num[gccver]/lib/libasan.8*.dylib + ( "%m" != "arm64" ) lib/gcc%type_num[gccver]/lib/libubsan.1*.dylib << Shlibs: << %p/lib/gcc%type_num[gccver]/lib/libgfortran.5.dylib 6.0.0 %n (>= 12.0.0-1) %p/lib/gcc%type_num[gccver]/lib/libstdc++.6.dylib 7.0.0 %n (>= 12.0.0-1) - ( "%m" = "arm" ) %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib 1.0.0 %n (>= 12.0.0-1) - ( "%m" != "arm" ) %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.dylib 1.0.0 %n (>= 12.0.0-1) - ( "%m" != "arm" ) !%p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib + ( "%m" = "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib 1.0.0 %n (>= 12.0.0-1) + ( "%m" != "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.dylib 1.0.0 %n (>= 12.0.0-1) + ( "%m" != "arm64" ) !%p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib %p/lib/gcc%type_num[gccver]/lib/libitm.1.dylib 2.0.0 %n (>= 12.0.0-1) %p/lib/gcc%type_num[gccver]/lib/libssp.0.dylib 1.0.0 %n (>= 12.0.0-1) %p/lib/gcc%type_num[gccver]/lib/libobjc-gnu.4.dylib 5.0.0 %n (>= 12.0.0-1) %p/lib/gcc%type_num[gccver]/lib/libgomp.1.dylib 2.0.0 %n (>= 12.0.0-1) %p/lib/gcc%type_num[gccver]/lib/libquadmath.0.dylib 1.0.0 %n (>= 12.0.0-1) %p/lib/gcc%type_num[gccver]/lib/libatomic.1.dylib 4.0.0 %n (>= 12.0.0-1) - ( "%m" != "arm" ) %p/lib/gcc%type_num[gccver]/lib/libasan.8.dylib 9.0.0 %n (>= 12.0.0-1) - ( "%m" != "arm" ) %p/lib/gcc%type_num[gccver]/lib/libubsan.1.dylib 2.0.0 %n (>= 12.0.0-1) + ( "%m" != "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libasan.8.dylib 9.0.0 %n (>= 12.0.0-1) + ( "%m" != "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libubsan.1.dylib 2.0.0 %n (>= 12.0.0-1) << << SplitOff2: << @@ -288,7 +291,7 @@ DescDetail: << C, C++, Objective C and Fortran are included in this package. . The C and C++ compilers are named gcc-12 and g++-12 to avoid - conflicts with gcc and g++ installed by the Apple Developer Tools + conflicts with gcc and g++ installed by the Apple Developer Tools. << DescPackaging: << Build with -fsf-%type_num[gccver] suffix and place non-overlapping files into new gcc%type_num[gccver]-compiler @@ -304,10 +307,10 @@ DescPackaging: << need to add it's own -isysroot flag. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79885 - Homebrew patches for arm/aarch64 build and macOS 13 from - https://github.com/Homebrew/formula-patches/blob/master/gcc/gcc-%v-{arm,ventura}.diff - - libasan.* and libsubsan.* currently not built on arm. - There are both "1" and "1.1" versions of libgcc_s.dylib now, but only "1" on arm. + Homebrew patches for arm64/aarch64 build and macOS 13 from + https://github.com/Homebrew/formula-patches/blob/master/gcc/gcc-%v.diff + - libasan.* and libsubsan.* currently not built on arm64. + There are both "1" and "1.1" versions of libgcc_s.dylib now, but only "1.1" on arm64. Manual fixes of @rpath install_names required for aarch64 build to maintain downstream package compatibility. << diff --git a/10.9-libcxx/stable/main/finkinfo/languages/gcc12.patch b/10.9-libcxx/stable/main/finkinfo/languages/gcc12.patch new file mode 100644 index 00000000000..dae9d82450e --- /dev/null +++ b/10.9-libcxx/stable/main/finkinfo/languages/gcc12.patch @@ -0,0 +1,16840 @@ +diff --git a/Makefile.def b/Makefile.def +index 72d58549645..639cdd78988 100644 +--- a/Makefile.def ++++ b/Makefile.def +@@ -47,10 +47,11 @@ host_modules= { module= fixincludes; bootstrap=true; + host_modules= { module= flex; no_check_cross= true; }; + host_modules= { module= gas; bootstrap=true; }; + host_modules= { module= gcc; bootstrap=true; +- extra_make_flags="$(EXTRA_GCC_FLAGS)"; }; ++ extra_make_flags="$(EXTRA_GCC_FLAGS)"; ++ extra_configure_flags='@gcc_host_pie@'; }; + host_modules= { module= gmp; lib_path=.libs; bootstrap=true; + // Work around in-tree gmp configure bug with missing flex. +- extra_configure_flags='--disable-shared LEX="touch lex.yy.c"'; ++ extra_configure_flags='--disable-shared LEX="touch lex.yy.c" @host_libs_picflag@'; + extra_make_flags='AM_CFLAGS="-DNO_ASM"'; + no_install= true; + // none-*-* disables asm optimizations, bootstrap-testing +@@ -60,14 +61,14 @@ host_modules= { module= gmp; lib_path=.libs; bootstrap=true; + // different from host for target. + target="none-${host_vendor}-${host_os}"; }; + host_modules= { module= mpfr; lib_path=src/.libs; bootstrap=true; +- extra_configure_flags='--disable-shared @extra_mpfr_configure_flags@'; ++ extra_configure_flags='--disable-shared @extra_mpfr_configure_flags@ @host_libs_picflag@'; + extra_make_flags='AM_CFLAGS="-DNO_ASM"'; + no_install= true; }; + host_modules= { module= mpc; lib_path=src/.libs; bootstrap=true; +- extra_configure_flags='--disable-shared @extra_mpc_gmp_configure_flags@ @extra_mpc_mpfr_configure_flags@ --disable-maintainer-mode'; ++ extra_configure_flags='--disable-shared @extra_mpc_gmp_configure_flags@ @extra_mpc_mpfr_configure_flags@ @host_libs_picflag@ --disable-maintainer-mode'; + no_install= true; }; + host_modules= { module= isl; lib_path=.libs; bootstrap=true; +- extra_configure_flags='--disable-shared @extra_isl_gmp_configure_flags@'; ++ extra_configure_flags='--disable-shared @extra_isl_gmp_configure_flags@ @host_libs_picflag@'; + extra_make_flags='V=1'; + no_install= true; }; + host_modules= { module= libelf; lib_path=.libs; bootstrap=true; +@@ -75,6 +76,7 @@ host_modules= { module= libelf; lib_path=.libs; bootstrap=true; + no_install= true; }; + host_modules= { module= gold; bootstrap=true; }; + host_modules= { module= gprof; }; ++// intl acts on 'host_shared' directly, and does not support --with-pic. + host_modules= { module= intl; bootstrap=true; }; + host_modules= { module= tcl; + missing=mostlyclean; }; +@@ -110,7 +112,7 @@ host_modules= { module= libiberty-linker-plugin; bootstrap=true; + // We abuse missing to avoid installing anything for libiconv. + host_modules= { module= libiconv; + bootstrap=true; +- extra_configure_flags='--disable-shared'; ++ extra_configure_flags='--disable-shared @host_libs_picflag@'; + no_install= true; + missing= pdf; + missing= html; +@@ -125,7 +127,7 @@ host_modules= { module= sim; }; + host_modules= { module= texinfo; no_install= true; }; + host_modules= { module= zlib; no_install=true; no_check=true; + bootstrap=true; +- extra_configure_flags='@extra_host_zlib_configure_flags@';}; ++ extra_configure_flags='@extra_host_zlib_configure_flags@ @host_libs_picflag@';}; + host_modules= { module= gnulib; }; + host_modules= { module= gdbsupport; }; + host_modules= { module= gdbserver; }; +diff --git a/Makefile.in b/Makefile.in +index 593495e1650..e3b44f99a7d 100644 +--- a/Makefile.in ++++ b/Makefile.in +@@ -12012,7 +12012,7 @@ configure-gcc: + $$s/$$module_srcdir/configure \ + --srcdir=$${topdir}/$$module_srcdir \ + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ +- --target=${target_alias} \ ++ --target=${target_alias} @gcc_host_pie@ \ + || exit 1 + @endif gcc + +@@ -12047,7 +12047,8 @@ configure-stage1-gcc: + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ + --target=${target_alias} \ + \ +- $(STAGE1_CONFIGURE_FLAGS) ++ $(STAGE1_CONFIGURE_FLAGS) \ ++ @gcc_host_pie@ + @endif gcc-bootstrap + + .PHONY: configure-stage2-gcc maybe-configure-stage2-gcc +@@ -12080,7 +12081,8 @@ configure-stage2-gcc: + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ +- $(STAGE2_CONFIGURE_FLAGS) ++ $(STAGE2_CONFIGURE_FLAGS) \ ++ @gcc_host_pie@ + @endif gcc-bootstrap + + .PHONY: configure-stage3-gcc maybe-configure-stage3-gcc +@@ -12113,7 +12115,8 @@ configure-stage3-gcc: + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ +- $(STAGE3_CONFIGURE_FLAGS) ++ $(STAGE3_CONFIGURE_FLAGS) \ ++ @gcc_host_pie@ + @endif gcc-bootstrap + + .PHONY: configure-stage4-gcc maybe-configure-stage4-gcc +@@ -12146,7 +12149,8 @@ configure-stage4-gcc: + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ +- $(STAGE4_CONFIGURE_FLAGS) ++ $(STAGE4_CONFIGURE_FLAGS) \ ++ @gcc_host_pie@ + @endif gcc-bootstrap + + .PHONY: configure-stageprofile-gcc maybe-configure-stageprofile-gcc +@@ -12179,7 +12183,8 @@ configure-stageprofile-gcc: + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ +- $(STAGEprofile_CONFIGURE_FLAGS) ++ $(STAGEprofile_CONFIGURE_FLAGS) \ ++ @gcc_host_pie@ + @endif gcc-bootstrap + + .PHONY: configure-stagetrain-gcc maybe-configure-stagetrain-gcc +@@ -12212,7 +12217,8 @@ configure-stagetrain-gcc: + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ +- $(STAGEtrain_CONFIGURE_FLAGS) ++ $(STAGEtrain_CONFIGURE_FLAGS) \ ++ @gcc_host_pie@ + @endif gcc-bootstrap + + .PHONY: configure-stagefeedback-gcc maybe-configure-stagefeedback-gcc +@@ -12245,7 +12251,8 @@ configure-stagefeedback-gcc: + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ +- $(STAGEfeedback_CONFIGURE_FLAGS) ++ $(STAGEfeedback_CONFIGURE_FLAGS) \ ++ @gcc_host_pie@ + @endif gcc-bootstrap + + .PHONY: configure-stageautoprofile-gcc maybe-configure-stageautoprofile-gcc +@@ -12278,7 +12285,8 @@ configure-stageautoprofile-gcc: + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ +- $(STAGEautoprofile_CONFIGURE_FLAGS) ++ $(STAGEautoprofile_CONFIGURE_FLAGS) \ ++ @gcc_host_pie@ + @endif gcc-bootstrap + + .PHONY: configure-stageautofeedback-gcc maybe-configure-stageautofeedback-gcc +@@ -12311,7 +12319,8 @@ configure-stageautofeedback-gcc: + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ +- $(STAGEautofeedback_CONFIGURE_FLAGS) ++ $(STAGEautofeedback_CONFIGURE_FLAGS) \ ++ @gcc_host_pie@ + @endif gcc-bootstrap + + +@@ -13152,7 +13161,7 @@ configure-gmp: + $$s/$$module_srcdir/configure \ + --srcdir=$${topdir}/$$module_srcdir \ + $(HOST_CONFIGARGS) --build=${build_alias} --host=none-${host_vendor}-${host_os} \ +- --target=none-${host_vendor}-${host_os} --disable-shared LEX="touch lex.yy.c" \ ++ --target=none-${host_vendor}-${host_os} --disable-shared LEX="touch lex.yy.c" @host_libs_picflag@ \ + || exit 1 + @endif gmp + +@@ -13188,7 +13197,7 @@ configure-stage1-gmp: + --target=none-${host_vendor}-${host_os} \ + \ + $(STAGE1_CONFIGURE_FLAGS) \ +- --disable-shared LEX="touch lex.yy.c" ++ --disable-shared LEX="touch lex.yy.c" @host_libs_picflag@ + @endif gmp-bootstrap + + .PHONY: configure-stage2-gmp maybe-configure-stage2-gmp +@@ -13222,7 +13231,7 @@ configure-stage2-gmp: + --target=none-${host_vendor}-${host_os} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGE2_CONFIGURE_FLAGS) \ +- --disable-shared LEX="touch lex.yy.c" ++ --disable-shared LEX="touch lex.yy.c" @host_libs_picflag@ + @endif gmp-bootstrap + + .PHONY: configure-stage3-gmp maybe-configure-stage3-gmp +@@ -13256,7 +13265,7 @@ configure-stage3-gmp: + --target=none-${host_vendor}-${host_os} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGE3_CONFIGURE_FLAGS) \ +- --disable-shared LEX="touch lex.yy.c" ++ --disable-shared LEX="touch lex.yy.c" @host_libs_picflag@ + @endif gmp-bootstrap + + .PHONY: configure-stage4-gmp maybe-configure-stage4-gmp +@@ -13290,7 +13299,7 @@ configure-stage4-gmp: + --target=none-${host_vendor}-${host_os} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGE4_CONFIGURE_FLAGS) \ +- --disable-shared LEX="touch lex.yy.c" ++ --disable-shared LEX="touch lex.yy.c" @host_libs_picflag@ + @endif gmp-bootstrap + + .PHONY: configure-stageprofile-gmp maybe-configure-stageprofile-gmp +@@ -13324,7 +13333,7 @@ configure-stageprofile-gmp: + --target=none-${host_vendor}-${host_os} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEprofile_CONFIGURE_FLAGS) \ +- --disable-shared LEX="touch lex.yy.c" ++ --disable-shared LEX="touch lex.yy.c" @host_libs_picflag@ + @endif gmp-bootstrap + + .PHONY: configure-stagetrain-gmp maybe-configure-stagetrain-gmp +@@ -13358,7 +13367,7 @@ configure-stagetrain-gmp: + --target=none-${host_vendor}-${host_os} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEtrain_CONFIGURE_FLAGS) \ +- --disable-shared LEX="touch lex.yy.c" ++ --disable-shared LEX="touch lex.yy.c" @host_libs_picflag@ + @endif gmp-bootstrap + + .PHONY: configure-stagefeedback-gmp maybe-configure-stagefeedback-gmp +@@ -13392,7 +13401,7 @@ configure-stagefeedback-gmp: + --target=none-${host_vendor}-${host_os} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEfeedback_CONFIGURE_FLAGS) \ +- --disable-shared LEX="touch lex.yy.c" ++ --disable-shared LEX="touch lex.yy.c" @host_libs_picflag@ + @endif gmp-bootstrap + + .PHONY: configure-stageautoprofile-gmp maybe-configure-stageautoprofile-gmp +@@ -13426,7 +13435,7 @@ configure-stageautoprofile-gmp: + --target=none-${host_vendor}-${host_os} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEautoprofile_CONFIGURE_FLAGS) \ +- --disable-shared LEX="touch lex.yy.c" ++ --disable-shared LEX="touch lex.yy.c" @host_libs_picflag@ + @endif gmp-bootstrap + + .PHONY: configure-stageautofeedback-gmp maybe-configure-stageautofeedback-gmp +@@ -13460,7 +13469,7 @@ configure-stageautofeedback-gmp: + --target=none-${host_vendor}-${host_os} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEautofeedback_CONFIGURE_FLAGS) \ +- --disable-shared LEX="touch lex.yy.c" ++ --disable-shared LEX="touch lex.yy.c" @host_libs_picflag@ + @endif gmp-bootstrap + + +@@ -14289,7 +14298,7 @@ configure-mpfr: + $$s/$$module_srcdir/configure \ + --srcdir=$${topdir}/$$module_srcdir \ + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ +- --target=${target_alias} --disable-shared @extra_mpfr_configure_flags@ \ ++ --target=${target_alias} --disable-shared @extra_mpfr_configure_flags@ @host_libs_picflag@ \ + || exit 1 + @endif mpfr + +@@ -14325,7 +14334,7 @@ configure-stage1-mpfr: + --target=${target_alias} \ + \ + $(STAGE1_CONFIGURE_FLAGS) \ +- --disable-shared @extra_mpfr_configure_flags@ ++ --disable-shared @extra_mpfr_configure_flags@ @host_libs_picflag@ + @endif mpfr-bootstrap + + .PHONY: configure-stage2-mpfr maybe-configure-stage2-mpfr +@@ -14359,7 +14368,7 @@ configure-stage2-mpfr: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGE2_CONFIGURE_FLAGS) \ +- --disable-shared @extra_mpfr_configure_flags@ ++ --disable-shared @extra_mpfr_configure_flags@ @host_libs_picflag@ + @endif mpfr-bootstrap + + .PHONY: configure-stage3-mpfr maybe-configure-stage3-mpfr +@@ -14393,7 +14402,7 @@ configure-stage3-mpfr: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGE3_CONFIGURE_FLAGS) \ +- --disable-shared @extra_mpfr_configure_flags@ ++ --disable-shared @extra_mpfr_configure_flags@ @host_libs_picflag@ + @endif mpfr-bootstrap + + .PHONY: configure-stage4-mpfr maybe-configure-stage4-mpfr +@@ -14427,7 +14436,7 @@ configure-stage4-mpfr: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGE4_CONFIGURE_FLAGS) \ +- --disable-shared @extra_mpfr_configure_flags@ ++ --disable-shared @extra_mpfr_configure_flags@ @host_libs_picflag@ + @endif mpfr-bootstrap + + .PHONY: configure-stageprofile-mpfr maybe-configure-stageprofile-mpfr +@@ -14461,7 +14470,7 @@ configure-stageprofile-mpfr: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEprofile_CONFIGURE_FLAGS) \ +- --disable-shared @extra_mpfr_configure_flags@ ++ --disable-shared @extra_mpfr_configure_flags@ @host_libs_picflag@ + @endif mpfr-bootstrap + + .PHONY: configure-stagetrain-mpfr maybe-configure-stagetrain-mpfr +@@ -14495,7 +14504,7 @@ configure-stagetrain-mpfr: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEtrain_CONFIGURE_FLAGS) \ +- --disable-shared @extra_mpfr_configure_flags@ ++ --disable-shared @extra_mpfr_configure_flags@ @host_libs_picflag@ + @endif mpfr-bootstrap + + .PHONY: configure-stagefeedback-mpfr maybe-configure-stagefeedback-mpfr +@@ -14529,7 +14538,7 @@ configure-stagefeedback-mpfr: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEfeedback_CONFIGURE_FLAGS) \ +- --disable-shared @extra_mpfr_configure_flags@ ++ --disable-shared @extra_mpfr_configure_flags@ @host_libs_picflag@ + @endif mpfr-bootstrap + + .PHONY: configure-stageautoprofile-mpfr maybe-configure-stageautoprofile-mpfr +@@ -14563,7 +14572,7 @@ configure-stageautoprofile-mpfr: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEautoprofile_CONFIGURE_FLAGS) \ +- --disable-shared @extra_mpfr_configure_flags@ ++ --disable-shared @extra_mpfr_configure_flags@ @host_libs_picflag@ + @endif mpfr-bootstrap + + .PHONY: configure-stageautofeedback-mpfr maybe-configure-stageautofeedback-mpfr +@@ -14597,7 +14606,7 @@ configure-stageautofeedback-mpfr: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEautofeedback_CONFIGURE_FLAGS) \ +- --disable-shared @extra_mpfr_configure_flags@ ++ --disable-shared @extra_mpfr_configure_flags@ @host_libs_picflag@ + @endif mpfr-bootstrap + + +@@ -15426,7 +15435,7 @@ configure-mpc: + $$s/$$module_srcdir/configure \ + --srcdir=$${topdir}/$$module_srcdir \ + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ +- --target=${target_alias} --disable-shared @extra_mpc_gmp_configure_flags@ @extra_mpc_mpfr_configure_flags@ --disable-maintainer-mode \ ++ --target=${target_alias} --disable-shared @extra_mpc_gmp_configure_flags@ @extra_mpc_mpfr_configure_flags@ @host_libs_picflag@ --disable-maintainer-mode \ + || exit 1 + @endif mpc + +@@ -15462,7 +15471,7 @@ configure-stage1-mpc: + --target=${target_alias} \ + \ + $(STAGE1_CONFIGURE_FLAGS) \ +- --disable-shared @extra_mpc_gmp_configure_flags@ @extra_mpc_mpfr_configure_flags@ --disable-maintainer-mode ++ --disable-shared @extra_mpc_gmp_configure_flags@ @extra_mpc_mpfr_configure_flags@ @host_libs_picflag@ --disable-maintainer-mode + @endif mpc-bootstrap + + .PHONY: configure-stage2-mpc maybe-configure-stage2-mpc +@@ -15496,7 +15505,7 @@ configure-stage2-mpc: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGE2_CONFIGURE_FLAGS) \ +- --disable-shared @extra_mpc_gmp_configure_flags@ @extra_mpc_mpfr_configure_flags@ --disable-maintainer-mode ++ --disable-shared @extra_mpc_gmp_configure_flags@ @extra_mpc_mpfr_configure_flags@ @host_libs_picflag@ --disable-maintainer-mode + @endif mpc-bootstrap + + .PHONY: configure-stage3-mpc maybe-configure-stage3-mpc +@@ -15530,7 +15539,7 @@ configure-stage3-mpc: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGE3_CONFIGURE_FLAGS) \ +- --disable-shared @extra_mpc_gmp_configure_flags@ @extra_mpc_mpfr_configure_flags@ --disable-maintainer-mode ++ --disable-shared @extra_mpc_gmp_configure_flags@ @extra_mpc_mpfr_configure_flags@ @host_libs_picflag@ --disable-maintainer-mode + @endif mpc-bootstrap + + .PHONY: configure-stage4-mpc maybe-configure-stage4-mpc +@@ -15564,7 +15573,7 @@ configure-stage4-mpc: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGE4_CONFIGURE_FLAGS) \ +- --disable-shared @extra_mpc_gmp_configure_flags@ @extra_mpc_mpfr_configure_flags@ --disable-maintainer-mode ++ --disable-shared @extra_mpc_gmp_configure_flags@ @extra_mpc_mpfr_configure_flags@ @host_libs_picflag@ --disable-maintainer-mode + @endif mpc-bootstrap + + .PHONY: configure-stageprofile-mpc maybe-configure-stageprofile-mpc +@@ -15598,7 +15607,7 @@ configure-stageprofile-mpc: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEprofile_CONFIGURE_FLAGS) \ +- --disable-shared @extra_mpc_gmp_configure_flags@ @extra_mpc_mpfr_configure_flags@ --disable-maintainer-mode ++ --disable-shared @extra_mpc_gmp_configure_flags@ @extra_mpc_mpfr_configure_flags@ @host_libs_picflag@ --disable-maintainer-mode + @endif mpc-bootstrap + + .PHONY: configure-stagetrain-mpc maybe-configure-stagetrain-mpc +@@ -15632,7 +15641,7 @@ configure-stagetrain-mpc: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEtrain_CONFIGURE_FLAGS) \ +- --disable-shared @extra_mpc_gmp_configure_flags@ @extra_mpc_mpfr_configure_flags@ --disable-maintainer-mode ++ --disable-shared @extra_mpc_gmp_configure_flags@ @extra_mpc_mpfr_configure_flags@ @host_libs_picflag@ --disable-maintainer-mode + @endif mpc-bootstrap + + .PHONY: configure-stagefeedback-mpc maybe-configure-stagefeedback-mpc +@@ -15666,7 +15675,7 @@ configure-stagefeedback-mpc: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEfeedback_CONFIGURE_FLAGS) \ +- --disable-shared @extra_mpc_gmp_configure_flags@ @extra_mpc_mpfr_configure_flags@ --disable-maintainer-mode ++ --disable-shared @extra_mpc_gmp_configure_flags@ @extra_mpc_mpfr_configure_flags@ @host_libs_picflag@ --disable-maintainer-mode + @endif mpc-bootstrap + + .PHONY: configure-stageautoprofile-mpc maybe-configure-stageautoprofile-mpc +@@ -15700,7 +15709,7 @@ configure-stageautoprofile-mpc: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEautoprofile_CONFIGURE_FLAGS) \ +- --disable-shared @extra_mpc_gmp_configure_flags@ @extra_mpc_mpfr_configure_flags@ --disable-maintainer-mode ++ --disable-shared @extra_mpc_gmp_configure_flags@ @extra_mpc_mpfr_configure_flags@ @host_libs_picflag@ --disable-maintainer-mode + @endif mpc-bootstrap + + .PHONY: configure-stageautofeedback-mpc maybe-configure-stageautofeedback-mpc +@@ -15734,7 +15743,7 @@ configure-stageautofeedback-mpc: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEautofeedback_CONFIGURE_FLAGS) \ +- --disable-shared @extra_mpc_gmp_configure_flags@ @extra_mpc_mpfr_configure_flags@ --disable-maintainer-mode ++ --disable-shared @extra_mpc_gmp_configure_flags@ @extra_mpc_mpfr_configure_flags@ @host_libs_picflag@ --disable-maintainer-mode + @endif mpc-bootstrap + + +@@ -16563,7 +16572,7 @@ configure-isl: + $$s/$$module_srcdir/configure \ + --srcdir=$${topdir}/$$module_srcdir \ + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ +- --target=${target_alias} --disable-shared @extra_isl_gmp_configure_flags@ \ ++ --target=${target_alias} --disable-shared @extra_isl_gmp_configure_flags@ @host_libs_picflag@ \ + || exit 1 + @endif isl + +@@ -16599,7 +16608,7 @@ configure-stage1-isl: + --target=${target_alias} \ + \ + $(STAGE1_CONFIGURE_FLAGS) \ +- --disable-shared @extra_isl_gmp_configure_flags@ ++ --disable-shared @extra_isl_gmp_configure_flags@ @host_libs_picflag@ + @endif isl-bootstrap + + .PHONY: configure-stage2-isl maybe-configure-stage2-isl +@@ -16633,7 +16642,7 @@ configure-stage2-isl: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGE2_CONFIGURE_FLAGS) \ +- --disable-shared @extra_isl_gmp_configure_flags@ ++ --disable-shared @extra_isl_gmp_configure_flags@ @host_libs_picflag@ + @endif isl-bootstrap + + .PHONY: configure-stage3-isl maybe-configure-stage3-isl +@@ -16667,7 +16676,7 @@ configure-stage3-isl: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGE3_CONFIGURE_FLAGS) \ +- --disable-shared @extra_isl_gmp_configure_flags@ ++ --disable-shared @extra_isl_gmp_configure_flags@ @host_libs_picflag@ + @endif isl-bootstrap + + .PHONY: configure-stage4-isl maybe-configure-stage4-isl +@@ -16701,7 +16710,7 @@ configure-stage4-isl: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGE4_CONFIGURE_FLAGS) \ +- --disable-shared @extra_isl_gmp_configure_flags@ ++ --disable-shared @extra_isl_gmp_configure_flags@ @host_libs_picflag@ + @endif isl-bootstrap + + .PHONY: configure-stageprofile-isl maybe-configure-stageprofile-isl +@@ -16735,7 +16744,7 @@ configure-stageprofile-isl: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEprofile_CONFIGURE_FLAGS) \ +- --disable-shared @extra_isl_gmp_configure_flags@ ++ --disable-shared @extra_isl_gmp_configure_flags@ @host_libs_picflag@ + @endif isl-bootstrap + + .PHONY: configure-stagetrain-isl maybe-configure-stagetrain-isl +@@ -16769,7 +16778,7 @@ configure-stagetrain-isl: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEtrain_CONFIGURE_FLAGS) \ +- --disable-shared @extra_isl_gmp_configure_flags@ ++ --disable-shared @extra_isl_gmp_configure_flags@ @host_libs_picflag@ + @endif isl-bootstrap + + .PHONY: configure-stagefeedback-isl maybe-configure-stagefeedback-isl +@@ -16803,7 +16812,7 @@ configure-stagefeedback-isl: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEfeedback_CONFIGURE_FLAGS) \ +- --disable-shared @extra_isl_gmp_configure_flags@ ++ --disable-shared @extra_isl_gmp_configure_flags@ @host_libs_picflag@ + @endif isl-bootstrap + + .PHONY: configure-stageautoprofile-isl maybe-configure-stageautoprofile-isl +@@ -16837,7 +16846,7 @@ configure-stageautoprofile-isl: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEautoprofile_CONFIGURE_FLAGS) \ +- --disable-shared @extra_isl_gmp_configure_flags@ ++ --disable-shared @extra_isl_gmp_configure_flags@ @host_libs_picflag@ + @endif isl-bootstrap + + .PHONY: configure-stageautofeedback-isl maybe-configure-stageautofeedback-isl +@@ -16871,7 +16880,7 @@ configure-stageautofeedback-isl: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEautofeedback_CONFIGURE_FLAGS) \ +- --disable-shared @extra_isl_gmp_configure_flags@ ++ --disable-shared @extra_isl_gmp_configure_flags@ @host_libs_picflag@ + @endif isl-bootstrap + + +@@ -30806,7 +30815,7 @@ configure-libiconv: + $$s/$$module_srcdir/configure \ + --srcdir=$${topdir}/$$module_srcdir \ + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ +- --target=${target_alias} --disable-shared \ ++ --target=${target_alias} --disable-shared @host_libs_picflag@ \ + || exit 1 + @endif libiconv + +@@ -30842,7 +30851,7 @@ configure-stage1-libiconv: + --target=${target_alias} \ + \ + $(STAGE1_CONFIGURE_FLAGS) \ +- --disable-shared ++ --disable-shared @host_libs_picflag@ + @endif libiconv-bootstrap + + .PHONY: configure-stage2-libiconv maybe-configure-stage2-libiconv +@@ -30876,7 +30885,7 @@ configure-stage2-libiconv: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGE2_CONFIGURE_FLAGS) \ +- --disable-shared ++ --disable-shared @host_libs_picflag@ + @endif libiconv-bootstrap + + .PHONY: configure-stage3-libiconv maybe-configure-stage3-libiconv +@@ -30910,7 +30919,7 @@ configure-stage3-libiconv: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGE3_CONFIGURE_FLAGS) \ +- --disable-shared ++ --disable-shared @host_libs_picflag@ + @endif libiconv-bootstrap + + .PHONY: configure-stage4-libiconv maybe-configure-stage4-libiconv +@@ -30944,7 +30953,7 @@ configure-stage4-libiconv: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGE4_CONFIGURE_FLAGS) \ +- --disable-shared ++ --disable-shared @host_libs_picflag@ + @endif libiconv-bootstrap + + .PHONY: configure-stageprofile-libiconv maybe-configure-stageprofile-libiconv +@@ -30978,7 +30987,7 @@ configure-stageprofile-libiconv: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEprofile_CONFIGURE_FLAGS) \ +- --disable-shared ++ --disable-shared @host_libs_picflag@ + @endif libiconv-bootstrap + + .PHONY: configure-stagetrain-libiconv maybe-configure-stagetrain-libiconv +@@ -31012,7 +31021,7 @@ configure-stagetrain-libiconv: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEtrain_CONFIGURE_FLAGS) \ +- --disable-shared ++ --disable-shared @host_libs_picflag@ + @endif libiconv-bootstrap + + .PHONY: configure-stagefeedback-libiconv maybe-configure-stagefeedback-libiconv +@@ -31046,7 +31055,7 @@ configure-stagefeedback-libiconv: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEfeedback_CONFIGURE_FLAGS) \ +- --disable-shared ++ --disable-shared @host_libs_picflag@ + @endif libiconv-bootstrap + + .PHONY: configure-stageautoprofile-libiconv maybe-configure-stageautoprofile-libiconv +@@ -31080,7 +31089,7 @@ configure-stageautoprofile-libiconv: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEautoprofile_CONFIGURE_FLAGS) \ +- --disable-shared ++ --disable-shared @host_libs_picflag@ + @endif libiconv-bootstrap + + .PHONY: configure-stageautofeedback-libiconv maybe-configure-stageautofeedback-libiconv +@@ -31114,7 +31123,7 @@ configure-stageautofeedback-libiconv: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEautofeedback_CONFIGURE_FLAGS) \ +- --disable-shared ++ --disable-shared @host_libs_picflag@ + @endif libiconv-bootstrap + + +@@ -34178,7 +34187,7 @@ configure-zlib: + $$s/$$module_srcdir/configure \ + --srcdir=$${topdir}/$$module_srcdir \ + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ +- --target=${target_alias} @extra_host_zlib_configure_flags@ \ ++ --target=${target_alias} @extra_host_zlib_configure_flags@ @host_libs_picflag@ \ + || exit 1 + @endif zlib + +@@ -34214,7 +34223,7 @@ configure-stage1-zlib: + --target=${target_alias} \ + \ + $(STAGE1_CONFIGURE_FLAGS) \ +- @extra_host_zlib_configure_flags@ ++ @extra_host_zlib_configure_flags@ @host_libs_picflag@ + @endif zlib-bootstrap + + .PHONY: configure-stage2-zlib maybe-configure-stage2-zlib +@@ -34248,7 +34257,7 @@ configure-stage2-zlib: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGE2_CONFIGURE_FLAGS) \ +- @extra_host_zlib_configure_flags@ ++ @extra_host_zlib_configure_flags@ @host_libs_picflag@ + @endif zlib-bootstrap + + .PHONY: configure-stage3-zlib maybe-configure-stage3-zlib +@@ -34282,7 +34291,7 @@ configure-stage3-zlib: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGE3_CONFIGURE_FLAGS) \ +- @extra_host_zlib_configure_flags@ ++ @extra_host_zlib_configure_flags@ @host_libs_picflag@ + @endif zlib-bootstrap + + .PHONY: configure-stage4-zlib maybe-configure-stage4-zlib +@@ -34316,7 +34325,7 @@ configure-stage4-zlib: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGE4_CONFIGURE_FLAGS) \ +- @extra_host_zlib_configure_flags@ ++ @extra_host_zlib_configure_flags@ @host_libs_picflag@ + @endif zlib-bootstrap + + .PHONY: configure-stageprofile-zlib maybe-configure-stageprofile-zlib +@@ -34350,7 +34359,7 @@ configure-stageprofile-zlib: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEprofile_CONFIGURE_FLAGS) \ +- @extra_host_zlib_configure_flags@ ++ @extra_host_zlib_configure_flags@ @host_libs_picflag@ + @endif zlib-bootstrap + + .PHONY: configure-stagetrain-zlib maybe-configure-stagetrain-zlib +@@ -34384,7 +34393,7 @@ configure-stagetrain-zlib: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEtrain_CONFIGURE_FLAGS) \ +- @extra_host_zlib_configure_flags@ ++ @extra_host_zlib_configure_flags@ @host_libs_picflag@ + @endif zlib-bootstrap + + .PHONY: configure-stagefeedback-zlib maybe-configure-stagefeedback-zlib +@@ -34418,7 +34427,7 @@ configure-stagefeedback-zlib: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEfeedback_CONFIGURE_FLAGS) \ +- @extra_host_zlib_configure_flags@ ++ @extra_host_zlib_configure_flags@ @host_libs_picflag@ + @endif zlib-bootstrap + + .PHONY: configure-stageautoprofile-zlib maybe-configure-stageautoprofile-zlib +@@ -34452,7 +34461,7 @@ configure-stageautoprofile-zlib: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEautoprofile_CONFIGURE_FLAGS) \ +- @extra_host_zlib_configure_flags@ ++ @extra_host_zlib_configure_flags@ @host_libs_picflag@ + @endif zlib-bootstrap + + .PHONY: configure-stageautofeedback-zlib maybe-configure-stageautofeedback-zlib +@@ -34486,7 +34495,7 @@ configure-stageautofeedback-zlib: + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ + $(STAGEautofeedback_CONFIGURE_FLAGS) \ +- @extra_host_zlib_configure_flags@ ++ @extra_host_zlib_configure_flags@ @host_libs_picflag@ + @endif zlib-bootstrap + + +diff --git a/c++tools/Makefile.in b/c++tools/Makefile.in +index d6a33613732..4d5a5b0522b 100644 +--- a/c++tools/Makefile.in ++++ b/c++tools/Makefile.in +@@ -28,8 +28,9 @@ AUTOCONF := @AUTOCONF@ + AUTOHEADER := @AUTOHEADER@ + CXX := @CXX@ + CXXFLAGS := @CXXFLAGS@ +-PIEFLAG := @PIEFLAG@ +-CXXOPTS := $(CXXFLAGS) $(PIEFLAG) -fno-exceptions -fno-rtti ++PICFLAG := @PICFLAG@ ++LD_PICFLAG := @LD_PICFLAG@ ++CXXOPTS := $(CXXFLAGS) $(PICFLAG) -fno-exceptions -fno-rtti + LDFLAGS := @LDFLAGS@ + exeext := @EXEEXT@ + LIBIBERTY := ../libiberty/libiberty.a +@@ -88,11 +89,15 @@ ifeq (@CXX_AUX_TOOLS@,yes) + + all::g++-mapper-server$(exeext) + ++ifneq ($(PICFLAG),) ++override LIBIBERTY := ../libiberty/pic/libiberty.a ++endif ++ + MAPPER.O := server.o resolver.o + CODYLIB = ../libcody/libcody.a + CXXINC += -I$(srcdir)/../libcody -I$(srcdir)/../include -I$(srcdir)/../gcc -I. -I../gcc + g++-mapper-server$(exeext): $(MAPPER.O) $(CODYLIB) +- +$(CXX) $(LDFLAGS) $(PIEFLAG) -o $@ $^ $(LIBIBERTY) $(NETLIBS) ++ +$(CXX) $(LDFLAGS) $(PICFLAG) $(LD_PICFLAG) -o $@ $^ $(LIBIBERTY) $(NETLIBS) + + # copy to gcc dir so tests there can run + all::../gcc/g++-mapper-server$(exeext) +diff --git a/c++tools/configure b/c++tools/configure +index 742816e4253..88087009383 100755 +--- a/c++tools/configure ++++ b/c++tools/configure +@@ -627,7 +627,8 @@ get_gcc_base_ver + EGREP + GREP + CXXCPP +-PIEFLAG ++LD_PICFLAG ++PICFLAG + MAINTAINER + CXX_AUX_TOOLS + AUTOHEADER +@@ -700,6 +701,7 @@ enable_c___tools + enable_maintainer_mode + enable_checking + enable_default_pie ++enable_host_pie + with_gcc_major_version_only + ' + ac_precious_vars='build_alias +@@ -1333,6 +1335,7 @@ Optional Features: + only specific categories of checks. Categories are: + yes,no,all,none,release. + --enable-default-pie enable Position Independent Executable as default ++ --enable-host-pie build host code as PIE + + Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] +@@ -2990,12 +2993,20 @@ fi + # Check whether --enable-default-pie was given. + # Check whether --enable-default-pie was given. + if test "${enable_default_pie+set}" = set; then : +- enableval=$enable_default_pie; PIEFLAG=-fPIE ++ enableval=$enable_default_pie; PICFLAG=-fPIE + else +- PIEFLAG= ++ PICFLAG= + fi + + ++# Enable --enable-host-pie ++# Check whether --enable-host-pie was given. ++if test "${enable_host_pie+set}" = set; then : ++ enableval=$enable_host_pie; PICFLAG=-fPIE; LD_PICFLAG=-pie ++fi ++ ++ ++ + + # Check if O_CLOEXEC is defined by fcntl + +diff --git a/c++tools/configure.ac b/c++tools/configure.ac +index 6662b5ad7c9..1e42689f2eb 100644 +--- a/c++tools/configure.ac ++++ b/c++tools/configure.ac +@@ -102,8 +102,15 @@ fi + AC_ARG_ENABLE(default-pie, + [AS_HELP_STRING([--enable-default-pie], + [enable Position Independent Executable as default])], +-[PIEFLAG=-fPIE], [PIEFLAG=]) +-AC_SUBST([PIEFLAG]) ++[PICFLAG=-fPIE], [PICFLAG=]) ++ ++# Enable --enable-host-pie ++AC_ARG_ENABLE(host-pie, ++[AS_HELP_STRING([--enable-host-pie], ++ [build host code as PIE])], ++[PICFLAG=-fPIE; LD_PICFLAG=-pie], []) ++AC_SUBST(PICFLAG) ++AC_SUBST(LD_PICFLAG) + + # Check if O_CLOEXEC is defined by fcntl + AC_CACHE_CHECK(for O_CLOEXEC, ac_cv_o_cloexec, [ +diff --git a/configure b/configure +index 77638bc84a6..6b5016ac5c2 100755 +--- a/configure ++++ b/configure +@@ -685,7 +685,11 @@ get_gcc_base_ver + extra_host_zlib_configure_flags + extra_host_libiberty_configure_flags + stage1_languages ++host_libs_picflag ++PICFLAG + host_shared ++gcc_host_pie ++host_pie + extra_linker_plugin_flags + extra_linker_plugin_configure_flags + islinc +@@ -829,6 +833,7 @@ enable_isl_version_check + enable_lto + enable_linker_plugin_configure_flags + enable_linker_plugin_flags ++enable_host_pie + enable_host_shared + enable_stage1_languages + enable_objc_gc +@@ -1557,6 +1562,7 @@ Optional Features: + --enable-linker-plugin-flags=FLAGS + additional flags for configuring and building linker + plugins [none] ++ --enable-host-pie build position independent host executables + --enable-host-shared build host code as shared libraries + --enable-stage1-languages[=all] + choose additional languages to build during stage1. +@@ -3488,6 +3494,8 @@ esac + + # Disable libffi for some systems. + case "${target}" in ++ aarch64*-*-darwin2*) ++ ;; + powerpc-*-darwin*) + ;; + i[3456789]86-*-darwin*) +@@ -8410,6 +8418,20 @@ else + fi + fi + ++case $target in ++ *-darwin2* | *-darwin1[56789]*) ++ # For these versions, we default to using embedded rpaths. ++ if test "x$enable_darwin_at_rpath" != "xno"; then ++ poststage1_ldflags="$poststage1_ldflags -nodefaultrpaths" ++ fi ++ ;; ++ *-darwin*) ++ # For these versions, we only use embedded rpaths on demand. ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ poststage1_ldflags="$poststage1_ldflags -nodefaultrpaths" ++ fi ++ ;; ++esac + + + # GCC GRAPHITE dependency isl. +@@ -8641,6 +8663,39 @@ fi + + + ++# Handle --enable-host-pie ++# If host PIE executables are the default (or must be forced on) for some host, ++# we must pass that configuration to the gcc directory. ++gcc_host_pie= ++# Check whether --enable-host-pie was given. ++if test "${enable_host_pie+set}" = set; then : ++ enableval=$enable_host_pie; host_pie=$enableval ++ case $host in ++ *-*-darwin2*) ++ if test x$host_pie != xyes ; then ++ # for Darwin20+ this is required. ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: PIE executables are required for the configured host, host-pie setting ignored." >&5 ++$as_echo "$as_me: WARNING: PIE executables are required for the configured host, host-pie setting ignored." >&2;} ++ host_pie=yes ++ gcc_host_pie=--enable-host-pie ++ fi ;; ++ *) ;; ++ esac ++else ++ case $host in ++ *-*-darwin2*) ++ # Default to PIE (mandatory for aarch64). ++ host_pie=yes ++ gcc_host_pie=--enable-host-pie ++ ;; ++ *) host_pie=no ;; ++ esac ++fi ++ ++ ++ ++ ++ + # Enable --enable-host-shared. + # Checked early to determine whether jit is an 'all' language + # Check whether --enable-host-shared was given. +@@ -8650,20 +8705,60 @@ if test "${enable_host_shared+set}" = set; then : + x86_64-*-darwin* | aarch64-*-darwin*) + if test x$host_shared != xyes ; then + # PIC is the default, and actually cannot be switched off. +- echo configure.ac: warning: PIC code is required for the configured target, host-shared setting ignored. 1>&2 ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: PIC code is required for the configured host; host-shared setting ignored." >&5 ++$as_echo "$as_me: WARNING: PIC code is required for the configured host; host-shared setting ignored." >&2;} ++ host_shared=yes ++ fi ;; ++ *-*-darwin*) ++ if test x$host_pie = xyes -a x$host_shared != xyes ; then ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: PIC code is required for PIE host executables host-shared setting ignored." >&5 ++$as_echo "$as_me: WARNING: PIC code is required for PIE host executables host-shared setting ignored." >&2;} + host_shared=yes + fi ;; + *) ;; + esac + else +- case $target in ++ case $host in ++ # 64B x86_64 and Aarch64 Darwin default to PIC. + x86_64-*-darwin* | aarch64-*-darwin*) host_shared=yes ;; +- *) host_shared=no ;; ++ # 32B and powerpc64 Darwin must use PIC to link PIE exes. ++ *-*-darwin*) host_shared=$host_pie ;; ++ *) host_shared=no;; + esac + fi + + + ++if test x$host_shared = xyes; then ++ case $host in ++ *-*-darwin*) ++ # Since host shared is the default for 64b Darwin, and also enabled for ++ # host_pie, ensure that we present the PIE flag when host_pie is active. ++ if test x$host_pie = xyes; then ++ PICFLAG=-fPIE ++ fi ++ ;; ++ *) ++ PICFLAG=-fPIC ++ ;; ++ esac ++elif test x$host_pie = xyes; then ++ PICFLAG=-fPIE ++else ++ PICFLAG= ++fi ++ ++ ++ ++# If we are building PIC/PIE host executables, and we are building dependent ++# libs (e.g. GMP) in-tree those libs need to be configured to generate PIC ++# code. ++host_libs_picflag= ++if test "$host_shared" = "yes" -o "$host_pie" = "yes"; then ++host_libs_picflag='--with-pic' ++fi ++ ++ + # By default, C and C++ are the only stage 1 languages. + stage1_languages=,c, + +diff --git a/configure.ac b/configure.ac +index 7abd02f8b56..e8a22fe6dd4 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -748,6 +748,8 @@ esac + + # Disable libffi for some systems. + case "${target}" in ++ aarch64*-*-darwin2*) ++ ;; + powerpc-*-darwin*) + ;; + i[[3456789]]86-*-darwin*) +@@ -1827,6 +1829,20 @@ AC_ARG_WITH(boot-ldflags, + if test "$poststage1_libs" = ""; then + poststage1_ldflags="-static-libstdc++ -static-libgcc" + fi]) ++case $target in ++ *-darwin2* | *-darwin1[[56789]]*) ++ # For these versions, we default to using embedded rpaths. ++ if test "x$enable_darwin_at_rpath" != "xno"; then ++ poststage1_ldflags="$poststage1_ldflags -nodefaultrpaths" ++ fi ++ ;; ++ *-darwin*) ++ # For these versions, we only use embedded rpaths on demand. ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ poststage1_ldflags="$poststage1_ldflags -nodefaultrpaths" ++ fi ++ ;; ++esac + AC_SUBST(poststage1_ldflags) + + # GCC GRAPHITE dependency isl. +@@ -1912,6 +1928,36 @@ AC_ARG_ENABLE(linker-plugin-flags, + extra_linker_plugin_flags=) + AC_SUBST(extra_linker_plugin_flags) + ++# Handle --enable-host-pie ++# If host PIE executables are the default (or must be forced on) for some host, ++# we must pass that configuration to the gcc directory. ++gcc_host_pie= ++AC_ARG_ENABLE(host-pie, ++[AS_HELP_STRING([--enable-host-pie], ++ [build position independent host executables])], ++[host_pie=$enableval ++ case $host in ++ *-*-darwin2*) ++ if test x$host_pie != xyes ; then ++ # for Darwin20+ this is required. ++ AC_MSG_WARN([PIE executables are required for the configured host, host-pie setting ignored.]) ++ host_pie=yes ++ gcc_host_pie=--enable-host-pie ++ fi ;; ++ *) ;; ++ esac], ++[case $host in ++ *-*-darwin2*) ++ # Default to PIE (mandatory for aarch64). ++ host_pie=yes ++ gcc_host_pie=--enable-host-pie ++ ;; ++ *) host_pie=no ;; ++ esac]) ++ ++AC_SUBST(host_pie) ++AC_SUBST(gcc_host_pie) ++ + # Enable --enable-host-shared. + # Checked early to determine whether jit is an 'all' language + AC_ARG_ENABLE(host-shared, +@@ -1922,17 +1968,55 @@ AC_ARG_ENABLE(host-shared, + x86_64-*-darwin* | aarch64-*-darwin*) + if test x$host_shared != xyes ; then + # PIC is the default, and actually cannot be switched off. +- echo configure.ac: warning: PIC code is required for the configured target, host-shared setting ignored. 1>&2 ++ AC_MSG_WARN([PIC code is required for the configured host; host-shared setting ignored.]) ++ host_shared=yes ++ fi ;; ++ *-*-darwin*) ++ if test x$host_pie = xyes -a x$host_shared != xyes ; then ++ AC_MSG_WARN([PIC code is required for PIE host executables host-shared setting ignored.]) + host_shared=yes + fi ;; + *) ;; + esac], +-[case $target in ++[case $host in ++ # 64B x86_64 and Aarch64 Darwin default to PIC. + x86_64-*-darwin* | aarch64-*-darwin*) host_shared=yes ;; +- *) host_shared=no ;; ++ # 32B and powerpc64 Darwin must use PIC to link PIE exes. ++ *-*-darwin*) host_shared=$host_pie ;; ++ *) host_shared=no;; + esac]) + AC_SUBST(host_shared) + ++if test x$host_shared = xyes; then ++ case $host in ++ *-*-darwin*) ++ # Since host shared is the default for 64b Darwin, and also enabled for ++ # host_pie, ensure that we present the PIE flag when host_pie is active. ++ if test x$host_pie = xyes; then ++ PICFLAG=-fPIE ++ fi ++ ;; ++ *) ++ PICFLAG=-fPIC ++ ;; ++ esac ++elif test x$host_pie = xyes; then ++ PICFLAG=-fPIE ++else ++ PICFLAG= ++fi ++ ++AC_SUBST(PICFLAG) ++ ++# If we are building PIC/PIE host executables, and we are building dependent ++# libs (e.g. GMP) in-tree those libs need to be configured to generate PIC ++# code. ++host_libs_picflag= ++if test "$host_shared" = "yes" -o "$host_pie" = "yes"; then ++host_libs_picflag='--with-pic' ++fi ++AC_SUBST(host_libs_picflag) ++ + # By default, C and C++ are the only stage 1 languages. + stage1_languages=,c, + +diff --git a/contrib/compare-debug b/contrib/compare-debug +index cf80ae32695..678a897c931 100755 +--- a/contrib/compare-debug ++++ b/contrib/compare-debug +@@ -60,9 +60,19 @@ trap 'rm -f "$1.$suf1" "$2.$suf2"' 0 1 2 15 + case `uname -s` in + Darwin) + # The strip command on darwin does not remove all debug info. +- # Fortunately, we can use ld to do it instead. +- ld -S -r -no_uuid "$1" -o "$1.$suf1" +- ld -S -r -no_uuid "$2" -o "$2.$suf2" ++ # Fortunately, we can use ld to do it instead, but even ld on earlier ++ # system versions can be fussy about what it finds - make sure we use ++ # a ld that understands coalesced sections. ++ case `uname -r` in ++ 8*) ++ ld64 -S -r -no_uuid "$1" -o "$1.$suf1" ++ ld64 -S -r -no_uuid "$2" -o "$2.$suf2" ++ ;; ++ *) ++ ld -S -r -no_uuid "$1" -o "$1.$suf1" ++ ld -S -r -no_uuid "$2" -o "$2.$suf2" ++ ;; ++ esac + ;; + *) + cp "$1" "$1.$suf1" +diff --git a/fixincludes/Makefile.in b/fixincludes/Makefile.in +index 1937dcaa32d..e6ce41dba39 100644 +--- a/fixincludes/Makefile.in ++++ b/fixincludes/Makefile.in +@@ -73,7 +73,7 @@ default : all + # Now figure out from those variables how to compile and link. + + .c.o: +- $(CC) -c $(CFLAGS) $(WARN_CFLAGS) $(CPPFLAGS) $(FIXINC_CFLAGS) $< ++ $(CC) -c $(CFLAGS) $(PICFLAG) $(WARN_CFLAGS) $(CPPFLAGS) $(FIXINC_CFLAGS) $< + + # The only suffixes we want for implicit rules are .c and .o. + .SUFFIXES: +@@ -87,7 +87,11 @@ default : all + ## + ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + ++ifeq ($(PICFLAG),) + LIBIBERTY=../libiberty/libiberty.a ++else ++LIBIBERTY=../libiberty/pic/libiberty.a ++endif + + ALLOBJ = fixincl.o fixtests.o fixfixes.o server.o procopen.o \ + fixlib.o fixopts.o +@@ -107,15 +111,15 @@ oneprocess : full-stamp + twoprocess : test-stamp $(AF) + + full-stamp : $(ALLOBJ) $(LIBIBERTY) +- $(CC) $(CFLAGS) $(LDFLAGS) -o $(FI) $(ALLOBJ) $(LIBIBERTY) ++ $(CC) $(CFLAGS) $(PICFLAG) $(LDFLAGS) $(LD_PICFLAG) -o $(FI) $(ALLOBJ) $(LIBIBERTY) + $(STAMP) $@ + + test-stamp : $(TESTOBJ) $(LIBIBERTY) +- $(CC) $(CFLAGS) $(LDFLAGS) -o $(FI) $(TESTOBJ) $(LIBIBERTY) ++ $(CC) $(CFLAGS) $(PICFLAG) $(LDFLAGS) $(LD_PICFLAG) -o $(FI) $(TESTOBJ) $(LIBIBERTY) + $(STAMP) $@ + + $(AF): $(FIXOBJ) $(LIBIBERTY) +- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(FIXOBJ) $(LIBIBERTY) ++ $(CC) $(CFLAGS) $(PICFLAG) $(LDFLAGS) $(LD_PICFLAG) -o $@ $(FIXOBJ) $(LIBIBERTY) + + $(ALLOBJ) : $(HDR) + fixincl.o : fixincl.c $(srcdir)/fixincl.x +diff --git a/fixincludes/configure b/fixincludes/configure +index 0d5cd6967ca..5d1db193a50 100755 +--- a/fixincludes/configure ++++ b/fixincludes/configure +@@ -623,6 +623,8 @@ ac_subst_vars='LTLIBOBJS + LIBOBJS + get_gcc_base_ver + MAINT ++LD_PICFLAG ++PICFLAG + TARGET + target_noncanonical + WERROR +@@ -695,6 +697,7 @@ enable_option_checking + enable_werror_always + with_local_prefix + enable_twoprocess ++enable_host_pie + enable_maintainer_mode + with_gcc_major_version_only + ' +@@ -1323,6 +1326,7 @@ Optional Features: + --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + --enable-werror-always enable -Werror despite compiler version + --enable-twoprocess Use a separate process to apply the fixes ++ --enable-host-pie build host code as PIE + --enable-maintainer-mode enable make rules and dependencies not useful + (and sometimes confusing) to the casual installer + +@@ -3044,7 +3048,6 @@ ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. + # the compiler configuration to `libtool'. + # _LT_LANG_CXX_CONFIG + +- + # _LT_SYS_HIDDEN_LIBDEPS([TAGNAME]) + # --------------------------------- + # Figure out "hidden" library dependencies from verbose +@@ -4835,6 +4838,15 @@ $as_echo "#define SEPARATE_FIX_PROC 1" >>confdefs.h + + fi + ++# Enable --enable-host-pie. ++# Check whether --enable-host-pie was given. ++if test "${enable_host_pie+set}" = set; then : ++ enableval=$enable_host_pie; PICFLAG=-fPIE; LD_PICFLAG=-pie ++fi ++ ++ ++ ++ + case $host in + vax-dec-bsd* ) + +diff --git a/fixincludes/configure.ac b/fixincludes/configure.ac +index ef2227e3c93..4e78511d20f 100644 +--- a/fixincludes/configure.ac ++++ b/fixincludes/configure.ac +@@ -68,6 +68,14 @@ if test $TARGET = twoprocess; then + [Define if testing and fixing are done by separate process]) + fi + ++# Enable --enable-host-pie. ++AC_ARG_ENABLE(host-pie, ++[AS_HELP_STRING([--enable-host-pie], ++ [build host code as PIE])], ++[PICFLAG=-fPIE; LD_PICFLAG=-pie], []) ++AC_SUBST(PICFLAG) ++AC_SUBST(LD_PICFLAG) ++ + case $host in + vax-dec-bsd* ) + AC_DEFINE(exit, xexit, [Define to xexit if the host system does not support atexit]) +diff --git a/fixincludes/fixincl.x b/fixincludes/fixincl.x +index 0bc8eb049a3..2e810ba92e1 100644 +--- a/fixincludes/fixincl.x ++++ b/fixincludes/fixincl.x +@@ -2,11 +2,11 @@ + * + * DO NOT EDIT THIS FILE (fixincl.x) + * +- * It has been AutoGen-ed March 30, 2024 at 04:03:59 PM by AutoGen 5.18.7 ++ * It has been AutoGen-ed June 9, 2024 at 09:57:56 AM by AutoGen 5.18.7 + * From the definitions inclhack.def + * and the template file fixincl + */ +-/* DO NOT SVN-MERGE THIS FILE, EITHER Sat Mar 30 16:03:59 GMT 2024 ++/* DO NOT SVN-MERGE THIS FILE, EITHER Sun Jun 9 09:57:56 BST 2024 + * + * You must regenerate it. Use the ./genfixes script. + * +@@ -15,7 +15,7 @@ + * certain ANSI-incompatible system header files which are fixed to work + * correctly with ANSI C and placed in a directory that GNU C will search. + * +- * This file contains 269 fixup descriptions. ++ * This file contains 267 fixup descriptions. + * + * See README for more information. + * +@@ -267,56 +267,6 @@ static const char* apzAab_Darwin7_9_Long_Double_FuncsPatch[] = { + #endif /* __MATH__ */", + (char*)NULL }; + +-/* * * * * * * * * * * * * * * * * * * * * * * * * * +- * +- * Description of Darwin_Api_Availability fix +- */ +-tSCC zDarwin_Api_AvailabilityName[] = +- "darwin_api_availability"; +- +-/* +- * File name selection pattern +- */ +-tSCC zDarwin_Api_AvailabilityList[] = +- "os/availability.h\0"; +-/* +- * Machine/OS name selection pattern +- */ +-tSCC* apzDarwin_Api_AvailabilityMachs[] = { +- "*-*-darwin*", +- (const char*)NULL }; +- +-/* +- * content selection pattern - do fix if pattern found +- */ +-tSCC zDarwin_Api_AvailabilitySelect0[] = +- " *#define __API_AVAILABLE.*\n\ +- *#define __API_DEPRECATED.*\n\ +- *#define __API_DEPRECATED_WITH_REPLACEMENT.*\n\ +- *#define __API_UNAVAILABLE.*\n"; +- +-/* +- * content bypass pattern - skip fix if pattern found +- */ +-tSCC zDarwin_Api_AvailabilityBypass0[] = +- "__IPHONE_OS_VERSION_MIN_REQUIRED"; +- +-#define DARWIN_API_AVAILABILITY_TEST_CT 2 +-static tTestDesc aDarwin_Api_AvailabilityTests[] = { +- { TT_NEGREP, zDarwin_Api_AvailabilityBypass0, (regex_t*)NULL }, +- { TT_EGREP, zDarwin_Api_AvailabilitySelect0, (regex_t*)NULL }, }; +- +-/* +- * Fix Command Arguments for Darwin_Api_Availability +- */ +-static const char* apzDarwin_Api_AvailabilityPatch[] = { +- "format", +- " #define API_AVAILABLE(...)\n\ +- #define API_DEPRECATED(...)\n\ +- #define API_DEPRECATED_WITH_REPLACEMENT(...)\n\ +- #define API_UNAVAILABLE(...)\n", +- (char*)NULL }; +- + /* * * * * * * * * * * * * * * * * * * * * * * * * * + * + * Description of Aab_Fd_Zero_Asm_Posix_Types_H fix +@@ -2763,51 +2713,6 @@ extern \"C\" {\n\ + #endif\n", + (char*)NULL }; + +-/* * * * * * * * * * * * * * * * * * * * * * * * * * +- * +- * Description of Darwin_Availabilityinternal fix +- */ +-tSCC zDarwin_AvailabilityinternalName[] = +- "darwin_availabilityinternal"; +- +-/* +- * File name selection pattern +- */ +-tSCC zDarwin_AvailabilityinternalList[] = +- "AvailabilityInternal.h\0"; +-/* +- * Machine/OS name selection pattern +- */ +-tSCC* apzDarwin_AvailabilityinternalMachs[] = { +- "*-*-darwin*", +- (const char*)NULL }; +- +-/* +- * content selection pattern - do fix if pattern found +- */ +-tSCC zDarwin_AvailabilityinternalSelect0[] = +- "#define[ \t]+(__API_[ADU]\\([^)]*\\)).*"; +- +-#define DARWIN_AVAILABILITYINTERNAL_TEST_CT 1 +-static tTestDesc aDarwin_AvailabilityinternalTests[] = { +- { TT_EGREP, zDarwin_AvailabilityinternalSelect0, (regex_t*)NULL }, }; +- +-/* +- * Fix Command Arguments for Darwin_Availabilityinternal +- */ +-static const char* apzDarwin_AvailabilityinternalPatch[] = { +- "format", +- "#if defined(__has_attribute)\n\ +- #if __has_attribute(availability)\n\ +-%0\n\ +- #else\n\ +- #define %1\n\ +- #endif\n\ +-#else\n\ +- #define %1\n\ +-#endif", +- (char*)NULL }; +- + /* * * * * * * * * * * * * * * * * * * * * * * * * * + * + * Description of Darwin_9_Long_Double_Funcs_2 fix +@@ -10959,9 +10864,9 @@ static const char* apzX11_SprintfPatch[] = { + * + * List of all fixes + */ +-#define REGEX_COUNT 307 ++#define REGEX_COUNT 304 + #define MACH_LIST_SIZE_LIMIT 187 +-#define FIX_COUNT 269 ++#define FIX_COUNT 267 + + /* + * Enumerate the fixes +@@ -10970,7 +10875,6 @@ typedef enum { + AAB_AIX_STDIO_FIXIDX, + AAB_AIX_FCNTL_FIXIDX, + AAB_DARWIN7_9_LONG_DOUBLE_FUNCS_FIXIDX, +- DARWIN_API_AVAILABILITY_FIXIDX, + AAB_FD_ZERO_ASM_POSIX_TYPES_H_FIXIDX, + AAB_FD_ZERO_GNU_TYPES_H_FIXIDX, + AAB_FD_ZERO_SELECTBITS_H_FIXIDX, +@@ -11032,7 +10936,6 @@ typedef enum { + CTRL_QUOTES_DEF_FIXIDX, + CTRL_QUOTES_USE_FIXIDX, + CXX_UNREADY_FIXIDX, +- DARWIN_AVAILABILITYINTERNAL_FIXIDX, + DARWIN_9_LONG_DOUBLE_FUNCS_2_FIXIDX, + DARWIN_EXTERNC_FIXIDX, + DARWIN_GCC4_BREAKAGE_FIXIDX, +@@ -11254,11 +11157,6 @@ tFixDesc fixDescList[ FIX_COUNT ] = { + AAB_DARWIN7_9_LONG_DOUBLE_FUNCS_TEST_CT, FD_MACH_ONLY | FD_REPLACEMENT, + aAab_Darwin7_9_Long_Double_FuncsTests, apzAab_Darwin7_9_Long_Double_FuncsPatch, 0 }, + +- { zDarwin_Api_AvailabilityName, zDarwin_Api_AvailabilityList, +- apzDarwin_Api_AvailabilityMachs, +- DARWIN_API_AVAILABILITY_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE, +- aDarwin_Api_AvailabilityTests, apzDarwin_Api_AvailabilityPatch, 0 }, +- + { zAab_Fd_Zero_Asm_Posix_Types_HName, zAab_Fd_Zero_Asm_Posix_Types_HList, + apzAab_Fd_Zero_Asm_Posix_Types_HMachs, + AAB_FD_ZERO_ASM_POSIX_TYPES_H_TEST_CT, FD_MACH_ONLY | FD_REPLACEMENT, +@@ -11564,11 +11462,6 @@ tFixDesc fixDescList[ FIX_COUNT ] = { + CXX_UNREADY_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE, + aCxx_UnreadyTests, apzCxx_UnreadyPatch, 0 }, + +- { zDarwin_AvailabilityinternalName, zDarwin_AvailabilityinternalList, +- apzDarwin_AvailabilityinternalMachs, +- DARWIN_AVAILABILITYINTERNAL_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE, +- aDarwin_AvailabilityinternalTests, apzDarwin_AvailabilityinternalPatch, 0 }, +- + { zDarwin_9_Long_Double_Funcs_2Name, zDarwin_9_Long_Double_Funcs_2List, + apzDarwin_9_Long_Double_Funcs_2Machs, + DARWIN_9_LONG_DOUBLE_FUNCS_2_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE, +diff --git a/fixincludes/inclhack.def b/fixincludes/inclhack.def +index 31a21c2a66d..c4ab0dd4ff6 100644 +--- a/fixincludes/inclhack.def ++++ b/fixincludes/inclhack.def +@@ -194,33 +194,6 @@ fix = { + _EndOfHeader_; + }; + +-/* +- * SDKs for 10.13 and 10.14 omit the definitions for API_AVAILABLE where +- * __attribute__((availability)) is not supported. +- */ +-fix = { +- hackname = darwin_api_availability; +- mach = "*-*-darwin*"; +- files = os/availability.h; +- bypass = "__IPHONE_OS_VERSION_MIN_REQUIRED"; +- select = +- " *#define __API_AVAILABLE.*\n" +- " *#define __API_DEPRECATED.*\n" +- " *#define __API_DEPRECATED_WITH_REPLACEMENT.*\n" +- " *#define __API_UNAVAILABLE.*\n"; +- c_fix = format; +- c_fix_arg = +- " #define API_AVAILABLE(...)\n" +- " #define API_DEPRECATED(...)\n" +- " #define API_DEPRECATED_WITH_REPLACEMENT(...)\n" +- " #define API_UNAVAILABLE(...)\n"; +- test_text = +- "#define __API_AVAILABLE(...)\n" +- "#define __API_DEPRECATED(...)\n" +- "#define __API_DEPRECATED_WITH_REPLACEMENT(...)\n" +- "#define __API_UNAVAILABLE(...)\n"; +-}; +- + /* + * This fixes __FD_ZERO bug for linux 2.x.y (x <= 2 && y <= some n) + */ +@@ -1350,32 +1323,6 @@ fix = { + test_text = "extern void* malloc( size_t );"; + }; + +-/* +- * macOS 10.12 uses __attribute__((availability)) +- * unconditionally. +- */ +-fix = { +- hackname = darwin_availabilityinternal; +- mach = "*-*-darwin*"; +- files = AvailabilityInternal.h; +- select = "#define[ \t]+(__API_[ADU]\\([^)]*\\)).*"; +- c_fix = format; +- c_fix_arg = <<- _EOFix_ +- #if defined(__has_attribute) +- #if __has_attribute(availability) +- %0 +- #else +- #define %1 +- #endif +- #else +- #define %1 +- #endif +- _EOFix_; +- +- test_text = "#define __API_A(x) __attribute__((availability(__API_AVAILABLE_PLATFORM_##x)))\n" +- "#define __API_D(msg,x) __attribute__((availability(__API_DEPRECATED_PLATFORM_##x,message=msg)))"; +-}; +- + /* + * For the AAB_darwin7_9_long_double_funcs fix (and later fixes for long long) + * to be useful, the main math.h must use <> and not "" includes. +diff --git a/gcc/Makefile.in b/gcc/Makefile.in +index 31ff95500c9..3bfaeebdbd2 100644 +--- a/gcc/Makefile.in ++++ b/gcc/Makefile.in +@@ -155,6 +155,9 @@ LDFLAGS = @LDFLAGS@ + # Should we build position-independent host code? + PICFLAG = @PICFLAG@ + ++# The linker flag for the above. ++LD_PICFLAG = @LD_PICFLAG@ ++ + # Flags to determine code coverage. When coverage is disabled, this will + # contain the optimization flags, as you normally want code coverage + # without optimization. +@@ -263,18 +266,17 @@ LINKER = $(CC) + LINKER_FLAGS = $(CFLAGS) + endif + ++enable_host_pie = @enable_host_pie@ ++ + # Enable Intel CET on Intel CET enabled host if needed. + CET_HOST_FLAGS = @CET_HOST_FLAGS@ + COMPILER += $(CET_HOST_FLAGS) + +-NO_PIE_CFLAGS = @NO_PIE_CFLAGS@ +-NO_PIE_FLAG = @NO_PIE_FLAG@ +- +-# We don't want to compile the compilers with -fPIE, it make PCH fail. +-COMPILER += $(NO_PIE_CFLAGS) ++# Maybe compile the compilers with -fPIE or -fPIC. ++COMPILER += $(PICFLAG) + +-# Link with -no-pie since we compile the compiler with -fno-PIE. +-LINKER += $(NO_PIE_FLAG) ++# Link with -pie, or -no-pie, depending on the above. ++LINKER += $(LD_PICFLAG) + + # Like LINKER, but use a mutex for serializing front end links. + ifeq (@DO_LINK_MUTEX@,true) +@@ -1036,7 +1038,7 @@ RTL_SSA_H = $(PRETTY_PRINT_H) insn-config.h splay-tree-utils.h \ + # programs built during a bootstrap. + # autoconf inserts -DCROSS_DIRECTORY_STRUCTURE if we are building a + # cross compiler which does not use the native headers and libraries. +-INTERNAL_CFLAGS = -DIN_GCC $(PICFLAG) @CROSS@ ++INTERNAL_CFLAGS = -DIN_GCC @CROSS@ + + # This is the variable actually used when we compile. If you change this, + # you probably want to update BUILD_CFLAGS in configure.ac +@@ -1054,21 +1056,24 @@ ALL_CXXFLAGS = $(T_CFLAGS) $(CFLAGS-$@) $(CXXFLAGS) $(INTERNAL_CFLAGS) \ + ALL_CPPFLAGS = $(INCLUDES) $(CPPFLAGS) + + # This is the variable to use when using $(COMPILER). +-ALL_COMPILERFLAGS = $(ALL_CXXFLAGS) ++ALL_COMPILERFLAGS = $(ALL_CXXFLAGS) $(PICFLAG) + + # This is the variable to use when using $(LINKER). +-ALL_LINKERFLAGS = $(ALL_CXXFLAGS) ++ALL_LINKERFLAGS = $(ALL_CXXFLAGS) $(LD_PICFLAG) + + # Build and host support libraries. + +-# Use the "pic" build of libiberty if --enable-host-shared, unless we are +-# building for mingw. ++# Use the "pic" build of libiberty if --enable-host-shared or --enable-host-pie, ++# unless we are building for mingw. + LIBIBERTY_PICDIR=$(if $(findstring mingw,$(target)),,pic) +-ifeq ($(enable_host_shared),yes) ++ifneq ($(enable_host_shared)$(enable_host_pie),) + LIBIBERTY = ../libiberty/$(LIBIBERTY_PICDIR)/libiberty.a +-BUILD_LIBIBERTY = $(build_libobjdir)/libiberty/$(LIBIBERTY_PICDIR)/libiberty.a + else + LIBIBERTY = ../libiberty/libiberty.a ++endif ++ifeq ($(enable_host_shared),yes) ++BUILD_LIBIBERTY = $(build_libobjdir)/libiberty/$(LIBIBERTY_PICDIR)/libiberty.a ++else + BUILD_LIBIBERTY = $(build_libobjdir)/libiberty/libiberty.a + endif + +@@ -1153,6 +1158,8 @@ LANG_MAKEFRAGS = @all_lang_makefrags@ + # Used by gcc/jit/Make-lang.in + LD_VERSION_SCRIPT_OPTION = @ld_version_script_option@ + LD_SONAME_OPTION = @ld_soname_option@ ++@ENABLE_DARWIN_AT_RPATH_TRUE@DARWIN_RPATH = @rpath ++@ENABLE_DARWIN_AT_RPATH_FALSE@DARWIN_RPATH = ${libdir} + + # Flags to pass to recursive makes. + # CC is set by configure. +@@ -1942,9 +1949,12 @@ cs-tconfig.h: Makefile + $(SHELL) $(srcdir)/mkconfig.sh tconfig.h + + cs-tm.h: Makefile +- TARGET_CPU_DEFAULT="$(target_cpu_default)" \ +- HEADERS="$(tm_include_list)" DEFINES="$(tm_defines)" \ +- $(SHELL) $(srcdir)/mkconfig.sh tm.h ++@ENABLE_DARWIN_AT_RPATH_FALSE@ TARGET_CPU_DEFAULT="$(target_cpu_default)" \ ++@ENABLE_DARWIN_AT_RPATH_FALSE@ HEADERS="$(tm_include_list)" DEFINES="$(tm_defines)" \ ++@ENABLE_DARWIN_AT_RPATH_FALSE@ $(SHELL) $(srcdir)/mkconfig.sh tm.h ++@ENABLE_DARWIN_AT_RPATH_TRUE@ TARGET_CPU_DEFAULT="$(target_cpu_default)" \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ HEADERS="$(tm_include_list)" DEFINES="$(tm_defines) DARWIN_AT_RPATH=1" \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ $(SHELL) $(srcdir)/mkconfig.sh tm.h + + cs-tm_p.h: Makefile + TARGET_CPU_DEFAULT="" \ +@@ -4116,6 +4126,9 @@ site.exp: ./config.status Makefile + echo "set COMPAT_OPTIONS \"$(COMPAT_OPTIONS)\"" >> ./site.tmp; \ + else true; \ + fi ++ @if test "X@ENABLE_DARWIN_AT_RPATH_TRUE@" != "X#" ; then \ ++ echo "set ENABLE_DARWIN_AT_RPATH 1" >> ./site.tmp; \ ++ fi + @echo "## All variables above are generated by configure. Do Not Edit ##" >> ./site.tmp + @cat ./site.tmp > site.exp + @cat site.bak | sed \ +diff --git a/gcc/aclocal.m4 b/gcc/aclocal.m4 +index 6be36df5190..126e09bbcd1 100644 +--- a/gcc/aclocal.m4 ++++ b/gcc/aclocal.m4 +@@ -12,6 +12,56 @@ + # PARTICULAR PURPOSE. + + m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])]) ++# AM_CONDITIONAL -*- Autoconf -*- ++ ++# Copyright (C) 1997-2017 Free Software Foundation, Inc. ++# ++# This file is free software; the Free Software Foundation ++# gives unlimited permission to copy and/or distribute it, ++# with or without modifications, as long as this notice is preserved. ++ ++# AM_CONDITIONAL(NAME, SHELL-CONDITION) ++# ------------------------------------- ++# Define a conditional. ++AC_DEFUN([AM_CONDITIONAL], ++[AC_PREREQ([2.52])dnl ++ m4_if([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], ++ [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl ++AC_SUBST([$1_TRUE])dnl ++AC_SUBST([$1_FALSE])dnl ++_AM_SUBST_NOTMAKE([$1_TRUE])dnl ++_AM_SUBST_NOTMAKE([$1_FALSE])dnl ++m4_define([_AM_COND_VALUE_$1], [$2])dnl ++if $2; then ++ $1_TRUE= ++ $1_FALSE='#' ++else ++ $1_TRUE='#' ++ $1_FALSE= ++fi ++AC_CONFIG_COMMANDS_PRE( ++[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then ++ AC_MSG_ERROR([[conditional "$1" was never defined. ++Usually this means the macro was only invoked conditionally.]]) ++fi])]) ++ ++# Copyright (C) 2006-2017 Free Software Foundation, Inc. ++# ++# This file is free software; the Free Software Foundation ++# gives unlimited permission to copy and/or distribute it, ++# with or without modifications, as long as this notice is preserved. ++ ++# _AM_SUBST_NOTMAKE(VARIABLE) ++# --------------------------- ++# Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in. ++# This macro is traced by Automake. ++AC_DEFUN([_AM_SUBST_NOTMAKE]) ++ ++# AM_SUBST_NOTMAKE(VARIABLE) ++# -------------------------- ++# Public sister of _AM_SUBST_NOTMAKE. ++AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)]) ++ + m4_include([../libtool.m4]) + m4_include([../ltoptions.m4]) + m4_include([../ltsugar.m4]) +diff --git a/gcc/ada/Makefile.rtl b/gcc/ada/Makefile.rtl +index aaf853e3a2a..b20218310f3 100644 +--- a/gcc/ada/Makefile.rtl ++++ b/gcc/ada/Makefile.rtl +@@ -2822,6 +2822,15 @@ ifeq ($(strip $(filter-out darwin%,$(target_os))),) + TOOLS_TARGET_PAIRS = indepsw.adbname)) ++ return true; ++ return false; ++} ++ + /* Verify that argument value POS at position ARGNO to attribute NAME + applied to function TYPE refers to a function parameter at position + POS and the expected type CODE. Treat CODE == INTEGER_TYPE as +diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc +index 94bef24220b..867cf15412b 100644 +--- a/gcc/c-family/c-common.cc ++++ b/gcc/c-family/c-common.cc +@@ -309,6 +309,44 @@ const struct fname_var_t fname_vars[] = + {NULL, 0, 0}, + }; + ++/* Flags to restrict availability of generic features that ++ are known to __has_{feature,extension}. */ ++ ++enum ++{ ++ HF_FLAG_NONE = 0, ++ HF_FLAG_EXT = 1, /* Available only as an extension. */ ++ HF_FLAG_SANITIZE = 2, /* Availability depends on sanitizer flags. */ ++}; ++ ++/* Info for generic features which can be queried through ++ __has_{feature,extension}. */ ++ ++struct hf_feature_info ++{ ++ const char *ident; ++ unsigned flags; ++ unsigned mask; ++}; ++ ++/* Table of generic features which can be queried through ++ __has_{feature,extension}. */ ++ ++static constexpr hf_feature_info has_feature_table[] = ++{ ++ { "address_sanitizer", HF_FLAG_SANITIZE, SANITIZE_ADDRESS }, ++ { "thread_sanitizer", HF_FLAG_SANITIZE, SANITIZE_THREAD }, ++ { "leak_sanitizer", HF_FLAG_SANITIZE, SANITIZE_LEAK }, ++ { "hwaddress_sanitizer", HF_FLAG_SANITIZE, SANITIZE_HWADDRESS }, ++ { "undefined_behavior_sanitizer", HF_FLAG_SANITIZE, SANITIZE_UNDEFINED }, ++ { "attribute_deprecated_with_message", HF_FLAG_NONE, 0 }, ++ { "attribute_unavailable_with_message", HF_FLAG_NONE, 0 }, ++ { "enumerator_attributes", HF_FLAG_NONE, 0 }, ++ { "tls", HF_FLAG_NONE, 0 }, ++ { "gnu_asm_goto_with_outputs", HF_FLAG_EXT, 0 }, ++ { "gnu_asm_goto_with_outputs_full", HF_FLAG_EXT, 0 } ++}; ++ + /* Global visibility options. */ + struct visibility_flags visibility_options; + +@@ -9486,4 +9524,63 @@ c_common_finalize_early_debug (void) + (*debug_hooks->early_global_decl) (cnode->decl); + } + ++/* Map from identifiers to booleans. Value is true for features, and ++ false for extensions. Used to implement __has_{feature,extension}. */ ++ ++using feature_map_t = hash_map ; ++static feature_map_t *feature_map; ++ ++/* Register a feature for __has_{feature,extension}. FEATURE_P is true ++ if the feature identified by NAME is a feature (as opposed to an ++ extension). */ ++ ++void ++c_common_register_feature (const char *name, bool feature_p) ++{ ++ bool dup = feature_map->put (get_identifier (name), feature_p); ++ gcc_checking_assert (!dup); ++} ++ ++/* Lazily initialize hash table for __has_{feature,extension}, ++ dispatching to the appropriate front end to register language-specific ++ features. */ ++ ++static void ++init_has_feature () ++{ ++ gcc_checking_assert (!feature_map); ++ feature_map = new feature_map_t; ++ ++ for (unsigned i = 0; i < ARRAY_SIZE (has_feature_table); i++) ++ { ++ const hf_feature_info *info = has_feature_table + i; ++ ++ if ((info->flags & HF_FLAG_SANITIZE) && !(flag_sanitize & info->mask)) ++ continue; ++ ++ const bool feature_p = !(info->flags & HF_FLAG_EXT); ++ c_common_register_feature (info->ident, feature_p); ++ } ++ ++ /* Register language-specific features. */ ++ c_family_register_lang_features (); ++} ++ ++/* If STRICT_P is true, evaluate __has_feature (IDENT). ++ Otherwise, evaluate __has_extension (IDENT). */ ++ ++bool ++has_feature_p (const char *ident, bool strict_p) ++{ ++ if (!feature_map) ++ init_has_feature (); ++ ++ tree name = canonicalize_attr_name (get_identifier (ident)); ++ bool *feat_p = feature_map->get (name); ++ if (!feat_p) ++ return false; ++ ++ return !strict_p || *feat_p; ++} ++ + #include "gt-c-family-c-common.h" +diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h +index 3d5b9c40e6b..dff0d14ecb2 100644 +--- a/gcc/c-family/c-common.h ++++ b/gcc/c-family/c-common.h +@@ -1068,6 +1068,14 @@ extern bool c_cpp_diagnostic (cpp_reader *, enum cpp_diagnostic_level, + ATTRIBUTE_GCC_DIAG(5,0); + extern int c_common_has_attribute (cpp_reader *, bool); + extern int c_common_has_builtin (cpp_reader *); ++extern int c_common_has_feature (cpp_reader *, bool); ++ ++/* Implemented by each front end in *-lang.cc. */ ++extern void c_family_register_lang_features (); ++ ++/* Implemented in c-family/c-common.cc. */ ++extern void c_common_register_feature (const char *, bool); ++extern bool has_feature_p (const char *, bool); + + extern bool parse_optimize_options (tree, bool); + +@@ -1470,6 +1478,7 @@ extern void warn_for_multistatement_macros (location_t, location_t, + /* In c-attribs.cc. */ + extern bool attribute_takes_identifier_p (const_tree); + extern tree handle_deprecated_attribute (tree *, tree, tree, int, bool *); ++extern bool attribute_clang_form_p (const_tree); + extern tree handle_unused_attribute (tree *, tree, tree, int, bool *); + extern tree handle_fallthrough_attribute (tree *, tree, tree, int, bool *); + extern int parse_tm_stmt_attr (tree, int); +diff --git a/gcc/c-family/c-lex.cc b/gcc/c-family/c-lex.cc +index bd48bfc88e0..62a41f334dd 100644 +--- a/gcc/c-family/c-lex.cc ++++ b/gcc/c-family/c-lex.cc +@@ -82,6 +82,7 @@ init_c_lex (void) + cb->read_pch = c_common_read_pch; + cb->has_attribute = c_common_has_attribute; + cb->has_builtin = c_common_has_builtin; ++ cb->has_feature = c_common_has_feature; + cb->get_source_date_epoch = cb_get_source_date_epoch; + cb->get_suggestion = cb_get_suggestion; + cb->remap_filename = remap_macro_filename; +@@ -441,16 +442,16 @@ c_common_has_attribute (cpp_reader *pfile, bool std_syntax) + return result; + } + +-/* Callback for has_builtin. */ ++/* Helper for __has_{builtin,feature,extension}. */ + +-int +-c_common_has_builtin (cpp_reader *pfile) ++static const char * ++c_common_lex_availability_macro (cpp_reader *pfile, const char *builtin) + { + const cpp_token *token = get_token_no_padding (pfile); + if (token->type != CPP_OPEN_PAREN) + { + cpp_error (pfile, CPP_DL_ERROR, +- "missing '(' after \"__has_builtin\""); ++ "missing '(' after \"__has_%s\"", builtin); + return 0; + } + +@@ -470,7 +471,7 @@ c_common_has_builtin (cpp_reader *pfile) + else + { + cpp_error (pfile, CPP_DL_ERROR, +- "macro \"__has_builtin\" requires an identifier"); ++ "macro \"__has_%s\" requires an identifier", builtin); + if (token->type == CPP_CLOSE_PAREN) + return 0; + } +@@ -489,9 +490,38 @@ c_common_has_builtin (cpp_reader *pfile) + break; + } + ++ return name; ++} ++ ++/* Callback for has_builtin. */ ++ ++int ++c_common_has_builtin (cpp_reader *pfile) ++{ ++ const char *name = c_common_lex_availability_macro (pfile, "builtin"); ++ if (!name) ++ return 0; ++ + return names_builtin_p (name); + } + ++/* Callback for has_feature. STRICT_P is true for has_feature and false ++ for has_extension. */ ++ ++int ++c_common_has_feature (cpp_reader *pfile, bool strict_p) ++{ ++ const char *builtin = strict_p ? "feature" : "extension"; ++ const char *name = c_common_lex_availability_macro (pfile, builtin); ++ if (!name) ++ return 0; ++ ++ /* If -pedantic-errors is given, __has_extension is equivalent to ++ __has_feature. */ ++ strict_p |= flag_pedantic_errors; ++ return has_feature_p (name, strict_p); ++} ++ + + /* Read a token and return its type. Fill *VALUE with its value, if + applicable. Fill *CPP_FLAGS with the token's flags, if it is +@@ -523,6 +553,21 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags, + + case CPP_NUMBER: + { ++ /* If the user wants number-like entities to be returned as a raw ++ string, then don't try to classify them, which emits unwanted ++ diagnostics. */ ++ if (lex_flags & C_LEX_NUMBER_AS_STRING) ++ { ++ /* build_string adds a trailing NUL at [len]. */ ++ tree num_string = build_string (tok->val.str.len + 1, ++ (const char *) tok->val.str.text); ++ TREE_TYPE (num_string) = char_array_type_node; ++ *value = num_string; ++ /* We will effectively note this as CPP_N_INVALID, because we ++ made no checks here. */ ++ break; ++ } ++ + const char *suffix = NULL; + unsigned int flags = cpp_classify_number (parse_in, tok, &suffix, *loc); + +diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc +index a341a061758..b584a05c935 100644 +--- a/gcc/c-family/c-opts.cc ++++ b/gcc/c-family/c-opts.cc +@@ -1068,7 +1068,7 @@ c_common_post_options (const char **pfilename) + + if (flag_extern_tls_init) + { +- if (!TARGET_SUPPORTS_ALIASES || !SUPPORTS_WEAK) ++ if (!SUPPORTS_WEAK) + { + /* Lazy TLS initialization for a variable in another TU requires + alias and weak reference support. */ +diff --git a/gcc/c-family/c-ppoutput.cc b/gcc/c-family/c-ppoutput.cc +index 9de46a9655f..9aa8aeadf9c 100644 +--- a/gcc/c-family/c-ppoutput.cc ++++ b/gcc/c-family/c-ppoutput.cc +@@ -152,6 +152,7 @@ init_pp_output (FILE *out_stream) + + cb->has_attribute = c_common_has_attribute; + cb->has_builtin = c_common_has_builtin; ++ cb->has_feature = c_common_has_feature; + cb->get_source_date_epoch = cb_get_source_date_epoch; + cb->remap_filename = remap_macro_filename; + +diff --git a/gcc/c-family/c-pragma.h b/gcc/c-family/c-pragma.h +index 54864c2ec41..78bb5fe2943 100644 +--- a/gcc/c-family/c-pragma.h ++++ b/gcc/c-family/c-pragma.h +@@ -256,6 +256,9 @@ extern enum cpp_ttype pragma_lex (tree *, location_t *loc = NULL); + #define C_LEX_STRING_NO_JOIN 2 /* Do not concatenate strings + nor translate them into execution + character set. */ ++#define C_LEX_NUMBER_AS_STRING 4 /* Do not classify a number, but ++ instead return it as a raw ++ string. */ + + /* This is not actually available to pragma parsers. It's merely a + convenient location to declare this function for c-lex, after +diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt +index 07da40ef43b..d2c4700e1b6 100644 +--- a/gcc/c-family/c.opt ++++ b/gcc/c-family/c.opt +@@ -1443,6 +1443,10 @@ Wsubobject-linkage + C++ ObjC++ Var(warn_subobject_linkage) Warning Init(1) + Warn if a class type has a base or a field whose type uses the anonymous namespace or depends on a type with no linkage. + ++Welaborated-enum-base ++C++ ObjC++ Var(warn_elaborated_enum_base) Warning Init(1) ++Warn if an additional enum-base is used in an elaborated-type-specifier. ++ + Wduplicate-decl-specifier + C ObjC Var(warn_duplicate_decl_specifier) Warning LangEnabledBy(C ObjC,Wall) + Warn when a declaration has duplicate const, volatile, restrict or _Atomic specifier. +@@ -1885,7 +1889,7 @@ Implement resolution of DR 150 for matching of template template arguments. + + fnext-runtime + ObjC ObjC++ LTO RejectNegative Var(flag_next_runtime) +-Generate code for NeXT (Apple Mac OS X) runtime environment. ++Generate code for NeXT (Apple macOS) runtime environment. + + fnil-receivers + ObjC ObjC++ Var(flag_nil_receivers) Init(1) +diff --git a/gcc/c/c-lang.cc b/gcc/c/c-lang.cc +index eecc0a07137..72b5962dbf2 100644 +--- a/gcc/c/c-lang.cc ++++ b/gcc/c/c-lang.cc +@@ -49,6 +49,15 @@ enum c_language_kind c_language = clk_c; + /* Each front end provides its own lang hook initializer. */ + struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER; + ++/* Implement c-family hook to register language-specific features for ++ __has_{feature,extension}. */ ++ ++void ++c_family_register_lang_features () ++{ ++ c_register_features (); ++} ++ + #if CHECKING_P + + namespace selftest { +diff --git a/gcc/c/c-objc-common.cc b/gcc/c/c-objc-common.cc +index cba01f4d5f3..ecf3a9628f1 100644 +--- a/gcc/c/c-objc-common.cc ++++ b/gcc/c/c-objc-common.cc +@@ -34,6 +34,38 @@ along with GCC; see the file COPYING3. If not see + static bool c_tree_printer (pretty_printer *, text_info *, const char *, + int, bool, bool, bool, bool *, const char **); + ++/* Info for C language features which can be queried through ++ __has_{feature,extension}. */ ++ ++struct c_feature_info ++{ ++ const char *ident; ++ const int *enable_flag; ++}; ++ ++static const c_feature_info c_feature_table[] = ++{ ++ { "c_alignas", &flag_isoc11 }, ++ { "c_alignof", &flag_isoc11 }, ++ { "c_atomic", &flag_isoc11 }, ++ { "c_generic_selections", &flag_isoc11 }, ++ { "c_static_assert", &flag_isoc11 }, ++ { "c_thread_local", &flag_isoc11 } ++}; ++ ++/* Register features specific to the C language. */ ++ ++void ++c_register_features () ++{ ++ for (unsigned i = 0; i < ARRAY_SIZE (c_feature_table); i++) ++ { ++ const c_feature_info *info = c_feature_table + i; ++ const bool feat_p = !info->enable_flag || *info->enable_flag; ++ c_common_register_feature (info->ident, feat_p); ++ } ++} ++ + bool + c_missing_noreturn_ok_p (tree decl) + { +diff --git a/gcc/c/c-objc-common.h b/gcc/c/c-objc-common.h +index 0b60df9750f..6d2f2dd8a09 100644 +--- a/gcc/c/c-objc-common.h ++++ b/gcc/c/c-objc-common.h +@@ -21,6 +21,9 @@ along with GCC; see the file COPYING3. If not see + #ifndef GCC_C_OBJC_COMMON + #define GCC_C_OBJC_COMMON + ++/* Implemented in c-objc-common.cc. */ ++extern void c_register_features (); ++ + /* Lang hooks that are shared between C and ObjC are defined here. Hooks + specific to C or ObjC go in c-lang.cc and objc/objc-lang.cc, respectively. */ + +diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc +index 78a313fe31e..cf423a964ee 100644 +--- a/gcc/c/c-parser.cc ++++ b/gcc/c/c-parser.cc +@@ -202,6 +202,9 @@ struct GTY(()) c_parser { + should translate them to the execution character set (false + inside attributes). */ + BOOL_BITFIELD translate_strings_p : 1; ++ /* True if we want to lex arbitrary number-like sequences as their ++ string representation. */ ++ BOOL_BITFIELD lex_number_as_string : 1; + + /* Objective-C specific parser/lexer information. */ + +@@ -276,10 +279,10 @@ c_lex_one_token (c_parser *parser, c_token *token, bool raw = false) + + if (raw || vec_safe_length (parser->raw_tokens) == 0) + { ++ int lex_flags = parser->lex_joined_string ? 0 : C_LEX_STRING_NO_JOIN; ++ lex_flags |= parser->lex_number_as_string ? C_LEX_NUMBER_AS_STRING : 0; + token->type = c_lex_with_flags (&token->value, &token->location, +- &token->flags, +- (parser->lex_joined_string +- ? 0 : C_LEX_STRING_NO_JOIN)); ++ &token->flags, lex_flags); + token->id_kind = C_ID_NONE; + token->keyword = RID_MAX; + token->pragma_kind = PRAGMA_NONE; +@@ -4561,6 +4564,88 @@ c_parser_gnu_attribute_any_word (c_parser *parser) + return attr_name; + } + ++/* Handle parsing clang-form attribute arguments, where we need to adjust ++ the parsing rules to relate to a specific attribute. */ ++ ++static tree ++c_parser_clang_attribute_arguments (c_parser *parser, tree /*attr_id*/) ++{ ++ /* We can, if required, alter the parsing on the basis of the attribute. ++ At present, we handle the availability attr, where ach entry can be : ++ identifier ++ identifier=N.MM.Z ++ identifier="string" ++ followed by ',' or ) for the last entry*/ ++ ++ tree attr_args = NULL_TREE; ++ do ++ { ++ tree name = NULL_TREE; ++ tree value = NULL_TREE; ++ ++ if (c_parser_next_token_is (parser, CPP_NAME) ++ && c_parser_peek_token (parser)->id_kind == C_ID_ID) ++ { ++ name = c_parser_peek_token (parser)->value; ++ c_parser_consume_token (parser); ++ } ++ else if (c_parser_next_token_is (parser, CPP_COMMA)) ++ name = error_mark_node; /* Comma handled below. */ ++ else ++ { ++ bool saved_join_state = parser->lex_joined_string; ++ parser->lex_number_as_string = 1; ++ parser->lex_joined_string = 1; ++ c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, ++ "expected an attribute keyword"); ++ parser->lex_number_as_string = 0; ++ parser->lex_joined_string = saved_join_state; ++ return error_mark_node; ++ } ++ if (c_parser_next_token_is (parser, CPP_EQ)) ++ { ++ c_parser_consume_token (parser); /* eat the '=' */ ++ /* We need to bludgeon the lexer into not trying to interpret the ++ xx.yy.zz form, since that just looks like a malformed float. ++ Also, as a result of macro processing, we can have strig literals ++ that are in multiple pieces so, for this specific part of the ++ parse, we need to join strings. */ ++ bool saved_join_state = parser->lex_joined_string; ++ parser->lex_number_as_string = 1; ++ parser->lex_joined_string = 1; ++ /* So look at the next token, expecting a string, or something that ++ looks initially like a number, but might be a version number. */ ++ c_parser_peek_token (parser); ++ /* Done with the funky number parsing. */ ++ parser->lex_number_as_string = 0; ++ parser->lex_joined_string = saved_join_state; ++ if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN) ++ && c_parser_next_token_is_not (parser, CPP_COMMA)) ++ { ++ value = c_parser_peek_token (parser)->value; ++ /* ???: check for error mark and early-return? */ ++ c_parser_consume_token (parser); ++ } ++ /* else value is absent. */ ++ } ++ else if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN) ++ && c_parser_next_token_is_not (parser, CPP_COMMA)) ++ { ++ c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, ++ "expected %<,%> or %<=%>"); ++ return error_mark_node; ++ } ++ if (c_parser_next_token_is (parser, CPP_COMMA)) ++ c_parser_consume_token (parser); /* Just skip the comma. */ ++ tree t = tree_cons (value, name, NULL); ++ if (!attr_args) ++ attr_args = t; ++ else ++ chainon (attr_args, t); ++ } while (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN)); ++ return attr_args; ++} ++ + /* Parse attribute arguments. This is a common form of syntax + covering all currently valid GNU and standard attributes. + +@@ -4707,9 +4792,13 @@ c_parser_gnu_attribute (c_parser *parser, tree attrs, + attrs = chainon (attrs, attr); + return attrs; + } +- c_parser_consume_token (parser); ++ c_parser_consume_token (parser); /* The '('. */ + +- tree attr_args ++ tree attr_args; ++ if (attribute_clang_form_p (attr_name)) ++ attr_args = c_parser_clang_attribute_arguments (parser, attr_name); ++ else ++ attr_args + = c_parser_attribute_arguments (parser, + attribute_takes_identifier_p (attr_name), + false, true); +diff --git a/gcc/calls.cc b/gcc/calls.cc +index 4d0bc45be28..95463b14d23 100644 +--- a/gcc/calls.cc ++++ b/gcc/calls.cc +@@ -1355,7 +1355,8 @@ initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED, + with those made by function.cc. */ + + /* See if this argument should be passed by invisible reference. */ +- function_arg_info arg (type, argpos < n_named_args); ++ function_arg_info arg (type, argpos < n_named_args, ++ argpos == n_named_args - 1); + if (pass_by_reference (args_so_far_pnt, arg)) + { + const bool callee_copies +@@ -1475,10 +1476,13 @@ initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED, + + unsignedp = TYPE_UNSIGNED (type); + arg.type = type; +- arg.mode +- = promote_function_mode (type, TYPE_MODE (type), &unsignedp, +- fndecl ? TREE_TYPE (fndecl) : fntype, 0); +- ++ arg.mode = TYPE_MODE (type); ++// arg.mode ++// = promote_function_mode (type, TYPE_MODE (type), &unsignedp, ++// fndecl ? TREE_TYPE (fndecl) : fntype, 0); ++ arg.mode = promote_function_mode (args_so_far, arg, ++ fndecl ? TREE_TYPE (fndecl) : fntype, ++ &unsignedp, 0); + args[i].unsignedp = unsignedp; + args[i].mode = arg.mode; + +@@ -1528,6 +1532,7 @@ initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED, + #endif + reg_parm_stack_space, + args[i].pass_on_stack ? 0 : args[i].partial, ++ args_so_far, + fndecl, args_size, &args[i].locate); + #ifdef BLOCK_REG_PADDING + else +@@ -4030,6 +4035,7 @@ split_complex_types (tree types) + return types; + } + ++extern void debug_tree (tree); + /* Output a library call to function ORGFUN (a SYMBOL_REF rtx) + for a value of mode OUTMODE, + with NARGS different arguments, passed as ARGS. +@@ -4215,6 +4221,7 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value, + argvec[count].reg != 0, + #endif + reg_parm_stack_space, 0, ++ args_so_far, + NULL_TREE, &args_size, &argvec[count].locate); + + if (argvec[count].reg == 0 || argvec[count].partial != 0 +@@ -4285,8 +4292,16 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value, + val = force_operand (XEXP (slot, 0), NULL_RTX); + } + +- arg.mode = promote_function_mode (NULL_TREE, arg.mode, &unsigned_p, +- NULL_TREE, 0); ++// arg.mode = promote_function_mode (NULL_TREE, arg.mode, &unsigned_p, ++// NULL_TREE, 0); ++ tree t = arg.type; ++if (t) ++ debug_tree (t); ++gcc_assert (!t); ++ arg.type = NULL_TREE; ++ arg.mode = promote_function_mode (args_so_far, arg, NULL_TREE, ++ &unsigned_p, 0); ++ arg.type = t; + argvec[count].mode = arg.mode; + argvec[count].value = convert_modes (arg.mode, GET_MODE (val), val, + unsigned_p); +@@ -4306,6 +4321,7 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value, + argvec[count].reg != 0, + #endif + reg_parm_stack_space, argvec[count].partial, ++ args_so_far, + NULL_TREE, &args_size, &argvec[count].locate); + args_size.constant += argvec[count].locate.size.constant; + gcc_assert (!argvec[count].locate.size.var); +diff --git a/gcc/calls.h b/gcc/calls.h +index fd7836e481d..a2a4f85e23e 100644 +--- a/gcc/calls.h ++++ b/gcc/calls.h +@@ -35,24 +35,43 @@ class function_arg_info + { + public: + function_arg_info () +- : type (NULL_TREE), mode (VOIDmode), named (false), ++ : type (NULL_TREE), mode (VOIDmode), named (false), last_named (false), + pass_by_reference (false) + {} + + /* Initialize an argument of mode MODE, either before or after promotion. */ + function_arg_info (machine_mode mode, bool named) +- : type (NULL_TREE), mode (mode), named (named), pass_by_reference (false) ++ : type (NULL_TREE), mode (mode), named (named), last_named (false), ++ pass_by_reference (false) ++ {} ++ ++ function_arg_info (machine_mode mode, bool named, bool last_named) ++ : type (NULL_TREE), mode (mode), named (named), last_named (last_named), ++ pass_by_reference (false) + {} + + /* Initialize an unpromoted argument of type TYPE. */ + function_arg_info (tree type, bool named) +- : type (type), mode (TYPE_MODE (type)), named (named), ++ : type (type), mode (TYPE_MODE (type)), named (named), last_named (false), + pass_by_reference (false) + {} + ++ /* Initialize an unpromoted argument of type TYPE. */ ++ function_arg_info (tree type, bool named, bool last_named) ++ : type (type), mode (TYPE_MODE (type)), named (named), ++ last_named (last_named), pass_by_reference (false) ++ {} ++ + /* Initialize an argument with explicit properties. */ + function_arg_info (tree type, machine_mode mode, bool named) +- : type (type), mode (mode), named (named), pass_by_reference (false) ++ : type (type), mode (mode), named (named), last_named (false), ++ pass_by_reference (false) ++ {} ++ ++ /* Initialize an argument with explicit properties. */ ++ function_arg_info (tree type, machine_mode mode, bool named, bool last_named) ++ : type (type), mode (mode), named (named), last_named (last_named), ++ pass_by_reference (false) + {} + + /* Return true if the gimple-level type is an aggregate. */ +@@ -105,6 +124,9 @@ public: + "..."). See also TARGET_STRICT_ARGUMENT_NAMING. */ + unsigned int named : 1; + ++ /* True if this is the last named argument. */ ++ unsigned int last_named : 1; ++ + /* True if we have decided to pass the argument by reference, in which case + the function_arg_info describes a pointer to the original argument. */ + unsigned int pass_by_reference : 1; +diff --git a/gcc/collect2.cc b/gcc/collect2.cc +index d81c7f28f16..d5af65def40 100644 +--- a/gcc/collect2.cc ++++ b/gcc/collect2.cc +@@ -73,7 +73,7 @@ along with GCC; see the file COPYING3. If not see + In a cross-compiler, this means you need a cross nm, + but that is not quite as unpleasant as special headers. */ + +-#if !defined (OBJECT_FORMAT_COFF) ++#if !defined (OBJECT_FORMAT_COFF) && !defined (OBJECT_FORMAT_MACHO) + #define OBJECT_FORMAT_NONE + #endif + +@@ -107,7 +107,7 @@ along with GCC; see the file COPYING3. If not see + + #endif /* OBJECT_FORMAT_COFF */ + +-#ifdef OBJECT_FORMAT_NONE ++#if defined (OBJECT_FORMAT_NONE) || defined (OBJECT_FORMAT_MACHO) + + /* Default flags to pass to nm. */ + #ifndef NM_FLAGS +@@ -525,7 +525,7 @@ static const char *const target_machine = TARGET_MACHINE; + + Return 0 if not found, otherwise return its name, allocated with malloc. */ + +-#ifdef OBJECT_FORMAT_NONE ++#if defined (OBJECT_FORMAT_NONE) || defined (OBJECT_FORMAT_MACHO) + + /* Add an entry for the object file NAME to object file list LIST. + New entries are added at the end of the list. The original pointer +@@ -764,6 +764,12 @@ do_link (char **ld_argv, const char *atsuffix) + } + } + ++#if defined (OBJECT_FORMAT_MACHO) ++# define LLD_NAME "ld64.lld" ++#else ++# define LLD_NAME "ld.lld" ++#endif ++ + /* Main program. */ + + int +@@ -777,16 +783,19 @@ main (int argc, char **argv) + USE_BFD_LD, + USE_LLD_LD, + USE_MOLD_LD, ++ USE_CLASSIC_LD, + USE_LD_MAX + } selected_linker = USE_DEFAULT_LD; ++ + static const char *const ld_suffixes[USE_LD_MAX] = + { + "ld", + PLUGIN_LD_SUFFIX, + "ld.gold", + "ld.bfd", +- "ld.lld", +- "ld.mold" ++ LLD_NAME, ++ "ld.mold", ++ "ld-classic" + }; + static const char *const real_ld_suffix = "real-ld"; + static const char *const collect_ld_suffix = "collect-ld"; +@@ -953,14 +962,22 @@ main (int argc, char **argv) + if (selected_linker == USE_DEFAULT_LD) + selected_linker = USE_PLUGIN_LD; + } ++#if !defined (OBJECT_FORMAT_MACHO) + else if (strcmp (argv[i], "-fuse-ld=bfd") == 0) + selected_linker = USE_BFD_LD; + else if (strcmp (argv[i], "-fuse-ld=gold") == 0) + selected_linker = USE_GOLD_LD; ++#endif + else if (strcmp (argv[i], "-fuse-ld=lld") == 0) + selected_linker = USE_LLD_LD; + else if (strcmp (argv[i], "-fuse-ld=mold") == 0) + selected_linker = USE_MOLD_LD; ++#if defined (OBJECT_FORMAT_MACHO) ++ else if (strcmp (argv[i], "-fuse-ld=classic") == 0) ++ selected_linker = USE_CLASSIC_LD; ++#endif ++ else if (strcmp (argv[i], "-fuse-ld=") == 0) ++ selected_linker = USE_DEFAULT_LD; + else if (startswith (argv[i], "-o")) + { + /* Parse the output filename if it's given so that we can make +@@ -1052,7 +1069,8 @@ main (int argc, char **argv) + ld_file_name = 0; + #ifdef DEFAULT_LINKER + if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD || +- selected_linker == USE_LLD_LD || selected_linker == USE_MOLD_LD) ++ selected_linker == USE_LLD_LD || selected_linker == USE_MOLD_LD || ++ selected_linker == USE_CLASSIC_LD) + { + char *linker_name; + # ifdef HOST_EXECUTABLE_SUFFIX +@@ -2266,7 +2284,7 @@ write_aix_file (FILE *stream, struct id *list) + } + #endif + +-#ifdef OBJECT_FORMAT_NONE ++#if defined (OBJECT_FORMAT_NONE) || defined (OBJECT_FORMAT_MACHO) + + /* Check to make sure the file is an LTO object file. */ + +diff --git a/gcc/common.opt b/gcc/common.opt +index 8a0dafc522d..fdcfdebd1fb 100644 +--- a/gcc/common.opt ++++ b/gcc/common.opt +@@ -2733,6 +2733,10 @@ fstack-usage + Common RejectNegative Var(flag_stack_usage) + Output stack usage information on a per-function basis. + ++fstack-use-cumulative-args ++Common RejectNegative Var(flag_stack_use_cumulative_args) Init(STACK_USE_CUMULATIVE_ARGS_INIT) ++Use cumulative args-based stack layout hooks. ++ + fstrength-reduce + Common Ignore + Does nothing. Preserved for backward compatibility. +@@ -2801,10 +2805,25 @@ Common Var(flag_tracer) Optimization + Perform superblock formation via tail duplication. + + ftrampolines +-Common Var(flag_trampolines) Init(0) ++Common Var(flag_trampolines) Init(HEAP_TRAMPOLINES_INIT) + For targets that normally need trampolines for nested functions, always + generate them instead of using descriptors. + ++ftrampoline-impl= ++Common Joined RejectNegative Enum(trampoline_impl) Var(flag_trampoline_impl) Init(HEAP_TRAMPOLINES_INIT ? TRAMPOLINE_IMPL_HEAP : TRAMPOLINE_IMPL_STACK) ++Whether trampolines are generated in executable memory rather than ++executable stack. ++ ++Enum ++Name(trampoline_impl) Type(enum trampoline_impl) UnknownError(unknown trampoline implementation %qs) ++ ++EnumValue ++Enum(trampoline_impl) String(stack) Value(TRAMPOLINE_IMPL_STACK) ++ ++EnumValue ++Enum(trampoline_impl) String(heap) Value(TRAMPOLINE_IMPL_HEAP) ++ ++ + ; Zero means that floating-point math operations cannot generate a + ; (user-visible) trap. This is the case, for example, in nonstop + ; IEEE 754 arithmetic. +@@ -3058,6 +3077,10 @@ fuse-ld=mold + Common Driver Negative(fuse-ld=mold) + Use the Modern linker (MOLD) linker instead of the default linker. + ++fuse-ld=classic ++Common Driver Negative(fuse-ld=classic) ++Use the ld-classic linker instead of the default linker. ++ + fuse-linker-plugin + Common Undocumented Var(flag_use_linker_plugin) + +diff --git a/gcc/common/config/aarch64/aarch64-common.cc b/gcc/common/config/aarch64/aarch64-common.cc +index dfda5b8372a..074557edd50 100644 +--- a/gcc/common/config/aarch64/aarch64-common.cc ++++ b/gcc/common/config/aarch64/aarch64-common.cc +@@ -421,6 +421,7 @@ aarch64_get_extension_string_for_isa_flags (uint64_t isa_flags, + we just mask all default bits away at the end. */ + isa_flag_bits &= ~default_arch_flags; + ++#ifndef DISABLE_AARCH64_AS_CRC_BUGFIX + /* We now have the smallest set of features we need to process. A subsequent + linear scan of the bits in isa_flag_bits will allow us to print the ext + names. However as a special case if CRC was enabled before, always print +@@ -432,6 +433,7 @@ aarch64_get_extension_string_for_isa_flags (uint64_t isa_flags, + issue, so we don't need this fix when targeting Armv8-R. */ + if ((isa_flags & AARCH64_ISA_CRC) && !AARCH64_ISA_V8_R) + isa_flag_bits |= AARCH64_ISA_CRC; ++#endif + + /* Pass Two: + Print the option names that we're sure we must turn on. These are only +diff --git a/gcc/config.gcc b/gcc/config.gcc +index 5c378c698ff..196225955ba 100644 +--- a/gcc/config.gcc ++++ b/gcc/config.gcc +@@ -1089,6 +1089,26 @@ case ${target} in + ;; + esac + ++# Figure out if we need to enable heap trampolines ++# and variadic functions handling. ++case ${target} in ++aarch64*-*-darwin2*) ++ # This applies to arm64 Darwin variadic funtions. ++ tm_defines="$tm_defines STACK_USE_CUMULATIVE_ARGS_INIT=1" ++ # Executable stack is forbidden. ++ tm_defines="$tm_defines HEAP_TRAMPOLINES_INIT=1" ++ ;; ++*-*-darwin2*) ++ tm_defines="$tm_defines STACK_USE_CUMULATIVE_ARGS_INIT=0" ++ # Currently, we do this for macOS 11 and above. ++ tm_defines="$tm_defines HEAP_TRAMPOLINES_INIT=1" ++ ;; ++*) ++ tm_defines="$tm_defines STACK_USE_CUMULATIVE_ARGS_INIT=0" ++ tm_defines="$tm_defines HEAP_TRAMPOLINES_INIT=0" ++ ;; ++esac ++ + case ${target} in + aarch64*-*-elf | aarch64*-*-fuchsia* | aarch64*-*-rtems*) + tm_file="${tm_file} dbxelf.h elfos.h newlib-stdint.h" +@@ -1127,6 +1147,14 @@ aarch64*-*-elf | aarch64*-*-fuchsia* | aarch64*-*-rtems*) + done + TM_MULTILIB_CONFIG=`echo $TM_MULTILIB_CONFIG | sed 's/^,//'` + ;; ++aarch64-*-darwin*) ++ tm_file="${tm_file} aarch64/aarch64-errata.h" ++ tmake_file="${tmake_file} aarch64/t-aarch64 aarch64/t-aarch64-darwin" ++ tm_defines="${tm_defines} TARGET_DEFAULT_ASYNC_UNWIND_TABLES=1" ++ tm_defines="${tm_defines} DISABLE_AARCH64_AS_CRC_BUGFIX=1" ++ # Choose a default CPU version that will work for all current releases. ++ with_cpu=${with_cpu:-apple-m1} ++ ;; + aarch64*-*-freebsd*) + tm_file="${tm_file} dbxelf.h elfos.h ${fbsd_tm_file}" + tm_file="${tm_file} aarch64/aarch64-elf.h aarch64/aarch64-errata.h aarch64/aarch64-freebsd.h" +@@ -4177,8 +4205,8 @@ case "${target}" in + fi + for which in cpu arch tune; do + eval "val=\$with_$which" +- base_val=`echo $val | sed -e 's/\+.*//'` +- ext_val=`echo $val | sed -e 's/[a-z0-9.-]\+//'` ++ base_val=`echo $val | sed -E -e 's/\+.*//'` ++ ext_val=`echo $val | sed -E -e 's/[a-z0-9.-]+//'` + + if [ $which = arch ]; then + def=aarch64-arches.def +@@ -4237,9 +4265,9 @@ case "${target}" in + + while [ x"$ext_val" != x ] + do +- ext_val=`echo $ext_val | sed -e 's/\+//'` +- ext=`echo $ext_val | sed -e 's/\+.*//'` +- base_ext=`echo $ext | sed -e 's/^no//'` ++ ext_val=`echo $ext_val | sed -E -e 's/\+//'` ++ ext=`echo $ext_val | sed -E -e 's/\+.*//'` ++ base_ext=`echo $ext | sed -E -e 's/^no//'` + opt_line=`echo -e "$options_parsed" | \ + grep "^\"$base_ext\""` + +@@ -4268,7 +4296,7 @@ case "${target}" in + echo "Unknown extension used in --with-$which=$val" 1>&2 + exit 1 + fi +- ext_val=`echo $ext_val | sed -e 's/[a-z0-9]\+//'` ++ ext_val=`echo $ext_val | sed -E -e 's/[a-z0-9]+//'` + done + + ext_mask="(("$ext_mask") << TARGET_CPU_NBITS)" +diff --git a/gcc/config.in b/gcc/config.in +index 52f496ca5de..80dfff17b74 100644 +--- a/gcc/config.in ++++ b/gcc/config.in +@@ -49,6 +49,19 @@ + #endif + + ++/* Specify a runpath directory, additional to those provided by the compiler ++ */ ++#ifndef USED_FOR_TARGET ++#undef DARWIN_ADD_RPATH ++#endif ++ ++ ++/* Should add an extra runpath directory */ ++#ifndef USED_FOR_TARGET ++#undef DARWIN_DO_EXTRA_RPATH ++#endif ++ ++ + /* Define to enable the use of a default assembler. */ + #ifndef USED_FOR_TARGET + #undef DEFAULT_ASSEMBLER +@@ -628,15 +641,13 @@ + #endif + + +-/* Define if your Mac OS X assembler supports -mllvm -x86-pad-for-align=false. +- */ ++/* Define if your macOS assembler supports -mllvm -x86-pad-for-align=false. */ + #ifndef USED_FOR_TARGET + #undef HAVE_AS_MLLVM_X86_PAD_FOR_ALIGN + #endif + + +-/* Define if your Mac OS X assembler supports the -mmacos-version-min option. +- */ ++/* Define if your macOS assembler supports the -mmacos-version-min option. */ + #ifndef USED_FOR_TARGET + #undef HAVE_AS_MMACOSX_VERSION_MIN_OPTION + #endif +@@ -2250,6 +2261,12 @@ + #endif + + ++/* Define to 1 if ld64 supports '-demangle'. */ ++#ifndef USED_FOR_TARGET ++#undef LD64_HAS_DEMANGLE ++#endif ++ ++ + /* Define to 1 if ld64 supports '-export_dynamic'. */ + #ifndef USED_FOR_TARGET + #undef LD64_HAS_EXPORT_DYNAMIC +diff --git a/gcc/config/aarch64/aarch64-builtins.cc b/gcc/config/aarch64/aarch64-builtins.cc +index 197b763658c..2f78fcf6b6c 100644 +--- a/gcc/config/aarch64/aarch64-builtins.cc ++++ b/gcc/config/aarch64/aarch64-builtins.cc +@@ -619,6 +619,8 @@ enum aarch64_builtins + AARCH64_RBIT, + AARCH64_RBITL, + AARCH64_RBITLL, ++ /* OS-specific */ ++ AARCH64_BUILTIN_CFSTRING, + AARCH64_BUILTIN_MAX + }; + +@@ -738,6 +740,9 @@ tree aarch64_fp16_ptr_type_node = NULL_TREE; + tree aarch64_bf16_type_node = NULL_TREE; + tree aarch64_bf16_ptr_type_node = NULL_TREE; + ++/* Pointer to __float128 on Mach-O, where the 128b float is not long double. */ ++tree aarch64_float128_ptr_type_node = NULL_TREE; ++ + /* Wrapper around add_builtin_function. NAME is the name of the built-in + function, TYPE is the function type, CODE is the function subcode + (relative to AARCH64_BUILTIN_GENERAL), and ATTRS is the function +@@ -1490,6 +1495,29 @@ aarch64_init_bf16_types (void) + aarch64_bf16_ptr_type_node = build_pointer_type (aarch64_bf16_type_node); + } + ++/* Initialize the backend REAL_TYPE type supporting __float128 on Mach-O, ++ as well as the related built-ins. */ ++static void ++aarch64_init_float128_types (void) ++{ ++ /* The __float128 type. The node has already been created as ++ _Float128, so for C we only need to register the __float128 name for ++ it. For C++, we create a distinct type which will mangle differently ++ (g) vs. _Float128 (DF128_) and behave backwards compatibly. */ ++ if (float128_type_node == NULL_TREE) ++ { ++ float128_type_node = make_node (REAL_TYPE); ++ TYPE_PRECISION (float128_type_node) ++ = TYPE_PRECISION (float128_type_node); ++ SET_TYPE_MODE (float128_type_node, TYPE_MODE (float128_type_node)); ++ layout_type (float128_type_node); ++ } ++ lang_hooks.types.register_builtin_type (float128_type_node, "__float128"); ++ ++ aarch64_float128_ptr_type_node = build_pointer_type (float128_type_node); ++} ++ ++ + /* Pointer authentication builtins that will become NOP on legacy platform. + Currently, these builtins are for internal use only (libgcc EH unwinder). */ + +@@ -1778,8 +1806,9 @@ aarch64_general_init_builtins (void) + aarch64_init_fpsr_fpcr_builtins (); + + aarch64_init_fp16_types (); +- + aarch64_init_bf16_types (); ++ if (TARGET_MACHO) ++ aarch64_init_float128_types (); + + { + aarch64_simd_switcher simd; +@@ -1816,6 +1845,14 @@ aarch64_general_init_builtins (void) + handle_arm_acle_h (); + } + ++void ++aarch64_init_subtarget_builtins (void) ++{ ++#ifdef SUBTARGET_INIT_BUILTINS ++ SUBTARGET_INIT_BUILTINS; ++#endif ++} ++ + /* Implement TARGET_BUILTIN_DECL for the AARCH64_BUILTIN_GENERAL group. */ + tree + aarch64_general_builtin_decl (unsigned code, bool) +diff --git a/gcc/config/aarch64/aarch64-c.cc b/gcc/config/aarch64/aarch64-c.cc +index a4c407724a7..fdcb41b272e 100644 +--- a/gcc/config/aarch64/aarch64-c.cc ++++ b/gcc/config/aarch64/aarch64-c.cc +@@ -222,6 +222,16 @@ aarch64_cpu_cpp_builtins (cpp_reader *pfile) + { + aarch64_define_unconditional_macros (pfile); + aarch64_update_cpp_builtins (pfile); ++ ++ if (TARGET_MACHO) ++ { ++ builtin_define ("__builtin_copysignq=__builtin_copysignf128"); ++ builtin_define ("__builtin_fabsq=__builtin_fabsf128"); ++ builtin_define ("__builtin_huge_valq=__builtin_huge_valf128"); ++ builtin_define ("__builtin_infq=__builtin_inff128"); ++ builtin_define ("__builtin_nanq=__builtin_nanf128"); ++ builtin_define ("__builtin_nansq=__builtin_nansf128"); ++ } + } + + /* Hook to validate the current #pragma GCC target and set the state, and +@@ -370,4 +380,8 @@ aarch64_register_pragmas (void) + targetm.check_builtin_call = aarch64_check_builtin_call; + + c_register_pragma ("GCC", "aarch64", aarch64_pragma_aarch64); ++ ++#ifdef REGISTER_SUBTARGET_PRAGMAS ++ REGISTER_SUBTARGET_PRAGMAS (); ++#endif + } +diff --git a/gcc/config/aarch64/aarch64-cores.def b/gcc/config/aarch64/aarch64-cores.def +index 956afa70714..ee2d8c57c1e 100644 +--- a/gcc/config/aarch64/aarch64-cores.def ++++ b/gcc/config/aarch64/aarch64-cores.def +@@ -161,6 +161,18 @@ AARCH64_CORE("cortex-a76.cortex-a55", cortexa76cortexa55, cortexa53, 8_2A, AAR + /* Armv8-R Architecture Processors. */ + AARCH64_CORE("cortex-r82", cortexr82, cortexa53, 8R, AARCH64_FL_FOR_ARCH8_R, cortexa53, 0x41, 0xd15, -1) + ++/* Apple (A12 and M) cores. ++ Apple implementer ID from xnu, ++ guesses for part #, guesses for scheduler ident, generic_armv8_a for costs. ++ A12 seems mostly 8.3, ++ M1 seems to be 8.4 + extras (see comments in option-extensions about f16fml), ++ M2 mostly 8.5 but with missing mandatory features. ++ M3 is pretty much the same as M2. */ ++AARCH64_CORE("apple-a12", applea12, cortexa53, 8_3A, AARCH64_FL_FOR_ARCH8_3, cortexa53, 0x61, 0x12, -1) ++AARCH64_CORE("apple-m1", applem1, cortexa57, 8_4A, AARCH64_FL_FOR_ARCH8_4 | AARCH64_FL_F16 | AARCH64_FL_SB | AARCH64_FL_SSBS, cortexa73, 0x61, 0x23, -1) ++AARCH64_CORE("apple-m2", applem2, cortexa57, 8_4A, AARCH64_FL_FOR_ARCH8_4 | AARCH64_FL_I8MM | AARCH64_FL_BF16 | AARCH64_FL_F16 | AARCH64_FL_SB | AARCH64_FL_SSBS, cortexa73, 0x61, 0x23, -1) ++AARCH64_CORE("apple-m3", applem3, cortexa57, 8_4A, AARCH64_FL_FOR_ARCH8_4 | AARCH64_FL_I8MM | AARCH64_FL_BF16 | AARCH64_FL_F16 | AARCH64_FL_SB | AARCH64_FL_SSBS, cortexa73, 0x61, 0x23, -1) ++ + /* Armv9.0-A Architecture Processors. */ + + /* Arm ('A') cores. */ +diff --git a/gcc/config/aarch64/aarch64-protos.h b/gcc/config/aarch64/aarch64-protos.h +index 9d99a021379..6d8dc45ea3d 100644 +--- a/gcc/config/aarch64/aarch64-protos.h ++++ b/gcc/config/aarch64/aarch64-protos.h +@@ -108,6 +108,14 @@ enum aarch64_symbol_type + SYMBOL_TLSLE24, + SYMBOL_TLSLE32, + SYMBOL_TLSLE48, ++ SYMBOL_MO_SMALL_ABS, ++ SYMBOL_MO_SMALL_PCR, ++ SYMBOL_MO_SMALL_GOT, ++ SYMBOL_MO_SMALL_TLS, ++ SYMBOL_MO_LARGE_ABS, ++ SYMBOL_MO_LARGE_PCR, ++ SYMBOL_MO_LARGE_GOT, ++ SYMBOL_MO_LARGE_TLS, + SYMBOL_FORCE_TO_MEM + }; + +@@ -763,6 +771,7 @@ void aarch64_post_cfi_startproc (void); + poly_int64 aarch64_initial_elimination_offset (unsigned, unsigned); + int aarch64_get_condition_code (rtx); + bool aarch64_address_valid_for_prefetch_p (rtx, bool); ++bool aarch64_address_valid_for_unscaled_prefetch_p (rtx, bool); + bool aarch64_bitmask_imm (HOST_WIDE_INT val, machine_mode); + unsigned HOST_WIDE_INT aarch64_and_split_imm1 (HOST_WIDE_INT val_in); + unsigned HOST_WIDE_INT aarch64_and_split_imm2 (HOST_WIDE_INT val_in); +@@ -793,7 +802,11 @@ bool aarch64_is_extend_from_extract (scalar_int_mode, rtx, rtx); + bool aarch64_is_long_call_p (rtx); + bool aarch64_is_noplt_call_p (rtx); + bool aarch64_label_mentioned_p (rtx); ++#if TARGET_MACHO ++void aarch64_darwin_declare_function_name (FILE *, const char*, tree ); ++#else + void aarch64_declare_function_name (FILE *, const char*, tree); ++#endif + void aarch64_asm_output_alias (FILE *, const tree, const tree); + void aarch64_asm_output_external (FILE *, tree, const char*); + bool aarch64_legitimate_pic_operand_p (rtx); +@@ -990,6 +1003,7 @@ void aarch64_override_options_internal (struct gcc_options *); + + const char *aarch64_general_mangle_builtin_type (const_tree); + void aarch64_general_init_builtins (void); ++void aarch64_init_subtarget_builtins (void); + tree aarch64_general_fold_builtin (unsigned int, tree, unsigned int, tree *); + gimple *aarch64_general_gimple_fold_builtin (unsigned int, gcall *, + gimple_stmt_iterator *); +diff --git a/gcc/config/aarch64/aarch64-tune.md b/gcc/config/aarch64/aarch64-tune.md +index 2c1852c8fe6..859c52d2289 100644 +--- a/gcc/config/aarch64/aarch64-tune.md ++++ b/gcc/config/aarch64/aarch64-tune.md +@@ -1,5 +1,5 @@ + ;; -*- buffer-read-only: t -*- + ;; Generated automatically by gentune.sh from aarch64-cores.def + (define_attr "tune" +- "cortexa34,cortexa35,cortexa53,cortexa57,cortexa72,cortexa73,thunderx,thunderxt88p1,thunderxt88,octeontx,octeontxt81,octeontxt83,thunderxt81,thunderxt83,ampere1,ampere1a,emag,xgene1,falkor,qdf24xx,exynosm1,phecda,thunderx2t99p1,vulcan,thunderx2t99,cortexa55,cortexa75,cortexa76,cortexa76ae,cortexa77,cortexa78,cortexa78ae,cortexa78c,cortexa65,cortexa65ae,cortexx1,ares,neoversen1,neoversee1,octeontx2,octeontx2t98,octeontx2t96,octeontx2t93,octeontx2f95,octeontx2f95n,octeontx2f95mm,a64fx,tsv110,thunderx3t110,zeus,neoversev1,neoverse512tvb,saphira,cortexa57cortexa53,cortexa72cortexa53,cortexa73cortexa35,cortexa73cortexa53,cortexa75cortexa55,cortexa76cortexa55,cortexr82,cortexa510,cortexa710,cortexx2,neoversen2,cobalt100,demeter,neoversev2" ++ "cortexa34,cortexa35,cortexa53,cortexa57,cortexa72,cortexa73,thunderx,thunderxt88p1,thunderxt88,octeontx,octeontxt81,octeontxt83,thunderxt81,thunderxt83,ampere1,ampere1a,emag,xgene1,falkor,qdf24xx,exynosm1,phecda,thunderx2t99p1,vulcan,thunderx2t99,cortexa55,cortexa75,cortexa76,cortexa76ae,cortexa77,cortexa78,cortexa78ae,cortexa78c,cortexa65,cortexa65ae,cortexx1,ares,neoversen1,neoversee1,octeontx2,octeontx2t98,octeontx2t96,octeontx2t93,octeontx2f95,octeontx2f95n,octeontx2f95mm,a64fx,tsv110,thunderx3t110,zeus,neoversev1,neoverse512tvb,saphira,cortexa57cortexa53,cortexa72cortexa53,cortexa73cortexa35,cortexa73cortexa53,cortexa75cortexa55,cortexa76cortexa55,cortexr82,applea12,applem1,applem2,applem3,cortexa510,cortexa710,cortexx2,neoversen2,cobalt100,demeter,neoversev2" + (const (symbol_ref "((enum attr_tune) aarch64_tune)"))) +diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc +index f8082c4035e..ef13e465ccd 100644 +--- a/gcc/config/aarch64/aarch64.cc ++++ b/gcc/config/aarch64/aarch64.cc +@@ -292,8 +292,10 @@ static bool aarch64_vfp_is_call_or_return_candidate (machine_mode, + const_tree, + machine_mode *, int *, + bool *, bool); ++#if !TARGET_MACHO + static void aarch64_elf_asm_constructor (rtx, int) ATTRIBUTE_UNUSED; + static void aarch64_elf_asm_destructor (rtx, int) ATTRIBUTE_UNUSED; ++#endif + static void aarch64_override_options_after_change (void); + static bool aarch64_vector_mode_supported_p (machine_mode); + static int aarch64_address_cost (rtx, machine_mode, addr_space_t, bool); +@@ -2786,6 +2788,9 @@ static const struct attribute_spec aarch64_attribute_table[] = + { + /* { name, min_len, max_len, decl_req, type_req, fn_type_req, + affects_type_identity, handler, exclude } */ ++#ifdef SUBTARGET_ATTRIBUTE_TABLE ++ SUBTARGET_ATTRIBUTE_TABLE, ++#endif + { "aarch64_vector_pcs", 0, 0, false, true, true, true, + handle_aarch64_vector_pcs_attribute, NULL }, + { "arm_sve_vector_bits", 1, 1, false, true, false, true, +@@ -4010,7 +4015,7 @@ aarch64_hard_regno_mode_ok (unsigned regno, machine_mode mode) + if (known_le (GET_MODE_SIZE (mode), 8)) + return true; + if (known_le (GET_MODE_SIZE (mode), 16)) +- return (regno & 1) == 0; ++ return (regno & 1) == 0 || TARGET_MACHO; /* darwinpcs D.4 */ + } + else if (FP_REGNUM_P (regno)) + { +@@ -4056,8 +4061,10 @@ static bool + aarch64_takes_arguments_in_sve_regs_p (const_tree fntype) + { + CUMULATIVE_ARGS args_so_far_v; ++ /* This does not apply to variadic functions, so all the (currently ++ uncounted) arguments must be named. */ + aarch64_init_cumulative_args (&args_so_far_v, NULL_TREE, NULL_RTX, +- NULL_TREE, 0, true); ++ NULL_TREE, -1, true); + cumulative_args_t args_so_far = pack_cumulative_args (&args_so_far_v); + + for (tree chain = TYPE_ARG_TYPES (fntype); +@@ -4542,6 +4549,7 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm, + switch (type) + { + case SYMBOL_SMALL_ABSOLUTE: ++ case SYMBOL_MO_SMALL_PCR: + { + /* In ILP32, the mode of dest can be either SImode or DImode. */ + rtx tmp_reg = dest; +@@ -4552,6 +4560,21 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm, + if (can_create_pseudo_p ()) + tmp_reg = gen_reg_rtx (mode); + ++ if (TARGET_MACHO) ++ { ++ rtx sym, off; ++ split_const (imm, &sym, &off); ++ /* Negative offsets don't work, whether by intention is TBD. */ ++ if (INTVAL (off) < 0 || INTVAL (off) > 8 * 1024 * 1024) ++ { ++ emit_move_insn (tmp_reg, gen_rtx_HIGH (mode, sym)); ++ emit_insn (gen_add_losym (dest, tmp_reg, sym)); ++ /* FIXME: add the SI option if/when we support ilp32. */ ++ emit_insn (gen_adddi3 (dest, dest, off)); ++ return; ++ } ++ /* else small enough positive offset is OK. */ ++ } + emit_move_insn (tmp_reg, gen_rtx_HIGH (mode, copy_rtx (imm))); + emit_insn (gen_add_losym (dest, tmp_reg, imm)); + return; +@@ -4635,6 +4658,7 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm, + return; + } + ++ case SYMBOL_MO_SMALL_GOT: + case SYMBOL_SMALL_GOT_4G: + emit_insn (gen_rtx_SET (dest, imm)); + return; +@@ -6696,6 +6720,7 @@ aarch64_expand_mov_immediate (rtx dest, rtx imm) + case SYMBOL_SMALL_TLSIE: + case SYMBOL_SMALL_GOT_28K: + case SYMBOL_SMALL_GOT_4G: ++ case SYMBOL_MO_SMALL_GOT: + case SYMBOL_TINY_GOT: + case SYMBOL_TINY_TLSIE: + if (const_offset != 0) +@@ -6709,6 +6734,7 @@ aarch64_expand_mov_immediate (rtx dest, rtx imm) + /* FALLTHRU */ + + case SYMBOL_SMALL_ABSOLUTE: ++ case SYMBOL_MO_SMALL_PCR: + case SYMBOL_TINY_ABSOLUTE: + case SYMBOL_TLSLE12: + case SYMBOL_TLSLE24: +@@ -7288,6 +7314,7 @@ aarch64_return_in_memory (const_tree type, const_tree fndecl ATTRIBUTE_UNUSED) + gcc_unreachable (); + } + ++#if !TARGET_MACHO + static bool + aarch64_vfp_is_call_candidate (cumulative_args_t pcum_v, machine_mode mode, + const_tree type, int *nregs) +@@ -7297,6 +7324,7 @@ aarch64_vfp_is_call_candidate (cumulative_args_t pcum_v, machine_mode mode, + &pcum->aapcs_vfp_rmode, + nregs, NULL, pcum->silent_p); + } ++#endif + + /* Given MODE and TYPE of a function argument, return the alignment in + bits. The idea is to suppress any stronger alignment requested by +@@ -7316,7 +7344,7 @@ aarch64_function_arg_alignment (machine_mode mode, const_tree type, + if (integer_zerop (TYPE_SIZE (type))) + return 0; + +- gcc_assert (TYPE_MODE (type) == mode); ++ gcc_assert (TARGET_MACHO || TYPE_MODE (type) == mode); + + if (!AGGREGATE_TYPE_P (type)) + { +@@ -7402,6 +7430,13 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) + gcc_assert (!alignment || abi_break < alignment); + + pcum->aapcs_arg_processed = true; ++ if (TARGET_MACHO) ++ { ++ /* Set suitable defaults for queries. */ ++ pcum->darwinpcs_arg_boundary ++ = aarch64_function_arg_alignment (mode, type, &abi_break); ++ pcum->darwinpcs_arg_padding = BITS_PER_UNIT; ++ } + + pure_scalable_type_info pst_info; + if (type && pst_info.analyze_registers (type)) +@@ -7461,13 +7496,29 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) + /* No frontends can create types with variable-sized modes, so we + shouldn't be asked to pass or return them. */ + size = GET_MODE_SIZE (mode).to_constant (); ++ ++ if (TARGET_MACHO) ++ /* Since we can pack things on the stack, we need the unrounded size. */ ++ pcum->darwinpcs_stack_bytes = size; ++ + size = ROUND_UP (size, UNITS_PER_WORD); + + allocate_ncrn = (type) ? !(FLOAT_TYPE_P (type)) : !FLOAT_MODE_P (mode); ++ bool is_ha = false; ++#if !TARGET_MACHO + allocate_nvrn = aarch64_vfp_is_call_candidate (pcum_v, + mode, + type, + &nregs); ++#else ++ /* We care if the value is a homogenous aggregate when laying out the stack, ++ so use this call directly. */ ++ allocate_nvrn ++ = aarch64_vfp_is_call_or_return_candidate (mode, type, ++ &pcum->aapcs_vfp_rmode, ++ &nregs, &is_ha, ++ pcum->silent_p); ++#endif + gcc_assert (!sve_p || !allocate_nvrn); + + /* allocate_ncrn may be false-positive, but allocate_nvrn is quite reliable. +@@ -7484,7 +7535,13 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) + if (!pcum->silent_p && !TARGET_FLOAT) + aarch64_err_no_fpadvsimd (mode); + +- if (nvrn + nregs <= NUM_FP_ARG_REGS) ++ if (TARGET_MACHO ++ && !arg.named) ++ { ++ pcum->aapcs_nextnvrn = NUM_FP_ARG_REGS; ++ goto on_stack; ++ } ++ else if (nvrn + nregs <= NUM_FP_ARG_REGS) + { + pcum->aapcs_nextnvrn = nvrn + nregs; + if (!aarch64_composite_type_p (type, mode)) +@@ -7514,6 +7571,7 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) + } + pcum->aapcs_reg = par; + } ++ pcum->darwinpcs_stack_bytes = 0; + return; + } + else +@@ -7530,14 +7588,24 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) + /* C6 - C9. though the sign and zero extension semantics are + handled elsewhere. This is the case where the argument fits + entirely general registers. */ ++ + if (allocate_ncrn && (ncrn + nregs <= NUM_ARG_REGS)) + { + gcc_assert (nregs == 0 || nregs == 1 || nregs == 2); + ++ if (TARGET_MACHO ++ && !arg.named) ++ { ++ pcum->aapcs_nextncrn = NUM_ARG_REGS; ++ goto on_stack; ++ } ++ + /* C.8 if the argument has an alignment of 16 then the NGRN is + rounded up to the next even number. */ + if (nregs == 2 + && ncrn % 2 ++ /* Darwin PCS deletes rule C.8. */ ++ && !TARGET_MACHO + /* The == 16 * BITS_PER_UNIT instead of >= 16 * BITS_PER_UNIT + comparison is there because for > 16 * BITS_PER_UNIT + alignment nregs should be > 2 and therefore it should be +@@ -7589,8 +7657,8 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) + } + pcum->aapcs_reg = par; + } +- + pcum->aapcs_nextncrn = ncrn + nregs; ++ pcum->darwinpcs_stack_bytes = 0; + return; + } + +@@ -7600,10 +7668,87 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) + /* The argument is passed on stack; record the needed number of words for + this argument and align the total size if necessary. */ + on_stack: +- pcum->aapcs_stack_words = size / UNITS_PER_WORD; + +- if (aarch64_function_arg_alignment (mode, type, &abi_break) +- == 16 * BITS_PER_UNIT) ++ unsigned int align = aarch64_function_arg_alignment (mode, type, &abi_break); ++ ++ if (TARGET_MACHO) ++ { ++ /* Darwin does not round up the allocation for smaller entities to 8 ++ bytes. It only requires the natural alignment for these. ++ ++ but we don't do this for: ++ * unnamed parms in variadic functions ++ * complex types ++ * unions ++ * aggregates (except for homogeneous ones which are handles as the ++ enclosed type). ++ each entry starts a new slot. ++ ++ 16 byte entities are naturally aligned on the stack. ++ There was no darwinpcs for GCC 9, so neither the implementation ++ change nor the warning should fire here (i.e. we do not need to check ++ if 16byte entities alter the stack size). */ ++ ++ gcc_checking_assert (arg.named == pcum->named_p); ++ pcum->darwinpcs_arg_padding = BITS_PER_UNIT; ++ if (!pcum->named_p ++ || TREE_CODE (type) == COMPLEX_TYPE ++ || (TREE_CODE (type) == RECORD_TYPE ++ && !is_ha && !SCALAR_FLOAT_MODE_P (pcum->aapcs_vfp_rmode)) ++ || TREE_CODE (type) == UNION_TYPE) ++ { ++ pcum->aapcs_stack_words = size / UNITS_PER_WORD; ++ pcum->darwinpcs_sub_word_offset = 0; ++ pcum->darwinpcs_sub_word_pos = 0; ++ pcum->darwinpcs_arg_boundary = MAX (align, PARM_BOUNDARY); ++ if (!pcum->named_p) ++ pcum->darwinpcs_arg_padding = PARM_BOUNDARY; ++ return; ++ } ++ ++ /* Updated sub-word offset aligned for the new object. ++ We are looking for the case that the new object will fit after some ++ existing object(s) in the same stack slot. In that case, we do not ++ need to add any more stack space for it. */ ++ int new_off ++ = ROUND_UP (pcum->darwinpcs_sub_word_pos, align / BITS_PER_UNIT); ++ ++ if (new_off >= UNITS_PER_WORD) ++ { ++ /* That exceeds a stack slot, start a new one. */ ++ pcum->darwinpcs_sub_word_offset = 0; ++ pcum->darwinpcs_sub_word_pos = 0; ++ new_off = 0; ++ } ++ /* This is the end of the new object. */ ++ int new_pos = new_off + pcum->darwinpcs_stack_bytes; ++ ++ if (pcum->darwinpcs_sub_word_pos == 0) ++ /* New stack slot, just allocate one or more words, and note where ++ the next arg will start. */ ++ pcum->aapcs_stack_words = size / UNITS_PER_WORD; ++ else if (new_pos <= UNITS_PER_WORD) ++ /* Old stack slot, object starts at new_off and goes to new_pos, we do ++ not add any stack space. */ ++ pcum->darwinpcs_sub_word_offset = new_off; ++ pcum->darwinpcs_sub_word_pos = new_pos; ++ pcum->darwinpcs_arg_boundary = align ; ++ if (pcum->last_named_p && new_pos > 0) ++ { ++ /* Round the last named arg to the start of the next stack slot. */ ++ if (new_pos <= 4) ++ pcum->darwinpcs_arg_padding = PARM_BOUNDARY; ++ else if (new_pos <= 6) ++ pcum->darwinpcs_arg_padding = 4 * BITS_PER_UNIT; ++ else if (pcum->darwinpcs_sub_word_pos <= 7) ++ pcum->darwinpcs_arg_padding = 2 * BITS_PER_UNIT; ++ } ++ return; ++ } ++ ++ /* size was already rounded up to PARM_BOUNDARY. */ ++ pcum->aapcs_stack_words = size / UNITS_PER_WORD; ++ if (align == 16 * BITS_PER_UNIT) + { + int new_size = ROUND_UP (pcum->aapcs_stack_size, 16 / UNITS_PER_WORD); + if (pcum->aapcs_stack_size != new_size) +@@ -7656,7 +7801,28 @@ aarch64_init_cumulative_args (CUMULATIVE_ARGS *pcum, + pcum->aapcs_arg_processed = false; + pcum->aapcs_stack_words = 0; + pcum->aapcs_stack_size = 0; ++ pcum->darwinpcs_stack_bytes = 0; ++ pcum->darwinpcs_sub_word_offset = 0; ++ pcum->darwinpcs_sub_word_pos = 0; ++ pcum->darwinpcs_arg_boundary = BITS_PER_UNIT; ++ pcum->darwinpcs_arg_padding = BITS_PER_UNIT; ++ /* If we have been invoked for incoming args, then n_named will have been ++ set to -1, but we should have a function decl - so pick up the named ++ count from that. If that fails, and we end up with -1, this effectively ++ corresponds to assuming that there is an arbitrary number of named ++ args. */ ++ pcum->darwinpcs_n_named = n_named; ++ if (n_named == (unsigned)-1 && fndecl) ++ { ++ tree fnt = TREE_TYPE (fndecl); ++ if (fnt && TYPE_ARG_TYPES (fnt)) ++ pcum->darwinpcs_n_named = list_length (TYPE_ARG_TYPES (fnt)); ++ } ++ pcum->darwinpcs_n_args_processed = 0; ++ pcum->named_p = pcum->darwinpcs_n_named != 0; ++ pcum->last_named_p = pcum->darwinpcs_n_named == 1; + pcum->silent_p = silent_p; ++ pcum->aapcs_vfp_rmode = VOIDmode; + + if (!silent_p + && !TARGET_FLOAT +@@ -7695,8 +7861,10 @@ aarch64_function_arg_advance (cumulative_args_t pcum_v, + || pcum->pcs_variant == ARM_PCS_SVE) + { + aarch64_layout_arg (pcum_v, arg); +- gcc_assert ((pcum->aapcs_reg != NULL_RTX) +- != (pcum->aapcs_stack_words != 0)); ++ pcum->darwinpcs_n_args_processed++; ++ gcc_assert (TARGET_MACHO ++ || (pcum->aapcs_reg != NULL_RTX) ++ != (pcum->aapcs_stack_words != 0)); + pcum->aapcs_arg_processed = false; + pcum->aapcs_ncrn = pcum->aapcs_nextncrn; + pcum->aapcs_nvrn = pcum->aapcs_nextnvrn; +@@ -7704,6 +7872,12 @@ aarch64_function_arg_advance (cumulative_args_t pcum_v, + pcum->aapcs_stack_size += pcum->aapcs_stack_words; + pcum->aapcs_stack_words = 0; + pcum->aapcs_reg = NULL_RTX; ++ pcum->darwinpcs_arg_boundary = BITS_PER_UNIT; ++ pcum->darwinpcs_arg_padding = BITS_PER_UNIT; ++ pcum->named_p ++ = pcum->darwinpcs_n_args_processed < pcum->darwinpcs_n_named; ++ pcum->last_named_p ++ = pcum->darwinpcs_n_args_processed + 1 == pcum->darwinpcs_n_named; + } + } + +@@ -7714,12 +7888,15 @@ aarch64_function_arg_regno_p (unsigned regno) + || (FP_REGNUM_P (regno) && regno < V0_REGNUM + NUM_FP_ARG_REGS)); + } + +-/* Implement FUNCTION_ARG_BOUNDARY. Every parameter gets at least +- PARM_BOUNDARY bits of alignment, but will be given anything up +- to STACK_BOUNDARY bits if the type requires it. This makes sure +- that both before and after the layout of each argument, the Next +- Stacked Argument Address (NSAA) will have a minimum alignment of +- 8 bytes. */ ++/* Implement FUNCTION_ARG_BOUNDARY. ++ For AAPCS64, Every parameter gets at least PARM_BOUNDARY bits of ++ alignment, but will be given anything up to STACK_BOUNDARY bits ++ if the type requires it. This makes sure that both before and after ++ the layout of each argument, the Next Stacked Argument Address (NSAA) ++ will have a minimum alignment of 8 bytes. ++ ++ For darwinpcs, this is only called to lower va_arg entries which are ++ always aligned as for AAPCS64. */ + + static unsigned int + aarch64_function_arg_boundary (machine_mode mode, const_tree type) +@@ -7727,6 +7904,22 @@ aarch64_function_arg_boundary (machine_mode mode, const_tree type) + unsigned int abi_break; + unsigned int alignment = aarch64_function_arg_alignment (mode, type, + &abi_break); ++ /* We rely on aarch64_layout_arg and aarch64_gimplify_va_arg_expr ++ to emit warnings about ABI incompatibility. */ ++#if TARGET_MACHO ++ /* This can only work for unnamed args. */ ++ machine_mode comp_mode = VOIDmode; ++ int nregs; ++ bool is_ha; ++ aarch64_vfp_is_call_or_return_candidate (mode, type, &comp_mode, &nregs, ++ &is_ha, /*silent*/true); ++ if (TREE_CODE (type) == COMPLEX_TYPE ++ || (TREE_CODE (type) == RECORD_TYPE ++ && !is_ha && !SCALAR_FLOAT_MODE_P (comp_mode)) ++ || TREE_CODE (type) == UNION_TYPE) ++ return MIN (MAX (alignment, PARM_BOUNDARY), STACK_BOUNDARY); ++ return MIN (alignment, STACK_BOUNDARY); ++#else + alignment = MIN (MAX (alignment, PARM_BOUNDARY), STACK_BOUNDARY); + if (abi_break && warn_psabi) + { +@@ -7736,6 +7929,96 @@ aarch64_function_arg_boundary (machine_mode mode, const_tree type) + "%qT changed in GCC 9.1", type); + } + return alignment; ++#endif ++} ++ ++/* For Darwin, we want to use the arg boundary computed when laying out the ++ function arg, to cope with items packed on the stack and the different ++ rules applied to unnamed parms. */ ++ ++static unsigned int ++aarch64_function_arg_boundary_ca (machine_mode mode ATTRIBUTE_UNUSED, ++ const_tree type ATTRIBUTE_UNUSED, ++ cumulative_args_t ca ATTRIBUTE_UNUSED) ++{ ++ unsigned int abi_break; ++ unsigned int alignment = aarch64_function_arg_alignment (mode, type, ++ &abi_break); ++ /* We rely on aarch64_layout_arg and aarch64_gimplify_va_arg_expr ++ to emit warnings about ABI incompatibility. */ ++#if TARGET_MACHO ++ CUMULATIVE_ARGS *pcum = get_cumulative_args (ca); ++gcc_checking_assert (pcum->aapcs_arg_processed); ++ ++ bool named_p = pcum->darwinpcs_n_args_processed < pcum->darwinpcs_n_named; ++gcc_checking_assert (named_p == pcum->named_p); ++ machine_mode comp_mode = VOIDmode; ++ int nregs; ++ bool is_ha; ++ aarch64_vfp_is_call_or_return_candidate (mode, type, &comp_mode, &nregs, ++ &is_ha, /*silent*/true); ++ bool no_pack = (TREE_CODE (type) == COMPLEX_TYPE ++ || (TREE_CODE (type) == RECORD_TYPE ++ && !is_ha && !SCALAR_FLOAT_MODE_P (comp_mode)) ++ || TREE_CODE (type) == UNION_TYPE); ++ ++ bool in_regs = (pcum->aapcs_reg != NULL_RTX); ++ ++ if ((named_p && !no_pack) || in_regs) ++ ; /* Leave the alignment as natural. */ ++ else ++ alignment = MAX (alignment, PARM_BOUNDARY); ++gcc_checking_assert (alignment == pcum->darwinpcs_arg_boundary); ++ return MIN (alignment, STACK_BOUNDARY); ++ ++#else ++ alignment = MIN (MAX (alignment, PARM_BOUNDARY), STACK_BOUNDARY); ++ if (abi_break && warn_psabi) ++ { ++ abi_break = MIN (MAX (abi_break, PARM_BOUNDARY), STACK_BOUNDARY); ++ if (alignment != abi_break) ++ inform (input_location, "parameter passing for argument of type " ++ "%qT changed in GCC 9.1", type); ++ } ++ return alignment; ++#endif ++} ++ ++/* Implement TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA for darwinpcs which allows ++ non-standard passing of byte-aligned items [D.2]. This is done by pulling ++ the values out of the cumulative args struct. */ ++ ++static unsigned int ++aarch64_function_arg_round_boundary_ca (machine_mode mode ATTRIBUTE_UNUSED, ++ const_tree type ATTRIBUTE_UNUSED, ++ cumulative_args_t ca) ++{ ++ CUMULATIVE_ARGS *pcum = get_cumulative_args (ca); ++gcc_checking_assert (pcum->aapcs_arg_processed); ++ bool named_p = pcum->darwinpcs_n_args_processed < pcum->darwinpcs_n_named; ++gcc_checking_assert (named_p == pcum->named_p); ++ bool last_named_p = pcum->darwinpcs_n_args_processed + 1 == pcum->darwinpcs_n_named; ++gcc_checking_assert (last_named_p == pcum->last_named_p); ++ ++ unsigned boundary = BITS_PER_UNIT; ++ if (last_named_p && pcum->darwinpcs_sub_word_pos > 0) ++ { ++ /* Round the last named arg to the start of the next stack slot. */ ++ if (pcum->darwinpcs_sub_word_pos <= 4) ++ boundary = PARM_BOUNDARY; ++ else if (pcum->darwinpcs_sub_word_pos <= 6) ++ boundary = 4 * BITS_PER_UNIT; ++ else if (pcum->darwinpcs_sub_word_pos <= 7) ++ boundary = 2 * BITS_PER_UNIT; ++ } ++ else if (named_p) ++ /* Named args are naturally aligned, but with no rounding. */ ++ ; ++ else ++ /* un-named args are rounded to fill slots. */ ++ boundary = PARM_BOUNDARY; ++gcc_checking_assert (boundary == pcum->darwinpcs_arg_padding); ++ return boundary; + } + + /* Implement TARGET_GET_RAW_RESULT_MODE and TARGET_GET_RAW_ARG_MODE. */ +@@ -10972,6 +11255,7 @@ aarch64_classify_address (struct aarch64_address_info *info, + /* load literal: pc-relative constant pool entry. Only supported + for SI mode or larger. */ + info->type = ADDRESS_SYMBOLIC; ++ info->offset = NULL_RTX; + + if (!load_store_pair_p + && GET_MODE_SIZE (mode).is_constant (&const_size) +@@ -10979,6 +11263,7 @@ aarch64_classify_address (struct aarch64_address_info *info, + { + poly_int64 offset; + rtx sym = strip_offset_and_salt (x, &offset); ++ + return ((LABEL_REF_P (sym) + || (SYMBOL_REF_P (sym) + && CONSTANT_POOL_ADDRESS_P (sym) +@@ -10996,10 +11281,13 @@ aarch64_classify_address (struct aarch64_address_info *info, + poly_int64 offset; + HOST_WIDE_INT const_offset; + rtx sym = strip_offset_and_salt (info->offset, &offset); ++ + if (SYMBOL_REF_P (sym) + && offset.is_constant (&const_offset) + && (aarch64_classify_symbol (sym, const_offset) +- == SYMBOL_SMALL_ABSOLUTE)) ++ == SYMBOL_SMALL_ABSOLUTE ++ || aarch64_classify_symbol (sym, const_offset) ++ == SYMBOL_MO_SMALL_PCR)) + { + /* The symbol and offset must be aligned to the access size. */ + unsigned int align; +@@ -11049,6 +11337,55 @@ aarch64_address_valid_for_prefetch_p (rtx x, bool strict_p) + if (!res) + return false; + ++ /* For ELF targets using GAS, we emit prfm unconditionally; GAS will alter ++ the instruction to pick the prfum form where possible (i.e. when the ++ offset is in the range -256..255) and fall back to prfm otherwise. ++ We can reject cases where the offset exceeds the range usable by both ++ insns [-256..32760], or for offsets > 255 when the value is not divisible ++ by 8. ++ For Mach-O (Darwin) where the assembler uses the LLVM back end, that does ++ not yet do the substitution, so we must reject all prfum cases. */ ++ if (addr.offset) ++ { ++ HOST_WIDE_INT offs = INTVAL (addr.offset); ++ if (offs < -256) /* Out of range for both prfum and prfm. */ ++ return false; ++ if (offs > 32760) /* Out of range for prfm. */ ++ return false; ++ if (offs & 0x07) /* We cannot use prfm. */ ++ { ++ if (offs > 255) /* Out of range for prfum. */ ++ return false; ++ if (TARGET_MACHO) ++ return false; ++ } ++ if (TARGET_MACHO && offs < 0) ++ return false; ++ } ++ ++ /* ... except writeback forms. */ ++ return addr.type != ADDRESS_REG_WB; ++} ++ ++/* Return true if the address X is valid for a PRFUM instruction. ++ STRICT_P is true if we should do strict checking with ++ aarch64_classify_address. */ ++ ++bool ++aarch64_address_valid_for_unscaled_prefetch_p (rtx x, bool strict_p) ++{ ++ struct aarch64_address_info addr; ++ ++ /* PRFUM accepts the same addresses as DImode, but constrained to a range ++ -256..255. */ ++ bool res = aarch64_classify_address (&addr, x, DImode, strict_p); ++ if (!res) ++ return false; ++ ++ if (addr.offset && ((INTVAL (addr.offset) > 255) ++ || (INTVAL (addr.offset) < -256))) ++ return false; ++ + /* ... except writeback forms. */ + return addr.type != ADDRESS_REG_WB; + } +@@ -11733,6 +12070,144 @@ sizetochar (int size) + } + } + ++static void ++output_macho_postfix_expr (FILE *file, rtx x, const char *postfix) ++{ ++ char buf[256]; ++ ++ restart: ++ switch (GET_CODE (x)) ++ { ++ case PC: ++ putc ('.', file); ++ break; ++ ++ case SYMBOL_REF: ++ if (SYMBOL_REF_DECL (x)) ++ assemble_external (SYMBOL_REF_DECL (x)); ++ assemble_name (file, XSTR (x, 0)); ++ fprintf (file, "@%s", postfix); ++ break; ++ ++ case LABEL_REF: ++ x = label_ref_label (x); ++ /* Fall through. */ ++ case CODE_LABEL: ++ ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x)); ++ assemble_name (file, buf); ++ fprintf (file, "@%s", postfix); ++ break; ++ ++ case CONST_INT: ++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x)); ++ break; ++ ++ case CONST: ++ /* This used to output parentheses around the expression, ++ but that does not work on the 386 (either ATT or BSD assembler). */ ++ output_macho_postfix_expr (file, XEXP (x, 0), postfix); ++ break; ++ ++ case CONST_WIDE_INT: ++ /* We do not know the mode here so we have to use a round about ++ way to build a wide-int to get it printed properly. */ ++ { ++ wide_int w = wide_int::from_array (&CONST_WIDE_INT_ELT (x, 0), ++ CONST_WIDE_INT_NUNITS (x), ++ CONST_WIDE_INT_NUNITS (x) ++ * HOST_BITS_PER_WIDE_INT, ++ false); ++ print_decs (w, file); ++ } ++ break; ++ ++ case CONST_DOUBLE: ++ if (CONST_DOUBLE_AS_INT_P (x)) ++ { ++ /* We can use %d if the number is one word and positive. */ ++ if (CONST_DOUBLE_HIGH (x)) ++ fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX, ++ (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (x), ++ (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (x)); ++ else if (CONST_DOUBLE_LOW (x) < 0) ++ fprintf (file, HOST_WIDE_INT_PRINT_HEX, ++ (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (x)); ++ else ++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x)); ++ } ++ else ++ /* We can't handle floating point constants; ++ PRINT_OPERAND must handle them. */ ++ output_operand_lossage ("floating constant misused"); ++ break; ++ ++ case CONST_FIXED: ++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_FIXED_VALUE_LOW (x)); ++ break; ++ ++ case PLUS: ++ /* Some assemblers need integer constants to appear last (eg masm). */ ++ if (CONST_INT_P (XEXP (x, 0))) ++ { ++ output_macho_postfix_expr (file, XEXP (x, 1), postfix); ++ if (INTVAL (XEXP (x, 0)) >= 0) ++ fprintf (file, "+"); ++ output_addr_const (file, XEXP (x, 0)); ++ } ++ else ++ { ++ output_macho_postfix_expr (file, XEXP (x, 0), postfix); ++ if (!CONST_INT_P (XEXP (x, 1)) ++ || INTVAL (XEXP (x, 1)) >= 0) ++ fprintf (file, "+"); ++ output_addr_const (file, XEXP (x, 1)); ++ } ++ break; ++ ++ case MINUS: ++ /* Avoid outputting things like x-x or x+5-x, ++ since some assemblers can't handle that. */ ++ x = simplify_subtraction (x); ++ if (GET_CODE (x) != MINUS) ++ goto restart; ++ ++ output_macho_postfix_expr (file, XEXP (x, 0), postfix); ++ fprintf (file, "-"); ++ if ((CONST_INT_P (XEXP (x, 1)) && INTVAL (XEXP (x, 1)) >= 0) ++ || GET_CODE (XEXP (x, 1)) == PC ++ || GET_CODE (XEXP (x, 1)) == SYMBOL_REF) ++ output_addr_const (file, XEXP (x, 1)); ++ else ++ { ++ fputs (targetm.asm_out.open_paren, file); ++ output_addr_const (file, XEXP (x, 1)); ++ fputs (targetm.asm_out.close_paren, file); ++ } ++ break; ++ ++ case ZERO_EXTEND: ++ case SIGN_EXTEND: ++ case SUBREG: ++ case TRUNCATE: ++ output_addr_const (file, XEXP (x, 0)); ++ break; ++ ++ case UNSPEC: ++ if (XINT (x, 1) == UNSPEC_SALT_ADDR) ++ { ++ output_macho_postfix_expr (file, XVECEXP (x, 0, 0), postfix); ++ break; ++ } ++ /* FALLTHROUGH */ ++ default: ++ if (targetm.asm_out.output_addr_const_extra (file, x)) ++ break; ++ ++ output_operand_lossage ("invalid expression as operand"); ++ } ++ ++} ++ + /* Print operand X to file F in a target specific manner according to CODE. + The acceptable formatting commands given by CODE are: + 'c': An integer or symbol address without a preceding # +@@ -11801,6 +12276,12 @@ aarch64_print_operand (FILE *f, rtx x, int code) + } + break; + ++ case 'J': ++ output_macho_postfix_expr (f, x, "PAGEOFF"); ++ break; ++ case 'O': ++ output_macho_postfix_expr (f, x, "GOTPAGEOFF"); ++ break; + case 'e': + { + x = unwrap_const_vec_duplicate (x); +@@ -12124,7 +12605,7 @@ aarch64_print_operand (FILE *f, rtx x, int code) + case 'A': + if (GET_CODE (x) == HIGH) + x = XEXP (x, 0); +- ++#if !TARGET_MACHO + switch (aarch64_classify_symbolic_expression (x)) + { + case SYMBOL_SMALL_GOT_4G: +@@ -12155,9 +12636,26 @@ aarch64_print_operand (FILE *f, rtx x, int code) + break; + } + output_addr_const (asm_out_file, x); ++#endif ++#if TARGET_MACHO ++ switch (aarch64_classify_symbolic_expression (x)) ++ { ++ case SYMBOL_MO_SMALL_PCR: ++ output_macho_postfix_expr (asm_out_file, x, "PAGE"); ++ break; ++ case SYMBOL_MO_SMALL_GOT: ++ output_macho_postfix_expr (asm_out_file, x, "GOTPAGE"); ++ break; ++ default: ++ /* large code model unimplemented. */ ++ gcc_unreachable (); ++ break; ++ } ++#endif + break; + + case 'L': ++#if !TARGET_MACHO + switch (aarch64_classify_symbolic_expression (x)) + { + case SYMBOL_SMALL_GOT_4G: +@@ -12195,10 +12693,12 @@ aarch64_print_operand (FILE *f, rtx x, int code) + default: + break; + } ++#endif + output_addr_const (asm_out_file, x); + break; + + case 'G': ++#if !TARGET_MACHO + switch (aarch64_classify_symbolic_expression (x)) + { + case SYMBOL_TLSLE24: +@@ -12207,6 +12707,7 @@ aarch64_print_operand (FILE *f, rtx x, int code) + default: + break; + } ++#endif + output_addr_const (asm_out_file, x); + break; + +@@ -12356,8 +12857,13 @@ aarch64_print_address_internal (FILE *f, machine_mode mode, rtx x, + break; + + case ADDRESS_LO_SUM: ++#if TARGET_MACHO ++ asm_fprintf (f, "[%s, #", reg_names [REGNO (addr.base)]); ++ output_macho_postfix_expr (f, addr.offset, "PAGEOFF"); ++#else + asm_fprintf (f, "[%s, #:lo12:", reg_names [REGNO (addr.base)]); + output_addr_const (f, addr.offset); ++#endif + asm_fprintf (f, "]"); + return true; + +@@ -12610,6 +13116,26 @@ aarch64_secondary_reload (bool in_p ATTRIBUTE_UNUSED, rtx x, + return NO_REGS; + } + ++#if TARGET_MACHO ++/* Implement TARGET_FRAME_POINTER_REQUIRED. */ ++ ++static bool ++aarch64_darwin_frame_pointer_required () ++{ ++ if (crtl->calls_eh_return) ++ return true; ++ ++ /* Not used in leaf functions (unless forced). */ ++ if (flag_omit_leaf_frame_pointer && leaf_function_p ()) ++ return false; ++ ++ /* NOTE: We are allowing the user to force omission of the frame ++ pointer, (despite that it is not ABI-compliant). */ ++ ++ return flag_omit_frame_pointer != 1; ++} ++#endif ++ + static bool + aarch64_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to) + { +@@ -12827,6 +13353,8 @@ aarch64_asm_output_labelref (FILE* f, const char *name) + asm_fprintf (f, "%U%s", name); + } + ++#if !TARGET_MACHO ++ + static void + aarch64_elf_asm_constructor (rtx symbol, int priority) + { +@@ -12866,6 +13394,7 @@ aarch64_elf_asm_destructor (rtx symbol, int priority) + assemble_aligned_integer (POINTER_BYTES, symbol); + } + } ++#endif + + const char* + aarch64_output_casesi (rtx *operands) +@@ -12969,7 +13498,11 @@ aarch64_select_rtx_section (machine_mode mode, + if (aarch64_can_use_per_function_literal_pools_p ()) + return function_section (current_function_decl); + ++#if TARGET_MACHO ++ return machopic_select_rtx_section (mode, x, align); ++#else + return default_elf_select_rtx_section (mode, x, align); ++#endif + } + + /* Implement ASM_OUTPUT_POOL_EPILOGUE. */ +@@ -15172,15 +15705,17 @@ aarch64_init_builtins () + { + aarch64_general_init_builtins (); + aarch64_sve::init_builtins (); +-#ifdef SUBTARGET_INIT_BUILTINS +- SUBTARGET_INIT_BUILTINS; +-#endif ++ aarch64_init_subtarget_builtins (); + } + + /* Implement TARGET_FOLD_BUILTIN. */ + static tree + aarch64_fold_builtin (tree fndecl, int nargs, tree *args, bool) + { ++#ifdef SUBTARGET_FOLD_BUILTIN ++ if (tree res = SUBTARGET_FOLD_BUILTIN (fndecl, nargs, args, false)) ++ return res; ++#endif + unsigned int code = DECL_MD_FUNCTION_CODE (fndecl); + unsigned int subcode = code >> AARCH64_BUILTIN_SHIFT; + tree type = TREE_TYPE (TREE_TYPE (fndecl)); +@@ -18513,10 +19048,14 @@ initialize_aarch64_code_model (struct gcc_options *opts) + } + break; + case AARCH64_CMODEL_LARGE: +- if (opts->x_flag_pic) ++ if (TARGET_MACHO) ++ /* We need to implement fPIC here (arm64_32 also accepts the large ++ model). */ ++ sorry ("code model %qs not supported yet", "large"); ++ else if (opts->x_flag_pic) + sorry ("code model %qs with %<-f%s%>", "large", + opts->x_flag_pic > 1 ? "PIC" : "pic"); +- if (opts->x_aarch64_abi == AARCH64_ABI_ILP32) ++ else if (opts->x_aarch64_abi == AARCH64_ABI_ILP32) + sorry ("code model %qs not supported in ilp32 mode", "large"); + break; + case AARCH64_CMODEL_TINY_PIC: +@@ -19439,7 +19978,9 @@ aarch64_classify_symbol (rtx x, HOST_WIDE_INT offset) + case AARCH64_CMODEL_SMALL_SPIC: + case AARCH64_CMODEL_SMALL_PIC: + case AARCH64_CMODEL_SMALL: +- return SYMBOL_SMALL_ABSOLUTE; ++ return TARGET_MACHO ++ ? SYMBOL_MO_SMALL_PCR ++ : SYMBOL_SMALL_ABSOLUTE; + + default: + gcc_unreachable (); +@@ -19475,10 +20016,22 @@ aarch64_classify_symbol (rtx x, HOST_WIDE_INT offset) + + return SYMBOL_TINY_ABSOLUTE; + +- + case AARCH64_CMODEL_SMALL_SPIC: + case AARCH64_CMODEL_SMALL_PIC: + case AARCH64_CMODEL_SMALL: ++#if TARGET_MACHO ++ if (TARGET_MACHO) ++ { ++ /* Constant pool addresses are always TU-local and PC- ++ relative. We indirect common, external and weak ++ symbols (but weak only if not hidden). */ ++ if (!CONSTANT_POOL_ADDRESS_P (x) ++ && (MACHO_SYMBOL_MUST_INDIRECT_P (x) ++ || !aarch64_symbol_binds_local_p (x))) ++ return SYMBOL_MO_SMALL_GOT; ++ } ++ else ++#endif + if ((flag_pic || SYMBOL_REF_WEAK (x)) + && !aarch64_symbol_binds_local_p (x)) + return aarch64_cmodel == AARCH64_CMODEL_SMALL_SPIC +@@ -19490,7 +20043,8 @@ aarch64_classify_symbol (rtx x, HOST_WIDE_INT offset) + || offset_within_block_p (x, offset))) + return SYMBOL_FORCE_TO_MEM; + +- return SYMBOL_SMALL_ABSOLUTE; ++ return TARGET_MACHO ? SYMBOL_MO_SMALL_PCR ++ : SYMBOL_SMALL_ABSOLUTE; + + case AARCH64_CMODEL_LARGE: + /* This is alright even in PIC code as the constant +@@ -19620,7 +20174,10 @@ static GTY(()) tree va_list_type; + void *__vr_top; + int __gr_offs; + int __vr_offs; +- }; */ ++ }; ++ ++ darwinpcs uses 'char *' for the va_list (in common with other platform ++ ports). */ + + static tree + aarch64_build_builtin_va_list (void) +@@ -19628,6 +20185,13 @@ aarch64_build_builtin_va_list (void) + tree va_list_name; + tree f_stack, f_grtop, f_vrtop, f_groff, f_vroff; + ++ /* darwinpcs uses a simple char * for this. */ ++ if (TARGET_MACHO) ++ { ++ va_list_type = build_pointer_type (char_type_node); ++ return va_list_type; ++ } ++ + /* Create the type. */ + va_list_type = lang_hooks.types.make_type (RECORD_TYPE); + /* Give it the required name. */ +@@ -19699,6 +20263,13 @@ aarch64_expand_builtin_va_start (tree valist, rtx nextarg ATTRIBUTE_UNUSED) + int vr_save_area_size = cfun->va_list_fpr_size; + int vr_offset; + ++ /* darwinpcs uses the default, char * va_list impl. */ ++ if (TARGET_MACHO) ++ { ++ std_expand_builtin_va_start (valist, nextarg); ++ return; ++ } ++ + cum = &crtl->args.info; + if (cfun->va_list_gpr_size) + gr_save_area_size = MIN ((NUM_ARG_REGS - cum->aapcs_ncrn) * UNITS_PER_WORD, +@@ -19789,6 +20360,9 @@ aarch64_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p, + HOST_WIDE_INT size, rsize, adjust, align; + tree t, u, cond1, cond2; + ++ if (TARGET_MACHO) ++ return std_gimplify_va_arg_expr (valist, type, pre_p, post_p); ++ + indirect_p = pass_va_arg_by_reference (type); + if (indirect_p) + type = build_pointer_type (type); +@@ -19973,8 +20547,18 @@ aarch64_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p, + field_ptr_t = double_ptr_type_node; + break; + case E_TFmode: +- field_t = long_double_type_node; +- field_ptr_t = long_double_ptr_type_node; ++ if (TARGET_MACHO) ++ { ++ /* Darwin has __float128, and long double is the same as ++ double. */ ++ field_t = float128_type_node; ++ field_ptr_t = aarch64_float128_ptr_type_node; ++ } ++ else ++ { ++ field_t = long_double_type_node; ++ field_ptr_t = long_double_ptr_type_node; ++ } + break; + case E_HFmode: + field_t = aarch64_fp16_type_node; +@@ -20045,6 +20629,9 @@ aarch64_setup_incoming_varargs (cumulative_args_t cum_v, + int gr_saved = cfun->va_list_gpr_size; + int vr_saved = cfun->va_list_fpr_size; + ++ if (TARGET_MACHO) ++ return default_setup_incoming_varargs (cum_v, arg, pretend_size, no_rtl); ++ + /* The caller has advanced CUM up to, but not beyond, the last named + argument. Advance a local copy of CUM past the last "real" named + argument, to find out how many registers are left over. */ +@@ -20872,6 +21459,12 @@ aarch64_autovectorize_vector_modes (vector_modes *modes, bool) + static const char * + aarch64_mangle_type (const_tree type) + { ++ /* The darwinpcs ABI documents say that "__va_list" has to be ++ mangled as char *. */ ++ if (TARGET_MACHO ++ && lang_hooks.types_compatible_p (CONST_CAST_TREE (type), va_list_type)) ++ return "Pc"; ++ + /* The AArch64 ABI documents say that "__va_list" has to be + mangled as if it is in the "std" namespace. */ + if (lang_hooks.types_compatible_p (CONST_CAST_TREE (type), va_list_type)) +@@ -20886,6 +21479,12 @@ aarch64_mangle_type (const_tree type) + return "Dh"; + } + ++ /* __float128 is mangled as "g" on darwin. _Float128 is not mangled here, ++ but handled in common code (as "DF128_"). */ ++ if (TARGET_MACHO && TYPE_MODE (type) == TFmode ++ && TYPE_MAIN_VARIANT (type) == float128_type_node) ++ return "g"; ++ + /* Mangle AArch64-specific internal types. TYPE_NAME is non-NULL_TREE for + builtin types. */ + if (TYPE_NAME (type) != NULL) +@@ -21576,7 +22175,8 @@ aarch64_mov_operand_p (rtx x, machine_mode mode) + + /* GOT accesses are valid moves. */ + if (SYMBOL_REF_P (x) +- && aarch64_classify_symbolic_expression (x) == SYMBOL_SMALL_GOT_4G) ++ && (aarch64_classify_symbolic_expression (x) == SYMBOL_SMALL_GOT_4G ++ || aarch64_classify_symbolic_expression (x) == SYMBOL_MO_SMALL_GOT)) + return true; + + if (SYMBOL_REF_P (x) && mode == DImode && CONSTANT_ADDRESS_P (x)) +@@ -22688,12 +23288,8 @@ aarch64_asm_output_variant_pcs (FILE *stream, const tree decl, const char* name) + static std::string aarch64_last_printed_arch_string; + static std::string aarch64_last_printed_tune_string; + +-/* Implement ASM_DECLARE_FUNCTION_NAME. Output the ISA features used +- by the function fndecl. */ +- +-void +-aarch64_declare_function_name (FILE *stream, const char* name, +- tree fndecl) ++static void ++aarch64_function_options_preamble (tree fndecl) + { + tree target_parts = DECL_FUNCTION_SPECIFIC_TARGET (fndecl); + +@@ -22732,15 +23328,60 @@ aarch64_declare_function_name (FILE *stream, const char* name, + this_tune->name); + aarch64_last_printed_tune_string = this_tune->name; + } ++} ++ ++/* Implement ASM_DECLARE_FUNCTION_NAME. Output the ISA features used ++ by the function fndecl. */ ++ ++#if TARGET_MACHO ++void ++aarch64_darwin_declare_function_name (FILE *stream, const char* name, ++ tree fndecl) ++{ ++ gcc_checking_assert (TREE_CODE (fndecl) == FUNCTION_DECL); ++ gcc_checking_assert (!DECL_COMMON (fndecl)); ++ ++ /* Update .arch and .tune as needed. */ ++ aarch64_function_options_preamble (fndecl); ++ ++ /* Darwin does not emit pcs variant info. */ ++ ++ rtx decl_rtx = XEXP (DECL_RTL (fndecl), 0); ++ if (GET_CODE (decl_rtx) != SYMBOL_REF) ++ name = IDENTIFIER_POINTER (DECL_NAME (fndecl)); ++ ++ if (! DECL_WEAK (fndecl) ++ && ((TREE_STATIC (fndecl) && !TREE_PUBLIC (fndecl)) ++ || DECL_INITIAL (fndecl))) ++ machopic_define_symbol (DECL_RTL (fndecl)); ++ if ((TREE_STATIC (fndecl) && !TREE_PUBLIC (fndecl)) ++ || DECL_INITIAL (fndecl)) ++ (* targetm.encode_section_info) (fndecl, DECL_RTL (fndecl), false); ++ ASM_OUTPUT_FUNCTION_LABEL (stream, name, fndecl); ++ ++ cfun->machine->label_is_assembled = true; ++} + ++#else ++ ++void ++aarch64_declare_function_name (FILE *stream, const char* name, ++ tree fndecl) ++{ ++ /* Update .arch and .tune as needed. */ ++ aarch64_function_options_preamble (fndecl); ++ /* Emit any necessary pcs information. */ + aarch64_asm_output_variant_pcs (stream, fndecl, name); + + /* Don't forget the type directive for ELF. */ ++#ifdef ASM_OUTPUT_TYPE_DIRECTIVE + ASM_OUTPUT_TYPE_DIRECTIVE (stream, name, "function"); +- ASM_OUTPUT_LABEL (stream, name); ++#endif ++ ASM_OUTPUT_FUNCTION_LABEL (stream, name, fndecl); + + cfun->machine->label_is_assembled = true; + } ++#endif + + /* Implement PRINT_PATCHABLE_FUNCTION_ENTRY. */ + +@@ -22797,12 +23438,17 @@ aarch64_output_patchable_area (unsigned int patch_area_size, bool record_p) + /* Implement ASM_OUTPUT_DEF_FROM_DECLS. Output .variant_pcs for aliases. */ + + void +-aarch64_asm_output_alias (FILE *stream, const tree decl, const tree target) ++aarch64_asm_output_alias (FILE *stream, const tree decl, ++ const tree target ATTRIBUTE_UNUSED) + { + const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0); ++#ifdef ASM_OUTPUT_DEF + const char *value = IDENTIFIER_POINTER (target); ++#endif + aarch64_asm_output_variant_pcs (stream, decl, name); ++#ifdef ASM_OUTPUT_DEF + ASM_OUTPUT_DEF (stream, name, value); ++#endif + } + + /* Implement ASM_OUTPUT_EXTERNAL. Output .variant_pcs for undefined +@@ -22848,6 +23494,9 @@ aarch64_start_file (void) + aarch64_last_printed_arch_string.c_str ()); + + default_file_start (); ++#if TARGET_MACHO ++ darwin_file_start (); ++#endif + } + + /* Emit load exclusive. */ +@@ -23325,6 +23974,10 @@ aarch64_float_const_representable_p (rtx x) + || REAL_VALUE_MINUS_ZERO (r)) + return false; + ++ /* For BFmode, only handle 0.0. */ ++ if (GET_MODE (x) == BFmode) ++ return r.cl == rvc_zero; ++ + /* Extract exponent. */ + r = real_value_abs (&r); + exponent = REAL_EXP (&r); +@@ -23428,6 +24081,16 @@ aarch64_output_simd_mov_immediate (rtx const_vector, unsigned width, + } + + gcc_assert (CONST_INT_P (info.u.mov.value)); ++ unsigned HOST_WIDE_INT value = UINTVAL (info.u.mov.value); ++ ++ /* We have signed chars which can result in a sign-extended 8bit value ++ which is then emitted as an unsigned hex value, and the LLVM back end ++ assembler rejects that as being too big. */ ++ if (TARGET_MACHO && (known_eq (GET_MODE_BITSIZE (info.elt_mode), 8))) ++ { ++ unsigned HOST_WIDE_INT mask = (1U << GET_MODE_BITSIZE (info.elt_mode))-1; ++ value &= mask; ++ } + + if (which == AARCH64_CHECK_MOV) + { +@@ -23436,16 +24099,16 @@ aarch64_output_simd_mov_immediate (rtx const_vector, unsigned width, + ? "msl" : "lsl"); + if (lane_count == 1) + snprintf (templ, sizeof (templ), "%s\t%%d0, " HOST_WIDE_INT_PRINT_HEX, +- mnemonic, UINTVAL (info.u.mov.value)); ++ mnemonic, value); + else if (info.u.mov.shift) + snprintf (templ, sizeof (templ), "%s\t%%0.%d%c, " + HOST_WIDE_INT_PRINT_HEX ", %s %d", mnemonic, lane_count, +- element_char, UINTVAL (info.u.mov.value), shift_op, ++ element_char, value, shift_op, + info.u.mov.shift); + else + snprintf (templ, sizeof (templ), "%s\t%%0.%d%c, " + HOST_WIDE_INT_PRINT_HEX, mnemonic, lane_count, +- element_char, UINTVAL (info.u.mov.value)); ++ element_char, value); + } + else + { +@@ -23454,12 +24117,12 @@ aarch64_output_simd_mov_immediate (rtx const_vector, unsigned width, + if (info.u.mov.shift) + snprintf (templ, sizeof (templ), "%s\t%%0.%d%c, #" + HOST_WIDE_INT_PRINT_DEC ", %s #%d", mnemonic, lane_count, +- element_char, UINTVAL (info.u.mov.value), "lsl", ++ element_char, value, "lsl", + info.u.mov.shift); + else + snprintf (templ, sizeof (templ), "%s\t%%0.%d%c, #" + HOST_WIDE_INT_PRINT_DEC, mnemonic, lane_count, +- element_char, UINTVAL (info.u.mov.value)); ++ element_char, value); + } + return templ; + } +@@ -26605,12 +27268,14 @@ aarch64_libgcc_floating_mode_supported_p (scalar_float_mode mode) + } + + /* Implement TARGET_SCALAR_MODE_SUPPORTED_P - return TRUE +- if MODE is HFmode, and punt to the generic implementation otherwise. */ ++ if MODE is [BH]Fmode, or TFmode on Mach-O, and punt to the generic ++ implementation otherwise. */ + + static bool + aarch64_scalar_mode_supported_p (scalar_mode mode) + { +- return (mode == HFmode ++ ++ return ((mode == HFmode || mode == BFmode || (mode == TFmode && TARGET_MACHO)) + ? true + : default_scalar_mode_supported_p (mode)); + } +@@ -27378,19 +28043,37 @@ aarch64_sls_emit_shared_blr_thunks (FILE *out_file) + continue; + + const char *name = indirect_symbol_names[regnum]; +- switch_to_section (get_named_section (decl, NULL, 0)); ++ /* If the target uses a unique section for this switch to it. */ ++ if (DECL_SECTION_NAME (decl)) ++ switch_to_section (get_named_section (decl, NULL, 0)); ++ else ++ switch_to_section (text_section); + ASM_OUTPUT_ALIGN (out_file, 2); +- targetm.asm_out.globalize_label (out_file, name); ++ if (!TARGET_MACHO) ++ targetm.asm_out.globalize_label (out_file, name); ++#ifdef ASM_OUTPUT_TYPE_DIRECTIVE ++ ASM_OUTPUT_TYPE_DIRECTIVE (out_file, name, "function"); ++#endif ++ if (TARGET_MACHO) ++ { ++#ifdef ASM_WEAKEN_DECL ++ if (DECL_WEAK (decl)) ++ ASM_WEAKEN_DECL (out_file, decl, name, 0); ++ else ++#endif ++ targetm.asm_out.globalize_decl_name (out_file, decl); ++ } + /* Only emits if the compiler is configured for an assembler that can + handle visibility directives. */ + targetm.asm_out.assemble_visibility (decl, VISIBILITY_HIDDEN); +- ASM_OUTPUT_TYPE_DIRECTIVE (out_file, name, "function"); + ASM_OUTPUT_LABEL (out_file, name); + aarch64_sls_emit_function_stub (out_file, regnum); + /* Use the most conservative target to ensure it can always be used by any + function in the translation unit. */ + asm_fprintf (out_file, "\tdsb\tsy\n\tisb\n"); ++#ifdef ASM_DECLARE_FUNCTION_SIZE + ASM_DECLARE_FUNCTION_SIZE (out_file, name, decl); ++#endif + } + } + +@@ -27421,6 +28104,60 @@ aarch64_indirect_call_asm (rtx addr) + return ""; + } + ++#if TARGET_MACHO ++/* This handles the promotion of function return values. ++ It also handles function args under two specific curcumstances: ++ - called from combine with a register argument ++ - caller for a libcall with type == NULL. ++ The remaining cases for argument promotion are handled with access to ++ cumulative args data, below. */ ++machine_mode ++aarch64_darwin_promote_fn_mode (const_tree type, machine_mode mode, ++ int *punsignedp, ++ const_tree funtype ATTRIBUTE_UNUSED, ++ int for_return ATTRIBUTE_UNUSED) ++{ ++ /* With the amended use of promote using cargs, the only cases that arrive ++ here with for_return == 0 are from combine (where the value is definitely ++ in a register) and for libcalls, where type == NULL. We want to promote ++ function return values in the callee, so this becomes pretty much ++ unconditional now. */ ++ if (type != NULL_TREE) ++ return promote_mode (type, mode, punsignedp); ++ return mode; ++} ++ ++/* Ensure that we only promote the mode of named parms when they are passed in ++ a register. Named values passed on the stack retain their original mode and ++ alignment. */ ++machine_mode ++aarch64_darwin_promote_function_mode_ca (cumulative_args_t ca, ++ function_arg_info arg, ++ const_tree funtype ATTRIBUTE_UNUSED, ++ int *punsignedp, ++ int for_return ATTRIBUTE_UNUSED) ++{ ++ tree type = arg.type; ++ machine_mode mode = arg.mode; ++ machine_mode new_mode = promote_mode (type, mode, punsignedp); ++ if (new_mode == mode || arg.named == false ++ || GET_MODE_CLASS (new_mode) != MODE_INT ++ || known_gt (GET_MODE_SIZE (new_mode), 4)) ++ return new_mode; ++ ++ CUMULATIVE_ARGS *pcum = get_cumulative_args (ca); ++ /* Make sure that changes in assumption do not get missed. */ ++ gcc_checking_assert (for_return == 0 && new_mode == SImode ++ && !pcum->aapcs_arg_processed); ++ /* We have a named integer value that fits in a reg; if there's one available ++ then promote the value. */ ++ if (pcum->aapcs_ncrn < 8) ++ return new_mode; ++ return mode; ++} ++ ++#endif ++ + /* Target-specific selftests. */ + + #if CHECKING_P +@@ -27583,6 +28320,15 @@ aarch64_run_selftests (void) + #undef TARGET_ASM_ALIGNED_SI_OP + #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t" + ++#if TARGET_MACHO ++#undef TARGET_ASM_UNALIGNED_HI_OP ++#define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t" ++#undef TARGET_ASM_UNALIGNED_SI_OP ++#define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t" ++#undef TARGET_ASM_UNALIGNED_DI_OP ++#define TARGET_ASM_UNALIGNED_DI_OP "\t.quad\t" ++#endif ++ + #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK + #define TARGET_ASM_CAN_OUTPUT_MI_THUNK \ + hook_bool_const_tree_hwi_hwi_const_tree_true +@@ -27669,6 +28415,12 @@ aarch64_run_selftests (void) + #undef TARGET_FUNCTION_ARG_BOUNDARY + #define TARGET_FUNCTION_ARG_BOUNDARY aarch64_function_arg_boundary + ++#undef TARGET_FUNCTION_ARG_BOUNDARY_CA ++#define TARGET_FUNCTION_ARG_BOUNDARY_CA aarch64_function_arg_boundary_ca ++ ++#undef TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA ++#define TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA aarch64_function_arg_round_boundary_ca ++ + #undef TARGET_FUNCTION_ARG_PADDING + #define TARGET_FUNCTION_ARG_PADDING aarch64_function_arg_padding + +@@ -27996,7 +28748,7 @@ aarch64_libgcc_floating_mode_supported_p + + /* The architecture reserves bits 0 and 1 so use bit 2 for descriptors. */ + #undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS +-#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 4 ++#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS AARCH64_CUSTOM_FUNCTION_TEST + + #undef TARGET_HARD_REGNO_NREGS + #define TARGET_HARD_REGNO_NREGS aarch64_hard_regno_nregs +@@ -28083,6 +28835,11 @@ aarch64_libgcc_floating_mode_supported_p + #undef TARGET_HAVE_SHADOW_CALL_STACK + #define TARGET_HAVE_SHADOW_CALL_STACK true + ++#if TARGET_MACHO ++#undef TARGET_FRAME_POINTER_REQUIRED ++#define TARGET_FRAME_POINTER_REQUIRED aarch64_darwin_frame_pointer_required ++#endif ++ + struct gcc_target targetm = TARGET_INITIALIZER; + + #include "gt-aarch64.h" +diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h +index fadcf98b85c..3f85d26b59b 100644 +--- a/gcc/config/aarch64/aarch64.h ++++ b/gcc/config/aarch64/aarch64.h +@@ -54,6 +54,10 @@ + #define TARGET_SIMD (!TARGET_GENERAL_REGS_ONLY && AARCH64_ISA_SIMD) + #define TARGET_FLOAT (!TARGET_GENERAL_REGS_ONLY && AARCH64_ISA_FP) + ++/* If this is non-zero then generated code of the object format, ABI and ++ assembler syntax used by Darwin (Mach-O) platforms. */ ++#define TARGET_MACHO 0 ++ + #define UNITS_PER_WORD 8 + + #define UNITS_PER_VREG 16 +@@ -131,6 +135,12 @@ + /* Heap alignment (same as BIGGEST_ALIGNMENT and STACK_BOUNDARY). */ + #define MALLOC_ABI_ALIGNMENT 128 + ++/* We will and with this value to test if a custom function descriptor needs ++ a static chain. The function boundary must the adjusted so that the bit ++ this represents is no longer part of the address. 0 Disables the custom ++ function descriptors. */ ++#define AARCH64_CUSTOM_FUNCTION_TEST 4 ++ + /* Defined by the ABI */ + #define WCHAR_TYPE "unsigned int" + #define WCHAR_TYPE_SIZE 32 +@@ -1038,6 +1048,24 @@ typedef struct + aapcs_reg == NULL_RTX. */ + int aapcs_stack_size; /* The total size (in words, per 8 byte) of the + stack arg area so far. */ ++ ++ /* In the darwinpcs, items smaller than one word are packed onto the stack ++ naturally aligned. Unnamed parameters passed in a variadic call are, ++ however, aligned the same way as the AAPCS64. This means that we need to ++ pad the last named arg to the next parm boundary (and hence notice when ++ we are processing that arg). */ ++ int darwinpcs_stack_bytes; /* If the argument is passed on the stack, this ++ the byte-size. */ ++ int darwinpcs_sub_word_offset;/* This is the offset of this arg within a word ++ when placing smaller items for darwinpcs. */ ++ int darwinpcs_sub_word_pos; /* The next byte available within the word for ++ darwinpcs. */ ++ unsigned darwinpcs_arg_boundary; /* The computed argument boundary. */ ++ unsigned darwinpcs_arg_padding; /* The computed argument padding. */ ++ unsigned darwinpcs_n_named; /* Number of named arguments. */ ++ unsigned darwinpcs_n_args_processed; /* Processed so far. */ ++ bool named_p; /* Is this arg named? */ ++ bool last_named_p; /* Is this the last named arg? */ + bool silent_p; /* True if we should act silently, rather than + raise an error for invalid calls. */ + } CUMULATIVE_ARGS; +@@ -1322,8 +1350,13 @@ extern const char *host_detect_local_cpu (int argc, const char **argv); + #define ASM_CPU_SPEC \ + MCPU_TO_MARCH_SPEC + ++#ifndef SUBTARGET_EXTRA_SPECS ++#define SUBTARGET_EXTRA_SPECS ++#endif ++ + #define EXTRA_SPECS \ +- { "asm_cpu_spec", ASM_CPU_SPEC } ++ { "asm_cpu_spec", ASM_CPU_SPEC }, \ ++ SUBTARGET_EXTRA_SPECS + + #define ASM_OUTPUT_POOL_EPILOGUE aarch64_asm_output_pool_epilogue + +@@ -1337,6 +1370,10 @@ extern GTY(()) tree aarch64_fp16_ptr_type_node; + extern GTY(()) tree aarch64_bf16_type_node; + extern GTY(()) tree aarch64_bf16_ptr_type_node; + ++/* A pointer to the user-visible __float128 (on Mach-O). Defined in ++ aarch64-builtins.c. */ ++extern GTY(()) tree aarch64_float128_ptr_type_node; ++ + /* The generic unwind code in libgcc does not initialize the frame pointer. + So in order to unwind a function using a frame pointer, the very first + function that is unwound must save the frame pointer. That way the frame +diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md +index 99f185718c9..2c165c6047a 100644 +--- a/gcc/config/aarch64/aarch64.md ++++ b/gcc/config/aarch64/aarch64.md +@@ -304,6 +304,7 @@ + UNSPEC_LD1RO + UNSPEC_SALT_ADDR + UNSPECV_PATCHABLE_AREA ++ UNSPEC_MACHOPIC_OFFSET ; Common to Mach-O ports. + ]) + + (define_c_enum "unspecv" [ +@@ -850,6 +851,37 @@ + [(set_attr "type" "load_4")] + ) + ++(define_insn "prefetch_unscaled" ++ [(prefetch (match_operand:DI 0 "aarch64_unscaled_prefetch_operand" "Du") ++ (match_operand:QI 1 "const_int_operand" "") ++ (match_operand:QI 2 "const_int_operand" ""))] ++ "" ++ { ++ const char * pftype[2][4] = ++ { ++ {"prfum\\tPLDL1STRM, %0", ++ "prfum\\tPLDL3KEEP, %0", ++ "prfum\\tPLDL2KEEP, %0", ++ "prfum\\tPLDL1KEEP, %0"}, ++ {"prfum\\tPSTL1STRM, %0", ++ "prfum\\tPSTL3KEEP, %0", ++ "prfum\\tPSTL2KEEP, %0", ++ "prfum\\tPSTL1KEEP, %0"}, ++ }; ++ ++ int locality = INTVAL (operands[2]); ++ ++ gcc_assert (IN_RANGE (locality, 0, 3)); ++ ++ /* PRFUM accepts the same addresses as a 64-bit LDR so wrap ++ the address into a DImode MEM so that aarch64_print_operand knows ++ how to print it. */ ++ operands[0] = gen_rtx_MEM (DImode, operands[0]); ++ return pftype[INTVAL(operands[1])][locality]; ++ } ++ [(set_attr "type" "load_4")] ++) ++ + (define_insn "trap" + [(trap_if (const_int 1) (const_int 8))] + "" +@@ -1305,7 +1337,7 @@ + ldr\\t%s0, %1 + str\\t%w1, %0 + str\\t%s1, %0 +- adrp\\t%x0, %A1\;ldr\\t%w0, [%x0, %L1] ++ * return TARGET_MACHO ? \"adrp\\t%x0, %A1\;ldr\\t%w0, [%x0, %O1]\" : \"adrp\\t%x0, %A1\;ldr\\t%w0, [%x0, %L1]\"; + adr\\t%x0, %c1 + adrp\\t%x0, %A1 + fmov\\t%s0, %w1 +@@ -1344,7 +1376,7 @@ + ldr\\t%d0, %1 + str\\t%x1, %0 + str\\t%d1, %0 +- * return TARGET_ILP32 ? \"adrp\\t%0, %A1\;ldr\\t%w0, [%0, %L1]\" : \"adrp\\t%0, %A1\;ldr\\t%0, [%0, %L1]\"; ++ * return TARGET_ILP32 ? (TARGET_MACHO ? \"adrp\\t%0, %A1\;ldr\\t%w0, [%0, %O1]\" : \"adrp\\t%0, %A1\;ldr\\t%w0, [%0, %L1]\") : (TARGET_MACHO ? \"adrp\\t%0, %A1\;ldr\\t%0, [%0, %O1]\" : \"adrp\\t%0, %A1\;ldr\\t%0, [%0, %L1]\"); + adr\\t%x0, %c1 + adrp\\t%x0, %A1 + fmov\\t%d0, %x1 +@@ -1777,16 +1809,16 @@ + (set_attr "arch" "*,fp")] + ) + +-(define_insn "load_pair_dw_tftf" +- [(set (match_operand:TF 0 "register_operand" "=w") +- (match_operand:TF 1 "aarch64_mem_pair_operand" "Ump")) +- (set (match_operand:TF 2 "register_operand" "=w") +- (match_operand:TF 3 "memory_operand" "m"))] ++(define_insn "load_pair_dw_" ++ [(set (match_operand:TX 0 "register_operand" "=w") ++ (match_operand:TX 1 "aarch64_mem_pair_operand" "Ump")) ++ (set (match_operand:TX2 2 "register_operand" "=w") ++ (match_operand:TX2 3 "memory_operand" "m"))] + "TARGET_SIMD + && rtx_equal_p (XEXP (operands[3], 0), + plus_constant (Pmode, + XEXP (operands[1], 0), +- GET_MODE_SIZE (TFmode)))" ++ GET_MODE_SIZE (mode)))" + "ldp\\t%q0, %q2, %z1" + [(set_attr "type" "neon_ldp_q") + (set_attr "fp" "yes")] +@@ -1827,11 +1859,11 @@ + (set_attr "arch" "*,fp")] + ) + +-(define_insn "store_pair_dw_tftf" +- [(set (match_operand:TF 0 "aarch64_mem_pair_operand" "=Ump") +- (match_operand:TF 1 "register_operand" "w")) +- (set (match_operand:TF 2 "memory_operand" "=m") +- (match_operand:TF 3 "register_operand" "w"))] ++(define_insn "store_pair_dw_" ++ [(set (match_operand:TX 0 "aarch64_mem_pair_operand" "=Ump") ++ (match_operand:TX 1 "register_operand" "w")) ++ (set (match_operand:TX2 2 "memory_operand" "=m") ++ (match_operand:TX2 3 "register_operand" "w"))] + "TARGET_SIMD && + rtx_equal_p (XEXP (operands[2], 0), + plus_constant (Pmode, +@@ -6889,7 +6921,10 @@ + (lo_sum:P (match_operand:P 1 "register_operand" "r") + (match_operand 2 "aarch64_valid_symref" "S")))] + "" +- "add\\t%0, %1, :lo12:%c2" ++ { return TARGET_MACHO ++ ? "add\\t%0, %1, %J2;" ++ : "add\\t%0, %1, :lo12:%c2"; ++ } + [(set_attr "type" "alu_imm")] + ) + +diff --git a/gcc/config/aarch64/aarch64.opt b/gcc/config/aarch64/aarch64.opt +index 92220b26ee2..15ec719ca2d 100644 +--- a/gcc/config/aarch64/aarch64.opt ++++ b/gcc/config/aarch64/aarch64.opt +@@ -152,6 +152,13 @@ Enum(aarch64_abi) String(ilp32) Value(AARCH64_ABI_ILP32) + EnumValue + Enum(aarch64_abi) String(lp64) Value(AARCH64_ABI_LP64) + ++EnumValue ++Enum(aarch64_abi) String(darwinpcs) Value(AARCH64_ABI_LP64) ++ ++m64 ++Target RejectNegative Alias(mabi=, darwinpcs) ++On Darwin for compatibility with other platform variants. ++ + mpc-relative-literal-loads + Target Save Var(pcrelative_literal_loads) Init(2) Save + PC relative literal loads. +diff --git a/gcc/config/aarch64/constraints.md b/gcc/config/aarch64/constraints.md +index ee7587cca16..cb73a2daae8 100644 +--- a/gcc/config/aarch64/constraints.md ++++ b/gcc/config/aarch64/constraints.md +@@ -158,7 +158,9 @@ + A constraint that matches a small GOT access." + (and (match_code "const,symbol_ref") + (match_test "aarch64_classify_symbolic_expression (op) +- == SYMBOL_SMALL_GOT_4G"))) ++ == SYMBOL_SMALL_GOT_4G ++ || aarch64_classify_symbolic_expression (op) ++ == SYMBOL_MO_SMALL_GOT"))) + + (define_constraint "Uss" + "@internal +@@ -490,6 +492,11 @@ + An address valid for a prefetch instruction." + (match_test "aarch64_address_valid_for_prefetch_p (op, true)")) + ++(define_address_constraint "Du" ++ "@internal ++ An address valid for a prefetch instruction with an unscaled offset." ++ (match_test "aarch64_address_valid_for_unscaled_prefetch_p (op, true)")) ++ + (define_constraint "vgb" + "@internal + A constraint that matches an immediate offset valid for SVE LD1B +diff --git a/gcc/config/aarch64/darwin.h b/gcc/config/aarch64/darwin.h +new file mode 100644 +index 00000000000..08febf1401b +--- /dev/null ++++ b/gcc/config/aarch64/darwin.h +@@ -0,0 +1,289 @@ ++/* Target definitions for Arm64/Aarch64 running on macOS/iOS. ++ ++Copyright The GNU Toolchain Authors. ++Contributed by Iain Sandoe. ++ ++This file is part of GCC. ++ ++GCC is free software; you can redistribute it and/or modify ++it under the terms of the GNU General Public License as published by ++the Free Software Foundation; either version 3, or (at your option) ++any later version. ++ ++GCC is distributed in the hope that it will be useful, ++but WITHOUT ANY WARRANTY; without even the implied warranty of ++MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++GNU General Public License for more details. ++ ++You should have received a copy of the GNU General Public License ++along with GCC; see the file COPYING3. If not see ++. */ ++ ++/* Enable Mach-O bits in generic Aarch64 code. */ ++#undef TARGET_MACHO ++#define TARGET_MACHO 1 ++ ++#undef DARWIN_ARM64 ++#define DARWIN_ARM64 1 ++ ++/* This is used in generic code in darwin.cc (at present, we have no support ++ for the arm64_32 target). */ ++#undef TARGET_64BIT ++#define TARGET_64BIT 1 ++ ++#undef PTRDIFF_TYPE ++#define PTRDIFF_TYPE "long int" ++ ++#undef TARGET_PROMOTE_FUNCTION_MODE ++#define TARGET_PROMOTE_FUNCTION_MODE aarch64_darwin_promote_fn_mode ++ ++#undef TARGET_PROMOTE_FUNCTION_MODE_CA ++#define TARGET_PROMOTE_FUNCTION_MODE_CA aarch64_darwin_promote_function_mode_ca ++ ++/* NOTE that arm64_32 is a valid thing and corresponds to darwinpcs ++ and TARGET_ILP32, but we are not implementing that for now. */ ++#define TARGET_OS_CPP_BUILTINS() \ ++ do { \ ++ builtin_define ("__LITTLE_ENDIAN__"); \ ++ builtin_define ("__arm64"); \ ++ builtin_define ("__arm64__"); \ ++ darwin_cpp_builtins (pfile); \ ++ } while (0) ++ ++/* In Darwin's Arm64 ABI, chars are signed. */ ++ ++#undef DEFAULT_SIGNED_CHAR ++#define DEFAULT_SIGNED_CHAR 1 ++ ++#undef LONG_DOUBLE_TYPE_SIZE ++#define LONG_DOUBLE_TYPE_SIZE 64 ++ ++/* Disable custom function descriptors on Darwin (we use heap-based ++ trampolines). */ ++#undef AARCH64_CUSTOM_FUNCTION_TEST ++#define AARCH64_CUSTOM_FUNCTION_TEST 0 ++ ++/* Non-PIE executables are forbidden by the Arm64-darwin security model; ++ remove the option from link-lines since they just produce a warning from ++ ld64 and are then ignored anyway. */ ++#undef DARWIN_NOPIE_SPEC ++#define DARWIN_NOPIE_SPEC \ ++" % ++# include ++#endif ++ ++ ++#if TARGET_MACHO ++ ++/* Default architecture to use if -mcpu=native did not detect a known CPU. */ ++#define DEFAULT_ARCH "apple-m1" ++ ++/* macOS does not have /proc/cpuinfo and needs a different approach, ++ based on sysctl. It is much simpler. */ ++ ++const char * ++host_detect_local_cpu (ATTRIBUTE_UNUSED int argc, ATTRIBUTE_UNUSED const char **argv) ++{ ++ bool arch = false; ++ bool tune = false; ++ bool cpu = false; ++ const char *res = NULL; ++ uint32_t family; ++ size_t len = sizeof(family); ++ ++ gcc_assert (argc); ++ if (!argv[0]) ++ return NULL; ++ ++ /* Are we processing -march, mtune or mcpu? */ ++ arch = strcmp (argv[0], "arch") == 0; ++ if (!arch) ++ tune = strcmp (argv[0], "tune") == 0; ++ if (!arch && !tune) ++ cpu = strcmp (argv[0], "cpu") == 0; ++ if (!arch && !tune && !cpu) ++ return NULL; ++ ++ sysctlbyname("hw.cpufamily", &family, &len, NULL, 0); ++ ++ switch (family) ++ { ++ case 0x07d34b9f: // Vortex, Tempest ++ res = "apple-a12"; ++ break; ++ case 0x573b5eec: ++ case 0x1b588bb3: // Firestorm, Icestorm ++ res = "apple-m1"; ++ break; ++ case 0xda33d83d: // Blizzard, Avalanche ++ res = "apple-m2"; ++ break; ++ case 0xfa33415e: // Ibiza (M3) ++ case 0x5f4dea93: // Lobos (M3 Pro) ++ case 0x72015832: // Palma (M3 Max) ++ res = "apple-m3"; ++ break; ++ default: ++ res = DEFAULT_ARCH; ++ } ++ ++ if (res) ++ return concat ("-m", argv[0], "=", res, NULL); ++ else ++ return NULL; ++} ++ ++#else ++ + struct aarch64_arch_extension + { + const char *ext; +@@ -468,3 +536,4 @@ not_found: + } + } + ++#endif +diff --git a/gcc/config/aarch64/falkor-tag-collision-avoidance.cc b/gcc/config/aarch64/falkor-tag-collision-avoidance.cc +index 5f198290568..ab881d9abc0 100644 +--- a/gcc/config/aarch64/falkor-tag-collision-avoidance.cc ++++ b/gcc/config/aarch64/falkor-tag-collision-avoidance.cc +@@ -740,7 +740,7 @@ dump_insn_list (const rtx &t, const insn_info_list_t &insn_info, + void *unused ATTRIBUTE_UNUSED) + { + gcc_assert (dump_file); +- fprintf (dump_file, "Tag 0x%lx ::\n", INTVAL (t)); ++ fprintf (dump_file, "Tag 0x" HOST_WIDE_INT_PRINT_HEX_PURE " ::\n", INTVAL (t)); + + for (unsigned i = 0; i < insn_info.length (); i++) + dump_insn_slim (dump_file, insn_info[i]->insn); +diff --git a/gcc/config/aarch64/iterators.md b/gcc/config/aarch64/iterators.md +index d49e37893df..b2c507745a8 100644 +--- a/gcc/config/aarch64/iterators.md ++++ b/gcc/config/aarch64/iterators.md +@@ -306,6 +306,11 @@ + ;; TX plus V16QImode. + (define_mode_iterator TX_V16QI [TI TF V16QI]) + ++;; Duplicate of TX above ++(define_mode_iterator TX2 [TI TF]) ++ ++(define_mode_iterator VTX [TI TF V16QI V8HI V4SI V2DI V8HF V4SF V2DF V8BF]) ++ + ;; Advanced SIMD opaque structure modes. + (define_mode_iterator VSTRUCT [OI CI XI]) + +diff --git a/gcc/config/aarch64/predicates.md b/gcc/config/aarch64/predicates.md +index c308015ac2c..cd88f93ca2d 100644 +--- a/gcc/config/aarch64/predicates.md ++++ b/gcc/config/aarch64/predicates.md +@@ -261,9 +261,24 @@ + (define_predicate "aarch64_prefetch_operand" + (match_test "aarch64_address_valid_for_prefetch_p (op, false)")) + ++(define_predicate "aarch64_unscaled_prefetch_operand" ++ (match_test "aarch64_address_valid_for_unscaled_prefetch_p (op, false)")) ++ + (define_predicate "aarch64_valid_symref" + (match_code "const, symbol_ref, label_ref") + { ++ if (TARGET_MACHO) ++ { ++ rtx x = op; ++ rtx offset; ++ split_const (x, &x, &offset); ++ if (GET_CODE (x) == CONST) ++ x = XEXP (x, 0); ++ if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_SALT_ADDR) ++ x = XVECEXP (x, 0, 0); ++ if (SYMBOL_REF_P (x) && INTVAL (offset) < 0) ++ return false; ++ } + return (aarch64_classify_symbolic_expression (op) + != SYMBOL_FORCE_TO_MEM); + }) +diff --git a/gcc/config/aarch64/t-aarch64-darwin b/gcc/config/aarch64/t-aarch64-darwin +new file mode 100644 +index 00000000000..e2b8ad9237f +--- /dev/null ++++ b/gcc/config/aarch64/t-aarch64-darwin +@@ -0,0 +1,25 @@ ++# Machine description for AArch64 architecture. ++# Copyright (C) 2020 Free Software Foundation, Inc. ++# ++# This file is part of GCC. ++# ++# GCC is free software; you can redistribute it and/or modify it ++# under the terms of the GNU General Public License as published by ++# the Free Software Foundation; either version 3, or (at your option) ++# any later version. ++# ++# GCC is distributed in the hope that it will be useful, but ++# WITHOUT ANY WARRANTY; without even the implied warranty of ++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++# General Public License for more details. ++# ++# You should have received a copy of the GNU General Public License ++# along with GCC; see the file COPYING3. If not see ++# . ++ ++LIB1ASMSRC = aarch64/lib1funcs.asm ++LIB1ASMFUNCS = _aarch64_sync_cache_range ++ ++# TODO - figure out what multilib provisions we should make for ++# a) arm64e ++# b) arm64_32 +diff --git a/gcc/config/darwin-c.cc b/gcc/config/darwin-c.cc +index 923434da5b1..fe4b5538a0b 100644 +--- a/gcc/config/darwin-c.cc ++++ b/gcc/config/darwin-c.cc +@@ -555,7 +555,7 @@ find_subframework_header (cpp_reader *pfile, const char *header, cpp_dir **dirp) + return 0; + } + +-/* Given an OS X version VERSION_STR, return it as a statically-allocated array ++/* Given an macOS version VERSION_STR, return it as a statically-allocated array + of three integers. If VERSION_STR is invalid, return NULL. + + VERSION_STR must consist of one, two, or three tokens, each separated by +@@ -612,7 +612,7 @@ parse_version (const char *version_str) + return version_array; + } + +-/* Given VERSION -- a three-component OS X version represented as an array of ++/* Given VERSION -- a three-component macOS version represented as an array of + non-negative integers -- return a statically-allocated string suitable for + the legacy __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro. If VERSION + is invalid and cannot be coerced into a valid form, return NULL. +@@ -645,7 +645,7 @@ version_as_legacy_macro (const unsigned long *version) + return result; + } + +-/* Given VERSION -- a three-component OS X version represented as an array of ++/* Given VERSION -- a three-component macOS version represented as an array of + non-negative integers -- return a statically-allocated string suitable for + the modern __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro. If VERSION + is invalid, return NULL. +@@ -675,7 +675,7 @@ version_as_modern_macro (const unsigned long *version) + + /* Return the value of darwin_macosx_version_min, suitably formatted for the + __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro. Values representing +- OS X 10.9 and earlier are encoded using the legacy four-character format, ++ macOS 10.9 and earlier are encoded using the legacy four-character format, + while 10.10 and later use a modern six-character format. (For example, + "10.9" produces "1090", and "10.10.1" produces "101001".) If + darwin_macosx_version_min is invalid and cannot be coerced into a valid +diff --git a/gcc/config/darwin-driver.cc b/gcc/config/darwin-driver.cc +index 00287f3d5ec..98a1ea7b672 100644 +--- a/gcc/config/darwin-driver.cc ++++ b/gcc/config/darwin-driver.cc +@@ -268,10 +268,13 @@ darwin_driver_init (unsigned int *decoded_options_count, + bool seenX86_64 = false; + bool seenPPC = false; + bool seenPPC64 = false; ++#if !DARWIN_ARM64 ++ bool seenArm64 = false; + bool seenM32 = false; + bool seenM64 = false; + bool appendM32 = false; + bool appendM64 = false; ++#endif + const char *vers_string = NULL; + bool seen_version_min = false; + bool seen_sysroot_p = false; +@@ -296,6 +299,12 @@ darwin_driver_init (unsigned int *decoded_options_count, + seenPPC = true; + else if (!strcmp ((*decoded_options)[i].arg, "ppc64")) + seenPPC64 = true; ++ else if (!strcmp ((*decoded_options)[i].arg, "arm64")) ++#if !DARWIN_ARM64 ++ seenArm64 = true; ++#else ++ ; /* We accept the option, but don't need to act on it. */ ++#endif + else + error ("this compiler does not support %qs", + (*decoded_options)[i].arg); +@@ -309,7 +318,7 @@ darwin_driver_init (unsigned int *decoded_options_count, + --i; + --*decoded_options_count; + break; +- ++#if !DARWIN_ARM64 + case OPT_m32: + seenM32 = true; + break; +@@ -317,6 +326,7 @@ darwin_driver_init (unsigned int *decoded_options_count, + case OPT_m64: + seenM64 = true; + break; ++#endif + + case OPT_mmacosx_version_min_: + seen_version_min = true; +@@ -366,6 +376,9 @@ darwin_driver_init (unsigned int *decoded_options_count, + if (seenPPC || seenPPC64) + warning (0, "this compiler does not support PowerPC" + " (%<-arch%> option ignored)"); ++ else if (seenArm64) ++ warning (0, "this compiler does not support Arm64" ++ " (%<-arch%> option ignored)"); + if (seenX86) + { + if (seenX86_64 || seenM64) +@@ -389,6 +402,9 @@ darwin_driver_init (unsigned int *decoded_options_count, + if (seenX86 || seenX86_64) + warning (0, "this compiler does not support x86" + " (%<-arch%> option ignored)"); ++ else if (seenArm64) ++ warning (0, "this compiler does not support Arm64" ++ " (%<-arch%> option ignored)"); + if (seenPPC) + { + if (seenPPC64 || seenM64) +@@ -408,12 +424,20 @@ darwin_driver_init (unsigned int *decoded_options_count, + if (! seenM64) /* Add -m64 if the User didn't. */ + appendM64 = true; + } ++#elif DARWIN_ARM64 ++ if (seenPPC || seenPPC64) ++ warning (0, "this compiler does not support PowerPC" ++ " (%<-arch%> option ignored)"); ++ if (seenX86 || seenX86_64) ++ warning (0, "this compiler does not support x86" ++ " (%<-arch%> option ignored)"); + #endif + + /* If there is nothing else on the command line, do not add sysroot etc. */ + if (*decoded_options_count <= 1) + return; + ++#if !DARWIN_ARM64 + if (appendM32 || appendM64) + { + ++*decoded_options_count; +@@ -423,6 +447,7 @@ darwin_driver_init (unsigned int *decoded_options_count, + generate_option (appendM32 ? OPT_m32 : OPT_m64, NULL, 1, CL_DRIVER, + &(*decoded_options)[*decoded_options_count - 1]); + } ++#endif + + if (!seen_sysroot_p) + { +@@ -440,7 +465,7 @@ darwin_driver_init (unsigned int *decoded_options_count, + } + } + +- /* We will need to know the OS X version we're trying to build for here ++ /* We will need to know the macOS version we're trying to build for here + so that we can figure out the mechanism and source for the sysroot to + be used. */ + if (!seen_version_min) +diff --git a/gcc/config/darwin-protos.h b/gcc/config/darwin-protos.h +index c7f87098ab9..5dee00fd643 100644 +--- a/gcc/config/darwin-protos.h ++++ b/gcc/config/darwin-protos.h +@@ -86,9 +86,12 @@ extern void darwin_asm_lto_end (void); + extern void darwin_mark_decl_preserved (const char *); + + extern tree darwin_handle_kext_attribute (tree *, tree, tree, int, bool *); +-extern tree darwin_handle_weak_import_attribute (tree *node, tree name, +- tree args, int flags, +- bool * no_add_attrs); ++extern tree darwin_handle_weak_import_attribute (tree *, tree, tree, int, ++ bool *); ++extern tree darwin_handle_availability_attribute (tree *, tree, tree, ++ int, bool *); ++extern bool darwin_attribute_takes_identifier_p (const_tree); ++ + extern void machopic_output_stub (FILE *, const char *, const char *); + extern void darwin_globalize_label (FILE *, const char *); + extern void darwin_assemble_visibility (tree, int); +@@ -124,6 +127,7 @@ extern void darwin_enter_string_into_cfstring_table (tree); + extern void darwin_asm_output_anchor (rtx symbol); + extern bool darwin_use_anchors_for_symbol_p (const_rtx symbol); + extern bool darwin_kextabi_p (void); ++extern bool darwin_unreachable_traps_p (void); + extern void darwin_override_options (void); + extern void darwin_patch_builtins (void); + extern void darwin_rename_builtins (void); +diff --git a/gcc/config/darwin.cc b/gcc/config/darwin.cc +index 76feb87a29d..0f45ccfbc16 100644 +--- a/gcc/config/darwin.cc ++++ b/gcc/config/darwin.cc +@@ -29,6 +29,7 @@ along with GCC; see the file COPYING3. If not see + #include "cfghooks.h" + #include "df.h" + #include "memmodel.h" ++#include "c-family/c-common.h" /* enum rid. */ + #include "tm_p.h" + #include "stringpool.h" + #include "attribs.h" +@@ -49,6 +50,7 @@ along with GCC; see the file COPYING3. If not see + #include "optabs.h" + #include "flags.h" + #include "opts.h" ++#include "c-family/c-objc.h" /* for objc_method_decl(). */ + + /* Fix and Continue. + +@@ -102,6 +104,7 @@ int darwin_running_cxx; + + /* Some code-gen now depends on OS major version numbers (at least). */ + int generating_for_darwin_version ; ++unsigned long current_os_version = 0; + + /* For older linkers we need to emit special sections (marked 'coalesced') for + for weak or single-definition items. */ +@@ -131,7 +134,7 @@ struct { + section * darwin_sections[NUM_DARWIN_SECTIONS]; + + /* While we transition to using in-tests instead of ifdef'd code. */ +-#if !HAVE_lo_sum ++#if !HAVE_lo_sum || DARWIN_ARM64 + #define gen_macho_high(m,a,b) (a) + #define gen_macho_low(m,a,b,c) (a) + #endif +@@ -1065,6 +1068,7 @@ machopic_legitimize_pic_address (rtx orig, machine_mode mode, rtx reg) + return pic_ref; + } + ++#if !DARWIN_ARM64 + /* Callbacks to output the stub or non-lazy pointers. + Each works on the item in *SLOT,if it has been used. + DATA is the FILE* for assembly output. +@@ -1220,6 +1224,7 @@ machopic_finish (FILE *out_file) + machopic_indirections->traverse_noresize + (out_file); + } ++#endif + + int + machopic_operand_p (rtx op) +@@ -2155,6 +2160,122 @@ darwin_handle_kext_attribute (tree *node, tree name, + return NULL_TREE; + } + ++enum version_components { MAJOR, MINOR, TINY }; ++ ++/* Parse a version number in x.y.z form and validate it as a macOS ++ version. Ideally, we'd put this in a common place usable by the ++ Darwin backend. */ ++ ++static bool ++parse_version (unsigned version_array[3], const char *version_str) ++{ ++ size_t version_len; ++ char *end, last = '\0', delimiter = '.', alt_delim = '_'; ++ ++ if (!version_str) ++ return false; ++ ++ /* Handle the odd situation in which we get STRING_CST which contain the ++ starting and ending quotes. */ ++ if (version_str[0] == '"') ++ { ++ version_str++; ++ version_len = strrchr (&version_str[1], '"') - version_str; ++ last = '"'; ++ } ++ else ++ version_len = strlen (version_str); ++ ++ if (version_len < 1) ++ return false; ++ ++ /* Version string must consist of digits and periods only. */ ++ if (strspn (version_str, "0123456789._") != version_len) ++ return false; ++ ++ if (!ISDIGIT (version_str[0]) || !ISDIGIT (version_str[version_len - 1])) ++ return false; ++ ++ version_array[MAJOR] = strtoul (version_str, &end, 10); ++ if (*end == '_') ++ { ++ delimiter = '_'; ++ alt_delim = '.'; ++ } ++ version_str = end + ((*end == delimiter) ? 1 : 0); ++ if (version_array[MAJOR] == 100000) ++ return true; ++ if (version_array[MAJOR] > 99) ++ return false; ++ ++ /* Version string must not contain adjacent delimiters. */ ++ if (*version_str == delimiter || *version_str == alt_delim) ++ return false; ++ ++ version_array[MINOR] = strtoul (version_str, &end, 10); ++ if (*end == alt_delim) ++ return false; ++ version_str = end + ((*end == delimiter) ? 1 : 0); ++ if (version_array[MINOR] > 99) ++ return false; ++ ++ version_array[TINY] = strtoul (version_str, &end, 10); ++ if (version_array[TINY] > 99) ++ return false; ++ ++ /* Version string must contain no more than three tokens. */ ++ if (*end != last) ++ return false; ++ ++ return true; ++} ++ ++/* Turn a version expressed as maj.min.tiny into an unsigned long ++ integer representing the value used in macOS availability macros. */ ++ ++static unsigned long ++version_from_version_array (unsigned vers[3]) ++{ ++ unsigned long res = 0; ++ /* There seems to be a special "unknown" value. */ ++ if (vers[0] == 100000) ++ return 999999; ++ ++ /* Here, we follow the 'modern' / 'legacy' numbering scheme for versions. */ ++ if (vers[0] > 10 || vers[1] >= 10) ++ res = vers[0] * 10000 + vers[1] * 100 + vers[2]; ++ else ++ { ++ res = vers[0] * 100; ++ if (vers[1] > 9) ++ res += 90; ++ else ++ res += vers[1] * 10; ++ if (vers[2] > 9) ++ res += 9; ++ else ++ res += vers[1]; ++ } ++ return res; ++} ++ ++/* Extract a macOS version from an availability attribute argument. */ ++ ++static unsigned long ++os_version_from_avail_value (tree value) ++{ ++ unsigned long res = 0; ++ unsigned vers[3] = {0,0,0}; ++ if (TREE_CODE (value) == STRING_CST) ++ { ++ if (parse_version (&vers[0], TREE_STRING_POINTER (value))) ++ res = version_from_version_array (&vers[0]); ++ } ++ else ++ gcc_unreachable (); ++ return res; ++} ++ + /* Handle a "weak_import" attribute; arguments as in + struct attribute_spec.handler. */ + +@@ -2176,6 +2297,231 @@ darwin_handle_weak_import_attribute (tree *node, tree name, + return NULL_TREE; + } + ++#define NUM_AV_OSES 13 ++const char *availability_os[NUM_AV_OSES] ++ = { "macos", "macosx", "ios", "tvos", "watchos", "driverkit", "swift", ++ "maccatalyst", "macCatalyst", "xros", "visionos", "android", "zos" }; ++ ++#define NUM_AV_CLAUSES 6 ++const char *availability_clause[NUM_AV_CLAUSES] ++ = { "unavailable", "introduced", "deprecated", "obsoleted", "message", ++ "replacement" }; ++ ++/* Validate and act upon the arguments to an 'availability' attribute. */ ++ ++tree ++darwin_handle_availability_attribute (tree *node, tree name, tree args, ++ int flags, bool * no_add_attrs) ++{ ++ tree decl = *node; ++ *no_add_attrs = true; ++ ++ if (!decl || (!TYPE_P (decl) && !DECL_P (decl))) ++ { ++ warning (OPT_Wattributes, "%qE attribute ignored", name); ++ return NULL_TREE; ++ } ++ else if (decl == error_mark_node) ++ return NULL_TREE; ++ ++ location_t loc = DECL_SOURCE_LOCATION (decl); ++ if (args == NULL_TREE) ++ { ++ error_at (loc, "%qE attribute requires at least one argument", ++ name); ++ return NULL_TREE; ++ } ++ else if (args == error_mark_node) ++ return NULL_TREE; ++ ++ /* The first argument must name a supported OS - although we could choose ++ to ignore any OS we don't recognise. */ ++ gcc_checking_assert (TREE_CODE (args) == TREE_LIST); ++ tree platform = TREE_VALUE (args); ++ if (platform == error_mark_node) ++ return NULL_TREE; ++ ++ gcc_checking_assert (TREE_CODE (platform) == IDENTIFIER_NODE); ++ bool platform_ok = false; ++ unsigned plat_num = 0; ++ for (; plat_num < (unsigned) NUM_AV_OSES; plat_num++) ++ if (strcmp (availability_os[plat_num], IDENTIFIER_POINTER (platform)) == 0) ++ { ++ platform_ok = true; ++ break; ++ } ++ if (!platform_ok) ++ { ++ error_at (input_location, ++ "platform %qE is not recognised for the % " ++ "attribute", platform); ++ return NULL_TREE; ++ } ++ else if (plat_num > 1) /* We only compile for macos so far. */ ++ return NULL_TREE; ++ ++ /* We might be dealing with an object or type. */ ++ tree target_decl = NULL_TREE; ++ tree type = NULL_TREE; ++ bool warn = false; ++ if (DECL_P (*node)) ++ { ++ type = TREE_TYPE (decl); ++ ++ if (TREE_CODE (decl) == TYPE_DECL ++ || TREE_CODE (decl) == PARM_DECL ++ || VAR_OR_FUNCTION_DECL_P (decl) ++ || TREE_CODE (decl) == FIELD_DECL ++ || TREE_CODE (decl) == CONST_DECL ++ /*|| objc_method_decl (TREE_CODE (decl))*/) ++ target_decl = decl; ++ else ++ warn = true; ++ } ++ else if (TYPE_P (*node)) ++ type = target_decl = *node; ++ else ++ warn = true; ++ ++ tree what = NULL_TREE; ++ if (warn) ++ { ++ if (type && TYPE_NAME (type)) ++ { ++ if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) ++ what = TYPE_NAME (*node); ++ else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL ++ && DECL_NAME (TYPE_NAME (type))) ++ what = DECL_NAME (TYPE_NAME (type)); ++ } ++ if (what) ++ warning (OPT_Wattributes, "%qE attribute ignored for %qE", name, what); ++ else ++ warning (OPT_Wattributes, "%qE attribute ignored", name); ++ return NULL_TREE; ++ } ++ ++ /* Now we have to parse the availability clauses. */ ++ tree msg = NULL_TREE; ++ tree replacement = NULL_TREE; ++ bool unavailable = false; ++ unsigned introduced = 1000; ++ unsigned deprecated = current_os_version + 1; ++ unsigned obsoleted = current_os_version + 1; ++ for (tree arg = TREE_CHAIN (args); arg; arg = TREE_CHAIN (arg)) ++ { ++ tree clause_name = TREE_VALUE (arg); ++ tree clause_value = TREE_PURPOSE (arg); ++ if (clause_name == error_mark_node ++ || clause_value == error_mark_node) ++ continue; ++ unsigned clause_num = 0; ++ for (; clause_num < (unsigned) NUM_AV_CLAUSES; clause_num++) ++ if (strcmp (availability_clause[clause_num], ++ IDENTIFIER_POINTER (clause_name)) == 0) ++ break; ++ switch (clause_num) ++ { ++ default: ++ error_at (input_location, ++ "clause %qE is not recognised for the % " ++ "attribute", clause_name); ++ break; ++ case 0: ++ unavailable = true; ++ break; ++ case 1: ++ case 2: ++ case 3: ++ if (!clause_value) ++ error_at (input_location, "%<%E=%> requires a value", clause_name); ++ else ++ { ++ unsigned version = os_version_from_avail_value (clause_value); ++ if (version == 0) ++ error_at (input_location, "the value %qE provided to %qE is " ++ "not a valid OS version", clause_value, clause_name); ++ else if (clause_num == 1) ++ introduced = version; ++ else if (clause_num == 2) ++ deprecated = version; ++ else if (clause_num == 3) ++ obsoleted = version; ++ } ++ break; ++ case 4: ++ case 5: ++ if (!clause_value || TREE_CODE (clause_value) != STRING_CST) ++ error_at (input_location, "%<%E=%> requires a string", clause_name); ++ else if (clause_num == 4) ++ msg = clause_value; ++ else ++ replacement = clause_value; ++ break; ++ } ++ } ++ /* Now figure out what to do. */ ++ tree maybe_text = NULL_TREE; ++ if (replacement) ++ maybe_text = tree_cons (NULL_TREE, replacement, NULL_TREE); ++ else if (msg) ++ maybe_text = tree_cons (NULL_TREE, msg, NULL_TREE); ++ ++ if (unavailable || current_os_version >= obsoleted) ++ { ++ TREE_UNAVAILABLE (*node) = true; ++ /* We do not handle the availability attribute at diagnostics-time, so ++ if we want the informational messages, then attach them to additional ++ attributes for the deprecation or unavailability. TODO; maybe we can ++ fabricate the composite here. */ ++ if (maybe_text) ++ { ++ *no_add_attrs = false; ++ tree new_attr = tree_cons (get_identifier ("unavailable"), ++ maybe_text, NULL_TREE); ++ /* This is the actual consequence of the evaluation. */ ++ if (TYPE_P (target_decl) && !(flags & (int) ATTR_FLAG_TYPE_IN_PLACE)) ++ { ++ *node = build_variant_type_copy (*node); ++ TYPE_ATTRIBUTES (*node) = chainon (TYPE_ATTRIBUTES (*node), ++ new_attr); ++ } ++ else ++ DECL_ATTRIBUTES (*node) = chainon (DECL_ATTRIBUTES (*node), ++ new_attr); ++ } ++ } ++ else if (current_os_version > deprecated) ++ { ++ TREE_DEPRECATED (*node) = true; ++ if (maybe_text) ++ { ++ *no_add_attrs = false; ++ tree new_attr = tree_cons (get_identifier ("deprecated"), ++ maybe_text, NULL_TREE); ++ /* This is the actual consequence of the evaluation. */ ++ if (TYPE_P (target_decl) && !(flags & (int) ATTR_FLAG_TYPE_IN_PLACE)) ++ { ++ *node = build_variant_type_copy (*node); ++ TYPE_ATTRIBUTES (*node) = chainon (TYPE_ATTRIBUTES (*node), ++ new_attr); ++ } ++ else ++ DECL_ATTRIBUTES (*node) = chainon (DECL_ATTRIBUTES (*node), ++ new_attr); ++ } ++ } ++ else if (current_os_version < introduced) ++ *no_add_attrs = false; ++ return NULL_TREE; ++} ++ ++bool ++darwin_attribute_takes_identifier_p (const_tree attr_id) ++{ ++ return is_attribute_p ("availability", attr_id); ++} ++ + /* Emit a label for an FDE, making it global and/or weak if appropriate. + The third parameter is nonzero if this is for exception handling. + The fourth parameter is nonzero if this is just a placeholder for an +@@ -2267,6 +2613,8 @@ darwin_emit_except_table_label (FILE *file) + rtx + darwin_make_eh_symbol_indirect (rtx orig, bool ARG_UNUSED (pubvis)) + { ++ if (DARWIN_ARM64) ++ return orig; + if (DARWIN_PPC == 0 && TARGET_64BIT) + return orig; + +@@ -3115,7 +3463,12 @@ darwin_file_end (void) + fprintf (asm_out_file, "\t.long\t0\n\t.long\t%u\n", flags); + } + ++#if !DARWIN_ARM64 + machopic_finish (asm_out_file); ++#else ++ gcc_checking_assert (!machopic_indirections); ++#endif ++ + if (flag_apple_kext) + { + /* These sections are only used for kernel code. */ +@@ -3291,6 +3644,13 @@ darwin_kextabi_p (void) { + return flag_apple_kext; + } + ++/* True, iff we want to map __builtin_unreachable to a trap. */ ++ ++bool ++darwin_unreachable_traps_p (void) { ++ return darwin_unreachable_traps; ++} ++ + void + darwin_override_options (void) + { +@@ -3311,7 +3671,14 @@ darwin_override_options (void) + generating_for_darwin_version = 8; + + /* Earlier versions are not specifically accounted, until required. */ ++ unsigned vers[3] = {0,0,0}; ++ if (!parse_version (vers, darwin_macosx_version_min)) ++ error_at (UNKNOWN_LOCATION, "how did we get a bad OS version? (%s)", ++ darwin_macosx_version_min); ++ current_os_version = version_from_version_array (vers); + } ++ else ++ current_os_version = 1058; + + /* Some codegen needs to account for the capabilities of the target + linker. */ +diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h +index 6b124601274..8149af6fc5d 100644 +--- a/gcc/config/darwin.h ++++ b/gcc/config/darwin.h +@@ -1,4 +1,4 @@ +-/* Target definitions for Darwin (Mac OS X) systems. ++/* Target definitions for Darwin (macOS) systems. + Copyright (C) 1989-2022 Free Software Foundation, Inc. + Contributed by Apple Computer Inc. + +@@ -27,7 +27,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + #define CONFIG_DARWIN_H + + /* The definitions in this file are common to all processor types +- running Darwin, which is the kernel for Mac OS X. Darwin is ++ running Darwin, which is the kernel for macOS. Darwin is + basically a BSD user layer laid over a Mach kernel, then evolved + for many years (at NeXT) in parallel with other Unix systems. So + while the runtime is a somewhat idiosyncratic Mach-based thing, +@@ -42,6 +42,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + + #define DARWIN_X86 0 + #define DARWIN_PPC 0 ++#define DARWIN_ARM64 0 + + #define OBJECT_FORMAT_MACHO 1 + +@@ -271,6 +272,12 @@ extern GTY(()) int darwin_ms_struct; + "% 10.11 mmacosx-version-min= -lgcc_s.1.1)" ++# define DARWIN_SHARED_WEAK_ADDS \ ++"%{%:version-compare(>= 10.11 mmacosx-version-min= -lemutls_w): \ ++ " DARWIN_HEAP_T_LIB "}" ++#endif ++ ++ ++/* We might elect to add a path even when this compiler does not use embedded ++ run paths, so that we can use libraries from an alternate compiler that is ++ using embedded runpaths. */ ++#if DARWIN_DO_EXTRA_RPATH ++# define DARWIN_EXTRA_RPATH \ ++"%{!r:%{!nostdlib:%{!nodefaultrpaths:\ ++ %:version-compare(>= 10.5 mmacosx-version-min= -rpath) \ ++ %:version-compare(>= 10.5 mmacosx-version-min= " DARWIN_ADD_RPATH ") \ ++ }}}" ++#else ++# define DARWIN_EXTRA_RPATH "" ++#endif ++ + #define SUBSUBTARGET_OVERRIDE_OPTIONS \ + do { \ + darwin_override_options (); \ +@@ -337,7 +373,8 @@ extern GTY(()) int darwin_ms_struct; + */ + + #define DARWIN_NOCOMPACT_UNWIND \ +-" %:version-compare(>= 10.6 mmacosx-version-min= -no_compact_unwind) " ++"%{!fuse-ld=lld: \ ++ %:version-compare(>= 10.6 mmacosx-version-min= -no_compact_unwind)}" + + /* In Darwin linker specs we can put -lcrt0.o and ld will search the library + path for crt0.o or -lcrtx.a and it will search for libcrtx.a. As for +@@ -357,10 +394,12 @@ extern GTY(()) int darwin_ms_struct; + #define LINK_COMMAND_SPEC_A \ + "%{!c:%{!E:%{!S:%{!M:%{!MM:%{!fsyntax-only:%{!fdump=*: \ + %(linker)" \ ++ DARWIN_LD_DEMANGLE \ + LINK_PLUGIN_SPEC \ + "%{flto*:% 10.6 mmacosx-version-min= -lgcc_eh); \ + shared-libgcc|fexceptions|fobjc-exceptions|fgnu-runtime: \ +- %:version-compare(!> 10.11 mmacosx-version-min= -lgcc_s.1.1) \ ++ " DARWIN_SHARED_LIBGCC " \ + %:version-compare(!> 10.3.9 mmacosx-version-min= -lgcc_eh) \ + %:version-compare(>< 10.3.9 10.5 mmacosx-version-min= -lgcc_s.10.4) \ + %:version-compare(>< 10.5 10.6 mmacosx-version-min= -lgcc_s.10.5) \ +@@ -527,10 +568,11 @@ extern GTY(()) int darwin_ms_struct; + + #define DARWIN_WEAK_CRTS \ + "%{static-libgcc|static: \ +- %:version-compare(>= 10.6 mmacosx-version-min= -lemutls_w) ; \ +- shared-libgcc|fexceptions|fobjc-exceptions|fgnu-runtime: \ +- %:version-compare(>= 10.11 mmacosx-version-min= -lemutls_w) ; \ +- : -lemutls_w \ ++ %{%:version-compare(>= 10.6 mmacosx-version-min= -lemutls_w): \ ++ " DARWIN_HEAP_T_LIB "} ; \ ++ shared-libgcc|fexceptions|fobjc-exceptions|fgnu-runtime: " \ ++ DARWIN_SHARED_WEAK_ADDS " ; \ ++ : -lemutls_w " DARWIN_HEAP_T_LIB " \ + }" + + /* We specify crt0.o as -lcrt0.o so that ld will search the library path. */ +@@ -561,7 +603,8 @@ extern GTY(()) int darwin_ms_struct; + { "darwin_crt2", DARWIN_CRT2_SPEC }, \ + { "darwin_crt3", DARWIN_CRT3_SPEC }, \ + { "darwin_dylib1", DARWIN_DYLIB1_SPEC }, \ +- { "darwin_bundle1", DARWIN_BUNDLE1_SPEC }, ++ { "darwin_bundle1", DARWIN_BUNDLE1_SPEC }, \ ++ { "darwin_rpaths", DARWIN_RPATH_SPEC }, + + #define DARWIN_CRT1_SPEC \ + "%:version-compare(!> 10.5 mmacosx-version-min= -lcrt1.o) \ +@@ -587,6 +630,16 @@ extern GTY(()) int darwin_ms_struct; + "%{!static:%:version-compare(< 10.6 mmacosx-version-min= -lbundle1.o) \ + %{fgnu-tm: -lcrttms.o}}" + ++#if DARWIN_AT_RPATH ++/* A default rpath, that picks up dependent libraries installed in the same ++ director as one being loaded. */ ++#define DARWIN_RPATH_SPEC \ ++ "%:version-compare(>= 10.5 mmacosx-version-min= -rpath) \ ++ %{%:version-compare(>= 10.5 mmacosx-version-min= @loader_path): %P }" ++#else ++#define DARWIN_RPATH_SPEC "" ++#endif ++ + #ifdef HAVE_AS_MMACOSX_VERSION_MIN_OPTION + /* Emit macosx version (but only major). */ + #define ASM_MMACOSX_VERSION_MIN_SPEC \ +@@ -957,7 +1010,12 @@ extern GTY(()) section * darwin_sections[NUM_DARWIN_SECTIONS]; + { "apple_kext_compatibility", 0, 0, false, true, false, false, \ + darwin_handle_kext_attribute, NULL }, \ + { "weak_import", 0, 0, true, false, false, false, \ +- darwin_handle_weak_import_attribute, NULL } ++ darwin_handle_weak_import_attribute, NULL }, \ ++ { "availability", 0, -1, true, false, false, false, \ ++ darwin_handle_availability_attribute, NULL } ++ ++#undef TARGET_ATTRIBUTE_TAKES_IDENTIFIER_P ++#define TARGET_ATTRIBUTE_TAKES_IDENTIFIER_P darwin_attribute_takes_identifier_p + + /* Make local constant labels linker-visible, so that if one follows a + weak_global constant, ld64 will be able to separate the atoms. */ +@@ -1205,6 +1263,10 @@ void add_framework_path (char *); + #define TARGET_N_FORMAT_TYPES 1 + #define TARGET_FORMAT_TYPES darwin_additional_format_types + ++/* We want __builtin_unreachable to be expanded as a trap instruction. */ ++#undef TARGET_UNREACHABLE_SHOULD_TRAP ++#define TARGET_UNREACHABLE_SHOULD_TRAP darwin_unreachable_traps_p ++ + #ifndef USED_FOR_TARGET + extern void darwin_driver_init (unsigned int *,struct cl_decoded_option **); + #define GCC_DRIVER_HOST_INITIALIZATION \ +diff --git a/gcc/config/darwin.opt b/gcc/config/darwin.opt +index 51fe410cb72..80a753e2d38 100644 +--- a/gcc/config/darwin.opt ++++ b/gcc/config/darwin.opt +@@ -91,6 +91,10 @@ mtarget-linker + Target RejectNegative Joined Separate Var(darwin_target_linker) Init(LD64_VERSION) + -mtarget-linker Specify that ld64 is the toolchain linker for the current invocation. + ++munreachable-traps ++Target Var(darwin_unreachable_traps) Init(1) ++When set (the default) this makes __builtin_unreachable render as a trap. ++ + ; Driver options. + + all_load +@@ -241,6 +245,10 @@ nodefaultexport + Driver RejectNegative + Do not add a default symbol exports to modules or dynamic libraries. + ++nodefaultrpaths ++Driver RejectNegative ++Do not add default run paths (for the compiler library directories) to executables, modules or dynamic libraries. ++ + nofixprebinding + Driver RejectNegative + (Obsolete after 10.3.9) Set MH_NOPREFIXBINDING, in an executable. +diff --git a/gcc/config/i386/darwin.h b/gcc/config/i386/darwin.h +index 12cdc34a19e..e5d6797fe8a 100644 +--- a/gcc/config/i386/darwin.h ++++ b/gcc/config/i386/darwin.h +@@ -121,6 +121,9 @@ along with GCC; see the file COPYING3. If not see + #define DARWIN_SUBARCH_SPEC DARWIN_ARCH_SPEC + #endif + ++#undef DARWIN_HEAP_T_LIB ++#define DARWIN_HEAP_T_LIB " -lheapt_w " ++ + #undef SUBTARGET_EXTRA_SPECS + #define SUBTARGET_EXTRA_SPECS \ + DARWIN_EXTRA_SPECS \ +@@ -308,3 +311,9 @@ along with GCC; see the file COPYING3. If not see + #define CLEAR_INSN_CACHE(beg, end) \ + extern void sys_icache_invalidate(void *start, size_t len); \ + sys_icache_invalidate ((beg), (size_t)((end)-(beg))) ++ ++/* Disable custom function descriptors for Darwin when we have off-stack ++ trampolines. */ ++#undef X86_CUSTOM_FUNCTION_TEST ++#define X86_CUSTOM_FUNCTION_TEST \ ++ (flag_trampolines && flag_trampoline_impl == TRAMPOLINE_IMPL_HEAP) ? 0 : 1 +diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc +index af42e4b9739..872e5203aba 100644 +--- a/gcc/config/i386/i386.cc ++++ b/gcc/config/i386/i386.cc +@@ -24792,7 +24792,7 @@ ix86_libgcc_floating_mode_supported_p + #define TARGET_HARD_REGNO_SCRATCH_OK ix86_hard_regno_scratch_ok + + #undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS +-#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 1 ++#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS X86_CUSTOM_FUNCTION_TEST + + #undef TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID + #define TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID ix86_addr_space_zero_address_valid +diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h +index 5cea7157a1c..30a6a1cefe2 100644 +--- a/gcc/config/i386/i386.h ++++ b/gcc/config/i386/i386.h +@@ -749,6 +749,12 @@ extern const char *host_detect_local_cpu (int argc, const char **argv); + /* Minimum allocation boundary for the code of a function. */ + #define FUNCTION_BOUNDARY 8 + ++/* We will and with this value to test if a custom function descriptor needs ++ a static chain. The function boundary must the adjusted so that the bit ++ this represents is no longer part of the address. 0 Disables the custom ++ function descriptors. */ ++#define X86_CUSTOM_FUNCTION_TEST 1 ++ + /* C++ stores the virtual bit in the lowest bit of function pointers. */ + #define TARGET_PTRMEMFUNC_VBIT_LOCATION ptrmemfunc_vbit_in_pfn + +diff --git a/gcc/config/rs6000/darwin.h b/gcc/config/rs6000/darwin.h +index 626b40dab29..aabcbd61e2e 100644 +--- a/gcc/config/rs6000/darwin.h ++++ b/gcc/config/rs6000/darwin.h +@@ -113,6 +113,9 @@ + -lSystem \ + }" + ++#undef DARWIN_HEAP_T_LIB ++#define DARWIN_HEAP_T_LIB " " ++ + /* We want -fPIC by default, unless we're using -static to compile for + the kernel or some such. The "-faltivec" option should have been + called "-maltivec" all along. */ +diff --git a/gcc/configure b/gcc/configure +index f697874f2d8..508c4e01ca6 100755 +--- a/gcc/configure ++++ b/gcc/configure +@@ -632,10 +632,10 @@ ac_includes_default="\ + ac_subst_vars='LTLIBOBJS + LIBOBJS + CET_HOST_FLAGS +-NO_PIE_FLAG +-NO_PIE_CFLAGS +-enable_default_pie ++LD_PICFLAG + PICFLAG ++enable_default_pie ++enable_host_pie + enable_host_shared + enable_plugin + pluginlibs +@@ -735,11 +735,15 @@ ORIGINAL_NM_FOR_TARGET + gcc_cv_nm + ORIGINAL_LD_GOLD_FOR_TARGET + ORIGINAL_LD_BFD_FOR_TARGET ++ORIGINAL_CLASSIC_LD_FOR_TARGET ++ORIGINAL_LLD_FOR_TARGET + ORIGINAL_LD_FOR_TARGET + ORIGINAL_PLUGIN_LD_FOR_TARGET + gcc_cv_ld + ORIGINAL_AS_FOR_TARGET + gcc_cv_as ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + enable_fast_install + objdir + OTOOL64 +@@ -1000,6 +1004,8 @@ enable_static + with_pic + enable_fast_install + enable_libtool_lock ++enable_darwin_at_rpath ++with_darwin_extra_rpath + enable_ld + enable_gold + with_plugin_ld +@@ -1025,6 +1031,7 @@ enable_link_serialization + enable_version_specific_runtime_libs + enable_plugin + enable_host_shared ++enable_host_pie + enable_libquadmath_support + with_linker_hash_style + with_diagnostics_color +@@ -1733,6 +1740,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --enable-ld[=ARG] build ld [ARG={default,yes,no}] + --enable-gold[=ARG] build gold [ARG={default,yes,no}] + --enable-gnu-indirect-function +@@ -1787,6 +1797,7 @@ Optional Features: + in a compiler-specific directory + --enable-plugin enable plugin support + --enable-host-shared build host code as shared libraries ++ --enable-host-pie build host code as PIE + --disable-libquadmath-support + disable libquadmath support for Fortran + --enable-default-pie enable Position Independent Executable as default +@@ -1850,6 +1861,9 @@ Optional Packages: + --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] ++ --with-darwin-extra-rpath=[ARG] ++ Specify a runpath directory, additional to those ++ provided by the compiler + --with-plugin-ld=[ARG] specify the plugin linker + --with-glibc-version=M.N + assume GCC used with glibc version M.N or later +@@ -3748,20 +3762,19 @@ gcc_gxx_libcxx_include_dir= + + # Check whether --with-gxx-libcxx-include-dir was given. + if test "${with_gxx_libcxx_include_dir+set}" = set; then : +- withval=$with_gxx_libcxx_include_dir; case "${withval}" in +-yes) as_fn_error $? "bad value ${withval} given for libc++ include directory" "$LINENO" 5 ;; +-*) gcc_gxx_libcxx_include_dir=$with_gxx_libcxx_include_dir ;; +-esac ++ withval=$with_gxx_libcxx_include_dir; gcc_gxx_libcxx_include_dir=$with_gxx_libcxx_include_dir + fi + + + # --with-gxx-libcxx-include-dir controls the enabling of the -stdlib option. + # if --with-gxx-libcxx-include-dir is 'no' we disable the stdlib option. ++# if --with-gxx-libcxx-include-dir is 'yes' we enable the stdlib option and use ++# the default path within the installation. + # if --with-gxx-libcxx-include-dir is unset we enable the stdlib option +-# based on the platform (to be available on platform versions where it is the ++# based on the platform (to be available on platform versions where it is the + # default for the system tools). We also use a default path within the compiler +-# install tree. +-# Otherwise, we use the path provided and enable the stdlib option. ++# install tree. ++# Otherwise, we use the path provided and enable the stdlib option. + # If both --with-sysroot and --with-gxx-libcxx-include-dir are passed, we + # check to see if the latter starts with the former and, upon success, compute + # gcc_gxx_libcxx_include_dir as relative to the sysroot. +@@ -3769,16 +3782,20 @@ gcc_gxx_libcxx_include_dir_add_sysroot=0 + gcc_enable_stdlib_opt=0 + if test x${gcc_gxx_libcxx_include_dir} != x; then + if test x${gcc_gxx_libcxx_include_dir} = xno; then +- # set defaults for the dir, but the option is disabled anyway. ++ # set defaults for the dir, but the option is disabled anyway. + gcc_gxx_libcxx_include_dir= ++ elif test x${gcc_gxx_libcxx_include_dir} = xyes; then ++ # set defaults for the dir, and enable. ++ gcc_gxx_libcxx_include_dir= ++ gcc_enable_stdlib_opt=1 + else + gcc_enable_stdlib_opt=1 + fi + else + case $target in + *-darwin1[1-9]* | *-darwin2*) +- # Default this on for Darwin versions which default to libcxx, +- # and embed the path in the compiler install so that we get a ++ # Default this on for Darwin versions which default to libcxx, ++ # and embed the path in the compiler install so that we get a + # self-contained toolchain. + gcc_enable_stdlib_opt=1 + ;; +@@ -16180,7 +16197,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -17885,6 +17902,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -17902,9 +17962,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -19691,7 +19755,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 19694 "configure" ++#line 19758 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -19797,7 +19861,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 19800 "configure" ++#line 19864 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -20673,6 +20737,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc_CXX=no + hardcode_direct_CXX=no + hardcode_automatic_CXX=yes +@@ -20690,12 +20797,20 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + if test "$lt_cv_apple_cc_single_mod" != "yes"; then +- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring${_lt_dsymutil}" + archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" + fi + +@@ -23046,6 +23161,35 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ ++DARWIN_DO_EXTRA_RPATH=0 ++ ++# Check whether --with-darwin-extra-rpath was given. ++if test "${with_darwin_extra_rpath+set}" = set; then : ++ withval=$with_darwin_extra_rpath; if test x"$withval" != x; then ++ DARWIN_ADD_RPATH="$withval" ++ DARWIN_DO_EXTRA_RPATH=1 ++ fi ++fi ++ ++ ++cat >>confdefs.h <<_ACEOF ++#define DARWIN_DO_EXTRA_RPATH $DARWIN_DO_EXTRA_RPATH ++_ACEOF ++ ++ ++cat >>confdefs.h <<_ACEOF ++#define DARWIN_ADD_RPATH "$DARWIN_ADD_RPATH" ++_ACEOF ++ ++ + # Identify the assembler which will work hand-in-glove with the newly + # built GCC, so that we can examine its features. This is the assembler + # which will be driven by the driver program. +@@ -23322,6 +23466,14 @@ fi + $as_echo "$gold_non_default" >&6; } + + ORIGINAL_LD_FOR_TARGET=$gcc_cv_ld ++if test x"$ld64_flag" = x"yes"; then ++ORIGINAL_LLD_FOR_TARGET=${gcc_cv_ld}64.lld ++else ++ORIGINAL_LLD_FOR_TARGET=$gcc_cv_lld ++fi ++ORIGINAL_CLASSIC_LD_FOR_TARGET=$gcc_cv_ld-classic ++ ++ + + case "$ORIGINAL_LD_FOR_TARGET" in + ./collect-ld | ./collect-ld$build_exeext) ;; +@@ -30851,6 +31003,7 @@ if test x"$ld64_flag" = x"yes"; then + # Set defaults for possibly untestable items. + gcc_cv_ld64_export_dynamic=0 + gcc_cv_ld64_platform_version=0 ++ gcc_cv_ld64_demangle=0 + + if test "$build" = "$host"; then + darwin_try_test=1 +@@ -30874,6 +31027,9 @@ $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 97; then ++ gcc_cv_ld64_demangle=1 ++ fi + if test "$gcc_cv_ld64_major" -ge 236; then + gcc_cv_ld64_export_dynamic=1 + fi +@@ -30891,6 +31047,15 @@ $as_echo_n "checking linker version... " >&6; } + { $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 -demangle support" >&5 ++$as_echo_n "checking linker for -demangle support... " >&6; } ++ gcc_cv_ld64_demangle=1 ++ if $gcc_cv_ld -demangle < /dev/null 2>&1 | grep 'unknown option' > /dev/null; then ++ gcc_cv_ld64_demangle=0 ++ fi ++ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_ld64_demangle" >&5 ++$as_echo "$gcc_cv_ld64_demangle" >&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 +@@ -30919,6 +31084,12 @@ _ACEOF + fi + + ++cat >>confdefs.h <<_ACEOF ++#define LD64_HAS_DEMANGLE $gcc_cv_ld64_demangle ++_ACEOF ++ ++ ++ + cat >>confdefs.h <<_ACEOF + #define LD64_HAS_EXPORT_DYNAMIC $gcc_cv_ld64_export_dynamic + _ACEOF +@@ -32452,13 +32623,17 @@ fi + # Enable --enable-host-shared + # Check whether --enable-host-shared was given. + if test "${enable_host_shared+set}" = set; then : +- enableval=$enable_host_shared; PICFLAG=-fPIC +-else +- PICFLAG= ++ enableval=$enable_host_shared; + fi + + + ++# Enable --enable-host-pie ++# Check whether --enable-host-pie was given. ++if test "${enable_host_pie+set}" = set; then : ++ enableval=$enable_host_pie; ++fi ++ + + + # Check whether --enable-libquadmath-support was given. +@@ -32612,10 +32787,6 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_c_no_fpie" >&5 + $as_echo "$gcc_cv_c_no_fpie" >&6; } +-if test "$gcc_cv_c_no_fpie" = "yes"; then +- NO_PIE_CFLAGS="-fno-PIE" +-fi +- + + # Check if -no-pie works. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -no-pie option" >&5 +@@ -32640,11 +32811,28 @@ rm -f core conftest.err conftest.$ac_objext \ + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_no_pie" >&5 + $as_echo "$gcc_cv_no_pie" >&6; } +-if test "$gcc_cv_no_pie" = "yes"; then +- NO_PIE_FLAG="-no-pie" ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE ++elif test x$gcc_cv_c_no_fpie = xyes; then ++ PICFLAG=-fno-PIE ++else ++ PICFLAG= ++fi ++ ++if test x$enable_host_pie = xyes; then ++ LD_PICFLAG=-pie ++elif test x$gcc_cv_no_pie = xyes; then ++ LD_PICFLAG=-no-pie ++else ++ LD_PICFLAG= + fi + + ++ ++ + # Enable Intel CET on Intel CET enabled host if jit is enabled. + # Check whether --enable-cet was given. + if test "${enable_cet+set}" = set; then : +@@ -33127,6 +33315,10 @@ LTLIBOBJS=$ac_ltlibobjs + + + ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + + : "${CONFIG_STATUS=./config.status}" + ac_write_fail=0 +diff --git a/gcc/configure.ac b/gcc/configure.ac +index fec897c2c08..d7d07c76719 100644 +--- a/gcc/configure.ac ++++ b/gcc/configure.ac +@@ -234,18 +234,17 @@ gcc_gxx_libcxx_include_dir= + AC_ARG_WITH(gxx-libcxx-include-dir, + [AS_HELP_STRING([--with-gxx-libcxx-include-dir=DIR], + [specifies directory to find libc++ header files])], +-[case "${withval}" in +-yes) AC_MSG_ERROR(bad value ${withval} given for libc++ include directory) ;; +-*) gcc_gxx_libcxx_include_dir=$with_gxx_libcxx_include_dir ;; +-esac]) ++[gcc_gxx_libcxx_include_dir=$with_gxx_libcxx_include_dir]) + + # --with-gxx-libcxx-include-dir controls the enabling of the -stdlib option. + # if --with-gxx-libcxx-include-dir is 'no' we disable the stdlib option. ++# if --with-gxx-libcxx-include-dir is 'yes' we enable the stdlib option and use ++# the default path within the installation. + # if --with-gxx-libcxx-include-dir is unset we enable the stdlib option +-# based on the platform (to be available on platform versions where it is the ++# based on the platform (to be available on platform versions where it is the + # default for the system tools). We also use a default path within the compiler +-# install tree. +-# Otherwise, we use the path provided and enable the stdlib option. ++# install tree. ++# Otherwise, we use the path provided and enable the stdlib option. + # If both --with-sysroot and --with-gxx-libcxx-include-dir are passed, we + # check to see if the latter starts with the former and, upon success, compute + # gcc_gxx_libcxx_include_dir as relative to the sysroot. +@@ -253,16 +252,20 @@ gcc_gxx_libcxx_include_dir_add_sysroot=0 + gcc_enable_stdlib_opt=0 + if test x${gcc_gxx_libcxx_include_dir} != x; then + if test x${gcc_gxx_libcxx_include_dir} = xno; then +- # set defaults for the dir, but the option is disabled anyway. ++ # set defaults for the dir, but the option is disabled anyway. ++ gcc_gxx_libcxx_include_dir= ++ elif test x${gcc_gxx_libcxx_include_dir} = xyes; then ++ # set defaults for the dir, and enable. + gcc_gxx_libcxx_include_dir= ++ gcc_enable_stdlib_opt=1 + else + gcc_enable_stdlib_opt=1 + fi + else + case $target in + *-darwin1[[1-9]]* | *-darwin2*) +- # Default this on for Darwin versions which default to libcxx, +- # and embed the path in the compiler install so that we get a ++ # Default this on for Darwin versions which default to libcxx, ++ # and embed the path in the compiler install so that we get a + # self-contained toolchain. + gcc_enable_stdlib_opt=1 + ;; +@@ -2576,6 +2579,21 @@ AC_PROG_LIBTOOL + AC_SUBST(objdir) + AC_SUBST(enable_fast_install) + ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) ++DARWIN_DO_EXTRA_RPATH=0 ++AC_ARG_WITH(darwin-extra-rpath, ++[AS_HELP_STRING( ++ [[--with-darwin-extra-rpath=[ARG]]], ++ [Specify a runpath directory, additional to those provided by the compiler])], ++[if test x"$withval" != x; then ++ DARWIN_ADD_RPATH="$withval" ++ DARWIN_DO_EXTRA_RPATH=1 ++ fi]) ++AC_DEFINE_UNQUOTED(DARWIN_DO_EXTRA_RPATH, $DARWIN_DO_EXTRA_RPATH, ++ [Should add an extra runpath directory]) ++AC_DEFINE_UNQUOTED(DARWIN_ADD_RPATH, "$DARWIN_ADD_RPATH", ++ [Specify a runpath directory, additional to those provided by the compiler]) ++ + # Identify the assembler which will work hand-in-glove with the newly + # built GCC, so that we can examine its features. This is the assembler + # which will be driven by the driver program. +@@ -2748,7 +2766,15 @@ fi + AC_MSG_RESULT($gold_non_default) + + ORIGINAL_LD_FOR_TARGET=$gcc_cv_ld ++if test x"$ld64_flag" = x"yes"; then ++ORIGINAL_LLD_FOR_TARGET=${gcc_cv_ld}64.lld ++else ++ORIGINAL_LLD_FOR_TARGET=$gcc_cv_lld ++fi ++ORIGINAL_CLASSIC_LD_FOR_TARGET=$gcc_cv_ld-classic + AC_SUBST(ORIGINAL_LD_FOR_TARGET) ++AC_SUBST(ORIGINAL_LLD_FOR_TARGET) ++AC_SUBST(ORIGINAL_CLASSIC_LD_FOR_TARGET) + case "$ORIGINAL_LD_FOR_TARGET" in + ./collect-ld | ./collect-ld$build_exeext) ;; + *) AC_CONFIG_FILES(collect-ld:exec-tool.in, [chmod +x collect-ld]) ;; +@@ -4776,7 +4802,7 @@ foo: nop + gcc_cv_as_mllvm_x86_pad_for_align, + [-mllvm -x86-pad-for-align=false], [.text],, + [AC_DEFINE(HAVE_AS_MLLVM_X86_PAD_FOR_ALIGN, 1, +- [Define if your Mac OS X assembler supports -mllvm -x86-pad-for-align=false.])]) ++ [Define if your macOS assembler supports -mllvm -x86-pad-for-align=false.])]) + ;; + esac + +@@ -6383,6 +6409,7 @@ if test x"$ld64_flag" = x"yes"; then + # Set defaults for possibly untestable items. + gcc_cv_ld64_export_dynamic=0 + gcc_cv_ld64_platform_version=0 ++ gcc_cv_ld64_demangle=0 + + if test "$build" = "$host"; then + darwin_try_test=1 +@@ -6404,6 +6431,9 @@ if test x"$ld64_flag" = x"yes"; 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 97; then ++ gcc_cv_ld64_demangle=1 ++ fi + if test "$gcc_cv_ld64_major" -ge 236; then + gcc_cv_ld64_export_dynamic=1 + fi +@@ -6419,6 +6449,13 @@ if test x"$ld64_flag" = x"yes"; then + fi + AC_MSG_RESULT($gcc_cv_ld64_version) + ++ AC_MSG_CHECKING(linker for -demangle support) ++ gcc_cv_ld64_demangle=1 ++ if $gcc_cv_ld -demangle < /dev/null 2>&1 | grep 'unknown option' > /dev/null; then ++ gcc_cv_ld64_demangle=0 ++ fi ++ AC_MSG_RESULT($gcc_cv_ld64_demangle) ++ + 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 +@@ -6439,6 +6476,9 @@ if test x"$ld64_flag" = x"yes"; then + [Define to ld64 version.]) + fi + ++ AC_DEFINE_UNQUOTED(LD64_HAS_DEMANGLE, $gcc_cv_ld64_demangle, ++ [Define to 1 if ld64 supports '-demangle'.]) ++ + AC_DEFINE_UNQUOTED(LD64_HAS_EXPORT_DYNAMIC, $gcc_cv_ld64_export_dynamic, + [Define to 1 if ld64 supports '-export_dynamic'.]) + +@@ -7586,11 +7626,14 @@ fi + # Enable --enable-host-shared + AC_ARG_ENABLE(host-shared, + [AS_HELP_STRING([--enable-host-shared], +- [build host code as shared libraries])], +-[PICFLAG=-fPIC], [PICFLAG=]) ++ [build host code as shared libraries])]) + AC_SUBST(enable_host_shared) +-AC_SUBST(PICFLAG) + ++# Enable --enable-host-pie ++AC_ARG_ENABLE(host-pie, ++[AS_HELP_STRING([--enable-host-pie], ++ [build host code as PIE])]) ++AC_SUBST(enable_host_pie) + + AC_ARG_ENABLE(libquadmath-support, + [AS_HELP_STRING([--disable-libquadmath-support], +@@ -7712,10 +7755,6 @@ AC_CACHE_CHECK([for -fno-PIE option], + [gcc_cv_c_no_fpie=yes], + [gcc_cv_c_no_fpie=no]) + CXXFLAGS="$saved_CXXFLAGS"]) +-if test "$gcc_cv_c_no_fpie" = "yes"; then +- NO_PIE_CFLAGS="-fno-PIE" +-fi +-AC_SUBST([NO_PIE_CFLAGS]) + + # Check if -no-pie works. + AC_CACHE_CHECK([for -no-pie option], +@@ -7726,10 +7765,27 @@ AC_CACHE_CHECK([for -no-pie option], + [gcc_cv_no_pie=yes], + [gcc_cv_no_pie=no]) + LDFLAGS="$saved_LDFLAGS"]) +-if test "$gcc_cv_no_pie" = "yes"; then +- NO_PIE_FLAG="-no-pie" ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE ++elif test x$gcc_cv_c_no_fpie = xyes; then ++ PICFLAG=-fno-PIE ++else ++ PICFLAG= + fi +-AC_SUBST([NO_PIE_FLAG]) ++ ++if test x$enable_host_pie = xyes; then ++ LD_PICFLAG=-pie ++elif test x$gcc_cv_no_pie = xyes; then ++ LD_PICFLAG=-no-pie ++else ++ LD_PICFLAG= ++fi ++ ++AC_SUBST([PICFLAG]) ++AC_SUBST([LD_PICFLAG]) + + # Enable Intel CET on Intel CET enabled host if jit is enabled. + GCC_CET_HOST_FLAGS(CET_HOST_FLAGS) +diff --git a/gcc/coretypes.h b/gcc/coretypes.h +index 08b9ac9094c..9885d45ec91 100644 +--- a/gcc/coretypes.h ++++ b/gcc/coretypes.h +@@ -199,6 +199,12 @@ enum tls_model { + TLS_MODEL_LOCAL_EXEC + }; + ++/* Types of trampoline implementation. */ ++enum trampoline_impl { ++ TRAMPOLINE_IMPL_STACK, ++ TRAMPOLINE_IMPL_HEAP ++}; ++ + /* Types of ABI for an offload compiler. */ + enum offload_abi { + OFFLOAD_ABI_UNSET, +diff --git a/gcc/cp/cp-lang.cc b/gcc/cp/cp-lang.cc +index 7c8b94741fa..50a02b19f54 100644 +--- a/gcc/cp/cp-lang.cc ++++ b/gcc/cp/cp-lang.cc +@@ -118,6 +118,15 @@ objcp_tsubst_copy_and_build (tree /*t*/, + return NULL_TREE; + } + ++/* Implement c-family hook to add language-specific features ++ for __has_{feature,extension}. */ ++ ++void ++c_family_register_lang_features () ++{ ++ cp_register_features (); ++} ++ + static const char * + cxx_dwarf_name (tree t, int verbosity) + { +diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc +index f40fd588176..3557e15333c 100644 +--- a/gcc/cp/cp-objcp-common.cc ++++ b/gcc/cp/cp-objcp-common.cc +@@ -23,9 +23,152 @@ along with GCC; see the file COPYING3. If not see + #include "coretypes.h" + #include "cp-tree.h" + #include "cp-objcp-common.h" ++#include "c-family/c-common.h" + #include "dwarf2.h" + #include "stringpool.h" + ++/* Class to determine whether a given C++ language feature is available. ++ Used to implement __has_{feature,extension}. */ ++ ++struct cp_feature_selector ++{ ++ enum ++ { ++ DIALECT, ++ FLAG ++ } kind; ++ ++ enum class result ++ { ++ NONE, ++ EXT, ++ FEAT ++ }; ++ ++ union ++ { ++ const int *enable_flag; ++ struct { ++ enum cxx_dialect feat; ++ enum cxx_dialect ext; ++ } dialect; ++ }; ++ ++ constexpr cp_feature_selector (const int *flag) ++ : kind (FLAG), enable_flag (flag) {} ++ constexpr cp_feature_selector (enum cxx_dialect feat, ++ enum cxx_dialect ext) ++ : kind (DIALECT), dialect{feat, ext} {} ++ constexpr cp_feature_selector (enum cxx_dialect feat) ++ : cp_feature_selector (feat, feat) {} ++ ++ inline result has_feature () const; ++}; ++ ++/* Check whether this language feature is available as a feature, ++ extension, or not at all. */ ++ ++cp_feature_selector::result ++cp_feature_selector::has_feature () const ++{ ++ switch (kind) ++ { ++ case DIALECT: ++ if (cxx_dialect >= dialect.feat) ++ return result::FEAT; ++ else if (cxx_dialect >= dialect.ext) ++ return result::EXT; ++ else ++ return result::NONE; ++ case FLAG: ++ return *enable_flag ? result::FEAT : result::NONE; ++ } ++ ++ gcc_unreachable (); ++} ++ ++/* Information about a C++ language feature which can be queried ++ through __has_{feature,extension}. IDENT is the name of the feature, ++ and SELECTOR encodes how to compute whether the feature is available. */ ++ ++struct cp_feature_info ++{ ++ const char *ident; ++ cp_feature_selector selector; ++}; ++ ++/* Table of features for __has_{feature,extension}. */ ++ ++static constexpr cp_feature_info cp_feature_table[] = ++{ ++ { "cxx_exceptions", &flag_exceptions }, ++ { "cxx_rtti", &flag_rtti }, ++ { "cxx_access_control_sfinae", { cxx11, cxx98 } }, ++ { "cxx_alias_templates", cxx11 }, ++ { "cxx_alignas", cxx11 }, ++ { "cxx_alignof", cxx11 }, ++ { "cxx_attributes", cxx11 }, ++ { "cxx_constexpr", cxx11 }, ++ { "cxx_decltype", cxx11 }, ++ { "cxx_decltype_incomplete_return_types", cxx11 }, ++ { "cxx_default_function_template_args", cxx11 }, ++ { "cxx_defaulted_functions", cxx11 }, ++ { "cxx_delegating_constructors", cxx11 }, ++ { "cxx_deleted_functions", cxx11 }, ++ { "cxx_explicit_conversions", cxx11 }, ++ { "cxx_generalized_initializers", cxx11 }, ++ { "cxx_implicit_moves", cxx11 }, ++ { "cxx_inheriting_constructors", cxx11 }, ++ { "cxx_inline_namespaces", { cxx11, cxx98 } }, ++ { "cxx_lambdas", cxx11 }, ++ { "cxx_local_type_template_args", cxx11 }, ++ { "cxx_noexcept", cxx11 }, ++ { "cxx_nonstatic_member_init", cxx11 }, ++ { "cxx_nullptr", cxx11 }, ++ { "cxx_override_control", cxx11 }, ++ { "cxx_reference_qualified_functions", cxx11 }, ++ { "cxx_range_for", cxx11 }, ++ { "cxx_raw_string_literals", cxx11 }, ++ { "cxx_rvalue_references", cxx11 }, ++ { "cxx_static_assert", cxx11 }, ++ { "cxx_thread_local", cxx11 }, ++ { "cxx_auto_type", cxx11 }, ++ { "cxx_strong_enums", cxx11 }, ++ { "cxx_trailing_return", cxx11 }, ++ { "cxx_unicode_literals", cxx11 }, ++ { "cxx_unrestricted_unions", cxx11 }, ++ { "cxx_user_literals", cxx11 }, ++ { "cxx_variadic_templates", { cxx11, cxx98 } }, ++ { "cxx_binary_literals", { cxx14, cxx98 } }, ++ { "cxx_contextual_conversions", { cxx14, cxx98 } }, ++ { "cxx_decltype_auto", cxx14 }, ++ { "cxx_aggregate_nsdmi", cxx14 }, ++ { "cxx_init_captures", { cxx14, cxx11 } }, ++ { "cxx_generic_lambdas", cxx14 }, ++ { "cxx_relaxed_constexpr", cxx14 }, ++ { "cxx_return_type_deduction", cxx14 }, ++ { "cxx_variable_templates", cxx14 }, ++ { "modules", &flag_modules }, ++}; ++ ++/* Register C++ language features for __has_{feature,extension}. */ ++ ++void ++cp_register_features () ++{ ++ using result = cp_feature_selector::result; ++ ++ for (unsigned i = 0; i < ARRAY_SIZE (cp_feature_table); i++) ++ { ++ const cp_feature_info *info = cp_feature_table + i; ++ const auto res = info->selector.has_feature (); ++ if (res == result::NONE) ++ continue; ++ ++ c_common_register_feature (info->ident, res == result::FEAT); ++ } ++} ++ + /* Special routine to get the alias set for C++. */ + + alias_set_type +diff --git a/gcc/cp/cp-objcp-common.h b/gcc/cp/cp-objcp-common.h +index 3c04e5c0265..5a61c233303 100644 +--- a/gcc/cp/cp-objcp-common.h ++++ b/gcc/cp/cp-objcp-common.h +@@ -35,6 +35,7 @@ extern tree cp_classtype_as_base (const_tree); + extern tree cp_get_global_decls (); + extern tree cp_pushdecl (tree); + extern void cp_register_dumps (gcc::dump_manager *); ++extern void cp_register_features (); + extern bool cp_handle_option (size_t, const char *, HOST_WIDE_INT, int, + location_t, const struct cl_option_handlers *); + extern tree cxx_make_type_hook (tree_code); +diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc +index c5e5fbfba4a..6eb0a7b3613 100644 +--- a/gcc/cp/decl2.cc ++++ b/gcc/cp/decl2.cc +@@ -3674,9 +3674,8 @@ get_tls_init_fn (tree var) + if (!flag_extern_tls_init && DECL_EXTERNAL (var)) + return NULL_TREE; + +- /* If the variable is internal, or if we can't generate aliases, +- call the local init function directly. */ +- if (!TREE_PUBLIC (var) || !TARGET_SUPPORTS_ALIASES) ++ /* If the variable is internal call the local init function directly. */ ++ if (!TREE_PUBLIC (var)) + return get_local_tls_init_fn (DECL_SOURCE_LOCATION (var)); + + tree sname = mangle_tls_init_fn (var); +@@ -3839,6 +3838,25 @@ generate_tls_wrapper (tree fn) + expand_or_defer_fn (finish_function (/*inline_p=*/false)); + } + ++/* A dummy init function to act as a weak placeholder for a (possibly non- ++ existent) dynamic init. */ ++static void ++generate_tls_dummy_init (tree fn) ++{ ++ tree var = DECL_BEFRIENDING_CLASSES (fn); ++ tree init_fn = get_tls_init_fn (var); ++ /* If have no init fn, or it is non-weak, then we do not need to make a ++ dummy. */ ++ if (!init_fn || !lookup_attribute ("weak", DECL_ATTRIBUTES (init_fn))) ++ return; ++ start_preparsed_function (init_fn, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED); ++ tree body = begin_function_body (); ++ declare_weak (init_fn); ++ finish_return_stmt (NULL_TREE); ++ finish_function_body (body); ++ expand_or_defer_fn (finish_function (/*inline_p=*/false)); ++} ++ + /* Start the process of running a particular set of global constructors + or destructors. Subroutine of do_[cd]tors. Also called from + vtv_start_verification_constructor_init_function. */ +@@ -4822,22 +4840,24 @@ handle_tls_init (void) + finish_expr_stmt (cp_build_modify_expr (loc, guard, NOP_EXPR, + boolean_true_node, + tf_warning_or_error)); ++ auto_vec direct_calls; + for (; vars; vars = TREE_CHAIN (vars)) + { + tree var = TREE_VALUE (vars); + tree init = TREE_PURPOSE (vars); + one_static_initialization_or_destruction (var, init, true); + +- /* Output init aliases even with -fno-extern-tls-init. */ +- if (TARGET_SUPPORTS_ALIASES && TREE_PUBLIC (var)) ++ /* Output inits even with -fno-extern-tls-init. ++ We save the list here and output either an alias or a stub function ++ below. */ ++ if (TREE_PUBLIC (var)) + { +- tree single_init_fn = get_tls_init_fn (var); ++ tree single_init_fn = get_tls_init_fn (var); + if (single_init_fn == NULL_TREE) + continue; +- cgraph_node *alias +- = cgraph_node::get_create (fn)->create_same_body_alias +- (single_init_fn, fn); +- gcc_assert (alias != NULL); ++ if (single_init_fn == fn) ++ continue; ++ direct_calls.safe_push (single_init_fn); + } + } + +@@ -4845,6 +4865,30 @@ handle_tls_init (void) + finish_if_stmt (if_stmt); + finish_function_body (body); + expand_or_defer_fn (finish_function (/*inline_p=*/false)); ++ ++ /* For each TLS var that we have an init function, we either emit an alias ++ between that and the tls_init, or a stub function that just calls the ++ tls_init. */ ++ while (!direct_calls.is_empty()) ++ { ++ tree single_init_fn = direct_calls.pop (); ++ if (TARGET_SUPPORTS_ALIASES) ++ { ++ cgraph_node *alias ++ = cgraph_node::get_create (fn)->create_same_body_alias ++ (single_init_fn, fn); ++ gcc_assert (alias != NULL); ++ } ++ else ++ { ++ start_preparsed_function (single_init_fn, NULL_TREE, SF_PRE_PARSED); ++ tree body = begin_function_body (); ++ tree r = build_call_expr (fn, 0); ++ finish_expr_stmt (r); ++ finish_function_body (body); ++ expand_or_defer_fn (finish_function (/*inline_p=*/false)); ++ } ++ } + } + + /* We're at the end of compilation, so generate any mangling aliases that +@@ -5273,7 +5317,14 @@ c_parse_final_cleanups (void) + } + + if (!DECL_INITIAL (decl) && decl_tls_wrapper_p (decl)) +- generate_tls_wrapper (decl); ++ { ++ generate_tls_wrapper (decl); ++ /* The wrapper might have a weak reference to an init, we provide ++ a dummy function to satisfy that here. The linker/dynamic ++ loader will override this with the actual init, if one is ++ required. */ ++ generate_tls_dummy_init (decl); ++ } + + if (!DECL_SAVED_TREE (decl)) + continue; +diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc +index 9c1bd32cff1..1ccbcfd3aca 100644 +--- a/gcc/cp/parser.cc ++++ b/gcc/cp/parser.cc +@@ -629,6 +629,91 @@ cp_lexer_alloc (void) + return lexer; + } + ++/* Context-sensitive parse-checking for clang-style attributes. */ ++ ++enum clang_attr_state { ++ CA_NONE = 0, ++ CA_ATTR, ++ CA_BR1, CA_BR2, ++ CA_LIST, ++ CA_LIST_ARGS, ++ CA_IS_CA, ++ CA_CA_ARGS, ++ CA_LIST_CONT ++}; ++ ++/* State machine tracking context of attribute lexing. */ ++ ++static enum clang_attr_state ++cp_lexer_attribute_state (cp_token& token, enum clang_attr_state attr_state) ++{ ++ /* Implement a context-sensitive parser for clang attributes. ++ We detect __attribute__((clang_style_attribute (ARGS))) and lex the ++ args ARGS with the following differences from GNU attributes: ++ (a) number-like values are lexed as strings [this allows lexing XX.YY.ZZ ++ version numbers]. ++ (b) we concatenate strings, since clang attributes allow this too. */ ++ switch (attr_state) ++ { ++ case CA_NONE: ++ if (token.type == CPP_KEYWORD ++ && token.keyword == RID_ATTRIBUTE) ++ attr_state = CA_ATTR; ++ break; ++ case CA_ATTR: ++ if (token.type == CPP_OPEN_PAREN) ++ attr_state = CA_BR1; ++ else ++ attr_state = CA_NONE; ++ break; ++ case CA_BR1: ++ if (token.type == CPP_OPEN_PAREN) ++ attr_state = CA_BR2; ++ else ++ attr_state = CA_NONE; ++ break; ++ case CA_BR2: ++ if (token.type == CPP_NAME) ++ { ++ tree identifier = (token.type == CPP_KEYWORD) ++ /* For keywords, use the canonical spelling, not the ++ parsed identifier. */ ++ ? ridpointers[(int) token.keyword] ++ : token.u.value; ++ identifier = canonicalize_attr_name (identifier); ++ if (attribute_clang_form_p (identifier)) ++ attr_state = CA_IS_CA; ++ else ++ attr_state = CA_LIST; ++ } ++ else ++ attr_state = CA_NONE; ++ break; ++ case CA_IS_CA: ++ case CA_LIST: ++ if (token.type == CPP_COMMA) ++ attr_state = CA_BR2; /* Back to the list outer. */ ++ else if (token.type == CPP_OPEN_PAREN) ++ attr_state = attr_state == CA_IS_CA ? CA_CA_ARGS ++ : CA_LIST_ARGS; ++ else ++ attr_state = CA_NONE; ++ break; ++ case CA_CA_ARGS: /* We will special-case args in this state. */ ++ case CA_LIST_ARGS: ++ if (token.type == CPP_CLOSE_PAREN) ++ attr_state = CA_LIST_CONT; ++ break; ++ case CA_LIST_CONT: ++ if (token.type == CPP_COMMA) ++ attr_state = CA_BR2; /* Back to the list outer. */ ++ else ++ attr_state = CA_NONE; ++ break; ++ } ++ return attr_state; ++} ++ + /* Create a new main C++ lexer, the lexer that gets tokens from the + preprocessor. */ + +@@ -645,6 +730,8 @@ cp_lexer_new_main (void) + c_common_no_more_pch (); + + cp_lexer *lexer = cp_lexer_alloc (); ++ enum clang_attr_state attr_state = CA_NONE; ++ + /* Put the first token in the buffer. */ + cp_token *tok = lexer->buffer->quick_push (token); + +@@ -659,8 +746,15 @@ cp_lexer_new_main (void) + /* Process the previous token. */ + module_token_lang (tok->type, tok->keyword, tok->u.value, + tok->location, filter); ++ ++ attr_state = cp_lexer_attribute_state (*tok, attr_state); + tok = vec_safe_push (lexer->buffer, cp_token ()); +- cp_lexer_get_preprocessor_token (C_LEX_STRING_NO_JOIN, tok); ++ unsigned int flags = C_LEX_STRING_NO_JOIN; ++ /* If we are processing clang-style attribute args, lex numbers as ++ potential version strings; NN .. NN.MM .. NN.MM.OO */ ++ if (attr_state == CA_CA_ARGS) ++ flags |= C_LEX_NUMBER_AS_STRING; ++ cp_lexer_get_preprocessor_token (flags, tok); + } + + lexer->next_token = lexer->buffer->address (); +@@ -859,7 +953,7 @@ cp_lexer_get_preprocessor_token (unsigned flags, cp_token *token) + { + static int is_extern_c = 0; + +- /* Get a new token from the preprocessor. */ ++ /* Get a new token from the preprocessor. */ + token->type + = c_lex_with_flags (&token->u.value, &token->location, &token->flags, + flags); +@@ -20831,11 +20925,13 @@ cp_parser_enum_specifier (cp_parser* parser) + + /* Check for the `:' that denotes a specified underlying type in C++0x. + Note that a ':' could also indicate a bitfield width, however. */ ++ location_t colon_loc = UNKNOWN_LOCATION; + if (cp_lexer_next_token_is (parser->lexer, CPP_COLON)) + { + cp_decl_specifier_seq type_specifiers; + + /* Consume the `:'. */ ++ colon_loc = cp_lexer_peek_token (parser->lexer)->location; + cp_lexer_consume_token (parser->lexer); + + auto tdf +@@ -20884,10 +20980,13 @@ cp_parser_enum_specifier (cp_parser* parser) + && cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON)) + { + if (has_underlying_type) +- cp_parser_commit_to_tentative_parse (parser); +- cp_parser_error (parser, "expected %<;%> or %<{%>"); +- if (has_underlying_type) +- return error_mark_node; ++ pedwarn (colon_loc, ++ OPT_Welaborated_enum_base, ++ "declaration of enumeration with " ++ "fixed underlying type and no enumerator list is " ++ "only permitted as a standalone declaration"); ++ else ++ cp_parser_error (parser, "expected %<;%> or %<{%>"); + } + } + +@@ -28696,6 +28795,91 @@ cp_parser_gnu_attributes_opt (cp_parser* parser) + return attributes; + } + ++/* Parse the arguments list for a clang attribute. */ ++static tree ++cp_parser_clang_attribute (cp_parser *parser, tree/*attr_id*/) ++{ ++ /* Each entry can be : ++ identifier ++ identifier=N.MM.Z ++ identifier="string" ++ followed by ',' or ) for the last entry*/ ++ ++ matching_parens parens; ++ if (!parens.require_open (parser)) ++ return NULL; ++ ++ bool save_translate_strings_p = parser->translate_strings_p; ++ parser->translate_strings_p = false; ++ tree attr_args = NULL_TREE; ++ cp_token *token; ++ do ++ { ++ tree name = NULL_TREE; ++ tree value = NULL_TREE; ++ ++ token = cp_lexer_peek_token (parser->lexer); ++ if (token->type == CPP_NAME) ++ name = token->u.value; ++ else if (token->type == CPP_KEYWORD) ++ name = ridpointers[(int) token->keyword]; ++ else if (token->flags & NAMED_OP) ++ name = get_identifier (cpp_type2name (token->type, token->flags)); ++ else ++ { ++ /* FIXME: context-sensitive for that attrib. */ ++ error_at (token->location, "expected an attribute keyword"); ++ cp_parser_skip_to_closing_parenthesis (parser, ++ /*recovering=*/true, ++ /*or_comma=*/false, ++ /*consume_paren=*/false); ++ attr_args = error_mark_node; ++ break; ++ } ++ cp_lexer_consume_token (parser->lexer); ++ ++ if (cp_lexer_next_token_is (parser->lexer, CPP_EQ)) ++ { ++ cp_lexer_consume_token (parser->lexer); /* eat the '=' */ ++ if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN) ++ && cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA)) ++ { ++ token = cp_lexer_peek_token (parser->lexer); ++ if (token->type == CPP_STRING) ++ value = cp_parser_string_literal (parser, /*translate=*/false, ++ /*wide_ok=*/false); ++ else ++ { ++ value = token->u.value; ++ cp_lexer_consume_token (parser->lexer); ++ } ++ } ++ /* else value is missing. */ ++ } ++ else if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN) ++ && cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA)) ++ { ++ error_at (token->location, "expected %<,%>, %<=%> or %<)%>"); ++ cp_parser_skip_to_closing_parenthesis (parser, ++ /*recovering=*/true, ++ /*or_comma=*/false, ++ /*consume_paren=*/false); ++ attr_args = error_mark_node; ++ break; ++ } ++ if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA)) ++ cp_lexer_consume_token (parser->lexer); ++ tree t = tree_cons (value, name, NULL_TREE); ++ attr_args = chainon (attr_args, t); ++ } while (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN)); ++ ++ parser->translate_strings_p = save_translate_strings_p; ++ if (!parens.require_close (parser)) ++ return error_mark_node; ++ ++ return attr_args; ++} ++ + /* Parse a GNU attribute-list. + + attribute-list: +@@ -28755,9 +28939,12 @@ cp_parser_gnu_attribute_list (cp_parser* parser, bool exactly_one /* = false */) + + /* Peek at the next token. */ + token = cp_lexer_peek_token (parser->lexer); +- /* If it's an `(', then parse the attribute arguments. */ +- if (token->type == CPP_OPEN_PAREN) ++ if (token->type == CPP_OPEN_PAREN ++ && attribute_clang_form_p (identifier)) ++ arguments = cp_parser_clang_attribute (parser, identifier); ++ else if (token->type == CPP_OPEN_PAREN) + { ++ /* If it's an `(', then parse the attribute arguments. */ + vec *vec; + int attr_flag = (attribute_takes_identifier_p (identifier) + ? id_attr : normal_attr); +@@ -28772,12 +28959,12 @@ cp_parser_gnu_attribute_list (cp_parser* parser, bool exactly_one /* = false */) + arguments = build_tree_list_vec (vec); + release_tree_vector (vec); + } +- /* Save the arguments away. */ +- TREE_VALUE (attribute) = arguments; + } + + if (arguments != error_mark_node) + { ++ /* Save the arguments away. */ ++ TREE_VALUE (attribute) = arguments; + /* Add this attribute to the list. */ + TREE_CHAIN (attribute) = attribute_list; + attribute_list = attribute; +diff --git a/gcc/cumulative-args.h b/gcc/cumulative-args.h +new file mode 100644 +index 00000000000..b60928e37f9 +--- /dev/null ++++ b/gcc/cumulative-args.h +@@ -0,0 +1,20 @@ ++#ifndef GCC_CUMULATIVE_ARGS_H ++#define GCC_CUMULATIVE_ARGS_H ++ ++#if CHECKING_P ++ ++struct cumulative_args_t { void *magic; void *p; }; ++ ++#else /* !CHECKING_P */ ++ ++/* When using a GCC build compiler, we could use ++ __attribute__((transparent_union)) to get cumulative_args_t function ++ arguments passed like scalars where the ABI would mandate a less ++ efficient way of argument passing otherwise. However, that would come ++ at the cost of less type-safe !CHECKING_P compilation. */ ++ ++union cumulative_args_t { void *p; }; ++ ++#endif /* !CHECKING_P */ ++ ++#endif /* GCC_CUMULATIVE_ARGS_H */ +diff --git a/gcc/d/Make-lang.in b/gcc/d/Make-lang.in +index f3e34c54015..0801eecfb47 100644 +--- a/gcc/d/Make-lang.in ++++ b/gcc/d/Make-lang.in +@@ -60,7 +60,7 @@ WARN_DFLAGS = -Wall -Wdeprecated $(NOCOMMON_FLAG) + ALL_DFLAGS = $(DFLAGS-$@) $(GDCFLAGS) -fversion=IN_GCC $(CHECKING_DFLAGS) \ + $(PICFLAG) $(ALIASING_FLAGS) $(COVERAGE_FLAGS) $(WARN_DFLAGS) + +-DCOMPILE.base = $(GDC) $(NO_PIE_CFLAGS) -c $(ALL_DFLAGS) -o $@ ++DCOMPILE.base = $(GDC) -c $(ALL_DFLAGS) -o $@ + DCOMPILE = $(DCOMPILE.base) -MT $@ -MMD -MP -MF $(@D)/$(DEPDIR)/$(*F).TPo + DPOSTCOMPILE = @mv $(@D)/$(DEPDIR)/$(*F).TPo $(@D)/$(DEPDIR)/$(*F).Po + DLINKER = $(GDC) $(NO_PIE_FLAG) -lstdc++ +diff --git a/gcc/d/dmd/aggregate.h b/gcc/d/dmd/aggregate.h +index bdeb38e8b45..92a3dcdc0c6 100644 +--- a/gcc/d/dmd/aggregate.h ++++ b/gcc/d/dmd/aggregate.h +@@ -115,8 +115,8 @@ public: + Expression *getRTInfo; // pointer to GC info generated by object.RTInfo(this) + + Visibility visibility; +- bool noDefaultCtor; // no default construction +- bool disableNew; // disallow allocations using `new` ++ d_bool noDefaultCtor; // no default construction ++ d_bool disableNew; // disallow allocations using `new` + Sizeok sizeok; // set when structsize contains valid data + + virtual Scope *newScope(Scope *sc); +@@ -265,13 +265,13 @@ public: + // (does not include baseClass) + + BaseClasses *vtblInterfaces; // array of base interfaces that have +- // their own vtbl[] ++ // their own vtbl[] + + TypeInfoClassDeclaration *vclassinfo; // the ClassInfo object for this ClassDeclaration +- bool com; // true if this is a COM class (meaning it derives from IUnknown) +- bool stack; // true if this is a scope class ++ d_bool com; // true if this is a COM class (meaning it derives from IUnknown) ++ d_bool stack; // true if this is a scope class + int cppDtorVtblIndex; // slot reserved for the virtual destructor [extern(C++)] +- bool inuse; // to prevent recursive attempts ++ d_bool inuse; // to prevent recursive attempts + + ThreeState isabstract; // if abstract class + Baseok baseok; // set the progress of base classes resolving +diff --git a/gcc/d/dmd/attrib.h b/gcc/d/dmd/attrib.h +index 812729b3f27..0bed3efc814 100644 +--- a/gcc/d/dmd/attrib.h ++++ b/gcc/d/dmd/attrib.h +@@ -133,7 +133,7 @@ public: + class AnonDeclaration : public AttribDeclaration + { + public: +- bool isunion; ++ d_bool isunion; + int sem; // 1 if successful semantic() + unsigned anonoffset; // offset of anonymous struct + unsigned anonstructsize; // size of anonymous struct +@@ -177,8 +177,8 @@ class StaticIfDeclaration : public ConditionalDeclaration + { + public: + ScopeDsymbol *scopesym; +- bool addisdone; +- bool onStack; ++ d_bool addisdone; ++ d_bool onStack; + + StaticIfDeclaration *syntaxCopy(Dsymbol *s); + Dsymbols *include(Scope *sc); +@@ -194,8 +194,8 @@ class StaticForeachDeclaration : public AttribDeclaration + public: + StaticForeach *sfe; + ScopeDsymbol *scopesym; +- bool onStack; +- bool cached; ++ d_bool onStack; ++ d_bool cached; + Dsymbols *cache; + + StaticForeachDeclaration *syntaxCopy(Dsymbol *s); +@@ -228,7 +228,7 @@ public: + Expressions *exps; + + ScopeDsymbol *scopesym; +- bool compiled; ++ d_bool compiled; + + CompileDeclaration *syntaxCopy(Dsymbol *s); + void addMember(Scope *sc, ScopeDsymbol *sds); +diff --git a/gcc/d/dmd/common/outbuffer.h b/gcc/d/dmd/common/outbuffer.h +index fed25c0d030..d7a340da11a 100644 +--- a/gcc/d/dmd/common/outbuffer.h ++++ b/gcc/d/dmd/common/outbuffer.h +@@ -21,11 +21,11 @@ struct OutBuffer + private: + DArray data; + d_size_t offset; +- bool notlinehead; ++ d_bool notlinehead; + void *fileMapping; // pointer to a file mapping object not used on the C++ side + public: +- bool doindent; +- bool spaces; ++ d_bool doindent; ++ d_bool spaces; + int level; + + OutBuffer() +diff --git a/gcc/d/dmd/cond.h b/gcc/d/dmd/cond.h +index d69c13e8101..c45457ef16d 100644 +--- a/gcc/d/dmd/cond.h ++++ b/gcc/d/dmd/cond.h +@@ -50,7 +50,7 @@ public: + ForeachStatement *aggrfe; + ForeachRangeStatement *rangefe; + +- bool needExpansion; ++ d_bool needExpansion; + + StaticForeach *syntaxCopy(); + }; +diff --git a/gcc/d/dmd/declaration.h b/gcc/d/dmd/declaration.h +index 6fe4a221c3b..6679daa8f77 100644 +--- a/gcc/d/dmd/declaration.h ++++ b/gcc/d/dmd/declaration.h +@@ -165,7 +165,7 @@ class TupleDeclaration : public Declaration + { + public: + Objects *objects; +- bool isexp; // true: expression tuple ++ d_bool isexp; // true: expression tuple + + TypeTuple *tupletype; // !=NULL if this is a type tuple + +@@ -598,7 +598,7 @@ public: + + // set if someone took the address of this function + int tookAddressOf; +- bool requiresClosure; // this function needs a closure ++ d_bool requiresClosure; // this function needs a closure + + // local variables in this function which are referenced by nested functions + VarDeclarations closureVars; +@@ -699,7 +699,7 @@ class FuncAliasDeclaration : public FuncDeclaration + { + public: + FuncDeclaration *funcalias; +- bool hasOverloads; ++ d_bool hasOverloads; + + FuncAliasDeclaration *isFuncAliasDeclaration() { return this; } + const char *kind() const; +@@ -715,7 +715,7 @@ public: + Type *treq; // target of return type inference + + // backend +- bool deferToObj; ++ d_bool deferToObj; + + FuncLiteralDeclaration *syntaxCopy(Dsymbol *); + bool isNested() const; +@@ -735,7 +735,7 @@ public: + class CtorDeclaration : public FuncDeclaration + { + public: +- bool isCpCtor; ++ d_bool isCpCtor; + CtorDeclaration *syntaxCopy(Dsymbol *); + const char *kind() const; + const char *toChars() const; +diff --git a/gcc/d/dmd/dsymbol.h b/gcc/d/dmd/dsymbol.h +index 35500af4548..31fc9c8a243 100644 +--- a/gcc/d/dmd/dsymbol.h ++++ b/gcc/d/dmd/dsymbol.h +@@ -164,7 +164,7 @@ struct FieldState + unsigned fieldAlign; + unsigned bitOffset; + +- bool inFlight; ++ d_bool inFlight; + }; + + class Dsymbol : public ASTNode +@@ -178,7 +178,7 @@ public: + Loc loc; // where defined + Scope *_scope; // !=NULL means context to use for semantic() + const utf8_t *prettystring; +- bool errors; // this symbol failed to pass semantic() ++ d_bool errors; // this symbol failed to pass semantic() + PASS semanticRun; + unsigned short localNum; // perturb mangled name to avoid collisions with those in FuncDeclaration.localsymtab + DeprecatedDeclaration *depdecl; // customized deprecation message +diff --git a/gcc/d/dmd/expression.h b/gcc/d/dmd/expression.h +index 330dcdb77ec..c4fcb1b1683 100644 +--- a/gcc/d/dmd/expression.h ++++ b/gcc/d/dmd/expression.h +@@ -326,7 +326,7 @@ class DsymbolExp : public Expression + { + public: + Dsymbol *s; +- bool hasOverloads; ++ d_bool hasOverloads; + + DsymbolExp *syntaxCopy(); + bool isLvalue(); +@@ -470,8 +470,8 @@ public: + */ + int stageflags; + +- bool useStaticInit; // if this is true, use the StructDeclaration's init symbol +- bool isOriginal; // used when moving instances to indicate `this is this.origin` ++ d_bool useStaticInit; // if this is true, use the StructDeclaration's init symbol ++ d_bool isOriginal; // used when moving instances to indicate `this is this.origin` + OwnedBy ownedByCtfe; + + static StructLiteralExp *create(const Loc &loc, StructDeclaration *sd, void *elements, Type *stype = NULL); +@@ -530,8 +530,8 @@ public: + Expression *argprefix; // expression to be evaluated just before arguments[] + + CtorDeclaration *member; // constructor function +- bool onstack; // allocate on stack +- bool thrownew; // this NewExp is the expression of a ThrowStatement ++ d_bool onstack; // allocate on stack ++ d_bool thrownew; // this NewExp is the expression of a ThrowStatement + + static NewExp *create(const Loc &loc, Expression *thisexp, Type *newtype, Expressions *arguments); + NewExp *syntaxCopy(); +@@ -557,7 +557,7 @@ class SymbolExp : public Expression + public: + Declaration *var; + Dsymbol *originalScope; +- bool hasOverloads; ++ d_bool hasOverloads; + + void accept(Visitor *v) { v->visit(this); } + }; +@@ -579,7 +579,7 @@ public: + class VarExp : public SymbolExp + { + public: +- bool delegateWasExtracted; ++ d_bool delegateWasExtracted; + static VarExp *create(const Loc &loc, Declaration *var, bool hasOverloads = true); + bool equals(const RootObject *o) const; + bool isLvalue(); +@@ -755,9 +755,9 @@ class DotIdExp : public UnaExp + { + public: + Identifier *ident; +- bool noderef; // true if the result of the expression will never be dereferenced +- bool wantsym; // do not replace Symbol with its initializer during semantic() +- bool arrow; // ImportC: if -> instead of . ++ d_bool noderef; // true if the result of the expression will never be dereferenced ++ d_bool wantsym; // do not replace Symbol with its initializer during semantic() ++ d_bool arrow; // ImportC: if -> instead of . + + static DotIdExp *create(const Loc &loc, Expression *e, Identifier *ident); + void accept(Visitor *v) { v->visit(this); } +@@ -777,7 +777,7 @@ class DotVarExp : public UnaExp + { + public: + Declaration *var; +- bool hasOverloads; ++ d_bool hasOverloads; + + bool isLvalue(); + Expression *toLvalue(Scope *sc, Expression *e); +@@ -801,7 +801,7 @@ class DelegateExp : public UnaExp + { + public: + FuncDeclaration *func; +- bool hasOverloads; ++ d_bool hasOverloads; + VarDeclaration *vthis2; // container for multi-context + + +@@ -821,9 +821,9 @@ class CallExp : public UnaExp + public: + Expressions *arguments; // function arguments + FuncDeclaration *f; // symbol to call +- bool directcall; // true if a virtual call is devirtualized +- bool inDebugStatement; // true if this was in a debug statement +- bool ignoreAttributes; // don't enforce attributes (e.g. call @gc function in @nogc code) ++ d_bool directcall; // true if a virtual call is devirtualized ++ d_bool inDebugStatement; // true if this was in a debug statement ++ d_bool ignoreAttributes; // don't enforce attributes (e.g. call @gc function in @nogc code) + VarDeclaration *vthis2; // container for multi-context + + static CallExp *create(const Loc &loc, Expression *e, Expressions *exps); +@@ -882,7 +882,7 @@ public: + class DeleteExp : public UnaExp + { + public: +- bool isRAII; ++ d_bool isRAII; + void accept(Visitor *v) { v->visit(this); } + }; + +@@ -927,9 +927,9 @@ public: + Expression *upr; // NULL if implicit 0 + Expression *lwr; // NULL if implicit [length - 1] + VarDeclaration *lengthVar; +- bool upperIsInBounds; // true if upr <= e1.length +- bool lowerIsLessThanUpper; // true if lwr <= upr +- bool arrayop; // an array operation, rather than a slice ++ d_bool upperIsInBounds; // true if upr <= e1.length ++ d_bool lowerIsLessThanUpper; // true if lwr <= upr ++ d_bool arrayop; // an array operation, rather than a slice + + SliceExp *syntaxCopy(); + bool isLvalue(); +@@ -1001,8 +1001,8 @@ public: + class CommaExp : public BinExp + { + public: +- bool isGenerated; +- bool allowCommaExp; ++ d_bool isGenerated; ++ d_bool allowCommaExp; + bool isLvalue(); + Expression *toLvalue(Scope *sc, Expression *e); + Expression *modifiableLvalue(Scope *sc, Expression *e); +@@ -1015,8 +1015,8 @@ class IndexExp : public BinExp + { + public: + VarDeclaration *lengthVar; +- bool modifiable; +- bool indexIsInBounds; // true if 0 <= e2 && e2 <= e1.length - 1 ++ d_bool modifiable; ++ d_bool indexIsInBounds; // true if 0 <= e2 && e2 <= e1.length - 1 + + IndexExp *syntaxCopy(); + bool isLvalue(); +diff --git a/gcc/d/dmd/globals.h b/gcc/d/dmd/globals.h +index 2a33692380e..6f230142770 100644 +--- a/gcc/d/dmd/globals.h ++++ b/gcc/d/dmd/globals.h +@@ -92,78 +92,78 @@ enum class FeatureState : signed char + // Put command line switches in here + struct Param + { +- bool obj; // write object file +- bool link; // perform link +- bool dll; // generate shared dynamic library +- bool lib; // write library file instead of object file(s) +- bool multiobj; // break one object file into multiple ones +- bool oneobj; // write one object file instead of multiple ones +- bool trace; // insert profiling hooks +- bool tracegc; // instrument calls to 'new' +- bool verbose; // verbose compile +- bool vcg_ast; // write-out codegen-ast +- bool showColumns; // print character (column) numbers in diagnostics +- bool vtls; // identify thread local variables +- bool vtemplates; // collect and list statistics on template instantiations +- bool vtemplatesListInstances; // collect and list statistics on template instantiations origins +- bool vgc; // identify gc usage +- bool vfield; // identify non-mutable field variables +- bool vcomplex; // identify complex/imaginary type usage +- bool vin; // identify 'in' parameters ++ d_bool obj; // write object file ++ d_bool link; // perform link ++ d_bool dll; // generate shared dynamic library ++ d_bool lib; // write library file instead of object file(s) ++ d_bool multiobj; // break one object file into multiple ones ++ d_bool oneobj; // write one object file instead of multiple ones ++ d_bool trace; // insert profiling hooks ++ d_bool tracegc; // instrument calls to 'new' ++ d_bool verbose; // verbose compile ++ d_bool vcg_ast; // write-out codegen-ast ++ d_bool showColumns; // print character (column) numbers in diagnostics ++ d_bool vtls; // identify thread local variables ++ d_bool vtemplates; // collect and list statistics on template instantiations ++ d_bool vtemplatesListInstances; // collect and list statistics on template instantiations origins ++ d_bool vgc; // identify gc usage ++ d_bool vfield; // identify non-mutable field variables ++ d_bool vcomplex; // identify complex/imaginary type usage ++ d_bool vin; // identify 'in' parameters + unsigned char symdebug; // insert debug symbolic information +- bool symdebugref; // insert debug information for all referenced types, too +- bool optimize; // run optimizer ++ d_bool symdebugref; // insert debug information for all referenced types, too ++ d_bool optimize; // run optimizer + Diagnostic useDeprecated; +- bool stackstomp; // add stack stomping code +- bool useUnitTests; // generate unittest code +- bool useInline; // inline expand functions ++ d_bool stackstomp; // add stack stomping code ++ d_bool useUnitTests; // generate unittest code ++ d_bool useInline; // inline expand functions + FeatureState useDIP25; // implement https://wiki.dlang.org/DIP25 + FeatureState useDIP1000; // implement https://dlang.org/spec/memory-safe-d.html#scope-return-params +- bool useDIP1021; // implement https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1021.md +- bool release; // build release version +- bool preservePaths; // true means don't strip path from source file ++ d_bool useDIP1021; // implement https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1021.md ++ d_bool release; // build release version ++ d_bool preservePaths; // true means don't strip path from source file + Diagnostic warnings; + unsigned char pic; // generate position-independent-code for shared libs +- bool color; // use ANSI colors in console output +- bool cov; // generate code coverage data ++ d_bool color; // use ANSI colors in console output ++ d_bool cov; // generate code coverage data + unsigned char covPercent; // 0..100 code coverage percentage required +- bool ctfe_cov; // generate coverage data for ctfe +- bool nofloat; // code should not pull in floating point support +- bool ignoreUnsupportedPragmas; // rather than error on them +- bool useModuleInfo; // generate runtime module information +- bool useTypeInfo; // generate runtime type information +- bool useExceptions; // support exception handling +- bool noSharedAccess; // read/write access to shared memory objects +- bool previewIn; // `in` means `scope const`, perhaps `ref`, accepts rvalues +- bool shortenedMethods; // allow => in normal function declarations +- bool betterC; // be a "better C" compiler; no dependency on D runtime +- bool addMain; // add a default main() function +- bool allInst; // generate code for all template instantiations +- bool fix16997; // fix integral promotions for unary + - ~ operators ++ d_bool ctfe_cov; // generate coverage data for ctfe ++ d_bool nofloat; // code should not pull in floating point support ++ d_bool ignoreUnsupportedPragmas; // rather than error on them ++ d_bool useModuleInfo; // generate runtime module information ++ d_bool useTypeInfo; // generate runtime type information ++ d_bool useExceptions; // support exception handling ++ d_bool noSharedAccess; // read/write access to shared memory objects ++ d_bool previewIn; // `in` means `scope const`, perhaps `ref`, accepts rvalues ++ d_bool shortenedMethods; // allow => in normal function declarations ++ d_bool betterC; // be a "better C" compiler; no dependency on D runtime ++ d_bool addMain; // add a default main() function ++ d_bool allInst; // generate code for all template instantiations ++ d_bool fix16997; // fix integral promotions for unary + - ~ operators + // https://issues.dlang.org/show_bug.cgi?id=16997 +- bool fixAliasThis; // if the current scope has an alias this, check it before searching upper scopes +- bool inclusiveInContracts; // 'in' contracts of overridden methods must be a superset of parent contract +- bool ehnogc; // use @nogc exception handling ++ d_bool fixAliasThis; // if the current scope has an alias this, check it before searching upper scopes ++ d_bool inclusiveInContracts; // 'in' contracts of overridden methods must be a superset of parent contract ++ d_bool ehnogc; // use @nogc exception handling + FeatureState dtorFields; // destruct fields of partially constructed objects + // https://issues.dlang.org/show_bug.cgi?id=14246 +- bool fieldwise; // do struct equality testing field-wise rather than by memcmp() ++ d_bool fieldwise; // do struct equality testing field-wise rather than by memcmp() + FeatureState rvalueRefParam; // allow rvalues to be arguments to ref parameters + CppStdRevision cplusplus; // version of C++ name mangling to support +- bool markdown; // enable Markdown replacements in Ddoc +- bool vmarkdown; // list instances of Markdown replacements in Ddoc +- bool showGaggedErrors; // print gagged errors anyway +- bool printErrorContext; // print errors with the error context (the error line in the source file) +- bool manual; // open browser on compiler manual +- bool usage; // print usage and exit +- bool mcpuUsage; // print help on -mcpu switch +- bool transitionUsage; // print help on -transition switch +- bool checkUsage; // print help on -check switch +- bool checkActionUsage; // print help on -checkaction switch +- bool revertUsage; // print help on -revert switch +- bool previewUsage; // print help on -preview switch +- bool externStdUsage; // print help on -extern-std switch +- bool hcUsage; // print help on -HC switch +- bool logo; // print logo; ++ d_bool markdown; // enable Markdown replacements in Ddoc ++ d_bool vmarkdown; // list instances of Markdown replacements in Ddoc ++ d_bool showGaggedErrors; // print gagged errors anyway ++ d_bool printErrorContext; // print errors with the error context (the error line in the source file) ++ d_bool manual; // open browser on compiler manual ++ d_bool usage; // print usage and exit ++ d_bool mcpuUsage; // print help on -mcpu switch ++ d_bool transitionUsage; // print help on -transition switch ++ d_bool checkUsage; // print help on -check switch ++ d_bool checkActionUsage; // print help on -checkaction switch ++ d_bool revertUsage; // print help on -revert switch ++ d_bool previewUsage; // print help on -preview switch ++ d_bool externStdUsage; // print help on -extern-std switch ++ d_bool hcUsage; // print help on -HC switch ++ d_bool logo; // print logo; + + CHECKENABLE useInvariants; // generate class invariant checks + CHECKENABLE useIn; // generate precondition checks +@@ -185,21 +185,21 @@ struct Param + DString objname; // .obj file output name + DString libname; // .lib file output name + +- bool doDocComments; // process embedded documentation comments ++ d_bool doDocComments; // process embedded documentation comments + DString docdir; // write documentation file to docdir directory + DString docname; // write documentation file to docname + Array ddocfiles; // macro include files for Ddoc + +- bool doHdrGeneration; // process embedded documentation comments ++ d_bool doHdrGeneration; // process embedded documentation comments + DString hdrdir; // write 'header' file to docdir directory + DString hdrname; // write 'header' file to docname +- bool hdrStripPlainFunctions; // strip the bodies of plain (non-template) functions ++ d_bool hdrStripPlainFunctions; // strip the bodies of plain (non-template) functions + + CxxHeaderMode doCxxHdrGeneration; // write 'Cxx header' file + DString cxxhdrdir; // write 'header' file to docdir directory + DString cxxhdrname; // write 'header' file to docname + +- bool doJsonGeneration; // write JSON file ++ d_bool doJsonGeneration; // write JSON file + DString jsonfilename; // write JSON file to jsonfilename + unsigned jsonFieldFlags; // JSON field flags to include + +@@ -220,13 +220,13 @@ struct Param + DString moduleDepsFile; // filename for deps output + OutBuffer *moduleDeps; // contents to be written to deps file + +- bool emitMakeDeps; // whether to emit makedeps ++ d_bool emitMakeDeps; // whether to emit makedeps + DString makeDepsFile; // filename for makedeps output + Array makeDeps; // dependencies for makedeps + + MessageStyle messageStyle; // style of file/line annotations on messages + +- bool run; // run resulting executable ++ d_bool run; // run resulting executable + Strings runargs; // arguments for executable + + // Linker stuff +@@ -244,7 +244,7 @@ struct Param + struct structalign_t + { + unsigned short value; +- bool pack; ++ d_bool pack; + + bool isDefault() const; + void setDefault(); +@@ -291,7 +291,7 @@ struct Global + Array* versionids; // command line versions and predefined versions + Array* debugids; // command line debug versions and predefined versions + +- bool hasMainFunction; ++ d_bool hasMainFunction; + unsigned varSequenceNumber; + + FileManager* fileManager; +diff --git a/gcc/d/dmd/identifier.h b/gcc/d/dmd/identifier.h +index 4c748beb5d8..795b0d17157 100644 +--- a/gcc/d/dmd/identifier.h ++++ b/gcc/d/dmd/identifier.h +@@ -17,7 +17,7 @@ class Identifier : public RootObject + { + private: + int value; +- bool isAnonymous_; ++ d_bool isAnonymous_; + DString string; + + public: +diff --git a/gcc/d/dmd/init.h b/gcc/d/dmd/init.h +index 73dc4bba2e4..718c01f8b51 100644 +--- a/gcc/d/dmd/init.h ++++ b/gcc/d/dmd/init.h +@@ -75,7 +75,7 @@ public: + Initializers value; // of Initializer *'s + unsigned dim; // length of array being initialized + Type *type; // type that array will be used to initialize +- bool sem; // true if semantic() is run ++ d_bool sem; // true if semantic() is run + + bool isAssociativeArray() const; + Expression *toAssocArrayLiteral(); +@@ -86,7 +86,7 @@ public: + class ExpInitializer : public Initializer + { + public: +- bool expandTuples; ++ d_bool expandTuples; + Expression *exp; + + void accept(Visitor *v) { v->visit(this); } +@@ -109,7 +109,7 @@ class CInitializer : public Initializer + public: + DesigInits initializerList; + Type *type; // type that array will be used to initialize +- bool sem; // true if semantic() is run ++ d_bool sem; // true if semantic() is run + + void accept(Visitor *v) { v->visit(this); } + }; +diff --git a/gcc/d/dmd/module.h b/gcc/d/dmd/module.h +index 048b3a0452c..539bbbbaae3 100644 +--- a/gcc/d/dmd/module.h ++++ b/gcc/d/dmd/module.h +@@ -75,8 +75,8 @@ public: + unsigned errors; // if any errors in file + unsigned numlines; // number of lines in source file + FileType filetype; // source file type +- bool hasAlwaysInlines; // contains references to functions that must be inlined +- bool isPackageFile; // if it is a package.d ++ d_bool hasAlwaysInlines; // contains references to functions that must be inlined ++ d_bool isPackageFile; // if it is a package.d + Package *pkg; // if isPackageFile is true, the Package that contains this package.d + Strings contentImportedFiles; // array of files whose content was imported + int needmoduleinfo; +@@ -165,7 +165,7 @@ struct ModuleDeclaration + Loc loc; + Identifier *id; + DArray packages; // array of Identifier's representing packages +- bool isdeprecated; // if it is a deprecated module ++ d_bool isdeprecated; // if it is a deprecated module + Expression *msg; + + const char *toChars() const; +diff --git a/gcc/d/dmd/mtype.h b/gcc/d/dmd/mtype.h +index 6ba47dfa34e..781571e8857 100644 +--- a/gcc/d/dmd/mtype.h ++++ b/gcc/d/dmd/mtype.h +@@ -584,7 +584,7 @@ struct ParameterList + Parameters* parameters; + StorageClass stc; + VarArg varargs; +- bool hasIdentifierList; // true if C identifier-list style ++ d_bool hasIdentifierList; // true if C identifier-list style + + size_t length(); + Parameter *operator[](size_t i) { return Parameter::getNth(parameters, i); } +@@ -774,7 +774,7 @@ class TypeStruct : public Type + public: + StructDeclaration *sym; + AliasThisRec att; +- bool inuse; ++ d_bool inuse; + + static TypeStruct *create(StructDeclaration *sym); + const char *kind(); +diff --git a/gcc/d/dmd/objc.h b/gcc/d/dmd/objc.h +index a03015489a4..c27aecbe44a 100644 +--- a/gcc/d/dmd/objc.h ++++ b/gcc/d/dmd/objc.h +@@ -37,8 +37,8 @@ struct ObjcSelector + + struct ObjcClassDeclaration + { +- bool isMeta; +- bool isExtern; ++ d_bool isMeta; ++ d_bool isExtern; + + Identifier* identifier; + ClassDeclaration* classDeclaration; +@@ -52,7 +52,7 @@ struct ObjcFuncDeclaration + { + ObjcSelector* selector; + VarDeclaration* selectorParameter; +- bool isOptional; ++ d_bool isOptional; + }; + + class Objc +diff --git a/gcc/d/dmd/root/dcompat.h b/gcc/d/dmd/root/dcompat.h +index 5823e7c4886..4e73d956034 100644 +--- a/gcc/d/dmd/root/dcompat.h ++++ b/gcc/d/dmd/root/dcompat.h +@@ -36,7 +36,7 @@ struct DString : public DArray + }; + + /// Corresponding C++ type that maps to D size_t +-#if __APPLE__ && __i386__ ++#if __APPLE__ && (__i386__ || __ppc__) + // size_t is 'unsigned long', which makes it mangle differently than D's 'uint' + typedef unsigned d_size_t; + #elif MARS && DMD_VERSION >= 2079 && DMD_VERSION <= 2081 && \ +@@ -49,3 +49,11 @@ typedef unsigned d_size_t; + #else + typedef size_t d_size_t; + #endif ++ ++/// Corresponding C++ type that maps to D bool ++#if __APPLE__ && __ppc__ ++// bool is defined as an 'int', which does not match same size as D ++typedef char d_bool; ++#else ++typedef bool d_bool; ++#endif +diff --git a/gcc/d/dmd/root/optional.h b/gcc/d/dmd/root/optional.h +index e4a41a06100..c28f0685ee4 100644 +--- a/gcc/d/dmd/root/optional.h ++++ b/gcc/d/dmd/root/optional.h +@@ -11,6 +11,8 @@ + * Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/root/optional.h + */ + ++#include "dcompat.h" // for d_bool ++ + /// Optional type that is either `empty` or contains a value of type `T` + template + struct Optional final +@@ -20,7 +22,7 @@ private: + T value; + + /** whether `value` is set **/ +- bool present; ++ d_bool present; + + public: + /** Creates an `Optional` with the given value **/ +diff --git a/gcc/d/dmd/scope.h b/gcc/d/dmd/scope.h +index a163e7577a2..8d1807684e6 100644 +--- a/gcc/d/dmd/scope.h ++++ b/gcc/d/dmd/scope.h +@@ -85,8 +85,8 @@ struct Scope + ForeachStatement *fes; // if nested function for ForeachStatement, this is it + Scope *callsc; // used for __FUNCTION__, __PRETTY_FUNCTION__ and __MODULE__ + Dsymbol *inunion; // !=null if processing members of a union +- bool nofree; // true if shouldn't free it +- bool inLoop; // true if inside a loop (where constructor calls aren't allowed) ++ d_bool nofree; // true if shouldn't free it ++ d_bool inLoop; // true if inside a loop (where constructor calls aren't allowed) + int intypeof; // in typeof(exp) + VarDeclaration *lastVar; // Previous symbol used to prevent goto-skips-init + +diff --git a/gcc/d/dmd/statement.h b/gcc/d/dmd/statement.h +index 66eddd8ab55..670fac1406b 100644 +--- a/gcc/d/dmd/statement.h ++++ b/gcc/d/dmd/statement.h +@@ -430,7 +430,7 @@ class SwitchStatement : public Statement + public: + Expression *condition; + Statement *_body; +- bool isFinal; ++ d_bool isFinal; + + DefaultStatement *sdefault; + Statement *tryBody; // set to TryCatchStatement or TryFinallyStatement if in _body portion +@@ -597,11 +597,11 @@ public: + + VarDeclaration *var; + // set if semantic processing errors +- bool errors; ++ d_bool errors; + + // was generated by the compiler, + // wasn't present in source code +- bool internalCatch; ++ d_bool internalCatch; + + Catch *syntaxCopy(); + }; +@@ -613,7 +613,7 @@ public: + Statement *finalbody; + + Statement *tryBody; // set to enclosing TryCatchStatement or TryFinallyStatement if in _body portion +- bool bodyFallsThru; // true if _body falls through to finally ++ d_bool bodyFallsThru; // true if _body falls through to finally + + static TryFinallyStatement *create(const Loc &loc, Statement *body, Statement *finalbody); + TryFinallyStatement *syntaxCopy(); +@@ -640,7 +640,7 @@ public: + Expression *exp; + // was generated by the compiler, + // wasn't present in source code +- bool internalThrow; ++ d_bool internalThrow; + + ThrowStatement *syntaxCopy(); + +@@ -682,7 +682,7 @@ public: + VarDeclaration *lastVar; + Statement *gotoTarget; // interpret + void* extra; // used by Statement_toIR() +- bool breaks; // someone did a 'break ident' ++ d_bool breaks; // someone did a 'break ident' + + LabelStatement *syntaxCopy(); + +@@ -694,8 +694,8 @@ class LabelDsymbol : public Dsymbol + public: + LabelStatement *statement; + +- bool deleted; // set if rewritten to return in foreach delegate +- bool iasm; // set if used by inline assembler ++ d_bool deleted; // set if rewritten to return in foreach delegate ++ d_bool iasm; // set if used by inline assembler + + static LabelDsymbol *create(Identifier *ident); + LabelDsymbol *isLabel(); +@@ -719,8 +719,8 @@ public: + code *asmcode; + unsigned asmalign; // alignment of this statement + unsigned regs; // mask of registers modified (must match regm_t in back end) +- bool refparam; // true if function parameter is referenced +- bool naked; // true if function is to be naked ++ d_bool refparam; // true if function parameter is referenced ++ d_bool naked; // true if function is to be naked + + InlineAsmStatement *syntaxCopy(); + void accept(Visitor *v) { v->visit(this); } +diff --git a/gcc/d/dmd/target.h b/gcc/d/dmd/target.h +index 096c16fd610..a7b2ff5c03e 100644 +--- a/gcc/d/dmd/target.h ++++ b/gcc/d/dmd/target.h +@@ -89,14 +89,14 @@ struct TargetCPP + Clang, + DigitalMars, + Gcc, +- Microsoft, +- Sun ++ Microsoft, ++ Sun + }; +- bool reverseOverloads; // with dmc and cl, overloaded functions are grouped and in reverse order +- bool exceptions; // set if catching C++ exceptions is supported +- bool twoDtorInVtable; // target C++ ABI puts deleting and non-deleting destructor into vtable +- bool splitVBasetable; // set if C++ ABI uses separate tables for virtual functions and virtual bases +- bool wrapDtorInExternD; // set if C++ dtors require a D wrapper to be callable from runtime ++ d_bool reverseOverloads; // with dmc and cl, overloaded functions are grouped and in reverse order ++ d_bool exceptions; // set if catching C++ exceptions is supported ++ d_bool twoDtorInVtable; // target C++ ABI puts deleting and non-deleting destructor into vtable ++ d_bool splitVBasetable; // set if C++ ABI uses separate tables for virtual functions and virtual bases ++ d_bool wrapDtorInExternD; // set if C++ dtors require a D wrapper to be callable from runtime + Runtime runtime; + + const char *toMangle(Dsymbol *s); +@@ -110,7 +110,7 @@ struct TargetCPP + + struct TargetObjC + { +- bool supported; // set if compiler can interface with Objective-C ++ d_bool supported; // set if compiler can interface with Objective-C + }; + + struct Target +@@ -156,15 +156,15 @@ struct Target + + DString architectureName; // name of the platform architecture (e.g. X86_64) + CPU cpu; // CPU instruction set to target +- bool is64bit; // generate 64 bit code for x86_64; true by default for 64 bit dmd +- bool isLP64; // pointers are 64 bits ++ d_bool is64bit; // generate 64 bit code for x86_64; true by default for 64 bit dmd ++ d_bool isLP64; // pointers are 64 bits + + // Environmental + DString obj_ext; /// extension for object files + DString lib_ext; /// extension for static library files + DString dll_ext; /// extension for dynamic library files +- bool run_noext; /// allow -run sources without extensions +- bool omfobj; /// for Win32: write OMF object files instead of COFF ++ d_bool run_noext; /// allow -run sources without extensions ++ d_bool omfobj; /// for Win32: write OMF object files instead of COFF + + template + struct FPTypeProperties +diff --git a/gcc/d/dmd/template.h b/gcc/d/dmd/template.h +index 86863769141..9c6cc40ea84 100644 +--- a/gcc/d/dmd/template.h ++++ b/gcc/d/dmd/template.h +@@ -63,12 +63,12 @@ public: + + Dsymbol *onemember; // if !=NULL then one member of this template + +- bool literal; // this template declaration is a literal +- bool ismixin; // template declaration is only to be used as a mixin +- bool isstatic; // this is static template declaration +- bool isTrivialAliasSeq; // matches `template AliasSeq(T...) { alias AliasSeq = T; } +- bool isTrivialAlias; // matches pattern `template Alias(T) { alias Alias = qualifiers(T); }` +- bool deprecated_; // this template declaration is deprecated ++ d_bool literal; // this template declaration is a literal ++ d_bool ismixin; // template declaration is only to be used as a mixin ++ d_bool isstatic; // this is static template declaration ++ d_bool isTrivialAliasSeq; // matches `template AliasSeq(T...) { alias AliasSeq = T; } ++ d_bool isTrivialAlias; // matches pattern `template Alias(T) { alias Alias = qualifiers(T); }` ++ d_bool deprecated_; // this template declaration is deprecated + Visibility visibility; + int inuse; // for recursive expansion detection + +@@ -119,7 +119,7 @@ public: + * A dependent template parameter should return MATCHexact in matchArg() + * to respect the match level of the corresponding precedent parameter. + */ +- bool dependent; ++ d_bool dependent; + + virtual TemplateTypeParameter *isTemplateTypeParameter(); + virtual TemplateValueParameter *isTemplateValueParameter(); +diff --git a/gcc/d/dmd/visitor.h b/gcc/d/dmd/visitor.h +index 5d6b94ccd02..da4680ca2fb 100644 +--- a/gcc/d/dmd/visitor.h ++++ b/gcc/d/dmd/visitor.h +@@ -657,6 +657,6 @@ public: + class StoppableVisitor : public Visitor + { + public: +- bool stop; ++ d_bool stop; + StoppableVisitor() : stop(false) {} + }; +diff --git a/gcc/doc/contrib.texi b/gcc/doc/contrib.texi +index e14cf5e4751..342cc8dd079 100644 +--- a/gcc/doc/contrib.texi ++++ b/gcc/doc/contrib.texi +@@ -1511,7 +1511,7 @@ Gael Thomas for @code{VMClassLoader} boot packages support suggestions. + + @item + Andreas Tobler for Darwin and Solaris testing and fixing, @code{Qt4} +-support for Darwin/OS X, @code{Graphics2D} support, @code{gtk+} ++support for Darwin / macOS, @code{Graphics2D} support, @code{gtk+} + updates. + + @item +diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi +index 90b2767e39a..cf36cde4e15 100644 +--- a/gcc/doc/cpp.texi ++++ b/gcc/doc/cpp.texi +@@ -3198,6 +3198,8 @@ directive}: @samp{#if}, @samp{#ifdef} or @samp{#ifndef}. + * @code{__has_cpp_attribute}:: + * @code{__has_c_attribute}:: + * @code{__has_builtin}:: ++* @code{__has_feature}:: ++* @code{__has_extension}:: + * @code{__has_include}:: + @end menu + +@@ -3560,6 +3562,45 @@ the operator is as follows: + #endif + @end smallexample + ++@node @code{__has_feature} ++@subsection @code{__has_feature} ++@cindex @code{__has_feature} ++ ++The special operator @code{__has_feature (@var{operand})} may be used in ++constant integer contexts and in preprocessor @samp{#if} and @samp{#elif} ++expressions to test whether the identifier given in @var{operand} is recognized ++as a feature supported by GCC given the current options and, in the case of ++standard language features, whether the feature is available in the chosen ++version of the language standard. ++ ++Note that @code{__has_feature} and @code{__has_extension} are not recommended ++for use in new code, and are only provided for compatibility with Clang. For ++details of which identifiers are accepted by these function-like macros, see ++@w{@uref{https://clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension, ++the Clang documentation}}. ++ ++@node @code{__has_extension} ++@subsection @code{__has_extension} ++@cindex @code{__has_extension} ++ ++The special operator @code{__has_extension (@var{operand})} may be used in ++constant integer contexts and in preprocessor @samp{#if} and @samp{#elif} ++expressions to test whether the identifier given in @var{operand} is recognized ++as an extension supported by GCC given the current options. In any given ++context, the features accepted by @code{__has_extension} are a strict superset ++of those accepted by @code{__has_feature}. Unlike @code{__has_feature}, ++@code{__has_extension} tests whether a given feature is available regardless of ++strict language standards conformance. ++ ++If the @option{-pedantic-errors} flag is given, @code{__has_extension} is ++equivalent to @code{__has_feature}. ++ ++Note that @code{__has_feature} and @code{__has_extension} are not recommended ++for use in new code, and are only provided for compatibility with Clang. For ++details of which identifiers are accepted by these function-like macros, see ++@w{@uref{https://clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension, ++the Clang documentation}}. ++ + @node @code{__has_include} + @subsection @code{__has_include} + @cindex @code{__has_include} +diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi +index 0eb9bdcfac5..1a94cf3b3a2 100644 +--- a/gcc/doc/extend.texi ++++ b/gcc/doc/extend.texi +@@ -23796,7 +23796,7 @@ attribute, do change the value of preprocessor macros like + + The following pragmas are available for all architectures running the + Darwin operating system. These are useful for compatibility with other +-Mac OS compilers. ++macOS compilers. + + @table @code + @item mark @var{tokens}@dots{} +@@ -24975,7 +24975,7 @@ compiled separately. + @end table + + G++ implements the Borland model on targets where the linker supports it, +-including ELF targets (such as GNU/Linux), Mac OS X and Microsoft Windows. ++including ELF targets (such as GNU/Linux), macOS and Microsoft Windows. + Otherwise G++ implements neither automatic model. + + You have the following options for dealing with template instantiations: +diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi +index d488b768987..5f7d1878bca 100644 +--- a/gcc/doc/install.texi ++++ b/gcc/doc/install.texi +@@ -1031,14 +1031,26 @@ code. + + @item --enable-host-shared + Specify that the @emph{host} code should be built into position-independent +-machine code (with -fPIC), allowing it to be used within shared libraries, +-but yielding a slightly slower compiler. ++machine code (with @option{-fPIC}), allowing it to be used within shared ++libraries, but yielding a slightly slower compiler. + + This option is required when building the libgccjit.so library. + + Contrast with @option{--enable-shared}, which affects @emph{target} + libraries. + ++@item --enable-host-pie ++Specify that the @emph{host} executables should be built into ++position-independent executables (with @option{-fPIE} and @option{-pie}), ++yielding a slightly slower compiler (but faster than ++@option{--enable-host-shared}). Position-independent executables are loaded ++at random addresses each time they are executed, therefore provide additional ++protection against Return Oriented Programming (ROP) attacks. ++ ++@option{--enable-host-pie}) may be used with @option{--enable-host-shared}), ++in which case @option{-fPIC} is used when compiling, and @option{-pie} when ++linking. ++ + @item @anchor{with-gnu-as}--with-gnu-as + Specify that the compiler should assume that the + assembler it finds is the GNU assembler. However, this does not modify +@@ -1721,6 +1733,12 @@ particularly useful if you intend to use several versions of GCC in + parallel. The default is @samp{yes} for @samp{libada}, and @samp{no} for + the remaining libraries. + ++@item --with-darwin-extra-rpath ++This is provided to allow distributions to add a single additional ++runpath on Darwin / macOS systems. This allows for cases where the ++installed GCC library directories are then symlinked to a common ++directory outside of the GCC installation. ++ + @item @anchor{WithAixSoname}--with-aix-soname=@samp{aix}, @samp{svr4} or @samp{both} + Traditional AIX shared library versioning (versioned @code{Shared Object} + files as members of unversioned @code{Archive Library} files named +diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi +index c83f667260e..d42de5518b7 100644 +--- a/gcc/doc/invoke.texi ++++ b/gcc/doc/invoke.texi +@@ -252,7 +252,8 @@ in the following sections. + -Wdelete-non-virtual-dtor -Wno-deprecated-array-compare @gol + -Wdeprecated-copy -Wdeprecated-copy-dtor @gol + -Wno-deprecated-enum-enum-conversion -Wno-deprecated-enum-float-conversion @gol +--Weffc++ -Wno-exceptions -Wextra-semi -Wno-inaccessible-base @gol ++-Weffc++ -Wno-elaborated-enum-base -Wno-exceptions -Wextra-semi @gol ++-Wno-inaccessible-base @gol + -Wno-inherited-variadic-ctor -Wno-init-list-lifetime @gol + -Winvalid-imported-macros @gol + -Wno-invalid-offsetof -Wno-literal-suffix @gol +@@ -680,7 +681,7 @@ Objective-C and Objective-C++ Dialects}. + -fverbose-asm -fpack-struct[=@var{n}] @gol + -fleading-underscore -ftls-model=@var{model} @gol + -fstack-reuse=@var{reuse_level} @gol +--ftrampolines -ftrapv -fwrapv @gol ++-ftrampolines -ftrampoline-impl=@r{[}stack@r{|}heap@r{]} -ftrapv -fwrapv @gol + -fvisibility=@r{[}default@r{|}internal@r{|}hidden@r{|}protected@r{]} @gol + -fstrict-volatile-bitfields -fsync-libcalls} + +@@ -904,7 +905,7 @@ Objective-C and Objective-C++ Dialects}. + -twolevel_namespace -umbrella -undefined @gol + -unexported_symbols_list -weak_reference_mismatches @gol + -whatsloaded -F -gused -gfull -mmacosx-version-min=@var{version} @gol +--mkernel -mone-byte-bool} ++-mkernel -mone-byte-bool -munreachable-traps} + + @emph{DEC Alpha Options} + @gccoptlist{-mno-fp-regs -msoft-float @gol +@@ -3637,6 +3638,15 @@ to result in dangling pointers. Since the underlying array for an + it is easy to inadvertently keep a pointer to the array past the end + of the array's lifetime. For example: + ++@item -Wno-elaborated-enum-base ++@opindex Welaborated-enum-base ++@opindex Wno-elaborated-enum-base ++For C++11 and above, warn if an (invalid) additional enum-base is used ++in an elaborated-type-specifier. That is, if an enum with given ++underlying type and no enumerator list is used in a declaration other ++than just a standalone declaration of the enum. Enabled by default. This ++warning is upgraded to an error with -pedantic-errors. ++ + @itemize @bullet + @item + If a function returns a temporary @code{initializer_list}, or a local +@@ -4522,7 +4532,7 @@ Use @var{class-name} as the name of the class to instantiate for each + literal string specified with the syntax @code{@@"@dots{}"}. The default + class name is @code{NXConstantString} if the GNU runtime is being used, and + @code{NSConstantString} if the NeXT runtime is being used (see below). On +-Darwin (macOS, MacOS X) platforms, the @option{-fconstant-cfstrings} option, if ++Darwin / macOS platforms, the @option{-fconstant-cfstrings} option, if + also present, overrides the @option{-fconstant-string-class} setting and cause + @code{@@"@dots{}"} literals to be laid out as constant CoreFoundation strings. + Note that @option{-fconstant-cfstrings} is an alias for the target-specific +@@ -4536,7 +4546,7 @@ runtime. This is the default for most types of systems. + @item -fnext-runtime + @opindex fnext-runtime + Generate output compatible with the NeXT runtime. This is the default +-for NeXT-based systems, including Darwin and Mac OS X@. The macro ++for NeXT-based systems, including Darwin / macOS. The macro + @code{__NEXT_RUNTIME__} is predefined if (and only if) this option is + used. + +@@ -5722,8 +5732,45 @@ Give an error whenever the @dfn{base standard} (see @option{-Wpedantic}) + requires a diagnostic, in some cases where there is undefined behavior + at compile-time and in some other cases that do not prevent compilation + of programs that are valid according to the standard. This is not +-equivalent to @option{-Werror=pedantic}, since there are errors enabled +-by this option and not enabled by the latter and vice versa. ++equivalent to @option{-Werror=pedantic}: the latter option is unlikely to be ++useful, as it only makes errors of the diagnostics that are controlled by ++@option{-Wpedantic}, whereas this option also affects required diagnostics that ++are always enabled or controlled by options other than @option{-Wpedantic}. ++ ++If you want the required diagnostics that are warnings by default to ++be errors instead, but don't also want to enable the @option{-Wpedantic} ++diagnostics, you can specify @option{-pedantic-errors -Wno-pedantic} ++(or @option{-pedantic-errors -Wno-error=pedantic} to enable them but ++only as warnings). ++ ++Some required diagnostics are errors by default, but can be reduced to ++warnings using @option{-fpermissive} or their specific warning option, ++e.g. @option{-Wno-error=narrowing}. ++ ++Some diagnostics for non-ISO practices are controlled by specific ++warning options other than @option{-Wpedantic}, but are also made ++errors by @option{-pedantic-errors}. For instance: ++ ++@gccoptlist{ ++-Wattributes @r{(for standard attributes)} ++-Wchanges-meaning @r{(C++)} ++-Wcomma-subscript @r{(C++23 or later)} ++-Wdeclaration-after-statement @r{(C90 or earlier)} ++-Welaborated-enum-base @r{(C++11 or later)} ++-Wimplicit-int @r{(C99 or later)} ++-Wimplicit-function-declaration @r{(C99 or later)} ++-Wincompatible-pointer-types ++-Wint-conversion ++-Wlong-long @r{(C90 or earlier)} ++-Wmain ++-Wnarrowing @r{(C++11 or later)} ++-Wpointer-arith ++-Wpointer-sign ++-Wincompatible-pointer-types ++-Wregister @r{(C++17 or later)} ++-Wvla @r{(C90 or earlier)} ++-Wwrite-strings @r{(C++11 or later)} ++} + + @item -Wall + @opindex Wall +@@ -10292,7 +10339,7 @@ possible. + Produce debugging information in DWARF format (if that is supported). + The value of @var{version} may be either 2, 3, 4 or 5; the default + version for most targets is 5 (with the exception of VxWorks, TPF and +-Darwin/Mac OS X, which default to version 2, and AIX, which defaults ++Darwin / macOS, which default to version 2, and AIX, which defaults + to version 4). + + Note that with DWARF Version 2, some ports require and always +@@ -17080,6 +17127,17 @@ the behavior of older compilers in which temporaries' stack space is + not reused, the aggressive stack reuse can lead to runtime errors. This + option is used to control the temporary stack reuse optimization. + ++@item -fstack-use-cumulative-args ++@opindex fstack_use_cumulative_args ++This option instructs the compiler to use the ++@code{cumulative_args_t}-based stack layout target hooks, ++@code{TARGET_FUNCTION_ARG_BOUNDARY_CA} and ++@code{TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA}. If a given target does ++not define these hooks, the default behaviour is to fallback to using ++the standard non-@code{_CA} variants instead. Certain targets (such as ++AArch64 Darwin) require using the more advanced @code{_CA}-based ++hooks: For these targets this option should be enabled by default. ++ + @item -ftrapv + @opindex ftrapv + This option generates traps for signed overflow on addition, subtraction, +@@ -17565,6 +17623,21 @@ For languages other than Ada, the @code{-ftrampolines} and + trampolines are always generated on platforms that need them + for nested functions. + ++@opindex ftrampoline-impl ++@item -ftrampoline-impl=@r{[}stack@r{|}heap@r{]} ++By default, trampolines are generated on stack. However, certain platforms ++(such as the Apple M1) do not permit an executable stack. Compiling with ++@option{-ftrampoline-impl=heap} generate calls to ++@code{__gcc_nested_func_ptr_created} and ++@code{__gcc_nested_func_ptr_deleted} in order to allocate and ++deallocate trampoline space on the executable heap. These functions are ++implemented in libgcc, and will only be provided on specific targets: ++x86_64 Darwin, x86_64 and aarch64 Linux. @emph{PLEASE NOTE}: Heap ++trampolines are @emph{not} guaranteed to be correctly deallocated if you ++@code{setjmp}, instantiate nested functions, and then @code{longjmp} back ++to a state prior to having allocated those nested functions. ++ ++@opindex fvisibility + @item -fvisibility=@r{[}default@r{|}internal@r{|}hidden@r{|}protected@r{]} + @opindex fvisibility + Set the default ELF image symbol visibility to the specified option---all +@@ -22850,6 +22923,12 @@ without that switch. Using this switch may require recompiling all + other modules in a program, including system libraries. Use this + switch to conform to a non-default data model. + ++@item -munreachable-traps ++@itemx -munreachable-traps ++@opindex munreachable-traps ++Causes @code{__builtin_unreachable} to be rendered as a trap. This is the ++default for all Darwin architectures. ++ + @item -mfix-and-continue + @itemx -ffix-and-continue + @itemx -findirect-data +@@ -22896,6 +22975,14 @@ an executable when linking, using the Darwin @file{libtool} command. + This causes GCC's output file to have the @samp{ALL} subtype, instead of + one controlled by the @option{-mcpu} or @option{-march} option. + ++@opindex nodefaultrpaths ++@item -nodefaultrpaths ++Do not add default run paths for the compiler library directories to ++executables, modules or dynamic libraries. On macOS 10.5 and later, ++the embedded runpath is added by default unless the user adds ++@option{-nodefaultrpaths} to the link line. Run paths are needed ++(and therefore enforced) to build on macOS version 10.11 or later. ++ + @item -allowable_client @var{client_name} + @itemx -client_name + @itemx -compatibility_version +@@ -28806,7 +28893,7 @@ the same as @option{-mbig}. + + @item -mdynamic-no-pic + @opindex mdynamic-no-pic +-On Darwin and Mac OS X systems, compile code so that it is not ++On Darwin / macOS systems, compile code so that it is not + relocatable, but that its external references are relocatable. The + resulting code is suitable for applications, but not shared + libraries. +diff --git a/gcc/doc/plugins.texi b/gcc/doc/plugins.texi +index 6d1a5fa7607..b978fb415c6 100644 +--- a/gcc/doc/plugins.texi ++++ b/gcc/doc/plugins.texi +@@ -44,7 +44,7 @@ Plugins are loaded with + + Where @var{name} is the plugin name and @var{ext} is the platform-specific + dynamic library extension. It should be @code{dll} on Windows/MinGW, +-@code{dylib} on Darwin/Mac OS X, and @code{so} on all other platforms. ++@code{dylib} on Darwin/macOS, and @code{so} on all other platforms. + The plugin arguments are parsed by GCC and passed to respective + plugins as key-value pairs. Multiple plugins can be invoked by + specifying multiple @option{-fplugin} arguments. +diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi +index c5006afc00d..c44c4ff1978 100644 +--- a/gcc/doc/tm.texi ++++ b/gcc/doc/tm.texi +@@ -1025,6 +1025,10 @@ also define the hook to @code{default_promote_function_mode_always_promote} + if you would like to apply the same rules given by @code{PROMOTE_MODE}. + @end deftypefn + ++@deftypefn {Target Hook} machine_mode TARGET_PROMOTE_FUNCTION_MODE_CA (cumulative_args_t, @var{function_arg_info}, @var{const_tree}, int *@var{}, @var{int}) ++Like @code{promote_function_mode}, but takes a cumulative_args pointer and a current arg to supply the input. ++@end deftypefn ++ + @defmac PARM_BOUNDARY + Normal alignment required for function parameters on the stack, in + bits. All stack parameters receive at least this much alignment +@@ -4322,6 +4326,16 @@ with the specified mode and type. The default hook returns + @code{PARM_BOUNDARY} for all arguments. + @end deftypefn + ++@deftypefn {Target Hook} {unsigned int} TARGET_FUNCTION_ARG_BOUNDARY_CA (machine_mode @var{mode}, const_tree @var{type}, cumulative_args_t @var{ca}) ++This is the @code{cumulative_args_t}-based version of ++@code{TARGET_FUNCTION_ARG_BOUNDARY}. Define this hook if you need more ++fine-grained control over argument alignment, e.g. depending on whether ++it is a named argument or not, or any other criteria that you choose to ++place in the @var{ca} structure. ++ ++The default hook will call @code{TARGET_FUNCTION_ARG_BOUNDARY}. ++@end deftypefn ++ + @deftypefn {Target Hook} {unsigned int} TARGET_FUNCTION_ARG_ROUND_BOUNDARY (machine_mode @var{mode}, const_tree @var{type}) + Normally, the size of an argument is rounded up to @code{PARM_BOUNDARY}, + which is the default value for this hook. You can define this hook to +@@ -4329,6 +4343,16 @@ return a different value if an argument size must be rounded to a larger + value. + @end deftypefn + ++@deftypefn {Target Hook} {unsigned int} TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA (machine_mode @var{mode}, const_tree @var{type}, cumulative_args_t @var{ca}) ++This is the @code{cumulative_args_t}-based version of ++@code{TARGET_FUNCTION_ARG_ROUND_BOUNDARY}. Define this hook if you need more ++fine-grained control over argument size rounding, e.g. depending on whether ++it is a named argument or not, or any other criteria that you choose to ++place in the @var{ca} structure. ++ ++The default hook will call @code{TARGET_FUNCTION_ARG_ROUND_BOUNDARY}. ++@end deftypefn ++ + @defmac FUNCTION_ARG_REGNO_P (@var{regno}) + A C expression that is nonzero if @var{regno} is the number of a hard + register in which function arguments are sometimes passed. This does +@@ -5728,7 +5752,7 @@ This hook determines whether a function from a class of functions + Set this macro to 1 to use the "NeXT" Objective-C message sending conventions + by default. This calling convention involves passing the object, the selector + and the method arguments all at once to the method-lookup library function. +-This is the usual setting when targeting Darwin/Mac OS X systems, which have ++This is the usual setting when targeting Darwin / macOS systems, which have + the NeXT runtime installed. + + If the macro is set to 0, the "GNU" Objective-C message sending convention +@@ -12527,6 +12551,11 @@ This target hook can be used to generate a target-specific code + If selftests are enabled, run any selftests for this target. + @end deftypefn + ++@deftypefn {Target Hook} bool TARGET_UNREACHABLE_SHOULD_TRAP (void) ++This hook should return @code{true} if the target wants @code{__builtin_unreachable} to expand to a trap or @code{abort ()}. ++ The default value is false. ++@end deftypefn ++ + @deftypefn {Target Hook} bool TARGET_MEMTAG_CAN_TAG_ADDRESSES () + True if the backend architecture naturally supports ignoring some region + of pointers. This feature means that @option{-fsanitize=hwaddress} can +diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in +index f869ddd5e5b..7fb14849efc 100644 +--- a/gcc/doc/tm.texi.in ++++ b/gcc/doc/tm.texi.in +@@ -935,6 +935,8 @@ applied. + + @hook TARGET_PROMOTE_FUNCTION_MODE + ++@hook TARGET_PROMOTE_FUNCTION_MODE_CA ++ + @defmac PARM_BOUNDARY + Normal alignment required for function parameters on the stack, in + bits. All stack parameters receive at least this much alignment +@@ -3330,8 +3332,12 @@ required. + + @hook TARGET_FUNCTION_ARG_BOUNDARY + ++@hook TARGET_FUNCTION_ARG_BOUNDARY_CA ++ + @hook TARGET_FUNCTION_ARG_ROUND_BOUNDARY + ++@hook TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA ++ + @defmac FUNCTION_ARG_REGNO_P (@var{regno}) + A C expression that is nonzero if @var{regno} is the number of a hard + register in which function arguments are sometimes passed. This does +@@ -3997,7 +4003,7 @@ macro, a reasonable default is used. + Set this macro to 1 to use the "NeXT" Objective-C message sending conventions + by default. This calling convention involves passing the object, the selector + and the method arguments all at once to the method-lookup library function. +-This is the usual setting when targeting Darwin/Mac OS X systems, which have ++This is the usual setting when targeting Darwin / macOS systems, which have + the NeXT runtime installed. + + If the macro is set to 0, the "GNU" Objective-C message sending convention +@@ -8164,6 +8170,8 @@ maintainer is familiar with. + + @hook TARGET_RUN_TARGET_SELFTESTS + ++@hook TARGET_UNREACHABLE_SHOULD_TRAP ++ + @hook TARGET_MEMTAG_CAN_TAG_ADDRESSES + + @hook TARGET_MEMTAG_TAG_SIZE +diff --git a/gcc/exec-tool.in b/gcc/exec-tool.in +index cf7222745fb..2b98aa14551 100644 +--- a/gcc/exec-tool.in ++++ b/gcc/exec-tool.in +@@ -23,6 +23,8 @@ ORIGINAL_AS_FOR_TARGET="@ORIGINAL_AS_FOR_TARGET@" + ORIGINAL_LD_FOR_TARGET="@ORIGINAL_LD_FOR_TARGET@" + ORIGINAL_LD_BFD_FOR_TARGET="@ORIGINAL_LD_BFD_FOR_TARGET@" + ORIGINAL_LD_GOLD_FOR_TARGET="@ORIGINAL_LD_GOLD_FOR_TARGET@" ++ORIGINAL_LLD_FOR_TARGET="@ORIGINAL_LLD_FOR_TARGET@" ++ORIGINAL_CLASSIC_LD_FOR_TARGET="@ORIGINAL_CLASSIC_LD_FOR_TARGET@" + ORIGINAL_PLUGIN_LD_FOR_TARGET="@ORIGINAL_PLUGIN_LD_FOR_TARGET@" + ORIGINAL_NM_FOR_TARGET="@ORIGINAL_NM_FOR_TARGET@" + ORIGINAL_DSYMUTIL_FOR_TARGET="@ORIGINAL_DSYMUTIL_FOR_TARGET@" +@@ -39,24 +41,41 @@ case "$invoked" in + dir=gas + ;; + collect-ld) +- # Check -fuse-ld=bfd and -fuse-ld=gold +- case " $* " in +- *\ -fuse-ld=bfd\ *) +- original=$ORIGINAL_LD_BFD_FOR_TARGET +- ;; +- *\ -fuse-ld=gold\ *) +- original=$ORIGINAL_LD_GOLD_FOR_TARGET +- ;; +- *) +- # when using a linker plugin, gcc will always pass '-plugin' as the +- # first or second option to the linker. +- if test x"$1" = "x-plugin" || test x"$2" = "x-plugin"; then +- original=$ORIGINAL_PLUGIN_LD_FOR_TARGET +- else +- original=$ORIGINAL_LD_FOR_TARGET +- fi +- ;; +- esac ++ # when using a linker plugin, gcc will always pass '-plugin' as the ++ # first or second option to the linker. ++ if test x"$1" = "x-plugin" || test x"$2" = "x-plugin"; then ++ original=$ORIGINAL_PLUGIN_LD_FOR_TARGET ++ else ++ original=$ORIGINAL_LD_FOR_TARGET ++ fi ++ # Check -fuse-ld=bfd, -fuse-ld=gold and -fuse-ld=classic ++ # Remove -fuse-ld=classic from the command line ++ for arg do ++ # temporarily, remove the arg. ++ shift ++ case $arg in ++ -fuse-ld=bfd) ++ original=$ORIGINAL_LD_BFD_FOR_TARGET ++ ;; ++ -fuse-ld=gold) ++ original=$ORIGINAL_LD_GOLD_FOR_TARGET ++ ;; ++ -fuse-ld=lld) ++ original=$ORIGINAL_LLD_FOR_TARGET ++ # We want to remove this from the command line; by the slightly ++ # obtuse mechanism of not putting it back. ++ continue ++ ;; ++ -fuse-ld=classic) ++ original=$ORIGINAL_CLASSIC_LD_FOR_TARGET ++ # As for lld. ++ continue ++ ;; ++ *) ;; ++ esac ++ # if we want to keep the arg, put it back. ++ set -- "$@" "$arg" ++ done + prog=ld-new$exeext + if test "$original" = ../gold/ld-new$exeext; then + dir=gold +diff --git a/gcc/explow.cc b/gcc/explow.cc +index d8aa75ee9ba..2695b6afc9d 100644 +--- a/gcc/explow.cc ++++ b/gcc/explow.cc +@@ -37,6 +37,7 @@ along with GCC; see the file COPYING3. If not see + #include "langhooks.h" + #include "except.h" + #include "dojump.h" ++#include "calls.h" + #include "explow.h" + #include "expr.h" + #include "stringpool.h" +@@ -817,6 +818,16 @@ promote_function_mode (const_tree type, machine_mode mode, int *punsignedp, + return mode; + } + } ++ ++machine_mode ++promote_function_mode (cumulative_args_t args_so_far, function_arg_info arg, ++ const_tree funtype, int *punsignedp , int for_return) ++{ ++ return targetm.calls.promote_function_mode_ca (args_so_far, arg, funtype, ++ punsignedp, for_return); ++// return promote_function_mode (arg.type, arg.mode, punsignedp, funtype, for_return); ++} ++ + /* Return the mode to use to store a scalar of TYPE and MODE. + PUNSIGNEDP points to the signedness of the type and may be adjusted + to show what signedness to use on extension operations. */ +diff --git a/gcc/explow.h b/gcc/explow.h +index 2b9f7e43215..159da9ac642 100644 +--- a/gcc/explow.h ++++ b/gcc/explow.h +@@ -20,6 +20,8 @@ along with GCC; see the file COPYING3. If not see + #ifndef GCC_EXPLOW_H + #define GCC_EXPLOW_H + ++#include "calls.h" /* for cummulative args stuff. */ ++ + /* Return a memory reference like MEMREF, but which is known to have a + valid address. */ + extern rtx validize_mem (rtx); +@@ -47,8 +49,13 @@ extern rtx force_not_mem (rtx); + + /* Return mode and signedness to use when an argument or result in the + given mode is promoted. */ +-extern machine_mode promote_function_mode (const_tree, machine_mode, int *, +- const_tree, int); ++machine_mode promote_function_mode (const_tree, machine_mode, int *, ++ const_tree, int); ++ ++/* Return mode and signedness to use when an argument or result in the ++ given mode is promoted. */ ++machine_mode promote_function_mode (cumulative_args_t, function_arg_info, ++ const_tree, int *, int); + + /* Return mode and signedness to use when an object in the given mode + is promoted. */ +diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi +index d34e0b5e8f9..b895d99be69 100644 +--- a/gcc/fortran/gfortran.texi ++++ b/gcc/fortran/gfortran.texi +@@ -978,7 +978,7 @@ low level file descriptor corresponding to an open Fortran unit. Then, + using e.g. the @code{ISO_C_BINDING} feature, one can call the + underlying system call to flush dirty data to stable storage, such as + @code{fsync} on POSIX, @code{_commit} on MingW, or @code{fcntl(fd, +-F_FULLSYNC, 0)} on Mac OS X. The following example shows how to call ++F_FULLSYNC, 0)} on macOS. The following example shows how to call + fsync: + + @smallexample +diff --git a/gcc/function.cc b/gcc/function.cc +index d84a3240ee1..8ea53c3418e 100644 +--- a/gcc/function.cc ++++ b/gcc/function.cc +@@ -58,8 +58,8 @@ along with GCC; see the file COPYING3. If not see + #include "varasm.h" + #include "except.h" + #include "dojump.h" +-#include "explow.h" + #include "calls.h" ++#include "explow.h" + #include "expr.h" + #include "optabs-tree.h" + #include "output.h" +@@ -2445,7 +2445,10 @@ assign_parm_find_data_types (struct assign_parm_data_all *all, tree parm, + else if (DECL_CHAIN (parm)) + data->arg.named = 1; /* Not the last non-variadic parm. */ + else if (targetm.calls.strict_argument_naming (all->args_so_far)) +- data->arg.named = 1; /* Only variadic ones are unnamed. */ ++ { ++ data->arg.named = 1; /* Only variadic ones are unnamed. */ ++ data->arg.last_named = 1; ++ } + else + data->arg.named = 0; /* Treat as variadic. */ + +@@ -2487,9 +2490,12 @@ assign_parm_find_data_types (struct assign_parm_data_all *all, tree parm, + + /* Find mode as it is passed by the ABI. */ + unsignedp = TYPE_UNSIGNED (data->arg.type); +- data->arg.mode +- = promote_function_mode (data->arg.type, data->arg.mode, &unsignedp, +- TREE_TYPE (current_function_decl), 0); ++// data->arg.mode ++// = promote_function_mode (data->arg.type, data->arg.mode, &unsignedp, ++// TREE_TYPE (current_function_decl), 0); ++ data->arg.mode = promote_function_mode (all->args_so_far, data->arg, ++ TREE_TYPE (current_function_decl), ++ &unsignedp, 0); + } + + /* A subroutine of assign_parms. Invoke setup_incoming_varargs. */ +@@ -2502,6 +2508,7 @@ assign_parms_setup_varargs (struct assign_parm_data_all *all, + + function_arg_info last_named_arg = data->arg; + last_named_arg.named = true; ++ last_named_arg.last_named = true; + targetm.calls.setup_incoming_varargs (all->args_so_far, last_named_arg, + &varargs_pretend_bytes, no_rtl); + +@@ -2610,7 +2617,9 @@ assign_parm_find_entry_rtl (struct assign_parm_data_all *all, + + locate_and_pad_parm (data->arg.mode, data->arg.type, in_regs, + all->reg_parm_stack_space, +- entry_parm ? data->partial : 0, current_function_decl, ++ entry_parm ? data->partial : 0, ++ all->args_so_far, ++ current_function_decl, + &all->stack_args_size, &data->locate); + + /* Update parm_stack_boundary if this parameter is passed in the +@@ -3924,7 +3933,8 @@ gimplify_parameters (gimple_seq *cleanup) + if (data.arg.pass_by_reference) + { + tree type = TREE_TYPE (data.arg.type); +- function_arg_info orig_arg (type, data.arg.named); ++ function_arg_info orig_arg (type, data.arg.named, ++ data.arg.last_named); + if (reference_callee_copied (&all.args_so_far_v, orig_arg)) + { + tree local, t; +@@ -4027,6 +4037,7 @@ gimplify_parameters (gimple_seq *cleanup) + void + locate_and_pad_parm (machine_mode passed_mode, tree type, int in_regs, + int reg_parm_stack_space, int partial, ++ cumulative_args_t ca, + tree fndecl ATTRIBUTE_UNUSED, + struct args_size *initial_offset_ptr, + struct locate_and_pad_arg_data *locate) +@@ -4064,9 +4075,23 @@ locate_and_pad_parm (machine_mode passed_mode, tree type, int in_regs, + ? arg_size_in_bytes (type) + : size_int (GET_MODE_SIZE (passed_mode))); + where_pad = targetm.calls.function_arg_padding (passed_mode, type); +- boundary = targetm.calls.function_arg_boundary (passed_mode, type); +- round_boundary = targetm.calls.function_arg_round_boundary (passed_mode, +- type); ++ ++ if (flag_stack_use_cumulative_args) ++ { ++ boundary = targetm.calls.function_arg_boundary_ca (passed_mode, ++ type, ++ ca); ++ round_boundary = targetm.calls.function_arg_round_boundary_ca ++ (passed_mode, type, ca); ++ } ++ else ++ { ++ boundary = targetm.calls.function_arg_boundary (passed_mode, ++ type); ++ round_boundary = targetm.calls.function_arg_round_boundary ++ (passed_mode, type); ++ } ++ + locate->where_pad = where_pad; + + /* Alignment can't exceed MAX_SUPPORTED_STACK_ALIGNMENT. */ +diff --git a/gcc/function.h b/gcc/function.h +index a53fb24d217..4dc16c64717 100644 +--- a/gcc/function.h ++++ b/gcc/function.h +@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3. If not see + #ifndef GCC_FUNCTION_H + #define GCC_FUNCTION_H + ++#include "cumulative-args.h" + + /* Stack of pending (incomplete) sequences saved by `start_sequence'. + Each element describes one pending sequence. +@@ -661,6 +662,7 @@ extern int aggregate_value_p (const_tree, const_tree); + extern bool use_register_for_decl (const_tree); + extern gimple_seq gimplify_parameters (gimple_seq *); + extern void locate_and_pad_parm (machine_mode, tree, int, int, int, ++ cumulative_args_t, + tree, struct args_size *, + struct locate_and_pad_arg_data *); + extern void generate_setjmp_warnings (void); +diff --git a/gcc/gcc.cc b/gcc/gcc.cc +index fbcc9d03314..bd2b90ce16f 100644 +--- a/gcc/gcc.cc ++++ b/gcc/gcc.cc +@@ -574,6 +574,7 @@ or with constant text in a single argument. + %l process LINK_SPEC as a spec. + %L process LIB_SPEC as a spec. + %M Output multilib_os_dir. ++ %P Output a RUNPATH_OPTION for each directory in startfile_prefixes. + %G process LIBGCC_SPEC as a spec. + %R Output the concatenation of target_system_root and + target_sysroot_suffix. +@@ -1193,6 +1194,10 @@ proper position among the other output files. */ + # define SYSROOT_HEADERS_SUFFIX_SPEC "" + #endif + ++#ifndef RUNPATH_OPTION ++# define RUNPATH_OPTION "-rpath" ++#endif ++ + static const char *asm_debug = ASM_DEBUG_SPEC; + static const char *asm_debug_option = ASM_DEBUG_OPTION_SPEC; + static const char *cpp_spec = CPP_SPEC; +@@ -5897,6 +5902,7 @@ struct spec_path_info { + size_t append_len; + bool omit_relative; + bool separate_options; ++ bool realpaths; + }; + + static void * +@@ -5906,6 +5912,16 @@ spec_path (char *path, void *data) + size_t len = 0; + char save = 0; + ++ /* The path must exist; we want to resolve it to the realpath so that this ++ can be embedded as a runpath. */ ++ if (info->realpaths) ++ path = lrealpath (path); ++ ++ /* However, if we failed to resolve it - perhaps because there was a bogus ++ -B option on the command line, then punt on this entry. */ ++ if (!path) ++ return NULL; ++ + if (info->omit_relative && !IS_ABSOLUTE_PATH (path)) + return NULL; + +@@ -6137,6 +6153,22 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part) + info.omit_relative = false; + #endif + info.separate_options = false; ++ info.realpaths = false; ++ ++ for_each_path (&startfile_prefixes, true, 0, spec_path, &info); ++ } ++ break; ++ ++ case 'P': ++ { ++ struct spec_path_info info; ++ ++ info.option = RUNPATH_OPTION; ++ info.append_len = 0; ++ info.omit_relative = false; ++ info.separate_options = true; ++ /* We want to embed the actual paths that have the libraries. */ ++ info.realpaths = true; + + for_each_path (&startfile_prefixes, true, 0, spec_path, &info); + } +@@ -6463,6 +6495,7 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part) + info.append_len = strlen (info.append); + info.omit_relative = false; + info.separate_options = true; ++ info.realpaths = false; + + for_each_path (&include_prefixes, false, info.append_len, + spec_path, &info); +diff --git a/gcc/ginclude/stddef.h b/gcc/ginclude/stddef.h +index 79e296d4a66..a9caa0467ba 100644 +--- a/gcc/ginclude/stddef.h ++++ b/gcc/ginclude/stddef.h +@@ -427,9 +427,8 @@ typedef struct { + /* _Float128 is defined as a basic type, so max_align_t must be + sufficiently aligned for it. This code must work in C++, so we + use __float128 here; that is only available on some +- architectures, but only on i386 is extra alignment needed for +- __float128. */ +-#ifdef __i386__ ++ architectures. */ ++#if defined(__i386__) || (__APPLE__ && __aarch64__) + __float128 __max_align_f128 __attribute__((__aligned__(__alignof(__float128)))); + #endif + } max_align_t; +diff --git a/gcc/jit/Make-lang.in b/gcc/jit/Make-lang.in +index 33ed7e357a2..e78a496de89 100644 +--- a/gcc/jit/Make-lang.in ++++ b/gcc/jit/Make-lang.in +@@ -69,7 +69,7 @@ LIBGCCJIT_COMPAT = 0 + LIBGCCJIT_BASENAME = libgccjit + + LIBGCCJIT_SONAME = \ +- ${libdir}/$(LIBGCCJIT_BASENAME).$(LIBGCCJIT_VERSION_NUM).dylib ++ $(DARWIN_RPATH)/$(LIBGCCJIT_BASENAME).$(LIBGCCJIT_VERSION_NUM).dylib + LIBGCCJIT_FILENAME = $(LIBGCCJIT_BASENAME).$(LIBGCCJIT_VERSION_NUM).dylib + LIBGCCJIT_LINKER_NAME = $(LIBGCCJIT_BASENAME).dylib + +diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc +index 79714132b91..a475379671e 100644 +--- a/gcc/jit/jit-playback.cc ++++ b/gcc/jit/jit-playback.cc +@@ -3000,7 +3000,7 @@ invoke_driver (const char *ctxt_progname, + ADD_ARG ("-fno-use-linker-plugin"); + + #if defined (DARWIN_X86) || defined (DARWIN_PPC) +- /* OS X's linker defaults to treating undefined symbols as errors. ++ /* macOS's linker defaults to treating undefined symbols as errors. + If the context has any imported functions or globals they will be + undefined until the .so is dynamically-linked into the process. + Ensure that the driver passes in "-undefined dynamic_lookup" to the +diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h +index b3c389e93f6..925c5c23c0c 100644 +--- a/gcc/jit/libgccjit.h ++++ b/gcc/jit/libgccjit.h +@@ -21,6 +21,9 @@ along with GCC; see the file COPYING3. If not see + #define LIBGCCJIT_H + + #include ++#ifdef __APPLE__ ++# include /* For ssize_t. */ ++#endif + + #ifdef __cplusplus + extern "C" { +diff --git a/gcc/objc/objc-act.cc b/gcc/objc/objc-act.cc +index 4820c5dbac3..ba98ff0b85d 100644 +--- a/gcc/objc/objc-act.cc ++++ b/gcc/objc/objc-act.cc +@@ -3319,7 +3319,7 @@ objc_build_string_object (tree string) + length = TREE_STRING_LENGTH (string) - 1; + + /* The target may have different ideas on how to construct an ObjC string +- literal. On Darwin (Mac OS X), for example, we may wish to obtain a ++ literal. On Darwin / macOS, for example, we may wish to obtain a + constant CFString reference instead. + At present, this is only supported for the NeXT runtime. */ + if (flag_next_runtime +@@ -10364,5 +10364,51 @@ objc_common_tree_size (enum tree_code code) + } + } + ++/* Information for Objective-C-specific features known to __has_feature. */ ++ ++struct objc_feature_info ++{ ++ typedef bool (*predicate_t) (); ++ ++ const char *ident; ++ predicate_t predicate; ++ ++ constexpr objc_feature_info (const char *name) ++ : ident (name), predicate (nullptr) {} ++ constexpr objc_feature_info (const char *name, predicate_t p) ++ : ident (name), predicate (p) {} ++ ++ bool has_feature () const ++ { ++ return predicate ? predicate () : true; ++ } ++}; ++ ++static bool objc_nonfragile_abi_p () ++{ ++ return flag_next_runtime && flag_objc_abi >= 2; ++} ++ ++static constexpr objc_feature_info objc_features[] = ++{ ++ { "objc_default_synthesize_properties" }, ++ { "objc_instancetype" }, ++ { "objc_nonfragile_abi", objc_nonfragile_abi_p } ++}; ++ ++/* Register Objective-C-specific features for __has_feature. */ ++ ++void ++objc_common_register_features () ++{ ++ for (unsigned i = 0; i < ARRAY_SIZE (objc_features); i++) ++ { ++ const objc_feature_info *info = objc_features + i; ++ if (!info->has_feature ()) ++ continue; ++ ++ c_common_register_feature (info->ident, true); ++ } ++} + + #include "gt-objc-objc-act.h" +diff --git a/gcc/objc/objc-act.h b/gcc/objc/objc-act.h +index 7d0c6d5077f..62f0f440cf4 100644 +--- a/gcc/objc/objc-act.h ++++ b/gcc/objc/objc-act.h +@@ -28,6 +28,9 @@ const char *objc_printable_name (tree, int); + int objc_gimplify_expr (tree *, gimple_seq *, gimple_seq *); + void objc_common_init_ts (void); + ++/* Register features common to Objective-C and Objective-C++. */ ++void objc_common_register_features (); ++ + /* NB: The remaining public functions are prototyped in c-common.h, for the + benefit of stub-objc.cc and objc-act.cc. */ + +diff --git a/gcc/objc/objc-lang.cc b/gcc/objc/objc-lang.cc +index ef664f555b0..3fd7b0f9265 100644 +--- a/gcc/objc/objc-lang.cc ++++ b/gcc/objc/objc-lang.cc +@@ -50,6 +50,16 @@ enum c_language_kind c_language = clk_objc; + /* Each front end provides its own lang hook initializer. */ + struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER; + ++/* Implement c-family hook to add language-specific features ++ for __has_{feature,extension}. */ ++ ++void ++c_family_register_lang_features () ++{ ++ objc_common_register_features (); ++ c_register_features (); ++} ++ + /* Lang hook routines common to C and ObjC appear in c-objc-common.cc; + there should be very few (if any) routines below. */ + +diff --git a/gcc/objcp/objcp-lang.cc b/gcc/objcp/objcp-lang.cc +index 2e8809b865d..6582460e1a9 100644 +--- a/gcc/objcp/objcp-lang.cc ++++ b/gcc/objcp/objcp-lang.cc +@@ -82,6 +82,16 @@ objcp_tsubst_copy_and_build (tree t, tree args, tsubst_flags_t complain, + #undef RECURSE + } + ++/* Implement c-family hook to add language-specific features ++ for __has_{feature,extension}. */ ++ ++void ++c_family_register_lang_features () ++{ ++ objc_common_register_features (); ++ cp_register_features (); ++} ++ + static void + objcxx_init_ts (void) + { +diff --git a/gcc/opts.cc b/gcc/opts.cc +index a97630d1c9a..40cf287cc69 100644 +--- a/gcc/opts.cc ++++ b/gcc/opts.cc +@@ -3147,6 +3147,7 @@ common_handle_option (struct gcc_options *opts, + break; + + case OPT_fuse_ld_bfd: ++ case OPT_fuse_ld_classic: + case OPT_fuse_ld_gold: + case OPT_fuse_ld_lld: + case OPT_fuse_ld_mold: +diff --git a/gcc/plugin.cc b/gcc/plugin.cc +index cbe4b7eff60..d30634bde9c 100644 +--- a/gcc/plugin.cc ++++ b/gcc/plugin.cc +@@ -189,10 +189,10 @@ add_new_plugin (const char* plugin_name) + #if defined(__MINGW32__) + static const char plugin_ext[] = ".dll"; + #elif defined(__APPLE__) +- /* Mac OS has two types of libraries: dynamic libraries (.dylib) and ++ /* macOS has two types of libraries: dynamic libraries (.dylib) and + plugins (.bundle). Both can be used with dlopen()/dlsym() but the + former cannot be linked at build time (i.e., with the -lfoo linker +- option). A GCC plugin is therefore probably a Mac OS plugin but their ++ option). A GCC plugin is therefore probably a macOS plugin but their + use seems to be quite rare and the .bundle extension is more of a + recommendation rather than the rule. This raises the questions of how + well they are supported by tools (e.g., libtool). So to avoid +diff --git a/gcc/target.def b/gcc/target.def +index d85adf36a39..0f5667500a4 100644 +--- a/gcc/target.def ++++ b/gcc/target.def +@@ -4551,6 +4551,13 @@ if you would like to apply the same rules given by @code{PROMOTE_MODE}.", + const_tree funtype, int for_return), + default_promote_function_mode) + ++DEFHOOK ++(promote_function_mode_ca, ++ "Like @code{promote_function_mode}, but takes a cumulative_args pointer \ ++ and a current arg to supply the input.", ++ machine_mode, (cumulative_args_t, function_arg_info, const_tree, int *, int), ++ default_promote_function_mode_ca) ++ + DEFHOOK + (promote_prototypes, + "This target hook returns @code{true} if an argument declared in a\n\ +@@ -4967,6 +4974,18 @@ with the specified mode and type. The default hook returns\n\ + unsigned int, (machine_mode mode, const_tree type), + default_function_arg_boundary) + ++DEFHOOK ++(function_arg_boundary_ca, ++ "This is the @code{cumulative_args_t}-based version of\n\ ++@code{TARGET_FUNCTION_ARG_BOUNDARY}. Define this hook if you need more\n\ ++fine-grained control over argument alignment, e.g. depending on whether\n\ ++it is a named argument or not, or any other criteria that you choose to\n\ ++place in the @var{ca} structure.\n\ ++\n\ ++The default hook will call @code{TARGET_FUNCTION_ARG_BOUNDARY}.", ++ unsigned int, (machine_mode mode, const_tree type, cumulative_args_t ca), ++ default_function_arg_boundary_ca) ++ + DEFHOOK + (function_arg_round_boundary, + "Normally, the size of an argument is rounded up to @code{PARM_BOUNDARY},\n\ +@@ -4976,6 +4995,18 @@ value.", + unsigned int, (machine_mode mode, const_tree type), + default_function_arg_round_boundary) + ++DEFHOOK ++(function_arg_round_boundary_ca, ++ "This is the @code{cumulative_args_t}-based version of\n\ ++@code{TARGET_FUNCTION_ARG_ROUND_BOUNDARY}. Define this hook if you need more\n\ ++fine-grained control over argument size rounding, e.g. depending on whether\n\ ++it is a named argument or not, or any other criteria that you choose to\n\ ++place in the @var{ca} structure.\n\ ++\n\ ++The default hook will call @code{TARGET_FUNCTION_ARG_ROUND_BOUNDARY}.", ++ unsigned int, (machine_mode mode, const_tree type, cumulative_args_t ca), ++ default_function_arg_round_boundary_ca) ++ + /* Return the diagnostic message string if function without a prototype + is not allowed for this 'val' argument; NULL otherwise. */ + DEFHOOK +@@ -7111,6 +7142,16 @@ DEFHOOKPOD + @option{-fsanitize=shadow-call-stack}. The default value is false.", + bool, false) + ++/* This value represents whether __builtin_unreachable should be expanded ++ as a trap instruction (or an abort() if the trap is not available). */ ++DEFHOOK ++(unreachable_should_trap, ++ "This hook should return @code{true} if the target wants \ ++ @code{__builtin_unreachable} to expand to a trap or @code{abort ()}.\n\ ++ The default value is false.", ++ bool, (void), ++ hook_bool_void_false) ++ + /* Close the 'struct gcc_target' definition. */ + HOOK_VECTOR_END (C90_EMPTY_HACK) + +diff --git a/gcc/target.h b/gcc/target.h +index d6fa6931499..7f8f488e154 100644 +--- a/gcc/target.h ++++ b/gcc/target.h +@@ -51,22 +51,8 @@ + #include "insn-codes.h" + #include "tm.h" + #include "hard-reg-set.h" +- +-#if CHECKING_P +- +-struct cumulative_args_t { void *magic; void *p; }; +- +-#else /* !CHECKING_P */ +- +-/* When using a GCC build compiler, we could use +- __attribute__((transparent_union)) to get cumulative_args_t function +- arguments passed like scalars where the ABI would mandate a less +- efficient way of argument passing otherwise. However, that would come +- at the cost of less type-safe !CHECKING_P compilation. */ +- +-union cumulative_args_t { void *p; }; +- +-#endif /* !CHECKING_P */ ++#include "tree-core.h" ++#include "cumulative-args.h" + + /* Types of memory operation understood by the "by_pieces" infrastructure. + Used by the TARGET_USE_BY_PIECES_INFRASTRUCTURE_P target hook and +diff --git a/gcc/targhooks.cc b/gcc/targhooks.cc +index 399d6f874dc..6651ad872aa 100644 +--- a/gcc/targhooks.cc ++++ b/gcc/targhooks.cc +@@ -158,6 +158,15 @@ default_promote_function_mode_always_promote (const_tree type, + return promote_mode (type, mode, punsignedp); + } + ++machine_mode ++default_promote_function_mode_ca (cumulative_args_t, function_arg_info arg, ++ const_tree funtype, int *punsignedp, ++ int for_return) ++{ ++ return promote_function_mode (arg.type, arg.mode, punsignedp, ++ funtype, for_return); ++} ++ + machine_mode + default_cc_modes_compatible (machine_mode m1, machine_mode m2) + { +@@ -850,6 +859,14 @@ default_function_arg_boundary (machine_mode mode ATTRIBUTE_UNUSED, + return PARM_BOUNDARY; + } + ++unsigned int ++default_function_arg_boundary_ca (machine_mode mode ATTRIBUTE_UNUSED, ++ const_tree type ATTRIBUTE_UNUSED, ++ cumulative_args_t ca ATTRIBUTE_UNUSED) ++{ ++ return default_function_arg_boundary (mode, type); ++} ++ + unsigned int + default_function_arg_round_boundary (machine_mode mode ATTRIBUTE_UNUSED, + const_tree type ATTRIBUTE_UNUSED) +@@ -857,6 +874,14 @@ default_function_arg_round_boundary (machine_mode mode ATTRIBUTE_UNUSED, + return PARM_BOUNDARY; + } + ++unsigned int ++default_function_arg_round_boundary_ca (machine_mode mode ATTRIBUTE_UNUSED, ++ const_tree type ATTRIBUTE_UNUSED, ++ cumulative_args_t ca ATTRIBUTE_UNUSED) ++{ ++ return default_function_arg_round_boundary (mode, type); ++} ++ + void + hook_void_bitmap (bitmap regs ATTRIBUTE_UNUSED) + { +diff --git a/gcc/targhooks.h b/gcc/targhooks.h +index ecce55ebe79..5aa565bb3b7 100644 +--- a/gcc/targhooks.h ++++ b/gcc/targhooks.h +@@ -34,6 +34,9 @@ extern machine_mode default_promote_function_mode (const_tree, machine_mode, + extern machine_mode default_promote_function_mode_always_promote + (const_tree, machine_mode, int *, const_tree, int); + ++extern machine_mode default_promote_function_mode_ca ++ (cumulative_args_t, function_arg_info, const_tree, int *, int); ++ + extern machine_mode default_cc_modes_compatible (machine_mode, + machine_mode); + +@@ -154,6 +157,12 @@ extern unsigned int default_function_arg_boundary (machine_mode, + const_tree); + extern unsigned int default_function_arg_round_boundary (machine_mode, + const_tree); ++extern unsigned int default_function_arg_boundary_ca (machine_mode, ++ const_tree, ++ cumulative_args_t ca); ++extern unsigned int default_function_arg_round_boundary_ca (machine_mode, ++ const_tree, ++ cumulative_args_t ca); + extern bool hook_bool_const_rtx_commutative_p (const_rtx, int); + extern rtx default_function_value (const_tree, const_tree, bool); + extern HARD_REG_SET default_zero_call_used_regs (HARD_REG_SET); +diff --git a/gcc/testsuite/gfortran.dg/coarray/caf.exp b/gcc/testsuite/gfortran.dg/coarray/caf.exp +index 8683a2ab435..ee051ea13e1 100644 +--- a/gcc/testsuite/gfortran.dg/coarray/caf.exp ++++ b/gcc/testsuite/gfortran.dg/coarray/caf.exp +@@ -28,6 +28,7 @@ + + # Load procedures from common libraries. + load_lib gfortran-dg.exp ++load_lib atomic-dg.exp + + # If a testcase doesn't have special options, use these. + global DEFAULT_FFLAGS +@@ -47,6 +48,7 @@ global gfortran_test_path + global gfortran_aux_module_flags + set gfortran_test_path $srcdir/$subdir + set gfortran_aux_module_flags $DEFAULT_FFLAGS ++ + proc dg-compile-aux-modules { args } { + global gfortran_test_path + global gfortran_aux_module_flags +@@ -68,12 +70,6 @@ proc dg-compile-aux-modules { args } { + } + } + +-# Add -latomic only where supported. Assume built-in support elsewhere. +-set maybe_atomic_lib "" +-if [check_effective_target_libatomic_available] { +- set maybe_atomic_lib "-latomic" +-} +- + # Main loop. + foreach test [lsort [glob -nocomplain $srcdir/$subdir/*.\[fF\]{,90,95,03,08} ]] { + # If we're only testing specific files and this isn't one of them, skip it. +@@ -97,14 +93,14 @@ foreach test [lsort [glob -nocomplain $srcdir/$subdir/*.\[fF\]{,90,95,03,08} ]] + foreach flags $option_list { + verbose "Testing $nshort (single), $flags" 1 + set gfortran_aux_module_flags "-fcoarray=single $flags" +- dg-test $test "-fcoarray=single $flags $maybe_atomic_lib" "" ++ dg-test $test "-fcoarray=single $flags" {} + cleanup-modules "" + } + + foreach flags $option_list { + verbose "Testing $nshort (libcaf_single), $flags" 1 + set gfortran_aux_module_flags "-fcoarray=lib $flags -lcaf_single" +- dg-test $test "-fcoarray=lib $flags -lcaf_single $maybe_atomic_lib" "" ++ dg-test $test "-fcoarray=lib $flags -lcaf_single" {} + cleanup-modules "" + } + } +diff --git a/gcc/testsuite/gfortran.dg/dg.exp b/gcc/testsuite/gfortran.dg/dg.exp +index bd7ad95ad0d..1b228cc546e 100644 +--- a/gcc/testsuite/gfortran.dg/dg.exp ++++ b/gcc/testsuite/gfortran.dg/dg.exp +@@ -18,6 +18,7 @@ + + # Load support procs. + load_lib gfortran-dg.exp ++load_lib atomic-dg.exp + + # If a testcase doesn't have special options, use these. + global DEFAULT_FFLAGS +@@ -53,13 +54,14 @@ proc dg-compile-aux-modules { args } { + } + } + ++set all_flags $DEFAULT_FFLAGS ++ + # Main loop. + gfortran-dg-runtest [lsort \ +- [glob -nocomplain $srcdir/$subdir/*.\[fF\]{,90,95,03,08} ] ] "" $DEFAULT_FFLAGS ++ [glob -nocomplain $srcdir/$subdir/*.\[fF\]{,90,95,03,08} ] ] "" $all_flags + + gfortran-dg-runtest [lsort \ +- [glob -nocomplain $srcdir/$subdir/g77/*.\[fF\] ] ] "" $DEFAULT_FFLAGS +- ++ [glob -nocomplain $srcdir/$subdir/g77/*.\[fF\] ] ] "" $all_flags + + # All done. + dg-finish +diff --git a/gcc/testsuite/lib/asan-dg.exp b/gcc/testsuite/lib/asan-dg.exp +index 7e0f85dc9b0..88c6ece8caa 100644 +--- a/gcc/testsuite/lib/asan-dg.exp ++++ b/gcc/testsuite/lib/asan-dg.exp +@@ -78,7 +78,7 @@ proc asan_link_flags_1 { paths lib } { + || [file exists "${gccpath}/libsanitizer/${lib}/.libs/lib${lib}.${shlib_ext}"] } { + append flags " -B${gccpath}/libsanitizer/ " + append flags " -B${gccpath}/libsanitizer/${lib}/ " +- append flags " -L${gccpath}/libsanitizer/${lib}/.libs " ++ append flags " -B${gccpath}/libsanitizer/${lib}/.libs " + append ld_library_path ":${gccpath}/libsanitizer/${lib}/.libs" + } + } else { +diff --git a/gcc/testsuite/lib/atomic-dg.exp b/gcc/testsuite/lib/atomic-dg.exp +index 86dcfa674ea..c9244fb6cac 100644 +--- a/gcc/testsuite/lib/atomic-dg.exp ++++ b/gcc/testsuite/lib/atomic-dg.exp +@@ -33,7 +33,7 @@ proc atomic_link_flags { paths } { + if { [file exists "${gccpath}/libatomic/.libs/libatomic.a"] + || [file exists "${gccpath}/libatomic/.libs/libatomic.${shlib_ext}"] } { + append flags " -B${gccpath}/libatomic/ " +- append flags " -L${gccpath}/libatomic/.libs" ++ append flags " -B${gccpath}/libatomic/.libs" + append ld_library_path ":${gccpath}/libatomic/.libs" + } + } else { +diff --git a/gcc/testsuite/lib/gdc.exp b/gcc/testsuite/lib/gdc.exp +index 73bc61780c8..2ca0dd1fb75 100644 +--- a/gcc/testsuite/lib/gdc.exp ++++ b/gcc/testsuite/lib/gdc.exp +@@ -133,6 +133,28 @@ proc gdc_link_flags { paths } { + set include_cxx_flags 0 + } + ++ # We need to add options to locate libgphobos and libstdc++ ++ # Usually '-L' options are added to point to the relevant directories for ++ # the uninstalled libraries. ++ ++ # In cases where libraries are available as both shared and convenience ++ # some additional checks are made. ++ ++ # For some targets -static-xxxx options are handled by specs substitution ++ # and need a '-B' option rather than '-L'. For Darwin, when embedded ++ # runpaths are in use (the default for all versions after macOS 10.11), ++ # '-B' is also needed to provide the runpath. ++ # When '-B' is used, this results in a '-L' for each path that exists (so ++ # that appending a '-L' as well is a needless duplicate). There are also ++ # cases where tools warn for duplicates, leading to spurious fails. ++ # Therefore the objective of the code below is to add just one '-L' or ++ # '-B' for each of the libraries. ++ ++ set target_wants_B_option 0 ++ if { [istarget *-*-darwin9* ] || [istarget *-*-darwin\[12\]* ] } { ++ set target_wants_B_option 1 ++ } ++ + if { $gccpath != "" } { + # Path to libgphobos.spec. + append flags "-B${gccpath}/libphobos/src " +@@ -143,7 +165,11 @@ proc gdc_link_flags { paths } { + + if { [file exists "${gccpath}/libphobos/src/.libs/libgphobos.a"] \ + || [file exists "${gccpath}/libphobos/src/.libs/libgphobos.${shlib_ext}"] } { +- append flags "-L${gccpath}/libphobos/src/.libs " ++ if { $target_wants_B_option } { ++ append flags "-B${gccpath}/libphobos/src/.libs " ++ } else { ++ append flags "-L${gccpath}/libphobos/src/.libs " ++ } + append ld_library_path ":${gccpath}/libphobos/src/.libs" + } + # Static linking is default. If only the shared lib is available adjust +@@ -163,7 +189,11 @@ proc gdc_link_flags { paths } { + if $include_cxx_flags { + if { [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] \ + || [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.${shlib_ext}"] } { +- append flags "-L${gccpath}/libstdc++-v3/src/.libs " ++ if { $target_wants_B_option } { ++ append flags "-B${gccpath}/libstdc++-v3/src/.libs " ++ } else { ++ append flags "-L${gccpath}/libstdc++-v3/src/.libs " ++ } + append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs" + } + } +@@ -173,7 +203,11 @@ proc gdc_link_flags { paths } { + + set libphobos [lookfor_file ${tool_root_dir} libgphobos] + if { $libphobos != "" } { +- append flags "-B${libphobos} -L${libphobos} " ++ if { $target_wants_B_option } { ++ append flags "-B${libphobos} " ++ } else { ++ append flags " -L${libphobos} " ++ } + append ld_library_path ":${libphobos}" + } + set libiberty [lookfor_file ${tool_root_dir} libiberty] +diff --git a/gcc/testsuite/lib/gfortran.exp b/gcc/testsuite/lib/gfortran.exp +index 5f692d8f350..38239f8f8c8 100644 +--- a/gcc/testsuite/lib/gfortran.exp ++++ b/gcc/testsuite/lib/gfortran.exp +@@ -79,6 +79,7 @@ proc gfortran_link_flags { paths } { + global ld_library_path + global GFORTRAN_UNDER_TEST + global shlib_ext ++ global ENABLE_DARWIN_AT_RPATH + + set gccpath ${paths} + set libio_dir "" +@@ -87,39 +88,63 @@ proc gfortran_link_flags { paths } { + set shlib_ext [get_shlib_extension] + verbose "shared lib extension: $shlib_ext" + ++ # We need to add options to locate libgfortran and the dependent libs ++ # libquadmath (supporting REAL*16) and libatomic (supporting operations ++ # used by coarrays). Usually '-L' options are added to point to the ++ # relevant directories for the uninstalled libraries. ++ ++ # In cases where libraries are available as both shared and convenience ++ # some additional checks are made. ++ ++ # For some targets -static-xxxx options are handled by specs substitution ++ # and need a '-B' option rather than '-L'. For Darwin, when embedded ++ # runpaths are in use (the default for all versions after macOS 10.11), ++ # '-B' is also needed to provide the runpath. ++ # When '-B' is used, this results in a '-L' for each path that exists (so ++ # that appending a '-L' as well is a needless duplicate). There are also ++ # cases where tools warn for duplicates, leading to spurious fails. ++ # Therefore the objective of the code below is to add just one '-L' or ++ # '-B' for each of the libraries. ++ ++ set target_wants_B_option 0 ++ if { [istarget *-*-darwin9* ] || [istarget *-*-darwin\[12\]* ] } { ++ set target_wants_B_option 1 ++ } ++ + if { $gccpath != "" } { +- if [file exists "${gccpath}/libgfortran/.libs/libgfortran.a"] { +- # Some targets use libgfortran.a%s in their specs, so they need a -B option +- # for uninstalled testing. +- append flags "-B${gccpath}/libgfortran/.libs " +- append flags "-L${gccpath}/libgfortran/.libs " +- append ld_library_path ":${gccpath}/libgfortran/.libs" +- } +- if [file exists "${gccpath}/libgfortran/.libs/libgfortran.${shlib_ext}"] { +- append flags "-L${gccpath}/libgfortran/.libs " +- append ld_library_path ":${gccpath}/libgfortran/.libs" +- } + if [file exists "${gccpath}/libgfortran/libgforbegin.a"] { + append flags "-L${gccpath}/libgfortran " + } +- if [file exists "${gccpath}/libatomic/.libs/libatomic.${shlib_ext}"] { +- append flags "-L${gccpath}/libatomic/.libs " +- append ld_library_path ":${gccpath}/libatomic/.libs" ++ if { [file exists "${gccpath}/libgfortran/.libs/libgfortran.a"] || ++ [file exists "${gccpath}/libgfortran/.libs/libgfortran.${shlib_ext}"] } { ++ if { $target_wants_B_option } { ++ append flags "-B${gccpath}/libgfortran/.libs " ++ } else { ++ append flags "-L${gccpath}/libgfortran/.libs " ++ } ++ append ld_library_path ":${gccpath}/libgfortran/.libs" + } +- if [file exists "${gccpath}/libatomic/libatomic.a"] { +- append flags "-L${gccpath}/libatomic " ++ ++ if { [file exists "${gccpath}/libatomic/.libs/libatomic.a"] || ++ [file exists "${gccpath}/libatomic/.libs/libatomic.${shlib_ext}"] } { ++ if { $target_wants_B_option } { ++ append flags "-B${gccpath}/libatomic/.libs " ++ } else { ++ append flags "-L${gccpath}/libatomic/.libs " ++ } ++ append ld_library_path ":${gccpath}/libatomic/.libs" + } +- if [file exists "${gccpath}/libquadmath/.libs/libquadmath.a"] { +- # Some targets use libquadmath.a%s in their specs, so they need a -B option +- # for uninstalled testing. ++ ++ if { [file exists "${gccpath}/libquadmath/.libs/libquadmath.a"] || ++ [file exists "${gccpath}/libquadmath/.libs/libquadmath.${shlib_ext}"] } { ++ if { $target_wants_B_option } { + append flags "-B${gccpath}/libquadmath/.libs " ++ } else { + append flags "-L${gccpath}/libquadmath/.libs " +- append ld_library_path ":${gccpath}/libquadmath/.libs" +- } +- if [file exists "${gccpath}/libquadmath/.libs/libquadmath.${shlib_ext}"] { +- append flags "-L${gccpath}/libquadmath/.libs " +- append ld_library_path ":${gccpath}/libquadmath/.libs" ++ } ++ append ld_library_path ":${gccpath}/libquadmath/.libs" + } ++ + if [file exists "${gccpath}/libiberty/libiberty.a"] { + append flags "-L${gccpath}/libiberty " + } +diff --git a/gcc/testsuite/lib/target-libpath.exp b/gcc/testsuite/lib/target-libpath.exp +index d09cd515d20..24f5710396c 100644 +--- a/gcc/testsuite/lib/target-libpath.exp ++++ b/gcc/testsuite/lib/target-libpath.exp +@@ -67,6 +67,7 @@ proc set_ld_library_path_env_vars { } { + global orig_dyld_library_path + global orig_path + global orig_gcc_exec_prefix ++ global ENABLE_DARWIN_AT_RPATH + global env + + # Save the original GCC_EXEC_PREFIX. +@@ -133,6 +134,7 @@ proc set_ld_library_path_env_vars { } { + # + # Doing this is somewhat of a hack as ld_library_path gets repeated in + # SHLIB_PATH and LD_LIBRARY_PATH when unix_load sets these variables. ++ if { ![istarget *-*-darwin*] } { + if { $orig_ld_library_path_saved } { + setenv LD_LIBRARY_PATH "$ld_library_path:$orig_ld_library_path" + } else { +@@ -166,10 +168,22 @@ proc set_ld_library_path_env_vars { } { + } else { + setenv LD_LIBRARY_PATH_64 "$ld_library_path" + } +- if { $orig_dyld_library_path_saved } { +- setenv DYLD_LIBRARY_PATH "$ld_library_path:$orig_dyld_library_path" +- } else { +- setenv DYLD_LIBRARY_PATH "$ld_library_path" ++ } ++ if { [istarget *-*-darwin*] } { ++ if { [info exists ENABLE_DARWIN_AT_RPATH] || [istarget *-*-darwin1\[5-9\]*] ++ || [istarget *-*-darwin20*] } { ++ # Either we are not using DYLD_LIBRARY_PATH or we're on a version of the ++ # OS for which it is not passed through system exes. ++ if [info exists env(DYLD_LIBRARY_PATH)] { ++ unsetenv DYLD_LIBRARY_PATH ++ } ++ } else { ++ if { $orig_dyld_library_path_saved } { ++ setenv DYLD_LIBRARY_PATH "$ld_library_path:$orig_dyld_library_path" ++ } else { ++ setenv DYLD_LIBRARY_PATH "$ld_library_path" ++ } ++ } + } + if { [istarget *-*-cygwin*] || [istarget *-*-mingw*] } { + if { $orig_path_saved } { +@@ -179,6 +193,7 @@ proc set_ld_library_path_env_vars { } { + } + } + ++ verbose -log "set paths" + verbose -log "LD_LIBRARY_PATH=[getenv LD_LIBRARY_PATH]" + verbose -log "LD_RUN_PATH=[getenv LD_RUN_PATH]" + verbose -log "SHLIB_PATH=[getenv SHLIB_PATH]" +diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp +index 64216dfbdb2..809bc46fa80 100644 +--- a/gcc/testsuite/lib/target-supports.exp ++++ b/gcc/testsuite/lib/target-supports.exp +@@ -11959,3 +11959,15 @@ main: + .byte 0 + } ""] + } ++ ++# Return 1 if the target supports heap-trampoline, 0 otherwise. ++proc check_effective_target_heap_trampoline {} { ++ if { [istarget aarch64*-*-linux*] ++ || [istarget i?86-*-darwin*] ++ || [istarget x86_64-*-darwin*] ++ || [istarget i?86-*-linux*] ++ || [istarget x86_64-*-linux*] } { ++ return 1 ++ } ++ return 0 ++} +diff --git a/gcc/toplev.cc b/gcc/toplev.cc +index 055e0642f77..8eec63b63d4 100644 +--- a/gcc/toplev.cc ++++ b/gcc/toplev.cc +@@ -1364,7 +1364,7 @@ process_options (bool no_backend) + option flags in use. */ + if (version_flag) + { +- print_version (stderr, "", true); ++ /* We already printed the version header in main (). */ + if (!quiet_flag) + { + fputs ("options passed: ", stderr); +diff --git a/gcc/tree-nested.cc b/gcc/tree-nested.cc +index 3c2cf46e3f4..1bc6c7b546b 100644 +--- a/gcc/tree-nested.cc ++++ b/gcc/tree-nested.cc +@@ -611,6 +611,14 @@ get_trampoline_type (struct nesting_info *info) + if (trampoline_type) + return trampoline_type; + ++ /* When trampolines are created off-stack then the only thing we need in the ++ local frame is a single pointer. */ ++ if (flag_trampoline_impl == TRAMPOLINE_IMPL_HEAP) ++ { ++ trampoline_type = build_pointer_type (void_type_node); ++ return trampoline_type; ++ } ++ + align = TRAMPOLINE_ALIGNMENT; + size = TRAMPOLINE_SIZE; + +@@ -2791,17 +2799,27 @@ convert_tramp_reference_op (tree *tp, int *walk_subtrees, void *data) + + /* Compute the address of the field holding the trampoline. */ + x = get_frame_field (info, target_context, x, &wi->gsi); +- x = build_addr (x); +- x = gsi_gimplify_val (info, x, &wi->gsi); + +- /* Do machine-specific ugliness. Normally this will involve +- computing extra alignment, but it can really be anything. */ +- if (descr) +- builtin = builtin_decl_implicit (BUILT_IN_ADJUST_DESCRIPTOR); ++ /* APB: We don't need to do the adjustment calls when using off-stack ++ trampolines, any such adjustment will be done when the off-stack ++ trampoline is created. */ ++ if (!descr && flag_trampoline_impl == TRAMPOLINE_IMPL_HEAP) ++ x = gsi_gimplify_val (info, x, &wi->gsi); + else +- builtin = builtin_decl_implicit (BUILT_IN_ADJUST_TRAMPOLINE); +- call = gimple_build_call (builtin, 1, x); +- x = init_tmp_var_with_call (info, &wi->gsi, call); ++ { ++ x = build_addr (x); ++ ++ x = gsi_gimplify_val (info, x, &wi->gsi); ++ ++ /* Do machine-specific ugliness. Normally this will involve ++ computing extra alignment, but it can really be anything. */ ++ if (descr) ++ builtin = builtin_decl_implicit (BUILT_IN_ADJUST_DESCRIPTOR); ++ else ++ builtin = builtin_decl_implicit (BUILT_IN_ADJUST_TRAMPOLINE); ++ call = gimple_build_call (builtin, 1, x); ++ x = init_tmp_var_with_call (info, &wi->gsi, call); ++ } + + /* Cast back to the proper function type. */ + x = build1 (NOP_EXPR, TREE_TYPE (t), x); +@@ -3380,6 +3398,7 @@ build_init_call_stmt (struct nesting_info *info, tree decl, tree field, + static void + finalize_nesting_tree_1 (struct nesting_info *root) + { ++ gimple_seq cleanup_list = NULL; + gimple_seq stmt_list = NULL; + gimple *stmt; + tree context = root->context; +@@ -3511,9 +3530,48 @@ finalize_nesting_tree_1 (struct nesting_info *root) + if (!field) + continue; + +- x = builtin_decl_implicit (BUILT_IN_INIT_TRAMPOLINE); +- stmt = build_init_call_stmt (root, i->context, field, x); +- gimple_seq_add_stmt (&stmt_list, stmt); ++ if (flag_trampoline_impl == TRAMPOLINE_IMPL_HEAP) ++ { ++ /* We pass a whole bunch of arguments to the builtin function that ++ creates the off-stack trampoline, these are ++ 1. The nested function chain value (that must be passed to the ++ nested function so it can find the function arguments). ++ 2. A pointer to the nested function implementation, ++ 3. The address in the local stack frame where we should write ++ the address of the trampoline. ++ ++ When this code was originally written I just kind of threw ++ everything at the builtin, figuring I'd work out what was ++ actually needed later, I think, the stack pointer could ++ certainly be dropped, arguments #2 and #4 are based off the ++ stack pointer anyway, so #1 doesn't seem to add much value. */ ++ tree arg1, arg2, arg3; ++ ++ gcc_assert (DECL_STATIC_CHAIN (i->context)); ++ arg1 = build_addr (root->frame_decl); ++ arg2 = build_addr (i->context); ++ ++ x = build3 (COMPONENT_REF, TREE_TYPE (field), ++ root->frame_decl, field, NULL_TREE); ++ arg3 = build_addr (x); ++ ++ x = builtin_decl_explicit (BUILT_IN_GCC_NESTED_PTR_CREATED); ++ stmt = gimple_build_call (x, 3, arg1, arg2, arg3); ++ gimple_seq_add_stmt (&stmt_list, stmt); ++ ++ /* This call to delete the nested function trampoline is added to ++ the cleanup list, and called when we exit the current scope. */ ++ x = builtin_decl_explicit (BUILT_IN_GCC_NESTED_PTR_DELETED); ++ stmt = gimple_build_call (x, 0); ++ gimple_seq_add_stmt (&cleanup_list, stmt); ++ } ++ else ++ { ++ /* Original code to initialise the on stack trampoline. */ ++ x = builtin_decl_implicit (BUILT_IN_INIT_TRAMPOLINE); ++ stmt = build_init_call_stmt (root, i->context, field, x); ++ gimple_seq_add_stmt (&stmt_list, stmt); ++ } + } + } + +@@ -3538,11 +3596,40 @@ finalize_nesting_tree_1 (struct nesting_info *root) + /* If we created initialization statements, insert them. */ + if (stmt_list) + { +- gbind *bind; +- annotate_all_with_location (stmt_list, DECL_SOURCE_LOCATION (context)); +- bind = gimple_seq_first_stmt_as_a_bind (gimple_body (context)); +- gimple_seq_add_seq (&stmt_list, gimple_bind_body (bind)); +- gimple_bind_set_body (bind, stmt_list); ++ if (flag_trampoline_impl == TRAMPOLINE_IMPL_HEAP) ++ { ++ /* Handle off-stack trampolines. */ ++ gbind *bind; ++ annotate_all_with_location (stmt_list, DECL_SOURCE_LOCATION (context)); ++ annotate_all_with_location (cleanup_list, DECL_SOURCE_LOCATION (context)); ++ bind = gimple_seq_first_stmt_as_a_bind (gimple_body (context)); ++ gimple_seq_add_seq (&stmt_list, gimple_bind_body (bind)); ++ ++ gimple_seq xxx_list = NULL; ++ ++ if (cleanup_list != NULL) ++ { ++ /* Maybe we shouldn't be creating this try/finally if -fno-exceptions is ++ in use. If this is the case, then maybe we should, instead, be ++ inserting the cleanup code onto every path out of this function? Not ++ yet figured out how we would do this. */ ++ gtry *t = gimple_build_try (stmt_list, cleanup_list, GIMPLE_TRY_FINALLY); ++ gimple_seq_add_stmt (&xxx_list, t); ++ } ++ else ++ xxx_list = stmt_list; ++ ++ gimple_bind_set_body (bind, xxx_list); ++ } ++ else ++ { ++ /* The traditional, on stack trampolines. */ ++ gbind *bind; ++ annotate_all_with_location (stmt_list, DECL_SOURCE_LOCATION (context)); ++ bind = gimple_seq_first_stmt_as_a_bind (gimple_body (context)); ++ gimple_seq_add_seq (&stmt_list, gimple_bind_body (bind)); ++ gimple_bind_set_body (bind, stmt_list); ++ } + } + + /* If a chain_decl was created, then it needs to be registered with +diff --git a/gcc/tree.cc b/gcc/tree.cc +index 6b28eb9f10d..7b0f08fba4e 100644 +--- a/gcc/tree.cc ++++ b/gcc/tree.cc +@@ -9796,6 +9796,28 @@ build_common_builtin_nodes (void) + "__builtin_nonlocal_goto", + ECF_NORETURN | ECF_NOTHROW); + ++ tree ptr_ptr_type_node = build_pointer_type (ptr_type_node); ++ ++ if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_CREATED)) ++ { ++ ftype = build_function_type_list (void_type_node, ++ ptr_type_node, // void *chain ++ ptr_type_node, // void *func ++ ptr_ptr_type_node, // void **dst ++ NULL_TREE); ++ local_define_builtin ("__builtin___gcc_nested_func_ptr_created", ftype, ++ BUILT_IN_GCC_NESTED_PTR_CREATED, ++ "__gcc_nested_func_ptr_created", ECF_NOTHROW); ++ } ++ ++ if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_DELETED)) ++ { ++ ftype = build_function_type_list (void_type_node, NULL_TREE); ++ local_define_builtin ("__builtin___gcc_nested_func_ptr_deleted", ftype, ++ BUILT_IN_GCC_NESTED_PTR_DELETED, ++ "__gcc_nested_func_ptr_deleted", ECF_NOTHROW); ++ } ++ + ftype = build_function_type_list (void_type_node, + ptr_type_node, ptr_type_node, NULL_TREE); + local_define_builtin ("__builtin_setjmp_setup", ftype, +diff --git a/intl/Makefile.in b/intl/Makefile.in +index 409d693c48e..5beebdc152c 100644 +--- a/intl/Makefile.in ++++ b/intl/Makefile.in +@@ -54,7 +54,7 @@ CTAGS = @CTAGS@ + ETAGS = @ETAGS@ + MKID = @MKID@ + +-COMPILE = $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEFS) $(DEFS-$@) $(INCLUDES) ++COMPILE = $(CC) -c $(CPPFLAGS) $(CFLAGS) @PICFLAG@ $(DEFS) $(DEFS-$@) $(INCLUDES) + + HEADERS = \ + gmo.h \ +diff --git a/intl/configure b/intl/configure +index 03f40487a92..79bb5831a47 100755 +--- a/intl/configure ++++ b/intl/configure +@@ -623,6 +623,8 @@ ac_header_list= + ac_subst_vars='LTLIBOBJS + LIBOBJS + PICFLAG ++enable_host_pie ++enable_host_shared + BISON3_NO + BISON3_YES + INCINTL +@@ -731,6 +733,7 @@ with_libintl_prefix + with_libintl_type + enable_maintainer_mode + enable_host_shared ++enable_host_pie + ' + ac_precious_vars='build_alias + host_alias +@@ -1356,6 +1359,7 @@ Optional Features: + --disable-rpath do not hardcode runtime library paths + --enable-maintainer-mode enable rules only needed by maintainers + --enable-host-shared build host code as shared libraries ++ --enable-host-pie build host code as PIE + + Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] +@@ -6852,15 +6856,31 @@ fi + + + ++# Enable --enable-host-shared. + # Check whether --enable-host-shared was given. + if test "${enable_host_shared+set}" = set; then : +- enableval=$enable_host_shared; PICFLAG=-fPIC ++ enableval=$enable_host_shared; ++fi ++ ++ ++ ++# Enable --enable-host-pie. ++# Check whether --enable-host-pie was given. ++if test "${enable_host_pie+set}" = set; then : ++ enableval=$enable_host_pie; ++fi ++ ++ ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE + else + PICFLAG= + fi + + +- + ac_config_files="$ac_config_files Makefile config.intl" + + cat >confcache <<\_ACEOF +diff --git a/intl/configure.ac b/intl/configure.ac +index 16a740aa230..81aa831f59f 100644 +--- a/intl/configure.ac ++++ b/intl/configure.ac +@@ -83,10 +83,25 @@ fi + AC_SUBST(BISON3_YES) + AC_SUBST(BISON3_NO) + ++# Enable --enable-host-shared. + AC_ARG_ENABLE(host-shared, + [AS_HELP_STRING([--enable-host-shared], +- [build host code as shared libraries])], +-[PICFLAG=-fPIC], [PICFLAG=]) ++ [build host code as shared libraries])]) ++AC_SUBST(enable_host_shared) ++ ++# Enable --enable-host-pie. ++AC_ARG_ENABLE(host-pie, ++[AS_HELP_STRING([--enable-host-pie], ++ [build host code as PIE])]) ++AC_SUBST(enable_host_pie) ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE ++else ++ PICFLAG= ++fi + AC_SUBST(PICFLAG) + + AC_CONFIG_FILES(Makefile config.intl) +diff --git a/libada/configure b/libada/configure +index 162d9731f26..9c8b133d817 100755 +--- a/libada/configure ++++ b/libada/configure +@@ -3212,6 +3212,9 @@ case "${host}" in + # sets the default TLS model and affects inlining. + PICFLAG=-fPIC + ;; ++ loongarch*-*-*) ++ PICFLAG=-fpic ++ ;; + mips-sgi-irix6*) + # PIC is the default. + ;; +diff --git a/libatomic/Makefile.am b/libatomic/Makefile.am +index d88515e4a03..c45f19251bc 100644 +--- a/libatomic/Makefile.am ++++ b/libatomic/Makefile.am +@@ -65,8 +65,13 @@ libatomic_version_script = + libatomic_version_dep = + endif + libatomic_version_info = -version-info $(libtool_VERSION) ++if ENABLE_DARWIN_AT_RPATH ++libatomic_darwin_rpath = -Wc,-nodefaultrpaths ++libatomic_darwin_rpath += -Wl,-rpath,@loader_path ++endif + +-libatomic_la_LDFLAGS = $(libatomic_version_info) $(libatomic_version_script) $(lt_host_flags) ++libatomic_la_LDFLAGS = $(libatomic_version_info) $(libatomic_version_script) \ ++ $(lt_host_flags) $(libatomic_darwin_rpath) + libatomic_la_SOURCES = gload.c gstore.c gcas.c gexch.c glfree.c lock.c init.c \ + fenv.c fence.c flag.c + +diff --git a/libatomic/Makefile.in b/libatomic/Makefile.in +index 80d25653dc7..47c1e5354bd 100644 +--- a/libatomic/Makefile.in ++++ b/libatomic/Makefile.in +@@ -403,7 +403,12 @@ noinst_LTLIBRARIES = libatomic_convenience.la + @LIBAT_BUILD_VERSIONED_SHLIB_GNU_TRUE@@LIBAT_BUILD_VERSIONED_SHLIB_TRUE@libatomic_version_dep = $(top_srcdir)/libatomic.map + @LIBAT_BUILD_VERSIONED_SHLIB_SUN_TRUE@@LIBAT_BUILD_VERSIONED_SHLIB_TRUE@libatomic_version_dep = libatomic.map-sun + libatomic_version_info = -version-info $(libtool_VERSION) +-libatomic_la_LDFLAGS = $(libatomic_version_info) $(libatomic_version_script) $(lt_host_flags) ++@ENABLE_DARWIN_AT_RPATH_TRUE@libatomic_darwin_rpath = \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path ++libatomic_la_LDFLAGS = $(libatomic_version_info) $(libatomic_version_script) \ ++ $(lt_host_flags) $(libatomic_darwin_rpath) ++ + libatomic_la_SOURCES = gload.c gstore.c gcas.c gexch.c glfree.c lock.c init.c \ + fenv.c fence.c flag.c + +diff --git a/libatomic/configure b/libatomic/configure +index 92853dd8a45..9871ef4bfb7 100755 +--- a/libatomic/configure ++++ b/libatomic/configure +@@ -658,6 +658,8 @@ OPT_LDFLAGS + SECTION_LDFLAGS + enable_aarch64_lse + libtool_VERSION ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + MAINT + MAINTAINER_MODE_FALSE + MAINTAINER_MODE_TRUE +@@ -803,6 +805,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + enable_maintainer_mode + enable_symvers + enable_werror +@@ -1452,6 +1455,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --enable-maintainer-mode + enable make rules and dependencies not useful (and + sometimes confusing) to the casual installer +@@ -7603,7 +7609,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -9576,6 +9582,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -9593,9 +9642,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -11382,7 +11435,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11385 "configure" ++#line 11438 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11488,7 +11541,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11491 "configure" ++#line 11544 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11773,6 +11826,15 @@ fi + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ ++ + # For libtool versioning info, format is CURRENT:REVISION:AGE + libtool_VERSION=3:0:2 + +@@ -15900,6 +15962,10 @@ if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then + as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + + if test -z "${LIBAT_BUILD_VERSIONED_SHLIB_TRUE}" && test -z "${LIBAT_BUILD_VERSIONED_SHLIB_FALSE}"; then + as_fn_error $? "conditional \"LIBAT_BUILD_VERSIONED_SHLIB\" was never defined. +diff --git a/libatomic/configure.ac b/libatomic/configure.ac +index 5563551aaae..6b9d3085806 100644 +--- a/libatomic/configure.ac ++++ b/libatomic/configure.ac +@@ -156,6 +156,8 @@ AC_SUBST(enable_shared) + AC_SUBST(enable_static) + AM_MAINTAINER_MODE + ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) ++ + # For libtool versioning info, format is CURRENT:REVISION:AGE + libtool_VERSION=3:0:2 + AC_SUBST(libtool_VERSION) +diff --git a/libatomic/testsuite/Makefile.in b/libatomic/testsuite/Makefile.in +index 333980ec2c1..8bc70562e5b 100644 +--- a/libatomic/testsuite/Makefile.in ++++ b/libatomic/testsuite/Makefile.in +@@ -262,6 +262,7 @@ target_alias = @target_alias@ + target_cpu = @target_cpu@ + target_os = @target_os@ + target_vendor = @target_vendor@ ++tmake_file = @tmake_file@ + toolexecdir = @toolexecdir@ + toolexeclibdir = @toolexeclibdir@ + top_build_prefix = @top_build_prefix@ +diff --git a/libatomic/testsuite/lib/libatomic.exp b/libatomic/testsuite/lib/libatomic.exp +index 38f3e5673e2..a2589234a07 100644 +--- a/libatomic/testsuite/lib/libatomic.exp ++++ b/libatomic/testsuite/lib/libatomic.exp +@@ -147,11 +147,15 @@ proc libatomic_init { args } { + if { $blddir != "" } { + lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/" + lappend ALWAYS_CFLAGS "additional_flags=-I${blddir}" +- lappend ALWAYS_CFLAGS "ldflags=-L${blddir}/.libs" ++ if [istarget *-*-darwin*] { ++ lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/.libs" ++ } else { ++ lappend ALWAYS_CFLAGS "ldflags=-L${blddir}/.libs" ++ } + } + lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/.." + +- if [istarget *-*-darwin*] { ++ if [istarget *-*-darwin\[89\]*] { + lappend ALWAYS_CFLAGS "additional_flags=-shared-libgcc" + } + +diff --git a/libbacktrace/Makefile.in b/libbacktrace/Makefile.in +index 08cdd21fb40..8898251161d 100644 +--- a/libbacktrace/Makefile.in ++++ b/libbacktrace/Makefile.in +@@ -15,7 +15,7 @@ + @SET_MAKE@ + + # Makefile.am -- Backtrace Makefile. +-# Copyright (C) 2012-2021 Free Software Foundation, Inc. ++# Copyright (C) 2012-2022 Free Software Foundation, Inc. + + # Redistribution and use in source and binary forms, with or without + # modification, are permitted provided that the following conditions are +diff --git a/libbacktrace/backtrace.c b/libbacktrace/backtrace.c +index d28575ec897..cf6491682a7 100644 +--- a/libbacktrace/backtrace.c ++++ b/libbacktrace/backtrace.c +@@ -70,6 +70,13 @@ unwind (struct _Unwind_Context *context, void *vdata) + uintptr_t pc; + int ip_before_insn = 0; + ++#ifdef __APPLE__ ++# undef HAVE_GETIPINFO ++# if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 ++# define HAVE_GETIPINFO 1 ++# endif ++#endif ++ + #ifdef HAVE_GETIPINFO + pc = _Unwind_GetIPInfo (context, &ip_before_insn); + #else +diff --git a/libbacktrace/configure b/libbacktrace/configure +index 17f470a4bec..6bd8394387e 100755 +--- a/libbacktrace/configure ++++ b/libbacktrace/configure +@@ -675,6 +675,8 @@ PIC_FLAG + WARN_FLAGS + EXTRA_FLAGS + BACKTRACE_FILE ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + OTOOL64 + OTOOL + LIPO +@@ -799,6 +801,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + enable_largefile + enable_cet + enable_werror +@@ -1447,6 +1450,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --disable-largefile omit support for large files + --enable-cet enable Intel CET in target libraries [default=auto] + --disable-werror disable building with -Werror +@@ -7999,7 +8005,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -9705,6 +9711,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -9722,9 +9771,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -11511,7 +11564,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11514 "configure" ++#line 11567 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11617,7 +11670,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11620 "configure" ++#line 11673 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11856,6 +11909,15 @@ CC="$lt_save_CC" + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ ++ + # Check whether --enable-largefile was given. + if test "${enable_largefile+set}" = set; then : + enableval=$enable_largefile; +@@ -14273,6 +14335,10 @@ if test -z "${HAVE_DWZ_TRUE}" && test -z "${HAVE_DWZ_FALSE}"; then + as_fn_error $? "conditional \"HAVE_DWZ\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${HAVE_ELF_TRUE}" && test -z "${HAVE_ELF_FALSE}"; then + as_fn_error $? "conditional \"HAVE_ELF\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac +index 597c9705db8..7f89bf33c6b 100644 +--- a/libbacktrace/configure.ac ++++ b/libbacktrace/configure.ac +@@ -84,6 +84,8 @@ AM_CONDITIONAL(HAVE_DWZ, test "$DWZ" != "") + LT_INIT + AM_PROG_LIBTOOL + ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) ++ + AC_SYS_LARGEFILE + + backtrace_supported=yes +diff --git a/libbacktrace/simple.c b/libbacktrace/simple.c +index 6a1a1c92a12..811255ab6b5 100644 +--- a/libbacktrace/simple.c ++++ b/libbacktrace/simple.c +@@ -65,6 +65,13 @@ simple_unwind (struct _Unwind_Context *context, void *vdata) + uintptr_t pc; + int ip_before_insn = 0; + ++#ifdef __APPLE__ ++# undef HAVE_GETIPINFO ++# if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 ++# define HAVE_GETIPINFO 1 ++# endif ++#endif ++ + #ifdef HAVE_GETIPINFO + pc = _Unwind_GetIPInfo (context, &ip_before_insn); + #else +diff --git a/libcc1/configure b/libcc1/configure +index 01cfb2806da..78519868102 100755 +--- a/libcc1/configure ++++ b/libcc1/configure +@@ -787,6 +787,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + enable_cet + with_gcc_major_version_only + enable_werror_always +@@ -1439,6 +1440,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --enable-cet enable Intel CET in host libraries [default=auto] + --enable-werror-always enable -Werror despite compiler version + --enable-plugin enable plugin support +@@ -7266,7 +7270,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -8971,6 +8975,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -8988,9 +9035,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -10777,7 +10828,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 10780 "configure" ++#line 10831 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -10883,7 +10934,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 10886 "configure" ++#line 10937 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -12165,6 +12216,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc_CXX=no + hardcode_direct_CXX=no + hardcode_automatic_CXX=yes +@@ -12182,12 +12276,20 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + if test "$lt_cv_apple_cc_single_mod" != "yes"; then +- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring${_lt_dsymutil}" + archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" + fi + +diff --git a/libcody/Makefile.in b/libcody/Makefile.in +index 7eaf8ace8ce..0ff1625a39f 100644 +--- a/libcody/Makefile.in ++++ b/libcody/Makefile.in +@@ -31,7 +31,7 @@ endif + CXXOPTS += $(filter-out -DHAVE_CONFIG_H,@DEFS@) -include config.h + + # Linker options +-LDFLAGS := @LDFLAGS@ ++LDFLAGS := @LDFLAGS@ @LD_PICFLAG@ + LIBS := @LIBS@ + + # Per-source & per-directory compile flags (warning: recursive) +diff --git a/libcody/configure b/libcody/configure +index da52a5cfca5..0e536c0ccb0 100755 +--- a/libcody/configure ++++ b/libcody/configure +@@ -591,7 +591,10 @@ configure_args + AR + RANLIB + EXCEPTIONS ++LD_PICFLAG + PICFLAG ++enable_host_pie ++enable_host_shared + OBJEXT + EXEEXT + ac_ct_CXX +@@ -653,6 +656,7 @@ enable_maintainer_mode + with_compiler + enable_checking + enable_host_shared ++enable_host_pie + enable_exceptions + ' + ac_precious_vars='build_alias +@@ -1286,6 +1290,7 @@ Optional Features: + yes,no,all,none,release. Flags are: misc,valgrind or + other strings + --enable-host-shared build host code as shared libraries ++ --enable-host-pie build host code as PIE + --enable-exceptions enable exceptions & rtti + + Optional Packages: +@@ -2635,11 +2640,34 @@ fi + # Enable --enable-host-shared. + # Check whether --enable-host-shared was given. + if test "${enable_host_shared+set}" = set; then : +- enableval=$enable_host_shared; PICFLAG=-fPIC ++ enableval=$enable_host_shared; ++fi ++ ++ ++ ++# Enable --enable-host-pie. ++# Check whether --enable-host-pie was given. ++if test "${enable_host_pie+set}" = set; then : ++ enableval=$enable_host_pie; ++fi ++ ++ ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE + else + PICFLAG= + fi + ++if test x$enable_host_pie = xyes; then ++ LD_PICFLAG=-pie ++else ++ LD_PICFLAG= ++fi ++ ++ + + + # Check whether --enable-exceptions was given. +diff --git a/libcody/configure.ac b/libcody/configure.ac +index 960191ecb72..14e8dd4a226 100644 +--- a/libcody/configure.ac ++++ b/libcody/configure.ac +@@ -63,9 +63,31 @@ fi + # Enable --enable-host-shared. + AC_ARG_ENABLE(host-shared, + [AS_HELP_STRING([--enable-host-shared], +- [build host code as shared libraries])], +-[PICFLAG=-fPIC], [PICFLAG=]) ++ [build host code as shared libraries])]) ++AC_SUBST(enable_host_shared) ++ ++# Enable --enable-host-pie. ++AC_ARG_ENABLE(host-pie, ++[AS_HELP_STRING([--enable-host-pie], ++ [build host code as PIE])]) ++AC_SUBST(enable_host_pie) ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE ++else ++ PICFLAG= ++fi ++ ++if test x$enable_host_pie = xyes; then ++ LD_PICFLAG=-pie ++else ++ LD_PICFLAG= ++fi ++ + AC_SUBST(PICFLAG) ++AC_SUBST(LD_PICFLAG) + + NMS_ENABLE_EXCEPTIONS + +diff --git a/libcpp/configure b/libcpp/configure +index 75145390215..85168273cd1 100755 +--- a/libcpp/configure ++++ b/libcpp/configure +@@ -625,6 +625,8 @@ ac_includes_default="\ + ac_subst_vars='LTLIBOBJS + CET_HOST_FLAGS + PICFLAG ++enable_host_pie ++enable_host_shared + MAINT + USED_CATALOGS + PACKAGE +@@ -738,6 +740,7 @@ enable_maintainer_mode + enable_checking + enable_canonical_system_headers + enable_host_shared ++enable_host_pie + enable_cet + enable_valgrind_annotations + ' +@@ -1379,6 +1382,7 @@ Optional Features: + --enable-canonical-system-headers + enable or disable system headers canonicalization + --enable-host-shared build host code as shared libraries ++ --enable-host-pie build host code as PIE + --enable-cet enable Intel CET in host libraries [default=auto] + --enable-valgrind-annotations + enable valgrind runtime interaction +@@ -7605,7 +7609,23 @@ esac + # Enable --enable-host-shared. + # Check whether --enable-host-shared was given. + if test "${enable_host_shared+set}" = set; then : +- enableval=$enable_host_shared; PICFLAG=-fPIC ++ enableval=$enable_host_shared; ++fi ++ ++ ++ ++# Enable --enable-host-pie. ++# Check whether --enable-host-pie was given. ++if test "${enable_host_pie+set}" = set; then : ++ enableval=$enable_host_pie; ++fi ++ ++ ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE + else + PICFLAG= + fi +diff --git a/libcpp/configure.ac b/libcpp/configure.ac +index 9b6042518e5..d25bf5f414f 100644 +--- a/libcpp/configure.ac ++++ b/libcpp/configure.ac +@@ -211,8 +211,23 @@ esac + # Enable --enable-host-shared. + AC_ARG_ENABLE(host-shared, + [AS_HELP_STRING([--enable-host-shared], +- [build host code as shared libraries])], +-[PICFLAG=-fPIC], [PICFLAG=]) ++ [build host code as shared libraries])]) ++AC_SUBST(enable_host_shared) ++ ++# Enable --enable-host-pie. ++AC_ARG_ENABLE(host-pie, ++[AS_HELP_STRING([--enable-host-pie], ++ [build host code as PIE])]) ++AC_SUBST(enable_host_pie) ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE ++else ++ PICFLAG= ++fi ++ + AC_SUBST(PICFLAG) + + # Enable Intel CET on Intel CET enabled host if jit is enabled. +diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h +index abdc207d1a1..073c9e8bf2f 100644 +--- a/libcpp/include/cpplib.h ++++ b/libcpp/include/cpplib.h +@@ -721,6 +721,9 @@ struct cpp_callbacks + /* Callback to determine whether a built-in function is recognized. */ + int (*has_builtin) (cpp_reader *); + ++ /* Callback to determine whether a feature is available. */ ++ int (*has_feature) (cpp_reader *, bool); ++ + /* Callback that can change a user lazy into normal macro. */ + void (*user_lazy_macro) (cpp_reader *, cpp_macro *, unsigned); + +@@ -925,7 +928,9 @@ enum cpp_builtin_type + BT_HAS_STD_ATTRIBUTE, /* `__has_c_attribute(x)' */ + BT_HAS_BUILTIN, /* `__has_builtin(x)' */ + BT_HAS_INCLUDE, /* `__has_include(x)' */ +- BT_HAS_INCLUDE_NEXT /* `__has_include_next(x)' */ ++ BT_HAS_INCLUDE_NEXT, /* `__has_include_next(x)' */ ++ BT_HAS_FEATURE, /* `__has_feature(x)' */ ++ BT_HAS_EXTENSION /* `__has_extension(x)' */ + }; + + #define CPP_HASHNODE(HNODE) ((cpp_hashnode *) (HNODE)) +diff --git a/libcpp/init.cc b/libcpp/init.cc +index f4ab83d2145..aefaf3706cd 100644 +--- a/libcpp/init.cc ++++ b/libcpp/init.cc +@@ -420,6 +420,8 @@ static const struct builtin_macro builtin_array[] = + B("__has_builtin", BT_HAS_BUILTIN, true), + B("__has_include", BT_HAS_INCLUDE, true), + B("__has_include_next",BT_HAS_INCLUDE_NEXT, true), ++ B("__has_feature", BT_HAS_FEATURE, true), ++ B("__has_extension", BT_HAS_EXTENSION, true), + /* Keep builtins not used for -traditional-cpp at the end, and + update init_builtins() if any more are added. */ + B("_Pragma", BT_PRAGMA, true), +diff --git a/libcpp/macro.cc b/libcpp/macro.cc +index 8ebf360c03c..d8ce51bbbda 100644 +--- a/libcpp/macro.cc ++++ b/libcpp/macro.cc +@@ -677,6 +677,12 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node, + number = builtin_has_include (pfile, node, + node->value.builtin == BT_HAS_INCLUDE_NEXT); + break; ++ ++ case BT_HAS_FEATURE: ++ case BT_HAS_EXTENSION: ++ number = pfile->cb.has_feature (pfile, ++ node->value.builtin == BT_HAS_FEATURE); ++ break; + } + + if (result == NULL) +diff --git a/libdecnumber/configure b/libdecnumber/configure +index da5302f9315..d805fdeab5a 100755 +--- a/libdecnumber/configure ++++ b/libdecnumber/configure +@@ -626,6 +626,8 @@ ac_subst_vars='LTLIBOBJS + LIBOBJS + CET_HOST_FLAGS + PICFLAG ++enable_host_pie ++enable_host_shared + ADDITIONAL_OBJS + enable_decimal_float + target_os +@@ -706,6 +708,7 @@ enable_werror_always + enable_maintainer_mode + enable_decimal_float + enable_host_shared ++enable_host_pie + enable_cet + ' + ac_precious_vars='build_alias +@@ -1338,6 +1341,7 @@ Optional Features: + or 'dpd' choses which decimal floating point format + to use + --enable-host-shared build host code as shared libraries ++ --enable-host-pie build host code as PIE + --enable-cet enable Intel CET in host libraries [default=auto] + + Some influential environment variables: +@@ -5185,7 +5189,23 @@ $as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h + # Enable --enable-host-shared. + # Check whether --enable-host-shared was given. + if test "${enable_host_shared+set}" = set; then : +- enableval=$enable_host_shared; PICFLAG=-fPIC ++ enableval=$enable_host_shared; ++fi ++ ++ ++ ++# Enable --enable-host-pie. ++# Check whether --enable-host-pie was given. ++if test "${enable_host_pie+set}" = set; then : ++ enableval=$enable_host_pie; ++fi ++ ++ ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE + else + PICFLAG= + fi +diff --git a/libdecnumber/configure.ac b/libdecnumber/configure.ac +index 0794031ec83..14f67f926d1 100644 +--- a/libdecnumber/configure.ac ++++ b/libdecnumber/configure.ac +@@ -100,8 +100,23 @@ AC_C_BIGENDIAN + # Enable --enable-host-shared. + AC_ARG_ENABLE(host-shared, + [AS_HELP_STRING([--enable-host-shared], +- [build host code as shared libraries])], +-[PICFLAG=-fPIC], [PICFLAG=]) ++ [build host code as shared libraries])]) ++AC_SUBST(enable_host_shared) ++ ++# Enable --enable-host-pie. ++AC_ARG_ENABLE(host-pie, ++[AS_HELP_STRING([--enable-host-pie], ++ [build host code as PIE])]) ++AC_SUBST(enable_host_pie) ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE ++else ++ PICFLAG= ++fi ++ + AC_SUBST(PICFLAG) + + # Enable Intel CET on Intel CET enabled host if jit is enabled. +diff --git a/libffi/Makefile.am b/libffi/Makefile.am +index c6d6f849c53..d2ae0c04c7b 100644 +--- a/libffi/Makefile.am ++++ b/libffi/Makefile.am +@@ -214,7 +214,12 @@ libffi.map: $(top_srcdir)/libffi.map.in + $(COMPILE) -D$(TARGET) -DGENERATE_LIBFFI_MAP \ + -E -x assembler-with-cpp -o $@ $(top_srcdir)/libffi.map.in + +-libffi_la_LDFLAGS = -no-undefined $(libffi_version_info) $(libffi_version_script) $(LTLDFLAGS) $(AM_LTLDFLAGS) ++if ENABLE_DARWIN_AT_RPATH ++libffi_darwin_rpath = -Wl,-rpath,@loader_path ++endif ++libffi_la_LDFLAGS = -no-undefined $(libffi_version_info) \ ++ $(libffi_version_script) $(LTLDFLAGS) $(AM_LTLDFLAGS) \ ++ $(libffi_darwin_rpath) + libffi_la_DEPENDENCIES = $(libffi_la_LIBADD) $(libffi_version_dep) + + AM_CPPFLAGS = -I. -I$(top_srcdir)/include -Iinclude -I$(top_srcdir)/src +diff --git a/libffi/Makefile.in b/libffi/Makefile.in +index 5524a6a571e..34e77a45d1a 100644 +--- a/libffi/Makefile.in ++++ b/libffi/Makefile.in +@@ -597,7 +597,11 @@ AM_CFLAGS = -Wall -g -fexceptions $(CET_FLAGS) $(am__append_2) + @LIBFFI_BUILD_VERSIONED_SHLIB_GNU_TRUE@@LIBFFI_BUILD_VERSIONED_SHLIB_TRUE@libffi_version_dep = libffi.map + @LIBFFI_BUILD_VERSIONED_SHLIB_SUN_TRUE@@LIBFFI_BUILD_VERSIONED_SHLIB_TRUE@libffi_version_dep = libffi.map-sun + libffi_version_info = -version-info `grep -v '^\#' $(srcdir)/libtool-version` +-libffi_la_LDFLAGS = -no-undefined $(libffi_version_info) $(libffi_version_script) $(LTLDFLAGS) $(AM_LTLDFLAGS) ++@ENABLE_DARWIN_AT_RPATH_TRUE@libffi_darwin_rpath = -Wl,-rpath,@loader_path ++libffi_la_LDFLAGS = -no-undefined $(libffi_version_info) \ ++ $(libffi_version_script) $(LTLDFLAGS) $(AM_LTLDFLAGS) \ ++ $(libffi_darwin_rpath) ++ + libffi_la_DEPENDENCIES = $(libffi_la_LIBADD) $(libffi_version_dep) + AM_CPPFLAGS = -I. -I$(top_srcdir)/include -Iinclude -I$(top_srcdir)/src + AM_CCASFLAGS = $(AM_CPPFLAGS) $(CET_FLAGS) +diff --git a/libffi/configure b/libffi/configure +index 575641cca1d..7a68bfdfe51 100755 +--- a/libffi/configure ++++ b/libffi/configure +@@ -667,6 +667,8 @@ MAINT + MAINTAINER_MODE_FALSE + MAINTAINER_MODE_TRUE + READELF ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + CXXCPP + CPP + OTOOL64 +@@ -810,6 +812,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + enable_maintainer_mode + enable_pax_emutramp + enable_debug +@@ -1465,6 +1468,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --enable-maintainer-mode + enable make rules and dependencies not useful (and + sometimes confusing) to the casual installer +@@ -7792,7 +7798,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -9766,6 +9772,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -9783,9 +9832,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -11572,7 +11625,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11575 "configure" ++#line 11628 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11678,7 +11731,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11681 "configure" ++#line 11734 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -12554,6 +12607,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc_CXX=no + hardcode_direct_CXX=no + hardcode_automatic_CXX=yes +@@ -12571,12 +12667,20 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + if test "$lt_cv_apple_cc_single_mod" != "yes"; then +- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring${_lt_dsymutil}" + archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" + fi + +@@ -14926,6 +15030,14 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu + # Only expand once: + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}readelf", so it can be a program name with args. +@@ -17071,6 +17183,10 @@ if test -z "${am__fastdepCCAS_TRUE}" && test -z "${am__fastdepCCAS_FALSE}"; then + as_fn_error $? "conditional \"am__fastdepCCAS\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then + as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/libffi/configure.ac b/libffi/configure.ac +index 014d89d0423..716f20ae313 100644 +--- a/libffi/configure.ac ++++ b/libffi/configure.ac +@@ -55,6 +55,7 @@ AC_SUBST(CET_FLAGS) + AM_PROG_AS + AM_PROG_CC_C_O + AC_PROG_LIBTOOL ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) + + AC_CHECK_TOOL(READELF, readelf) + +diff --git a/libffi/doc/version.texi b/libffi/doc/version.texi +index f2b741e87e4..6261b21fec9 100644 +--- a/libffi/doc/version.texi ++++ b/libffi/doc/version.texi +@@ -1,4 +1,4 @@ +-@set UPDATED 27 June 2021 +-@set UPDATED-MONTH June 2021 ++@set UPDATED 31 August 2022 ++@set UPDATED-MONTH August 2022 + @set EDITION 3.4.2 + @set VERSION 3.4.2 +diff --git a/libffi/testsuite/lib/libffi.exp b/libffi/testsuite/lib/libffi.exp +index 7dc7b5d19a3..46a0796ab4c 100644 +--- a/libffi/testsuite/lib/libffi.exp ++++ b/libffi/testsuite/lib/libffi.exp +@@ -337,8 +337,13 @@ proc libffi-init { args } { + verbose "libffi_dir $libffi_dir" + if { $libffi_dir != "" } { + set libffi_dir [file dirname ${libffi_dir}] +- set libffi_link_flags "-L${libffi_dir}/.libs" +- lappend libffi_link_flags "-L${blddircxx}/src/.libs" ++ if [istarget *-*-darwin*] { ++ set libffi_link_flags "-B${libffi_dir}/.libs" ++ lappend libffi_link_flags "-B${blddircxx}/src/.libs" ++ } else { ++ set libffi_link_flags "-L${libffi_dir}/.libs" ++ lappend libffi_link_flags "-L${blddircxx}/src/.libs" ++ } + } + + set_ld_library_path_env_vars +@@ -382,7 +387,7 @@ proc libffi_target_compile { source dest type options } { + # Darwin needs a stack execution allowed flag. + + if { [istarget "*-*-darwin9*"] || [istarget "*-*-darwin1*"] +- || [istarget "*-*-darwin2*"] } { ++ || [istarget "x86_64-*-darwin2*"] } { + lappend options "additional_flags=-Wl,-allow_stack_execute" + } + +diff --git a/libgcc/config.host b/libgcc/config.host +index 89e3dbc7c8a..96d093bdc9a 100644 +--- a/libgcc/config.host ++++ b/libgcc/config.host +@@ -82,7 +82,7 @@ m32c*-*-*) + cpu_type=m32c + tmake_file=t-fdpbit + ;; +-aarch64*-*-*) ++aarch64*-*-* | arm64*-*-*) + cpu_type=aarch64 + ;; + alpha*-*-*) +@@ -241,9 +241,11 @@ case ${host} in + ;; + esac + tmake_file="$tmake_file t-slibgcc-darwin" +- # newer toolsets produce warnings when building for unsupported versions. + case ${host} in +- *-*-darwin1[89]* | *-*-darwin2* ) ++ *-*-darwin2*) ++ tmake_file="t-darwin-min-11 $tmake_file" ++ ;; ++ *-*-darwin1[89]*) + tmake_file="t-darwin-min-8 $tmake_file" + ;; + *-*-darwin9* | *-*-darwin1[0-7]*) +@@ -259,7 +261,29 @@ case ${host} in + echo "Warning: libgcc configured to support macOS 10.5" 1>&2 + ;; + esac +- extra_parts="crt3.o libd10-uwfef.a crttms.o crttme.o libemutls_w.a" ++ # We are not using libtool to build the libs here, so we need to replicate ++ # a little of the logic around setting Darwin rpaths. Setting an explicit ++ # yes or no is honoured, otherwise we choose a suitable default. ++ # Sadly, this has to be kept in line with the rules in libtool.m4. ++ # This make fragment will override the setting in t-slibgcc-darwin so it ++ # must appear after it. ++ if test "x$enable_darwin_at_rpath" = "x"; then ++ echo "enable_darwin_at_rpath is unset" 1>&2 ++ case ${host} in ++ *-darwin[45678]*) ;; ++ *-darwin9* | *-darwin1[01234]*) ;; # We might default these on later. ++ *-darwin*) ++ echo "but is needed after macOS 10.11 (setting it on)" 1>&2 ++ enable_darwin_at_rpath=yes ++ ;; ++ esac ++ else ++ echo "enable_darwin_at_rpath is '$enable_darwin_at_rpath'" 1>&2 ++ fi ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ tmake_file="$tmake_file t-darwin-rpath " ++ fi ++ extra_parts="crt3.o crttms.o crttme.o libemutls_w.a " + ;; + *-*-dragonfly*) + tmake_file="$tmake_file t-crtstuff-pic t-libgcc-pic t-eh-dw2-dip" +@@ -402,6 +426,15 @@ aarch64*-*-elf | aarch64*-*-rtems*) + tmake_file="${tmake_file} ${cpu_type}/t-softfp t-softfp t-crtfm" + md_unwind_header=aarch64/aarch64-unwind.h + ;; ++aarch64*-*-darwin*) ++ extra_parts="$extra_parts crtfastmath.o libheapt_w.a" ++ tmake_file="${tmake_file} ${cpu_type}/t-aarch64" ++ tmake_file="${tmake_file} ${cpu_type}/t-lse " ++ tmake_file="${tmake_file} ${cpu_type}/t-softfp t-softfp " ++ tmake_file="${tmake_file} t-crtfm" ++ tmake_file="${tmake_file} ${cpu_type}/t-heap-trampoline" ++ md_unwind_header=aarch64/aarch64-unwind.h ++ ;; + aarch64*-*-freebsd*) + extra_parts="$extra_parts crtfastmath.o" + tmake_file="${tmake_file} ${cpu_type}/t-aarch64" +@@ -426,6 +459,7 @@ aarch64*-*-linux*) + tmake_file="${tmake_file} ${cpu_type}/t-aarch64" + tmake_file="${tmake_file} ${cpu_type}/t-lse t-slibgcc-libgcc" + tmake_file="${tmake_file} ${cpu_type}/t-softfp t-softfp t-crtfm" ++ tmake_file="${tmake_file} ${cpu_type}/t-heap-trampoline" + ;; + aarch64*-*-vxworks7*) + extra_parts="$extra_parts crtfastmath.o" +@@ -719,12 +753,18 @@ hppa*-*-netbsd*) + i[34567]86-*-darwin*) + tmake_file="$tmake_file i386/t-crtpc t-crtfm i386/t-msabi" + tm_file="$tm_file i386/darwin-lib.h" +- extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o" ++ extra_parts="$extra_parts libd10-uwfef.a " ++ extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o" ++ extra_parts="$extra_parts crtfastmath.o libheapt_w.a" ++ tmake_file="${tmake_file} i386/t-heap-trampoline" + ;; + x86_64-*-darwin*) + tmake_file="$tmake_file i386/t-crtpc t-crtfm i386/t-msabi" + tm_file="$tm_file i386/darwin-lib.h" +- extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o" ++ extra_parts="$extra_parts libd10-uwfef.a " ++ extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o" ++ extra_parts="$extra_parts crtfastmath.o libheapt_w.a" ++ tmake_file="${tmake_file} i386/t-heap-trampoline" + ;; + i[34567]86-*-elfiamcu) + tmake_file="$tmake_file i386/t-crtstuff t-softfp-sfdftf i386/32/t-softfp i386/32/t-iamcu i386/t-softfp t-softfp t-dfprules" +@@ -774,6 +814,7 @@ i[34567]86-*-linux*) + tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules" + tm_file="${tm_file} i386/elf-lib.h" + md_unwind_header=i386/linux-unwind.h ++ tmake_file="${tmake_file} i386/t-heap-trampoline" + ;; + i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-kopensolaris*-gnu) + extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o" +@@ -791,6 +832,7 @@ x86_64-*-linux*) + tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules" + tm_file="${tm_file} i386/elf-lib.h" + md_unwind_header=i386/linux-unwind.h ++ tmake_file="${tmake_file} i386/t-heap-trampoline" + ;; + x86_64-*-kfreebsd*-gnu) + extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o" +@@ -1187,12 +1229,14 @@ powerpc-*-darwin*) + # We build the darwin10 EH shim for Rosetta (running on x86 machines). + tm_file="$tm_file i386/darwin-lib.h" + tmake_file="$tmake_file rs6000/t-ppc64-fp rs6000/t-ibm-ldouble" ++ extra_parts="$extra_parts libd10-uwfef.a " + extra_parts="$extra_parts crt2.o crt3_2.o libef_ppc.a dw_ppc.o" + ;; + powerpc64-*-darwin*) + # We build the darwin10 EH shim for Rosetta (running on x86 machines). + tm_file="$tm_file i386/darwin-lib.h" + tmake_file="$tmake_file rs6000/t-darwin64 rs6000/t-ibm-ldouble" ++ extra_parts="$extra_parts libd10-uwfef.a " + extra_parts="$extra_parts crt2.o crt3_2.o libef_ppc.a dw_ppc.o" + ;; + powerpc*-*-freebsd*) +diff --git a/libgcc/config/aarch64/heap-trampoline.c b/libgcc/config/aarch64/heap-trampoline.c +new file mode 100644 +index 00000000000..b2c69aa5892 +--- /dev/null ++++ b/libgcc/config/aarch64/heap-trampoline.c +@@ -0,0 +1,185 @@ ++/* Copyright The GNU Toolchain Authors. */ ++ ++/* libc is required to allocate trampolines. */ ++#ifndef inhibit_libc ++ ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#if __APPLE__ ++/* For pthread_jit_write_protect_np */ ++#include ++#endif ++ ++/* HEAP_T_ATTR is provided to allow targets to build the exported functions ++ as weak definitions. */ ++#ifndef HEAP_T_ATTR ++# define HEAP_T_ATTR ++#endif ++ ++void *allocate_trampoline_page (void); ++int get_trampolines_per_page (void); ++struct tramp_ctrl_data *allocate_tramp_ctrl (struct tramp_ctrl_data *parent); ++void *allocate_trampoline_page (void); ++ ++void __gcc_nested_func_ptr_created (void *chain, void *func, void **dst); ++void __gcc_nested_func_ptr_deleted (void); ++ ++#if defined(__linux__) ++static const unsigned char aarch64_trampoline_insns[6][4] = { ++ {0x5f, 0x24, 0x03, 0xd5}, /* hint 34 */ ++ {0xb1, 0x00, 0x00, 0x58}, /* ldr x17, .+20 */ ++ {0xd2, 0x00, 0x00, 0x58}, /* ldr x18, .+24 */ ++ {0x20, 0x02, 0x1f, 0xd6}, /* br x17 */ ++ {0x9f, 0x3f, 0x03, 0xd5}, /* dsb sy */ ++ {0xdf, 0x3f, 0x03, 0xd5} /* isb */ ++}; ++ ++#elif __APPLE__ ++static const unsigned char aarch64_trampoline_insns[6][4] = { ++ {0x5f, 0x24, 0x03, 0xd5}, /* hint 34 */ ++ {0xb1, 0x00, 0x00, 0x58}, /* ldr x17, .+20 */ ++ {0xd0, 0x00, 0x00, 0x58}, /* ldr x16, .+24 */ ++ {0x20, 0x02, 0x1f, 0xd6}, /* br x17 */ ++ {0x9f, 0x3f, 0x03, 0xd5}, /* dsb sy */ ++ {0xdf, 0x3f, 0x03, 0xd5} /* isb */ ++}; ++ ++#else ++#error "Unsupported AArch64 platform for heap trampolines" ++#endif ++ ++struct aarch64_trampoline { ++ unsigned char insns[6][4]; ++ void *func_ptr; ++ void *chain_ptr; ++}; ++ ++struct tramp_ctrl_data ++{ ++ struct tramp_ctrl_data *prev; ++ ++ int free_trampolines; ++ ++ /* This will be pointing to an executable mmap'ed page. */ ++ struct aarch64_trampoline *trampolines; ++}; ++ ++int ++get_trampolines_per_page (void) ++{ ++ return getpagesize() / sizeof(struct aarch64_trampoline); ++} ++ ++static _Thread_local struct tramp_ctrl_data *tramp_ctrl_curr = NULL; ++ ++void * ++allocate_trampoline_page (void) ++{ ++ void *page; ++ ++#if defined(__linux__) ++ page = mmap (0, getpagesize (), PROT_WRITE | PROT_EXEC, ++ MAP_ANON | MAP_PRIVATE, 0, 0); ++#elif __APPLE__ ++ page = mmap (0, getpagesize (), PROT_WRITE | PROT_EXEC, ++ MAP_ANON | MAP_PRIVATE | MAP_JIT, 0, 0); ++#else ++ page = MAP_FAILED; ++#endif ++ ++ return page; ++} ++ ++struct tramp_ctrl_data * ++allocate_tramp_ctrl (struct tramp_ctrl_data *parent) ++{ ++ struct tramp_ctrl_data *p = malloc (sizeof (struct tramp_ctrl_data)); ++ if (p == NULL) ++ return NULL; ++ ++ p->trampolines = allocate_trampoline_page (); ++ ++ if (p->trampolines == MAP_FAILED) ++ return NULL; ++ ++ p->prev = parent; ++ p->free_trampolines = get_trampolines_per_page(); ++ ++ return p; ++} ++ ++HEAP_T_ATTR ++void ++__gcc_nested_func_ptr_created (void *chain, void *func, void **dst) ++{ ++ if (tramp_ctrl_curr == NULL) ++ { ++ tramp_ctrl_curr = allocate_tramp_ctrl (NULL); ++ if (tramp_ctrl_curr == NULL) ++ abort (); ++ } ++ ++ if (tramp_ctrl_curr->free_trampolines == 0) ++ { ++ void *tramp_ctrl = allocate_tramp_ctrl (tramp_ctrl_curr); ++ if (!tramp_ctrl) ++ abort (); ++ ++ tramp_ctrl_curr = tramp_ctrl; ++ } ++ ++ struct aarch64_trampoline *trampoline ++ = &tramp_ctrl_curr->trampolines[get_trampolines_per_page () ++ - tramp_ctrl_curr->free_trampolines]; ++ ++#if __APPLE__ ++ /* Disable write protection for the MAP_JIT regions in this thread (see ++ https://developer.apple.com/documentation/apple-silicon/porting-just-in-time-compilers-to-apple-silicon) */ ++ pthread_jit_write_protect_np (0); ++#endif ++ ++ memcpy (trampoline->insns, aarch64_trampoline_insns, ++ sizeof(aarch64_trampoline_insns)); ++ trampoline->func_ptr = func; ++ trampoline->chain_ptr = chain; ++ ++#if __APPLE__ ++ /* Re-enable write protection. */ ++ pthread_jit_write_protect_np (1); ++#endif ++ ++ tramp_ctrl_curr->free_trampolines -= 1; ++ ++ __builtin___clear_cache ((void *)trampoline->insns, ++ ((void *)trampoline->insns + sizeof(trampoline->insns))); ++ ++ *dst = &trampoline->insns; ++} ++ ++HEAP_T_ATTR ++void ++__gcc_nested_func_ptr_deleted (void) ++{ ++ if (tramp_ctrl_curr == NULL) ++ abort (); ++ ++ tramp_ctrl_curr->free_trampolines += 1; ++ ++ if (tramp_ctrl_curr->free_trampolines == get_trampolines_per_page ()) ++ { ++ if (tramp_ctrl_curr->prev == NULL) ++ return; ++ ++ munmap (tramp_ctrl_curr->trampolines, getpagesize()); ++ struct tramp_ctrl_data *prev = tramp_ctrl_curr->prev; ++ free (tramp_ctrl_curr); ++ tramp_ctrl_curr = prev; ++ } ++} ++ ++#endif /* !inhibit_libc */ +diff --git a/libgcc/config/aarch64/lse.S b/libgcc/config/aarch64/lse.S +index 9c29cf08b59..97b68c42cc1 100644 +--- a/libgcc/config/aarch64/lse.S ++++ b/libgcc/config/aarch64/lse.S +@@ -58,7 +58,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + #endif + + /* Declare the symbol gating the LSE implementations. */ ++#if __ELF__ + .hidden __aarch64_have_lse_atomics ++#else ++ .private_extern __aarch64_have_lse_atomics ++#endif + + /* Turn size and memory model defines into mnemonic fragments. */ + #if SIZE == 1 +@@ -164,6 +168,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + #define BTI_C hint 34 + + /* Start and end a function. */ ++#if __ELF__ + .macro STARTFN name + .text + .balign 16 +@@ -187,6 +192,29 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + cbz w(tmp0), \label + .endm + ++#else ++.macro STARTFN name ++ .text ++ .balign 16 ++ .private_extern _\name ++ .cfi_startproc ++_\name: ++ BTI_C ++.endm ++ ++.macro ENDFN name ++ .cfi_endproc ++.endm ++ ++/* Branch to LABEL if LSE is disabled. */ ++.macro JUMP_IF_NOT_LSE label ++ adrp x(tmp0), ___aarch64_have_lse_atomics@PAGE ++ ldrb w(tmp0), [x(tmp0), ___aarch64_have_lse_atomics@PAGEOFF] ++ cbz w(tmp0), \label ++.endm ++ ++#endif ++ + #ifdef L_cas + + STARTFN NAME(cas) +diff --git a/libgcc/config/aarch64/sfp-machine.h b/libgcc/config/aarch64/sfp-machine.h +index be9b42174c4..5dc1827ee3a 100644 +--- a/libgcc/config/aarch64/sfp-machine.h ++++ b/libgcc/config/aarch64/sfp-machine.h +@@ -122,6 +122,27 @@ void __sfp_handle_exceptions (int); + + + /* Define ALIASNAME as a strong alias for NAME. */ ++#if defined __APPLE__ ++/* Mach-O doesn't support aliasing, so we build a secondary function for ++ the alias - we need to do a bit of a dance to find out what the type of ++ the arguments is and then apply that to the secondary function. ++ If these functions ever return anything but CMPtype we need to revisit ++ this... */ ++typedef float alias_HFtype __attribute__ ((mode (HF))); ++typedef float alias_SFtype __attribute__ ((mode (SF))); ++typedef float alias_DFtype __attribute__ ((mode (DF))); ++typedef float alias_TFtype __attribute__ ((mode (TF))); ++#define ALIAS_SELECTOR \ ++ CMPtype (*) (alias_HFtype, alias_HFtype): (alias_HFtype) 0, \ ++ CMPtype (*) (alias_SFtype, alias_SFtype): (alias_SFtype) 0, \ ++ CMPtype (*) (alias_DFtype, alias_DFtype): (alias_DFtype) 0, \ ++ CMPtype (*) (alias_TFtype, alias_TFtype): (alias_TFtype) 0 ++#define strong_alias(name, aliasname) \ ++ CMPtype aliasname (__typeof (_Generic (name, ALIAS_SELECTOR)) a, \ ++ __typeof (_Generic (name, ALIAS_SELECTOR)) b) \ ++ { return name (a, b); } ++#else + # define strong_alias(name, aliasname) _strong_alias(name, aliasname) + # define _strong_alias(name, aliasname) \ + extern __typeof (name) aliasname __attribute__ ((alias (#name))); ++#endif +diff --git a/libgcc/config/aarch64/t-darwin b/libgcc/config/aarch64/t-darwin +new file mode 100644 +index 00000000000..f6ecda7b608 +--- /dev/null ++++ b/libgcc/config/aarch64/t-darwin +@@ -0,0 +1,7 @@ ++# Ensure we have a suitable minimum OS version. ++ ++HOST_LIBGCC2_CFLAGS += -mmacosx-version-min=11.0 ++ ++LIB2_SIDITI_CONV_FUNCS = yes ++ ++BUILD_LIBGCCS1 = +diff --git a/libgcc/config/aarch64/t-heap-trampoline b/libgcc/config/aarch64/t-heap-trampoline +new file mode 100644 +index 00000000000..6468fb8704f +--- /dev/null ++++ b/libgcc/config/aarch64/t-heap-trampoline +@@ -0,0 +1,20 @@ ++# Copyright The GNU Toolchain Authors. ++ ++# This file is part of GCC. ++# ++# GCC is free software; you can redistribute it and/or modify it ++# under the terms of the GNU General Public License as published by ++# the Free Software Foundation; either version 3, or (at your option) ++# any later version. ++# ++# GCC is distributed in the hope that it will be useful, but ++# WITHOUT ANY WARRANTY; without even the implied warranty of ++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++# General Public License for more details. ++# ++# You should have received a copy of the GNU General Public License ++# along with GCC; see the file COPYING3. If not see ++# . ++ ++LIB2ADDEH += $(srcdir)/config/aarch64/heap-trampoline.c ++LIB2ADDEHSHARED += $(srcdir)/config/aarch64/heap-trampoline.c +diff --git a/libgcc/config/i386/heap-trampoline.c b/libgcc/config/i386/heap-trampoline.c +new file mode 100644 +index 00000000000..2e8df1cfbd2 +--- /dev/null ++++ b/libgcc/config/i386/heap-trampoline.c +@@ -0,0 +1,255 @@ ++/* Copyright The GNU Toolchain Authors. */ ++ ++/* libc is required to allocate trampolines. */ ++#ifndef inhibit_libc ++ ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#if __APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101400 ++/* For pthread_jit_write_protect_np */ ++#include ++#endif ++ ++/* HEAP_T_ATTR is provided to allow targets to build the exported functions ++ as weak definitions. */ ++#ifndef HEAP_T_ATTR ++# define HEAP_T_ATTR ++#endif ++ ++void *allocate_trampoline_page (void); ++int get_trampolines_per_page (void); ++struct tramp_ctrl_data *allocate_tramp_ctrl (struct tramp_ctrl_data *parent); ++void *allocate_trampoline_page (void); ++ ++void __gcc_nested_func_ptr_created (void *chain, void *func, void **dst); ++void __gcc_nested_func_ptr_deleted (void); ++ ++#if __x86_64__ ++ ++#ifdef __LP64__ ++static const uint8_t trampoline_insns[] = { ++#if defined __CET__ && (__CET__ & 1) != 0 ++ /* endbr64. */ ++ 0xf3, 0x0f, 0x1e, 0xfa, ++#endif ++ ++ /* movabsq $,%r11 */ ++ 0x49, 0xbb, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++ ++ /* movabsq $,%r10 */ ++ 0x49, 0xba, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++ ++ /* rex.WB jmpq *%r11 */ ++ 0x41, 0xff, 0xe3, ++ ++ /* Pad to the multiple of 4 bytes. */ ++ 0x90 ++}; ++#else ++static const uint8_t trampoline_insns[] = { ++#if defined __CET__ && (__CET__ & 1) != 0 ++ /* endbr64. */ ++ 0xf3, 0x0f, 0x1e, 0xfa, ++#endif ++ ++ /* movl $,%r11d */ ++ 0x41, 0xbb, ++ 0x00, 0x00, 0x00, 0x00, ++ ++ /* movl $,%r10d */ ++ 0x41, 0xba, ++ 0x00, 0x00, 0x00, 0x00, ++ ++ /* rex.WB jmpq *%r11 */ ++ 0x41, 0xff, 0xe3, ++ ++ /* Pad to the multiple of 4 bytes. */ ++ 0x90 ++}; ++#endif ++ ++union ix86_trampoline { ++ uint8_t insns[sizeof(trampoline_insns)]; ++ ++ struct __attribute__((packed)) fields { ++#if defined __CET__ && (__CET__ & 1) != 0 ++ uint8_t endbr64[4]; ++#endif ++ uint8_t insn_0[2]; ++ void *func_ptr; ++ uint8_t insn_1[2]; ++ void *chain_ptr; ++ uint8_t insn_2[3]; ++ uint8_t pad; ++ } fields; ++}; ++ ++#elif __i386__ ++ ++static const uint8_t trampoline_insns[] = { ++ /* movl $,%ecx */ ++ 0xb9, ++ 0x00, 0x00, 0x00, 0x00, ++ ++ /* jmpl -. */ ++ 0xe9, ++ 0x00, 0x00, 0x00, 0x00, ++}; ++ ++union ix86_trampoline { ++ uint8_t insns[sizeof(trampoline_insns)]; ++ ++ struct __attribute__((packed)) fields { ++ uint8_t insn_0[1]; ++ void *chain_ptr; ++ uint8_t insn_1[1]; ++ uintptr_t func_offset; ++ } fields; ++}; ++ ++#else ++#error unsupported architecture/ABI ++#endif ++ ++struct tramp_ctrl_data ++{ ++ struct tramp_ctrl_data *prev; ++ ++ int free_trampolines; ++ ++ /* This will be pointing to an executable mmap'ed page. */ ++ union ix86_trampoline *trampolines; ++}; ++ ++int ++get_trampolines_per_page (void) ++{ ++ return getpagesize() / sizeof(union ix86_trampoline); ++} ++ ++static _Thread_local struct tramp_ctrl_data *tramp_ctrl_curr = NULL; ++ ++void * ++allocate_trampoline_page (void) ++{ ++ void *page; ++ ++#if defined(__gnu_linux__) ++ page = mmap (0, getpagesize (), PROT_WRITE | PROT_EXEC, ++ MAP_ANON | MAP_PRIVATE, 0, 0); ++#elif __APPLE__ ++# if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101400 ++ page = mmap (0, getpagesize (), PROT_WRITE | PROT_EXEC, ++ MAP_ANON | MAP_PRIVATE | MAP_JIT, 0, 0); ++# else ++ page = mmap (0, getpagesize (), PROT_WRITE | PROT_EXEC, ++ MAP_ANON | MAP_PRIVATE, 0, 0); ++# endif ++#else ++ page = MAP_FAILED; ++#endif ++ ++ return page; ++} ++ ++struct tramp_ctrl_data * ++allocate_tramp_ctrl (struct tramp_ctrl_data *parent) ++{ ++ struct tramp_ctrl_data *p = malloc (sizeof (struct tramp_ctrl_data)); ++ if (p == NULL) ++ return NULL; ++ ++ p->trampolines = allocate_trampoline_page (); ++ ++ if (p->trampolines == MAP_FAILED) ++ return NULL; ++ ++ p->prev = parent; ++ p->free_trampolines = get_trampolines_per_page(); ++ ++ return p; ++} ++ ++HEAP_T_ATTR ++void ++__gcc_nested_func_ptr_created (void *chain, void *func, void **dst) ++{ ++ if (tramp_ctrl_curr == NULL) ++ { ++ tramp_ctrl_curr = allocate_tramp_ctrl (NULL); ++ if (tramp_ctrl_curr == NULL) ++ abort (); ++ } ++ ++ if (tramp_ctrl_curr->free_trampolines == 0) ++ { ++ void *tramp_ctrl = allocate_tramp_ctrl (tramp_ctrl_curr); ++ if (!tramp_ctrl) ++ abort (); ++ ++ tramp_ctrl_curr = tramp_ctrl; ++ } ++ ++ union ix86_trampoline *trampoline ++ = &tramp_ctrl_curr->trampolines[get_trampolines_per_page () ++ - tramp_ctrl_curr->free_trampolines]; ++ ++#if __APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101400 ++ /* Disable write protection for the MAP_JIT regions in this thread (see ++ https://developer.apple.com/documentation/apple-silicon/porting-just-in-time-compilers-to-apple-silicon) */ ++ pthread_jit_write_protect_np (0); ++#endif ++ ++ memcpy (trampoline->insns, trampoline_insns, ++ sizeof(trampoline_insns)); ++ trampoline->fields.chain_ptr = chain; ++#if __x86_64__ ++ trampoline->fields.func_ptr = func; ++#elif __i386__ ++ uintptr_t off_add = (uintptr_t) &trampoline->fields.func_offset; ++ off_add += 4; ++ trampoline->fields.func_offset = (uintptr_t)func - off_add; ++#endif ++ ++#if __APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101400 ++ /* Re-enable write protection. */ ++ pthread_jit_write_protect_np (1); ++#endif ++ ++ tramp_ctrl_curr->free_trampolines -= 1; ++ ++ __builtin___clear_cache ((void *)trampoline->insns, ++ ((void *)trampoline->insns + sizeof(trampoline->insns))); ++ ++ *dst = &trampoline->insns; ++} ++ ++HEAP_T_ATTR ++void ++__gcc_nested_func_ptr_deleted (void) ++{ ++ if (tramp_ctrl_curr == NULL) ++ abort (); ++ ++ tramp_ctrl_curr->free_trampolines += 1; ++ ++ if (tramp_ctrl_curr->free_trampolines == get_trampolines_per_page ()) ++ { ++ if (tramp_ctrl_curr->prev == NULL) ++ return; ++ ++ munmap (tramp_ctrl_curr->trampolines, getpagesize()); ++ struct tramp_ctrl_data *prev = tramp_ctrl_curr->prev; ++ free (tramp_ctrl_curr); ++ tramp_ctrl_curr = prev; ++ } ++} ++ ++#endif /* !inhibit_libc */ +diff --git a/libgcc/config/i386/t-heap-trampoline b/libgcc/config/i386/t-heap-trampoline +new file mode 100644 +index 00000000000..5cd11f594ba +--- /dev/null ++++ b/libgcc/config/i386/t-heap-trampoline +@@ -0,0 +1,20 @@ ++# Copyright The GNU Toolchain Authors. ++ ++# This file is part of GCC. ++# ++# GCC is free software; you can redistribute it and/or modify it ++# under the terms of the GNU General Public License as published by ++# the Free Software Foundation; either version 3, or (at your option) ++# any later version. ++# ++# GCC is distributed in the hope that it will be useful, but ++# WITHOUT ANY WARRANTY; without even the implied warranty of ++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++# General Public License for more details. ++# ++# You should have received a copy of the GNU General Public License ++# along with GCC; see the file COPYING3. If not see ++# . ++ ++LIB2ADDEH += $(srcdir)/config/i386/heap-trampoline.c ++LIB2ADDEHSHARED += $(srcdir)/config/i386/heap-trampoline.c +diff --git a/libgcc/config/t-darwin b/libgcc/config/t-darwin +index a3bb70c6a0a..0f65b54a230 100644 +--- a/libgcc/config/t-darwin ++++ b/libgcc/config/t-darwin +@@ -51,5 +51,18 @@ LIB2ADDEH = $(srcdir)/unwind-dw2.c \ + # Do not build a shared unwind lib by default. + LIBEHSOBJS= + ++# Make heap trampoline helpers weak definitions so that we can merge them from ++# multiple DSOs. ++heap-trampoline.o: HOST_LIBGCC2_CFLAGS += \ ++ -DHEAP_T_ATTR='__attribute__((__weak__,__visibility__("default")))' ++heap-trampoline_s.o: HOST_LIBGCC2_CFLAGS += \ ++ -DHEAP_T_ATTR='__attribute__((__weak__,__visibility__("default")))' ++ ++# Make a heap trampoline support CRT so that it can be linked optionally, use ++# the shared version so that we can link with DSOs. ++libheapt_w.a: heap-trampoline_s.o ++ $(AR_CREATE_FOR_TARGET) $@ $< ++ $(RANLIB_FOR_TARGET) $@ ++ + # Symbols for all the sub-ports. + SHLIB_MAPFILES = libgcc-std.ver $(srcdir)/config/libgcc-libsystem.ver +diff --git a/libgcc/config/t-darwin-min-11 b/libgcc/config/t-darwin-min-11 +new file mode 100644 +index 00000000000..4009d41addb +--- /dev/null ++++ b/libgcc/config/t-darwin-min-11 +@@ -0,0 +1,3 @@ ++# Support building with -mmacosx-version-min back to macOS 11. ++DARWIN_MIN_LIB_VERSION = -mmacosx-version-min=11 ++DARWIN_MIN_CRT_VERSION = -mmacosx-version-min=11 +diff --git a/libgcc/config/t-darwin-rpath b/libgcc/config/t-darwin-rpath +new file mode 100644 +index 00000000000..e73d7f378b0 +--- /dev/null ++++ b/libgcc/config/t-darwin-rpath +@@ -0,0 +1,2 @@ ++# Use @rpath and add a search path to exes and dylibs that depend on this. ++SHLIB_RPATH = @rpath +diff --git a/libgcc/config/t-slibgcc-darwin b/libgcc/config/t-slibgcc-darwin +index cb0cbbdb1c5..da4886848e8 100644 +--- a/libgcc/config/t-slibgcc-darwin ++++ b/libgcc/config/t-slibgcc-darwin +@@ -1,4 +1,4 @@ +-# Build a shared libgcc library with the darwin linker. ++# Build a shared libgcc library able to use embedded runpaths. + + SHLIB_SOVERSION = 1.1 + SHLIB_SO_MINVERSION = 1 +@@ -6,7 +6,6 @@ SHLIB_VERSTRING = -compatibility_version $(SHLIB_SO_MINVERSION) \ + -current_version $(SHLIB_SOVERSION) + SHLIB_EXT = .dylib + SHLIB_LC = -lSystem +-SHLIB_INSTALL_DIR = $(slibdir) + + SHLIB_MKMAP = $(srcdir)/mkmap-flat.awk + SHLIB_MKMAP_OPTS = -v leading_underscore=1 +@@ -23,11 +22,16 @@ SHLIB_SONAME = @shlib_base_name@$(SHLIB_EXT) + # subdir. The code under MULTIBUILDTOP combines these into a single FAT + # library, that is what we eventually install. + ++# When enable_darwin_at_rpath is true, use @rpath instead of $(slibdir) for ++# this and dylibs that depend on this. So this def must come first and be ++# overridden in a make fragment that depends on the rpath setting. ++SHLIB_RPATH = $(slibdir) ++ + SHLIB_LINK = $(CC) $(LIBGCC2_CFLAGS) $(LDFLAGS) -dynamiclib -nodefaultlibs \ +- -install_name $(SHLIB_INSTALL_DIR)/$(SHLIB_INSTALL_NAME) \ ++ -install_name $(SHLIB_RPATH)/$(SHLIB_INSTALL_NAME) \ + -single_module -o $(SHLIB_DIR)/$(SHLIB_SONAME) \ + -Wl,-exported_symbols_list,$(SHLIB_MAP) \ +- $(SHLIB_VERSTRING) \ ++ $(SHLIB_VERSTRING) -nodefaultrpaths \ + @multilib_flags@ @shlib_objs@ $(SHLIB_LC) + + # we do our own thing +@@ -63,9 +67,9 @@ EHS_INSTNAME = libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT) + libgcc_ehs$(SHLIB_EXT): $(LIBEHSOBJS) $(extra-parts) + mkdir -p $(MULTIDIR) + $(CC) $(LIBGCC2_CFLAGS) $(LDFLAGS) -dynamiclib -nodefaultlibs \ +- -install_name $(SHLIB_INSTALL_DIR)/$(EHS_INSTNAME) \ ++ -install_name $(SHLIB_RPATH)/$(EHS_INSTNAME) \ + -o $(MULTIDIR)/libgcc_ehs$(SHLIB_EXT) $(SHLIB_VERSTRING) \ +- $(LIBEHSOBJS) $(SHLIB_LC) ++ -nodefaultrpaths $(LIBEHSOBJS) $(SHLIB_LC) + + all: libgcc_ehs$(SHLIB_EXT) + +@@ -122,12 +126,12 @@ libgcc_s.1.dylib: all-multi libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT) \ + cp ../$${mlib}/libgcc/$${mlib}/libgcc_ehs$(SHLIB_EXT) \ + ./libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} || exit 1 ; \ + arch=`$(LIPO) -info libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} | sed -e 's/.*:\ //'` ; \ +- $(CC) -arch $${arch} -nodefaultlibs -dynamiclib \ ++ $(CC) -arch $${arch} -nodefaultlibs -dynamiclib -nodefaultrpaths \ + -o libgcc_s.1$(SHLIB_EXT)_T_$${mlib} \ + -Wl,-reexport_library,libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} \ + -Wl,-reexport_library,libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} \ +- -install_name $(SHLIB_INSTALL_DIR)/libgcc_s.1.dylib \ +- -compatibility_version 1 -current_version 1 ; \ ++ -install_name $(SHLIB_RPATH)/libgcc_s.1.dylib \ ++ -compatibility_version 1 -current_version 1.1 ; \ + done + $(LIPO) -output libgcc_s.1$(SHLIB_EXT) -create libgcc_s.1$(SHLIB_EXT)_T* + rm libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T* +@@ -141,13 +145,13 @@ libgcc_s.1.dylib: all-multi libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT) + cp ../$${mlib}/libgcc/$${mlib}/libgcc_s$(SHLIB_EXT) \ + ./libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} || exit 1 ; \ + arch=`$(LIPO) -info libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} | sed -e 's/.*:\ //'` ; \ +- $(CC) -arch $${arch} -nodefaultlibs -dynamiclib \ ++ $(CC) -arch $${arch} -nodefaultlibs -dynamiclib -nodefaultrpaths \ + -o libgcc_s.1$(SHLIB_EXT)_T_$${mlib} \ + -Wl,-reexport_library,libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} \ + -lSystem \ + -Wl,-reexported_symbols_list,$(srcdir)/config/darwin-unwind.ver \ +- -install_name $(SHLIB_INSTALL_DIR)/libgcc_s.1.dylib \ +- -compatibility_version 1 -current_version 1 ; \ ++ -install_name $(SHLIB_RPATH)/libgcc_s.1.dylib \ ++ -compatibility_version 1 -current_version 1.1 ; \ + done + $(LIPO) -output libgcc_s.1$(SHLIB_EXT) -create libgcc_s.1$(SHLIB_EXT)_T* + rm libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T* +diff --git a/libgcc/libgcc-std.ver.in b/libgcc/libgcc-std.ver.in +index 513ddd0bd0d..38d9d53bf77 100644 +--- a/libgcc/libgcc-std.ver.in ++++ b/libgcc/libgcc-std.ver.in +@@ -1944,3 +1944,9 @@ GCC_7.0.0 { + __PFX__divmoddi4 + __PFX__divmodti4 + } ++ ++%inherit GCC_14.0.0 GCC_7.0.0 ++GCC_14.0.0 { ++ __gcc_nested_func_ptr_created ++ __gcc_nested_func_ptr_deleted ++} +diff --git a/libgcc/libgcc2.h b/libgcc/libgcc2.h +index fc24ac34502..7c90eaacdf8 100644 +--- a/libgcc/libgcc2.h ++++ b/libgcc/libgcc2.h +@@ -29,6 +29,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + #pragma GCC visibility push(default) + #endif + ++extern void __gcc_nested_func_ptr_created (void *, void *, void **); ++extern void __gcc_nested_func_ptr_deleted (void); ++ + extern int __gcc_bcmp (const unsigned char *, const unsigned char *, size_t); + extern void __clear_cache (void *, void *); + extern void __eprintf (const char *, const char *, unsigned int, const char *) +diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am +index 5ce0cd7cd05..b1338a201cd 100644 +--- a/libgfortran/Makefile.am ++++ b/libgfortran/Makefile.am +@@ -37,6 +37,11 @@ else + version_arg = + version_dep = + endif ++extra_darwin_ldflags_libgfortran = @extra_ldflags_libgfortran@ ++if ENABLE_DARWIN_AT_RPATH ++extra_darwin_ldflags_libgfortran += -Wc,-nodefaultrpaths ++extra_darwin_ldflags_libgfortran += -Wl,-rpath,@loader_path ++endif + + gfor_c_HEADERS = ISO_Fortran_binding.h + gfor_cdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include +@@ -50,7 +55,7 @@ libgfortran_la_LINK = $(LINK) $(libgfortran_la_LDFLAGS) + libgfortran_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ + $(LTLDFLAGS) $(LIBQUADLIB) ../libbacktrace/libbacktrace.la \ + $(HWCAP_LDFLAGS) \ +- $(LIBM) $(extra_ldflags_libgfortran) \ ++ $(LIBM) $(extra_darwin_ldflags_libgfortran) \ + $(version_arg) -Wc,-shared-libgcc + libgfortran_la_DEPENDENCIES = $(version_dep) libgfortran.spec $(LIBQUADLIB_DEP) + +diff --git a/libgfortran/Makefile.in b/libgfortran/Makefile.in +index 7ac6bfba657..52dd5f1819e 100644 +--- a/libgfortran/Makefile.in ++++ b/libgfortran/Makefile.in +@@ -91,8 +91,10 @@ POST_UNINSTALL = : + build_triplet = @build@ + host_triplet = @host@ + target_triplet = @target@ +-@LIBGFOR_MINIMAL_TRUE@am__append_1 = -DLIBGFOR_MINIMAL +-@LIBGFOR_MINIMAL_FALSE@am__append_2 = \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@am__append_1 = -Wc,-nodefaultrpaths \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path ++@LIBGFOR_MINIMAL_TRUE@am__append_2 = -DLIBGFOR_MINIMAL ++@LIBGFOR_MINIMAL_FALSE@am__append_3 = \ + @LIBGFOR_MINIMAL_FALSE@io/close.c \ + @LIBGFOR_MINIMAL_FALSE@io/file_pos.c \ + @LIBGFOR_MINIMAL_FALSE@io/format.c \ +@@ -110,7 +112,7 @@ target_triplet = @target@ + @LIBGFOR_MINIMAL_FALSE@io/fbuf.c \ + @LIBGFOR_MINIMAL_FALSE@io/async.c + +-@LIBGFOR_MINIMAL_FALSE@am__append_3 = \ ++@LIBGFOR_MINIMAL_FALSE@am__append_4 = \ + @LIBGFOR_MINIMAL_FALSE@intrinsics/access.c \ + @LIBGFOR_MINIMAL_FALSE@intrinsics/c99_functions.c \ + @LIBGFOR_MINIMAL_FALSE@intrinsics/chdir.c \ +@@ -143,9 +145,9 @@ target_triplet = @target@ + @LIBGFOR_MINIMAL_FALSE@intrinsics/umask.c \ + @LIBGFOR_MINIMAL_FALSE@intrinsics/unlink.c + +-@IEEE_SUPPORT_TRUE@am__append_4 = ieee/ieee_helper.c +-@LIBGFOR_MINIMAL_TRUE@am__append_5 = runtime/minimal.c +-@LIBGFOR_MINIMAL_FALSE@am__append_6 = \ ++@IEEE_SUPPORT_TRUE@am__append_5 = ieee/ieee_helper.c ++@LIBGFOR_MINIMAL_TRUE@am__append_6 = runtime/minimal.c ++@LIBGFOR_MINIMAL_FALSE@am__append_7 = \ + @LIBGFOR_MINIMAL_FALSE@runtime/backtrace.c \ + @LIBGFOR_MINIMAL_FALSE@runtime/convert_char.c \ + @LIBGFOR_MINIMAL_FALSE@runtime/environ.c \ +@@ -157,7 +159,7 @@ target_triplet = @target@ + + + # dummy sources for libtool +-@onestep_TRUE@am__append_7 = libgfortran_c.c libgfortran_f.f90 ++@onestep_TRUE@am__append_8 = libgfortran_c.c libgfortran_f.f90 + subdir = . + ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 + am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \ +@@ -589,7 +591,7 @@ AMTAR = @AMTAR@ + + # Some targets require additional compiler options for IEEE compatibility. + AM_CFLAGS = @AM_CFLAGS@ -fcx-fortran-rules $(SECTION_FLAGS) \ +- $(IEEE_FLAGS) $(am__append_1) ++ $(IEEE_FLAGS) $(am__append_2) + AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ + AM_FCFLAGS = @AM_FCFLAGS@ $(IEEE_FLAGS) + AR = @AR@ +@@ -748,6 +750,8 @@ gcc_version := $(shell @get_gcc_base_ver@ $(top_srcdir)/../gcc/BASE-VER) + @LIBGFOR_USE_SYMVER_FALSE@version_dep = + @LIBGFOR_USE_SYMVER_GNU_TRUE@@LIBGFOR_USE_SYMVER_TRUE@version_dep = gfortran.ver + @LIBGFOR_USE_SYMVER_SUN_TRUE@@LIBGFOR_USE_SYMVER_TRUE@version_dep = gfortran.ver-sun gfortran.ver ++extra_darwin_ldflags_libgfortran = @extra_ldflags_libgfortran@ \ ++ $(am__append_1) + gfor_c_HEADERS = ISO_Fortran_binding.h + gfor_cdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include + LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS)) \ +@@ -759,7 +763,7 @@ libgfortran_la_LINK = $(LINK) $(libgfortran_la_LDFLAGS) + libgfortran_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ + $(LTLDFLAGS) $(LIBQUADLIB) ../libbacktrace/libbacktrace.la \ + $(HWCAP_LDFLAGS) \ +- $(LIBM) $(extra_ldflags_libgfortran) \ ++ $(LIBM) $(extra_darwin_ldflags_libgfortran) \ + $(version_arg) -Wc,-shared-libgcc + + libgfortran_la_DEPENDENCIES = $(version_dep) libgfortran.spec $(LIBQUADLIB_DEP) +@@ -780,7 +784,7 @@ AM_CPPFLAGS = -iquote$(srcdir)/io -I$(srcdir)/$(MULTISRCTOP)../gcc \ + -I$(MULTIBUILDTOP)../libbacktrace \ + -I../libbacktrace + +-gfor_io_src = io/size_from_kind.c $(am__append_2) ++gfor_io_src = io/size_from_kind.c $(am__append_3) + gfor_io_headers = \ + io/io.h \ + io/fbuf.h \ +@@ -802,7 +806,7 @@ gfor_helper_src = intrinsics/associated.c intrinsics/abort.c \ + intrinsics/selected_int_kind.f90 \ + intrinsics/selected_real_kind.f90 intrinsics/trigd.c \ + intrinsics/unpack_generic.c runtime/in_pack_generic.c \ +- runtime/in_unpack_generic.c $(am__append_3) $(am__append_4) ++ runtime/in_unpack_generic.c $(am__append_4) $(am__append_5) + @IEEE_SUPPORT_TRUE@gfor_ieee_helper_src = ieee/ieee_helper.c + @IEEE_SUPPORT_FALSE@gfor_ieee_src = + @IEEE_SUPPORT_TRUE@gfor_ieee_src = \ +@@ -811,8 +815,8 @@ gfor_helper_src = intrinsics/associated.c intrinsics/abort.c \ + @IEEE_SUPPORT_TRUE@ieee/ieee_features.F90 + + gfor_src = runtime/bounds.c runtime/compile_options.c runtime/memory.c \ +- runtime/string.c runtime/select.c $(am__append_5) \ +- $(am__append_6) ++ runtime/string.c runtime/select.c $(am__append_6) \ ++ $(am__append_7) + i_all_c = \ + $(srcdir)/generated/all_l1.c \ + $(srcdir)/generated/all_l2.c \ +@@ -1652,7 +1656,7 @@ intrinsics/random_init.f90 + + BUILT_SOURCES = $(gfor_built_src) $(gfor_built_specific_src) \ + $(gfor_built_specific2_src) $(gfor_misc_specifics) \ +- $(am__append_7) ++ $(am__append_8) + prereq_SRC = $(gfor_src) $(gfor_built_src) $(gfor_io_src) \ + $(gfor_helper_src) $(gfor_ieee_src) $(gfor_io_headers) $(gfor_specific_src) + +diff --git a/libgfortran/configure b/libgfortran/configure +index ae64dca3114..625269e4924 100755 +--- a/libgfortran/configure ++++ b/libgfortran/configure +@@ -655,6 +655,8 @@ extra_ldflags_libgfortran + ac_ct_FC + FCFLAGS + FC ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + enable_static + enable_shared + lt_host_flags +@@ -824,6 +826,7 @@ enable_static + with_pic + enable_fast_install + enable_libtool_lock ++enable_darwin_at_rpath + enable_largefile + enable_libquadmath_support + with_gcc_major_version_only +@@ -1479,6 +1482,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --disable-largefile omit support for large files + --disable-libquadmath-support + disable libquadmath support for Fortran +@@ -9229,7 +9235,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -10939,6 +10945,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -10956,9 +11005,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -12766,7 +12819,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12769 "configure" ++#line 12822 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -12872,7 +12925,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12875 "configure" ++#line 12928 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -13274,6 +13327,14 @@ esac + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ + #AC_MSG_NOTICE([====== Finished libtool configuration]) ; sleep 10 + + # We need gfortran to compile parts of the library +@@ -14917,6 +14978,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc_FC=no + hardcode_direct_FC=no + hardcode_automatic_FC=yes +@@ -14934,9 +15038,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds_FC="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_FC="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds_FC="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds_FC="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds_FC="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds_FC="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -16190,9 +16298,10 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + # extra LD Flags which are required for targets ++extra_ldflags_libgfortran= + case "${host}" in +- *-darwin*) +- # Darwin needs -single_module when linking libgfortran ++ *-*-darwin[4567]*) ++ # Earlier Darwin needs -single_module when linking libgfortran + extra_ldflags_libgfortran=-Wl,-single_module + ;; + esac +@@ -28519,6 +28628,10 @@ if test -z "${HAVE_HWCAP_TRUE}" && test -z "${HAVE_HWCAP_FALSE}"; then + as_fn_error $? "conditional \"HAVE_HWCAP\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${LIBGFOR_BUILD_QUAD_TRUE}" && test -z "${LIBGFOR_BUILD_QUAD_FALSE}"; then + as_fn_error $? "conditional \"LIBGFOR_BUILD_QUAD\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac +index 97cc490cb5e..a21f56648a2 100644 +--- a/libgfortran/configure.ac ++++ b/libgfortran/configure.ac +@@ -282,6 +282,7 @@ LT_LIB_M + ACX_LT_HOST_FLAGS + AC_SUBST(enable_shared) + AC_SUBST(enable_static) ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) + #AC_MSG_NOTICE([====== Finished libtool configuration]) ; sleep 10 + + # We need gfortran to compile parts of the library +@@ -290,9 +291,10 @@ FC="$GFORTRAN" + AC_PROG_FC(gfortran) + + # extra LD Flags which are required for targets ++extra_ldflags_libgfortran= + case "${host}" in +- *-darwin*) +- # Darwin needs -single_module when linking libgfortran ++ *-*-darwin[[4567]]*) ++ # Earlier Darwin needs -single_module when linking libgfortran + extra_ldflags_libgfortran=-Wl,-single_module + ;; + esac +diff --git a/libgo/configure b/libgo/configure +index ffe17c9be55..de5c1ac9b3d 100755 +--- a/libgo/configure ++++ b/libgo/configure +@@ -708,6 +708,8 @@ glibgo_toolexecdir + WERROR + WARN_FLAGS + CC_FOR_BUILD ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + enable_static + enable_shared + CPP +@@ -11544,7 +11546,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11547 "configure" ++#line 11549 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11650,7 +11652,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11653 "configure" ++#line 11655 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -13779,6 +13781,14 @@ CC="$lt_save_CC" + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ + + CC_FOR_BUILD=${CC_FOR_BUILD:-gcc} + +@@ -16321,6 +16331,10 @@ if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then + as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${USE_LIBFFI_TRUE}" && test -z "${USE_LIBFFI_FALSE}"; then + as_fn_error $? "conditional \"USE_LIBFFI\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/libgo/configure.ac b/libgo/configure.ac +index 7e2b98ba67c..7b0222bb620 100644 +--- a/libgo/configure.ac ++++ b/libgo/configure.ac +@@ -53,6 +53,7 @@ AC_LIBTOOL_DLOPEN + AM_PROG_LIBTOOL + AC_SUBST(enable_shared) + AC_SUBST(enable_static) ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) + + CC_FOR_BUILD=${CC_FOR_BUILD:-gcc} + AC_SUBST(CC_FOR_BUILD) +diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am +index f8b2a06d63e..81ba6c634fa 100644 +--- a/libgomp/Makefile.am ++++ b/libgomp/Makefile.am +@@ -53,9 +53,14 @@ else + libgomp_version_script = + libgomp_version_dep = + endif ++ + libgomp_version_info = -version-info $(libtool_VERSION) ++if ENABLE_DARWIN_AT_RPATH ++libgomp_darwin_rpath = -Wc,-nodefaultrpaths ++libgomp_darwin_rpath += -Wl,-rpath,@loader_path ++endif + libgomp_la_LDFLAGS = $(libgomp_version_info) $(libgomp_version_script) \ +- $(lt_host_flags) ++ $(lt_host_flags) $(libgomp_darwin_rpath) + libgomp_la_DEPENDENCIES = $(libgomp_version_dep) + libgomp_la_LINK = $(LINK) $(libgomp_la_LDFLAGS) + +diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in +index 31ad7aa4b48..aba4c88e97a 100644 +--- a/libgomp/Makefile.in ++++ b/libgomp/Makefile.in +@@ -547,8 +547,11 @@ nodist_toolexeclib_HEADERS = libgomp.spec + @LIBGOMP_BUILD_VERSIONED_SHLIB_GNU_TRUE@@LIBGOMP_BUILD_VERSIONED_SHLIB_TRUE@libgomp_version_dep = libgomp.ver + @LIBGOMP_BUILD_VERSIONED_SHLIB_SUN_TRUE@@LIBGOMP_BUILD_VERSIONED_SHLIB_TRUE@libgomp_version_dep = libgomp.ver-sun + libgomp_version_info = -version-info $(libtool_VERSION) ++@ENABLE_DARWIN_AT_RPATH_TRUE@libgomp_darwin_rpath = \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path + libgomp_la_LDFLAGS = $(libgomp_version_info) $(libgomp_version_script) \ +- $(lt_host_flags) ++ $(lt_host_flags) $(libgomp_darwin_rpath) + + libgomp_la_DEPENDENCIES = $(libgomp_version_dep) + libgomp_la_LINK = $(LINK) $(libgomp_la_LDFLAGS) +diff --git a/libgomp/configure b/libgomp/configure +index 67f6b1435a5..5e8e36fee71 100755 +--- a/libgomp/configure ++++ b/libgomp/configure +@@ -693,6 +693,8 @@ FC + MAINT + MAINTAINER_MODE_FALSE + MAINTAINER_MODE_TRUE ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + enable_static + enable_shared + lt_host_flags +@@ -833,6 +835,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + enable_maintainer_mode + with_cuda_driver + with_cuda_driver_include +@@ -1494,6 +1497,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --enable-maintainer-mode + enable make rules and dependencies not useful (and + sometimes confusing) to the casual installer +@@ -7653,7 +7659,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -9626,6 +9632,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -9643,9 +9692,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -11432,7 +11485,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11435 "configure" ++#line 11488 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11538,7 +11591,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11541 "configure" ++#line 11594 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11799,6 +11852,14 @@ esac + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5 +@@ -13474,6 +13535,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc_FC=no + hardcode_direct_FC=no + hardcode_automatic_FC=yes +@@ -13491,9 +13595,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds_FC="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_FC="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds_FC="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds_FC="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds_FC="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds_FC="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -17306,6 +17414,10 @@ if test -z "${BUILD_INFO_TRUE}" && test -z "${BUILD_INFO_FALSE}"; then + as_fn_error $? "conditional \"BUILD_INFO\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then + as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/libgomp/configure.ac b/libgomp/configure.ac +index dd88f20103a..5deba114027 100644 +--- a/libgomp/configure.ac ++++ b/libgomp/configure.ac +@@ -149,6 +149,7 @@ AM_PROG_LIBTOOL + ACX_LT_HOST_FLAGS + AC_SUBST(enable_shared) + AC_SUBST(enable_static) ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) + + AM_MAINTAINER_MODE + +diff --git a/libgomp/env.c b/libgomp/env.c +index 1c4ee894515..29e7d853559 100644 +--- a/libgomp/env.c ++++ b/libgomp/env.c +@@ -60,6 +60,7 @@ + #endif /* LIBGOMP_OFFLOADED_ONLY */ + + #include "secure_getenv.h" ++#include "environ.h" + + struct gomp_task_icv gomp_global_icv = { + .nthreads_var = 1, +diff --git a/libiberty/configure b/libiberty/configure +index ca83f89da6d..ac7aa950032 100755 +--- a/libiberty/configure ++++ b/libiberty/configure +@@ -5208,6 +5208,9 @@ case "${host}" in + # sets the default TLS model and affects inlining. + PICFLAG=-fPIC + ;; ++ loongarch*-*-*) ++ PICFLAG=-fpic ++ ;; + mips-sgi-irix6*) + # PIC is the default. + ;; +@@ -5254,8 +5257,8 @@ case "${enable_shared}" in + *) shared=yes ;; + esac + +-# ...unless --enable-host-shared was passed from top-level config: +-if [ "${enable_host_shared}" = "yes" ]; then ++# ...unless --enable-host-{shared,pie} was passed from top-level config: ++if [ "${enable_host_shared}" = "yes" ] || [ "${enable_host_pie}" = "yes" ]; then + shared=yes + fi + +diff --git a/libiberty/configure.ac b/libiberty/configure.ac +index 84a7b378fad..bf3f9fe77ee 100644 +--- a/libiberty/configure.ac ++++ b/libiberty/configure.ac +@@ -232,8 +232,8 @@ case "${enable_shared}" in + *) shared=yes ;; + esac + +-# ...unless --enable-host-shared was passed from top-level config: +-if [[ "${enable_host_shared}" = "yes" ]]; then ++# ...unless --enable-host-{shared,pie} was passed from top-level config: ++if [[ "${enable_host_shared}" = "yes" ]] || [[ "${enable_host_pie}" = "yes" ]]; then + shared=yes + fi + +diff --git a/libitm/Makefile.am b/libitm/Makefile.am +index 3f31ad30556..a25317b07fe 100644 +--- a/libitm/Makefile.am ++++ b/libitm/Makefile.am +@@ -54,7 +54,12 @@ libitm_version_info = -version-info $(libtool_VERSION) + # want or need libstdc++. + libitm_la_DEPENDENCIES = $(libitm_version_dep) + libitm_la_LINK = $(LINK) $(libitm_la_LDFLAGS) +-libitm_la_LDFLAGS = $(libitm_version_info) $(libitm_version_script) ++if ENABLE_DARWIN_AT_RPATH ++libitm_darwin_rpath = -Wc,-nodefaultrpaths ++libitm_darwin_rpath += -Wl,-rpath,@loader_path ++endif ++libitm_la_LDFLAGS = $(libitm_version_info) $(libitm_version_script) \ ++ $(libitm_darwin_rpath) + + libitm_la_SOURCES = \ + aatree.cc alloc.cc alloc_c.cc alloc_cpp.cc barrier.cc beginend.cc \ +diff --git a/libitm/Makefile.in b/libitm/Makefile.in +index 7f53ea9b9db..ed28db45057 100644 +--- a/libitm/Makefile.in ++++ b/libitm/Makefile.in +@@ -481,7 +481,12 @@ libitm_version_info = -version-info $(libtool_VERSION) + # want or need libstdc++. + libitm_la_DEPENDENCIES = $(libitm_version_dep) + libitm_la_LINK = $(LINK) $(libitm_la_LDFLAGS) +-libitm_la_LDFLAGS = $(libitm_version_info) $(libitm_version_script) ++@ENABLE_DARWIN_AT_RPATH_TRUE@libitm_darwin_rpath = \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path ++libitm_la_LDFLAGS = $(libitm_version_info) $(libitm_version_script) \ ++ $(libitm_darwin_rpath) ++ + libitm_la_SOURCES = aatree.cc alloc.cc alloc_c.cc alloc_cpp.cc \ + barrier.cc beginend.cc clone.cc eh_cpp.cc local.cc query.cc \ + retry.cc rwlock.cc useraction.cc util.cc sjlj.S tls.cc \ +diff --git a/libitm/config/aarch64/sjlj.S b/libitm/config/aarch64/sjlj.S +index 296cb683a9f..941e886143e 100644 +--- a/libitm/config/aarch64/sjlj.S ++++ b/libitm/config/aarch64/sjlj.S +@@ -57,10 +57,19 @@ + + .text + .align 2 ++#if __ELF__ + .global _ITM_beginTransaction + .type _ITM_beginTransaction, %function + + _ITM_beginTransaction: ++ ++#elif __MACH__ ++ .global __ITM_beginTransaction ++ ++__ITM_beginTransaction: ++ ++#endif ++ + cfi_startproc + CFI_PAC_KEY + PAC_AND_BTI +@@ -84,8 +93,13 @@ _ITM_beginTransaction: + + /* Invoke GTM_begin_transaction with the struct we just built. */ + mov x1, sp ++#if __ELF__ + bl GTM_begin_transaction +- ++#elif __MACH__ ++ bl _GTM_begin_transaction ++#else ++#error "unexpected object format" ++#endif + /* Return; we don't need to restore any of the call-saved regs. */ + ldp x29, x30, [sp], 11*16 + cfi_adjust_cfa_offset(-11*16) +@@ -95,14 +109,23 @@ _ITM_beginTransaction: + CFI_PAC_TOGGLE + ret + cfi_endproc ++#if __ELF__ + .size _ITM_beginTransaction, . - _ITM_beginTransaction ++#endif + + .align 2 ++#if __ELF__ + .global GTM_longjmp + .hidden GTM_longjmp + .type GTM_longjmp, %function + + GTM_longjmp: ++ ++#elif __MACH__ ++ .private_extern _GTM_longjmp ++ ++_GTM_longjmp: ++#endif + /* The first parameter becomes the return value (x0). + The third parameter is ignored for now. */ + cfi_startproc +@@ -126,7 +149,9 @@ GTM_longjmp: + CFI_PAC_TOGGLE + br x30 + cfi_endproc ++#if __ELF__ + .size GTM_longjmp, . - GTM_longjmp ++#endif + + /* GNU_PROPERTY_AARCH64_* macros from elf.h for use in asm code. */ + #define FEATURE_1_AND 0xc0000000 +diff --git a/libitm/configure b/libitm/configure +index 18fc2d3a10a..863c588e90c 100755 +--- a/libitm/configure ++++ b/libitm/configure +@@ -660,6 +660,8 @@ libtool_VERSION + MAINT + MAINTAINER_MODE_FALSE + MAINTAINER_MODE_TRUE ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + enable_static + enable_shared + CXXCPP +@@ -810,6 +812,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + enable_maintainer_mode + enable_linux_futex + enable_tls +@@ -1462,6 +1465,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --enable-maintainer-mode + enable make rules and dependencies not useful (and + sometimes confusing) to the casual installer +@@ -8278,7 +8284,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -10252,6 +10258,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -10269,9 +10318,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -12058,7 +12111,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12061 "configure" ++#line 12114 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -12164,7 +12217,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12167 "configure" ++#line 12220 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -13040,6 +13093,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc_CXX=no + hardcode_direct_CXX=no + hardcode_automatic_CXX=yes +@@ -13057,12 +13153,20 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + if test "$lt_cv_apple_cc_single_mod" != "yes"; then +- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring${_lt_dsymutil}" + archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" + fi + +@@ -15414,6 +15518,14 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5 +@@ -18172,6 +18284,10 @@ if test -z "${BUILD_INFO_TRUE}" && test -z "${BUILD_INFO_FALSE}"; then + as_fn_error $? "conditional \"BUILD_INFO\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then + as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/libitm/configure.ac b/libitm/configure.ac +index 78a682376d9..209a025a90e 100644 +--- a/libitm/configure.ac ++++ b/libitm/configure.ac +@@ -157,6 +157,7 @@ AM_CONDITIONAL(BUILD_INFO, test $gcc_cv_prog_makeinfo_modern = "yes") + AM_PROG_LIBTOOL + AC_SUBST(enable_shared) + AC_SUBST(enable_static) ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) + + AM_MAINTAINER_MODE + +diff --git a/libitm/configure.tgt b/libitm/configure.tgt +index 06e90973ef3..acaf4f85712 100644 +--- a/libitm/configure.tgt ++++ b/libitm/configure.tgt +@@ -50,7 +50,7 @@ fi + # Map the target cpu to an ARCH sub-directory. At the same time, + # work out any special compilation flags as necessary. + case "${target_cpu}" in +- aarch64*) ARCH=aarch64 ;; ++ aarch64* | arm64*) ARCH=aarch64 ;; + alpha*) ARCH=alpha ;; + rs6000 | powerpc*) + XCFLAGS="${XCFLAGS} -mhtm" +diff --git a/libitm/testsuite/lib/libitm.exp b/libitm/testsuite/lib/libitm.exp +index 6d8e3e71310..906534022eb 100644 +--- a/libitm/testsuite/lib/libitm.exp ++++ b/libitm/testsuite/lib/libitm.exp +@@ -158,6 +158,7 @@ proc libitm_init { args } { + } + + if [istarget *-*-darwin*] { ++ lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/.libs" + lappend ALWAYS_CFLAGS "additional_flags=-shared-libgcc" + } + +diff --git a/libitm/testsuite/libitm.c++/c++.exp b/libitm/testsuite/libitm.c++/c++.exp +index f92aa096104..295c5bd4703 100644 +--- a/libitm/testsuite/libitm.c++/c++.exp ++++ b/libitm/testsuite/libitm.c++/c++.exp +@@ -56,8 +56,10 @@ if { $lang_test_file_found } { + # Gather a list of all tests. + set tests [lsort [glob -nocomplain $srcdir/$subdir/*.C]] + ++ set stdcxxadder "" + if { $blddir != "" } { + set ld_library_path "$always_ld_library_path:${blddir}/${lang_library_path}" ++ set stdcxxadder "-B ${blddir}/${lang_library_path}" + } else { + set ld_library_path "$always_ld_library_path" + } +@@ -72,7 +74,7 @@ if { $lang_test_file_found } { + } + + # Main loop. +- dg-runtest $tests "" $libstdcxx_includes ++ dg-runtest $tests $stdcxxadder $libstdcxx_includes + } + + # All done. +diff --git a/libobjc/configure b/libobjc/configure +index 5d1b424a66d..65054115fd0 100755 +--- a/libobjc/configure ++++ b/libobjc/configure +@@ -636,6 +636,9 @@ OBJC_BOEHM_GC_LIBS + OBJC_BOEHM_GC_INCLUDES + OBJC_BOEHM_GC + OBJC_GCFLAGS ++extra_ldflags_libobjc ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + SET_MAKE + CPP + OTOOL64 +@@ -667,7 +670,6 @@ RANLIB + AR + AS + XCFLAGS +-extra_ldflags_libobjc + lt_host_flags + OBJEXT + EXEEXT +@@ -755,6 +757,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + enable_tls + enable_objc_gc + with_target_bdw_gc +@@ -1392,6 +1395,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --enable-tls Use thread-local storage [default=yes] + --enable-objc-gc enable use of Boehm's garbage collector with the GNU + Objective-C runtime +@@ -3430,17 +3436,6 @@ esac + + + +-case "${host}" in +- *-darwin*) +- # Darwin needs -single_module when linking libobjc +- extra_ldflags_libobjc='$(lt_host_flags) -Wl,-single_module' +- ;; +- *-cygwin*|*-mingw*) +- # Tell libtool to build DLLs on Windows +- extra_ldflags_libobjc='$(lt_host_flags)' +- ;; +-esac +- + + # Add CET specific flags if CET is enabled + +@@ -3466,7 +3461,7 @@ case "$host" in + case "$enable_cet" in + auto) + # Check if target supports multi-byte NOPs +- # and if assembler supports CET insn. ++ # and if compiler and assembler support CET insn. + cet_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -fcf-protection" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +@@ -6967,7 +6962,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -8944,6 +8939,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -8961,9 +8999,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -10771,7 +10813,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 10784 "configure" ++#line 10816 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -10877,7 +10919,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 10890 "configure" ++#line 10922 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11149,6 +11191,38 @@ $as_echo "no" >&6; } + fi + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ ++ ++# Must come after libtool is initialized. ++case "${host}" in ++ *-darwin[4567]*) ++ # Earlier Darwin versions need -single_module when linking libobjc; they ++ # do not support @rpath. ++ extra_ldflags_libobjc='$(lt_host_flags) -Wl,-single_module' ++ ;; ++ *-darwin*) ++ # Otherwise, single_module is the default and multi-module is ignored and ++ # obsolete. ++ extra_ldflags_libobjc='$(lt_host_flags)' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ extra_ldflags_libobjc="${extra_ldflags_libobjc} -Wc,-nodefaultrpaths" ++ extra_ldflags_libobjc="${extra_ldflags_libobjc} -Wl,-rpath,@loader_path" ++ fi ++ ;; ++ *-cygwin*|*-mingw*) ++ # Tell libtool to build DLLs on Windows ++ extra_ldflags_libobjc='$(lt_host_flags)' ++ ;; ++esac ++ ++ + # ------- + # Headers + # ------- +@@ -11890,6 +11964,10 @@ if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then + as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + + : "${CONFIG_STATUS=./config.status}" + ac_write_fail=0 +diff --git a/libobjc/configure.ac b/libobjc/configure.ac +index f8f577cfbef..2a9bf1fed4c 100644 +--- a/libobjc/configure.ac ++++ b/libobjc/configure.ac +@@ -147,17 +147,6 @@ m4_rename_force([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS]) + + # extra LD Flags which are required for targets + ACX_LT_HOST_FLAGS +-case "${host}" in +- *-darwin*) +- # Darwin needs -single_module when linking libobjc +- extra_ldflags_libobjc='$(lt_host_flags) -Wl,-single_module' +- ;; +- *-cygwin*|*-mingw*) +- # Tell libtool to build DLLs on Windows +- extra_ldflags_libobjc='$(lt_host_flags)' +- ;; +-esac +-AC_SUBST(extra_ldflags_libobjc) + + # Add CET specific flags if CET is enabled + GCC_CET_FLAGS(CET_FLAGS) +@@ -182,6 +171,31 @@ AM_PROG_CC_C_O + + AC_PROG_MAKE_SET + ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) ++ ++# Must come after libtool is initialized. ++case "${host}" in ++ *-darwin[[4567]]*) ++ # Earlier Darwin versions need -single_module when linking libobjc; they ++ # do not support @rpath. ++ extra_ldflags_libobjc='$(lt_host_flags) -Wl,-single_module' ++ ;; ++ *-darwin*) ++ # Otherwise, single_module is the default and multi-module is ignored and ++ # obsolete. ++ extra_ldflags_libobjc='$(lt_host_flags)' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ extra_ldflags_libobjc="${extra_ldflags_libobjc} -Wc,-nodefaultrpaths" ++ extra_ldflags_libobjc="${extra_ldflags_libobjc} -Wl,-rpath,@loader_path" ++ fi ++ ;; ++ *-cygwin*|*-mingw*) ++ # Tell libtool to build DLLs on Windows ++ extra_ldflags_libobjc='$(lt_host_flags)' ++ ;; ++esac ++AC_SUBST(extra_ldflags_libobjc) ++ + # ------- + # Headers + # ------- +diff --git a/liboffloadmic/configure b/liboffloadmic/configure +index dfa8287fd75..995fd94e977 100755 +--- a/liboffloadmic/configure ++++ b/liboffloadmic/configure +@@ -782,6 +782,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + with_gcc_major_version_only + ' + ac_precious_vars='build_alias +@@ -1434,6 +1435,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + + Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] +@@ -7900,23 +7904,25 @@ _LT_EOF + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_force_load" >&5 + $as_echo "$lt_cv_ld_force_load" >&6; } +- case $host_os in +- rhapsody* | darwin1.[012]) ++ # Allow for Darwin 4-7 (macOS 10.0-10.3) although these are not expect to ++ # build without first building modern cctools / linker. ++ case $host_cpu-$host_os in ++ *-rhapsody* | *-darwin1.[012]) + _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;; +- darwin1.*) ++ *-darwin1.*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; +- darwin*) # darwin 5.x on +- # if running on 10.5 or later, the deployment target defaults +- # to the OS version, if on x86, and 10.4, the deployment +- # target defaults to 10.4. Don't you love it? +- case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in +- 10.0,*86*-darwin8*|10.0,*-darwin[91]*) +- _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; ++ *-darwin*) ++ # darwin 5.x (macOS 10.1) onwards we only need to adjust when the ++ # deployment target is forced to an earlier version. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) ++ ;; + 10.[012][,.]*) +- _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; +- 10.*) +- _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; +- esac ++ _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ++ ;; ++ *) ++ ;; ++ esac + ;; + esac + if test "$lt_cv_apple_cc_single_mod" = "yes"; then +@@ -9614,6 +9620,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -9631,9 +9680,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -11420,7 +11473,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11433 "configure" ++#line 11476 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11526,7 +11579,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11539 "configure" ++#line 11582 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -12402,6 +12455,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc_CXX=no + hardcode_direct_CXX=no + hardcode_automatic_CXX=yes +@@ -12419,12 +12515,20 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + if test "$lt_cv_apple_cc_single_mod" != "yes"; then +- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring${_lt_dsymutil}" + archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" + fi + +@@ -14265,16 +14369,6 @@ freebsd* | dragonfly*) + esac + ;; + +-gnu*) +- version_type=linux +- need_lib_prefix=no +- need_version=no +- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' +- soname_spec='${libname}${release}${shared_ext}$major' +- shlibpath_var=LD_LIBRARY_PATH +- hardcode_into_libs=yes +- ;; +- + haiku*) + version_type=linux + need_lib_prefix=no +@@ -14396,7 +14490,7 @@ linux*oldld* | linux*aout* | linux*coff*) + # project, but have not yet been accepted: they are GCC-local changes + # for the time being. (See + # https://lists.gnu.org/archive/html/libtool-patches/2018-05/msg00000.html) +-linux* | k*bsd*-gnu | kopensolaris*-gnu | uclinuxfdpiceabi) ++linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu* | uclinuxfdpiceabi) + version_type=linux + need_lib_prefix=no + need_version=no +diff --git a/liboffloadmic/plugin/Makefile.in b/liboffloadmic/plugin/Makefile.in +index 8d5ad0025c2..c53f2d32b3b 100644 +--- a/liboffloadmic/plugin/Makefile.in ++++ b/liboffloadmic/plugin/Makefile.in +@@ -123,10 +123,10 @@ subdir = . + ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 + am__aclocal_m4_deps = $(top_srcdir)/../../config/acx.m4 \ + $(top_srcdir)/../../config/depstand.m4 \ +- $(top_srcdir)/../../config/toolexeclibdir.m4 \ + $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/multi.m4 \ + $(top_srcdir)/../../config/override.m4 \ ++ $(top_srcdir)/../../config/toolexeclibdir.m4 \ + $(top_srcdir)/../../libtool.m4 \ + $(top_srcdir)/../../ltoptions.m4 \ + $(top_srcdir)/../../ltsugar.m4 \ +diff --git a/liboffloadmic/plugin/aclocal.m4 b/liboffloadmic/plugin/aclocal.m4 +index 9fa1d1216c1..1bb91402f66 100644 +--- a/liboffloadmic/plugin/aclocal.m4 ++++ b/liboffloadmic/plugin/aclocal.m4 +@@ -1169,10 +1169,10 @@ AC_SUBST([am__untar]) + + m4_include([../../config/acx.m4]) + m4_include([../../config/depstand.m4]) +-m4_include([../../config/toolexeclibdir.m4]) + m4_include([../../config/lead-dot.m4]) + m4_include([../../config/multi.m4]) + m4_include([../../config/override.m4]) ++m4_include([../../config/toolexeclibdir.m4]) + m4_include([../../libtool.m4]) + m4_include([../../ltoptions.m4]) + m4_include([../../ltsugar.m4]) +diff --git a/liboffloadmic/plugin/configure b/liboffloadmic/plugin/configure +index 0b21d7d4eed..929b7278e8a 100755 +--- a/liboffloadmic/plugin/configure ++++ b/liboffloadmic/plugin/configure +@@ -778,6 +778,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + with_gcc_major_version_only + ' + ac_precious_vars='build_alias +@@ -1431,6 +1432,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + + Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] +@@ -7280,23 +7284,25 @@ _LT_EOF + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_force_load" >&5 + $as_echo "$lt_cv_ld_force_load" >&6; } +- case $host_os in +- rhapsody* | darwin1.[012]) ++ # Allow for Darwin 4-7 (macOS 10.0-10.3) although these are not expect to ++ # build without first building modern cctools / linker. ++ case $host_cpu-$host_os in ++ *-rhapsody* | *-darwin1.[012]) + _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;; +- darwin1.*) ++ *-darwin1.*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; +- darwin*) # darwin 5.x on +- # if running on 10.5 or later, the deployment target defaults +- # to the OS version, if on x86, and 10.4, the deployment +- # target defaults to 10.4. Don't you love it? +- case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in +- 10.0,*86*-darwin8*|10.0,*-darwin[91]*) +- _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; ++ *-darwin*) ++ # darwin 5.x (macOS 10.1) onwards we only need to adjust when the ++ # deployment target is forced to an earlier version. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) ++ ;; + 10.[012][,.]*) +- _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; +- 10.*) +- _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; +- esac ++ _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ++ ;; ++ *) ++ ;; ++ esac + ;; + esac + if test "$lt_cv_apple_cc_single_mod" = "yes"; then +@@ -9261,6 +9267,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -9278,9 +9327,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -11067,7 +11120,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11080 "configure" ++#line 11123 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11173,7 +11226,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11186 "configure" ++#line 11229 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -12049,6 +12102,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc_CXX=no + hardcode_direct_CXX=no + hardcode_automatic_CXX=yes +@@ -12066,12 +12162,20 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + if test "$lt_cv_apple_cc_single_mod" != "yes"; then +- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring${_lt_dsymutil}" + archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" + fi + +@@ -13912,16 +14016,6 @@ freebsd* | dragonfly*) + esac + ;; + +-gnu*) +- version_type=linux +- need_lib_prefix=no +- need_version=no +- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' +- soname_spec='${libname}${release}${shared_ext}$major' +- shlibpath_var=LD_LIBRARY_PATH +- hardcode_into_libs=yes +- ;; +- + haiku*) + version_type=linux + need_lib_prefix=no +@@ -14043,7 +14137,7 @@ linux*oldld* | linux*aout* | linux*coff*) + # project, but have not yet been accepted: they are GCC-local changes + # for the time being. (See + # https://lists.gnu.org/archive/html/libtool-patches/2018-05/msg00000.html) +-linux* | k*bsd*-gnu | kopensolaris*-gnu | uclinuxfdpiceabi) ++linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu* | uclinuxfdpiceabi) + version_type=linux + need_lib_prefix=no + need_version=no +diff --git a/libphobos/configure b/libphobos/configure +index 9da06f087d0..77fd1728549 100755 +--- a/libphobos/configure ++++ b/libphobos/configure +@@ -707,6 +707,8 @@ get_gcc_base_ver + phobos_compiler_shared_flag + phobos_compiler_pic_flag + phobos_lt_pic_flag ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + enable_static + enable_shared + OTOOL64 +@@ -838,6 +840,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + with_gcc_major_version_only + enable_werror + with_libatomic +@@ -1490,6 +1493,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --enable-werror turns on -Werror [default=no] + --enable-version-specific-runtime-libs + Specify that runtime libraries should be installed +@@ -8239,7 +8245,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -9944,6 +9950,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -9961,9 +10010,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -11750,7 +11803,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11753 "configure" ++#line 11806 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11856,7 +11909,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11859 "configure" ++#line 11912 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -13381,6 +13434,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc_D=no + hardcode_direct_D=no + hardcode_automatic_D=yes +@@ -13398,9 +13494,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds_D="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_D="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds_D="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds_D="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds_D="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds_D="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -14002,6 +14102,14 @@ CFLAGS=$lt_save_CFLAGS + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ + + # libtool variables for Phobos shared and position-independent compiles. + # +@@ -15726,6 +15834,10 @@ if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then + as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${DRUNTIME_CPU_AARCH64_TRUE}" && test -z "${DRUNTIME_CPU_AARCH64_FALSE}"; then + as_fn_error $? "conditional \"DRUNTIME_CPU_AARCH64\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/libphobos/configure.ac b/libphobos/configure.ac +index 31209ba2920..cc372587939 100644 +--- a/libphobos/configure.ac ++++ b/libphobos/configure.ac +@@ -93,6 +93,7 @@ AM_PROG_LIBTOOL + WITH_LOCAL_DRUNTIME([LT_LANG([D])], []) + AC_SUBST(enable_shared) + AC_SUBST(enable_static) ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) + + # libtool variables for Phobos shared and position-independent compiles. + # +diff --git a/libphobos/libdruntime/Makefile.am b/libphobos/libdruntime/Makefile.am +index 6ca4012b713..861ec0ebc03 100644 +--- a/libphobos/libdruntime/Makefile.am ++++ b/libphobos/libdruntime/Makefile.am +@@ -128,8 +128,11 @@ ALL_DRUNTIME_SOURCES = $(DRUNTIME_DSOURCES) $(DRUNTIME_CSOURCES) \ + toolexeclib_LTLIBRARIES = libgdruntime.la + libgdruntime_la_SOURCES = $(ALL_DRUNTIME_SOURCES) + libgdruntime_la_LIBTOOLFLAGS = ++if ENABLE_DARWIN_AT_RPATH ++libgdruntime_darwin_rpath = -Wl,-rpath,@loader_path ++endif + libgdruntime_la_LDFLAGS = -Wc,-nophoboslib,-dstartfiles,-B../src,-Bgcc \ +- -version-info $(libtool_VERSION) ++ -version-info $(libtool_VERSION) $(libgdruntime_darwin_rpath) + libgdruntime_la_LIBADD = $(LIBATOMIC) $(LIBBACKTRACE) + libgdruntime_la_DEPENDENCIES = $(DRTSTUFF) + # Also override library link commands: This is not strictly +diff --git a/libphobos/libdruntime/Makefile.in b/libphobos/libdruntime/Makefile.in +index f7f78d71ff7..9f3361c7702 100644 +--- a/libphobos/libdruntime/Makefile.in ++++ b/libphobos/libdruntime/Makefile.in +@@ -805,8 +805,9 @@ ALL_DRUNTIME_SOURCES = $(DRUNTIME_DSOURCES) $(DRUNTIME_CSOURCES) \ + toolexeclib_LTLIBRARIES = libgdruntime.la + libgdruntime_la_SOURCES = $(ALL_DRUNTIME_SOURCES) + libgdruntime_la_LIBTOOLFLAGS = ++@ENABLE_DARWIN_AT_RPATH_TRUE@libgdruntime_darwin_rpath = -Wl,-rpath,@loader_path + libgdruntime_la_LDFLAGS = -Wc,-nophoboslib,-dstartfiles,-B../src,-Bgcc \ +- -version-info $(libtool_VERSION) ++ -version-info $(libtool_VERSION) $(libgdruntime_darwin_rpath) + + libgdruntime_la_LIBADD = $(LIBATOMIC) $(LIBBACKTRACE) + libgdruntime_la_DEPENDENCIES = $(DRTSTUFF) +diff --git a/libphobos/libdruntime/config/aarch64/switchcontext.S b/libphobos/libdruntime/config/aarch64/switchcontext.S +index cf96e28fb50..3df60947fba 100644 +--- a/libphobos/libdruntime/config/aarch64/switchcontext.S ++++ b/libphobos/libdruntime/config/aarch64/switchcontext.S +@@ -44,7 +44,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + */ + .text + .global CSYM(fiber_switchContext) ++#ifndef __APPLE__ + .type CSYM(fiber_switchContext), %function ++#endif + .align 4 + CSYM(fiber_switchContext): + .cfi_startproc +@@ -77,8 +79,9 @@ CSYM(fiber_switchContext): + ldp d15, d14, [sp], #20*8 + ret + .cfi_endproc ++#ifndef __APPLE__ + .size CSYM(fiber_switchContext),.-CSYM(fiber_switchContext) +- ++#endif + /** + * When generating any kind of backtrace (gdb, exception handling) for + * a function called in a Fiber, we need to tell the unwinder to stop +@@ -93,11 +96,15 @@ CSYM(fiber_switchContext): + .text + .global CSYM(fiber_trampoline) + .p2align 2 ++#ifndef __APPLE__ + .type CSYM(fiber_trampoline), %function ++#endif + CSYM(fiber_trampoline): + .cfi_startproc + .cfi_undefined x30 + // fiber_entryPoint never returns + bl CSYM(fiber_entryPoint) + .cfi_endproc ++#ifndef __APPLE__ + .size CSYM(fiber_trampoline),.-CSYM(fiber_trampoline) ++#endif +diff --git a/libphobos/libdruntime/config/arm/switchcontext.S b/libphobos/libdruntime/config/arm/switchcontext.S +index 562e0c76f42..72b281febb8 100644 +--- a/libphobos/libdruntime/config/arm/switchcontext.S ++++ b/libphobos/libdruntime/config/arm/switchcontext.S +@@ -60,11 +60,15 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + */ + + .text ++#ifndef __APPLE__ + #if defined(__ARM_PCS_VFP) || (defined(__ARM_PCS) && !defined(__SOFTFP__)) + .fpu vfp + #endif + .global CSYM(fiber_switchContext) + .type CSYM(fiber_switchContext), %function ++#else ++ .global CSYM(fiber_switchContext) ++#endif + .align 4 + CSYM(fiber_switchContext): + .cfi_sections .debug_frame +@@ -111,8 +115,12 @@ CSYM(fiber_switchContext): + mov lr, #0 + // return by writing lr into pc + mov pc, r1 ++#ifndef __APPLE__ + .fnend + .cfi_endproc + .size CSYM(fiber_switchContext),.-CSYM(fiber_switchContext) ++#else ++ .cfi_endproc ++#endif + + #endif +diff --git a/libphobos/libdruntime/core/thread/fiber.d b/libphobos/libdruntime/core/thread/fiber.d +index bd53eed2d10..5a3d4cce216 100644 +--- a/libphobos/libdruntime/core/thread/fiber.d ++++ b/libphobos/libdruntime/core/thread/fiber.d +@@ -1788,6 +1788,7 @@ version (OSX) + { + version (X86) version = UnsafeFiberMigration; + version (X86_64) version = UnsafeFiberMigration; ++ version (AArch64) version = UnsafeFiberMigration; + } + + version (UnsafeFiberMigration) +diff --git a/libphobos/src/Makefile.am b/libphobos/src/Makefile.am +index da7a2004ff8..a47d985c5b7 100644 +--- a/libphobos/src/Makefile.am ++++ b/libphobos/src/Makefile.am +@@ -44,8 +44,11 @@ toolexeclib_DATA = libgphobos.spec + toolexeclib_LTLIBRARIES = libgphobos.la + libgphobos_la_SOURCES = $(ALL_PHOBOS_SOURCES) + libgphobos_la_LIBTOOLFLAGS = ++if ENABLE_DARWIN_AT_RPATH ++libgphobos_darwin_rpath = -Wl,-rpath,@loader_path ++endif + libgphobos_la_LDFLAGS = -Wc,-nophoboslib,-dstartfiles,-B../libdruntime/gcc \ +- -version-info $(libtool_VERSION) ++ -version-info $(libtool_VERSION) $(libgphobos_darwin_rpath) + if ENABLE_LIBDRUNTIME_ONLY + libgphobos_la_LIBADD = ../libdruntime/libgdruntime_convenience.la + else +diff --git a/libphobos/src/Makefile.in b/libphobos/src/Makefile.in +index 6f58fee01ac..212ea2469f2 100644 +--- a/libphobos/src/Makefile.in ++++ b/libphobos/src/Makefile.in +@@ -528,8 +528,9 @@ toolexeclib_DATA = libgphobos.spec + toolexeclib_LTLIBRARIES = libgphobos.la + libgphobos_la_SOURCES = $(ALL_PHOBOS_SOURCES) + libgphobos_la_LIBTOOLFLAGS = ++@ENABLE_DARWIN_AT_RPATH_TRUE@libgphobos_darwin_rpath = -Wl,-rpath,@loader_path + libgphobos_la_LDFLAGS = -Wc,-nophoboslib,-dstartfiles,-B../libdruntime/gcc \ +- -version-info $(libtool_VERSION) ++ -version-info $(libtool_VERSION) $(libgphobos_darwin_rpath) + + @ENABLE_LIBDRUNTIME_ONLY_FALSE@libgphobos_la_LIBADD = \ + @ENABLE_LIBDRUNTIME_ONLY_FALSE@ ../libdruntime/libgdruntime_convenience.la $(LIBZ) +diff --git a/libquadmath/Makefile.am b/libquadmath/Makefile.am +index 35dffb46f6e..f199adf4602 100644 +--- a/libquadmath/Makefile.am ++++ b/libquadmath/Makefile.am +@@ -36,8 +36,13 @@ endif + + toolexeclib_LTLIBRARIES = libquadmath.la + libquadmath_la_LIBADD = ++ ++if ENABLE_DARWIN_AT_RPATH ++libquadmath_darwin_rpath = -Wc,-nodefaultrpaths ++libquadmath_darwin_rpath += -Wl,-rpath,@loader_path ++endif + libquadmath_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ +- $(version_arg) $(lt_host_flags) -lm ++ $(version_arg) $(lt_host_flags) $(LIBM) $(libquadmath_darwin_rpath) + libquadmath_la_DEPENDENCIES = $(version_dep) $(libquadmath_la_LIBADD) + + nodist_libsubinclude_HEADERS = quadmath.h quadmath_weak.h +diff --git a/libquadmath/Makefile.in b/libquadmath/Makefile.in +index 8c011212258..70025758cd5 100644 +--- a/libquadmath/Makefile.in ++++ b/libquadmath/Makefile.in +@@ -355,6 +355,7 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ + INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ + LD = @LD@ + LDFLAGS = @LDFLAGS@ ++LIBM = @LIBM@ + LIBOBJS = @LIBOBJS@ + LIBS = @LIBS@ + LIBTOOL = @LIBTOOL@ +@@ -463,8 +464,10 @@ AUTOMAKE_OPTIONS = foreign info-in-builddir + @BUILD_LIBQUADMATH_TRUE@@LIBQUAD_USE_SYMVER_SUN_TRUE@@LIBQUAD_USE_SYMVER_TRUE@version_dep = quadmath.map-sun + @BUILD_LIBQUADMATH_TRUE@toolexeclib_LTLIBRARIES = libquadmath.la + @BUILD_LIBQUADMATH_TRUE@libquadmath_la_LIBADD = ++@BUILD_LIBQUADMATH_TRUE@@ENABLE_DARWIN_AT_RPATH_TRUE@libquadmath_darwin_rpath = -Wc,-nodefaultrpaths \ ++@BUILD_LIBQUADMATH_TRUE@@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path + @BUILD_LIBQUADMATH_TRUE@libquadmath_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ +-@BUILD_LIBQUADMATH_TRUE@ $(version_arg) $(lt_host_flags) -lm ++@BUILD_LIBQUADMATH_TRUE@ $(version_arg) $(lt_host_flags) $(LIBM) $(libquadmath_darwin_rpath) + + @BUILD_LIBQUADMATH_TRUE@libquadmath_la_DEPENDENCIES = $(version_dep) $(libquadmath_la_LIBADD) + @BUILD_LIBQUADMATH_TRUE@nodist_libsubinclude_HEADERS = quadmath.h quadmath_weak.h +diff --git a/libquadmath/configure b/libquadmath/configure +index b3ee64f9c7d..735d1e05e68 100755 +--- a/libquadmath/configure ++++ b/libquadmath/configure +@@ -644,11 +644,14 @@ LIBQUAD_USE_SYMVER_GNU_FALSE + LIBQUAD_USE_SYMVER_GNU_TRUE + LIBQUAD_USE_SYMVER_FALSE + LIBQUAD_USE_SYMVER_TRUE ++LIBM + toolexeclibdir + toolexecdir + MAINT + MAINTAINER_MODE_FALSE + MAINTAINER_MODE_TRUE ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + enable_static + enable_shared + lt_host_flags +@@ -785,6 +788,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + enable_maintainer_mode + with_toolexeclibdir + enable_symvers +@@ -1435,6 +1439,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --enable-maintainer-mode + enable make rules and dependencies not useful (and + sometimes confusing) to the casual installer +@@ -7267,7 +7274,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -8979,6 +8986,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -8996,9 +9046,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -10806,7 +10860,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 10819 "configure" ++#line 10863 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -10912,7 +10966,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 10925 "configure" ++#line 10969 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11173,6 +11227,14 @@ esac + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5 +@@ -12137,6 +12199,20 @@ esac + + + ++# AC_CHECK_LIBM variant which avoids AC_CHECK_LIB (that doesn't work ++# on bare metal). In the past we've used -lm in Makefile.am unconditionally, ++# let's use it there unless target knows it doesn't need that. ++LIBM= ++case $host in ++*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-haiku* | *-*-pw32* | *-*-darwin*) ++ # These system don't have libm, or don't need it ++ ;; ++*) ++ LIBM=-lm ++ ;; ++esac ++ ++ + for ac_header in fenv.h langinfo.h locale.h wchar.h wctype.h limits.h ctype.h printf.h errno.h + do : + as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` +@@ -13031,7 +13107,7 @@ case "$host" in + case "$enable_cet" in + auto) + # Check if target supports multi-byte NOPs +- # and if assembler supports CET insn. ++ # and if compiler and assembler support CET insn. + cet_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -fcf-protection" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +@@ -13397,6 +13473,10 @@ if test -z "${BUILD_INFO_TRUE}" && test -z "${BUILD_INFO_FALSE}"; then + as_fn_error $? "conditional \"BUILD_INFO\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then + as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/libquadmath/configure.ac b/libquadmath/configure.ac +index eec4084a45f..349be2607c6 100644 +--- a/libquadmath/configure.ac ++++ b/libquadmath/configure.ac +@@ -59,6 +59,7 @@ AM_PROG_LIBTOOL + ACX_LT_HOST_FLAGS + AC_SUBST(enable_shared) + AC_SUBST(enable_static) ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) + + AM_MAINTAINER_MODE + +@@ -121,6 +122,20 @@ esac + AC_SUBST(toolexecdir) + AC_SUBST(toolexeclibdir) + ++# AC_CHECK_LIBM variant which avoids AC_CHECK_LIB (that doesn't work ++# on bare metal). In the past we've used -lm in Makefile.am unconditionally, ++# let's use it there unless target knows it doesn't need that. ++LIBM= ++case $host in ++*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-haiku* | *-*-pw32* | *-*-darwin*) ++ # These system don't have libm, or don't need it ++ ;; ++*) ++ LIBM=-lm ++ ;; ++esac ++AC_SUBST([LIBM]) ++ + AC_CHECK_HEADERS(fenv.h langinfo.h locale.h wchar.h wctype.h limits.h ctype.h printf.h errno.h) + LIBQUAD_CHECK_MATH_H_SIGNGAM + +diff --git a/libsanitizer/Makefile.in b/libsanitizer/Makefile.in +index aab88deb6e8..65e7f2e9553 100644 +--- a/libsanitizer/Makefile.in ++++ b/libsanitizer/Makefile.in +@@ -345,7 +345,6 @@ pdfdir = @pdfdir@ + prefix = @prefix@ + program_transform_name = @program_transform_name@ + psdir = @psdir@ +-runstatedir = @runstatedir@ + sbindir = @sbindir@ + sharedstatedir = @sharedstatedir@ + srcdir = @srcdir@ +diff --git a/libsanitizer/asan/Makefile.am b/libsanitizer/asan/Makefile.am +index 4f802f723d6..223d3e07816 100644 +--- a/libsanitizer/asan/Makefile.am ++++ b/libsanitizer/asan/Makefile.am +@@ -60,7 +60,12 @@ libasan_la_LIBADD += $(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la + endif + libasan_la_LIBADD += $(LIBSTDCXX_RAW_CXX_LDFLAGS) + +-libasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libasan) ++if ENABLE_DARWIN_AT_RPATH ++libasan_darwin_rpath = -Wc,-nodefaultrpaths ++libasan_darwin_rpath += -Wl,-rpath,@loader_path ++endif ++libasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ ++ $(link_libasan) $(libasan_darwin_rpath) + + libasan_preinit.o: asan_preinit.o + cp $< $@ +diff --git a/libsanitizer/asan/Makefile.in b/libsanitizer/asan/Makefile.in +index 2476fbc5a26..e88e5e0b0a7 100644 +--- a/libsanitizer/asan/Makefile.in ++++ b/libsanitizer/asan/Makefile.in +@@ -399,7 +399,6 @@ pdfdir = @pdfdir@ + prefix = @prefix@ + program_transform_name = @program_transform_name@ + psdir = @psdir@ +-runstatedir = @runstatedir@ + sbindir = @sbindir@ + sharedstatedir = @sharedstatedir@ + srcdir = @srcdir@ +@@ -466,7 +465,12 @@ libasan_la_LIBADD = \ + $(top_builddir)/sanitizer_common/libsanitizer_common.la \ + $(top_builddir)/lsan/libsanitizer_lsan.la $(am__append_2) \ + $(am__append_3) $(LIBSTDCXX_RAW_CXX_LDFLAGS) +-libasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libasan) ++@ENABLE_DARWIN_AT_RPATH_TRUE@libasan_darwin_rpath = \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path ++libasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ ++ $(link_libasan) $(libasan_darwin_rpath) ++ + + # Work around what appears to be a GNU make bug handling MAKEFLAGS + # values defined in terms of make variables, as is the case for CC and +diff --git a/libsanitizer/configure b/libsanitizer/configure +index ae8c1bd7e83..96530d540de 100755 +--- a/libsanitizer/configure ++++ b/libsanitizer/configure +@@ -666,6 +666,8 @@ LSAN_SUPPORTED_FALSE + LSAN_SUPPORTED_TRUE + TSAN_SUPPORTED_FALSE + TSAN_SUPPORTED_TRUE ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + enable_static + enable_shared + CXXCPP +@@ -817,6 +819,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + enable_werror + with_gcc_major_version_only + enable_cet +@@ -1471,6 +1474,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --disable-werror disable building with -Werror + --enable-cet enable Intel CET in target libraries [default=auto] + +@@ -8848,7 +8854,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -10553,6 +10559,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -10570,9 +10619,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -12359,7 +12412,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12362 "configure" ++#line 12415 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -12465,7 +12518,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12468 "configure" ++#line 12521 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -13341,6 +13394,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc_CXX=no + hardcode_direct_CXX=no + hardcode_automatic_CXX=yes +@@ -13358,12 +13454,20 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + if test "$lt_cv_apple_cc_single_mod" != "yes"; then +- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring${_lt_dsymutil}" + archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" + fi + +@@ -15763,6 +15867,15 @@ esac + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ ++ + # The cast to long int works around a bug in the HP C Compiler + # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects + # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. +@@ -17153,6 +17266,10 @@ if test -z "${am__fastdepCCAS_TRUE}" && test -z "${am__fastdepCCAS_FALSE}"; then + as_fn_error $? "conditional \"am__fastdepCCAS\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${TSAN_SUPPORTED_TRUE}" && test -z "${TSAN_SUPPORTED_FALSE}"; then + as_fn_error $? "conditional \"TSAN_SUPPORTED\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/libsanitizer/configure.ac b/libsanitizer/configure.ac +index ad49f29db7e..7115c782c82 100644 +--- a/libsanitizer/configure.ac ++++ b/libsanitizer/configure.ac +@@ -85,6 +85,8 @@ esac + AC_SUBST(enable_shared) + AC_SUBST(enable_static) + ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) ++ + AC_CHECK_SIZEOF([void *]) + + if test "${multilib}" = "yes"; then +diff --git a/libsanitizer/hwasan/Makefile.am b/libsanitizer/hwasan/Makefile.am +index e12c0a0ce71..4061078c734 100644 +--- a/libsanitizer/hwasan/Makefile.am ++++ b/libsanitizer/hwasan/Makefile.am +@@ -46,7 +46,11 @@ libhwasan_la_LIBADD += $(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la + endif + libhwasan_la_LIBADD += $(LIBSTDCXX_RAW_CXX_LDFLAGS) + +-libhwasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libhwasan) ++if ENABLE_DARWIN_AT_RPATH ++libhwasan_darwin_rpath = -nodefaultrpaths -Wl,-rpath,@loader_path/ ++endif ++libhwasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ ++ $(link_libhwasan) $(libhwasan_darwin_rpath) + + # Work around what appears to be a GNU make bug handling MAKEFLAGS + # values defined in terms of make variables, as is the case for CC and +diff --git a/libsanitizer/hwasan/Makefile.in b/libsanitizer/hwasan/Makefile.in +index 67553f3979d..d20f2dc6eef 100644 +--- a/libsanitizer/hwasan/Makefile.in ++++ b/libsanitizer/hwasan/Makefile.in +@@ -387,7 +387,6 @@ pdfdir = @pdfdir@ + prefix = @prefix@ + program_transform_name = @program_transform_name@ + psdir = @psdir@ +-runstatedir = @runstatedir@ + sbindir = @sbindir@ + sharedstatedir = @sharedstatedir@ + srcdir = @srcdir@ +@@ -442,7 +441,10 @@ libhwasan_la_SOURCES = $(hwasan_files) + libhwasan_la_LIBADD = \ + $(top_builddir)/sanitizer_common/libsanitizer_common.la \ + $(am__append_1) $(am__append_2) $(LIBSTDCXX_RAW_CXX_LDFLAGS) +-libhwasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libhwasan) ++@ENABLE_DARWIN_AT_RPATH_TRUE@libhwasan_darwin_rpath = -nodefaultrpaths -Wl,-rpath,@loader_path/ ++libhwasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ ++ $(link_libhwasan) $(libhwasan_darwin_rpath) ++ + + # Work around what appears to be a GNU make bug handling MAKEFLAGS + # values defined in terms of make variables, as is the case for CC and +diff --git a/libsanitizer/interception/Makefile.in b/libsanitizer/interception/Makefile.in +index bce788aeea7..85dd386de47 100644 +--- a/libsanitizer/interception/Makefile.in ++++ b/libsanitizer/interception/Makefile.in +@@ -317,7 +317,6 @@ pdfdir = @pdfdir@ + prefix = @prefix@ + program_transform_name = @program_transform_name@ + psdir = @psdir@ +-runstatedir = @runstatedir@ + sbindir = @sbindir@ + sharedstatedir = @sharedstatedir@ + srcdir = @srcdir@ +diff --git a/libsanitizer/libbacktrace/Makefile.in b/libsanitizer/libbacktrace/Makefile.in +index ece4f11a855..c0243fa4aab 100644 +--- a/libsanitizer/libbacktrace/Makefile.in ++++ b/libsanitizer/libbacktrace/Makefile.in +@@ -367,7 +367,6 @@ pdfdir = @pdfdir@ + prefix = @prefix@ + program_transform_name = @program_transform_name@ + psdir = @psdir@ +-runstatedir = @runstatedir@ + sbindir = @sbindir@ + sharedstatedir = @sharedstatedir@ + srcdir = @srcdir@ +diff --git a/libsanitizer/lsan/Makefile.am b/libsanitizer/lsan/Makefile.am +index 6ff28ff5eea..7701b0e18cf 100644 +--- a/libsanitizer/lsan/Makefile.am ++++ b/libsanitizer/lsan/Makefile.am +@@ -41,8 +41,12 @@ if LIBBACKTRACE_SUPPORTED + liblsan_la_LIBADD += $(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la + endif + liblsan_la_LIBADD += $(LIBSTDCXX_RAW_CXX_LDFLAGS) +-liblsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_liblsan) +- ++if ENABLE_DARWIN_AT_RPATH ++liblsan_darwin_rpath = -Wc,-nodefaultrpaths ++liblsan_darwin_rpath += -Wl,-rpath,@loader_path ++endif ++liblsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ ++ $(link_liblsan) $(liblsan_darwin_rpath) + liblsan_preinit.o: lsan_preinit.o + cp $< $@ + +diff --git a/libsanitizer/lsan/Makefile.in b/libsanitizer/lsan/Makefile.in +index 857f244cd86..078edf01fda 100644 +--- a/libsanitizer/lsan/Makefile.in ++++ b/libsanitizer/lsan/Makefile.in +@@ -362,7 +362,6 @@ pdfdir = @pdfdir@ + prefix = @prefix@ + program_transform_name = @program_transform_name@ + psdir = @psdir@ +-runstatedir = @runstatedir@ + sbindir = @sbindir@ + sharedstatedir = @sharedstatedir@ + srcdir = @srcdir@ +@@ -414,7 +413,12 @@ liblsan_la_LIBADD = \ + $(top_builddir)/sanitizer_common/libsanitizer_common.la \ + $(top_builddir)/interception/libinterception.la \ + $(am__append_1) $(LIBSTDCXX_RAW_CXX_LDFLAGS) +-liblsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_liblsan) ++@ENABLE_DARWIN_AT_RPATH_TRUE@liblsan_darwin_rpath = \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path ++liblsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ ++ $(link_liblsan) $(liblsan_darwin_rpath) ++ + + # Work around what appears to be a GNU make bug handling MAKEFLAGS + # values defined in terms of make variables, as is the case for CC and +@@ -789,7 +793,6 @@ uninstall-am: uninstall-nodist_toolexeclibHEADERS \ + + .PRECIOUS: Makefile + +- + liblsan_preinit.o: lsan_preinit.o + cp $< $@ + +diff --git a/libsanitizer/sanitizer_common/Makefile.in b/libsanitizer/sanitizer_common/Makefile.in +index c4b009fed83..e5e1c1d51fe 100644 +--- a/libsanitizer/sanitizer_common/Makefile.in ++++ b/libsanitizer/sanitizer_common/Makefile.in +@@ -354,7 +354,6 @@ pdfdir = @pdfdir@ + prefix = @prefix@ + program_transform_name = @program_transform_name@ + psdir = @psdir@ +-runstatedir = @runstatedir@ + sbindir = @sbindir@ + sharedstatedir = @sharedstatedir@ + srcdir = @srcdir@ +diff --git a/libsanitizer/tsan/Makefile.am b/libsanitizer/tsan/Makefile.am +index ae588a67df6..47ee50bee1a 100644 +--- a/libsanitizer/tsan/Makefile.am ++++ b/libsanitizer/tsan/Makefile.am +@@ -58,7 +58,11 @@ libtsan_la_LIBADD += $(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la + libtsan_la_DEPENDENCIES +=$(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la + endif + libtsan_la_LIBADD += $(LIBSTDCXX_RAW_CXX_LDFLAGS) +-libtsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libtsan) ++if ENABLE_DARWIN_AT_RPATH ++libtsan_darwin_rpath = -nodefaultrpaths -Wl,-rpath,@loader_path/ ++endif ++libtsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ ++ $(link_libtsan) $(libtsan_darwin_rpath) + + libtsan_preinit.o: tsan_preinit.o + cp $< $@ +diff --git a/libsanitizer/tsan/Makefile.in b/libsanitizer/tsan/Makefile.in +index 538d2e8eb68..d6efff71e2f 100644 +--- a/libsanitizer/tsan/Makefile.in ++++ b/libsanitizer/tsan/Makefile.in +@@ -391,7 +391,6 @@ pdfdir = @pdfdir@ + prefix = @prefix@ + program_transform_name = @program_transform_name@ + psdir = @psdir@ +-runstatedir = @runstatedir@ + sbindir = @sbindir@ + sharedstatedir = @sharedstatedir@ + srcdir = @srcdir@ +@@ -466,7 +465,10 @@ libtsan_la_DEPENDENCIES = \ + $(top_builddir)/sanitizer_common/libsanitizer_common.la \ + $(top_builddir)/interception/libinterception.la \ + $(TSAN_TARGET_DEPENDENT_OBJECTS) $(am__append_2) +-libtsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libtsan) ++@ENABLE_DARWIN_AT_RPATH_TRUE@libtsan_darwin_rpath = -nodefaultrpaths -Wl,-rpath,@loader_path/ ++libtsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ ++ $(link_libtsan) $(libtsan_darwin_rpath) ++ + + # Work around what appears to be a GNU make bug handling MAKEFLAGS + # values defined in terms of make variables, as is the case for CC and +diff --git a/libsanitizer/ubsan/Makefile.am b/libsanitizer/ubsan/Makefile.am +index d480f26adc0..7769b3437e4 100644 +--- a/libsanitizer/ubsan/Makefile.am ++++ b/libsanitizer/ubsan/Makefile.am +@@ -36,7 +36,12 @@ if LIBBACKTRACE_SUPPORTED + libubsan_la_LIBADD += $(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la + endif + libubsan_la_LIBADD += $(LIBSTDCXX_RAW_CXX_LDFLAGS) +-libubsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libubsan) ++if ENABLE_DARWIN_AT_RPATH ++libubsan_darwin_rpath = -Wc,-nodefaultrpaths ++libubsan_darwin_rpath += -Wl,-rpath,@loader_path ++endif ++libubsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ ++ $(link_libubsan) $(libubsan_darwin_rpath) + + # Use special rules for files that require RTTI support. + ubsan_handlers_cxx.% ubsan_type_hash.% ubsan_type_hash_itanium.% : AM_CXXFLAGS += -frtti +diff --git a/libsanitizer/ubsan/Makefile.in b/libsanitizer/ubsan/Makefile.in +index 497e0338696..7e51480e970 100644 +--- a/libsanitizer/ubsan/Makefile.in ++++ b/libsanitizer/ubsan/Makefile.in +@@ -356,7 +356,6 @@ pdfdir = @pdfdir@ + prefix = @prefix@ + program_transform_name = @program_transform_name@ + psdir = @psdir@ +-runstatedir = @runstatedir@ + sbindir = @sbindir@ + sharedstatedir = @sharedstatedir@ + srcdir = @srcdir@ +@@ -401,7 +400,12 @@ libubsan_la_SOURCES = $(ubsan_files) + libubsan_la_LIBADD = \ + $(top_builddir)/sanitizer_common/libsanitizer_common.la \ + $(am__append_1) $(am__append_2) $(LIBSTDCXX_RAW_CXX_LDFLAGS) +-libubsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libubsan) ++@ENABLE_DARWIN_AT_RPATH_TRUE@libubsan_darwin_rpath = \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path ++libubsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ ++ $(link_libubsan) $(libubsan_darwin_rpath) ++ + + # Work around what appears to be a GNU make bug handling MAKEFLAGS + # values defined in terms of make variables, as is the case for CC and +diff --git a/libssp/Makefile.am b/libssp/Makefile.am +index 945dc3c8336..d2a92b3aed1 100644 +--- a/libssp/Makefile.am ++++ b/libssp/Makefile.am +@@ -49,8 +49,12 @@ libssp_la_SOURCES = \ + vsnprintf-chk.c vsprintf-chk.c + libssp_la_LIBADD = + libssp_la_DEPENDENCIES = $(version_dep) $(libssp_la_LIBADD) ++if ENABLE_DARWIN_AT_RPATH ++libssp_darwin_rpath = -Wc,-nodefaultrpaths ++libssp_darwin_rpath += -Wl,-rpath,@loader_path ++endif + libssp_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ +- $(version_arg) $(lt_host_flags) ++ $(version_arg) $(lt_host_flags) $(libssp_darwin_rpath) + + libssp_nonshared_la_SOURCES = \ + ssp-local.c +diff --git a/libssp/Makefile.in b/libssp/Makefile.in +index bc8a0dc2b28..1cf86361b96 100644 +--- a/libssp/Makefile.in ++++ b/libssp/Makefile.in +@@ -376,8 +376,11 @@ libssp_la_SOURCES = \ + + libssp_la_LIBADD = + libssp_la_DEPENDENCIES = $(version_dep) $(libssp_la_LIBADD) ++@ENABLE_DARWIN_AT_RPATH_TRUE@libssp_darwin_rpath = \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path + libssp_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ +- $(version_arg) $(lt_host_flags) ++ $(version_arg) $(lt_host_flags) $(libssp_darwin_rpath) + + libssp_nonshared_la_SOURCES = \ + ssp-local.c +diff --git a/libssp/configure b/libssp/configure +index 10ba209bde8..cb0a9a4308a 100755 +--- a/libssp/configure ++++ b/libssp/configure +@@ -636,6 +636,8 @@ LIBOBJS + get_gcc_base_ver + toolexeclibdir + toolexecdir ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + enable_static + enable_shared + lt_host_flags +@@ -781,6 +783,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + with_toolexeclibdir + with_gcc_major_version_only + ' +@@ -1426,6 +1429,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + + Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] +@@ -4338,7 +4344,7 @@ case "$host" in + case "$enable_cet" in + auto) + # Check if target supports multi-byte NOPs +- # and if assembler supports CET insn. ++ # and if compiler and assembler support CET insn. + cet_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -fcf-protection" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +@@ -7453,7 +7459,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -9165,6 +9171,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -9182,9 +9231,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -10992,7 +11045,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11005 "configure" ++#line 11048 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11098,7 +11151,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11111 "configure" ++#line 11154 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11376,6 +11429,15 @@ fi + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ ++ + # Calculate toolexeclibdir + # Also toolexecdir, though it's only used in toolexeclibdir + case ${version_specific_libs} in +@@ -11585,6 +11647,10 @@ if test -z "${LIBSSP_USE_SYMVER_SUN_TRUE}" && test -z "${LIBSSP_USE_SYMVER_SUN_F + as_fn_error $? "conditional \"LIBSSP_USE_SYMVER_SUN\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + + : "${CONFIG_STATUS=./config.status}" + ac_write_fail=0 +diff --git a/libssp/configure.ac b/libssp/configure.ac +index f30f81c54f6..90778e2355d 100644 +--- a/libssp/configure.ac ++++ b/libssp/configure.ac +@@ -165,6 +165,8 @@ AC_SUBST(enable_static) + + GCC_WITH_TOOLEXECLIBDIR + ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) ++ + # Calculate toolexeclibdir + # Also toolexecdir, though it's only used in toolexeclibdir + case ${version_specific_libs} in +diff --git a/libstdc++-v3/config/os/bsd/darwin/os_defines.h b/libstdc++-v3/config/os/bsd/darwin/os_defines.h +index f56f31ad2f5..5b611d32e0d 100644 +--- a/libstdc++-v3/config/os/bsd/darwin/os_defines.h ++++ b/libstdc++-v3/config/os/bsd/darwin/os_defines.h +@@ -33,11 +33,11 @@ + links to, so there's no need for weak-ness for that. */ + #define _GLIBCXX_GTHREAD_USE_WEAK 0 + +-// On Darwin, in order to enable overriding of operator new and delete, +-// GCC makes the definition of these functions weak, relies on the +-// loader to implement weak semantics properly, and uses +-// -flat_namespace to work around the way that it doesn't. +-#define _GLIBCXX_WEAK_DEFINITION __attribute__ ((weak)) ++// On Darwin, in order to enable overriding of operator new and delete, the ++// ABI library exports a weak definition. The static linker will override this ++// iff a user-provided implementation is given (providing that the user ++// implementation is not itself a weak definition). ++#define _GLIBCXX_WEAK_DEFINITION __attribute__ ((__weak__)) + + #if defined (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) \ + && (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1080) +diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure +index ccc23f1b352..8c15ae6f9bd 100755 +--- a/libstdc++-v3/configure ++++ b/libstdc++-v3/configure +@@ -788,6 +788,8 @@ glibcxx_compiler_pic_flag + glibcxx_lt_pic_flag + OS_IS_DARWIN_FALSE + OS_IS_DARWIN_TRUE ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + enable_static + enable_shared + lt_host_flags +@@ -923,6 +925,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + enable_hosted_libstdcxx + enable_libstdcxx_verbose + enable_libstdcxx_pch +@@ -1610,6 +1613,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --disable-hosted-libstdcxx + only build freestanding C++ runtime support + --disable-libstdcxx-verbose +@@ -8526,7 +8532,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -10366,6 +10372,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -10383,9 +10432,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -12193,7 +12246,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12196 "configure" ++#line 12249 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -12299,7 +12352,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12302 "configure" ++#line 12355 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -13181,6 +13234,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc_CXX=no + hardcode_direct_CXX=no + hardcode_automatic_CXX=yes +@@ -13198,12 +13294,20 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + if test "$lt_cv_apple_cc_single_mod" != "yes"; then +- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring${_lt_dsymutil}" + archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" + fi + +@@ -15580,6 +15684,14 @@ esac + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ + + os_is_darwin=no + case ${host_os} in +@@ -15997,7 +16109,7 @@ $as_echo "$glibcxx_cv_atomic_long_long" >&6; } + # Fake what AC_TRY_COMPILE does. + + cat > conftest.$ac_ext << EOF +-#line 16000 "configure" ++#line 16112 "configure" + int main() + { + typedef bool atomic_type; +@@ -16032,7 +16144,7 @@ $as_echo "$glibcxx_cv_atomic_bool" >&6; } + rm -f conftest* + + cat > conftest.$ac_ext << EOF +-#line 16035 "configure" ++#line 16147 "configure" + int main() + { + typedef short atomic_type; +@@ -16067,7 +16179,7 @@ $as_echo "$glibcxx_cv_atomic_short" >&6; } + rm -f conftest* + + cat > conftest.$ac_ext << EOF +-#line 16070 "configure" ++#line 16182 "configure" + int main() + { + // NB: _Atomic_word not necessarily int. +@@ -16103,7 +16215,7 @@ $as_echo "$glibcxx_cv_atomic_int" >&6; } + rm -f conftest* + + cat > conftest.$ac_ext << EOF +-#line 16106 "configure" ++#line 16218 "configure" + int main() + { + typedef long long atomic_type; +@@ -16259,7 +16371,7 @@ $as_echo "mutex" >&6; } + # unnecessary for this test. + + cat > conftest.$ac_ext << EOF +-#line 16262 "configure" ++#line 16374 "configure" + int main() + { + _Decimal32 d1; +@@ -16301,7 +16413,7 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + # unnecessary for this test. + + cat > conftest.$ac_ext << EOF +-#line 16304 "configure" ++#line 16416 "configure" + template + struct same + { typedef T2 type; }; +@@ -79309,6 +79421,10 @@ if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then + as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${OS_IS_DARWIN_TRUE}" && test -z "${OS_IS_DARWIN_FALSE}"; then + as_fn_error $? "conditional \"OS_IS_DARWIN\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac +index dc0c61973d1..f9c9f959848 100644 +--- a/libstdc++-v3/configure.ac ++++ b/libstdc++-v3/configure.ac +@@ -99,6 +99,7 @@ AM_PROG_LIBTOOL + ACX_LT_HOST_FLAGS + AC_SUBST(enable_shared) + AC_SUBST(enable_static) ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) + + os_is_darwin=no + case ${host_os} in +diff --git a/libstdc++-v3/configure.host b/libstdc++-v3/configure.host +index ec32980aa0d..da5b1578d91 100644 +--- a/libstdc++-v3/configure.host ++++ b/libstdc++-v3/configure.host +@@ -234,11 +234,6 @@ case "${host_os}" in + darwin8 | darwin8.* ) + # For 8+ compatibility is better if not -flat_namespace. + OPT_LDFLAGS="${OPT_LDFLAGS} -Wl,-single_module" +- case "${host_cpu}" in +- i[34567]86 | x86_64) +- OPTIMIZE_CXXFLAGS="${OPTIMIZE_CXXFLAGS} -fvisibility-inlines-hidden" +- ;; +- esac + os_include_dir="os/bsd/darwin" + ;; + darwin*) +diff --git a/libstdc++-v3/src/Makefile.am b/libstdc++-v3/src/Makefile.am +index b83c222d51d..2ff635a7264 100644 +--- a/libstdc++-v3/src/Makefile.am ++++ b/libstdc++-v3/src/Makefile.am +@@ -139,8 +139,13 @@ libstdc___la_DEPENDENCIES = \ + $(top_builddir)/src/c++17/libc++17convenience.la \ + $(top_builddir)/src/c++20/libc++20convenience.la + ++if ENABLE_DARWIN_AT_RPATH ++libstdc___darwin_rpath = -Wc,-nodefaultrpaths ++libstdc___darwin_rpath += -Wl,-rpath,@loader_path ++endif ++ + libstdc___la_LDFLAGS = \ +- -version-info $(libtool_VERSION) ${version_arg} -lm ++ -version-info $(libtool_VERSION) ${version_arg} -lm $(libstdc___darwin_rpath) + + libstdc___la_LINK = $(CXXLINK) $(libstdc___la_LDFLAGS) $(lt_host_flags) + +diff --git a/libstdc++-v3/src/Makefile.in b/libstdc++-v3/src/Makefile.in +index cef290c5d11..3676208223a 100644 +--- a/libstdc++-v3/src/Makefile.in ++++ b/libstdc++-v3/src/Makefile.in +@@ -553,8 +553,11 @@ libstdc___la_DEPENDENCIES = \ + $(top_builddir)/src/c++17/libc++17convenience.la \ + $(top_builddir)/src/c++20/libc++20convenience.la + ++@ENABLE_DARWIN_AT_RPATH_TRUE@libstdc___darwin_rpath = \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path + libstdc___la_LDFLAGS = \ +- -version-info $(libtool_VERSION) ${version_arg} -lm ++ -version-info $(libtool_VERSION) ${version_arg} -lm $(libstdc___darwin_rpath) + + libstdc___la_LINK = $(CXXLINK) $(libstdc___la_LDFLAGS) $(lt_host_flags) + @GLIBCXX_LDBL_ALT128_COMPAT_FALSE@@GLIBCXX_LDBL_COMPAT_TRUE@LTCXXCOMPILE64 = $(LTCXXCOMPILE) +diff --git a/libtool.m4 b/libtool.m4 +index 17f8e5f3074..1060b698168 100644 +--- a/libtool.m4 ++++ b/libtool.m4 +@@ -1005,7 +1005,7 @@ _LT_EOF + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[[89]]*|UNSET,*-darwin[[12]][[0123456789]]*) ++ UNSET,*-darwin[[89]]*|UNSET,*-darwin[[12]][[0-9]]*) + ;; + 10.[[012]][[,.]]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -1039,6 +1039,45 @@ _LT_EOF + m4_defun([_LT_DARWIN_LINKER_FEATURES], + [ + m4_require([_LT_REQUIRED_DARWIN_CHECKS]) ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ AC_ARG_ENABLE([darwin-at-rpath], ++ AS_HELP_STRING([--enable-darwin-at-rpath], ++ [install libraries with @rpath/library-name, requires rpaths to be added to executables]), ++ [if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[[4-8]]*|UNSET,rhapsody*|10.[[0-4]][[,.]]*) ++ AC_MSG_WARN([Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)]) ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi], ++ [case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[[4-8]]*|UNSET,rhapsody*|10.[[0-4]][[,.]]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[[5-9]]*|UNSET,darwin2*|10.1[[1-9]][[,.]]*|1[[1-9]].*[[,.]]* ) ++ AC_MSG_NOTICE([@rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)]) ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ]) ++ + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_automatic, $1)=yes +@@ -1056,13 +1095,21 @@ m4_defun([_LT_DARWIN_LINKER_FEATURES], + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + m4_if([$1], [CXX], + [ if test "$lt_cv_apple_cc_single_mod" != "yes"; then +- _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring${_lt_dsymutil}" + _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" + fi + ],[]) +@@ -6441,7 +6488,6 @@ fi # test "$_lt_caught_CXX_error" != yes + AC_LANG_POP + ])# _LT_LANG_CXX_CONFIG + +- + # _LT_SYS_HIDDEN_LIBDEPS([TAGNAME]) + # --------------------------------- + # Figure out "hidden" library dependencies from verbose +diff --git a/libvtv/configure b/libvtv/configure +index d64b4af5c6b..3ce65ead30a 100755 +--- a/libvtv/configure ++++ b/libvtv/configure +@@ -640,6 +640,8 @@ VTV_CYGMIN_FALSE + VTV_CYGMIN_TRUE + XCFLAGS + libtool_VERSION ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + enable_static + enable_shared + lt_host_flags +@@ -797,6 +799,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + enable_cet + with_gcc_major_version_only + ' +@@ -1446,6 +1449,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --enable-cet enable Intel CET in target libraries [default=auto] + + Optional Packages: +@@ -8743,7 +8749,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -10448,6 +10454,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -10465,9 +10514,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -12254,7 +12307,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12267 "configure" ++#line 12310 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -12360,7 +12413,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12373 "configure" ++#line 12416 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -13236,6 +13289,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc_CXX=no + hardcode_direct_CXX=no + hardcode_automatic_CXX=yes +@@ -13253,12 +13349,20 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + if test "$lt_cv_apple_cc_single_mod" != "yes"; then +- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring${_lt_dsymutil}" + archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" + fi + +@@ -15099,16 +15203,6 @@ freebsd* | dragonfly*) + esac + ;; + +-gnu*) +- version_type=linux +- need_lib_prefix=no +- need_version=no +- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' +- soname_spec='${libname}${release}${shared_ext}$major' +- shlibpath_var=LD_LIBRARY_PATH +- hardcode_into_libs=yes +- ;; +- + haiku*) + version_type=linux + need_lib_prefix=no +@@ -15230,7 +15324,7 @@ linux*oldld* | linux*aout* | linux*coff*) + # project, but have not yet been accepted: they are GCC-local changes + # for the time being. (See + # https://lists.gnu.org/archive/html/libtool-patches/2018-05/msg00000.html) +-linux* | k*bsd*-gnu | kopensolaris*-gnu | uclinuxfdpiceabi) ++linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu* | uclinuxfdpiceabi) + version_type=linux + need_lib_prefix=no + need_version=no +@@ -15642,6 +15736,14 @@ esac + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ + + # For libtool versioning info, format is CURRENT:REVISION:AGE + libtool_VERSION=1:0:0 +@@ -15672,7 +15774,7 @@ case "$host" in + case "$enable_cet" in + auto) + # Check if target supports multi-byte NOPs +- # and if assembler supports CET insn. ++ # and if compiler and assembler support CET insn. + cet_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -fcf-protection" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +@@ -15987,6 +16089,10 @@ if test -z "${am__fastdepCXX_TRUE}" && test -z "${am__fastdepCXX_FALSE}"; then + as_fn_error $? "conditional \"am__fastdepCXX\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${VTV_CYGMIN_TRUE}" && test -z "${VTV_CYGMIN_FALSE}"; then + as_fn_error $? "conditional \"VTV_CYGMIN\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/libvtv/configure.ac b/libvtv/configure.ac +index f3b937e4b10..50aaadbb3a3 100644 +--- a/libvtv/configure.ac ++++ b/libvtv/configure.ac +@@ -153,6 +153,7 @@ AM_PROG_LIBTOOL + ACX_LT_HOST_FLAGS + AC_SUBST(enable_shared) + AC_SUBST(enable_static) ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) + + # For libtool versioning info, format is CURRENT:REVISION:AGE + libtool_VERSION=1:0:0 +diff --git a/lto-plugin/configure b/lto-plugin/configure +index b820accfd65..f6c076de88a 100755 +--- a/lto-plugin/configure ++++ b/lto-plugin/configure +@@ -634,6 +634,8 @@ LTLIBOBJS + LIBOBJS + target_noncanonical + lt_host_flags ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + OTOOL64 + OTOOL + LIPO +@@ -785,6 +787,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + ' + ac_precious_vars='build_alias + host_alias +@@ -1430,6 +1433,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + + Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] +@@ -8569,7 +8575,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -10275,6 +10281,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -10292,9 +10341,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -12081,7 +12134,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12084 "configure" ++#line 12137 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -12187,7 +12240,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12190 "configure" ++#line 12243 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -12424,6 +12477,14 @@ CC="$lt_save_CC" + # Only expand once: + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ + + + +@@ -12670,6 +12731,10 @@ if test -z "${LTO_PLUGIN_USE_SYMVER_SUN_TRUE}" && test -z "${LTO_PLUGIN_USE_SYMV + as_fn_error $? "conditional \"LTO_PLUGIN_USE_SYMVER_SUN\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + + : "${CONFIG_STATUS=./config.status}" + ac_write_fail=0 +diff --git a/lto-plugin/configure.ac b/lto-plugin/configure.ac +index bc5b618a495..317596288b2 100644 +--- a/lto-plugin/configure.ac ++++ b/lto-plugin/configure.ac +@@ -88,6 +88,7 @@ AM_CONDITIONAL(LTO_PLUGIN_USE_SYMVER_GNU, [test "x$lto_plugin_use_symver" = xgnu + AM_CONDITIONAL(LTO_PLUGIN_USE_SYMVER_SUN, [test "x$lto_plugin_use_symver" = xsun]) + + AM_PROG_LIBTOOL ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) + ACX_LT_HOST_FLAGS + AC_SUBST(target_noncanonical) + AC_TYPE_INT64_T +diff --git a/zlib/Makefile.in b/zlib/Makefile.in +index 3f5102d1b87..80fe3b69116 100644 +--- a/zlib/Makefile.in ++++ b/zlib/Makefile.in +@@ -353,6 +353,8 @@ datadir = @datadir@ + datarootdir = @datarootdir@ + docdir = @docdir@ + dvidir = @dvidir@ ++enable_host_pie = @enable_host_pie@ ++enable_host_shared = @enable_host_shared@ + exec_prefix = @exec_prefix@ + host = @host@ + host_alias = @host_alias@ +diff --git a/zlib/configure b/zlib/configure +index f489f31bc70..6c76fccc68c 100755 +--- a/zlib/configure ++++ b/zlib/configure +@@ -635,10 +635,14 @@ am__EXEEXT_TRUE + LTLIBOBJS + LIBOBJS + PICFLAG ++enable_host_pie ++enable_host_shared + TARGET_LIBRARY_FALSE + TARGET_LIBRARY_TRUE + toolexeclibdir + toolexecdir ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + CPP + OTOOL64 + OTOOL +@@ -776,8 +780,10 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + with_toolexeclibdir + enable_host_shared ++enable_host_pie + ' + ac_precious_vars='build_alias + host_alias +@@ -1419,7 +1425,11 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --enable-host-shared build host code as shared libraries ++ --enable-host-pie build host code as PIE + + Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] +@@ -4169,7 +4179,7 @@ case "$host" in + case "$enable_cet" in + auto) + # Check if target supports multi-byte NOPs +- # and if assembler supports CET insn. ++ # and if compiler and assembler support CET insn. + cet_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -fcf-protection" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +@@ -6929,7 +6939,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -8908,6 +8918,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -8925,9 +8978,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -10735,7 +10792,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 10748 "configure" ++#line 10795 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -10841,7 +10898,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 10854 "configure" ++#line 10901 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11078,6 +11135,14 @@ CC="$lt_save_CC" + # Only expand once: + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ + + # Find CPP now so that any conditional tests below won't do it and + # thereby make the resulting definitions conditional. +@@ -11524,15 +11589,31 @@ else + multilib_arg= + fi + ++# Enable --enable-host-shared. + # Check whether --enable-host-shared was given. + if test "${enable_host_shared+set}" = set; then : +- enableval=$enable_host_shared; PICFLAG=-fPIC ++ enableval=$enable_host_shared; ++fi ++ ++ ++ ++# Enable --enable-host-pie. ++# Check whether --enable-host-pie was given. ++if test "${enable_host_pie+set}" = set; then : ++ enableval=$enable_host_pie; ++fi ++ ++ ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE + else + PICFLAG= + fi + + +- + ac_config_files="$ac_config_files Makefile" + + cat >confcache <<\_ACEOF +@@ -11708,6 +11789,10 @@ if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then + as_fn_error $? "conditional \"am__fastdepCC\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${TARGET_LIBRARY_TRUE}" && test -z "${TARGET_LIBRARY_FALSE}"; then + as_fn_error $? "conditional \"TARGET_LIBRARY\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/zlib/configure.ac b/zlib/configure.ac +index be1cfe29651..9501cdfea85 100644 +--- a/zlib/configure.ac ++++ b/zlib/configure.ac +@@ -64,6 +64,7 @@ GCC_CET_FLAGS(CET_FLAGS) + AC_SUBST(CET_FLAGS) + + AC_PROG_LIBTOOL ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) + + # Find CPP now so that any conditional tests below won't do it and + # thereby make the resulting definitions conditional. +@@ -122,11 +123,26 @@ else + multilib_arg= + fi + ++# Enable --enable-host-shared. + AC_ARG_ENABLE(host-shared, + [AS_HELP_STRING([--enable-host-shared], +- [build host code as shared libraries])], +-[PICFLAG=-fPIC], [PICFLAG=]) +-AC_SUBST(PICFLAG) ++ [build host code as shared libraries])]) ++AC_SUBST(enable_host_shared) ++ ++# Enable --enable-host-pie. ++AC_ARG_ENABLE(host-pie, ++[AS_HELP_STRING([--enable-host-pie], ++ [build host code as PIE])]) ++AC_SUBST(enable_host_pie) ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE ++else ++ PICFLAG= ++fi + ++AC_SUBST(PICFLAG) + AC_CONFIG_FILES([Makefile]) + AC_OUTPUT diff --git a/10.9-libcxx/stable/main/finkinfo/languages/gcc13-13.0.info b/10.9-libcxx/stable/main/finkinfo/languages/gcc13-13.0.info new file mode 100644 index 00000000000..53634d75cd5 --- /dev/null +++ b/10.9-libcxx/stable/main/finkinfo/languages/gcc13-13.0.info @@ -0,0 +1,322 @@ +Info2: << +Package: gcc13 +Version: 13.3.0 +Revision: 2 +Type: gccver (13) +Distribution: 13.0 +Source: mirror:gnu:gcc/gcc-%v/gcc-%v.tar.xz +Source-Checksum: SHA256(0845e9621c9543a13f484e94584a49ffc0129970e9914624235fc1d061a0c083) +PatchFile: %n.patch +PatchFile-MD5: 05ab738b7d4a29348173e1f746d40b9e +PatchScript: << + #!/bin/sh -ev + patch -p1 < %{PatchFile} + # don't update live infodoc dir + find . -name Makefile.in | xargs perl -pi -e 's/install-info --version/false/g' +<< +NoSetCPPFLAGS: True +NoSetLDFLAGS: True +UseMaxBuildJobs: True +Conflicts: << + gcc5, gcc6, gcc7, gcc8, + gcc9, + gcc10, + gcc11, + gcc12, + gcc13, + gcc14 +<< +Replaces: << + gcc5, gcc6, gcc7, gcc8, + gcc9, + gcc10, + gcc11, + gcc12, + gcc13, + gcc14 +<< +Depends: << + %N-compiler (= %v-%r) +<< +BuildDepends: << + fink (>= 0.32), + fink-package-precedence, + gettext-tools, + gmp5 (>= 6.1.2-1), + install-info, + isl22, + libgettext8-dev, + libiconv-dev, + libmpc3 (>= 1.0.3-1), + libmpfr6, + x11-dev +<< +ConfigureParams: << + --prefix=%p/lib/gcc%type_num[gccver] \ + --mandir=%p/share/man \ + --infodir=%p/lib/gcc%type_num[gccver]/info \ + --enable-languages=c,c++,fortran,lto,objc,obj-c++ \ + --with-gmp=%p \ + --with-libiconv-prefix=%p \ + --with-isl=%p \ + --with-mpc=%p \ + --with-system-zlib \ + --program-suffix=-fsf-%type_num[gccver] \ + --disable-multilib \ + --enable-stage1-checking \ + ${USE_SYSROOT} \ + --with-pkgversion="Fink %n %v-%r" \ + --with-bugurl="https://github.com/fink/fink-distributions/issues" +<< +InfoTest: << + TestDepends: << + autogen, + dejagnu, + ( "%m" != "arm64" ) apple-gdb + << + TestScript: << + #!/bin/bash -ev + if [ "%m" = "arm64" ]; then + echo "The gcc testsuite requires Apple's gdb, which is not available on this architecture." + exit 0 + elif [ $UID = 0 ]; then + if [ -e /usr/bin/csrutil && `csrutil status | grep -c disabled` ]; then + cd ../darwin_objdir; make -k check RUNTESTFLAGS="--target_board=unix'{-m64}'" || : + else + echo "The gcc testsuite must be run with SIP disabled or package installed." + exit 0 + fi + else + echo "The gcc testsuite must be run as root due to its use of gdb." + exit 0 + fi + << +<< +InfoDocs: gcc.info gfortran.info cpp.info gccinstall.info libgomp.info cppinternals.info gccint.info +CompileScript: << + #!/bin/bash -ev + set +x + if [ -e /usr/local/lib/libgmp.a ] || [ -e /usr/local/lib/libgmp.dylib ]; then + echo "-----WARNING-----WARNING-----WARNING-----" + echo "You seem to have GMP installed in /usr/local." + echo "This is known to cause %N to fail to build." + echo "Please move aside /usr/local and try again." + echo "-----WARNING-----WARNING-----WARNING-----" + exit 1 + else + echo "Good, /usr/local/lib/libgmp* not present." + fi + set -x + ulimit -s `ulimit -s` + mkdir ../darwin_objdir + cd ../darwin_objdir + # build doesn't play well with GNU-make + # unsupported option '-static-libgcc' + export MAKE=/usr/bin/make + # Only need sysroot on 10.14+ because /usr/include has been removed + OSX_MAJOR_VERSION=`sw_vers -productVersion | cut -d. -f1-2` + if dpkg --compare-versions "$OSX_MAJOR_VERSION" ge "10.14"; then + # Get the unversioned SDK path + SDK_PATH=`dirname $(xcrun --sdk macosx --show-sdk-path)`/MacOSX.sdk + # This should really be --with-build-sysroot but that's not getting propagated through the entire build process. + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79885 + export USE_SYSROOT="--with-sysroot=${SDK_PATH}" + fi + # check for incompatible clang ( 6.0 << bad-clang << 7.2) + clangvers=`clang --version | cut -d\ -f4` + $(`dpkg --compare-versions $clangvers '>>' 6.0`) && $(`dpkg --compare-versions $clangvers '<<' 7.2`) && clangcheck='y' + if [ "$clangcheck" = "y" ]; then + ../gcc-%v/configure %c --with-build-config=bootstrap-debug + else + ../gcc-%v/configure %c + fi + # Use bootstrap-lean to reduce disk usage. + # Note that this causes plugin testsuite failures + # since the plugin headers must come from prev-gcc. + # make bootstrap-lean + make bootstrap + fink-package-precedence --prohibit-bdep=%n . +<< +InstallScript: << + #!/bin/sh -ev + darwinvers=`uname -r` + cd ../darwin_objdir + make -j 1 install DESTDIR=%d + mkdir -p %i/bin + + # Add symlinks to recreate previous naming of executables in %p/bin + # as well as %p/lib/gcc%type_num[gccver]/bin and new -fsf-%type_num[gccver] naming in %p/bin. + binfiles="gcc g++ c++ cpp gcov" + for binfile in $binfiles ; do + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/$binfile-%type_num[gccver] + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-%type_num[gccver] + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-fsf-%type_num[gccver] + done + binfiles="gfortran" + for binfile in $binfiles ; do + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/$binfile + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-fsf-%type_num[gccver] + done + + # Remove unsupported executables + binfiles="gcc-ar gcc-nm gcc-ranlib" + for binfile in $binfiles ; do + rm -f %i/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/*-apple-darwin${darwinvers}-$binfile-fsf-%type_num[gccver] + done + + # Add symlinks for manpages under old names. + man1files="cpp g++ gcc gcov" + for man1file in $man1files ; do + ln -s $man1file-fsf-%type_num[gccver].1 %i/share/man/man1/$man1file-%type_num[gccver].1 + done + man1files="gfortran" + for man1file in $man1files ; do + ln -s $man1file-fsf-%type_num[gccver].1 %i/share/man/man1/$man1file.1 + done + + # Rename manpages with -fsf-%type_num[gccver] suffix and create symlinks to old names. + man7files="fsf-funding gfdl gpl" + for man7file in $man7files ; do + mv %i/share/man/man7/$man7file.7 %i/share/man/man7/$man7file-fsf-%type_num[gccver].7 + ln -s $man7file-fsf-%type_num[gccver].7 %i/share/man/man7/$man7file.7 + done + + # Add dir for installed info files, and link them to %i/share/info. + # the %i/lib/gcc%type_num[gccver]/info/* files will go into the -compiler package + # and the files in %i/share/info go into the main package, this allows + # the info files for specific compiler versions to be accessed with + # e.g. `info -d /fink_install_dir/lib/gcc%type_num[gccver]/info gcc', but the "main" info files will + # be available for the install gccXX package in %p/share/info, as usual + install -d -m 755 %i/share/info + for infofile in $(find %i/lib/gcc%type_num[gccver]/info -name '*.info*'); do + infobase=$(basename $infofile) + case $infofile in + *info) %p/bin/install-info --infodir=%i/lib/gcc%type_num[gccver]/info ${infofile} ;; + esac + ln -s %p/lib/gcc%type_num[gccver]/info/$infobase %i/share/info/$infobase + done + + # remove build path from .la files + perl -pi -e "s, \-L[^ ']*/%n-%v-%r/darwin_objdir/[^ ']*,,g" `find %i/lib/gcc%type_num[gccver]/lib -name '*.la'` + if [ "%m" = "arm64" ]; then + arch=aarch64 + else + arch=%m + fi + + # @rpath install_names are required for aarch64 build, but break some linked binaries + # - enforce actual install paths here; take care to update the cross-referenced dylibs. + cd %d + for dylib in .%p/lib/gcc%type_num[gccver]/lib/lib*.[0-9].dylib; do + install_name_tool -id ${dylib#.} $dylib + install_name_tool -change @rpath/libgcc_s.1.1.dylib %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib \ + -change @rpath/libstdc++.6.dylib %p/lib/gcc%type_num[gccver]/lib/libstdc++.6.dylib \ + -change @rpath/libquadmath.0.dylib %p/lib/gcc%type_num[gccver]/lib/libquadmath.0.dylib $dylib + done + otool -L .%p/lib/gcc%type_num[gccver]/lib/lib*.[0-9].dylib | grep '@rpath' && exit 2 + + cp %b/gcc/config/darwin-sections.def %i/lib/gcc%type_num[gccver]/lib/gcc/${arch}-apple-darwin${darwinvers}/%v/plugin/include/config +<< +SplitOff: << + Package: %N-shlibs + Replaces: << + gcc4 (<= 20050130-4), + gfortran-shlibs + << + Provides: << + gfortran-shlibs + << + Description: Shared libraries for %N + DocFiles: gcc/COPYING gcc/COPYING.LIB + Files: << + lib/gcc%type_num[gccver]/lib/libgfortran.5*.dylib + lib/gcc%type_num[gccver]/lib/libstdc++.6*.dylib + lib/gcc%type_num[gccver]/lib/libgcc_s.1*.dylib + lib/gcc%type_num[gccver]/lib/libitm.1*.dylib + lib/gcc%type_num[gccver]/lib/libssp.0*.dylib + lib/gcc%type_num[gccver]/lib/libobjc-gnu.4*.dylib + lib/gcc%type_num[gccver]/lib/libgomp.1*.dylib + lib/gcc%type_num[gccver]/lib/libquadmath.0*.dylib + lib/gcc%type_num[gccver]/lib/libatomic.1*.dylib + << + Shlibs: << + %p/lib/gcc%type_num[gccver]/lib/libgfortran.5.dylib 6.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libstdc++.6.dylib 7.0.0 %n (>= 13.1.0-1) + ( "%m" = "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib 1.0.0 %n (>= 13.1.0-1) + ( "%m" != "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.dylib 1.0.0 %n (>= 13.1.0-1) + ( "%m" != "arm64" ) !%p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib + %p/lib/gcc%type_num[gccver]/lib/libitm.1.dylib 2.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libssp.0.dylib 1.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libobjc-gnu.4.dylib 5.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libgomp.1.dylib 2.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libquadmath.0.dylib 1.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libatomic.1.dylib 4.0.0 %n (>= 13.1.0-1) + << +<< +SplitOff2: << + Package: %N-compiler + Depends: << + gmp5-shlibs (>= 6.1.2-1), + isl22-shlibs, + libgettext8-shlibs, + libgmpxx5-shlibs (>= 6.1.2-1), + libiconv, + libmpc3-shlibs (>= 1.0.3-1), + libmpfr6-shlibs, + %N-shlibs (= %v-%r) + << + BuildDependsOnly: False + Description: Compiler Binaries for gcc%type_num[gccver] + DocFiles: gcc/COPYING gcc/COPYING.LIB gcc/ChangeLog gcc/ABOUT-GCC-NLS gcc/README.Portability + Files: << + bin/*-fsf-%type_num[gccver] + lib/gcc%type_num[gccver] + share/man/man1/*-fsf-%type_num[gccver].1 + share/man/man7/*-fsf-%type_num[gccver].7 + << +<< +License: GPL +Description: GNU Compiler Collection Version %type_num[gccver] +DescDetail: << + GCC, the GNU Compiler Collection, includes front ends for + C, C++, Objective-C, Objective-C++, Fortran and Ada. + . + C, C++, Objective C and Fortran are included in this package. + . + The C and C++ compilers are named gcc-13 and g++-13 to avoid + conflicts with gcc and g++ installed by the Apple Developer Tools. +<< +DescPackaging: << + Build with -fsf-%type_num[gccver] suffix and place non-overlapping files into new gcc%type_num[gccver]-compiler + package which can co-exist with other gccXX-compiler packages. Overlapping files + are left in main gcc%type_num[gccver] package which still conflicts with other gccXX packages. + + macOS10.14 no longer supports building 32bit libraries, so must disable multilib. + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87030 + + We use --with-sysroot to find the hidden system-headers in case /usr/include is not + populated. Ideally want --with-build-sysroot because we only need the headers to build + gcc and that should not impact the end product, but then anything using gccX will + need to add it's own -isysroot flag. + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79885 + + Homebrew patches for arm64/aarch64 build and macOS 13 from + https://github.com/Homebrew/formula-patches/blob/master/gcc/gcc-%v.diff + - libasan.* and libsubsan.* currently not built on darwin22+ - see + https://github.com/iains/gcc-darwin-arm64/commit/e722a1f4 + and missing from the 13.0-15.0 packages until resolved. + There are both "1" and "1.1" versions of libgcc_s.dylib now, but only "1.1" on arm64. + Manual fixes of @rpath install_names required for aarch64 build to maintain downstream + package compatibility. + + With Xcode 16 compilation of libgcc/config/aarch64/lse.S fails on a `STARTFN` macro with + 'non-private labels cannot appear between .cfi_startproc / .cfi_endproc pairs' + - no complete fix for this found in the 13.x branch, so I back-patched the entire file + from 14.2 + Homebrew (r2) patches to build on Sonoma and Sequoia; + addional commits from iains/gcc-13-branch as per + https://github.com/Homebrew/homebrew-core/blob/master/Formula/g/gcc@13.rb . +<< +Homepage: http://gcc.gnu.org/ +Maintainer: None +<< diff --git a/10.9-libcxx/stable/main/finkinfo/languages/gcc13-14.0.info b/10.9-libcxx/stable/main/finkinfo/languages/gcc13-14.0.info new file mode 100644 index 00000000000..1f741bcf406 --- /dev/null +++ b/10.9-libcxx/stable/main/finkinfo/languages/gcc13-14.0.info @@ -0,0 +1,323 @@ +Info2: << +Package: gcc13 +Version: 13.3.0 +Revision: 2 +Type: gccver (13) +Distribution: 14.0 +Architecture: arm64 +Source: mirror:gnu:gcc/gcc-%v/gcc-%v.tar.xz +Source-Checksum: SHA256(0845e9621c9543a13f484e94584a49ffc0129970e9914624235fc1d061a0c083) +PatchFile: %n.patch +PatchFile-MD5: 05ab738b7d4a29348173e1f746d40b9e +PatchScript: << + #!/bin/sh -ev + patch -p1 < %{PatchFile} + # don't update live infodoc dir + find . -name Makefile.in | xargs perl -pi -e 's/install-info --version/false/g' +<< +NoSetCPPFLAGS: True +NoSetLDFLAGS: True +UseMaxBuildJobs: True +Conflicts: << + gcc5, gcc6, gcc7, gcc8, + gcc9, + gcc10, + gcc11, + gcc12, + gcc13, + gcc14 +<< +Replaces: << + gcc5, gcc6, gcc7, gcc8, + gcc9, + gcc10, + gcc11, + gcc12, + gcc13, + gcc14 +<< +Depends: << + %N-compiler (= %v-%r) +<< +BuildDepends: << + fink (>= 0.32), + fink-package-precedence, + gettext-tools, + gmp5 (>= 6.1.2-1), + install-info, + isl22, + libgettext8-dev, + libiconv-dev, + libmpc3 (>= 1.0.3-1), + libmpfr6, + x11-dev +<< +ConfigureParams: << + --prefix=%p/lib/gcc%type_num[gccver] \ + --mandir=%p/share/man \ + --infodir=%p/lib/gcc%type_num[gccver]/info \ + --enable-languages=c,c++,fortran,lto,objc,obj-c++ \ + --with-gmp=%p \ + --with-libiconv-prefix=%p \ + --with-isl=%p \ + --with-mpc=%p \ + --with-system-zlib \ + --program-suffix=-fsf-%type_num[gccver] \ + --disable-multilib \ + --enable-stage1-checking \ + ${USE_SYSROOT} \ + --with-pkgversion="Fink %n %v-%r" \ + --with-bugurl="https://github.com/fink/fink-distributions/issues" +<< +InfoTest: << + TestDepends: << + autogen, + dejagnu, + ( "%m" != "arm64" ) apple-gdb + << + TestScript: << + #!/bin/bash -ev + if [ "%m" = "arm64" ]; then + echo "The gcc testsuite requires Apple's gdb, which is not available on this architecture." + exit 0 + elif [ $UID = 0 ]; then + if [ -e /usr/bin/csrutil && `csrutil status | grep -c disabled` ]; then + cd ../darwin_objdir; make -k check RUNTESTFLAGS="--target_board=unix'{-m64}'" || : + else + echo "The gcc testsuite must be run with SIP disabled or package installed." + exit 0 + fi + else + echo "The gcc testsuite must be run as root due to its use of gdb." + exit 0 + fi + << +<< +InfoDocs: gcc.info gfortran.info cpp.info gccinstall.info libgomp.info cppinternals.info gccint.info +CompileScript: << + #!/bin/bash -ev + set +x + if [ -e /usr/local/lib/libgmp.a ] || [ -e /usr/local/lib/libgmp.dylib ]; then + echo "-----WARNING-----WARNING-----WARNING-----" + echo "You seem to have GMP installed in /usr/local." + echo "This is known to cause %N to fail to build." + echo "Please move aside /usr/local and try again." + echo "-----WARNING-----WARNING-----WARNING-----" + exit 1 + else + echo "Good, /usr/local/lib/libgmp* not present." + fi + set -x + ulimit -s `ulimit -s` + mkdir ../darwin_objdir + cd ../darwin_objdir + # build doesn't play well with GNU-make + # unsupported option '-static-libgcc' + export MAKE=/usr/bin/make + # Only need sysroot on 10.14+ because /usr/include has been removed + OSX_MAJOR_VERSION=`sw_vers -productVersion | cut -d. -f1-2` + if dpkg --compare-versions "$OSX_MAJOR_VERSION" ge "10.14"; then + # Get the unversioned SDK path + SDK_PATH=`dirname $(xcrun --sdk macosx --show-sdk-path)`/MacOSX.sdk + # This should really be --with-build-sysroot but that's not getting propagated through the entire build process. + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79885 + export USE_SYSROOT="--with-sysroot=${SDK_PATH}" + fi + # check for incompatible clang ( 6.0 << bad-clang << 7.2) + clangvers=`clang --version | cut -d\ -f4` + $(`dpkg --compare-versions $clangvers '>>' 6.0`) && $(`dpkg --compare-versions $clangvers '<<' 7.2`) && clangcheck='y' + if [ "$clangcheck" = "y" ]; then + ../gcc-%v/configure %c --with-build-config=bootstrap-debug + else + ../gcc-%v/configure %c + fi + # Use bootstrap-lean to reduce disk usage. + # Note that this causes plugin testsuite failures + # since the plugin headers must come from prev-gcc. + # make bootstrap-lean + make bootstrap + fink-package-precedence --prohibit-bdep=%n . +<< +InstallScript: << + #!/bin/sh -ev + darwinvers=`uname -r` + cd ../darwin_objdir + make -j 1 install DESTDIR=%d + mkdir -p %i/bin + + # Add symlinks to recreate previous naming of executables in %p/bin + # as well as %p/lib/gcc%type_num[gccver]/bin and new -fsf-%type_num[gccver] naming in %p/bin. + binfiles="gcc g++ c++ cpp gcov" + for binfile in $binfiles ; do + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/$binfile-%type_num[gccver] + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-%type_num[gccver] + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-fsf-%type_num[gccver] + done + binfiles="gfortran" + for binfile in $binfiles ; do + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/$binfile + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-fsf-%type_num[gccver] + done + + # Remove unsupported executables + binfiles="gcc-ar gcc-nm gcc-ranlib" + for binfile in $binfiles ; do + rm -f %i/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/*-apple-darwin${darwinvers}-$binfile-fsf-%type_num[gccver] + done + + # Add symlinks for manpages under old names. + man1files="cpp g++ gcc gcov" + for man1file in $man1files ; do + ln -s $man1file-fsf-%type_num[gccver].1 %i/share/man/man1/$man1file-%type_num[gccver].1 + done + man1files="gfortran" + for man1file in $man1files ; do + ln -s $man1file-fsf-%type_num[gccver].1 %i/share/man/man1/$man1file.1 + done + + # Rename manpages with -fsf-%type_num[gccver] suffix and create symlinks to old names. + man7files="fsf-funding gfdl gpl" + for man7file in $man7files ; do + mv %i/share/man/man7/$man7file.7 %i/share/man/man7/$man7file-fsf-%type_num[gccver].7 + ln -s $man7file-fsf-%type_num[gccver].7 %i/share/man/man7/$man7file.7 + done + + # Add dir for installed info files, and link them to %i/share/info. + # the %i/lib/gcc%type_num[gccver]/info/* files will go into the -compiler package + # and the files in %i/share/info go into the main package, this allows + # the info files for specific compiler versions to be accessed with + # e.g. `info -d /fink_install_dir/lib/gcc%type_num[gccver]/info gcc', but the "main" info files will + # be available for the install gccXX package in %p/share/info, as usual + install -d -m 755 %i/share/info + for infofile in $(find %i/lib/gcc%type_num[gccver]/info -name '*.info*'); do + infobase=$(basename $infofile) + case $infofile in + *info) %p/bin/install-info --infodir=%i/lib/gcc%type_num[gccver]/info ${infofile} ;; + esac + ln -s %p/lib/gcc%type_num[gccver]/info/$infobase %i/share/info/$infobase + done + + # remove build path from .la files + perl -pi -e "s, \-L[^ ']*/%n-%v-%r/darwin_objdir/[^ ']*,,g" `find %i/lib/gcc%type_num[gccver]/lib -name '*.la'` + if [ "%m" = "arm64" ]; then + arch=aarch64 + else + arch=%m + fi + + # @rpath install_names are required for aarch64 build, but break some linked binaries + # - enforce actual install paths here; take care to update the cross-referenced dylibs. + cd %d + for dylib in .%p/lib/gcc%type_num[gccver]/lib/lib*.[0-9].dylib; do + install_name_tool -id ${dylib#.} $dylib + install_name_tool -change @rpath/libgcc_s.1.1.dylib %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib \ + -change @rpath/libstdc++.6.dylib %p/lib/gcc%type_num[gccver]/lib/libstdc++.6.dylib \ + -change @rpath/libquadmath.0.dylib %p/lib/gcc%type_num[gccver]/lib/libquadmath.0.dylib $dylib + done + otool -L .%p/lib/gcc%type_num[gccver]/lib/lib*.[0-9].dylib | grep '@rpath' && exit 2 + + cp %b/gcc/config/darwin-sections.def %i/lib/gcc%type_num[gccver]/lib/gcc/${arch}-apple-darwin${darwinvers}/%v/plugin/include/config +<< +SplitOff: << + Package: %N-shlibs + Replaces: << + gcc4 (<= 20050130-4), + gfortran-shlibs + << + Provides: << + gfortran-shlibs + << + Description: Shared libraries for %N + DocFiles: gcc/COPYING gcc/COPYING.LIB + Files: << + lib/gcc%type_num[gccver]/lib/libgfortran.5*.dylib + lib/gcc%type_num[gccver]/lib/libstdc++.6*.dylib + lib/gcc%type_num[gccver]/lib/libgcc_s.1*.dylib + lib/gcc%type_num[gccver]/lib/libitm.1*.dylib + lib/gcc%type_num[gccver]/lib/libssp.0*.dylib + lib/gcc%type_num[gccver]/lib/libobjc-gnu.4*.dylib + lib/gcc%type_num[gccver]/lib/libgomp.1*.dylib + lib/gcc%type_num[gccver]/lib/libquadmath.0*.dylib + lib/gcc%type_num[gccver]/lib/libatomic.1*.dylib + << + Shlibs: << + %p/lib/gcc%type_num[gccver]/lib/libgfortran.5.dylib 6.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libstdc++.6.dylib 7.0.0 %n (>= 13.1.0-1) + ( "%m" = "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib 1.0.0 %n (>= 13.1.0-1) + ( "%m" != "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.dylib 1.0.0 %n (>= 13.1.0-1) + ( "%m" != "arm64" ) !%p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib + %p/lib/gcc%type_num[gccver]/lib/libitm.1.dylib 2.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libssp.0.dylib 1.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libobjc-gnu.4.dylib 5.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libgomp.1.dylib 2.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libquadmath.0.dylib 1.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libatomic.1.dylib 4.0.0 %n (>= 13.1.0-1) + << +<< +SplitOff2: << + Package: %N-compiler + Depends: << + gmp5-shlibs (>= 6.1.2-1), + isl22-shlibs, + libgettext8-shlibs, + libgmpxx5-shlibs (>= 6.1.2-1), + libiconv, + libmpc3-shlibs (>= 1.0.3-1), + libmpfr6-shlibs, + %N-shlibs (= %v-%r) + << + BuildDependsOnly: False + Description: Compiler Binaries for gcc%type_num[gccver] + DocFiles: gcc/COPYING gcc/COPYING.LIB gcc/ChangeLog gcc/ABOUT-GCC-NLS gcc/README.Portability + Files: << + bin/*-fsf-%type_num[gccver] + lib/gcc%type_num[gccver] + share/man/man1/*-fsf-%type_num[gccver].1 + share/man/man7/*-fsf-%type_num[gccver].7 + << +<< +License: GPL +Description: GNU Compiler Collection Version %type_num[gccver] +DescDetail: << + GCC, the GNU Compiler Collection, includes front ends for + C, C++, Objective-C, Objective-C++, Fortran and Ada. + . + C, C++, Objective C and Fortran are included in this package. + . + The C and C++ compilers are named gcc-13 and g++-13 to avoid + conflicts with gcc and g++ installed by the Apple Developer Tools. +<< +DescPackaging: << + Build with -fsf-%type_num[gccver] suffix and place non-overlapping files into new gcc%type_num[gccver]-compiler + package which can co-exist with other gccXX-compiler packages. Overlapping files + are left in main gcc%type_num[gccver] package which still conflicts with other gccXX packages. + + macOS10.14 no longer supports building 32bit libraries, so must disable multilib. + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87030 + + We use --with-sysroot to find the hidden system-headers in case /usr/include is not + populated. Ideally want --with-build-sysroot because we only need the headers to build + gcc and that should not impact the end product, but then anything using gccX will + need to add it's own -isysroot flag. + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79885 + + Homebrew patches for arm64/aarch64 build and macOS 13 from + https://github.com/Homebrew/formula-patches/blob/master/gcc/gcc-%v.diff + - libasan.* and libsubsan.* currently not built on darwin22+ - see + https://github.com/iains/gcc-darwin-arm64/commit/e722a1f4 + and missing from the 13.0-15.0 packages until resolved. + There are both "1" and "1.1" versions of libgcc_s.dylib now, but only "1.1" on arm64. + Manual fixes of @rpath install_names required for aarch64 build to maintain downstream + package compatibility. + + With Xcode 16 compilation of libgcc/config/aarch64/lse.S fails on a `STARTFN` macro with + 'non-private labels cannot appear between .cfi_startproc / .cfi_endproc pairs' + - no complete fix for this found in the 13.x branch, so I back-patched the entire file + from 14.2 + Homebrew (r2) patches to build on Sonoma and Sequoia; + addional commits from iains/gcc-13-branch as per + https://github.com/Homebrew/homebrew-core/blob/master/Formula/g/gcc@13.rb . +<< +Homepage: http://gcc.gnu.org/ +Maintainer: None +<< diff --git a/10.9-libcxx/stable/main/finkinfo/languages/gcc13-15.0.info b/10.9-libcxx/stable/main/finkinfo/languages/gcc13-15.0.info new file mode 100644 index 00000000000..cb9bd379775 --- /dev/null +++ b/10.9-libcxx/stable/main/finkinfo/languages/gcc13-15.0.info @@ -0,0 +1,323 @@ +Info2: << +Package: gcc13 +Version: 13.3.0 +Revision: 2 +Type: gccver (13) +Distribution: 15.0 +Architecture: arm64 +Source: mirror:gnu:gcc/gcc-%v/gcc-%v.tar.xz +Source-Checksum: SHA256(0845e9621c9543a13f484e94584a49ffc0129970e9914624235fc1d061a0c083) +PatchFile: %n.patch +PatchFile-MD5: 05ab738b7d4a29348173e1f746d40b9e +PatchScript: << + #!/bin/sh -ev + patch -p1 < %{PatchFile} + # don't update live infodoc dir + find . -name Makefile.in | xargs perl -pi -e 's/install-info --version/false/g' +<< +NoSetCPPFLAGS: True +NoSetLDFLAGS: True +UseMaxBuildJobs: True +Conflicts: << + gcc5, gcc6, gcc7, gcc8, + gcc9, + gcc10, + gcc11, + gcc12, + gcc13, + gcc14 +<< +Replaces: << + gcc5, gcc6, gcc7, gcc8, + gcc9, + gcc10, + gcc11, + gcc12, + gcc13, + gcc14 +<< +Depends: << + %N-compiler (= %v-%r) +<< +BuildDepends: << + fink (>= 0.32), + fink-package-precedence, + gettext-tools, + gmp5 (>= 6.1.2-1), + install-info, + isl22, + libgettext8-dev, + libiconv-dev, + libmpc3 (>= 1.0.3-1), + libmpfr6, + x11-dev +<< +ConfigureParams: << + --prefix=%p/lib/gcc%type_num[gccver] \ + --mandir=%p/share/man \ + --infodir=%p/lib/gcc%type_num[gccver]/info \ + --enable-languages=c,c++,fortran,lto,objc,obj-c++ \ + --with-gmp=%p \ + --with-libiconv-prefix=%p \ + --with-isl=%p \ + --with-mpc=%p \ + --with-system-zlib \ + --program-suffix=-fsf-%type_num[gccver] \ + --disable-multilib \ + --enable-stage1-checking \ + ${USE_SYSROOT} \ + --with-pkgversion="Fink %n %v-%r" \ + --with-bugurl="https://github.com/fink/fink-distributions/issues" +<< +InfoTest: << + TestDepends: << + autogen, + dejagnu, + ( "%m" != "arm64" ) apple-gdb + << + TestScript: << + #!/bin/bash -ev + if [ "%m" = "arm64" ]; then + echo "The gcc testsuite requires Apple's gdb, which is not available on this architecture." + exit 0 + elif [ $UID = 0 ]; then + if [ -e /usr/bin/csrutil && `csrutil status | grep -c disabled` ]; then + cd ../darwin_objdir; make -k check RUNTESTFLAGS="--target_board=unix'{-m64}'" || : + else + echo "The gcc testsuite must be run with SIP disabled or package installed." + exit 0 + fi + else + echo "The gcc testsuite must be run as root due to its use of gdb." + exit 0 + fi + << +<< +InfoDocs: gcc.info gfortran.info cpp.info gccinstall.info libgomp.info cppinternals.info gccint.info +CompileScript: << + #!/bin/bash -ev + set +x + if [ -e /usr/local/lib/libgmp.a ] || [ -e /usr/local/lib/libgmp.dylib ]; then + echo "-----WARNING-----WARNING-----WARNING-----" + echo "You seem to have GMP installed in /usr/local." + echo "This is known to cause %N to fail to build." + echo "Please move aside /usr/local and try again." + echo "-----WARNING-----WARNING-----WARNING-----" + exit 1 + else + echo "Good, /usr/local/lib/libgmp* not present." + fi + set -x + ulimit -s `ulimit -s` + mkdir ../darwin_objdir + cd ../darwin_objdir + # build doesn't play well with GNU-make + # unsupported option '-static-libgcc' + export MAKE=/usr/bin/make + # Only need sysroot on 10.14+ because /usr/include has been removed + OSX_MAJOR_VERSION=`sw_vers -productVersion | cut -d. -f1-2` + if dpkg --compare-versions "$OSX_MAJOR_VERSION" ge "10.14"; then + # Get the unversioned SDK path + SDK_PATH=`dirname $(xcrun --sdk macosx --show-sdk-path)`/MacOSX.sdk + # This should really be --with-build-sysroot but that's not getting propagated through the entire build process. + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79885 + export USE_SYSROOT="--with-sysroot=${SDK_PATH}" + fi + # check for incompatible clang ( 6.0 << bad-clang << 7.2) + clangvers=`clang --version | cut -d\ -f4` + $(`dpkg --compare-versions $clangvers '>>' 6.0`) && $(`dpkg --compare-versions $clangvers '<<' 7.2`) && clangcheck='y' + if [ "$clangcheck" = "y" ]; then + ../gcc-%v/configure %c --with-build-config=bootstrap-debug + else + ../gcc-%v/configure %c + fi + # Use bootstrap-lean to reduce disk usage. + # Note that this causes plugin testsuite failures + # since the plugin headers must come from prev-gcc. + # make bootstrap-lean + make bootstrap + fink-package-precedence --prohibit-bdep=%n . +<< +InstallScript: << + #!/bin/sh -ev + darwinvers=`uname -r` + cd ../darwin_objdir + make -j 1 install DESTDIR=%d + mkdir -p %i/bin + + # Add symlinks to recreate previous naming of executables in %p/bin + # as well as %p/lib/gcc%type_num[gccver]/bin and new -fsf-%type_num[gccver] naming in %p/bin. + binfiles="gcc g++ c++ cpp gcov" + for binfile in $binfiles ; do + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/$binfile-%type_num[gccver] + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-%type_num[gccver] + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-fsf-%type_num[gccver] + done + binfiles="gfortran" + for binfile in $binfiles ; do + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/$binfile + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-fsf-%type_num[gccver] + done + + # Remove unsupported executables + binfiles="gcc-ar gcc-nm gcc-ranlib" + for binfile in $binfiles ; do + rm -f %i/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/*-apple-darwin${darwinvers}-$binfile-fsf-%type_num[gccver] + done + + # Add symlinks for manpages under old names. + man1files="cpp g++ gcc gcov" + for man1file in $man1files ; do + ln -s $man1file-fsf-%type_num[gccver].1 %i/share/man/man1/$man1file-%type_num[gccver].1 + done + man1files="gfortran" + for man1file in $man1files ; do + ln -s $man1file-fsf-%type_num[gccver].1 %i/share/man/man1/$man1file.1 + done + + # Rename manpages with -fsf-%type_num[gccver] suffix and create symlinks to old names. + man7files="fsf-funding gfdl gpl" + for man7file in $man7files ; do + mv %i/share/man/man7/$man7file.7 %i/share/man/man7/$man7file-fsf-%type_num[gccver].7 + ln -s $man7file-fsf-%type_num[gccver].7 %i/share/man/man7/$man7file.7 + done + + # Add dir for installed info files, and link them to %i/share/info. + # the %i/lib/gcc%type_num[gccver]/info/* files will go into the -compiler package + # and the files in %i/share/info go into the main package, this allows + # the info files for specific compiler versions to be accessed with + # e.g. `info -d /fink_install_dir/lib/gcc%type_num[gccver]/info gcc', but the "main" info files will + # be available for the install gccXX package in %p/share/info, as usual + install -d -m 755 %i/share/info + for infofile in $(find %i/lib/gcc%type_num[gccver]/info -name '*.info*'); do + infobase=$(basename $infofile) + case $infofile in + *info) %p/bin/install-info --infodir=%i/lib/gcc%type_num[gccver]/info ${infofile} ;; + esac + ln -s %p/lib/gcc%type_num[gccver]/info/$infobase %i/share/info/$infobase + done + + # remove build path from .la files + perl -pi -e "s, \-L[^ ']*/%n-%v-%r/darwin_objdir/[^ ']*,,g" `find %i/lib/gcc%type_num[gccver]/lib -name '*.la'` + if [ "%m" = "arm64" ]; then + arch=aarch64 + else + arch=%m + fi + + # @rpath install_names are required for aarch64 build, but break some linked binaries + # - enforce actual install paths here; take care to update the cross-referenced dylibs. + cd %d + for dylib in .%p/lib/gcc%type_num[gccver]/lib/lib*.[0-9].dylib; do + install_name_tool -id ${dylib#.} $dylib + install_name_tool -change @rpath/libgcc_s.1.1.dylib %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib \ + -change @rpath/libstdc++.6.dylib %p/lib/gcc%type_num[gccver]/lib/libstdc++.6.dylib \ + -change @rpath/libquadmath.0.dylib %p/lib/gcc%type_num[gccver]/lib/libquadmath.0.dylib $dylib + done + otool -L .%p/lib/gcc%type_num[gccver]/lib/lib*.[0-9].dylib | grep '@rpath' && exit 2 + + cp %b/gcc/config/darwin-sections.def %i/lib/gcc%type_num[gccver]/lib/gcc/${arch}-apple-darwin${darwinvers}/%v/plugin/include/config +<< +SplitOff: << + Package: %N-shlibs + Replaces: << + gcc4 (<= 20050130-4), + gfortran-shlibs + << + Provides: << + gfortran-shlibs + << + Description: Shared libraries for %N + DocFiles: gcc/COPYING gcc/COPYING.LIB + Files: << + lib/gcc%type_num[gccver]/lib/libgfortran.5*.dylib + lib/gcc%type_num[gccver]/lib/libstdc++.6*.dylib + lib/gcc%type_num[gccver]/lib/libgcc_s.1*.dylib + lib/gcc%type_num[gccver]/lib/libitm.1*.dylib + lib/gcc%type_num[gccver]/lib/libssp.0*.dylib + lib/gcc%type_num[gccver]/lib/libobjc-gnu.4*.dylib + lib/gcc%type_num[gccver]/lib/libgomp.1*.dylib + lib/gcc%type_num[gccver]/lib/libquadmath.0*.dylib + lib/gcc%type_num[gccver]/lib/libatomic.1*.dylib + << + Shlibs: << + %p/lib/gcc%type_num[gccver]/lib/libgfortran.5.dylib 6.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libstdc++.6.dylib 7.0.0 %n (>= 13.1.0-1) + ( "%m" = "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib 1.0.0 %n (>= 13.1.0-1) + ( "%m" != "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.dylib 1.0.0 %n (>= 13.1.0-1) + ( "%m" != "arm64" ) !%p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib + %p/lib/gcc%type_num[gccver]/lib/libitm.1.dylib 2.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libssp.0.dylib 1.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libobjc-gnu.4.dylib 5.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libgomp.1.dylib 2.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libquadmath.0.dylib 1.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libatomic.1.dylib 4.0.0 %n (>= 13.1.0-1) + << +<< +SplitOff2: << + Package: %N-compiler + Depends: << + gmp5-shlibs (>= 6.1.2-1), + isl22-shlibs, + libgettext8-shlibs, + libgmpxx5-shlibs (>= 6.1.2-1), + libiconv, + libmpc3-shlibs (>= 1.0.3-1), + libmpfr6-shlibs, + %N-shlibs (= %v-%r) + << + BuildDependsOnly: False + Description: Compiler Binaries for gcc%type_num[gccver] + DocFiles: gcc/COPYING gcc/COPYING.LIB gcc/ChangeLog gcc/ABOUT-GCC-NLS gcc/README.Portability + Files: << + bin/*-fsf-%type_num[gccver] + lib/gcc%type_num[gccver] + share/man/man1/*-fsf-%type_num[gccver].1 + share/man/man7/*-fsf-%type_num[gccver].7 + << +<< +License: GPL +Description: GNU Compiler Collection Version %type_num[gccver] +DescDetail: << + GCC, the GNU Compiler Collection, includes front ends for + C, C++, Objective-C, Objective-C++, Fortran and Ada. + . + C, C++, Objective C and Fortran are included in this package. + . + The C and C++ compilers are named gcc-13 and g++-13 to avoid + conflicts with gcc and g++ installed by the Apple Developer Tools. +<< +DescPackaging: << + Build with -fsf-%type_num[gccver] suffix and place non-overlapping files into new gcc%type_num[gccver]-compiler + package which can co-exist with other gccXX-compiler packages. Overlapping files + are left in main gcc%type_num[gccver] package which still conflicts with other gccXX packages. + + macOS10.14 no longer supports building 32bit libraries, so must disable multilib. + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87030 + + We use --with-sysroot to find the hidden system-headers in case /usr/include is not + populated. Ideally want --with-build-sysroot because we only need the headers to build + gcc and that should not impact the end product, but then anything using gccX will + need to add it's own -isysroot flag. + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79885 + + Homebrew patches for arm64/aarch64 build and macOS 13 from + https://github.com/Homebrew/formula-patches/blob/master/gcc/gcc-%v.diff + - libasan.* and libsubsan.* currently not built on darwin22+ - see + https://github.com/iains/gcc-darwin-arm64/commit/e722a1f4 + and missing from the 13.0-15.0 packages until resolved. + There are both "1" and "1.1" versions of libgcc_s.dylib now, but only "1.1" on arm64. + Manual fixes of @rpath install_names required for aarch64 build to maintain downstream + package compatibility. + + With Xcode 16 compilation of libgcc/config/aarch64/lse.S fails on a `STARTFN` macro with + 'non-private labels cannot appear between .cfi_startproc / .cfi_endproc pairs' + - no complete fix for this found in the 13.x branch, so I back-patched the entire file + from 14.2 + Homebrew (r2) patches to build on Sonoma and Sequoia; + addional commits from iains/gcc-13-branch as per + https://github.com/Homebrew/homebrew-core/blob/master/Formula/g/gcc@13.rb . +<< +Homepage: http://gcc.gnu.org/ +Maintainer: None +<< diff --git a/10.9-libcxx/stable/main/finkinfo/languages/gcc13.info b/10.9-libcxx/stable/main/finkinfo/languages/gcc13.info new file mode 100644 index 00000000000..6ea4ad4bf10 --- /dev/null +++ b/10.9-libcxx/stable/main/finkinfo/languages/gcc13.info @@ -0,0 +1,325 @@ +Info2: << +Package: gcc13 +Version: 13.3.0 +Revision: 2 +Type: gccver (13) +Distribution: 10.9, 10.10, 10.11, 10.12, 10.13, 10.14, 10.14.5, 10.15, 11.0, 11.3, 12.0 +Source: mirror:gnu:gcc/gcc-%v/gcc-%v.tar.xz +Source-Checksum: SHA256(0845e9621c9543a13f484e94584a49ffc0129970e9914624235fc1d061a0c083) +PatchFile: %n.patch +PatchFile-MD5: 05ab738b7d4a29348173e1f746d40b9e +PatchScript: << + #!/bin/sh -ev + patch -p1 < %{PatchFile} + # don't update live infodoc dir + find . -name Makefile.in | xargs perl -pi -e 's/install-info --version/false/g' +<< +NoSetCPPFLAGS: True +NoSetLDFLAGS: True +UseMaxBuildJobs: True +Conflicts: << + gcc5, gcc6, gcc7, gcc8, + gcc9, + gcc10, + gcc11, + gcc12, + gcc13, + gcc14 +<< +Replaces: << + gcc5, gcc6, gcc7, gcc8, + gcc9, + gcc10, + gcc11, + gcc12, + gcc13, + gcc14 +<< +Depends: << + %N-compiler (= %v-%r) +<< +BuildDepends: << + fink (>= 0.32), + fink-package-precedence, + gettext-tools, + gmp5 (>= 6.1.2-1), + install-info, + isl22, + libgettext8-dev, + libiconv-dev, + libmpc3 (>= 1.0.3-1), + libmpfr6, + x11-dev, + ( "%m" = "arm64" ) xcode (>= 14.2.0) +<< +ConfigureParams: << + --prefix=%p/lib/gcc%type_num[gccver] \ + --mandir=%p/share/man \ + --infodir=%p/lib/gcc%type_num[gccver]/info \ + --enable-languages=c,c++,fortran,lto,objc,obj-c++ \ + --with-gmp=%p \ + --with-libiconv-prefix=%p \ + --with-isl=%p \ + --with-mpc=%p \ + --with-system-zlib \ + --program-suffix=-fsf-%type_num[gccver] \ + --disable-multilib \ + --enable-stage1-checking \ + ${USE_SYSROOT} \ + --with-pkgversion="Fink %n %v-%r" \ + --with-bugurl="https://github.com/fink/fink-distributions/issues" +<< +InfoTest: << + TestDepends: << + autogen, + dejagnu, + ( "%m" != "arm64" ) apple-gdb + << + TestScript: << + #!/bin/bash -ev + if [ "%m" = "arm64" ]; then + echo "The gcc testsuite requires Apple's gdb, which is not available on this architecture." + exit 0 + elif [ $UID = 0 ]; then + if [ -e /usr/bin/csrutil && `csrutil status | grep -c disabled` ]; then + cd ../darwin_objdir; make -k check RUNTESTFLAGS="--target_board=unix'{-m64}'" || : + else + echo "The gcc testsuite must be run with SIP disabled or package installed." + exit 0 + fi + else + echo "The gcc testsuite must be run as root due to its use of gdb." + exit 0 + fi + << +<< +InfoDocs: gcc.info gfortran.info cpp.info gccinstall.info libgomp.info cppinternals.info gccint.info +CompileScript: << + #!/bin/bash -ev + set +x + if [ -e /usr/local/lib/libgmp.a ] || [ -e /usr/local/lib/libgmp.dylib ]; then + echo "-----WARNING-----WARNING-----WARNING-----" + echo "You seem to have GMP installed in /usr/local." + echo "This is known to cause %N to fail to build." + echo "Please move aside /usr/local and try again." + echo "-----WARNING-----WARNING-----WARNING-----" + exit 1 + else + echo "Good, /usr/local/lib/libgmp* not present." + fi + set -x + ulimit -s `ulimit -s` + mkdir ../darwin_objdir + cd ../darwin_objdir + # build doesn't play well with GNU-make + # unsupported option '-static-libgcc' + export MAKE=/usr/bin/make + # Only need sysroot on 10.14+ because /usr/include has been removed + OSX_MAJOR_VERSION=`sw_vers -productVersion | cut -d. -f1-2` + if dpkg --compare-versions "$OSX_MAJOR_VERSION" ge "10.14"; then + # Get the unversioned SDK path + SDK_PATH=`dirname $(xcrun --sdk macosx --show-sdk-path)`/MacOSX.sdk + # This should really be --with-build-sysroot but that's not getting propagated through the entire build process. + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79885 + export USE_SYSROOT="--with-sysroot=${SDK_PATH}" + fi + # check for incompatible clang ( 6.0 << bad-clang << 7.2) + clangvers=`clang --version | cut -d\ -f4` + $(`dpkg --compare-versions $clangvers '>>' 6.0`) && $(`dpkg --compare-versions $clangvers '<<' 7.2`) && clangcheck='y' + if [ "$clangcheck" = "y" ]; then + ../gcc-%v/configure %c --with-build-config=bootstrap-debug + else + ../gcc-%v/configure %c + fi + # Use bootstrap-lean to reduce disk usage. + # Note that this causes plugin testsuite failures + # since the plugin headers must come from prev-gcc. + # make bootstrap-lean + make bootstrap + fink-package-precedence --prohibit-bdep=%n . +<< +InstallScript: << + #!/bin/sh -ev + darwinvers=`uname -r` + cd ../darwin_objdir + make -j 1 install DESTDIR=%d + mkdir -p %i/bin + + # Add symlinks to recreate previous naming of executables in %p/bin + # as well as %p/lib/gcc%type_num[gccver]/bin and new -fsf-%type_num[gccver] naming in %p/bin. + binfiles="gcc g++ c++ cpp gcov" + for binfile in $binfiles ; do + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/$binfile-%type_num[gccver] + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-%type_num[gccver] + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-fsf-%type_num[gccver] + done + binfiles="gfortran" + for binfile in $binfiles ; do + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/$binfile + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-fsf-%type_num[gccver] + done + + # Remove unsupported executables + binfiles="gcc-ar gcc-nm gcc-ranlib" + for binfile in $binfiles ; do + rm -f %i/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/*-apple-darwin${darwinvers}-$binfile-fsf-%type_num[gccver] + done + + # Add symlinks for manpages under old names. + man1files="cpp g++ gcc gcov" + for man1file in $man1files ; do + ln -s $man1file-fsf-%type_num[gccver].1 %i/share/man/man1/$man1file-%type_num[gccver].1 + done + man1files="gfortran" + for man1file in $man1files ; do + ln -s $man1file-fsf-%type_num[gccver].1 %i/share/man/man1/$man1file.1 + done + + # Rename manpages with -fsf-%type_num[gccver] suffix and create symlinks to old names. + man7files="fsf-funding gfdl gpl" + for man7file in $man7files ; do + mv %i/share/man/man7/$man7file.7 %i/share/man/man7/$man7file-fsf-%type_num[gccver].7 + ln -s $man7file-fsf-%type_num[gccver].7 %i/share/man/man7/$man7file.7 + done + + # Add dir for installed info files, and link them to %i/share/info. + # the %i/lib/gcc%type_num[gccver]/info/* files will go into the -compiler package + # and the files in %i/share/info go into the main package, this allows + # the info files for specific compiler versions to be accessed with + # e.g. `info -d /fink_install_dir/lib/gcc%type_num[gccver]/info gcc', but the "main" info files will + # be available for the install gccXX package in %p/share/info, as usual + install -d -m 755 %i/share/info + for infofile in $(find %i/lib/gcc%type_num[gccver]/info -name '*.info*'); do + infobase=$(basename $infofile) + case $infofile in + *info) %p/bin/install-info --infodir=%i/lib/gcc%type_num[gccver]/info ${infofile} ;; + esac + ln -s %p/lib/gcc%type_num[gccver]/info/$infobase %i/share/info/$infobase + done + + # remove build path from .la files + perl -pi -e "s, \-L[^ ']*/%n-%v-%r/darwin_objdir/[^ ']*,,g" `find %i/lib/gcc%type_num[gccver]/lib -name '*.la'` + if [ "%m" = "arm64" ]; then + arch=aarch64 + else + arch=%m + fi + + # @rpath install_names are required for aarch64 build, but break some linked binaries + # - enforce actual install paths here; take care to update the cross-referenced dylibs. + cd %d + for dylib in .%p/lib/gcc%type_num[gccver]/lib/lib*.[0-9].dylib; do + install_name_tool -id ${dylib#.} $dylib + install_name_tool -change @rpath/libgcc_s.1.1.dylib %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib \ + -change @rpath/libstdc++.6.dylib %p/lib/gcc%type_num[gccver]/lib/libstdc++.6.dylib \ + -change @rpath/libquadmath.0.dylib %p/lib/gcc%type_num[gccver]/lib/libquadmath.0.dylib $dylib + done + otool -L .%p/lib/gcc%type_num[gccver]/lib/lib*.[0-9].dylib | grep '@rpath' && exit 2 + + cp %b/gcc/config/darwin-sections.def %i/lib/gcc%type_num[gccver]/lib/gcc/${arch}-apple-darwin${darwinvers}/%v/plugin/include/config +<< +SplitOff: << + Package: %N-shlibs + Replaces: << + gcc4 (<= 20050130-4), + gfortran-shlibs + << + Provides: << + gfortran-shlibs + << + Description: Shared libraries for %N + DocFiles: gcc/COPYING gcc/COPYING.LIB + Files: << + lib/gcc%type_num[gccver]/lib/libgfortran.5*.dylib + lib/gcc%type_num[gccver]/lib/libstdc++.6*.dylib + lib/gcc%type_num[gccver]/lib/libgcc_s.1*.dylib + lib/gcc%type_num[gccver]/lib/libitm.1*.dylib + lib/gcc%type_num[gccver]/lib/libssp.0*.dylib + lib/gcc%type_num[gccver]/lib/libobjc-gnu.4*.dylib + lib/gcc%type_num[gccver]/lib/libgomp.1*.dylib + lib/gcc%type_num[gccver]/lib/libquadmath.0*.dylib + lib/gcc%type_num[gccver]/lib/libatomic.1*.dylib + lib/gcc%type_num[gccver]/lib/libasan.8*.dylib + lib/gcc%type_num[gccver]/lib/libubsan.1*.dylib + << + Shlibs: << + %p/lib/gcc%type_num[gccver]/lib/libgfortran.5.dylib 6.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libstdc++.6.dylib 7.0.0 %n (>= 13.1.0-1) + ( "%m" = "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib 1.0.0 %n (>= 13.1.0-1) + ( "%m" != "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.dylib 1.0.0 %n (>= 13.1.0-1) + ( "%m" != "arm64" ) !%p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib + %p/lib/gcc%type_num[gccver]/lib/libitm.1.dylib 2.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libssp.0.dylib 1.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libobjc-gnu.4.dylib 5.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libgomp.1.dylib 2.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libquadmath.0.dylib 1.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libatomic.1.dylib 4.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libasan.8.dylib 9.0.0 %n (>= 13.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libubsan.1.dylib 2.0.0 %n (>= 13.1.0-1) + << +<< +SplitOff2: << + Package: %N-compiler + Depends: << + gmp5-shlibs (>= 6.1.2-1), + isl22-shlibs, + libgettext8-shlibs, + libgmpxx5-shlibs (>= 6.1.2-1), + libiconv, + libmpc3-shlibs (>= 1.0.3-1), + libmpfr6-shlibs, + %N-shlibs (= %v-%r) + << + BuildDependsOnly: False + Description: Compiler Binaries for gcc%type_num[gccver] + DocFiles: gcc/COPYING gcc/COPYING.LIB gcc/ChangeLog gcc/ABOUT-GCC-NLS gcc/README.Portability + Files: << + bin/*-fsf-%type_num[gccver] + lib/gcc%type_num[gccver] + share/man/man1/*-fsf-%type_num[gccver].1 + share/man/man7/*-fsf-%type_num[gccver].7 + << +<< +License: GPL +Description: GNU Compiler Collection Version %type_num[gccver] +DescDetail: << + GCC, the GNU Compiler Collection, includes front ends for + C, C++, Objective-C, Objective-C++, Fortran and Ada. + . + C, C++, Objective C and Fortran are included in this package. + . + The C and C++ compilers are named gcc-13 and g++-13 to avoid + conflicts with gcc and g++ installed by the Apple Developer Tools. +<< +DescPackaging: << + Build with -fsf-%type_num[gccver] suffix and place non-overlapping files into new gcc%type_num[gccver]-compiler + package which can co-exist with other gccXX-compiler packages. Overlapping files + are left in main gcc%type_num[gccver] package which still conflicts with other gccXX packages. + + macOS10.14 no longer supports building 32bit libraries, so must disable multilib. + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87030 + + We use --with-sysroot to find the hidden system-headers in case /usr/include is not + populated. Ideally want --with-build-sysroot because we only need the headers to build + gcc and that should not impact the end product, but then anything using gccX will + need to add it's own -isysroot flag. + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79885 + + Homebrew patches for arm64/aarch64 build and macOS 13 from + https://github.com/Homebrew/formula-patches/blob/master/gcc/gcc-%v.diff + - experimental libasan.* and libsubsan.* build on arm64, requires XCode 14.2. + There are both "1" and "1.1" versions of libgcc_s.dylib now, but only "1.1" on arm64. + Manual fixes of @rpath install_names required for aarch64 build to maintain downstream + package compatibility. + + With Xcode 16 compilation of libgcc/config/aarch64/lse.S fails on a `STARTFN` macro with + 'non-private labels cannot appear between .cfi_startproc / .cfi_endproc pairs' + - no complete fix for this found in the 13.x branch, so I back-patched the entire file + from 14.2 + Homebrew (r2) patches to build on Sonoma and Sequoia; + addional commits from iains/gcc-13-branch as per + https://github.com/Homebrew/homebrew-core/blob/master/Formula/g/gcc@13.rb . +<< +Homepage: http://gcc.gnu.org/ +Maintainer: None +<< diff --git a/10.9-libcxx/stable/main/finkinfo/languages/gcc13.patch b/10.9-libcxx/stable/main/finkinfo/languages/gcc13.patch new file mode 100644 index 00000000000..16630a923e3 --- /dev/null +++ b/10.9-libcxx/stable/main/finkinfo/languages/gcc13.patch @@ -0,0 +1,15141 @@ +diff --git a/Makefile.def b/Makefile.def +index 35e994eb77e..9b4a8a2bf7a 100644 +--- a/Makefile.def ++++ b/Makefile.def +@@ -47,7 +47,8 @@ host_modules= { module= fixincludes; bootstrap=true; + host_modules= { module= flex; no_check_cross= true; }; + host_modules= { module= gas; bootstrap=true; }; + host_modules= { module= gcc; bootstrap=true; +- extra_make_flags="$(EXTRA_GCC_FLAGS)"; }; ++ extra_make_flags="$(EXTRA_GCC_FLAGS)"; ++ extra_configure_flags='@gcc_host_pie@'; }; + host_modules= { module= gmp; lib_path=.libs; bootstrap=true; + // Work around in-tree gmp configure bug with missing flex. + extra_configure_flags='--disable-shared LEX="touch lex.yy.c" @host_libs_picflag@'; +diff --git a/Makefile.in b/Makefile.in +index 205d3c30bde..fdfd3d75593 100644 +--- a/Makefile.in ++++ b/Makefile.in +@@ -12016,7 +12016,7 @@ configure-gcc: + $$s/$$module_srcdir/configure \ + --srcdir=$${topdir}/$$module_srcdir \ + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ +- --target=${target_alias} \ ++ --target=${target_alias} @gcc_host_pie@ \ + || exit 1 + @endif gcc + +@@ -12051,7 +12051,8 @@ configure-stage1-gcc: + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ + --target=${target_alias} \ + \ +- $(STAGE1_CONFIGURE_FLAGS) ++ $(STAGE1_CONFIGURE_FLAGS) \ ++ @gcc_host_pie@ + @endif gcc-bootstrap + + .PHONY: configure-stage2-gcc maybe-configure-stage2-gcc +@@ -12084,7 +12085,8 @@ configure-stage2-gcc: + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ +- $(STAGE2_CONFIGURE_FLAGS) ++ $(STAGE2_CONFIGURE_FLAGS) \ ++ @gcc_host_pie@ + @endif gcc-bootstrap + + .PHONY: configure-stage3-gcc maybe-configure-stage3-gcc +@@ -12117,7 +12119,8 @@ configure-stage3-gcc: + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ +- $(STAGE3_CONFIGURE_FLAGS) ++ $(STAGE3_CONFIGURE_FLAGS) \ ++ @gcc_host_pie@ + @endif gcc-bootstrap + + .PHONY: configure-stage4-gcc maybe-configure-stage4-gcc +@@ -12150,7 +12153,8 @@ configure-stage4-gcc: + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ +- $(STAGE4_CONFIGURE_FLAGS) ++ $(STAGE4_CONFIGURE_FLAGS) \ ++ @gcc_host_pie@ + @endif gcc-bootstrap + + .PHONY: configure-stageprofile-gcc maybe-configure-stageprofile-gcc +@@ -12183,7 +12187,8 @@ configure-stageprofile-gcc: + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ +- $(STAGEprofile_CONFIGURE_FLAGS) ++ $(STAGEprofile_CONFIGURE_FLAGS) \ ++ @gcc_host_pie@ + @endif gcc-bootstrap + + .PHONY: configure-stagetrain-gcc maybe-configure-stagetrain-gcc +@@ -12216,7 +12221,8 @@ configure-stagetrain-gcc: + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ +- $(STAGEtrain_CONFIGURE_FLAGS) ++ $(STAGEtrain_CONFIGURE_FLAGS) \ ++ @gcc_host_pie@ + @endif gcc-bootstrap + + .PHONY: configure-stagefeedback-gcc maybe-configure-stagefeedback-gcc +@@ -12249,7 +12255,8 @@ configure-stagefeedback-gcc: + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ +- $(STAGEfeedback_CONFIGURE_FLAGS) ++ $(STAGEfeedback_CONFIGURE_FLAGS) \ ++ @gcc_host_pie@ + @endif gcc-bootstrap + + .PHONY: configure-stageautoprofile-gcc maybe-configure-stageautoprofile-gcc +@@ -12282,7 +12289,8 @@ configure-stageautoprofile-gcc: + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ +- $(STAGEautoprofile_CONFIGURE_FLAGS) ++ $(STAGEautoprofile_CONFIGURE_FLAGS) \ ++ @gcc_host_pie@ + @endif gcc-bootstrap + + .PHONY: configure-stageautofeedback-gcc maybe-configure-stageautofeedback-gcc +@@ -12315,7 +12323,8 @@ configure-stageautofeedback-gcc: + $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \ + --target=${target_alias} \ + --with-build-libsubdir=$(HOST_SUBDIR) \ +- $(STAGEautofeedback_CONFIGURE_FLAGS) ++ $(STAGEautofeedback_CONFIGURE_FLAGS) \ ++ @gcc_host_pie@ + @endif gcc-bootstrap + + +diff --git a/c++tools/Makefile.in b/c++tools/Makefile.in +index 77bda3d56dc..dcb1029e064 100644 +--- a/c++tools/Makefile.in ++++ b/c++tools/Makefile.in +@@ -29,8 +29,9 @@ AUTOCONF := @AUTOCONF@ + AUTOHEADER := @AUTOHEADER@ + CXX := @CXX@ + CXXFLAGS := @CXXFLAGS@ +-PIEFLAG := @PIEFLAG@ +-CXXOPTS := $(CXXFLAGS) $(PIEFLAG) -fno-exceptions -fno-rtti ++PICFLAG := @PICFLAG@ ++LD_PICFLAG := @LD_PICFLAG@ ++CXXOPTS := $(CXXFLAGS) $(PICFLAG) -fno-exceptions -fno-rtti + LDFLAGS := @LDFLAGS@ + exeext := @EXEEXT@ + LIBIBERTY := ../libiberty/libiberty.a +@@ -90,11 +91,15 @@ ifeq (@CXX_AUX_TOOLS@,yes) + + all::g++-mapper-server$(exeext) + ++ifneq ($(PICFLAG),) ++override LIBIBERTY := ../libiberty/pic/libiberty.a ++endif ++ + MAPPER.O := server.o resolver.o + CODYLIB = ../libcody/libcody.a + CXXINC += -I$(srcdir)/../libcody -I$(srcdir)/../include -I$(srcdir)/../gcc -I. -I../gcc + g++-mapper-server$(exeext): $(MAPPER.O) $(CODYLIB) +- +$(CXX) $(LDFLAGS) $(PIEFLAG) -o $@ $^ $(LIBIBERTY) $(NETLIBS) ++ +$(CXX) $(LDFLAGS) $(PICFLAG) $(LD_PICFLAG) -o $@ $^ $(LIBIBERTY) $(NETLIBS) + + # copy to gcc dir so tests there can run + all::../gcc/g++-mapper-server$(exeext) +diff --git a/c++tools/configure b/c++tools/configure +index 742816e4253..88087009383 100755 +--- a/c++tools/configure ++++ b/c++tools/configure +@@ -627,7 +627,8 @@ get_gcc_base_ver + EGREP + GREP + CXXCPP +-PIEFLAG ++LD_PICFLAG ++PICFLAG + MAINTAINER + CXX_AUX_TOOLS + AUTOHEADER +@@ -700,6 +701,7 @@ enable_c___tools + enable_maintainer_mode + enable_checking + enable_default_pie ++enable_host_pie + with_gcc_major_version_only + ' + ac_precious_vars='build_alias +@@ -1333,6 +1335,7 @@ Optional Features: + only specific categories of checks. Categories are: + yes,no,all,none,release. + --enable-default-pie enable Position Independent Executable as default ++ --enable-host-pie build host code as PIE + + Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] +@@ -2990,12 +2993,20 @@ fi + # Check whether --enable-default-pie was given. + # Check whether --enable-default-pie was given. + if test "${enable_default_pie+set}" = set; then : +- enableval=$enable_default_pie; PIEFLAG=-fPIE ++ enableval=$enable_default_pie; PICFLAG=-fPIE + else +- PIEFLAG= ++ PICFLAG= + fi + + ++# Enable --enable-host-pie ++# Check whether --enable-host-pie was given. ++if test "${enable_host_pie+set}" = set; then : ++ enableval=$enable_host_pie; PICFLAG=-fPIE; LD_PICFLAG=-pie ++fi ++ ++ ++ + + # Check if O_CLOEXEC is defined by fcntl + +diff --git a/c++tools/configure.ac b/c++tools/configure.ac +index 23e98c8e721..44dfaccbbfa 100644 +--- a/c++tools/configure.ac ++++ b/c++tools/configure.ac +@@ -102,8 +102,15 @@ fi + AC_ARG_ENABLE(default-pie, + [AS_HELP_STRING([--enable-default-pie], + [enable Position Independent Executable as default])], +-[PIEFLAG=-fPIE], [PIEFLAG=]) +-AC_SUBST([PIEFLAG]) ++[PICFLAG=-fPIE], [PICFLAG=]) ++ ++# Enable --enable-host-pie ++AC_ARG_ENABLE(host-pie, ++[AS_HELP_STRING([--enable-host-pie], ++ [build host code as PIE])], ++[PICFLAG=-fPIE; LD_PICFLAG=-pie], []) ++AC_SUBST(PICFLAG) ++AC_SUBST(LD_PICFLAG) + + # Check if O_CLOEXEC is defined by fcntl + AC_CACHE_CHECK(for O_CLOEXEC, ac_cv_o_cloexec, [ +diff --git a/configure b/configure +index 117a7ef23f2..c721ee4b5b2 100755 +--- a/configure ++++ b/configure +@@ -687,7 +687,10 @@ extra_host_zlib_configure_flags + extra_host_libiberty_configure_flags + stage1_languages + host_libs_picflag ++PICFLAG + host_shared ++gcc_host_pie ++host_pie + extra_linker_plugin_flags + extra_linker_plugin_configure_flags + islinc +@@ -830,6 +833,7 @@ enable_isl_version_check + enable_lto + enable_linker_plugin_configure_flags + enable_linker_plugin_flags ++enable_host_pie + enable_host_shared + enable_stage1_languages + enable_objc_gc +@@ -1558,6 +1562,7 @@ Optional Features: + --enable-linker-plugin-flags=FLAGS + additional flags for configuring and building linker + plugins [none] ++ --enable-host-pie build position independent host executables + --enable-host-shared build host code as shared libraries + --enable-stage1-languages[=all] + choose additional languages to build during stage1. +@@ -3451,6 +3456,8 @@ esac + + # Disable libffi for some systems. + case "${target}" in ++ aarch64*-*-darwin2*) ++ ;; + powerpc-*-darwin*) + ;; + i[3456789]86-*-darwin*) +@@ -8414,6 +8421,20 @@ else + fi + fi + ++case $target in ++ *-darwin2* | *-darwin1[56789]*) ++ # For these versions, we default to using embedded rpaths. ++ if test "x$enable_darwin_at_rpath" != "xno"; then ++ poststage1_ldflags="$poststage1_ldflags -nodefaultrpaths" ++ fi ++ ;; ++ *-darwin*) ++ # For these versions, we only use embedded rpaths on demand. ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ poststage1_ldflags="$poststage1_ldflags -nodefaultrpaths" ++ fi ++ ;; ++esac + + + # GCC GRAPHITE dependency isl. +@@ -8645,6 +8666,39 @@ fi + + + ++# Handle --enable-host-pie ++# If host PIE executables are the default (or must be forced on) for some host, ++# we must pass that configuration to the gcc directory. ++gcc_host_pie= ++# Check whether --enable-host-pie was given. ++if test "${enable_host_pie+set}" = set; then : ++ enableval=$enable_host_pie; host_pie=$enableval ++ case $host in ++ *-*-darwin2*) ++ if test x$host_pie != xyes ; then ++ # for Darwin20+ this is required. ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: PIE executables are required for the configured host, host-pie setting ignored." >&5 ++$as_echo "$as_me: WARNING: PIE executables are required for the configured host, host-pie setting ignored." >&2;} ++ host_pie=yes ++ gcc_host_pie=--enable-host-pie ++ fi ;; ++ *) ;; ++ esac ++else ++ case $host in ++ *-*-darwin2*) ++ # Default to PIE (mandatory for aarch64). ++ host_pie=yes ++ gcc_host_pie=--enable-host-pie ++ ;; ++ *) host_pie=no ;; ++ esac ++fi ++ ++ ++ ++ ++ + # Enable --enable-host-shared. + # Checked early to determine whether jit is an 'all' language + # Check whether --enable-host-shared was given. +@@ -8654,26 +8708,57 @@ if test "${enable_host_shared+set}" = set; then : + x86_64-*-darwin* | aarch64-*-darwin*) + if test x$host_shared != xyes ; then + # PIC is the default, and actually cannot be switched off. +- echo configure.ac: warning: PIC code is required for the configured target, host-shared setting ignored. 1>&2 ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: PIC code is required for the configured host; host-shared setting ignored." >&5 ++$as_echo "$as_me: WARNING: PIC code is required for the configured host; host-shared setting ignored." >&2;} ++ host_shared=yes ++ fi ;; ++ *-*-darwin*) ++ if test x$host_pie = xyes -a x$host_shared != xyes ; then ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: PIC code is required for PIE host executables host-shared setting ignored." >&5 ++$as_echo "$as_me: WARNING: PIC code is required for PIE host executables host-shared setting ignored." >&2;} + host_shared=yes + fi ;; + *) ;; + esac + else + case $host in ++ # 64B x86_64 and Aarch64 Darwin default to PIC. + x86_64-*-darwin* | aarch64-*-darwin*) host_shared=yes ;; +- *) host_shared=no ;; ++ # 32B and powerpc64 Darwin must use PIC to link PIE exes. ++ *-*-darwin*) host_shared=$host_pie ;; ++ *) host_shared=no;; + esac + fi + + + + ++if test x$host_shared = xyes; then ++ case $host in ++ *-*-darwin*) ++ # Since host shared is the default for 64b Darwin, and also enabled for ++ # host_pie, ensure that we present the PIE flag when host_pie is active. ++ if test x$host_pie = xyes; then ++ PICFLAG=-fPIE ++ fi ++ ;; ++ *) ++ PICFLAG=-fPIC ++ ;; ++ esac ++elif test x$host_pie = xyes; then ++ PICFLAG=-fPIE ++else ++ PICFLAG= ++fi ++ ++ ++ + # If we are building PIC/PIE host executables, and we are building dependent + # libs (e.g. GMP) in-tree those libs need to be configured to generate PIC + # code. + host_libs_picflag= +-if test "$host_shared" = "yes";then ++if test "$host_shared" = "yes" -o "$host_pie" = "yes"; then + host_libs_picflag='--with-pic' + fi + +diff --git a/configure.ac b/configure.ac +index b3e9bbd2aa5..a75c9e8850c 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -710,6 +710,8 @@ esac + + # Disable libffi for some systems. + case "${target}" in ++ aarch64*-*-darwin2*) ++ ;; + powerpc-*-darwin*) + ;; + i[[3456789]]86-*-darwin*) +@@ -1806,6 +1808,20 @@ AC_ARG_WITH(boot-ldflags, + if test "$poststage1_libs" = ""; then + poststage1_ldflags="-static-libstdc++ -static-libgcc" + fi]) ++case $target in ++ *-darwin2* | *-darwin1[[56789]]*) ++ # For these versions, we default to using embedded rpaths. ++ if test "x$enable_darwin_at_rpath" != "xno"; then ++ poststage1_ldflags="$poststage1_ldflags -nodefaultrpaths" ++ fi ++ ;; ++ *-darwin*) ++ # For these versions, we only use embedded rpaths on demand. ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ poststage1_ldflags="$poststage1_ldflags -nodefaultrpaths" ++ fi ++ ;; ++esac + AC_SUBST(poststage1_ldflags) + + # GCC GRAPHITE dependency isl. +@@ -1891,6 +1907,36 @@ AC_ARG_ENABLE(linker-plugin-flags, + extra_linker_plugin_flags=) + AC_SUBST(extra_linker_plugin_flags) + ++# Handle --enable-host-pie ++# If host PIE executables are the default (or must be forced on) for some host, ++# we must pass that configuration to the gcc directory. ++gcc_host_pie= ++AC_ARG_ENABLE(host-pie, ++[AS_HELP_STRING([--enable-host-pie], ++ [build position independent host executables])], ++[host_pie=$enableval ++ case $host in ++ *-*-darwin2*) ++ if test x$host_pie != xyes ; then ++ # for Darwin20+ this is required. ++ AC_MSG_WARN([PIE executables are required for the configured host, host-pie setting ignored.]) ++ host_pie=yes ++ gcc_host_pie=--enable-host-pie ++ fi ;; ++ *) ;; ++ esac], ++[case $host in ++ *-*-darwin2*) ++ # Default to PIE (mandatory for aarch64). ++ host_pie=yes ++ gcc_host_pie=--enable-host-pie ++ ;; ++ *) host_pie=no ;; ++ esac]) ++ ++AC_SUBST(host_pie) ++AC_SUBST(gcc_host_pie) ++ + # Enable --enable-host-shared. + # Checked early to determine whether jit is an 'all' language + AC_ARG_ENABLE(host-shared, +@@ -1901,23 +1947,52 @@ AC_ARG_ENABLE(host-shared, + x86_64-*-darwin* | aarch64-*-darwin*) + if test x$host_shared != xyes ; then + # PIC is the default, and actually cannot be switched off. +- echo configure.ac: warning: PIC code is required for the configured target, host-shared setting ignored. 1>&2 ++ AC_MSG_WARN([PIC code is required for the configured host; host-shared setting ignored.]) ++ host_shared=yes ++ fi ;; ++ *-*-darwin*) ++ if test x$host_pie = xyes -a x$host_shared != xyes ; then ++ AC_MSG_WARN([PIC code is required for PIE host executables host-shared setting ignored.]) + host_shared=yes + fi ;; + *) ;; + esac], + [case $host in ++ # 64B x86_64 and Aarch64 Darwin default to PIC. + x86_64-*-darwin* | aarch64-*-darwin*) host_shared=yes ;; +- *) host_shared=no ;; ++ # 32B and powerpc64 Darwin must use PIC to link PIE exes. ++ *-*-darwin*) host_shared=$host_pie ;; ++ *) host_shared=no;; + esac]) + + AC_SUBST(host_shared) + ++if test x$host_shared = xyes; then ++ case $host in ++ *-*-darwin*) ++ # Since host shared is the default for 64b Darwin, and also enabled for ++ # host_pie, ensure that we present the PIE flag when host_pie is active. ++ if test x$host_pie = xyes; then ++ PICFLAG=-fPIE ++ fi ++ ;; ++ *) ++ PICFLAG=-fPIC ++ ;; ++ esac ++elif test x$host_pie = xyes; then ++ PICFLAG=-fPIE ++else ++ PICFLAG= ++fi ++ ++AC_SUBST(PICFLAG) ++ + # If we are building PIC/PIE host executables, and we are building dependent + # libs (e.g. GMP) in-tree those libs need to be configured to generate PIC + # code. + host_libs_picflag= +-if test "$host_shared" = "yes";then ++if test "$host_shared" = "yes" -o "$host_pie" = "yes"; then + host_libs_picflag='--with-pic' + fi + AC_SUBST(host_libs_picflag) +diff --git a/fixincludes/Makefile.in b/fixincludes/Makefile.in +index 1937dcaa32d..e6ce41dba39 100644 +--- a/fixincludes/Makefile.in ++++ b/fixincludes/Makefile.in +@@ -73,7 +73,7 @@ default : all + # Now figure out from those variables how to compile and link. + + .c.o: +- $(CC) -c $(CFLAGS) $(WARN_CFLAGS) $(CPPFLAGS) $(FIXINC_CFLAGS) $< ++ $(CC) -c $(CFLAGS) $(PICFLAG) $(WARN_CFLAGS) $(CPPFLAGS) $(FIXINC_CFLAGS) $< + + # The only suffixes we want for implicit rules are .c and .o. + .SUFFIXES: +@@ -87,7 +87,11 @@ default : all + ## + ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + ++ifeq ($(PICFLAG),) + LIBIBERTY=../libiberty/libiberty.a ++else ++LIBIBERTY=../libiberty/pic/libiberty.a ++endif + + ALLOBJ = fixincl.o fixtests.o fixfixes.o server.o procopen.o \ + fixlib.o fixopts.o +@@ -107,15 +111,15 @@ oneprocess : full-stamp + twoprocess : test-stamp $(AF) + + full-stamp : $(ALLOBJ) $(LIBIBERTY) +- $(CC) $(CFLAGS) $(LDFLAGS) -o $(FI) $(ALLOBJ) $(LIBIBERTY) ++ $(CC) $(CFLAGS) $(PICFLAG) $(LDFLAGS) $(LD_PICFLAG) -o $(FI) $(ALLOBJ) $(LIBIBERTY) + $(STAMP) $@ + + test-stamp : $(TESTOBJ) $(LIBIBERTY) +- $(CC) $(CFLAGS) $(LDFLAGS) -o $(FI) $(TESTOBJ) $(LIBIBERTY) ++ $(CC) $(CFLAGS) $(PICFLAG) $(LDFLAGS) $(LD_PICFLAG) -o $(FI) $(TESTOBJ) $(LIBIBERTY) + $(STAMP) $@ + + $(AF): $(FIXOBJ) $(LIBIBERTY) +- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(FIXOBJ) $(LIBIBERTY) ++ $(CC) $(CFLAGS) $(PICFLAG) $(LDFLAGS) $(LD_PICFLAG) -o $@ $(FIXOBJ) $(LIBIBERTY) + + $(ALLOBJ) : $(HDR) + fixincl.o : fixincl.c $(srcdir)/fixincl.x +diff --git a/fixincludes/configure b/fixincludes/configure +index bdcc41f6ddc..b2759ee3b98 100755 +--- a/fixincludes/configure ++++ b/fixincludes/configure +@@ -623,6 +623,8 @@ ac_subst_vars='LTLIBOBJS + LIBOBJS + get_gcc_base_ver + MAINT ++LD_PICFLAG ++PICFLAG + TARGET + target_noncanonical + WERROR +@@ -695,6 +697,7 @@ enable_option_checking + enable_werror_always + with_local_prefix + enable_twoprocess ++enable_host_pie + enable_maintainer_mode + with_gcc_major_version_only + ' +@@ -1323,6 +1326,7 @@ Optional Features: + --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + --enable-werror-always enable -Werror despite compiler version + --enable-twoprocess Use a separate process to apply the fixes ++ --enable-host-pie build host code as PIE + --enable-maintainer-mode enable make rules and dependencies not useful + (and sometimes confusing) to the casual installer + +@@ -3044,7 +3048,6 @@ ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. + # the compiler configuration to `libtool'. + # _LT_LANG_CXX_CONFIG + +- + # _LT_SYS_HIDDEN_LIBDEPS([TAGNAME]) + # --------------------------------- + # Figure out "hidden" library dependencies from verbose +@@ -4835,6 +4838,15 @@ $as_echo "#define SEPARATE_FIX_PROC 1" >>confdefs.h + + fi + ++# Enable --enable-host-pie. ++# Check whether --enable-host-pie was given. ++if test "${enable_host_pie+set}" = set; then : ++ enableval=$enable_host_pie; PICFLAG=-fPIE; LD_PICFLAG=-pie ++fi ++ ++ ++ ++ + case $host in + vax-dec-bsd* ) + +diff --git a/fixincludes/configure.ac b/fixincludes/configure.ac +index ef2227e3c93..4e78511d20f 100644 +--- a/fixincludes/configure.ac ++++ b/fixincludes/configure.ac +@@ -68,6 +68,14 @@ if test $TARGET = twoprocess; then + [Define if testing and fixing are done by separate process]) + fi + ++# Enable --enable-host-pie. ++AC_ARG_ENABLE(host-pie, ++[AS_HELP_STRING([--enable-host-pie], ++ [build host code as PIE])], ++[PICFLAG=-fPIE; LD_PICFLAG=-pie], []) ++AC_SUBST(PICFLAG) ++AC_SUBST(LD_PICFLAG) ++ + case $host in + vax-dec-bsd* ) + AC_DEFINE(exit, xexit, [Define to xexit if the host system does not support atexit]) +diff --git a/fixincludes/fixincl.x b/fixincludes/fixincl.x +index e52f11d8460..6c6f9e02902 100644 +--- a/fixincludes/fixincl.x ++++ b/fixincludes/fixincl.x +@@ -2,11 +2,11 @@ + * + * DO NOT EDIT THIS FILE (fixincl.x) + * +- * It has been AutoGen-ed December 11, 2023 at 02:50:24 PM by AutoGen 5.18.16 ++ * It has been AutoGen-ed October 6, 2024 at 07:10:01 PM by AutoGen 5.18.7 + * From the definitions inclhack.def + * and the template file fixincl + */ +-/* DO NOT SVN-MERGE THIS FILE, EITHER Mon Dec 11 14:50:24 CET 2023 ++/* DO NOT SVN-MERGE THIS FILE, EITHER Sun Oct 6 19:10:01 BST 2024 + * + * You must regenerate it. Use the ./genfixes script. + * +@@ -15,7 +15,7 @@ + * certain ANSI-incompatible system header files which are fixed to work + * correctly with ANSI C and placed in a directory that GNU C will search. + * +- * This file contains 274 fixup descriptions. ++ * This file contains 272 fixup descriptions. + * + * See README for more information. + * +@@ -267,56 +267,6 @@ static const char* apzAab_Darwin7_9_Long_Double_FuncsPatch[] = { + #endif /* __MATH__ */", + (char*)NULL }; + +-/* * * * * * * * * * * * * * * * * * * * * * * * * * +- * +- * Description of Darwin_Api_Availability fix +- */ +-tSCC zDarwin_Api_AvailabilityName[] = +- "darwin_api_availability"; +- +-/* +- * File name selection pattern +- */ +-tSCC zDarwin_Api_AvailabilityList[] = +- "os/availability.h\0"; +-/* +- * Machine/OS name selection pattern +- */ +-tSCC* apzDarwin_Api_AvailabilityMachs[] = { +- "*-*-darwin*", +- (const char*)NULL }; +- +-/* +- * content selection pattern - do fix if pattern found +- */ +-tSCC zDarwin_Api_AvailabilitySelect0[] = +- " *#define __API_AVAILABLE.*\n\ +- *#define __API_DEPRECATED.*\n\ +- *#define __API_DEPRECATED_WITH_REPLACEMENT.*\n\ +- *#define __API_UNAVAILABLE.*\n"; +- +-/* +- * content bypass pattern - skip fix if pattern found +- */ +-tSCC zDarwin_Api_AvailabilityBypass0[] = +- "__IPHONE_OS_VERSION_MIN_REQUIRED"; +- +-#define DARWIN_API_AVAILABILITY_TEST_CT 2 +-static tTestDesc aDarwin_Api_AvailabilityTests[] = { +- { TT_NEGREP, zDarwin_Api_AvailabilityBypass0, (regex_t*)NULL }, +- { TT_EGREP, zDarwin_Api_AvailabilitySelect0, (regex_t*)NULL }, }; +- +-/* +- * Fix Command Arguments for Darwin_Api_Availability +- */ +-static const char* apzDarwin_Api_AvailabilityPatch[] = { +- "format", +- " #define API_AVAILABLE(...)\n\ +- #define API_DEPRECATED(...)\n\ +- #define API_DEPRECATED_WITH_REPLACEMENT(...)\n\ +- #define API_UNAVAILABLE(...)\n", +- (char*)NULL }; +- + /* * * * * * * * * * * * * * * * * * * * * * * * * * + * + * Description of Aab_Fd_Zero_Asm_Posix_Types_H fix +@@ -2619,7 +2569,7 @@ tSCC zApple_Local_Stdio_Fn_DeprecationName[] = + * File name selection pattern + */ + tSCC zApple_Local_Stdio_Fn_DeprecationList[] = +- "stdio.h\0"; ++ "stdio.h\0_stdio.h\0"; + /* + * Machine/OS name selection pattern + */ +@@ -2763,51 +2713,6 @@ extern \"C\" {\n\ + #endif\n", + (char*)NULL }; + +-/* * * * * * * * * * * * * * * * * * * * * * * * * * +- * +- * Description of Darwin_Availabilityinternal fix +- */ +-tSCC zDarwin_AvailabilityinternalName[] = +- "darwin_availabilityinternal"; +- +-/* +- * File name selection pattern +- */ +-tSCC zDarwin_AvailabilityinternalList[] = +- "AvailabilityInternal.h\0"; +-/* +- * Machine/OS name selection pattern +- */ +-tSCC* apzDarwin_AvailabilityinternalMachs[] = { +- "*-*-darwin*", +- (const char*)NULL }; +- +-/* +- * content selection pattern - do fix if pattern found +- */ +-tSCC zDarwin_AvailabilityinternalSelect0[] = +- "#define[ \t]+(__API_[ADU]\\([^)]*\\)).*"; +- +-#define DARWIN_AVAILABILITYINTERNAL_TEST_CT 1 +-static tTestDesc aDarwin_AvailabilityinternalTests[] = { +- { TT_EGREP, zDarwin_AvailabilityinternalSelect0, (regex_t*)NULL }, }; +- +-/* +- * Fix Command Arguments for Darwin_Availabilityinternal +- */ +-static const char* apzDarwin_AvailabilityinternalPatch[] = { +- "format", +- "#if defined(__has_attribute)\n\ +- #if __has_attribute(availability)\n\ +-%0\n\ +- #else\n\ +- #define %1\n\ +- #endif\n\ +-#else\n\ +- #define %1\n\ +-#endif", +- (char*)NULL }; +- + /* * * * * * * * * * * * * * * * * * * * * * * * * * + * + * Description of Darwin_9_Long_Double_Funcs_2 fix +@@ -11169,9 +11074,9 @@ static const char* apzX11_SprintfPatch[] = { + * + * List of all fixes + */ +-#define REGEX_COUNT 313 ++#define REGEX_COUNT 310 + #define MACH_LIST_SIZE_LIMIT 187 +-#define FIX_COUNT 274 ++#define FIX_COUNT 272 + + /* + * Enumerate the fixes +@@ -11180,7 +11085,6 @@ typedef enum { + AAB_AIX_STDIO_FIXIDX, + AAB_AIX_FCNTL_FIXIDX, + AAB_DARWIN7_9_LONG_DOUBLE_FUNCS_FIXIDX, +- DARWIN_API_AVAILABILITY_FIXIDX, + AAB_FD_ZERO_ASM_POSIX_TYPES_H_FIXIDX, + AAB_FD_ZERO_GNU_TYPES_H_FIXIDX, + AAB_FD_ZERO_SELECTBITS_H_FIXIDX, +@@ -11242,7 +11146,6 @@ typedef enum { + CTRL_QUOTES_DEF_FIXIDX, + CTRL_QUOTES_USE_FIXIDX, + CXX_UNREADY_FIXIDX, +- DARWIN_AVAILABILITYINTERNAL_FIXIDX, + DARWIN_9_LONG_DOUBLE_FUNCS_2_FIXIDX, + DARWIN_EXTERNC_FIXIDX, + DARWIN_GCC4_BREAKAGE_FIXIDX, +@@ -11469,11 +11372,6 @@ tFixDesc fixDescList[ FIX_COUNT ] = { + AAB_DARWIN7_9_LONG_DOUBLE_FUNCS_TEST_CT, FD_MACH_ONLY | FD_REPLACEMENT, + aAab_Darwin7_9_Long_Double_FuncsTests, apzAab_Darwin7_9_Long_Double_FuncsPatch, 0 }, + +- { zDarwin_Api_AvailabilityName, zDarwin_Api_AvailabilityList, +- apzDarwin_Api_AvailabilityMachs, +- DARWIN_API_AVAILABILITY_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE, +- aDarwin_Api_AvailabilityTests, apzDarwin_Api_AvailabilityPatch, 0 }, +- + { zAab_Fd_Zero_Asm_Posix_Types_HName, zAab_Fd_Zero_Asm_Posix_Types_HList, + apzAab_Fd_Zero_Asm_Posix_Types_HMachs, + AAB_FD_ZERO_ASM_POSIX_TYPES_H_TEST_CT, FD_MACH_ONLY | FD_REPLACEMENT, +@@ -11779,11 +11677,6 @@ tFixDesc fixDescList[ FIX_COUNT ] = { + CXX_UNREADY_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE, + aCxx_UnreadyTests, apzCxx_UnreadyPatch, 0 }, + +- { zDarwin_AvailabilityinternalName, zDarwin_AvailabilityinternalList, +- apzDarwin_AvailabilityinternalMachs, +- DARWIN_AVAILABILITYINTERNAL_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE, +- aDarwin_AvailabilityinternalTests, apzDarwin_AvailabilityinternalPatch, 0 }, +- + { zDarwin_9_Long_Double_Funcs_2Name, zDarwin_9_Long_Double_Funcs_2List, + apzDarwin_9_Long_Double_Funcs_2Machs, + DARWIN_9_LONG_DOUBLE_FUNCS_2_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE, +diff --git a/fixincludes/inclhack.def b/fixincludes/inclhack.def +index 19e0ea2df66..560b455717e 100644 +--- a/fixincludes/inclhack.def ++++ b/fixincludes/inclhack.def +@@ -194,33 +194,6 @@ fix = { + _EndOfHeader_; + }; + +-/* +- * SDKs for 10.13 and 10.14 omit the definitions for API_AVAILABLE where +- * __attribute__((availability)) is not supported. +- */ +-fix = { +- hackname = darwin_api_availability; +- mach = "*-*-darwin*"; +- files = os/availability.h; +- bypass = "__IPHONE_OS_VERSION_MIN_REQUIRED"; +- select = +- " *#define __API_AVAILABLE.*\n" +- " *#define __API_DEPRECATED.*\n" +- " *#define __API_DEPRECATED_WITH_REPLACEMENT.*\n" +- " *#define __API_UNAVAILABLE.*\n"; +- c_fix = format; +- c_fix_arg = +- " #define API_AVAILABLE(...)\n" +- " #define API_DEPRECATED(...)\n" +- " #define API_DEPRECATED_WITH_REPLACEMENT(...)\n" +- " #define API_UNAVAILABLE(...)\n"; +- test_text = +- "#define __API_AVAILABLE(...)\n" +- "#define __API_DEPRECATED(...)\n" +- "#define __API_DEPRECATED_WITH_REPLACEMENT(...)\n" +- "#define __API_UNAVAILABLE(...)\n"; +-}; +- + /* + * This fixes __FD_ZERO bug for linux 2.x.y (x <= 2 && y <= some n) + */ +@@ -1273,6 +1246,7 @@ fix = { + hackname = apple_local_stdio_fn_deprecation; + mach = "*-*-*darwin2*"; + files = stdio.h; ++ files = _stdio.h; + select = "__deprecated_msg([^\n]*)$"; + c_fix = format; + c_fix_arg = "#if defined(__APPLE_LOCAL_DEPRECATIONS)\n" +@@ -1350,32 +1324,6 @@ fix = { + test_text = "extern void* malloc( size_t );"; + }; + +-/* +- * macOS 10.12 uses __attribute__((availability)) +- * unconditionally. +- */ +-fix = { +- hackname = darwin_availabilityinternal; +- mach = "*-*-darwin*"; +- files = AvailabilityInternal.h; +- select = "#define[ \t]+(__API_[ADU]\\([^)]*\\)).*"; +- c_fix = format; +- c_fix_arg = <<- _EOFix_ +- #if defined(__has_attribute) +- #if __has_attribute(availability) +- %0 +- #else +- #define %1 +- #endif +- #else +- #define %1 +- #endif +- _EOFix_; +- +- test_text = "#define __API_A(x) __attribute__((availability(__API_AVAILABLE_PLATFORM_##x)))\n" +- "#define __API_D(msg,x) __attribute__((availability(__API_DEPRECATED_PLATFORM_##x,message=msg)))"; +-}; +- + /* + * For the AAB_darwin7_9_long_double_funcs fix (and later fixes for long long) + * to be useful, the main math.h must use <> and not "" includes. +diff --git a/gcc/Makefile.in b/gcc/Makefile.in +index 775aaa1b3c4..740199cb36f 100644 +--- a/gcc/Makefile.in ++++ b/gcc/Makefile.in +@@ -158,6 +158,9 @@ LDFLAGS = @LDFLAGS@ + # Should we build position-independent host code? + PICFLAG = @PICFLAG@ + ++# The linker flag for the above. ++LD_PICFLAG = @LD_PICFLAG@ ++ + # Flags to determine code coverage. When coverage is disabled, this will + # contain the optimization flags, as you normally want code coverage + # without optimization. +@@ -266,19 +269,19 @@ LINKER = $(CC) + LINKER_FLAGS = $(CFLAGS) + endif + ++enable_host_pie = @enable_host_pie@ ++ + # Enable Intel CET on Intel CET enabled host if needed. + CET_HOST_FLAGS = @CET_HOST_FLAGS@ + COMPILER += $(CET_HOST_FLAGS) + +-NO_PIE_CFLAGS = @NO_PIE_CFLAGS@ +-NO_PIE_FLAG = @NO_PIE_FLAG@ + DO_LINK_MUTEX = @DO_LINK_MUTEX@ + +-# We don't want to compile the compilers with -fPIE, it make PCH fail. +-COMPILER += $(NO_PIE_CFLAGS) ++# Maybe compile the compilers with -fPIE or -fPIC. ++COMPILER += $(PICFLAG) + +-# Link with -no-pie since we compile the compiler with -fno-PIE. +-LINKER += $(NO_PIE_FLAG) ++# Link with -pie, or -no-pie, depending on the above. ++LINKER += $(LD_PICFLAG) + + # Like LINKER, but use a mutex for serializing front end links. + ifeq (@DO_LINK_MUTEX@,true) +@@ -1050,7 +1053,7 @@ RTL_SSA_H = $(PRETTY_PRINT_H) insn-config.h splay-tree-utils.h \ + # programs built during a bootstrap. + # autoconf inserts -DCROSS_DIRECTORY_STRUCTURE if we are building a + # cross compiler which does not use the native headers and libraries. +-INTERNAL_CFLAGS = -DIN_GCC $(PICFLAG) @CROSS@ ++INTERNAL_CFLAGS = -DIN_GCC @CROSS@ + + # This is the variable actually used when we compile. If you change this, + # you probably want to update BUILD_CFLAGS in configure.ac +@@ -1068,21 +1071,24 @@ ALL_CXXFLAGS = $(T_CFLAGS) $(CFLAGS-$@) $(CXXFLAGS) $(INTERNAL_CFLAGS) \ + ALL_CPPFLAGS = $(INCLUDES) $(CPPFLAGS) + + # This is the variable to use when using $(COMPILER). +-ALL_COMPILERFLAGS = $(ALL_CXXFLAGS) ++ALL_COMPILERFLAGS = $(ALL_CXXFLAGS) $(PICFLAG) + + # This is the variable to use when using $(LINKER). +-ALL_LINKERFLAGS = $(ALL_CXXFLAGS) ++ALL_LINKERFLAGS = $(ALL_CXXFLAGS) $(LD_PICFLAG) + + # Build and host support libraries. + +-# Use the "pic" build of libiberty if --enable-host-shared, unless we are +-# building for mingw. ++# Use the "pic" build of libiberty if --enable-host-shared or --enable-host-pie, ++# unless we are building for mingw. + LIBIBERTY_PICDIR=$(if $(findstring mingw,$(target)),,pic) +-ifeq ($(enable_host_shared),yes) ++ifneq ($(enable_host_shared)$(enable_host_pie),) + LIBIBERTY = ../libiberty/$(LIBIBERTY_PICDIR)/libiberty.a +-BUILD_LIBIBERTY = $(build_libobjdir)/libiberty/$(LIBIBERTY_PICDIR)/libiberty.a + else + LIBIBERTY = ../libiberty/libiberty.a ++endif ++ifeq ($(enable_host_shared),yes) ++BUILD_LIBIBERTY = $(build_libobjdir)/libiberty/$(LIBIBERTY_PICDIR)/libiberty.a ++else + BUILD_LIBIBERTY = $(build_libobjdir)/libiberty/libiberty.a + endif + +@@ -1167,6 +1173,8 @@ LANG_MAKEFRAGS = @all_lang_makefrags@ + # Used by gcc/jit/Make-lang.in + LD_VERSION_SCRIPT_OPTION = @ld_version_script_option@ + LD_SONAME_OPTION = @ld_soname_option@ ++@ENABLE_DARWIN_AT_RPATH_TRUE@DARWIN_RPATH = @rpath ++@ENABLE_DARWIN_AT_RPATH_FALSE@DARWIN_RPATH = ${libdir} + + # Flags to pass to recursive makes. + # CC is set by configure. +@@ -1973,9 +1981,12 @@ cs-tconfig.h: Makefile + $(SHELL) $(srcdir)/mkconfig.sh tconfig.h + + cs-tm.h: Makefile +- TARGET_CPU_DEFAULT="$(target_cpu_default)" \ +- HEADERS="$(tm_include_list)" DEFINES="$(tm_defines)" \ +- $(SHELL) $(srcdir)/mkconfig.sh tm.h ++@ENABLE_DARWIN_AT_RPATH_FALSE@ TARGET_CPU_DEFAULT="$(target_cpu_default)" \ ++@ENABLE_DARWIN_AT_RPATH_FALSE@ HEADERS="$(tm_include_list)" DEFINES="$(tm_defines)" \ ++@ENABLE_DARWIN_AT_RPATH_FALSE@ $(SHELL) $(srcdir)/mkconfig.sh tm.h ++@ENABLE_DARWIN_AT_RPATH_TRUE@ TARGET_CPU_DEFAULT="$(target_cpu_default)" \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ HEADERS="$(tm_include_list)" DEFINES="$(tm_defines) DARWIN_AT_RPATH=1" \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ $(SHELL) $(srcdir)/mkconfig.sh tm.h + + cs-tm_p.h: Makefile + TARGET_CPU_DEFAULT="" \ +@@ -4141,6 +4152,9 @@ site.exp: ./config.status Makefile + echo "set COMPAT_OPTIONS \"$(COMPAT_OPTIONS)\"" >> ./site.tmp; \ + else true; \ + fi ++ @if test "X@ENABLE_DARWIN_AT_RPATH_TRUE@" != "X#" ; then \ ++ echo "set ENABLE_DARWIN_AT_RPATH 1" >> ./site.tmp; \ ++ fi + @echo "## All variables above are generated by configure. Do Not Edit ##" >> ./site.tmp + @cat ./site.tmp > site.exp + @cat site.bak | sed \ +diff --git a/gcc/aclocal.m4 b/gcc/aclocal.m4 +index 6be36df5190..126e09bbcd1 100644 +--- a/gcc/aclocal.m4 ++++ b/gcc/aclocal.m4 +@@ -12,6 +12,56 @@ + # PARTICULAR PURPOSE. + + m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])]) ++# AM_CONDITIONAL -*- Autoconf -*- ++ ++# Copyright (C) 1997-2017 Free Software Foundation, Inc. ++# ++# This file is free software; the Free Software Foundation ++# gives unlimited permission to copy and/or distribute it, ++# with or without modifications, as long as this notice is preserved. ++ ++# AM_CONDITIONAL(NAME, SHELL-CONDITION) ++# ------------------------------------- ++# Define a conditional. ++AC_DEFUN([AM_CONDITIONAL], ++[AC_PREREQ([2.52])dnl ++ m4_if([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], ++ [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl ++AC_SUBST([$1_TRUE])dnl ++AC_SUBST([$1_FALSE])dnl ++_AM_SUBST_NOTMAKE([$1_TRUE])dnl ++_AM_SUBST_NOTMAKE([$1_FALSE])dnl ++m4_define([_AM_COND_VALUE_$1], [$2])dnl ++if $2; then ++ $1_TRUE= ++ $1_FALSE='#' ++else ++ $1_TRUE='#' ++ $1_FALSE= ++fi ++AC_CONFIG_COMMANDS_PRE( ++[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then ++ AC_MSG_ERROR([[conditional "$1" was never defined. ++Usually this means the macro was only invoked conditionally.]]) ++fi])]) ++ ++# Copyright (C) 2006-2017 Free Software Foundation, Inc. ++# ++# This file is free software; the Free Software Foundation ++# gives unlimited permission to copy and/or distribute it, ++# with or without modifications, as long as this notice is preserved. ++ ++# _AM_SUBST_NOTMAKE(VARIABLE) ++# --------------------------- ++# Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in. ++# This macro is traced by Automake. ++AC_DEFUN([_AM_SUBST_NOTMAKE]) ++ ++# AM_SUBST_NOTMAKE(VARIABLE) ++# -------------------------- ++# Public sister of _AM_SUBST_NOTMAKE. ++AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)]) ++ + m4_include([../libtool.m4]) + m4_include([../ltoptions.m4]) + m4_include([../ltsugar.m4]) +diff --git a/gcc/ada/gcc-interface/Make-lang.in b/gcc/ada/gcc-interface/Make-lang.in +index 9507f2f0920..2b9b0de8273 100644 +--- a/gcc/ada/gcc-interface/Make-lang.in ++++ b/gcc/ada/gcc-interface/Make-lang.in +@@ -72,7 +72,8 @@ else + endif + + ALL_ADAFLAGS = \ +- $(CFLAGS) $(ADA_CFLAGS) $(ADAFLAGS) $(CHECKING_ADAFLAGS) $(WARN_ADAFLAGS) ++ $(CFLAGS) $(ADA_CFLAGS) $(ADAFLAGS) $(CHECKING_ADAFLAGS) \ ++ $(WARN_ADAFLAGS) $(PICFLAG) + FORCE_DEBUG_ADAFLAGS = -g + ADA_CFLAGS = + COMMON_ADA_INCLUDES = -I- -I. -Iada/generated -Iada -I$(srcdir)/ada +@@ -1109,7 +1110,7 @@ ada/b_gnat1.adb : $(GNAT1_ADA_OBJS) + ada/b_gnat1.o : ada/b_gnat1.adb + # Do not use ADAFLAGS to get rid of -gnatg which generates a lot + # of style messages. +- $(CC) -c $(CFLAGS) $(ADA_CFLAGS) -gnatp -gnatws $(ADA_INCLUDES) \ ++ $(CC) -c $(CFLAGS) $(ADA_CFLAGS) $(PICFLAG) -gnatp -gnatws $(ADA_INCLUDES) \ + $< $(ADA_OUTPUT_OPTION) + + ada/b_gnatb.adb : $(GNATBIND_OBJS) ada/gnatbind.o +@@ -1118,7 +1119,7 @@ ada/b_gnatb.adb : $(GNATBIND_OBJS) ada/gnatbind.o + $(MV) b_gnatb.adb b_gnatb.ads ada/ + + ada/b_gnatb.o : ada/b_gnatb.adb +- $(CC) -c $(CFLAGS) $(ADA_CFLAGS) -gnatp -gnatws $(ADA_INCLUDES) \ ++ $(CC) -c $(CFLAGS) $(ADA_CFLAGS) $(PICFLAG) -gnatp -gnatws $(ADA_INCLUDES) \ + $< $(ADA_OUTPUT_OPTION) + + include $(srcdir)/ada/Make-generated.in +diff --git a/gcc/ada/gcc-interface/Makefile.in b/gcc/ada/gcc-interface/Makefile.in +index da6a56fcec8..51a4bf17038 100644 +--- a/gcc/ada/gcc-interface/Makefile.in ++++ b/gcc/ada/gcc-interface/Makefile.in +@@ -91,6 +91,7 @@ LS = ls + RANLIB = @RANLIB@ + RANLIB_FLAGS = @ranlib_flags@ + AWK = @AWK@ ++PICFLAG = @PICFLAG@ + + COMPILER = $(CC) + COMPILER_FLAGS = $(CFLAGS) +@@ -239,7 +240,11 @@ ALL_CPPFLAGS = $(CPPFLAGS) + ALL_COMPILERFLAGS = $(ALL_CFLAGS) + + # This is where we get libiberty.a from. ++ifeq ($(PICFLAG),) + LIBIBERTY = ../../libiberty/libiberty.a ++else ++LIBIBERTY = ../../libiberty/pic/libiberty.a ++endif + + # We need to link against libbacktrace because diagnostic.c in + # libcommon.a uses it. +@@ -256,9 +261,6 @@ TOOLS_LIBS = ../version.o ../link.o ../targext.o ../../ggc-none.o \ + $(LIBGNAT) $(LIBINTL) $(LIBICONV) ../$(LIBBACKTRACE) ../$(LIBIBERTY) \ + $(SYSLIBS) $(TGT_LIB) + +-# Add -no-pie to TOOLS_LIBS since some of them are compiled with -fno-PIE. +-TOOLS_LIBS += @NO_PIE_FLAG@ +- + # Specify the directories to be searched for header files. + # Both . and srcdir are used, in that order, + # so that tm.h and config.h will be found in the compilation +@@ -789,12 +791,15 @@ gnatlib-shared-darwin: + $(GNATRTL_NONTASKING_OBJS) $(LIBGNAT_OBJS) \ + $(SO_OPTS) \ + -Wl,-install_name,@rpath/libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) \ +- $(MISCLIB) ++ -nodefaultrpaths -Wl,-rpath,@loader_path/,-rpath,@loader_path/.. \ ++ -Wl,-rpath,@loader_path/../../../../ $(MISCLIB) + cd $(RTSDIR); $(GCC_FOR_ADA_RTS) -dynamiclib $(PICFLAG_FOR_TARGET) \ + -o libgnarl$(hyphen)$(LIBRARY_VERSION)$(soext) \ + $(GNATRTL_TASKING_OBJS) \ + $(SO_OPTS) \ + -Wl,-install_name,@rpath/libgnarl$(hyphen)$(LIBRARY_VERSION)$(soext) \ ++ -nodefaultrpaths -Wl,-rpath,@loader_path/,-rpath,@loader_path/.. \ ++ -Wl,-rpath,@loader_path/../../../../ \ + $(THREADSLIB) -Wl,libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) + cd $(RTSDIR); $(LN_S) libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) \ + libgnat$(soext) +diff --git a/gcc/analyzer/kf.cc b/gcc/analyzer/kf.cc +index 4389ff917b8..0fe5d2a2e67 100644 +--- a/gcc/analyzer/kf.cc ++++ b/gcc/analyzer/kf.cc +@@ -1081,7 +1081,7 @@ register_known_functions (known_function_manager &kfm) + like this: + extern int *___errno(void) __attribute__((__const__)); + #define errno (*(___errno())) +- and OS X like this: ++ and macOS like this: + extern int * __error(void); + #define errno (*__error()) + and similarly __errno for newlib. +diff --git a/gcc/builtins.cc b/gcc/builtins.cc +index 1bfdc598eec..1122527cbd7 100644 +--- a/gcc/builtins.cc ++++ b/gcc/builtins.cc +@@ -5501,6 +5501,13 @@ expand_builtin_trap (void) + static void + expand_builtin_unreachable (void) + { ++ /* If the target wants a trap in place of the fall-through, use that. */ ++ if (targetm.unreachable_should_trap ()) ++ { ++ expand_builtin_trap (); ++ return; ++ } ++ + /* Use gimple_build_builtin_unreachable or builtin_decl_unreachable + to avoid this. */ + gcc_checking_assert (!sanitize_flags_p (SANITIZE_UNREACHABLE)); +@@ -7958,6 +7965,10 @@ expand_builtin (tree exp, rtx target, rtx subtarget, machine_mode mode, + case BUILT_IN_ADJUST_DESCRIPTOR: + return expand_builtin_adjust_descriptor (exp); + ++ case BUILT_IN_GCC_NESTED_PTR_CREATED: ++ case BUILT_IN_GCC_NESTED_PTR_DELETED: ++ break; /* At present, no expansion, just call the function. */ ++ + case BUILT_IN_FORK: + case BUILT_IN_EXECL: + case BUILT_IN_EXECV: +diff --git a/gcc/builtins.def b/gcc/builtins.def +index 4ad95a12f83..448cf837ec8 100644 +--- a/gcc/builtins.def ++++ b/gcc/builtins.def +@@ -1067,6 +1067,8 @@ DEF_BUILTIN_STUB (BUILT_IN_ADJUST_TRAMPOLINE, "__builtin_adjust_trampoline") + DEF_BUILTIN_STUB (BUILT_IN_INIT_DESCRIPTOR, "__builtin_init_descriptor") + DEF_BUILTIN_STUB (BUILT_IN_ADJUST_DESCRIPTOR, "__builtin_adjust_descriptor") + DEF_BUILTIN_STUB (BUILT_IN_NONLOCAL_GOTO, "__builtin_nonlocal_goto") ++DEF_EXT_LIB_BUILTIN (BUILT_IN_GCC_NESTED_PTR_CREATED, "__gcc_nested_func_ptr_created", BT_FN_VOID_PTR_PTR_PTR, ATTR_NOTHROW_LIST) ++DEF_EXT_LIB_BUILTIN (BUILT_IN_GCC_NESTED_PTR_DELETED, "__gcc_nested_func_ptr_deleted", BT_FN_VOID, ATTR_NOTHROW_LIST) + + /* Implementing __builtin_setjmp. */ + DEF_BUILTIN_STUB (BUILT_IN_SETJMP_SETUP, "__builtin_setjmp_setup") +diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc +index 67709912a11..a0adac162e9 100644 +--- a/gcc/c-family/c-attribs.cc ++++ b/gcc/c-family/c-attribs.cc +@@ -607,6 +607,18 @@ attribute_takes_identifier_p (const_tree attr_id) + return targetm.attribute_takes_identifier_p (attr_id); + } + ++/* Returns TRUE iff the attribute indicated by ATTR_ID needs its ++ arguments converted to string constants. */ ++ ++bool ++attribute_clang_form_p (const_tree attr_id) ++{ ++ const struct attribute_spec *spec = lookup_attribute_spec (attr_id); ++ if (spec && !strcmp ("availability", spec->name)) ++ return true; ++ return false; ++} ++ + /* Verify that argument value POS at position ARGNO to attribute NAME + applied to function FN (which is either a function declaration or function + type) refers to a function parameter at position POS and the expected type +diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc +index 303d7f1ef5d..e3c3fae8dea 100644 +--- a/gcc/c-family/c-common.cc ++++ b/gcc/c-family/c-common.cc +@@ -311,6 +311,48 @@ const struct fname_var_t fname_vars[] = + {NULL, 0, 0}, + }; + ++/* Flags to restrict availability of generic features that ++ are known to __has_{feature,extension}. */ ++ ++enum ++{ ++ HF_FLAG_NONE = 0, ++ HF_FLAG_EXT = 1, /* Available only as an extension. */ ++ HF_FLAG_SANITIZE = 2, /* Availability depends on sanitizer flags. */ ++}; ++ ++/* Info for generic features which can be queried through ++ __has_{feature,extension}. */ ++ ++struct hf_feature_info ++{ ++ const char *ident; ++ unsigned flags; ++ unsigned mask; ++}; ++ ++/* Table of generic features which can be queried through ++ __has_{feature,extension}. */ ++ ++static constexpr hf_feature_info has_feature_table[] = ++{ ++ { "address_sanitizer", HF_FLAG_SANITIZE, SANITIZE_ADDRESS }, ++ { "thread_sanitizer", HF_FLAG_SANITIZE, SANITIZE_THREAD }, ++ { "leak_sanitizer", HF_FLAG_SANITIZE, SANITIZE_LEAK }, ++ { "hwaddress_sanitizer", HF_FLAG_SANITIZE, SANITIZE_HWADDRESS }, ++ { "undefined_behavior_sanitizer", HF_FLAG_SANITIZE, SANITIZE_UNDEFINED }, ++ { "attribute_deprecated_with_message", HF_FLAG_NONE, 0 }, ++ { "attribute_unavailable_with_message", HF_FLAG_NONE, 0 }, ++ { "enumerator_attributes", HF_FLAG_NONE, 0 }, ++ { "tls", HF_FLAG_NONE, 0 }, ++ { "gnu_asm_goto_with_outputs", HF_FLAG_EXT, 0 }, ++ { "gnu_asm_goto_with_outputs_full", HF_FLAG_EXT, 0 }, ++ { "attribute_availability", HF_FLAG_NONE, 0 }, ++ { "attribute_availability_with_message", HF_FLAG_NONE, 0 }, ++ { "attribute_availability_with_replacement", HF_FLAG_NONE, 0 }, ++ { "attribute_availability_with_version_underscores", HF_FLAG_NONE, 0 } ++}; ++ + /* Global visibility options. */ + struct visibility_flags visibility_options; + +@@ -9552,4 +9590,63 @@ c_strict_flex_array_level_of (tree array_field) + return strict_flex_array_level; + } + ++/* Map from identifiers to booleans. Value is true for features, and ++ false for extensions. Used to implement __has_{feature,extension}. */ ++ ++using feature_map_t = hash_map ; ++static feature_map_t *feature_map; ++ ++/* Register a feature for __has_{feature,extension}. FEATURE_P is true ++ if the feature identified by NAME is a feature (as opposed to an ++ extension). */ ++ ++void ++c_common_register_feature (const char *name, bool feature_p) ++{ ++ bool dup = feature_map->put (get_identifier (name), feature_p); ++ gcc_checking_assert (!dup); ++} ++ ++/* Lazily initialize hash table for __has_{feature,extension}, ++ dispatching to the appropriate front end to register language-specific ++ features. */ ++ ++static void ++init_has_feature () ++{ ++ gcc_checking_assert (!feature_map); ++ feature_map = new feature_map_t; ++ ++ for (unsigned i = 0; i < ARRAY_SIZE (has_feature_table); i++) ++ { ++ const hf_feature_info *info = has_feature_table + i; ++ ++ if ((info->flags & HF_FLAG_SANITIZE) && !(flag_sanitize & info->mask)) ++ continue; ++ ++ const bool feature_p = !(info->flags & HF_FLAG_EXT); ++ c_common_register_feature (info->ident, feature_p); ++ } ++ ++ /* Register language-specific features. */ ++ c_family_register_lang_features (); ++} ++ ++/* If STRICT_P is true, evaluate __has_feature (IDENT). ++ Otherwise, evaluate __has_extension (IDENT). */ ++ ++bool ++has_feature_p (const char *ident, bool strict_p) ++{ ++ if (!feature_map) ++ init_has_feature (); ++ ++ tree name = canonicalize_attr_name (get_identifier (ident)); ++ bool *feat_p = feature_map->get (name); ++ if (!feat_p) ++ return false; ++ ++ return !strict_p || *feat_p; ++} ++ + #include "gt-c-family-c-common.h" +diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h +index f96350b64af..41d69d45ea6 100644 +--- a/gcc/c-family/c-common.h ++++ b/gcc/c-family/c-common.h +@@ -1121,6 +1121,14 @@ extern bool c_cpp_diagnostic (cpp_reader *, enum cpp_diagnostic_level, + ATTRIBUTE_GCC_DIAG(5,0); + extern int c_common_has_attribute (cpp_reader *, bool); + extern int c_common_has_builtin (cpp_reader *); ++extern int c_common_has_feature (cpp_reader *, bool); ++ ++/* Implemented by each front end in *-lang.cc. */ ++extern void c_family_register_lang_features (); ++ ++/* Implemented in c-family/c-common.cc. */ ++extern void c_common_register_feature (const char *, bool); ++extern bool has_feature_p (const char *, bool); + + extern bool parse_optimize_options (tree, bool); + +@@ -1529,6 +1537,7 @@ extern void check_for_xor_used_as_pow (location_t lhs_loc, tree lhs_val, + /* In c-attribs.cc. */ + extern bool attribute_takes_identifier_p (const_tree); + extern tree handle_deprecated_attribute (tree *, tree, tree, int, bool *); ++extern bool attribute_clang_form_p (const_tree); + extern tree handle_unused_attribute (tree *, tree, tree, int, bool *); + extern tree handle_fallthrough_attribute (tree *, tree, tree, int, bool *); + extern int parse_tm_stmt_attr (tree, int); +diff --git a/gcc/c-family/c-lex.cc b/gcc/c-family/c-lex.cc +index 0acfdaa95c9..2a504a98edf 100644 +--- a/gcc/c-family/c-lex.cc ++++ b/gcc/c-family/c-lex.cc +@@ -82,6 +82,7 @@ init_c_lex (void) + cb->read_pch = c_common_read_pch; + cb->has_attribute = c_common_has_attribute; + cb->has_builtin = c_common_has_builtin; ++ cb->has_feature = c_common_has_feature; + cb->get_source_date_epoch = cb_get_source_date_epoch; + cb->get_suggestion = cb_get_suggestion; + cb->remap_filename = remap_macro_filename; +@@ -457,16 +458,16 @@ c_common_has_attribute (cpp_reader *pfile, bool std_syntax) + return result; + } + +-/* Callback for has_builtin. */ ++/* Helper for __has_{builtin,feature,extension}. */ + +-int +-c_common_has_builtin (cpp_reader *pfile) ++static const char * ++c_common_lex_availability_macro (cpp_reader *pfile, const char *builtin) + { + const cpp_token *token = get_token_no_padding (pfile); + if (token->type != CPP_OPEN_PAREN) + { + cpp_error (pfile, CPP_DL_ERROR, +- "missing '(' after \"__has_builtin\""); ++ "missing '(' after \"__has_%s\"", builtin); + return 0; + } + +@@ -486,7 +487,7 @@ c_common_has_builtin (cpp_reader *pfile) + else + { + cpp_error (pfile, CPP_DL_ERROR, +- "macro \"__has_builtin\" requires an identifier"); ++ "macro \"__has_%s\" requires an identifier", builtin); + if (token->type == CPP_CLOSE_PAREN) + return 0; + } +@@ -505,9 +506,38 @@ c_common_has_builtin (cpp_reader *pfile) + break; + } + ++ return name; ++} ++ ++/* Callback for has_builtin. */ ++ ++int ++c_common_has_builtin (cpp_reader *pfile) ++{ ++ const char *name = c_common_lex_availability_macro (pfile, "builtin"); ++ if (!name) ++ return 0; ++ + return names_builtin_p (name); + } + ++/* Callback for has_feature. STRICT_P is true for has_feature and false ++ for has_extension. */ ++ ++int ++c_common_has_feature (cpp_reader *pfile, bool strict_p) ++{ ++ const char *builtin = strict_p ? "feature" : "extension"; ++ const char *name = c_common_lex_availability_macro (pfile, builtin); ++ if (!name) ++ return 0; ++ ++ /* If -pedantic-errors is given, __has_extension is equivalent to ++ __has_feature. */ ++ strict_p |= flag_pedantic_errors; ++ return has_feature_p (name, strict_p); ++} ++ + + /* Read a token and return its type. Fill *VALUE with its value, if + applicable. Fill *CPP_FLAGS with the token's flags, if it is +@@ -539,6 +569,21 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags, + + case CPP_NUMBER: + { ++ /* If the user wants number-like entities to be returned as a raw ++ string, then don't try to classify them, which emits unwanted ++ diagnostics. */ ++ if (lex_flags & C_LEX_NUMBER_AS_STRING) ++ { ++ /* build_string adds a trailing NUL at [len]. */ ++ tree num_string = build_string (tok->val.str.len + 1, ++ (const char *) tok->val.str.text); ++ TREE_TYPE (num_string) = char_array_type_node; ++ *value = num_string; ++ /* We will effectively note this as CPP_N_INVALID, because we ++ made no checks here. */ ++ break; ++ } ++ + const char *suffix = NULL; + unsigned int flags = cpp_classify_number (parse_in, tok, &suffix, *loc); + +diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc +index c68a2a27469..a600d40c87e 100644 +--- a/gcc/c-family/c-opts.cc ++++ b/gcc/c-family/c-opts.cc +@@ -1070,7 +1070,7 @@ c_common_post_options (const char **pfilename) + + if (flag_extern_tls_init) + { +- if (!TARGET_SUPPORTS_ALIASES || !SUPPORTS_WEAK) ++ if (!SUPPORTS_WEAK) + { + /* Lazy TLS initialization for a variable in another TU requires + alias and weak reference support. */ +diff --git a/gcc/c-family/c-ppoutput.cc b/gcc/c-family/c-ppoutput.cc +index 4aa2bef2c0f..a1488c6f086 100644 +--- a/gcc/c-family/c-ppoutput.cc ++++ b/gcc/c-family/c-ppoutput.cc +@@ -162,6 +162,7 @@ init_pp_output (FILE *out_stream) + + cb->has_attribute = c_common_has_attribute; + cb->has_builtin = c_common_has_builtin; ++ cb->has_feature = c_common_has_feature; + cb->get_source_date_epoch = cb_get_source_date_epoch; + cb->remap_filename = remap_macro_filename; + +diff --git a/gcc/c-family/c-pragma.h b/gcc/c-family/c-pragma.h +index 9cc95ab3ee3..3e86a16d4ae 100644 +--- a/gcc/c-family/c-pragma.h ++++ b/gcc/c-family/c-pragma.h +@@ -272,6 +272,9 @@ extern enum cpp_ttype pragma_lex (tree *, location_t *loc = NULL); + #define C_LEX_STRING_NO_JOIN 2 /* Do not concatenate strings + nor translate them into execution + character set. */ ++#define C_LEX_NUMBER_AS_STRING 4 /* Do not classify a number, but ++ instead return it as a raw ++ string. */ + + /* This is not actually available to pragma parsers. It's merely a + convenient location to declare this function for c-lex, after +diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt +index a75038930ae..c7e662018d5 100644 +--- a/gcc/c-family/c.opt ++++ b/gcc/c-family/c.opt +@@ -1484,6 +1484,10 @@ Wsubobject-linkage + C++ ObjC++ Var(warn_subobject_linkage) Warning Init(1) + Warn if a class type has a base or a field whose type uses the anonymous namespace or depends on a type with no linkage. + ++Welaborated-enum-base ++C++ ObjC++ Var(warn_elaborated_enum_base) Warning Init(1) ++Warn if an additional enum-base is used in an elaborated-type-specifier. ++ + Wduplicate-decl-specifier + C ObjC Var(warn_duplicate_decl_specifier) Warning LangEnabledBy(C ObjC,Wall) + Warn when a declaration has duplicate const, volatile, restrict or _Atomic specifier. +@@ -1639,6 +1643,10 @@ static-libmpxwrappers + Driver WarnRemoved + Removed in GCC 9. This switch has no effect. + ++fallow-extended-attribute-placement ++C ObjC C++ ObjC++ LTO Var(flag_allow_ext_attr_placement) Init(0) ++Allow placement of attributes on function definitions. ++ + fcilkplus + C ObjC C++ ObjC++ LTO Undocumented Ignore + Removed in GCC 8. This switch has no effect. +@@ -1967,7 +1975,7 @@ Implement resolution of DR 150 for matching of template template arguments. + + fnext-runtime + ObjC ObjC++ LTO RejectNegative Var(flag_next_runtime) +-Generate code for NeXT (Apple Mac OS X) runtime environment. ++Generate code for NeXT (Apple macOS) runtime environment. + + fnil-receivers + ObjC ObjC++ Var(flag_nil_receivers) Init(1) +diff --git a/gcc/c/c-lang.cc b/gcc/c/c-lang.cc +index b4e0c8cfb8a..11e7aaac2e3 100644 +--- a/gcc/c/c-lang.cc ++++ b/gcc/c/c-lang.cc +@@ -61,6 +61,15 @@ c_get_sarif_source_language (const char *) + return "c"; + } + ++/* Implement c-family hook to register language-specific features for ++ __has_{feature,extension}. */ ++ ++void ++c_family_register_lang_features () ++{ ++ c_register_features (); ++} ++ + #if CHECKING_P + + namespace selftest { +diff --git a/gcc/c/c-objc-common.cc b/gcc/c/c-objc-common.cc +index e4aed61ed00..fad46626570 100644 +--- a/gcc/c/c-objc-common.cc ++++ b/gcc/c/c-objc-common.cc +@@ -34,6 +34,38 @@ along with GCC; see the file COPYING3. If not see + static bool c_tree_printer (pretty_printer *, text_info *, const char *, + int, bool, bool, bool, bool *, const char **); + ++/* Info for C language features which can be queried through ++ __has_{feature,extension}. */ ++ ++struct c_feature_info ++{ ++ const char *ident; ++ const int *enable_flag; ++}; ++ ++static const c_feature_info c_feature_table[] = ++{ ++ { "c_alignas", &flag_isoc11 }, ++ { "c_alignof", &flag_isoc11 }, ++ { "c_atomic", &flag_isoc11 }, ++ { "c_generic_selections", &flag_isoc11 }, ++ { "c_static_assert", &flag_isoc11 }, ++ { "c_thread_local", &flag_isoc11 } ++}; ++ ++/* Register features specific to the C language. */ ++ ++void ++c_register_features () ++{ ++ for (unsigned i = 0; i < ARRAY_SIZE (c_feature_table); i++) ++ { ++ const c_feature_info *info = c_feature_table + i; ++ const bool feat_p = !info->enable_flag || *info->enable_flag; ++ c_common_register_feature (info->ident, feat_p); ++ } ++} ++ + bool + c_missing_noreturn_ok_p (tree decl) + { +diff --git a/gcc/c/c-objc-common.h b/gcc/c/c-objc-common.h +index d31dacb9dd4..34dc23a1bd0 100644 +--- a/gcc/c/c-objc-common.h ++++ b/gcc/c/c-objc-common.h +@@ -21,6 +21,9 @@ along with GCC; see the file COPYING3. If not see + #ifndef GCC_C_OBJC_COMMON + #define GCC_C_OBJC_COMMON + ++/* Implemented in c-objc-common.cc. */ ++extern void c_register_features (); ++ + /* Lang hooks that are shared between C and ObjC are defined here. Hooks + specific to C or ObjC go in c-lang.cc and objc/objc-lang.cc, respectively. */ + +diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc +index 3627a3fbdc7..5abc6e84697 100644 +--- a/gcc/c/c-parser.cc ++++ b/gcc/c/c-parser.cc +@@ -217,6 +217,9 @@ struct GTY(()) c_parser { + should translate them to the execution character set (false + inside attributes). */ + BOOL_BITFIELD translate_strings_p : 1; ++ /* True if we want to lex arbitrary number-like sequences as their ++ string representation. */ ++ BOOL_BITFIELD lex_number_as_string : 1; + + /* Objective-C specific parser/lexer information. */ + +@@ -291,10 +294,10 @@ c_lex_one_token (c_parser *parser, c_token *token, bool raw = false) + + if (raw || vec_safe_length (parser->raw_tokens) == 0) + { ++ int lex_flags = parser->lex_joined_string ? 0 : C_LEX_STRING_NO_JOIN; ++ lex_flags |= parser->lex_number_as_string ? C_LEX_NUMBER_AS_STRING : 0; + token->type = c_lex_with_flags (&token->value, &token->location, +- &token->flags, +- (parser->lex_joined_string +- ? 0 : C_LEX_STRING_NO_JOIN)); ++ &token->flags, lex_flags); + token->id_kind = C_ID_NONE; + token->keyword = RID_MAX; + token->pragma_kind = PRAGMA_NONE; +@@ -2579,15 +2582,28 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, + d = d->declarator; + underspec_name = d->u.id.id; + } ++ tree postfix_attrs = NULL_TREE; ++ if (flag_allow_ext_attr_placement ++ && c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) ++ { ++ postfix_attrs = c_parser_gnu_attributes (parser); ++ /* IF we have a function definition, and we're allowing it then ++ treat these attributes as if they had been prepended. */ ++ if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) ++ { ++ all_prefix_attrs = chainon (all_prefix_attrs, postfix_attrs); ++ postfix_attrs = NULL_TREE; ++ } ++ } + if (c_parser_next_token_is (parser, CPP_EQ) + || c_parser_next_token_is (parser, CPP_COMMA) + || c_parser_next_token_is (parser, CPP_SEMICOLON) + || c_parser_next_token_is_keyword (parser, RID_ASM) + || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE) ++ || postfix_attrs + || c_parser_next_token_is_keyword (parser, RID_IN)) + { + tree asm_name = NULL_TREE; +- tree postfix_attrs = NULL_TREE; + if (!diagnosed_no_specs && !specs->declspecs_seen_p) + { + diagnosed_no_specs = true; +@@ -2599,8 +2615,9 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, + if (c_parser_next_token_is_keyword (parser, RID_ASM)) + asm_name = c_parser_simple_asm_expr (parser); + if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) ++ postfix_attrs = c_parser_gnu_attributes (parser); ++ if (postfix_attrs) + { +- postfix_attrs = c_parser_gnu_attributes (parser); + if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) + { + /* This means there is an attribute specifier after +@@ -4993,6 +4996,88 @@ c_parser_gnu_attribute_any_word (c_parser *parser) + return attr_name; + } + ++/* Handle parsing clang-form attribute arguments, where we need to adjust ++ the parsing rules to relate to a specific attribute. */ ++ ++static tree ++c_parser_clang_attribute_arguments (c_parser *parser, tree /*attr_id*/) ++{ ++ /* We can, if required, alter the parsing on the basis of the attribute. ++ At present, we handle the availability attr, where ach entry can be : ++ identifier ++ identifier=N.MM.Z ++ identifier="string" ++ followed by ',' or ) for the last entry*/ ++ ++ tree attr_args = NULL_TREE; ++ do ++ { ++ tree name = NULL_TREE; ++ tree value = NULL_TREE; ++ ++ if (c_parser_next_token_is (parser, CPP_NAME) ++ && c_parser_peek_token (parser)->id_kind == C_ID_ID) ++ { ++ name = c_parser_peek_token (parser)->value; ++ c_parser_consume_token (parser); ++ } ++ else if (c_parser_next_token_is (parser, CPP_COMMA)) ++ name = error_mark_node; /* Comma handled below. */ ++ else ++ { ++ bool saved_join_state = parser->lex_joined_string; ++ parser->lex_number_as_string = 1; ++ parser->lex_joined_string = 1; ++ c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, ++ "expected an attribute keyword"); ++ parser->lex_number_as_string = 0; ++ parser->lex_joined_string = saved_join_state; ++ return error_mark_node; ++ } ++ if (c_parser_next_token_is (parser, CPP_EQ)) ++ { ++ c_parser_consume_token (parser); /* eat the '=' */ ++ /* We need to bludgeon the lexer into not trying to interpret the ++ xx.yy.zz form, since that just looks like a malformed float. ++ Also, as a result of macro processing, we can have strig literals ++ that are in multiple pieces so, for this specific part of the ++ parse, we need to join strings. */ ++ bool saved_join_state = parser->lex_joined_string; ++ parser->lex_number_as_string = 1; ++ parser->lex_joined_string = 1; ++ /* So look at the next token, expecting a string, or something that ++ looks initially like a number, but might be a version number. */ ++ c_parser_peek_token (parser); ++ /* Done with the funky number parsing. */ ++ parser->lex_number_as_string = 0; ++ parser->lex_joined_string = saved_join_state; ++ if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN) ++ && c_parser_next_token_is_not (parser, CPP_COMMA)) ++ { ++ value = c_parser_peek_token (parser)->value; ++ /* ???: check for error mark and early-return? */ ++ c_parser_consume_token (parser); ++ } ++ /* else value is absent. */ ++ } ++ else if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN) ++ && c_parser_next_token_is_not (parser, CPP_COMMA)) ++ { ++ c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, ++ "expected %<,%> or %<=%>"); ++ return error_mark_node; ++ } ++ if (c_parser_next_token_is (parser, CPP_COMMA)) ++ c_parser_consume_token (parser); /* Just skip the comma. */ ++ tree t = tree_cons (value, name, NULL); ++ if (!attr_args) ++ attr_args = t; ++ else ++ chainon (attr_args, t); ++ } while (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN)); ++ return attr_args; ++} ++ + /* Parse attribute arguments. This is a common form of syntax + covering all currently valid GNU and standard attributes. + +@@ -5158,9 +5243,13 @@ c_parser_gnu_attribute (c_parser *parser, tree attrs, + attrs = chainon (attrs, attr); + return attrs; + } +- c_parser_consume_token (parser); ++ c_parser_consume_token (parser); /* The '('. */ + +- tree attr_args ++ tree attr_args; ++ if (attribute_clang_form_p (attr_name)) ++ attr_args = c_parser_clang_attribute_arguments (parser, attr_name); ++ else ++ attr_args + = c_parser_attribute_arguments (parser, + attribute_takes_identifier_p (attr_name), + false, +diff --git a/gcc/calls.cc b/gcc/calls.cc +index 53b0f58b709..b58990f1b90 100644 +--- a/gcc/calls.cc ++++ b/gcc/calls.cc +@@ -1367,7 +1367,8 @@ initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED, + with those made by function.cc. */ + + /* See if this argument should be passed by invisible reference. */ +- function_arg_info arg (type, argpos < n_named_args); ++ function_arg_info arg (type, argpos < n_named_args, ++ argpos == n_named_args - 1); + if (pass_by_reference (args_so_far_pnt, arg)) + { + const bool callee_copies +@@ -1487,10 +1488,13 @@ initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED, + + unsignedp = TYPE_UNSIGNED (type); + arg.type = type; +- arg.mode +- = promote_function_mode (type, TYPE_MODE (type), &unsignedp, +- fndecl ? TREE_TYPE (fndecl) : fntype, 0); +- ++ arg.mode = TYPE_MODE (type); ++// arg.mode ++// = promote_function_mode (type, TYPE_MODE (type), &unsignedp, ++// fndecl ? TREE_TYPE (fndecl) : fntype, 0); ++ arg.mode = promote_function_mode (args_so_far, arg, ++ fndecl ? TREE_TYPE (fndecl) : fntype, ++ &unsignedp, 0); + args[i].unsignedp = unsignedp; + args[i].mode = arg.mode; + +@@ -1540,6 +1544,7 @@ initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED, + #endif + reg_parm_stack_space, + args[i].pass_on_stack ? 0 : args[i].partial, ++ args_so_far, + fndecl, args_size, &args[i].locate); + #ifdef BLOCK_REG_PADDING + else +@@ -4076,6 +4081,7 @@ split_complex_types (tree types) + return types; + } + ++extern void debug_tree (tree); + /* Output a library call to function ORGFUN (a SYMBOL_REF rtx) + for a value of mode OUTMODE, + with NARGS different arguments, passed as ARGS. +@@ -4261,6 +4267,7 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value, + argvec[count].reg != 0, + #endif + reg_parm_stack_space, 0, ++ args_so_far, + NULL_TREE, &args_size, &argvec[count].locate); + + if (argvec[count].reg == 0 || argvec[count].partial != 0 +@@ -4331,8 +4338,16 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value, + val = force_operand (XEXP (slot, 0), NULL_RTX); + } + +- arg.mode = promote_function_mode (NULL_TREE, arg.mode, &unsigned_p, +- NULL_TREE, 0); ++// arg.mode = promote_function_mode (NULL_TREE, arg.mode, &unsigned_p, ++// NULL_TREE, 0); ++ tree t = arg.type; ++if (t) ++ debug_tree (t); ++gcc_assert (!t); ++ arg.type = NULL_TREE; ++ arg.mode = promote_function_mode (args_so_far, arg, NULL_TREE, ++ &unsigned_p, 0); ++ arg.type = t; + argvec[count].mode = arg.mode; + argvec[count].value = convert_modes (arg.mode, GET_MODE (val), val, + unsigned_p); +@@ -4352,6 +4367,7 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value, + argvec[count].reg != 0, + #endif + reg_parm_stack_space, argvec[count].partial, ++ args_so_far, + NULL_TREE, &args_size, &argvec[count].locate); + args_size.constant += argvec[count].locate.size.constant; + gcc_assert (!argvec[count].locate.size.var); +diff --git a/gcc/calls.h b/gcc/calls.h +index c7f8c5e4b39..42a1774fe84 100644 +--- a/gcc/calls.h ++++ b/gcc/calls.h +@@ -35,24 +35,43 @@ class function_arg_info + { + public: + function_arg_info () +- : type (NULL_TREE), mode (VOIDmode), named (false), ++ : type (NULL_TREE), mode (VOIDmode), named (false), last_named (false), + pass_by_reference (false) + {} + + /* Initialize an argument of mode MODE, either before or after promotion. */ + function_arg_info (machine_mode mode, bool named) +- : type (NULL_TREE), mode (mode), named (named), pass_by_reference (false) ++ : type (NULL_TREE), mode (mode), named (named), last_named (false), ++ pass_by_reference (false) ++ {} ++ ++ function_arg_info (machine_mode mode, bool named, bool last_named) ++ : type (NULL_TREE), mode (mode), named (named), last_named (last_named), ++ pass_by_reference (false) + {} + + /* Initialize an unpromoted argument of type TYPE. */ + function_arg_info (tree type, bool named) +- : type (type), mode (TYPE_MODE (type)), named (named), ++ : type (type), mode (TYPE_MODE (type)), named (named), last_named (false), + pass_by_reference (false) + {} + ++ /* Initialize an unpromoted argument of type TYPE. */ ++ function_arg_info (tree type, bool named, bool last_named) ++ : type (type), mode (TYPE_MODE (type)), named (named), ++ last_named (last_named), pass_by_reference (false) ++ {} ++ + /* Initialize an argument with explicit properties. */ + function_arg_info (tree type, machine_mode mode, bool named) +- : type (type), mode (mode), named (named), pass_by_reference (false) ++ : type (type), mode (mode), named (named), last_named (false), ++ pass_by_reference (false) ++ {} ++ ++ /* Initialize an argument with explicit properties. */ ++ function_arg_info (tree type, machine_mode mode, bool named, bool last_named) ++ : type (type), mode (mode), named (named), last_named (last_named), ++ pass_by_reference (false) + {} + + /* Return true if the gimple-level type is an aggregate. */ +@@ -105,6 +124,9 @@ public: + "..."). See also TARGET_STRICT_ARGUMENT_NAMING. */ + unsigned int named : 1; + ++ /* True if this is the last named argument. */ ++ unsigned int last_named : 1; ++ + /* True if we have decided to pass the argument by reference, in which case + the function_arg_info describes a pointer to the original argument. */ + unsigned int pass_by_reference : 1; +diff --git a/gcc/collect2.cc b/gcc/collect2.cc +index 63b9a0c233a..1d7d9a442ac 100644 +--- a/gcc/collect2.cc ++++ b/gcc/collect2.cc +@@ -73,7 +73,7 @@ along with GCC; see the file COPYING3. If not see + In a cross-compiler, this means you need a cross nm, + but that is not quite as unpleasant as special headers. */ + +-#if !defined (OBJECT_FORMAT_COFF) ++#if !defined (OBJECT_FORMAT_COFF) && !defined (OBJECT_FORMAT_MACHO) + #define OBJECT_FORMAT_NONE + #endif + +@@ -107,7 +107,7 @@ along with GCC; see the file COPYING3. If not see + + #endif /* OBJECT_FORMAT_COFF */ + +-#ifdef OBJECT_FORMAT_NONE ++#if defined (OBJECT_FORMAT_NONE) || defined (OBJECT_FORMAT_MACHO) + + /* Default flags to pass to nm. */ + #ifndef NM_FLAGS +@@ -525,7 +525,7 @@ static const char *const target_machine = TARGET_MACHINE; + + Return 0 if not found, otherwise return its name, allocated with malloc. */ + +-#ifdef OBJECT_FORMAT_NONE ++#if defined (OBJECT_FORMAT_NONE) || defined (OBJECT_FORMAT_MACHO) + + /* Add an entry for the object file NAME to object file list LIST. + New entries are added at the end of the list. The original pointer +@@ -764,6 +764,12 @@ do_link (char **ld_argv, const char *atsuffix) + } + } + ++#if defined (OBJECT_FORMAT_MACHO) ++# define LLD_NAME "ld64.lld" ++#else ++# define LLD_NAME "ld.lld" ++#endif ++ + /* Main program. */ + + int +@@ -777,16 +783,19 @@ main (int argc, char **argv) + USE_BFD_LD, + USE_LLD_LD, + USE_MOLD_LD, ++ USE_CLASSIC_LD, + USE_LD_MAX + } selected_linker = USE_DEFAULT_LD; ++ + static const char *const ld_suffixes[USE_LD_MAX] = + { + "ld", + PLUGIN_LD_SUFFIX, + "ld.gold", + "ld.bfd", +- "ld.lld", +- "ld.mold" ++ LLD_NAME, ++ "ld.mold", ++ "ld-classic" + }; + static const char *const real_ld_suffix = "real-ld"; + static const char *const collect_ld_suffix = "collect-ld"; +@@ -953,14 +962,22 @@ main (int argc, char **argv) + if (selected_linker == USE_DEFAULT_LD) + selected_linker = USE_PLUGIN_LD; + } ++#if !defined (OBJECT_FORMAT_MACHO) + else if (strcmp (argv[i], "-fuse-ld=bfd") == 0) + selected_linker = USE_BFD_LD; + else if (strcmp (argv[i], "-fuse-ld=gold") == 0) + selected_linker = USE_GOLD_LD; ++#endif + else if (strcmp (argv[i], "-fuse-ld=lld") == 0) + selected_linker = USE_LLD_LD; + else if (strcmp (argv[i], "-fuse-ld=mold") == 0) + selected_linker = USE_MOLD_LD; ++#if defined (OBJECT_FORMAT_MACHO) ++ else if (strcmp (argv[i], "-fuse-ld=classic") == 0) ++ selected_linker = USE_CLASSIC_LD; ++#endif ++ else if (strcmp (argv[i], "-fuse-ld=") == 0) ++ selected_linker = USE_DEFAULT_LD; + else if (startswith (argv[i], "-o")) + { + /* Parse the output filename if it's given so that we can make +@@ -1052,7 +1069,8 @@ main (int argc, char **argv) + ld_file_name = 0; + #ifdef DEFAULT_LINKER + if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD || +- selected_linker == USE_LLD_LD || selected_linker == USE_MOLD_LD) ++ selected_linker == USE_LLD_LD || selected_linker == USE_MOLD_LD || ++ selected_linker == USE_CLASSIC_LD) + { + char *linker_name; + # ifdef HOST_EXECUTABLE_SUFFIX +@@ -2266,7 +2284,7 @@ write_aix_file (FILE *stream, struct id *list) + } + #endif + +-#ifdef OBJECT_FORMAT_NONE ++#if defined (OBJECT_FORMAT_NONE) || defined (OBJECT_FORMAT_MACHO) + + /* Check to make sure the file is an LTO object file. */ + +diff --git a/gcc/common.opt b/gcc/common.opt +index b055c7bd9ac..cf32af4bbaf 100644 +--- a/gcc/common.opt ++++ b/gcc/common.opt +@@ -2794,6 +2794,10 @@ fstack-usage + Common RejectNegative Var(flag_stack_usage) + Output stack usage information on a per-function basis. + ++fstack-use-cumulative-args ++Common RejectNegative Var(flag_stack_use_cumulative_args) Init(STACK_USE_CUMULATIVE_ARGS_INIT) ++Use cumulative args-based stack layout hooks. ++ + fstrength-reduce + Common Ignore + Does nothing. Preserved for backward compatibility. +@@ -2862,10 +2866,25 @@ Common Var(flag_tracer) Optimization + Perform superblock formation via tail duplication. + + ftrampolines +-Common Var(flag_trampolines) Init(0) ++Common Var(flag_trampolines) Init(HEAP_TRAMPOLINES_INIT) + For targets that normally need trampolines for nested functions, always + generate them instead of using descriptors. + ++ftrampoline-impl= ++Common Joined RejectNegative Enum(trampoline_impl) Var(flag_trampoline_impl) Init(HEAP_TRAMPOLINES_INIT ? TRAMPOLINE_IMPL_HEAP : TRAMPOLINE_IMPL_STACK) ++Whether trampolines are generated in executable memory rather than ++executable stack. ++ ++Enum ++Name(trampoline_impl) Type(enum trampoline_impl) UnknownError(unknown trampoline implementation %qs) ++ ++EnumValue ++Enum(trampoline_impl) String(stack) Value(TRAMPOLINE_IMPL_STACK) ++ ++EnumValue ++Enum(trampoline_impl) String(heap) Value(TRAMPOLINE_IMPL_HEAP) ++ ++ + ; Zero means that floating-point math operations cannot generate a + ; (user-visible) trap. This is the case, for example, in nonstop + ; IEEE 754 arithmetic. +@@ -3123,6 +3142,10 @@ fuse-ld=mold + Common Driver Negative(fuse-ld=mold) + Use the Modern linker (MOLD) linker instead of the default linker. + ++fuse-ld=classic ++Common Driver Negative(fuse-ld=classic) ++Use the ld-classic linker instead of the default linker. ++ + fuse-linker-plugin + Common Undocumented Var(flag_use_linker_plugin) + +diff --git a/gcc/common/config/aarch64/aarch64-common.cc b/gcc/common/config/aarch64/aarch64-common.cc +index 20bc4e1291b..5058d2feaf4 100644 +--- a/gcc/common/config/aarch64/aarch64-common.cc ++++ b/gcc/common/config/aarch64/aarch64-common.cc +@@ -301,8 +301,12 @@ aarch64_get_extension_string_for_isa_flags + + However, assemblers with Armv8-R AArch64 support should not have this + issue, so we don't need this fix when targeting Armv8-R. */ +- auto explicit_flags = (!(current_flags & AARCH64_FL_V8R) +- ? AARCH64_FL_CRC : 0); ++ aarch64_feature_flags explicit_flags = ++#ifndef DISABLE_AARCH64_AS_CRC_BUGFIX ++ (!(current_flags & AARCH64_ISA_V8R) ? AARCH64_FL_CRC : 0); ++#else ++ 0; ++#endif + + /* Add the features in isa_flags & ~current_flags using the smallest + possible number of extensions. We can do this by iterating over the +@@ -331,7 +335,10 @@ aarch64_get_extension_string_for_isa_flags + if (added & opt.flag_canonical) + { + outstr += "+"; +- outstr += opt.name; ++ if (startswith (opt.name, "rdm")) ++ outstr += "rdm"; ++ else ++ outstr += opt.name; + } + + /* Remove the features in current_flags & ~isa_flags. If the feature does +@@ -344,7 +351,10 @@ aarch64_get_extension_string_for_isa_flags + { + current_flags &= ~opt.flags_off; + outstr += "+no"; +- outstr += opt.name; ++ if (startswith (opt.name, "rdm")) ++ outstr += "rdm"; ++ else ++ outstr += opt.name; + } + + return outstr; +diff --git a/gcc/config.gcc b/gcc/config.gcc +index c3b73d05eb7..1b807618a1e 100644 +--- a/gcc/config.gcc ++++ b/gcc/config.gcc +@@ -1125,6 +1125,26 @@ case ${target} in + ;; + esac + ++# Figure out if we need to enable heap trampolines ++# and variadic functions handling. ++case ${target} in ++aarch64*-*-darwin2*) ++ # This applies to arm64 Darwin variadic funtions. ++ tm_defines="$tm_defines STACK_USE_CUMULATIVE_ARGS_INIT=1" ++ # Executable stack is forbidden. ++ tm_defines="$tm_defines HEAP_TRAMPOLINES_INIT=1" ++ ;; ++*-*-darwin2*) ++ tm_defines="$tm_defines STACK_USE_CUMULATIVE_ARGS_INIT=0" ++ # Currently, we do this for macOS 11 and above. ++ tm_defines="$tm_defines HEAP_TRAMPOLINES_INIT=1" ++ ;; ++*) ++ tm_defines="$tm_defines STACK_USE_CUMULATIVE_ARGS_INIT=0" ++ tm_defines="$tm_defines HEAP_TRAMPOLINES_INIT=0" ++ ;; ++esac ++ + case ${target} in + aarch64*-*-elf | aarch64*-*-fuchsia* | aarch64*-*-rtems*) + tm_file="${tm_file} elfos.h newlib-stdint.h" +@@ -1164,6 +1184,14 @@ aarch64*-*-elf | aarch64*-*-fuchsia* | aarch64*-*-rtems*) + done + TM_MULTILIB_CONFIG=`echo $TM_MULTILIB_CONFIG | sed 's/^,//'` + ;; ++aarch64-*-darwin* ) ++ tm_file="${tm_file} aarch64/aarch64-errata.h" ++ tmake_file="${tmake_file} aarch64/t-aarch64 aarch64/t-aarch64-darwin" ++ tm_defines="${tm_defines} TARGET_DEFAULT_ASYNC_UNWIND_TABLES=1" ++ tm_defines="${tm_defines} DISABLE_AARCH64_AS_CRC_BUGFIX=1" ++ # Choose a default CPU version that will work for all current releases. ++ with_cpu=${with_cpu:-apple-m1} ++ ;; + aarch64*-*-freebsd*) + tm_file="${tm_file} elfos.h ${fbsd_tm_file}" + tm_file="${tm_file} aarch64/aarch64-elf.h aarch64/aarch64-errata.h aarch64/aarch64-freebsd.h" +@@ -4125,8 +4153,8 @@ case "${target}" in + fi + for which in cpu arch tune; do + eval "val=\$with_$which" +- base_val=`echo $val | sed -e 's/\+.*//'` +- ext_val=`echo $val | sed -e 's/[a-z0-9.-]\+//'` ++ base_val=`echo $val | sed -E -e 's/\+.*//'` ++ ext_val=`echo $val | sed -E -e 's/[a-z0-9.-]+//'` + + if [ $which = arch ]; then + def=aarch64-arches.def +@@ -4158,9 +4186,9 @@ case "${target}" in + + while [ x"$ext_val" != x ] + do +- ext_val=`echo $ext_val | sed -e 's/\+//'` +- ext=`echo $ext_val | sed -e 's/\+.*//'` +- base_ext=`echo $ext | sed -e 's/^no//'` ++ ext_val=`echo $ext_val | sed -E -e 's/\+//'` ++ ext=`echo $ext_val | sed -E -e 's/\+.*//'` ++ base_ext=`echo $ext | sed -E -e 's/^no//'` + opt_line=`echo -e "$options_parsed" | \ + grep "^\"$base_ext\""` + +@@ -4171,7 +4199,7 @@ case "${target}" in + echo "Unknown extension used in --with-$which=$val" 1>&2 + exit 1 + fi +- ext_val=`echo $ext_val | sed -e 's/[a-z0-9]\+//'` ++ ext_val=`echo $ext_val | sed -E -e 's/[a-z0-9]+//'` + done + + true +diff --git a/gcc/config.in b/gcc/config.in +index 5281a12a707..b70b0bebda9 100644 +--- a/gcc/config.in ++++ b/gcc/config.in +@@ -49,6 +49,19 @@ + #endif + + ++/* Specify a runpath directory, additional to those provided by the compiler ++ */ ++#ifndef USED_FOR_TARGET ++#undef DARWIN_ADD_RPATH ++#endif ++ ++ ++/* Should add an extra runpath directory */ ++#ifndef USED_FOR_TARGET ++#undef DARWIN_DO_EXTRA_RPATH ++#endif ++ ++ + /* Define to enable the use of a default assembler. */ + #ifndef USED_FOR_TARGET + #undef DEFAULT_ASSEMBLER +@@ -634,8 +647,7 @@ + #endif + + +-/* Define if your Mac OS X assembler supports -mllvm -x86-pad-for-align=false. +- */ ++/* Define if your macOS assembler supports -mllvm -x86-pad-for-align=false. */ + #ifndef USED_FOR_TARGET + #undef HAVE_AS_MLLVM_X86_PAD_FOR_ALIGN + #endif +@@ -2201,6 +2213,12 @@ + #endif + + ++/* Define to 1 if ld64 supports '-demangle'. */ ++#ifndef USED_FOR_TARGET ++#undef LD64_HAS_DEMANGLE ++#endif ++ ++ + /* Define to 1 if ld64 supports '-export_dynamic'. */ + #ifndef USED_FOR_TARGET + #undef LD64_HAS_EXPORT_DYNAMIC +diff --git a/gcc/config/aarch64/aarch64-builtins.cc b/gcc/config/aarch64/aarch64-builtins.cc +index 8ad82841a4d..567fb10b7fb 100644 +--- a/gcc/config/aarch64/aarch64-builtins.cc ++++ b/gcc/config/aarch64/aarch64-builtins.cc +@@ -785,6 +785,8 @@ enum aarch64_builtins + AARCH64_RBIT, + AARCH64_RBITL, + AARCH64_RBITLL, ++ /* OS-specific */ ++ AARCH64_BUILTIN_CFSTRING, + AARCH64_BUILTIN_MAX + }; + +@@ -920,6 +922,9 @@ tree aarch64_fp16_ptr_type_node = NULL_TREE; + /* Back-end node type for brain float (bfloat) types. */ + tree aarch64_bf16_ptr_type_node = NULL_TREE; + ++/* Pointer to __float128 on Mach-O, where the 128b float is not long double. */ ++tree aarch64_float128_ptr_type_node = NULL_TREE; ++ + /* Wrapper around add_builtin_function. NAME is the name of the built-in + function, TYPE is the function type, CODE is the function subcode + (relative to AARCH64_BUILTIN_GENERAL), and ATTRS is the function +@@ -1695,6 +1700,29 @@ aarch64_init_bf16_types (void) + aarch64_bf16_ptr_type_node = build_pointer_type (bfloat16_type_node); + } + ++/* Initialize the backend REAL_TYPE type supporting __float128 on Mach-O, ++ as well as the related built-ins. */ ++static void ++aarch64_init_float128_types (void) ++{ ++ /* The __float128 type. The node has already been created as ++ _Float128, so for C we only need to register the __float128 name for ++ it. For C++, we create a distinct type which will mangle differently ++ (g) vs. _Float128 (DF128_) and behave backwards compatibly. */ ++ if (float128t_type_node == NULL_TREE) ++ { ++ float128t_type_node = make_node (REAL_TYPE); ++ TYPE_PRECISION (float128t_type_node) ++ = TYPE_PRECISION (float128_type_node); ++ SET_TYPE_MODE (float128t_type_node, TYPE_MODE (float128_type_node)); ++ layout_type (float128t_type_node); ++ } ++ lang_hooks.types.register_builtin_type (float128t_type_node, "__float128"); ++ ++ aarch64_float128_ptr_type_node = build_pointer_type (float128t_type_node); ++} ++ ++ + /* Pointer authentication builtins that will become NOP on legacy platform. + Currently, these builtins are for internal use only (libgcc EH unwinder). */ + +@@ -1983,8 +2011,9 @@ aarch64_general_init_builtins (void) + aarch64_init_fpsr_fpcr_builtins (); + + aarch64_init_fp16_types (); +- + aarch64_init_bf16_types (); ++ if (TARGET_MACHO) ++ aarch64_init_float128_types (); + + { + aarch64_simd_switcher simd; +@@ -2021,6 +2050,14 @@ aarch64_general_init_builtins (void) + handle_arm_acle_h (); + } + ++void ++aarch64_init_subtarget_builtins (void) ++{ ++#ifdef SUBTARGET_INIT_BUILTINS ++ SUBTARGET_INIT_BUILTINS; ++#endif ++} ++ + /* Implement TARGET_BUILTIN_DECL for the AARCH64_BUILTIN_GENERAL group. */ + tree + aarch64_general_builtin_decl (unsigned code, bool) +diff --git a/gcc/config/aarch64/aarch64-c.cc b/gcc/config/aarch64/aarch64-c.cc +index 578ec6f45b0..56c83ac05a7 100644 +--- a/gcc/config/aarch64/aarch64-c.cc ++++ b/gcc/config/aarch64/aarch64-c.cc +@@ -224,6 +224,16 @@ aarch64_cpu_cpp_builtins (cpp_reader *pfile) + { + aarch64_define_unconditional_macros (pfile); + aarch64_update_cpp_builtins (pfile); ++ ++ if (TARGET_MACHO) ++ { ++ builtin_define ("__builtin_copysignq=__builtin_copysignf128"); ++ builtin_define ("__builtin_fabsq=__builtin_fabsf128"); ++ builtin_define ("__builtin_huge_valq=__builtin_huge_valf128"); ++ builtin_define ("__builtin_infq=__builtin_inff128"); ++ builtin_define ("__builtin_nanq=__builtin_nanf128"); ++ builtin_define ("__builtin_nansq=__builtin_nansf128"); ++ } + } + + /* Hook to validate the current #pragma GCC target and set the state, and +@@ -359,4 +369,8 @@ aarch64_register_pragmas (void) + targetm.check_builtin_call = aarch64_check_builtin_call; + + c_register_pragma ("GCC", "aarch64", aarch64_pragma_aarch64); ++ ++#ifdef REGISTER_SUBTARGET_PRAGMAS ++ REGISTER_SUBTARGET_PRAGMAS (); ++#endif + } +diff --git a/gcc/config/aarch64/aarch64-cores.def b/gcc/config/aarch64/aarch64-cores.def +index fdda0697b88..2dc4ae6ce52 100644 +--- a/gcc/config/aarch64/aarch64-cores.def ++++ b/gcc/config/aarch64/aarch64-cores.def +@@ -165,6 +165,18 @@ AARCH64_CORE("cortex-a76.cortex-a55", cortexa76cortexa55, cortexa53, V8_2A, (F + /* Armv8-R Architecture Processors. */ + AARCH64_CORE("cortex-r82", cortexr82, cortexa53, V8R, (), cortexa53, 0x41, 0xd15, -1) + ++/* Apple (A12 and M) cores. ++ Apple implementer ID from xnu, ++ guesses for part #, guesses for scheduler ident, generic_armv8_a for costs. ++ A12 seems mostly 8.3, ++ M1 seems to be 8.4 + extras (see comments in option-extensions about f16fml), ++ M2 mostly 8.5 but with missing mandatory features. ++ M3 is pretty much the same as M2. */ ++AARCH64_CORE("apple-a12", applea12, cortexa53, V8_3A, (), cortexa53, 0x61, 0x12, -1) ++AARCH64_CORE("apple-m1", applem1, cortexa57, V8_4A, (F16, SB, SSBS), cortexa73, 0x61, 0x23, -1) ++AARCH64_CORE("apple-m2", applem2, cortexa57, V8_4A, (I8MM, BF16, F16, SB, SSBS), cortexa73, 0x61, 0x23, -1) ++AARCH64_CORE("apple-m3", applem3, cortexa57, V8_4A, (I8MM, BF16, F16, SB, SSBS), cortexa73, 0x61, 0x23, -1) ++ + /* Armv9.0-A Architecture Processors. */ + + /* Arm ('A') cores. */ +diff --git a/gcc/config/aarch64/aarch64-protos.h b/gcc/config/aarch64/aarch64-protos.h +index 32716f6cb15..a107f9ef069 100644 +--- a/gcc/config/aarch64/aarch64-protos.h ++++ b/gcc/config/aarch64/aarch64-protos.h +@@ -109,6 +109,14 @@ enum aarch64_symbol_type + SYMBOL_TLSLE24, + SYMBOL_TLSLE32, + SYMBOL_TLSLE48, ++ SYMBOL_MO_SMALL_ABS, ++ SYMBOL_MO_SMALL_PCR, ++ SYMBOL_MO_SMALL_GOT, ++ SYMBOL_MO_SMALL_TLS, ++ SYMBOL_MO_LARGE_ABS, ++ SYMBOL_MO_LARGE_PCR, ++ SYMBOL_MO_LARGE_GOT, ++ SYMBOL_MO_LARGE_TLS, + SYMBOL_FORCE_TO_MEM + }; + +@@ -745,6 +753,7 @@ void aarch64_post_cfi_startproc (void); + poly_int64 aarch64_initial_elimination_offset (unsigned, unsigned); + int aarch64_get_condition_code (rtx); + bool aarch64_address_valid_for_prefetch_p (rtx, bool); ++bool aarch64_address_valid_for_unscaled_prefetch_p (rtx, bool); + bool aarch64_bitmask_imm (unsigned HOST_WIDE_INT val, machine_mode); + unsigned HOST_WIDE_INT aarch64_and_split_imm1 (HOST_WIDE_INT val_in); + unsigned HOST_WIDE_INT aarch64_and_split_imm2 (HOST_WIDE_INT val_in); +@@ -775,7 +784,11 @@ bool aarch64_is_extend_from_extract (scalar_int_mode, rtx, rtx); + bool aarch64_is_long_call_p (rtx); + bool aarch64_is_noplt_call_p (rtx); + bool aarch64_label_mentioned_p (rtx); ++#if TARGET_MACHO ++void aarch64_darwin_declare_function_name (FILE *, const char*, tree ); ++#else + void aarch64_declare_function_name (FILE *, const char*, tree); ++#endif + void aarch64_asm_output_alias (FILE *, const tree, const tree); + void aarch64_asm_output_external (FILE *, tree, const char*); + bool aarch64_legitimate_pic_operand_p (rtx); +@@ -971,6 +984,7 @@ void aarch64_override_options_internal (struct gcc_options *); + + const char *aarch64_general_mangle_builtin_type (const_tree); + void aarch64_general_init_builtins (void); ++void aarch64_init_subtarget_builtins (void); + tree aarch64_general_fold_builtin (unsigned int, tree, unsigned int, tree *); + gimple *aarch64_general_gimple_fold_builtin (unsigned int, gcall *, + gimple_stmt_iterator *); +diff --git a/gcc/config/aarch64/aarch64-tune.md b/gcc/config/aarch64/aarch64-tune.md +index 9d46d38a292..3c3aa72d3de 100644 +--- a/gcc/config/aarch64/aarch64-tune.md ++++ b/gcc/config/aarch64/aarch64-tune.md +@@ -1,5 +1,5 @@ + ;; -*- buffer-read-only: t -*- + ;; Generated automatically by gentune.sh from aarch64-cores.def + (define_attr "tune" +- "cortexa34,cortexa35,cortexa53,cortexa57,cortexa72,cortexa73,thunderx,thunderxt88p1,thunderxt88,octeontx,octeontxt81,octeontxt83,thunderxt81,thunderxt83,ampere1,ampere1a,emag,xgene1,falkor,qdf24xx,exynosm1,phecda,thunderx2t99p1,vulcan,thunderx2t99,cortexa55,cortexa75,cortexa76,cortexa76ae,cortexa77,cortexa78,cortexa78ae,cortexa78c,cortexa65,cortexa65ae,cortexx1,cortexx1c,neoversen1,ares,neoversee1,octeontx2,octeontx2t98,octeontx2t96,octeontx2t93,octeontx2f95,octeontx2f95n,octeontx2f95mm,a64fx,tsv110,thunderx3t110,neoversev1,zeus,neoverse512tvb,saphira,cortexa57cortexa53,cortexa72cortexa53,cortexa73cortexa35,cortexa73cortexa53,cortexa75cortexa55,cortexa76cortexa55,cortexr82,cortexa510,cortexa710,cortexa715,cortexx2,cortexx3,neoversen2,cobalt100,neoversev2,demeter" ++ "cortexa34,cortexa35,cortexa53,cortexa57,cortexa72,cortexa73,thunderx,thunderxt88p1,thunderxt88,octeontx,octeontxt81,octeontxt83,thunderxt81,thunderxt83,ampere1,ampere1a,emag,xgene1,falkor,qdf24xx,exynosm1,phecda,thunderx2t99p1,vulcan,thunderx2t99,cortexa55,cortexa75,cortexa76,cortexa76ae,cortexa77,cortexa78,cortexa78ae,cortexa78c,cortexa65,cortexa65ae,cortexx1,cortexx1c,neoversen1,ares,neoversee1,octeontx2,octeontx2t98,octeontx2t96,octeontx2t93,octeontx2f95,octeontx2f95n,octeontx2f95mm,a64fx,tsv110,thunderx3t110,neoversev1,zeus,neoverse512tvb,saphira,cortexa57cortexa53,cortexa72cortexa53,cortexa73cortexa35,cortexa73cortexa53,cortexa75cortexa55,cortexa76cortexa55,cortexr82,applea12,applem1,applem2,applem3,cortexa510,cortexa710,cortexa715,cortexx2,cortexx3,neoversen2,cobalt100,neoversev2,demeter" + (const (symbol_ref "((enum attr_tune) aarch64_tune)"))) +diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc +index b8a4ab1b980..d2f503447ae 100644 +--- a/gcc/config/aarch64/aarch64.cc ++++ b/gcc/config/aarch64/aarch64.cc +@@ -295,8 +295,10 @@ static bool aarch64_vfp_is_call_or_return_candidate (machine_mode, + const_tree, + machine_mode *, int *, + bool *, bool); ++#if !TARGET_MACHO + static void aarch64_elf_asm_constructor (rtx, int) ATTRIBUTE_UNUSED; + static void aarch64_elf_asm_destructor (rtx, int) ATTRIBUTE_UNUSED; ++#endif + static void aarch64_override_options_after_change (void); + static bool aarch64_vector_mode_supported_p (machine_mode); + static int aarch64_address_cost (rtx, machine_mode, addr_space_t, bool); +@@ -2795,6 +2797,9 @@ static const struct attribute_spec aarch64_attribute_table[] = + { + /* { name, min_len, max_len, decl_req, type_req, fn_type_req, + affects_type_identity, handler, exclude } */ ++#ifdef SUBTARGET_ATTRIBUTE_TABLE ++ SUBTARGET_ATTRIBUTE_TABLE, ++#endif + { "aarch64_vector_pcs", 0, 0, false, true, true, true, + handle_aarch64_vector_pcs_attribute, NULL }, + { "arm_sve_vector_bits", 1, 1, false, true, false, true, +@@ -3949,7 +3954,7 @@ aarch64_hard_regno_mode_ok (unsigned regno, machine_mode mode) + if (known_le (GET_MODE_SIZE (mode), 8)) + return true; + if (known_le (GET_MODE_SIZE (mode), 16)) +- return (regno & 1) == 0; ++ return (regno & 1) == 0 || TARGET_MACHO; /* darwinpcs D.4 */ + } + else if (FP_REGNUM_P (regno)) + { +@@ -3995,8 +4000,10 @@ static bool + aarch64_takes_arguments_in_sve_regs_p (const_tree fntype) + { + CUMULATIVE_ARGS args_so_far_v; ++ /* This does not apply to variadic functions, so all the (currently ++ uncounted) arguments must be named. */ + aarch64_init_cumulative_args (&args_so_far_v, NULL_TREE, NULL_RTX, +- NULL_TREE, 0, true); ++ NULL_TREE, -1, true); + cumulative_args_t args_so_far = pack_cumulative_args (&args_so_far_v); + + for (tree chain = TYPE_ARG_TYPES (fntype); +@@ -4481,6 +4488,7 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm, + switch (type) + { + case SYMBOL_SMALL_ABSOLUTE: ++ case SYMBOL_MO_SMALL_PCR: + { + /* In ILP32, the mode of dest can be either SImode or DImode. */ + rtx tmp_reg = dest; +@@ -4491,6 +4499,21 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm, + if (can_create_pseudo_p ()) + tmp_reg = gen_reg_rtx (mode); + ++ if (TARGET_MACHO) ++ { ++ rtx sym, off; ++ split_const (imm, &sym, &off); ++ /* Negative offsets don't work, whether by intention is TBD. */ ++ if (INTVAL (off) < 0 || INTVAL (off) > 8 * 1024 * 1024) ++ { ++ emit_move_insn (tmp_reg, gen_rtx_HIGH (mode, sym)); ++ emit_insn (gen_add_losym (dest, tmp_reg, sym)); ++ /* FIXME: add the SI option if/when we support ilp32. */ ++ emit_insn (gen_adddi3 (dest, dest, off)); ++ return; ++ } ++ /* else small enough positive offset is OK. */ ++ } + emit_move_insn (tmp_reg, gen_rtx_HIGH (mode, copy_rtx (imm))); + emit_insn (gen_add_losym (dest, tmp_reg, imm)); + return; +@@ -4574,6 +4597,7 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm, + return; + } + ++ case SYMBOL_MO_SMALL_GOT: + case SYMBOL_SMALL_GOT_4G: + emit_insn (gen_rtx_SET (dest, imm)); + return; +@@ -6855,6 +6879,7 @@ aarch64_expand_mov_immediate (rtx dest, rtx imm) + case SYMBOL_SMALL_TLSIE: + case SYMBOL_SMALL_GOT_28K: + case SYMBOL_SMALL_GOT_4G: ++ case SYMBOL_MO_SMALL_GOT: + case SYMBOL_TINY_GOT: + case SYMBOL_TINY_TLSIE: + if (const_offset != 0) +@@ -6868,6 +6893,7 @@ aarch64_expand_mov_immediate (rtx dest, rtx imm) + /* FALLTHRU */ + + case SYMBOL_SMALL_ABSOLUTE: ++ case SYMBOL_MO_SMALL_PCR: + case SYMBOL_TINY_ABSOLUTE: + case SYMBOL_TLSLE12: + case SYMBOL_TLSLE24: +@@ -7449,6 +7475,7 @@ aarch64_return_in_memory (const_tree type, const_tree fndecl ATTRIBUTE_UNUSED) + gcc_unreachable (); + } + ++#if !TARGET_MACHO + static bool + aarch64_vfp_is_call_candidate (cumulative_args_t pcum_v, machine_mode mode, + const_tree type, int *nregs) +@@ -7458,6 +7485,7 @@ aarch64_vfp_is_call_candidate (cumulative_args_t pcum_v, machine_mode mode, + &pcum->aapcs_vfp_rmode, + nregs, NULL, pcum->silent_p); + } ++#endif + + /* Given MODE and TYPE of a function argument, return the alignment in + bits. The idea is to suppress any stronger alignment requested by +@@ -7481,7 +7509,7 @@ aarch64_function_arg_alignment (machine_mode mode, const_tree type, + if (integer_zerop (TYPE_SIZE (type))) + return 0; + +- gcc_assert (TYPE_MODE (type) == mode); ++ gcc_assert (TARGET_MACHO || TYPE_MODE (type) == mode); + + if (!AGGREGATE_TYPE_P (type)) + { +@@ -7641,6 +7669,14 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) + Both behaviors were wrong, but in different cases. */ + + pcum->aapcs_arg_processed = true; ++ if (TARGET_MACHO) ++ { ++ /* Set suitable defaults for queries. */ ++ pcum->darwinpcs_arg_boundary ++ = aarch64_function_arg_alignment (mode, type, &abi_break, ++ &abi_break_packed); ++ pcum->darwinpcs_arg_padding = BITS_PER_UNIT; ++ } + + pure_scalable_type_info pst_info; + if (type && pst_info.analyze_registers (type)) +@@ -7700,13 +7736,29 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) + /* No frontends can create types with variable-sized modes, so we + shouldn't be asked to pass or return them. */ + size = GET_MODE_SIZE (mode).to_constant (); ++ ++ if (TARGET_MACHO) ++ /* Since we can pack things on the stack, we need the unrounded size. */ ++ pcum->darwinpcs_stack_bytes = size; ++ + size = ROUND_UP (size, UNITS_PER_WORD); + + allocate_ncrn = (type) ? !(FLOAT_TYPE_P (type)) : !FLOAT_MODE_P (mode); ++ bool is_ha = false; ++#if !TARGET_MACHO + allocate_nvrn = aarch64_vfp_is_call_candidate (pcum_v, + mode, + type, + &nregs); ++#else ++ /* We care if the value is a homogenous aggregate when laying out the stack, ++ so use this call directly. */ ++ allocate_nvrn ++ = aarch64_vfp_is_call_or_return_candidate (mode, type, ++ &pcum->aapcs_vfp_rmode, ++ &nregs, &is_ha, ++ pcum->silent_p); ++#endif + gcc_assert (!sve_p || !allocate_nvrn); + + unsigned int alignment +@@ -7727,7 +7779,13 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) + if (!pcum->silent_p && !TARGET_FLOAT) + aarch64_err_no_fpadvsimd (mode); + +- if (nvrn + nregs <= NUM_FP_ARG_REGS) ++ if (TARGET_MACHO ++ && !arg.named) ++ { ++ pcum->aapcs_nextnvrn = NUM_FP_ARG_REGS; ++ goto on_stack; ++ } ++ else if (nvrn + nregs <= NUM_FP_ARG_REGS) + { + pcum->aapcs_nextnvrn = nvrn + nregs; + if (!aarch64_composite_type_p (type, mode)) +@@ -7757,6 +7815,7 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) + } + pcum->aapcs_reg = par; + } ++ pcum->darwinpcs_stack_bytes = 0; + return; + } + else +@@ -7773,14 +7832,24 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) + /* C6 - C9. though the sign and zero extension semantics are + handled elsewhere. This is the case where the argument fits + entirely general registers. */ ++ + if (allocate_ncrn && (ncrn + nregs <= NUM_ARG_REGS)) + { + gcc_assert (nregs == 0 || nregs == 1 || nregs == 2); + ++ if (TARGET_MACHO ++ && !arg.named) ++ { ++ pcum->aapcs_nextncrn = NUM_ARG_REGS; ++ goto on_stack; ++ } ++ + /* C.8 if the argument has an alignment of 16 then the NGRN is + rounded up to the next even number. */ + if (nregs == 2 +- && ncrn % 2) ++ && ncrn % 2 ++ /* Darwin PCS deletes rule C.8. */ ++ && !TARGET_MACHO) + { + /* Emit a warning if the alignment changed when taking the + 'packed' attribute into account. */ +@@ -7842,8 +7911,8 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) + } + pcum->aapcs_reg = par; + } +- + pcum->aapcs_nextncrn = ncrn + nregs; ++ pcum->darwinpcs_stack_bytes = 0; + return; + } + +@@ -7853,7 +7922,81 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) + /* The argument is passed on stack; record the needed number of words for + this argument and align the total size if necessary. */ + on_stack: +- pcum->aapcs_stack_words = size / UNITS_PER_WORD; ++ ++ if (TARGET_MACHO) ++ { ++ /* Darwin does not round up the allocation for smaller entities to 8 ++ bytes. It only requires the natural alignment for these. ++ ++ but we don't do this for: ++ * unnamed parms in variadic functions ++ * complex types ++ * unions ++ * aggregates (except for homogeneous ones which are handles as the ++ enclosed type). ++ each entry starts a new slot. ++ ++ 16 byte entities are naturally aligned on the stack. ++ There was no darwinpcs for GCC 9, so neither the implementation ++ change nor the warning should fire here (i.e. we do not need to check ++ if 16byte entities alter the stack size). */ ++ ++ gcc_checking_assert (arg.named == pcum->named_p); ++ pcum->darwinpcs_arg_padding = BITS_PER_UNIT; ++ if (!pcum->named_p ++ || TREE_CODE (type) == COMPLEX_TYPE ++ || (TREE_CODE (type) == RECORD_TYPE ++ && !is_ha && !SCALAR_FLOAT_MODE_P (pcum->aapcs_vfp_rmode)) ++ || TREE_CODE (type) == UNION_TYPE) ++ { ++ pcum->aapcs_stack_words = size / UNITS_PER_WORD; ++ pcum->darwinpcs_sub_word_offset = 0; ++ pcum->darwinpcs_sub_word_pos = 0; ++ pcum->darwinpcs_arg_boundary = MAX (alignment, PARM_BOUNDARY); ++ if (!pcum->named_p) ++ pcum->darwinpcs_arg_padding = PARM_BOUNDARY; ++ return; ++ } ++ ++ /* Updated sub-word offset aligned for the new object. ++ We are looking for the case that the new object will fit after some ++ existing object(s) in the same stack slot. In that case, we do not ++ need to add any more stack space for it. */ ++ int new_off ++ = ROUND_UP (pcum->darwinpcs_sub_word_pos, alignment / BITS_PER_UNIT); ++ ++ if (new_off >= UNITS_PER_WORD) ++ { ++ /* That exceeds a stack slot, start a new one. */ ++ pcum->darwinpcs_sub_word_offset = 0; ++ pcum->darwinpcs_sub_word_pos = 0; ++ new_off = 0; ++ } ++ /* This is the end of the new object. */ ++ int new_pos = new_off + pcum->darwinpcs_stack_bytes; ++ ++ if (pcum->darwinpcs_sub_word_pos == 0) ++ /* New stack slot, just allocate one or more words, and note where ++ the next arg will start. */ ++ pcum->aapcs_stack_words = size / UNITS_PER_WORD; ++ else if (new_pos <= UNITS_PER_WORD) ++ /* Old stack slot, object starts at new_off and goes to new_pos, we do ++ not add any stack space. */ ++ pcum->darwinpcs_sub_word_offset = new_off; ++ pcum->darwinpcs_sub_word_pos = new_pos; ++ pcum->darwinpcs_arg_boundary = alignment ; ++ if (pcum->last_named_p && new_pos > 0) ++ { ++ /* Round the last named arg to the start of the next stack slot. */ ++ if (new_pos <= 4) ++ pcum->darwinpcs_arg_padding = PARM_BOUNDARY; ++ else if (new_pos <= 6) ++ pcum->darwinpcs_arg_padding = 4 * BITS_PER_UNIT; ++ else if (pcum->darwinpcs_sub_word_pos <= 7) ++ pcum->darwinpcs_arg_padding = 2 * BITS_PER_UNIT; ++ } ++ return; ++ } + + if (warn_pcs_change + && abi_break_packed +@@ -7862,6 +8005,8 @@ on_stack: + inform (input_location, "parameter passing for argument of type " + "%qT changed in GCC 13.1", type); + ++ /* size was already rounded up to PARM_BOUNDARY. */ ++ pcum->aapcs_stack_words = size / UNITS_PER_WORD; + if (alignment == 16 * BITS_PER_UNIT) + { + int new_size = ROUND_UP (pcum->aapcs_stack_size, 16 / UNITS_PER_WORD); +@@ -7915,7 +8060,28 @@ aarch64_init_cumulative_args (CUMULATIVE_ARGS *pcum, + pcum->aapcs_arg_processed = false; + pcum->aapcs_stack_words = 0; + pcum->aapcs_stack_size = 0; ++ pcum->darwinpcs_stack_bytes = 0; ++ pcum->darwinpcs_sub_word_offset = 0; ++ pcum->darwinpcs_sub_word_pos = 0; ++ pcum->darwinpcs_arg_boundary = BITS_PER_UNIT; ++ pcum->darwinpcs_arg_padding = BITS_PER_UNIT; ++ /* If we have been invoked for incoming args, then n_named will have been ++ set to -1, but we should have a function decl - so pick up the named ++ count from that. If that fails, and we end up with -1, this effectively ++ corresponds to assuming that there is an arbitrary number of named ++ args. */ ++ pcum->darwinpcs_n_named = n_named; ++ if (n_named == (unsigned)-1 && fndecl) ++ { ++ tree fnt = TREE_TYPE (fndecl); ++ if (fnt && TYPE_ARG_TYPES (fnt)) ++ pcum->darwinpcs_n_named = list_length (TYPE_ARG_TYPES (fnt)); ++ } ++ pcum->darwinpcs_n_args_processed = 0; ++ pcum->named_p = pcum->darwinpcs_n_named != 0; ++ pcum->last_named_p = pcum->darwinpcs_n_named == 1; + pcum->silent_p = silent_p; ++ pcum->aapcs_vfp_rmode = VOIDmode; + + if (!silent_p + && !TARGET_FLOAT +@@ -7954,8 +8120,10 @@ aarch64_function_arg_advance (cumulative_args_t pcum_v, + || pcum->pcs_variant == ARM_PCS_SVE) + { + aarch64_layout_arg (pcum_v, arg); +- gcc_assert ((pcum->aapcs_reg != NULL_RTX) +- != (pcum->aapcs_stack_words != 0)); ++ pcum->darwinpcs_n_args_processed++; ++ gcc_assert (TARGET_MACHO ++ || (pcum->aapcs_reg != NULL_RTX) ++ != (pcum->aapcs_stack_words != 0)); + pcum->aapcs_arg_processed = false; + pcum->aapcs_ncrn = pcum->aapcs_nextncrn; + pcum->aapcs_nvrn = pcum->aapcs_nextnvrn; +@@ -7963,6 +8131,12 @@ aarch64_function_arg_advance (cumulative_args_t pcum_v, + pcum->aapcs_stack_size += pcum->aapcs_stack_words; + pcum->aapcs_stack_words = 0; + pcum->aapcs_reg = NULL_RTX; ++ pcum->darwinpcs_arg_boundary = BITS_PER_UNIT; ++ pcum->darwinpcs_arg_padding = BITS_PER_UNIT; ++ pcum->named_p ++ = pcum->darwinpcs_n_args_processed < pcum->darwinpcs_n_named; ++ pcum->last_named_p ++ = pcum->darwinpcs_n_args_processed + 1 == pcum->darwinpcs_n_named; + } + } + +@@ -7974,12 +8148,15 @@ aarch64_function_arg_regno_p (unsigned regno) + || (PR_REGNUM_P (regno) && regno < P0_REGNUM + NUM_PR_ARG_REGS)); + } + +-/* Implement FUNCTION_ARG_BOUNDARY. Every parameter gets at least +- PARM_BOUNDARY bits of alignment, but will be given anything up +- to STACK_BOUNDARY bits if the type requires it. This makes sure +- that both before and after the layout of each argument, the Next +- Stacked Argument Address (NSAA) will have a minimum alignment of +- 8 bytes. */ ++/* Implement FUNCTION_ARG_BOUNDARY. ++ For AAPCS64, Every parameter gets at least PARM_BOUNDARY bits of ++ alignment, but will be given anything up to STACK_BOUNDARY bits ++ if the type requires it. This makes sure that both before and after ++ the layout of each argument, the Next Stacked Argument Address (NSAA) ++ will have a minimum alignment of 8 bytes. ++ ++ For darwinpcs, this is only called to lower va_arg entries which are ++ always aligned as for AAPCS64. */ + + static unsigned int + aarch64_function_arg_boundary (machine_mode mode, const_tree type) +@@ -7991,8 +8168,107 @@ aarch64_function_arg_boundary (machine_mode mode, const_tree type) + &abi_break_packed); + /* We rely on aarch64_layout_arg and aarch64_gimplify_va_arg_expr + to emit warnings about ABI incompatibility. */ ++#if TARGET_MACHO ++ /* This can only work for unnamed args. */ ++ machine_mode comp_mode = VOIDmode; ++ int nregs; ++ bool is_ha; ++ aarch64_vfp_is_call_or_return_candidate (mode, type, &comp_mode, &nregs, ++ &is_ha, /*silent*/true); ++ if (TREE_CODE (type) == COMPLEX_TYPE ++ || (TREE_CODE (type) == RECORD_TYPE ++ && !is_ha && !SCALAR_FLOAT_MODE_P (comp_mode)) ++ || TREE_CODE (type) == UNION_TYPE) ++ return MIN (MAX (alignment, PARM_BOUNDARY), STACK_BOUNDARY); ++ return MIN (alignment, STACK_BOUNDARY); ++#else ++ alignment = MIN (MAX (alignment, PARM_BOUNDARY), STACK_BOUNDARY); ++ return alignment; ++#endif ++} ++ ++/* For Darwin, we want to use the arg boundary computed when laying out the ++ function arg, to cope with items packed on the stack and the different ++ rules applied to unnamed parms. */ ++ ++static unsigned int ++aarch64_function_arg_boundary_ca (machine_mode mode ATTRIBUTE_UNUSED, ++ const_tree type ATTRIBUTE_UNUSED, ++ cumulative_args_t ca ATTRIBUTE_UNUSED) ++{ ++ unsigned int abi_break; ++ unsigned int abi_break_packed; ++ unsigned int alignment = aarch64_function_arg_alignment (mode, type, ++ &abi_break, ++ &abi_break_packed); ++ /* We rely on aarch64_layout_arg and aarch64_gimplify_va_arg_expr ++ to emit warnings about ABI incompatibility. */ ++#if TARGET_MACHO ++ CUMULATIVE_ARGS *pcum = get_cumulative_args (ca); ++gcc_checking_assert (pcum->aapcs_arg_processed); ++ ++ bool named_p = pcum->darwinpcs_n_args_processed < pcum->darwinpcs_n_named; ++gcc_checking_assert (named_p == pcum->named_p); ++ machine_mode comp_mode = VOIDmode; ++ int nregs; ++ bool is_ha; ++ aarch64_vfp_is_call_or_return_candidate (mode, type, &comp_mode, &nregs, ++ &is_ha, /*silent*/true); ++ bool no_pack = (TREE_CODE (type) == COMPLEX_TYPE ++ || (TREE_CODE (type) == RECORD_TYPE ++ && !is_ha && !SCALAR_FLOAT_MODE_P (comp_mode)) ++ || TREE_CODE (type) == UNION_TYPE); ++ ++ bool in_regs = (pcum->aapcs_reg != NULL_RTX); ++ ++ if ((named_p && !no_pack) || in_regs) ++ ; /* Leave the alignment as natural. */ ++ else ++ alignment = MAX (alignment, PARM_BOUNDARY); ++gcc_checking_assert (alignment == pcum->darwinpcs_arg_boundary); ++ return MIN (alignment, STACK_BOUNDARY); ++ ++#else + alignment = MIN (MAX (alignment, PARM_BOUNDARY), STACK_BOUNDARY); + return alignment; ++#endif ++} ++ ++/* Implement TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA for darwinpcs which allows ++ non-standard passing of byte-aligned items [D.2]. This is done by pulling ++ the values out of the cumulative args struct. */ ++ ++static unsigned int ++aarch64_function_arg_round_boundary_ca (machine_mode mode ATTRIBUTE_UNUSED, ++ const_tree type ATTRIBUTE_UNUSED, ++ cumulative_args_t ca) ++{ ++ CUMULATIVE_ARGS *pcum = get_cumulative_args (ca); ++gcc_checking_assert (pcum->aapcs_arg_processed); ++ bool named_p = pcum->darwinpcs_n_args_processed < pcum->darwinpcs_n_named; ++gcc_checking_assert (named_p == pcum->named_p); ++ bool last_named_p = pcum->darwinpcs_n_args_processed + 1 == pcum->darwinpcs_n_named; ++gcc_checking_assert (last_named_p == pcum->last_named_p); ++ ++ unsigned boundary = BITS_PER_UNIT; ++ if (last_named_p && pcum->darwinpcs_sub_word_pos > 0) ++ { ++ /* Round the last named arg to the start of the next stack slot. */ ++ if (pcum->darwinpcs_sub_word_pos <= 4) ++ boundary = PARM_BOUNDARY; ++ else if (pcum->darwinpcs_sub_word_pos <= 6) ++ boundary = 4 * BITS_PER_UNIT; ++ else if (pcum->darwinpcs_sub_word_pos <= 7) ++ boundary = 2 * BITS_PER_UNIT; ++ } ++ else if (named_p) ++ /* Named args are naturally aligned, but with no rounding. */ ++ ; ++ else ++ /* un-named args are rounded to fill slots. */ ++ boundary = PARM_BOUNDARY; ++gcc_checking_assert (boundary == pcum->darwinpcs_arg_padding); ++ return boundary; + } + + /* Implement TARGET_GET_RAW_RESULT_MODE and TARGET_GET_RAW_ARG_MODE. */ +@@ -11091,6 +11367,7 @@ aarch64_classify_address (struct aarch64_address_info *info, + /* load literal: pc-relative constant pool entry. Only supported + for SI mode or larger. */ + info->type = ADDRESS_SYMBOLIC; ++ info->offset = NULL_RTX; + + if (!load_store_pair_p + && GET_MODE_SIZE (mode).is_constant (&const_size) +@@ -11098,6 +11375,7 @@ aarch64_classify_address (struct aarch64_address_info *info, + { + poly_int64 offset; + rtx sym = strip_offset_and_salt (x, &offset); ++ + return ((LABEL_REF_P (sym) + || (SYMBOL_REF_P (sym) + && CONSTANT_POOL_ADDRESS_P (sym) +@@ -11115,10 +11393,13 @@ aarch64_classify_address (struct aarch64_address_info *info, + poly_int64 offset; + HOST_WIDE_INT const_offset; + rtx sym = strip_offset_and_salt (info->offset, &offset); ++ + if (SYMBOL_REF_P (sym) + && offset.is_constant (&const_offset) + && (aarch64_classify_symbol (sym, const_offset) +- == SYMBOL_SMALL_ABSOLUTE)) ++ == SYMBOL_SMALL_ABSOLUTE ++ || aarch64_classify_symbol (sym, const_offset) ++ == SYMBOL_MO_SMALL_PCR)) + { + /* The symbol and offset must be aligned to the access size. */ + unsigned int align; +@@ -11168,6 +11449,55 @@ aarch64_address_valid_for_prefetch_p (rtx x, bool strict_p) + if (!res) + return false; + ++ /* For ELF targets using GAS, we emit prfm unconditionally; GAS will alter ++ the instruction to pick the prfum form where possible (i.e. when the ++ offset is in the range -256..255) and fall back to prfm otherwise. ++ We can reject cases where the offset exceeds the range usable by both ++ insns [-256..32760], or for offsets > 255 when the value is not divisible ++ by 8. ++ For Mach-O (Darwin) where the assembler uses the LLVM back end, that does ++ not yet do the substitution, so we must reject all prfum cases. */ ++ if (addr.offset) ++ { ++ HOST_WIDE_INT offs = INTVAL (addr.offset); ++ if (offs < -256) /* Out of range for both prfum and prfm. */ ++ return false; ++ if (offs > 32760) /* Out of range for prfm. */ ++ return false; ++ if (offs & 0x07) /* We cannot use prfm. */ ++ { ++ if (offs > 255) /* Out of range for prfum. */ ++ return false; ++ if (TARGET_MACHO) ++ return false; ++ } ++ if (TARGET_MACHO && offs < 0) ++ return false; ++ } ++ ++ /* ... except writeback forms. */ ++ return addr.type != ADDRESS_REG_WB; ++} ++ ++/* Return true if the address X is valid for a PRFUM instruction. ++ STRICT_P is true if we should do strict checking with ++ aarch64_classify_address. */ ++ ++bool ++aarch64_address_valid_for_unscaled_prefetch_p (rtx x, bool strict_p) ++{ ++ struct aarch64_address_info addr; ++ ++ /* PRFUM accepts the same addresses as DImode, but constrained to a range ++ -256..255. */ ++ bool res = aarch64_classify_address (&addr, x, DImode, strict_p); ++ if (!res) ++ return false; ++ ++ if (addr.offset && ((INTVAL (addr.offset) > 255) ++ || (INTVAL (addr.offset) < -256))) ++ return false; ++ + /* ... except writeback forms. */ + return addr.type != ADDRESS_REG_WB; + } +@@ -11881,6 +12211,144 @@ sizetochar (int size) + } + } + ++static void ++output_macho_postfix_expr (FILE *file, rtx x, const char *postfix) ++{ ++ char buf[256]; ++ ++ restart: ++ switch (GET_CODE (x)) ++ { ++ case PC: ++ putc ('.', file); ++ break; ++ ++ case SYMBOL_REF: ++ if (SYMBOL_REF_DECL (x)) ++ assemble_external (SYMBOL_REF_DECL (x)); ++ assemble_name (file, XSTR (x, 0)); ++ fprintf (file, "@%s", postfix); ++ break; ++ ++ case LABEL_REF: ++ x = label_ref_label (x); ++ /* Fall through. */ ++ case CODE_LABEL: ++ ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x)); ++ assemble_name (file, buf); ++ fprintf (file, "@%s", postfix); ++ break; ++ ++ case CONST_INT: ++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x)); ++ break; ++ ++ case CONST: ++ /* This used to output parentheses around the expression, ++ but that does not work on the 386 (either ATT or BSD assembler). */ ++ output_macho_postfix_expr (file, XEXP (x, 0), postfix); ++ break; ++ ++ case CONST_WIDE_INT: ++ /* We do not know the mode here so we have to use a round about ++ way to build a wide-int to get it printed properly. */ ++ { ++ wide_int w = wide_int::from_array (&CONST_WIDE_INT_ELT (x, 0), ++ CONST_WIDE_INT_NUNITS (x), ++ CONST_WIDE_INT_NUNITS (x) ++ * HOST_BITS_PER_WIDE_INT, ++ false); ++ print_decs (w, file); ++ } ++ break; ++ ++ case CONST_DOUBLE: ++ if (CONST_DOUBLE_AS_INT_P (x)) ++ { ++ /* We can use %d if the number is one word and positive. */ ++ if (CONST_DOUBLE_HIGH (x)) ++ fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX, ++ (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (x), ++ (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (x)); ++ else if (CONST_DOUBLE_LOW (x) < 0) ++ fprintf (file, HOST_WIDE_INT_PRINT_HEX, ++ (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (x)); ++ else ++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x)); ++ } ++ else ++ /* We can't handle floating point constants; ++ PRINT_OPERAND must handle them. */ ++ output_operand_lossage ("floating constant misused"); ++ break; ++ ++ case CONST_FIXED: ++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_FIXED_VALUE_LOW (x)); ++ break; ++ ++ case PLUS: ++ /* Some assemblers need integer constants to appear last (eg masm). */ ++ if (CONST_INT_P (XEXP (x, 0))) ++ { ++ output_macho_postfix_expr (file, XEXP (x, 1), postfix); ++ if (INTVAL (XEXP (x, 0)) >= 0) ++ fprintf (file, "+"); ++ output_addr_const (file, XEXP (x, 0)); ++ } ++ else ++ { ++ output_macho_postfix_expr (file, XEXP (x, 0), postfix); ++ if (!CONST_INT_P (XEXP (x, 1)) ++ || INTVAL (XEXP (x, 1)) >= 0) ++ fprintf (file, "+"); ++ output_addr_const (file, XEXP (x, 1)); ++ } ++ break; ++ ++ case MINUS: ++ /* Avoid outputting things like x-x or x+5-x, ++ since some assemblers can't handle that. */ ++ x = simplify_subtraction (x); ++ if (GET_CODE (x) != MINUS) ++ goto restart; ++ ++ output_macho_postfix_expr (file, XEXP (x, 0), postfix); ++ fprintf (file, "-"); ++ if ((CONST_INT_P (XEXP (x, 1)) && INTVAL (XEXP (x, 1)) >= 0) ++ || GET_CODE (XEXP (x, 1)) == PC ++ || GET_CODE (XEXP (x, 1)) == SYMBOL_REF) ++ output_addr_const (file, XEXP (x, 1)); ++ else ++ { ++ fputs (targetm.asm_out.open_paren, file); ++ output_addr_const (file, XEXP (x, 1)); ++ fputs (targetm.asm_out.close_paren, file); ++ } ++ break; ++ ++ case ZERO_EXTEND: ++ case SIGN_EXTEND: ++ case SUBREG: ++ case TRUNCATE: ++ output_addr_const (file, XEXP (x, 0)); ++ break; ++ ++ case UNSPEC: ++ if (XINT (x, 1) == UNSPEC_SALT_ADDR) ++ { ++ output_macho_postfix_expr (file, XVECEXP (x, 0, 0), postfix); ++ break; ++ } ++ /* FALLTHROUGH */ ++ default: ++ if (targetm.asm_out.output_addr_const_extra (file, x)) ++ break; ++ ++ output_operand_lossage ("invalid expression as operand"); ++ } ++ ++} ++ + /* Print operand X to file F in a target specific manner according to CODE. + The acceptable formatting commands given by CODE are: + 'c': An integer or symbol address without a preceding # +@@ -11949,6 +12417,12 @@ aarch64_print_operand (FILE *f, rtx x, int code) + } + break; + ++ case 'J': ++ output_macho_postfix_expr (f, x, "PAGEOFF"); ++ break; ++ case 'O': ++ output_macho_postfix_expr (f, x, "GOTPAGEOFF"); ++ break; + case 'e': + { + x = unwrap_const_vec_duplicate (x); +@@ -12272,7 +12746,7 @@ aarch64_print_operand (FILE *f, rtx x, int code) + case 'A': + if (GET_CODE (x) == HIGH) + x = XEXP (x, 0); +- ++#if !TARGET_MACHO + switch (aarch64_classify_symbolic_expression (x)) + { + case SYMBOL_SMALL_GOT_4G: +@@ -12303,9 +12777,26 @@ aarch64_print_operand (FILE *f, rtx x, int code) + break; + } + output_addr_const (asm_out_file, x); ++#endif ++#if TARGET_MACHO ++ switch (aarch64_classify_symbolic_expression (x)) ++ { ++ case SYMBOL_MO_SMALL_PCR: ++ output_macho_postfix_expr (asm_out_file, x, "PAGE"); ++ break; ++ case SYMBOL_MO_SMALL_GOT: ++ output_macho_postfix_expr (asm_out_file, x, "GOTPAGE"); ++ break; ++ default: ++ /* large code model unimplemented. */ ++ gcc_unreachable (); ++ break; ++ } ++#endif + break; + + case 'L': ++#if !TARGET_MACHO + switch (aarch64_classify_symbolic_expression (x)) + { + case SYMBOL_SMALL_GOT_4G: +@@ -12343,10 +12834,12 @@ aarch64_print_operand (FILE *f, rtx x, int code) + default: + break; + } ++#endif + output_addr_const (asm_out_file, x); + break; + + case 'G': ++#if !TARGET_MACHO + switch (aarch64_classify_symbolic_expression (x)) + { + case SYMBOL_TLSLE24: +@@ -12355,6 +12848,7 @@ aarch64_print_operand (FILE *f, rtx x, int code) + default: + break; + } ++#endif + output_addr_const (asm_out_file, x); + break; + +@@ -12504,8 +12998,13 @@ aarch64_print_address_internal (FILE *f, machine_mode mode, rtx x, + break; + + case ADDRESS_LO_SUM: ++#if TARGET_MACHO ++ asm_fprintf (f, "[%s, #", reg_names [REGNO (addr.base)]); ++ output_macho_postfix_expr (f, addr.offset, "PAGEOFF"); ++#else + asm_fprintf (f, "[%s, #:lo12:", reg_names [REGNO (addr.base)]); + output_addr_const (f, addr.offset); ++#endif + asm_fprintf (f, "]"); + return true; + +@@ -12786,6 +13285,26 @@ aarch64_secondary_memory_needed (machine_mode mode, reg_class_t class1, + return false; + } + ++#if TARGET_MACHO ++/* Implement TARGET_FRAME_POINTER_REQUIRED. */ ++ ++static bool ++aarch64_darwin_frame_pointer_required () ++{ ++ if (crtl->calls_eh_return) ++ return true; ++ ++ /* Not used in leaf functions (unless forced). */ ++ if (flag_omit_leaf_frame_pointer && leaf_function_p ()) ++ return false; ++ ++ /* NOTE: We are allowing the user to force omission of the frame ++ pointer, (despite that it is not ABI-compliant). */ ++ ++ return flag_omit_frame_pointer != 1; ++} ++#endif ++ + static bool + aarch64_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to) + { +@@ -13003,6 +13522,8 @@ aarch64_asm_output_labelref (FILE* f, const char *name) + asm_fprintf (f, "%U%s", name); + } + ++#if !TARGET_MACHO ++ + static void + aarch64_elf_asm_constructor (rtx symbol, int priority) + { +@@ -13042,6 +13563,7 @@ aarch64_elf_asm_destructor (rtx symbol, int priority) + assemble_aligned_integer (POINTER_BYTES, symbol); + } + } ++#endif + + const char* + aarch64_output_casesi (rtx *operands) +@@ -13145,7 +13667,11 @@ aarch64_select_rtx_section (machine_mode mode, + if (aarch64_can_use_per_function_literal_pools_p ()) + return function_section (current_function_decl); + ++#if TARGET_MACHO ++ return machopic_select_rtx_section (mode, x, align); ++#else + return default_elf_select_rtx_section (mode, x, align); ++#endif + } + + /* Implement ASM_OUTPUT_POOL_EPILOGUE. */ +@@ -15369,15 +15895,17 @@ aarch64_init_builtins () + { + aarch64_general_init_builtins (); + aarch64_sve::init_builtins (); +-#ifdef SUBTARGET_INIT_BUILTINS +- SUBTARGET_INIT_BUILTINS; +-#endif ++ aarch64_init_subtarget_builtins (); + } + + /* Implement TARGET_FOLD_BUILTIN. */ + static tree + aarch64_fold_builtin (tree fndecl, int nargs, tree *args, bool) + { ++#ifdef SUBTARGET_FOLD_BUILTIN ++ if (tree res = SUBTARGET_FOLD_BUILTIN (fndecl, nargs, args, false)) ++ return res; ++#endif + unsigned int code = DECL_MD_FUNCTION_CODE (fndecl); + unsigned int subcode = code >> AARCH64_BUILTIN_SHIFT; + tree type = TREE_TYPE (TREE_TYPE (fndecl)); +@@ -18561,10 +19089,14 @@ initialize_aarch64_code_model (struct gcc_options *opts) + } + break; + case AARCH64_CMODEL_LARGE: +- if (opts->x_flag_pic) ++ if (TARGET_MACHO) ++ /* We need to implement fPIC here (arm64_32 also accepts the large ++ model). */ ++ sorry ("code model %qs not supported yet", "large"); ++ else if (opts->x_flag_pic) + sorry ("code model %qs with %<-f%s%>", "large", + opts->x_flag_pic > 1 ? "PIC" : "pic"); +- if (opts->x_aarch64_abi == AARCH64_ABI_ILP32) ++ else if (opts->x_aarch64_abi == AARCH64_ABI_ILP32) + sorry ("code model %qs not supported in ilp32 mode", "large"); + break; + case AARCH64_CMODEL_TINY_PIC: +@@ -19450,7 +19982,9 @@ aarch64_classify_symbol (rtx x, HOST_WIDE_INT offset) + case AARCH64_CMODEL_SMALL_SPIC: + case AARCH64_CMODEL_SMALL_PIC: + case AARCH64_CMODEL_SMALL: +- return SYMBOL_SMALL_ABSOLUTE; ++ return TARGET_MACHO ++ ? SYMBOL_MO_SMALL_PCR ++ : SYMBOL_SMALL_ABSOLUTE; + + default: + gcc_unreachable (); +@@ -19486,10 +20020,22 @@ aarch64_classify_symbol (rtx x, HOST_WIDE_INT offset) + + return SYMBOL_TINY_ABSOLUTE; + +- + case AARCH64_CMODEL_SMALL_SPIC: + case AARCH64_CMODEL_SMALL_PIC: + case AARCH64_CMODEL_SMALL: ++#if TARGET_MACHO ++ if (TARGET_MACHO) ++ { ++ /* Constant pool addresses are always TU-local and PC- ++ relative. We indirect common, external and weak ++ symbols (but weak only if not hidden). */ ++ if (!CONSTANT_POOL_ADDRESS_P (x) ++ && (MACHO_SYMBOL_MUST_INDIRECT_P (x) ++ || !aarch64_symbol_binds_local_p (x))) ++ return SYMBOL_MO_SMALL_GOT; ++ } ++ else ++#endif + if ((flag_pic || SYMBOL_REF_WEAK (x)) + && !aarch64_symbol_binds_local_p (x)) + return aarch64_cmodel == AARCH64_CMODEL_SMALL_SPIC +@@ -19501,7 +20047,8 @@ aarch64_classify_symbol (rtx x, HOST_WIDE_INT offset) + || offset_within_block_p (x, offset))) + return SYMBOL_FORCE_TO_MEM; + +- return SYMBOL_SMALL_ABSOLUTE; ++ return TARGET_MACHO ? SYMBOL_MO_SMALL_PCR ++ : SYMBOL_SMALL_ABSOLUTE; + + case AARCH64_CMODEL_LARGE: + /* This is alright even in PIC code as the constant +@@ -19631,7 +20178,10 @@ static GTY(()) tree va_list_type; + void *__vr_top; + int __gr_offs; + int __vr_offs; +- }; */ ++ }; ++ ++ darwinpcs uses 'char *' for the va_list (in common with other platform ++ ports). */ + + static tree + aarch64_build_builtin_va_list (void) +@@ -19639,6 +20189,13 @@ aarch64_build_builtin_va_list (void) + tree va_list_name; + tree f_stack, f_grtop, f_vrtop, f_groff, f_vroff; + ++ /* darwinpcs uses a simple char * for this. */ ++ if (TARGET_MACHO) ++ { ++ va_list_type = build_pointer_type (char_type_node); ++ return va_list_type; ++ } ++ + /* Create the type. */ + va_list_type = lang_hooks.types.make_type (RECORD_TYPE); + /* Give it the required name. */ +@@ -19710,6 +20267,13 @@ aarch64_expand_builtin_va_start (tree valist, rtx nextarg ATTRIBUTE_UNUSED) + int vr_save_area_size = cfun->va_list_fpr_size; + int vr_offset; + ++ /* darwinpcs uses the default, char * va_list impl. */ ++ if (TARGET_MACHO) ++ { ++ std_expand_builtin_va_start (valist, nextarg); ++ return; ++ } ++ + cum = &crtl->args.info; + if (cfun->va_list_gpr_size) + gr_save_area_size = MIN ((NUM_ARG_REGS - cum->aapcs_ncrn) * UNITS_PER_WORD, +@@ -19800,6 +20364,9 @@ aarch64_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p, + HOST_WIDE_INT size, rsize, adjust, align; + tree t, u, cond1, cond2; + ++ if (TARGET_MACHO) ++ return std_gimplify_va_arg_expr (valist, type, pre_p, post_p); ++ + indirect_p = pass_va_arg_by_reference (type); + if (indirect_p) + type = build_pointer_type (type); +@@ -19990,8 +20557,18 @@ aarch64_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p, + field_ptr_t = double_ptr_type_node; + break; + case E_TFmode: +- field_t = long_double_type_node; +- field_ptr_t = long_double_ptr_type_node; ++ if (TARGET_MACHO) ++ { ++ /* Darwin has __float128, and long double is the same as ++ double. */ ++ field_t = float128_type_node; ++ field_ptr_t = aarch64_float128_ptr_type_node; ++ } ++ else ++ { ++ field_t = long_double_type_node; ++ field_ptr_t = long_double_ptr_type_node; ++ } + break; + case E_SDmode: + field_t = dfloat32_type_node; +@@ -20074,6 +20651,9 @@ aarch64_setup_incoming_varargs (cumulative_args_t cum_v, + int gr_saved = cfun->va_list_gpr_size; + int vr_saved = cfun->va_list_fpr_size; + ++ if (TARGET_MACHO) ++ return default_setup_incoming_varargs (cum_v, arg, pretend_size, no_rtl); ++ + /* The caller has advanced CUM up to, but not beyond, the last named + argument. Advance a local copy of CUM past the last "real" named + argument, to find out how many registers are left over. */ +@@ -20906,6 +21486,12 @@ aarch64_autovectorize_vector_modes (vector_modes *modes, bool) + static const char * + aarch64_mangle_type (const_tree type) + { ++ /* The darwinpcs ABI documents say that "__va_list" has to be ++ mangled as char *. */ ++ if (TARGET_MACHO ++ && lang_hooks.types_compatible_p (CONST_CAST_TREE (type), va_list_type)) ++ return "Pc"; ++ + /* The AArch64 ABI documents say that "__va_list" has to be + mangled as if it is in the "std" namespace. */ + if (lang_hooks.types_compatible_p (CONST_CAST_TREE (type), va_list_type)) +@@ -20922,6 +21508,12 @@ aarch64_mangle_type (const_tree type) + return "Dh"; + } + ++ /* __float128 is mangled as "g" on darwin. _Float128 is not mangled here, ++ but handled in common code (as "DF128_"). */ ++ if (TARGET_MACHO && TYPE_MODE (type) == TFmode ++ && TYPE_MAIN_VARIANT (type) == float128t_type_node) ++ return "g"; ++ + /* Mangle AArch64-specific internal types. TYPE_NAME is non-NULL_TREE for + builtin types. */ + if (TYPE_NAME (type) != NULL) +@@ -21615,7 +22207,8 @@ aarch64_mov_operand_p (rtx x, machine_mode mode) + + /* GOT accesses are valid moves. */ + if (SYMBOL_REF_P (x) +- && aarch64_classify_symbolic_expression (x) == SYMBOL_SMALL_GOT_4G) ++ && (aarch64_classify_symbolic_expression (x) == SYMBOL_SMALL_GOT_4G ++ || aarch64_classify_symbolic_expression (x) == SYMBOL_MO_SMALL_GOT)) + return true; + + if (SYMBOL_REF_P (x) && mode == DImode && CONSTANT_ADDRESS_P (x)) +@@ -22759,12 +23352,8 @@ aarch64_asm_output_variant_pcs (FILE *stream, const tree decl, const char* name) + static std::string aarch64_last_printed_arch_string; + static std::string aarch64_last_printed_tune_string; + +-/* Implement ASM_DECLARE_FUNCTION_NAME. Output the ISA features used +- by the function fndecl. */ +- +-void +-aarch64_declare_function_name (FILE *stream, const char* name, +- tree fndecl) ++static void ++aarch64_function_options_preamble (tree fndecl) + { + tree target_parts = DECL_FUNCTION_SPECIFIC_TARGET (fndecl); + +@@ -22803,15 +23392,60 @@ aarch64_declare_function_name (FILE *stream, const char* name, + this_tune->name); + aarch64_last_printed_tune_string = this_tune->name; + } ++} ++ ++/* Implement ASM_DECLARE_FUNCTION_NAME. Output the ISA features used ++ by the function fndecl. */ + ++#if TARGET_MACHO ++void ++aarch64_darwin_declare_function_name (FILE *stream, const char* name, ++ tree fndecl) ++{ ++ gcc_checking_assert (TREE_CODE (fndecl) == FUNCTION_DECL); ++ gcc_checking_assert (!DECL_COMMON (fndecl)); ++ ++ /* Update .arch and .tune as needed. */ ++ aarch64_function_options_preamble (fndecl); ++ ++ /* Darwin does not emit pcs variant info. */ ++ ++ rtx decl_rtx = XEXP (DECL_RTL (fndecl), 0); ++ if (GET_CODE (decl_rtx) != SYMBOL_REF) ++ name = IDENTIFIER_POINTER (DECL_NAME (fndecl)); ++ ++ if (! DECL_WEAK (fndecl) ++ && ((TREE_STATIC (fndecl) && !TREE_PUBLIC (fndecl)) ++ || DECL_INITIAL (fndecl))) ++ machopic_define_symbol (DECL_RTL (fndecl)); ++ if ((TREE_STATIC (fndecl) && !TREE_PUBLIC (fndecl)) ++ || DECL_INITIAL (fndecl)) ++ (* targetm.encode_section_info) (fndecl, DECL_RTL (fndecl), false); ++ ASM_OUTPUT_FUNCTION_LABEL (stream, name, fndecl); ++ ++ cfun->machine->label_is_assembled = true; ++} ++ ++#else ++ ++void ++aarch64_declare_function_name (FILE *stream, const char* name, ++ tree fndecl) ++{ ++ /* Update .arch and .tune as needed. */ ++ aarch64_function_options_preamble (fndecl); ++ /* Emit any necessary pcs information. */ + aarch64_asm_output_variant_pcs (stream, fndecl, name); + + /* Don't forget the type directive for ELF. */ ++#ifdef ASM_OUTPUT_TYPE_DIRECTIVE + ASM_OUTPUT_TYPE_DIRECTIVE (stream, name, "function"); +- ASM_OUTPUT_LABEL (stream, name); ++#endif ++ ASM_OUTPUT_FUNCTION_LABEL (stream, name, fndecl); + + cfun->machine->label_is_assembled = true; + } ++#endif + + /* Implement PRINT_PATCHABLE_FUNCTION_ENTRY. */ + +@@ -22868,12 +23502,17 @@ aarch64_output_patchable_area (unsigned int patch_area_size, bool record_p) + /* Implement ASM_OUTPUT_DEF_FROM_DECLS. Output .variant_pcs for aliases. */ + + void +-aarch64_asm_output_alias (FILE *stream, const tree decl, const tree target) ++aarch64_asm_output_alias (FILE *stream, const tree decl, ++ const tree target ATTRIBUTE_UNUSED) + { + const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0); ++#ifdef ASM_OUTPUT_DEF + const char *value = IDENTIFIER_POINTER (target); ++#endif + aarch64_asm_output_variant_pcs (stream, decl, name); ++#ifdef ASM_OUTPUT_DEF + ASM_OUTPUT_DEF (stream, name, value); ++#endif + } + + /* Implement ASM_OUTPUT_EXTERNAL. Output .variant_pcs for undefined +@@ -22919,6 +23558,9 @@ aarch64_start_file (void) + aarch64_last_printed_arch_string.c_str ()); + + default_file_start (); ++#if TARGET_MACHO ++ darwin_file_start (); ++#endif + } + + /* Emit load exclusive. */ +@@ -23396,6 +24038,10 @@ aarch64_float_const_representable_p (rtx x) + || REAL_VALUE_MINUS_ZERO (r)) + return false; + ++ /* For BFmode, only handle 0.0. */ ++ if (GET_MODE (x) == BFmode) ++ return real_iszero (&r, false); ++ + /* Extract exponent. */ + r = real_value_abs (&r); + exponent = REAL_EXP (&r); +@@ -23499,6 +24145,16 @@ aarch64_output_simd_mov_immediate (rtx const_vector, unsigned width, + } + + gcc_assert (CONST_INT_P (info.u.mov.value)); ++ unsigned HOST_WIDE_INT value = UINTVAL (info.u.mov.value); ++ ++ /* We have signed chars which can result in a sign-extended 8bit value ++ which is then emitted as an unsigned hex value, and the LLVM back end ++ assembler rejects that as being too big. */ ++ if (TARGET_MACHO && (known_eq (GET_MODE_BITSIZE (info.elt_mode), 8))) ++ { ++ unsigned HOST_WIDE_INT mask = (1U << GET_MODE_BITSIZE (info.elt_mode))-1; ++ value &= mask; ++ } + + if (which == AARCH64_CHECK_MOV) + { +@@ -23507,16 +24163,16 @@ aarch64_output_simd_mov_immediate (rtx const_vector, unsigned width, + ? "msl" : "lsl"); + if (lane_count == 1) + snprintf (templ, sizeof (templ), "%s\t%%d0, " HOST_WIDE_INT_PRINT_HEX, +- mnemonic, UINTVAL (info.u.mov.value)); ++ mnemonic, value); + else if (info.u.mov.shift) + snprintf (templ, sizeof (templ), "%s\t%%0.%d%c, " + HOST_WIDE_INT_PRINT_HEX ", %s %d", mnemonic, lane_count, +- element_char, UINTVAL (info.u.mov.value), shift_op, ++ element_char, value, shift_op, + info.u.mov.shift); + else + snprintf (templ, sizeof (templ), "%s\t%%0.%d%c, " + HOST_WIDE_INT_PRINT_HEX, mnemonic, lane_count, +- element_char, UINTVAL (info.u.mov.value)); ++ element_char, value); + } + else + { +@@ -23525,12 +24181,12 @@ aarch64_output_simd_mov_immediate (rtx const_vector, unsigned width, + if (info.u.mov.shift) + snprintf (templ, sizeof (templ), "%s\t%%0.%d%c, #" + HOST_WIDE_INT_PRINT_DEC ", %s #%d", mnemonic, lane_count, +- element_char, UINTVAL (info.u.mov.value), "lsl", ++ element_char, value, "lsl", + info.u.mov.shift); + else + snprintf (templ, sizeof (templ), "%s\t%%0.%d%c, #" + HOST_WIDE_INT_PRINT_DEC, mnemonic, lane_count, +- element_char, UINTVAL (info.u.mov.value)); ++ element_char, value); + } + return templ; + } +@@ -26728,7 +27384,8 @@ aarch64_libgcc_floating_mode_supported_p (scalar_float_mode mode) + } + + /* Implement TARGET_SCALAR_MODE_SUPPORTED_P - return TRUE +- if MODE is [BH]Fmode, and punt to the generic implementation otherwise. */ ++ if MODE is [BH]Fmode, or TFmode on Mach-O, and punt to the generic ++ implementation otherwise. */ + + static bool + aarch64_scalar_mode_supported_p (scalar_mode mode) +@@ -26736,7 +27393,7 @@ aarch64_scalar_mode_supported_p (scalar_mode mode) + if (DECIMAL_FLOAT_MODE_P (mode)) + return default_decimal_float_supported_p (); + +- return ((mode == HFmode || mode == BFmode) ++ return ((mode == HFmode || mode == BFmode || (mode == TFmode && TARGET_MACHO)) + ? true + : default_scalar_mode_supported_p (mode)); + } +@@ -27476,19 +28133,37 @@ aarch64_sls_emit_shared_blr_thunks (FILE *out_file) + continue; + + const char *name = indirect_symbol_names[regnum]; +- switch_to_section (get_named_section (decl, NULL, 0)); ++ /* If the target uses a unique section for this switch to it. */ ++ if (DECL_SECTION_NAME (decl)) ++ switch_to_section (get_named_section (decl, NULL, 0)); ++ else ++ switch_to_section (text_section); + ASM_OUTPUT_ALIGN (out_file, 2); +- targetm.asm_out.globalize_label (out_file, name); ++ if (!TARGET_MACHO) ++ targetm.asm_out.globalize_label (out_file, name); ++#ifdef ASM_OUTPUT_TYPE_DIRECTIVE ++ ASM_OUTPUT_TYPE_DIRECTIVE (out_file, name, "function"); ++#endif ++ if (TARGET_MACHO) ++ { ++#ifdef ASM_WEAKEN_DECL ++ if (DECL_WEAK (decl)) ++ ASM_WEAKEN_DECL (out_file, decl, name, 0); ++ else ++#endif ++ targetm.asm_out.globalize_decl_name (out_file, decl); ++ } + /* Only emits if the compiler is configured for an assembler that can + handle visibility directives. */ + targetm.asm_out.assemble_visibility (decl, VISIBILITY_HIDDEN); +- ASM_OUTPUT_TYPE_DIRECTIVE (out_file, name, "function"); + ASM_OUTPUT_LABEL (out_file, name); + aarch64_sls_emit_function_stub (out_file, regnum); + /* Use the most conservative target to ensure it can always be used by any + function in the translation unit. */ + asm_fprintf (out_file, "\tdsb\tsy\n\tisb\n"); ++#ifdef ASM_DECLARE_FUNCTION_SIZE + ASM_DECLARE_FUNCTION_SIZE (out_file, name, decl); ++#endif + } + } + +@@ -27519,6 +28194,60 @@ aarch64_indirect_call_asm (rtx addr) + return ""; + } + ++#if TARGET_MACHO ++/* This handles the promotion of function return values. ++ It also handles function args under two specific curcumstances: ++ - called from combine with a register argument ++ - caller for a libcall with type == NULL. ++ The remaining cases for argument promotion are handled with access to ++ cumulative args data, below. */ ++machine_mode ++aarch64_darwin_promote_fn_mode (const_tree type, machine_mode mode, ++ int *punsignedp, ++ const_tree funtype ATTRIBUTE_UNUSED, ++ int for_return ATTRIBUTE_UNUSED) ++{ ++ /* With the amended use of promote using cargs, the only cases that arrive ++ here with for_return == 0 are from combine (where the value is definitely ++ in a register) and for libcalls, where type == NULL. We want to promote ++ function return values in the callee, so this becomes pretty much ++ unconditional now. */ ++ if (type != NULL_TREE) ++ return promote_mode (type, mode, punsignedp); ++ return mode; ++} ++ ++/* Ensure that we only promote the mode of named parms when they are passed in ++ a register. Named values passed on the stack retain their original mode and ++ alignment. */ ++machine_mode ++aarch64_darwin_promote_function_mode_ca (cumulative_args_t ca, ++ function_arg_info arg, ++ const_tree funtype ATTRIBUTE_UNUSED, ++ int *punsignedp, ++ int for_return ATTRIBUTE_UNUSED) ++{ ++ tree type = arg.type; ++ machine_mode mode = arg.mode; ++ machine_mode new_mode = promote_mode (type, mode, punsignedp); ++ if (new_mode == mode || arg.named == false ++ || GET_MODE_CLASS (new_mode) != MODE_INT ++ || known_gt (GET_MODE_SIZE (new_mode), 4)) ++ return new_mode; ++ ++ CUMULATIVE_ARGS *pcum = get_cumulative_args (ca); ++ /* Make sure that changes in assumption do not get missed. */ ++ gcc_checking_assert (for_return == 0 && new_mode == SImode ++ && !pcum->aapcs_arg_processed); ++ /* We have a named integer value that fits in a reg; if there's one available ++ then promote the value. */ ++ if (pcum->aapcs_ncrn < 8) ++ return new_mode; ++ return mode; ++} ++ ++#endif ++ + /* Target-specific selftests. */ + + #if CHECKING_P +@@ -27681,6 +28410,15 @@ aarch64_run_selftests (void) + #undef TARGET_ASM_ALIGNED_SI_OP + #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t" + ++#if TARGET_MACHO ++#undef TARGET_ASM_UNALIGNED_HI_OP ++#define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t" ++#undef TARGET_ASM_UNALIGNED_SI_OP ++#define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t" ++#undef TARGET_ASM_UNALIGNED_DI_OP ++#define TARGET_ASM_UNALIGNED_DI_OP "\t.quad\t" ++#endif ++ + #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK + #define TARGET_ASM_CAN_OUTPUT_MI_THUNK \ + hook_bool_const_tree_hwi_hwi_const_tree_true +@@ -27767,6 +28505,12 @@ aarch64_run_selftests (void) + #undef TARGET_FUNCTION_ARG_BOUNDARY + #define TARGET_FUNCTION_ARG_BOUNDARY aarch64_function_arg_boundary + ++#undef TARGET_FUNCTION_ARG_BOUNDARY_CA ++#define TARGET_FUNCTION_ARG_BOUNDARY_CA aarch64_function_arg_boundary_ca ++ ++#undef TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA ++#define TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA aarch64_function_arg_round_boundary_ca ++ + #undef TARGET_FUNCTION_ARG_PADDING + #define TARGET_FUNCTION_ARG_PADDING aarch64_function_arg_padding + +@@ -28091,7 +28835,7 @@ aarch64_libgcc_floating_mode_supported_p + + /* The architecture reserves bits 0 and 1 so use bit 2 for descriptors. */ + #undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS +-#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 4 ++#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS AARCH64_CUSTOM_FUNCTION_TEST + + #undef TARGET_HARD_REGNO_NREGS + #define TARGET_HARD_REGNO_NREGS aarch64_hard_regno_nregs +@@ -28181,6 +28925,11 @@ aarch64_libgcc_floating_mode_supported_p + #undef TARGET_CONST_ANCHOR + #define TARGET_CONST_ANCHOR 0x1000000 + ++#if TARGET_MACHO ++#undef TARGET_FRAME_POINTER_REQUIRED ++#define TARGET_FRAME_POINTER_REQUIRED aarch64_darwin_frame_pointer_required ++#endif ++ + struct gcc_target targetm = TARGET_INITIALIZER; + + #include "gt-aarch64.h" +diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h +index cfeaf4657ab..81d5658f1cb 100644 +--- a/gcc/config/aarch64/aarch64.h ++++ b/gcc/config/aarch64/aarch64.h +@@ -65,6 +65,10 @@ + #define TARGET_SIMD (AARCH64_ISA_SIMD) + #define TARGET_FLOAT (AARCH64_ISA_FP) + ++/* If this is non-zero then generated code of the object format, ABI and ++ assembler syntax used by Darwin (Mach-O) platforms. */ ++#define TARGET_MACHO 0 ++ + #define UNITS_PER_WORD 8 + + #define UNITS_PER_VREG 16 +@@ -142,6 +146,12 @@ + /* Heap alignment (same as BIGGEST_ALIGNMENT and STACK_BOUNDARY). */ + #define MALLOC_ABI_ALIGNMENT 128 + ++/* We will and with this value to test if a custom function descriptor needs ++ a static chain. The function boundary must the adjusted so that the bit ++ this represents is no longer part of the address. 0 Disables the custom ++ function descriptors. */ ++#define AARCH64_CUSTOM_FUNCTION_TEST 4 ++ + /* Defined by the ABI */ + #define WCHAR_TYPE "unsigned int" + #define WCHAR_TYPE_SIZE 32 +@@ -944,6 +954,24 @@ typedef struct + aapcs_reg == NULL_RTX. */ + int aapcs_stack_size; /* The total size (in words, per 8 byte) of the + stack arg area so far. */ ++ ++ /* In the darwinpcs, items smaller than one word are packed onto the stack ++ naturally aligned. Unnamed parameters passed in a variadic call are, ++ however, aligned the same way as the AAPCS64. This means that we need to ++ pad the last named arg to the next parm boundary (and hence notice when ++ we are processing that arg). */ ++ int darwinpcs_stack_bytes; /* If the argument is passed on the stack, this ++ the byte-size. */ ++ int darwinpcs_sub_word_offset;/* This is the offset of this arg within a word ++ when placing smaller items for darwinpcs. */ ++ int darwinpcs_sub_word_pos; /* The next byte available within the word for ++ darwinpcs. */ ++ unsigned darwinpcs_arg_boundary; /* The computed argument boundary. */ ++ unsigned darwinpcs_arg_padding; /* The computed argument padding. */ ++ unsigned darwinpcs_n_named; /* Number of named arguments. */ ++ unsigned darwinpcs_n_args_processed; /* Processed so far. */ ++ bool named_p; /* Is this arg named? */ ++ bool last_named_p; /* Is this the last named arg? */ + bool silent_p; /* True if we should act silently, rather than + raise an error for invalid calls. */ + } CUMULATIVE_ARGS; +@@ -1242,8 +1270,13 @@ extern const char *aarch64_rewrite_mcpu (int argc, const char **argv); + #define ASM_CPU_SPEC \ + MCPU_TO_MARCH_SPEC + ++#ifndef SUBTARGET_EXTRA_SPECS ++#define SUBTARGET_EXTRA_SPECS ++#endif ++ + #define EXTRA_SPECS \ +- { "asm_cpu_spec", ASM_CPU_SPEC } ++ { "asm_cpu_spec", ASM_CPU_SPEC }, \ ++ SUBTARGET_EXTRA_SPECS + + #define ASM_OUTPUT_POOL_EPILOGUE aarch64_asm_output_pool_epilogue + +@@ -1256,6 +1289,10 @@ extern GTY(()) tree aarch64_fp16_ptr_type_node; + bfloat16_type_node. Defined in aarch64-builtins.cc. */ + extern GTY(()) tree aarch64_bf16_ptr_type_node; + ++/* A pointer to the user-visible __float128 (on Mach-O). Defined in ++ aarch64-builtins.c. */ ++extern GTY(()) tree aarch64_float128_ptr_type_node; ++ + /* The generic unwind code in libgcc does not initialize the frame pointer. + So in order to unwind a function using a frame pointer, the very first + function that is unwound must save the frame pointer. That way the frame +diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md +index 922cc987595..5c7c81548e1 100644 +--- a/gcc/config/aarch64/aarch64.md ++++ b/gcc/config/aarch64/aarch64.md +@@ -304,6 +304,7 @@ + UNSPEC_LD1RO + UNSPEC_SALT_ADDR + UNSPECV_PATCHABLE_AREA ++ UNSPEC_MACHOPIC_OFFSET ; Common to Mach-O ports. + ]) + + (define_c_enum "unspecv" [ +@@ -850,6 +851,37 @@ + [(set_attr "type" "load_4")] + ) + ++(define_insn "prefetch_unscaled" ++ [(prefetch (match_operand:DI 0 "aarch64_unscaled_prefetch_operand" "Du") ++ (match_operand:QI 1 "const_int_operand" "") ++ (match_operand:QI 2 "const_int_operand" ""))] ++ "" ++ { ++ const char * pftype[2][4] = ++ { ++ {"prfum\\tPLDL1STRM, %0", ++ "prfum\\tPLDL3KEEP, %0", ++ "prfum\\tPLDL2KEEP, %0", ++ "prfum\\tPLDL1KEEP, %0"}, ++ {"prfum\\tPSTL1STRM, %0", ++ "prfum\\tPSTL3KEEP, %0", ++ "prfum\\tPSTL2KEEP, %0", ++ "prfum\\tPSTL1KEEP, %0"}, ++ }; ++ ++ int locality = INTVAL (operands[2]); ++ ++ gcc_assert (IN_RANGE (locality, 0, 3)); ++ ++ /* PRFUM accepts the same addresses as a 64-bit LDR so wrap ++ the address into a DImode MEM so that aarch64_print_operand knows ++ how to print it. */ ++ operands[0] = gen_rtx_MEM (DImode, operands[0]); ++ return pftype[INTVAL(operands[1])][locality]; ++ } ++ [(set_attr "type" "load_4")] ++) ++ + (define_insn "trap" + [(trap_if (const_int 1) (const_int 8))] + "" +@@ -1322,7 +1354,7 @@ + ldr\\t%s0, %1 + str\\t%w1, %0 + str\\t%s1, %0 +- adrp\\t%x0, %A1\;ldr\\t%w0, [%x0, %L1] ++ * return TARGET_MACHO ? \"adrp\\t%x0, %A1\;ldr\\t%w0, [%x0, %O1]\" : \"adrp\\t%x0, %A1\;ldr\\t%w0, [%x0, %L1]\"; + adr\\t%x0, %c1 + adrp\\t%x0, %A1 + fmov\\t%s0, %w1 +@@ -1360,7 +1392,7 @@ + ldr\\t%d0, %1 + str\\t%x1, %0 + str\\t%d1, %0 +- * return TARGET_ILP32 ? \"adrp\\t%0, %A1\;ldr\\t%w0, [%0, %L1]\" : \"adrp\\t%0, %A1\;ldr\\t%0, [%0, %L1]\"; ++ * return TARGET_ILP32 ? (TARGET_MACHO ? \"adrp\\t%0, %A1\;ldr\\t%w0, [%0, %O1]\" : \"adrp\\t%0, %A1\;ldr\\t%w0, [%0, %L1]\") : (TARGET_MACHO ? \"adrp\\t%0, %A1\;ldr\\t%0, [%0, %O1]\" : \"adrp\\t%0, %A1\;ldr\\t%0, [%0, %L1]\"); + adr\\t%x0, %c1 + adrp\\t%x0, %A1 + fmov\\t%d0, %x1 +@@ -1799,16 +1831,16 @@ + (set_attr "arch" "*,fp")] + ) + +-(define_insn "load_pair_dw_tftf" +- [(set (match_operand:TF 0 "register_operand" "=w") +- (match_operand:TF 1 "aarch64_mem_pair_operand" "Ump")) +- (set (match_operand:TF 2 "register_operand" "=w") +- (match_operand:TF 3 "memory_operand" "m"))] ++(define_insn "load_pair_dw_" ++ [(set (match_operand:TX 0 "register_operand" "=w") ++ (match_operand:TX 1 "aarch64_mem_pair_operand" "Ump")) ++ (set (match_operand:TX2 2 "register_operand" "=w") ++ (match_operand:TX2 3 "memory_operand" "m"))] + "TARGET_SIMD + && rtx_equal_p (XEXP (operands[3], 0), + plus_constant (Pmode, + XEXP (operands[1], 0), +- GET_MODE_SIZE (TFmode)))" ++ GET_MODE_SIZE (mode)))" + "ldp\\t%q0, %q2, %z1" + [(set_attr "type" "neon_ldp_q") + (set_attr "fp" "yes")] +@@ -1849,11 +1881,11 @@ + (set_attr "arch" "*,fp")] + ) + +-(define_insn "store_pair_dw_tftf" +- [(set (match_operand:TF 0 "aarch64_mem_pair_operand" "=Ump") +- (match_operand:TF 1 "register_operand" "w")) +- (set (match_operand:TF 2 "memory_operand" "=m") +- (match_operand:TF 3 "register_operand" "w"))] ++(define_insn "store_pair_dw_" ++ [(set (match_operand:TX 0 "aarch64_mem_pair_operand" "=Ump") ++ (match_operand:TX 1 "register_operand" "w")) ++ (set (match_operand:TX2 2 "memory_operand" "=m") ++ (match_operand:TX2 3 "register_operand" "w"))] + "TARGET_SIMD && + rtx_equal_p (XEXP (operands[2], 0), + plus_constant (Pmode, +@@ -7045,7 +7077,10 @@ + (lo_sum:P (match_operand:P 1 "register_operand" "r") + (match_operand 2 "aarch64_valid_symref" "S")))] + "" +- "add\\t%0, %1, :lo12:%c2" ++ { return TARGET_MACHO ++ ? "add\\t%0, %1, %J2;" ++ : "add\\t%0, %1, :lo12:%c2"; ++ } + [(set_attr "type" "alu_imm")] + ) + +diff --git a/gcc/config/aarch64/aarch64.opt b/gcc/config/aarch64/aarch64.opt +index 1d7967db9c0..cc97d7263ba 100644 +--- a/gcc/config/aarch64/aarch64.opt ++++ b/gcc/config/aarch64/aarch64.opt +@@ -158,6 +158,13 @@ Enum(aarch64_abi) String(ilp32) Value(AARCH64_ABI_ILP32) + EnumValue + Enum(aarch64_abi) String(lp64) Value(AARCH64_ABI_LP64) + ++EnumValue ++Enum(aarch64_abi) String(darwinpcs) Value(AARCH64_ABI_LP64) ++ ++m64 ++Target RejectNegative Alias(mabi=, darwinpcs) ++On Darwin for compatibility with other platform variants. ++ + mpc-relative-literal-loads + Target Save Var(pcrelative_literal_loads) Init(2) Save + PC relative literal loads. +diff --git a/gcc/config/aarch64/constraints.md b/gcc/config/aarch64/constraints.md +index 5b20abc27e5..9c6a631c6fb 100644 +--- a/gcc/config/aarch64/constraints.md ++++ b/gcc/config/aarch64/constraints.md +@@ -168,7 +168,9 @@ + A constraint that matches a small GOT access." + (and (match_code "const,symbol_ref") + (match_test "aarch64_classify_symbolic_expression (op) +- == SYMBOL_SMALL_GOT_4G"))) ++ == SYMBOL_SMALL_GOT_4G ++ || aarch64_classify_symbolic_expression (op) ++ == SYMBOL_MO_SMALL_GOT"))) + + (define_constraint "Uss" + "@internal +@@ -505,6 +507,11 @@ + An address valid for a prefetch instruction." + (match_test "aarch64_address_valid_for_prefetch_p (op, true)")) + ++(define_address_constraint "Du" ++ "@internal ++ An address valid for a prefetch instruction with an unscaled offset." ++ (match_test "aarch64_address_valid_for_unscaled_prefetch_p (op, true)")) ++ + (define_constraint "vgb" + "@internal + A constraint that matches an immediate offset valid for SVE LD1B +diff --git a/gcc/config/aarch64/darwin.h b/gcc/config/aarch64/darwin.h +new file mode 100644 +index 00000000000..08febf1401b +--- /dev/null ++++ b/gcc/config/aarch64/darwin.h +@@ -0,0 +1,289 @@ ++/* Target definitions for Arm64/Aarch64 running on macOS/iOS. ++ ++Copyright The GNU Toolchain Authors. ++Contributed by Iain Sandoe. ++ ++This file is part of GCC. ++ ++GCC is free software; you can redistribute it and/or modify ++it under the terms of the GNU General Public License as published by ++the Free Software Foundation; either version 3, or (at your option) ++any later version. ++ ++GCC is distributed in the hope that it will be useful, ++but WITHOUT ANY WARRANTY; without even the implied warranty of ++MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++GNU General Public License for more details. ++ ++You should have received a copy of the GNU General Public License ++along with GCC; see the file COPYING3. If not see ++. */ ++ ++/* Enable Mach-O bits in generic Aarch64 code. */ ++#undef TARGET_MACHO ++#define TARGET_MACHO 1 ++ ++#undef DARWIN_ARM64 ++#define DARWIN_ARM64 1 ++ ++/* This is used in generic code in darwin.cc (at present, we have no support ++ for the arm64_32 target). */ ++#undef TARGET_64BIT ++#define TARGET_64BIT 1 ++ ++#undef PTRDIFF_TYPE ++#define PTRDIFF_TYPE "long int" ++ ++#undef TARGET_PROMOTE_FUNCTION_MODE ++#define TARGET_PROMOTE_FUNCTION_MODE aarch64_darwin_promote_fn_mode ++ ++#undef TARGET_PROMOTE_FUNCTION_MODE_CA ++#define TARGET_PROMOTE_FUNCTION_MODE_CA aarch64_darwin_promote_function_mode_ca ++ ++/* NOTE that arm64_32 is a valid thing and corresponds to darwinpcs ++ and TARGET_ILP32, but we are not implementing that for now. */ ++#define TARGET_OS_CPP_BUILTINS() \ ++ do { \ ++ builtin_define ("__LITTLE_ENDIAN__"); \ ++ builtin_define ("__arm64"); \ ++ builtin_define ("__arm64__"); \ ++ darwin_cpp_builtins (pfile); \ ++ } while (0) ++ ++/* In Darwin's Arm64 ABI, chars are signed. */ ++ ++#undef DEFAULT_SIGNED_CHAR ++#define DEFAULT_SIGNED_CHAR 1 ++ ++#undef LONG_DOUBLE_TYPE_SIZE ++#define LONG_DOUBLE_TYPE_SIZE 64 ++ ++/* Disable custom function descriptors on Darwin (we use heap-based ++ trampolines). */ ++#undef AARCH64_CUSTOM_FUNCTION_TEST ++#define AARCH64_CUSTOM_FUNCTION_TEST 0 ++ ++/* Non-PIE executables are forbidden by the Arm64-darwin security model; ++ remove the option from link-lines since they just produce a warning from ++ ld64 and are then ignored anyway. */ ++#undef DARWIN_NOPIE_SPEC ++#define DARWIN_NOPIE_SPEC \ ++" % ++# include ++#endif ++ ++ ++#if TARGET_MACHO ++ ++/* Default architecture to use if -mcpu=native did not detect a known CPU. */ ++#define DEFAULT_ARCH "apple-m1" ++ ++/* macOS does not have /proc/cpuinfo and needs a different approach, ++ based on sysctl. It is much simpler. */ ++ ++const char * ++host_detect_local_cpu (ATTRIBUTE_UNUSED int argc, ATTRIBUTE_UNUSED const char **argv) ++{ ++ bool arch = false; ++ bool tune = false; ++ bool cpu = false; ++ const char *res = NULL; ++ uint32_t family; ++ size_t len = sizeof(family); ++ ++ gcc_assert (argc); ++ if (!argv[0]) ++ return NULL; ++ ++ /* Are we processing -march, mtune or mcpu? */ ++ arch = strcmp (argv[0], "arch") == 0; ++ if (!arch) ++ tune = strcmp (argv[0], "tune") == 0; ++ if (!arch && !tune) ++ cpu = strcmp (argv[0], "cpu") == 0; ++ if (!arch && !tune && !cpu) ++ return NULL; ++ ++ sysctlbyname("hw.cpufamily", &family, &len, NULL, 0); ++ ++ switch (family) ++ { ++ case 0x07d34b9f: // Vortex, Tempest ++ res = "apple-a12"; ++ break; ++ case 0x573b5eec: ++ case 0x1b588bb3: // Firestorm, Icestorm ++ res = "apple-m1"; ++ break; ++ case 0xda33d83d: // Blizzard, Avalanche ++ res = "apple-m2"; ++ break; ++ case 0xfa33415e: // Ibiza (M3) ++ case 0x5f4dea93: // Lobos (M3 Pro) ++ case 0x72015832: // Palma (M3 Max) ++ res = "apple-m3"; ++ break; ++ default: ++ res = DEFAULT_ARCH; ++ } ++ ++ if (res) ++ return concat ("-m", argv[0], "=", res, NULL); ++ else ++ return NULL; ++} ++ ++#else ++ + struct aarch64_arch_extension + { + const char *ext; +@@ -468,3 +536,4 @@ not_found: + } + } + ++#endif +diff --git a/gcc/config/aarch64/falkor-tag-collision-avoidance.cc b/gcc/config/aarch64/falkor-tag-collision-avoidance.cc +index 39e3f5c2d1b..9b3357f5952 100644 +--- a/gcc/config/aarch64/falkor-tag-collision-avoidance.cc ++++ b/gcc/config/aarch64/falkor-tag-collision-avoidance.cc +@@ -740,7 +740,7 @@ dump_insn_list (const rtx &t, const insn_info_list_t &insn_info, + void *unused ATTRIBUTE_UNUSED) + { + gcc_assert (dump_file); +- fprintf (dump_file, "Tag 0x%lx ::\n", INTVAL (t)); ++ fprintf (dump_file, "Tag 0x" HOST_WIDE_INT_PRINT_HEX_PURE " ::\n", INTVAL (t)); + + for (unsigned i = 0; i < insn_info.length (); i++) + dump_insn_slim (dump_file, insn_info[i]->insn); +diff --git a/gcc/config/aarch64/iterators.md b/gcc/config/aarch64/iterators.md +index 86a196d3536..0708a924745 100644 +--- a/gcc/config/aarch64/iterators.md ++++ b/gcc/config/aarch64/iterators.md +@@ -316,6 +316,9 @@ + ;; TX plus V16QImode. + (define_mode_iterator TX_V16QI [TI TF TD V16QI]) + ++;; Duplicate of TX above ++(define_mode_iterator TX2 [TI TF TD]) ++ + (define_mode_iterator VTX [TI TF TD V16QI V8HI V4SI V2DI V8HF V4SF V2DF V8BF]) + + ;; Advanced SIMD opaque structure modes. +diff --git a/gcc/config/aarch64/predicates.md b/gcc/config/aarch64/predicates.md +index 3f5f4df8c46..4c3498dfe2c 100644 +--- a/gcc/config/aarch64/predicates.md ++++ b/gcc/config/aarch64/predicates.md +@@ -277,9 +277,24 @@ + (define_predicate "aarch64_prefetch_operand" + (match_test "aarch64_address_valid_for_prefetch_p (op, false)")) + ++(define_predicate "aarch64_unscaled_prefetch_operand" ++ (match_test "aarch64_address_valid_for_unscaled_prefetch_p (op, false)")) ++ + (define_predicate "aarch64_valid_symref" + (match_code "const, symbol_ref, label_ref") + { ++ if (TARGET_MACHO) ++ { ++ rtx x = op; ++ rtx offset; ++ split_const (x, &x, &offset); ++ if (GET_CODE (x) == CONST) ++ x = XEXP (x, 0); ++ if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_SALT_ADDR) ++ x = XVECEXP (x, 0, 0); ++ if (SYMBOL_REF_P (x) && INTVAL (offset) < 0) ++ return false; ++ } + return (aarch64_classify_symbolic_expression (op) + != SYMBOL_FORCE_TO_MEM); + }) +diff --git a/gcc/config/aarch64/t-aarch64-darwin b/gcc/config/aarch64/t-aarch64-darwin +new file mode 100644 +index 00000000000..e2b8ad9237f +--- /dev/null ++++ b/gcc/config/aarch64/t-aarch64-darwin +@@ -0,0 +1,25 @@ ++# Machine description for AArch64 architecture. ++# Copyright (C) 2020 Free Software Foundation, Inc. ++# ++# This file is part of GCC. ++# ++# GCC is free software; you can redistribute it and/or modify it ++# under the terms of the GNU General Public License as published by ++# the Free Software Foundation; either version 3, or (at your option) ++# any later version. ++# ++# GCC is distributed in the hope that it will be useful, but ++# WITHOUT ANY WARRANTY; without even the implied warranty of ++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++# General Public License for more details. ++# ++# You should have received a copy of the GNU General Public License ++# along with GCC; see the file COPYING3. If not see ++# . ++ ++LIB1ASMSRC = aarch64/lib1funcs.asm ++LIB1ASMFUNCS = _aarch64_sync_cache_range ++ ++# TODO - figure out what multilib provisions we should make for ++# a) arm64e ++# b) arm64_32 +diff --git a/gcc/config/darwin-c.cc b/gcc/config/darwin-c.cc +index 579b9fa9317..10d5fb12d9b 100644 +--- a/gcc/config/darwin-c.cc ++++ b/gcc/config/darwin-c.cc +@@ -555,7 +555,7 @@ find_subframework_header (cpp_reader *pfile, const char *header, cpp_dir **dirp) + return 0; + } + +-/* Given an OS X version VERSION_STR, return it as a statically-allocated array ++/* Given an macOS version VERSION_STR, return it as a statically-allocated array + of three integers. If VERSION_STR is invalid, return NULL. + + VERSION_STR must consist of one, two, or three tokens, each separated by +@@ -612,7 +612,7 @@ parse_version (const char *version_str) + return version_array; + } + +-/* Given VERSION -- a three-component OS X version represented as an array of ++/* Given VERSION -- a three-component macOS version represented as an array of + non-negative integers -- return a statically-allocated string suitable for + the legacy __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro. If VERSION + is invalid and cannot be coerced into a valid form, return NULL. +@@ -645,7 +645,7 @@ version_as_legacy_macro (const unsigned long *version) + return result; + } + +-/* Given VERSION -- a three-component OS X version represented as an array of ++/* Given VERSION -- a three-component macOS version represented as an array of + non-negative integers -- return a statically-allocated string suitable for + the modern __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro. If VERSION + is invalid, return NULL. +@@ -675,7 +675,7 @@ version_as_modern_macro (const unsigned long *version) + + /* Return the value of darwin_macosx_version_min, suitably formatted for the + __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro. Values representing +- OS X 10.9 and earlier are encoded using the legacy four-character format, ++ macOS 10.9 and earlier are encoded using the legacy four-character format, + while 10.10 and later use a modern six-character format. (For example, + "10.9" produces "1090", and "10.10.1" produces "101001".) If + darwin_macosx_version_min is invalid and cannot be coerced into a valid +diff --git a/gcc/config/darwin-driver.cc b/gcc/config/darwin-driver.cc +index 9c1dcc3d794..b2f39af9f68 100644 +--- a/gcc/config/darwin-driver.cc ++++ b/gcc/config/darwin-driver.cc +@@ -268,10 +268,13 @@ darwin_driver_init (unsigned int *decoded_options_count, + bool seenX86_64 = false; + bool seenPPC = false; + bool seenPPC64 = false; ++#if !DARWIN_ARM64 ++ bool seenArm64 = false; + bool seenM32 = false; + bool seenM64 = false; + bool appendM32 = false; + bool appendM64 = false; ++#endif + const char *vers_string = NULL; + bool seen_version_min = false; + bool seen_sysroot_p = false; +@@ -296,6 +299,12 @@ darwin_driver_init (unsigned int *decoded_options_count, + seenPPC = true; + else if (!strcmp ((*decoded_options)[i].arg, "ppc64")) + seenPPC64 = true; ++ else if (!strcmp ((*decoded_options)[i].arg, "arm64")) ++#if !DARWIN_ARM64 ++ seenArm64 = true; ++#else ++ ; /* We accept the option, but don't need to act on it. */ ++#endif + else + error ("this compiler does not support %qs", + (*decoded_options)[i].arg); +@@ -309,7 +318,7 @@ darwin_driver_init (unsigned int *decoded_options_count, + --i; + --*decoded_options_count; + break; +- ++#if !DARWIN_ARM64 + case OPT_m32: + seenM32 = true; + break; +@@ -317,6 +326,7 @@ darwin_driver_init (unsigned int *decoded_options_count, + case OPT_m64: + seenM64 = true; + break; ++#endif + + case OPT_mmacosx_version_min_: + seen_version_min = true; +@@ -366,6 +376,9 @@ darwin_driver_init (unsigned int *decoded_options_count, + if (seenPPC || seenPPC64) + warning (0, "this compiler does not support PowerPC" + " (%<-arch%> option ignored)"); ++ else if (seenArm64) ++ warning (0, "this compiler does not support Arm64" ++ " (%<-arch%> option ignored)"); + if (seenX86) + { + if (seenX86_64 || seenM64) +@@ -389,6 +402,9 @@ darwin_driver_init (unsigned int *decoded_options_count, + if (seenX86 || seenX86_64) + warning (0, "this compiler does not support x86" + " (%<-arch%> option ignored)"); ++ else if (seenArm64) ++ warning (0, "this compiler does not support Arm64" ++ " (%<-arch%> option ignored)"); + if (seenPPC) + { + if (seenPPC64 || seenM64) +@@ -408,12 +424,20 @@ darwin_driver_init (unsigned int *decoded_options_count, + if (! seenM64) /* Add -m64 if the User didn't. */ + appendM64 = true; + } ++#elif DARWIN_ARM64 ++ if (seenPPC || seenPPC64) ++ warning (0, "this compiler does not support PowerPC" ++ " (%<-arch%> option ignored)"); ++ if (seenX86 || seenX86_64) ++ warning (0, "this compiler does not support x86" ++ " (%<-arch%> option ignored)"); + #endif + + /* If there is nothing else on the command line, do not add sysroot etc. */ + if (*decoded_options_count <= 1) + return; + ++#if !DARWIN_ARM64 + if (appendM32 || appendM64) + { + ++*decoded_options_count; +@@ -423,6 +447,7 @@ darwin_driver_init (unsigned int *decoded_options_count, + generate_option (appendM32 ? OPT_m32 : OPT_m64, NULL, 1, CL_DRIVER, + &(*decoded_options)[*decoded_options_count - 1]); + } ++#endif + + if (!seen_sysroot_p) + { +@@ -440,7 +465,7 @@ darwin_driver_init (unsigned int *decoded_options_count, + } + } + +- /* We will need to know the OS X version we're trying to build for here ++ /* We will need to know the macOS version we're trying to build for here + so that we can figure out the mechanism and source for the sysroot to + be used. */ + if (!seen_version_min) +diff --git a/gcc/config/darwin-protos.h b/gcc/config/darwin-protos.h +index 9df358ee7d3..babc8883b6e 100644 +--- a/gcc/config/darwin-protos.h ++++ b/gcc/config/darwin-protos.h +@@ -86,9 +86,12 @@ extern void darwin_asm_lto_end (void); + extern void darwin_mark_decl_preserved (const char *); + + extern tree darwin_handle_kext_attribute (tree *, tree, tree, int, bool *); +-extern tree darwin_handle_weak_import_attribute (tree *node, tree name, +- tree args, int flags, +- bool * no_add_attrs); ++extern tree darwin_handle_weak_import_attribute (tree *, tree, tree, int, ++ bool *); ++extern tree darwin_handle_availability_attribute (tree *, tree, tree, ++ int, bool *); ++extern bool darwin_attribute_takes_identifier_p (const_tree); ++ + extern void machopic_output_stub (FILE *, const char *, const char *); + extern void darwin_globalize_label (FILE *, const char *); + extern void darwin_assemble_visibility (tree, int); +@@ -124,6 +127,7 @@ extern void darwin_enter_string_into_cfstring_table (tree); + extern void darwin_asm_output_anchor (rtx symbol); + extern bool darwin_use_anchors_for_symbol_p (const_rtx symbol); + extern bool darwin_kextabi_p (void); ++extern bool darwin_unreachable_traps_p (void); + extern void darwin_override_options (void); + extern void darwin_patch_builtins (void); + extern void darwin_rename_builtins (void); +diff --git a/gcc/config/darwin.cc b/gcc/config/darwin.cc +index 1471dbb6046..e95520f2a15 100644 +--- a/gcc/config/darwin.cc ++++ b/gcc/config/darwin.cc +@@ -29,6 +29,7 @@ along with GCC; see the file COPYING3. If not see + #include "cfghooks.h" + #include "df.h" + #include "memmodel.h" ++#include "c-family/c-common.h" /* enum rid. */ + #include "tm_p.h" + #include "stringpool.h" + #include "attribs.h" +@@ -49,6 +50,7 @@ along with GCC; see the file COPYING3. If not see + #include "optabs.h" + #include "flags.h" + #include "opts.h" ++#include "c-family/c-objc.h" /* for objc_method_decl(). */ + + /* Fix and Continue. + +@@ -102,6 +104,7 @@ int darwin_running_cxx; + + /* Some code-gen now depends on OS major version numbers (at least). */ + int generating_for_darwin_version ; ++unsigned long current_os_version = 0; + + /* For older linkers we need to emit special sections (marked 'coalesced') for + for weak or single-definition items. */ +@@ -131,7 +134,7 @@ struct { + section * darwin_sections[NUM_DARWIN_SECTIONS]; + + /* While we transition to using in-tests instead of ifdef'd code. */ +-#if !HAVE_lo_sum ++#if !HAVE_lo_sum || DARWIN_ARM64 + #define gen_macho_high(m,a,b) (a) + #define gen_macho_low(m,a,b,c) (a) + #endif +@@ -1065,6 +1068,7 @@ machopic_legitimize_pic_address (rtx orig, machine_mode mode, rtx reg) + return pic_ref; + } + ++#if !DARWIN_ARM64 + /* Callbacks to output the stub or non-lazy pointers. + Each works on the item in *SLOT,if it has been used. + DATA is the FILE* for assembly output. +@@ -1220,6 +1224,7 @@ machopic_finish (FILE *out_file) + machopic_indirections->traverse_noresize + (out_file); + } ++#endif + + int + machopic_operand_p (rtx op) +@@ -2155,6 +2160,122 @@ darwin_handle_kext_attribute (tree *node, tree name, + return NULL_TREE; + } + ++enum version_components { MAJOR, MINOR, TINY }; ++ ++/* Parse a version number in x.y.z form and validate it as a macOS ++ version. Ideally, we'd put this in a common place usable by the ++ Darwin backend. */ ++ ++static bool ++parse_version (unsigned version_array[3], const char *version_str) ++{ ++ size_t version_len; ++ char *end, last = '\0', delimiter = '.', alt_delim = '_'; ++ ++ if (!version_str) ++ return false; ++ ++ /* Handle the odd situation in which we get STRING_CST which contain the ++ starting and ending quotes. */ ++ if (version_str[0] == '"') ++ { ++ version_str++; ++ version_len = strrchr (&version_str[1], '"') - version_str; ++ last = '"'; ++ } ++ else ++ version_len = strlen (version_str); ++ ++ if (version_len < 1) ++ return false; ++ ++ /* Version string must consist of digits and periods only. */ ++ if (strspn (version_str, "0123456789._") != version_len) ++ return false; ++ ++ if (!ISDIGIT (version_str[0]) || !ISDIGIT (version_str[version_len - 1])) ++ return false; ++ ++ version_array[MAJOR] = strtoul (version_str, &end, 10); ++ if (*end == '_') ++ { ++ delimiter = '_'; ++ alt_delim = '.'; ++ } ++ version_str = end + ((*end == delimiter) ? 1 : 0); ++ if (version_array[MAJOR] == 100000) ++ return true; ++ if (version_array[MAJOR] > 99) ++ return false; ++ ++ /* Version string must not contain adjacent delimiters. */ ++ if (*version_str == delimiter || *version_str == alt_delim) ++ return false; ++ ++ version_array[MINOR] = strtoul (version_str, &end, 10); ++ if (*end == alt_delim) ++ return false; ++ version_str = end + ((*end == delimiter) ? 1 : 0); ++ if (version_array[MINOR] > 99) ++ return false; ++ ++ version_array[TINY] = strtoul (version_str, &end, 10); ++ if (version_array[TINY] > 99) ++ return false; ++ ++ /* Version string must contain no more than three tokens. */ ++ if (*end != last) ++ return false; ++ ++ return true; ++} ++ ++/* Turn a version expressed as maj.min.tiny into an unsigned long ++ integer representing the value used in macOS availability macros. */ ++ ++static unsigned long ++version_from_version_array (unsigned vers[3]) ++{ ++ unsigned long res = 0; ++ /* There seems to be a special "unknown" value. */ ++ if (vers[0] == 100000) ++ return 999999; ++ ++ /* Here, we follow the 'modern' / 'legacy' numbering scheme for versions. */ ++ if (vers[0] > 10 || vers[1] >= 10) ++ res = vers[0] * 10000 + vers[1] * 100 + vers[2]; ++ else ++ { ++ res = vers[0] * 100; ++ if (vers[1] > 9) ++ res += 90; ++ else ++ res += vers[1] * 10; ++ if (vers[2] > 9) ++ res += 9; ++ else ++ res += vers[1]; ++ } ++ return res; ++} ++ ++/* Extract a macOS version from an availability attribute argument. */ ++ ++static unsigned long ++os_version_from_avail_value (tree value) ++{ ++ unsigned long res = 0; ++ unsigned vers[3] = {0,0,0}; ++ if (TREE_CODE (value) == STRING_CST) ++ { ++ if (parse_version (&vers[0], TREE_STRING_POINTER (value))) ++ res = version_from_version_array (&vers[0]); ++ } ++ else ++ gcc_unreachable (); ++ return res; ++} ++ + /* Handle a "weak_import" attribute; arguments as in + struct attribute_spec.handler. */ + +@@ -2176,6 +2297,231 @@ darwin_handle_weak_import_attribute (tree *node, tree name, + return NULL_TREE; + } + ++#define NUM_AV_OSES 13 ++const char *availability_os[NUM_AV_OSES] ++ = { "macos", "macosx", "ios", "tvos", "watchos", "driverkit", "swift", ++ "maccatalyst", "macCatalyst", "xros", "visionos", "android", "zos" }; ++ ++#define NUM_AV_CLAUSES 6 ++const char *availability_clause[NUM_AV_CLAUSES] ++ = { "unavailable", "introduced", "deprecated", "obsoleted", "message", ++ "replacement" }; ++ ++/* Validate and act upon the arguments to an 'availability' attribute. */ ++ ++tree ++darwin_handle_availability_attribute (tree *node, tree name, tree args, ++ int flags, bool * no_add_attrs) ++{ ++ tree decl = *node; ++ *no_add_attrs = true; ++ ++ if (!decl || (!TYPE_P (decl) && !DECL_P (decl))) ++ { ++ warning (OPT_Wattributes, "%qE attribute ignored", name); ++ return NULL_TREE; ++ } ++ else if (decl == error_mark_node) ++ return NULL_TREE; ++ ++ location_t loc = DECL_SOURCE_LOCATION (decl); ++ if (args == NULL_TREE) ++ { ++ error_at (loc, "%qE attribute requires at least one argument", ++ name); ++ return NULL_TREE; ++ } ++ else if (args == error_mark_node) ++ return NULL_TREE; ++ ++ /* The first argument must name a supported OS - although we could choose ++ to ignore any OS we don't recognise. */ ++ gcc_checking_assert (TREE_CODE (args) == TREE_LIST); ++ tree platform = TREE_VALUE (args); ++ if (platform == error_mark_node) ++ return NULL_TREE; ++ ++ gcc_checking_assert (TREE_CODE (platform) == IDENTIFIER_NODE); ++ bool platform_ok = false; ++ unsigned plat_num = 0; ++ for (; plat_num < (unsigned) NUM_AV_OSES; plat_num++) ++ if (strcmp (availability_os[plat_num], IDENTIFIER_POINTER (platform)) == 0) ++ { ++ platform_ok = true; ++ break; ++ } ++ if (!platform_ok) ++ { ++ error_at (input_location, ++ "platform %qE is not recognised for the % " ++ "attribute", platform); ++ return NULL_TREE; ++ } ++ else if (plat_num > 1) /* We only compile for macos so far. */ ++ return NULL_TREE; ++ ++ /* We might be dealing with an object or type. */ ++ tree target_decl = NULL_TREE; ++ tree type = NULL_TREE; ++ bool warn = false; ++ if (DECL_P (*node)) ++ { ++ type = TREE_TYPE (decl); ++ ++ if (TREE_CODE (decl) == TYPE_DECL ++ || TREE_CODE (decl) == PARM_DECL ++ || VAR_OR_FUNCTION_DECL_P (decl) ++ || TREE_CODE (decl) == FIELD_DECL ++ || TREE_CODE (decl) == CONST_DECL ++ /*|| objc_method_decl (TREE_CODE (decl))*/) ++ target_decl = decl; ++ else ++ warn = true; ++ } ++ else if (TYPE_P (*node)) ++ type = target_decl = *node; ++ else ++ warn = true; ++ ++ tree what = NULL_TREE; ++ if (warn) ++ { ++ if (type && TYPE_NAME (type)) ++ { ++ if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) ++ what = TYPE_NAME (*node); ++ else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL ++ && DECL_NAME (TYPE_NAME (type))) ++ what = DECL_NAME (TYPE_NAME (type)); ++ } ++ if (what) ++ warning (OPT_Wattributes, "%qE attribute ignored for %qE", name, what); ++ else ++ warning (OPT_Wattributes, "%qE attribute ignored", name); ++ return NULL_TREE; ++ } ++ ++ /* Now we have to parse the availability clauses. */ ++ tree msg = NULL_TREE; ++ tree replacement = NULL_TREE; ++ bool unavailable = false; ++ unsigned introduced = 1000; ++ unsigned deprecated = current_os_version + 1; ++ unsigned obsoleted = current_os_version + 1; ++ for (tree arg = TREE_CHAIN (args); arg; arg = TREE_CHAIN (arg)) ++ { ++ tree clause_name = TREE_VALUE (arg); ++ tree clause_value = TREE_PURPOSE (arg); ++ if (clause_name == error_mark_node ++ || clause_value == error_mark_node) ++ continue; ++ unsigned clause_num = 0; ++ for (; clause_num < (unsigned) NUM_AV_CLAUSES; clause_num++) ++ if (strcmp (availability_clause[clause_num], ++ IDENTIFIER_POINTER (clause_name)) == 0) ++ break; ++ switch (clause_num) ++ { ++ default: ++ error_at (input_location, ++ "clause %qE is not recognised for the % " ++ "attribute", clause_name); ++ break; ++ case 0: ++ unavailable = true; ++ break; ++ case 1: ++ case 2: ++ case 3: ++ if (!clause_value) ++ error_at (input_location, "%<%E=%> requires a value", clause_name); ++ else ++ { ++ unsigned version = os_version_from_avail_value (clause_value); ++ if (version == 0) ++ error_at (input_location, "the value %qE provided to %qE is " ++ "not a valid OS version", clause_value, clause_name); ++ else if (clause_num == 1) ++ introduced = version; ++ else if (clause_num == 2) ++ deprecated = version; ++ else if (clause_num == 3) ++ obsoleted = version; ++ } ++ break; ++ case 4: ++ case 5: ++ if (!clause_value || TREE_CODE (clause_value) != STRING_CST) ++ error_at (input_location, "%<%E=%> requires a string", clause_name); ++ else if (clause_num == 4) ++ msg = clause_value; ++ else ++ replacement = clause_value; ++ break; ++ } ++ } ++ /* Now figure out what to do. */ ++ tree maybe_text = NULL_TREE; ++ if (replacement) ++ maybe_text = tree_cons (NULL_TREE, replacement, NULL_TREE); ++ else if (msg) ++ maybe_text = tree_cons (NULL_TREE, msg, NULL_TREE); ++ ++ if (unavailable || current_os_version >= obsoleted) ++ { ++ TREE_UNAVAILABLE (*node) = true; ++ /* We do not handle the availability attribute at diagnostics-time, so ++ if we want the informational messages, then attach them to additional ++ attributes for the deprecation or unavailability. TODO; maybe we can ++ fabricate the composite here. */ ++ if (maybe_text) ++ { ++ *no_add_attrs = false; ++ tree new_attr = tree_cons (get_identifier ("unavailable"), ++ maybe_text, NULL_TREE); ++ /* This is the actual consequence of the evaluation. */ ++ if (TYPE_P (target_decl) && !(flags & (int) ATTR_FLAG_TYPE_IN_PLACE)) ++ { ++ *node = build_variant_type_copy (*node); ++ TYPE_ATTRIBUTES (*node) = chainon (TYPE_ATTRIBUTES (*node), ++ new_attr); ++ } ++ else ++ DECL_ATTRIBUTES (*node) = chainon (DECL_ATTRIBUTES (*node), ++ new_attr); ++ } ++ } ++ else if (current_os_version > deprecated) ++ { ++ TREE_DEPRECATED (*node) = true; ++ if (maybe_text) ++ { ++ *no_add_attrs = false; ++ tree new_attr = tree_cons (get_identifier ("deprecated"), ++ maybe_text, NULL_TREE); ++ /* This is the actual consequence of the evaluation. */ ++ if (TYPE_P (target_decl) && !(flags & (int) ATTR_FLAG_TYPE_IN_PLACE)) ++ { ++ *node = build_variant_type_copy (*node); ++ TYPE_ATTRIBUTES (*node) = chainon (TYPE_ATTRIBUTES (*node), ++ new_attr); ++ } ++ else ++ DECL_ATTRIBUTES (*node) = chainon (DECL_ATTRIBUTES (*node), ++ new_attr); ++ } ++ } ++ else if (current_os_version < introduced) ++ *no_add_attrs = false; ++ return NULL_TREE; ++} ++ ++bool ++darwin_attribute_takes_identifier_p (const_tree attr_id) ++{ ++ return is_attribute_p ("availability", attr_id); ++} ++ + /* Emit a label for an FDE, making it global and/or weak if appropriate. + The third parameter is nonzero if this is for exception handling. + The fourth parameter is nonzero if this is just a placeholder for an +@@ -2267,6 +2613,8 @@ darwin_emit_except_table_label (FILE *file) + rtx + darwin_make_eh_symbol_indirect (rtx orig, bool ARG_UNUSED (pubvis)) + { ++ if (DARWIN_ARM64) ++ return orig; + if (DARWIN_PPC == 0 && TARGET_64BIT) + return orig; + +@@ -3115,7 +3463,12 @@ darwin_file_end (void) + fprintf (asm_out_file, "\t.long\t0\n\t.long\t%u\n", flags); + } + ++#if !DARWIN_ARM64 + machopic_finish (asm_out_file); ++#else ++ gcc_checking_assert (!machopic_indirections); ++#endif ++ + if (flag_apple_kext) + { + /* These sections are only used for kernel code. */ +@@ -3291,6 +3644,13 @@ darwin_kextabi_p (void) { + return flag_apple_kext; + } + ++/* True, iff we want to map __builtin_unreachable to a trap. */ ++ ++bool ++darwin_unreachable_traps_p (void) { ++ return darwin_unreachable_traps; ++} ++ + void + darwin_override_options (void) + { +@@ -3311,7 +3671,14 @@ darwin_override_options (void) + generating_for_darwin_version = 8; + + /* Earlier versions are not specifically accounted, until required. */ ++ unsigned vers[3] = {0,0,0}; ++ if (!parse_version (vers, darwin_macosx_version_min)) ++ error_at (UNKNOWN_LOCATION, "how did we get a bad OS version? (%s)", ++ darwin_macosx_version_min); ++ current_os_version = version_from_version_array (vers); + } ++ else ++ current_os_version = 1058; + + /* Some codegen needs to account for the capabilities of the target + linker. */ +@@ -3561,6 +3928,11 @@ darwin_override_options (void) + + /* The c_dialect...() macros are not available to us here. */ + darwin_running_cxx = (strstr (lang_hooks.name, "C++") != 0); ++ ++ /* We need to consume attributes on function definitions from the the SDK ++ headers. */ ++ if (!OPTION_SET_P (flag_allow_ext_attr_placement)) ++ flag_allow_ext_attr_placement = true; + } + + #if DARWIN_PPC +diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h +index 5c6c38ddc63..fcf9eff27d3 100644 +--- a/gcc/config/darwin.h ++++ b/gcc/config/darwin.h +@@ -1,4 +1,4 @@ +-/* Target definitions for Darwin (Mac OS X) systems. ++/* Target definitions for Darwin (macOS) systems. + Copyright (C) 1989-2023 Free Software Foundation, Inc. + Contributed by Apple Computer Inc. + +@@ -27,7 +27,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + #define CONFIG_DARWIN_H + + /* The definitions in this file are common to all processor types +- running Darwin, which is the kernel for Mac OS X. Darwin is ++ running Darwin, which is the kernel for macOS. Darwin is + basically a BSD user layer laid over a Mach kernel, then evolved + for many years (at NeXT) in parallel with other Unix systems. So + while the runtime is a somewhat idiosyncratic Mach-based thing, +@@ -42,6 +42,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + + #define DARWIN_X86 0 + #define DARWIN_PPC 0 ++#define DARWIN_ARM64 0 + + #define OBJECT_FORMAT_MACHO 1 + +@@ -133,10 +134,9 @@ extern GTY(()) int darwin_ms_struct; + cases where these driver opts are used multiple times, or to control + operations on more than one command (e.g. dynamiclib). These are handled + specially and we then add %= 10.7 mmacosx-version-min= -no_pie) }" + + #define DARWIN_CC1_SPEC \ +- "% 10.11 mmacosx-version-min= -lgcc_s.1.1)" ++# define DARWIN_SHARED_WEAK_ADDS \ ++"%{%:version-compare(>= 10.11 mmacosx-version-min= -lemutls_w): \ ++ " DARWIN_HEAP_T_LIB "}" ++#endif ++ ++ ++/* We might elect to add a path even when this compiler does not use embedded ++ run paths, so that we can use libraries from an alternate compiler that is ++ using embedded runpaths. */ ++#if DARWIN_DO_EXTRA_RPATH ++# define DARWIN_EXTRA_RPATH \ ++"%{!r:%{!nostdlib:%{!nodefaultrpaths:\ ++ %:version-compare(>= 10.5 mmacosx-version-min= -rpath) \ ++ %:version-compare(>= 10.5 mmacosx-version-min= " DARWIN_ADD_RPATH ") \ ++ }}}" ++#else ++# define DARWIN_EXTRA_RPATH "" ++#endif + + #define SUBSUBTARGET_OVERRIDE_OPTIONS \ + do { \ +@@ -336,7 +372,8 @@ extern GTY(()) int darwin_ms_struct; + */ + + #define DARWIN_NOCOMPACT_UNWIND \ +-" %:version-compare(>= 10.6 mmacosx-version-min= -no_compact_unwind) " ++"%{!fuse-ld=lld: \ ++ %:version-compare(>= 10.6 mmacosx-version-min= -no_compact_unwind)}" + + /* In Darwin linker specs we can put -lcrt0.o and ld will search the library + path for crt0.o or -lcrtx.a and it will search for libcrtx.a. As for +@@ -356,10 +393,12 @@ extern GTY(()) int darwin_ms_struct; + #define LINK_COMMAND_SPEC_A \ + "%{!c:%{!E:%{!S:%{!M:%{!MM:%{!fsyntax-only:%{!fdump=*: \ + %(linker)" \ ++ DARWIN_LD_DEMANGLE \ + LINK_PLUGIN_SPEC \ + "%{flto*:% 10.6 mmacosx-version-min= -lgcc_eh); \ + shared-libgcc|fexceptions|fobjc-exceptions|fgnu-runtime: \ +- %:version-compare(!> 10.11 mmacosx-version-min= -lgcc_s.1.1) \ ++ " DARWIN_SHARED_LIBGCC " \ + %:version-compare(!> 10.3.9 mmacosx-version-min= -lgcc_eh) \ + %:version-compare(>< 10.3.9 10.5 mmacosx-version-min= -lgcc_s.10.4) \ + %:version-compare(>< 10.5 10.6 mmacosx-version-min= -lgcc_s.10.5) \ +@@ -520,18 +561,19 @@ extern GTY(()) int darwin_ms_struct; + + #define DARWIN_WEAK_CRTS \ + "%{static-libgcc|static: \ +- %:version-compare(>= 10.6 mmacosx-version-min= -lemutls_w) ; \ +- shared-libgcc|fexceptions|fobjc-exceptions|fgnu-runtime: \ +- %:version-compare(>= 10.11 mmacosx-version-min= -lemutls_w) ; \ +- : -lemutls_w \ ++ %{%:version-compare(>= 10.6 mmacosx-version-min= -lemutls_w): \ ++ " DARWIN_HEAP_T_LIB "} ; \ ++ shared-libgcc|fexceptions|fobjc-exceptions|fgnu-runtime: " \ ++ DARWIN_SHARED_WEAK_ADDS " ; \ ++ : -lemutls_w " DARWIN_HEAP_T_LIB " \ + }" + + /* We specify crt0.o as -lcrt0.o so that ld will search the library path. */ + + #undef STARTFILE_SPEC + #define STARTFILE_SPEC \ +-"%{dynamiclib: %(darwin_dylib1) %{fgnu-tm: -lcrttms.o}} \ +- %{!dynamiclib:%{bundle:%(darwin_bundle1)} \ ++"%{dynamiclib|shared: %(darwin_dylib1) %{fgnu-tm: -lcrttms.o}} \ ++ %{!dynamiclib:%{!shared:%{bundle:%(darwin_bundle1)} \ + %{!bundle:%{pg:%{static:-lgcrt0.o} \ + %{!static:%{object:-lgcrt0.o} \ + %{!object:%{preload:-lgcrt0.o} \ +@@ -542,8 +584,8 @@ extern GTY(()) int darwin_ms_struct; + %{!static:%{object:-lcrt0.o} \ + %{!object:%{preload:-lcrt0.o} \ + %{!preload: %(darwin_crt1) \ +- %(darwin_crt2)}}}}}} \ +- %(darwin_crt3) % 10.5 mmacosx-version-min= -lcrt1.o) \ +@@ -580,6 +623,16 @@ extern GTY(()) int darwin_ms_struct; + "%{!static:%:version-compare(< 10.6 mmacosx-version-min= -lbundle1.o) \ + %{fgnu-tm: -lcrttms.o}}" + ++#if DARWIN_AT_RPATH ++/* A default rpath, that picks up dependent libraries installed in the same ++ director as one being loaded. */ ++#define DARWIN_RPATH_SPEC \ ++ "%:version-compare(>= 10.5 mmacosx-version-min= -rpath) \ ++ %{%:version-compare(>= 10.5 mmacosx-version-min= @loader_path): %P }" ++#else ++#define DARWIN_RPATH_SPEC "" ++#endif ++ + #ifdef HAVE_AS_MMACOSX_VERSION_MIN_OPTION + /* Emit macosx version (but only major). */ + #define ASM_MMACOSX_VERSION_MIN_SPEC \ +@@ -598,6 +651,8 @@ extern GTY(()) int darwin_ms_struct; + #define ASM_OPTIONS "%{v} %{w:-W} %{I*}" + #endif + ++#define AS_NEEDS_DASH_FOR_PIPED_INPUT ++ + /* Default Darwin ASM_SPEC, very simple. */ + #define ASM_SPEC \ + "%{static} -arch %(darwin_arch) " \ +@@ -927,7 +982,12 @@ extern GTY(()) section * darwin_sections[NUM_DARWIN_SECTIONS]; + { "apple_kext_compatibility", 0, 0, false, true, false, false, \ + darwin_handle_kext_attribute, NULL }, \ + { "weak_import", 0, 0, true, false, false, false, \ +- darwin_handle_weak_import_attribute, NULL } ++ darwin_handle_weak_import_attribute, NULL }, \ ++ { "availability", 0, -1, true, false, false, false, \ ++ darwin_handle_availability_attribute, NULL } ++ ++#undef TARGET_ATTRIBUTE_TAKES_IDENTIFIER_P ++#define TARGET_ATTRIBUTE_TAKES_IDENTIFIER_P darwin_attribute_takes_identifier_p + + /* Make local constant labels linker-visible, so that if one follows a + weak_global constant, ld64 will be able to separate the atoms. */ +@@ -1175,6 +1233,10 @@ void add_framework_path (char *); + #define TARGET_N_FORMAT_TYPES 1 + #define TARGET_FORMAT_TYPES darwin_additional_format_types + ++/* We want __builtin_unreachable to be expanded as a trap instruction. */ ++#undef TARGET_UNREACHABLE_SHOULD_TRAP ++#define TARGET_UNREACHABLE_SHOULD_TRAP darwin_unreachable_traps_p ++ + #ifndef USED_FOR_TARGET + extern void darwin_driver_init (unsigned int *,struct cl_decoded_option **); + #define GCC_DRIVER_HOST_INITIALIZATION \ +diff --git a/gcc/config/darwin.opt b/gcc/config/darwin.opt +index d655aaef2fb..97b1a747918 100644 +--- a/gcc/config/darwin.opt ++++ b/gcc/config/darwin.opt +@@ -91,6 +91,10 @@ mtarget-linker + Target RejectNegative Joined Separate Var(darwin_target_linker) Init(LD64_VERSION) + -mtarget-linker Specify that ld64 is the toolchain linker for the current invocation. + ++munreachable-traps ++Target Var(darwin_unreachable_traps) Init(1) ++When set (the default) this makes __builtin_unreachable render as a trap. ++ + ; Driver options. + + all_load +@@ -241,6 +245,10 @@ nodefaultexport + Driver RejectNegative + Do not add a default symbol exports to modules or dynamic libraries. + ++nodefaultrpaths ++Driver RejectNegative ++Do not add default run paths (for the compiler library directories) to executables, modules or dynamic libraries. ++ + nofixprebinding + Driver RejectNegative + (Obsolete after 10.3.9) Set MH_NOPREFIXBINDING, in an executable. +diff --git a/gcc/config/i386/darwin.h b/gcc/config/i386/darwin.h +index 588bd669bdd..657ea470683 100644 +--- a/gcc/config/i386/darwin.h ++++ b/gcc/config/i386/darwin.h +@@ -121,6 +121,9 @@ along with GCC; see the file COPYING3. If not see + #define DARWIN_SUBARCH_SPEC DARWIN_ARCH_SPEC + #endif + ++#undef DARWIN_HEAP_T_LIB ++#define DARWIN_HEAP_T_LIB " -lheapt_w " ++ + #undef SUBTARGET_EXTRA_SPECS + #define SUBTARGET_EXTRA_SPECS \ + DARWIN_EXTRA_SPECS \ +@@ -308,3 +311,9 @@ along with GCC; see the file COPYING3. If not see + #define CLEAR_INSN_CACHE(beg, end) \ + extern void sys_icache_invalidate(void *start, size_t len); \ + sys_icache_invalidate ((beg), (size_t)((end)-(beg))) ++ ++/* Disable custom function descriptors for Darwin when we have off-stack ++ trampolines. */ ++#undef X86_CUSTOM_FUNCTION_TEST ++#define X86_CUSTOM_FUNCTION_TEST \ ++ (flag_trampolines && flag_trampoline_impl == TRAMPOLINE_IMPL_HEAP) ? 0 : 1 +diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc +index 499184166ff..be6d408031b 100644 +--- a/gcc/config/i386/i386.cc ++++ b/gcc/config/i386/i386.cc +@@ -25245,7 +25245,7 @@ ix86_libgcc_floating_mode_supported_p + #define TARGET_HARD_REGNO_SCRATCH_OK ix86_hard_regno_scratch_ok + + #undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS +-#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 1 ++#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS X86_CUSTOM_FUNCTION_TEST + + #undef TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID + #define TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID ix86_addr_space_zero_address_valid +diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h +index 539083f2fbf..77644b0ed1d 100644 +--- a/gcc/config/i386/i386.h ++++ b/gcc/config/i386/i386.h +@@ -754,6 +754,12 @@ extern const char *host_detect_local_cpu (int argc, const char **argv); + /* Minimum allocation boundary for the code of a function. */ + #define FUNCTION_BOUNDARY 8 + ++/* We will and with this value to test if a custom function descriptor needs ++ a static chain. The function boundary must the adjusted so that the bit ++ this represents is no longer part of the address. 0 Disables the custom ++ function descriptors. */ ++#define X86_CUSTOM_FUNCTION_TEST 1 ++ + /* C++ stores the virtual bit in the lowest bit of function pointers. */ + #define TARGET_PTRMEMFUNC_VBIT_LOCATION ptrmemfunc_vbit_in_pfn + +diff --git a/gcc/config/rs6000/darwin.h b/gcc/config/rs6000/darwin.h +index 4d5d6f6d5a8..3a2e480ace6 100644 +--- a/gcc/config/rs6000/darwin.h ++++ b/gcc/config/rs6000/darwin.h +@@ -98,7 +98,7 @@ + Include libmx when targeting Darwin 7.0 and above, but before libSystem, + since the functions are actually in libSystem but for 7.x compatibility + we want them to be looked for in libmx first. +- Include libSystemStubs when compiling against 10.3 - 10.5 SDKs (we assume ++ Include libSystemStubs when compiling against 10.3 - 10.6 SDKs (we assume + this is the case when targetting these) - but not for 64-bit long double. + Don't do either for m64, the library is either a dummy or non-existent. + */ +@@ -107,12 +107,15 @@ + #define LIB_SPEC \ + "%{!static: \ + %{!m64:%{!mlong-double-64: \ +- %{pg:%:version-compare(>< 10.3 10.5 mmacosx-version-min= -lSystemStubs_profile)} \ +- %{!pg:%:version-compare(>< 10.3 10.5 mmacosx-version-min= -lSystemStubs)} \ ++ %{pg:%:version-compare(>< 10.3 10.7 mmacosx-version-min= -lSystemStubs_profile)} \ ++ %{!pg:%:version-compare(>< 10.3 10.7 mmacosx-version-min= -lSystemStubs)} \ + %:version-compare(>< 10.3 10.4 mmacosx-version-min= -lmx)}} \ + -lSystem \ + }" + ++#undef DARWIN_HEAP_T_LIB ++#define DARWIN_HEAP_T_LIB " " ++ + /* We want -fPIC by default, unless we're using -static to compile for + the kernel or some such. The "-faltivec" option should have been + called "-maltivec" all along. */ +diff --git a/gcc/configure b/gcc/configure +index ade0af23e8c..4af01a09637 100755 +--- a/gcc/configure ++++ b/gcc/configure +@@ -632,10 +632,10 @@ ac_includes_default="\ + ac_subst_vars='LTLIBOBJS + LIBOBJS + CET_HOST_FLAGS +-NO_PIE_FLAG +-NO_PIE_CFLAGS +-enable_default_pie ++LD_PICFLAG + PICFLAG ++enable_default_pie ++enable_host_pie + enable_host_shared + enable_plugin + pluginlibs +@@ -735,11 +735,15 @@ ORIGINAL_NM_FOR_TARGET + gcc_cv_nm + ORIGINAL_LD_GOLD_FOR_TARGET + ORIGINAL_LD_BFD_FOR_TARGET ++ORIGINAL_CLASSIC_LD_FOR_TARGET ++ORIGINAL_LLD_FOR_TARGET + ORIGINAL_LD_FOR_TARGET + ORIGINAL_PLUGIN_LD_FOR_TARGET + gcc_cv_ld + ORIGINAL_AS_FOR_TARGET + gcc_cv_as ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + enable_fast_install + objdir + OTOOL64 +@@ -1004,6 +1008,8 @@ enable_static + with_pic + enable_fast_install + enable_libtool_lock ++enable_darwin_at_rpath ++with_darwin_extra_rpath + enable_ld + enable_gold + with_plugin_ld +@@ -1029,6 +1035,7 @@ enable_link_serialization + enable_version_specific_runtime_libs + enable_plugin + enable_host_shared ++enable_host_pie + enable_libquadmath_support + with_linker_hash_style + with_diagnostics_color +@@ -1742,6 +1749,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --enable-ld[=ARG] build ld [ARG={default,yes,no}] + --enable-gold[=ARG] build gold [ARG={default,yes,no}] + --enable-gnu-indirect-function +@@ -1796,6 +1806,7 @@ Optional Features: + in a compiler-specific directory + --enable-plugin enable plugin support + --enable-host-shared build host code as shared libraries ++ --enable-host-pie build host code as PIE + --disable-libquadmath-support + disable libquadmath support for Fortran + --enable-default-pie enable Position Independent Executable as default +@@ -1860,6 +1871,9 @@ Optional Packages: + --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] ++ --with-darwin-extra-rpath=[ARG] ++ Specify a runpath directory, additional to those ++ provided by the compiler + --with-plugin-ld=[ARG] specify the plugin linker + --with-glibc-version=M.N + assume GCC used with glibc version M.N or later +@@ -3759,20 +3773,19 @@ gcc_gxx_libcxx_include_dir= + + # Check whether --with-gxx-libcxx-include-dir was given. + if test "${with_gxx_libcxx_include_dir+set}" = set; then : +- withval=$with_gxx_libcxx_include_dir; case "${withval}" in +-yes) as_fn_error $? "bad value ${withval} given for libc++ include directory" "$LINENO" 5 ;; +-*) gcc_gxx_libcxx_include_dir=$with_gxx_libcxx_include_dir ;; +-esac ++ withval=$with_gxx_libcxx_include_dir; gcc_gxx_libcxx_include_dir=$with_gxx_libcxx_include_dir + fi + + + # --with-gxx-libcxx-include-dir controls the enabling of the -stdlib option. + # if --with-gxx-libcxx-include-dir is 'no' we disable the stdlib option. ++# if --with-gxx-libcxx-include-dir is 'yes' we enable the stdlib option and use ++# the default path within the installation. + # if --with-gxx-libcxx-include-dir is unset we enable the stdlib option +-# based on the platform (to be available on platform versions where it is the ++# based on the platform (to be available on platform versions where it is the + # default for the system tools). We also use a default path within the compiler +-# install tree. +-# Otherwise, we use the path provided and enable the stdlib option. ++# install tree. ++# Otherwise, we use the path provided and enable the stdlib option. + # If both --with-sysroot and --with-gxx-libcxx-include-dir are passed, we + # check to see if the latter starts with the former and, upon success, compute + # gcc_gxx_libcxx_include_dir as relative to the sysroot. +@@ -3780,16 +3793,20 @@ gcc_gxx_libcxx_include_dir_add_sysroot=0 + gcc_enable_stdlib_opt=0 + if test x${gcc_gxx_libcxx_include_dir} != x; then + if test x${gcc_gxx_libcxx_include_dir} = xno; then +- # set defaults for the dir, but the option is disabled anyway. ++ # set defaults for the dir, but the option is disabled anyway. + gcc_gxx_libcxx_include_dir= ++ elif test x${gcc_gxx_libcxx_include_dir} = xyes; then ++ # set defaults for the dir, and enable. ++ gcc_gxx_libcxx_include_dir= ++ gcc_enable_stdlib_opt=1 + else + gcc_enable_stdlib_opt=1 + fi + else + case $target in + *-darwin1[1-9]* | *-darwin2*) +- # Default this on for Darwin versions which default to libcxx, +- # and embed the path in the compiler install so that we get a ++ # Default this on for Darwin versions which default to libcxx, ++ # and embed the path in the compiler install so that we get a + # self-contained toolchain. + gcc_enable_stdlib_opt=1 + ;; +@@ -16341,7 +16358,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -18046,6 +18063,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -18063,9 +18123,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -19871,7 +19935,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 19874 "configure" ++#line 19938 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -19977,7 +20041,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 19980 "configure" ++#line 20044 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -20853,6 +20917,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc_CXX=no + hardcode_direct_CXX=no + hardcode_automatic_CXX=yes +@@ -20870,12 +20977,20 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + if test "$lt_cv_apple_cc_single_mod" != "yes"; then +- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring${_lt_dsymutil}" + archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" + fi + +@@ -23246,6 +23361,35 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ ++DARWIN_DO_EXTRA_RPATH=0 ++ ++# Check whether --with-darwin-extra-rpath was given. ++if test "${with_darwin_extra_rpath+set}" = set; then : ++ withval=$with_darwin_extra_rpath; if test x"$withval" != x; then ++ DARWIN_ADD_RPATH="$withval" ++ DARWIN_DO_EXTRA_RPATH=1 ++ fi ++fi ++ ++ ++cat >>confdefs.h <<_ACEOF ++#define DARWIN_DO_EXTRA_RPATH $DARWIN_DO_EXTRA_RPATH ++_ACEOF ++ ++ ++cat >>confdefs.h <<_ACEOF ++#define DARWIN_ADD_RPATH "$DARWIN_ADD_RPATH" ++_ACEOF ++ ++ + # Identify the assembler which will work hand-in-glove with the newly + # built GCC, so that we can examine its features. This is the assembler + # which will be driven by the driver program. +@@ -23522,6 +23666,14 @@ fi + $as_echo "$gold_non_default" >&6; } + + ORIGINAL_LD_FOR_TARGET=$gcc_cv_ld ++if test x"$ld64_flag" = x"yes"; then ++ORIGINAL_LLD_FOR_TARGET=${gcc_cv_ld}64.lld ++else ++ORIGINAL_LLD_FOR_TARGET=$gcc_cv_lld ++fi ++ORIGINAL_CLASSIC_LD_FOR_TARGET=$gcc_cv_ld-classic ++ ++ + + case "$ORIGINAL_LD_FOR_TARGET" in + ./collect-ld | ./collect-ld$build_exeext) ;; +@@ -30638,6 +30790,7 @@ if test x"$ld64_flag" = x"yes"; then + # Set defaults for possibly untestable items. + gcc_cv_ld64_export_dynamic=0 + gcc_cv_ld64_platform_version=0 ++ gcc_cv_ld64_demangle=0 + + if test "$build" = "$host"; then + darwin_try_test=1 +@@ -30661,6 +30814,9 @@ $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 97; then ++ gcc_cv_ld64_demangle=1 ++ fi + if test "$gcc_cv_ld64_major" -ge 236; then + gcc_cv_ld64_export_dynamic=1 + fi +@@ -30678,6 +30834,15 @@ $as_echo_n "checking linker version... " >&6; } + { $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 -demangle support" >&5 ++$as_echo_n "checking linker for -demangle support... " >&6; } ++ gcc_cv_ld64_demangle=1 ++ if $gcc_cv_ld -demangle < /dev/null 2>&1 | grep 'unknown option' > /dev/null; then ++ gcc_cv_ld64_demangle=0 ++ fi ++ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_ld64_demangle" >&5 ++$as_echo "$gcc_cv_ld64_demangle" >&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 +@@ -30706,6 +30871,12 @@ _ACEOF + fi + + ++cat >>confdefs.h <<_ACEOF ++#define LD64_HAS_DEMANGLE $gcc_cv_ld64_demangle ++_ACEOF ++ ++ ++ + cat >>confdefs.h <<_ACEOF + #define LD64_HAS_EXPORT_DYNAMIC $gcc_cv_ld64_export_dynamic + _ACEOF +@@ -32251,13 +32422,17 @@ fi + # Enable --enable-host-shared + # Check whether --enable-host-shared was given. + if test "${enable_host_shared+set}" = set; then : +- enableval=$enable_host_shared; PICFLAG=-fPIC +-else +- PICFLAG= ++ enableval=$enable_host_shared; + fi + + + ++# Enable --enable-host-pie ++# Check whether --enable-host-pie was given. ++if test "${enable_host_pie+set}" = set; then : ++ enableval=$enable_host_pie; ++fi ++ + + + # Check whether --enable-libquadmath-support was given. +@@ -32411,10 +32586,6 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_c_no_fpie" >&5 + $as_echo "$gcc_cv_c_no_fpie" >&6; } +-if test "$gcc_cv_c_no_fpie" = "yes"; then +- NO_PIE_CFLAGS="-fno-PIE" +-fi +- + + # Check if -no-pie works. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -no-pie option" >&5 +@@ -32439,11 +32610,28 @@ rm -f core conftest.err conftest.$ac_objext \ + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_no_pie" >&5 + $as_echo "$gcc_cv_no_pie" >&6; } +-if test "$gcc_cv_no_pie" = "yes"; then +- NO_PIE_FLAG="-no-pie" ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE ++elif test x$gcc_cv_c_no_fpie = xyes; then ++ PICFLAG=-fno-PIE ++else ++ PICFLAG= ++fi ++ ++if test x$enable_host_pie = xyes; then ++ LD_PICFLAG=-pie ++elif test x$gcc_cv_no_pie = xyes; then ++ LD_PICFLAG=-no-pie ++else ++ LD_PICFLAG= + fi + + ++ ++ + # Enable Intel CET on Intel CET enabled host if jit is enabled. + # Check whether --enable-cet was given. + if test "${enable_cet+set}" = set; then : +@@ -32926,6 +33114,10 @@ LTLIBOBJS=$ac_ltlibobjs + + + ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + + : "${CONFIG_STATUS=./config.status}" + ac_write_fail=0 +diff --git a/gcc/configure.ac b/gcc/configure.ac +index bf8ff4d6390..8c2ff477635 100644 +--- a/gcc/configure.ac ++++ b/gcc/configure.ac +@@ -235,18 +235,17 @@ gcc_gxx_libcxx_include_dir= + AC_ARG_WITH(gxx-libcxx-include-dir, + [AS_HELP_STRING([--with-gxx-libcxx-include-dir=DIR], + [specifies directory to find libc++ header files])], +-[case "${withval}" in +-yes) AC_MSG_ERROR(bad value ${withval} given for libc++ include directory) ;; +-*) gcc_gxx_libcxx_include_dir=$with_gxx_libcxx_include_dir ;; +-esac]) ++[gcc_gxx_libcxx_include_dir=$with_gxx_libcxx_include_dir]) + + # --with-gxx-libcxx-include-dir controls the enabling of the -stdlib option. + # if --with-gxx-libcxx-include-dir is 'no' we disable the stdlib option. ++# if --with-gxx-libcxx-include-dir is 'yes' we enable the stdlib option and use ++# the default path within the installation. + # if --with-gxx-libcxx-include-dir is unset we enable the stdlib option +-# based on the platform (to be available on platform versions where it is the ++# based on the platform (to be available on platform versions where it is the + # default for the system tools). We also use a default path within the compiler +-# install tree. +-# Otherwise, we use the path provided and enable the stdlib option. ++# install tree. ++# Otherwise, we use the path provided and enable the stdlib option. + # If both --with-sysroot and --with-gxx-libcxx-include-dir are passed, we + # check to see if the latter starts with the former and, upon success, compute + # gcc_gxx_libcxx_include_dir as relative to the sysroot. +@@ -254,16 +253,20 @@ gcc_gxx_libcxx_include_dir_add_sysroot=0 + gcc_enable_stdlib_opt=0 + if test x${gcc_gxx_libcxx_include_dir} != x; then + if test x${gcc_gxx_libcxx_include_dir} = xno; then +- # set defaults for the dir, but the option is disabled anyway. ++ # set defaults for the dir, but the option is disabled anyway. ++ gcc_gxx_libcxx_include_dir= ++ elif test x${gcc_gxx_libcxx_include_dir} = xyes; then ++ # set defaults for the dir, and enable. + gcc_gxx_libcxx_include_dir= ++ gcc_enable_stdlib_opt=1 + else + gcc_enable_stdlib_opt=1 + fi + else + case $target in + *-darwin1[[1-9]]* | *-darwin2*) +- # Default this on for Darwin versions which default to libcxx, +- # and embed the path in the compiler install so that we get a ++ # Default this on for Darwin versions which default to libcxx, ++ # and embed the path in the compiler install so that we get a + # self-contained toolchain. + gcc_enable_stdlib_opt=1 + ;; +@@ -2625,6 +2628,21 @@ AC_PROG_LIBTOOL + AC_SUBST(objdir) + AC_SUBST(enable_fast_install) + ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) ++DARWIN_DO_EXTRA_RPATH=0 ++AC_ARG_WITH(darwin-extra-rpath, ++[AS_HELP_STRING( ++ [[--with-darwin-extra-rpath=[ARG]]], ++ [Specify a runpath directory, additional to those provided by the compiler])], ++[if test x"$withval" != x; then ++ DARWIN_ADD_RPATH="$withval" ++ DARWIN_DO_EXTRA_RPATH=1 ++ fi]) ++AC_DEFINE_UNQUOTED(DARWIN_DO_EXTRA_RPATH, $DARWIN_DO_EXTRA_RPATH, ++ [Should add an extra runpath directory]) ++AC_DEFINE_UNQUOTED(DARWIN_ADD_RPATH, "$DARWIN_ADD_RPATH", ++ [Specify a runpath directory, additional to those provided by the compiler]) ++ + # Identify the assembler which will work hand-in-glove with the newly + # built GCC, so that we can examine its features. This is the assembler + # which will be driven by the driver program. +@@ -2797,7 +2815,15 @@ fi + AC_MSG_RESULT($gold_non_default) + + ORIGINAL_LD_FOR_TARGET=$gcc_cv_ld ++if test x"$ld64_flag" = x"yes"; then ++ORIGINAL_LLD_FOR_TARGET=${gcc_cv_ld}64.lld ++else ++ORIGINAL_LLD_FOR_TARGET=$gcc_cv_lld ++fi ++ORIGINAL_CLASSIC_LD_FOR_TARGET=$gcc_cv_ld-classic + AC_SUBST(ORIGINAL_LD_FOR_TARGET) ++AC_SUBST(ORIGINAL_LLD_FOR_TARGET) ++AC_SUBST(ORIGINAL_CLASSIC_LD_FOR_TARGET) + case "$ORIGINAL_LD_FOR_TARGET" in + ./collect-ld | ./collect-ld$build_exeext) ;; + *) AC_CONFIG_FILES(collect-ld:exec-tool.in, [chmod +x collect-ld]) ;; +@@ -4793,7 +4819,7 @@ foo: nop + gcc_cv_as_mllvm_x86_pad_for_align, + [-mllvm -x86-pad-for-align=false], [.text],, + [AC_DEFINE(HAVE_AS_MLLVM_X86_PAD_FOR_ALIGN, 1, +- [Define if your Mac OS X assembler supports -mllvm -x86-pad-for-align=false.])]) ++ [Define if your macOS assembler supports -mllvm -x86-pad-for-align=false.])]) + ;; + esac + +@@ -6273,6 +6299,7 @@ if test x"$ld64_flag" = x"yes"; then + # Set defaults for possibly untestable items. + gcc_cv_ld64_export_dynamic=0 + gcc_cv_ld64_platform_version=0 ++ gcc_cv_ld64_demangle=0 + + if test "$build" = "$host"; then + darwin_try_test=1 +@@ -6294,6 +6321,9 @@ if test x"$ld64_flag" = x"yes"; 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 97; then ++ gcc_cv_ld64_demangle=1 ++ fi + if test "$gcc_cv_ld64_major" -ge 236; then + gcc_cv_ld64_export_dynamic=1 + fi +@@ -6309,6 +6339,13 @@ if test x"$ld64_flag" = x"yes"; then + fi + AC_MSG_RESULT($gcc_cv_ld64_version) + ++ AC_MSG_CHECKING(linker for -demangle support) ++ gcc_cv_ld64_demangle=1 ++ if $gcc_cv_ld -demangle < /dev/null 2>&1 | grep 'unknown option' > /dev/null; then ++ gcc_cv_ld64_demangle=0 ++ fi ++ AC_MSG_RESULT($gcc_cv_ld64_demangle) ++ + 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 +@@ -6329,6 +6366,9 @@ if test x"$ld64_flag" = x"yes"; then + [Define to ld64 version.]) + fi + ++ AC_DEFINE_UNQUOTED(LD64_HAS_DEMANGLE, $gcc_cv_ld64_demangle, ++ [Define to 1 if ld64 supports '-demangle'.]) ++ + AC_DEFINE_UNQUOTED(LD64_HAS_EXPORT_DYNAMIC, $gcc_cv_ld64_export_dynamic, + [Define to 1 if ld64 supports '-export_dynamic'.]) + +@@ -7479,11 +7519,14 @@ fi + # Enable --enable-host-shared + AC_ARG_ENABLE(host-shared, + [AS_HELP_STRING([--enable-host-shared], +- [build host code as shared libraries])], +-[PICFLAG=-fPIC], [PICFLAG=]) ++ [build host code as shared libraries])]) + AC_SUBST(enable_host_shared) +-AC_SUBST(PICFLAG) + ++# Enable --enable-host-pie ++AC_ARG_ENABLE(host-pie, ++[AS_HELP_STRING([--enable-host-pie], ++ [build host code as PIE])]) ++AC_SUBST(enable_host_pie) + + AC_ARG_ENABLE(libquadmath-support, + [AS_HELP_STRING([--disable-libquadmath-support], +@@ -7605,10 +7648,6 @@ AC_CACHE_CHECK([for -fno-PIE option], + [gcc_cv_c_no_fpie=yes], + [gcc_cv_c_no_fpie=no]) + CXXFLAGS="$saved_CXXFLAGS"]) +-if test "$gcc_cv_c_no_fpie" = "yes"; then +- NO_PIE_CFLAGS="-fno-PIE" +-fi +-AC_SUBST([NO_PIE_CFLAGS]) + + # Check if -no-pie works. + AC_CACHE_CHECK([for -no-pie option], +@@ -7619,10 +7658,27 @@ AC_CACHE_CHECK([for -no-pie option], + [gcc_cv_no_pie=yes], + [gcc_cv_no_pie=no]) + LDFLAGS="$saved_LDFLAGS"]) +-if test "$gcc_cv_no_pie" = "yes"; then +- NO_PIE_FLAG="-no-pie" ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE ++elif test x$gcc_cv_c_no_fpie = xyes; then ++ PICFLAG=-fno-PIE ++else ++ PICFLAG= + fi +-AC_SUBST([NO_PIE_FLAG]) ++ ++if test x$enable_host_pie = xyes; then ++ LD_PICFLAG=-pie ++elif test x$gcc_cv_no_pie = xyes; then ++ LD_PICFLAG=-no-pie ++else ++ LD_PICFLAG= ++fi ++ ++AC_SUBST([PICFLAG]) ++AC_SUBST([LD_PICFLAG]) + + # Enable Intel CET on Intel CET enabled host if jit is enabled. + GCC_CET_HOST_FLAGS(CET_HOST_FLAGS) +diff --git a/gcc/coretypes.h b/gcc/coretypes.h +index ca8837cef67..7e022a427c4 100644 +--- a/gcc/coretypes.h ++++ b/gcc/coretypes.h +@@ -199,6 +199,12 @@ enum tls_model { + TLS_MODEL_LOCAL_EXEC + }; + ++/* Types of trampoline implementation. */ ++enum trampoline_impl { ++ TRAMPOLINE_IMPL_STACK, ++ TRAMPOLINE_IMPL_HEAP ++}; ++ + /* Types of ABI for an offload compiler. */ + enum offload_abi { + OFFLOAD_ABI_UNSET, +diff --git a/gcc/cp/cp-lang.cc b/gcc/cp/cp-lang.cc +index 2f541460c4a..84200a9a04a 100644 +--- a/gcc/cp/cp-lang.cc ++++ b/gcc/cp/cp-lang.cc +@@ -121,6 +121,15 @@ objcp_tsubst_copy_and_build (tree /*t*/, + return NULL_TREE; + } + ++/* Implement c-family hook to add language-specific features ++ for __has_{feature,extension}. */ ++ ++void ++c_family_register_lang_features () ++{ ++ cp_register_features (); ++} ++ + static const char * + cxx_dwarf_name (tree t, int verbosity) + { +diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc +index 93b027b80ce..10b9b35a1c0 100644 +--- a/gcc/cp/cp-objcp-common.cc ++++ b/gcc/cp/cp-objcp-common.cc +@@ -23,10 +23,153 @@ along with GCC; see the file COPYING3. If not see + #include "coretypes.h" + #include "cp-tree.h" + #include "cp-objcp-common.h" ++#include "c-family/c-common.h" + #include "dwarf2.h" + #include "stringpool.h" + #include "contracts.h" + ++/* Class to determine whether a given C++ language feature is available. ++ Used to implement __has_{feature,extension}. */ ++ ++struct cp_feature_selector ++{ ++ enum ++ { ++ DIALECT, ++ FLAG ++ } kind; ++ ++ enum class result ++ { ++ NONE, ++ EXT, ++ FEAT ++ }; ++ ++ union ++ { ++ const int *enable_flag; ++ struct { ++ enum cxx_dialect feat; ++ enum cxx_dialect ext; ++ } dialect; ++ }; ++ ++ constexpr cp_feature_selector (const int *flag) ++ : kind (FLAG), enable_flag (flag) {} ++ constexpr cp_feature_selector (enum cxx_dialect feat, ++ enum cxx_dialect ext) ++ : kind (DIALECT), dialect{feat, ext} {} ++ constexpr cp_feature_selector (enum cxx_dialect feat) ++ : cp_feature_selector (feat, feat) {} ++ ++ inline result has_feature () const; ++}; ++ ++/* Check whether this language feature is available as a feature, ++ extension, or not at all. */ ++ ++cp_feature_selector::result ++cp_feature_selector::has_feature () const ++{ ++ switch (kind) ++ { ++ case DIALECT: ++ if (cxx_dialect >= dialect.feat) ++ return result::FEAT; ++ else if (cxx_dialect >= dialect.ext) ++ return result::EXT; ++ else ++ return result::NONE; ++ case FLAG: ++ return *enable_flag ? result::FEAT : result::NONE; ++ } ++ ++ gcc_unreachable (); ++} ++ ++/* Information about a C++ language feature which can be queried ++ through __has_{feature,extension}. IDENT is the name of the feature, ++ and SELECTOR encodes how to compute whether the feature is available. */ ++ ++struct cp_feature_info ++{ ++ const char *ident; ++ cp_feature_selector selector; ++}; ++ ++/* Table of features for __has_{feature,extension}. */ ++ ++static constexpr cp_feature_info cp_feature_table[] = ++{ ++ { "cxx_exceptions", &flag_exceptions }, ++ { "cxx_rtti", &flag_rtti }, ++ { "cxx_access_control_sfinae", { cxx11, cxx98 } }, ++ { "cxx_alias_templates", cxx11 }, ++ { "cxx_alignas", cxx11 }, ++ { "cxx_alignof", cxx11 }, ++ { "cxx_attributes", cxx11 }, ++ { "cxx_constexpr", cxx11 }, ++ { "cxx_decltype", cxx11 }, ++ { "cxx_decltype_incomplete_return_types", cxx11 }, ++ { "cxx_default_function_template_args", cxx11 }, ++ { "cxx_defaulted_functions", cxx11 }, ++ { "cxx_delegating_constructors", cxx11 }, ++ { "cxx_deleted_functions", cxx11 }, ++ { "cxx_explicit_conversions", cxx11 }, ++ { "cxx_generalized_initializers", cxx11 }, ++ { "cxx_implicit_moves", cxx11 }, ++ { "cxx_inheriting_constructors", cxx11 }, ++ { "cxx_inline_namespaces", { cxx11, cxx98 } }, ++ { "cxx_lambdas", cxx11 }, ++ { "cxx_local_type_template_args", cxx11 }, ++ { "cxx_noexcept", cxx11 }, ++ { "cxx_nonstatic_member_init", cxx11 }, ++ { "cxx_nullptr", cxx11 }, ++ { "cxx_override_control", cxx11 }, ++ { "cxx_reference_qualified_functions", cxx11 }, ++ { "cxx_range_for", cxx11 }, ++ { "cxx_raw_string_literals", cxx11 }, ++ { "cxx_rvalue_references", cxx11 }, ++ { "cxx_static_assert", cxx11 }, ++ { "cxx_thread_local", cxx11 }, ++ { "cxx_auto_type", cxx11 }, ++ { "cxx_strong_enums", cxx11 }, ++ { "cxx_trailing_return", cxx11 }, ++ { "cxx_unicode_literals", cxx11 }, ++ { "cxx_unrestricted_unions", cxx11 }, ++ { "cxx_user_literals", cxx11 }, ++ { "cxx_variadic_templates", { cxx11, cxx98 } }, ++ { "cxx_binary_literals", { cxx14, cxx98 } }, ++ { "cxx_contextual_conversions", { cxx14, cxx98 } }, ++ { "cxx_decltype_auto", cxx14 }, ++ { "cxx_aggregate_nsdmi", cxx14 }, ++ { "cxx_init_captures", { cxx14, cxx11 } }, ++ { "cxx_generic_lambdas", cxx14 }, ++ { "cxx_relaxed_constexpr", cxx14 }, ++ { "cxx_return_type_deduction", cxx14 }, ++ { "cxx_variable_templates", cxx14 }, ++ { "modules", &flag_modules }, ++}; ++ ++/* Register C++ language features for __has_{feature,extension}. */ ++ ++void ++cp_register_features () ++{ ++ using result = cp_feature_selector::result; ++ ++ for (unsigned i = 0; i < ARRAY_SIZE (cp_feature_table); i++) ++ { ++ const cp_feature_info *info = cp_feature_table + i; ++ const auto res = info->selector.has_feature (); ++ if (res == result::NONE) ++ continue; ++ ++ c_common_register_feature (info->ident, res == result::FEAT); ++ } ++} ++ + /* Special routine to get the alias set for C++. */ + + alias_set_type +diff --git a/gcc/cp/cp-objcp-common.h b/gcc/cp/cp-objcp-common.h +index 80893aa1752..9d4d873deb7 100644 +--- a/gcc/cp/cp-objcp-common.h ++++ b/gcc/cp/cp-objcp-common.h +@@ -34,6 +34,7 @@ extern tree cp_classtype_as_base (const_tree); + extern tree cp_get_global_decls (); + extern tree cp_pushdecl (tree); + extern void cp_register_dumps (gcc::dump_manager *); ++extern void cp_register_features (); + extern bool cp_handle_option (size_t, const char *, HOST_WIDE_INT, int, + location_t, const struct cl_option_handlers *); + extern tree cxx_make_type_hook (tree_code); +diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc +index 36e1f2ce300..213e52c70e4 100644 +--- a/gcc/cp/decl2.cc ++++ b/gcc/cp/decl2.cc +@@ -3712,9 +3712,8 @@ get_tls_init_fn (tree var) + if (!flag_extern_tls_init && DECL_EXTERNAL (var)) + return NULL_TREE; + +- /* If the variable is internal, or if we can't generate aliases, +- call the local init function directly. */ +- if (!TREE_PUBLIC (var) || !TARGET_SUPPORTS_ALIASES) ++ /* If the variable is internal call the local init function directly. */ ++ if (!TREE_PUBLIC (var)) + return get_local_tls_init_fn (DECL_SOURCE_LOCATION (var)); + + tree sname = mangle_tls_init_fn (var); +@@ -3877,6 +3876,25 @@ generate_tls_wrapper (tree fn) + expand_or_defer_fn (finish_function (/*inline_p=*/false)); + } + ++/* A dummy init function to act as a weak placeholder for a (possibly non- ++ existent) dynamic init. */ ++static void ++generate_tls_dummy_init (tree fn) ++{ ++ tree var = DECL_BEFRIENDING_CLASSES (fn); ++ tree init_fn = get_tls_init_fn (var); ++ /* If have no init fn, or it is non-weak, then we do not need to make a ++ dummy. */ ++ if (!init_fn || !lookup_attribute ("weak", DECL_ATTRIBUTES (init_fn))) ++ return; ++ start_preparsed_function (init_fn, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED); ++ tree body = begin_function_body (); ++ declare_weak (init_fn); ++ finish_return_stmt (NULL_TREE); ++ finish_function_body (body); ++ expand_or_defer_fn (finish_function (/*inline_p=*/false)); ++} ++ + /* Start a global constructor or destructor function. */ + + static tree +@@ -4666,22 +4684,24 @@ handle_tls_init (void) + finish_expr_stmt (cp_build_modify_expr (loc, guard, NOP_EXPR, + boolean_true_node, + tf_warning_or_error)); ++ auto_vec direct_calls; + for (; vars; vars = TREE_CHAIN (vars)) + { + tree var = TREE_VALUE (vars); + tree init = TREE_PURPOSE (vars); + one_static_initialization_or_destruction (/*initp=*/true, var, init); + +- /* Output init aliases even with -fno-extern-tls-init. */ +- if (TARGET_SUPPORTS_ALIASES && TREE_PUBLIC (var)) ++ /* Output inits even with -fno-extern-tls-init. ++ We save the list here and output either an alias or a stub function ++ below. */ ++ if (TREE_PUBLIC (var)) + { +- tree single_init_fn = get_tls_init_fn (var); ++ tree single_init_fn = get_tls_init_fn (var); + if (single_init_fn == NULL_TREE) + continue; +- cgraph_node *alias +- = cgraph_node::get_create (fn)->create_same_body_alias +- (single_init_fn, fn); +- gcc_assert (alias != NULL); ++ if (single_init_fn == fn) ++ continue; ++ direct_calls.safe_push (single_init_fn); + } + } + +@@ -4689,6 +4709,30 @@ handle_tls_init (void) + finish_if_stmt (if_stmt); + finish_function_body (body); + expand_or_defer_fn (finish_function (/*inline_p=*/false)); ++ ++ /* For each TLS var that we have an init function, we either emit an alias ++ between that and the tls_init, or a stub function that just calls the ++ tls_init. */ ++ while (!direct_calls.is_empty()) ++ { ++ tree single_init_fn = direct_calls.pop (); ++ if (TARGET_SUPPORTS_ALIASES) ++ { ++ cgraph_node *alias ++ = cgraph_node::get_create (fn)->create_same_body_alias ++ (single_init_fn, fn); ++ gcc_assert (alias != NULL); ++ } ++ else ++ { ++ start_preparsed_function (single_init_fn, NULL_TREE, SF_PRE_PARSED); ++ tree body = begin_function_body (); ++ tree r = build_call_expr (fn, 0); ++ finish_expr_stmt (r); ++ finish_function_body (body); ++ expand_or_defer_fn (finish_function (/*inline_p=*/false)); ++ } ++ } + } + + /* We're at the end of compilation, so generate any mangling aliases that +@@ -5107,7 +5151,14 @@ c_parse_final_cleanups (void) + } + + if (!DECL_INITIAL (decl) && decl_tls_wrapper_p (decl)) +- generate_tls_wrapper (decl); ++ { ++ generate_tls_wrapper (decl); ++ /* The wrapper might have a weak reference to an init, we provide ++ a dummy function to satisfy that here. The linker/dynamic ++ loader will override this with the actual init, if one is ++ required. */ ++ generate_tls_dummy_init (decl); ++ } + + if (!DECL_SAVED_TREE (decl)) + continue; +diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc +index 4e67da6ff3a..1f1b76234b4 100644 +--- a/gcc/cp/parser.cc ++++ b/gcc/cp/parser.cc +@@ -694,6 +694,91 @@ cp_lexer_handle_early_pragma (cp_lexer *lexer) + static cp_parser *cp_parser_new (cp_lexer *); + static GTY (()) cp_parser *the_parser; + ++/* Context-sensitive parse-checking for clang-style attributes. */ ++ ++enum clang_attr_state { ++ CA_NONE = 0, ++ CA_ATTR, ++ CA_BR1, CA_BR2, ++ CA_LIST, ++ CA_LIST_ARGS, ++ CA_IS_CA, ++ CA_CA_ARGS, ++ CA_LIST_CONT ++}; ++ ++/* State machine tracking context of attribute lexing. */ ++ ++static enum clang_attr_state ++cp_lexer_attribute_state (cp_token& token, enum clang_attr_state attr_state) ++{ ++ /* Implement a context-sensitive parser for clang attributes. ++ We detect __attribute__((clang_style_attribute (ARGS))) and lex the ++ args ARGS with the following differences from GNU attributes: ++ (a) number-like values are lexed as strings [this allows lexing XX.YY.ZZ ++ version numbers]. ++ (b) we concatenate strings, since clang attributes allow this too. */ ++ switch (attr_state) ++ { ++ case CA_NONE: ++ if (token.type == CPP_KEYWORD ++ && token.keyword == RID_ATTRIBUTE) ++ attr_state = CA_ATTR; ++ break; ++ case CA_ATTR: ++ if (token.type == CPP_OPEN_PAREN) ++ attr_state = CA_BR1; ++ else ++ attr_state = CA_NONE; ++ break; ++ case CA_BR1: ++ if (token.type == CPP_OPEN_PAREN) ++ attr_state = CA_BR2; ++ else ++ attr_state = CA_NONE; ++ break; ++ case CA_BR2: ++ if (token.type == CPP_NAME) ++ { ++ tree identifier = (token.type == CPP_KEYWORD) ++ /* For keywords, use the canonical spelling, not the ++ parsed identifier. */ ++ ? ridpointers[(int) token.keyword] ++ : token.u.value; ++ identifier = canonicalize_attr_name (identifier); ++ if (attribute_clang_form_p (identifier)) ++ attr_state = CA_IS_CA; ++ else ++ attr_state = CA_LIST; ++ } ++ else ++ attr_state = CA_NONE; ++ break; ++ case CA_IS_CA: ++ case CA_LIST: ++ if (token.type == CPP_COMMA) ++ attr_state = CA_BR2; /* Back to the list outer. */ ++ else if (token.type == CPP_OPEN_PAREN) ++ attr_state = attr_state == CA_IS_CA ? CA_CA_ARGS ++ : CA_LIST_ARGS; ++ else ++ attr_state = CA_NONE; ++ break; ++ case CA_CA_ARGS: /* We will special-case args in this state. */ ++ case CA_LIST_ARGS: ++ if (token.type == CPP_CLOSE_PAREN) ++ attr_state = CA_LIST_CONT; ++ break; ++ case CA_LIST_CONT: ++ if (token.type == CPP_COMMA) ++ attr_state = CA_BR2; /* Back to the list outer. */ ++ else ++ attr_state = CA_NONE; ++ break; ++ } ++ return attr_state; ++} ++ + /* Create a new main C++ lexer, the lexer that gets tokens from the + preprocessor, and also create the main parser. */ + +@@ -710,6 +795,8 @@ cp_lexer_new_main (void) + c_common_no_more_pch (); + + cp_lexer *lexer = cp_lexer_alloc (); ++ enum clang_attr_state attr_state = CA_NONE; ++ + /* Put the first token in the buffer. */ + cp_token *tok = lexer->buffer->quick_push (token); + +@@ -733,8 +820,14 @@ cp_lexer_new_main (void) + if (tok->type == CPP_PRAGMA_EOL) + cp_lexer_handle_early_pragma (lexer); + ++ attr_state = cp_lexer_attribute_state (*tok, attr_state); + tok = vec_safe_push (lexer->buffer, cp_token ()); +- cp_lexer_get_preprocessor_token (C_LEX_STRING_NO_JOIN, tok); ++ unsigned int flags = C_LEX_STRING_NO_JOIN; ++ /* If we are processing clang-style attribute args, lex numbers as ++ potential version strings; NN .. NN.MM .. NN.MM.OO */ ++ if (attr_state == CA_CA_ARGS) ++ flags |= C_LEX_NUMBER_AS_STRING; ++ cp_lexer_get_preprocessor_token (flags, tok); + } + + lexer->next_token = lexer->buffer->address (); +@@ -936,7 +1029,7 @@ cp_lexer_get_preprocessor_token (unsigned flags, cp_token *token) + { + static int is_extern_c = 0; + +- /* Get a new token from the preprocessor. */ ++ /* Get a new token from the preprocessor. */ + token->type + = c_lex_with_flags (&token->u.value, &token->location, &token->flags, + flags); +@@ -20992,11 +21085,13 @@ cp_parser_enum_specifier (cp_parser* parser) + + /* Check for the `:' that denotes a specified underlying type in C++0x. + Note that a ':' could also indicate a bitfield width, however. */ ++ location_t colon_loc = UNKNOWN_LOCATION; + if (cp_lexer_next_token_is (parser->lexer, CPP_COLON)) + { + cp_decl_specifier_seq type_specifiers; + + /* Consume the `:'. */ ++ colon_loc = cp_lexer_peek_token (parser->lexer)->location; + cp_lexer_consume_token (parser->lexer); + + auto tdf +@@ -21045,10 +21140,13 @@ cp_parser_enum_specifier (cp_parser* parser) + && cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON)) + { + if (has_underlying_type) +- cp_parser_commit_to_tentative_parse (parser); +- cp_parser_error (parser, "expected %<;%> or %<{%>"); +- if (has_underlying_type) +- return error_mark_node; ++ pedwarn (colon_loc, ++ OPT_Welaborated_enum_base, ++ "declaration of enumeration with " ++ "fixed underlying type and no enumerator list is " ++ "only permitted as a standalone declaration"); ++ else ++ cp_parser_error (parser, "expected %<;%> or %<{%>"); + } + } + +@@ -22772,9 +22870,16 @@ cp_parser_init_declarator (cp_parser* parser, + "an % specification is not allowed " + "on a function-definition"); + if (attributes) +- error_at (attributes_start_token->location, +- "attributes are not allowed " +- "on a function-definition"); ++ { ++ /* When we are allowing attributes in this position, then add ++ them to the prefix ones. */ ++ if (flag_allow_ext_attr_placement) ++ prefix_attributes = chainon (prefix_attributes, attributes); ++ else ++ error_at (attributes_start_token->location, ++ "attributes are not allowed " ++ "on a function-definition"); ++ } + /* This is a function-definition. */ + *function_definition_p = true; + +@@ -29051,6 +29156,91 @@ cp_parser_gnu_attributes_opt (cp_parser* parser) + return attributes; + } + ++/* Parse the arguments list for a clang attribute. */ ++static tree ++cp_parser_clang_attribute (cp_parser *parser, tree/*attr_id*/) ++{ ++ /* Each entry can be : ++ identifier ++ identifier=N.MM.Z ++ identifier="string" ++ followed by ',' or ) for the last entry*/ ++ ++ matching_parens parens; ++ if (!parens.require_open (parser)) ++ return NULL; ++ ++ bool save_translate_strings_p = parser->translate_strings_p; ++ parser->translate_strings_p = false; ++ tree attr_args = NULL_TREE; ++ cp_token *token; ++ do ++ { ++ tree name = NULL_TREE; ++ tree value = NULL_TREE; ++ ++ token = cp_lexer_peek_token (parser->lexer); ++ if (token->type == CPP_NAME) ++ name = token->u.value; ++ else if (token->type == CPP_KEYWORD) ++ name = ridpointers[(int) token->keyword]; ++ else if (token->flags & NAMED_OP) ++ name = get_identifier (cpp_type2name (token->type, token->flags)); ++ else ++ { ++ /* FIXME: context-sensitive for that attrib. */ ++ error_at (token->location, "expected an attribute keyword"); ++ cp_parser_skip_to_closing_parenthesis (parser, ++ /*recovering=*/true, ++ /*or_comma=*/false, ++ /*consume_paren=*/false); ++ attr_args = error_mark_node; ++ break; ++ } ++ cp_lexer_consume_token (parser->lexer); ++ ++ if (cp_lexer_next_token_is (parser->lexer, CPP_EQ)) ++ { ++ cp_lexer_consume_token (parser->lexer); /* eat the '=' */ ++ if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN) ++ && cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA)) ++ { ++ token = cp_lexer_peek_token (parser->lexer); ++ if (token->type == CPP_STRING) ++ value = cp_parser_string_literal (parser, /*translate=*/false, ++ /*wide_ok=*/false); ++ else ++ { ++ value = token->u.value; ++ cp_lexer_consume_token (parser->lexer); ++ } ++ } ++ /* else value is missing. */ ++ } ++ else if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN) ++ && cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA)) ++ { ++ error_at (token->location, "expected %<,%>, %<=%> or %<)%>"); ++ cp_parser_skip_to_closing_parenthesis (parser, ++ /*recovering=*/true, ++ /*or_comma=*/false, ++ /*consume_paren=*/false); ++ attr_args = error_mark_node; ++ break; ++ } ++ if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA)) ++ cp_lexer_consume_token (parser->lexer); ++ tree t = tree_cons (value, name, NULL_TREE); ++ attr_args = chainon (attr_args, t); ++ } while (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN)); ++ ++ parser->translate_strings_p = save_translate_strings_p; ++ if (!parens.require_close (parser)) ++ return error_mark_node; ++ ++ return attr_args; ++} ++ + /* Parse a GNU attribute-list. + + attribute-list: +@@ -29110,9 +29293,12 @@ cp_parser_gnu_attribute_list (cp_parser* parser, bool exactly_one /* = false */) + + /* Peek at the next token. */ + token = cp_lexer_peek_token (parser->lexer); +- /* If it's an `(', then parse the attribute arguments. */ +- if (token->type == CPP_OPEN_PAREN) ++ if (token->type == CPP_OPEN_PAREN ++ && attribute_clang_form_p (identifier)) ++ arguments = cp_parser_clang_attribute (parser, identifier); ++ else if (token->type == CPP_OPEN_PAREN) + { ++ /* If it's an `(', then parse the attribute arguments. */ + vec *vec; + int attr_flag = (attribute_takes_identifier_p (identifier) + ? id_attr : normal_attr); +@@ -29129,12 +29315,12 @@ cp_parser_gnu_attribute_list (cp_parser* parser, bool exactly_one /* = false */) + arguments = build_tree_list_vec (vec); + release_tree_vector (vec); + } +- /* Save the arguments away. */ +- TREE_VALUE (attribute) = arguments; + } + + if (arguments != error_mark_node) + { ++ /* Save the arguments away. */ ++ TREE_VALUE (attribute) = arguments; + /* Add this attribute to the list. */ + TREE_CHAIN (attribute) = attribute_list; + attribute_list = attribute; +diff --git a/gcc/cumulative-args.h b/gcc/cumulative-args.h +new file mode 100644 +index 00000000000..b60928e37f9 +--- /dev/null ++++ b/gcc/cumulative-args.h +@@ -0,0 +1,20 @@ ++#ifndef GCC_CUMULATIVE_ARGS_H ++#define GCC_CUMULATIVE_ARGS_H ++ ++#if CHECKING_P ++ ++struct cumulative_args_t { void *magic; void *p; }; ++ ++#else /* !CHECKING_P */ ++ ++/* When using a GCC build compiler, we could use ++ __attribute__((transparent_union)) to get cumulative_args_t function ++ arguments passed like scalars where the ABI would mandate a less ++ efficient way of argument passing otherwise. However, that would come ++ at the cost of less type-safe !CHECKING_P compilation. */ ++ ++union cumulative_args_t { void *p; }; ++ ++#endif /* !CHECKING_P */ ++ ++#endif /* GCC_CUMULATIVE_ARGS_H */ +diff --git a/gcc/d/Make-lang.in b/gcc/d/Make-lang.in +index 1679fb81097..4fbf2096416 100644 +--- a/gcc/d/Make-lang.in ++++ b/gcc/d/Make-lang.in +@@ -64,7 +64,7 @@ ALL_DFLAGS = $(DFLAGS-$@) $(GDCFLAGS) -fversion=IN_GCC $(CHECKING_DFLAGS) \ + $(PICFLAG) $(ALIASING_FLAGS) $(NOEXCEPTION_DFLAGS) $(COVERAGE_FLAGS) \ + $(WARN_DFLAGS) + +-DCOMPILE.base = $(GDC) $(NO_PIE_CFLAGS) -c $(ALL_DFLAGS) -o $@ ++DCOMPILE.base = $(GDC) -c $(ALL_DFLAGS) -o $@ + DCOMPILE = $(DCOMPILE.base) -MT $@ -MMD -MP -MF $(@D)/$(DEPDIR)/$(*F).TPo + DPOSTCOMPILE = @mv $(@D)/$(DEPDIR)/$(*F).TPo $(@D)/$(DEPDIR)/$(*F).Po + DLINKER = $(GDC) $(NO_PIE_FLAG) -lstdc++ +diff --git a/gcc/doc/contrib.texi b/gcc/doc/contrib.texi +index 758805dc5db..f8f002cdc8e 100644 +--- a/gcc/doc/contrib.texi ++++ b/gcc/doc/contrib.texi +@@ -1515,7 +1515,7 @@ Gael Thomas for @code{VMClassLoader} boot packages support suggestions. + + @item + Andreas Tobler for Darwin and Solaris testing and fixing, @code{Qt4} +-support for Darwin/OS X, @code{Graphics2D} support, @code{gtk+} ++support for Darwin / macOS, @code{Graphics2D} support, @code{gtk+} + updates. + + @item +diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi +index b0a2ce3ac6b..f57278dd2e8 100644 +--- a/gcc/doc/cpp.texi ++++ b/gcc/doc/cpp.texi +@@ -3198,6 +3198,8 @@ directive}: @samp{#if}, @samp{#ifdef} or @samp{#ifndef}. + * @code{__has_cpp_attribute}:: + * @code{__has_c_attribute}:: + * @code{__has_builtin}:: ++* @code{__has_feature}:: ++* @code{__has_extension}:: + * @code{__has_include}:: + @end menu + +@@ -3560,6 +3562,45 @@ the operator is as follows: + #endif + @end smallexample + ++@node @code{__has_feature} ++@subsection @code{__has_feature} ++@cindex @code{__has_feature} ++ ++The special operator @code{__has_feature (@var{operand})} may be used in ++constant integer contexts and in preprocessor @samp{#if} and @samp{#elif} ++expressions to test whether the identifier given in @var{operand} is recognized ++as a feature supported by GCC given the current options and, in the case of ++standard language features, whether the feature is available in the chosen ++version of the language standard. ++ ++Note that @code{__has_feature} and @code{__has_extension} are not recommended ++for use in new code, and are only provided for compatibility with Clang. For ++details of which identifiers are accepted by these function-like macros, see ++@w{@uref{https://clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension, ++the Clang documentation}}. ++ ++@node @code{__has_extension} ++@subsection @code{__has_extension} ++@cindex @code{__has_extension} ++ ++The special operator @code{__has_extension (@var{operand})} may be used in ++constant integer contexts and in preprocessor @samp{#if} and @samp{#elif} ++expressions to test whether the identifier given in @var{operand} is recognized ++as an extension supported by GCC given the current options. In any given ++context, the features accepted by @code{__has_extension} are a strict superset ++of those accepted by @code{__has_feature}. Unlike @code{__has_feature}, ++@code{__has_extension} tests whether a given feature is available regardless of ++strict language standards conformance. ++ ++If the @option{-pedantic-errors} flag is given, @code{__has_extension} is ++equivalent to @code{__has_feature}. ++ ++Note that @code{__has_feature} and @code{__has_extension} are not recommended ++for use in new code, and are only provided for compatibility with Clang. For ++details of which identifiers are accepted by these function-like macros, see ++@w{@uref{https://clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension, ++the Clang documentation}}. ++ + @node @code{__has_include} + @subsection @code{__has_include} + @cindex @code{__has_include} +diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi +index d6fcd611339..a16375085d5 100644 +--- a/gcc/doc/extend.texi ++++ b/gcc/doc/extend.texi +@@ -23797,7 +23797,7 @@ attribute, do change the value of preprocessor macros like + + The following pragmas are available for all architectures running the + Darwin operating system. These are useful for compatibility with other +-Mac OS compilers. ++macOS compilers. + + @table @code + @cindex pragma, mark +@@ -24976,7 +24976,7 @@ compiled separately. + @end table + + G++ implements the Borland model on targets where the linker supports it, +-including ELF targets (such as GNU/Linux), Mac OS X and Microsoft Windows. ++including ELF targets (such as GNU/Linux), macOS and Microsoft Windows. + Otherwise G++ implements neither automatic model. + + You have the following options for dealing with template instantiations: +diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi +index b30d3691fe6..de05d1c42da 100644 +--- a/gcc/doc/install.texi ++++ b/gcc/doc/install.texi +@@ -1075,14 +1075,26 @@ code. + + @item --enable-host-shared + Specify that the @emph{host} code should be built into position-independent +-machine code (with -fPIC), allowing it to be used within shared libraries, +-but yielding a slightly slower compiler. ++machine code (with @option{-fPIC}), allowing it to be used within shared ++libraries, but yielding a slightly slower compiler. + + This option is required when building the libgccjit.so library. + + Contrast with @option{--enable-shared}, which affects @emph{target} + libraries. + ++@item --enable-host-pie ++Specify that the @emph{host} executables should be built into ++position-independent executables (with @option{-fPIE} and @option{-pie}), ++yielding a slightly slower compiler (but faster than ++@option{--enable-host-shared}). Position-independent executables are loaded ++at random addresses each time they are executed, therefore provide additional ++protection against Return Oriented Programming (ROP) attacks. ++ ++@option{--enable-host-pie}) may be used with @option{--enable-host-shared}), ++in which case @option{-fPIC} is used when compiling, and @option{-pie} when ++linking. ++ + @item @anchor{with-gnu-as}--with-gnu-as + Specify that the compiler should assume that the + assembler it finds is the GNU assembler. However, this does not modify +@@ -1790,6 +1802,12 @@ particularly useful if you intend to use several versions of GCC in + parallel. The default is @samp{yes} for @samp{libada}, and @samp{no} for + the remaining libraries. + ++@item --with-darwin-extra-rpath ++This is provided to allow distributions to add a single additional ++runpath on Darwin / macOS systems. This allows for cases where the ++installed GCC library directories are then symlinked to a common ++directory outside of the GCC installation. ++ + @item @anchor{WithAixSoname}--with-aix-soname=@samp{aix}, @samp{svr4} or @samp{both} + Traditional AIX shared library versioning (versioned @code{Shared Object} + files as members of unversioned @code{Archive Library} files named +diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi +index 792ce283bb9..cedffc51987 100644 +--- a/gcc/doc/invoke.texi ++++ b/gcc/doc/invoke.texi +@@ -254,7 +254,8 @@ in the following sections. + -Wdelete-non-virtual-dtor -Wno-deprecated-array-compare + -Wdeprecated-copy -Wdeprecated-copy-dtor + -Wno-deprecated-enum-enum-conversion -Wno-deprecated-enum-float-conversion +--Weffc++ -Wno-exceptions -Wextra-semi -Wno-inaccessible-base ++-Weffc++ -Wno-elaborated-enum-base ++-Wno-exceptions -Wextra-semi -Wno-inaccessible-base + -Wno-inherited-variadic-ctor -Wno-init-list-lifetime + -Winvalid-constexpr -Winvalid-imported-macros + -Wno-invalid-offsetof -Wno-literal-suffix +@@ -706,8 +707,9 @@ Objective-C and Objective-C++ Dialects}. + -freg-struct-return -fshort-enums -fshort-wchar + -fverbose-asm -fpack-struct[=@var{n}] + -fleading-underscore -ftls-model=@var{model} +--fstack-reuse=@var{reuse_level} +--ftrampolines -ftrapv -fwrapv ++-fstack-reuse=@var{reuse_level} -fstack-use-cumulative-args ++-ftrampolines -ftrampoline-impl=@r{[}stack@r{|}heap@r{]} ++-ftrapv -fwrapv + -fvisibility=@r{[}default@r{|}internal@r{|}hidden@r{|}protected@r{]} + -fstrict-volatile-bitfields -fsync-libcalls} + +@@ -914,7 +916,7 @@ Objective-C and Objective-C++ Dialects}. + -iframework + -image_base -init -install_name -keep_private_externs + -multi_module -multiply_defined -multiply_defined_unused +--noall_load -no_dead_strip_inits_and_terms ++-noall_load -no_dead_strip_inits_and_terms -nodefaultrpaths + -nofixprebinding -nomultidefs -noprebind -noseglinkedit + -pagezero_size -prebind -prebind_all_twolevel_modules + -private_bundle -read_only_relocs -sectalign +@@ -927,7 +929,7 @@ Objective-C and Objective-C++ Dialects}. + -twolevel_namespace -umbrella -undefined + -unexported_symbols_list -weak_reference_mismatches + -whatsloaded -F -gused -gfull -mmacosx-version-min=@var{version} +--mkernel -mone-byte-bool} ++-mkernel -mone-byte-bool -munreachable-traps} + + @emph{DEC Alpha Options} + @gccoptlist{-mno-fp-regs -msoft-float +@@ -3839,6 +3841,15 @@ bool b = e <= 3.7; + @option{-std=c++20}. In pre-C++20 dialects, this warning can be enabled + by @option{-Wenum-conversion}. + ++@opindex Welaborated-enum-base ++@opindex Wno-elaborated-enum-base ++@item -Wno-elaborated-enum-base ++For C++11 and above, warn if an (invalid) additional enum-base is used ++in an elaborated-type-specifier. That is, if an enum with given ++underlying type and no enumerator list is used in a declaration other ++than just a standalone declaration of the enum. Enabled by default. This ++warning is upgraded to an error with -pedantic-errors. ++ + @opindex Winit-list-lifetime + @opindex Wno-init-list-lifetime + @item -Wno-init-list-lifetime @r{(C++ and Objective-C++ only)} +@@ -4802,7 +4813,7 @@ Use @var{class-name} as the name of the class to instantiate for each + literal string specified with the syntax @code{@@"@dots{}"}. The default + class name is @code{NXConstantString} if the GNU runtime is being used, and + @code{NSConstantString} if the NeXT runtime is being used (see below). On +-Darwin (macOS, MacOS X) platforms, the @option{-fconstant-cfstrings} option, if ++Darwin / macOS platforms, the @option{-fconstant-cfstrings} option, if + also present, overrides the @option{-fconstant-string-class} setting and cause + @code{@@"@dots{}"} literals to be laid out as constant CoreFoundation strings. + Note that @option{-fconstant-cfstrings} is an alias for the target-specific +@@ -4816,7 +4827,7 @@ runtime. This is the default for most types of systems. + @opindex fnext-runtime + @item -fnext-runtime + Generate output compatible with the NeXT runtime. This is the default +-for NeXT-based systems, including Darwin and Mac OS X@. The macro ++for NeXT-based systems, including Darwin / macOS. The macro + @code{__NEXT_RUNTIME__} is predefined if (and only if) this option is + used. + +@@ -6031,8 +6042,45 @@ Give an error whenever the @dfn{base standard} (see @option{-Wpedantic}) + requires a diagnostic, in some cases where there is undefined behavior + at compile-time and in some other cases that do not prevent compilation + of programs that are valid according to the standard. This is not +-equivalent to @option{-Werror=pedantic}, since there are errors enabled +-by this option and not enabled by the latter and vice versa. ++equivalent to @option{-Werror=pedantic}: the latter option is unlikely to be ++useful, as it only makes errors of the diagnostics that are controlled by ++@option{-Wpedantic}, whereas this option also affects required diagnostics that ++are always enabled or controlled by options other than @option{-Wpedantic}. ++ ++If you want the required diagnostics that are warnings by default to ++be errors instead, but don't also want to enable the @option{-Wpedantic} ++diagnostics, you can specify @option{-pedantic-errors -Wno-pedantic} ++(or @option{-pedantic-errors -Wno-error=pedantic} to enable them but ++only as warnings). ++ ++Some required diagnostics are errors by default, but can be reduced to ++warnings using @option{-fpermissive} or their specific warning option, ++e.g. @option{-Wno-error=narrowing}. ++ ++Some diagnostics for non-ISO practices are controlled by specific ++warning options other than @option{-Wpedantic}, but are also made ++errors by @option{-pedantic-errors}. For instance: ++ ++@gccoptlist{ ++-Wattributes @r{(for standard attributes)} ++-Wchanges-meaning @r{(C++)} ++-Wcomma-subscript @r{(C++23 or later)} ++-Wdeclaration-after-statement @r{(C90 or earlier)} ++-Welaborated-enum-base @r{(C++11 or later)} ++-Wimplicit-int @r{(C99 or later)} ++-Wimplicit-function-declaration @r{(C99 or later)} ++-Wincompatible-pointer-types ++-Wint-conversion ++-Wlong-long @r{(C90 or earlier)} ++-Wmain ++-Wnarrowing @r{(C++11 or later)} ++-Wpointer-arith ++-Wpointer-sign ++-Wincompatible-pointer-types ++-Wregister @r{(C++17 or later)} ++-Wvla @r{(C90 or earlier)} ++-Wwrite-strings @r{(C++11 or later)} ++} + + @opindex Wall + @opindex Wno-all +@@ -11285,7 +11333,7 @@ possible. + Produce debugging information in DWARF format (if that is supported). + The value of @var{version} may be either 2, 3, 4 or 5; the default + version for most targets is 5 (with the exception of VxWorks, TPF and +-Darwin/Mac OS X, which default to version 2, and AIX, which defaults ++Darwin / macOS, which default to version 2, and AIX, which defaults + to version 4). + + Note that with DWARF Version 2, some ports require and always +@@ -18167,6 +18215,17 @@ the behavior of older compilers in which temporaries' stack space is + not reused, the aggressive stack reuse can lead to runtime errors. This + option is used to control the temporary stack reuse optimization. + ++@opindex fstack_use_cumulative_args ++@item -fstack-use-cumulative-args ++This option instructs the compiler to use the ++@code{cumulative_args_t}-based stack layout target hooks, ++@code{TARGET_FUNCTION_ARG_BOUNDARY_CA} and ++@code{TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA}. If a given target does ++not define these hooks, the default behaviour is to fallback to using ++the standard non-@code{_CA} variants instead. Certain targets (such as ++AArch64 Darwin) require using the more advanced @code{_CA}-based ++hooks: For these targets this option should be enabled by default. ++ + @opindex ftrapv + @item -ftrapv + This option generates traps for signed overflow on addition, subtraction, +@@ -18652,6 +18711,20 @@ For languages other than Ada, the @code{-ftrampolines} and + trampolines are always generated on platforms that need them + for nested functions. + ++@opindex ftrampoline-impl ++@item -ftrampoline-impl=@r{[}stack@r{|}heap@r{]} ++By default, trampolines are generated on stack. However, certain platforms ++(such as the Apple M1) do not permit an executable stack. Compiling with ++@option{-ftrampoline-impl=heap} generate calls to ++@code{__gcc_nested_func_ptr_created} and ++@code{__gcc_nested_func_ptr_deleted} in order to allocate and ++deallocate trampoline space on the executable heap. These functions are ++implemented in libgcc, and will only be provided on specific targets: ++x86_64 Darwin, x86_64 and aarch64 Linux. @emph{PLEASE NOTE}: Heap ++trampolines are @emph{not} guaranteed to be correctly deallocated if you ++@code{setjmp}, instantiate nested functions, and then @code{longjmp} back ++to a state prior to having allocated those nested functions. ++ + @opindex fvisibility + @item -fvisibility=@r{[}default@r{|}internal@r{|}hidden@r{|}protected@r{]} + Set the default ELF image symbol visibility to the specified option---all +@@ -24024,6 +24097,11 @@ without that switch. Using this switch may require recompiling all + other modules in a program, including system libraries. Use this + switch to conform to a non-default data model. + ++@opindex munreachable-traps ++@item -munreachable-traps ++Causes @code{__builtin_unreachable} to be rendered as a trap. This is the ++default for all Darwin architectures. ++ + @opindex mfix-and-continue + @opindex ffix-and-continue + @opindex findirect-data +@@ -24070,6 +24148,14 @@ an executable when linking, using the Darwin @file{libtool} command. + This causes GCC's output file to have the @samp{ALL} subtype, instead of + one controlled by the @option{-mcpu} or @option{-march} option. + ++@opindex nodefaultrpaths ++@item -nodefaultrpaths ++Do not add default run paths for the compiler library directories to ++executables, modules or dynamic libraries. On macOS 10.5 and later, ++the embedded runpath is added by default unless the user adds ++@option{-nodefaultrpaths} to the link line. Run paths are needed ++(and therefore enforced) to build on macOS version 10.11 or later. ++ + @item -allowable_client @var{client_name} + @itemx -client_name + @itemx -compatibility_version +@@ -29823,7 +29909,7 @@ the same as @option{-mbig}. + + @opindex mdynamic-no-pic + @item -mdynamic-no-pic +-On Darwin and Mac OS X systems, compile code so that it is not ++On Darwin / macOS systems, compile code so that it is not + relocatable, but that its external references are relocatable. The + resulting code is suitable for applications, but not shared + libraries. +diff --git a/gcc/doc/plugins.texi b/gcc/doc/plugins.texi +index 26df8b490df..f9a23180ed8 100644 +--- a/gcc/doc/plugins.texi ++++ b/gcc/doc/plugins.texi +@@ -44,7 +44,7 @@ Plugins are loaded with + + Where @var{name} is the plugin name and @var{ext} is the platform-specific + dynamic library extension. It should be @code{dll} on Windows/MinGW, +-@code{dylib} on Darwin/Mac OS X, and @code{so} on all other platforms. ++@code{dylib} on Darwin/macOS, and @code{so} on all other platforms. + The plugin arguments are parsed by GCC and passed to respective + plugins as key-value pairs. Multiple plugins can be invoked by + specifying multiple @option{-fplugin} arguments. +diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi +index a660e33739b..1080f85dfa1 100644 +--- a/gcc/doc/tm.texi ++++ b/gcc/doc/tm.texi +@@ -1042,6 +1042,10 @@ also define the hook to @code{default_promote_function_mode_always_promote} + if you would like to apply the same rules given by @code{PROMOTE_MODE}. + @end deftypefn + ++@deftypefn {Target Hook} machine_mode TARGET_PROMOTE_FUNCTION_MODE_CA (cumulative_args_t, @var{function_arg_info}, @var{const_tree}, int *@var{}, @var{int}) ++Like @code{promote_function_mode}, but takes a cumulative_args pointer and a current arg to supply the input. ++@end deftypefn ++ + @defmac PARM_BOUNDARY + Normal alignment required for function parameters on the stack, in + bits. All stack parameters receive at least this much alignment +@@ -4354,6 +4358,16 @@ with the specified mode and type. The default hook returns + @code{PARM_BOUNDARY} for all arguments. + @end deftypefn + ++@deftypefn {Target Hook} {unsigned int} TARGET_FUNCTION_ARG_BOUNDARY_CA (machine_mode @var{mode}, const_tree @var{type}, cumulative_args_t @var{ca}) ++This is the @code{cumulative_args_t}-based version of ++@code{TARGET_FUNCTION_ARG_BOUNDARY}. Define this hook if you need more ++fine-grained control over argument alignment, e.g. depending on whether ++it is a named argument or not, or any other criteria that you choose to ++place in the @var{ca} structure. ++ ++The default hook will call @code{TARGET_FUNCTION_ARG_BOUNDARY}. ++@end deftypefn ++ + @deftypefn {Target Hook} {unsigned int} TARGET_FUNCTION_ARG_ROUND_BOUNDARY (machine_mode @var{mode}, const_tree @var{type}) + Normally, the size of an argument is rounded up to @code{PARM_BOUNDARY}, + which is the default value for this hook. You can define this hook to +@@ -4361,6 +4375,16 @@ return a different value if an argument size must be rounded to a larger + value. + @end deftypefn + ++@deftypefn {Target Hook} {unsigned int} TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA (machine_mode @var{mode}, const_tree @var{type}, cumulative_args_t @var{ca}) ++This is the @code{cumulative_args_t}-based version of ++@code{TARGET_FUNCTION_ARG_ROUND_BOUNDARY}. Define this hook if you need more ++fine-grained control over argument size rounding, e.g. depending on whether ++it is a named argument or not, or any other criteria that you choose to ++place in the @var{ca} structure. ++ ++The default hook will call @code{TARGET_FUNCTION_ARG_ROUND_BOUNDARY}. ++@end deftypefn ++ + @defmac FUNCTION_ARG_REGNO_P (@var{regno}) + A C expression that is nonzero if @var{regno} is the number of a hard + register in which function arguments are sometimes passed. This does +@@ -5764,7 +5788,7 @@ This hook determines whether a function from a class of functions + Set this macro to 1 to use the "NeXT" Objective-C message sending conventions + by default. This calling convention involves passing the object, the selector + and the method arguments all at once to the method-lookup library function. +-This is the usual setting when targeting Darwin/Mac OS X systems, which have ++This is the usual setting when targeting Darwin / macOS systems, which have + the NeXT runtime installed. + + If the macro is set to 0, the "GNU" Objective-C message sending convention +@@ -12365,6 +12389,11 @@ This target hook can be used to generate a target-specific code + If selftests are enabled, run any selftests for this target. + @end deftypefn + ++@deftypefn {Target Hook} bool TARGET_UNREACHABLE_SHOULD_TRAP (void) ++This hook should return @code{true} if the target wants @code{__builtin_unreachable} to expand to a trap or @code{abort ()}. ++ The default value is false. ++@end deftypefn ++ + @deftypefn {Target Hook} bool TARGET_MEMTAG_CAN_TAG_ADDRESSES () + True if the backend architecture naturally supports ignoring some region + of pointers. This feature means that @option{-fsanitize=hwaddress} can +diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in +index f7ab5d48a63..7f82c02bf33 100644 +--- a/gcc/doc/tm.texi.in ++++ b/gcc/doc/tm.texi.in +@@ -938,6 +938,8 @@ applied. + + @hook TARGET_PROMOTE_FUNCTION_MODE + ++@hook TARGET_PROMOTE_FUNCTION_MODE_CA ++ + @defmac PARM_BOUNDARY + Normal alignment required for function parameters on the stack, in + bits. All stack parameters receive at least this much alignment +@@ -3341,8 +3343,12 @@ required. + + @hook TARGET_FUNCTION_ARG_BOUNDARY + ++@hook TARGET_FUNCTION_ARG_BOUNDARY_CA ++ + @hook TARGET_FUNCTION_ARG_ROUND_BOUNDARY + ++@hook TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA ++ + @defmac FUNCTION_ARG_REGNO_P (@var{regno}) + A C expression that is nonzero if @var{regno} is the number of a hard + register in which function arguments are sometimes passed. This does +@@ -4008,7 +4014,7 @@ macro, a reasonable default is used. + Set this macro to 1 to use the "NeXT" Objective-C message sending conventions + by default. This calling convention involves passing the object, the selector + and the method arguments all at once to the method-lookup library function. +-This is the usual setting when targeting Darwin/Mac OS X systems, which have ++This is the usual setting when targeting Darwin / macOS systems, which have + the NeXT runtime installed. + + If the macro is set to 0, the "GNU" Objective-C message sending convention +@@ -7965,6 +7971,8 @@ maintainer is familiar with. + + @hook TARGET_RUN_TARGET_SELFTESTS + ++@hook TARGET_UNREACHABLE_SHOULD_TRAP ++ + @hook TARGET_MEMTAG_CAN_TAG_ADDRESSES + + @hook TARGET_MEMTAG_TAG_SIZE +diff --git a/gcc/exec-tool.in b/gcc/exec-tool.in +index bddf46ab70a..a9120f36e19 100644 +--- a/gcc/exec-tool.in ++++ b/gcc/exec-tool.in +@@ -23,6 +23,8 @@ ORIGINAL_AS_FOR_TARGET="@ORIGINAL_AS_FOR_TARGET@" + ORIGINAL_LD_FOR_TARGET="@ORIGINAL_LD_FOR_TARGET@" + ORIGINAL_LD_BFD_FOR_TARGET="@ORIGINAL_LD_BFD_FOR_TARGET@" + ORIGINAL_LD_GOLD_FOR_TARGET="@ORIGINAL_LD_GOLD_FOR_TARGET@" ++ORIGINAL_LLD_FOR_TARGET="@ORIGINAL_LLD_FOR_TARGET@" ++ORIGINAL_CLASSIC_LD_FOR_TARGET="@ORIGINAL_CLASSIC_LD_FOR_TARGET@" + ORIGINAL_PLUGIN_LD_FOR_TARGET="@ORIGINAL_PLUGIN_LD_FOR_TARGET@" + ORIGINAL_NM_FOR_TARGET="@ORIGINAL_NM_FOR_TARGET@" + ORIGINAL_DSYMUTIL_FOR_TARGET="@ORIGINAL_DSYMUTIL_FOR_TARGET@" +@@ -39,24 +41,41 @@ case "$invoked" in + dir=gas + ;; + collect-ld) +- # Check -fuse-ld=bfd and -fuse-ld=gold +- case " $* " in +- *\ -fuse-ld=bfd\ *) +- original=$ORIGINAL_LD_BFD_FOR_TARGET +- ;; +- *\ -fuse-ld=gold\ *) +- original=$ORIGINAL_LD_GOLD_FOR_TARGET +- ;; +- *) +- # when using a linker plugin, gcc will always pass '-plugin' as the +- # first or second option to the linker. +- if test x"$1" = "x-plugin" || test x"$2" = "x-plugin"; then +- original=$ORIGINAL_PLUGIN_LD_FOR_TARGET +- else +- original=$ORIGINAL_LD_FOR_TARGET +- fi +- ;; +- esac ++ # when using a linker plugin, gcc will always pass '-plugin' as the ++ # first or second option to the linker. ++ if test x"$1" = "x-plugin" || test x"$2" = "x-plugin"; then ++ original=$ORIGINAL_PLUGIN_LD_FOR_TARGET ++ else ++ original=$ORIGINAL_LD_FOR_TARGET ++ fi ++ # Check -fuse-ld=bfd, -fuse-ld=gold and -fuse-ld=classic ++ # Remove -fuse-ld=classic from the command line ++ for arg do ++ # temporarily, remove the arg. ++ shift ++ case $arg in ++ -fuse-ld=bfd) ++ original=$ORIGINAL_LD_BFD_FOR_TARGET ++ ;; ++ -fuse-ld=gold) ++ original=$ORIGINAL_LD_GOLD_FOR_TARGET ++ ;; ++ -fuse-ld=lld) ++ original=$ORIGINAL_LLD_FOR_TARGET ++ # We want to remove this from the command line; by the slightly ++ # obtuse mechanism of not putting it back. ++ continue ++ ;; ++ -fuse-ld=classic) ++ original=$ORIGINAL_CLASSIC_LD_FOR_TARGET ++ # As for lld. ++ continue ++ ;; ++ *) ;; ++ esac ++ # if we want to keep the arg, put it back. ++ set -- "$@" "$arg" ++ done + prog=ld-new$exeext + if test "$original" = ../gold/ld-new$exeext; then + dir=gold +diff --git a/gcc/explow.cc b/gcc/explow.cc +index 6424c0802f0..7c2973a9602 100644 +--- a/gcc/explow.cc ++++ b/gcc/explow.cc +@@ -37,6 +37,7 @@ along with GCC; see the file COPYING3. If not see + #include "langhooks.h" + #include "except.h" + #include "dojump.h" ++#include "calls.h" + #include "explow.h" + #include "expr.h" + #include "stringpool.h" +@@ -817,6 +818,16 @@ promote_function_mode (const_tree type, machine_mode mode, int *punsignedp, + return mode; + } + } ++ ++machine_mode ++promote_function_mode (cumulative_args_t args_so_far, function_arg_info arg, ++ const_tree funtype, int *punsignedp , int for_return) ++{ ++ return targetm.calls.promote_function_mode_ca (args_so_far, arg, funtype, ++ punsignedp, for_return); ++// return promote_function_mode (arg.type, arg.mode, punsignedp, funtype, for_return); ++} ++ + /* Return the mode to use to store a scalar of TYPE and MODE. + PUNSIGNEDP points to the signedness of the type and may be adjusted + to show what signedness to use on extension operations. */ +diff --git a/gcc/explow.h b/gcc/explow.h +index 2db4f5c0de0..c7d22862187 100644 +--- a/gcc/explow.h ++++ b/gcc/explow.h +@@ -20,6 +20,8 @@ along with GCC; see the file COPYING3. If not see + #ifndef GCC_EXPLOW_H + #define GCC_EXPLOW_H + ++#include "calls.h" /* for cummulative args stuff. */ ++ + /* Return a memory reference like MEMREF, but which is known to have a + valid address. */ + extern rtx validize_mem (rtx); +@@ -47,8 +49,13 @@ extern rtx force_not_mem (rtx); + + /* Return mode and signedness to use when an argument or result in the + given mode is promoted. */ +-extern machine_mode promote_function_mode (const_tree, machine_mode, int *, +- const_tree, int); ++machine_mode promote_function_mode (const_tree, machine_mode, int *, ++ const_tree, int); ++ ++/* Return mode and signedness to use when an argument or result in the ++ given mode is promoted. */ ++machine_mode promote_function_mode (cumulative_args_t, function_arg_info, ++ const_tree, int *, int); + + /* Return mode and signedness to use when an object in the given mode + is promoted. */ +diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi +index 87baf5ac9a1..908f2b7a344 100644 +--- a/gcc/fortran/gfortran.texi ++++ b/gcc/fortran/gfortran.texi +@@ -978,7 +978,7 @@ low level file descriptor corresponding to an open Fortran unit. Then, + using e.g. the @code{ISO_C_BINDING} feature, one can call the + underlying system call to flush dirty data to stable storage, such as + @code{fsync} on POSIX, @code{_commit} on MingW, or @code{fcntl(fd, +-F_FULLSYNC, 0)} on Mac OS X. The following example shows how to call ++F_FULLSYNC, 0)} on macOS. The following example shows how to call + fsync: + + @smallexample +diff --git a/gcc/function.cc b/gcc/function.cc +index 8d6c4478866..4308e24b5cb 100644 +--- a/gcc/function.cc ++++ b/gcc/function.cc +@@ -58,8 +58,8 @@ along with GCC; see the file COPYING3. If not see + #include "varasm.h" + #include "except.h" + #include "dojump.h" +-#include "explow.h" + #include "calls.h" ++#include "explow.h" + #include "expr.h" + #include "optabs-tree.h" + #include "output.h" +@@ -2448,7 +2448,10 @@ assign_parm_find_data_types (struct assign_parm_data_all *all, tree parm, + else if (DECL_CHAIN (parm)) + data->arg.named = 1; /* Not the last non-variadic parm. */ + else if (targetm.calls.strict_argument_naming (all->args_so_far)) +- data->arg.named = 1; /* Only variadic ones are unnamed. */ ++ { ++ data->arg.named = 1; /* Only variadic ones are unnamed. */ ++ data->arg.last_named = 1; ++ } + else + data->arg.named = 0; /* Treat as variadic. */ + +@@ -2490,9 +2493,12 @@ assign_parm_find_data_types (struct assign_parm_data_all *all, tree parm, + + /* Find mode as it is passed by the ABI. */ + unsignedp = TYPE_UNSIGNED (data->arg.type); +- data->arg.mode +- = promote_function_mode (data->arg.type, data->arg.mode, &unsignedp, +- TREE_TYPE (current_function_decl), 0); ++// data->arg.mode ++// = promote_function_mode (data->arg.type, data->arg.mode, &unsignedp, ++// TREE_TYPE (current_function_decl), 0); ++ data->arg.mode = promote_function_mode (all->args_so_far, data->arg, ++ TREE_TYPE (current_function_decl), ++ &unsignedp, 0); + } + + /* A subroutine of assign_parms. Invoke setup_incoming_varargs. */ +@@ -2505,6 +2511,7 @@ assign_parms_setup_varargs (struct assign_parm_data_all *all, + + function_arg_info last_named_arg = data->arg; + last_named_arg.named = true; ++ last_named_arg.last_named = true; + targetm.calls.setup_incoming_varargs (all->args_so_far, last_named_arg, + &varargs_pretend_bytes, no_rtl); + +@@ -2613,7 +2620,9 @@ assign_parm_find_entry_rtl (struct assign_parm_data_all *all, + + locate_and_pad_parm (data->arg.mode, data->arg.type, in_regs, + all->reg_parm_stack_space, +- entry_parm ? data->partial : 0, current_function_decl, ++ entry_parm ? data->partial : 0, ++ all->args_so_far, ++ current_function_decl, + &all->stack_args_size, &data->locate); + + /* Update parm_stack_boundary if this parameter is passed in the +@@ -3945,7 +3954,8 @@ gimplify_parameters (gimple_seq *cleanup) + if (data.arg.pass_by_reference) + { + tree type = TREE_TYPE (data.arg.type); +- function_arg_info orig_arg (type, data.arg.named); ++ function_arg_info orig_arg (type, data.arg.named, ++ data.arg.last_named); + if (reference_callee_copied (&all.args_so_far_v, orig_arg)) + { + tree local, t; +@@ -4048,6 +4058,7 @@ gimplify_parameters (gimple_seq *cleanup) + void + locate_and_pad_parm (machine_mode passed_mode, tree type, int in_regs, + int reg_parm_stack_space, int partial, ++ cumulative_args_t ca, + tree fndecl ATTRIBUTE_UNUSED, + struct args_size *initial_offset_ptr, + struct locate_and_pad_arg_data *locate) +@@ -4085,9 +4096,23 @@ locate_and_pad_parm (machine_mode passed_mode, tree type, int in_regs, + ? arg_size_in_bytes (type) + : size_int (GET_MODE_SIZE (passed_mode))); + where_pad = targetm.calls.function_arg_padding (passed_mode, type); +- boundary = targetm.calls.function_arg_boundary (passed_mode, type); +- round_boundary = targetm.calls.function_arg_round_boundary (passed_mode, +- type); ++ ++ if (flag_stack_use_cumulative_args) ++ { ++ boundary = targetm.calls.function_arg_boundary_ca (passed_mode, ++ type, ++ ca); ++ round_boundary = targetm.calls.function_arg_round_boundary_ca ++ (passed_mode, type, ca); ++ } ++ else ++ { ++ boundary = targetm.calls.function_arg_boundary (passed_mode, ++ type); ++ round_boundary = targetm.calls.function_arg_round_boundary ++ (passed_mode, type); ++ } ++ + locate->where_pad = where_pad; + + /* Alignment can't exceed MAX_SUPPORTED_STACK_ALIGNMENT. */ +diff --git a/gcc/function.h b/gcc/function.h +index d4ce8a7c6c6..09ab17e66c1 100644 +--- a/gcc/function.h ++++ b/gcc/function.h +@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3. If not see + #ifndef GCC_FUNCTION_H + #define GCC_FUNCTION_H + ++#include "cumulative-args.h" + + /* Stack of pending (incomplete) sequences saved by `start_sequence'. + Each element describes one pending sequence. +@@ -665,6 +666,7 @@ extern int aggregate_value_p (const_tree, const_tree); + extern bool use_register_for_decl (const_tree); + extern gimple_seq gimplify_parameters (gimple_seq *); + extern void locate_and_pad_parm (machine_mode, tree, int, int, int, ++ cumulative_args_t, + tree, struct args_size *, + struct locate_and_pad_arg_data *); + extern void generate_setjmp_warnings (void); +diff --git a/gcc/gcc.cc b/gcc/gcc.cc +index 16bb07f2cdc..d0349741d2f 100644 +--- a/gcc/gcc.cc ++++ b/gcc/gcc.cc +@@ -575,6 +575,7 @@ or with constant text in a single argument. + %l process LINK_SPEC as a spec. + %L process LIB_SPEC as a spec. + %M Output multilib_os_dir. ++ %P Output a RUNPATH_OPTION for each directory in startfile_prefixes. + %G process LIBGCC_SPEC as a spec. + %R Output the concatenation of target_system_root and + target_sysroot_suffix. +@@ -1178,6 +1179,10 @@ proper position among the other output files. */ + # define SYSROOT_HEADERS_SUFFIX_SPEC "" + #endif + ++#ifndef RUNPATH_OPTION ++# define RUNPATH_OPTION "-rpath" ++#endif ++ + static const char *asm_debug = ASM_DEBUG_SPEC; + static const char *asm_debug_option = ASM_DEBUG_OPTION_SPEC; + static const char *cpp_spec = CPP_SPEC; +@@ -5859,6 +5864,7 @@ struct spec_path_info { + size_t append_len; + bool omit_relative; + bool separate_options; ++ bool realpaths; + }; + + static void * +@@ -5868,6 +5874,16 @@ spec_path (char *path, void *data) + size_t len = 0; + char save = 0; + ++ /* The path must exist; we want to resolve it to the realpath so that this ++ can be embedded as a runpath. */ ++ if (info->realpaths) ++ path = lrealpath (path); ++ ++ /* However, if we failed to resolve it - perhaps because there was a bogus ++ -B option on the command line, then punt on this entry. */ ++ if (!path) ++ return NULL; ++ + if (info->omit_relative && !IS_ABSOLUTE_PATH (path)) + return NULL; + +@@ -6099,6 +6115,22 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part) + info.omit_relative = false; + #endif + info.separate_options = false; ++ info.realpaths = false; ++ ++ for_each_path (&startfile_prefixes, true, 0, spec_path, &info); ++ } ++ break; ++ ++ case 'P': ++ { ++ struct spec_path_info info; ++ ++ info.option = RUNPATH_OPTION; ++ info.append_len = 0; ++ info.omit_relative = false; ++ info.separate_options = true; ++ /* We want to embed the actual paths that have the libraries. */ ++ info.realpaths = true; + + for_each_path (&startfile_prefixes, true, 0, spec_path, &info); + } +@@ -6425,6 +6457,7 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part) + info.append_len = strlen (info.append); + info.omit_relative = false; + info.separate_options = true; ++ info.realpaths = false; + + for_each_path (&include_prefixes, false, info.append_len, + spec_path, &info); +diff --git a/gcc/ginclude/stddef.h b/gcc/ginclude/stddef.h +index 12ceef39180..af071079940 100644 +--- a/gcc/ginclude/stddef.h ++++ b/gcc/ginclude/stddef.h +@@ -428,9 +428,8 @@ typedef struct { + /* _Float128 is defined as a basic type, so max_align_t must be + sufficiently aligned for it. This code must work in C++, so we + use __float128 here; that is only available on some +- architectures, but only on i386 is extra alignment needed for +- __float128. */ +-#ifdef __i386__ ++ architectures. */ ++#if defined(__i386__) || (__APPLE__ && __aarch64__) + __float128 __max_align_f128 __attribute__((__aligned__(__alignof(__float128)))); + #endif + } max_align_t; +diff --git a/gcc/jit/Make-lang.in b/gcc/jit/Make-lang.in +index 55079209264..5bdba6c6a4c 100644 +--- a/gcc/jit/Make-lang.in ++++ b/gcc/jit/Make-lang.in +@@ -69,7 +69,7 @@ LIBGCCJIT_COMPAT = 0 + LIBGCCJIT_BASENAME = libgccjit + + LIBGCCJIT_SONAME = \ +- ${libdir}/$(LIBGCCJIT_BASENAME).$(LIBGCCJIT_VERSION_NUM).dylib ++ $(DARWIN_RPATH)/$(LIBGCCJIT_BASENAME).$(LIBGCCJIT_VERSION_NUM).dylib + LIBGCCJIT_FILENAME = $(LIBGCCJIT_BASENAME).$(LIBGCCJIT_VERSION_NUM).dylib + LIBGCCJIT_LINKER_NAME = $(LIBGCCJIT_BASENAME).dylib + +diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc +index e06f161aad9..2a04573b47a 100644 +--- a/gcc/jit/jit-playback.cc ++++ b/gcc/jit/jit-playback.cc +@@ -3024,7 +3024,7 @@ invoke_driver (const char *ctxt_progname, + ADD_ARG ("-fno-use-linker-plugin"); + + #if defined (DARWIN_X86) || defined (DARWIN_PPC) +- /* OS X's linker defaults to treating undefined symbols as errors. ++ /* macOS's linker defaults to treating undefined symbols as errors. + If the context has any imported functions or globals they will be + undefined until the .so is dynamically-linked into the process. + Ensure that the driver passes in "-undefined dynamic_lookup" to the +diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h +index 057d3e58e73..04545e4c6f6 100644 +--- a/gcc/jit/libgccjit.h ++++ b/gcc/jit/libgccjit.h +@@ -21,6 +21,9 @@ along with GCC; see the file COPYING3. If not see + #define LIBGCCJIT_H + + #include ++#ifdef __APPLE__ ++# include /* For ssize_t. */ ++#endif + + #ifdef __cplusplus + extern "C" { +diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in +index 0ae3e183977..320f9300e5f 100644 +--- a/gcc/m2/Make-lang.in ++++ b/gcc/m2/Make-lang.in +@@ -501,6 +501,11 @@ GM2_MIN_FLAGS=$(GM2_G) $(GM2_OS) \ + -Wpedantic-cast -Wpedantic-param-names -fno-exceptions \ + -ffunction-sections -fdata-sections $(GM2_CPP) + ++# ALL_LINKERFLAGS may include -pie (when GCC is configured with ++# --enable-host-pie), so use -fPIE if needed. (It would not be ++# a good idea to override CFLAGS.) ++GM2_PICFLAGS = $(PICFLAG) ++ + O2=-O2 -g + SO_O2=-O2 -g -fPIC + SO=-O0 -g -fPIC +@@ -1396,7 +1401,7 @@ m2/mc-boot-ch/$(SRC_PREFIX)%.o: m2/mc-boot-ch/$(SRC_PREFIX)%.c m2/gm2-libs/gm2-l + + m2/mc-boot-ch/$(SRC_PREFIX)%.o: m2/mc-boot-ch/$(SRC_PREFIX)%.cc m2/gm2-libs/gm2-libs-host.h + -test -d $(@D) || $(mkinstalldirs) $(@D) +- $(CXX) $(CXXFLAGS) -DHAVE_CONFIG_H -g -c -I. -Im2/gm2-libs -I$(srcdir)/../include -I$(srcdir) $(INCLUDES) -Im2/gm2-libs $< -o $@ ++ $(CXX) $(CXXFLAGS) $(GM2_PICFLAGS) -DHAVE_CONFIG_H -g -c -I. -Im2/gm2-libs -I$(srcdir)/../include -I$(srcdir) $(INCLUDES) -Im2/gm2-libs $< -o $@ + + m2/mc-boot/main.o: $(M2LINK) $(srcdir)/m2/init/mcinit + -test -d $(@D)/$(DEPDIR) || $(mkinstalldirs) $(@D)/$(DEPDIR) +diff --git a/gcc/objc/objc-act.cc b/gcc/objc/objc-act.cc +index fe2d2b595b4..85580592803 100644 +--- a/gcc/objc/objc-act.cc ++++ b/gcc/objc/objc-act.cc +@@ -3317,7 +3317,7 @@ objc_build_string_object (tree string) + length = TREE_STRING_LENGTH (string) - 1; + + /* The target may have different ideas on how to construct an ObjC string +- literal. On Darwin (Mac OS X), for example, we may wish to obtain a ++ literal. On Darwin / macOS, for example, we may wish to obtain a + constant CFString reference instead. + At present, this is only supported for the NeXT runtime. */ + if (flag_next_runtime +@@ -10362,5 +10362,51 @@ objc_common_tree_size (enum tree_code code) + } + } + ++/* Information for Objective-C-specific features known to __has_feature. */ ++ ++struct objc_feature_info ++{ ++ typedef bool (*predicate_t) (); ++ ++ const char *ident; ++ predicate_t predicate; ++ ++ constexpr objc_feature_info (const char *name) ++ : ident (name), predicate (nullptr) {} ++ constexpr objc_feature_info (const char *name, predicate_t p) ++ : ident (name), predicate (p) {} ++ ++ bool has_feature () const ++ { ++ return predicate ? predicate () : true; ++ } ++}; ++ ++static bool objc_nonfragile_abi_p () ++{ ++ return flag_next_runtime && flag_objc_abi >= 2; ++} ++ ++static constexpr objc_feature_info objc_features[] = ++{ ++ { "objc_default_synthesize_properties" }, ++ { "objc_instancetype" }, ++ { "objc_nonfragile_abi", objc_nonfragile_abi_p } ++}; ++ ++/* Register Objective-C-specific features for __has_feature. */ ++ ++void ++objc_common_register_features () ++{ ++ for (unsigned i = 0; i < ARRAY_SIZE (objc_features); i++) ++ { ++ const objc_feature_info *info = objc_features + i; ++ if (!info->has_feature ()) ++ continue; ++ ++ c_common_register_feature (info->ident, true); ++ } ++} + + #include "gt-objc-objc-act.h" +diff --git a/gcc/objc/objc-act.h b/gcc/objc/objc-act.h +index e21ab52d8ca..bcf0249515a 100644 +--- a/gcc/objc/objc-act.h ++++ b/gcc/objc/objc-act.h +@@ -29,6 +29,9 @@ int objc_gimplify_expr (tree *, gimple_seq *, gimple_seq *); + void objc_common_init_ts (void); + const char *objc_get_sarif_source_language (const char *); + ++/* Register features common to Objective-C and Objective-C++. */ ++void objc_common_register_features (); ++ + /* NB: The remaining public functions are prototyped in c-common.h, for the + benefit of stub-objc.cc and objc-act.cc. */ + +diff --git a/gcc/objc/objc-lang.cc b/gcc/objc/objc-lang.cc +index 89b3be48b9e..7568248ba13 100644 +--- a/gcc/objc/objc-lang.cc ++++ b/gcc/objc/objc-lang.cc +@@ -58,6 +58,16 @@ objc_get_sarif_source_language (const char *) + return "objectivec"; + } + ++/* Implement c-family hook to add language-specific features ++ for __has_{feature,extension}. */ ++ ++void ++c_family_register_lang_features () ++{ ++ objc_common_register_features (); ++ c_register_features (); ++} ++ + /* Lang hook routines common to C and ObjC appear in c-objc-common.cc; + there should be very few (if any) routines below. */ + +diff --git a/gcc/objcp/objcp-lang.cc b/gcc/objcp/objcp-lang.cc +index 9887209b9c8..ede59a69d13 100644 +--- a/gcc/objcp/objcp-lang.cc ++++ b/gcc/objcp/objcp-lang.cc +@@ -80,6 +80,16 @@ objcp_tsubst_copy_and_build (tree t, tree args, tsubst_flags_t complain, + #undef RECURSE + } + ++/* Implement c-family hook to add language-specific features ++ for __has_{feature,extension}. */ ++ ++void ++c_family_register_lang_features () ++{ ++ objc_common_register_features (); ++ cp_register_features (); ++} ++ + static void + objcxx_init_ts (void) + { +diff --git a/gcc/opts.cc b/gcc/opts.cc +index e0ba89ffe51..71371e23cf1 100644 +--- a/gcc/opts.cc ++++ b/gcc/opts.cc +@@ -3215,6 +3215,7 @@ common_handle_option (struct gcc_options *opts, + break; + + case OPT_fuse_ld_bfd: ++ case OPT_fuse_ld_classic: + case OPT_fuse_ld_gold: + case OPT_fuse_ld_lld: + case OPT_fuse_ld_mold: +diff --git a/gcc/plugin.cc b/gcc/plugin.cc +index 142f3fa4131..c3e40b2cf75 100644 +--- a/gcc/plugin.cc ++++ b/gcc/plugin.cc +@@ -190,10 +190,10 @@ add_new_plugin (const char* plugin_name) + #if defined(__MINGW32__) + static const char plugin_ext[] = ".dll"; + #elif defined(__APPLE__) +- /* Mac OS has two types of libraries: dynamic libraries (.dylib) and ++ /* macOS has two types of libraries: dynamic libraries (.dylib) and + plugins (.bundle). Both can be used with dlopen()/dlsym() but the + former cannot be linked at build time (i.e., with the -lfoo linker +- option). A GCC plugin is therefore probably a Mac OS plugin but their ++ option). A GCC plugin is therefore probably a macOS plugin but their + use seems to be quite rare and the .bundle extension is more of a + recommendation rather than the rule. This raises the questions of how + well they are supported by tools (e.g., libtool). So to avoid +diff --git a/gcc/target.def b/gcc/target.def +index 171bbd1caf1..75b51d26074 100644 +--- a/gcc/target.def ++++ b/gcc/target.def +@@ -4574,6 +4574,13 @@ if you would like to apply the same rules given by @code{PROMOTE_MODE}.", + const_tree funtype, int for_return), + default_promote_function_mode) + ++DEFHOOK ++(promote_function_mode_ca, ++ "Like @code{promote_function_mode}, but takes a cumulative_args pointer \ ++ and a current arg to supply the input.", ++ machine_mode, (cumulative_args_t, function_arg_info, const_tree, int *, int), ++ default_promote_function_mode_ca) ++ + DEFHOOK + (promote_prototypes, + "This target hook returns @code{true} if an argument declared in a\n\ +@@ -4992,6 +4999,18 @@ with the specified mode and type. The default hook returns\n\ + unsigned int, (machine_mode mode, const_tree type), + default_function_arg_boundary) + ++DEFHOOK ++(function_arg_boundary_ca, ++ "This is the @code{cumulative_args_t}-based version of\n\ ++@code{TARGET_FUNCTION_ARG_BOUNDARY}. Define this hook if you need more\n\ ++fine-grained control over argument alignment, e.g. depending on whether\n\ ++it is a named argument or not, or any other criteria that you choose to\n\ ++place in the @var{ca} structure.\n\ ++\n\ ++The default hook will call @code{TARGET_FUNCTION_ARG_BOUNDARY}.", ++ unsigned int, (machine_mode mode, const_tree type, cumulative_args_t ca), ++ default_function_arg_boundary_ca) ++ + DEFHOOK + (function_arg_round_boundary, + "Normally, the size of an argument is rounded up to @code{PARM_BOUNDARY},\n\ +@@ -5001,6 +5020,18 @@ value.", + unsigned int, (machine_mode mode, const_tree type), + default_function_arg_round_boundary) + ++DEFHOOK ++(function_arg_round_boundary_ca, ++ "This is the @code{cumulative_args_t}-based version of\n\ ++@code{TARGET_FUNCTION_ARG_ROUND_BOUNDARY}. Define this hook if you need more\n\ ++fine-grained control over argument size rounding, e.g. depending on whether\n\ ++it is a named argument or not, or any other criteria that you choose to\n\ ++place in the @var{ca} structure.\n\ ++\n\ ++The default hook will call @code{TARGET_FUNCTION_ARG_ROUND_BOUNDARY}.", ++ unsigned int, (machine_mode mode, const_tree type, cumulative_args_t ca), ++ default_function_arg_round_boundary_ca) ++ + /* Return the diagnostic message string if function without a prototype + is not allowed for this 'val' argument; NULL otherwise. */ + DEFHOOK +@@ -7138,6 +7169,16 @@ DEFHOOKPOD + @option{-fsanitize=shadow-call-stack}. The default value is false.", + bool, false) + ++/* This value represents whether __builtin_unreachable should be expanded ++ as a trap instruction (or an abort() if the trap is not available). */ ++DEFHOOK ++(unreachable_should_trap, ++ "This hook should return @code{true} if the target wants \ ++ @code{__builtin_unreachable} to expand to a trap or @code{abort ()}.\n\ ++ The default value is false.", ++ bool, (void), ++ hook_bool_void_false) ++ + /* Close the 'struct gcc_target' definition. */ + HOOK_VECTOR_END (C90_EMPTY_HACK) + +diff --git a/gcc/target.h b/gcc/target.h +index cd448e4b7ab..064523f2a2e 100644 +--- a/gcc/target.h ++++ b/gcc/target.h +@@ -51,22 +51,8 @@ + #include "insn-codes.h" + #include "tm.h" + #include "hard-reg-set.h" +- +-#if CHECKING_P +- +-struct cumulative_args_t { void *magic; void *p; }; +- +-#else /* !CHECKING_P */ +- +-/* When using a GCC build compiler, we could use +- __attribute__((transparent_union)) to get cumulative_args_t function +- arguments passed like scalars where the ABI would mandate a less +- efficient way of argument passing otherwise. However, that would come +- at the cost of less type-safe !CHECKING_P compilation. */ +- +-union cumulative_args_t { void *p; }; +- +-#endif /* !CHECKING_P */ ++#include "tree-core.h" ++#include "cumulative-args.h" + + /* Types of memory operation understood by the "by_pieces" infrastructure. + Used by the TARGET_USE_BY_PIECES_INFRASTRUCTURE_P target hook and +diff --git a/gcc/targhooks.cc b/gcc/targhooks.cc +index 51bf3fb7a82..13a7c206cc5 100644 +--- a/gcc/targhooks.cc ++++ b/gcc/targhooks.cc +@@ -159,6 +159,15 @@ default_promote_function_mode_always_promote (const_tree type, + return promote_mode (type, mode, punsignedp); + } + ++machine_mode ++default_promote_function_mode_ca (cumulative_args_t, function_arg_info arg, ++ const_tree funtype, int *punsignedp, ++ int for_return) ++{ ++ return promote_function_mode (arg.type, arg.mode, punsignedp, ++ funtype, for_return); ++} ++ + machine_mode + default_cc_modes_compatible (machine_mode m1, machine_mode m2) + { +@@ -856,6 +865,14 @@ default_function_arg_boundary (machine_mode mode ATTRIBUTE_UNUSED, + return PARM_BOUNDARY; + } + ++unsigned int ++default_function_arg_boundary_ca (machine_mode mode ATTRIBUTE_UNUSED, ++ const_tree type ATTRIBUTE_UNUSED, ++ cumulative_args_t ca ATTRIBUTE_UNUSED) ++{ ++ return default_function_arg_boundary (mode, type); ++} ++ + unsigned int + default_function_arg_round_boundary (machine_mode mode ATTRIBUTE_UNUSED, + const_tree type ATTRIBUTE_UNUSED) +@@ -863,6 +880,14 @@ default_function_arg_round_boundary (machine_mode mode ATTRIBUTE_UNUSED, + return PARM_BOUNDARY; + } + ++unsigned int ++default_function_arg_round_boundary_ca (machine_mode mode ATTRIBUTE_UNUSED, ++ const_tree type ATTRIBUTE_UNUSED, ++ cumulative_args_t ca ATTRIBUTE_UNUSED) ++{ ++ return default_function_arg_round_boundary (mode, type); ++} ++ + void + hook_void_bitmap (bitmap regs ATTRIBUTE_UNUSED) + { +diff --git a/gcc/targhooks.h b/gcc/targhooks.h +index cf3d3107a0d..cd4e830b2f3 100644 +--- a/gcc/targhooks.h ++++ b/gcc/targhooks.h +@@ -34,6 +34,9 @@ extern machine_mode default_promote_function_mode (const_tree, machine_mode, + extern machine_mode default_promote_function_mode_always_promote + (const_tree, machine_mode, int *, const_tree, int); + ++extern machine_mode default_promote_function_mode_ca ++ (cumulative_args_t, function_arg_info, const_tree, int *, int); ++ + extern machine_mode default_cc_modes_compatible (machine_mode, + machine_mode); + +@@ -158,6 +161,12 @@ extern unsigned int default_function_arg_boundary (machine_mode, + const_tree); + extern unsigned int default_function_arg_round_boundary (machine_mode, + const_tree); ++extern unsigned int default_function_arg_boundary_ca (machine_mode, ++ const_tree, ++ cumulative_args_t ca); ++extern unsigned int default_function_arg_round_boundary_ca (machine_mode, ++ const_tree, ++ cumulative_args_t ca); + extern bool hook_bool_const_rtx_commutative_p (const_rtx, int); + extern rtx default_function_value (const_tree, const_tree, bool); + extern HARD_REG_SET default_zero_call_used_regs (HARD_REG_SET); +diff --git a/gcc/tree-nested.cc b/gcc/tree-nested.cc +index 0f44b3dc735..8355425f0d1 100644 +--- a/gcc/tree-nested.cc ++++ b/gcc/tree-nested.cc +@@ -611,6 +611,14 @@ get_trampoline_type (struct nesting_info *info) + if (trampoline_type) + return trampoline_type; + ++ /* When trampolines are created off-stack then the only thing we need in the ++ local frame is a single pointer. */ ++ if (flag_trampoline_impl == TRAMPOLINE_IMPL_HEAP) ++ { ++ trampoline_type = build_pointer_type (void_type_node); ++ return trampoline_type; ++ } ++ + align = TRAMPOLINE_ALIGNMENT; + size = TRAMPOLINE_SIZE; + +@@ -2793,17 +2801,27 @@ convert_tramp_reference_op (tree *tp, int *walk_subtrees, void *data) + + /* Compute the address of the field holding the trampoline. */ + x = get_frame_field (info, target_context, x, &wi->gsi); +- x = build_addr (x); +- x = gsi_gimplify_val (info, x, &wi->gsi); + +- /* Do machine-specific ugliness. Normally this will involve +- computing extra alignment, but it can really be anything. */ +- if (descr) +- builtin = builtin_decl_implicit (BUILT_IN_ADJUST_DESCRIPTOR); ++ /* APB: We don't need to do the adjustment calls when using off-stack ++ trampolines, any such adjustment will be done when the off-stack ++ trampoline is created. */ ++ if (!descr && flag_trampoline_impl == TRAMPOLINE_IMPL_HEAP) ++ x = gsi_gimplify_val (info, x, &wi->gsi); + else +- builtin = builtin_decl_implicit (BUILT_IN_ADJUST_TRAMPOLINE); +- call = gimple_build_call (builtin, 1, x); +- x = init_tmp_var_with_call (info, &wi->gsi, call); ++ { ++ x = build_addr (x); ++ ++ x = gsi_gimplify_val (info, x, &wi->gsi); ++ ++ /* Do machine-specific ugliness. Normally this will involve ++ computing extra alignment, but it can really be anything. */ ++ if (descr) ++ builtin = builtin_decl_implicit (BUILT_IN_ADJUST_DESCRIPTOR); ++ else ++ builtin = builtin_decl_implicit (BUILT_IN_ADJUST_TRAMPOLINE); ++ call = gimple_build_call (builtin, 1, x); ++ x = init_tmp_var_with_call (info, &wi->gsi, call); ++ } + + /* Cast back to the proper function type. */ + x = build1 (NOP_EXPR, TREE_TYPE (t), x); +@@ -3382,6 +3400,7 @@ build_init_call_stmt (struct nesting_info *info, tree decl, tree field, + static void + finalize_nesting_tree_1 (struct nesting_info *root) + { ++ gimple_seq cleanup_list = NULL; + gimple_seq stmt_list = NULL; + gimple *stmt; + tree context = root->context; +@@ -3513,9 +3532,48 @@ finalize_nesting_tree_1 (struct nesting_info *root) + if (!field) + continue; + +- x = builtin_decl_implicit (BUILT_IN_INIT_TRAMPOLINE); +- stmt = build_init_call_stmt (root, i->context, field, x); +- gimple_seq_add_stmt (&stmt_list, stmt); ++ if (flag_trampoline_impl == TRAMPOLINE_IMPL_HEAP) ++ { ++ /* We pass a whole bunch of arguments to the builtin function that ++ creates the off-stack trampoline, these are ++ 1. The nested function chain value (that must be passed to the ++ nested function so it can find the function arguments). ++ 2. A pointer to the nested function implementation, ++ 3. The address in the local stack frame where we should write ++ the address of the trampoline. ++ ++ When this code was originally written I just kind of threw ++ everything at the builtin, figuring I'd work out what was ++ actually needed later, I think, the stack pointer could ++ certainly be dropped, arguments #2 and #4 are based off the ++ stack pointer anyway, so #1 doesn't seem to add much value. */ ++ tree arg1, arg2, arg3; ++ ++ gcc_assert (DECL_STATIC_CHAIN (i->context)); ++ arg1 = build_addr (root->frame_decl); ++ arg2 = build_addr (i->context); ++ ++ x = build3 (COMPONENT_REF, TREE_TYPE (field), ++ root->frame_decl, field, NULL_TREE); ++ arg3 = build_addr (x); ++ ++ x = builtin_decl_explicit (BUILT_IN_GCC_NESTED_PTR_CREATED); ++ stmt = gimple_build_call (x, 3, arg1, arg2, arg3); ++ gimple_seq_add_stmt (&stmt_list, stmt); ++ ++ /* This call to delete the nested function trampoline is added to ++ the cleanup list, and called when we exit the current scope. */ ++ x = builtin_decl_explicit (BUILT_IN_GCC_NESTED_PTR_DELETED); ++ stmt = gimple_build_call (x, 0); ++ gimple_seq_add_stmt (&cleanup_list, stmt); ++ } ++ else ++ { ++ /* Original code to initialise the on stack trampoline. */ ++ x = builtin_decl_implicit (BUILT_IN_INIT_TRAMPOLINE); ++ stmt = build_init_call_stmt (root, i->context, field, x); ++ gimple_seq_add_stmt (&stmt_list, stmt); ++ } + } + } + +@@ -3540,11 +3598,40 @@ finalize_nesting_tree_1 (struct nesting_info *root) + /* If we created initialization statements, insert them. */ + if (stmt_list) + { +- gbind *bind; +- annotate_all_with_location (stmt_list, DECL_SOURCE_LOCATION (context)); +- bind = gimple_seq_first_stmt_as_a_bind (gimple_body (context)); +- gimple_seq_add_seq (&stmt_list, gimple_bind_body (bind)); +- gimple_bind_set_body (bind, stmt_list); ++ if (flag_trampoline_impl == TRAMPOLINE_IMPL_HEAP) ++ { ++ /* Handle off-stack trampolines. */ ++ gbind *bind; ++ annotate_all_with_location (stmt_list, DECL_SOURCE_LOCATION (context)); ++ annotate_all_with_location (cleanup_list, DECL_SOURCE_LOCATION (context)); ++ bind = gimple_seq_first_stmt_as_a_bind (gimple_body (context)); ++ gimple_seq_add_seq (&stmt_list, gimple_bind_body (bind)); ++ ++ gimple_seq xxx_list = NULL; ++ ++ if (cleanup_list != NULL) ++ { ++ /* Maybe we shouldn't be creating this try/finally if -fno-exceptions is ++ in use. If this is the case, then maybe we should, instead, be ++ inserting the cleanup code onto every path out of this function? Not ++ yet figured out how we would do this. */ ++ gtry *t = gimple_build_try (stmt_list, cleanup_list, GIMPLE_TRY_FINALLY); ++ gimple_seq_add_stmt (&xxx_list, t); ++ } ++ else ++ xxx_list = stmt_list; ++ ++ gimple_bind_set_body (bind, xxx_list); ++ } ++ else ++ { ++ /* The traditional, on stack trampolines. */ ++ gbind *bind; ++ annotate_all_with_location (stmt_list, DECL_SOURCE_LOCATION (context)); ++ bind = gimple_seq_first_stmt_as_a_bind (gimple_body (context)); ++ gimple_seq_add_seq (&stmt_list, gimple_bind_body (bind)); ++ gimple_bind_set_body (bind, stmt_list); ++ } + } + + /* If a chain_decl was created, then it needs to be registered with +diff --git a/gcc/tree.cc b/gcc/tree.cc +index 12dea81a5f3..88370418be4 100644 +--- a/gcc/tree.cc ++++ b/gcc/tree.cc +@@ -9853,6 +9853,28 @@ build_common_builtin_nodes (void) + "__builtin_nonlocal_goto", + ECF_NORETURN | ECF_NOTHROW); + ++ tree ptr_ptr_type_node = build_pointer_type (ptr_type_node); ++ ++ if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_CREATED)) ++ { ++ ftype = build_function_type_list (void_type_node, ++ ptr_type_node, // void *chain ++ ptr_type_node, // void *func ++ ptr_ptr_type_node, // void **dst ++ NULL_TREE); ++ local_define_builtin ("__builtin___gcc_nested_func_ptr_created", ftype, ++ BUILT_IN_GCC_NESTED_PTR_CREATED, ++ "__gcc_nested_func_ptr_created", ECF_NOTHROW); ++ } ++ ++ if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_DELETED)) ++ { ++ ftype = build_function_type_list (void_type_node, NULL_TREE); ++ local_define_builtin ("__builtin___gcc_nested_func_ptr_deleted", ftype, ++ BUILT_IN_GCC_NESTED_PTR_DELETED, ++ "__gcc_nested_func_ptr_deleted", ECF_NOTHROW); ++ } ++ + ftype = build_function_type_list (void_type_node, + ptr_type_node, ptr_type_node, NULL_TREE); + local_define_builtin ("__builtin_setjmp_setup", ftype, +diff --git a/intl/Makefile.in b/intl/Makefile.in +index 409d693c48e..5beebdc152c 100644 +--- a/intl/Makefile.in ++++ b/intl/Makefile.in +@@ -54,7 +54,7 @@ CTAGS = @CTAGS@ + ETAGS = @ETAGS@ + MKID = @MKID@ + +-COMPILE = $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEFS) $(DEFS-$@) $(INCLUDES) ++COMPILE = $(CC) -c $(CPPFLAGS) $(CFLAGS) @PICFLAG@ $(DEFS) $(DEFS-$@) $(INCLUDES) + + HEADERS = \ + gmo.h \ +diff --git a/intl/configure b/intl/configure +index 03f40487a92..79bb5831a47 100755 +--- a/intl/configure ++++ b/intl/configure +@@ -623,6 +623,8 @@ ac_header_list= + ac_subst_vars='LTLIBOBJS + LIBOBJS + PICFLAG ++enable_host_pie ++enable_host_shared + BISON3_NO + BISON3_YES + INCINTL +@@ -731,6 +733,7 @@ with_libintl_prefix + with_libintl_type + enable_maintainer_mode + enable_host_shared ++enable_host_pie + ' + ac_precious_vars='build_alias + host_alias +@@ -1356,6 +1359,7 @@ Optional Features: + --disable-rpath do not hardcode runtime library paths + --enable-maintainer-mode enable rules only needed by maintainers + --enable-host-shared build host code as shared libraries ++ --enable-host-pie build host code as PIE + + Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] +@@ -6852,15 +6856,31 @@ fi + + + ++# Enable --enable-host-shared. + # Check whether --enable-host-shared was given. + if test "${enable_host_shared+set}" = set; then : +- enableval=$enable_host_shared; PICFLAG=-fPIC ++ enableval=$enable_host_shared; ++fi ++ ++ ++ ++# Enable --enable-host-pie. ++# Check whether --enable-host-pie was given. ++if test "${enable_host_pie+set}" = set; then : ++ enableval=$enable_host_pie; ++fi ++ ++ ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE + else + PICFLAG= + fi + + +- + ac_config_files="$ac_config_files Makefile config.intl" + + cat >confcache <<\_ACEOF +diff --git a/intl/configure.ac b/intl/configure.ac +index 16a740aa230..81aa831f59f 100644 +--- a/intl/configure.ac ++++ b/intl/configure.ac +@@ -83,10 +83,25 @@ fi + AC_SUBST(BISON3_YES) + AC_SUBST(BISON3_NO) + ++# Enable --enable-host-shared. + AC_ARG_ENABLE(host-shared, + [AS_HELP_STRING([--enable-host-shared], +- [build host code as shared libraries])], +-[PICFLAG=-fPIC], [PICFLAG=]) ++ [build host code as shared libraries])]) ++AC_SUBST(enable_host_shared) ++ ++# Enable --enable-host-pie. ++AC_ARG_ENABLE(host-pie, ++[AS_HELP_STRING([--enable-host-pie], ++ [build host code as PIE])]) ++AC_SUBST(enable_host_pie) ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE ++else ++ PICFLAG= ++fi + AC_SUBST(PICFLAG) + + AC_CONFIG_FILES(Makefile config.intl) +diff --git a/libatomic/Makefile.am b/libatomic/Makefile.am +index c6c8d81c56a..3bb32f32ebf 100644 +--- a/libatomic/Makefile.am ++++ b/libatomic/Makefile.am +@@ -65,8 +65,13 @@ libatomic_version_script = + libatomic_version_dep = + endif + libatomic_version_info = -version-info $(libtool_VERSION) ++if ENABLE_DARWIN_AT_RPATH ++libatomic_darwin_rpath = -Wc,-nodefaultrpaths ++libatomic_darwin_rpath += -Wl,-rpath,@loader_path ++endif + +-libatomic_la_LDFLAGS = $(libatomic_version_info) $(libatomic_version_script) $(lt_host_flags) ++libatomic_la_LDFLAGS = $(libatomic_version_info) $(libatomic_version_script) \ ++ $(lt_host_flags) $(libatomic_darwin_rpath) + libatomic_la_SOURCES = gload.c gstore.c gcas.c gexch.c glfree.c lock.c init.c \ + fenv.c fence.c flag.c + +diff --git a/libatomic/Makefile.in b/libatomic/Makefile.in +index a0fa3dfc8cc..ef7ef451751 100644 +--- a/libatomic/Makefile.in ++++ b/libatomic/Makefile.in +@@ -417,7 +417,12 @@ noinst_LTLIBRARIES = libatomic_convenience.la + @LIBAT_BUILD_VERSIONED_SHLIB_GNU_TRUE@@LIBAT_BUILD_VERSIONED_SHLIB_TRUE@libatomic_version_dep = $(top_srcdir)/libatomic.map + @LIBAT_BUILD_VERSIONED_SHLIB_SUN_TRUE@@LIBAT_BUILD_VERSIONED_SHLIB_TRUE@libatomic_version_dep = libatomic.map-sun + libatomic_version_info = -version-info $(libtool_VERSION) +-libatomic_la_LDFLAGS = $(libatomic_version_info) $(libatomic_version_script) $(lt_host_flags) ++@ENABLE_DARWIN_AT_RPATH_TRUE@libatomic_darwin_rpath = \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path ++libatomic_la_LDFLAGS = $(libatomic_version_info) $(libatomic_version_script) \ ++ $(lt_host_flags) $(libatomic_darwin_rpath) ++ + libatomic_la_SOURCES = gload.c gstore.c gcas.c gexch.c glfree.c lock.c \ + init.c fenv.c fence.c flag.c $(am__append_2) + SIZEOBJS = load store cas exch fadd fsub fand fior fxor fnand tas +diff --git a/libatomic/configure b/libatomic/configure +index e47d2d7fb35..7c1d46b6762 100755 +--- a/libatomic/configure ++++ b/libatomic/configure +@@ -658,6 +658,8 @@ OPT_LDFLAGS + SECTION_LDFLAGS + enable_aarch64_lse + libtool_VERSION ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + MAINT + MAINTAINER_MODE_FALSE + MAINTAINER_MODE_TRUE +@@ -803,6 +805,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + enable_maintainer_mode + enable_symvers + enable_werror +@@ -1452,6 +1455,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --enable-maintainer-mode + enable make rules and dependencies not useful (and + sometimes confusing) to the casual installer +@@ -7608,7 +7614,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -9581,6 +9587,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -9598,9 +9647,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -11406,7 +11459,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11409 "configure" ++#line 11462 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11512,7 +11565,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11515 "configure" ++#line 11568 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11797,6 +11850,15 @@ fi + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ ++ + # For libtool versioning info, format is CURRENT:REVISION:AGE + libtool_VERSION=3:0:2 + +@@ -15924,6 +15986,10 @@ if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then + as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + + if test -z "${LIBAT_BUILD_VERSIONED_SHLIB_TRUE}" && test -z "${LIBAT_BUILD_VERSIONED_SHLIB_FALSE}"; then + as_fn_error $? "conditional \"LIBAT_BUILD_VERSIONED_SHLIB\" was never defined. +diff --git a/libatomic/configure.ac b/libatomic/configure.ac +index 31304685dbd..20981f16f70 100644 +--- a/libatomic/configure.ac ++++ b/libatomic/configure.ac +@@ -156,6 +156,8 @@ AC_SUBST(enable_shared) + AC_SUBST(enable_static) + AM_MAINTAINER_MODE + ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) ++ + # For libtool versioning info, format is CURRENT:REVISION:AGE + libtool_VERSION=3:0:2 + AC_SUBST(libtool_VERSION) +diff --git a/libbacktrace/configure b/libbacktrace/configure +index 6af2c04c81a..4a25e38a2dc 100755 +--- a/libbacktrace/configure ++++ b/libbacktrace/configure +@@ -681,6 +681,8 @@ PIC_FLAG + WARN_FLAGS + EXTRA_FLAGS + BACKTRACE_FILE ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + OTOOL64 + OTOOL + LIPO +@@ -805,6 +807,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + enable_largefile + enable_cet + enable_werror +@@ -1453,6 +1456,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --disable-largefile omit support for large files + --enable-cet enable Intel CET in target libraries [default=auto] + --disable-werror disable building with -Werror +@@ -8010,7 +8016,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -9716,6 +9722,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -9733,9 +9782,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -11541,7 +11594,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11544 "configure" ++#line 11597 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11647,7 +11700,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11650 "configure" ++#line 11703 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11886,6 +11939,15 @@ CC="$lt_save_CC" + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ ++ + # Check whether --enable-largefile was given. + if test "${enable_largefile+set}" = set; then : + enableval=$enable_largefile; +@@ -14435,6 +14497,10 @@ if test -z "${HAVE_DWZ_TRUE}" && test -z "${HAVE_DWZ_FALSE}"; then + as_fn_error $? "conditional \"HAVE_DWZ\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${HAVE_ELF_TRUE}" && test -z "${HAVE_ELF_FALSE}"; then + as_fn_error $? "conditional \"HAVE_ELF\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac +index 39e6bf41e35..98b96fcb86f 100644 +--- a/libbacktrace/configure.ac ++++ b/libbacktrace/configure.ac +@@ -84,6 +84,8 @@ AM_CONDITIONAL(HAVE_DWZ, test "$DWZ" != "") + LT_INIT + AM_PROG_LIBTOOL + ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) ++ + AC_SYS_LARGEFILE + + backtrace_supported=yes +diff --git a/libcc1/configure b/libcc1/configure +index bae3b8712b6..cd9acc3bf13 100755 +--- a/libcc1/configure ++++ b/libcc1/configure +@@ -787,6 +787,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + enable_cet + with_gcc_major_version_only + enable_werror_always +@@ -1439,6 +1440,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --enable-cet enable Intel CET in host libraries [default=auto] + --enable-werror-always enable -Werror despite compiler version + --enable-plugin enable plugin support +@@ -7271,7 +7275,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -8976,6 +8980,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -8993,9 +9040,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -10801,7 +10852,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 10804 "configure" ++#line 10855 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -10907,7 +10958,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 10910 "configure" ++#line 10961 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -12189,6 +12240,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc_CXX=no + hardcode_direct_CXX=no + hardcode_automatic_CXX=yes +@@ -12206,12 +12300,20 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + if test "$lt_cv_apple_cc_single_mod" != "yes"; then +- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring${_lt_dsymutil}" + archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" + fi + +diff --git a/libcody/Makefile.in b/libcody/Makefile.in +index bb87468cb9a..cb01b0092d8 100644 +--- a/libcody/Makefile.in ++++ b/libcody/Makefile.in +@@ -31,7 +31,7 @@ endif + CXXOPTS += $(filter-out -DHAVE_CONFIG_H,@DEFS@) -include config.h + + # Linker options +-LDFLAGS := @LDFLAGS@ ++LDFLAGS := @LDFLAGS@ @LD_PICFLAG@ + LIBS := @LIBS@ + + # Per-source & per-directory compile flags (warning: recursive) +diff --git a/libcody/configure b/libcody/configure +index da52a5cfca5..0e536c0ccb0 100755 +--- a/libcody/configure ++++ b/libcody/configure +@@ -591,7 +591,10 @@ configure_args + AR + RANLIB + EXCEPTIONS ++LD_PICFLAG + PICFLAG ++enable_host_pie ++enable_host_shared + OBJEXT + EXEEXT + ac_ct_CXX +@@ -653,6 +656,7 @@ enable_maintainer_mode + with_compiler + enable_checking + enable_host_shared ++enable_host_pie + enable_exceptions + ' + ac_precious_vars='build_alias +@@ -1286,6 +1290,7 @@ Optional Features: + yes,no,all,none,release. Flags are: misc,valgrind or + other strings + --enable-host-shared build host code as shared libraries ++ --enable-host-pie build host code as PIE + --enable-exceptions enable exceptions & rtti + + Optional Packages: +@@ -2635,11 +2640,34 @@ fi + # Enable --enable-host-shared. + # Check whether --enable-host-shared was given. + if test "${enable_host_shared+set}" = set; then : +- enableval=$enable_host_shared; PICFLAG=-fPIC ++ enableval=$enable_host_shared; ++fi ++ ++ ++ ++# Enable --enable-host-pie. ++# Check whether --enable-host-pie was given. ++if test "${enable_host_pie+set}" = set; then : ++ enableval=$enable_host_pie; ++fi ++ ++ ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE + else + PICFLAG= + fi + ++if test x$enable_host_pie = xyes; then ++ LD_PICFLAG=-pie ++else ++ LD_PICFLAG= ++fi ++ ++ + + + # Check whether --enable-exceptions was given. +diff --git a/libcody/configure.ac b/libcody/configure.ac +index 960191ecb72..14e8dd4a226 100644 +--- a/libcody/configure.ac ++++ b/libcody/configure.ac +@@ -63,9 +63,31 @@ fi + # Enable --enable-host-shared. + AC_ARG_ENABLE(host-shared, + [AS_HELP_STRING([--enable-host-shared], +- [build host code as shared libraries])], +-[PICFLAG=-fPIC], [PICFLAG=]) ++ [build host code as shared libraries])]) ++AC_SUBST(enable_host_shared) ++ ++# Enable --enable-host-pie. ++AC_ARG_ENABLE(host-pie, ++[AS_HELP_STRING([--enable-host-pie], ++ [build host code as PIE])]) ++AC_SUBST(enable_host_pie) ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE ++else ++ PICFLAG= ++fi ++ ++if test x$enable_host_pie = xyes; then ++ LD_PICFLAG=-pie ++else ++ LD_PICFLAG= ++fi ++ + AC_SUBST(PICFLAG) ++AC_SUBST(LD_PICFLAG) + + NMS_ENABLE_EXCEPTIONS + +diff --git a/libcpp/configure b/libcpp/configure +index e9937cde330..1389ddab544 100755 +--- a/libcpp/configure ++++ b/libcpp/configure +@@ -625,6 +625,8 @@ ac_includes_default="\ + ac_subst_vars='LTLIBOBJS + CET_HOST_FLAGS + PICFLAG ++enable_host_pie ++enable_host_shared + MAINT + USED_CATALOGS + PACKAGE +@@ -738,6 +740,7 @@ enable_maintainer_mode + enable_checking + enable_canonical_system_headers + enable_host_shared ++enable_host_pie + enable_cet + enable_valgrind_annotations + ' +@@ -1379,6 +1382,7 @@ Optional Features: + --enable-canonical-system-headers + enable or disable system headers canonicalization + --enable-host-shared build host code as shared libraries ++ --enable-host-pie build host code as PIE + --enable-cet enable Intel CET in host libraries [default=auto] + --enable-valgrind-annotations + enable valgrind runtime interaction +@@ -7605,7 +7609,23 @@ esac + # Enable --enable-host-shared. + # Check whether --enable-host-shared was given. + if test "${enable_host_shared+set}" = set; then : +- enableval=$enable_host_shared; PICFLAG=-fPIC ++ enableval=$enable_host_shared; ++fi ++ ++ ++ ++# Enable --enable-host-pie. ++# Check whether --enable-host-pie was given. ++if test "${enable_host_pie+set}" = set; then : ++ enableval=$enable_host_pie; ++fi ++ ++ ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE + else + PICFLAG= + fi +diff --git a/libcpp/configure.ac b/libcpp/configure.ac +index 89ac99b04bd..b29b4d6acf1 100644 +--- a/libcpp/configure.ac ++++ b/libcpp/configure.ac +@@ -211,8 +211,23 @@ esac + # Enable --enable-host-shared. + AC_ARG_ENABLE(host-shared, + [AS_HELP_STRING([--enable-host-shared], +- [build host code as shared libraries])], +-[PICFLAG=-fPIC], [PICFLAG=]) ++ [build host code as shared libraries])]) ++AC_SUBST(enable_host_shared) ++ ++# Enable --enable-host-pie. ++AC_ARG_ENABLE(host-pie, ++[AS_HELP_STRING([--enable-host-pie], ++ [build host code as PIE])]) ++AC_SUBST(enable_host_pie) ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE ++else ++ PICFLAG= ++fi ++ + AC_SUBST(PICFLAG) + + # Enable Intel CET on Intel CET enabled host if jit is enabled. +diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h +index b8e50ae15bb..26474a470ac 100644 +--- a/libcpp/include/cpplib.h ++++ b/libcpp/include/cpplib.h +@@ -756,6 +756,9 @@ struct cpp_callbacks + /* Callback to determine whether a built-in function is recognized. */ + int (*has_builtin) (cpp_reader *); + ++ /* Callback to determine whether a feature is available. */ ++ int (*has_feature) (cpp_reader *, bool); ++ + /* Callback that can change a user lazy into normal macro. */ + void (*user_lazy_macro) (cpp_reader *, cpp_macro *, unsigned); + +@@ -960,7 +963,9 @@ enum cpp_builtin_type + BT_HAS_STD_ATTRIBUTE, /* `__has_c_attribute(x)' */ + BT_HAS_BUILTIN, /* `__has_builtin(x)' */ + BT_HAS_INCLUDE, /* `__has_include(x)' */ +- BT_HAS_INCLUDE_NEXT /* `__has_include_next(x)' */ ++ BT_HAS_INCLUDE_NEXT, /* `__has_include_next(x)' */ ++ BT_HAS_FEATURE, /* `__has_feature(x)' */ ++ BT_HAS_EXTENSION /* `__has_extension(x)' */ + }; + + #define CPP_HASHNODE(HNODE) ((cpp_hashnode *) (HNODE)) +diff --git a/libcpp/init.cc b/libcpp/init.cc +index c508f06112a..465dafefe9d 100644 +--- a/libcpp/init.cc ++++ b/libcpp/init.cc +@@ -433,6 +433,8 @@ static const struct builtin_macro builtin_array[] = + B("__has_builtin", BT_HAS_BUILTIN, true), + B("__has_include", BT_HAS_INCLUDE, true), + B("__has_include_next",BT_HAS_INCLUDE_NEXT, true), ++ B("__has_feature", BT_HAS_FEATURE, true), ++ B("__has_extension", BT_HAS_EXTENSION, true), + /* Keep builtins not used for -traditional-cpp at the end, and + update init_builtins() if any more are added. */ + B("_Pragma", BT_PRAGMA, true), +diff --git a/libcpp/macro.cc b/libcpp/macro.cc +index d4238d4f621..d2e8f9bd411 100644 +--- a/libcpp/macro.cc ++++ b/libcpp/macro.cc +@@ -677,6 +677,12 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node, + number = builtin_has_include (pfile, node, + node->value.builtin == BT_HAS_INCLUDE_NEXT); + break; ++ ++ case BT_HAS_FEATURE: ++ case BT_HAS_EXTENSION: ++ number = pfile->cb.has_feature (pfile, ++ node->value.builtin == BT_HAS_FEATURE); ++ break; + } + + if (result == NULL) +diff --git a/libdecnumber/configure b/libdecnumber/configure +index fb6db05565a..84bc4ffc767 100755 +--- a/libdecnumber/configure ++++ b/libdecnumber/configure +@@ -626,6 +626,8 @@ ac_subst_vars='LTLIBOBJS + LIBOBJS + CET_HOST_FLAGS + PICFLAG ++enable_host_pie ++enable_host_shared + ADDITIONAL_OBJS + enable_decimal_float + target_os +@@ -706,6 +708,7 @@ enable_werror_always + enable_maintainer_mode + enable_decimal_float + enable_host_shared ++enable_host_pie + enable_cet + ' + ac_precious_vars='build_alias +@@ -1338,6 +1341,7 @@ Optional Features: + or 'dpd' choses which decimal floating point format + to use + --enable-host-shared build host code as shared libraries ++ --enable-host-pie build host code as PIE + --enable-cet enable Intel CET in host libraries [default=auto] + + Some influential environment variables: +@@ -5186,7 +5190,23 @@ $as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h + # Enable --enable-host-shared. + # Check whether --enable-host-shared was given. + if test "${enable_host_shared+set}" = set; then : +- enableval=$enable_host_shared; PICFLAG=-fPIC ++ enableval=$enable_host_shared; ++fi ++ ++ ++ ++# Enable --enable-host-pie. ++# Check whether --enable-host-pie was given. ++if test "${enable_host_pie+set}" = set; then : ++ enableval=$enable_host_pie; ++fi ++ ++ ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE + else + PICFLAG= + fi +diff --git a/libdecnumber/configure.ac b/libdecnumber/configure.ac +index aafd06f8a64..30a51ca410b 100644 +--- a/libdecnumber/configure.ac ++++ b/libdecnumber/configure.ac +@@ -100,8 +100,23 @@ AC_C_BIGENDIAN + # Enable --enable-host-shared. + AC_ARG_ENABLE(host-shared, + [AS_HELP_STRING([--enable-host-shared], +- [build host code as shared libraries])], +-[PICFLAG=-fPIC], [PICFLAG=]) ++ [build host code as shared libraries])]) ++AC_SUBST(enable_host_shared) ++ ++# Enable --enable-host-pie. ++AC_ARG_ENABLE(host-pie, ++[AS_HELP_STRING([--enable-host-pie], ++ [build host code as PIE])]) ++AC_SUBST(enable_host_pie) ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE ++else ++ PICFLAG= ++fi ++ + AC_SUBST(PICFLAG) + + # Enable Intel CET on Intel CET enabled host if jit is enabled. +diff --git a/libffi/Makefile.am b/libffi/Makefile.am +index c6d6f849c53..d2ae0c04c7b 100644 +--- a/libffi/Makefile.am ++++ b/libffi/Makefile.am +@@ -214,7 +214,12 @@ libffi.map: $(top_srcdir)/libffi.map.in + $(COMPILE) -D$(TARGET) -DGENERATE_LIBFFI_MAP \ + -E -x assembler-with-cpp -o $@ $(top_srcdir)/libffi.map.in + +-libffi_la_LDFLAGS = -no-undefined $(libffi_version_info) $(libffi_version_script) $(LTLDFLAGS) $(AM_LTLDFLAGS) ++if ENABLE_DARWIN_AT_RPATH ++libffi_darwin_rpath = -Wl,-rpath,@loader_path ++endif ++libffi_la_LDFLAGS = -no-undefined $(libffi_version_info) \ ++ $(libffi_version_script) $(LTLDFLAGS) $(AM_LTLDFLAGS) \ ++ $(libffi_darwin_rpath) + libffi_la_DEPENDENCIES = $(libffi_la_LIBADD) $(libffi_version_dep) + + AM_CPPFLAGS = -I. -I$(top_srcdir)/include -Iinclude -I$(top_srcdir)/src +diff --git a/libffi/Makefile.in b/libffi/Makefile.in +index 5524a6a571e..34e77a45d1a 100644 +--- a/libffi/Makefile.in ++++ b/libffi/Makefile.in +@@ -597,7 +597,11 @@ AM_CFLAGS = -Wall -g -fexceptions $(CET_FLAGS) $(am__append_2) + @LIBFFI_BUILD_VERSIONED_SHLIB_GNU_TRUE@@LIBFFI_BUILD_VERSIONED_SHLIB_TRUE@libffi_version_dep = libffi.map + @LIBFFI_BUILD_VERSIONED_SHLIB_SUN_TRUE@@LIBFFI_BUILD_VERSIONED_SHLIB_TRUE@libffi_version_dep = libffi.map-sun + libffi_version_info = -version-info `grep -v '^\#' $(srcdir)/libtool-version` +-libffi_la_LDFLAGS = -no-undefined $(libffi_version_info) $(libffi_version_script) $(LTLDFLAGS) $(AM_LTLDFLAGS) ++@ENABLE_DARWIN_AT_RPATH_TRUE@libffi_darwin_rpath = -Wl,-rpath,@loader_path ++libffi_la_LDFLAGS = -no-undefined $(libffi_version_info) \ ++ $(libffi_version_script) $(LTLDFLAGS) $(AM_LTLDFLAGS) \ ++ $(libffi_darwin_rpath) ++ + libffi_la_DEPENDENCIES = $(libffi_la_LIBADD) $(libffi_version_dep) + AM_CPPFLAGS = -I. -I$(top_srcdir)/include -Iinclude -I$(top_srcdir)/src + AM_CCASFLAGS = $(AM_CPPFLAGS) $(CET_FLAGS) +diff --git a/libffi/configure b/libffi/configure +index 2bb9f8d83d6..0fae8b5c96d 100755 +--- a/libffi/configure ++++ b/libffi/configure +@@ -667,6 +667,8 @@ MAINT + MAINTAINER_MODE_FALSE + MAINTAINER_MODE_TRUE + READELF ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + CXXCPP + CPP + OTOOL64 +@@ -810,6 +812,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + enable_maintainer_mode + enable_pax_emutramp + enable_debug +@@ -1465,6 +1468,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --enable-maintainer-mode + enable make rules and dependencies not useful (and + sometimes confusing) to the casual installer +@@ -7797,7 +7803,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -9771,6 +9777,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -9788,9 +9837,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -11596,7 +11649,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11599 "configure" ++#line 11652 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11702,7 +11755,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11705 "configure" ++#line 11758 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -12578,6 +12631,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc_CXX=no + hardcode_direct_CXX=no + hardcode_automatic_CXX=yes +@@ -12595,12 +12691,20 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + if test "$lt_cv_apple_cc_single_mod" != "yes"; then +- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring${_lt_dsymutil}" + archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" + fi + +@@ -14970,6 +15074,14 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu + # Only expand once: + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}readelf", so it can be a program name with args. +@@ -17115,6 +17227,10 @@ if test -z "${am__fastdepCCAS_TRUE}" && test -z "${am__fastdepCCAS_FALSE}"; then + as_fn_error $? "conditional \"am__fastdepCCAS\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then + as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/libffi/configure.ac b/libffi/configure.ac +index 014d89d0423..716f20ae313 100644 +--- a/libffi/configure.ac ++++ b/libffi/configure.ac +@@ -55,6 +55,7 @@ AC_SUBST(CET_FLAGS) + AM_PROG_AS + AM_PROG_CC_C_O + AC_PROG_LIBTOOL ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) + + AC_CHECK_TOOL(READELF, readelf) + +diff --git a/libffi/doc/version.texi b/libffi/doc/version.texi +index f2b741e87e4..6261b21fec9 100644 +--- a/libffi/doc/version.texi ++++ b/libffi/doc/version.texi +@@ -1,4 +1,4 @@ +-@set UPDATED 27 June 2021 +-@set UPDATED-MONTH June 2021 ++@set UPDATED 31 August 2022 ++@set UPDATED-MONTH August 2022 + @set EDITION 3.4.2 + @set VERSION 3.4.2 +diff --git a/libgcc/config.host b/libgcc/config.host +index c94d69d84b7..c0a4cc6fa9b 100644 +--- a/libgcc/config.host ++++ b/libgcc/config.host +@@ -82,7 +82,7 @@ m32c*-*-*) + cpu_type=m32c + tmake_file=t-fdpbit + ;; +-aarch64*-*-*) ++aarch64*-*-* | arm64*-*-*) + cpu_type=aarch64 + ;; + alpha*-*-*) +@@ -233,21 +233,26 @@ case ${host} in + ;; + esac + tmake_file="$tmake_file t-slibgcc-darwin" +- # newer toolsets produce warnings when building for unsupported versions. + case ${host} in +- *-*-darwin1[89]* | *-*-darwin2* ) +- tmake_file="t-darwin-min-8 $tmake_file" ++ x86_64-*-darwin2[0-3]*) ++ tmake_file="t-darwin-min-11 t-darwin-libgccs1 $tmake_file" ++ ;; ++ *-*-darwin2*) ++ tmake_file="t-darwin-min-11 $tmake_file" ++ ;; ++ *-*-darwin1[89]*) ++ tmake_file="t-darwin-min-8 t-darwin-libgccs1 $tmake_file" + ;; + *-*-darwin9* | *-*-darwin1[0-7]*) +- tmake_file="t-darwin-min-5 $tmake_file" ++ tmake_file="t-darwin-min-5 t-darwin-libgccs1 $tmake_file" + ;; + *-*-darwin[4-8]*) +- tmake_file="t-darwin-min-1 $tmake_file" ++ tmake_file="t-darwin-min-1 t-darwin-libgccs1 $tmake_file" + ;; + *) + # Fall back to configuring for the oldest system known to work with + # all archs and the current sources. +- tmake_file="t-darwin-min-5 $tmake_file" ++ tmake_file="t-darwin-min-5 t-darwin-libgccs1 $tmake_file" + echo "Warning: libgcc configured to support macOS 10.5" 1>&2 + ;; + esac +@@ -251,7 +258,29 @@ case ${host} in + echo "Warning: libgcc configured to support macOS 10.5" 1>&2 + ;; + esac +- extra_parts="crt3.o libd10-uwfef.a crttms.o crttme.o libemutls_w.a" ++ # We are not using libtool to build the libs here, so we need to replicate ++ # a little of the logic around setting Darwin rpaths. Setting an explicit ++ # yes or no is honoured, otherwise we choose a suitable default. ++ # Sadly, this has to be kept in line with the rules in libtool.m4. ++ # This make fragment will override the setting in t-slibgcc-darwin so it ++ # must appear after it. ++ if test "x$enable_darwin_at_rpath" = "x"; then ++ echo "enable_darwin_at_rpath is unset" 1>&2 ++ case ${host} in ++ *-darwin[45678]*) ;; ++ *-darwin9* | *-darwin1[01234]*) ;; # We might default these on later. ++ *-darwin*) ++ echo "but is needed after macOS 10.11 (setting it on)" 1>&2 ++ enable_darwin_at_rpath=yes ++ ;; ++ esac ++ else ++ echo "enable_darwin_at_rpath is '$enable_darwin_at_rpath'" 1>&2 ++ fi ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ tmake_file="$tmake_file t-darwin-rpath " ++ fi ++ extra_parts="crt3.o crttms.o crttme.o libemutls_w.a " + ;; + *-*-dragonfly*) + tmake_file="$tmake_file t-crtstuff-pic t-libgcc-pic t-eh-dw2-dip" +@@ -395,6 +419,15 @@ aarch64*-*-elf | aarch64*-*-rtems*) + tmake_file="${tmake_file} t-dfprules" + md_unwind_header=aarch64/aarch64-unwind.h + ;; ++aarch64*-*-darwin*) ++ extra_parts="$extra_parts crtfastmath.o libheapt_w.a" ++ tmake_file="${tmake_file} ${cpu_type}/t-aarch64" ++ tmake_file="${tmake_file} ${cpu_type}/t-lse " ++ tmake_file="${tmake_file} ${cpu_type}/t-softfp t-softfp " ++ tmake_file="${tmake_file} t-crtfm t-dfprules" ++ tmake_file="${tmake_file} ${cpu_type}/t-heap-trampoline" ++ md_unwind_header=aarch64/aarch64-unwind.h ++ ;; + aarch64*-*-freebsd*) + extra_parts="$extra_parts crtfastmath.o" + tmake_file="${tmake_file} ${cpu_type}/t-aarch64" +@@ -423,6 +456,7 @@ aarch64*-*-linux*) + tmake_file="${tmake_file} ${cpu_type}/t-lse t-slibgcc-libgcc" + tmake_file="${tmake_file} ${cpu_type}/t-softfp t-softfp t-crtfm" + tmake_file="${tmake_file} t-dfprules" ++ tmake_file="${tmake_file} ${cpu_type}/t-heap-trampoline" + ;; + aarch64*-*-vxworks7*) + extra_parts="$extra_parts crtfastmath.o" +@@ -691,12 +725,18 @@ hppa*-*-netbsd*) + i[34567]86-*-darwin*) + tmake_file="$tmake_file i386/t-crtpc t-crtfm i386/t-msabi" + tm_file="$tm_file i386/darwin-lib.h" +- extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o" ++ extra_parts="$extra_parts libd10-uwfef.a " ++ extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o" ++ extra_parts="$extra_parts crtfastmath.o libheapt_w.a" ++ tmake_file="${tmake_file} i386/t-heap-trampoline" + ;; + x86_64-*-darwin*) + tmake_file="$tmake_file i386/t-crtpc t-crtfm i386/t-msabi" + tm_file="$tm_file i386/darwin-lib.h" +- extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o" ++ extra_parts="$extra_parts libd10-uwfef.a " ++ extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o" ++ extra_parts="$extra_parts crtfastmath.o libheapt_w.a" ++ tmake_file="${tmake_file} i386/t-heap-trampoline" + ;; + i[34567]86-*-elfiamcu) + tmake_file="$tmake_file i386/t-crtstuff t-softfp-sfdftf i386/32/t-softfp i386/32/t-iamcu i386/t-softfp t-softfp t-dfprules" +@@ -746,6 +786,7 @@ i[34567]86-*-linux*) + tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules" + tm_file="${tm_file} i386/elf-lib.h" + md_unwind_header=i386/linux-unwind.h ++ tmake_file="${tmake_file} i386/t-heap-trampoline" + ;; + i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-kopensolaris*-gnu) + extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o" +@@ -763,6 +804,7 @@ x86_64-*-linux*) + tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules" + tm_file="${tm_file} i386/elf-lib.h" + md_unwind_header=i386/linux-unwind.h ++ tmake_file="${tmake_file} i386/t-heap-trampoline" + ;; + x86_64-*-kfreebsd*-gnu) + extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o" +@@ -1171,12 +1213,14 @@ powerpc-*-darwin*) + # We build the darwin10 EH shim for Rosetta (running on x86 machines). + tm_file="$tm_file i386/darwin-lib.h" + tmake_file="$tmake_file rs6000/t-ppc64-fp rs6000/t-ibm-ldouble" ++ extra_parts="$extra_parts libd10-uwfef.a " + extra_parts="$extra_parts crt2.o crt3_2.o libef_ppc.a dw_ppc.o" + ;; + powerpc64-*-darwin*) + # We build the darwin10 EH shim for Rosetta (running on x86 machines). + tm_file="$tm_file i386/darwin-lib.h" + tmake_file="$tmake_file rs6000/t-darwin64 rs6000/t-ibm-ldouble" ++ extra_parts="$extra_parts libd10-uwfef.a " + extra_parts="$extra_parts crt2.o crt3_2.o libef_ppc.a dw_ppc.o" + ;; + powerpc*-*-freebsd*) +diff --git a/libgcc/config/aarch64/heap-trampoline.c b/libgcc/config/aarch64/heap-trampoline.c +new file mode 100644 +index 00000000000..b2c69aa5892 +--- /dev/null ++++ b/libgcc/config/aarch64/heap-trampoline.c +@@ -0,0 +1,185 @@ ++/* Copyright The GNU Toolchain Authors. */ ++ ++/* libc is required to allocate trampolines. */ ++#ifndef inhibit_libc ++ ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#if __APPLE__ ++/* For pthread_jit_write_protect_np */ ++#include ++#endif ++ ++/* HEAP_T_ATTR is provided to allow targets to build the exported functions ++ as weak definitions. */ ++#ifndef HEAP_T_ATTR ++# define HEAP_T_ATTR ++#endif ++ ++void *allocate_trampoline_page (void); ++int get_trampolines_per_page (void); ++struct tramp_ctrl_data *allocate_tramp_ctrl (struct tramp_ctrl_data *parent); ++void *allocate_trampoline_page (void); ++ ++void __gcc_nested_func_ptr_created (void *chain, void *func, void **dst); ++void __gcc_nested_func_ptr_deleted (void); ++ ++#if defined(__linux__) ++static const unsigned char aarch64_trampoline_insns[6][4] = { ++ {0x5f, 0x24, 0x03, 0xd5}, /* hint 34 */ ++ {0xb1, 0x00, 0x00, 0x58}, /* ldr x17, .+20 */ ++ {0xd2, 0x00, 0x00, 0x58}, /* ldr x18, .+24 */ ++ {0x20, 0x02, 0x1f, 0xd6}, /* br x17 */ ++ {0x9f, 0x3f, 0x03, 0xd5}, /* dsb sy */ ++ {0xdf, 0x3f, 0x03, 0xd5} /* isb */ ++}; ++ ++#elif __APPLE__ ++static const unsigned char aarch64_trampoline_insns[6][4] = { ++ {0x5f, 0x24, 0x03, 0xd5}, /* hint 34 */ ++ {0xb1, 0x00, 0x00, 0x58}, /* ldr x17, .+20 */ ++ {0xd0, 0x00, 0x00, 0x58}, /* ldr x16, .+24 */ ++ {0x20, 0x02, 0x1f, 0xd6}, /* br x17 */ ++ {0x9f, 0x3f, 0x03, 0xd5}, /* dsb sy */ ++ {0xdf, 0x3f, 0x03, 0xd5} /* isb */ ++}; ++ ++#else ++#error "Unsupported AArch64 platform for heap trampolines" ++#endif ++ ++struct aarch64_trampoline { ++ unsigned char insns[6][4]; ++ void *func_ptr; ++ void *chain_ptr; ++}; ++ ++struct tramp_ctrl_data ++{ ++ struct tramp_ctrl_data *prev; ++ ++ int free_trampolines; ++ ++ /* This will be pointing to an executable mmap'ed page. */ ++ struct aarch64_trampoline *trampolines; ++}; ++ ++int ++get_trampolines_per_page (void) ++{ ++ return getpagesize() / sizeof(struct aarch64_trampoline); ++} ++ ++static _Thread_local struct tramp_ctrl_data *tramp_ctrl_curr = NULL; ++ ++void * ++allocate_trampoline_page (void) ++{ ++ void *page; ++ ++#if defined(__linux__) ++ page = mmap (0, getpagesize (), PROT_WRITE | PROT_EXEC, ++ MAP_ANON | MAP_PRIVATE, 0, 0); ++#elif __APPLE__ ++ page = mmap (0, getpagesize (), PROT_WRITE | PROT_EXEC, ++ MAP_ANON | MAP_PRIVATE | MAP_JIT, 0, 0); ++#else ++ page = MAP_FAILED; ++#endif ++ ++ return page; ++} ++ ++struct tramp_ctrl_data * ++allocate_tramp_ctrl (struct tramp_ctrl_data *parent) ++{ ++ struct tramp_ctrl_data *p = malloc (sizeof (struct tramp_ctrl_data)); ++ if (p == NULL) ++ return NULL; ++ ++ p->trampolines = allocate_trampoline_page (); ++ ++ if (p->trampolines == MAP_FAILED) ++ return NULL; ++ ++ p->prev = parent; ++ p->free_trampolines = get_trampolines_per_page(); ++ ++ return p; ++} ++ ++HEAP_T_ATTR ++void ++__gcc_nested_func_ptr_created (void *chain, void *func, void **dst) ++{ ++ if (tramp_ctrl_curr == NULL) ++ { ++ tramp_ctrl_curr = allocate_tramp_ctrl (NULL); ++ if (tramp_ctrl_curr == NULL) ++ abort (); ++ } ++ ++ if (tramp_ctrl_curr->free_trampolines == 0) ++ { ++ void *tramp_ctrl = allocate_tramp_ctrl (tramp_ctrl_curr); ++ if (!tramp_ctrl) ++ abort (); ++ ++ tramp_ctrl_curr = tramp_ctrl; ++ } ++ ++ struct aarch64_trampoline *trampoline ++ = &tramp_ctrl_curr->trampolines[get_trampolines_per_page () ++ - tramp_ctrl_curr->free_trampolines]; ++ ++#if __APPLE__ ++ /* Disable write protection for the MAP_JIT regions in this thread (see ++ https://developer.apple.com/documentation/apple-silicon/porting-just-in-time-compilers-to-apple-silicon) */ ++ pthread_jit_write_protect_np (0); ++#endif ++ ++ memcpy (trampoline->insns, aarch64_trampoline_insns, ++ sizeof(aarch64_trampoline_insns)); ++ trampoline->func_ptr = func; ++ trampoline->chain_ptr = chain; ++ ++#if __APPLE__ ++ /* Re-enable write protection. */ ++ pthread_jit_write_protect_np (1); ++#endif ++ ++ tramp_ctrl_curr->free_trampolines -= 1; ++ ++ __builtin___clear_cache ((void *)trampoline->insns, ++ ((void *)trampoline->insns + sizeof(trampoline->insns))); ++ ++ *dst = &trampoline->insns; ++} ++ ++HEAP_T_ATTR ++void ++__gcc_nested_func_ptr_deleted (void) ++{ ++ if (tramp_ctrl_curr == NULL) ++ abort (); ++ ++ tramp_ctrl_curr->free_trampolines += 1; ++ ++ if (tramp_ctrl_curr->free_trampolines == get_trampolines_per_page ()) ++ { ++ if (tramp_ctrl_curr->prev == NULL) ++ return; ++ ++ munmap (tramp_ctrl_curr->trampolines, getpagesize()); ++ struct tramp_ctrl_data *prev = tramp_ctrl_curr->prev; ++ free (tramp_ctrl_curr); ++ tramp_ctrl_curr = prev; ++ } ++} ++ ++#endif /* !inhibit_libc */ +diff --git a/libgcc/config/aarch64/aarch64-asm.h b/libgcc/config/aarch64/aarch64-asm.h +new file mode 100644 +index 00000000000..87ee33bc52a +--- /dev/null ++++ b/libgcc/config/aarch64/aarch64-asm.h +@@ -0,0 +1,128 @@ ++/* AArch64 asm definitions. ++ Copyright (C) 2023-2024 Free Software Foundation, Inc. ++ ++ This file is part of GCC. ++ ++ GCC is free software; you can redistribute it and/or modify it ++ under the terms of the GNU General Public License as published ++ by the Free Software Foundation; either version 3, or (at your ++ option) any later version. ++ ++ GCC is distributed in the hope that it will be useful, but WITHOUT ++ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ++ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public ++ License for more details. ++ ++ Under Section 7 of GPL version 3, you are granted additional ++ permissions described in the GCC Runtime Library Exception, version ++ 3.1, as published by the Free Software Foundation. ++ ++ You should have received a copy of the GNU General Public License and ++ a copy of the GCC Runtime Library Exception along with this program; ++ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see ++ . */ ++ ++#include "auto-target.h" ++ ++/* Marking variant PCS symbol references is important for PLT calls ++ otherwise it is for documenting the PCS in the symbol table. */ ++#ifdef HAVE_AS_VARIANT_PCS ++# define variant_pcs(name) .variant_pcs name ++#else ++# define variant_pcs(name) ++#endif ++ ++/* GNU_PROPERTY_AARCH64_* macros from elf.h for use in asm code. */ ++#define FEATURE_1_AND 0xc0000000 ++#define FEATURE_1_BTI 1 ++#define FEATURE_1_PAC 2 ++ ++/* Supported features based on the code generation options. */ ++#if defined(__ARM_FEATURE_BTI_DEFAULT) ++# define BTI_FLAG FEATURE_1_BTI ++# define BTI_C hint 34 ++#else ++# define BTI_FLAG 0 ++# define BTI_C ++#endif ++ ++#if __ARM_FEATURE_PAC_DEFAULT & 3 ++# define PAC_FLAG FEATURE_1_PAC ++# define PACIASP hint 25; .cfi_window_save ++# define AUTIASP hint 29; .cfi_window_save ++#else ++# define PAC_FLAG 0 ++# define PACIASP ++# define AUTIASP ++#endif ++ ++#define PASTE2(a, b) PASTE2a(a, b) ++#define PASTE2a(a, b) a ## b ++ ++#ifdef __USER_LABEL_PREFIX__ ++# define ASMNAME(name) PASTE2(__USER_LABEL_PREFIX__, name) ++#else ++# define ASMNAME(name) name ++#endif ++ ++#ifdef __ELF__ ++#define L(label) .L ## label ++#define HIDDEN(name) .hidden name ++#define GLOBAL(name) .global name ++#define SYMBOL_SIZE(name) .size name, .-name ++#define SYMBOL_TYPE(name, _type) .type name, _type ++#elif __APPLE__ ++#define L(label) L ## label ++#define HIDDEN(name) .private_extern name ++#define GLOBAL(name) .globl name ++#define SYMBOL_SIZE(name) ++#define SYMBOL_TYPE(name, _type) ++#else ++#define L(label) .L ## label ++#define HIDDEN(name) ++#define GLOBAL(name) .global name ++#define SYMBOL_SIZE(name) ++#define SYMBOL_TYPE(name, _type) ++#endif ++ ++/* Add a NT_GNU_PROPERTY_TYPE_0 note. */ ++#define GNU_PROPERTY(type, value) \ ++ .section .note.gnu.property, "a"; \ ++ .p2align 3; \ ++ .word 4; \ ++ .word 16; \ ++ .word 5; \ ++ .asciz "GNU"; \ ++ .word type; \ ++ .word 4; \ ++ .word value; \ ++ .word 0; \ ++ .previous ++ ++#if defined(__linux__) || defined(__FreeBSD__) ++/* Do not require executable stack. */ ++.section .note.GNU-stack, "", %progbits ++.previous ++ ++/* Add GNU property note if built with branch protection. */ ++# if (BTI_FLAG|PAC_FLAG) != 0 ++GNU_PROPERTY (FEATURE_1_AND, BTI_FLAG|PAC_FLAG) ++# endif ++#endif ++ ++.macro ENTRY_ALIGNP2m, name, align ++ .text ++ .p2align \align ++ GLOBAL (\name) ++ SYMBOL_TYPE(\name, %function) ++\name: ++ .cfi_startproc ++ BTI_C ++.endm ++ ++#define ENTRY(name) ENTRY_ALIGNP2m name, 4 ++ ++.macro ENDm, name ++ .cfi_endproc ++ SYMBOL_SIZE (\name) ++.endm +diff --git a/libgcc/config/aarch64/lse.S b/libgcc/config/aarch64/lse.S +index dde3a28e07b..87ee33bc52a 100644 +--- a/libgcc/config/aarch64/lse.S ++++ b/libgcc/config/aarch64/lse.S +@@ -1,5 +1,5 @@ + /* Out-of-line LSE atomics for AArch64 architecture. +- Copyright (C) 2019-2023 Free Software Foundation, Inc. ++ Copyright (C) 2019-2024 Free Software Foundation, Inc. + Contributed by Linaro Ltd. + + This file is part of GCC. +@@ -46,8 +46,12 @@ + * direct branch. The choice of LSE vs non-LSE is done via one byte load + * followed by a well-predicted direct branch. The functions are compiled + * separately to minimize code size. ++ * ++ * Since these functions have hidden visibility and are never called ++ * indirectly, they do not need to start with a BTI instruction. + */ + ++#include "aarch64-asm.h" + #include "auto-target.h" + + /* Tell the assembler to accept LSE instructions. */ +@@ -58,7 +62,7 @@ + #endif + + /* Declare the symbol gating the LSE implementations. */ +- .hidden __aarch64_have_lse_atomics ++ HIDDEN (ASMNAME (__aarch64_have_lse_atomics)) + + /* Turn size and memory model defines into mnemonic fragments. */ + #if SIZE == 1 +@@ -81,6 +85,7 @@ + # error + #endif + ++#undef L + #if MODEL == 1 + # define SUFF _relax + # define A +@@ -160,36 +165,24 @@ + #define tmp0 16 + #define tmp1 17 + #define tmp2 15 ++#define tmp3 14 ++#define tmp4 13 + +-#define BTI_C hint 34 +- +-/* Start and end a function. */ +-.macro STARTFN name +- .text +- .balign 16 +- .globl \name +- .hidden \name +- .type \name, %function +- .cfi_startproc +-\name: +- BTI_C +-.endm +- +-.macro ENDFN name +- .cfi_endproc +- .size \name, . - \name +-.endm +- + /* Branch to LABEL if LSE is disabled. */ + .macro JUMP_IF_NOT_LSE label +- adrp x(tmp0), __aarch64_have_lse_atomics +- ldrb w(tmp0), [x(tmp0), :lo12:__aarch64_have_lse_atomics] ++#if __APPLE__ ++ adrp x(tmp0), ASMNAME (__aarch64_have_lse_atomics)@PAGE ++ ldrb w(tmp0), [x(tmp0), ASMNAME (__aarch64_have_lse_atomics)@PAGEOFF] ++#else ++ adrp x(tmp0), ASMNAME (__aarch64_have_lse_atomics) ++ ldrb w(tmp0), [x(tmp0), :lo12:ASMNAME (__aarch64_have_lse_atomics)] ++#endif + cbz w(tmp0), \label + .endm + + #ifdef L_cas + +-STARTFN NAME(cas) ++ENTRY (ASMNAME (NAME(cas))) + JUMP_IF_NOT_LSE 8f + + #if SIZE < 16 +@@ -233,15 +226,16 @@ + 0: LDXP x0, x1, [x4] + cmp x0, x(tmp0) + ccmp x1, x(tmp1), #0, eq +- bne 1f +- STXP w(tmp2), x2, x3, [x4] +- cbnz w(tmp2), 0b +-1: BARRIER ++ csel x(tmp2), x2, x0, eq ++ csel x(tmp3), x3, x1, eq ++ STXP w(tmp4), x(tmp2), x(tmp3), [x4] ++ cbnz w(tmp4), 0b ++ BARRIER + ret + + #endif + +-ENDFN NAME(cas) ++ENDm ASMNAME (NAME(cas)) + #endif + + #ifdef L_swp +@@ -251,7 +245,7 @@ + # define SWP .inst 0x38208020 + B + N + #endif + +-STARTFN NAME(swp) ++ENTRY (ASMNAME (NAME (swp))) + JUMP_IF_NOT_LSE 8f + + SWP /* s(0), s(0), [x1] */ +@@ -264,7 +258,7 @@ + BARRIER + ret + +-ENDFN NAME(swp) ++ENDm ASMNAME (NAME (swp)) + #endif + + #if defined(L_ldadd) || defined(L_ldclr) \ +@@ -295,7 +289,7 @@ + # define LDOP .inst 0x38200020 + OPN + B + N + #endif + +-STARTFN NAME(LDNM) ++ENTRY (ASMNAME (NAME (LDNM))) + JUMP_IF_NOT_LSE 8f + + LDOP /* s(0), s(0), [x1] */ +@@ -309,45 +303,5 @@ + BARRIER + ret + +-ENDFN NAME(LDNM) +-#endif +- +-/* GNU_PROPERTY_AARCH64_* macros from elf.h for use in asm code. */ +-#define FEATURE_1_AND 0xc0000000 +-#define FEATURE_1_BTI 1 +-#define FEATURE_1_PAC 2 +- +-/* Supported features based on the code generation options. */ +-#if defined(__ARM_FEATURE_BTI_DEFAULT) +-# define BTI_FLAG FEATURE_1_BTI +-#else +-# define BTI_FLAG 0 +-#endif +- +-#if __ARM_FEATURE_PAC_DEFAULT & 3 +-# define PAC_FLAG FEATURE_1_PAC +-#else +-# define PAC_FLAG 0 +-#endif +- +-/* Add a NT_GNU_PROPERTY_TYPE_0 note. */ +-#define GNU_PROPERTY(type, value) \ +- .section .note.gnu.property, "a"; \ +- .p2align 3; \ +- .word 4; \ +- .word 16; \ +- .word 5; \ +- .asciz "GNU"; \ +- .word type; \ +- .word 4; \ +- .word value; \ +- .word 0; +- +-#if defined(__linux__) || defined(__FreeBSD__) +-.section .note.GNU-stack, "", %progbits +- +-/* Add GNU property note if built with branch protection. */ +-# if (BTI_FLAG|PAC_FLAG) != 0 +-GNU_PROPERTY (FEATURE_1_AND, BTI_FLAG|PAC_FLAG) +-# endif ++ENDm ASMNAME (NAME (LDNM)) + #endif +diff --git a/libgcc/config/aarch64/sfp-machine.h b/libgcc/config/aarch64/sfp-machine.h +index 97c38a34c86..b35e2c5e29a 100644 +--- a/libgcc/config/aarch64/sfp-machine.h ++++ b/libgcc/config/aarch64/sfp-machine.h +@@ -124,6 +124,27 @@ void __sfp_handle_exceptions (int); + + + /* Define ALIASNAME as a strong alias for NAME. */ ++#if defined __APPLE__ ++/* Mach-O doesn't support aliasing, so we build a secondary function for ++ the alias - we need to do a bit of a dance to find out what the type of ++ the arguments is and then apply that to the secondary function. ++ If these functions ever return anything but CMPtype we need to revisit ++ this... */ ++typedef float alias_HFtype __attribute__ ((mode (HF))); ++typedef float alias_SFtype __attribute__ ((mode (SF))); ++typedef float alias_DFtype __attribute__ ((mode (DF))); ++typedef float alias_TFtype __attribute__ ((mode (TF))); ++#define ALIAS_SELECTOR \ ++ CMPtype (*) (alias_HFtype, alias_HFtype): (alias_HFtype) 0, \ ++ CMPtype (*) (alias_SFtype, alias_SFtype): (alias_SFtype) 0, \ ++ CMPtype (*) (alias_DFtype, alias_DFtype): (alias_DFtype) 0, \ ++ CMPtype (*) (alias_TFtype, alias_TFtype): (alias_TFtype) 0 ++#define strong_alias(name, aliasname) \ ++ CMPtype aliasname (__typeof (_Generic (name, ALIAS_SELECTOR)) a, \ ++ __typeof (_Generic (name, ALIAS_SELECTOR)) b) \ ++ { return name (a, b); } ++#else + # define strong_alias(name, aliasname) _strong_alias(name, aliasname) + # define _strong_alias(name, aliasname) \ + extern __typeof (name) aliasname __attribute__ ((alias (#name))); ++#endif +diff --git a/libgcc/config/aarch64/t-darwin b/libgcc/config/aarch64/t-darwin +new file mode 100644 +index 00000000000..f6ecda7b608 +--- /dev/null ++++ b/libgcc/config/aarch64/t-darwin +@@ -0,0 +1,7 @@ ++# Ensure we have a suitable minimum OS version. ++ ++HOST_LIBGCC2_CFLAGS += -mmacosx-version-min=11.0 ++ ++LIB2_SIDITI_CONV_FUNCS = yes ++ ++BUILD_LIBGCCS1 = +diff --git a/libgcc/config/aarch64/t-heap-trampoline b/libgcc/config/aarch64/t-heap-trampoline +new file mode 100644 +index 00000000000..6468fb8704f +--- /dev/null ++++ b/libgcc/config/aarch64/t-heap-trampoline +@@ -0,0 +1,20 @@ ++# Copyright The GNU Toolchain Authors. ++ ++# This file is part of GCC. ++# ++# GCC is free software; you can redistribute it and/or modify it ++# under the terms of the GNU General Public License as published by ++# the Free Software Foundation; either version 3, or (at your option) ++# any later version. ++# ++# GCC is distributed in the hope that it will be useful, but ++# WITHOUT ANY WARRANTY; without even the implied warranty of ++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++# General Public License for more details. ++# ++# You should have received a copy of the GNU General Public License ++# along with GCC; see the file COPYING3. If not see ++# . ++ ++LIB2ADDEH += $(srcdir)/config/aarch64/heap-trampoline.c ++LIB2ADDEHSHARED += $(srcdir)/config/aarch64/heap-trampoline.c +diff --git a/libgcc/config/i386/heap-trampoline.c b/libgcc/config/i386/heap-trampoline.c +new file mode 100644 +index 00000000000..2e8df1cfbd2 +--- /dev/null ++++ b/libgcc/config/i386/heap-trampoline.c +@@ -0,0 +1,255 @@ ++/* Copyright The GNU Toolchain Authors. */ ++ ++/* libc is required to allocate trampolines. */ ++#ifndef inhibit_libc ++ ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#if __APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101400 ++/* For pthread_jit_write_protect_np */ ++#include ++#endif ++ ++/* HEAP_T_ATTR is provided to allow targets to build the exported functions ++ as weak definitions. */ ++#ifndef HEAP_T_ATTR ++# define HEAP_T_ATTR ++#endif ++ ++void *allocate_trampoline_page (void); ++int get_trampolines_per_page (void); ++struct tramp_ctrl_data *allocate_tramp_ctrl (struct tramp_ctrl_data *parent); ++void *allocate_trampoline_page (void); ++ ++void __gcc_nested_func_ptr_created (void *chain, void *func, void **dst); ++void __gcc_nested_func_ptr_deleted (void); ++ ++#if __x86_64__ ++ ++#ifdef __LP64__ ++static const uint8_t trampoline_insns[] = { ++#if defined __CET__ && (__CET__ & 1) != 0 ++ /* endbr64. */ ++ 0xf3, 0x0f, 0x1e, 0xfa, ++#endif ++ ++ /* movabsq $,%r11 */ ++ 0x49, 0xbb, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++ ++ /* movabsq $,%r10 */ ++ 0x49, 0xba, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++ ++ /* rex.WB jmpq *%r11 */ ++ 0x41, 0xff, 0xe3, ++ ++ /* Pad to the multiple of 4 bytes. */ ++ 0x90 ++}; ++#else ++static const uint8_t trampoline_insns[] = { ++#if defined __CET__ && (__CET__ & 1) != 0 ++ /* endbr64. */ ++ 0xf3, 0x0f, 0x1e, 0xfa, ++#endif ++ ++ /* movl $,%r11d */ ++ 0x41, 0xbb, ++ 0x00, 0x00, 0x00, 0x00, ++ ++ /* movl $,%r10d */ ++ 0x41, 0xba, ++ 0x00, 0x00, 0x00, 0x00, ++ ++ /* rex.WB jmpq *%r11 */ ++ 0x41, 0xff, 0xe3, ++ ++ /* Pad to the multiple of 4 bytes. */ ++ 0x90 ++}; ++#endif ++ ++union ix86_trampoline { ++ uint8_t insns[sizeof(trampoline_insns)]; ++ ++ struct __attribute__((packed)) fields { ++#if defined __CET__ && (__CET__ & 1) != 0 ++ uint8_t endbr64[4]; ++#endif ++ uint8_t insn_0[2]; ++ void *func_ptr; ++ uint8_t insn_1[2]; ++ void *chain_ptr; ++ uint8_t insn_2[3]; ++ uint8_t pad; ++ } fields; ++}; ++ ++#elif __i386__ ++ ++static const uint8_t trampoline_insns[] = { ++ /* movl $,%ecx */ ++ 0xb9, ++ 0x00, 0x00, 0x00, 0x00, ++ ++ /* jmpl -. */ ++ 0xe9, ++ 0x00, 0x00, 0x00, 0x00, ++}; ++ ++union ix86_trampoline { ++ uint8_t insns[sizeof(trampoline_insns)]; ++ ++ struct __attribute__((packed)) fields { ++ uint8_t insn_0[1]; ++ void *chain_ptr; ++ uint8_t insn_1[1]; ++ uintptr_t func_offset; ++ } fields; ++}; ++ ++#else ++#error unsupported architecture/ABI ++#endif ++ ++struct tramp_ctrl_data ++{ ++ struct tramp_ctrl_data *prev; ++ ++ int free_trampolines; ++ ++ /* This will be pointing to an executable mmap'ed page. */ ++ union ix86_trampoline *trampolines; ++}; ++ ++int ++get_trampolines_per_page (void) ++{ ++ return getpagesize() / sizeof(union ix86_trampoline); ++} ++ ++static _Thread_local struct tramp_ctrl_data *tramp_ctrl_curr = NULL; ++ ++void * ++allocate_trampoline_page (void) ++{ ++ void *page; ++ ++#if defined(__gnu_linux__) ++ page = mmap (0, getpagesize (), PROT_WRITE | PROT_EXEC, ++ MAP_ANON | MAP_PRIVATE, 0, 0); ++#elif __APPLE__ ++# if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101400 ++ page = mmap (0, getpagesize (), PROT_WRITE | PROT_EXEC, ++ MAP_ANON | MAP_PRIVATE | MAP_JIT, 0, 0); ++# else ++ page = mmap (0, getpagesize (), PROT_WRITE | PROT_EXEC, ++ MAP_ANON | MAP_PRIVATE, 0, 0); ++# endif ++#else ++ page = MAP_FAILED; ++#endif ++ ++ return page; ++} ++ ++struct tramp_ctrl_data * ++allocate_tramp_ctrl (struct tramp_ctrl_data *parent) ++{ ++ struct tramp_ctrl_data *p = malloc (sizeof (struct tramp_ctrl_data)); ++ if (p == NULL) ++ return NULL; ++ ++ p->trampolines = allocate_trampoline_page (); ++ ++ if (p->trampolines == MAP_FAILED) ++ return NULL; ++ ++ p->prev = parent; ++ p->free_trampolines = get_trampolines_per_page(); ++ ++ return p; ++} ++ ++HEAP_T_ATTR ++void ++__gcc_nested_func_ptr_created (void *chain, void *func, void **dst) ++{ ++ if (tramp_ctrl_curr == NULL) ++ { ++ tramp_ctrl_curr = allocate_tramp_ctrl (NULL); ++ if (tramp_ctrl_curr == NULL) ++ abort (); ++ } ++ ++ if (tramp_ctrl_curr->free_trampolines == 0) ++ { ++ void *tramp_ctrl = allocate_tramp_ctrl (tramp_ctrl_curr); ++ if (!tramp_ctrl) ++ abort (); ++ ++ tramp_ctrl_curr = tramp_ctrl; ++ } ++ ++ union ix86_trampoline *trampoline ++ = &tramp_ctrl_curr->trampolines[get_trampolines_per_page () ++ - tramp_ctrl_curr->free_trampolines]; ++ ++#if __APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101400 ++ /* Disable write protection for the MAP_JIT regions in this thread (see ++ https://developer.apple.com/documentation/apple-silicon/porting-just-in-time-compilers-to-apple-silicon) */ ++ pthread_jit_write_protect_np (0); ++#endif ++ ++ memcpy (trampoline->insns, trampoline_insns, ++ sizeof(trampoline_insns)); ++ trampoline->fields.chain_ptr = chain; ++#if __x86_64__ ++ trampoline->fields.func_ptr = func; ++#elif __i386__ ++ uintptr_t off_add = (uintptr_t) &trampoline->fields.func_offset; ++ off_add += 4; ++ trampoline->fields.func_offset = (uintptr_t)func - off_add; ++#endif ++ ++#if __APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101400 ++ /* Re-enable write protection. */ ++ pthread_jit_write_protect_np (1); ++#endif ++ ++ tramp_ctrl_curr->free_trampolines -= 1; ++ ++ __builtin___clear_cache ((void *)trampoline->insns, ++ ((void *)trampoline->insns + sizeof(trampoline->insns))); ++ ++ *dst = &trampoline->insns; ++} ++ ++HEAP_T_ATTR ++void ++__gcc_nested_func_ptr_deleted (void) ++{ ++ if (tramp_ctrl_curr == NULL) ++ abort (); ++ ++ tramp_ctrl_curr->free_trampolines += 1; ++ ++ if (tramp_ctrl_curr->free_trampolines == get_trampolines_per_page ()) ++ { ++ if (tramp_ctrl_curr->prev == NULL) ++ return; ++ ++ munmap (tramp_ctrl_curr->trampolines, getpagesize()); ++ struct tramp_ctrl_data *prev = tramp_ctrl_curr->prev; ++ free (tramp_ctrl_curr); ++ tramp_ctrl_curr = prev; ++ } ++} ++ ++#endif /* !inhibit_libc */ +diff --git a/libgcc/config/i386/t-darwin b/libgcc/config/i386/t-darwin +index 4c18da1efbf..c6b3acaaca2 100644 +--- a/libgcc/config/i386/t-darwin ++++ b/libgcc/config/i386/t-darwin +@@ -4,6 +4,3 @@ LIB2FUNCS_EXCLUDE = _fixtfdi _fixunstfdi _floatditf _floatunditf + + # Extra symbols for this port. + SHLIB_MAPFILES += $(srcdir)/config/i386/libgcc-darwin.ver +- +-# Build a legacy libgcc_s.1 +-BUILD_LIBGCCS1 = YES +diff --git a/libgcc/config/i386/t-heap-trampoline b/libgcc/config/i386/t-heap-trampoline +new file mode 100644 +index 00000000000..5cd11f594ba +--- /dev/null ++++ b/libgcc/config/i386/t-heap-trampoline +@@ -0,0 +1,20 @@ ++# Copyright The GNU Toolchain Authors. ++ ++# This file is part of GCC. ++# ++# GCC is free software; you can redistribute it and/or modify it ++# under the terms of the GNU General Public License as published by ++# the Free Software Foundation; either version 3, or (at your option) ++# any later version. ++# ++# GCC is distributed in the hope that it will be useful, but ++# WITHOUT ANY WARRANTY; without even the implied warranty of ++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++# General Public License for more details. ++# ++# You should have received a copy of the GNU General Public License ++# along with GCC; see the file COPYING3. If not see ++# . ++ ++LIB2ADDEH += $(srcdir)/config/i386/heap-trampoline.c ++LIB2ADDEHSHARED += $(srcdir)/config/i386/heap-trampoline.c +diff --git a/libgcc/config/rs6000/t-darwin b/libgcc/config/rs6000/t-darwin +index 183d0df92ce..8b513bdb1d7 100644 +--- a/libgcc/config/rs6000/t-darwin ++++ b/libgcc/config/rs6000/t-darwin +@@ -56,6 +56,3 @@ unwind-dw2_s.o: HOST_LIBGCC2_CFLAGS += -maltivec + unwind-dw2.o: HOST_LIBGCC2_CFLAGS += -maltivec + + LIB2ADDEH += $(srcdir)/config/rs6000/darwin-fallback.c +- +-# Build a legacy libgcc_s.1 +-BUILD_LIBGCCS1 = YES +diff --git a/libgcc/config/t-darwin b/libgcc/config/t-darwin +index a3bb70c6a0a..0f65b54a230 100644 +--- a/libgcc/config/t-darwin ++++ b/libgcc/config/t-darwin +@@ -51,5 +51,18 @@ LIB2ADDEH = $(srcdir)/unwind-dw2.c \ + # Do not build a shared unwind lib by default. + LIBEHSOBJS= + ++# Make heap trampoline helpers weak definitions so that we can merge them from ++# multiple DSOs. ++heap-trampoline.o: HOST_LIBGCC2_CFLAGS += \ ++ -DHEAP_T_ATTR='__attribute__((__weak__,__visibility__("default")))' ++heap-trampoline_s.o: HOST_LIBGCC2_CFLAGS += \ ++ -DHEAP_T_ATTR='__attribute__((__weak__,__visibility__("default")))' ++ ++# Make a heap trampoline support CRT so that it can be linked optionally, use ++# the shared version so that we can link with DSOs. ++libheapt_w.a: heap-trampoline_s.o ++ $(AR_CREATE_FOR_TARGET) $@ $< ++ $(RANLIB_FOR_TARGET) $@ ++ + # Symbols for all the sub-ports. + SHLIB_MAPFILES = libgcc-std.ver $(srcdir)/config/libgcc-libsystem.ver +diff --git a/libgcc/config/t-darwin-libgccs1 b/libgcc/config/t-darwin-libgccs1 +new file mode 100644 +index 00000000000..b88b1a5bba8 +--- /dev/null ++++ b/libgcc/config/t-darwin-libgccs1 +@@ -0,0 +1,3 @@ ++ ++# Build a legacy libgcc_s.1 ++BUILD_LIBGCCS1 = YES + +diff --git a/libgcc/config/t-darwin-min-11 b/libgcc/config/t-darwin-min-11 +new file mode 100644 +index 00000000000..4009d41addb +--- /dev/null ++++ b/libgcc/config/t-darwin-min-11 +@@ -0,0 +1,3 @@ ++# Support building with -mmacosx-version-min back to macOS 11. ++DARWIN_MIN_LIB_VERSION = -mmacosx-version-min=11 ++DARWIN_MIN_CRT_VERSION = -mmacosx-version-min=11 +diff --git a/libgcc/config/t-darwin-rpath b/libgcc/config/t-darwin-rpath +new file mode 100644 +index 00000000000..e73d7f378b0 +--- /dev/null ++++ b/libgcc/config/t-darwin-rpath +@@ -0,0 +1,2 @@ ++# Use @rpath and add a search path to exes and dylibs that depend on this. ++SHLIB_RPATH = @rpath +diff --git a/libgcc/config/t-slibgcc-darwin b/libgcc/config/t-slibgcc-darwin +index cb0cbbdb1c5..da4886848e8 100644 +--- a/libgcc/config/t-slibgcc-darwin ++++ b/libgcc/config/t-slibgcc-darwin +@@ -1,4 +1,4 @@ +-# Build a shared libgcc library with the darwin linker. ++# Build a shared libgcc library able to use embedded runpaths. + + SHLIB_SOVERSION = 1.1 + SHLIB_SO_MINVERSION = 1 +@@ -6,7 +6,6 @@ SHLIB_VERSTRING = -compatibility_version $(SHLIB_SO_MINVERSION) \ + -current_version $(SHLIB_SOVERSION) + SHLIB_EXT = .dylib + SHLIB_LC = -lSystem +-SHLIB_INSTALL_DIR = $(slibdir) + + SHLIB_MKMAP = $(srcdir)/mkmap-flat.awk + SHLIB_MKMAP_OPTS = -v leading_underscore=1 +@@ -23,11 +22,16 @@ SHLIB_SONAME = @shlib_base_name@$(SHLIB_EXT) + # subdir. The code under MULTIBUILDTOP combines these into a single FAT + # library, that is what we eventually install. + ++# When enable_darwin_at_rpath is true, use @rpath instead of $(slibdir) for ++# this and dylibs that depend on this. So this def must come first and be ++# overridden in a make fragment that depends on the rpath setting. ++SHLIB_RPATH = $(slibdir) ++ + SHLIB_LINK = $(CC) $(LIBGCC2_CFLAGS) $(LDFLAGS) -dynamiclib -nodefaultlibs \ +- -install_name $(SHLIB_INSTALL_DIR)/$(SHLIB_INSTALL_NAME) \ ++ -install_name $(SHLIB_RPATH)/$(SHLIB_INSTALL_NAME) \ + -single_module -o $(SHLIB_DIR)/$(SHLIB_SONAME) \ + -Wl,-exported_symbols_list,$(SHLIB_MAP) \ +- $(SHLIB_VERSTRING) \ ++ $(SHLIB_VERSTRING) -nodefaultrpaths \ + @multilib_flags@ @shlib_objs@ $(SHLIB_LC) + + # we do our own thing +@@ -63,9 +67,9 @@ EHS_INSTNAME = libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT) + libgcc_ehs$(SHLIB_EXT): $(LIBEHSOBJS) $(extra-parts) + mkdir -p $(MULTIDIR) + $(CC) $(LIBGCC2_CFLAGS) $(LDFLAGS) -dynamiclib -nodefaultlibs \ +- -install_name $(SHLIB_INSTALL_DIR)/$(EHS_INSTNAME) \ ++ -install_name $(SHLIB_RPATH)/$(EHS_INSTNAME) \ + -o $(MULTIDIR)/libgcc_ehs$(SHLIB_EXT) $(SHLIB_VERSTRING) \ +- $(LIBEHSOBJS) $(SHLIB_LC) ++ -nodefaultrpaths $(LIBEHSOBJS) $(SHLIB_LC) + + all: libgcc_ehs$(SHLIB_EXT) + +@@ -122,12 +126,12 @@ libgcc_s.1.dylib: all-multi libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT) \ + cp ../$${mlib}/libgcc/$${mlib}/libgcc_ehs$(SHLIB_EXT) \ + ./libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} || exit 1 ; \ + arch=`$(LIPO) -info libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} | sed -e 's/.*:\ //'` ; \ +- $(CC) -arch $${arch} -nodefaultlibs -dynamiclib \ ++ $(CC) -arch $${arch} -nodefaultlibs -dynamiclib -nodefaultrpaths \ + -o libgcc_s.1$(SHLIB_EXT)_T_$${mlib} \ + -Wl,-reexport_library,libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} \ + -Wl,-reexport_library,libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} \ +- -install_name $(SHLIB_INSTALL_DIR)/libgcc_s.1.dylib \ +- -compatibility_version 1 -current_version 1 ; \ ++ -install_name $(SHLIB_RPATH)/libgcc_s.1.dylib \ ++ -compatibility_version 1 -current_version 1.1 ; \ + done + $(LIPO) -output libgcc_s.1$(SHLIB_EXT) -create libgcc_s.1$(SHLIB_EXT)_T* + rm libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T* +@@ -141,13 +145,13 @@ libgcc_s.1.dylib: all-multi libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT) + cp ../$${mlib}/libgcc/$${mlib}/libgcc_s$(SHLIB_EXT) \ + ./libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} || exit 1 ; \ + arch=`$(LIPO) -info libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} | sed -e 's/.*:\ //'` ; \ +- $(CC) -arch $${arch} -nodefaultlibs -dynamiclib \ ++ $(CC) -arch $${arch} -nodefaultlibs -dynamiclib -nodefaultrpaths \ + -o libgcc_s.1$(SHLIB_EXT)_T_$${mlib} \ + -Wl,-reexport_library,libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} \ + -lSystem \ + -Wl,-reexported_symbols_list,$(srcdir)/config/darwin-unwind.ver \ +- -install_name $(SHLIB_INSTALL_DIR)/libgcc_s.1.dylib \ +- -compatibility_version 1 -current_version 1 ; \ ++ -install_name $(SHLIB_RPATH)/libgcc_s.1.dylib \ ++ -compatibility_version 1 -current_version 1.1 ; \ + done + $(LIPO) -output libgcc_s.1$(SHLIB_EXT) -create libgcc_s.1$(SHLIB_EXT)_T* + rm libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T* +diff --git a/libgcc/libgcc-std.ver.in b/libgcc/libgcc-std.ver.in +index c4f87a50e70..ad854bf0ded 100644 +--- a/libgcc/libgcc-std.ver.in ++++ b/libgcc/libgcc-std.ver.in +@@ -1944,3 +1944,9 @@ GCC_7.0.0 { + __PFX__divmoddi4 + __PFX__divmodti4 + } ++ ++%inherit GCC_14.0.0 GCC_7.0.0 ++GCC_14.0.0 { ++ __gcc_nested_func_ptr_created ++ __gcc_nested_func_ptr_deleted ++} +diff --git a/libgcc/libgcc2.h b/libgcc/libgcc2.h +index 3ec9bbd8164..a7a5dff0184 100644 +--- a/libgcc/libgcc2.h ++++ b/libgcc/libgcc2.h +@@ -29,6 +29,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + #pragma GCC visibility push(default) + #endif + ++extern void __gcc_nested_func_ptr_created (void *, void *, void **); ++extern void __gcc_nested_func_ptr_deleted (void); ++ + extern int __gcc_bcmp (const unsigned char *, const unsigned char *, size_t); + extern void __clear_cache (void *, void *); + extern void __eprintf (const char *, const char *, unsigned int, const char *) +diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am +index 454ad12e701..3d21373ae82 100644 +--- a/libgfortran/Makefile.am ++++ b/libgfortran/Makefile.am +@@ -37,6 +37,11 @@ else + version_arg = + version_dep = + endif ++extra_darwin_ldflags_libgfortran = @extra_ldflags_libgfortran@ ++if ENABLE_DARWIN_AT_RPATH ++extra_darwin_ldflags_libgfortran += -Wc,-nodefaultrpaths ++extra_darwin_ldflags_libgfortran += -Wl,-rpath,@loader_path ++endif + + gfor_c_HEADERS = ISO_Fortran_binding.h + gfor_cdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include +@@ -50,7 +55,7 @@ libgfortran_la_LINK = $(LINK) $(libgfortran_la_LDFLAGS) + libgfortran_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ + $(LTLDFLAGS) $(LIBQUADLIB) ../libbacktrace/libbacktrace.la \ + $(HWCAP_LDFLAGS) \ +- $(LIBM) $(extra_ldflags_libgfortran) \ ++ $(LIBM) $(extra_darwin_ldflags_libgfortran) \ + $(version_arg) -Wc,-shared-libgcc + libgfortran_la_DEPENDENCIES = $(version_dep) libgfortran.spec $(LIBQUADLIB_DEP) + +diff --git a/libgfortran/Makefile.in b/libgfortran/Makefile.in +index 23df0761096..ed0d05f502a 100644 +--- a/libgfortran/Makefile.in ++++ b/libgfortran/Makefile.in +@@ -91,8 +91,10 @@ POST_UNINSTALL = : + build_triplet = @build@ + host_triplet = @host@ + target_triplet = @target@ +-@LIBGFOR_MINIMAL_TRUE@am__append_1 = -DLIBGFOR_MINIMAL +-@LIBGFOR_MINIMAL_FALSE@am__append_2 = \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@am__append_1 = -Wc,-nodefaultrpaths \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path ++@LIBGFOR_MINIMAL_TRUE@am__append_2 = -DLIBGFOR_MINIMAL ++@LIBGFOR_MINIMAL_FALSE@am__append_3 = \ + @LIBGFOR_MINIMAL_FALSE@io/close.c \ + @LIBGFOR_MINIMAL_FALSE@io/file_pos.c \ + @LIBGFOR_MINIMAL_FALSE@io/format.c \ +@@ -110,7 +112,7 @@ target_triplet = @target@ + @LIBGFOR_MINIMAL_FALSE@io/fbuf.c \ + @LIBGFOR_MINIMAL_FALSE@io/async.c + +-@LIBGFOR_MINIMAL_FALSE@am__append_3 = \ ++@LIBGFOR_MINIMAL_FALSE@am__append_4 = \ + @LIBGFOR_MINIMAL_FALSE@intrinsics/access.c \ + @LIBGFOR_MINIMAL_FALSE@intrinsics/c99_functions.c \ + @LIBGFOR_MINIMAL_FALSE@intrinsics/chdir.c \ +@@ -143,9 +145,9 @@ target_triplet = @target@ + @LIBGFOR_MINIMAL_FALSE@intrinsics/umask.c \ + @LIBGFOR_MINIMAL_FALSE@intrinsics/unlink.c + +-@IEEE_SUPPORT_TRUE@am__append_4 = ieee/ieee_helper.c +-@LIBGFOR_MINIMAL_TRUE@am__append_5 = runtime/minimal.c +-@LIBGFOR_MINIMAL_FALSE@am__append_6 = \ ++@IEEE_SUPPORT_TRUE@am__append_5 = ieee/ieee_helper.c ++@LIBGFOR_MINIMAL_TRUE@am__append_6 = runtime/minimal.c ++@LIBGFOR_MINIMAL_FALSE@am__append_7 = \ + @LIBGFOR_MINIMAL_FALSE@runtime/backtrace.c \ + @LIBGFOR_MINIMAL_FALSE@runtime/convert_char.c \ + @LIBGFOR_MINIMAL_FALSE@runtime/environ.c \ +@@ -157,7 +159,7 @@ target_triplet = @target@ + + + # dummy sources for libtool +-@onestep_TRUE@am__append_7 = libgfortran_c.c libgfortran_f.f90 ++@onestep_TRUE@am__append_8 = libgfortran_c.c libgfortran_f.f90 + subdir = . + ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 + am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \ +@@ -589,7 +591,7 @@ AMTAR = @AMTAR@ + + # Some targets require additional compiler options for IEEE compatibility. + AM_CFLAGS = @AM_CFLAGS@ -fcx-fortran-rules $(SECTION_FLAGS) \ +- $(IEEE_FLAGS) $(am__append_1) ++ $(IEEE_FLAGS) $(am__append_2) + AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ + AM_FCFLAGS = @AM_FCFLAGS@ $(IEEE_FLAGS) + AR = @AR@ +@@ -749,6 +751,8 @@ gcc_version := $(shell @get_gcc_base_ver@ $(top_srcdir)/../gcc/BASE-VER) + @LIBGFOR_USE_SYMVER_FALSE@version_dep = + @LIBGFOR_USE_SYMVER_GNU_TRUE@@LIBGFOR_USE_SYMVER_TRUE@version_dep = gfortran.ver + @LIBGFOR_USE_SYMVER_SUN_TRUE@@LIBGFOR_USE_SYMVER_TRUE@version_dep = gfortran.ver-sun gfortran.ver ++extra_darwin_ldflags_libgfortran = @extra_ldflags_libgfortran@ \ ++ $(am__append_1) + gfor_c_HEADERS = ISO_Fortran_binding.h + gfor_cdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include + LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS)) \ +@@ -760,7 +764,7 @@ libgfortran_la_LINK = $(LINK) $(libgfortran_la_LDFLAGS) + libgfortran_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ + $(LTLDFLAGS) $(LIBQUADLIB) ../libbacktrace/libbacktrace.la \ + $(HWCAP_LDFLAGS) \ +- $(LIBM) $(extra_ldflags_libgfortran) \ ++ $(LIBM) $(extra_darwin_ldflags_libgfortran) \ + $(version_arg) -Wc,-shared-libgcc + + libgfortran_la_DEPENDENCIES = $(version_dep) libgfortran.spec $(LIBQUADLIB_DEP) +@@ -781,7 +785,7 @@ AM_CPPFLAGS = -iquote$(srcdir)/io -I$(srcdir)/$(MULTISRCTOP)../gcc \ + -I$(MULTIBUILDTOP)../libbacktrace \ + -I../libbacktrace + +-gfor_io_src = io/size_from_kind.c $(am__append_2) ++gfor_io_src = io/size_from_kind.c $(am__append_3) + gfor_io_headers = \ + io/io.h \ + io/fbuf.h \ +@@ -803,7 +807,7 @@ gfor_helper_src = intrinsics/associated.c intrinsics/abort.c \ + intrinsics/selected_int_kind.f90 \ + intrinsics/selected_real_kind.f90 intrinsics/trigd.c \ + intrinsics/unpack_generic.c runtime/in_pack_generic.c \ +- runtime/in_unpack_generic.c $(am__append_3) $(am__append_4) ++ runtime/in_unpack_generic.c $(am__append_4) $(am__append_5) + @IEEE_SUPPORT_TRUE@gfor_ieee_helper_src = ieee/ieee_helper.c + @IEEE_SUPPORT_FALSE@gfor_ieee_src = + @IEEE_SUPPORT_TRUE@gfor_ieee_src = \ +@@ -812,8 +816,8 @@ gfor_helper_src = intrinsics/associated.c intrinsics/abort.c \ + @IEEE_SUPPORT_TRUE@ieee/ieee_features.F90 + + gfor_src = runtime/bounds.c runtime/compile_options.c runtime/memory.c \ +- runtime/string.c runtime/select.c $(am__append_5) \ +- $(am__append_6) ++ runtime/string.c runtime/select.c $(am__append_6) \ ++ $(am__append_7) + i_all_c = \ + $(srcdir)/generated/all_l1.c \ + $(srcdir)/generated/all_l2.c \ +@@ -1653,7 +1657,7 @@ intrinsics/random_init.f90 + + BUILT_SOURCES = $(gfor_built_src) $(gfor_built_specific_src) \ + $(gfor_built_specific2_src) $(gfor_misc_specifics) \ +- $(am__append_7) ++ $(am__append_8) + prereq_SRC = $(gfor_src) $(gfor_built_src) $(gfor_io_src) \ + $(gfor_helper_src) $(gfor_ieee_src) $(gfor_io_headers) $(gfor_specific_src) + +diff --git a/libgfortran/configure b/libgfortran/configure +index d7c3a5e27a0..feb75f6e55e 100755 +--- a/libgfortran/configure ++++ b/libgfortran/configure +@@ -654,6 +654,8 @@ extra_ldflags_libgfortran + ac_ct_FC + FCFLAGS + FC ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + enable_static + enable_shared + lt_host_flags +@@ -823,6 +825,7 @@ enable_static + with_pic + enable_fast_install + enable_libtool_lock ++enable_darwin_at_rpath + enable_largefile + enable_libquadmath_support + with_gcc_major_version_only +@@ -1478,6 +1481,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --disable-largefile omit support for large files + --disable-libquadmath-support + disable libquadmath support for Fortran +@@ -9235,7 +9241,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -10945,6 +10951,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -10962,9 +11011,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -12791,7 +12844,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12794 "configure" ++#line 12847 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -12897,7 +12950,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12900 "configure" ++#line 12953 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -13299,6 +13352,14 @@ esac + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ + #AC_MSG_NOTICE([====== Finished libtool configuration]) ; sleep 10 + + # We need gfortran to compile parts of the library +@@ -14942,6 +15003,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc_FC=no + hardcode_direct_FC=no + hardcode_automatic_FC=yes +@@ -14959,9 +15063,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds_FC="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_FC="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds_FC="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds_FC="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds_FC="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds_FC="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -16234,9 +16342,10 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + # extra LD Flags which are required for targets ++extra_ldflags_libgfortran= + case "${host}" in +- *-darwin*) +- # Darwin needs -single_module when linking libgfortran ++ *-*-darwin[4567]*) ++ # Earlier Darwin needs -single_module when linking libgfortran + extra_ldflags_libgfortran=-Wl,-single_module + ;; + esac +@@ -31597,6 +31706,10 @@ if test -z "${HAVE_HWCAP_TRUE}" && test -z "${HAVE_HWCAP_FALSE}"; then + as_fn_error $? "conditional \"HAVE_HWCAP\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${IEEE_SUPPORT_TRUE}" && test -z "${IEEE_SUPPORT_FALSE}"; then + as_fn_error $? "conditional \"IEEE_SUPPORT\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac +index 07b9a48a19f..4ee63cf723e 100644 +--- a/libgfortran/configure.ac ++++ b/libgfortran/configure.ac +@@ -282,6 +282,7 @@ LT_LIB_M + ACX_LT_HOST_FLAGS + AC_SUBST(enable_shared) + AC_SUBST(enable_static) ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) + #AC_MSG_NOTICE([====== Finished libtool configuration]) ; sleep 10 + + # We need gfortran to compile parts of the library +@@ -290,9 +291,10 @@ FC="$GFORTRAN" + AC_PROG_FC(gfortran) + + # extra LD Flags which are required for targets ++extra_ldflags_libgfortran= + case "${host}" in +- *-darwin*) +- # Darwin needs -single_module when linking libgfortran ++ *-*-darwin[[4567]]*) ++ # Earlier Darwin needs -single_module when linking libgfortran + extra_ldflags_libgfortran=-Wl,-single_module + ;; + esac +diff --git a/libgm2/Makefile.am b/libgm2/Makefile.am +index 95df3ed7a30..aa35e747c9a 100644 +--- a/libgm2/Makefile.am ++++ b/libgm2/Makefile.am +@@ -46,6 +46,12 @@ SUBDIRS = libm2min libm2log libm2cor libm2iso libm2pim + GM2_BUILDDIR := $(shell pwd) + gm2_cdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include + ++if ENABLE_DARWIN_AT_RPATH ++DARWIN_AT_RPATH=yes ++else ++DARWIN_AT_RPATH=yes ++endif ++ + # Work around what appears to be a GNU make bug handling MAKEFLAGS + # values defined in terms of make variables, as is the case for CC and + # friends when we are called from the top level Makefile. +@@ -91,7 +97,8 @@ AM_MAKEFLAGS = \ + "WERROR=$(WERROR)" \ + "TARGET_LIB_PATH=$(TARGET_LIB_PATH)" \ + "TARGET_LIB_PATH_libgm2=$(TARGET_LIB_PATH_libgm2)" \ +- "LIBTOOL=$(GM2_BUILDDIR)/libtool" ++ "LIBTOOL=$(GM2_BUILDDIR)/libtool" \ ++ "DARWIN_AT_RPATH=$(DARWIN_AT_RPATH)" + + # Subdir rules rely on $(FLAGS_TO_PASS) + FLAGS_TO_PASS = $(AM_MAKEFLAGS) +diff --git a/libgm2/Makefile.in b/libgm2/Makefile.in +index 2b9592b3490..f97f6d0812d 100644 +--- a/libgm2/Makefile.in ++++ b/libgm2/Makefile.in +@@ -90,15 +90,15 @@ host_triplet = @host@ + target_triplet = @target@ + subdir = . + ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +-am__aclocal_m4_deps = $(top_srcdir)/../libtool.m4 \ +- $(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \ +- $(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \ +- $(top_srcdir)/../config/acx.m4 \ ++am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \ + $(top_srcdir)/../config/depstand.m4 \ + $(top_srcdir)/../config/lead-dot.m4 \ + $(top_srcdir)/../config/multi.m4 \ + $(top_srcdir)/../config/no-executables.m4 \ +- $(top_srcdir)/../config/override.m4 $(top_srcdir)/configure.ac ++ $(top_srcdir)/../config/override.m4 \ ++ $(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \ ++ $(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \ ++ $(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/configure.ac + am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) + DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \ +@@ -344,6 +344,8 @@ GM2_SRC = $(GCC_DIR)/m2 + SUBDIRS = libm2min libm2log libm2cor libm2iso libm2pim + GM2_BUILDDIR := $(shell pwd) + gm2_cdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include ++@ENABLE_DARWIN_AT_RPATH_FALSE@DARWIN_AT_RPATH = yes ++@ENABLE_DARWIN_AT_RPATH_TRUE@DARWIN_AT_RPATH = yes + + # Work around what appears to be a GNU make bug handling MAKEFLAGS + # values defined in terms of make variables, as is the case for CC and +@@ -390,7 +392,8 @@ AM_MAKEFLAGS = \ + "WERROR=$(WERROR)" \ + "TARGET_LIB_PATH=$(TARGET_LIB_PATH)" \ + "TARGET_LIB_PATH_libgm2=$(TARGET_LIB_PATH_libgm2)" \ +- "LIBTOOL=$(GM2_BUILDDIR)/libtool" ++ "LIBTOOL=$(GM2_BUILDDIR)/libtool" \ ++ "DARWIN_AT_RPATH=$(DARWIN_AT_RPATH)" + + + # Subdir rules rely on $(FLAGS_TO_PASS) +diff --git a/libgm2/aclocal.m4 b/libgm2/aclocal.m4 +index c352303012d..832065fbb9b 100644 +--- a/libgm2/aclocal.m4 ++++ b/libgm2/aclocal.m4 +@@ -1187,14 +1187,14 @@ AC_SUBST([am__tar]) + AC_SUBST([am__untar]) + ]) # _AM_PROG_TAR + +-m4_include([../libtool.m4]) +-m4_include([../ltoptions.m4]) +-m4_include([../ltsugar.m4]) +-m4_include([../ltversion.m4]) +-m4_include([../lt~obsolete.m4]) + m4_include([../config/acx.m4]) + m4_include([../config/depstand.m4]) + m4_include([../config/lead-dot.m4]) + m4_include([../config/multi.m4]) + m4_include([../config/no-executables.m4]) + m4_include([../config/override.m4]) ++m4_include([../libtool.m4]) ++m4_include([../ltoptions.m4]) ++m4_include([../ltsugar.m4]) ++m4_include([../ltversion.m4]) ++m4_include([../lt~obsolete.m4]) +diff --git a/libgm2/configure b/libgm2/configure +index bf35b403a20..64f4f8034ce 100755 +--- a/libgm2/configure ++++ b/libgm2/configure +@@ -649,6 +649,8 @@ GM2_FOR_TARGET + CC_FOR_BUILD + enable_static + enable_shared ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + CXXCPP + OTOOL64 + OTOOL +@@ -806,6 +808,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + with_gcc_major_version_only + ' + ac_precious_vars='build_alias +@@ -1456,6 +1459,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + + Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] +@@ -6611,10 +6617,6 @@ fi + + + +-enable_dlopen=yes +- +- +- + case `pwd` in + *\ * | *\ *) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5 +@@ -9185,7 +9187,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -9233,6 +9235,8 @@ done + + + ++ enable_dlopen=no ++ + + enable_win32_dll=no + +@@ -10896,6 +10900,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -10913,9 +10960,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -12742,7 +12793,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12745 "configure" ++#line 12796 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -12848,7 +12899,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12851 "configure" ++#line 12902 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -13730,6 +13781,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc_CXX=no + hardcode_direct_CXX=no + hardcode_automatic_CXX=yes +@@ -13747,12 +13841,20 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + if test "$lt_cv_apple_cc_single_mod" != "yes"; then +- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring${_lt_dsymutil}" + archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" + fi + +@@ -16126,6 +16228,21 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + ++enable_dlopen=yes ++ ++ ++ ++ ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ ++ ++ + + + if test "${multilib}" = "yes"; then +@@ -20314,6 +20431,10 @@ if test -z "${am__fastdepCCAS_TRUE}" && test -z "${am__fastdepCCAS_FALSE}"; then + as_fn_error $? "conditional \"am__fastdepCCAS\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${BUILD_PIMLIB_TRUE}" && test -z "${BUILD_PIMLIB_FALSE}"; then + as_fn_error $? "conditional \"BUILD_PIMLIB\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/libgm2/configure.ac b/libgm2/configure.ac +index 9386bbfe5ec..305d2dc4319 100644 +--- a/libgm2/configure.ac ++++ b/libgm2/configure.ac +@@ -213,8 +213,12 @@ AC_PATH_PROG(PERL, perl, perl-not-found-in-path-error) + AC_PROG_MAKE_SET + AC_PROG_INSTALL + +-AC_LIBTOOL_DLOPEN + AM_PROG_LIBTOOL ++LT_INIT ++AC_LIBTOOL_DLOPEN ++ ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) ++ + AC_SUBST(enable_shared) + AC_SUBST(enable_static) + +diff --git a/libgm2/libm2cor/Makefile.am b/libgm2/libm2cor/Makefile.am +index ae96b4bfe78..a08e6a949e0 100644 +--- a/libgm2/libm2cor/Makefile.am ++++ b/libgm2/libm2cor/Makefile.am +@@ -123,6 +123,10 @@ libm2cor_la_link_flags = -Wl,-undefined,dynamic_lookup + else + libm2cor_la_link_flags = + endif ++if ENABLE_DARWIN_AT_RPATH ++libm2cor_la_link_flags += -nodefaultrpaths -Wl,-rpath,@loader_path/ ++endif ++ + libm2cor_la_LINK = $(LINK) -version-info $(libtool_VERSION) $(libm2cor_la_link_flags) + BUILT_SOURCES = SYSTEM.def + CLEANFILES = SYSTEM.def +diff --git a/libgm2/libm2cor/Makefile.in b/libgm2/libm2cor/Makefile.in +index 8daf0eaa054..9e14c90ae7f 100644 +--- a/libgm2/libm2cor/Makefile.in ++++ b/libgm2/libm2cor/Makefile.in +@@ -105,17 +105,18 @@ POST_UNINSTALL = : + build_triplet = @build@ + host_triplet = @host@ + target_triplet = @target@ ++@BUILD_CORLIB_TRUE@@ENABLE_DARWIN_AT_RPATH_TRUE@am__append_1 = -nodefaultrpaths -Wl,-rpath,@loader_path/ + subdir = libm2cor + ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +-am__aclocal_m4_deps = $(top_srcdir)/../libtool.m4 \ +- $(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \ +- $(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \ +- $(top_srcdir)/../config/acx.m4 \ ++am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \ + $(top_srcdir)/../config/depstand.m4 \ + $(top_srcdir)/../config/lead-dot.m4 \ + $(top_srcdir)/../config/multi.m4 \ + $(top_srcdir)/../config/no-executables.m4 \ +- $(top_srcdir)/../config/override.m4 $(top_srcdir)/configure.ac ++ $(top_srcdir)/../config/override.m4 \ ++ $(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \ ++ $(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \ ++ $(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/configure.ac + am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) + DIST_COMMON = $(srcdir)/Makefile.am +@@ -469,8 +470,10 @@ FLAGS_TO_PASS = $(AM_MAKEFLAGS) + @BUILD_CORLIB_TRUE@ -fm2-pathname=m2iso -I$(GM2_SRC)/gm2-libs-iso \ + @BUILD_CORLIB_TRUE@ -fm2-g -g -Wcase-enum -Wreturn-type -fcase -fm2-prefix=m2cor + +-@BUILD_CORLIB_TRUE@@TARGET_DARWIN_FALSE@libm2cor_la_link_flags = +-@BUILD_CORLIB_TRUE@@TARGET_DARWIN_TRUE@libm2cor_la_link_flags = -Wl,-undefined,dynamic_lookup ++@BUILD_CORLIB_TRUE@@TARGET_DARWIN_FALSE@libm2cor_la_link_flags = \ ++@BUILD_CORLIB_TRUE@@TARGET_DARWIN_FALSE@ $(am__append_1) ++@BUILD_CORLIB_TRUE@@TARGET_DARWIN_TRUE@libm2cor_la_link_flags = -Wl,-undefined,dynamic_lookup \ ++@BUILD_CORLIB_TRUE@@TARGET_DARWIN_TRUE@ $(am__append_1) + @BUILD_CORLIB_TRUE@libm2cor_la_LINK = $(LINK) -version-info $(libtool_VERSION) $(libm2cor_la_link_flags) + @BUILD_CORLIB_TRUE@BUILT_SOURCES = SYSTEM.def + @BUILD_CORLIB_TRUE@CLEANFILES = SYSTEM.def +diff --git a/libgm2/libm2iso/Makefile.am b/libgm2/libm2iso/Makefile.am +index 90d344f0fa8..e88c4b68e4f 100644 +--- a/libgm2/libm2iso/Makefile.am ++++ b/libgm2/libm2iso/Makefile.am +@@ -197,6 +197,10 @@ libm2iso_la_link_flags = -Wl,-undefined,dynamic_lookup + else + libm2iso_la_link_flags = + endif ++if ENABLE_DARWIN_AT_RPATH ++libm2iso_la_link_flags += -nodefaultrpaths -Wl,-rpath,@loader_path/ ++endif ++ + libm2iso_la_LINK = $(LINK) -version-info $(libtool_VERSION) $(libm2iso_la_link_flags) + CLEANFILES = SYSTEM.def + BUILT_SOURCES = SYSTEM.def +diff --git a/libgm2/libm2iso/Makefile.in b/libgm2/libm2iso/Makefile.in +index 8d6443d3946..7be5ad1d601 100644 +--- a/libgm2/libm2iso/Makefile.in ++++ b/libgm2/libm2iso/Makefile.in +@@ -105,17 +105,18 @@ POST_UNINSTALL = : + build_triplet = @build@ + host_triplet = @host@ + target_triplet = @target@ ++@BUILD_ISOLIB_TRUE@@ENABLE_DARWIN_AT_RPATH_TRUE@am__append_1 = -nodefaultrpaths -Wl,-rpath,@loader_path/ + subdir = libm2iso + ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +-am__aclocal_m4_deps = $(top_srcdir)/../libtool.m4 \ +- $(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \ +- $(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \ +- $(top_srcdir)/../config/acx.m4 \ ++am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \ + $(top_srcdir)/../config/depstand.m4 \ + $(top_srcdir)/../config/lead-dot.m4 \ + $(top_srcdir)/../config/multi.m4 \ + $(top_srcdir)/../config/no-executables.m4 \ +- $(top_srcdir)/../config/override.m4 $(top_srcdir)/configure.ac ++ $(top_srcdir)/../config/override.m4 \ ++ $(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \ ++ $(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \ ++ $(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/configure.ac + am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) + DIST_COMMON = $(srcdir)/Makefile.am +@@ -570,8 +571,10 @@ FLAGS_TO_PASS = $(AM_MAKEFLAGS) + @BUILD_ISOLIB_TRUE@ -fm2-pathname=m2pim -I$(GM2_SRC)/gm2-libs \ + @BUILD_ISOLIB_TRUE@ -fiso -fextended-opaque -fm2-g -g -Wcase-enum -Wreturn-type -fcase -fm2-prefix=m2iso + +-@BUILD_ISOLIB_TRUE@@TARGET_DARWIN_FALSE@libm2iso_la_link_flags = +-@BUILD_ISOLIB_TRUE@@TARGET_DARWIN_TRUE@libm2iso_la_link_flags = -Wl,-undefined,dynamic_lookup ++@BUILD_ISOLIB_TRUE@@TARGET_DARWIN_FALSE@libm2iso_la_link_flags = \ ++@BUILD_ISOLIB_TRUE@@TARGET_DARWIN_FALSE@ $(am__append_1) ++@BUILD_ISOLIB_TRUE@@TARGET_DARWIN_TRUE@libm2iso_la_link_flags = -Wl,-undefined,dynamic_lookup \ ++@BUILD_ISOLIB_TRUE@@TARGET_DARWIN_TRUE@ $(am__append_1) + @BUILD_ISOLIB_TRUE@libm2iso_la_LINK = $(LINK) -version-info $(libtool_VERSION) $(libm2iso_la_link_flags) + @BUILD_ISOLIB_TRUE@CLEANFILES = SYSTEM.def + @BUILD_ISOLIB_TRUE@BUILT_SOURCES = SYSTEM.def +diff --git a/libgm2/libm2log/Makefile.am b/libgm2/libm2log/Makefile.am +index 27f38406b07..25f5f9b0916 100644 +--- a/libgm2/libm2log/Makefile.am ++++ b/libgm2/libm2log/Makefile.am +@@ -142,6 +142,9 @@ libm2log_la_link_flags = -Wl,-undefined,dynamic_lookup + else + libm2log_la_link_flags = + endif ++if ENABLE_DARWIN_AT_RPATH ++libm2log_la_link_flags += -nodefaultrpaths -Wl,-rpath,@loader_path/ ++endif + libm2log_la_LINK = $(LINK) -version-info $(libtool_VERSION) $(libm2log_la_link_flags) + BUILT_SOURCES = ../libm2pim/SYSTEM.def + +diff --git a/libgm2/libm2log/Makefile.in b/libgm2/libm2log/Makefile.in +index 2188f9ec0c5..f82ddb61842 100644 +--- a/libgm2/libm2log/Makefile.in ++++ b/libgm2/libm2log/Makefile.in +@@ -105,17 +105,18 @@ POST_UNINSTALL = : + build_triplet = @build@ + host_triplet = @host@ + target_triplet = @target@ ++@BUILD_LOGLIB_TRUE@@ENABLE_DARWIN_AT_RPATH_TRUE@am__append_1 = -nodefaultrpaths -Wl,-rpath,@loader_path/ + subdir = libm2log + ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +-am__aclocal_m4_deps = $(top_srcdir)/../libtool.m4 \ +- $(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \ +- $(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \ +- $(top_srcdir)/../config/acx.m4 \ ++am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \ + $(top_srcdir)/../config/depstand.m4 \ + $(top_srcdir)/../config/lead-dot.m4 \ + $(top_srcdir)/../config/multi.m4 \ + $(top_srcdir)/../config/no-executables.m4 \ +- $(top_srcdir)/../config/override.m4 $(top_srcdir)/configure.ac ++ $(top_srcdir)/../config/override.m4 \ ++ $(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \ ++ $(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \ ++ $(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/configure.ac + am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) + DIST_COMMON = $(srcdir)/Makefile.am +@@ -478,8 +479,10 @@ FLAGS_TO_PASS = $(AM_MAKEFLAGS) + @BUILD_LOGLIB_TRUE@ -fm2-pathname=m2iso -I$(GM2_SRC)/gm2-libs-iso \ + @BUILD_LOGLIB_TRUE@ -Wcase-enum -Wreturn-type -fcase -fm2-prefix=m2log + +-@BUILD_LOGLIB_TRUE@@TARGET_DARWIN_FALSE@libm2log_la_link_flags = +-@BUILD_LOGLIB_TRUE@@TARGET_DARWIN_TRUE@libm2log_la_link_flags = -Wl,-undefined,dynamic_lookup ++@BUILD_LOGLIB_TRUE@@TARGET_DARWIN_FALSE@libm2log_la_link_flags = \ ++@BUILD_LOGLIB_TRUE@@TARGET_DARWIN_FALSE@ $(am__append_1) ++@BUILD_LOGLIB_TRUE@@TARGET_DARWIN_TRUE@libm2log_la_link_flags = -Wl,-undefined,dynamic_lookup \ ++@BUILD_LOGLIB_TRUE@@TARGET_DARWIN_TRUE@ $(am__append_1) + @BUILD_LOGLIB_TRUE@libm2log_la_LINK = $(LINK) -version-info $(libtool_VERSION) $(libm2log_la_link_flags) + @BUILD_LOGLIB_TRUE@BUILT_SOURCES = ../libm2pim/SYSTEM.def + @BUILD_LOGLIB_TRUE@M2LIBDIR = /m2/m2log/ +diff --git a/libgm2/libm2min/Makefile.am b/libgm2/libm2min/Makefile.am +index 1ff160028f6..21411769505 100644 +--- a/libgm2/libm2min/Makefile.am ++++ b/libgm2/libm2min/Makefile.am +@@ -113,6 +113,9 @@ libm2min_la_link_flags = -Wl,-undefined,dynamic_lookup + else + libm2min_la_link_flags = + endif ++if ENABLE_DARWIN_AT_RPATH ++libm2min_la_link_flags += -nodefaultrpaths -Wl,-rpath,@loader_path/ ++endif + libm2min_la_LINK = $(LINK) -version-info $(libtool_VERSION) $(libm2min_la_link_flags) + BUILT_SOURCES = SYSTEM.def + CLEANFILES = SYSTEM.def +diff --git a/libgm2/libm2min/Makefile.in b/libgm2/libm2min/Makefile.in +index 42cba0e37b9..ed3312deb0f 100644 +--- a/libgm2/libm2min/Makefile.in ++++ b/libgm2/libm2min/Makefile.in +@@ -105,17 +105,18 @@ POST_UNINSTALL = : + build_triplet = @build@ + host_triplet = @host@ + target_triplet = @target@ ++@ENABLE_DARWIN_AT_RPATH_TRUE@am__append_1 = -nodefaultrpaths -Wl,-rpath,@loader_path/ + subdir = libm2min + ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +-am__aclocal_m4_deps = $(top_srcdir)/../libtool.m4 \ +- $(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \ +- $(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \ +- $(top_srcdir)/../config/acx.m4 \ ++am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \ + $(top_srcdir)/../config/depstand.m4 \ + $(top_srcdir)/../config/lead-dot.m4 \ + $(top_srcdir)/../config/multi.m4 \ + $(top_srcdir)/../config/no-executables.m4 \ +- $(top_srcdir)/../config/override.m4 $(top_srcdir)/configure.ac ++ $(top_srcdir)/../config/override.m4 \ ++ $(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \ ++ $(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \ ++ $(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/configure.ac + am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) + DIST_COMMON = $(srcdir)/Makefile.am +@@ -442,8 +443,10 @@ libm2min_la_M2FLAGS = \ + -fm2-pathname=m2pim -I$(GM2_SRC)/gm2-libs -fno-exceptions \ + -fno-m2-plugin -fno-scaffold-dynamic -fno-scaffold-main -fm2-prefix=m2min + +-@TARGET_DARWIN_FALSE@libm2min_la_link_flags = +-@TARGET_DARWIN_TRUE@libm2min_la_link_flags = -Wl,-undefined,dynamic_lookup ++@TARGET_DARWIN_FALSE@libm2min_la_link_flags = $(am__append_1) ++@TARGET_DARWIN_TRUE@libm2min_la_link_flags = \ ++@TARGET_DARWIN_TRUE@ -Wl,-undefined,dynamic_lookup \ ++@TARGET_DARWIN_TRUE@ $(am__append_1) + libm2min_la_LINK = $(LINK) -version-info $(libtool_VERSION) $(libm2min_la_link_flags) + BUILT_SOURCES = SYSTEM.def + CLEANFILES = SYSTEM.def +diff --git a/libgm2/libm2pim/Makefile.am b/libgm2/libm2pim/Makefile.am +index ac172b93337..61d6c814cc4 100644 +--- a/libgm2/libm2pim/Makefile.am ++++ b/libgm2/libm2pim/Makefile.am +@@ -175,6 +175,9 @@ libm2pim_la_link_flags = -Wl,-undefined,dynamic_lookup + else + libm2pim_la_link_flags = + endif ++if ENABLE_DARWIN_AT_RPATH ++libm2pim_la_link_flags += -nodefaultrpaths -Wl,-rpath,@loader_path/ ++endif + libm2pim_la_LINK = $(LINK) -version-info $(libtool_VERSION) $(libm2pim_la_link_flags) + BUILT_SOURCES = SYSTEM.def + CLEANFILES = SYSTEM.def +diff --git a/libgm2/libm2pim/Makefile.in b/libgm2/libm2pim/Makefile.in +index 4c2d574392b..0f3a6fe940e 100644 +--- a/libgm2/libm2pim/Makefile.in ++++ b/libgm2/libm2pim/Makefile.in +@@ -105,17 +105,18 @@ POST_UNINSTALL = : + build_triplet = @build@ + host_triplet = @host@ + target_triplet = @target@ ++@BUILD_PIMLIB_TRUE@@ENABLE_DARWIN_AT_RPATH_TRUE@am__append_1 = -nodefaultrpaths -Wl,-rpath,@loader_path/ + subdir = libm2pim + ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +-am__aclocal_m4_deps = $(top_srcdir)/../libtool.m4 \ +- $(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \ +- $(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \ +- $(top_srcdir)/../config/acx.m4 \ ++am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \ + $(top_srcdir)/../config/depstand.m4 \ + $(top_srcdir)/../config/lead-dot.m4 \ + $(top_srcdir)/../config/multi.m4 \ + $(top_srcdir)/../config/no-executables.m4 \ +- $(top_srcdir)/../config/override.m4 $(top_srcdir)/configure.ac ++ $(top_srcdir)/../config/override.m4 \ ++ $(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \ ++ $(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \ ++ $(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/configure.ac + am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) + DIST_COMMON = $(srcdir)/Makefile.am +@@ -539,8 +540,10 @@ FLAGS_TO_PASS = $(AM_MAKEFLAGS) + @BUILD_PIMLIB_TRUE@ -fm2-pathname=m2iso -I$(GM2_SRC)/gm2-libs-iso \ + @BUILD_PIMLIB_TRUE@ -fm2-g -g -Wcase-enum -Wreturn-type -fcase -fm2-prefix=m2pim + +-@BUILD_PIMLIB_TRUE@@TARGET_DARWIN_FALSE@libm2pim_la_link_flags = +-@BUILD_PIMLIB_TRUE@@TARGET_DARWIN_TRUE@libm2pim_la_link_flags = -Wl,-undefined,dynamic_lookup ++@BUILD_PIMLIB_TRUE@@TARGET_DARWIN_FALSE@libm2pim_la_link_flags = \ ++@BUILD_PIMLIB_TRUE@@TARGET_DARWIN_FALSE@ $(am__append_1) ++@BUILD_PIMLIB_TRUE@@TARGET_DARWIN_TRUE@libm2pim_la_link_flags = -Wl,-undefined,dynamic_lookup \ ++@BUILD_PIMLIB_TRUE@@TARGET_DARWIN_TRUE@ $(am__append_1) + @BUILD_PIMLIB_TRUE@libm2pim_la_LINK = $(LINK) -version-info $(libtool_VERSION) $(libm2pim_la_link_flags) + @BUILD_PIMLIB_TRUE@BUILT_SOURCES = SYSTEM.def + @BUILD_PIMLIB_TRUE@CLEANFILES = SYSTEM.def +diff --git a/libgo/configure b/libgo/configure +index a607dbff68e..72d46c3eec3 100755 +--- a/libgo/configure ++++ b/libgo/configure +@@ -708,6 +708,8 @@ glibgo_toolexecdir + WERROR + WARN_FLAGS + CC_FOR_BUILD ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + enable_static + enable_shared + CPP +@@ -11544,7 +11546,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11547 "configure" ++#line 11549 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11650,7 +11652,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11653 "configure" ++#line 11655 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -13779,6 +13781,14 @@ CC="$lt_save_CC" + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ + + CC_FOR_BUILD=${CC_FOR_BUILD:-gcc} + +@@ -16386,6 +16396,10 @@ if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then + as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${USE_LIBFFI_TRUE}" && test -z "${USE_LIBFFI_FALSE}"; then + as_fn_error $? "conditional \"USE_LIBFFI\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/libgo/configure.ac b/libgo/configure.ac +index a59aa091d1d..6f1ac32660b 100644 +--- a/libgo/configure.ac ++++ b/libgo/configure.ac +@@ -53,6 +53,7 @@ AC_LIBTOOL_DLOPEN + AM_PROG_LIBTOOL + AC_SUBST(enable_shared) + AC_SUBST(enable_static) ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) + + CC_FOR_BUILD=${CC_FOR_BUILD:-gcc} + AC_SUBST(CC_FOR_BUILD) +diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am +index 428f7a9dab5..ceb8c910abd 100644 +--- a/libgomp/Makefile.am ++++ b/libgomp/Makefile.am +@@ -53,9 +53,14 @@ else + libgomp_version_script = + libgomp_version_dep = + endif ++ + libgomp_version_info = -version-info $(libtool_VERSION) ++if ENABLE_DARWIN_AT_RPATH ++libgomp_darwin_rpath = -Wc,-nodefaultrpaths ++libgomp_darwin_rpath += -Wl,-rpath,@loader_path ++endif + libgomp_la_LDFLAGS = $(libgomp_version_info) $(libgomp_version_script) \ +- $(lt_host_flags) ++ $(lt_host_flags) $(libgomp_darwin_rpath) + libgomp_la_LIBADD = + libgomp_la_DEPENDENCIES = $(libgomp_version_dep) + libgomp_la_LINK = $(LINK) $(libgomp_la_LDFLAGS) +diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in +index f1afb5ef57f..ef97186e68d 100644 +--- a/libgomp/Makefile.in ++++ b/libgomp/Makefile.in +@@ -535,8 +535,11 @@ nodist_toolexeclib_HEADERS = libgomp.spec + @LIBGOMP_BUILD_VERSIONED_SHLIB_GNU_TRUE@@LIBGOMP_BUILD_VERSIONED_SHLIB_TRUE@libgomp_version_dep = libgomp.ver + @LIBGOMP_BUILD_VERSIONED_SHLIB_SUN_TRUE@@LIBGOMP_BUILD_VERSIONED_SHLIB_TRUE@libgomp_version_dep = libgomp.ver-sun + libgomp_version_info = -version-info $(libtool_VERSION) ++@ENABLE_DARWIN_AT_RPATH_TRUE@libgomp_darwin_rpath = \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path + libgomp_la_LDFLAGS = $(libgomp_version_info) $(libgomp_version_script) \ +- $(lt_host_flags) ++ $(lt_host_flags) $(libgomp_darwin_rpath) + + libgomp_la_LIBADD = $(DL_LIBS) + libgomp_la_DEPENDENCIES = $(libgomp_version_dep) +diff --git a/libgomp/configure b/libgomp/configure +index 389500df738..1c219c29f5e 100755 +--- a/libgomp/configure ++++ b/libgomp/configure +@@ -682,6 +682,8 @@ FC + MAINT + MAINTAINER_MODE_FALSE + MAINTAINER_MODE_TRUE ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + enable_static + enable_shared + lt_host_flags +@@ -822,6 +824,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + enable_maintainer_mode + enable_linux_futex + enable_tls +@@ -1477,6 +1480,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --enable-maintainer-mode + enable make rules and dependencies not useful (and + sometimes confusing) to the casual installer +@@ -7621,7 +7627,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -9594,6 +9600,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -9611,9 +9660,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -11419,7 +11472,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11422 "configure" ++#line 11475 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11525,7 +11578,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11528 "configure" ++#line 11581 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11786,6 +11839,14 @@ esac + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5 +@@ -13461,6 +13522,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc_FC=no + hardcode_direct_FC=no + hardcode_automatic_FC=yes +@@ -13478,9 +13582,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds_FC="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_FC="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds_FC="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds_FC="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds_FC="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds_FC="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -17129,6 +17237,10 @@ if test -z "${BUILD_INFO_TRUE}" && test -z "${BUILD_INFO_FALSE}"; then + as_fn_error $? "conditional \"BUILD_INFO\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then + as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/libgomp/configure.ac b/libgomp/configure.ac +index dd88f20103a..5deba114027 100644 +--- a/libgomp/configure.ac ++++ b/libgomp/configure.ac +@@ -149,6 +149,7 @@ AM_PROG_LIBTOOL + ACX_LT_HOST_FLAGS + AC_SUBST(enable_shared) + AC_SUBST(enable_static) ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) + + AM_MAINTAINER_MODE + +diff --git a/libiberty/configure b/libiberty/configure +index 860f981fa18..b8a19c42110 100755 +--- a/libiberty/configure ++++ b/libiberty/configure +@@ -5258,8 +5258,8 @@ case "${enable_shared}" in + *) shared=yes ;; + esac + +-# ...unless --enable-host-shared was passed from top-level config: +-if [ "${enable_host_shared}" = "yes" ]; then ++# ...unless --enable-host-{shared,pie} was passed from top-level config: ++if [ "${enable_host_shared}" = "yes" ] || [ "${enable_host_pie}" = "yes" ]; then + shared=yes + fi + +diff --git a/libiberty/configure.ac b/libiberty/configure.ac +index 28d996f9cf7..6747a7b5cff 100644 +--- a/libiberty/configure.ac ++++ b/libiberty/configure.ac +@@ -233,8 +233,8 @@ case "${enable_shared}" in + *) shared=yes ;; + esac + +-# ...unless --enable-host-shared was passed from top-level config: +-if [[ "${enable_host_shared}" = "yes" ]]; then ++# ...unless --enable-host-{shared,pie} was passed from top-level config: ++if [[ "${enable_host_shared}" = "yes" ]] || [[ "${enable_host_pie}" = "yes" ]]; then + shared=yes + fi + +diff --git a/libitm/Makefile.am b/libitm/Makefile.am +index 3f31ad30556..a25317b07fe 100644 +--- a/libitm/Makefile.am ++++ b/libitm/Makefile.am +@@ -54,7 +54,12 @@ libitm_version_info = -version-info $(libtool_VERSION) + # want or need libstdc++. + libitm_la_DEPENDENCIES = $(libitm_version_dep) + libitm_la_LINK = $(LINK) $(libitm_la_LDFLAGS) +-libitm_la_LDFLAGS = $(libitm_version_info) $(libitm_version_script) ++if ENABLE_DARWIN_AT_RPATH ++libitm_darwin_rpath = -Wc,-nodefaultrpaths ++libitm_darwin_rpath += -Wl,-rpath,@loader_path ++endif ++libitm_la_LDFLAGS = $(libitm_version_info) $(libitm_version_script) \ ++ $(libitm_darwin_rpath) + + libitm_la_SOURCES = \ + aatree.cc alloc.cc alloc_c.cc alloc_cpp.cc barrier.cc beginend.cc \ +diff --git a/libitm/Makefile.in b/libitm/Makefile.in +index 7f53ea9b9db..ed28db45057 100644 +--- a/libitm/Makefile.in ++++ b/libitm/Makefile.in +@@ -481,7 +481,12 @@ libitm_version_info = -version-info $(libtool_VERSION) + # want or need libstdc++. + libitm_la_DEPENDENCIES = $(libitm_version_dep) + libitm_la_LINK = $(LINK) $(libitm_la_LDFLAGS) +-libitm_la_LDFLAGS = $(libitm_version_info) $(libitm_version_script) ++@ENABLE_DARWIN_AT_RPATH_TRUE@libitm_darwin_rpath = \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path ++libitm_la_LDFLAGS = $(libitm_version_info) $(libitm_version_script) \ ++ $(libitm_darwin_rpath) ++ + libitm_la_SOURCES = aatree.cc alloc.cc alloc_c.cc alloc_cpp.cc \ + barrier.cc beginend.cc clone.cc eh_cpp.cc local.cc query.cc \ + retry.cc rwlock.cc useraction.cc util.cc sjlj.S tls.cc \ +diff --git a/libitm/config/aarch64/sjlj.S b/libitm/config/aarch64/sjlj.S +index 0342516cdc8..2c27f46dc43 100644 +--- a/libitm/config/aarch64/sjlj.S ++++ b/libitm/config/aarch64/sjlj.S +@@ -57,10 +57,19 @@ + + .text + .align 2 ++#if __ELF__ + .global _ITM_beginTransaction + .type _ITM_beginTransaction, %function + + _ITM_beginTransaction: ++ ++#elif __MACH__ ++ .global __ITM_beginTransaction ++ ++__ITM_beginTransaction: ++ ++#endif ++ + cfi_startproc + CFI_PAC_KEY + PAC_AND_BTI +@@ -84,8 +93,13 @@ _ITM_beginTransaction: + + /* Invoke GTM_begin_transaction with the struct we just built. */ + mov x1, sp ++#if __ELF__ + bl GTM_begin_transaction +- ++#elif __MACH__ ++ bl _GTM_begin_transaction ++#else ++#error "unexpected object format" ++#endif + /* Return; we don't need to restore any of the call-saved regs. */ + ldp x29, x30, [sp], 11*16 + cfi_adjust_cfa_offset(-11*16) +@@ -95,14 +109,23 @@ _ITM_beginTransaction: + CFI_PAC_TOGGLE + ret + cfi_endproc ++#if __ELF__ + .size _ITM_beginTransaction, . - _ITM_beginTransaction ++#endif + + .align 2 ++#if __ELF__ + .global GTM_longjmp + .hidden GTM_longjmp + .type GTM_longjmp, %function + + GTM_longjmp: ++ ++#elif __MACH__ ++ .private_extern _GTM_longjmp ++ ++_GTM_longjmp: ++#endif + /* The first parameter becomes the return value (x0). + The third parameter is ignored for now. */ + cfi_startproc +@@ -126,7 +149,9 @@ GTM_longjmp: + CFI_PAC_TOGGLE + br x30 + cfi_endproc ++#if __ELF__ + .size GTM_longjmp, . - GTM_longjmp ++#endif + + /* GNU_PROPERTY_AARCH64_* macros from elf.h for use in asm code. */ + #define FEATURE_1_AND 0xc0000000 +diff --git a/libitm/configure b/libitm/configure +index 6230c04dd24..b941ecf83f9 100755 +--- a/libitm/configure ++++ b/libitm/configure +@@ -660,6 +660,8 @@ libtool_VERSION + MAINT + MAINTAINER_MODE_FALSE + MAINTAINER_MODE_TRUE ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + enable_static + enable_shared + CXXCPP +@@ -810,6 +812,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + enable_maintainer_mode + enable_linux_futex + enable_tls +@@ -1462,6 +1465,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --enable-maintainer-mode + enable make rules and dependencies not useful (and + sometimes confusing) to the casual installer +@@ -8283,7 +8289,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -10257,6 +10263,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -10274,9 +10323,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -12082,7 +12135,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12085 "configure" ++#line 12138 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -12188,7 +12241,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12191 "configure" ++#line 12244 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -13064,6 +13117,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc_CXX=no + hardcode_direct_CXX=no + hardcode_automatic_CXX=yes +@@ -13081,12 +13177,20 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + if test "$lt_cv_apple_cc_single_mod" != "yes"; then +- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring${_lt_dsymutil}" + archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" + fi + +@@ -15458,6 +15562,14 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5 +@@ -18216,6 +18328,10 @@ if test -z "${BUILD_INFO_TRUE}" && test -z "${BUILD_INFO_FALSE}"; then + as_fn_error $? "conditional \"BUILD_INFO\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then + as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/libitm/configure.ac b/libitm/configure.ac +index 050d6b23e18..d0d108e1737 100644 +--- a/libitm/configure.ac ++++ b/libitm/configure.ac +@@ -157,6 +157,7 @@ AM_CONDITIONAL(BUILD_INFO, test $gcc_cv_prog_makeinfo_modern = "yes") + AM_PROG_LIBTOOL + AC_SUBST(enable_shared) + AC_SUBST(enable_static) ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) + + AM_MAINTAINER_MODE + +diff --git a/libitm/configure.tgt b/libitm/configure.tgt +index 0362e61570a..2818a587ebf 100644 +--- a/libitm/configure.tgt ++++ b/libitm/configure.tgt +@@ -50,7 +50,7 @@ fi + # Map the target cpu to an ARCH sub-directory. At the same time, + # work out any special compilation flags as necessary. + case "${target_cpu}" in +- aarch64*) ARCH=aarch64 ;; ++ aarch64* | arm64*) ARCH=aarch64 ;; + alpha*) ARCH=alpha ;; + rs6000 | powerpc*) + XCFLAGS="${XCFLAGS} -mhtm" +diff --git a/libobjc/configure b/libobjc/configure +index 6da20b8e4ff..ce18c249b66 100755 +--- a/libobjc/configure ++++ b/libobjc/configure +@@ -636,6 +636,9 @@ OBJC_BOEHM_GC_LIBS + OBJC_BOEHM_GC_INCLUDES + OBJC_BOEHM_GC + OBJC_GCFLAGS ++extra_ldflags_libobjc ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + SET_MAKE + CPP + OTOOL64 +@@ -667,7 +670,6 @@ RANLIB + AR + AS + XCFLAGS +-extra_ldflags_libobjc + lt_host_flags + OBJEXT + EXEEXT +@@ -755,6 +757,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + enable_tls + enable_objc_gc + with_target_bdw_gc +@@ -1392,6 +1395,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --enable-tls Use thread-local storage [default=yes] + --enable-objc-gc enable use of Boehm's garbage collector with the GNU + Objective-C runtime +@@ -3431,17 +3437,6 @@ esac + + + +-case "${host}" in +- *-darwin*) +- # Darwin needs -single_module when linking libobjc +- extra_ldflags_libobjc='$(lt_host_flags) -Wl,-single_module' +- ;; +- *-cygwin*|*-mingw*) +- # Tell libtool to build DLLs on Windows +- extra_ldflags_libobjc='$(lt_host_flags)' +- ;; +-esac +- + + # Add CET specific flags if CET is enabled + +@@ -6973,7 +6968,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -8950,6 +8945,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -8967,9 +9005,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -10796,7 +10838,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 10799 "configure" ++#line 10841 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -10902,7 +10944,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 10905 "configure" ++#line 10947 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11174,6 +11216,38 @@ $as_echo "no" >&6; } + fi + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ ++ ++# Must come after libtool is initialized. ++case "${host}" in ++ *-darwin[4567]*) ++ # Earlier Darwin versions need -single_module when linking libobjc; they ++ # do not support @rpath. ++ extra_ldflags_libobjc='$(lt_host_flags) -Wl,-single_module' ++ ;; ++ *-darwin*) ++ # Otherwise, single_module is the default and multi-module is ignored and ++ # obsolete. ++ extra_ldflags_libobjc='$(lt_host_flags)' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ extra_ldflags_libobjc="${extra_ldflags_libobjc} -Wc,-nodefaultrpaths" ++ extra_ldflags_libobjc="${extra_ldflags_libobjc} -Wl,-rpath,@loader_path" ++ fi ++ ;; ++ *-cygwin*|*-mingw*) ++ # Tell libtool to build DLLs on Windows ++ extra_ldflags_libobjc='$(lt_host_flags)' ++ ;; ++esac ++ ++ + # ------- + # Headers + # ------- +@@ -11915,6 +11989,10 @@ if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then + as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + + : "${CONFIG_STATUS=./config.status}" + ac_write_fail=0 +diff --git a/libobjc/configure.ac b/libobjc/configure.ac +index 9bd7d59d597..cb21ebbfcc7 100644 +--- a/libobjc/configure.ac ++++ b/libobjc/configure.ac +@@ -148,17 +148,6 @@ m4_rename_force([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS]) + + # extra LD Flags which are required for targets + ACX_LT_HOST_FLAGS +-case "${host}" in +- *-darwin*) +- # Darwin needs -single_module when linking libobjc +- extra_ldflags_libobjc='$(lt_host_flags) -Wl,-single_module' +- ;; +- *-cygwin*|*-mingw*) +- # Tell libtool to build DLLs on Windows +- extra_ldflags_libobjc='$(lt_host_flags)' +- ;; +-esac +-AC_SUBST(extra_ldflags_libobjc) + + # Add CET specific flags if CET is enabled + GCC_CET_FLAGS(CET_FLAGS) +@@ -183,6 +172,31 @@ AM_PROG_CC_C_O + + AC_PROG_MAKE_SET + ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) ++ ++# Must come after libtool is initialized. ++case "${host}" in ++ *-darwin[[4567]]*) ++ # Earlier Darwin versions need -single_module when linking libobjc; they ++ # do not support @rpath. ++ extra_ldflags_libobjc='$(lt_host_flags) -Wl,-single_module' ++ ;; ++ *-darwin*) ++ # Otherwise, single_module is the default and multi-module is ignored and ++ # obsolete. ++ extra_ldflags_libobjc='$(lt_host_flags)' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ extra_ldflags_libobjc="${extra_ldflags_libobjc} -Wc,-nodefaultrpaths" ++ extra_ldflags_libobjc="${extra_ldflags_libobjc} -Wl,-rpath,@loader_path" ++ fi ++ ;; ++ *-cygwin*|*-mingw*) ++ # Tell libtool to build DLLs on Windows ++ extra_ldflags_libobjc='$(lt_host_flags)' ++ ;; ++esac ++AC_SUBST(extra_ldflags_libobjc) ++ + # ------- + # Headers + # ------- +diff --git a/libphobos/configure b/libphobos/configure +index 925c53c5f5e..2e8c06d4d48 100755 +--- a/libphobos/configure ++++ b/libphobos/configure +@@ -707,6 +707,8 @@ get_gcc_base_ver + phobos_compiler_shared_flag + phobos_compiler_pic_flag + phobos_lt_pic_flag ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + enable_static + enable_shared + OTOOL64 +@@ -838,6 +840,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + with_gcc_major_version_only + enable_werror + with_libatomic +@@ -1490,6 +1493,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --enable-werror turns on -Werror [default=no] + --enable-version-specific-runtime-libs + Specify that runtime libraries should be installed +@@ -8244,7 +8250,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -9949,6 +9955,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -9966,9 +10015,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -11774,7 +11827,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11777 "configure" ++#line 11830 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11880,7 +11933,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11883 "configure" ++#line 11936 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -13405,6 +13458,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc_D=no + hardcode_direct_D=no + hardcode_automatic_D=yes +@@ -13422,9 +13518,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds_D="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_D="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds_D="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds_D="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds_D="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds_D="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -14026,6 +14126,14 @@ CFLAGS=$lt_save_CFLAGS + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ + + # libtool variables for Phobos shared and position-independent compiles. + # +@@ -15750,6 +15858,10 @@ if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then + as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${DRUNTIME_CPU_AARCH64_TRUE}" && test -z "${DRUNTIME_CPU_AARCH64_FALSE}"; then + as_fn_error $? "conditional \"DRUNTIME_CPU_AARCH64\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/libphobos/configure.ac b/libphobos/configure.ac +index 464f4105430..ba8b5ecd65b 100644 +--- a/libphobos/configure.ac ++++ b/libphobos/configure.ac +@@ -93,6 +93,7 @@ AM_PROG_LIBTOOL + WITH_LOCAL_DRUNTIME([LT_LANG([D])], []) + AC_SUBST(enable_shared) + AC_SUBST(enable_static) ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) + + # libtool variables for Phobos shared and position-independent compiles. + # +diff --git a/libphobos/libdruntime/Makefile.am b/libphobos/libdruntime/Makefile.am +index 8225ba4a028..186948806d5 100644 +--- a/libphobos/libdruntime/Makefile.am ++++ b/libphobos/libdruntime/Makefile.am +@@ -128,8 +128,11 @@ ALL_DRUNTIME_SOURCES = $(DRUNTIME_DSOURCES) $(DRUNTIME_CSOURCES) \ + toolexeclib_LTLIBRARIES = libgdruntime.la + libgdruntime_la_SOURCES = $(ALL_DRUNTIME_SOURCES) + libgdruntime_la_LIBTOOLFLAGS = ++if ENABLE_DARWIN_AT_RPATH ++libgdruntime_darwin_rpath = -Wl,-rpath,@loader_path ++endif + libgdruntime_la_LDFLAGS = -Wc,-nophoboslib,-dstartfiles,-B../src,-Bgcc \ +- -version-info $(libtool_VERSION) ++ -version-info $(libtool_VERSION) $(libgdruntime_darwin_rpath) + libgdruntime_la_LIBADD = $(LIBATOMIC) $(LIBBACKTRACE) + libgdruntime_la_DEPENDENCIES = $(DRTSTUFF) + # Also override library link commands: This is not strictly +diff --git a/libphobos/libdruntime/Makefile.in b/libphobos/libdruntime/Makefile.in +index 797d6435a7c..cd13090010f 100644 +--- a/libphobos/libdruntime/Makefile.in ++++ b/libphobos/libdruntime/Makefile.in +@@ -810,8 +810,9 @@ ALL_DRUNTIME_SOURCES = $(DRUNTIME_DSOURCES) $(DRUNTIME_CSOURCES) \ + toolexeclib_LTLIBRARIES = libgdruntime.la + libgdruntime_la_SOURCES = $(ALL_DRUNTIME_SOURCES) + libgdruntime_la_LIBTOOLFLAGS = ++@ENABLE_DARWIN_AT_RPATH_TRUE@libgdruntime_darwin_rpath = -Wl,-rpath,@loader_path + libgdruntime_la_LDFLAGS = -Wc,-nophoboslib,-dstartfiles,-B../src,-Bgcc \ +- -version-info $(libtool_VERSION) ++ -version-info $(libtool_VERSION) $(libgdruntime_darwin_rpath) + + libgdruntime_la_LIBADD = $(LIBATOMIC) $(LIBBACKTRACE) + libgdruntime_la_DEPENDENCIES = $(DRTSTUFF) +diff --git a/libphobos/src/Makefile.am b/libphobos/src/Makefile.am +index 6474fca5eb5..f6521ed5860 100644 +--- a/libphobos/src/Makefile.am ++++ b/libphobos/src/Makefile.am +@@ -44,8 +44,11 @@ toolexeclib_DATA = libgphobos.spec + toolexeclib_LTLIBRARIES = libgphobos.la + libgphobos_la_SOURCES = $(ALL_PHOBOS_SOURCES) + libgphobos_la_LIBTOOLFLAGS = ++if ENABLE_DARWIN_AT_RPATH ++libgphobos_darwin_rpath = -Wl,-rpath,@loader_path ++endif + libgphobos_la_LDFLAGS = -Wc,-nophoboslib,-dstartfiles,-B../libdruntime/gcc \ +- -version-info $(libtool_VERSION) ++ -version-info $(libtool_VERSION) $(libgphobos_darwin_rpath) + if ENABLE_LIBDRUNTIME_ONLY + libgphobos_la_LIBADD = ../libdruntime/libgdruntime_convenience.la + else +diff --git a/libphobos/src/Makefile.in b/libphobos/src/Makefile.in +index a6229587e7b..cc3358b437e 100644 +--- a/libphobos/src/Makefile.in ++++ b/libphobos/src/Makefile.in +@@ -529,8 +529,9 @@ toolexeclib_DATA = libgphobos.spec + toolexeclib_LTLIBRARIES = libgphobos.la + libgphobos_la_SOURCES = $(ALL_PHOBOS_SOURCES) + libgphobos_la_LIBTOOLFLAGS = ++@ENABLE_DARWIN_AT_RPATH_TRUE@libgphobos_darwin_rpath = -Wl,-rpath,@loader_path + libgphobos_la_LDFLAGS = -Wc,-nophoboslib,-dstartfiles,-B../libdruntime/gcc \ +- -version-info $(libtool_VERSION) ++ -version-info $(libtool_VERSION) $(libgphobos_darwin_rpath) + + @ENABLE_LIBDRUNTIME_ONLY_FALSE@libgphobos_la_LIBADD = \ + @ENABLE_LIBDRUNTIME_ONLY_FALSE@ ../libdruntime/libgdruntime_convenience.la $(LIBZ) +diff --git a/libquadmath/Makefile.am b/libquadmath/Makefile.am +index 35dffb46f6e..f199adf4602 100644 +--- a/libquadmath/Makefile.am ++++ b/libquadmath/Makefile.am +@@ -36,8 +36,13 @@ endif + + toolexeclib_LTLIBRARIES = libquadmath.la + libquadmath_la_LIBADD = ++ ++if ENABLE_DARWIN_AT_RPATH ++libquadmath_darwin_rpath = -Wc,-nodefaultrpaths ++libquadmath_darwin_rpath += -Wl,-rpath,@loader_path ++endif + libquadmath_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ +- $(version_arg) $(lt_host_flags) -lm ++ $(version_arg) $(lt_host_flags) $(LIBM) $(libquadmath_darwin_rpath) + libquadmath_la_DEPENDENCIES = $(version_dep) $(libquadmath_la_LIBADD) + + nodist_libsubinclude_HEADERS = quadmath.h quadmath_weak.h +diff --git a/libquadmath/Makefile.in b/libquadmath/Makefile.in +index 8c011212258..70025758cd5 100644 +--- a/libquadmath/Makefile.in ++++ b/libquadmath/Makefile.in +@@ -355,6 +355,7 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ + INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ + LD = @LD@ + LDFLAGS = @LDFLAGS@ ++LIBM = @LIBM@ + LIBOBJS = @LIBOBJS@ + LIBS = @LIBS@ + LIBTOOL = @LIBTOOL@ +@@ -463,8 +464,10 @@ AUTOMAKE_OPTIONS = foreign info-in-builddir + @BUILD_LIBQUADMATH_TRUE@@LIBQUAD_USE_SYMVER_SUN_TRUE@@LIBQUAD_USE_SYMVER_TRUE@version_dep = quadmath.map-sun + @BUILD_LIBQUADMATH_TRUE@toolexeclib_LTLIBRARIES = libquadmath.la + @BUILD_LIBQUADMATH_TRUE@libquadmath_la_LIBADD = ++@BUILD_LIBQUADMATH_TRUE@@ENABLE_DARWIN_AT_RPATH_TRUE@libquadmath_darwin_rpath = -Wc,-nodefaultrpaths \ ++@BUILD_LIBQUADMATH_TRUE@@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path + @BUILD_LIBQUADMATH_TRUE@libquadmath_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ +-@BUILD_LIBQUADMATH_TRUE@ $(version_arg) $(lt_host_flags) -lm ++@BUILD_LIBQUADMATH_TRUE@ $(version_arg) $(lt_host_flags) $(LIBM) $(libquadmath_darwin_rpath) + + @BUILD_LIBQUADMATH_TRUE@libquadmath_la_DEPENDENCIES = $(version_dep) $(libquadmath_la_LIBADD) + @BUILD_LIBQUADMATH_TRUE@nodist_libsubinclude_HEADERS = quadmath.h quadmath_weak.h +diff --git a/libquadmath/configure b/libquadmath/configure +index 958fb876c5b..c51d4f3776c 100755 +--- a/libquadmath/configure ++++ b/libquadmath/configure +@@ -644,11 +644,14 @@ LIBQUAD_USE_SYMVER_GNU_FALSE + LIBQUAD_USE_SYMVER_GNU_TRUE + LIBQUAD_USE_SYMVER_FALSE + LIBQUAD_USE_SYMVER_TRUE ++LIBM + toolexeclibdir + toolexecdir + MAINT + MAINTAINER_MODE_FALSE + MAINTAINER_MODE_TRUE ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + enable_static + enable_shared + lt_host_flags +@@ -785,6 +788,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + enable_maintainer_mode + with_toolexeclibdir + enable_symvers +@@ -1435,6 +1439,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --enable-maintainer-mode + enable make rules and dependencies not useful (and + sometimes confusing) to the casual installer +@@ -7272,7 +7279,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -8984,6 +8991,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -9001,9 +9051,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -10830,7 +10884,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 10833 "configure" ++#line 10887 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -10936,7 +10990,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 10939 "configure" ++#line 10993 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11197,6 +11251,14 @@ esac + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5 +@@ -12161,6 +12223,20 @@ esac + + + ++# AC_CHECK_LIBM variant which avoids AC_CHECK_LIB (that doesn't work ++# on bare metal). In the past we've used -lm in Makefile.am unconditionally, ++# let's use it there unless target knows it doesn't need that. ++LIBM= ++case $host in ++*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-haiku* | *-*-pw32* | *-*-darwin*) ++ # These system don't have libm, or don't need it ++ ;; ++*) ++ LIBM=-lm ++ ;; ++esac ++ ++ + for ac_header in fenv.h langinfo.h locale.h wchar.h wctype.h limits.h ctype.h printf.h errno.h + do : + as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` +@@ -13421,6 +13497,10 @@ if test -z "${BUILD_INFO_TRUE}" && test -z "${BUILD_INFO_FALSE}"; then + as_fn_error $? "conditional \"BUILD_INFO\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then + as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/libquadmath/configure.ac b/libquadmath/configure.ac +index eec4084a45f..349be2607c6 100644 +--- a/libquadmath/configure.ac ++++ b/libquadmath/configure.ac +@@ -59,6 +59,7 @@ AM_PROG_LIBTOOL + ACX_LT_HOST_FLAGS + AC_SUBST(enable_shared) + AC_SUBST(enable_static) ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) + + AM_MAINTAINER_MODE + +@@ -121,6 +122,20 @@ esac + AC_SUBST(toolexecdir) + AC_SUBST(toolexeclibdir) + ++# AC_CHECK_LIBM variant which avoids AC_CHECK_LIB (that doesn't work ++# on bare metal). In the past we've used -lm in Makefile.am unconditionally, ++# let's use it there unless target knows it doesn't need that. ++LIBM= ++case $host in ++*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-haiku* | *-*-pw32* | *-*-darwin*) ++ # These system don't have libm, or don't need it ++ ;; ++*) ++ LIBM=-lm ++ ;; ++esac ++AC_SUBST([LIBM]) ++ + AC_CHECK_HEADERS(fenv.h langinfo.h locale.h wchar.h wctype.h limits.h ctype.h printf.h errno.h) + LIBQUAD_CHECK_MATH_H_SIGNGAM + +diff --git a/libsanitizer/asan/Makefile.am b/libsanitizer/asan/Makefile.am +index 4f802f723d6..223d3e07816 100644 +--- a/libsanitizer/asan/Makefile.am ++++ b/libsanitizer/asan/Makefile.am +@@ -60,7 +60,12 @@ libasan_la_LIBADD += $(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la + endif + libasan_la_LIBADD += $(LIBSTDCXX_RAW_CXX_LDFLAGS) + +-libasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libasan) ++if ENABLE_DARWIN_AT_RPATH ++libasan_darwin_rpath = -Wc,-nodefaultrpaths ++libasan_darwin_rpath += -Wl,-rpath,@loader_path ++endif ++libasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ ++ $(link_libasan) $(libasan_darwin_rpath) + + libasan_preinit.o: asan_preinit.o + cp $< $@ +diff --git a/libsanitizer/asan/Makefile.in b/libsanitizer/asan/Makefile.in +index 7833a9a4c3f..e88e5e0b0a7 100644 +--- a/libsanitizer/asan/Makefile.in ++++ b/libsanitizer/asan/Makefile.in +@@ -465,7 +465,12 @@ libasan_la_LIBADD = \ + $(top_builddir)/sanitizer_common/libsanitizer_common.la \ + $(top_builddir)/lsan/libsanitizer_lsan.la $(am__append_2) \ + $(am__append_3) $(LIBSTDCXX_RAW_CXX_LDFLAGS) +-libasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libasan) ++@ENABLE_DARWIN_AT_RPATH_TRUE@libasan_darwin_rpath = \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path ++libasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ ++ $(link_libasan) $(libasan_darwin_rpath) ++ + + # Work around what appears to be a GNU make bug handling MAKEFLAGS + # values defined in terms of make variables, as is the case for CC and +diff --git a/libsanitizer/configure b/libsanitizer/configure +index e7984f96615..dac83083e30 100755 +--- a/libsanitizer/configure ++++ b/libsanitizer/configure +@@ -666,6 +666,8 @@ LSAN_SUPPORTED_FALSE + LSAN_SUPPORTED_TRUE + TSAN_SUPPORTED_FALSE + TSAN_SUPPORTED_TRUE ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + enable_static + enable_shared + CXXCPP +@@ -817,6 +819,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + enable_werror + with_gcc_major_version_only + enable_cet +@@ -1471,6 +1474,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --disable-werror disable building with -Werror + --enable-cet enable Intel CET in target libraries [default=auto] + +@@ -8853,7 +8859,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -10558,6 +10564,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -10575,9 +10624,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -12383,7 +12436,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12386 "configure" ++#line 12439 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -12489,7 +12542,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12492 "configure" ++#line 12545 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -13365,6 +13418,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc_CXX=no + hardcode_direct_CXX=no + hardcode_automatic_CXX=yes +@@ -13382,12 +13478,20 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + if test "$lt_cv_apple_cc_single_mod" != "yes"; then +- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring${_lt_dsymutil}" + archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" + fi + +@@ -15807,6 +15911,15 @@ esac + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ ++ + # The cast to long int works around a bug in the HP C Compiler + # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects + # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. +@@ -17205,6 +17318,10 @@ if test -z "${am__fastdepCCAS_TRUE}" && test -z "${am__fastdepCCAS_FALSE}"; then + as_fn_error $? "conditional \"am__fastdepCCAS\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${TSAN_SUPPORTED_TRUE}" && test -z "${TSAN_SUPPORTED_FALSE}"; then + as_fn_error $? "conditional \"TSAN_SUPPORTED\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/libsanitizer/configure.ac b/libsanitizer/configure.ac +index 04cd8910ed6..5906c8d4887 100644 +--- a/libsanitizer/configure.ac ++++ b/libsanitizer/configure.ac +@@ -85,6 +85,8 @@ esac + AC_SUBST(enable_shared) + AC_SUBST(enable_static) + ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) ++ + AC_CHECK_SIZEOF([void *]) + + if test "${multilib}" = "yes"; then +diff --git a/libsanitizer/hwasan/Makefile.am b/libsanitizer/hwasan/Makefile.am +index 5a89189f6d8..11b1a9c5c57 100644 +--- a/libsanitizer/hwasan/Makefile.am ++++ b/libsanitizer/hwasan/Makefile.am +@@ -47,7 +47,11 @@ libhwasan_la_LIBADD += $(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la + endif + libhwasan_la_LIBADD += $(LIBSTDCXX_RAW_CXX_LDFLAGS) + +-libhwasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libhwasan) ++if ENABLE_DARWIN_AT_RPATH ++libhwasan_darwin_rpath = -nodefaultrpaths -Wl,-rpath,@loader_path/ ++endif ++libhwasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ ++ $(link_libhwasan) $(libhwasan_darwin_rpath) + + libhwasan_preinit.o: hwasan_preinit.o + cp $< $@ +diff --git a/libsanitizer/hwasan/Makefile.in b/libsanitizer/hwasan/Makefile.in +index 4240aa90147..f9ec8f9c177 100644 +--- a/libsanitizer/hwasan/Makefile.in ++++ b/libsanitizer/hwasan/Makefile.in +@@ -445,7 +445,10 @@ libhwasan_la_SOURCES = $(hwasan_files) + libhwasan_la_LIBADD = \ + $(top_builddir)/sanitizer_common/libsanitizer_common.la \ + $(am__append_1) $(am__append_2) $(LIBSTDCXX_RAW_CXX_LDFLAGS) +-libhwasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libhwasan) ++@ENABLE_DARWIN_AT_RPATH_TRUE@libhwasan_darwin_rpath = -nodefaultrpaths -Wl,-rpath,@loader_path/ ++libhwasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ ++ $(link_libhwasan) $(libhwasan_darwin_rpath) ++ + + # Work around what appears to be a GNU make bug handling MAKEFLAGS + # values defined in terms of make variables, as is the case for CC and +diff --git a/libsanitizer/lsan/Makefile.am b/libsanitizer/lsan/Makefile.am +index 6ff28ff5eea..7701b0e18cf 100644 +--- a/libsanitizer/lsan/Makefile.am ++++ b/libsanitizer/lsan/Makefile.am +@@ -41,8 +41,12 @@ if LIBBACKTRACE_SUPPORTED + liblsan_la_LIBADD += $(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la + endif + liblsan_la_LIBADD += $(LIBSTDCXX_RAW_CXX_LDFLAGS) +-liblsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_liblsan) +- ++if ENABLE_DARWIN_AT_RPATH ++liblsan_darwin_rpath = -Wc,-nodefaultrpaths ++liblsan_darwin_rpath += -Wl,-rpath,@loader_path ++endif ++liblsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ ++ $(link_liblsan) $(liblsan_darwin_rpath) + liblsan_preinit.o: lsan_preinit.o + cp $< $@ + +diff --git a/libsanitizer/lsan/Makefile.in b/libsanitizer/lsan/Makefile.in +index d8fd4ee9557..078edf01fda 100644 +--- a/libsanitizer/lsan/Makefile.in ++++ b/libsanitizer/lsan/Makefile.in +@@ -413,7 +413,12 @@ liblsan_la_LIBADD = \ + $(top_builddir)/sanitizer_common/libsanitizer_common.la \ + $(top_builddir)/interception/libinterception.la \ + $(am__append_1) $(LIBSTDCXX_RAW_CXX_LDFLAGS) +-liblsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_liblsan) ++@ENABLE_DARWIN_AT_RPATH_TRUE@liblsan_darwin_rpath = \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path ++liblsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ ++ $(link_liblsan) $(liblsan_darwin_rpath) ++ + + # Work around what appears to be a GNU make bug handling MAKEFLAGS + # values defined in terms of make variables, as is the case for CC and +@@ -788,7 +793,6 @@ uninstall-am: uninstall-nodist_toolexeclibHEADERS \ + + .PRECIOUS: Makefile + +- + liblsan_preinit.o: lsan_preinit.o + cp $< $@ + +diff --git a/libsanitizer/tsan/Makefile.am b/libsanitizer/tsan/Makefile.am +index da80743da9d..01290b0313d 100644 +--- a/libsanitizer/tsan/Makefile.am ++++ b/libsanitizer/tsan/Makefile.am +@@ -57,7 +57,11 @@ libtsan_la_LIBADD += $(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la + libtsan_la_DEPENDENCIES +=$(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la + endif + libtsan_la_LIBADD += $(LIBSTDCXX_RAW_CXX_LDFLAGS) +-libtsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libtsan) ++if ENABLE_DARWIN_AT_RPATH ++libtsan_darwin_rpath = -nodefaultrpaths -Wl,-rpath,@loader_path/ ++endif ++libtsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ ++ $(link_libtsan) $(libtsan_darwin_rpath) + + libtsan_preinit.o: tsan_preinit.o + cp $< $@ +diff --git a/libsanitizer/tsan/Makefile.in b/libsanitizer/tsan/Makefile.in +index 36498832bb8..95011584bcb 100644 +--- a/libsanitizer/tsan/Makefile.in ++++ b/libsanitizer/tsan/Makefile.in +@@ -464,7 +464,10 @@ libtsan_la_DEPENDENCIES = \ + $(top_builddir)/sanitizer_common/libsanitizer_common.la \ + $(top_builddir)/interception/libinterception.la \ + $(TSAN_TARGET_DEPENDENT_OBJECTS) $(am__append_2) +-libtsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libtsan) ++@ENABLE_DARWIN_AT_RPATH_TRUE@libtsan_darwin_rpath = -nodefaultrpaths -Wl,-rpath,@loader_path/ ++libtsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ ++ $(link_libtsan) $(libtsan_darwin_rpath) ++ + + # Work around what appears to be a GNU make bug handling MAKEFLAGS + # values defined in terms of make variables, as is the case for CC and +diff --git a/libsanitizer/ubsan/Makefile.am b/libsanitizer/ubsan/Makefile.am +index d480f26adc0..7769b3437e4 100644 +--- a/libsanitizer/ubsan/Makefile.am ++++ b/libsanitizer/ubsan/Makefile.am +@@ -36,7 +36,12 @@ if LIBBACKTRACE_SUPPORTED + libubsan_la_LIBADD += $(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la + endif + libubsan_la_LIBADD += $(LIBSTDCXX_RAW_CXX_LDFLAGS) +-libubsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libubsan) ++if ENABLE_DARWIN_AT_RPATH ++libubsan_darwin_rpath = -Wc,-nodefaultrpaths ++libubsan_darwin_rpath += -Wl,-rpath,@loader_path ++endif ++libubsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ ++ $(link_libubsan) $(libubsan_darwin_rpath) + + # Use special rules for files that require RTTI support. + ubsan_handlers_cxx.% ubsan_type_hash.% ubsan_type_hash_itanium.% : AM_CXXFLAGS += -frtti +diff --git a/libsanitizer/ubsan/Makefile.in b/libsanitizer/ubsan/Makefile.in +index 92a8e387fd7..7e51480e970 100644 +--- a/libsanitizer/ubsan/Makefile.in ++++ b/libsanitizer/ubsan/Makefile.in +@@ -400,7 +400,12 @@ libubsan_la_SOURCES = $(ubsan_files) + libubsan_la_LIBADD = \ + $(top_builddir)/sanitizer_common/libsanitizer_common.la \ + $(am__append_1) $(am__append_2) $(LIBSTDCXX_RAW_CXX_LDFLAGS) +-libubsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libubsan) ++@ENABLE_DARWIN_AT_RPATH_TRUE@libubsan_darwin_rpath = \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path ++libubsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ ++ $(link_libubsan) $(libubsan_darwin_rpath) ++ + + # Work around what appears to be a GNU make bug handling MAKEFLAGS + # values defined in terms of make variables, as is the case for CC and +diff --git a/libssp/Makefile.am b/libssp/Makefile.am +index 1636e43b369..f7ed2aa6043 100644 +--- a/libssp/Makefile.am ++++ b/libssp/Makefile.am +@@ -49,8 +49,12 @@ libssp_la_SOURCES = \ + vsnprintf-chk.c vsprintf-chk.c + libssp_la_LIBADD = + libssp_la_DEPENDENCIES = $(version_dep) $(libssp_la_LIBADD) ++if ENABLE_DARWIN_AT_RPATH ++libssp_darwin_rpath = -Wc,-nodefaultrpaths ++libssp_darwin_rpath += -Wl,-rpath,@loader_path ++endif + libssp_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ +- $(version_arg) $(lt_host_flags) ++ $(version_arg) $(lt_host_flags) $(libssp_darwin_rpath) + + libssp_nonshared_la_SOURCES = \ + ssp-local.c +diff --git a/libssp/Makefile.in b/libssp/Makefile.in +index bc8a0dc2b28..1cf86361b96 100644 +--- a/libssp/Makefile.in ++++ b/libssp/Makefile.in +@@ -376,8 +376,11 @@ libssp_la_SOURCES = \ + + libssp_la_LIBADD = + libssp_la_DEPENDENCIES = $(version_dep) $(libssp_la_LIBADD) ++@ENABLE_DARWIN_AT_RPATH_TRUE@libssp_darwin_rpath = \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path + libssp_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` \ +- $(version_arg) $(lt_host_flags) ++ $(version_arg) $(lt_host_flags) $(libssp_darwin_rpath) + + libssp_nonshared_la_SOURCES = \ + ssp-local.c +diff --git a/libssp/configure b/libssp/configure +index 492915d2ce0..72102be1742 100755 +--- a/libssp/configure ++++ b/libssp/configure +@@ -636,6 +636,8 @@ LIBOBJS + get_gcc_base_ver + toolexeclibdir + toolexecdir ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + enable_static + enable_shared + lt_host_flags +@@ -781,6 +783,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + with_toolexeclibdir + with_gcc_major_version_only + ' +@@ -1426,6 +1429,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + + Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] +@@ -7458,7 +7464,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -9170,6 +9176,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -9187,9 +9236,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -11016,7 +11069,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11019 "configure" ++#line 11072 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11122,7 +11175,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 11125 "configure" ++#line 11178 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11400,6 +11453,15 @@ fi + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ ++ + # Calculate toolexeclibdir + # Also toolexecdir, though it's only used in toolexeclibdir + case ${version_specific_libs} in +@@ -11609,6 +11671,10 @@ if test -z "${LIBSSP_USE_SYMVER_SUN_TRUE}" && test -z "${LIBSSP_USE_SYMVER_SUN_F + as_fn_error $? "conditional \"LIBSSP_USE_SYMVER_SUN\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + + : "${CONFIG_STATUS=./config.status}" + ac_write_fail=0 +diff --git a/libssp/configure.ac b/libssp/configure.ac +index f30f81c54f6..90778e2355d 100644 +--- a/libssp/configure.ac ++++ b/libssp/configure.ac +@@ -165,6 +165,8 @@ AC_SUBST(enable_static) + + GCC_WITH_TOOLEXECLIBDIR + ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) ++ + # Calculate toolexeclibdir + # Also toolexecdir, though it's only used in toolexeclibdir + case ${version_specific_libs} in +diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure +index d35baaf7c6e..4cac54b99c9 100755 +--- a/libstdc++-v3/configure ++++ b/libstdc++-v3/configure +@@ -791,6 +791,8 @@ glibcxx_compiler_pic_flag + glibcxx_lt_pic_flag + OS_IS_DARWIN_FALSE + OS_IS_DARWIN_TRUE ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + enable_static + enable_shared + lt_host_flags +@@ -926,6 +928,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + enable_hosted_libstdcxx + enable_libstdcxx_hosted + enable_libstdcxx_verbose +@@ -1617,6 +1620,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --disable-hosted-libstdcxx + only build freestanding C++ runtime support + --disable-libstdcxx-hosted +@@ -8503,7 +8509,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -10343,6 +10349,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -10360,9 +10409,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -12189,7 +12242,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12192 "configure" ++#line 12245 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -12295,7 +12348,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12298 "configure" ++#line 12351 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -13177,6 +13230,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc_CXX=no + hardcode_direct_CXX=no + hardcode_automatic_CXX=yes +@@ -13194,12 +13290,20 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + if test "$lt_cv_apple_cc_single_mod" != "yes"; then +- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring${_lt_dsymutil}" + archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" + fi + +@@ -15596,6 +15700,14 @@ esac + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ + + os_is_darwin=no + case ${host_os} in +@@ -16033,7 +16145,7 @@ $as_echo "$glibcxx_cv_atomic_long_long" >&6; } + # Fake what AC_TRY_COMPILE does. + + cat > conftest.$ac_ext << EOF +-#line 16036 "configure" ++#line 16148 "configure" + int main() + { + typedef bool atomic_type; +@@ -16068,7 +16180,7 @@ $as_echo "$glibcxx_cv_atomic_bool" >&6; } + rm -f conftest* + + cat > conftest.$ac_ext << EOF +-#line 16071 "configure" ++#line 16183 "configure" + int main() + { + typedef short atomic_type; +@@ -16103,7 +16215,7 @@ $as_echo "$glibcxx_cv_atomic_short" >&6; } + rm -f conftest* + + cat > conftest.$ac_ext << EOF +-#line 16106 "configure" ++#line 16218 "configure" + int main() + { + // NB: _Atomic_word not necessarily int. +@@ -16139,7 +16251,7 @@ $as_echo "$glibcxx_cv_atomic_int" >&6; } + rm -f conftest* + + cat > conftest.$ac_ext << EOF +-#line 16142 "configure" ++#line 16254 "configure" + int main() + { + typedef long long atomic_type; +@@ -16295,7 +16407,7 @@ $as_echo "mutex" >&6; } + # unnecessary for this test. + + cat > conftest.$ac_ext << EOF +-#line 16298 "configure" ++#line 16410 "configure" + int main() + { + _Decimal32 d1; +@@ -16337,7 +16449,7 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + # unnecessary for this test. + + cat > conftest.$ac_ext << EOF +-#line 16340 "configure" ++#line 16452 "configure" + template + struct same + { typedef T2 type; }; +@@ -73309,6 +73421,10 @@ if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then + as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${OS_IS_DARWIN_TRUE}" && test -z "${OS_IS_DARWIN_FALSE}"; then + as_fn_error $? "conditional \"OS_IS_DARWIN\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac +index 0c3c7a2c11c..6dde72ca566 100644 +--- a/libstdc++-v3/configure.ac ++++ b/libstdc++-v3/configure.ac +@@ -108,6 +108,7 @@ AM_PROG_LIBTOOL + ACX_LT_HOST_FLAGS + AC_SUBST(enable_shared) + AC_SUBST(enable_static) ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) + + os_is_darwin=no + case ${host_os} in +diff --git a/libstdc++-v3/src/Makefile.am b/libstdc++-v3/src/Makefile.am +index 5b9af41cdb9..925137c2ccc 100644 +--- a/libstdc++-v3/src/Makefile.am ++++ b/libstdc++-v3/src/Makefile.am +@@ -152,8 +152,13 @@ libstdc___la_DEPENDENCIES = \ + $(top_builddir)/src/c++17/libc++17convenience.la \ + $(top_builddir)/src/c++20/libc++20convenience.la + ++if ENABLE_DARWIN_AT_RPATH ++libstdc___darwin_rpath = -Wc,-nodefaultrpaths ++libstdc___darwin_rpath += -Wl,-rpath,@loader_path ++endif ++ + libstdc___la_LDFLAGS = \ +- -version-info $(libtool_VERSION) ${version_arg} -lm ++ -version-info $(libtool_VERSION) ${version_arg} -lm $(libstdc___darwin_rpath) + + libstdc___la_LINK = $(CXXLINK) $(libstdc___la_LDFLAGS) $(lt_host_flags) + +diff --git a/libstdc++-v3/src/Makefile.in b/libstdc++-v3/src/Makefile.in +index f42d957af36..0ce75f30708 100644 +--- a/libstdc++-v3/src/Makefile.in ++++ b/libstdc++-v3/src/Makefile.in +@@ -560,8 +560,11 @@ libstdc___la_DEPENDENCIES = \ + $(top_builddir)/src/c++17/libc++17convenience.la \ + $(top_builddir)/src/c++20/libc++20convenience.la + ++@ENABLE_DARWIN_AT_RPATH_TRUE@libstdc___darwin_rpath = \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ ++@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path + libstdc___la_LDFLAGS = \ +- -version-info $(libtool_VERSION) ${version_arg} -lm ++ -version-info $(libtool_VERSION) ${version_arg} -lm $(libstdc___darwin_rpath) + + libstdc___la_LINK = $(CXXLINK) $(libstdc___la_LDFLAGS) $(lt_host_flags) + @GLIBCXX_LDBL_ALT128_COMPAT_FALSE@@GLIBCXX_LDBL_COMPAT_TRUE@LTCXXCOMPILE64 = $(LTCXXCOMPILE) +diff --git a/libtool.m4 b/libtool.m4 +index b92e284d9f9..5361f2619cc 100644 +--- a/libtool.m4 ++++ b/libtool.m4 +@@ -1005,7 +1005,7 @@ _LT_EOF + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[[89]]*|UNSET,*-darwin[[12]][[0123456789]]*) ++ UNSET,*-darwin[[89]]*|UNSET,*-darwin[[12]][[0-9]]*) + ;; + 10.[[012]][[,.]]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -1039,6 +1039,45 @@ _LT_EOF + m4_defun([_LT_DARWIN_LINKER_FEATURES], + [ + m4_require([_LT_REQUIRED_DARWIN_CHECKS]) ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ AC_ARG_ENABLE([darwin-at-rpath], ++ AS_HELP_STRING([--enable-darwin-at-rpath], ++ [install libraries with @rpath/library-name, requires rpaths to be added to executables]), ++ [if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[[4-8]]*|UNSET,rhapsody*|10.[[0-4]][[,.]]*) ++ AC_MSG_WARN([Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)]) ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi], ++ [case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[[4-8]]*|UNSET,rhapsody*|10.[[0-4]][[,.]]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[[5-9]]*|UNSET,darwin2*|10.1[[1-9]][[,.]]*|1[[1-9]].*[[,.]]* ) ++ AC_MSG_NOTICE([@rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)]) ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ]) ++ + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_automatic, $1)=yes +@@ -1056,13 +1095,21 @@ m4_defun([_LT_DARWIN_LINKER_FEATURES], + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + m4_if([$1], [CXX], + [ if test "$lt_cv_apple_cc_single_mod" != "yes"; then +- _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring${_lt_dsymutil}" + _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" + fi + ],[]) +@@ -6466,7 +6513,6 @@ fi # test "$_lt_caught_CXX_error" != yes + AC_LANG_POP + ])# _LT_LANG_CXX_CONFIG + +- + # _LT_SYS_HIDDEN_LIBDEPS([TAGNAME]) + # --------------------------------- + # Figure out "hidden" library dependencies from verbose +diff --git a/libvtv/configure b/libvtv/configure +index e7e490d8b3e..da4fe61d0cf 100755 +--- a/libvtv/configure ++++ b/libvtv/configure +@@ -640,6 +640,8 @@ VTV_CYGMIN_FALSE + VTV_CYGMIN_TRUE + XCFLAGS + libtool_VERSION ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + enable_static + enable_shared + lt_host_flags +@@ -797,6 +799,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + enable_cet + with_gcc_major_version_only + ' +@@ -1446,6 +1449,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --enable-cet enable Intel CET in target libraries [default=auto] + + Optional Packages: +@@ -8748,7 +8754,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -10453,6 +10459,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -10470,9 +10519,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -12278,7 +12331,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12281 "configure" ++#line 12334 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -12384,7 +12437,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12387 "configure" ++#line 12440 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -13260,6 +13313,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc_CXX=no + hardcode_direct_CXX=no + hardcode_automatic_CXX=yes +@@ -13277,12 +13373,20 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds_CXX="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + if test "$lt_cv_apple_cc_single_mod" != "yes"; then +- archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring${_lt_dsymutil}" + archive_expsym_cmds_CXX="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" + fi + +@@ -15676,6 +15780,14 @@ esac + + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ + + # For libtool versioning info, format is CURRENT:REVISION:AGE + libtool_VERSION=1:0:0 +@@ -16021,6 +16133,10 @@ if test -z "${am__fastdepCXX_TRUE}" && test -z "${am__fastdepCXX_FALSE}"; then + as_fn_error $? "conditional \"am__fastdepCXX\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${VTV_CYGMIN_TRUE}" && test -z "${VTV_CYGMIN_FALSE}"; then + as_fn_error $? "conditional \"VTV_CYGMIN\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/libvtv/configure.ac b/libvtv/configure.ac +index f3b937e4b10..50aaadbb3a3 100644 +--- a/libvtv/configure.ac ++++ b/libvtv/configure.ac +@@ -153,6 +153,7 @@ AM_PROG_LIBTOOL + ACX_LT_HOST_FLAGS + AC_SUBST(enable_shared) + AC_SUBST(enable_static) ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) + + # For libtool versioning info, format is CURRENT:REVISION:AGE + libtool_VERSION=1:0:0 +diff --git a/lto-plugin/configure b/lto-plugin/configure +index d522bd24c95..c3b1b5fe0b5 100755 +--- a/lto-plugin/configure ++++ b/lto-plugin/configure +@@ -634,6 +634,8 @@ LTLIBOBJS + LIBOBJS + target_noncanonical + lt_host_flags ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + OTOOL64 + OTOOL + LIPO +@@ -786,6 +788,7 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + ' + ac_precious_vars='build_alias + host_alias +@@ -1431,6 +1434,9 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + + Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] +@@ -8603,7 +8609,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -10309,6 +10315,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -10326,9 +10375,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -12134,7 +12187,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12137 "configure" ++#line 12190 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -12240,7 +12293,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 12243 "configure" ++#line 12296 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -12477,6 +12530,14 @@ CC="$lt_save_CC" + # Only expand once: + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ + + + +@@ -12723,6 +12784,10 @@ if test -z "${LTO_PLUGIN_USE_SYMVER_SUN_TRUE}" && test -z "${LTO_PLUGIN_USE_SYMV + as_fn_error $? "conditional \"LTO_PLUGIN_USE_SYMVER_SUN\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + + : "${CONFIG_STATUS=./config.status}" + ac_write_fail=0 +diff --git a/lto-plugin/configure.ac b/lto-plugin/configure.ac +index 0a7202782ae..5812bbbfc08 100644 +--- a/lto-plugin/configure.ac ++++ b/lto-plugin/configure.ac +@@ -110,6 +110,7 @@ fi + AC_SUBST(ac_lto_plugin_extra_ldflags) + + AM_PROG_LIBTOOL ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) + ACX_LT_HOST_FLAGS + AC_SUBST(target_noncanonical) + AC_TYPE_INT64_T +diff --git a/zlib/Makefile.in b/zlib/Makefile.in +index 3f5102d1b87..80fe3b69116 100644 +--- a/zlib/Makefile.in ++++ b/zlib/Makefile.in +@@ -353,6 +353,8 @@ datadir = @datadir@ + datarootdir = @datarootdir@ + docdir = @docdir@ + dvidir = @dvidir@ ++enable_host_pie = @enable_host_pie@ ++enable_host_shared = @enable_host_shared@ + exec_prefix = @exec_prefix@ + host = @host@ + host_alias = @host_alias@ +diff --git a/zlib/configure b/zlib/configure +index e35ac6e7e17..a7673a840ab 100755 +--- a/zlib/configure ++++ b/zlib/configure +@@ -635,10 +635,14 @@ am__EXEEXT_TRUE + LTLIBOBJS + LIBOBJS + PICFLAG ++enable_host_pie ++enable_host_shared + TARGET_LIBRARY_FALSE + TARGET_LIBRARY_TRUE + toolexeclibdir + toolexecdir ++ENABLE_DARWIN_AT_RPATH_FALSE ++ENABLE_DARWIN_AT_RPATH_TRUE + CPP + OTOOL64 + OTOOL +@@ -776,8 +780,10 @@ with_pic + enable_fast_install + with_gnu_ld + enable_libtool_lock ++enable_darwin_at_rpath + with_toolexeclibdir + enable_host_shared ++enable_host_pie + ' + ac_precious_vars='build_alias + host_alias +@@ -1419,7 +1425,11 @@ Optional Features: + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) ++ --enable-darwin-at-rpath ++ install libraries with @rpath/library-name, requires ++ rpaths to be added to executables + --enable-host-shared build host code as shared libraries ++ --enable-host-pie build host code as PIE + + Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] +@@ -6934,7 +6944,7 @@ $as_echo "$lt_cv_ld_force_load" >&6; } + # darwin 5.x (macOS 10.1) onwards we only need to adjust when the + # deployment target is forced to an earlier version. + case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host in +- UNSET,*-darwin[89]*|UNSET,*-darwin[12][0123456789]*) ++ UNSET,*-darwin[89]*|UNSET,*-darwin[12][0-9]*) + ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' +@@ -8913,6 +8923,49 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + darwin* | rhapsody*) + + ++ ++ # Publish an arg to allow the user to select that Darwin host (and target) ++ # libraries should be given install-names like @rpath/libfoo.dylib. This ++ # requires that the user of the library then adds an 'rpath' to the DSO that ++ # needs access. ++ # NOTE: there are defaults below, for systems that support rpaths. The person ++ # configuring can override the defaults for any system version that supports ++ # them - they are, however, forced off for system versions without support. ++ # Check whether --enable-darwin-at-rpath was given. ++if test "${enable_darwin_at_rpath+set}" = set; then : ++ enableval=$enable_darwin_at_rpath; if test "x$enable_darwin_at_rpath" = "xyes"; then ++ # This is not supported before macOS 10.5 / Darwin9. ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&5 ++$as_echo "$as_me: WARNING: Darwin @rpath library names are incompatible with OSX versions earlier than 10.5 (rpaths disabled)" >&2;} ++ enable_darwin_at_rpath=no ++ ;; ++ esac ++ fi ++else ++ case ${MACOSX_DEPLOYMENT_TARGET-UNSET},$host_os in ++ # As above, before 10.5 / Darwin9 this does not work. ++ UNSET,darwin[4-8]*|UNSET,rhapsody*|10.[0-4][,.]*) ++ enable_darwin_at_rpath=no ++ ;; ++ ++ # We cannot build and test reliably on macOS 10.11+ (Darwin15+) without use ++ # of rpaths, since runpaths set via DYLD_LIBRARY_PATH are elided by key ++ # system executables (e.g. /bin/sh). Force rpaths on for these systems. ++ UNSET,darwin1[5-9]*|UNSET,darwin2*|10.1[1-9][,.]*|1[1-9].*[,.]* ) ++ { $as_echo "$as_me:${as_lineno-$LINENO}: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&5 ++$as_echo "$as_me: @rpath library names are needed on macOS versions later than 10.11 (rpaths have been enabled)" >&6;} ++ enable_darwin_at_rpath=yes ++ ;; ++ # NOTE: we are not (yet) doing anything for 10.5 .. 10.10, since they can ++ # work with either DYLD_LIBRARY_PATH or embedded rpaths. ++ ++ esac ++ ++fi ++ ++ + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes +@@ -8930,9 +8983,13 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=func_echo_all +- archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" ++ _lt_install_name='\$rpath/\$soname' ++ if test "x$enable_darwin_at_rpath" = "xyes"; then ++ _lt_install_name='@rpath/\$soname' ++ fi ++ archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" +- archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" ++ archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name ${_lt_install_name} \$verstring ${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else +@@ -10759,7 +10816,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 10762 "configure" ++#line 10819 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -10865,7 +10922,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 10868 "configure" ++#line 10925 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -11102,6 +11159,14 @@ CC="$lt_save_CC" + # Only expand once: + + ++ if test x$enable_darwin_at_rpath = xyes; then ++ ENABLE_DARWIN_AT_RPATH_TRUE= ++ ENABLE_DARWIN_AT_RPATH_FALSE='#' ++else ++ ENABLE_DARWIN_AT_RPATH_TRUE='#' ++ ENABLE_DARWIN_AT_RPATH_FALSE= ++fi ++ + + # Find CPP now so that any conditional tests below won't do it and + # thereby make the resulting definitions conditional. +@@ -11548,15 +11613,31 @@ else + multilib_arg= + fi + ++# Enable --enable-host-shared. + # Check whether --enable-host-shared was given. + if test "${enable_host_shared+set}" = set; then : +- enableval=$enable_host_shared; PICFLAG=-fPIC ++ enableval=$enable_host_shared; ++fi ++ ++ ++ ++# Enable --enable-host-pie. ++# Check whether --enable-host-pie was given. ++if test "${enable_host_pie+set}" = set; then : ++ enableval=$enable_host_pie; ++fi ++ ++ ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE + else + PICFLAG= + fi + + +- + ac_config_files="$ac_config_files Makefile" + + cat >confcache <<\_ACEOF +@@ -11732,6 +11813,10 @@ if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then + as_fn_error $? "conditional \"am__fastdepCC\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 + fi ++if test -z "${ENABLE_DARWIN_AT_RPATH_TRUE}" && test -z "${ENABLE_DARWIN_AT_RPATH_FALSE}"; then ++ as_fn_error $? "conditional \"ENABLE_DARWIN_AT_RPATH\" was never defined. ++Usually this means the macro was only invoked conditionally." "$LINENO" 5 ++fi + if test -z "${TARGET_LIBRARY_TRUE}" && test -z "${TARGET_LIBRARY_FALSE}"; then + as_fn_error $? "conditional \"TARGET_LIBRARY\" was never defined. + Usually this means the macro was only invoked conditionally." "$LINENO" 5 +diff --git a/zlib/configure.ac b/zlib/configure.ac +index be1cfe29651..9501cdfea85 100644 +--- a/zlib/configure.ac ++++ b/zlib/configure.ac +@@ -64,6 +64,7 @@ GCC_CET_FLAGS(CET_FLAGS) + AC_SUBST(CET_FLAGS) + + AC_PROG_LIBTOOL ++AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = xyes]) + + # Find CPP now so that any conditional tests below won't do it and + # thereby make the resulting definitions conditional. +@@ -122,11 +123,26 @@ else + multilib_arg= + fi + ++# Enable --enable-host-shared. + AC_ARG_ENABLE(host-shared, + [AS_HELP_STRING([--enable-host-shared], +- [build host code as shared libraries])], +-[PICFLAG=-fPIC], [PICFLAG=]) +-AC_SUBST(PICFLAG) ++ [build host code as shared libraries])]) ++AC_SUBST(enable_host_shared) ++ ++# Enable --enable-host-pie. ++AC_ARG_ENABLE(host-pie, ++[AS_HELP_STRING([--enable-host-pie], ++ [build host code as PIE])]) ++AC_SUBST(enable_host_pie) ++ ++if test x$enable_host_shared = xyes; then ++ PICFLAG=-fPIC ++elif test x$enable_host_pie = xyes; then ++ PICFLAG=-fPIE ++else ++ PICFLAG= ++fi + ++AC_SUBST(PICFLAG) + AC_CONFIG_FILES([Makefile]) + AC_OUTPUT diff --git a/10.9-libcxx/stable/main/finkinfo/languages/gcc14-13.0.info b/10.9-libcxx/stable/main/finkinfo/languages/gcc14-13.0.info new file mode 100644 index 00000000000..826bd978ff0 --- /dev/null +++ b/10.9-libcxx/stable/main/finkinfo/languages/gcc14-13.0.info @@ -0,0 +1,318 @@ +Info2: << +Package: gcc14 +Version: 14.2.0 +Revision: 2 +Type: gccver (14) +Distribution: 13.0 +Source: mirror:gnu:gcc/gcc-%v/gcc-%v.tar.xz +Source-Checksum: SHA256(a7b39bc69cbf9e25826c5a60ab26477001f7c08d85cec04bc0e29cabed6f3cc9) +PatchFile: %n.patch +PatchFile-MD5: fafea628b0211ed3d4e4528deb0c2842 +PatchScript: << + #!/bin/sh -ev + patch -p1 < %{PatchFile} + # don't update live infodoc dir + find . -name Makefile.in | xargs perl -pi -e 's/install-info --version/false/g' +<< +NoSetCPPFLAGS: True +NoSetLDFLAGS: True +UseMaxBuildJobs: True +Conflicts: << + gcc5, gcc6, gcc7, gcc8, + gcc9, + gcc10, + gcc11, + gcc12, + gcc13, + gcc14 +<< +Replaces: << + gcc5, gcc6, gcc7, gcc8, + gcc9, + gcc10, + gcc11, + gcc12, + gcc13, + gcc14 +<< +Depends: << + %N-compiler (= %v-%r) +<< +BuildDepends: << + fink (>= 0.32), + fink-package-precedence, + gettext-tools, + gmp5 (>= 6.1.2-1), + install-info, + isl22, + libgettext8-dev, + libiconv-dev, + libmpc3 (>= 1.0.3-1), + libmpfr6, + x11-dev +<< +ConfigureParams: << + --prefix=%p/lib/gcc%type_num[gccver] \ + --mandir=%p/share/man \ + --infodir=%p/lib/gcc%type_num[gccver]/info \ + --enable-languages=c,c++,fortran,lto,objc,obj-c++ \ + --with-gmp=%p \ + --with-libiconv-prefix=%p \ + --with-isl=%p \ + --with-mpc=%p \ + --with-system-zlib \ + --program-suffix=-fsf-%type_num[gccver] \ + --disable-multilib \ + --enable-stage1-checking \ + ${USE_SYSROOT} \ + --with-pkgversion="Fink %n %v-%r" \ + --with-bugurl="https://github.com/fink/fink-distributions/issues" +<< +InfoTest: << + TestDepends: << + autogen, + dejagnu, + ( "%m" != "arm64" ) apple-gdb + << + TestScript: << + #!/bin/bash -ev + if [ "%m" = "arm64" ]; then + echo "The gcc testsuite requires Apple's gdb, which is not available on this architecture." + exit 0 + elif [ $UID = 0 ]; then + if [ -e /usr/bin/csrutil && `csrutil status | grep -c disabled` ]; then + cd ../darwin_objdir; make -k check RUNTESTFLAGS="--target_board=unix'{-m64}'" || : + else + echo "The gcc testsuite must be run with SIP disabled or package installed." + exit 0 + fi + else + echo "The gcc testsuite must be run as root due to its use of gdb." + exit 0 + fi + << +<< +InfoDocs: gcc.info gfortran.info cpp.info gccinstall.info libgomp.info cppinternals.info gccint.info +CompileScript: << + #!/bin/bash -ev + set +x + if [ -e /usr/local/lib/libgmp.a ] || [ -e /usr/local/lib/libgmp.dylib ]; then + echo "-----WARNING-----WARNING-----WARNING-----" + echo "You seem to have GMP installed in /usr/local." + echo "This is known to cause %N to fail to build." + echo "Please move aside /usr/local and try again." + echo "-----WARNING-----WARNING-----WARNING-----" + exit 1 + else + echo "Good, /usr/local/lib/libgmp* not present." + fi + set -x + ulimit -s `ulimit -s` + mkdir ../darwin_objdir + cd ../darwin_objdir + # build doesn't play well with GNU-make + # unsupported option '-static-libgcc' + export MAKE=/usr/bin/make + export target_configargs='--with-libiconv-prefix=%p' + # Only need sysroot on 10.14+ because /usr/include has been removed + OSX_MAJOR_VERSION=`sw_vers -productVersion | cut -d. -f1-2` + if dpkg --compare-versions "$OSX_MAJOR_VERSION" ge "10.14"; then + # Get the unversioned SDK path + SDK_PATH=`dirname $(xcrun --sdk macosx --show-sdk-path)`/MacOSX.sdk + # This should really be --with-build-sysroot but that's not getting propagated through the entire build process. + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79885 + export USE_SYSROOT="--with-sysroot=${SDK_PATH}" + fi + # check for incompatible clang ( 6.0 << bad-clang << 7.2) + clangvers=`clang --version | cut -d\ -f4` + $(`dpkg --compare-versions $clangvers '>>' 6.0`) && $(`dpkg --compare-versions $clangvers '<<' 7.2`) && clangcheck='y' + if [ "$clangcheck" = "y" ]; then + ../gcc-%v/configure %c --with-build-config=bootstrap-debug + else + ../gcc-%v/configure %c + fi + # Use bootstrap-lean to reduce disk usage. + # Note that this causes plugin testsuite failures + # since the plugin headers must come from prev-gcc. + # make bootstrap-lean + make bootstrap + fink-package-precedence --prohibit-bdep=%n . +<< +InstallScript: << + #!/bin/sh -ev + darwinvers=`uname -r` + cd ../darwin_objdir + make -j 1 install DESTDIR=%d + mkdir -p %i/bin + + # Add symlinks to recreate previous naming of executables in %p/bin + # as well as %p/lib/gcc%type_num[gccver]/bin and new -fsf-%type_num[gccver] naming in %p/bin. + binfiles="gcc g++ c++ cpp gcov" + for binfile in $binfiles ; do + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/$binfile-%type_num[gccver] + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-%type_num[gccver] + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-fsf-%type_num[gccver] + done + binfiles="gfortran" + for binfile in $binfiles ; do + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/$binfile + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-fsf-%type_num[gccver] + done + + # Remove unsupported executables + binfiles="gcc-ar gcc-nm gcc-ranlib" + for binfile in $binfiles ; do + rm -f %i/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/*-apple-darwin${darwinvers}-$binfile-fsf-%type_num[gccver] + done + + # Add symlinks for manpages under old names. + man1files="cpp g++ gcc gcov" + for man1file in $man1files ; do + ln -s $man1file-fsf-%type_num[gccver].1 %i/share/man/man1/$man1file-%type_num[gccver].1 + done + man1files="gfortran" + for man1file in $man1files ; do + ln -s $man1file-fsf-%type_num[gccver].1 %i/share/man/man1/$man1file.1 + done + + # Rename manpages with -fsf-%type_num[gccver] suffix and create symlinks to old names. + man7files="fsf-funding gfdl gpl" + for man7file in $man7files ; do + mv %i/share/man/man7/$man7file.7 %i/share/man/man7/$man7file-fsf-%type_num[gccver].7 + ln -s $man7file-fsf-%type_num[gccver].7 %i/share/man/man7/$man7file.7 + done + + # Add dir for installed info files, and link them to %i/share/info. + # the %i/lib/gcc%type_num[gccver]/info/* files will go into the -compiler package + # and the files in %i/share/info go into the main package, this allows + # the info files for specific compiler versions to be accessed with + # e.g. `info -d /fink_install_dir/lib/gcc%type_num[gccver]/info gcc', but the "main" info files will + # be available for the install gccXX package in %p/share/info, as usual + install -d -m 755 %i/share/info + for infofile in $(find %i/lib/gcc%type_num[gccver]/info -name '*.info*'); do + infobase=$(basename $infofile) + case $infofile in + *info) %p/bin/install-info --infodir=%i/lib/gcc%type_num[gccver]/info ${infofile} ;; + esac + ln -s %p/lib/gcc%type_num[gccver]/info/$infobase %i/share/info/$infobase + done + + # remove build path from .la files + perl -pi -e "s, \-L[^ ']*/%n-%v-%r/darwin_objdir/[^ ']*,,g" `find %i/lib/gcc%type_num[gccver]/lib -name '*.la'` + if [ "%m" = "arm64" ]; then + arch=aarch64 + else + arch=%m + fi + + # @rpath install_names are required for aarch64 build, but break some linked binaries + # - enforce actual install paths here; take care to update the cross-referenced dylibs. + cd %d + for dylib in .%p/lib/gcc%type_num[gccver]/lib/lib*.[0-9].dylib; do + install_name_tool -id ${dylib#.} $dylib + install_name_tool -change @rpath/libgcc_s.1.1.dylib %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib \ + -change @rpath/libstdc++.6.dylib %p/lib/gcc%type_num[gccver]/lib/libstdc++.6.dylib \ + -change @rpath/libquadmath.0.dylib %p/lib/gcc%type_num[gccver]/lib/libquadmath.0.dylib $dylib + done + otool -L .%p/lib/gcc%type_num[gccver]/lib/lib*.[0-9].dylib | grep '@rpath' && exit 2 + + cp %b/gcc/config/darwin-sections.def %i/lib/gcc%type_num[gccver]/lib/gcc/${arch}-apple-darwin${darwinvers}/%v/plugin/include/config +<< +SplitOff: << + Package: %N-shlibs + Replaces: << + gcc4 (<= 20050130-4), + gfortran-shlibs + << + Provides: << + gfortran-shlibs + << + Description: Shared libraries for %N + DocFiles: gcc/COPYING gcc/COPYING.LIB + Files: << + lib/gcc%type_num[gccver]/lib/libgfortran.5*.dylib + lib/gcc%type_num[gccver]/lib/libstdc++.6*.dylib + lib/gcc%type_num[gccver]/lib/libgcc_s.1*.dylib + lib/gcc%type_num[gccver]/lib/libitm.1*.dylib + lib/gcc%type_num[gccver]/lib/libssp.0*.dylib + lib/gcc%type_num[gccver]/lib/libobjc-gnu.4*.dylib + lib/gcc%type_num[gccver]/lib/libgomp.1*.dylib + lib/gcc%type_num[gccver]/lib/libquadmath.0*.dylib + lib/gcc%type_num[gccver]/lib/libatomic.1*.dylib + << + Shlibs: << + %p/lib/gcc%type_num[gccver]/lib/libgfortran.5.dylib 6.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libstdc++.6.dylib 7.0.0 %n (>= 14.1.0-1) + ( "%m" = "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib 1.0.0 %n (>= 14.1.0-1) + ( "%m" != "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.dylib 1.0.0 %n (>= 14.1.0-1) + ( "%m" != "arm64" ) !%p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib + %p/lib/gcc%type_num[gccver]/lib/libitm.1.dylib 2.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libssp.0.dylib 1.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libobjc-gnu.4.dylib 5.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libgomp.1.dylib 2.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libquadmath.0.dylib 1.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libatomic.1.dylib 4.0.0 %n (>= 14.1.0-1) + << +<< +SplitOff2: << + Package: %N-compiler + Depends: << + gmp5-shlibs (>= 6.1.2-1), + isl22-shlibs, + libgettext8-shlibs, + libgmpxx5-shlibs (>= 6.1.2-1), + libiconv, + libmpc3-shlibs (>= 1.0.3-1), + libmpfr6-shlibs, + %N-shlibs (= %v-%r) + << + BuildDependsOnly: False + Description: Compiler Binaries for gcc%type_num[gccver] + DocFiles: gcc/COPYING gcc/COPYING.LIB gcc/ChangeLog gcc/ABOUT-GCC-NLS gcc/README.Portability + Files: << + bin/*-fsf-%type_num[gccver] + lib/gcc%type_num[gccver] + share/man/man1/*-fsf-%type_num[gccver].1 + share/man/man7/*-fsf-%type_num[gccver].7 + << +<< +License: GPL +Description: GNU Compiler Collection Version %type_num[gccver] +DescDetail: << + GCC, the GNU Compiler Collection, includes front ends for + C, C++, Objective-C, Objective-C++, Fortran and Ada. + . + C, C++, Objective C and Fortran are included in this package. + . + The C and C++ compilers are named gcc-14 and g++-14 to avoid + conflicts with gcc and g++ installed by the Apple Developer Tools. +<< +DescPackaging: << + Build with -fsf-%type_num[gccver] suffix and place non-overlapping files into new gcc%type_num[gccver]-compiler + package which can co-exist with other gccXX-compiler packages. Overlapping files + are left in main gcc%type_num[gccver] package which still conflicts with other gccXX packages. + + macOS10.14 no longer supports building 32bit libraries, so must disable multilib. + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87030 + + We use --with-sysroot to find the hidden system-headers in case /usr/include is not + populated. Ideally want --with-build-sysroot because we only need the headers to build + gcc and that should not impact the end product, but then anything using gccX will + need to add it's own -isysroot flag. + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79885 + + Homebrew patches for arm64/aarch64 build and macOS 13+ from + https://github.com/Homebrew/formula-patches/blob/master/gcc/gcc-%v-r2.diff + - libasan.* and libsubsan.* currently not built on darwin22+ or arm64 - see + https://github.com/iains/gcc-darwin-arm64/commit/e722a1f4 + and missing from the 13.0-15.0 packages until resolved. + There are both "1" and "1.1" versions of libgcc_s.dylib now, but only "1.1" on arm64. + Manual fixes of @rpath install_names required for aarch64 build to maintain downstream + package compatibility. + Added `target_configargs` variable since for some reason libiconv prefix is not passed + down to libstdc++ config any more (https://github.com/iains/gcc-darwin-arm64/issues/129). +<< +Homepage: http://gcc.gnu.org/ +Maintainer: None +<< diff --git a/10.9-libcxx/stable/main/finkinfo/languages/gcc14-14.0.info b/10.9-libcxx/stable/main/finkinfo/languages/gcc14-14.0.info new file mode 100644 index 00000000000..645055db9df --- /dev/null +++ b/10.9-libcxx/stable/main/finkinfo/languages/gcc14-14.0.info @@ -0,0 +1,318 @@ +Info2: << +Package: gcc14 +Version: 14.2.0 +Revision: 2 +Type: gccver (14) +Distribution: 14.0 +Source: mirror:gnu:gcc/gcc-%v/gcc-%v.tar.xz +Source-Checksum: SHA256(a7b39bc69cbf9e25826c5a60ab26477001f7c08d85cec04bc0e29cabed6f3cc9) +PatchFile: %n.patch +PatchFile-MD5: fafea628b0211ed3d4e4528deb0c2842 +PatchScript: << + #!/bin/sh -ev + patch -p1 < %{PatchFile} + # don't update live infodoc dir + find . -name Makefile.in | xargs perl -pi -e 's/install-info --version/false/g' +<< +NoSetCPPFLAGS: True +NoSetLDFLAGS: True +UseMaxBuildJobs: True +Conflicts: << + gcc5, gcc6, gcc7, gcc8, + gcc9, + gcc10, + gcc11, + gcc12, + gcc13, + gcc14 +<< +Replaces: << + gcc5, gcc6, gcc7, gcc8, + gcc9, + gcc10, + gcc11, + gcc12, + gcc13, + gcc14 +<< +Depends: << + %N-compiler (= %v-%r) +<< +BuildDepends: << + fink (>= 0.32), + fink-package-precedence, + gettext-tools, + gmp5 (>= 6.1.2-1), + install-info, + isl22, + libgettext8-dev, + libiconv-dev, + libmpc3 (>= 1.0.3-1), + libmpfr6, + x11-dev +<< +ConfigureParams: << + --prefix=%p/lib/gcc%type_num[gccver] \ + --mandir=%p/share/man \ + --infodir=%p/lib/gcc%type_num[gccver]/info \ + --enable-languages=c,c++,fortran,lto,objc,obj-c++ \ + --with-gmp=%p \ + --with-libiconv-prefix=%p \ + --with-isl=%p \ + --with-mpc=%p \ + --with-system-zlib \ + --program-suffix=-fsf-%type_num[gccver] \ + --disable-multilib \ + --enable-stage1-checking \ + ${USE_SYSROOT} \ + --with-pkgversion="Fink %n %v-%r" \ + --with-bugurl="https://github.com/fink/fink-distributions/issues" +<< +InfoTest: << + TestDepends: << + autogen, + dejagnu, + ( "%m" != "arm64" ) apple-gdb + << + TestScript: << + #!/bin/bash -ev + if [ "%m" = "arm64" ]; then + echo "The gcc testsuite requires Apple's gdb, which is not available on this architecture." + exit 0 + elif [ $UID = 0 ]; then + if [ -e /usr/bin/csrutil && `csrutil status | grep -c disabled` ]; then + cd ../darwin_objdir; make -k check RUNTESTFLAGS="--target_board=unix'{-m64}'" || : + else + echo "The gcc testsuite must be run with SIP disabled or package installed." + exit 0 + fi + else + echo "The gcc testsuite must be run as root due to its use of gdb." + exit 0 + fi + << +<< +InfoDocs: gcc.info gfortran.info cpp.info gccinstall.info libgomp.info cppinternals.info gccint.info +CompileScript: << + #!/bin/bash -ev + set +x + if [ -e /usr/local/lib/libgmp.a ] || [ -e /usr/local/lib/libgmp.dylib ]; then + echo "-----WARNING-----WARNING-----WARNING-----" + echo "You seem to have GMP installed in /usr/local." + echo "This is known to cause %N to fail to build." + echo "Please move aside /usr/local and try again." + echo "-----WARNING-----WARNING-----WARNING-----" + exit 1 + else + echo "Good, /usr/local/lib/libgmp* not present." + fi + set -x + ulimit -s `ulimit -s` + mkdir ../darwin_objdir + cd ../darwin_objdir + # build doesn't play well with GNU-make + # unsupported option '-static-libgcc' + export MAKE=/usr/bin/make + export target_configargs='--with-libiconv-prefix=%p' + # Only need sysroot on 10.14+ because /usr/include has been removed + OSX_MAJOR_VERSION=`sw_vers -productVersion | cut -d. -f1-2` + if dpkg --compare-versions "$OSX_MAJOR_VERSION" ge "10.14"; then + # Get the unversioned SDK path + SDK_PATH=`dirname $(xcrun --sdk macosx --show-sdk-path)`/MacOSX.sdk + # This should really be --with-build-sysroot but that's not getting propagated through the entire build process. + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79885 + export USE_SYSROOT="--with-sysroot=${SDK_PATH}" + fi + # check for incompatible clang ( 6.0 << bad-clang << 7.2) + clangvers=`clang --version | cut -d\ -f4` + $(`dpkg --compare-versions $clangvers '>>' 6.0`) && $(`dpkg --compare-versions $clangvers '<<' 7.2`) && clangcheck='y' + if [ "$clangcheck" = "y" ]; then + ../gcc-%v/configure %c --with-build-config=bootstrap-debug + else + ../gcc-%v/configure %c + fi + # Use bootstrap-lean to reduce disk usage. + # Note that this causes plugin testsuite failures + # since the plugin headers must come from prev-gcc. + # make bootstrap-lean + make bootstrap + fink-package-precedence --prohibit-bdep=%n . +<< +InstallScript: << + #!/bin/sh -ev + darwinvers=`uname -r` + cd ../darwin_objdir + make -j 1 install DESTDIR=%d + mkdir -p %i/bin + + # Add symlinks to recreate previous naming of executables in %p/bin + # as well as %p/lib/gcc%type_num[gccver]/bin and new -fsf-%type_num[gccver] naming in %p/bin. + binfiles="gcc g++ c++ cpp gcov" + for binfile in $binfiles ; do + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/$binfile-%type_num[gccver] + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-%type_num[gccver] + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-fsf-%type_num[gccver] + done + binfiles="gfortran" + for binfile in $binfiles ; do + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/$binfile + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-fsf-%type_num[gccver] + done + + # Remove unsupported executables + binfiles="gcc-ar gcc-nm gcc-ranlib" + for binfile in $binfiles ; do + rm -f %i/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/*-apple-darwin${darwinvers}-$binfile-fsf-%type_num[gccver] + done + + # Add symlinks for manpages under old names. + man1files="cpp g++ gcc gcov" + for man1file in $man1files ; do + ln -s $man1file-fsf-%type_num[gccver].1 %i/share/man/man1/$man1file-%type_num[gccver].1 + done + man1files="gfortran" + for man1file in $man1files ; do + ln -s $man1file-fsf-%type_num[gccver].1 %i/share/man/man1/$man1file.1 + done + + # Rename manpages with -fsf-%type_num[gccver] suffix and create symlinks to old names. + man7files="fsf-funding gfdl gpl" + for man7file in $man7files ; do + mv %i/share/man/man7/$man7file.7 %i/share/man/man7/$man7file-fsf-%type_num[gccver].7 + ln -s $man7file-fsf-%type_num[gccver].7 %i/share/man/man7/$man7file.7 + done + + # Add dir for installed info files, and link them to %i/share/info. + # the %i/lib/gcc%type_num[gccver]/info/* files will go into the -compiler package + # and the files in %i/share/info go into the main package, this allows + # the info files for specific compiler versions to be accessed with + # e.g. `info -d /fink_install_dir/lib/gcc%type_num[gccver]/info gcc', but the "main" info files will + # be available for the install gccXX package in %p/share/info, as usual + install -d -m 755 %i/share/info + for infofile in $(find %i/lib/gcc%type_num[gccver]/info -name '*.info*'); do + infobase=$(basename $infofile) + case $infofile in + *info) %p/bin/install-info --infodir=%i/lib/gcc%type_num[gccver]/info ${infofile} ;; + esac + ln -s %p/lib/gcc%type_num[gccver]/info/$infobase %i/share/info/$infobase + done + + # remove build path from .la files + perl -pi -e "s, \-L[^ ']*/%n-%v-%r/darwin_objdir/[^ ']*,,g" `find %i/lib/gcc%type_num[gccver]/lib -name '*.la'` + if [ "%m" = "arm64" ]; then + arch=aarch64 + else + arch=%m + fi + + # @rpath install_names are required for aarch64 build, but break some linked binaries + # - enforce actual install paths here; take care to update the cross-referenced dylibs. + cd %d + for dylib in .%p/lib/gcc%type_num[gccver]/lib/lib*.[0-9].dylib; do + install_name_tool -id ${dylib#.} $dylib + install_name_tool -change @rpath/libgcc_s.1.1.dylib %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib \ + -change @rpath/libstdc++.6.dylib %p/lib/gcc%type_num[gccver]/lib/libstdc++.6.dylib \ + -change @rpath/libquadmath.0.dylib %p/lib/gcc%type_num[gccver]/lib/libquadmath.0.dylib $dylib + done + otool -L .%p/lib/gcc%type_num[gccver]/lib/lib*.[0-9].dylib | grep '@rpath' && exit 2 + + cp %b/gcc/config/darwin-sections.def %i/lib/gcc%type_num[gccver]/lib/gcc/${arch}-apple-darwin${darwinvers}/%v/plugin/include/config +<< +SplitOff: << + Package: %N-shlibs + Replaces: << + gcc4 (<= 20050130-4), + gfortran-shlibs + << + Provides: << + gfortran-shlibs + << + Description: Shared libraries for %N + DocFiles: gcc/COPYING gcc/COPYING.LIB + Files: << + lib/gcc%type_num[gccver]/lib/libgfortran.5*.dylib + lib/gcc%type_num[gccver]/lib/libstdc++.6*.dylib + lib/gcc%type_num[gccver]/lib/libgcc_s.1*.dylib + lib/gcc%type_num[gccver]/lib/libitm.1*.dylib + lib/gcc%type_num[gccver]/lib/libssp.0*.dylib + lib/gcc%type_num[gccver]/lib/libobjc-gnu.4*.dylib + lib/gcc%type_num[gccver]/lib/libgomp.1*.dylib + lib/gcc%type_num[gccver]/lib/libquadmath.0*.dylib + lib/gcc%type_num[gccver]/lib/libatomic.1*.dylib + << + Shlibs: << + %p/lib/gcc%type_num[gccver]/lib/libgfortran.5.dylib 6.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libstdc++.6.dylib 7.0.0 %n (>= 14.1.0-1) + ( "%m" = "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib 1.0.0 %n (>= 14.1.0-1) + ( "%m" != "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.dylib 1.0.0 %n (>= 14.1.0-1) + ( "%m" != "arm64" ) !%p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib + %p/lib/gcc%type_num[gccver]/lib/libitm.1.dylib 2.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libssp.0.dylib 1.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libobjc-gnu.4.dylib 5.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libgomp.1.dylib 2.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libquadmath.0.dylib 1.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libatomic.1.dylib 4.0.0 %n (>= 14.1.0-1) + << +<< +SplitOff2: << + Package: %N-compiler + Depends: << + gmp5-shlibs (>= 6.1.2-1), + isl22-shlibs, + libgettext8-shlibs, + libgmpxx5-shlibs (>= 6.1.2-1), + libiconv, + libmpc3-shlibs (>= 1.0.3-1), + libmpfr6-shlibs, + %N-shlibs (= %v-%r) + << + BuildDependsOnly: False + Description: Compiler Binaries for gcc%type_num[gccver] + DocFiles: gcc/COPYING gcc/COPYING.LIB gcc/ChangeLog gcc/ABOUT-GCC-NLS gcc/README.Portability + Files: << + bin/*-fsf-%type_num[gccver] + lib/gcc%type_num[gccver] + share/man/man1/*-fsf-%type_num[gccver].1 + share/man/man7/*-fsf-%type_num[gccver].7 + << +<< +License: GPL +Description: GNU Compiler Collection Version %type_num[gccver] +DescDetail: << + GCC, the GNU Compiler Collection, includes front ends for + C, C++, Objective-C, Objective-C++, Fortran and Ada. + . + C, C++, Objective C and Fortran are included in this package. + . + The C and C++ compilers are named gcc-14 and g++-14 to avoid + conflicts with gcc and g++ installed by the Apple Developer Tools. +<< +DescPackaging: << + Build with -fsf-%type_num[gccver] suffix and place non-overlapping files into new gcc%type_num[gccver]-compiler + package which can co-exist with other gccXX-compiler packages. Overlapping files + are left in main gcc%type_num[gccver] package which still conflicts with other gccXX packages. + + macOS10.14 no longer supports building 32bit libraries, so must disable multilib. + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87030 + + We use --with-sysroot to find the hidden system-headers in case /usr/include is not + populated. Ideally want --with-build-sysroot because we only need the headers to build + gcc and that should not impact the end product, but then anything using gccX will + need to add it's own -isysroot flag. + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79885 + + Homebrew patches for arm64/aarch64 build and macOS 13+ from + https://github.com/Homebrew/formula-patches/blob/master/gcc/gcc-%v-r2.diff + - libasan.* and libsubsan.* currently not built on darwin22+ or arm64 - see + https://github.com/iains/gcc-darwin-arm64/commit/e722a1f4 + and missing from the 13.0-15.0 packages until resolved. + There are both "1" and "1.1" versions of libgcc_s.dylib now, but only "1.1" on arm64. + Manual fixes of @rpath install_names required for aarch64 build to maintain downstream + package compatibility. + Added `target_configargs` variable since for some reason libiconv prefix is not passed + down to libstdc++ config any more (https://github.com/iains/gcc-darwin-arm64/issues/129). +<< +Homepage: http://gcc.gnu.org/ +Maintainer: None +<< diff --git a/10.9-libcxx/stable/main/finkinfo/languages/gcc14-15.0.info b/10.9-libcxx/stable/main/finkinfo/languages/gcc14-15.0.info new file mode 100644 index 00000000000..46d72d74079 --- /dev/null +++ b/10.9-libcxx/stable/main/finkinfo/languages/gcc14-15.0.info @@ -0,0 +1,318 @@ +Info2: << +Package: gcc14 +Version: 14.2.0 +Revision: 2 +Type: gccver (14) +Distribution: 15.0 +Source: mirror:gnu:gcc/gcc-%v/gcc-%v.tar.xz +Source-Checksum: SHA256(a7b39bc69cbf9e25826c5a60ab26477001f7c08d85cec04bc0e29cabed6f3cc9) +PatchFile: %n.patch +PatchFile-MD5: fafea628b0211ed3d4e4528deb0c2842 +PatchScript: << + #!/bin/sh -ev + patch -p1 < %{PatchFile} + # don't update live infodoc dir + find . -name Makefile.in | xargs perl -pi -e 's/install-info --version/false/g' +<< +NoSetCPPFLAGS: True +NoSetLDFLAGS: True +UseMaxBuildJobs: True +Conflicts: << + gcc5, gcc6, gcc7, gcc8, + gcc9, + gcc10, + gcc11, + gcc12, + gcc13, + gcc14 +<< +Replaces: << + gcc5, gcc6, gcc7, gcc8, + gcc9, + gcc10, + gcc11, + gcc12, + gcc13, + gcc14 +<< +Depends: << + %N-compiler (= %v-%r) +<< +BuildDepends: << + fink (>= 0.32), + fink-package-precedence, + gettext-tools, + gmp5 (>= 6.1.2-1), + install-info, + isl22, + libgettext8-dev, + libiconv-dev, + libmpc3 (>= 1.0.3-1), + libmpfr6, + x11-dev +<< +ConfigureParams: << + --prefix=%p/lib/gcc%type_num[gccver] \ + --mandir=%p/share/man \ + --infodir=%p/lib/gcc%type_num[gccver]/info \ + --enable-languages=c,c++,fortran,lto,objc,obj-c++ \ + --with-gmp=%p \ + --with-libiconv-prefix=%p \ + --with-isl=%p \ + --with-mpc=%p \ + --with-system-zlib \ + --program-suffix=-fsf-%type_num[gccver] \ + --disable-multilib \ + --enable-stage1-checking \ + ${USE_SYSROOT} \ + --with-pkgversion="Fink %n %v-%r" \ + --with-bugurl="https://github.com/fink/fink-distributions/issues" +<< +InfoTest: << + TestDepends: << + autogen, + dejagnu, + ( "%m" != "arm64" ) apple-gdb + << + TestScript: << + #!/bin/bash -ev + if [ "%m" = "arm64" ]; then + echo "The gcc testsuite requires Apple's gdb, which is not available on this architecture." + exit 0 + elif [ $UID = 0 ]; then + if [ -e /usr/bin/csrutil && `csrutil status | grep -c disabled` ]; then + cd ../darwin_objdir; make -k check RUNTESTFLAGS="--target_board=unix'{-m64}'" || : + else + echo "The gcc testsuite must be run with SIP disabled or package installed." + exit 0 + fi + else + echo "The gcc testsuite must be run as root due to its use of gdb." + exit 0 + fi + << +<< +InfoDocs: gcc.info gfortran.info cpp.info gccinstall.info libgomp.info cppinternals.info gccint.info +CompileScript: << + #!/bin/bash -ev + set +x + if [ -e /usr/local/lib/libgmp.a ] || [ -e /usr/local/lib/libgmp.dylib ]; then + echo "-----WARNING-----WARNING-----WARNING-----" + echo "You seem to have GMP installed in /usr/local." + echo "This is known to cause %N to fail to build." + echo "Please move aside /usr/local and try again." + echo "-----WARNING-----WARNING-----WARNING-----" + exit 1 + else + echo "Good, /usr/local/lib/libgmp* not present." + fi + set -x + ulimit -s `ulimit -s` + mkdir ../darwin_objdir + cd ../darwin_objdir + # build doesn't play well with GNU-make + # unsupported option '-static-libgcc' + export MAKE=/usr/bin/make + export target_configargs='--with-libiconv-prefix=%p' + # Only need sysroot on 10.14+ because /usr/include has been removed + OSX_MAJOR_VERSION=`sw_vers -productVersion | cut -d. -f1-2` + if dpkg --compare-versions "$OSX_MAJOR_VERSION" ge "10.14"; then + # Get the unversioned SDK path + SDK_PATH=`dirname $(xcrun --sdk macosx --show-sdk-path)`/MacOSX.sdk + # This should really be --with-build-sysroot but that's not getting propagated through the entire build process. + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79885 + export USE_SYSROOT="--with-sysroot=${SDK_PATH}" + fi + # check for incompatible clang ( 6.0 << bad-clang << 7.2) + clangvers=`clang --version | cut -d\ -f4` + $(`dpkg --compare-versions $clangvers '>>' 6.0`) && $(`dpkg --compare-versions $clangvers '<<' 7.2`) && clangcheck='y' + if [ "$clangcheck" = "y" ]; then + ../gcc-%v/configure %c --with-build-config=bootstrap-debug + else + ../gcc-%v/configure %c + fi + # Use bootstrap-lean to reduce disk usage. + # Note that this causes plugin testsuite failures + # since the plugin headers must come from prev-gcc. + # make bootstrap-lean + make bootstrap + fink-package-precedence --prohibit-bdep=%n . +<< +InstallScript: << + #!/bin/sh -ev + darwinvers=`uname -r` + cd ../darwin_objdir + make -j 1 install DESTDIR=%d + mkdir -p %i/bin + + # Add symlinks to recreate previous naming of executables in %p/bin + # as well as %p/lib/gcc%type_num[gccver]/bin and new -fsf-%type_num[gccver] naming in %p/bin. + binfiles="gcc g++ c++ cpp gcov" + for binfile in $binfiles ; do + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/$binfile-%type_num[gccver] + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-%type_num[gccver] + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-fsf-%type_num[gccver] + done + binfiles="gfortran" + for binfile in $binfiles ; do + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/$binfile + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-fsf-%type_num[gccver] + done + + # Remove unsupported executables + binfiles="gcc-ar gcc-nm gcc-ranlib" + for binfile in $binfiles ; do + rm -f %i/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/*-apple-darwin${darwinvers}-$binfile-fsf-%type_num[gccver] + done + + # Add symlinks for manpages under old names. + man1files="cpp g++ gcc gcov" + for man1file in $man1files ; do + ln -s $man1file-fsf-%type_num[gccver].1 %i/share/man/man1/$man1file-%type_num[gccver].1 + done + man1files="gfortran" + for man1file in $man1files ; do + ln -s $man1file-fsf-%type_num[gccver].1 %i/share/man/man1/$man1file.1 + done + + # Rename manpages with -fsf-%type_num[gccver] suffix and create symlinks to old names. + man7files="fsf-funding gfdl gpl" + for man7file in $man7files ; do + mv %i/share/man/man7/$man7file.7 %i/share/man/man7/$man7file-fsf-%type_num[gccver].7 + ln -s $man7file-fsf-%type_num[gccver].7 %i/share/man/man7/$man7file.7 + done + + # Add dir for installed info files, and link them to %i/share/info. + # the %i/lib/gcc%type_num[gccver]/info/* files will go into the -compiler package + # and the files in %i/share/info go into the main package, this allows + # the info files for specific compiler versions to be accessed with + # e.g. `info -d /fink_install_dir/lib/gcc%type_num[gccver]/info gcc', but the "main" info files will + # be available for the install gccXX package in %p/share/info, as usual + install -d -m 755 %i/share/info + for infofile in $(find %i/lib/gcc%type_num[gccver]/info -name '*.info*'); do + infobase=$(basename $infofile) + case $infofile in + *info) %p/bin/install-info --infodir=%i/lib/gcc%type_num[gccver]/info ${infofile} ;; + esac + ln -s %p/lib/gcc%type_num[gccver]/info/$infobase %i/share/info/$infobase + done + + # remove build path from .la files + perl -pi -e "s, \-L[^ ']*/%n-%v-%r/darwin_objdir/[^ ']*,,g" `find %i/lib/gcc%type_num[gccver]/lib -name '*.la'` + if [ "%m" = "arm64" ]; then + arch=aarch64 + else + arch=%m + fi + + # @rpath install_names are required for aarch64 build, but break some linked binaries + # - enforce actual install paths here; take care to update the cross-referenced dylibs. + cd %d + for dylib in .%p/lib/gcc%type_num[gccver]/lib/lib*.[0-9].dylib; do + install_name_tool -id ${dylib#.} $dylib + install_name_tool -change @rpath/libgcc_s.1.1.dylib %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib \ + -change @rpath/libstdc++.6.dylib %p/lib/gcc%type_num[gccver]/lib/libstdc++.6.dylib \ + -change @rpath/libquadmath.0.dylib %p/lib/gcc%type_num[gccver]/lib/libquadmath.0.dylib $dylib + done + otool -L .%p/lib/gcc%type_num[gccver]/lib/lib*.[0-9].dylib | grep '@rpath' && exit 2 + + cp %b/gcc/config/darwin-sections.def %i/lib/gcc%type_num[gccver]/lib/gcc/${arch}-apple-darwin${darwinvers}/%v/plugin/include/config +<< +SplitOff: << + Package: %N-shlibs + Replaces: << + gcc4 (<= 20050130-4), + gfortran-shlibs + << + Provides: << + gfortran-shlibs + << + Description: Shared libraries for %N + DocFiles: gcc/COPYING gcc/COPYING.LIB + Files: << + lib/gcc%type_num[gccver]/lib/libgfortran.5*.dylib + lib/gcc%type_num[gccver]/lib/libstdc++.6*.dylib + lib/gcc%type_num[gccver]/lib/libgcc_s.1*.dylib + lib/gcc%type_num[gccver]/lib/libitm.1*.dylib + lib/gcc%type_num[gccver]/lib/libssp.0*.dylib + lib/gcc%type_num[gccver]/lib/libobjc-gnu.4*.dylib + lib/gcc%type_num[gccver]/lib/libgomp.1*.dylib + lib/gcc%type_num[gccver]/lib/libquadmath.0*.dylib + lib/gcc%type_num[gccver]/lib/libatomic.1*.dylib + << + Shlibs: << + %p/lib/gcc%type_num[gccver]/lib/libgfortran.5.dylib 6.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libstdc++.6.dylib 7.0.0 %n (>= 14.1.0-1) + ( "%m" = "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib 1.0.0 %n (>= 14.1.0-1) + ( "%m" != "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.dylib 1.0.0 %n (>= 14.1.0-1) + ( "%m" != "arm64" ) !%p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib + %p/lib/gcc%type_num[gccver]/lib/libitm.1.dylib 2.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libssp.0.dylib 1.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libobjc-gnu.4.dylib 5.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libgomp.1.dylib 2.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libquadmath.0.dylib 1.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libatomic.1.dylib 4.0.0 %n (>= 14.1.0-1) + << +<< +SplitOff2: << + Package: %N-compiler + Depends: << + gmp5-shlibs (>= 6.1.2-1), + isl22-shlibs, + libgettext8-shlibs, + libgmpxx5-shlibs (>= 6.1.2-1), + libiconv, + libmpc3-shlibs (>= 1.0.3-1), + libmpfr6-shlibs, + %N-shlibs (= %v-%r) + << + BuildDependsOnly: False + Description: Compiler Binaries for gcc%type_num[gccver] + DocFiles: gcc/COPYING gcc/COPYING.LIB gcc/ChangeLog gcc/ABOUT-GCC-NLS gcc/README.Portability + Files: << + bin/*-fsf-%type_num[gccver] + lib/gcc%type_num[gccver] + share/man/man1/*-fsf-%type_num[gccver].1 + share/man/man7/*-fsf-%type_num[gccver].7 + << +<< +License: GPL +Description: GNU Compiler Collection Version %type_num[gccver] +DescDetail: << + GCC, the GNU Compiler Collection, includes front ends for + C, C++, Objective-C, Objective-C++, Fortran and Ada. + . + C, C++, Objective C and Fortran are included in this package. + . + The C and C++ compilers are named gcc-14 and g++-14 to avoid + conflicts with gcc and g++ installed by the Apple Developer Tools. +<< +DescPackaging: << + Build with -fsf-%type_num[gccver] suffix and place non-overlapping files into new gcc%type_num[gccver]-compiler + package which can co-exist with other gccXX-compiler packages. Overlapping files + are left in main gcc%type_num[gccver] package which still conflicts with other gccXX packages. + + macOS10.14 no longer supports building 32bit libraries, so must disable multilib. + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87030 + + We use --with-sysroot to find the hidden system-headers in case /usr/include is not + populated. Ideally want --with-build-sysroot because we only need the headers to build + gcc and that should not impact the end product, but then anything using gccX will + need to add it's own -isysroot flag. + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79885 + + Homebrew patches for arm64/aarch64 build and macOS 13+ from + https://github.com/Homebrew/formula-patches/blob/master/gcc/gcc-%v-r2.diff + - libasan.* and libsubsan.* currently not built on darwin22+ or arm64 - see + https://github.com/iains/gcc-darwin-arm64/commit/e722a1f4 + and missing from the 13.0-15.0 packages until resolved. + There are both "1" and "1.1" versions of libgcc_s.dylib now, but only "1.1" on arm64. + Manual fixes of @rpath install_names required for aarch64 build to maintain downstream + package compatibility. + Added `target_configargs` variable since for some reason libiconv prefix is not passed + down to libstdc++ config any more (https://github.com/iains/gcc-darwin-arm64/issues/129). +<< +Homepage: http://gcc.gnu.org/ +Maintainer: None +<< diff --git a/10.9-libcxx/stable/main/finkinfo/languages/gcc14.info b/10.9-libcxx/stable/main/finkinfo/languages/gcc14.info new file mode 100644 index 00000000000..4975a1bad90 --- /dev/null +++ b/10.9-libcxx/stable/main/finkinfo/languages/gcc14.info @@ -0,0 +1,319 @@ +Info2: << +Package: gcc14 +Version: 14.2.0 +Revision: 2 +Type: gccver (14) +Distribution: 10.14, 10.14.5, 10.15, 11.0, 11.3, 12.0 +Source: mirror:gnu:gcc/gcc-%v/gcc-%v.tar.xz +Source-Checksum: SHA256(a7b39bc69cbf9e25826c5a60ab26477001f7c08d85cec04bc0e29cabed6f3cc9) +PatchFile: %n.patch +PatchFile-MD5: fafea628b0211ed3d4e4528deb0c2842 +PatchScript: << + #!/bin/sh -ev + patch -p1 < %{PatchFile} + # don't update live infodoc dir + find . -name Makefile.in | xargs perl -pi -e 's/install-info --version/false/g' +<< +NoSetCPPFLAGS: True +NoSetLDFLAGS: True +UseMaxBuildJobs: True +Conflicts: << + gcc5, gcc6, gcc7, gcc8, + gcc9, + gcc10, + gcc11, + gcc12, + gcc13, + gcc14 +<< +Replaces: << + gcc5, gcc6, gcc7, gcc8, + gcc9, + gcc10, + gcc11, + gcc12, + gcc13, + gcc14 +<< +Depends: << + %N-compiler (= %v-%r) +<< +BuildDepends: << + fink (>= 0.32), + fink-package-precedence, + gettext-tools, + gmp5 (>= 6.1.2-1), + install-info, + isl22, + libgettext8-dev, + libiconv-dev, + libmpc3 (>= 1.0.3-1), + libmpfr6, + x11-dev +<< +ConfigureParams: << + --prefix=%p/lib/gcc%type_num[gccver] \ + --mandir=%p/share/man \ + --infodir=%p/lib/gcc%type_num[gccver]/info \ + --enable-languages=c,c++,fortran,lto,objc,obj-c++ \ + --with-gmp=%p \ + --with-libiconv-prefix=%p \ + --with-isl=%p \ + --with-mpc=%p \ + --with-system-zlib \ + --program-suffix=-fsf-%type_num[gccver] \ + --disable-multilib \ + --enable-stage1-checking \ + ${USE_SYSROOT} \ + --with-pkgversion="Fink %n %v-%r" \ + --with-bugurl="https://github.com/fink/fink-distributions/issues" +<< +InfoTest: << + TestDepends: << + autogen, + dejagnu, + ( "%m" != "arm64" ) apple-gdb + << + TestScript: << + #!/bin/bash -ev + if [ "%m" = "arm64" ]; then + echo "The gcc testsuite requires Apple's gdb, which is not available on this architecture." + exit 0 + elif [ $UID = 0 ]; then + if [ -e /usr/bin/csrutil && `csrutil status | grep -c disabled` ]; then + cd ../darwin_objdir; make -k check RUNTESTFLAGS="--target_board=unix'{-m64}'" || : + else + echo "The gcc testsuite must be run with SIP disabled or package installed." + exit 0 + fi + else + echo "The gcc testsuite must be run as root due to its use of gdb." + exit 0 + fi + << +<< +InfoDocs: gcc.info gfortran.info cpp.info gccinstall.info libgomp.info cppinternals.info gccint.info +CompileScript: << + #!/bin/bash -ev + set +x + if [ -e /usr/local/lib/libgmp.a ] || [ -e /usr/local/lib/libgmp.dylib ]; then + echo "-----WARNING-----WARNING-----WARNING-----" + echo "You seem to have GMP installed in /usr/local." + echo "This is known to cause %N to fail to build." + echo "Please move aside /usr/local and try again." + echo "-----WARNING-----WARNING-----WARNING-----" + exit 1 + else + echo "Good, /usr/local/lib/libgmp* not present." + fi + set -x + ulimit -s `ulimit -s` + mkdir ../darwin_objdir + cd ../darwin_objdir + # build doesn't play well with GNU-make + # unsupported option '-static-libgcc' + export MAKE=/usr/bin/make + export target_configargs='--with-libiconv-prefix=%p' + # Only need sysroot on 10.14+ because /usr/include has been removed + OSX_MAJOR_VERSION=`sw_vers -productVersion | cut -d. -f1-2` + if dpkg --compare-versions "$OSX_MAJOR_VERSION" ge "10.14"; then + # Get the unversioned SDK path + SDK_PATH=`dirname $(xcrun --sdk macosx --show-sdk-path)`/MacOSX.sdk + # This should really be --with-build-sysroot but that's not getting propagated through the entire build process. + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79885 + export USE_SYSROOT="--with-sysroot=${SDK_PATH}" + fi + # check for incompatible clang ( 6.0 << bad-clang << 7.2) + clangvers=`clang --version | cut -d\ -f4` + $(`dpkg --compare-versions $clangvers '>>' 6.0`) && $(`dpkg --compare-versions $clangvers '<<' 7.2`) && clangcheck='y' + if [ "$clangcheck" = "y" ]; then + ../gcc-%v/configure %c --with-build-config=bootstrap-debug + else + ../gcc-%v/configure %c + fi + # Use bootstrap-lean to reduce disk usage. + # Note that this causes plugin testsuite failures + # since the plugin headers must come from prev-gcc. + # make bootstrap-lean + make bootstrap + fink-package-precedence --prohibit-bdep=%n . +<< +InstallScript: << + #!/bin/sh -ev + darwinvers=`uname -r` + cd ../darwin_objdir + make -j 1 install DESTDIR=%d + mkdir -p %i/bin + + # Add symlinks to recreate previous naming of executables in %p/bin + # as well as %p/lib/gcc%type_num[gccver]/bin and new -fsf-%type_num[gccver] naming in %p/bin. + binfiles="gcc g++ c++ cpp gcov" + for binfile in $binfiles ; do + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/$binfile-%type_num[gccver] + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-%type_num[gccver] + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-fsf-%type_num[gccver] + done + binfiles="gfortran" + for binfile in $binfiles ; do + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/$binfile + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile + ln -s %p/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/bin/$binfile-fsf-%type_num[gccver] + done + + # Remove unsupported executables + binfiles="gcc-ar gcc-nm gcc-ranlib" + for binfile in $binfiles ; do + rm -f %i/lib/gcc%type_num[gccver]/bin/$binfile-fsf-%type_num[gccver] %i/lib/gcc%type_num[gccver]/bin/*-apple-darwin${darwinvers}-$binfile-fsf-%type_num[gccver] + done + + # Add symlinks for manpages under old names. + man1files="cpp g++ gcc gcov" + for man1file in $man1files ; do + ln -s $man1file-fsf-%type_num[gccver].1 %i/share/man/man1/$man1file-%type_num[gccver].1 + done + man1files="gfortran" + for man1file in $man1files ; do + ln -s $man1file-fsf-%type_num[gccver].1 %i/share/man/man1/$man1file.1 + done + + # Rename manpages with -fsf-%type_num[gccver] suffix and create symlinks to old names. + man7files="fsf-funding gfdl gpl" + for man7file in $man7files ; do + mv %i/share/man/man7/$man7file.7 %i/share/man/man7/$man7file-fsf-%type_num[gccver].7 + ln -s $man7file-fsf-%type_num[gccver].7 %i/share/man/man7/$man7file.7 + done + + # Add dir for installed info files, and link them to %i/share/info. + # the %i/lib/gcc%type_num[gccver]/info/* files will go into the -compiler package + # and the files in %i/share/info go into the main package, this allows + # the info files for specific compiler versions to be accessed with + # e.g. `info -d /fink_install_dir/lib/gcc%type_num[gccver]/info gcc', but the "main" info files will + # be available for the install gccXX package in %p/share/info, as usual + install -d -m 755 %i/share/info + for infofile in $(find %i/lib/gcc%type_num[gccver]/info -name '*.info*'); do + infobase=$(basename $infofile) + case $infofile in + *info) %p/bin/install-info --infodir=%i/lib/gcc%type_num[gccver]/info ${infofile} ;; + esac + ln -s %p/lib/gcc%type_num[gccver]/info/$infobase %i/share/info/$infobase + done + + # remove build path from .la files + perl -pi -e "s, \-L[^ ']*/%n-%v-%r/darwin_objdir/[^ ']*,,g" `find %i/lib/gcc%type_num[gccver]/lib -name '*.la'` + if [ "%m" = "arm64" ]; then + arch=aarch64 + else + arch=%m + fi + + # @rpath install_names are required for aarch64 build, but break some linked binaries + # - enforce actual install paths here; take care to update the cross-referenced dylibs. + cd %d + for dylib in .%p/lib/gcc%type_num[gccver]/lib/lib*.[0-9].dylib; do + install_name_tool -id ${dylib#.} $dylib + install_name_tool -change @rpath/libgcc_s.1.1.dylib %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib \ + -change @rpath/libstdc++.6.dylib %p/lib/gcc%type_num[gccver]/lib/libstdc++.6.dylib \ + -change @rpath/libquadmath.0.dylib %p/lib/gcc%type_num[gccver]/lib/libquadmath.0.dylib $dylib + done + otool -L .%p/lib/gcc%type_num[gccver]/lib/lib*.[0-9].dylib | grep '@rpath' && exit 2 + + cp %b/gcc/config/darwin-sections.def %i/lib/gcc%type_num[gccver]/lib/gcc/${arch}-apple-darwin${darwinvers}/%v/plugin/include/config +<< +SplitOff: << + Package: %N-shlibs + Replaces: << + gcc4 (<= 20050130-4), + gfortran-shlibs + << + Provides: << + gfortran-shlibs + << + Description: Shared libraries for %N + DocFiles: gcc/COPYING gcc/COPYING.LIB + Files: << + lib/gcc%type_num[gccver]/lib/libgfortran.5*.dylib + lib/gcc%type_num[gccver]/lib/libstdc++.6*.dylib + lib/gcc%type_num[gccver]/lib/libgcc_s.1*.dylib + lib/gcc%type_num[gccver]/lib/libitm.1*.dylib + lib/gcc%type_num[gccver]/lib/libssp.0*.dylib + lib/gcc%type_num[gccver]/lib/libobjc-gnu.4*.dylib + lib/gcc%type_num[gccver]/lib/libgomp.1*.dylib + lib/gcc%type_num[gccver]/lib/libquadmath.0*.dylib + lib/gcc%type_num[gccver]/lib/libatomic.1*.dylib + ( "%m" != "arm64" ) lib/gcc%type_num[gccver]/lib/libasan.8*.dylib + ( "%m" != "arm64" ) lib/gcc%type_num[gccver]/lib/libubsan.1*.dylib + << + Shlibs: << + %p/lib/gcc%type_num[gccver]/lib/libgfortran.5.dylib 6.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libstdc++.6.dylib 7.0.0 %n (>= 14.1.0-1) + ( "%m" = "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib 1.0.0 %n (>= 14.1.0-1) + ( "%m" != "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.dylib 1.0.0 %n (>= 14.1.0-1) + ( "%m" != "arm64" ) !%p/lib/gcc%type_num[gccver]/lib/libgcc_s.1.1.dylib + %p/lib/gcc%type_num[gccver]/lib/libitm.1.dylib 2.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libssp.0.dylib 1.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libobjc-gnu.4.dylib 5.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libgomp.1.dylib 2.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libquadmath.0.dylib 1.0.0 %n (>= 14.1.0-1) + %p/lib/gcc%type_num[gccver]/lib/libatomic.1.dylib 4.0.0 %n (>= 14.1.0-1) + ( "%m" != "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libasan.8.dylib 9.0.0 %n (>= 14.1.0-1) + ( "%m" != "arm64" ) %p/lib/gcc%type_num[gccver]/lib/libubsan.1.dylib 2.0.0 %n (>= 14.1.0-1) + << +<< +SplitOff2: << + Package: %N-compiler + Depends: << + gmp5-shlibs (>= 6.1.2-1), + isl22-shlibs, + libgettext8-shlibs, + libgmpxx5-shlibs (>= 6.1.2-1), + libiconv, + libmpc3-shlibs (>= 1.0.3-1), + libmpfr6-shlibs, + %N-shlibs (= %v-%r) + << + BuildDependsOnly: False + Description: Compiler Binaries for gcc%type_num[gccver] + DocFiles: gcc/COPYING gcc/COPYING.LIB gcc/ChangeLog gcc/ABOUT-GCC-NLS gcc/README.Portability + Files: << + bin/*-fsf-%type_num[gccver] + lib/gcc%type_num[gccver] + share/man/man1/*-fsf-%type_num[gccver].1 + share/man/man7/*-fsf-%type_num[gccver].7 + << +<< +License: GPL +Description: GNU Compiler Collection Version %type_num[gccver] +DescDetail: << + GCC, the GNU Compiler Collection, includes front ends for + C, C++, Objective-C, Objective-C++, Fortran and Ada. + . + C, C++, Objective C and Fortran are included in this package. + . + The C and C++ compilers are named gcc-14 and g++-14 to avoid + conflicts with gcc and g++ installed by the Apple Developer Tools. +<< +DescPackaging: << + Build with -fsf-%type_num[gccver] suffix and place non-overlapping files into new gcc%type_num[gccver]-compiler + package which can co-exist with other gccXX-compiler packages. Overlapping files + are left in main gcc%type_num[gccver] package which still conflicts with other gccXX packages. + + macOS10.14 no longer supports building 32bit libraries, so must disable multilib. + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87030 + + We use --with-sysroot to find the hidden system-headers in case /usr/include is not + populated. Ideally want --with-build-sysroot because we only need the headers to build + gcc and that should not impact the end product, but then anything using gccX will + need to add it's own -isysroot flag. + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79885 + + Homebrew patches for arm64/aarch64 build and macOS 13+ from + https://github.com/Homebrew/formula-patches/blob/master/gcc/gcc-%v-r2.diff + - libasan.* and libsubsan.* currently not built on darwin22+ or arm64 - see + https://github.com/iains/gcc-darwin-arm64/commit/e722a1f4 . + There are both "1" and "1.1" versions of libgcc_s.dylib now, but only "1.1" on arm64. + Manual fixes of @rpath install_names required for aarch64 build to maintain downstream + package compatibility. +<< +Homepage: http://gcc.gnu.org/ +Maintainer: None +<< diff --git a/10.9-libcxx/stable/main/finkinfo/languages/gcc14.patch b/10.9-libcxx/stable/main/finkinfo/languages/gcc14.patch new file mode 100644 index 00000000000..a5050aca32c --- /dev/null +++ b/10.9-libcxx/stable/main/finkinfo/languages/gcc14.patch @@ -0,0 +1,6084 @@ +diff --git a/configure b/configure +index 3b0abeb8b2e..f7a7da118cc 100755 +--- a/configure ++++ b/configure +@@ -3518,6 +3518,8 @@ esac + + # Disable libffi for some systems. + case "${target}" in ++ aarch64*-*-darwin2*) ++ ;; + powerpc-*-darwin*) + ;; + i[3456789]86-*-darwin*) +diff --git a/configure.ac b/configure.ac +index 042681c27be..21218446587 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -747,6 +747,8 @@ esac + + # Disable libffi for some systems. + case "${target}" in ++ aarch64*-*-darwin2*) ++ ;; + powerpc-*-darwin*) + ;; + i[[3456789]]86-*-darwin*) +diff --git a/fixincludes/fixincl.x b/fixincludes/fixincl.x +index e52f11d8460..6c6f9e02902 100644 +--- a/fixincludes/fixincl.x ++++ b/fixincludes/fixincl.x +@@ -2,11 +2,11 @@ + * + * DO NOT EDIT THIS FILE (fixincl.x) + * +- * It has been AutoGen-ed August 17, 2023 at 10:16:38 AM by AutoGen 5.18.12 ++ * It has been AutoGen-ed October 6, 2024 at 07:10:01 PM by AutoGen 5.18.7 + * From the definitions inclhack.def + * and the template file fixincl + */ +-/* DO NOT SVN-MERGE THIS FILE, EITHER Thu Aug 17 10:16:38 CEST 2023 ++/* DO NOT SVN-MERGE THIS FILE, EITHER Sun Oct 6 19:10:01 BST 2024 + * + * You must regenerate it. Use the ./genfixes script. + * +@@ -15,7 +15,7 @@ + * certain ANSI-incompatible system header files which are fixed to work + * correctly with ANSI C and placed in a directory that GNU C will search. + * +- * This file contains 274 fixup descriptions. ++ * This file contains 272 fixup descriptions. + * + * See README for more information. + * +@@ -267,56 +267,6 @@ static const char* apzAab_Darwin7_9_Long_Double_FuncsPatch[] = { + #endif /* __MATH__ */", + (char*)NULL }; + +-/* * * * * * * * * * * * * * * * * * * * * * * * * * +- * +- * Description of Darwin_Api_Availability fix +- */ +-tSCC zDarwin_Api_AvailabilityName[] = +- "darwin_api_availability"; +- +-/* +- * File name selection pattern +- */ +-tSCC zDarwin_Api_AvailabilityList[] = +- "os/availability.h\0"; +-/* +- * Machine/OS name selection pattern +- */ +-tSCC* apzDarwin_Api_AvailabilityMachs[] = { +- "*-*-darwin*", +- (const char*)NULL }; +- +-/* +- * content selection pattern - do fix if pattern found +- */ +-tSCC zDarwin_Api_AvailabilitySelect0[] = +- " *#define __API_AVAILABLE.*\n\ +- *#define __API_DEPRECATED.*\n\ +- *#define __API_DEPRECATED_WITH_REPLACEMENT.*\n\ +- *#define __API_UNAVAILABLE.*\n"; +- +-/* +- * content bypass pattern - skip fix if pattern found +- */ +-tSCC zDarwin_Api_AvailabilityBypass0[] = +- "__IPHONE_OS_VERSION_MIN_REQUIRED"; +- +-#define DARWIN_API_AVAILABILITY_TEST_CT 2 +-static tTestDesc aDarwin_Api_AvailabilityTests[] = { +- { TT_NEGREP, zDarwin_Api_AvailabilityBypass0, (regex_t*)NULL }, +- { TT_EGREP, zDarwin_Api_AvailabilitySelect0, (regex_t*)NULL }, }; +- +-/* +- * Fix Command Arguments for Darwin_Api_Availability +- */ +-static const char* apzDarwin_Api_AvailabilityPatch[] = { +- "format", +- " #define API_AVAILABLE(...)\n\ +- #define API_DEPRECATED(...)\n\ +- #define API_DEPRECATED_WITH_REPLACEMENT(...)\n\ +- #define API_UNAVAILABLE(...)\n", +- (char*)NULL }; +- + /* * * * * * * * * * * * * * * * * * * * * * * * * * + * + * Description of Aab_Fd_Zero_Asm_Posix_Types_H fix +@@ -2619,7 +2569,7 @@ tSCC zApple_Local_Stdio_Fn_DeprecationName[] = + * File name selection pattern + */ + tSCC zApple_Local_Stdio_Fn_DeprecationList[] = +- "stdio.h\0"; ++ "stdio.h\0_stdio.h\0"; + /* + * Machine/OS name selection pattern + */ +@@ -2763,51 +2713,6 @@ extern \"C\" {\n\ + #endif\n", + (char*)NULL }; + +-/* * * * * * * * * * * * * * * * * * * * * * * * * * +- * +- * Description of Darwin_Availabilityinternal fix +- */ +-tSCC zDarwin_AvailabilityinternalName[] = +- "darwin_availabilityinternal"; +- +-/* +- * File name selection pattern +- */ +-tSCC zDarwin_AvailabilityinternalList[] = +- "AvailabilityInternal.h\0"; +-/* +- * Machine/OS name selection pattern +- */ +-tSCC* apzDarwin_AvailabilityinternalMachs[] = { +- "*-*-darwin*", +- (const char*)NULL }; +- +-/* +- * content selection pattern - do fix if pattern found +- */ +-tSCC zDarwin_AvailabilityinternalSelect0[] = +- "#define[ \t]+(__API_[ADU]\\([^)]*\\)).*"; +- +-#define DARWIN_AVAILABILITYINTERNAL_TEST_CT 1 +-static tTestDesc aDarwin_AvailabilityinternalTests[] = { +- { TT_EGREP, zDarwin_AvailabilityinternalSelect0, (regex_t*)NULL }, }; +- +-/* +- * Fix Command Arguments for Darwin_Availabilityinternal +- */ +-static const char* apzDarwin_AvailabilityinternalPatch[] = { +- "format", +- "#if defined(__has_attribute)\n\ +- #if __has_attribute(availability)\n\ +-%0\n\ +- #else\n\ +- #define %1\n\ +- #endif\n\ +-#else\n\ +- #define %1\n\ +-#endif", +- (char*)NULL }; +- + /* * * * * * * * * * * * * * * * * * * * * * * * * * + * + * Description of Darwin_9_Long_Double_Funcs_2 fix +@@ -11169,9 +11074,9 @@ static const char* apzX11_SprintfPatch[] = { + * + * List of all fixes + */ +-#define REGEX_COUNT 313 ++#define REGEX_COUNT 310 + #define MACH_LIST_SIZE_LIMIT 187 +-#define FIX_COUNT 274 ++#define FIX_COUNT 272 + + /* + * Enumerate the fixes +@@ -11180,7 +11085,6 @@ typedef enum { + AAB_AIX_STDIO_FIXIDX, + AAB_AIX_FCNTL_FIXIDX, + AAB_DARWIN7_9_LONG_DOUBLE_FUNCS_FIXIDX, +- DARWIN_API_AVAILABILITY_FIXIDX, + AAB_FD_ZERO_ASM_POSIX_TYPES_H_FIXIDX, + AAB_FD_ZERO_GNU_TYPES_H_FIXIDX, + AAB_FD_ZERO_SELECTBITS_H_FIXIDX, +@@ -11242,7 +11146,6 @@ typedef enum { + CTRL_QUOTES_DEF_FIXIDX, + CTRL_QUOTES_USE_FIXIDX, + CXX_UNREADY_FIXIDX, +- DARWIN_AVAILABILITYINTERNAL_FIXIDX, + DARWIN_9_LONG_DOUBLE_FUNCS_2_FIXIDX, + DARWIN_EXTERNC_FIXIDX, + DARWIN_GCC4_BREAKAGE_FIXIDX, +@@ -11469,11 +11372,6 @@ tFixDesc fixDescList[ FIX_COUNT ] = { + AAB_DARWIN7_9_LONG_DOUBLE_FUNCS_TEST_CT, FD_MACH_ONLY | FD_REPLACEMENT, + aAab_Darwin7_9_Long_Double_FuncsTests, apzAab_Darwin7_9_Long_Double_FuncsPatch, 0 }, + +- { zDarwin_Api_AvailabilityName, zDarwin_Api_AvailabilityList, +- apzDarwin_Api_AvailabilityMachs, +- DARWIN_API_AVAILABILITY_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE, +- aDarwin_Api_AvailabilityTests, apzDarwin_Api_AvailabilityPatch, 0 }, +- + { zAab_Fd_Zero_Asm_Posix_Types_HName, zAab_Fd_Zero_Asm_Posix_Types_HList, + apzAab_Fd_Zero_Asm_Posix_Types_HMachs, + AAB_FD_ZERO_ASM_POSIX_TYPES_H_TEST_CT, FD_MACH_ONLY | FD_REPLACEMENT, +@@ -11779,11 +11677,6 @@ tFixDesc fixDescList[ FIX_COUNT ] = { + CXX_UNREADY_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE, + aCxx_UnreadyTests, apzCxx_UnreadyPatch, 0 }, + +- { zDarwin_AvailabilityinternalName, zDarwin_AvailabilityinternalList, +- apzDarwin_AvailabilityinternalMachs, +- DARWIN_AVAILABILITYINTERNAL_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE, +- aDarwin_AvailabilityinternalTests, apzDarwin_AvailabilityinternalPatch, 0 }, +- + { zDarwin_9_Long_Double_Funcs_2Name, zDarwin_9_Long_Double_Funcs_2List, + apzDarwin_9_Long_Double_Funcs_2Machs, + DARWIN_9_LONG_DOUBLE_FUNCS_2_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE, +diff --git a/fixincludes/inclhack.def b/fixincludes/inclhack.def +index 19e0ea2df66..560b455717e 100644 +--- a/fixincludes/inclhack.def ++++ b/fixincludes/inclhack.def +@@ -194,33 +194,6 @@ fix = { + _EndOfHeader_; + }; + +-/* +- * SDKs for 10.13 and 10.14 omit the definitions for API_AVAILABLE where +- * __attribute__((availability)) is not supported. +- */ +-fix = { +- hackname = darwin_api_availability; +- mach = "*-*-darwin*"; +- files = os/availability.h; +- bypass = "__IPHONE_OS_VERSION_MIN_REQUIRED"; +- select = +- " *#define __API_AVAILABLE.*\n" +- " *#define __API_DEPRECATED.*\n" +- " *#define __API_DEPRECATED_WITH_REPLACEMENT.*\n" +- " *#define __API_UNAVAILABLE.*\n"; +- c_fix = format; +- c_fix_arg = +- " #define API_AVAILABLE(...)\n" +- " #define API_DEPRECATED(...)\n" +- " #define API_DEPRECATED_WITH_REPLACEMENT(...)\n" +- " #define API_UNAVAILABLE(...)\n"; +- test_text = +- "#define __API_AVAILABLE(...)\n" +- "#define __API_DEPRECATED(...)\n" +- "#define __API_DEPRECATED_WITH_REPLACEMENT(...)\n" +- "#define __API_UNAVAILABLE(...)\n"; +-}; +- + /* + * This fixes __FD_ZERO bug for linux 2.x.y (x <= 2 && y <= some n) + */ +@@ -1273,6 +1246,7 @@ fix = { + hackname = apple_local_stdio_fn_deprecation; + mach = "*-*-*darwin2*"; + files = stdio.h; ++ files = _stdio.h; + select = "__deprecated_msg([^\n]*)$"; + c_fix = format; + c_fix_arg = "#if defined(__APPLE_LOCAL_DEPRECATIONS)\n" +@@ -1350,32 +1324,6 @@ fix = { + test_text = "extern void* malloc( size_t );"; + }; + +-/* +- * macOS 10.12 uses __attribute__((availability)) +- * unconditionally. +- */ +-fix = { +- hackname = darwin_availabilityinternal; +- mach = "*-*-darwin*"; +- files = AvailabilityInternal.h; +- select = "#define[ \t]+(__API_[ADU]\\([^)]*\\)).*"; +- c_fix = format; +- c_fix_arg = <<- _EOFix_ +- #if defined(__has_attribute) +- #if __has_attribute(availability) +- %0 +- #else +- #define %1 +- #endif +- #else +- #define %1 +- #endif +- _EOFix_; +- +- test_text = "#define __API_A(x) __attribute__((availability(__API_AVAILABLE_PLATFORM_##x)))\n" +- "#define __API_D(msg,x) __attribute__((availability(__API_DEPRECATED_PLATFORM_##x,message=msg)))"; +-}; +- + /* + * For the AAB_darwin7_9_long_double_funcs fix (and later fixes for long long) + * to be useful, the main math.h must use <> and not "" includes. +diff --git a/gcc/ada/init.c b/gcc/ada/init.c +index 7cf77471f1d..8d5acdd6fb6 100644 +--- a/gcc/ada/init.c ++++ b/gcc/ada/init.c +@@ -2479,7 +2479,10 @@ __gnat_map_signal (int sig, siginfo_t *si, void *mcontext ATTRIBUTE_UNUSED) + /* Reset the use of alt stack, so that the alt stack will be used + for the next signal delivery. + The stack can't be used in case of stack checking. */ ++#pragma GCC diagnostic push ++#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + syscall (SYS_sigreturn, NULL, UC_RESET_ALT_STACK); ++#pragma GCC diagnostic pop + break; + + case SIGFPE: +diff --git a/gcc/builtins.cc b/gcc/builtins.cc +index 7c1497561f7..9fc5300545c 100644 +--- a/gcc/builtins.cc ++++ b/gcc/builtins.cc +@@ -5929,6 +5929,13 @@ expand_builtin_trap (void) + static void + expand_builtin_unreachable (void) + { ++ /* If the target wants a trap in place of the fall-through, use that. */ ++ if (targetm.unreachable_should_trap ()) ++ { ++ expand_builtin_trap (); ++ return; ++ } ++ + /* Use gimple_build_builtin_unreachable or builtin_decl_unreachable + to avoid this. */ + gcc_checking_assert (!sanitize_flags_p (SANITIZE_UNREACHABLE)); +diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc +index 04e39b41bdf..6cb2637f3cf 100644 +--- a/gcc/c-family/c-attribs.cc ++++ b/gcc/c-family/c-attribs.cc +@@ -665,6 +665,18 @@ attribute_takes_identifier_p (const_tree attr_id) + return targetm.attribute_takes_identifier_p (attr_id); + } + ++/* Returns TRUE iff the attribute indicated by ATTR_ID needs its ++ arguments converted to string constants. */ ++ ++bool ++attribute_clang_form_p (const_tree attr_id) ++{ ++ const struct attribute_spec *spec = lookup_attribute_spec (attr_id); ++ if (spec && !strcmp ("availability", spec->name)) ++ return true; ++ return false; ++} ++ + /* Verify that argument value POS at position ARGNO to attribute NAME + applied to function FN (which is either a function declaration or function + type) refers to a function parameter at position POS and the expected type +diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc +index aae998d0f73..79dac5fccf3 100644 +--- a/gcc/c-family/c-common.cc ++++ b/gcc/c-family/c-common.cc +@@ -346,7 +346,11 @@ static constexpr hf_feature_info has_feature_table[] = + { "enumerator_attributes", HF_FLAG_NONE, 0 }, + { "tls", HF_FLAG_NONE, 0 }, + { "gnu_asm_goto_with_outputs", HF_FLAG_EXT, 0 }, +- { "gnu_asm_goto_with_outputs_full", HF_FLAG_EXT, 0 } ++ { "gnu_asm_goto_with_outputs_full", HF_FLAG_EXT, 0 }, ++ { "attribute_availability", HF_FLAG_NONE, 0 }, ++ { "attribute_availability_with_message", HF_FLAG_NONE, 0 }, ++ { "attribute_availability_with_replacement", HF_FLAG_NONE, 0 }, ++ { "attribute_availability_with_version_underscores", HF_FLAG_NONE, 0 } + }; + + /* Global visibility options. */ +diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h +index 2d5f5399885..78414d4519e 100644 +--- a/gcc/c-family/c-common.h ++++ b/gcc/c-family/c-common.h +@@ -1628,6 +1628,7 @@ extern void check_for_xor_used_as_pow (location_t lhs_loc, tree lhs_val, + /* In c-attribs.cc. */ + extern bool attribute_takes_identifier_p (const_tree); + extern tree handle_deprecated_attribute (tree *, tree, tree, int, bool *); ++extern bool attribute_clang_form_p (const_tree); + extern tree handle_unused_attribute (tree *, tree, tree, int, bool *); + extern tree handle_fallthrough_attribute (tree *, tree, tree, int, bool *); + extern int parse_tm_stmt_attr (tree, int); +diff --git a/gcc/c-family/c-lex.cc b/gcc/c-family/c-lex.cc +index ff5ce2bf729..d5cc6fa43a9 100644 +--- a/gcc/c-family/c-lex.cc ++++ b/gcc/c-family/c-lex.cc +@@ -584,6 +584,21 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags, + + case CPP_NUMBER: + { ++ /* If the user wants number-like entities to be returned as a raw ++ string, then don't try to classify them, which emits unwanted ++ diagnostics. */ ++ if (lex_flags & C_LEX_NUMBER_AS_STRING) ++ { ++ /* build_string adds a trailing NUL at [len]. */ ++ tree num_string = build_string (tok->val.str.len + 1, ++ (const char *) tok->val.str.text); ++ TREE_TYPE (num_string) = char_array_type_node; ++ *value = num_string; ++ /* We will effectively note this as CPP_N_INVALID, because we ++ made no checks here. */ ++ break; ++ } ++ + const char *suffix = NULL; + unsigned int flags = cpp_classify_number (parse_in, tok, &suffix, *loc); + +diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc +index f4dced8d826..4b45f83ca05 100644 +--- a/gcc/c-family/c-opts.cc ++++ b/gcc/c-family/c-opts.cc +@@ -1119,7 +1119,7 @@ c_common_post_options (const char **pfilename) + + if (flag_extern_tls_init) + { +- if (!TARGET_SUPPORTS_ALIASES || !SUPPORTS_WEAK) ++ if (!SUPPORTS_WEAK) + { + /* Lazy TLS initialization for a variable in another TU requires + alias and weak reference support. */ +diff --git a/gcc/c-family/c-pragma.h b/gcc/c-family/c-pragma.h +index ce93a52fa57..95828547713 100644 +--- a/gcc/c-family/c-pragma.h ++++ b/gcc/c-family/c-pragma.h +@@ -276,6 +276,9 @@ extern void pragma_lex_discard_to_eol (); + #define C_LEX_STRING_NO_JOIN 2 /* Do not concatenate strings + nor translate them into execution + character set. */ ++#define C_LEX_NUMBER_AS_STRING 4 /* Do not classify a number, but ++ instead return it as a raw ++ string. */ + + /* This is not actually available to pragma parsers. It's merely a + convenient location to declare this function for c-lex, after +diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt +index b310b40d857..418e87fa486 100644 +--- a/gcc/c-family/c.opt ++++ b/gcc/c-family/c.opt +@@ -1708,6 +1708,10 @@ static-libmpxwrappers + Driver WarnRemoved + Removed in GCC 9. This switch has no effect. + ++fallow-extended-attribute-placement ++C ObjC C++ ObjC++ LTO Var(flag_allow_ext_attr_placement) Init(0) ++Allow placement of attributes on function definitions. ++ + fcilkplus + C ObjC C++ ObjC++ LTO Undocumented Ignore + Removed in GCC 8. This switch has no effect. +diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc +index 5fcfff7134a..3ce7dd8b914 100644 +--- a/gcc/c/c-parser.cc ++++ b/gcc/c/c-parser.cc +@@ -217,6 +217,9 @@ struct GTY(()) c_parser { + should translate them to the execution character set (false + inside attributes). */ + BOOL_BITFIELD translate_strings_p : 1; ++ /* True if we want to lex arbitrary number-like sequences as their ++ string representation. */ ++ BOOL_BITFIELD lex_number_as_string : 1; + + /* Objective-C specific parser/lexer information. */ + +@@ -308,10 +311,10 @@ c_lex_one_token (c_parser *parser, c_token *token, bool raw = false) + + if (raw || vec_safe_length (parser->raw_tokens) == 0) + { ++ int lex_flags = parser->lex_joined_string ? 0 : C_LEX_STRING_NO_JOIN; ++ lex_flags |= parser->lex_number_as_string ? C_LEX_NUMBER_AS_STRING : 0; + token->type = c_lex_with_flags (&token->value, &token->location, +- &token->flags, +- (parser->lex_joined_string +- ? 0 : C_LEX_STRING_NO_JOIN)); ++ &token->flags, lex_flags); + token->id_kind = C_ID_NONE; + token->keyword = RID_MAX; + token->pragma_kind = PRAGMA_NONE; +@@ -2579,15 +2582,28 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, + d = d->declarator; + underspec_name = d->u.id.id; + } ++ tree postfix_attrs = NULL_TREE; ++ if (flag_allow_ext_attr_placement ++ && c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) ++ { ++ postfix_attrs = c_parser_gnu_attributes (parser); ++ /* IF we have a function definition, and we're allowing it then ++ treat these attributes as if they had been prepended. */ ++ if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) ++ { ++ all_prefix_attrs = chainon (all_prefix_attrs, postfix_attrs); ++ postfix_attrs = NULL_TREE; ++ } ++ } + if (c_parser_next_token_is (parser, CPP_EQ) + || c_parser_next_token_is (parser, CPP_COMMA) + || c_parser_next_token_is (parser, CPP_SEMICOLON) + || c_parser_next_token_is_keyword (parser, RID_ASM) + || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE) ++ || postfix_attrs + || c_parser_next_token_is_keyword (parser, RID_IN)) + { + tree asm_name = NULL_TREE; +- tree postfix_attrs = NULL_TREE; + if (!diagnosed_no_specs && !specs->declspecs_seen_p) + { + diagnosed_no_specs = true; +@@ -2599,8 +2615,9 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, + if (c_parser_next_token_is_keyword (parser, RID_ASM)) + asm_name = c_parser_simple_asm_expr (parser); + if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) ++ postfix_attrs = c_parser_gnu_attributes (parser); ++ if (postfix_attrs) + { +- postfix_attrs = c_parser_gnu_attributes (parser); + if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) + { + /* This means there is an attribute specifier after +@@ -5213,6 +5230,88 @@ c_parser_gnu_attribute_any_word (c_parser *parser) + return attr_name; + } + ++/* Handle parsing clang-form attribute arguments, where we need to adjust ++ the parsing rules to relate to a specific attribute. */ ++ ++static tree ++c_parser_clang_attribute_arguments (c_parser *parser, tree /*attr_id*/) ++{ ++ /* We can, if required, alter the parsing on the basis of the attribute. ++ At present, we handle the availability attr, where ach entry can be : ++ identifier ++ identifier=N.MM.Z ++ identifier="string" ++ followed by ',' or ) for the last entry*/ ++ ++ tree attr_args = NULL_TREE; ++ do ++ { ++ tree name = NULL_TREE; ++ tree value = NULL_TREE; ++ ++ if (c_parser_next_token_is (parser, CPP_NAME) ++ && c_parser_peek_token (parser)->id_kind == C_ID_ID) ++ { ++ name = c_parser_peek_token (parser)->value; ++ c_parser_consume_token (parser); ++ } ++ else if (c_parser_next_token_is (parser, CPP_COMMA)) ++ name = error_mark_node; /* Comma handled below. */ ++ else ++ { ++ bool saved_join_state = parser->lex_joined_string; ++ parser->lex_number_as_string = 1; ++ parser->lex_joined_string = 1; ++ c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, ++ "expected an attribute keyword"); ++ parser->lex_number_as_string = 0; ++ parser->lex_joined_string = saved_join_state; ++ return error_mark_node; ++ } ++ if (c_parser_next_token_is (parser, CPP_EQ)) ++ { ++ c_parser_consume_token (parser); /* eat the '=' */ ++ /* We need to bludgeon the lexer into not trying to interpret the ++ xx.yy.zz form, since that just looks like a malformed float. ++ Also, as a result of macro processing, we can have strig literals ++ that are in multiple pieces so, for this specific part of the ++ parse, we need to join strings. */ ++ bool saved_join_state = parser->lex_joined_string; ++ parser->lex_number_as_string = 1; ++ parser->lex_joined_string = 1; ++ /* So look at the next token, expecting a string, or something that ++ looks initially like a number, but might be a version number. */ ++ c_parser_peek_token (parser); ++ /* Done with the funky number parsing. */ ++ parser->lex_number_as_string = 0; ++ parser->lex_joined_string = saved_join_state; ++ if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN) ++ && c_parser_next_token_is_not (parser, CPP_COMMA)) ++ { ++ value = c_parser_peek_token (parser)->value; ++ /* ???: check for error mark and early-return? */ ++ c_parser_consume_token (parser); ++ } ++ /* else value is absent. */ ++ } ++ else if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN) ++ && c_parser_next_token_is_not (parser, CPP_COMMA)) ++ { ++ c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, ++ "expected %<,%> or %<=%>"); ++ return error_mark_node; ++ } ++ if (c_parser_next_token_is (parser, CPP_COMMA)) ++ c_parser_consume_token (parser); /* Just skip the comma. */ ++ tree t = tree_cons (value, name, NULL); ++ if (!attr_args) ++ attr_args = t; ++ else ++ chainon (attr_args, t); ++ } while (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN)); ++ return attr_args; ++} ++ + /* Parse attribute arguments. This is a common form of syntax + covering all currently valid GNU and standard attributes. + +@@ -5378,9 +5477,13 @@ c_parser_gnu_attribute (c_parser *parser, tree attrs, + attrs = chainon (attrs, attr); + return attrs; + } +- c_parser_consume_token (parser); ++ c_parser_consume_token (parser); /* The '('. */ + +- tree attr_args ++ tree attr_args; ++ if (attribute_clang_form_p (attr_name)) ++ attr_args = c_parser_clang_attribute_arguments (parser, attr_name); ++ else ++ attr_args + = c_parser_attribute_arguments (parser, + attribute_takes_identifier_p (attr_name), + false, +diff --git a/gcc/calls.cc b/gcc/calls.cc +index 21d78f9779f..d84998668a4 100644 +--- a/gcc/calls.cc ++++ b/gcc/calls.cc +@@ -1376,7 +1376,8 @@ initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED, + with those made by function.cc. */ + + /* See if this argument should be passed by invisible reference. */ +- function_arg_info arg (type, argpos < n_named_args); ++ function_arg_info arg (type, argpos < n_named_args, ++ argpos == n_named_args - 1); + if (pass_by_reference (args_so_far_pnt, arg)) + { + const bool callee_copies +@@ -1496,10 +1497,13 @@ initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED, + + unsignedp = TYPE_UNSIGNED (type); + arg.type = type; +- arg.mode +- = promote_function_mode (type, TYPE_MODE (type), &unsignedp, +- fndecl ? TREE_TYPE (fndecl) : fntype, 0); +- ++ arg.mode = TYPE_MODE (type); ++// arg.mode ++// = promote_function_mode (type, TYPE_MODE (type), &unsignedp, ++// fndecl ? TREE_TYPE (fndecl) : fntype, 0); ++ arg.mode = promote_function_mode (args_so_far, arg, ++ fndecl ? TREE_TYPE (fndecl) : fntype, ++ &unsignedp, 0); + args[i].unsignedp = unsignedp; + args[i].mode = arg.mode; + +@@ -1549,6 +1553,7 @@ initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED, + #endif + reg_parm_stack_space, + args[i].pass_on_stack ? 0 : args[i].partial, ++ args_so_far, + fndecl, args_size, &args[i].locate); + #ifdef BLOCK_REG_PADDING + else +@@ -4096,6 +4101,7 @@ split_complex_types (tree types) + return types; + } + ++extern void debug_tree (tree); + /* Output a library call to function ORGFUN (a SYMBOL_REF rtx) + for a value of mode OUTMODE, + with NARGS different arguments, passed as ARGS. +@@ -4281,6 +4287,7 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value, + argvec[count].reg != 0, + #endif + reg_parm_stack_space, 0, ++ args_so_far, + NULL_TREE, &args_size, &argvec[count].locate); + + if (argvec[count].reg == 0 || argvec[count].partial != 0 +@@ -4351,8 +4358,16 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value, + val = force_operand (XEXP (slot, 0), NULL_RTX); + } + +- arg.mode = promote_function_mode (NULL_TREE, arg.mode, &unsigned_p, +- NULL_TREE, 0); ++// arg.mode = promote_function_mode (NULL_TREE, arg.mode, &unsigned_p, ++// NULL_TREE, 0); ++ tree t = arg.type; ++if (t) ++ debug_tree (t); ++gcc_assert (!t); ++ arg.type = NULL_TREE; ++ arg.mode = promote_function_mode (args_so_far, arg, NULL_TREE, ++ &unsigned_p, 0); ++ arg.type = t; + argvec[count].mode = arg.mode; + argvec[count].value = convert_modes (arg.mode, GET_MODE (val), val, + unsigned_p); +@@ -4372,6 +4387,7 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value, + argvec[count].reg != 0, + #endif + reg_parm_stack_space, argvec[count].partial, ++ args_so_far, + NULL_TREE, &args_size, &argvec[count].locate); + args_size.constant += argvec[count].locate.size.constant; + gcc_assert (!argvec[count].locate.size.var); +diff --git a/gcc/calls.h b/gcc/calls.h +index 464a4e34e33..499f7560ee8 100644 +--- a/gcc/calls.h ++++ b/gcc/calls.h +@@ -35,24 +35,43 @@ class function_arg_info + { + public: + function_arg_info () +- : type (NULL_TREE), mode (VOIDmode), named (false), ++ : type (NULL_TREE), mode (VOIDmode), named (false), last_named (false), + pass_by_reference (false) + {} + + /* Initialize an argument of mode MODE, either before or after promotion. */ + function_arg_info (machine_mode mode, bool named) +- : type (NULL_TREE), mode (mode), named (named), pass_by_reference (false) ++ : type (NULL_TREE), mode (mode), named (named), last_named (false), ++ pass_by_reference (false) ++ {} ++ ++ function_arg_info (machine_mode mode, bool named, bool last_named) ++ : type (NULL_TREE), mode (mode), named (named), last_named (last_named), ++ pass_by_reference (false) + {} + + /* Initialize an unpromoted argument of type TYPE. */ + function_arg_info (tree type, bool named) +- : type (type), mode (TYPE_MODE (type)), named (named), ++ : type (type), mode (TYPE_MODE (type)), named (named), last_named (false), + pass_by_reference (false) + {} + ++ /* Initialize an unpromoted argument of type TYPE. */ ++ function_arg_info (tree type, bool named, bool last_named) ++ : type (type), mode (TYPE_MODE (type)), named (named), ++ last_named (last_named), pass_by_reference (false) ++ {} ++ + /* Initialize an argument with explicit properties. */ + function_arg_info (tree type, machine_mode mode, bool named) +- : type (type), mode (mode), named (named), pass_by_reference (false) ++ : type (type), mode (mode), named (named), last_named (false), ++ pass_by_reference (false) ++ {} ++ ++ /* Initialize an argument with explicit properties. */ ++ function_arg_info (tree type, machine_mode mode, bool named, bool last_named) ++ : type (type), mode (mode), named (named), last_named (last_named), ++ pass_by_reference (false) + {} + + /* Return true if the gimple-level type is an aggregate. */ +@@ -105,6 +124,9 @@ public: + "..."). See also TARGET_STRICT_ARGUMENT_NAMING. */ + unsigned int named : 1; + ++ /* True if this is the last named argument. */ ++ unsigned int last_named : 1; ++ + /* True if we have decided to pass the argument by reference, in which case + the function_arg_info describes a pointer to the original argument. */ + unsigned int pass_by_reference : 1; +diff --git a/gcc/collect2.cc b/gcc/collect2.cc +index 902014a9cc1..a7ca609334a 100644 +--- a/gcc/collect2.cc ++++ b/gcc/collect2.cc +@@ -73,7 +73,7 @@ along with GCC; see the file COPYING3. If not see + In a cross-compiler, this means you need a cross nm, + but that is not quite as unpleasant as special headers. */ + +-#if !defined (OBJECT_FORMAT_COFF) ++#if !defined (OBJECT_FORMAT_COFF) && !defined (OBJECT_FORMAT_MACHO) + #define OBJECT_FORMAT_NONE + #endif + +@@ -107,7 +107,7 @@ along with GCC; see the file COPYING3. If not see + + #endif /* OBJECT_FORMAT_COFF */ + +-#ifdef OBJECT_FORMAT_NONE ++#if defined (OBJECT_FORMAT_NONE) || defined (OBJECT_FORMAT_MACHO) + + /* Default flags to pass to nm. */ + #ifndef NM_FLAGS +@@ -525,7 +525,7 @@ static const char *const target_machine = TARGET_MACHINE; + + Return 0 if not found, otherwise return its name, allocated with malloc. */ + +-#ifdef OBJECT_FORMAT_NONE ++#if defined (OBJECT_FORMAT_NONE) || defined (OBJECT_FORMAT_MACHO) + + /* Add an entry for the object file NAME to object file list LIST. + New entries are added at the end of the list. The original pointer +@@ -764,6 +764,12 @@ do_link (char **ld_argv, const char *atsuffix) + } + } + ++#if defined (OBJECT_FORMAT_MACHO) ++# define LLD_NAME "ld64.lld" ++#else ++# define LLD_NAME "ld.lld" ++#endif ++ + /* Main program. */ + + int +@@ -777,16 +783,19 @@ main (int argc, char **argv) + USE_BFD_LD, + USE_LLD_LD, + USE_MOLD_LD, ++ USE_CLASSIC_LD, + USE_LD_MAX + } selected_linker = USE_DEFAULT_LD; ++ + static const char *const ld_suffixes[USE_LD_MAX] = + { + "ld", + PLUGIN_LD_SUFFIX, + "ld.gold", + "ld.bfd", +- "ld.lld", +- "ld.mold" ++ LLD_NAME, ++ "ld.mold", ++ "ld-classic" + }; + static const char *const real_ld_suffix = "real-ld"; + static const char *const collect_ld_suffix = "collect-ld"; +@@ -868,7 +877,7 @@ main (int argc, char **argv) + #ifdef CROSS_DIRECTORY_STRUCTURE + /* lld and mold are platform-agnostic and not prefixed with target + triple. */ +- if (!(i == USE_LLD_LD || i == USE_MOLD_LD)) ++ if (!(i == USE_LLD_LD || i == USE_MOLD_LD || i == USE_CLASSIC_LD)) + full_ld_suffixes[i] = concat (target_machine, "-", ld_suffixes[i], + NULL); + else +@@ -956,14 +965,22 @@ main (int argc, char **argv) + if (selected_linker == USE_DEFAULT_LD) + selected_linker = USE_PLUGIN_LD; + } ++#if !defined (OBJECT_FORMAT_MACHO) + else if (strcmp (argv[i], "-fuse-ld=bfd") == 0) + selected_linker = USE_BFD_LD; + else if (strcmp (argv[i], "-fuse-ld=gold") == 0) + selected_linker = USE_GOLD_LD; ++#endif + else if (strcmp (argv[i], "-fuse-ld=lld") == 0) + selected_linker = USE_LLD_LD; + else if (strcmp (argv[i], "-fuse-ld=mold") == 0) + selected_linker = USE_MOLD_LD; ++#if defined (OBJECT_FORMAT_MACHO) ++ else if (strcmp (argv[i], "-fuse-ld=classic") == 0) ++ selected_linker = USE_CLASSIC_LD; ++#endif ++ else if (strcmp (argv[i], "-fuse-ld=") == 0) ++ selected_linker = USE_DEFAULT_LD; + else if (startswith (argv[i], "-o")) + { + /* Parse the output filename if it's given so that we can make +@@ -1055,7 +1072,8 @@ main (int argc, char **argv) + ld_file_name = 0; + #ifdef DEFAULT_LINKER + if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD || +- selected_linker == USE_LLD_LD || selected_linker == USE_MOLD_LD) ++ selected_linker == USE_LLD_LD || selected_linker == USE_MOLD_LD || ++ selected_linker == USE_CLASSIC_LD) + { + char *linker_name; + # ifdef HOST_EXECUTABLE_SUFFIX +@@ -2270,7 +2288,7 @@ write_aix_file (FILE *stream, struct id *list) + } + #endif + +-#ifdef OBJECT_FORMAT_NONE ++#if defined (OBJECT_FORMAT_NONE) || defined (OBJECT_FORMAT_MACHO) + + /* Check to make sure the file is an LTO object file. */ + +diff --git a/gcc/common.opt b/gcc/common.opt +index ad348844775..cde259257b7 100644 +--- a/gcc/common.opt ++++ b/gcc/common.opt +@@ -2919,6 +2919,10 @@ fstack-usage + Common RejectNegative Var(flag_stack_usage) + Output stack usage information on a per-function basis. + ++fstack-use-cumulative-args ++Common RejectNegative Var(flag_stack_use_cumulative_args) Init(STACK_USE_CUMULATIVE_ARGS_INIT) ++Use cumulative args-based stack layout hooks. ++ + fstrength-reduce + Common Ignore + Does nothing. Preserved for backward compatibility. +@@ -3292,6 +3296,10 @@ fuse-ld=mold + Common Driver Negative(fuse-ld=mold) + Use the Modern linker (MOLD) linker instead of the default linker. + ++fuse-ld=classic ++Common Driver Negative(fuse-ld=classic) ++Use the ld-classic linker instead of the default linker. ++ + fuse-linker-plugin + Common Undocumented Var(flag_use_linker_plugin) + +diff --git a/gcc/common/config/aarch64/aarch64-common.cc b/gcc/common/config/aarch64/aarch64-common.cc +index 951d041d310..496d0d82e05 100644 +--- a/gcc/common/config/aarch64/aarch64-common.cc ++++ b/gcc/common/config/aarch64/aarch64-common.cc +@@ -298,8 +298,12 @@ aarch64_get_extension_string_for_isa_flags + + However, assemblers with Armv8-R AArch64 support should not have this + issue, so we don't need this fix when targeting Armv8-R. */ +- auto explicit_flags = (!(current_flags & AARCH64_FL_V8R) +- ? AARCH64_FL_CRC : 0); ++ aarch64_feature_flags explicit_flags = ++#ifndef DISABLE_AARCH64_AS_CRC_BUGFIX ++ (!(current_flags & AARCH64_ISA_V8R) ? AARCH64_FL_CRC : 0); ++#else ++ 0; ++#endif + + /* Add the features in isa_flags & ~current_flags using the smallest + possible number of extensions. We can do this by iterating over the +@@ -329,7 +333,10 @@ aarch64_get_extension_string_for_isa_flags + if (added & opt.flag_canonical) + { + outstr += "+"; +- outstr += opt.name; ++ if (startswith (opt.name, "rdm")) ++ outstr += "rdm"; ++ else ++ outstr += opt.name; + } + + /* Remove the features in current_flags & ~isa_flags. If the feature does +@@ -358,7 +365,10 @@ aarch64_get_extension_string_for_isa_flags + { + current_flags &= ~opt.flags_off; + outstr += "+no"; +- outstr += opt.name; ++ if (startswith (opt.name, "rdm")) ++ outstr += "rdm"; ++ else ++ outstr += opt.name; + } + } + +diff --git a/gcc/config.gcc b/gcc/config.gcc +index 95c91ee02be..381e27dc759 100644 +--- a/gcc/config.gcc ++++ b/gcc/config.gcc +@@ -1177,13 +1177,22 @@ case ${target} in + ;; + esac + +-# Figure out if we need to enable heap trampolines by default ++# Figure out if we need to enable heap trampolines ++# and variadic functions handling. + case ${target} in ++aarch64*-*-darwin2*) ++ # This applies to arm64 Darwin variadic funtions. ++ tm_defines="$tm_defines STACK_USE_CUMULATIVE_ARGS_INIT=1" ++ # Executable stack is forbidden. ++ tm_defines="$tm_defines HEAP_TRAMPOLINES_INIT=1" ++ ;; + *-*-darwin2*) ++ tm_defines="$tm_defines STACK_USE_CUMULATIVE_ARGS_INIT=0" + # Currently, we do this for macOS 11 and above. + tm_defines="$tm_defines HEAP_TRAMPOLINES_INIT=1" + ;; + *) ++ tm_defines="$tm_defines STACK_USE_CUMULATIVE_ARGS_INIT=0" + tm_defines="$tm_defines HEAP_TRAMPOLINES_INIT=0" + ;; + esac +@@ -1227,6 +1236,14 @@ aarch64*-*-elf | aarch64*-*-fuchsia* | aarch64*-*-rtems*) + done + TM_MULTILIB_CONFIG=`echo $TM_MULTILIB_CONFIG | sed 's/^,//'` + ;; ++aarch64-*-darwin* ) ++ tm_file="${tm_file} aarch64/aarch64-errata.h" ++ tmake_file="${tmake_file} aarch64/t-aarch64 aarch64/t-aarch64-darwin" ++ tm_defines="${tm_defines} TARGET_DEFAULT_ASYNC_UNWIND_TABLES=1" ++ tm_defines="${tm_defines} DISABLE_AARCH64_AS_CRC_BUGFIX=1" ++ # Choose a default CPU version that will work for all current releases. ++ with_cpu=${with_cpu:-apple-m1} ++ ;; + aarch64*-*-freebsd*) + tm_file="${tm_file} elfos.h ${fbsd_tm_file}" + tm_file="${tm_file} aarch64/aarch64-elf.h aarch64/aarch64-errata.h aarch64/aarch64-freebsd.h" +diff --git a/gcc/config/aarch64/aarch64-builtins.cc b/gcc/config/aarch64/aarch64-builtins.cc +index 75d21de1401..c54dcd941a3 100644 +--- a/gcc/config/aarch64/aarch64-builtins.cc ++++ b/gcc/config/aarch64/aarch64-builtins.cc +@@ -788,6 +788,8 @@ enum aarch64_builtins + AARCH64_PLDX, + AARCH64_PLI, + AARCH64_PLIX, ++ /* OS-specific */ ++ AARCH64_BUILTIN_CFSTRING, + AARCH64_BUILTIN_MAX + }; + +@@ -887,6 +889,9 @@ tree aarch64_fp16_ptr_type_node = NULL_TREE; + /* Back-end node type for brain float (bfloat) types. */ + tree aarch64_bf16_ptr_type_node = NULL_TREE; + ++/* Pointer to __float128 on Mach-O, where the 128b float is not long double. */ ++tree aarch64_float128_ptr_type_node = NULL_TREE; ++ + /* Wrapper around add_builtin_function. NAME is the name of the built-in + function, TYPE is the function type, CODE is the function subcode + (relative to AARCH64_BUILTIN_GENERAL), and ATTRS is the function +@@ -1662,6 +1667,29 @@ aarch64_init_bf16_types (void) + aarch64_bf16_ptr_type_node = build_pointer_type (bfloat16_type_node); + } + ++/* Initialize the backend REAL_TYPE type supporting __float128 on Mach-O, ++ as well as the related built-ins. */ ++static void ++aarch64_init_float128_types (void) ++{ ++ /* The __float128 type. The node has already been created as ++ _Float128, so for C we only need to register the __float128 name for ++ it. For C++, we create a distinct type which will mangle differently ++ (g) vs. _Float128 (DF128_) and behave backwards compatibly. */ ++ if (float128t_type_node == NULL_TREE) ++ { ++ float128t_type_node = make_node (REAL_TYPE); ++ TYPE_PRECISION (float128t_type_node) ++ = TYPE_PRECISION (float128_type_node); ++ SET_TYPE_MODE (float128t_type_node, TYPE_MODE (float128_type_node)); ++ layout_type (float128t_type_node); ++ } ++ lang_hooks.types.register_builtin_type (float128t_type_node, "__float128"); ++ ++ aarch64_float128_ptr_type_node = build_pointer_type (float128t_type_node); ++} ++ ++ + /* Pointer authentication builtins that will become NOP on legacy platform. + Currently, these builtins are for internal use only (libgcc EH unwinder). */ + +@@ -2047,8 +2075,9 @@ aarch64_general_init_builtins (void) + aarch64_init_fpsr_fpcr_builtins (); + + aarch64_init_fp16_types (); +- + aarch64_init_bf16_types (); ++ if (TARGET_MACHO) ++ aarch64_init_float128_types (); + + { + aarch64_simd_switcher simd; +@@ -2088,6 +2117,14 @@ aarch64_general_init_builtins (void) + handle_arm_acle_h (); + } + ++void ++aarch64_init_subtarget_builtins (void) ++{ ++#ifdef SUBTARGET_INIT_BUILTINS ++ SUBTARGET_INIT_BUILTINS; ++#endif ++} ++ + /* Implement TARGET_BUILTIN_DECL for the AARCH64_BUILTIN_GENERAL group. */ + tree + aarch64_general_builtin_decl (unsigned code, bool) +diff --git a/gcc/config/aarch64/aarch64-c.cc b/gcc/config/aarch64/aarch64-c.cc +index 2aff097dd33..2ebaa1554a0 100644 +--- a/gcc/config/aarch64/aarch64-c.cc ++++ b/gcc/config/aarch64/aarch64-c.cc +@@ -285,6 +285,16 @@ aarch64_cpu_cpp_builtins (cpp_reader *pfile) + { + aarch64_define_unconditional_macros (pfile); + aarch64_update_cpp_builtins (pfile); ++ ++ if (TARGET_MACHO) ++ { ++ builtin_define ("__builtin_copysignq=__builtin_copysignf128"); ++ builtin_define ("__builtin_fabsq=__builtin_fabsf128"); ++ builtin_define ("__builtin_huge_valq=__builtin_huge_valf128"); ++ builtin_define ("__builtin_infq=__builtin_inff128"); ++ builtin_define ("__builtin_nanq=__builtin_nanf128"); ++ builtin_define ("__builtin_nansq=__builtin_nansf128"); ++ } + } + + /* Hook to validate the current #pragma GCC target and set the state, and +@@ -424,4 +434,8 @@ aarch64_register_pragmas (void) + targetm.check_builtin_call = aarch64_check_builtin_call; + + c_register_pragma ("GCC", "aarch64", aarch64_pragma_aarch64); ++ ++#ifdef REGISTER_SUBTARGET_PRAGMAS ++ REGISTER_SUBTARGET_PRAGMAS (); ++#endif + } +diff --git a/gcc/config/aarch64/aarch64-cores.def b/gcc/config/aarch64/aarch64-cores.def +index f5536388f61..e1e05059456 100644 +--- a/gcc/config/aarch64/aarch64-cores.def ++++ b/gcc/config/aarch64/aarch64-cores.def +@@ -166,6 +166,17 @@ AARCH64_CORE("cortex-a76.cortex-a55", cortexa76cortexa55, cortexa53, V8_2A, (F + /* Armv8-R Architecture Processors. */ + AARCH64_CORE("cortex-r82", cortexr82, cortexa53, V8R, (), cortexa53, 0x41, 0xd15, -1) + ++/* Apple (A12 and M) cores. ++ Apple implementer ID from xnu, ++ guesses for part #, guesses for scheduler ident, generic_armv8_a for costs. ++ A12 seems mostly 8.3, ++ M1 seems to be 8.4 + extras (see comments in option-extensions about f16fml), ++ M2 mostly 8.5 but with missing mandatory features. */ ++AARCH64_CORE("apple-a12", applea12, cortexa53, V8_3A, (), generic_armv8_a, 0x61, 0x12, -1) ++AARCH64_CORE("apple-m1", applem1, cortexa57, V8_4A, (F16, SB, SSBS), generic_armv8_a, 0x61, 0x23, -1) ++AARCH64_CORE("apple-m2", applem2, cortexa57, V8_4A, (I8MM, BF16, F16, SB, SSBS), generic_armv8_a, 0x61, 0x23, -1) ++AARCH64_CORE("apple-m3", applem3, cortexa57, V8_4A, (I8MM, BF16, F16, SB, SSBS), generic_armv8_a, 0x61, 0x23, -1) ++ + /* Armv9.0-A Architecture Processors. */ + + /* Arm ('A') cores. */ +diff --git a/gcc/config/aarch64/aarch64-protos.h b/gcc/config/aarch64/aarch64-protos.h +index 42639e9efcf..192a9da99bb 100644 +--- a/gcc/config/aarch64/aarch64-protos.h ++++ b/gcc/config/aarch64/aarch64-protos.h +@@ -109,6 +109,14 @@ enum aarch64_symbol_type + SYMBOL_TLSLE24, + SYMBOL_TLSLE32, + SYMBOL_TLSLE48, ++ SYMBOL_MO_SMALL_ABS, ++ SYMBOL_MO_SMALL_PCR, ++ SYMBOL_MO_SMALL_GOT, ++ SYMBOL_MO_SMALL_TLS, ++ SYMBOL_MO_LARGE_ABS, ++ SYMBOL_MO_LARGE_PCR, ++ SYMBOL_MO_LARGE_GOT, ++ SYMBOL_MO_LARGE_TLS, + SYMBOL_FORCE_TO_MEM + }; + +@@ -748,6 +756,7 @@ void aarch64_post_cfi_startproc (void); + poly_int64 aarch64_initial_elimination_offset (unsigned, unsigned); + int aarch64_get_condition_code (rtx); + bool aarch64_address_valid_for_prefetch_p (rtx, bool); ++bool aarch64_address_valid_for_unscaled_prefetch_p (rtx, bool); + bool aarch64_bitmask_imm (unsigned HOST_WIDE_INT val, machine_mode); + unsigned HOST_WIDE_INT aarch64_and_split_imm1 (HOST_WIDE_INT val_in); + unsigned HOST_WIDE_INT aarch64_and_split_imm2 (HOST_WIDE_INT val_in); +@@ -782,7 +791,11 @@ bool aarch64_is_extend_from_extract (scalar_int_mode, rtx, rtx); + bool aarch64_is_long_call_p (rtx); + bool aarch64_is_noplt_call_p (rtx); + bool aarch64_label_mentioned_p (rtx); ++#if TARGET_MACHO ++void aarch64_darwin_declare_function_name (FILE *, const char*, tree ); ++#else + void aarch64_declare_function_name (FILE *, const char*, tree); ++#endif + void aarch64_asm_output_alias (FILE *, const tree, const tree); + void aarch64_asm_output_external (FILE *, tree, const char*); + bool aarch64_legitimate_pic_operand_p (rtx); +@@ -999,6 +1012,7 @@ void aarch64_override_options_internal (struct gcc_options *); + + const char *aarch64_general_mangle_builtin_type (const_tree); + void aarch64_general_init_builtins (void); ++void aarch64_init_subtarget_builtins (void); + tree aarch64_general_fold_builtin (unsigned int, tree, unsigned int, tree *); + gimple *aarch64_general_gimple_fold_builtin (unsigned int, gcall *, + gimple_stmt_iterator *); +diff --git a/gcc/config/aarch64/aarch64-tune.md b/gcc/config/aarch64/aarch64-tune.md +index 80254836e0e..36c551cfd6a 100644 +--- a/gcc/config/aarch64/aarch64-tune.md ++++ b/gcc/config/aarch64/aarch64-tune.md +@@ -1,5 +1,5 @@ + ;; -*- buffer-read-only: t -*- + ;; Generated automatically by gentune.sh from aarch64-cores.def + (define_attr "tune" +- "cortexa34,cortexa35,cortexa53,cortexa57,cortexa72,cortexa73,thunderx,thunderxt88p1,thunderxt88,octeontx,octeontxt81,octeontxt83,thunderxt81,thunderxt83,ampere1,ampere1a,ampere1b,emag,xgene1,falkor,qdf24xx,exynosm1,phecda,thunderx2t99p1,vulcan,thunderx2t99,cortexa55,cortexa75,cortexa76,cortexa76ae,cortexa77,cortexa78,cortexa78ae,cortexa78c,cortexa65,cortexa65ae,cortexx1,cortexx1c,neoversen1,ares,neoversee1,octeontx2,octeontx2t98,octeontx2t96,octeontx2t93,octeontx2f95,octeontx2f95n,octeontx2f95mm,a64fx,tsv110,thunderx3t110,neoversev1,zeus,neoverse512tvb,saphira,cortexa57cortexa53,cortexa72cortexa53,cortexa73cortexa35,cortexa73cortexa53,cortexa75cortexa55,cortexa76cortexa55,cortexr82,cortexa510,cortexa520,cortexa710,cortexa715,cortexa720,cortexx2,cortexx3,cortexx4,neoversen2,cobalt100,neoversev2,grace,demeter,generic,generic_armv8_a,generic_armv9_a" ++ "cortexa34,cortexa35,cortexa53,cortexa57,cortexa72,cortexa73,thunderx,thunderxt88p1,thunderxt88,octeontx,octeontxt81,octeontxt83,thunderxt81,thunderxt83,ampere1,ampere1a,ampere1b,emag,xgene1,falkor,qdf24xx,exynosm1,phecda,thunderx2t99p1,vulcan,thunderx2t99,cortexa55,cortexa75,cortexa76,cortexa76ae,cortexa77,cortexa78,cortexa78ae,cortexa78c,cortexa65,cortexa65ae,cortexx1,cortexx1c,neoversen1,ares,neoversee1,octeontx2,octeontx2t98,octeontx2t96,octeontx2t93,octeontx2f95,octeontx2f95n,octeontx2f95mm,a64fx,tsv110,thunderx3t110,neoversev1,zeus,neoverse512tvb,saphira,cortexa57cortexa53,cortexa72cortexa53,cortexa73cortexa35,cortexa73cortexa53,cortexa75cortexa55,cortexa76cortexa55,cortexr82,applea12,applem1,applem2,applem3,cortexa510,cortexa520,cortexa710,cortexa715,cortexa720,cortexx2,cortexx3,cortexx4,neoversen2,cobalt100,neoversev2,grace,demeter,generic,generic_armv8_a,generic_armv9_a" + (const (symbol_ref "((enum attr_tune) aarch64_tune)"))) +diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc +index 1beec94629d..f12b1a308ea 100644 +--- a/gcc/config/aarch64/aarch64.cc ++++ b/gcc/config/aarch64/aarch64.cc +@@ -329,8 +329,10 @@ static bool aarch64_vfp_is_call_or_return_candidate (machine_mode, + const_tree, + machine_mode *, int *, + bool *, bool); ++#if !TARGET_MACHO + static void aarch64_elf_asm_constructor (rtx, int) ATTRIBUTE_UNUSED; + static void aarch64_elf_asm_destructor (rtx, int) ATTRIBUTE_UNUSED; ++#endif + static void aarch64_override_options_after_change (void); + static bool aarch64_vector_mode_supported_p (machine_mode); + static int aarch64_address_cost (rtx, machine_mode, addr_space_t, bool); +@@ -848,6 +850,9 @@ static const attribute_spec aarch64_gnu_attributes[] = + { + /* { name, min_len, max_len, decl_req, type_req, fn_type_req, + affects_type_identity, handler, exclude } */ ++#ifdef SUBTARGET_ATTRIBUTE_TABLE ++ SUBTARGET_ATTRIBUTE_TABLE, ++#endif + { "aarch64_vector_pcs", 0, 0, false, true, true, true, + handle_aarch64_vector_pcs_attribute, NULL }, + { "arm_sve_vector_bits", 1, 1, false, true, false, true, +@@ -2067,7 +2072,7 @@ aarch64_hard_regno_mode_ok (unsigned regno, machine_mode mode) + if (known_le (GET_MODE_SIZE (mode), 8)) + return true; + if (known_le (GET_MODE_SIZE (mode), 16)) +- return (regno & 1) == 0; ++ return (regno & 1) == 0 || TARGET_MACHO; /* darwinpcs D.4 */ + } + else if (FP_REGNUM_P (regno)) + { +@@ -2113,8 +2118,10 @@ static bool + aarch64_takes_arguments_in_sve_regs_p (const_tree fntype) + { + CUMULATIVE_ARGS args_so_far_v; ++ /* This does not apply to variadic functions, so all the (currently ++ uncounted) arguments must be named. */ + aarch64_init_cumulative_args (&args_so_far_v, NULL_TREE, NULL_RTX, +- NULL_TREE, 0, true); ++ NULL_TREE, -1, true); + cumulative_args_t args_so_far = pack_cumulative_args (&args_so_far_v); + + for (tree chain = TYPE_ARG_TYPES (fntype); +@@ -2861,6 +2868,7 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm, + switch (type) + { + case SYMBOL_SMALL_ABSOLUTE: ++ case SYMBOL_MO_SMALL_PCR: + { + /* In ILP32, the mode of dest can be either SImode or DImode. */ + rtx tmp_reg = dest; +@@ -2871,6 +2879,21 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm, + if (can_create_pseudo_p ()) + tmp_reg = gen_reg_rtx (mode); + ++ if (TARGET_MACHO) ++ { ++ rtx sym, off; ++ split_const (imm, &sym, &off); ++ /* Negative offsets don't work, whether by intention is TBD. */ ++ if (INTVAL (off) < 0 || INTVAL (off) > 8 * 1024 * 1024) ++ { ++ emit_move_insn (tmp_reg, gen_rtx_HIGH (mode, sym)); ++ emit_insn (gen_add_losym (dest, tmp_reg, sym)); ++ /* FIXME: add the SI option if/when we support ilp32. */ ++ emit_insn (gen_adddi3 (dest, dest, off)); ++ return; ++ } ++ /* else small enough positive offset is OK. */ ++ } + emit_move_insn (tmp_reg, gen_rtx_HIGH (mode, copy_rtx (imm))); + emit_insn (gen_add_losym (dest, tmp_reg, imm)); + return; +@@ -2954,6 +2977,7 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm, + return; + } + ++ case SYMBOL_MO_SMALL_GOT: + case SYMBOL_SMALL_GOT_4G: + emit_insn (gen_rtx_SET (dest, imm)); + return; +@@ -6026,6 +6050,7 @@ aarch64_expand_mov_immediate (rtx dest, rtx imm) + case SYMBOL_SMALL_TLSIE: + case SYMBOL_SMALL_GOT_28K: + case SYMBOL_SMALL_GOT_4G: ++ case SYMBOL_MO_SMALL_GOT: + case SYMBOL_TINY_GOT: + case SYMBOL_TINY_TLSIE: + if (const_offset != 0) +@@ -6039,6 +6064,7 @@ aarch64_expand_mov_immediate (rtx dest, rtx imm) + /* FALLTHRU */ + + case SYMBOL_SMALL_ABSOLUTE: ++ case SYMBOL_MO_SMALL_PCR: + case SYMBOL_TINY_ABSOLUTE: + case SYMBOL_TLSLE12: + case SYMBOL_TLSLE24: +@@ -6628,6 +6654,7 @@ aarch64_return_in_memory (const_tree type, const_tree fndecl ATTRIBUTE_UNUSED) + gcc_unreachable (); + } + ++#if !TARGET_MACHO + static bool + aarch64_vfp_is_call_candidate (cumulative_args_t pcum_v, machine_mode mode, + const_tree type, int *nregs) +@@ -6637,6 +6664,7 @@ aarch64_vfp_is_call_candidate (cumulative_args_t pcum_v, machine_mode mode, + &pcum->aapcs_vfp_rmode, + nregs, NULL, pcum->silent_p); + } ++#endif + + /* Given MODE and TYPE of a function argument, return the alignment in + bits. The idea is to suppress any stronger alignment requested by +@@ -6665,7 +6693,7 @@ aarch64_function_arg_alignment (machine_mode mode, const_tree type, + if (integer_zerop (TYPE_SIZE (type))) + return 0; + +- gcc_assert (TYPE_MODE (type) == mode); ++ gcc_assert (TARGET_MACHO || TYPE_MODE (type) == mode); + + if (!AGGREGATE_TYPE_P (type)) + { +@@ -6863,6 +6891,14 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) + Both behaviors were wrong, but in different cases. */ + + pcum->aapcs_arg_processed = true; ++ if (TARGET_MACHO) ++ { ++ /* Set suitable defaults for queries. */ ++ pcum->darwinpcs_arg_boundary ++ = aarch64_function_arg_alignment (mode, type, &abi_break_gcc_9, ++ &abi_break_gcc_13, &abi_break_gcc_14); ++ pcum->darwinpcs_arg_padding = BITS_PER_UNIT; ++ } + + pure_scalable_type_info pst_info; + if (type && pst_info.analyze_registers (type)) +@@ -6922,13 +6958,29 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) + /* No frontends can create types with variable-sized modes, so we + shouldn't be asked to pass or return them. */ + size = GET_MODE_SIZE (mode).to_constant (); ++ ++ if (TARGET_MACHO) ++ /* Since we can pack things on the stack, we need the unrounded size. */ ++ pcum->darwinpcs_stack_bytes = size; ++ + size = ROUND_UP (size, UNITS_PER_WORD); + + allocate_ncrn = (type) ? !(FLOAT_TYPE_P (type)) : !FLOAT_MODE_P (mode); ++ bool is_ha = false; ++#if !TARGET_MACHO + allocate_nvrn = aarch64_vfp_is_call_candidate (pcum_v, + mode, + type, + &nregs); ++#else ++ /* We care if the value is a homogenous aggregate when laying out the stack, ++ so use this call directly. */ ++ allocate_nvrn ++ = aarch64_vfp_is_call_or_return_candidate (mode, type, ++ &pcum->aapcs_vfp_rmode, ++ &nregs, &is_ha, ++ pcum->silent_p); ++#endif + gcc_assert (!sve_p || !allocate_nvrn); + + unsigned int alignment +@@ -6957,7 +7009,13 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) + if (!pcum->silent_p && !TARGET_FLOAT) + aarch64_err_no_fpadvsimd (mode); + +- if (nvrn + nregs <= NUM_FP_ARG_REGS) ++ if (TARGET_MACHO ++ && !arg.named) ++ { ++ pcum->aapcs_nextnvrn = NUM_FP_ARG_REGS; ++ goto on_stack; ++ } ++ else if (nvrn + nregs <= NUM_FP_ARG_REGS) + { + pcum->aapcs_nextnvrn = nvrn + nregs; + if (!aarch64_composite_type_p (type, mode)) +@@ -6987,6 +7045,7 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) + } + pcum->aapcs_reg = par; + } ++ pcum->darwinpcs_stack_bytes = 0; + return; + } + else +@@ -7003,14 +7062,24 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) + /* C6 - C9. though the sign and zero extension semantics are + handled elsewhere. This is the case where the argument fits + entirely general registers. */ ++ + if (allocate_ncrn && (ncrn + nregs <= NUM_ARG_REGS)) + { + gcc_assert (nregs == 0 || nregs == 1 || nregs == 2); + ++ if (TARGET_MACHO ++ && !arg.named) ++ { ++ pcum->aapcs_nextncrn = NUM_ARG_REGS; ++ goto on_stack; ++ } ++ + /* C.8 if the argument has an alignment of 16 then the NGRN is + rounded up to the next even number. */ + if (nregs == 2 +- && ncrn % 2) ++ && ncrn % 2 ++ /* Darwin PCS deletes rule C.8. */ ++ && !TARGET_MACHO) + { + /* Emit a warning if the alignment changed when taking the + 'packed' attribute into account. */ +@@ -7080,8 +7149,8 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) + } + pcum->aapcs_reg = par; + } +- + pcum->aapcs_nextncrn = ncrn + nregs; ++ pcum->darwinpcs_stack_bytes = 0; + return; + } + +@@ -7091,7 +7160,81 @@ aarch64_layout_arg (cumulative_args_t pcum_v, const function_arg_info &arg) + /* The argument is passed on stack; record the needed number of words for + this argument and align the total size if necessary. */ + on_stack: +- pcum->aapcs_stack_words = size / UNITS_PER_WORD; ++ ++ if (TARGET_MACHO) ++ { ++ /* Darwin does not round up the allocation for smaller entities to 8 ++ bytes. It only requires the natural alignment for these. ++ ++ but we don't do this for: ++ * unnamed parms in variadic functions ++ * complex types ++ * unions ++ * aggregates (except for homogeneous ones which are handles as the ++ enclosed type). ++ each entry starts a new slot. ++ ++ 16 byte entities are naturally aligned on the stack. ++ There was no darwinpcs for GCC 9, so neither the implementation ++ change nor the warning should fire here (i.e. we do not need to check ++ if 16byte entities alter the stack size). */ ++ ++ gcc_checking_assert (arg.named == pcum->named_p); ++ pcum->darwinpcs_arg_padding = BITS_PER_UNIT; ++ if (!pcum->named_p ++ || TREE_CODE (type) == COMPLEX_TYPE ++ || (TREE_CODE (type) == RECORD_TYPE ++ && !is_ha && !SCALAR_FLOAT_MODE_P (pcum->aapcs_vfp_rmode)) ++ || TREE_CODE (type) == UNION_TYPE) ++ { ++ pcum->aapcs_stack_words = size / UNITS_PER_WORD; ++ pcum->darwinpcs_sub_word_offset = 0; ++ pcum->darwinpcs_sub_word_pos = 0; ++ pcum->darwinpcs_arg_boundary = MAX (alignment, PARM_BOUNDARY); ++ if (!pcum->named_p) ++ pcum->darwinpcs_arg_padding = PARM_BOUNDARY; ++ return; ++ } ++ ++ /* Updated sub-word offset aligned for the new object. ++ We are looking for the case that the new object will fit after some ++ existing object(s) in the same stack slot. In that case, we do not ++ need to add any more stack space for it. */ ++ int new_off ++ = ROUND_UP (pcum->darwinpcs_sub_word_pos, alignment / BITS_PER_UNIT); ++ ++ if (new_off >= UNITS_PER_WORD) ++ { ++ /* That exceeds a stack slot, start a new one. */ ++ pcum->darwinpcs_sub_word_offset = 0; ++ pcum->darwinpcs_sub_word_pos = 0; ++ new_off = 0; ++ } ++ /* This is the end of the new object. */ ++ int new_pos = new_off + pcum->darwinpcs_stack_bytes; ++ ++ if (pcum->darwinpcs_sub_word_pos == 0) ++ /* New stack slot, just allocate one or more words, and note where ++ the next arg will start. */ ++ pcum->aapcs_stack_words = size / UNITS_PER_WORD; ++ else if (new_pos <= UNITS_PER_WORD) ++ /* Old stack slot, object starts at new_off and goes to new_pos, we do ++ not add any stack space. */ ++ pcum->darwinpcs_sub_word_offset = new_off; ++ pcum->darwinpcs_sub_word_pos = new_pos; ++ pcum->darwinpcs_arg_boundary = alignment ; ++ if (pcum->last_named_p && new_pos > 0) ++ { ++ /* Round the last named arg to the start of the next stack slot. */ ++ if (new_pos <= 4) ++ pcum->darwinpcs_arg_padding = PARM_BOUNDARY; ++ else if (new_pos <= 6) ++ pcum->darwinpcs_arg_padding = 4 * BITS_PER_UNIT; ++ else if (pcum->darwinpcs_sub_word_pos <= 7) ++ pcum->darwinpcs_arg_padding = 2 * BITS_PER_UNIT; ++ } ++ return; ++ } + + if (warn_pcs_change_le_gcc14 + && abi_break_gcc_13 +@@ -7107,6 +7250,8 @@ on_stack: + inform (input_location, "parameter passing for argument of type " + "%qT changed in GCC 14.1", type); + ++ /* size was already rounded up to PARM_BOUNDARY. */ ++ pcum->aapcs_stack_words = size / UNITS_PER_WORD; + if (alignment == 16 * BITS_PER_UNIT) + { + int new_size = ROUND_UP (pcum->aapcs_stack_size, 16 / UNITS_PER_WORD); +@@ -7211,12 +7356,33 @@ aarch64_init_cumulative_args (CUMULATIVE_ARGS *pcum, + pcum->aapcs_arg_processed = false; + pcum->aapcs_stack_words = 0; + pcum->aapcs_stack_size = 0; ++ pcum->darwinpcs_stack_bytes = 0; ++ pcum->darwinpcs_sub_word_offset = 0; ++ pcum->darwinpcs_sub_word_pos = 0; ++ pcum->darwinpcs_arg_boundary = BITS_PER_UNIT; ++ pcum->darwinpcs_arg_padding = BITS_PER_UNIT; ++ /* If we have been invoked for incoming args, then n_named will have been ++ set to -1, but we should have a function decl - so pick up the named ++ count from that. If that fails, and we end up with -1, this effectively ++ corresponds to assuming that there is an arbitrary number of named ++ args. */ ++ pcum->darwinpcs_n_named = n_named; ++ if (n_named == (unsigned)-1 && fndecl) ++ { ++ tree fnt = TREE_TYPE (fndecl); ++ if (fnt && TYPE_ARG_TYPES (fnt)) ++ pcum->darwinpcs_n_named = list_length (TYPE_ARG_TYPES (fnt)); ++ } ++ pcum->darwinpcs_n_args_processed = 0; ++ pcum->named_p = pcum->darwinpcs_n_named != 0; ++ pcum->last_named_p = pcum->darwinpcs_n_named == 1; + pcum->silent_p = silent_p; + pcum->shared_za_flags + = (fntype ? aarch64_fntype_shared_flags (fntype, "za") : 0U); + pcum->shared_zt0_flags + = (fntype ? aarch64_fntype_shared_flags (fntype, "zt0") : 0U); + pcum->num_sme_mode_switch_args = 0; ++ pcum->aapcs_vfp_rmode = VOIDmode; + + if (!silent_p + && !TARGET_FLOAT +@@ -7255,9 +7421,11 @@ aarch64_function_arg_advance (cumulative_args_t pcum_v, + || pcum->pcs_variant == ARM_PCS_SVE) + { + aarch64_layout_arg (pcum_v, arg); +- gcc_assert ((pcum->aapcs_reg != NULL_RTX) +- != (pcum->aapcs_stack_words != 0)); +- if (pcum->aapcs_reg ++ pcum->darwinpcs_n_args_processed++; ++ gcc_assert (TARGET_MACHO ++ || (pcum->aapcs_reg != NULL_RTX) ++ != (pcum->aapcs_stack_words != 0)); ++ if (pcum->aapcs_reg + && aarch64_call_switches_pstate_sm (pcum->isa_mode)) + aarch64_record_sme_mode_switch_args (pcum); + +@@ -7268,6 +7436,12 @@ aarch64_function_arg_advance (cumulative_args_t pcum_v, + pcum->aapcs_stack_size += pcum->aapcs_stack_words; + pcum->aapcs_stack_words = 0; + pcum->aapcs_reg = NULL_RTX; ++ pcum->darwinpcs_arg_boundary = BITS_PER_UNIT; ++ pcum->darwinpcs_arg_padding = BITS_PER_UNIT; ++ pcum->named_p ++ = pcum->darwinpcs_n_args_processed < pcum->darwinpcs_n_named; ++ pcum->last_named_p ++ = pcum->darwinpcs_n_args_processed + 1 == pcum->darwinpcs_n_named; + } + } + +@@ -7279,12 +7453,15 @@ aarch64_function_arg_regno_p (unsigned regno) + || (PR_REGNUM_P (regno) && regno < P0_REGNUM + NUM_PR_ARG_REGS)); + } + +-/* Implement FUNCTION_ARG_BOUNDARY. Every parameter gets at least +- PARM_BOUNDARY bits of alignment, but will be given anything up +- to STACK_BOUNDARY bits if the type requires it. This makes sure +- that both before and after the layout of each argument, the Next +- Stacked Argument Address (NSAA) will have a minimum alignment of +- 8 bytes. */ ++/* Implement FUNCTION_ARG_BOUNDARY. ++ For AAPCS64, Every parameter gets at least PARM_BOUNDARY bits of ++ alignment, but will be given anything up to STACK_BOUNDARY bits ++ if the type requires it. This makes sure that both before and after ++ the layout of each argument, the Next Stacked Argument Address (NSAA) ++ will have a minimum alignment of 8 bytes. ++ ++ For darwinpcs, this is only called to lower va_arg entries which are ++ always aligned as for AAPCS64. */ + + static unsigned int + aarch64_function_arg_boundary (machine_mode mode, const_tree type) +@@ -7298,8 +7475,108 @@ aarch64_function_arg_boundary (machine_mode mode, const_tree type) + &abi_break_gcc_14); + /* We rely on aarch64_layout_arg and aarch64_gimplify_va_arg_expr + to emit warnings about ABI incompatibility. */ ++#if TARGET_MACHO ++ /* This can only work for unnamed args. */ ++ machine_mode comp_mode = VOIDmode; ++ int nregs; ++ bool is_ha; ++ aarch64_vfp_is_call_or_return_candidate (mode, type, &comp_mode, &nregs, ++ &is_ha, /*silent*/true); ++ if (TREE_CODE (type) == COMPLEX_TYPE ++ || (TREE_CODE (type) == RECORD_TYPE ++ && !is_ha && !SCALAR_FLOAT_MODE_P (comp_mode)) ++ || TREE_CODE (type) == UNION_TYPE) ++ return MIN (MAX (alignment, PARM_BOUNDARY), STACK_BOUNDARY); ++ return MIN (alignment, STACK_BOUNDARY); ++#else ++ alignment = MIN (MAX (alignment, PARM_BOUNDARY), STACK_BOUNDARY); ++ return alignment; ++#endif ++} ++ ++/* For Darwin, we want to use the arg boundary computed when laying out the ++ function arg, to cope with items packed on the stack and the different ++ rules applied to unnamed parms. */ ++ ++static unsigned int ++aarch64_function_arg_boundary_ca (machine_mode mode ATTRIBUTE_UNUSED, ++ const_tree type ATTRIBUTE_UNUSED, ++ cumulative_args_t ca ATTRIBUTE_UNUSED) ++{ ++ unsigned int abi_break_gcc_9; ++ unsigned int abi_break_gcc_13; ++ unsigned int abi_break_gcc_14; ++ unsigned int alignment ++ = aarch64_function_arg_alignment (mode, type, &abi_break_gcc_9, ++ &abi_break_gcc_13, &abi_break_gcc_14); ++ /* We rely on aarch64_layout_arg and aarch64_gimplify_va_arg_expr ++ to emit warnings about ABI incompatibility. */ ++#if TARGET_MACHO ++ CUMULATIVE_ARGS *pcum = get_cumulative_args (ca); ++gcc_checking_assert (pcum->aapcs_arg_processed); ++ ++ bool named_p = pcum->darwinpcs_n_args_processed < pcum->darwinpcs_n_named; ++gcc_checking_assert (named_p == pcum->named_p); ++ machine_mode comp_mode = VOIDmode; ++ int nregs; ++ bool is_ha; ++ aarch64_vfp_is_call_or_return_candidate (mode, type, &comp_mode, &nregs, ++ &is_ha, /*silent*/true); ++ bool no_pack = (TREE_CODE (type) == COMPLEX_TYPE ++ || (TREE_CODE (type) == RECORD_TYPE ++ && !is_ha && !SCALAR_FLOAT_MODE_P (comp_mode)) ++ || TREE_CODE (type) == UNION_TYPE); ++ ++ bool in_regs = (pcum->aapcs_reg != NULL_RTX); ++ ++ if ((named_p && !no_pack) || in_regs) ++ ; /* Leave the alignment as natural. */ ++ else ++ alignment = MAX (alignment, PARM_BOUNDARY); ++gcc_checking_assert (alignment == pcum->darwinpcs_arg_boundary); ++ return MIN (alignment, STACK_BOUNDARY); ++ ++#else + alignment = MIN (MAX (alignment, PARM_BOUNDARY), STACK_BOUNDARY); + return alignment; ++#endif ++} ++ ++/* Implement TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA for darwinpcs which allows ++ non-standard passing of byte-aligned items [D.2]. This is done by pulling ++ the values out of the cumulative args struct. */ ++ ++static unsigned int ++aarch64_function_arg_round_boundary_ca (machine_mode mode ATTRIBUTE_UNUSED, ++ const_tree type ATTRIBUTE_UNUSED, ++ cumulative_args_t ca) ++{ ++ CUMULATIVE_ARGS *pcum = get_cumulative_args (ca); ++gcc_checking_assert (pcum->aapcs_arg_processed); ++ bool named_p = pcum->darwinpcs_n_args_processed < pcum->darwinpcs_n_named; ++gcc_checking_assert (named_p == pcum->named_p); ++ bool last_named_p = pcum->darwinpcs_n_args_processed + 1 == pcum->darwinpcs_n_named; ++gcc_checking_assert (last_named_p == pcum->last_named_p); ++ ++ unsigned boundary = BITS_PER_UNIT; ++ if (last_named_p && pcum->darwinpcs_sub_word_pos > 0) ++ { ++ /* Round the last named arg to the start of the next stack slot. */ ++ if (pcum->darwinpcs_sub_word_pos <= 4) ++ boundary = PARM_BOUNDARY; ++ else if (pcum->darwinpcs_sub_word_pos <= 6) ++ boundary = 4 * BITS_PER_UNIT; ++ else if (pcum->darwinpcs_sub_word_pos <= 7) ++ boundary = 2 * BITS_PER_UNIT; ++ } ++ else if (named_p) ++ /* Named args are naturally aligned, but with no rounding. */ ++ ; ++ else ++ /* un-named args are rounded to fill slots. */ ++ boundary = PARM_BOUNDARY; ++gcc_checking_assert (boundary == pcum->darwinpcs_arg_padding); ++ return boundary; + } + + /* Implement TARGET_GET_RAW_RESULT_MODE and TARGET_GET_RAW_ARG_MODE. */ +@@ -10698,6 +10975,7 @@ aarch64_classify_address (struct aarch64_address_info *info, + /* load literal: pc-relative constant pool entry. Only supported + for SI mode or larger. */ + info->type = ADDRESS_SYMBOLIC; ++ info->offset = NULL_RTX; + + if (!load_store_pair_p + && GET_MODE_SIZE (mode).is_constant (&const_size) +@@ -10705,6 +10983,7 @@ aarch64_classify_address (struct aarch64_address_info *info, + { + poly_int64 offset; + rtx sym = strip_offset_and_salt (x, &offset); ++ + return ((LABEL_REF_P (sym) + || (SYMBOL_REF_P (sym) + && CONSTANT_POOL_ADDRESS_P (sym) +@@ -10722,10 +11001,13 @@ aarch64_classify_address (struct aarch64_address_info *info, + poly_int64 offset; + HOST_WIDE_INT const_offset; + rtx sym = strip_offset_and_salt (info->offset, &offset); ++ + if (SYMBOL_REF_P (sym) + && offset.is_constant (&const_offset) + && (aarch64_classify_symbol (sym, const_offset) +- == SYMBOL_SMALL_ABSOLUTE)) ++ == SYMBOL_SMALL_ABSOLUTE ++ || aarch64_classify_symbol (sym, const_offset) ++ == SYMBOL_MO_SMALL_PCR)) + { + /* The symbol and offset must be aligned to the access size. */ + unsigned int align; +@@ -10775,6 +11057,55 @@ aarch64_address_valid_for_prefetch_p (rtx x, bool strict_p) + if (!res) + return false; + ++ /* For ELF targets using GAS, we emit prfm unconditionally; GAS will alter ++ the instruction to pick the prfum form where possible (i.e. when the ++ offset is in the range -256..255) and fall back to prfm otherwise. ++ We can reject cases where the offset exceeds the range usable by both ++ insns [-256..32760], or for offsets > 255 when the value is not divisible ++ by 8. ++ For Mach-O (Darwin) where the assembler uses the LLVM back end, that does ++ not yet do the substitution, so we must reject all prfum cases. */ ++ if (addr.offset) ++ { ++ HOST_WIDE_INT offs = INTVAL (addr.offset); ++ if (offs < -256) /* Out of range for both prfum and prfm. */ ++ return false; ++ if (offs > 32760) /* Out of range for prfm. */ ++ return false; ++ if (offs & 0x07) /* We cannot use prfm. */ ++ { ++ if (offs > 255) /* Out of range for prfum. */ ++ return false; ++ if (TARGET_MACHO) ++ return false; ++ } ++ if (TARGET_MACHO && offs < 0) ++ return false; ++ } ++ ++ /* ... except writeback forms. */ ++ return addr.type != ADDRESS_REG_WB; ++} ++ ++/* Return true if the address X is valid for a PRFUM instruction. ++ STRICT_P is true if we should do strict checking with ++ aarch64_classify_address. */ ++ ++bool ++aarch64_address_valid_for_unscaled_prefetch_p (rtx x, bool strict_p) ++{ ++ struct aarch64_address_info addr; ++ ++ /* PRFUM accepts the same addresses as DImode, but constrained to a range ++ -256..255. */ ++ bool res = aarch64_classify_address (&addr, x, DImode, strict_p); ++ if (!res) ++ return false; ++ ++ if (addr.offset && ((INTVAL (addr.offset) > 255) ++ || (INTVAL (addr.offset) < -256))) ++ return false; ++ + /* ... except writeback forms. */ + return addr.type != ADDRESS_REG_WB; + } +@@ -11908,6 +12239,144 @@ sizetochar (int size) + } + } + ++static void ++output_macho_postfix_expr (FILE *file, rtx x, const char *postfix) ++{ ++ char buf[256]; ++ ++ restart: ++ switch (GET_CODE (x)) ++ { ++ case PC: ++ putc ('.', file); ++ break; ++ ++ case SYMBOL_REF: ++ if (SYMBOL_REF_DECL (x)) ++ assemble_external (SYMBOL_REF_DECL (x)); ++ assemble_name (file, XSTR (x, 0)); ++ fprintf (file, "@%s", postfix); ++ break; ++ ++ case LABEL_REF: ++ x = label_ref_label (x); ++ /* Fall through. */ ++ case CODE_LABEL: ++ ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x)); ++ assemble_name (file, buf); ++ fprintf (file, "@%s", postfix); ++ break; ++ ++ case CONST_INT: ++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x)); ++ break; ++ ++ case CONST: ++ /* This used to output parentheses around the expression, ++ but that does not work on the 386 (either ATT or BSD assembler). */ ++ output_macho_postfix_expr (file, XEXP (x, 0), postfix); ++ break; ++ ++ case CONST_WIDE_INT: ++ /* We do not know the mode here so we have to use a round about ++ way to build a wide-int to get it printed properly. */ ++ { ++ wide_int w = wide_int::from_array (&CONST_WIDE_INT_ELT (x, 0), ++ CONST_WIDE_INT_NUNITS (x), ++ CONST_WIDE_INT_NUNITS (x) ++ * HOST_BITS_PER_WIDE_INT, ++ false); ++ print_decs (w, file); ++ } ++ break; ++ ++ case CONST_DOUBLE: ++ if (CONST_DOUBLE_AS_INT_P (x)) ++ { ++ /* We can use %d if the number is one word and positive. */ ++ if (CONST_DOUBLE_HIGH (x)) ++ fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX, ++ (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (x), ++ (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (x)); ++ else if (CONST_DOUBLE_LOW (x) < 0) ++ fprintf (file, HOST_WIDE_INT_PRINT_HEX, ++ (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (x)); ++ else ++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x)); ++ } ++ else ++ /* We can't handle floating point constants; ++ PRINT_OPERAND must handle them. */ ++ output_operand_lossage ("floating constant misused"); ++ break; ++ ++ case CONST_FIXED: ++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_FIXED_VALUE_LOW (x)); ++ break; ++ ++ case PLUS: ++ /* Some assemblers need integer constants to appear last (eg masm). */ ++ if (CONST_INT_P (XEXP (x, 0))) ++ { ++ output_macho_postfix_expr (file, XEXP (x, 1), postfix); ++ if (INTVAL (XEXP (x, 0)) >= 0) ++ fprintf (file, "+"); ++ output_addr_const (file, XEXP (x, 0)); ++ } ++ else ++ { ++ output_macho_postfix_expr (file, XEXP (x, 0), postfix); ++ if (!CONST_INT_P (XEXP (x, 1)) ++ || INTVAL (XEXP (x, 1)) >= 0) ++ fprintf (file, "+"); ++ output_addr_const (file, XEXP (x, 1)); ++ } ++ break; ++ ++ case MINUS: ++ /* Avoid outputting things like x-x or x+5-x, ++ since some assemblers can't handle that. */ ++ x = simplify_subtraction (x); ++ if (GET_CODE (x) != MINUS) ++ goto restart; ++ ++ output_macho_postfix_expr (file, XEXP (x, 0), postfix); ++ fprintf (file, "-"); ++ if ((CONST_INT_P (XEXP (x, 1)) && INTVAL (XEXP (x, 1)) >= 0) ++ || GET_CODE (XEXP (x, 1)) == PC ++ || GET_CODE (XEXP (x, 1)) == SYMBOL_REF) ++ output_addr_const (file, XEXP (x, 1)); ++ else ++ { ++ fputs (targetm.asm_out.open_paren, file); ++ output_addr_const (file, XEXP (x, 1)); ++ fputs (targetm.asm_out.close_paren, file); ++ } ++ break; ++ ++ case ZERO_EXTEND: ++ case SIGN_EXTEND: ++ case SUBREG: ++ case TRUNCATE: ++ output_addr_const (file, XEXP (x, 0)); ++ break; ++ ++ case UNSPEC: ++ if (XINT (x, 1) == UNSPEC_SALT_ADDR) ++ { ++ output_macho_postfix_expr (file, XVECEXP (x, 0, 0), postfix); ++ break; ++ } ++ /* FALLTHROUGH */ ++ default: ++ if (targetm.asm_out.output_addr_const_extra (file, x)) ++ break; ++ ++ output_operand_lossage ("invalid expression as operand"); ++ } ++ ++} ++ + /* Print operand X to file F in a target specific manner according to CODE. + The acceptable formatting commands given by CODE are: + 'c': An integer or symbol address without a preceding # +@@ -11981,6 +12450,12 @@ aarch64_print_operand (FILE *f, rtx x, int code) + } + break; + ++ case 'J': ++ output_macho_postfix_expr (f, x, "PAGEOFF"); ++ break; ++ case 'O': ++ output_macho_postfix_expr (f, x, "GOTPAGEOFF"); ++ break; + case 'e': + { + x = unwrap_const_vec_duplicate (x); +@@ -12313,7 +12788,7 @@ aarch64_print_operand (FILE *f, rtx x, int code) + case 'A': + if (GET_CODE (x) == HIGH) + x = XEXP (x, 0); +- ++#if !TARGET_MACHO + switch (aarch64_classify_symbolic_expression (x)) + { + case SYMBOL_SMALL_GOT_4G: +@@ -12344,9 +12819,26 @@ aarch64_print_operand (FILE *f, rtx x, int code) + break; + } + output_addr_const (asm_out_file, x); ++#endif ++#if TARGET_MACHO ++ switch (aarch64_classify_symbolic_expression (x)) ++ { ++ case SYMBOL_MO_SMALL_PCR: ++ output_macho_postfix_expr (asm_out_file, x, "PAGE"); ++ break; ++ case SYMBOL_MO_SMALL_GOT: ++ output_macho_postfix_expr (asm_out_file, x, "GOTPAGE"); ++ break; ++ default: ++ /* large code model unimplemented. */ ++ gcc_unreachable (); ++ break; ++ } ++#endif + break; + + case 'L': ++#if !TARGET_MACHO + switch (aarch64_classify_symbolic_expression (x)) + { + case SYMBOL_SMALL_GOT_4G: +@@ -12384,10 +12876,12 @@ aarch64_print_operand (FILE *f, rtx x, int code) + default: + break; + } ++#endif + output_addr_const (asm_out_file, x); + break; + + case 'G': ++#if !TARGET_MACHO + switch (aarch64_classify_symbolic_expression (x)) + { + case SYMBOL_TLSLE24: +@@ -12396,6 +12890,7 @@ aarch64_print_operand (FILE *f, rtx x, int code) + default: + break; + } ++#endif + output_addr_const (asm_out_file, x); + break; + +@@ -12561,8 +13056,13 @@ aarch64_print_address_internal (FILE *f, machine_mode mode, rtx x, + break; + + case ADDRESS_LO_SUM: ++#if TARGET_MACHO ++ asm_fprintf (f, "[%s, #", reg_names [REGNO (addr.base)]); ++ output_macho_postfix_expr (f, addr.offset, "PAGEOFF"); ++#else + asm_fprintf (f, "[%s, #:lo12:", reg_names [REGNO (addr.base)]); + output_addr_const (f, addr.offset); ++#endif + asm_fprintf (f, "]"); + return true; + +@@ -12870,7 +13370,23 @@ aarch64_frame_pointer_required () + { + /* If the function needs to record the incoming value of PSTATE.SM, + make sure that the slot is accessible from the frame pointer. */ +- return aarch64_need_old_pstate_sm (); ++ if (!TARGET_MACHO) ++ return aarch64_need_old_pstate_sm (); ++ ++ /* We could do with some more general test. ++ gcc_checking_assert (!aarch64_need_old_pstate_sm ());*/ ++ ++ if (crtl->calls_eh_return || aarch64_need_old_pstate_sm ()) ++ return true; ++ ++ /* Not used in leaf functions (unless forced). */ ++ if (flag_omit_leaf_frame_pointer && leaf_function_p ()) ++ return false; ++ ++ /* NOTE: We are allowing the user to force omission of the frame ++ pointer, (despite that it is not ABI-compliant). */ ++ ++ return flag_omit_frame_pointer != 1; + } + + static bool +@@ -13098,6 +13614,8 @@ aarch64_asm_output_labelref (FILE* f, const char *name) + asm_fprintf (f, "%U%s", name); + } + ++#if !TARGET_MACHO ++ + static void + aarch64_elf_asm_constructor (rtx symbol, int priority) + { +@@ -13137,6 +13655,7 @@ aarch64_elf_asm_destructor (rtx symbol, int priority) + assemble_aligned_integer (POINTER_BYTES, symbol); + } + } ++#endif + + const char* + aarch64_output_casesi (rtx *operands) +@@ -13289,7 +13808,11 @@ aarch64_select_rtx_section (machine_mode mode, + if (aarch64_can_use_per_function_literal_pools_p ()) + return function_section (current_function_decl); + ++#if TARGET_MACHO ++ return machopic_select_rtx_section (mode, x, align); ++#else + return default_elf_select_rtx_section (mode, x, align); ++#endif + } + + /* Implement ASM_OUTPUT_POOL_EPILOGUE. */ +@@ -15559,15 +16082,17 @@ aarch64_init_builtins () + { + aarch64_general_init_builtins (); + aarch64_sve::init_builtins (); +-#ifdef SUBTARGET_INIT_BUILTINS +- SUBTARGET_INIT_BUILTINS; +-#endif ++ aarch64_init_subtarget_builtins (); + } + + /* Implement TARGET_FOLD_BUILTIN. */ + static tree + aarch64_fold_builtin (tree fndecl, int nargs, tree *args, bool) + { ++#ifdef SUBTARGET_FOLD_BUILTIN ++ if (tree res = SUBTARGET_FOLD_BUILTIN (fndecl, nargs, args, false)) ++ return res; ++#endif + unsigned int code = DECL_MD_FUNCTION_CODE (fndecl); + unsigned int subcode = code >> AARCH64_BUILTIN_SHIFT; + tree type = TREE_TYPE (TREE_TYPE (fndecl)); +@@ -18979,10 +19504,14 @@ initialize_aarch64_code_model (struct gcc_options *opts) + } + break; + case AARCH64_CMODEL_LARGE: +- if (opts->x_flag_pic) ++ if (TARGET_MACHO) ++ /* We need to implement fPIC here (arm64_32 also accepts the large ++ model). */ ++ sorry ("code model %qs not supported yet", "large"); ++ else if (opts->x_flag_pic) + sorry ("code model %qs with %<-f%s%>", "large", + opts->x_flag_pic > 1 ? "PIC" : "pic"); +- if (opts->x_aarch64_abi == AARCH64_ABI_ILP32) ++ else if (opts->x_aarch64_abi == AARCH64_ABI_ILP32) + sorry ("code model %qs not supported in ilp32 mode", "large"); + break; + case AARCH64_CMODEL_TINY_PIC: +@@ -20899,7 +21428,9 @@ aarch64_classify_symbol (rtx x, HOST_WIDE_INT offset) + case AARCH64_CMODEL_SMALL_SPIC: + case AARCH64_CMODEL_SMALL_PIC: + case AARCH64_CMODEL_SMALL: +- return SYMBOL_SMALL_ABSOLUTE; ++ return TARGET_MACHO ++ ? SYMBOL_MO_SMALL_PCR ++ : SYMBOL_SMALL_ABSOLUTE; + + default: + gcc_unreachable (); +@@ -20935,10 +21466,22 @@ aarch64_classify_symbol (rtx x, HOST_WIDE_INT offset) + + return SYMBOL_TINY_ABSOLUTE; + +- + case AARCH64_CMODEL_SMALL_SPIC: + case AARCH64_CMODEL_SMALL_PIC: + case AARCH64_CMODEL_SMALL: ++#if TARGET_MACHO ++ if (TARGET_MACHO) ++ { ++ /* Constant pool addresses are always TU-local and PC- ++ relative. We indirect common, external and weak ++ symbols (but weak only if not hidden). */ ++ if (!CONSTANT_POOL_ADDRESS_P (x) ++ && (MACHO_SYMBOL_MUST_INDIRECT_P (x) ++ || !aarch64_symbol_binds_local_p (x))) ++ return SYMBOL_MO_SMALL_GOT; ++ } ++ else ++#endif + if ((flag_pic || SYMBOL_REF_WEAK (x)) + && !aarch64_symbol_binds_local_p (x)) + return aarch64_cmodel == AARCH64_CMODEL_SMALL_SPIC +@@ -20950,7 +21493,8 @@ aarch64_classify_symbol (rtx x, HOST_WIDE_INT offset) + || offset_within_block_p (x, offset))) + return SYMBOL_FORCE_TO_MEM; + +- return SYMBOL_SMALL_ABSOLUTE; ++ return TARGET_MACHO ? SYMBOL_MO_SMALL_PCR ++ : SYMBOL_SMALL_ABSOLUTE; + + case AARCH64_CMODEL_LARGE: + /* This is alright even in PIC code as the constant +@@ -21080,7 +21624,10 @@ static GTY(()) tree va_list_type; + void *__vr_top; + int __gr_offs; + int __vr_offs; +- }; */ ++ }; ++ ++ darwinpcs uses 'char *' for the va_list (in common with other platform ++ ports). */ + + static tree + aarch64_build_builtin_va_list (void) +@@ -21088,6 +21635,13 @@ aarch64_build_builtin_va_list (void) + tree va_list_name; + tree f_stack, f_grtop, f_vrtop, f_groff, f_vroff; + ++ /* darwinpcs uses a simple char * for this. */ ++ if (TARGET_MACHO) ++ { ++ va_list_type = build_pointer_type (char_type_node); ++ return va_list_type; ++ } ++ + /* Create the type. */ + va_list_type = lang_hooks.types.make_type (RECORD_TYPE); + /* Give it the required name. */ +@@ -21159,6 +21713,13 @@ aarch64_expand_builtin_va_start (tree valist, rtx nextarg ATTRIBUTE_UNUSED) + int vr_save_area_size = cfun->va_list_fpr_size; + int vr_offset; + ++ /* darwinpcs uses the default, char * va_list impl. */ ++ if (TARGET_MACHO) ++ { ++ std_expand_builtin_va_start (valist, nextarg); ++ return; ++ } ++ + cum = &crtl->args.info; + if (cfun->va_list_gpr_size) + gr_save_area_size = MIN ((NUM_ARG_REGS - cum->aapcs_ncrn) * UNITS_PER_WORD, +@@ -21249,6 +21810,9 @@ aarch64_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p, + HOST_WIDE_INT size, rsize, adjust, align; + tree t, u, cond1, cond2; + ++ if (TARGET_MACHO) ++ return std_gimplify_va_arg_expr (valist, type, pre_p, post_p); ++ + indirect_p = pass_va_arg_by_reference (type); + if (indirect_p) + type = build_pointer_type (type); +@@ -21453,8 +22017,18 @@ aarch64_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p, + field_ptr_t = double_ptr_type_node; + break; + case E_TFmode: +- field_t = long_double_type_node; +- field_ptr_t = long_double_ptr_type_node; ++ if (TARGET_MACHO) ++ { ++ /* Darwin has __float128, and long double is the same as ++ double. */ ++ field_t = float128_type_node; ++ field_ptr_t = aarch64_float128_ptr_type_node; ++ } ++ else ++ { ++ field_t = long_double_type_node; ++ field_ptr_t = long_double_ptr_type_node; ++ } + break; + case E_SDmode: + field_t = dfloat32_type_node; +@@ -21537,6 +22111,9 @@ aarch64_setup_incoming_varargs (cumulative_args_t cum_v, + int gr_saved = cfun->va_list_gpr_size; + int vr_saved = cfun->va_list_fpr_size; + ++ if (TARGET_MACHO) ++ return default_setup_incoming_varargs (cum_v, arg, pretend_size, no_rtl); ++ + /* The caller has advanced CUM up to, but not beyond, the last named + argument. Advance a local copy of CUM past the last "real" named + argument, to find out how many registers are left over. */ +@@ -22380,6 +22957,12 @@ aarch64_autovectorize_vector_modes (vector_modes *modes, bool) + static const char * + aarch64_mangle_type (const_tree type) + { ++ /* The darwinpcs ABI documents say that "__va_list" has to be ++ mangled as char *. */ ++ if (TARGET_MACHO ++ && lang_hooks.types_compatible_p (CONST_CAST_TREE (type), va_list_type)) ++ return "Pc"; ++ + /* The AArch64 ABI documents say that "__va_list" has to be + mangled as if it is in the "std" namespace. */ + if (lang_hooks.types_compatible_p (CONST_CAST_TREE (type), va_list_type)) +@@ -22396,6 +22979,12 @@ aarch64_mangle_type (const_tree type) + return "Dh"; + } + ++ /* __float128 is mangled as "g" on darwin. _Float128 is not mangled here, ++ but handled in common code (as "DF128_"). */ ++ if (TARGET_MACHO && TYPE_MODE (type) == TFmode ++ && TYPE_MAIN_VARIANT (type) == float128t_type_node) ++ return "g"; ++ + /* Mangle AArch64-specific internal types. TYPE_NAME is non-NULL_TREE for + builtin types. */ + if (TYPE_NAME (type) != NULL) +@@ -23093,7 +23682,8 @@ aarch64_mov_operand_p (rtx x, machine_mode mode) + + /* GOT accesses are valid moves. */ + if (SYMBOL_REF_P (x) +- && aarch64_classify_symbolic_expression (x) == SYMBOL_SMALL_GOT_4G) ++ && (aarch64_classify_symbolic_expression (x) == SYMBOL_SMALL_GOT_4G ++ || aarch64_classify_symbolic_expression (x) == SYMBOL_MO_SMALL_GOT)) + return true; + + if (SYMBOL_REF_P (x) && mode == DImode && CONSTANT_ADDRESS_P (x)) +@@ -24430,12 +25020,8 @@ aarch64_asm_output_variant_pcs (FILE *stream, const tree decl, const char* name) + static std::string aarch64_last_printed_arch_string; + static std::string aarch64_last_printed_tune_string; + +-/* Implement ASM_DECLARE_FUNCTION_NAME. Output the ISA features used +- by the function fndecl. */ +- +-void +-aarch64_declare_function_name (FILE *stream, const char* name, +- tree fndecl) ++static void ++aarch64_function_options_preamble (tree fndecl) + { + tree target_parts = DECL_FUNCTION_SPECIFIC_TARGET (fndecl); + +@@ -24474,15 +25060,60 @@ aarch64_declare_function_name (FILE *stream, const char* name, + this_tune->name); + aarch64_last_printed_tune_string = this_tune->name; + } ++} ++ ++/* Implement ASM_DECLARE_FUNCTION_NAME. Output the ISA features used ++ by the function fndecl. */ ++ ++#if TARGET_MACHO ++void ++aarch64_darwin_declare_function_name (FILE *stream, const char* name, ++ tree fndecl) ++{ ++ gcc_checking_assert (TREE_CODE (fndecl) == FUNCTION_DECL); ++ gcc_checking_assert (!DECL_COMMON (fndecl)); + ++ /* Update .arch and .tune as needed. */ ++ aarch64_function_options_preamble (fndecl); ++ ++ /* Darwin does not emit pcs variant info. */ ++ ++ rtx decl_rtx = XEXP (DECL_RTL (fndecl), 0); ++ if (GET_CODE (decl_rtx) != SYMBOL_REF) ++ name = IDENTIFIER_POINTER (DECL_NAME (fndecl)); ++ ++ if (! DECL_WEAK (fndecl) ++ && ((TREE_STATIC (fndecl) && !TREE_PUBLIC (fndecl)) ++ || DECL_INITIAL (fndecl))) ++ machopic_define_symbol (DECL_RTL (fndecl)); ++ if ((TREE_STATIC (fndecl) && !TREE_PUBLIC (fndecl)) ++ || DECL_INITIAL (fndecl)) ++ (* targetm.encode_section_info) (fndecl, DECL_RTL (fndecl), false); ++ ASM_OUTPUT_FUNCTION_LABEL (stream, name, fndecl); ++ ++ cfun->machine->label_is_assembled = true; ++} ++ ++#else ++ ++void ++aarch64_declare_function_name (FILE *stream, const char* name, ++ tree fndecl) ++{ ++ /* Update .arch and .tune as needed. */ ++ aarch64_function_options_preamble (fndecl); ++ /* Emit any necessary pcs information. */ + aarch64_asm_output_variant_pcs (stream, fndecl, name); + + /* Don't forget the type directive for ELF. */ ++#ifdef ASM_OUTPUT_TYPE_DIRECTIVE + ASM_OUTPUT_TYPE_DIRECTIVE (stream, name, "function"); ++#endif + ASM_OUTPUT_FUNCTION_LABEL (stream, name, fndecl); + + cfun->machine->label_is_assembled = true; + } ++#endif + + /* Implement PRINT_PATCHABLE_FUNCTION_ENTRY. */ + +@@ -24539,12 +25170,17 @@ aarch64_output_patchable_area (unsigned int patch_area_size, bool record_p) + /* Implement ASM_OUTPUT_DEF_FROM_DECLS. Output .variant_pcs for aliases. */ + + void +-aarch64_asm_output_alias (FILE *stream, const tree decl, const tree target) ++aarch64_asm_output_alias (FILE *stream, const tree decl, ++ const tree target ATTRIBUTE_UNUSED) + { + const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0); ++#ifdef ASM_OUTPUT_DEF + const char *value = IDENTIFIER_POINTER (target); ++#endif + aarch64_asm_output_variant_pcs (stream, decl, name); ++#ifdef ASM_OUTPUT_DEF + ASM_OUTPUT_DEF (stream, name, value); ++#endif + } + + /* Implement ASM_OUTPUT_EXTERNAL. Output .variant_pcs for undefined +@@ -24590,6 +25226,9 @@ aarch64_start_file (void) + aarch64_last_printed_arch_string.c_str ()); + + default_file_start (); ++#if TARGET_MACHO ++ darwin_file_start (); ++#endif + } + + /* Emit load exclusive. */ +@@ -25169,6 +25808,16 @@ aarch64_output_simd_mov_immediate (rtx const_vector, unsigned width, + } + + gcc_assert (CONST_INT_P (info.u.mov.value)); ++ unsigned HOST_WIDE_INT value = UINTVAL (info.u.mov.value); ++ ++ /* We have signed chars which can result in a sign-extended 8bit value ++ which is then emitted as an unsigned hex value, and the LLVM back end ++ assembler rejects that as being too big. */ ++ if (TARGET_MACHO && (known_eq (GET_MODE_BITSIZE (info.elt_mode), 8))) ++ { ++ unsigned HOST_WIDE_INT mask = (1U << GET_MODE_BITSIZE (info.elt_mode))-1; ++ value &= mask; ++ } + + if (which == AARCH64_CHECK_MOV) + { +@@ -25177,16 +25826,16 @@ aarch64_output_simd_mov_immediate (rtx const_vector, unsigned width, + ? "msl" : "lsl"); + if (lane_count == 1) + snprintf (templ, sizeof (templ), "%s\t%%d0, " HOST_WIDE_INT_PRINT_HEX, +- mnemonic, UINTVAL (info.u.mov.value)); ++ mnemonic, value); + else if (info.u.mov.shift) + snprintf (templ, sizeof (templ), "%s\t%%0.%d%c, " + HOST_WIDE_INT_PRINT_HEX ", %s %d", mnemonic, lane_count, +- element_char, UINTVAL (info.u.mov.value), shift_op, ++ element_char, value, shift_op, + info.u.mov.shift); + else + snprintf (templ, sizeof (templ), "%s\t%%0.%d%c, " + HOST_WIDE_INT_PRINT_HEX, mnemonic, lane_count, +- element_char, UINTVAL (info.u.mov.value)); ++ element_char, value); + } + else + { +@@ -25195,12 +25844,12 @@ aarch64_output_simd_mov_immediate (rtx const_vector, unsigned width, + if (info.u.mov.shift) + snprintf (templ, sizeof (templ), "%s\t%%0.%d%c, #" + HOST_WIDE_INT_PRINT_DEC ", %s #%d", mnemonic, lane_count, +- element_char, UINTVAL (info.u.mov.value), "lsl", ++ element_char, value, "lsl", + info.u.mov.shift); + else + snprintf (templ, sizeof (templ), "%s\t%%0.%d%c, #" + HOST_WIDE_INT_PRINT_DEC, mnemonic, lane_count, +- element_char, UINTVAL (info.u.mov.value)); ++ element_char, value); + } + return templ; + } +@@ -28437,7 +29086,8 @@ aarch64_libgcc_floating_mode_supported_p (scalar_float_mode mode) + } + + /* Implement TARGET_SCALAR_MODE_SUPPORTED_P - return TRUE +- if MODE is [BH]Fmode, and punt to the generic implementation otherwise. */ ++ if MODE is [BH]Fmode, or TFmode on Mach-O, and punt to the generic ++ implementation otherwise. */ + + static bool + aarch64_scalar_mode_supported_p (scalar_mode mode) +@@ -28445,7 +29095,7 @@ aarch64_scalar_mode_supported_p (scalar_mode mode) + if (DECIMAL_FLOAT_MODE_P (mode)) + return default_decimal_float_supported_p (); + +- return ((mode == HFmode || mode == BFmode) ++ return ((mode == HFmode || mode == BFmode || (mode == TFmode && TARGET_MACHO)) + ? true + : default_scalar_mode_supported_p (mode)); + } +@@ -29262,19 +29912,37 @@ aarch64_sls_emit_shared_blr_thunks (FILE *out_file) + continue; + + const char *name = indirect_symbol_names[regnum]; +- switch_to_section (get_named_section (decl, NULL, 0)); ++ /* If the target uses a unique section for this switch to it. */ ++ if (DECL_SECTION_NAME (decl)) ++ switch_to_section (get_named_section (decl, NULL, 0)); ++ else ++ switch_to_section (text_section); + ASM_OUTPUT_ALIGN (out_file, 2); +- targetm.asm_out.globalize_label (out_file, name); ++ if (!TARGET_MACHO) ++ targetm.asm_out.globalize_label (out_file, name); ++#ifdef ASM_OUTPUT_TYPE_DIRECTIVE ++ ASM_OUTPUT_TYPE_DIRECTIVE (out_file, name, "function"); ++#endif ++ if (TARGET_MACHO) ++ { ++#ifdef ASM_WEAKEN_DECL ++ if (DECL_WEAK (decl)) ++ ASM_WEAKEN_DECL (out_file, decl, name, 0); ++ else ++#endif ++ targetm.asm_out.globalize_decl_name (out_file, decl); ++ } + /* Only emits if the compiler is configured for an assembler that can + handle visibility directives. */ + targetm.asm_out.assemble_visibility (decl, VISIBILITY_HIDDEN); +- ASM_OUTPUT_TYPE_DIRECTIVE (out_file, name, "function"); + ASM_OUTPUT_LABEL (out_file, name); + aarch64_sls_emit_function_stub (out_file, regnum); + /* Use the most conservative target to ensure it can always be used by any + function in the translation unit. */ + asm_fprintf (out_file, "\tdsb\tsy\n\tisb\n"); ++#ifdef ASM_DECLARE_FUNCTION_SIZE + ASM_DECLARE_FUNCTION_SIZE (out_file, name, decl); ++#endif + } + } + +@@ -30366,6 +31034,60 @@ aarch64_retrieve_sysreg (const char *regname, bool write_p, bool is128op) + return sysreg->encoding; + } + ++#if TARGET_MACHO ++/* This handles the promotion of function return values. ++ It also handles function args under two specific curcumstances: ++ - called from combine with a register argument ++ - caller for a libcall with type == NULL. ++ The remaining cases for argument promotion are handled with access to ++ cumulative args data, below. */ ++machine_mode ++aarch64_darwin_promote_fn_mode (const_tree type, machine_mode mode, ++ int *punsignedp, ++ const_tree funtype ATTRIBUTE_UNUSED, ++ int for_return ATTRIBUTE_UNUSED) ++{ ++ /* With the amended use of promote using cargs, the only cases that arrive ++ here with for_return == 0 are from combine (where the value is definitely ++ in a register) and for libcalls, where type == NULL. We want to promote ++ function return values in the callee, so this becomes pretty much ++ unconditional now. */ ++ if (type != NULL_TREE) ++ return promote_mode (type, mode, punsignedp); ++ return mode; ++} ++ ++/* Ensure that we only promote the mode of named parms when they are passed in ++ a register. Named values passed on the stack retain their original mode and ++ alignment. */ ++machine_mode ++aarch64_darwin_promote_function_mode_ca (cumulative_args_t ca, ++ function_arg_info arg, ++ const_tree funtype ATTRIBUTE_UNUSED, ++ int *punsignedp, ++ int for_return ATTRIBUTE_UNUSED) ++{ ++ tree type = arg.type; ++ machine_mode mode = arg.mode; ++ machine_mode new_mode = promote_mode (type, mode, punsignedp); ++ if (new_mode == mode || arg.named == false ++ || GET_MODE_CLASS (new_mode) != MODE_INT ++ || known_gt (GET_MODE_SIZE (new_mode), 4)) ++ return new_mode; ++ ++ CUMULATIVE_ARGS *pcum = get_cumulative_args (ca); ++ /* Make sure that changes in assumption do not get missed. */ ++ gcc_checking_assert (for_return == 0 && new_mode == SImode ++ && !pcum->aapcs_arg_processed); ++ /* We have a named integer value that fits in a reg; if there's one available ++ then promote the value. */ ++ if (pcum->aapcs_ncrn < 8) ++ return new_mode; ++ return mode; ++} ++ ++#endif ++ + /* Target-specific selftests. */ + + #if CHECKING_P +@@ -30571,6 +31293,15 @@ aarch64_run_selftests (void) + #undef TARGET_ASM_ALIGNED_SI_OP + #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t" + ++#if TARGET_MACHO ++#undef TARGET_ASM_UNALIGNED_HI_OP ++#define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t" ++#undef TARGET_ASM_UNALIGNED_SI_OP ++#define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t" ++#undef TARGET_ASM_UNALIGNED_DI_OP ++#define TARGET_ASM_UNALIGNED_DI_OP "\t.quad\t" ++#endif ++ + #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK + #define TARGET_ASM_CAN_OUTPUT_MI_THUNK \ + hook_bool_const_tree_hwi_hwi_const_tree_true +@@ -30673,6 +31404,12 @@ aarch64_run_selftests (void) + #undef TARGET_FUNCTION_ARG_BOUNDARY + #define TARGET_FUNCTION_ARG_BOUNDARY aarch64_function_arg_boundary + ++#undef TARGET_FUNCTION_ARG_BOUNDARY_CA ++#define TARGET_FUNCTION_ARG_BOUNDARY_CA aarch64_function_arg_boundary_ca ++ ++#undef TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA ++#define TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA aarch64_function_arg_round_boundary_ca ++ + #undef TARGET_FUNCTION_ARG_PADDING + #define TARGET_FUNCTION_ARG_PADDING aarch64_function_arg_padding + +@@ -31013,7 +31750,7 @@ aarch64_libgcc_floating_mode_supported_p + + /* The architecture reserves bits 0 and 1 so use bit 2 for descriptors. */ + #undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS +-#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 4 ++#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS AARCH64_CUSTOM_FUNCTION_TEST + + #undef TARGET_HARD_REGNO_NREGS + #define TARGET_HARD_REGNO_NREGS aarch64_hard_regno_nregs +diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h +index 4fa1dfc7906..84344e50fad 100644 +--- a/gcc/config/aarch64/aarch64.h ++++ b/gcc/config/aarch64/aarch64.h +@@ -72,6 +72,10 @@ + #define TARGET_SIMD (AARCH64_ISA_SIMD && AARCH64_ISA_SM_OFF) + #define TARGET_FLOAT (AARCH64_ISA_FP) + ++/* If this is non-zero then generated code of the object format, ABI and ++ assembler syntax used by Darwin (Mach-O) platforms. */ ++#define TARGET_MACHO 0 ++ + #define UNITS_PER_WORD 8 + + #define UNITS_PER_VREG 16 +@@ -149,6 +153,12 @@ + /* Heap alignment (same as BIGGEST_ALIGNMENT and STACK_BOUNDARY). */ + #define MALLOC_ABI_ALIGNMENT 128 + ++/* We will and with this value to test if a custom function descriptor needs ++ a static chain. The function boundary must the adjusted so that the bit ++ this represents is no longer part of the address. 0 Disables the custom ++ function descriptors. */ ++#define AARCH64_CUSTOM_FUNCTION_TEST 4 ++ + /* Defined by the ABI */ + #define WCHAR_TYPE "unsigned int" + #define WCHAR_TYPE_SIZE 32 +@@ -1146,6 +1156,24 @@ typedef struct + aapcs_reg == NULL_RTX. */ + int aapcs_stack_size; /* The total size (in words, per 8 byte) of the + stack arg area so far. */ ++ ++ /* In the darwinpcs, items smaller than one word are packed onto the stack ++ naturally aligned. Unnamed parameters passed in a variadic call are, ++ however, aligned the same way as the AAPCS64. This means that we need to ++ pad the last named arg to the next parm boundary (and hence notice when ++ we are processing that arg). */ ++ int darwinpcs_stack_bytes; /* If the argument is passed on the stack, this ++ the byte-size. */ ++ int darwinpcs_sub_word_offset;/* This is the offset of this arg within a word ++ when placing smaller items for darwinpcs. */ ++ int darwinpcs_sub_word_pos; /* The next byte available within the word for ++ darwinpcs. */ ++ unsigned darwinpcs_arg_boundary; /* The computed argument boundary. */ ++ unsigned darwinpcs_arg_padding; /* The computed argument padding. */ ++ unsigned darwinpcs_n_named; /* Number of named arguments. */ ++ unsigned darwinpcs_n_args_processed; /* Processed so far. */ ++ bool named_p; /* Is this arg named? */ ++ bool last_named_p; /* Is this the last named arg? */ + bool silent_p; /* True if we should act silently, rather than + raise an error for invalid calls. */ + +@@ -1457,8 +1485,13 @@ extern const char *aarch64_rewrite_mcpu (int argc, const char **argv); + #define ASM_CPU_SPEC \ + MCPU_TO_MARCH_SPEC + ++#ifndef SUBTARGET_EXTRA_SPECS ++#define SUBTARGET_EXTRA_SPECS ++#endif ++ + #define EXTRA_SPECS \ +- { "asm_cpu_spec", ASM_CPU_SPEC } ++ { "asm_cpu_spec", ASM_CPU_SPEC }, \ ++ SUBTARGET_EXTRA_SPECS + + #define ASM_OUTPUT_POOL_EPILOGUE aarch64_asm_output_pool_epilogue + +@@ -1471,6 +1504,10 @@ extern GTY(()) tree aarch64_fp16_ptr_type_node; + bfloat16_type_node. Defined in aarch64-builtins.cc. */ + extern GTY(()) tree aarch64_bf16_ptr_type_node; + ++/* A pointer to the user-visible __float128 (on Mach-O). Defined in ++ aarch64-builtins.c. */ ++extern GTY(()) tree aarch64_float128_ptr_type_node; ++ + /* The generic unwind code in libgcc does not initialize the frame pointer. + So in order to unwind a function using a frame pointer, the very first + function that is unwound must save the frame pointer. That way the frame +diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md +index dbde066f747..d1698b5b142 100644 +--- a/gcc/config/aarch64/aarch64.md ++++ b/gcc/config/aarch64/aarch64.md +@@ -363,6 +363,7 @@ + ;; Wraps a constant integer that should be multiplied by the number + ;; of quadwords in an SME vector. + UNSPEC_SME_VQ ++ UNSPEC_MACHOPIC_OFFSET ; Common to Mach-O ports. + ]) + + (define_c_enum "unspecv" [ +@@ -995,6 +996,37 @@ + [(set_attr "type" "load_4")] + ) + ++(define_insn "prefetch_unscaled" ++ [(prefetch (match_operand:DI 0 "aarch64_unscaled_prefetch_operand" "Du") ++ (match_operand:QI 1 "const_int_operand" "") ++ (match_operand:QI 2 "const_int_operand" ""))] ++ "" ++ { ++ const char * pftype[2][4] = ++ { ++ {"prfum\\tPLDL1STRM, %0", ++ "prfum\\tPLDL3KEEP, %0", ++ "prfum\\tPLDL2KEEP, %0", ++ "prfum\\tPLDL1KEEP, %0"}, ++ {"prfum\\tPSTL1STRM, %0", ++ "prfum\\tPSTL3KEEP, %0", ++ "prfum\\tPSTL2KEEP, %0", ++ "prfum\\tPSTL1KEEP, %0"}, ++ }; ++ ++ int locality = INTVAL (operands[2]); ++ ++ gcc_assert (IN_RANGE (locality, 0, 3)); ++ ++ /* PRFUM accepts the same addresses as a 64-bit LDR so wrap ++ the address into a DImode MEM so that aarch64_print_operand knows ++ how to print it. */ ++ operands[0] = gen_rtx_MEM (DImode, operands[0]); ++ return pftype[INTVAL(operands[1])][locality]; ++ } ++ [(set_attr "type" "load_4")] ++) ++ + (define_insn "trap" + [(trap_if (const_int 1) (const_int 8))] + "" +@@ -1447,7 +1479,7 @@ + [w , m ; load_4 , fp , 4] ldr\t%s0, %1 + [m , r Z; store_4 , * , 4] str\t%w1, %0 + [m , w ; store_4 , fp , 4] str\t%s1, %0 +- [r , Usw; load_4 , * , 8] adrp\t%x0, %A1;ldr\t%w0, [%x0, %L1] ++ [r , Usw; load_4 , * , 8] << TARGET_MACHO ? \"adrp\\t%x0, %A1\;ldr\\t%w0, [%x0, %O1]\" : \"adrp\\t%x0, %A1\;ldr\\t%w0, [%x0, %L1]\"; + [r , Usa; adr , * , 4] adr\t%x0, %c1 + [r , Ush; adr , * , 4] adrp\t%x0, %A1 + [w , r Z; f_mcr , fp , 4] fmov\t%s0, %w1 +@@ -1484,7 +1516,7 @@ + [w, m ; load_8 , fp , 4] ldr\t%d0, %1 + [m, r Z; store_8 , * , 4] str\t%x1, %0 + [m, w ; store_8 , fp , 4] str\t%d1, %0 +- [r, Usw; load_8 , * , 8] << TARGET_ILP32 ? "adrp\t%0, %A1;ldr\t%w0, [%0, %L1]" : "adrp\t%0, %A1;ldr\t%0, [%0, %L1]"; ++ [r, Usw; load_8 , * , 8] << TARGET_ILP32 ? (TARGET_MACHO ? \"adrp\\t%0, %A1\;ldr\\t%w0, [%0, %O1]\" : \"adrp\\t%0, %A1\;ldr\\t%w0, [%0, %L1]\") : (TARGET_MACHO ? \"adrp\\t%0, %A1\;ldr\\t%0, [%0, %O1]\" : \"adrp\\t%0, %A1\;ldr\\t%0, [%0, %L1]\"); + [r, Usa; adr , * , 4] adr\t%x0, %c1 + [r, Ush; adr , * , 4] adrp\t%x0, %A1 + [w, r Z; f_mcr , fp , 4] fmov\t%d0, %x1 +@@ -7387,7 +7419,10 @@ + (lo_sum:P (match_operand:P 1 "register_operand" "r") + (match_operand 2 "aarch64_valid_symref" "S")))] + "" +- "add\\t%0, %1, :lo12:%c2" ++ { return TARGET_MACHO ++ ? "add\\t%0, %1, %J2;" ++ : "add\\t%0, %1, :lo12:%c2"; ++ } + [(set_attr "type" "alu_imm")] + ) + +diff --git a/gcc/config/aarch64/aarch64.opt b/gcc/config/aarch64/aarch64.opt +index 6356c419399..5c9bb0a9056 100644 +--- a/gcc/config/aarch64/aarch64.opt ++++ b/gcc/config/aarch64/aarch64.opt +@@ -193,6 +193,13 @@ Enum(aarch64_abi) String(ilp32) Value(AARCH64_ABI_ILP32) + EnumValue + Enum(aarch64_abi) String(lp64) Value(AARCH64_ABI_LP64) + ++EnumValue ++Enum(aarch64_abi) String(darwinpcs) Value(AARCH64_ABI_LP64) ++ ++m64 ++Target RejectNegative Alias(mabi=, darwinpcs) ++On Darwin for compatibility with other platform variants. ++ + mpc-relative-literal-loads + Target Save Var(pcrelative_literal_loads) Init(2) Save + PC relative literal loads. +diff --git a/gcc/config/aarch64/constraints.md b/gcc/config/aarch64/constraints.md +index a2569cea510..9ade357cacc 100644 +--- a/gcc/config/aarch64/constraints.md ++++ b/gcc/config/aarch64/constraints.md +@@ -203,7 +203,9 @@ + A constraint that matches a small GOT access." + (and (match_code "const,symbol_ref") + (match_test "aarch64_classify_symbolic_expression (op) +- == SYMBOL_SMALL_GOT_4G"))) ++ == SYMBOL_SMALL_GOT_4G ++ || aarch64_classify_symbolic_expression (op) ++ == SYMBOL_MO_SMALL_GOT"))) + + (define_constraint "Uss" + "@internal +@@ -574,6 +576,11 @@ + An address valid for a prefetch instruction." + (match_test "aarch64_address_valid_for_prefetch_p (op, true)")) + ++(define_address_constraint "Du" ++ "@internal ++ An address valid for a prefetch instruction with an unscaled offset." ++ (match_test "aarch64_address_valid_for_unscaled_prefetch_p (op, true)")) ++ + (define_constraint "vgb" + "@internal + A constraint that matches an immediate offset valid for SVE LD1B +diff --git a/gcc/config/aarch64/darwin.h b/gcc/config/aarch64/darwin.h +new file mode 100644 +index 00000000000..4b6bac4cf4b +--- /dev/null ++++ b/gcc/config/aarch64/darwin.h +@@ -0,0 +1,291 @@ ++/* Target definitions for Arm64/Aarch64 running on macOS/iOS. ++ ++Copyright The GNU Toolchain Authors. ++Contributed by Iain Sandoe. ++ ++This file is part of GCC. ++ ++GCC is free software; you can redistribute it and/or modify ++it under the terms of the GNU General Public License as published by ++the Free Software Foundation; either version 3, or (at your option) ++any later version. ++ ++GCC is distributed in the hope that it will be useful, ++but WITHOUT ANY WARRANTY; without even the implied warranty of ++MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++GNU General Public License for more details. ++ ++You should have received a copy of the GNU General Public License ++along with GCC; see the file COPYING3. If not see ++. */ ++ ++/* Enable Mach-O bits in generic Aarch64 code. */ ++#undef TARGET_MACHO ++#define TARGET_MACHO 1 ++ ++#undef DARWIN_ARM64 ++#define DARWIN_ARM64 1 ++ ++/* This is used in generic code in darwin.cc (at present, we have no support ++ for the arm64_32 target). */ ++#undef TARGET_64BIT ++#define TARGET_64BIT 1 ++ ++#undef PTRDIFF_TYPE ++#define PTRDIFF_TYPE "long int" ++ ++#undef TARGET_PROMOTE_FUNCTION_MODE ++#define TARGET_PROMOTE_FUNCTION_MODE aarch64_darwin_promote_fn_mode ++ ++#undef TARGET_PROMOTE_FUNCTION_MODE_CA ++#define TARGET_PROMOTE_FUNCTION_MODE_CA aarch64_darwin_promote_function_mode_ca ++ ++/* NOTE that arm64_32 is a valid thing and corresponds to darwinpcs ++ and TARGET_ILP32, but we are not implementing that for now. */ ++#define TARGET_OS_CPP_BUILTINS() \ ++ do { \ ++ builtin_define ("__LITTLE_ENDIAN__"); \ ++ builtin_define ("__arm64"); \ ++ builtin_define ("__arm64__"); \ ++ darwin_cpp_builtins (pfile); \ ++ } while (0) ++ ++/* In Darwin's Arm64 ABI, chars are signed. */ ++ ++#undef DEFAULT_SIGNED_CHAR ++#define DEFAULT_SIGNED_CHAR 1 ++ ++#undef LONG_DOUBLE_TYPE_SIZE ++#define LONG_DOUBLE_TYPE_SIZE 64 ++ ++/* Disable custom function descriptors on Darwin (we use heap-based ++ trampolines). */ ++#undef AARCH64_CUSTOM_FUNCTION_TEST ++#define AARCH64_CUSTOM_FUNCTION_TEST 0 ++ ++/* Non-PIE executables are forbidden by the Arm64-darwin security model; ++ remove the option from link-lines since they just produce a warning from ++ ld64 and are then ignored anyway. */ ++#undef DARWIN_NOPIE_SPEC ++#define DARWIN_NOPIE_SPEC \ ++" % ++# include ++#endif ++ ++ ++#if TARGET_MACHO ++ ++/* Default architecture to use if -mcpu=native did not detect a known CPU. */ ++#define DEFAULT_ARCH "apple-m1" ++ ++/* macOS does not have /proc/cpuinfo and needs a different approach, ++ based on sysctl. It is much simpler. */ ++ ++const char * ++host_detect_local_cpu (ATTRIBUTE_UNUSED int argc, ATTRIBUTE_UNUSED const char **argv) ++{ ++ bool arch = false; ++ bool tune = false; ++ bool cpu = false; ++ const char *res = NULL; ++ uint32_t family; ++ size_t len = sizeof(family); ++ ++ gcc_assert (argc); ++ if (!argv[0]) ++ return NULL; ++ ++ /* Are we processing -march, mtune or mcpu? */ ++ arch = strcmp (argv[0], "arch") == 0; ++ if (!arch) ++ tune = strcmp (argv[0], "tune") == 0; ++ if (!arch && !tune) ++ cpu = strcmp (argv[0], "cpu") == 0; ++ if (!arch && !tune && !cpu) ++ return NULL; ++ ++ sysctlbyname("hw.cpufamily", &family, &len, NULL, 0); ++ ++ switch (family) ++ { ++ case 0x07d34b9f: // Vortex, Tempest ++ res = "apple-a12"; ++ break; ++ case 0x573b5eec: ++ case 0x1b588bb3: // Firestorm, Icestorm ++ res = "apple-m1"; ++ break; ++ case 0xda33d83d: // Blizzard, Avalanche ++ res = "apple-m2"; ++ break; ++ case 0xfa33415e: // Ibiza (M3) ++ case 0x5f4dea93: // Lobos (M3 Pro) ++ case 0x72015832: // Palma (M3 Max) ++ res = "apple-m3"; ++ break; ++ default: ++ res = DEFAULT_ARCH; ++ } ++ ++ if (res) ++ return concat ("-m", argv[0], "=", res, NULL); ++ else ++ return NULL; ++} ++ ++#else ++ + struct aarch64_arch_extension + { + const char *ext; +@@ -477,3 +545,4 @@ not_found: + } + } + ++#endif +diff --git a/gcc/config/aarch64/predicates.md b/gcc/config/aarch64/predicates.md +index b895f5dcb86..6e7487bcef5 100644 +--- a/gcc/config/aarch64/predicates.md ++++ b/gcc/config/aarch64/predicates.md +@@ -352,9 +352,24 @@ + (define_predicate "aarch64_prefetch_operand" + (match_test "aarch64_address_valid_for_prefetch_p (op, false)")) + ++(define_predicate "aarch64_unscaled_prefetch_operand" ++ (match_test "aarch64_address_valid_for_unscaled_prefetch_p (op, false)")) ++ + (define_predicate "aarch64_valid_symref" + (match_code "const, symbol_ref, label_ref") + { ++ if (TARGET_MACHO) ++ { ++ rtx x = op; ++ rtx offset; ++ split_const (x, &x, &offset); ++ if (GET_CODE (x) == CONST) ++ x = XEXP (x, 0); ++ if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_SALT_ADDR) ++ x = XVECEXP (x, 0, 0); ++ if (SYMBOL_REF_P (x) && INTVAL (offset) < 0) ++ return false; ++ } + return (aarch64_classify_symbolic_expression (op) + != SYMBOL_FORCE_TO_MEM); + }) +diff --git a/gcc/config/aarch64/t-aarch64-darwin b/gcc/config/aarch64/t-aarch64-darwin +new file mode 100644 +index 00000000000..e2b8ad9237f +--- /dev/null ++++ b/gcc/config/aarch64/t-aarch64-darwin +@@ -0,0 +1,25 @@ ++# Machine description for AArch64 architecture. ++# Copyright (C) 2020 Free Software Foundation, Inc. ++# ++# This file is part of GCC. ++# ++# GCC is free software; you can redistribute it and/or modify it ++# under the terms of the GNU General Public License as published by ++# the Free Software Foundation; either version 3, or (at your option) ++# any later version. ++# ++# GCC is distributed in the hope that it will be useful, but ++# WITHOUT ANY WARRANTY; without even the implied warranty of ++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++# General Public License for more details. ++# ++# You should have received a copy of the GNU General Public License ++# along with GCC; see the file COPYING3. If not see ++# . ++ ++LIB1ASMSRC = aarch64/lib1funcs.asm ++LIB1ASMFUNCS = _aarch64_sync_cache_range ++ ++# TODO - figure out what multilib provisions we should make for ++# a) arm64e ++# b) arm64_32 +diff --git a/gcc/config/darwin-driver.cc b/gcc/config/darwin-driver.cc +index eabe9bc970d..176bcfb6843 100644 +--- a/gcc/config/darwin-driver.cc ++++ b/gcc/config/darwin-driver.cc +@@ -268,10 +268,13 @@ darwin_driver_init (unsigned int *decoded_options_count, + bool seenX86_64 = false; + bool seenPPC = false; + bool seenPPC64 = false; ++#if !DARWIN_ARM64 ++ bool seenArm64 = false; + bool seenM32 = false; + bool seenM64 = false; + bool appendM32 = false; + bool appendM64 = false; ++#endif + const char *vers_string = NULL; + bool seen_version_min = false; + bool seen_sysroot_p = false; +@@ -296,6 +299,12 @@ darwin_driver_init (unsigned int *decoded_options_count, + seenPPC = true; + else if (!strcmp ((*decoded_options)[i].arg, "ppc64")) + seenPPC64 = true; ++ else if (!strcmp ((*decoded_options)[i].arg, "arm64")) ++#if !DARWIN_ARM64 ++ seenArm64 = true; ++#else ++ ; /* We accept the option, but don't need to act on it. */ ++#endif + else + error ("this compiler does not support %qs", + (*decoded_options)[i].arg); +@@ -309,7 +318,7 @@ darwin_driver_init (unsigned int *decoded_options_count, + --i; + --*decoded_options_count; + break; +- ++#if !DARWIN_ARM64 + case OPT_m32: + seenM32 = true; + break; +@@ -317,6 +326,7 @@ darwin_driver_init (unsigned int *decoded_options_count, + case OPT_m64: + seenM64 = true; + break; ++#endif + + case OPT_mmacosx_version_min_: + seen_version_min = true; +@@ -366,6 +376,9 @@ darwin_driver_init (unsigned int *decoded_options_count, + if (seenPPC || seenPPC64) + warning (0, "this compiler does not support PowerPC" + " (%<-arch%> option ignored)"); ++ else if (seenArm64) ++ warning (0, "this compiler does not support Arm64" ++ " (%<-arch%> option ignored)"); + if (seenX86) + { + if (seenX86_64 || seenM64) +@@ -389,6 +402,9 @@ darwin_driver_init (unsigned int *decoded_options_count, + if (seenX86 || seenX86_64) + warning (0, "this compiler does not support x86" + " (%<-arch%> option ignored)"); ++ else if (seenArm64) ++ warning (0, "this compiler does not support Arm64" ++ " (%<-arch%> option ignored)"); + if (seenPPC) + { + if (seenPPC64 || seenM64) +@@ -408,12 +424,20 @@ darwin_driver_init (unsigned int *decoded_options_count, + if (! seenM64) /* Add -m64 if the User didn't. */ + appendM64 = true; + } ++#elif DARWIN_ARM64 ++ if (seenPPC || seenPPC64) ++ warning (0, "this compiler does not support PowerPC" ++ " (%<-arch%> option ignored)"); ++ if (seenX86 || seenX86_64) ++ warning (0, "this compiler does not support x86" ++ " (%<-arch%> option ignored)"); + #endif + + /* If there is nothing else on the command line, do not add sysroot etc. */ + if (*decoded_options_count <= 1) + return; + ++#if !DARWIN_ARM64 + if (appendM32 || appendM64) + { + ++*decoded_options_count; +@@ -423,6 +447,7 @@ darwin_driver_init (unsigned int *decoded_options_count, + generate_option (appendM32 ? OPT_m32 : OPT_m64, NULL, 1, CL_DRIVER, + &(*decoded_options)[*decoded_options_count - 1]); + } ++#endif + + if (!seen_sysroot_p) + { +diff --git a/gcc/config/darwin-protos.h b/gcc/config/darwin-protos.h +index b67e05264e1..35116317b59 100644 +--- a/gcc/config/darwin-protos.h ++++ b/gcc/config/darwin-protos.h +@@ -86,9 +86,12 @@ extern void darwin_asm_lto_end (void); + extern void darwin_mark_decl_preserved (const char *); + + extern tree darwin_handle_kext_attribute (tree *, tree, tree, int, bool *); +-extern tree darwin_handle_weak_import_attribute (tree *node, tree name, +- tree args, int flags, +- bool * no_add_attrs); ++extern tree darwin_handle_weak_import_attribute (tree *, tree, tree, int, ++ bool *); ++extern tree darwin_handle_availability_attribute (tree *, tree, tree, ++ int, bool *); ++extern bool darwin_attribute_takes_identifier_p (const_tree); ++ + extern void machopic_output_stub (FILE *, const char *, const char *); + extern void darwin_globalize_label (FILE *, const char *); + extern void darwin_assemble_visibility (tree, int); +@@ -124,6 +127,7 @@ extern void darwin_enter_string_into_cfstring_table (tree); + extern void darwin_asm_output_anchor (rtx symbol); + extern bool darwin_use_anchors_for_symbol_p (const_rtx symbol); + extern bool darwin_kextabi_p (void); ++extern bool darwin_unreachable_traps_p (void); + extern void darwin_override_options (void); + extern void darwin_patch_builtins (void); + extern void darwin_rename_builtins (void); +diff --git a/gcc/config/darwin.cc b/gcc/config/darwin.cc +index 63b8c509405..e6657753211 100644 +--- a/gcc/config/darwin.cc ++++ b/gcc/config/darwin.cc +@@ -29,6 +29,7 @@ along with GCC; see the file COPYING3. If not see + #include "cfghooks.h" + #include "df.h" + #include "memmodel.h" ++#include "c-family/c-common.h" /* enum rid. */ + #include "tm_p.h" + #include "stringpool.h" + #include "attribs.h" +@@ -49,6 +50,7 @@ along with GCC; see the file COPYING3. If not see + #include "optabs.h" + #include "flags.h" + #include "opts.h" ++#include "c-family/c-objc.h" /* for objc_method_decl(). */ + + /* Fix and Continue. + +@@ -102,6 +104,7 @@ int darwin_running_cxx; + + /* Some code-gen now depends on OS major version numbers (at least). */ + int generating_for_darwin_version ; ++unsigned long current_os_version = 0; + + /* For older linkers we need to emit special sections (marked 'coalesced') for + for weak or single-definition items. */ +@@ -131,7 +134,7 @@ struct { + section * darwin_sections[NUM_DARWIN_SECTIONS]; + + /* While we transition to using in-tests instead of ifdef'd code. */ +-#if !HAVE_lo_sum ++#if !HAVE_lo_sum || DARWIN_ARM64 + #define gen_macho_high(m,a,b) (a) + #define gen_macho_low(m,a,b,c) (a) + #endif +@@ -1104,6 +1107,7 @@ machopic_legitimize_pic_address (rtx orig, machine_mode mode, rtx reg) + return pic_ref; + } + ++#if !DARWIN_ARM64 + /* Callbacks to output the stub or non-lazy pointers. + Each works on the item in *SLOT,if it has been used. + DATA is the FILE* for assembly output. +@@ -1259,6 +1263,7 @@ machopic_finish (FILE *out_file) + machopic_indirections->traverse_noresize + (out_file); + } ++#endif + + int + machopic_operand_p (rtx op) +@@ -2194,6 +2199,122 @@ darwin_handle_kext_attribute (tree *node, tree name, + return NULL_TREE; + } + ++enum version_components { MAJOR, MINOR, TINY }; ++ ++/* Parse a version number in x.y.z form and validate it as a macOS ++ version. Ideally, we'd put this in a common place usable by the ++ Darwin backend. */ ++ ++static bool ++parse_version (unsigned version_array[3], const char *version_str) ++{ ++ size_t version_len; ++ char *end, last = '\0', delimiter = '.', alt_delim = '_'; ++ ++ if (!version_str) ++ return false; ++ ++ /* Handle the odd situation in which we get STRING_CST which contain the ++ starting and ending quotes. */ ++ if (version_str[0] == '"') ++ { ++ version_str++; ++ version_len = strrchr (&version_str[1], '"') - version_str; ++ last = '"'; ++ } ++ else ++ version_len = strlen (version_str); ++ ++ if (version_len < 1) ++ return false; ++ ++ /* Version string must consist of digits and periods only. */ ++ if (strspn (version_str, "0123456789._") != version_len) ++ return false; ++ ++ if (!ISDIGIT (version_str[0]) || !ISDIGIT (version_str[version_len - 1])) ++ return false; ++ ++ version_array[MAJOR] = strtoul (version_str, &end, 10); ++ if (*end == '_') ++ { ++ delimiter = '_'; ++ alt_delim = '.'; ++ } ++ version_str = end + ((*end == delimiter) ? 1 : 0); ++ if (version_array[MAJOR] == 100000) ++ return true; ++ if (version_array[MAJOR] > 99) ++ return false; ++ ++ /* Version string must not contain adjacent delimiters. */ ++ if (*version_str == delimiter || *version_str == alt_delim) ++ return false; ++ ++ version_array[MINOR] = strtoul (version_str, &end, 10); ++ if (*end == alt_delim) ++ return false; ++ version_str = end + ((*end == delimiter) ? 1 : 0); ++ if (version_array[MINOR] > 99) ++ return false; ++ ++ version_array[TINY] = strtoul (version_str, &end, 10); ++ if (version_array[TINY] > 99) ++ return false; ++ ++ /* Version string must contain no more than three tokens. */ ++ if (*end != last) ++ return false; ++ ++ return true; ++} ++ ++/* Turn a version expressed as maj.min.tiny into an unsigned long ++ integer representing the value used in macOS availability macros. */ ++ ++static unsigned long ++version_from_version_array (unsigned vers[3]) ++{ ++ unsigned long res = 0; ++ /* There seems to be a special "unknown" value. */ ++ if (vers[0] == 100000) ++ return 999999; ++ ++ /* Here, we follow the 'modern' / 'legacy' numbering scheme for versions. */ ++ if (vers[0] > 10 || vers[1] >= 10) ++ res = vers[0] * 10000 + vers[1] * 100 + vers[2]; ++ else ++ { ++ res = vers[0] * 100; ++ if (vers[1] > 9) ++ res += 90; ++ else ++ res += vers[1] * 10; ++ if (vers[2] > 9) ++ res += 9; ++ else ++ res += vers[1]; ++ } ++ return res; ++} ++ ++/* Extract a macOS version from an availability attribute argument. */ ++ ++static unsigned long ++os_version_from_avail_value (tree value) ++{ ++ unsigned long res = 0; ++ unsigned vers[3] = {0,0,0}; ++ if (TREE_CODE (value) == STRING_CST) ++ { ++ if (parse_version (&vers[0], TREE_STRING_POINTER (value))) ++ res = version_from_version_array (&vers[0]); ++ } ++ else ++ gcc_unreachable (); ++ return res; ++} ++ + /* Handle a "weak_import" attribute; arguments as in + struct attribute_spec.handler. */ + +@@ -2215,6 +2336,231 @@ darwin_handle_weak_import_attribute (tree *node, tree name, + return NULL_TREE; + } + ++#define NUM_AV_OSES 13 ++const char *availability_os[NUM_AV_OSES] ++ = { "macos", "macosx", "ios", "tvos", "watchos", "driverkit", "swift", ++ "maccatalyst", "macCatalyst", "xros", "visionos", "android", "zos" }; ++ ++#define NUM_AV_CLAUSES 6 ++const char *availability_clause[NUM_AV_CLAUSES] ++ = { "unavailable", "introduced", "deprecated", "obsoleted", "message", ++ "replacement" }; ++ ++/* Validate and act upon the arguments to an 'availability' attribute. */ ++ ++tree ++darwin_handle_availability_attribute (tree *node, tree name, tree args, ++ int flags, bool * no_add_attrs) ++{ ++ tree decl = *node; ++ *no_add_attrs = true; ++ ++ if (!decl || (!TYPE_P (decl) && !DECL_P (decl))) ++ { ++ warning (OPT_Wattributes, "%qE attribute ignored", name); ++ return NULL_TREE; ++ } ++ else if (decl == error_mark_node) ++ return NULL_TREE; ++ ++ location_t loc = DECL_SOURCE_LOCATION (decl); ++ if (args == NULL_TREE) ++ { ++ error_at (loc, "%qE attribute requires at least one argument", ++ name); ++ return NULL_TREE; ++ } ++ else if (args == error_mark_node) ++ return NULL_TREE; ++ ++ /* The first argument must name a supported OS - although we could choose ++ to ignore any OS we don't recognise. */ ++ gcc_checking_assert (TREE_CODE (args) == TREE_LIST); ++ tree platform = TREE_VALUE (args); ++ if (platform == error_mark_node) ++ return NULL_TREE; ++ ++ gcc_checking_assert (TREE_CODE (platform) == IDENTIFIER_NODE); ++ bool platform_ok = false; ++ unsigned plat_num = 0; ++ for (; plat_num < (unsigned) NUM_AV_OSES; plat_num++) ++ if (strcmp (availability_os[plat_num], IDENTIFIER_POINTER (platform)) == 0) ++ { ++ platform_ok = true; ++ break; ++ } ++ if (!platform_ok) ++ { ++ error_at (input_location, ++ "platform %qE is not recognised for the % " ++ "attribute", platform); ++ return NULL_TREE; ++ } ++ else if (plat_num > 1) /* We only compile for macos so far. */ ++ return NULL_TREE; ++ ++ /* We might be dealing with an object or type. */ ++ tree target_decl = NULL_TREE; ++ tree type = NULL_TREE; ++ bool warn = false; ++ if (DECL_P (*node)) ++ { ++ type = TREE_TYPE (decl); ++ ++ if (TREE_CODE (decl) == TYPE_DECL ++ || TREE_CODE (decl) == PARM_DECL ++ || VAR_OR_FUNCTION_DECL_P (decl) ++ || TREE_CODE (decl) == FIELD_DECL ++ || TREE_CODE (decl) == CONST_DECL ++ /*|| objc_method_decl (TREE_CODE (decl))*/) ++ target_decl = decl; ++ else ++ warn = true; ++ } ++ else if (TYPE_P (*node)) ++ type = target_decl = *node; ++ else ++ warn = true; ++ ++ tree what = NULL_TREE; ++ if (warn) ++ { ++ if (type && TYPE_NAME (type)) ++ { ++ if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) ++ what = TYPE_NAME (*node); ++ else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL ++ && DECL_NAME (TYPE_NAME (type))) ++ what = DECL_NAME (TYPE_NAME (type)); ++ } ++ if (what) ++ warning (OPT_Wattributes, "%qE attribute ignored for %qE", name, what); ++ else ++ warning (OPT_Wattributes, "%qE attribute ignored", name); ++ return NULL_TREE; ++ } ++ ++ /* Now we have to parse the availability clauses. */ ++ tree msg = NULL_TREE; ++ tree replacement = NULL_TREE; ++ bool unavailable = false; ++ unsigned introduced = 1000; ++ unsigned deprecated = current_os_version + 1; ++ unsigned obsoleted = current_os_version + 1; ++ for (tree arg = TREE_CHAIN (args); arg; arg = TREE_CHAIN (arg)) ++ { ++ tree clause_name = TREE_VALUE (arg); ++ tree clause_value = TREE_PURPOSE (arg); ++ if (clause_name == error_mark_node ++ || clause_value == error_mark_node) ++ continue; ++ unsigned clause_num = 0; ++ for (; clause_num < (unsigned) NUM_AV_CLAUSES; clause_num++) ++ if (strcmp (availability_clause[clause_num], ++ IDENTIFIER_POINTER (clause_name)) == 0) ++ break; ++ switch (clause_num) ++ { ++ default: ++ error_at (input_location, ++ "clause %qE is not recognised for the % " ++ "attribute", clause_name); ++ break; ++ case 0: ++ unavailable = true; ++ break; ++ case 1: ++ case 2: ++ case 3: ++ if (!clause_value) ++ error_at (input_location, "%<%E=%> requires a value", clause_name); ++ else ++ { ++ unsigned version = os_version_from_avail_value (clause_value); ++ if (version == 0) ++ error_at (input_location, "the value %qE provided to %qE is " ++ "not a valid OS version", clause_value, clause_name); ++ else if (clause_num == 1) ++ introduced = version; ++ else if (clause_num == 2) ++ deprecated = version; ++ else if (clause_num == 3) ++ obsoleted = version; ++ } ++ break; ++ case 4: ++ case 5: ++ if (!clause_value || TREE_CODE (clause_value) != STRING_CST) ++ error_at (input_location, "%<%E=%> requires a string", clause_name); ++ else if (clause_num == 4) ++ msg = clause_value; ++ else ++ replacement = clause_value; ++ break; ++ } ++ } ++ /* Now figure out what to do. */ ++ tree maybe_text = NULL_TREE; ++ if (replacement) ++ maybe_text = tree_cons (NULL_TREE, replacement, NULL_TREE); ++ else if (msg) ++ maybe_text = tree_cons (NULL_TREE, msg, NULL_TREE); ++ ++ if (unavailable || current_os_version >= obsoleted) ++ { ++ TREE_UNAVAILABLE (*node) = true; ++ /* We do not handle the availability attribute at diagnostics-time, so ++ if we want the informational messages, then attach them to additional ++ attributes for the deprecation or unavailability. TODO; maybe we can ++ fabricate the composite here. */ ++ if (maybe_text) ++ { ++ *no_add_attrs = false; ++ tree new_attr = tree_cons (get_identifier ("unavailable"), ++ maybe_text, NULL_TREE); ++ /* This is the actual consequence of the evaluation. */ ++ if (TYPE_P (target_decl) && !(flags & (int) ATTR_FLAG_TYPE_IN_PLACE)) ++ { ++ *node = build_variant_type_copy (*node); ++ TYPE_ATTRIBUTES (*node) = chainon (TYPE_ATTRIBUTES (*node), ++ new_attr); ++ } ++ else ++ DECL_ATTRIBUTES (*node) = chainon (DECL_ATTRIBUTES (*node), ++ new_attr); ++ } ++ } ++ else if (current_os_version > deprecated) ++ { ++ TREE_DEPRECATED (*node) = true; ++ if (maybe_text) ++ { ++ *no_add_attrs = false; ++ tree new_attr = tree_cons (get_identifier ("deprecated"), ++ maybe_text, NULL_TREE); ++ /* This is the actual consequence of the evaluation. */ ++ if (TYPE_P (target_decl) && !(flags & (int) ATTR_FLAG_TYPE_IN_PLACE)) ++ { ++ *node = build_variant_type_copy (*node); ++ TYPE_ATTRIBUTES (*node) = chainon (TYPE_ATTRIBUTES (*node), ++ new_attr); ++ } ++ else ++ DECL_ATTRIBUTES (*node) = chainon (DECL_ATTRIBUTES (*node), ++ new_attr); ++ } ++ } ++ else if (current_os_version < introduced) ++ *no_add_attrs = false; ++ return NULL_TREE; ++} ++ ++bool ++darwin_attribute_takes_identifier_p (const_tree attr_id) ++{ ++ return is_attribute_p ("availability", attr_id); ++} ++ + /* Emit a label for an FDE, making it global and/or weak if appropriate. + The third parameter is nonzero if this is for exception handling. + The fourth parameter is nonzero if this is just a placeholder for an +@@ -2306,6 +2652,8 @@ darwin_emit_except_table_label (FILE *file) + rtx + darwin_make_eh_symbol_indirect (rtx orig, bool ARG_UNUSED (pubvis)) + { ++ if (DARWIN_ARM64) ++ return orig; + if (DARWIN_PPC == 0 && TARGET_64BIT) + return orig; + +@@ -3154,7 +3502,12 @@ darwin_file_end (void) + fprintf (asm_out_file, "\t.long\t0\n\t.long\t%u\n", flags); + } + ++#if !DARWIN_ARM64 + machopic_finish (asm_out_file); ++#else ++ gcc_checking_assert (!machopic_indirections); ++#endif ++ + if (flag_apple_kext) + { + /* These sections are only used for kernel code. */ +@@ -3330,6 +3683,13 @@ darwin_kextabi_p (void) { + return flag_apple_kext; + } + ++/* True, iff we want to map __builtin_unreachable to a trap. */ ++ ++bool ++darwin_unreachable_traps_p (void) { ++ return darwin_unreachable_traps; ++} ++ + void + darwin_override_options (void) + { +@@ -3350,7 +3710,14 @@ darwin_override_options (void) + generating_for_darwin_version = 8; + + /* Earlier versions are not specifically accounted, until required. */ ++ unsigned vers[3] = {0,0,0}; ++ if (!parse_version (vers, darwin_macosx_version_min)) ++ error_at (UNKNOWN_LOCATION, "how did we get a bad OS version? (%s)", ++ darwin_macosx_version_min); ++ current_os_version = version_from_version_array (vers); + } ++ else ++ current_os_version = 1058; + + /* Some codegen needs to account for the capabilities of the target + linker. */ +@@ -3592,6 +3959,11 @@ darwin_override_options (void) + + /* The c_dialect...() macros are not available to us here. */ + darwin_running_cxx = (strstr (lang_hooks.name, "C++") != 0); ++ ++ /* We need to consume attributes on function definitions from the the SDK ++ headers. */ ++ if (!OPTION_SET_P (flag_allow_ext_attr_placement)) ++ flag_allow_ext_attr_placement = true; + } + + #if DARWIN_PPC +diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h +index c09b9e9dc94..5370511bec2 100644 +--- a/gcc/config/darwin.h ++++ b/gcc/config/darwin.h +@@ -42,6 +42,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + + #define DARWIN_X86 0 + #define DARWIN_PPC 0 ++#define DARWIN_ARM64 0 + + #define OBJECT_FORMAT_MACHO 1 + +@@ -264,6 +265,8 @@ extern GTY(()) int darwin_ms_struct; + "%{weak_reference_mismatches*:\ + -Xlinker -weak_reference_mismatches -Xlinker %*} \ + %= 10.6 mmacosx-version-min= -no_compact_unwind) " ++"%{!fuse-ld=lld: \ ++ %:version-compare(>= 10.6 mmacosx-version-min= -no_compact_unwind)}" + + /* In Darwin linker specs we can put -lcrt0.o and ld will search the library + path for crt0.o or -lcrtx.a and it will search for libcrtx.a. As for +@@ -395,7 +399,8 @@ extern GTY(()) int darwin_ms_struct; + LINK_PLUGIN_SPEC \ + "%{flto*:% Specify that ld64 is the toolchain linker for the current invocation. + ++munreachable-traps ++Target Var(darwin_unreachable_traps) Init(1) ++When set (the default) this makes __builtin_unreachable render as a trap. ++ + ; Driver options. + + all_load +@@ -381,6 +385,10 @@ unexported_symbols_list + Driver RejectNegative Separate + -unexported_symbols_list Do not export the global symbols listed in . + ++weak_framework ++Driver RejectNegative Separate ++-weak_framework Make a weak link to the specified framework. ++ + weak_reference_mismatches + Driver RejectNegative Separate + -weak_reference_mismatches Specifies what to do if a symbol import conflicts between file (weak in one and not in another) the default is to treat the symbol as non-weak. +diff --git a/gcc/configure b/gcc/configure +index abc8bfdc244..4f3a5062736 100755 +--- a/gcc/configure ++++ b/gcc/configure +@@ -740,6 +740,8 @@ ORIGINAL_NM_FOR_TARGET + gcc_cv_nm + ORIGINAL_LD_GOLD_FOR_TARGET + ORIGINAL_LD_BFD_FOR_TARGET ++ORIGINAL_CLASSIC_LD_FOR_TARGET ++ORIGINAL_LLD_FOR_TARGET + ORIGINAL_LD_FOR_TARGET + ORIGINAL_PLUGIN_LD_FOR_TARGET + gcc_cv_ld +@@ -3803,20 +3805,19 @@ gcc_gxx_libcxx_include_dir= + + # Check whether --with-gxx-libcxx-include-dir was given. + if test "${with_gxx_libcxx_include_dir+set}" = set; then : +- withval=$with_gxx_libcxx_include_dir; case "${withval}" in +-yes) as_fn_error $? "bad value ${withval} given for libc++ include directory" "$LINENO" 5 ;; +-*) gcc_gxx_libcxx_include_dir=$with_gxx_libcxx_include_dir ;; +-esac ++ withval=$with_gxx_libcxx_include_dir; gcc_gxx_libcxx_include_dir=$with_gxx_libcxx_include_dir + fi + + + # --with-gxx-libcxx-include-dir controls the enabling of the -stdlib option. + # if --with-gxx-libcxx-include-dir is 'no' we disable the stdlib option. ++# if --with-gxx-libcxx-include-dir is 'yes' we enable the stdlib option and use ++# the default path within the installation. + # if --with-gxx-libcxx-include-dir is unset we enable the stdlib option +-# based on the platform (to be available on platform versions where it is the ++# based on the platform (to be available on platform versions where it is the + # default for the system tools). We also use a default path within the compiler +-# install tree. +-# Otherwise, we use the path provided and enable the stdlib option. ++# install tree. ++# Otherwise, we use the path provided and enable the stdlib option. + # If both --with-sysroot and --with-gxx-libcxx-include-dir are passed, we + # check to see if the latter starts with the former and, upon success, compute + # gcc_gxx_libcxx_include_dir as relative to the sysroot. +@@ -3824,16 +3825,20 @@ gcc_gxx_libcxx_include_dir_add_sysroot=0 + gcc_enable_stdlib_opt=0 + if test x${gcc_gxx_libcxx_include_dir} != x; then + if test x${gcc_gxx_libcxx_include_dir} = xno; then +- # set defaults for the dir, but the option is disabled anyway. ++ # set defaults for the dir, but the option is disabled anyway. ++ gcc_gxx_libcxx_include_dir= ++ elif test x${gcc_gxx_libcxx_include_dir} = xyes; then ++ # set defaults for the dir, and enable. + gcc_gxx_libcxx_include_dir= ++ gcc_enable_stdlib_opt=1 + else + gcc_enable_stdlib_opt=1 + fi + else + case $target in + *-darwin1[1-9]* | *-darwin2*) +- # Default this on for Darwin versions which default to libcxx, +- # and embed the path in the compiler install so that we get a ++ # Default this on for Darwin versions which default to libcxx, ++ # and embed the path in the compiler install so that we get a + # self-contained toolchain. + gcc_enable_stdlib_opt=1 + ;; +@@ -21575,7 +21580,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 21578 "configure" ++#line 21583 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -21681,7 +21686,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 21684 "configure" ++#line 21689 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -25306,6 +25311,14 @@ fi + $as_echo "$gold_non_default" >&6; } + + ORIGINAL_LD_FOR_TARGET=$gcc_cv_ld ++if test x"$ld64_flag" = x"yes"; then ++ORIGINAL_LLD_FOR_TARGET=${gcc_cv_ld}64.lld ++else ++ORIGINAL_LLD_FOR_TARGET=$gcc_cv_lld ++fi ++ORIGINAL_CLASSIC_LD_FOR_TARGET=$gcc_cv_ld-classic ++ ++ + + case "$ORIGINAL_LD_FOR_TARGET" in + ./collect-ld | ./collect-ld$build_exeext) ;; +diff --git a/gcc/configure.ac b/gcc/configure.ac +index 1d2cefa3f6a..e12a237ea11 100644 +--- a/gcc/configure.ac ++++ b/gcc/configure.ac +@@ -235,18 +235,17 @@ gcc_gxx_libcxx_include_dir= + AC_ARG_WITH(gxx-libcxx-include-dir, + [AS_HELP_STRING([--with-gxx-libcxx-include-dir=DIR], + [specifies directory to find libc++ header files])], +-[case "${withval}" in +-yes) AC_MSG_ERROR(bad value ${withval} given for libc++ include directory) ;; +-*) gcc_gxx_libcxx_include_dir=$with_gxx_libcxx_include_dir ;; +-esac]) ++[gcc_gxx_libcxx_include_dir=$with_gxx_libcxx_include_dir]) + + # --with-gxx-libcxx-include-dir controls the enabling of the -stdlib option. + # if --with-gxx-libcxx-include-dir is 'no' we disable the stdlib option. ++# if --with-gxx-libcxx-include-dir is 'yes' we enable the stdlib option and use ++# the default path within the installation. + # if --with-gxx-libcxx-include-dir is unset we enable the stdlib option +-# based on the platform (to be available on platform versions where it is the ++# based on the platform (to be available on platform versions where it is the + # default for the system tools). We also use a default path within the compiler +-# install tree. +-# Otherwise, we use the path provided and enable the stdlib option. ++# install tree. ++# Otherwise, we use the path provided and enable the stdlib option. + # If both --with-sysroot and --with-gxx-libcxx-include-dir are passed, we + # check to see if the latter starts with the former and, upon success, compute + # gcc_gxx_libcxx_include_dir as relative to the sysroot. +@@ -254,16 +253,20 @@ gcc_gxx_libcxx_include_dir_add_sysroot=0 + gcc_enable_stdlib_opt=0 + if test x${gcc_gxx_libcxx_include_dir} != x; then + if test x${gcc_gxx_libcxx_include_dir} = xno; then +- # set defaults for the dir, but the option is disabled anyway. ++ # set defaults for the dir, but the option is disabled anyway. + gcc_gxx_libcxx_include_dir= ++ elif test x${gcc_gxx_libcxx_include_dir} = xyes; then ++ # set defaults for the dir, and enable. ++ gcc_gxx_libcxx_include_dir= ++ gcc_enable_stdlib_opt=1 + else + gcc_enable_stdlib_opt=1 + fi + else + case $target in + *-darwin1[[1-9]]* | *-darwin2*) +- # Default this on for Darwin versions which default to libcxx, +- # and embed the path in the compiler install so that we get a ++ # Default this on for Darwin versions which default to libcxx, ++ # and embed the path in the compiler install so that we get a + # self-contained toolchain. + gcc_enable_stdlib_opt=1 + ;; +@@ -2817,7 +2820,15 @@ fi + AC_MSG_RESULT($gold_non_default) + + ORIGINAL_LD_FOR_TARGET=$gcc_cv_ld ++if test x"$ld64_flag" = x"yes"; then ++ORIGINAL_LLD_FOR_TARGET=${gcc_cv_ld}64.lld ++else ++ORIGINAL_LLD_FOR_TARGET=$gcc_cv_lld ++fi ++ORIGINAL_CLASSIC_LD_FOR_TARGET=$gcc_cv_ld-classic + AC_SUBST(ORIGINAL_LD_FOR_TARGET) ++AC_SUBST(ORIGINAL_LLD_FOR_TARGET) ++AC_SUBST(ORIGINAL_CLASSIC_LD_FOR_TARGET) + case "$ORIGINAL_LD_FOR_TARGET" in + ./collect-ld | ./collect-ld$build_exeext) ;; + *) AC_CONFIG_FILES(collect-ld:exec-tool.in, [chmod +x collect-ld]) ;; +diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc +index af2e08c8a63..5a054e75740 100644 +--- a/gcc/cp/decl2.cc ++++ b/gcc/cp/decl2.cc +@@ -3839,9 +3839,8 @@ get_tls_init_fn (tree var) + if (!flag_extern_tls_init && DECL_EXTERNAL (var)) + return NULL_TREE; + +- /* If the variable is internal, or if we can't generate aliases, +- call the local init function directly. */ +- if (!TREE_PUBLIC (var) || !TARGET_SUPPORTS_ALIASES) ++ /* If the variable is internal call the local init function directly. */ ++ if (!TREE_PUBLIC (var)) + return get_local_tls_init_fn (DECL_SOURCE_LOCATION (var)); + + tree sname = mangle_tls_init_fn (var); +@@ -4005,6 +4004,25 @@ generate_tls_wrapper (tree fn) + expand_or_defer_fn (finish_function (/*inline_p=*/false)); + } + ++/* A dummy init function to act as a weak placeholder for a (possibly non- ++ existent) dynamic init. */ ++static void ++generate_tls_dummy_init (tree fn) ++{ ++ tree var = DECL_BEFRIENDING_CLASSES (fn); ++ tree init_fn = get_tls_init_fn (var); ++ /* If have no init fn, or it is non-weak, then we do not need to make a ++ dummy. */ ++ if (!init_fn || !lookup_attribute ("weak", DECL_ATTRIBUTES (init_fn))) ++ return; ++ start_preparsed_function (init_fn, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED); ++ tree body = begin_function_body (); ++ declare_weak (init_fn); ++ finish_return_stmt (NULL_TREE); ++ finish_function_body (body); ++ expand_or_defer_fn (finish_function (/*inline_p=*/false)); ++} ++ + /* Start a global constructor or destructor function. */ + + static tree +@@ -4823,22 +4841,24 @@ handle_tls_init (void) + finish_expr_stmt (cp_build_modify_expr (loc, guard, NOP_EXPR, + boolean_true_node, + tf_warning_or_error)); ++ auto_vec direct_calls; + for (; vars; vars = TREE_CHAIN (vars)) + { + tree var = TREE_VALUE (vars); + tree init = TREE_PURPOSE (vars); + one_static_initialization_or_destruction (/*initp=*/true, var, init); + +- /* Output init aliases even with -fno-extern-tls-init. */ +- if (TARGET_SUPPORTS_ALIASES && TREE_PUBLIC (var)) ++ /* Output inits even with -fno-extern-tls-init. ++ We save the list here and output either an alias or a stub function ++ below. */ ++ if (TREE_PUBLIC (var)) + { +- tree single_init_fn = get_tls_init_fn (var); ++ tree single_init_fn = get_tls_init_fn (var); + if (single_init_fn == NULL_TREE) + continue; +- cgraph_node *alias +- = cgraph_node::get_create (fn)->create_same_body_alias +- (single_init_fn, fn); +- gcc_assert (alias != NULL); ++ if (single_init_fn == fn) ++ continue; ++ direct_calls.safe_push (single_init_fn); + } + } + +@@ -4846,6 +4866,30 @@ handle_tls_init (void) + finish_if_stmt (if_stmt); + finish_function_body (body); + expand_or_defer_fn (finish_function (/*inline_p=*/false)); ++ ++ /* For each TLS var that we have an init function, we either emit an alias ++ between that and the tls_init, or a stub function that just calls the ++ tls_init. */ ++ while (!direct_calls.is_empty()) ++ { ++ tree single_init_fn = direct_calls.pop (); ++ if (TARGET_SUPPORTS_ALIASES) ++ { ++ cgraph_node *alias ++ = cgraph_node::get_create (fn)->create_same_body_alias ++ (single_init_fn, fn); ++ gcc_assert (alias != NULL); ++ } ++ else ++ { ++ start_preparsed_function (single_init_fn, NULL_TREE, SF_PRE_PARSED); ++ tree body = begin_function_body (); ++ tree r = build_call_expr (fn, 0); ++ finish_expr_stmt (r); ++ finish_function_body (body); ++ expand_or_defer_fn (finish_function (/*inline_p=*/false)); ++ } ++ } + } + + /* We're at the end of compilation, so generate any mangling aliases that +@@ -5265,7 +5309,14 @@ c_parse_final_cleanups (void) + } + + if (!DECL_INITIAL (decl) && decl_tls_wrapper_p (decl)) +- generate_tls_wrapper (decl); ++ { ++ generate_tls_wrapper (decl); ++ /* The wrapper might have a weak reference to an init, we provide ++ a dummy function to satisfy that here. The linker/dynamic ++ loader will override this with the actual init, if one is ++ required. */ ++ generate_tls_dummy_init (decl); ++ } + + if (!DECL_SAVED_TREE (decl)) + continue; +diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc +index 7e81c1010c4..b6ea2e5e529 100644 +--- a/gcc/cp/parser.cc ++++ b/gcc/cp/parser.cc +@@ -705,6 +705,91 @@ cp_lexer_handle_early_pragma (cp_lexer *lexer) + static cp_parser *cp_parser_new (cp_lexer *); + static GTY (()) cp_parser *the_parser; + ++/* Context-sensitive parse-checking for clang-style attributes. */ ++ ++enum clang_attr_state { ++ CA_NONE = 0, ++ CA_ATTR, ++ CA_BR1, CA_BR2, ++ CA_LIST, ++ CA_LIST_ARGS, ++ CA_IS_CA, ++ CA_CA_ARGS, ++ CA_LIST_CONT ++}; ++ ++/* State machine tracking context of attribute lexing. */ ++ ++static enum clang_attr_state ++cp_lexer_attribute_state (cp_token& token, enum clang_attr_state attr_state) ++{ ++ /* Implement a context-sensitive parser for clang attributes. ++ We detect __attribute__((clang_style_attribute (ARGS))) and lex the ++ args ARGS with the following differences from GNU attributes: ++ (a) number-like values are lexed as strings [this allows lexing XX.YY.ZZ ++ version numbers]. ++ (b) we concatenate strings, since clang attributes allow this too. */ ++ switch (attr_state) ++ { ++ case CA_NONE: ++ if (token.type == CPP_KEYWORD ++ && token.keyword == RID_ATTRIBUTE) ++ attr_state = CA_ATTR; ++ break; ++ case CA_ATTR: ++ if (token.type == CPP_OPEN_PAREN) ++ attr_state = CA_BR1; ++ else ++ attr_state = CA_NONE; ++ break; ++ case CA_BR1: ++ if (token.type == CPP_OPEN_PAREN) ++ attr_state = CA_BR2; ++ else ++ attr_state = CA_NONE; ++ break; ++ case CA_BR2: ++ if (token.type == CPP_NAME) ++ { ++ tree identifier = (token.type == CPP_KEYWORD) ++ /* For keywords, use the canonical spelling, not the ++ parsed identifier. */ ++ ? ridpointers[(int) token.keyword] ++ : token.u.value; ++ identifier = canonicalize_attr_name (identifier); ++ if (attribute_clang_form_p (identifier)) ++ attr_state = CA_IS_CA; ++ else ++ attr_state = CA_LIST; ++ } ++ else ++ attr_state = CA_NONE; ++ break; ++ case CA_IS_CA: ++ case CA_LIST: ++ if (token.type == CPP_COMMA) ++ attr_state = CA_BR2; /* Back to the list outer. */ ++ else if (token.type == CPP_OPEN_PAREN) ++ attr_state = attr_state == CA_IS_CA ? CA_CA_ARGS ++ : CA_LIST_ARGS; ++ else ++ attr_state = CA_NONE; ++ break; ++ case CA_CA_ARGS: /* We will special-case args in this state. */ ++ case CA_LIST_ARGS: ++ if (token.type == CPP_CLOSE_PAREN) ++ attr_state = CA_LIST_CONT; ++ break; ++ case CA_LIST_CONT: ++ if (token.type == CPP_COMMA) ++ attr_state = CA_BR2; /* Back to the list outer. */ ++ else ++ attr_state = CA_NONE; ++ break; ++ } ++ return attr_state; ++} ++ + /* Create a new main C++ lexer, the lexer that gets tokens from the + preprocessor, and also create the main parser. */ + +@@ -721,6 +806,8 @@ cp_lexer_new_main (void) + c_common_no_more_pch (); + + cp_lexer *lexer = cp_lexer_alloc (); ++ enum clang_attr_state attr_state = CA_NONE; ++ + /* Put the first token in the buffer. */ + cp_token *tok = lexer->buffer->quick_push (token); + +@@ -744,8 +831,14 @@ cp_lexer_new_main (void) + if (tok->type == CPP_PRAGMA_EOL) + cp_lexer_handle_early_pragma (lexer); + ++ attr_state = cp_lexer_attribute_state (*tok, attr_state); + tok = vec_safe_push (lexer->buffer, cp_token ()); +- cp_lexer_get_preprocessor_token (C_LEX_STRING_NO_JOIN, tok); ++ unsigned int flags = C_LEX_STRING_NO_JOIN; ++ /* If we are processing clang-style attribute args, lex numbers as ++ potential version strings; NN .. NN.MM .. NN.MM.OO */ ++ if (attr_state == CA_CA_ARGS) ++ flags |= C_LEX_NUMBER_AS_STRING; ++ cp_lexer_get_preprocessor_token (flags, tok); + } + + lexer->next_token = lexer->buffer->address (); +@@ -962,7 +1055,7 @@ cp_lexer_get_preprocessor_token (unsigned flags, cp_token *token) + { + static int is_extern_c = 0; + +- /* Get a new token from the preprocessor. */ ++ /* Get a new token from the preprocessor. */ + token->type + = c_lex_with_flags (&token->u.value, &token->location, &token->flags, + flags); +@@ -23348,9 +23441,16 @@ cp_parser_init_declarator (cp_parser* parser, + "an % specification is not allowed " + "on a function-definition"); + if (attributes) +- error_at (attributes_start_token->location, +- "attributes are not allowed " +- "on a function-definition"); ++ { ++ /* When we are allowing attributes in this position, then add ++ them to the prefix ones. */ ++ if (flag_allow_ext_attr_placement) ++ prefix_attributes = chainon (prefix_attributes, attributes); ++ else ++ error_at (attributes_start_token->location, ++ "attributes are not allowed " ++ "on a function-definition"); ++ } + /* This is a function-definition. */ + *function_definition_p = true; + +@@ -29707,6 +29807,91 @@ cp_parser_gnu_attributes_opt (cp_parser* parser) + return attributes; + } + ++/* Parse the arguments list for a clang attribute. */ ++static tree ++cp_parser_clang_attribute (cp_parser *parser, tree/*attr_id*/) ++{ ++ /* Each entry can be : ++ identifier ++ identifier=N.MM.Z ++ identifier="string" ++ followed by ',' or ) for the last entry*/ ++ ++ matching_parens parens; ++ if (!parens.require_open (parser)) ++ return NULL; ++ ++ bool save_translate_strings_p = parser->translate_strings_p; ++ parser->translate_strings_p = false; ++ tree attr_args = NULL_TREE; ++ cp_token *token; ++ do ++ { ++ tree name = NULL_TREE; ++ tree value = NULL_TREE; ++ ++ token = cp_lexer_peek_token (parser->lexer); ++ if (token->type == CPP_NAME) ++ name = token->u.value; ++ else if (token->type == CPP_KEYWORD) ++ name = ridpointers[(int) token->keyword]; ++ else if (token->flags & NAMED_OP) ++ name = get_identifier (cpp_type2name (token->type, token->flags)); ++ else ++ { ++ /* FIXME: context-sensitive for that attrib. */ ++ error_at (token->location, "expected an attribute keyword"); ++ cp_parser_skip_to_closing_parenthesis (parser, ++ /*recovering=*/true, ++ /*or_comma=*/false, ++ /*consume_paren=*/false); ++ attr_args = error_mark_node; ++ break; ++ } ++ cp_lexer_consume_token (parser->lexer); ++ ++ if (cp_lexer_next_token_is (parser->lexer, CPP_EQ)) ++ { ++ cp_lexer_consume_token (parser->lexer); /* eat the '=' */ ++ if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN) ++ && cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA)) ++ { ++ token = cp_lexer_peek_token (parser->lexer); ++ if (token->type == CPP_STRING) ++ value = cp_parser_string_literal (parser, /*translate=*/false, ++ /*wide_ok=*/false); ++ else ++ { ++ value = token->u.value; ++ cp_lexer_consume_token (parser->lexer); ++ } ++ } ++ /* else value is missing. */ ++ } ++ else if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN) ++ && cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA)) ++ { ++ error_at (token->location, "expected %<,%>, %<=%> or %<)%>"); ++ cp_parser_skip_to_closing_parenthesis (parser, ++ /*recovering=*/true, ++ /*or_comma=*/false, ++ /*consume_paren=*/false); ++ attr_args = error_mark_node; ++ break; ++ } ++ if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA)) ++ cp_lexer_consume_token (parser->lexer); ++ tree t = tree_cons (value, name, NULL_TREE); ++ attr_args = chainon (attr_args, t); ++ } while (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN)); ++ ++ parser->translate_strings_p = save_translate_strings_p; ++ if (!parens.require_close (parser)) ++ return error_mark_node; ++ ++ return attr_args; ++} ++ + /* Parse a GNU attribute-list. + + attribute-list: +@@ -29766,9 +29951,12 @@ cp_parser_gnu_attribute_list (cp_parser* parser, bool exactly_one /* = false */) + + /* Peek at the next token. */ + token = cp_lexer_peek_token (parser->lexer); +- /* If it's an `(', then parse the attribute arguments. */ +- if (token->type == CPP_OPEN_PAREN) ++ if (token->type == CPP_OPEN_PAREN ++ && attribute_clang_form_p (identifier)) ++ arguments = cp_parser_clang_attribute (parser, identifier); ++ else if (token->type == CPP_OPEN_PAREN) + { ++ /* If it's an `(', then parse the attribute arguments. */ + vec *vec; + int attr_flag = (attribute_takes_identifier_p (identifier) + ? id_attr : normal_attr); +@@ -29785,12 +29973,12 @@ cp_parser_gnu_attribute_list (cp_parser* parser, bool exactly_one /* = false */) + arguments = build_tree_list_vec (vec); + release_tree_vector (vec); + } +- /* Save the arguments away. */ +- TREE_VALUE (attribute) = arguments; + } + + if (arguments != error_mark_node) + { ++ /* Save the arguments away. */ ++ TREE_VALUE (attribute) = arguments; + /* Add this attribute to the list. */ + TREE_CHAIN (attribute) = attribute_list; + attribute_list = attribute; +diff --git a/gcc/cumulative-args.h b/gcc/cumulative-args.h +new file mode 100644 +index 00000000000..b60928e37f9 +--- /dev/null ++++ b/gcc/cumulative-args.h +@@ -0,0 +1,20 @@ ++#ifndef GCC_CUMULATIVE_ARGS_H ++#define GCC_CUMULATIVE_ARGS_H ++ ++#if CHECKING_P ++ ++struct cumulative_args_t { void *magic; void *p; }; ++ ++#else /* !CHECKING_P */ ++ ++/* When using a GCC build compiler, we could use ++ __attribute__((transparent_union)) to get cumulative_args_t function ++ arguments passed like scalars where the ABI would mandate a less ++ efficient way of argument passing otherwise. However, that would come ++ at the cost of less type-safe !CHECKING_P compilation. */ ++ ++union cumulative_args_t { void *p; }; ++ ++#endif /* !CHECKING_P */ ++ ++#endif /* GCC_CUMULATIVE_ARGS_H */ +diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi +index f82f7d2817b..37fc1e3f9ee 100644 +--- a/gcc/doc/invoke.texi ++++ b/gcc/doc/invoke.texi +@@ -732,7 +732,7 @@ Objective-C and Objective-C++ Dialects}. + -freg-struct-return -fshort-enums -fshort-wchar + -fverbose-asm -fpack-struct[=@var{n}] + -fleading-underscore -ftls-model=@var{model} +--fstack-reuse=@var{reuse_level} ++-fstack-reuse=@var{reuse_level} -fstack-use-cumulative-args + -ftrampolines -ftrampoline-impl=@r{[}stack@r{|}heap@r{]} + -ftrapv -fwrapv + -fvisibility=@r{[}default@r{|}internal@r{|}hidden@r{|}protected@r{]} +@@ -954,7 +954,7 @@ Objective-C and Objective-C++ Dialects}. + -twolevel_namespace -umbrella -undefined + -unexported_symbols_list -weak_reference_mismatches + -whatsloaded -F -gused -gfull -mmacosx-version-min=@var{version} +--mkernel -mone-byte-bool} ++-mkernel -mone-byte-bool -munreachable-traps} + + @emph{DEC Alpha Options} + @gccoptlist{-mno-fp-regs -msoft-float +@@ -19132,6 +19132,17 @@ the behavior of older compilers in which temporaries' stack space is + not reused, the aggressive stack reuse can lead to runtime errors. This + option is used to control the temporary stack reuse optimization. + ++@opindex fstack_use_cumulative_args ++@item -fstack-use-cumulative-args ++This option instructs the compiler to use the ++@code{cumulative_args_t}-based stack layout target hooks, ++@code{TARGET_FUNCTION_ARG_BOUNDARY_CA} and ++@code{TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA}. If a given target does ++not define these hooks, the default behaviour is to fallback to using ++the standard non-@code{_CA} variants instead. Certain targets (such as ++AArch64 Darwin) require using the more advanced @code{_CA}-based ++hooks: For these targets this option should be enabled by default. ++ + @opindex ftrapv + @item -ftrapv + This option generates traps for signed overflow on addition, subtraction, +@@ -25148,6 +25159,11 @@ without that switch. Using this switch may require recompiling all + other modules in a program, including system libraries. Use this + switch to conform to a non-default data model. + ++@opindex munreachable-traps ++@item -munreachable-traps ++Causes @code{__builtin_unreachable} to be rendered as a trap. This is the ++default for all Darwin architectures. ++ + @opindex mfix-and-continue + @opindex ffix-and-continue + @opindex findirect-data +diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi +index cd50078227d..00df8aeb6b4 100644 +--- a/gcc/doc/tm.texi ++++ b/gcc/doc/tm.texi +@@ -1066,6 +1066,10 @@ also define the hook to @code{default_promote_function_mode_always_promote} + if you would like to apply the same rules given by @code{PROMOTE_MODE}. + @end deftypefn + ++@deftypefn {Target Hook} machine_mode TARGET_PROMOTE_FUNCTION_MODE_CA (cumulative_args_t, @var{function_arg_info}, @var{const_tree}, int *@var{}, @var{int}) ++Like @code{promote_function_mode}, but takes a cumulative_args pointer and a current arg to supply the input. ++@end deftypefn ++ + @defmac PARM_BOUNDARY + Normal alignment required for function parameters on the stack, in + bits. All stack parameters receive at least this much alignment +@@ -4471,6 +4475,16 @@ with the specified mode and type. The default hook returns + @code{PARM_BOUNDARY} for all arguments. + @end deftypefn + ++@deftypefn {Target Hook} {unsigned int} TARGET_FUNCTION_ARG_BOUNDARY_CA (machine_mode @var{mode}, const_tree @var{type}, cumulative_args_t @var{ca}) ++This is the @code{cumulative_args_t}-based version of ++@code{TARGET_FUNCTION_ARG_BOUNDARY}. Define this hook if you need more ++fine-grained control over argument alignment, e.g. depending on whether ++it is a named argument or not, or any other criteria that you choose to ++place in the @var{ca} structure. ++ ++The default hook will call @code{TARGET_FUNCTION_ARG_BOUNDARY}. ++@end deftypefn ++ + @deftypefn {Target Hook} {unsigned int} TARGET_FUNCTION_ARG_ROUND_BOUNDARY (machine_mode @var{mode}, const_tree @var{type}) + Normally, the size of an argument is rounded up to @code{PARM_BOUNDARY}, + which is the default value for this hook. You can define this hook to +@@ -4478,6 +4492,16 @@ return a different value if an argument size must be rounded to a larger + value. + @end deftypefn + ++@deftypefn {Target Hook} {unsigned int} TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA (machine_mode @var{mode}, const_tree @var{type}, cumulative_args_t @var{ca}) ++This is the @code{cumulative_args_t}-based version of ++@code{TARGET_FUNCTION_ARG_ROUND_BOUNDARY}. Define this hook if you need more ++fine-grained control over argument size rounding, e.g. depending on whether ++it is a named argument or not, or any other criteria that you choose to ++place in the @var{ca} structure. ++ ++The default hook will call @code{TARGET_FUNCTION_ARG_ROUND_BOUNDARY}. ++@end deftypefn ++ + @defmac FUNCTION_ARG_REGNO_P (@var{regno}) + A C expression that is nonzero if @var{regno} is the number of a hard + register in which function arguments are sometimes passed. This does +@@ -12709,6 +12733,11 @@ This target hook can be used to generate a target-specific code + If selftests are enabled, run any selftests for this target. + @end deftypefn + ++@deftypefn {Target Hook} bool TARGET_UNREACHABLE_SHOULD_TRAP (void) ++This hook should return @code{true} if the target wants @code{__builtin_unreachable} to expand to a trap or @code{abort ()}. ++ The default value is false. ++@end deftypefn ++ + @deftypefn {Target Hook} bool TARGET_MEMTAG_CAN_TAG_ADDRESSES () + True if the backend architecture naturally supports ignoring some region + of pointers. This feature means that @option{-fsanitize=hwaddress} can +diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in +index 058bd56487a..0ded0f992d4 100644 +--- a/gcc/doc/tm.texi.in ++++ b/gcc/doc/tm.texi.in +@@ -949,6 +949,8 @@ applied. + + @hook TARGET_PROMOTE_FUNCTION_MODE + ++@hook TARGET_PROMOTE_FUNCTION_MODE_CA ++ + @defmac PARM_BOUNDARY + Normal alignment required for function parameters on the stack, in + bits. All stack parameters receive at least this much alignment +@@ -3441,8 +3443,12 @@ required. + + @hook TARGET_FUNCTION_ARG_BOUNDARY + ++@hook TARGET_FUNCTION_ARG_BOUNDARY_CA ++ + @hook TARGET_FUNCTION_ARG_ROUND_BOUNDARY + ++@hook TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA ++ + @defmac FUNCTION_ARG_REGNO_P (@var{regno}) + A C expression that is nonzero if @var{regno} is the number of a hard + register in which function arguments are sometimes passed. This does +@@ -8099,6 +8105,8 @@ maintainer is familiar with. + + @hook TARGET_RUN_TARGET_SELFTESTS + ++@hook TARGET_UNREACHABLE_SHOULD_TRAP ++ + @hook TARGET_MEMTAG_CAN_TAG_ADDRESSES + + @hook TARGET_MEMTAG_TAG_SIZE +diff --git a/gcc/exec-tool.in b/gcc/exec-tool.in +index 7d152e083a7..ec1a144e415 100644 +--- a/gcc/exec-tool.in ++++ b/gcc/exec-tool.in +@@ -23,6 +23,8 @@ ORIGINAL_AS_FOR_TARGET="@ORIGINAL_AS_FOR_TARGET@" + ORIGINAL_LD_FOR_TARGET="@ORIGINAL_LD_FOR_TARGET@" + ORIGINAL_LD_BFD_FOR_TARGET="@ORIGINAL_LD_BFD_FOR_TARGET@" + ORIGINAL_LD_GOLD_FOR_TARGET="@ORIGINAL_LD_GOLD_FOR_TARGET@" ++ORIGINAL_LLD_FOR_TARGET="@ORIGINAL_LLD_FOR_TARGET@" ++ORIGINAL_CLASSIC_LD_FOR_TARGET="@ORIGINAL_CLASSIC_LD_FOR_TARGET@" + ORIGINAL_PLUGIN_LD_FOR_TARGET="@ORIGINAL_PLUGIN_LD_FOR_TARGET@" + ORIGINAL_NM_FOR_TARGET="@ORIGINAL_NM_FOR_TARGET@" + ORIGINAL_DSYMUTIL_FOR_TARGET="@ORIGINAL_DSYMUTIL_FOR_TARGET@" +@@ -39,24 +41,41 @@ case "$invoked" in + dir=gas + ;; + collect-ld) +- # Check -fuse-ld=bfd and -fuse-ld=gold +- case " $* " in +- *\ -fuse-ld=bfd\ *) +- original=$ORIGINAL_LD_BFD_FOR_TARGET +- ;; +- *\ -fuse-ld=gold\ *) +- original=$ORIGINAL_LD_GOLD_FOR_TARGET +- ;; +- *) +- # when using a linker plugin, gcc will always pass '-plugin' as the +- # first or second option to the linker. +- if test x"$1" = "x-plugin" || test x"$2" = "x-plugin"; then +- original=$ORIGINAL_PLUGIN_LD_FOR_TARGET +- else +- original=$ORIGINAL_LD_FOR_TARGET +- fi +- ;; +- esac ++ # when using a linker plugin, gcc will always pass '-plugin' as the ++ # first or second option to the linker. ++ if test x"$1" = "x-plugin" || test x"$2" = "x-plugin"; then ++ original=$ORIGINAL_PLUGIN_LD_FOR_TARGET ++ else ++ original=$ORIGINAL_LD_FOR_TARGET ++ fi ++ # Check -fuse-ld=bfd, -fuse-ld=gold and -fuse-ld=classic ++ # Remove -fuse-ld=classic from the command line ++ for arg do ++ # temporarily, remove the arg. ++ shift ++ case $arg in ++ -fuse-ld=bfd) ++ original=$ORIGINAL_LD_BFD_FOR_TARGET ++ ;; ++ -fuse-ld=gold) ++ original=$ORIGINAL_LD_GOLD_FOR_TARGET ++ ;; ++ -fuse-ld=lld) ++ original=$ORIGINAL_LLD_FOR_TARGET ++ # We want to remove this from the command line; by the slightly ++ # obtuse mechanism of not putting it back. ++ continue ++ ;; ++ -fuse-ld=classic) ++ original=$ORIGINAL_CLASSIC_LD_FOR_TARGET ++ # As for lld. ++ continue ++ ;; ++ *) ;; ++ esac ++ # if we want to keep the arg, put it back. ++ set -- "$@" "$arg" ++ done + prog=ld-new$exeext + if test "$original" = ../gold/ld-new$exeext; then + dir=gold +diff --git a/gcc/explow.cc b/gcc/explow.cc +index 8e5f6b8e680..ab5e9819117 100644 +--- a/gcc/explow.cc ++++ b/gcc/explow.cc +@@ -37,6 +37,7 @@ along with GCC; see the file COPYING3. If not see + #include "langhooks.h" + #include "except.h" + #include "dojump.h" ++#include "calls.h" + #include "explow.h" + #include "expr.h" + #include "stringpool.h" +@@ -817,6 +818,16 @@ promote_function_mode (const_tree type, machine_mode mode, int *punsignedp, + return mode; + } + } ++ ++machine_mode ++promote_function_mode (cumulative_args_t args_so_far, function_arg_info arg, ++ const_tree funtype, int *punsignedp , int for_return) ++{ ++ return targetm.calls.promote_function_mode_ca (args_so_far, arg, funtype, ++ punsignedp, for_return); ++// return promote_function_mode (arg.type, arg.mode, punsignedp, funtype, for_return); ++} ++ + /* Return the mode to use to store a scalar of TYPE and MODE. + PUNSIGNEDP points to the signedness of the type and may be adjusted + to show what signedness to use on extension operations. */ +diff --git a/gcc/explow.h b/gcc/explow.h +index 16aa02cfb68..6cc989798be 100644 +--- a/gcc/explow.h ++++ b/gcc/explow.h +@@ -20,6 +20,8 @@ along with GCC; see the file COPYING3. If not see + #ifndef GCC_EXPLOW_H + #define GCC_EXPLOW_H + ++#include "calls.h" /* for cummulative args stuff. */ ++ + /* Return a memory reference like MEMREF, but which is known to have a + valid address. */ + extern rtx validize_mem (rtx); +@@ -47,8 +49,13 @@ extern rtx force_not_mem (rtx); + + /* Return mode and signedness to use when an argument or result in the + given mode is promoted. */ +-extern machine_mode promote_function_mode (const_tree, machine_mode, int *, +- const_tree, int); ++machine_mode promote_function_mode (const_tree, machine_mode, int *, ++ const_tree, int); ++ ++/* Return mode and signedness to use when an argument or result in the ++ given mode is promoted. */ ++machine_mode promote_function_mode (cumulative_args_t, function_arg_info, ++ const_tree, int *, int); + + /* Return mode and signedness to use when an object in the given mode + is promoted. */ +diff --git a/gcc/function.cc b/gcc/function.cc +index 4edd4da1247..7e5434fd2af 100644 +--- a/gcc/function.cc ++++ b/gcc/function.cc +@@ -58,8 +58,8 @@ along with GCC; see the file COPYING3. If not see + #include "varasm.h" + #include "except.h" + #include "dojump.h" +-#include "explow.h" + #include "calls.h" ++#include "explow.h" + #include "expr.h" + #include "optabs-tree.h" + #include "output.h" +@@ -2449,7 +2449,10 @@ assign_parm_find_data_types (struct assign_parm_data_all *all, tree parm, + else if (DECL_CHAIN (parm)) + data->arg.named = 1; /* Not the last non-variadic parm. */ + else if (targetm.calls.strict_argument_naming (all->args_so_far)) +- data->arg.named = 1; /* Only variadic ones are unnamed. */ ++ { ++ data->arg.named = 1; /* Only variadic ones are unnamed. */ ++ data->arg.last_named = 1; ++ } + else + data->arg.named = 0; /* Treat as variadic. */ + +@@ -2491,9 +2494,12 @@ assign_parm_find_data_types (struct assign_parm_data_all *all, tree parm, + + /* Find mode as it is passed by the ABI. */ + unsignedp = TYPE_UNSIGNED (data->arg.type); +- data->arg.mode +- = promote_function_mode (data->arg.type, data->arg.mode, &unsignedp, +- TREE_TYPE (current_function_decl), 0); ++// data->arg.mode ++// = promote_function_mode (data->arg.type, data->arg.mode, &unsignedp, ++// TREE_TYPE (current_function_decl), 0); ++ data->arg.mode = promote_function_mode (all->args_so_far, data->arg, ++ TREE_TYPE (current_function_decl), ++ &unsignedp, 0); + } + + /* A subroutine of assign_parms. Invoke setup_incoming_varargs. */ +@@ -2506,6 +2512,7 @@ assign_parms_setup_varargs (struct assign_parm_data_all *all, + + function_arg_info last_named_arg = data->arg; + last_named_arg.named = true; ++ last_named_arg.last_named = true; + targetm.calls.setup_incoming_varargs (all->args_so_far, last_named_arg, + &varargs_pretend_bytes, no_rtl); + +@@ -2614,7 +2621,9 @@ assign_parm_find_entry_rtl (struct assign_parm_data_all *all, + + locate_and_pad_parm (data->arg.mode, data->arg.type, in_regs, + all->reg_parm_stack_space, +- entry_parm ? data->partial : 0, current_function_decl, ++ entry_parm ? data->partial : 0, ++ all->args_so_far, ++ current_function_decl, + &all->stack_args_size, &data->locate); + + /* Update parm_stack_boundary if this parameter is passed in the +@@ -3921,7 +3930,8 @@ gimplify_parameters (gimple_seq *cleanup) + if (data.arg.pass_by_reference) + { + tree type = TREE_TYPE (data.arg.type); +- function_arg_info orig_arg (type, data.arg.named); ++ function_arg_info orig_arg (type, data.arg.named, ++ data.arg.last_named); + if (reference_callee_copied (&all.args_so_far_v, orig_arg)) + { + tree local, t; +@@ -4024,6 +4034,7 @@ gimplify_parameters (gimple_seq *cleanup) + void + locate_and_pad_parm (machine_mode passed_mode, tree type, int in_regs, + int reg_parm_stack_space, int partial, ++ cumulative_args_t ca, + tree fndecl ATTRIBUTE_UNUSED, + struct args_size *initial_offset_ptr, + struct locate_and_pad_arg_data *locate) +@@ -4061,9 +4072,23 @@ locate_and_pad_parm (machine_mode passed_mode, tree type, int in_regs, + ? arg_size_in_bytes (type) + : size_int (GET_MODE_SIZE (passed_mode))); + where_pad = targetm.calls.function_arg_padding (passed_mode, type); +- boundary = targetm.calls.function_arg_boundary (passed_mode, type); +- round_boundary = targetm.calls.function_arg_round_boundary (passed_mode, +- type); ++ ++ if (flag_stack_use_cumulative_args) ++ { ++ boundary = targetm.calls.function_arg_boundary_ca (passed_mode, ++ type, ++ ca); ++ round_boundary = targetm.calls.function_arg_round_boundary_ca ++ (passed_mode, type, ca); ++ } ++ else ++ { ++ boundary = targetm.calls.function_arg_boundary (passed_mode, ++ type); ++ round_boundary = targetm.calls.function_arg_round_boundary ++ (passed_mode, type); ++ } ++ + locate->where_pad = where_pad; + + /* Alignment can't exceed MAX_SUPPORTED_STACK_ALIGNMENT. */ +diff --git a/gcc/function.h b/gcc/function.h +index c0ba6cc1531..520fde7694c 100644 +--- a/gcc/function.h ++++ b/gcc/function.h +@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3. If not see + #ifndef GCC_FUNCTION_H + #define GCC_FUNCTION_H + ++#include "cumulative-args.h" + + /* Stack of pending (incomplete) sequences saved by `start_sequence'. + Each element describes one pending sequence. +@@ -680,6 +681,7 @@ extern bool aggregate_value_p (const_tree, const_tree); + extern bool use_register_for_decl (const_tree); + extern gimple_seq gimplify_parameters (gimple_seq *); + extern void locate_and_pad_parm (machine_mode, tree, int, int, int, ++ cumulative_args_t, + tree, struct args_size *, + struct locate_and_pad_arg_data *); + extern void generate_setjmp_warnings (void); +diff --git a/gcc/ginclude/stddef.h b/gcc/ginclude/stddef.h +index 349213108ce..be884e96336 100644 +--- a/gcc/ginclude/stddef.h ++++ b/gcc/ginclude/stddef.h +@@ -428,9 +428,8 @@ typedef struct { + /* _Float128 is defined as a basic type, so max_align_t must be + sufficiently aligned for it. This code must work in C++, so we + use __float128 here; that is only available on some +- architectures, but only on i386 is extra alignment needed for +- __float128. */ +-#ifdef __i386__ ++ architectures. */ ++#if defined(__i386__) || (__APPLE__ && __aarch64__) + __float128 __max_align_f128 __attribute__((__aligned__(__alignof(__float128)))); + #endif + } max_align_t; +diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h +index 74e847b2dec..58d282046e8 100644 +--- a/gcc/jit/libgccjit.h ++++ b/gcc/jit/libgccjit.h +@@ -21,6 +21,9 @@ along with GCC; see the file COPYING3. If not see + #define LIBGCCJIT_H + + #include ++#ifdef __APPLE__ ++# include /* For ssize_t. */ ++#endif + + #ifdef __cplusplus + extern "C" { +diff --git a/gcc/opts.cc b/gcc/opts.cc +index 3333600e0ea..8355cc4b1de 100644 +--- a/gcc/opts.cc ++++ b/gcc/opts.cc +@@ -3289,6 +3289,7 @@ common_handle_option (struct gcc_options *opts, + break; + + case OPT_fuse_ld_bfd: ++ case OPT_fuse_ld_classic: + case OPT_fuse_ld_gold: + case OPT_fuse_ld_lld: + case OPT_fuse_ld_mold: +diff --git a/gcc/target.def b/gcc/target.def +index c27df8095be..20561fc8060 100644 +--- a/gcc/target.def ++++ b/gcc/target.def +@@ -4680,6 +4680,13 @@ if you would like to apply the same rules given by @code{PROMOTE_MODE}.", + const_tree funtype, int for_return), + default_promote_function_mode) + ++DEFHOOK ++(promote_function_mode_ca, ++ "Like @code{promote_function_mode}, but takes a cumulative_args pointer \ ++ and a current arg to supply the input.", ++ machine_mode, (cumulative_args_t, function_arg_info, const_tree, int *, int), ++ default_promote_function_mode_ca) ++ + DEFHOOK + (promote_prototypes, + "This target hook returns @code{true} if an argument declared in a\n\ +@@ -5133,6 +5140,18 @@ with the specified mode and type. The default hook returns\n\ + unsigned int, (machine_mode mode, const_tree type), + default_function_arg_boundary) + ++DEFHOOK ++(function_arg_boundary_ca, ++ "This is the @code{cumulative_args_t}-based version of\n\ ++@code{TARGET_FUNCTION_ARG_BOUNDARY}. Define this hook if you need more\n\ ++fine-grained control over argument alignment, e.g. depending on whether\n\ ++it is a named argument or not, or any other criteria that you choose to\n\ ++place in the @var{ca} structure.\n\ ++\n\ ++The default hook will call @code{TARGET_FUNCTION_ARG_BOUNDARY}.", ++ unsigned int, (machine_mode mode, const_tree type, cumulative_args_t ca), ++ default_function_arg_boundary_ca) ++ + DEFHOOK + (function_arg_round_boundary, + "Normally, the size of an argument is rounded up to @code{PARM_BOUNDARY},\n\ +@@ -5142,6 +5161,18 @@ value.", + unsigned int, (machine_mode mode, const_tree type), + default_function_arg_round_boundary) + ++DEFHOOK ++(function_arg_round_boundary_ca, ++ "This is the @code{cumulative_args_t}-based version of\n\ ++@code{TARGET_FUNCTION_ARG_ROUND_BOUNDARY}. Define this hook if you need more\n\ ++fine-grained control over argument size rounding, e.g. depending on whether\n\ ++it is a named argument or not, or any other criteria that you choose to\n\ ++place in the @var{ca} structure.\n\ ++\n\ ++The default hook will call @code{TARGET_FUNCTION_ARG_ROUND_BOUNDARY}.", ++ unsigned int, (machine_mode mode, const_tree type, cumulative_args_t ca), ++ default_function_arg_round_boundary_ca) ++ + /* Return the diagnostic message string if function without a prototype + is not allowed for this 'val' argument; NULL otherwise. */ + DEFHOOK +@@ -7389,6 +7420,16 @@ DEFHOOKPOD + libatomic. The default value is false.", + bool, false) + ++/* This value represents whether __builtin_unreachable should be expanded ++ as a trap instruction (or an abort() if the trap is not available). */ ++DEFHOOK ++(unreachable_should_trap, ++ "This hook should return @code{true} if the target wants \ ++ @code{__builtin_unreachable} to expand to a trap or @code{abort ()}.\n\ ++ The default value is false.", ++ bool, (void), ++ hook_bool_void_false) ++ + /* Close the 'struct gcc_target' definition. */ + HOOK_VECTOR_END (C90_EMPTY_HACK) + +diff --git a/gcc/target.h b/gcc/target.h +index c1f99b97b86..b51630a9782 100644 +--- a/gcc/target.h ++++ b/gcc/target.h +@@ -51,22 +51,8 @@ + #include "insn-codes.h" + #include "tm.h" + #include "hard-reg-set.h" +- +-#if CHECKING_P +- +-struct cumulative_args_t { void *magic; void *p; }; +- +-#else /* !CHECKING_P */ +- +-/* When using a GCC build compiler, we could use +- __attribute__((transparent_union)) to get cumulative_args_t function +- arguments passed like scalars where the ABI would mandate a less +- efficient way of argument passing otherwise. However, that would come +- at the cost of less type-safe !CHECKING_P compilation. */ +- +-union cumulative_args_t { void *p; }; +- +-#endif /* !CHECKING_P */ ++#include "tree-core.h" ++#include "cumulative-args.h" + + /* Target properties of _BitInt(N) type. _BitInt(N) is to be represented + as series of abi_limb_mode CEIL (N, GET_MODE_PRECISION (abi_limb_mode)) +diff --git a/gcc/targhooks.cc b/gcc/targhooks.cc +index fb339bf75dd..a529998f618 100644 +--- a/gcc/targhooks.cc ++++ b/gcc/targhooks.cc +@@ -161,6 +161,15 @@ default_promote_function_mode_always_promote (const_tree type, + return promote_mode (type, mode, punsignedp); + } + ++machine_mode ++default_promote_function_mode_ca (cumulative_args_t, function_arg_info arg, ++ const_tree funtype, int *punsignedp, ++ int for_return) ++{ ++ return promote_function_mode (arg.type, arg.mode, punsignedp, ++ funtype, for_return); ++} ++ + machine_mode + default_cc_modes_compatible (machine_mode m1, machine_mode m2) + { +@@ -876,6 +885,14 @@ default_function_arg_boundary (machine_mode mode ATTRIBUTE_UNUSED, + return PARM_BOUNDARY; + } + ++unsigned int ++default_function_arg_boundary_ca (machine_mode mode ATTRIBUTE_UNUSED, ++ const_tree type ATTRIBUTE_UNUSED, ++ cumulative_args_t ca ATTRIBUTE_UNUSED) ++{ ++ return default_function_arg_boundary (mode, type); ++} ++ + unsigned int + default_function_arg_round_boundary (machine_mode mode ATTRIBUTE_UNUSED, + const_tree type ATTRIBUTE_UNUSED) +@@ -883,6 +900,14 @@ default_function_arg_round_boundary (machine_mode mode ATTRIBUTE_UNUSED, + return PARM_BOUNDARY; + } + ++unsigned int ++default_function_arg_round_boundary_ca (machine_mode mode ATTRIBUTE_UNUSED, ++ const_tree type ATTRIBUTE_UNUSED, ++ cumulative_args_t ca ATTRIBUTE_UNUSED) ++{ ++ return default_function_arg_round_boundary (mode, type); ++} ++ + void + hook_void_bitmap (bitmap regs ATTRIBUTE_UNUSED) + { +diff --git a/gcc/targhooks.h b/gcc/targhooks.h +index 85f3817c176..392fd0d315e 100644 +--- a/gcc/targhooks.h ++++ b/gcc/targhooks.h +@@ -34,6 +34,9 @@ extern machine_mode default_promote_function_mode (const_tree, machine_mode, + extern machine_mode default_promote_function_mode_always_promote + (const_tree, machine_mode, int *, const_tree, int); + ++extern machine_mode default_promote_function_mode_ca ++ (cumulative_args_t, function_arg_info, const_tree, int *, int); ++ + extern machine_mode default_cc_modes_compatible (machine_mode, + machine_mode); + +@@ -160,6 +163,12 @@ extern unsigned int default_function_arg_boundary (machine_mode, + const_tree); + extern unsigned int default_function_arg_round_boundary (machine_mode, + const_tree); ++extern unsigned int default_function_arg_boundary_ca (machine_mode, ++ const_tree, ++ cumulative_args_t ca); ++extern unsigned int default_function_arg_round_boundary_ca (machine_mode, ++ const_tree, ++ cumulative_args_t ca); + extern bool hook_bool_const_rtx_commutative_p (const_rtx, int); + extern rtx default_function_value (const_tree, const_tree, bool); + extern HARD_REG_SET default_zero_call_used_regs (HARD_REG_SET); +diff --git a/gcc/testsuite/g++.dg/cpp0x/pr106435-b.cc b/gcc/testsuite/g++.dg/cpp0x/pr106435-b.cc +new file mode 100644 +index 00000000000..4f581694177 +--- /dev/null ++++ b/gcc/testsuite/g++.dg/cpp0x/pr106435-b.cc +@@ -0,0 +1,17 @@ ++// PR c++/106435 ++#include "pr106435.h" ++ ++//#include ++ ++Foo::Foo() { ++ ++num_calls; ++// std::cout << "Foo::Foo(this=" << this << ")\n"; ++} ++ ++int Foo::func() { ++// std::cout << "Foo::func(this=" << this << ")\n"; ++ return num_calls; ++} ++ ++thread_local Foo Bar::foo; ++thread_local Foo Bar::baz; +diff --git a/gcc/testsuite/g++.dg/cpp0x/pr106435.C b/gcc/testsuite/g++.dg/cpp0x/pr106435.C +new file mode 100644 +index 00000000000..d600976f9f9 +--- /dev/null ++++ b/gcc/testsuite/g++.dg/cpp0x/pr106435.C +@@ -0,0 +1,20 @@ ++// PR c++/106435 ++// { dg-do run { target c++11 } } ++// { dg-additional-sources "pr106435-b.cc" } ++ ++#include "pr106435.h" ++ ++int num_calls = 0; ++ ++extern "C" __attribute__((__noreturn__)) void abort(); ++ ++thread_local Foo Bar::bat; ++ ++int main() { ++ int v = Bar::foo.func(); ++ if (v != 2) ++ abort(); ++ v = Bar::bat.func(); ++ if (v != 3) ++ abort(); ++} +diff --git a/gcc/testsuite/g++.dg/cpp0x/pr106435.h b/gcc/testsuite/g++.dg/cpp0x/pr106435.h +new file mode 100644 +index 00000000000..240de1ee9a9 +--- /dev/null ++++ b/gcc/testsuite/g++.dg/cpp0x/pr106435.h +@@ -0,0 +1,14 @@ ++// PR c++/106435 ++#pragma once ++ ++extern int num_calls; ++struct Foo { ++ Foo(); ++ int func(); ++}; ++ ++struct Bar { ++ thread_local static Foo foo; ++ thread_local static Foo baz; ++ thread_local static Foo bat; ++}; +diff --git a/gcc/testsuite/g++.target/aarch64/float128-darwin-1.C b/gcc/testsuite/g++.target/aarch64/float128-darwin-1.C +new file mode 100644 +index 00000000000..0dbed063a71 +--- /dev/null ++++ b/gcc/testsuite/g++.target/aarch64/float128-darwin-1.C +@@ -0,0 +1,41 @@ ++/* { dg-do run { target { aarch64*-*-darwin* } } } */ ++/* { dg-options "-std=c++11 -std=gnu++98" } */ ++ ++#include ++#include ++#include ++ ++void foo () ++{ ++ float x1 = 1.0q; ++ double x2 = 1.0q; ++ long double x3 = 1.0q; ++ ++ _Float128 w1 = 0; ++ __float128 w2 = 0; ++ ++ float y1 = w1; // { dg-warning "with greater conversion rank" } ++ double y2 = w1; // { dg-warning "with greater conversion rank" } ++ long double y3 = w1; // { dg-warning "with greater conversion rank" } ++ ++ float z1 = w2; ++ double z2 = w2; ++ long double z3 = w2; ++} ++ ++int main () ++{ ++ // Check the correct mangling of floating-point types ++ if (typeid(float).name() != std::string("f")) ++ __builtin_abort(); ++ if (typeid(double).name() != std::string("d")) ++ __builtin_abort(); ++ if (typeid(long double).name() != std::string("e")) ++ __builtin_abort(); ++ if (typeid(__float128).name() != std::string("g")) ++ __builtin_abort(); ++ if (typeid(_Float128).name() != std::string("DF128_")) ++ __builtin_abort(); ++ if (typeid(1.0q).name() != std::string("g")) ++ __builtin_abort(); ++} +diff --git a/gcc/testsuite/gcc.target/aarch64/darwin/float128-01.c b/gcc/testsuite/gcc.target/aarch64/darwin/float128-01.c +new file mode 100644 +index 00000000000..93f6d24cebc +--- /dev/null ++++ b/gcc/testsuite/gcc.target/aarch64/darwin/float128-01.c +@@ -0,0 +1,48 @@ ++/* { dg-do run } */ ++/* we need this for _Float128. */ ++/* { dg-options "-std=gnu99 " } */ ++/* { dg-additional-options "-Wfloat-conversion" } */ ++ ++float f1 (__float128 z1, _Float128 z2) ++{ ++ float x, y; ++ x = z1; /* { dg-warning "conversion from '_Float128' to 'float'" } */ ++ y = z2; /* { dg-warning "conversion from '_Float128' to 'float'" } */ ++ return x + y; ++} ++ ++__float128 f2 () { ++ float f = 0.q; ++ return f; ++} ++ ++_Float128 f3 () { ++ float f = 0.q; ++ return f; ++} ++ ++int main () ++{ ++ __float128 x1 = __builtin_huge_valq (); ++ __float128 x2 = __builtin_infq (); ++ ++ _Float128 y1 = __builtin_huge_valq (); ++ _Float128 y2 = __builtin_infq (); ++ ++ if (!__builtin_isinf (x1)) ++ __builtin_abort(); ++ if (!__builtin_isinf (x2)) ++ __builtin_abort(); ++ ++ if (!__builtin_isinf (y1)) ++ __builtin_abort(); ++ if (!__builtin_isinf (y2)) ++ __builtin_abort(); ++ ++ if (x1 != x2) ++ __builtin_abort(); ++ if (y1 != y2) ++ __builtin_abort(); ++ ++ return 0; ++} +diff --git a/gcc/testsuite/gcc.target/aarch64/darwin/float128-02.c b/gcc/testsuite/gcc.target/aarch64/darwin/float128-02.c +new file mode 100644 +index 00000000000..5a8522f9622 +--- /dev/null ++++ b/gcc/testsuite/gcc.target/aarch64/darwin/float128-02.c +@@ -0,0 +1,101 @@ ++/* { dg-do run } */ ++/* we need this for _Float128. */ ++/* { dg-options "-std=gnu99 " } */ ++ ++void test (__float128 z1, __float128 z2, __float128 z3, __float128 z4) ++{ ++ __float128 w; ++ ++ if (!__builtin_isinf (z1)) ++ __builtin_abort(); ++ if (__builtin_isnan (z1)) ++ __builtin_abort(); ++ if (__builtin_isfinite (z1)) ++ __builtin_abort(); ++ if (__builtin_isnormal (z1)) ++ __builtin_abort(); ++ if (__builtin_signbit (z1)) ++ __builtin_abort(); ++ ++ if (__builtin_isinf (z2)) ++ __builtin_abort(); ++ if (!__builtin_isnan (z2)) ++ __builtin_abort(); ++ if (__builtin_isfinite (z2)) ++ __builtin_abort(); ++ if (__builtin_isnormal (z2)) ++ __builtin_abort(); ++ if (__builtin_signbit (z2)) ++ __builtin_abort(); ++ ++ if (__builtin_isinf (z3)) ++ __builtin_abort(); ++ if (!__builtin_isnan (z3)) ++ __builtin_abort(); ++ if (__builtin_isfinite (z3)) ++ __builtin_abort(); ++ if (__builtin_isnormal (z3)) ++ __builtin_abort(); ++ if (__builtin_signbit (z3)) ++ __builtin_abort(); ++ ++ if (__builtin_isinf (z4)) ++ __builtin_abort(); ++ if (__builtin_isnan (z4)) ++ __builtin_abort(); ++ if (!__builtin_isfinite (z4)) ++ __builtin_abort(); ++ if (!__builtin_isnormal (z4)) ++ __builtin_abort(); ++ if (__builtin_signbit (z4)) ++ __builtin_abort(); ++ ++ w = __builtin_copysignq (z1, -z4); ++ if (!__builtin_signbit (w)) ++ __builtin_abort(); ++ ++ w = __builtin_copysignq (z2, -z4); ++ if (!__builtin_signbit (w)) ++ __builtin_abort(); ++ ++ w = __builtin_copysignq (z3, -z4); ++ if (!__builtin_signbit (w)) ++ __builtin_abort(); ++ ++ w = __builtin_copysignq (z4, -z4); ++ if (!__builtin_signbit (w)) ++ __builtin_abort(); ++ ++ w = __builtin_copysignq (z1, -z4); ++ w = __builtin_fabsq (w); ++ if (__builtin_signbit (w)) ++ __builtin_abort(); ++ ++ w = __builtin_copysignq (z2, -z4); ++ w = __builtin_fabsq (w); ++ if (__builtin_signbit (w)) ++ __builtin_abort(); ++ ++ w = __builtin_copysignq (z3, -z4); ++ w = __builtin_fabsq (w); ++ if (__builtin_signbit (w)) ++ __builtin_abort(); ++ ++ w = __builtin_copysignq (z4, -z4); ++ w = __builtin_fabsq (w); ++ if (__builtin_signbit (w)) ++ __builtin_abort(); ++ ++} ++ ++int main () ++{ ++ __float128 x1 = __builtin_infq (); ++ __float128 x2 = __builtin_nanq (""); ++ __float128 x3 = __builtin_nansq (""); ++ __float128 x4 = 41.1094721q; ++ ++ test (x1, x2, x3, x4); ++ ++ return 0; ++} +diff --git a/gcc/testsuite/gcc.target/aarch64/sme/aarch64-sme.exp b/gcc/testsuite/gcc.target/aarch64/sme/aarch64-sme.exp +index 4b2fb4f24ba..c4982183128 100644 +--- a/gcc/testsuite/gcc.target/aarch64/sme/aarch64-sme.exp ++++ b/gcc/testsuite/gcc.target/aarch64/sme/aarch64-sme.exp +@@ -24,6 +24,11 @@ if {![istarget aarch64*-*-*] } { + return + } + ++# Exit immediately if this is Darwin (for now). ++if {[istarget *-*-darwin*] } { ++ return ++} ++ + # Load support procs. + load_lib gcc-dg.exp + +diff --git a/libgcc/config.host b/libgcc/config.host +index e75a7af647f..ae4c91dee35 100644 +--- a/libgcc/config.host ++++ b/libgcc/config.host +@@ -82,7 +82,7 @@ m32c*-*-*) + cpu_type=m32c + tmake_file=t-fdpbit + ;; +-aarch64*-*-*) ++aarch64*-*-* | arm64*-*-*) + cpu_type=aarch64 + ;; + alpha*-*-*) +@@ -236,19 +236,25 @@ case ${host} in + esac + tmake_file="$tmake_file t-slibgcc-darwin" + case ${host} in +- *-*-darwin1[89]* | *-*-darwin2* ) +- tmake_file="t-darwin-min-8 $tmake_file" ++ x86_64-*-darwin2[0-2]*) ++ tmake_file="t-darwin-min-11 t-darwin-libgccs1 $tmake_file" ++ ;; ++ *-*-darwin2*) ++ tmake_file="t-darwin-min-11 $tmake_file" ++ ;; ++ *-*-darwin1[89]*) ++ tmake_file="t-darwin-min-8 t-darwin-libgccs1 $tmake_file" + ;; + *-*-darwin9* | *-*-darwin1[0-7]*) +- tmake_file="t-darwin-min-5 $tmake_file" ++ tmake_file="t-darwin-min-5 t-darwin-libgccs1 $tmake_file" + ;; + *-*-darwin[4-8]*) +- tmake_file="t-darwin-min-1 $tmake_file" ++ tmake_file="t-darwin-min-1 t-darwin-libgccs1 $tmake_file" + ;; + *) + # Fall back to configuring for the oldest system known to work with + # all archs and the current sources. +- tmake_file="t-darwin-min-5 $tmake_file" ++ tmake_file="t-darwin-min-5 t-darwin-libgccs1 $tmake_file" + echo "Warning: libgcc configured to support macOS 10.5" 1>&2 + ;; + esac +@@ -274,7 +280,7 @@ case ${host} in + if test "x$enable_darwin_at_rpath" = "xyes"; then + tmake_file="$tmake_file t-darwin-rpath " + fi +- extra_parts="crt3.o libd10-uwfef.a crttms.o crttme.o libemutls_w.a" ++ extra_parts="crt3.o crttms.o crttme.o libemutls_w.a " + ;; + *-*-dragonfly*) + tmake_file="$tmake_file t-crtstuff-pic t-libgcc-pic t-eh-dw2-dip" +@@ -418,6 +424,15 @@ aarch64*-*-elf | aarch64*-*-rtems*) + tmake_file="${tmake_file} t-dfprules" + md_unwind_header=aarch64/aarch64-unwind.h + ;; ++aarch64*-*-darwin*) ++ extra_parts="$extra_parts crtfastmath.o libheapt_w.a" ++ tmake_file="${tmake_file} ${cpu_type}/t-aarch64" ++ tmake_file="${tmake_file} ${cpu_type}/t-lse" ++ tmake_file="${tmake_file} t-crtfm t-dfprules" ++ tmake_file="${tmake_file} ${cpu_type}/t-softfp t-softfp" ++ tmake_file="${tmake_file} ${cpu_type}/t-heap-trampoline" ++ md_unwind_header=aarch64/aarch64-unwind.h ++ ;; + aarch64*-*-freebsd*) + extra_parts="$extra_parts crtfastmath.o" + tmake_file="${tmake_file} ${cpu_type}/t-aarch64" +@@ -725,14 +740,14 @@ i[34567]86-*-darwin*) + tmake_file="$tmake_file i386/t-crtpc t-crtfm i386/t-msabi" + tm_file="$tm_file i386/darwin-lib.h" + extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o" +- extra_parts="$extra_parts crtfastmath.o libheapt_w.a" ++ extra_parts="$extra_parts crtfastmath.o libd10-uwfef.a libheapt_w.a" + tmake_file="${tmake_file} i386/t-heap-trampoline" + ;; + x86_64-*-darwin*) + tmake_file="$tmake_file i386/t-crtpc t-crtfm i386/t-msabi" + tm_file="$tm_file i386/darwin-lib.h" + extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o" +- extra_parts="$extra_parts crtfastmath.o libheapt_w.a" ++ extra_parts="$extra_parts crtfastmath.o libd10-uwfef.a libheapt_w.a" + tmake_file="${tmake_file} i386/t-heap-trampoline" + ;; + i[34567]86-*-elfiamcu) +@@ -1215,12 +1230,14 @@ powerpc-*-darwin*) + # We build the darwin10 EH shim for Rosetta (running on x86 machines). + tm_file="$tm_file i386/darwin-lib.h" + tmake_file="$tmake_file rs6000/t-ppc64-fp rs6000/t-ibm-ldouble" ++ extra_parts="$extra_parts libd10-uwfef.a " + extra_parts="$extra_parts crt2.o crt3_2.o libef_ppc.a dw_ppc.o" + ;; + powerpc64-*-darwin*) + # We build the darwin10 EH shim for Rosetta (running on x86 machines). + tm_file="$tm_file i386/darwin-lib.h" + tmake_file="$tmake_file rs6000/t-darwin64 rs6000/t-ibm-ldouble" ++ extra_parts="$extra_parts libd10-uwfef.a " + extra_parts="$extra_parts crt2.o crt3_2.o libef_ppc.a dw_ppc.o" + ;; + powerpc*-*-freebsd*) +diff --git a/libgcc/config/aarch64/__arm_sme_state.S b/libgcc/config/aarch64/__arm_sme_state.S +index 1fbb8c1ff53..b665769004f 100644 +--- a/libgcc/config/aarch64/__arm_sme_state.S ++++ b/libgcc/config/aarch64/__arm_sme_state.S +@@ -30,14 +30,19 @@ + - Takes no argument. + - Returns SME state in x0 and TPIDR2_EL0 in x1. */ + +-HIDDEN (__aarch64_have_sme) ++HIDDEN (ASMNAME (__aarch64_have_sme)) + +-variant_pcs (__arm_sme_state) ++variant_pcs (ASMNAME (__arm_sme_state)) + +-ENTRY (__arm_sme_state) ++ENTRY (ASMNAME (__arm_sme_state)) + /* Check if SME is available. */ +- adrp x1, __aarch64_have_sme +- ldrb w1, [x1, :lo12:__aarch64_have_sme] ++#ifdef __APPLE__ ++ adrp x1, ASMNAME (__aarch64_have_sme)@PAGE ++ ldrb w1, [x1, ASMNAME (__aarch64_have_sme)@PAGEOFF] ++#else ++ adrp x1, ASMNAME (__aarch64_have_sme) ++ ldrb w1, [x1, :lo12:ASMNAME (__aarch64_have_sme)] ++#endif + cbz w1, L(nosme) + + /* Expose the bottom 2 bits of svcr (SM, ZA) in x0 and set the +@@ -52,4 +57,4 @@ L(nosme): + mov x0, 0 + mov x1, 0 + ret +-END (__arm_sme_state) ++ENDm ASMNAME(__arm_sme_state) +diff --git a/libgcc/config/aarch64/__arm_tpidr2_restore.S b/libgcc/config/aarch64/__arm_tpidr2_restore.S +index 5088c86df32..bcfb935bc96 100644 +--- a/libgcc/config/aarch64/__arm_tpidr2_restore.S ++++ b/libgcc/config/aarch64/__arm_tpidr2_restore.S +@@ -31,9 +31,9 @@ + - Does not return a value. + - Can abort on failure (then registers are not preserved). */ + +-variant_pcs (__arm_tpidr2_restore) ++variant_pcs (ASMNAME (__arm_tpidr2_restore)) + +-ENTRY (__arm_tpidr2_restore) ++ENTRY (ASMNAME (__arm_tpidr2_restore)) + .inst 0xd53bd0ae /* mrs x14, tpidr2_el0 */ + cbnz x14, L(fail) + +@@ -85,5 +85,5 @@ L(fail): + str x16, [sp, 16] + .cfi_rel_offset 46, 16 + .inst 0xd503467f /* smstop */ +- bl abort +-END (__arm_tpidr2_restore) ++ bl ASMNAME (abort) ++ENDm ASMNAME (__arm_tpidr2_restore) +diff --git a/libgcc/config/aarch64/__arm_tpidr2_save.S b/libgcc/config/aarch64/__arm_tpidr2_save.S +index 2466b5863e4..28e75ade2d0 100644 +--- a/libgcc/config/aarch64/__arm_tpidr2_save.S ++++ b/libgcc/config/aarch64/__arm_tpidr2_save.S +@@ -35,10 +35,15 @@ HIDDEN (__aarch64_have_sme) + + variant_pcs (__arm_tpidr2_save) + +-ENTRY (__arm_tpidr2_save) ++ENTRY (ASMNAME (__arm_tpidr2_save)) + /* Check if SME is available. */ +- adrp x14, __aarch64_have_sme +- ldrb w14, [x14, :lo12:__aarch64_have_sme] ++#if __APPLE__ ++ adrp x14, ASMNAME (__aarch64_have_sme)@PAGE ++ ldrb w14, [x14, ASMNAME (__aarch64_have_sme)@PAGEOFF] ++#else ++ adrp x14, ASMNAME (__aarch64_have_sme) ++ ldrb w14, [x14, :lo12:ASMNAME (__aarch64_have_sme)] ++#endif + cbz w14, L(end) + + .inst 0xd53bd0ae /* mrs x14, tpidr2_el0 */ +@@ -92,10 +97,18 @@ L(fail): + str x16, [sp, 16] + .cfi_rel_offset 46, 16 + .inst 0xd503467f /* smstop */ +- bl abort +-END (__arm_tpidr2_save) +- ++ bl ASMNAME (abort) ++ENDm ASMNAME (__arm_tpidr2_save) ++ ++ GLOBAL(ASMNAME (__libgcc_arm_tpidr2_save)) ++ HIDDEN (ASMNAME (__libgcc_arm_tpidr2_save)) ++#if __APPLE__ ++ .text ++ .p2align 4 ++ASMNAME (__libgcc_arm_tpidr2_save): ++ b ASMNAME (__arm_tpidr2_save) ++#else + /* Hidden alias used by __arm_za_disable. */ +-.global __libgcc_arm_tpidr2_save +-HIDDEN (__libgcc_arm_tpidr2_save) +-.set __libgcc_arm_tpidr2_save, __arm_tpidr2_save ++.set ASMNAME (__libgcc_arm_tpidr2_save), ASMNAME (__arm_tpidr2_save) ++#endif ++ +diff --git a/libgcc/config/aarch64/__arm_za_disable.S b/libgcc/config/aarch64/__arm_za_disable.S +index c372fcffe18..9aefed6cde7 100644 +--- a/libgcc/config/aarch64/__arm_za_disable.S ++++ b/libgcc/config/aarch64/__arm_za_disable.S +@@ -31,16 +31,33 @@ + - Does not return a value. + - Can abort on failure (then registers are not preserved). */ + +-HIDDEN (__aarch64_have_sme) ++HIDDEN (ASMNAME(__aarch64_have_sme)) + +-HIDDEN (__libgcc_arm_tpidr2_save) ++HIDDEN (ASMNAME(__libgcc_arm_tpidr2_save)) + +-variant_pcs (__arm_za_disable) ++variant_pcs (ASMNAME(__arm_za_disable)) + +-ENTRY (__arm_za_disable) ++GLOBAL (ASMNAME (__libgcc_arm_za_disable)) ++HIDDEN (ASMNAME (__libgcc_arm_za_disable)) ++#if __APPLE__ ++ .text ++ .p2align 4 ++ASMNAME (__libgcc_arm_za_disable): ++ b ASMNAME (__arm_za_disable) ++#else ++/* Hidden alias used by the unwinder. */ ++.set ASMNAME (__libgcc_arm_za_disable), ASMNAME (__arm_za_disable) ++#endif ++ ++ENTRY (ASMNAME (__arm_za_disable)) + /* Check if SME is available. */ +- adrp x14, __aarch64_have_sme +- ldrb w14, [x14, :lo12:__aarch64_have_sme] ++#if __APPLE__ ++ adrp x14, ASMNAME (__aarch64_have_sme)@PAGE ++ ldrb w14, [x14, ASMNAME (__aarch64_have_sme)@PAGEOFF] ++#else ++ adrp x14, ASMNAME (__aarch64_have_sme) ++ ldrb w14, [x14, :lo12:ASMNAME (__aarch64_have_sme)] ++#endif + cbz w14, L(end) + + .inst 0xd53bd0ae /* mrs x14, tpidr2_el0 */ +@@ -52,7 +69,7 @@ ENTRY (__arm_za_disable) + .cfi_rel_offset x29, 0 + .cfi_rel_offset x30, 8 + mov x29, sp +- bl __libgcc_arm_tpidr2_save ++ bl ASMNAME (__libgcc_arm_tpidr2_save) + .inst 0xd51bd0bf /* msr tpidr2_el0, xzr */ + .inst 0xd503447f /* smstop za */ + ldp x29, x30, [sp], 16 +@@ -62,9 +79,5 @@ ENTRY (__arm_za_disable) + AUTIASP + L(end): + ret +-END (__arm_za_disable) ++ENDm ASMNAME(__arm_za_disable) + +-/* Hidden alias used by the unwinder. */ +-.global __libgcc_arm_za_disable +-HIDDEN (__libgcc_arm_za_disable) +-.set __libgcc_arm_za_disable, __arm_za_disable +diff --git a/libgcc/config/aarch64/aarch64-asm.h b/libgcc/config/aarch64/aarch64-asm.h +index 83c2e5944b3..7e41e6eb082 100644 +--- a/libgcc/config/aarch64/aarch64-asm.h ++++ b/libgcc/config/aarch64/aarch64-asm.h +@@ -24,8 +24,6 @@ + + #include "auto-target.h" + +-#define L(label) .L ## label +- + /* Marking variant PCS symbol references is important for PLT calls + otherwise it is for documenting the PCS in the symbol table. */ + #ifdef HAVE_AS_VARIANT_PCS +@@ -58,12 +56,31 @@ + # define AUTIASP + #endif + ++#define PASTE2(a, b) PASTE2a(a, b) ++#define PASTE2a(a, b) a ## b ++ ++#ifdef __USER_LABEL_PREFIX__ ++# define ASMNAME(name) PASTE2(__USER_LABEL_PREFIX__, name) ++#else ++# define ASMNAME(name) name ++#endif ++ + #ifdef __ELF__ ++#define L(label) .L ## label + #define HIDDEN(name) .hidden name ++#define GLOBAL(name) .global name + #define SYMBOL_SIZE(name) .size name, .-name + #define SYMBOL_TYPE(name, _type) .type name, _type ++#elif __APPLE__ ++#define L(label) L ## label ++#define HIDDEN(name) .private_extern name ++#define GLOBAL(name) .globl name ++#define SYMBOL_SIZE(name) ++#define SYMBOL_TYPE(name, _type) + #else ++#define L(label) .L ## label + #define HIDDEN(name) ++#define GLOBAL(name) .global name + #define SYMBOL_SIZE(name) + #define SYMBOL_TYPE(name, _type) + #endif +@@ -93,16 +110,19 @@ GNU_PROPERTY (FEATURE_1_AND, BTI_FLAG|PAC_FLAG) + # endif + #endif + +-#define ENTRY_ALIGN(name, align) \ +- .global name; \ +- SYMBOL_TYPE(name, %function); \ +- .balign align; \ +- name: \ +- .cfi_startproc; \ +- BTI_C +- +-#define ENTRY(name) ENTRY_ALIGN(name, 16) +- +-#define END(name) \ +- .cfi_endproc; \ +- SYMBOL_SIZE(name) ++.macro ENTRY_ALIGNP2m, name, align ++ .text ++ .p2align \align ++ GLOBAL (\name) ++ SYMBOL_TYPE(\name, %function) ++\name: ++ .cfi_startproc ++ BTI_C ++.endm ++ ++#define ENTRY(name) ENTRY_ALIGNP2m name, 4 ++ ++.macro ENDm, name ++ .cfi_endproc ++ SYMBOL_SIZE (\name) ++.endm +diff --git a/libgcc/config/aarch64/lse.S b/libgcc/config/aarch64/lse.S +index ecef47086c6..54b85b5ad2a 100644 +--- a/libgcc/config/aarch64/lse.S ++++ b/libgcc/config/aarch64/lse.S +@@ -62,7 +62,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + #endif + + /* Declare the symbol gating the LSE implementations. */ +- HIDDEN(__aarch64_have_lse_atomics) ++ HIDDEN (ASMNAME (__aarch64_have_lse_atomics)) + + /* Turn size and memory model defines into mnemonic fragments. */ + #if SIZE == 1 +@@ -85,6 +85,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + # error + #endif + ++#undef L + #if MODEL == 1 + # define SUFF _relax + # define A +@@ -167,32 +168,21 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + #define tmp3 14 + #define tmp4 13 + +-/* Start and end a function. */ +-.macro STARTFN name +- .text +- .balign 16 +- .globl \name +- HIDDEN(\name) +- SYMBOL_TYPE(\name, %function) +- .cfi_startproc +-\name: +-.endm +- +-.macro ENDFN name +- .cfi_endproc +- SYMBOL_SIZE(\name) +-.endm +- + /* Branch to LABEL if LSE is disabled. */ + .macro JUMP_IF_NOT_LSE label +- adrp x(tmp0), __aarch64_have_lse_atomics +- ldrb w(tmp0), [x(tmp0), :lo12:__aarch64_have_lse_atomics] ++#if __APPLE__ ++ adrp x(tmp0), ASMNAME (__aarch64_have_lse_atomics)@PAGE ++ ldrb w(tmp0), [x(tmp0), ASMNAME (__aarch64_have_lse_atomics)@PAGEOFF] ++#else ++ adrp x(tmp0), ASMNAME (__aarch64_have_lse_atomics) ++ ldrb w(tmp0), [x(tmp0), :lo12:ASMNAME (__aarch64_have_lse_atomics)] ++#endif + cbz w(tmp0), \label + .endm + + #ifdef L_cas + +-STARTFN NAME(cas) ++ENTRY (ASMNAME (NAME(cas))) + JUMP_IF_NOT_LSE 8f + + #if SIZE < 16 +@@ -245,7 +235,7 @@ STARTFN NAME(cas) + + #endif + +-ENDFN NAME(cas) ++ENDm ASMNAME (NAME(cas)) + #endif + + #ifdef L_swp +@@ -255,7 +245,7 @@ ENDFN NAME(cas) + # define SWP .inst 0x38208020 + B + N + #endif + +-STARTFN NAME(swp) ++ENTRY (ASMNAME (NAME (swp))) + JUMP_IF_NOT_LSE 8f + + SWP /* s(0), s(0), [x1] */ +@@ -268,7 +258,7 @@ STARTFN NAME(swp) + BARRIER + ret + +-ENDFN NAME(swp) ++ENDm ASMNAME (NAME (swp)) + #endif + + #if defined(L_ldadd) || defined(L_ldclr) \ +@@ -299,7 +289,7 @@ ENDFN NAME(swp) + # define LDOP .inst 0x38200020 + OPN + B + N + #endif + +-STARTFN NAME(LDNM) ++ENTRY (ASMNAME (NAME (LDNM))) + JUMP_IF_NOT_LSE 8f + + LDOP /* s(0), s(0), [x1] */ +@@ -313,5 +303,5 @@ STARTFN NAME(LDNM) + BARRIER + ret + +-ENDFN NAME(LDNM) ++ENDm ASMNAME (NAME (LDNM)) + #endif +diff --git a/libgcc/config/aarch64/sfp-machine.h b/libgcc/config/aarch64/sfp-machine.h +index 7fbb2a4288a..3ebc1d5fe44 100644 +--- a/libgcc/config/aarch64/sfp-machine.h ++++ b/libgcc/config/aarch64/sfp-machine.h +@@ -124,6 +124,27 @@ void __sfp_handle_exceptions (int); + + + /* Define ALIASNAME as a strong alias for NAME. */ ++#if defined __APPLE__ ++/* Mach-O doesn't support aliasing, so we build a secondary function for ++ the alias - we need to do a bit of a dance to find out what the type of ++ the arguments is and then apply that to the secondary function. ++ If these functions ever return anything but CMPtype we need to revisit ++ this... */ ++typedef float alias_HFtype __attribute__ ((mode (HF))); ++typedef float alias_SFtype __attribute__ ((mode (SF))); ++typedef float alias_DFtype __attribute__ ((mode (DF))); ++typedef float alias_TFtype __attribute__ ((mode (TF))); ++#define ALIAS_SELECTOR \ ++ CMPtype (*) (alias_HFtype, alias_HFtype): (alias_HFtype) 0, \ ++ CMPtype (*) (alias_SFtype, alias_SFtype): (alias_SFtype) 0, \ ++ CMPtype (*) (alias_DFtype, alias_DFtype): (alias_DFtype) 0, \ ++ CMPtype (*) (alias_TFtype, alias_TFtype): (alias_TFtype) 0 ++#define strong_alias(name, aliasname) \ ++ CMPtype aliasname (__typeof (_Generic (name, ALIAS_SELECTOR)) a, \ ++ __typeof (_Generic (name, ALIAS_SELECTOR)) b) \ ++ { return name (a, b); } ++#else + # define strong_alias(name, aliasname) _strong_alias(name, aliasname) + # define _strong_alias(name, aliasname) \ + extern __typeof (name) aliasname __attribute__ ((alias (#name))); ++#endif +diff --git a/libgcc/config/aarch64/t-darwin b/libgcc/config/aarch64/t-darwin +new file mode 100644 +index 00000000000..f6ecda7b608 +--- /dev/null ++++ b/libgcc/config/aarch64/t-darwin +@@ -0,0 +1,7 @@ ++# Ensure we have a suitable minimum OS version. ++ ++HOST_LIBGCC2_CFLAGS += -mmacosx-version-min=11.0 ++ ++LIB2_SIDITI_CONV_FUNCS = yes ++ ++BUILD_LIBGCCS1 = +diff --git a/libgcc/config/i386/t-darwin b/libgcc/config/i386/t-darwin +index 4c18da1efbf..c6b3acaaca2 100644 +--- a/libgcc/config/i386/t-darwin ++++ b/libgcc/config/i386/t-darwin +@@ -4,6 +4,3 @@ LIB2FUNCS_EXCLUDE = _fixtfdi _fixunstfdi _floatditf _floatunditf + + # Extra symbols for this port. + SHLIB_MAPFILES += $(srcdir)/config/i386/libgcc-darwin.ver +- +-# Build a legacy libgcc_s.1 +-BUILD_LIBGCCS1 = YES +diff --git a/libgcc/config/rs6000/t-darwin b/libgcc/config/rs6000/t-darwin +index 183d0df92ce..8b513bdb1d7 100644 +--- a/libgcc/config/rs6000/t-darwin ++++ b/libgcc/config/rs6000/t-darwin +@@ -56,6 +56,3 @@ unwind-dw2_s.o: HOST_LIBGCC2_CFLAGS += -maltivec + unwind-dw2.o: HOST_LIBGCC2_CFLAGS += -maltivec + + LIB2ADDEH += $(srcdir)/config/rs6000/darwin-fallback.c +- +-# Build a legacy libgcc_s.1 +-BUILD_LIBGCCS1 = YES +diff --git a/libgcc/config/t-darwin-libgccs1 b/libgcc/config/t-darwin-libgccs1 +new file mode 100644 +index 00000000000..b88b1a5bba8 +--- /dev/null ++++ b/libgcc/config/t-darwin-libgccs1 +@@ -0,0 +1,3 @@ ++ ++# Build a legacy libgcc_s.1 ++BUILD_LIBGCCS1 = YES +diff --git a/libgcc/config/t-darwin-min-11 b/libgcc/config/t-darwin-min-11 +new file mode 100644 +index 00000000000..4009d41addb +--- /dev/null ++++ b/libgcc/config/t-darwin-min-11 +@@ -0,0 +1,3 @@ ++# Support building with -mmacosx-version-min back to macOS 11. ++DARWIN_MIN_LIB_VERSION = -mmacosx-version-min=11 ++DARWIN_MIN_CRT_VERSION = -mmacosx-version-min=11 +diff --git a/libitm/config/aarch64/sjlj.S b/libitm/config/aarch64/sjlj.S +index 6b248f7c040..dd844e8c9d8 100644 +--- a/libitm/config/aarch64/sjlj.S ++++ b/libitm/config/aarch64/sjlj.S +@@ -57,10 +57,19 @@ + + .text + .align 2 ++#if __ELF__ + .global _ITM_beginTransaction + .type _ITM_beginTransaction, %function + + _ITM_beginTransaction: ++ ++#elif __MACH__ ++ .global __ITM_beginTransaction ++ ++__ITM_beginTransaction: ++ ++#endif ++ + cfi_startproc + CFI_PAC_KEY + PAC_AND_BTI +@@ -84,8 +93,13 @@ _ITM_beginTransaction: + + /* Invoke GTM_begin_transaction with the struct we just built. */ + mov x1, sp ++#if __ELF__ + bl GTM_begin_transaction +- ++#elif __MACH__ ++ bl _GTM_begin_transaction ++#else ++#error "unexpected object format" ++#endif + /* Return; we don't need to restore any of the call-saved regs. */ + ldp x29, x30, [sp], 11*16 + cfi_adjust_cfa_offset(-11*16) +@@ -95,14 +109,23 @@ _ITM_beginTransaction: + CFI_PAC_TOGGLE + ret + cfi_endproc ++#if __ELF__ + .size _ITM_beginTransaction, . - _ITM_beginTransaction ++#endif + + .align 2 ++#if __ELF__ + .global GTM_longjmp + .hidden GTM_longjmp + .type GTM_longjmp, %function + + GTM_longjmp: ++ ++#elif __MACH__ ++ .private_extern _GTM_longjmp ++ ++_GTM_longjmp: ++#endif + /* The first parameter becomes the return value (x0). + The third parameter is ignored for now. */ + cfi_startproc +@@ -126,7 +149,9 @@ GTM_longjmp: + CFI_PAC_TOGGLE + br x30 + cfi_endproc ++#if __ELF__ + .size GTM_longjmp, . - GTM_longjmp ++#endif + + /* GNU_PROPERTY_AARCH64_* macros from elf.h for use in asm code. */ + #define FEATURE_1_AND 0xc0000000 +diff --git a/libitm/configure.tgt b/libitm/configure.tgt +index a8276f05d9b..6fad8534372 100644 +--- a/libitm/configure.tgt ++++ b/libitm/configure.tgt +@@ -50,7 +50,7 @@ fi + # Map the target cpu to an ARCH sub-directory. At the same time, + # work out any special compilation flags as necessary. + case "${target_cpu}" in +- aarch64*) ARCH=aarch64 ;; ++ aarch64* | arm64*) ARCH=aarch64 ;; + alpha*) ARCH=alpha ;; + rs6000 | powerpc*) + XCFLAGS="${XCFLAGS} -mhtm" +diff --git a/libphobos/libdruntime/core/internal/gc/impl/conservative/gc.d b/libphobos/libdruntime/core/internal/gc/impl/conservative/gc.d +index cb8df47507f..2b70a8cca2b 100644 +--- a/libphobos/libdruntime/core/internal/gc/impl/conservative/gc.d ++++ b/libphobos/libdruntime/core/internal/gc/impl/conservative/gc.d +@@ -30,8 +30,13 @@ module core.internal.gc.impl.conservative.gc; + + /***************************************************/ + version = COLLECT_PARALLEL; // parallel scanning +-version (Posix) +- version = COLLECT_FORK; ++version (GNU) ++{ ++ version (linux) ++ version = COLLECT_FORK; // uses clone(), battle tested and reliable ++} ++else version (Posix) ++ version = COLLECT_FORK; + + import core.internal.gc.bits; + import core.internal.gc.os;