[PATCH] D71434: [Driver] Use .init_array for all gcc installations and simplify Generic_ELF -fno-use-init-array rules
Fangrui Song via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 12 13:28:46 PST 2019
MaskRay created this revision.
MaskRay added reviewers: echristo, rnk, thakis.
Herald added subscribers: cfe-commits, s.egerton, simoncook, fedor.sergeev, krytarowski, emaste, dschuff.
Herald added a project: clang.
D39317 <https://reviews.llvm.org/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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D71434
Files:
clang/lib/Driver/ToolChains/FreeBSD.cpp
clang/lib/Driver/ToolChains/FreeBSD.h
clang/lib/Driver/ToolChains/Gnu.cpp
clang/test/Driver/constructors.c
Index: clang/test/Driver/constructors.c
===================================================================
--- clang/test/Driver/constructors.c
+++ clang/test/Driver/constructors.c
@@ -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 \
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2782,23 +2782,7 @@
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");
}
Index: clang/lib/Driver/ToolChains/FreeBSD.h
===================================================================
--- clang/lib/Driver/ToolChains/FreeBSD.h
+++ clang/lib/Driver/ToolChains/FreeBSD.h
@@ -76,6 +76,10 @@
// 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;
Index: clang/lib/Driver/ToolChains/FreeBSD.cpp
===================================================================
--- clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -467,3 +467,12 @@
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");
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71434.233676.patch
Type: text/x-patch
Size: 3409 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191212/a0311c6e/attachment.bin>
More information about the cfe-commits
mailing list