[Driver] Use .init_array for all gcc installations and simplify Generic_ELF -fno-use-init-array rules
D39317 made clang use .init_array when no gcc installations is found. This change changes all gcc installations to use .init_array . GCC 4.7 by default stopped providing .ctors/.dtors compatible crt files, and stopped emitting .ctors for __attribute__((constructor)). .init_array should always work. FreeBSD rules are moved to FreeBSD.cpp to make Generic_ELF rules clean. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D71434
This commit is contained in:
@@ -89,6 +89,10 @@ Non-comprehensive list of changes in this release
|
||||
to run at a lower frequency which can impact performance. This behavior can be
|
||||
changed by passing -mprefer-vector-width=512 on the command line.
|
||||
|
||||
* clang now defaults to ``.init_array`` on Linux. It used to use ``.ctors`` if
|
||||
the found gcc installation is older than 4.7.0. Add ``-fno-use-init-array`` to
|
||||
get the old behavior (``.ctors``).
|
||||
|
||||
New Compiler Flags
|
||||
------------------
|
||||
|
||||
|
||||
@@ -467,3 +467,12 @@ SanitizerMask FreeBSD::getSupportedSanitizers() const {
|
||||
Res |= SanitizerKind::Memory;
|
||||
return Res;
|
||||
}
|
||||
|
||||
void FreeBSD::addClangTargetOptions(const ArgList &DriverArgs,
|
||||
ArgStringList &CC1Args,
|
||||
Action::OffloadKind) const {
|
||||
if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
|
||||
options::OPT_fno_use_init_array,
|
||||
getTriple().getOSMajorVersion() >= 12))
|
||||
CC1Args.push_back("-fno-use-init-array");
|
||||
}
|
||||
|
||||
@@ -76,6 +76,10 @@ public:
|
||||
// Until dtrace (via CTF) and LLDB can deal with distributed debug info,
|
||||
// FreeBSD defaults to standalone/full debug info.
|
||||
bool GetDefaultStandaloneDebug() const override { return true; }
|
||||
void
|
||||
addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
|
||||
llvm::opt::ArgStringList &CC1Args,
|
||||
Action::OffloadKind DeviceOffloadKind) const override;
|
||||
|
||||
protected:
|
||||
Tool *buildAssembler() const override;
|
||||
|
||||
@@ -2782,23 +2782,7 @@ void Generic_ELF::anchor() {}
|
||||
void Generic_ELF::addClangTargetOptions(const ArgList &DriverArgs,
|
||||
ArgStringList &CC1Args,
|
||||
Action::OffloadKind) const {
|
||||
const Generic_GCC::GCCVersion &V = GCCInstallation.getVersion();
|
||||
bool UseInitArrayDefault =
|
||||
getTriple().getArch() == llvm::Triple::aarch64 ||
|
||||
getTriple().getArch() == llvm::Triple::aarch64_be ||
|
||||
(getTriple().isOSFreeBSD() &&
|
||||
getTriple().getOSMajorVersion() >= 12) ||
|
||||
(getTriple().getOS() == llvm::Triple::Linux &&
|
||||
((!GCCInstallation.isValid() || !V.isOlderThan(4, 7, 0)) ||
|
||||
getTriple().isAndroid())) ||
|
||||
getTriple().getOS() == llvm::Triple::NaCl ||
|
||||
(getTriple().getVendor() == llvm::Triple::MipsTechnologies &&
|
||||
!getTriple().hasEnvironment()) ||
|
||||
getTriple().getOS() == llvm::Triple::Solaris ||
|
||||
getTriple().getArch() == llvm::Triple::riscv32 ||
|
||||
getTriple().getArch() == llvm::Triple::riscv64;
|
||||
|
||||
if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
|
||||
options::OPT_fno_use_init_array, UseInitArrayDefault))
|
||||
options::OPT_fno_use_init_array, true))
|
||||
CC1Args.push_back("-fno-use-init-array");
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
// RUN: -target i386-unknown-linux \
|
||||
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
|
||||
// RUN: --gcc-toolchain="" \
|
||||
// RUN: | FileCheck --check-prefix=CHECK-NO-INIT-ARRAY %s
|
||||
// RUN: | FileCheck --check-prefix=CHECK-INIT-ARRAY %s
|
||||
//
|
||||
// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
|
||||
// RUN: -fuse-init-array \
|
||||
|
||||
Reference in New Issue
Block a user