From 377a97a6db9c850b45cf88b1c22f938abe19ffbe Mon Sep 17 00:00:00 2001 From: jdh8d <jdh8d@git.zephyr-software.com> Date: Wed, 30 Sep 2015 18:24:58 +0000 Subject: [PATCH] updates to p1transform to allow for the frame size doubleing to be disabled. Former-commit-id: 6a00be1939b8a0e530cb80f270280e5b1135b27f --- tools/transforms/PNMain.cpp | 18 +++++++++++++++++- tools/transforms/PNStackLayout.cpp | 13 +++++++++---- tools/transforms/globals.h | 8 +++++++- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/tools/transforms/PNMain.cpp b/tools/transforms/PNMain.cpp index d96b93df1..5ec4f2176 100644 --- a/tools/transforms/PNMain.cpp +++ b/tools/transforms/PNMain.cpp @@ -69,7 +69,8 @@ enum MIN_STACK_PAD_OPTION, MAX_STACK_PAD_OPTION, RECURSIVE_MIN_STACK_PAD_OPTION, - RECURSIVE_MAX_STACK_PAD_OPTION + RECURSIVE_MAX_STACK_PAD_OPTION, + SHOULD_DOUBLE_FRAME_SIZE_OPTION }; @@ -92,6 +93,7 @@ static struct option const long_options[] = {"max_stack_padding",required_argument, NULL, MAX_STACK_PAD_OPTION}, {"recursive_min_stack_padding",required_argument, NULL, RECURSIVE_MIN_STACK_PAD_OPTION}, {"recursive_max_stack_padding",required_argument, NULL, RECURSIVE_MAX_STACK_PAD_OPTION}, + {"should_double_frame_size",required_argument, NULL, SHOULD_DOUBLE_FRAME_SIZE_OPTION}, {NULL, 0, NULL, 0} }; @@ -326,6 +328,20 @@ int main(int argc, char **argv) pn_options->setRecursiveMaxStackPadding(recursive_max_stack_padding); break; } + case SHOULD_DOUBLE_FRAME_SIZE_OPTION: + { + if(strcasecmp("true",optarg)==0) + pn_options->setShouldDoubleFrameSize(true); + else if(strcasecmp("false",optarg)==0) + pn_options->setShouldDoubleFrameSize(false); + else + { + cout<<"Error: should_double_frame_size option needs to be 'true' or 'false': found "<<optarg<<endl; + usage(); + exit(1); + } + break; + } case '?': { //error message already printed by getopt_long diff --git a/tools/transforms/PNStackLayout.cpp b/tools/transforms/PNStackLayout.cpp index f94963482..98cd8afe2 100644 --- a/tools/transforms/PNStackLayout.cpp +++ b/tools/transforms/PNStackLayout.cpp @@ -83,10 +83,15 @@ unsigned int PNStackLayout::GetRandomPadding(unsigned int obj_size) //align the original stack frame if not aligned, adding more bytes if necessary //TODO: should this be scaled down if the func is recursive? - //if the original frame size is not aligned, then add as many bytes as necessary to align it - //for example, if 3 bytes over alignment, and the alignment stride is 8, then add 8 - 3, or 5 bytes. - pad += (ALIGNMENT_BYTE_SIZE - (stack_layout.frame_alloc_size % ALIGNMENT_BYTE_SIZE)); - pad += stack_layout.frame_alloc_size; + + + if(pn_options->getShouldDoubleFrameSize()) + { + //if the original frame size is not aligned, then add as many bytes as necessary to align it + //for example, if 3 bytes over alignment, and the alignment stride is 8, then add 8 - 3, or 5 bytes. + pad += (ALIGNMENT_BYTE_SIZE - (stack_layout.frame_alloc_size % ALIGNMENT_BYTE_SIZE)); + pad += stack_layout.frame_alloc_size; + } return pad; } diff --git a/tools/transforms/globals.h b/tools/transforms/globals.h index 122ef2f24..ff5c45542 100644 --- a/tools/transforms/globals.h +++ b/tools/transforms/globals.h @@ -23,26 +23,31 @@ extern bool verbose_log; -class PNOptions { +class PNOptions +{ public: // default configuration parameters go here PNOptions() { + // specify defaults; min_stack_padding = 64; max_stack_padding = 64; recursive_min_stack_padding = 32; recursive_max_stack_padding = 64; do_canaries = true; + should_double_frame_size=true; } void setMinStackPadding(int val) { min_stack_padding = val; } void setMaxStackPadding(int val) { max_stack_padding = val; } void setRecursiveMinStackPadding(int val) { recursive_min_stack_padding = val; } void setRecursiveMaxStackPadding(int val) { recursive_max_stack_padding = val; } + void setShouldDoubleFrameSize(bool val) { should_double_frame_size = val; } int getMinStackPadding() const { return min_stack_padding; } int getMaxStackPadding() const { return max_stack_padding; } int getRecursiveMinStackPadding() const { return recursive_min_stack_padding; } int getRecursiveMaxStackPadding() const { return recursive_max_stack_padding; } + bool getShouldDoubleFrameSize() const { return should_double_frame_size; } void setDoCanaries(bool canaries) { do_canaries = canaries; } bool getDoCanaries() const { return do_canaries; } @@ -53,6 +58,7 @@ class PNOptions { int recursive_min_stack_padding; int recursive_max_stack_padding; bool do_canaries; + bool should_double_frame_size; }; extern PNOptions *pn_options; -- GitLab