Skip to content

Commit df50259

Browse files
committed
[Driver] Disable uwtable by default in -ffreestanding mode
We make the same decision when compiling the kernel or kexts -- we should do this in -ffreestanding mode as well to avoid size regressions in a potentially large set of firmware projects. It's still possible to get uwtable information in -ffreestanding mode by compiling with -funwind-tables (I expect this to be a rare case: I certainly haven't seen any projects like that). Context: -munwind-tables was enabled by default for some arm targets in r310006. Testing: check-clang rdar://problem/33934446 Differential Revision: https://reviews.llvm.org/D37777 llvm-svn: 313087
1 parent 0b95d37 commit df50259

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3392,6 +3392,15 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
33923392
CmdArgs.push_back("-mpie-copy-relocations");
33933393
}
33943394

3395+
// -fhosted is default.
3396+
// TODO: Audit uses of KernelOrKext and see where it'd be more appropriate to
3397+
// use Freestanding.
3398+
bool Freestanding =
3399+
Args.hasFlag(options::OPT_ffreestanding, options::OPT_fhosted, false) ||
3400+
KernelOrKext;
3401+
if (Freestanding)
3402+
CmdArgs.push_back("-ffreestanding");
3403+
33953404
// This is a coarse approximation of what llvm-gcc actually does, both
33963405
// -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
33973406
// complicated ways.
@@ -3400,7 +3409,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
34003409
options::OPT_fno_asynchronous_unwind_tables,
34013410
(getToolChain().IsUnwindTablesDefault(Args) ||
34023411
getToolChain().getSanitizerArgs().needsUnwindTables()) &&
3403-
!KernelOrKext);
3412+
!Freestanding);
34043413
if (Args.hasFlag(options::OPT_funwind_tables, options::OPT_fno_unwind_tables,
34053414
AsynchronousUnwindTables))
34063415
CmdArgs.push_back("-munwind-tables");
@@ -3790,11 +3799,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
37903799

37913800
Args.AddLastArg(CmdArgs, options::OPT_ftlsmodel_EQ);
37923801

3793-
// -fhosted is default.
3794-
if (Args.hasFlag(options::OPT_ffreestanding, options::OPT_fhosted, false) ||
3795-
KernelOrKext)
3796-
CmdArgs.push_back("-ffreestanding");
3797-
37983802
// Forward -f (flag) options which we can pass directly.
37993803
Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls);
38003804
Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions);

clang/test/Driver/clang-translation.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,22 @@
7373
// RUN: FileCheck -check-prefix=ARM64-APPLE %s
7474
// ARM64-APPLE: -munwind-table
7575

76+
// RUN: %clang -target arm64-apple-ios10 -### -ffreestanding -S %s -arch arm64 2>&1 | \
77+
// RUN: FileCheck -check-prefix=ARM64-FREESTANDING-APPLE %s
78+
//
79+
// RUN: %clang -target arm64-apple-ios10 -### -fno-unwind-tables -ffreestanding -S %s -arch arm64 2>&1 | \
80+
// RUN: FileCheck -check-prefix=ARM64-FREESTANDING-APPLE %s
81+
//
82+
// ARM64-FREESTANDING-APPLE-NOT: -munwind-table
83+
84+
// RUN: %clang -target arm64-apple-ios10 -### -funwind-tables -S %s -arch arm64 2>&1 | \
85+
// RUN: FileCheck -check-prefix=ARM64-EXPLICIT-UWTABLE-APPLE %s
86+
//
87+
// RUN: %clang -target arm64-apple-ios10 -### -ffreestanding -funwind-tables -S %s -arch arm64 2>&1 | \
88+
// RUN: FileCheck -check-prefix=ARM64-EXPLICIT-UWTABLE-APPLE %s
89+
//
90+
// ARM64-EXPLICIT-UWTABLE-APPLE: -munwind-table
91+
7692
// RUN: %clang -target arm64-apple-ios10 -fno-exceptions -### -S %s -arch arm64 2>&1 | \
7793
// RUN: FileCheck -check-prefix=ARM64-APPLE-EXCEP %s
7894
// ARM64-APPLE-EXCEP-NOT: -munwind-table

0 commit comments

Comments
 (0)