summaryrefslogtreecommitdiff
path: root/libgcc/unwind.inc
diff options
context:
space:
mode:
authorIgor Tsimbalist <igor.v.tsimbalist@intel.com>2017-11-17 16:21:23 +0100
committerIgor Tsimbalist <itsimbal@gcc.gnu.org>2017-11-17 16:21:23 +0100
commit6a10fff4e2c2fc4bc5c3f313c08698d83c2292a1 (patch)
tree714437517f3bed4370e786ffd6a22ca4d11f139f /libgcc/unwind.inc
parentf1b7bc164cb370b15c6e62d65120e6494729ac0c (diff)
Add Intel CET support for EH in libgcc.
Control-flow Enforcement Technology (CET), published by Intel, introduces the Shadow Stack feature, which ensures a return from a function is done to exactly the same location from where the function was called. When EH is present the control-flow transfer may skip some stack frames and the shadow stack has to be adjusted not to signal a violation of a control-flow transfer. It's done by counting a number of skiping frames and adjasting shadow stack pointer by this number. Having new semantic of the 'ret' instruction if CET is supported in HW the 'ret' instruction cannot be generated in ix86_expand_epilogue when we are returning after EH is processed. Added a code in ix86_expand_epilogue to adjust Shadow Stack pointer and to generate an indirect jump instead of 'ret'. As sp register is used during this adjustment thus the argument in pro_epilogue_adjust_stack is changed to update cfa_reg based on whether control-flow instrumentation is set. Without updating the cfa_reg field there is an assert later in dwarf2 pass related to mismatch the stack register and cfa_reg value. gcc/ * config/i386/i386.c (ix86_expand_epilogue): Change simple return to indirect jump for EH return if control-flow protection is enabled. Change explicit 'false' argument in pro_epilogue_adjust_stack with a value of flag_cf_protection. * config/i386/i386.md (simple_return_indirect_internal): Remove SImode restriction to support 64-bit. libgcc/ * config/i386/linux-unwind.h: Include config/i386/shadow-stack-unwind.h. * config/i386/shadow-stack-unwind.h: New file. * unwind-dw2.c: (uw_install_context): Add a frame parameter and pass it to _Unwind_Frames_Extra. * unwind-generic.h (_Unwind_Frames_Extra): New. * unwind.inc (_Unwind_RaiseException_Phase2): Add frames_p parameter. Add local variable frames to count number of frames. (_Unwind_ForcedUnwind_Phase2): Likewise. (_Unwind_RaiseException): Add local variable frames to count number of frames, pass it to _Unwind_RaiseException_Phase2 and uw_install_context. (_Unwind_ForcedUnwind): Likewise. (_Unwind_Resume): Likewise. (_Unwind_Resume_or_Rethrow): Likewise. From-SVN: r254876
Diffstat (limited to 'libgcc/unwind.inc')
-rw-r--r--libgcc/unwind.inc34
1 files changed, 23 insertions, 11 deletions
diff --git a/libgcc/unwind.inc b/libgcc/unwind.inc
index 658bd94f8f3..a98154b1b72 100644
--- a/libgcc/unwind.inc
+++ b/libgcc/unwind.inc
@@ -36,9 +36,11 @@
static _Unwind_Reason_Code
_Unwind_RaiseException_Phase2(struct _Unwind_Exception *exc,
- struct _Unwind_Context *context)
+ struct _Unwind_Context *context,
+ unsigned long *frames_p)
{
_Unwind_Reason_Code code;
+ unsigned long frames = 1;
while (1)
{
@@ -71,8 +73,10 @@ _Unwind_RaiseException_Phase2(struct _Unwind_Exception *exc,
gcc_assert (!match_handler);
uw_update_context (context, &fs);
+ frames++;
}
+ *frames_p = frames;
return code;
}
@@ -83,6 +87,7 @@ _Unwind_RaiseException(struct _Unwind_Exception *exc)
{
struct _Unwind_Context this_context, cur_context;
_Unwind_Reason_Code code;
+ unsigned long frames;
/* Set up this_context to describe the current stack frame. */
uw_init_context (&this_context);
@@ -128,11 +133,11 @@ _Unwind_RaiseException(struct _Unwind_Exception *exc)
exc->private_2 = uw_identify_context (&cur_context);
cur_context = this_context;
- code = _Unwind_RaiseException_Phase2 (exc, &cur_context);
+ code = _Unwind_RaiseException_Phase2 (exc, &cur_context, &frames);
if (code != _URC_INSTALL_CONTEXT)
return code;
- uw_install_context (&this_context, &cur_context);
+ uw_install_context (&this_context, &cur_context, frames);
}
@@ -140,11 +145,13 @@ _Unwind_RaiseException(struct _Unwind_Exception *exc)
static _Unwind_Reason_Code
_Unwind_ForcedUnwind_Phase2 (struct _Unwind_Exception *exc,
- struct _Unwind_Context *context)
+ struct _Unwind_Context *context,
+ unsigned long *frames_p)
{
_Unwind_Stop_Fn stop = (_Unwind_Stop_Fn) (_Unwind_Ptr) exc->private_1;
void *stop_argument = (void *) (_Unwind_Ptr) exc->private_2;
_Unwind_Reason_Code code, stop_code;
+ unsigned long frames = 1;
while (1)
{
@@ -183,8 +190,10 @@ _Unwind_ForcedUnwind_Phase2 (struct _Unwind_Exception *exc,
/* Update cur_context to describe the same frame as fs, and discard
the previous context if necessary. */
uw_advance_context (context, &fs);
+ frames++;
}
+ *frames_p = frames;
return code;
}
@@ -197,6 +206,7 @@ _Unwind_ForcedUnwind (struct _Unwind_Exception *exc,
{
struct _Unwind_Context this_context, cur_context;
_Unwind_Reason_Code code;
+ unsigned long frames;
uw_init_context (&this_context);
cur_context = this_context;
@@ -204,11 +214,11 @@ _Unwind_ForcedUnwind (struct _Unwind_Exception *exc,
exc->private_1 = (_Unwind_Ptr) stop;
exc->private_2 = (_Unwind_Ptr) stop_argument;
- code = _Unwind_ForcedUnwind_Phase2 (exc, &cur_context);
+ code = _Unwind_ForcedUnwind_Phase2 (exc, &cur_context, &frames);
if (code != _URC_INSTALL_CONTEXT)
return code;
- uw_install_context (&this_context, &cur_context);
+ uw_install_context (&this_context, &cur_context, frames);
}
@@ -220,6 +230,7 @@ _Unwind_Resume (struct _Unwind_Exception *exc)
{
struct _Unwind_Context this_context, cur_context;
_Unwind_Reason_Code code;
+ unsigned long frames;
uw_init_context (&this_context);
cur_context = this_context;
@@ -227,13 +238,13 @@ _Unwind_Resume (struct _Unwind_Exception *exc)
/* Choose between continuing to process _Unwind_RaiseException
or _Unwind_ForcedUnwind. */
if (exc->private_1 == 0)
- code = _Unwind_RaiseException_Phase2 (exc, &cur_context);
+ code = _Unwind_RaiseException_Phase2 (exc, &cur_context, &frames);
else
- code = _Unwind_ForcedUnwind_Phase2 (exc, &cur_context);
+ code = _Unwind_ForcedUnwind_Phase2 (exc, &cur_context, &frames);
gcc_assert (code == _URC_INSTALL_CONTEXT);
- uw_install_context (&this_context, &cur_context);
+ uw_install_context (&this_context, &cur_context, frames);
}
@@ -245,6 +256,7 @@ _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *exc)
{
struct _Unwind_Context this_context, cur_context;
_Unwind_Reason_Code code;
+ unsigned long frames;
/* Choose between continuing to process _Unwind_RaiseException
or _Unwind_ForcedUnwind. */
@@ -254,11 +266,11 @@ _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *exc)
uw_init_context (&this_context);
cur_context = this_context;
- code = _Unwind_ForcedUnwind_Phase2 (exc, &cur_context);
+ code = _Unwind_ForcedUnwind_Phase2 (exc, &cur_context, &frames);
gcc_assert (code == _URC_INSTALL_CONTEXT);
- uw_install_context (&this_context, &cur_context);
+ uw_install_context (&this_context, &cur_context, frames);
}