diff --git a/docs/tools/eosio-cpp.md b/docs/tools/eosio-cpp.md index 6ebab10a56..2cde5b53df 100644 --- a/docs/tools/eosio-cpp.md +++ b/docs/tools/eosio-cpp.md @@ -54,6 +54,7 @@ compiler options: -fno-lto - Disable LTO -fno-post-pass - Don't run post processing pass -fno-stack-first - Don't set the stack first in memory + -stack-size - Specifies the maximum stack size for the contract -fstack-protector - Enable stack protectors for functions potentially vulnerable to stack smashing -fstack-protector-all - Force the usage of stack protectors for all functions -fstack-protector-strong - Use a strong heuristic to apply stack protectors to functions diff --git a/docs/tools/eosio-ld.md b/docs/tools/eosio-ld.md index 41c29e2532..87f368e834 100644 --- a/docs/tools/eosio-ld.md +++ b/docs/tools/eosio-ld.md @@ -20,6 +20,7 @@ ld options: -fno-lto - Disable LTO -fno-post-pass - Don't run post processing pass -fno-stack-first - Don't set the stack first in memory + -stack-size - Specifies the maximum stack size for the contract -fuse-main - Use main as entry -l= - Root name of library to link -lto-opt= - LTO Optimization level (O0-O3) diff --git a/tools/include/compiler_options.hpp.in b/tools/include/compiler_options.hpp.in index d65c88c9f8..e860c2fc25 100644 --- a/tools/include/compiler_options.hpp.in +++ b/tools/include/compiler_options.hpp.in @@ -63,6 +63,11 @@ static cl::opt fno_stack_first_opt( "fno-stack-first", cl::desc("Don't set the stack first in memory"), cl::cat(LD_CAT)); +static cl::opt stack_size_opt( + "stack-size", + cl::desc("Specifies the maximum stack size for the contract. Defaults to ${EOSIO_STACK_SIZE} bytes."), + cl::init(${EOSIO_STACK_SIZE}), + cl::cat(LD_CAT)); static cl::opt fno_post_pass_opt( "fno-post-pass", cl::desc("Don't run post processing pass"), @@ -415,7 +420,6 @@ static void GetLdDefaults(std::vector& ldopts) { if (!fnative_opt) { ldopts.emplace_back("--gc-sections"); ldopts.emplace_back("--strip-all"); - ldopts.emplace_back("-zstack-size="+std::string("${EOSIO_STACK_SIZE}")); ldopts.emplace_back("--merge-data-segments"); if (fquery_opt || fquery_server_opt || fquery_client_opt) { ldopts.emplace_back("--export-table"); @@ -720,10 +724,12 @@ static Options CreateOptions(bool add_defaults=true) { else { ldopts.emplace_back("--lto-O3"); } + ldopts.emplace_back("-zstack-size=" + std::to_string(stack_size_opt)); #else if (fno_stack_first_opt) { ldopts.emplace_back("-fno-stack-first"); } + ldopts.emplace_back("-stack-size=" + std::to_string(stack_size_opt)); if (fno_lto_opt) { ldopts.emplace_back("-fno-lto-opt"); }