160 lines
6.9 KiB
Diff
160 lines
6.9 KiB
Diff
Author: Martell Malone <martellmalone@gmail.com>
|
|
|
|
This adds seh exception handling on the clang side.
|
|
For now this will remove link errors regardless if seh is supported on the llvm backend or not.
|
|
|
|
diff --git a/include/clang/Basic/LangOptions.def b/include/clang/Basic/LangOptions.def
|
|
index 34dfea2..ac20a9b 100644
|
|
--- a/include/clang/Basic/LangOptions.def
|
|
+++ b/include/clang/Basic/LangOptions.def
|
|
@@ -80,6 +80,7 @@ LANGOPT(Exceptions , 1, 0, "exception handling")
|
|
LANGOPT(ObjCExceptions , 1, 0, "Objective-C exceptions")
|
|
LANGOPT(CXXExceptions , 1, 0, "C++ exceptions")
|
|
LANGOPT(SjLjExceptions , 1, 0, "setjmp-longjump exception handling")
|
|
+LANGOPT(SEHExceptions , 1, 0, "SEH exception handling")
|
|
LANGOPT(TraditionalCPP , 1, 0, "traditional CPP emulation")
|
|
LANGOPT(RTTI , 1, 1, "run-time type information")
|
|
LANGOPT(MSBitfields , 1, 0, "Microsoft-compatible structure layout")
|
|
diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td
|
|
index 5ffeb43..ab73ca8 100644
|
|
--- a/include/clang/Driver/CC1Options.td
|
|
+++ b/include/clang/Driver/CC1Options.td
|
|
@@ -397,6 +397,8 @@ def fblocks_runtime_optional : Flag<["-"], "fblocks-runtime-optional">,
|
|
HelpText<"Weakly link in the blocks runtime">;
|
|
def fsjlj_exceptions : Flag<["-"], "fsjlj-exceptions">,
|
|
HelpText<"Use SjLj style exceptions">;
|
|
+def fseh_exceptions : Flag<["-"], "fseh-exceptions">,
|
|
+ HelpText<"Use SEH style exceptions">;
|
|
def main_file_name : Separate<["-"], "main-file-name">,
|
|
HelpText<"Main file name to use for debug info">;
|
|
def split_dwarf_file : Separate<["-"], "split-dwarf-file">,
|
|
diff --git a/include/clang/Driver/ToolChain.h b/include/clang/Driver/ToolChain.h
|
|
index ceb1c76..30d687f 100644
|
|
--- a/include/clang/Driver/ToolChain.h
|
|
+++ b/include/clang/Driver/ToolChain.h
|
|
@@ -238,6 +238,9 @@ public:
|
|
/// UseSjLjExceptions - Does this tool chain use SjLj exceptions.
|
|
virtual bool UseSjLjExceptions() const { return false; }
|
|
|
|
+ /// UseSEHExceptions - Does this tool chain use SEH exceptions.
|
|
+ virtual bool UseSEHExceptions() const { return false; }
|
|
+
|
|
/// ComputeLLVMTriple - Return the LLVM target triple to use, after taking
|
|
/// command line arguments into account.
|
|
virtual std::string
|
|
diff --git a/lib/CodeGen/CGException.cpp b/lib/CodeGen/CGException.cpp
|
|
index cc03b0a..a4aa44b 100644
|
|
--- a/lib/CodeGen/CGException.cpp
|
|
+++ b/lib/CodeGen/CGException.cpp
|
|
@@ -155,22 +155,27 @@ namespace {
|
|
static const EHPersonality &get(const LangOptions &Lang);
|
|
static const EHPersonality GNU_C;
|
|
static const EHPersonality GNU_C_SJLJ;
|
|
+ static const EHPersonality GNU_C_SEH;
|
|
static const EHPersonality GNU_ObjC;
|
|
static const EHPersonality GNUstep_ObjC;
|
|
static const EHPersonality GNU_ObjCXX;
|
|
static const EHPersonality NeXT_ObjC;
|
|
static const EHPersonality GNU_CPlusPlus;
|
|
static const EHPersonality GNU_CPlusPlus_SJLJ;
|
|
+ static const EHPersonality GNU_CPlusPlus_SEH;
|
|
};
|
|
}
|
|
|
|
const EHPersonality EHPersonality::GNU_C = { "__gcc_personality_v0", 0 };
|
|
const EHPersonality EHPersonality::GNU_C_SJLJ = { "__gcc_personality_sj0", 0 };
|
|
+const EHPersonality EHPersonality::GNU_C_SEH = { "__gcc_personality_seh0", 0 };
|
|
const EHPersonality EHPersonality::NeXT_ObjC = { "__objc_personality_v0", 0 };
|
|
const EHPersonality EHPersonality::GNU_CPlusPlus = { "__gxx_personality_v0", 0};
|
|
const EHPersonality
|
|
EHPersonality::GNU_CPlusPlus_SJLJ = { "__gxx_personality_sj0", 0 };
|
|
const EHPersonality
|
|
+EHPersonality::GNU_CPlusPlus_SEH = { "__gxx_personality_seh0", 0 };
|
|
+const EHPersonality
|
|
EHPersonality::GNU_ObjC = {"__gnu_objc_personality_v0", "objc_exception_throw"};
|
|
const EHPersonality
|
|
EHPersonality::GNU_ObjCXX = { "__gnustep_objcxx_personality_v0", 0 };
|
|
@@ -180,6 +185,8 @@ EHPersonality::GNUstep_ObjC = { "__gnustep_objc_personality_v0", 0 };
|
|
static const EHPersonality &getCPersonality(const LangOptions &L) {
|
|
if (L.SjLjExceptions)
|
|
return EHPersonality::GNU_C_SJLJ;
|
|
+ if (L.SEHExceptions)
|
|
+ return EHPersonality::GNU_C_SEH;
|
|
return EHPersonality::GNU_C;
|
|
}
|
|
|
|
@@ -204,6 +211,8 @@ static const EHPersonality &getObjCPersonality(const LangOptions &L) {
|
|
static const EHPersonality &getCXXPersonality(const LangOptions &L) {
|
|
if (L.SjLjExceptions)
|
|
return EHPersonality::GNU_CPlusPlus_SJLJ;
|
|
+ else if (L.SEHExceptions)
|
|
+ return EHPersonality::GNU_CPlusPlus_SEH;
|
|
else
|
|
return EHPersonality::GNU_CPlusPlus;
|
|
}
|
|
diff --git a/lib/Driver/MinGWToolChain.cpp b/lib/Driver/MinGWToolChain.cpp
|
|
index 87c0aa2..b2de534 100644
|
|
--- a/lib/Driver/MinGWToolChain.cpp
|
|
+++ b/lib/Driver/MinGWToolChain.cpp
|
|
@@ -93,6 +93,10 @@ bool MinGW::isPICDefaultForced() const {
|
|
return getArch() == llvm::Triple::x86_64;
|
|
}
|
|
|
|
+bool MinGW::UseSEHExceptions() const {
|
|
+ return getArch() == llvm::Triple::x86_64;
|
|
+}
|
|
+
|
|
void MinGW::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
|
|
ArgStringList &CC1Args) const {
|
|
if (DriverArgs.hasArg(options::OPT_nostdinc))
|
|
diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h
|
|
index 556afed..bbad5d0 100644
|
|
--- a/lib/Driver/ToolChains.h
|
|
+++ b/lib/Driver/ToolChains.h
|
|
@@ -750,6 +750,7 @@ public:
|
|
virtual bool isPICDefault() const;
|
|
virtual bool isPIEDefault() const;
|
|
virtual bool isPICDefaultForced() const;
|
|
+ virtual bool UseSEHExceptions() const;
|
|
|
|
virtual void
|
|
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
|
|
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
|
|
index a670502..65bd056 100644
|
|
--- a/lib/Driver/Tools.cpp
|
|
+++ b/lib/Driver/Tools.cpp
|
|
@@ -3440,6 +3440,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
|
|
|
if (getToolChain().UseSjLjExceptions())
|
|
CmdArgs.push_back("-fsjlj-exceptions");
|
|
+ else if (getToolChain().UseSEHExceptions())
|
|
+ CmdArgs.push_back("-fseh-exceptions");
|
|
|
|
// C++ "sane" operator new.
|
|
if (!Args.hasFlag(options::OPT_fassume_sane_operator_new,
|
|
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
|
|
index 92202b7..de55c8b 100644
|
|
--- a/lib/Frontend/CompilerInvocation.cpp
|
|
+++ b/lib/Frontend/CompilerInvocation.cpp
|
|
@@ -1317,6 +1317,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
|
|
Opts.ObjCExceptions = Args.hasArg(OPT_fobjc_exceptions);
|
|
Opts.CXXExceptions = Args.hasArg(OPT_fcxx_exceptions);
|
|
Opts.SjLjExceptions = Args.hasArg(OPT_fsjlj_exceptions);
|
|
+ Opts.SEHExceptions = Args.hasArg(OPT_fseh_exceptions);
|
|
Opts.TraditionalCPP = Args.hasArg(OPT_traditional_cpp);
|
|
|
|
Opts.RTTI = !Args.hasArg(OPT_fno_rtti);
|
|
diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp
|
|
index 39c474b..ceab8ac 100644
|
|
--- a/lib/Frontend/InitPreprocessor.cpp
|
|
+++ b/lib/Frontend/InitPreprocessor.cpp
|
|
@@ -495,6 +495,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
|
|
Builder.defineMacro("__GXX_RTTI");
|
|
if (LangOpts.SjLjExceptions)
|
|
Builder.defineMacro("__USING_SJLJ_EXCEPTIONS__");
|
|
+ if (LangOpts.SEHExceptions)
|
|
+ Builder.defineMacro("__SEH__");
|
|
|
|
if (LangOpts.Deprecated)
|
|
Builder.defineMacro("__DEPRECATED");
|