@@ -404,7 +404,7 @@ shouldUseExceptionTablesForObjCExceptions(const ObjCRuntime &runtime,
404404// / master flag, -fexceptions and also language specific flags to enable/disable
405405// / C++ and Objective-C exceptions. This makes it possible to for example
406406// / disable C++ exceptions but enable Objective-C exceptions.
407- static void addExceptionArgs (const ArgList &Args, types::ID InputType,
407+ static bool addExceptionArgs (const ArgList &Args, types::ID InputType,
408408 const ToolChain &TC, bool KernelOrKext,
409409 const ObjCRuntime &objcRuntime,
410410 ArgStringList &CmdArgs) {
@@ -419,7 +419,7 @@ static void addExceptionArgs(const ArgList &Args, types::ID InputType,
419419 Args.ClaimAllArgs (options::OPT_fno_objc_exceptions);
420420 Args.ClaimAllArgs (options::OPT_fcxx_exceptions);
421421 Args.ClaimAllArgs (options::OPT_fno_cxx_exceptions);
422- return ;
422+ return false ;
423423 }
424424
425425 // See if the user explicitly enabled exceptions.
@@ -462,6 +462,7 @@ static void addExceptionArgs(const ArgList &Args, types::ID InputType,
462462
463463 if (EH)
464464 CmdArgs.push_back (" -fexceptions" );
465+ return EH;
465466}
466467
467468static bool ShouldEnableAutolink (const ArgList &Args, const ToolChain &TC,
@@ -4971,14 +4972,15 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
49714972 // This is a coarse approximation of what llvm-gcc actually does, both
49724973 // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
49734974 // complicated ways.
4974- bool AsynchronousUnwindTables =
4975+ bool UnwindTables =
49754976 Args.hasFlag (options::OPT_fasynchronous_unwind_tables,
49764977 options::OPT_fno_asynchronous_unwind_tables,
49774978 (TC.IsUnwindTablesDefault (Args) ||
49784979 TC.getSanitizerArgs ().needsUnwindTables ()) &&
49794980 !Freestanding);
4980- if (Args.hasFlag (options::OPT_funwind_tables, options::OPT_fno_unwind_tables,
4981- AsynchronousUnwindTables))
4981+ UnwindTables = Args.hasFlag (options::OPT_funwind_tables,
4982+ options::OPT_fno_unwind_tables, UnwindTables);
4983+ if (UnwindTables)
49824984 CmdArgs.push_back (" -munwind-tables" );
49834985
49844986 // Prepare `-aux-target-cpu` and `-aux-target-feature` unless
@@ -6039,8 +6041,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
60396041 CmdArgs.push_back (" -fapplication-extension" );
60406042
60416043 // Handle GCC-style exception args.
6044+ bool EH = false ;
60426045 if (!C.getDriver ().IsCLMode ())
6043- addExceptionArgs (Args, InputType, TC, KernelOrKext, Runtime, CmdArgs);
6046+ EH = addExceptionArgs (Args, InputType, TC, KernelOrKext, Runtime, CmdArgs);
60446047
60456048 // Handle exception personalities
60466049 Arg *A = Args.getLastArg (
@@ -6600,6 +6603,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
66006603 !TC.getTriple ().isAndroid () && TC.useIntegratedAs ()))
66016604 CmdArgs.push_back (" -faddrsig" );
66026605
6606+ if ((Triple.isOSBinFormatELF () || Triple.isOSBinFormatMachO ()) &&
6607+ (EH || UnwindTables || DebugInfoKind != codegenoptions::NoDebugInfo))
6608+ CmdArgs.push_back (" -D__GCC_HAVE_DWARF2_CFI_ASM=1" );
6609+
66036610 if (Arg *A = Args.getLastArg (options::OPT_fsymbol_partition_EQ)) {
66046611 std::string Str = A->getAsString (Args);
66056612 if (!TC.getTriple ().isOSBinFormatELF ())
0 commit comments