From: Nico Weber Date: Thu, 26 Oct 2017 23:26:29 +0000 (+0000) Subject: Use -fuse-init-array if no gcc installation is found. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d724af7fa85aee225bfe4876b602151cc83f5dd0;p=clang Use -fuse-init-array if no gcc installation is found. clang currently uses .init_array instead of .ctors on Linux if it detects gcc 4.7+. Make it so that it also uses .init_array if no gcc installation is found at all – if there's no old gcc, there's nothing we need to be compatible with. icecc for example runs clang in a very small chroot, so before this change clang would use .ctors if run under icecc. And lld currently silently mislinks inputs with .ctors sections, so before this clang + icecc + lld would produce broken binaries. (But this seems like a good change independent of that lld bug.) https://reviews.llvm.org/D39317 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@316713 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/ReleaseNotes.rst b/docs/ReleaseNotes.rst index 30afc52ad2..4c8099121e 100644 --- a/docs/ReleaseNotes.rst +++ b/docs/ReleaseNotes.rst @@ -105,6 +105,10 @@ Non-comprehensive list of changes in this release Users should generally expect this to be regularly raised to match the most recently released version of the Visual C++ compiler. +- clang now defaults to ``.init_array`` if no gcc installation can be found. + If a gcc installation is found, it still prefers ``.ctors`` if the found + gcc is older than 4.7.0. + New Compiler Flags ------------------ diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp index 08d4aa51f2..08282ff003 100644 --- a/lib/Driver/ToolChains/Gnu.cpp +++ b/lib/Driver/ToolChains/Gnu.cpp @@ -2366,7 +2366,8 @@ void Generic_ELF::addClangTargetOptions(const ArgList &DriverArgs, getTriple().getArch() == llvm::Triple::aarch64 || getTriple().getArch() == llvm::Triple::aarch64_be || (getTriple().getOS() == llvm::Triple::Linux && - (!V.isOlderThan(4, 7, 0) || getTriple().isAndroid())) || + ((!GCCInstallation.isValid() || !V.isOlderThan(4, 7, 0)) || + getTriple().isAndroid())) || getTriple().getOS() == llvm::Triple::NaCl || (getTriple().getVendor() == llvm::Triple::MipsTechnologies && !getTriple().hasEnvironment()) || diff --git a/test/Driver/constructors.c b/test/Driver/constructors.c index 39a199a3c6..884fbe8466 100644 --- a/test/Driver/constructors.c +++ b/test/Driver/constructors.c @@ -6,6 +6,12 @@ // // RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \ // RUN: -target i386-unknown-linux \ +// RUN: --sysroot=%S/Inputs/resource_dir \ +// RUN: --gcc-toolchain="" \ +// RUN: | FileCheck --check-prefix=CHECK-INIT-ARRAY %s +// +// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \ +// RUN: -target i386-unknown-linux \ // RUN: --sysroot=%S/Inputs/fake_install_tree \ // RUN: --gcc-toolchain="" \ // RUN: | FileCheck --check-prefix=CHECK-INIT-ARRAY %s