t.p.northover created this revision. Herald added subscribers: kristof.beyls, mcrosier. Herald added a project: All. t.p.northover requested review of this revision. Herald added a subscriber: MaskRay. Herald added a project: clang.
AArch64 MachO has a compact unwind format where most functions' unwind info can be represented in just 4 bytes. But this cannot represent any asynchronous CFI function, so it's essentially disabled when that's used. This is a large code-size hit that we'd rather not take unless explicitly requested. So this patch adds a new callback to switch the default on ARM64 MachO to synchronous. Command-line options can still turn it on if anyone wants to take the hit. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D131153 Files: clang/include/clang/Driver/ToolChain.h clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Driver/ToolChains/Darwin.cpp clang/lib/Driver/ToolChains/Darwin.h clang/test/Driver/clang-translation.c clang/test/Preprocessor/unwind-tables.c
Index: clang/test/Preprocessor/unwind-tables.c =================================================================== --- clang/test/Preprocessor/unwind-tables.c +++ clang/test/Preprocessor/unwind-tables.c @@ -3,7 +3,7 @@ // RUN: %clang %s -dM -E -target x86_64 | FileCheck %s // RUN: %clang %s -dM -E -target x86_64 -funwind-tables -fno-asynchronous-unwind-tables -g | FileCheck %s -// RUN: %clang %s -dM -E -target aarch64-apple-darwin | FileCheck %s +// RUN: %clang %s -dM -E -target aarch64-apple-darwin | FileCheck %s --check-prefix=NO // RUN: %clang %s -dM -E -target x86_64 -fno-asynchronous-unwind-tables -g | FileCheck %s // RUN: %clang %s -dM -E -target x86_64 -fno-asynchronous-unwind-tables -fexceptions | FileCheck %s Index: clang/test/Driver/clang-translation.c =================================================================== --- clang/test/Driver/clang-translation.c +++ clang/test/Driver/clang-translation.c @@ -78,7 +78,11 @@ // RUN: %clang -target arm64-apple-ios10 -### -S %s -arch arm64 2>&1 | \ // RUN: FileCheck -check-prefix=ARM64-APPLE %s -// ARM64-APPLE: -funwind-tables=2 +// ARM64-APPLE-NOT: -funwind-tables + +// RUN: %clang -target arm64-apple-ios10 -funwind-tables -### -S %s -arch arm64 2>&1 | \ +// RUN: FileCheck -check-prefix=ARM64-APPLE-UNWIND %s +// ARM64-APPLE-UNWIND: -funwind-tables=1 // RUN: %clang -target arm64-apple-ios10 -### -ffreestanding -S %s -arch arm64 2>&1 | \ // RUN: FileCheck -check-prefix=ARM64-FREESTANDING-APPLE %s Index: clang/lib/Driver/ToolChains/Darwin.h =================================================================== --- clang/lib/Driver/ToolChains/Darwin.h +++ clang/lib/Driver/ToolChains/Darwin.h @@ -256,6 +256,9 @@ bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override; + bool + IsAsyncUnwindTablesDefault(const llvm::opt::ArgList &Args) const override; + RuntimeLibType GetDefaultRuntimeLibType() const override { return ToolChain::RLT_CompilerRT; } Index: clang/lib/Driver/ToolChains/Darwin.cpp =================================================================== --- clang/lib/Driver/ToolChains/Darwin.cpp +++ clang/lib/Driver/ToolChains/Darwin.cpp @@ -2894,6 +2894,15 @@ true)); } +bool MachO::IsAsyncUnwindTablesDefault(const ArgList &Args) const { + // AArch64 has compact unwind format, making the size overhead from + // asynchronous unwind particularly bad, so disable by default. + if (getArch() == llvm::Triple::aarch64) + return false; + + return IsUnwindTablesDefault(Args); +} + bool MachO::UseDwarfDebugFlags() const { if (const char *S = ::getenv("RC_DEBUG_OPTIONS")) return S[0] != '\0'; Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -5387,11 +5387,12 @@ // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more // complicated ways. auto SanitizeArgs = TC.getSanitizerArgs(Args); - bool AsyncUnwindTables = Args.hasFlag( - options::OPT_fasynchronous_unwind_tables, - options::OPT_fno_asynchronous_unwind_tables, - (TC.IsUnwindTablesDefault(Args) || SanitizeArgs.needsUnwindTables()) && - !Freestanding); + bool AsyncUnwindTables = + Args.hasFlag(options::OPT_fasynchronous_unwind_tables, + options::OPT_fno_asynchronous_unwind_tables, + (TC.IsAsyncUnwindTablesDefault(Args) || + SanitizeArgs.needsUnwindTables()) && + !Freestanding); bool UnwindTables = Args.hasFlag(options::OPT_funwind_tables, options::OPT_fno_unwind_tables, false); if (AsyncUnwindTables) Index: clang/include/clang/Driver/ToolChain.h =================================================================== --- clang/include/clang/Driver/ToolChain.h +++ clang/include/clang/Driver/ToolChain.h @@ -497,6 +497,13 @@ /// by default. virtual bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const; + /// IsAsyncUnwindTablesDefault - Does this tool chain use + /// -fasync-unwind-tables by default. + virtual bool + IsAsyncUnwindTablesDefault(const llvm::opt::ArgList &Args) const { + return IsUnwindTablesDefault(Args); + } + /// Test whether this toolchain supports outline atomics by default. virtual bool IsAArch64OutlineAtomicsDefault(const llvm::opt::ArgList &Args) const {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits