From 64f75885a7618151f2f99a637a48b42f5607cff2 Mon Sep 17 00:00:00 2001 From: Jeeyong Um Date: Sun, 25 Aug 2019 12:51:41 +0000 Subject: [PATCH 1/8] Fix segfault during ABI generation for tuple When passed parameter of clang::QualType is not clang::ElaboratedType, segfault occurs during ABI generation. --- tools/include/eosio/abigen.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/include/eosio/abigen.hpp b/tools/include/eosio/abigen.hpp index b7bea3715f..8e445b243d 100644 --- a/tools/include/eosio/abigen.hpp +++ b/tools/include/eosio/abigen.hpp @@ -110,7 +110,7 @@ namespace eosio { namespace cdt { void add_tuple(const clang::QualType& type) { auto pt = llvm::dyn_cast(type.getTypePtr()); - auto tst = llvm::dyn_cast(pt->desugar().getTypePtr()); + auto tst = llvm::dyn_cast((pt) ? pt->desugar().getTypePtr() : type.getTypePtr()); if (!tst) throw abigen_ex; abi_struct tup; From ec59e63c601e7dbd1c544d208d1df687575d145a Mon Sep 17 00:00:00 2001 From: Jeeyong Um Date: Sun, 25 Aug 2019 10:11:35 +0000 Subject: [PATCH 2/8] merge cherry-pick --- tools/include/eosio/abigen.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/include/eosio/abigen.hpp b/tools/include/eosio/abigen.hpp index 8e445b243d..d3ec265917 100644 --- a/tools/include/eosio/abigen.hpp +++ b/tools/include/eosio/abigen.hpp @@ -433,6 +433,12 @@ namespace eosio { namespace cdt { if (as.base == td.new_type_name) return true; } + for ( auto v : _abi.variants ) { + for ( auto vt : v.types ) { + if ( remove_suffix(vt) == td.new_type_name ) + return true; + } + } for ( auto t : _abi.tables ) if ( t.type == td.new_type_name ) return true; From 999e66189bf0770d4fc4893b8d6ad2d36ab6e554 Mon Sep 17 00:00:00 2001 From: Jeeyong Um Date: Sun, 25 Aug 2019 08:10:55 +0000 Subject: [PATCH 3/8] Fix segfault when using nested typedef When typedef is nested in other namespace, `clang::ElaboratedType` is passed to `get_type_alias` instead of `clang::TypedefType`. When dynamic cast to clang::TypedefType fails, try casting to ElaboratedType once mroe to avoid build fail by segfault. --- tools/include/eosio/gen.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/include/eosio/gen.hpp b/tools/include/eosio/gen.hpp index 151c82facd..ee740e8a9a 100644 --- a/tools/include/eosio/gen.hpp +++ b/tools/include/eosio/gen.hpp @@ -569,12 +569,16 @@ struct generation_utils { inline std::string get_type_alias_string( const clang::QualType& t ) { if (auto dt = llvm::dyn_cast(t.getTypePtr())) return get_type(dt->desugar()); + else if (auto dt = llvm::dyn_cast(t.getTypePtr())) + return get_type_alias_string(dt->desugar()); return get_type(t); } inline std::vector get_type_alias( const clang::QualType& t ) { if (auto dt = llvm::dyn_cast(t.getTypePtr())) return {dt->desugar()}; + else if (auto dt = llvm::dyn_cast(t.getTypePtr())) + return get_type_alias(dt->desugar()); return {}; } From 24fb732016c4d95b2547149c1caaf63a58a8bc1c Mon Sep 17 00:00:00 2001 From: Jeeyong Um Date: Sun, 25 Aug 2019 07:25:24 +0000 Subject: [PATCH 4/8] Fix stack overflow caused by recursive add_type `add_type` calls itself recursively to add all types it refers to. If user-defined types refer to each other or themselves, it causes stack overflow by cycle. --- tools/include/eosio/abigen.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/include/eosio/abigen.hpp b/tools/include/eosio/abigen.hpp index d3ec265917..cd6c70c50e 100644 --- a/tools/include/eosio/abigen.hpp +++ b/tools/include/eosio/abigen.hpp @@ -247,6 +247,9 @@ namespace eosio { namespace cdt { } void add_type( const clang::QualType& t ) { + if (evaluated.count(t.getTypePtr())) + return; + evaluated.insert(t.getTypePtr()); auto type = get_ignored_type(t); if (!is_builtin_type(translate_type(type))) { if (is_aliasing(type)) @@ -485,5 +488,6 @@ namespace eosio { namespace cdt { std::set tables; std::set ctables; std::map rcs; + std::set evaluated; }; }} // ns eosio::cdt From 82e210729aba7ebe58e6a65d206248852d9f7be1 Mon Sep 17 00:00:00 2001 From: Jeeyong Um Date: Wed, 7 Aug 2019 23:52:48 +0000 Subject: [PATCH 5/8] fix cherry-pick conflict --- tools/include/compiler_options.hpp.in | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/tools/include/compiler_options.hpp.in b/tools/include/compiler_options.hpp.in index 633deec6fa..1c2ed83b0b 100644 --- a/tools/include/compiler_options.hpp.in +++ b/tools/include/compiler_options.hpp.in @@ -536,9 +536,8 @@ static Options CreateOptions(bool add_defaults=true) { for ( auto input_filename : input_filename_opt ) { #ifdef ONLY_LD ldopts.push_back(input_filename); -#else - inputs.push_back(input_filename); #endif + inputs.push_back(input_filename); } #ifdef ONLY_LD @@ -751,25 +750,23 @@ static Options CreateOptions(bool add_defaults=true) { #ifndef ONLY_LD if (inputs.size() == 1) { llvm::SmallString<256> fn = llvm::sys::path::filename(inputs[0]); - llvm::SmallString<256> fn2 = fn; - llvm::sys::path::replace_extension(fn, ".wasm"); + llvm::sys::path::replace_extension(fn, fnative_opt ? "" : ".wasm"); output_fn = fn.str(); - llvm::SmallString<256> res; - llvm::sys::path::system_temp_directory(true, res); - ldopts.emplace_back(std::string(std::string(res.str())+"/"+std::string(fn2.str())+".o")); } else { ldopts.emplace_back("a.out"); } -#endif +#else if (inputs.size() == 1) { llvm::SmallString<256> fn = llvm::sys::path::filename(inputs[0]); - llvm::sys::path::replace_extension(fn, ".wasm"); - ldopts.emplace_back("-o "+output_fn); + llvm::sys::path::replace_extension(fn, ""); + llvm::sys::path::replace_extension(fn, fnative_opt ? "" : ".wasm"); output_fn = fn.str(); + ldopts.emplace_back("-o "+output_fn); } else { - ldopts.emplace_back("-o a.out"); output_fn = "a.out"; + ldopts.emplace_back("-o "+output_fn); } +#endif } else { ldopts.emplace_back("-o "+o_opt); @@ -834,5 +831,13 @@ static Options CreateOptions(bool add_defaults=true) { if (fuse_main_opt) ldopts.emplace_back("-fuse-main"); #endif +<<<<<<< HEAD +======= + +#ifndef ONLY_LD +>>>>>>> a153ef9c... Set default output filename return {output_fn, inputs, link, abigen, pp_dir, abigen_output, abigen_contract, copts, ldopts, agopts, agresources, debug, fnative_opt}; +#else + return {output_fn, {}, link, abigen, pp_dir, abigen_output, abigen_contract, copts, ldopts, agopts, agresources, debug, fnative_opt}; +#endif } From 5076c9048dafad666b963471ff0a1368cc959485 Mon Sep 17 00:00:00 2001 From: Bucky Kittinger Date: Fri, 27 Sep 2019 16:31:29 -0400 Subject: [PATCH 6/8] merge fixes --- libraries/eosiolib/chain.h | 1 + tools/include/compiler_options.hpp.in | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/libraries/eosiolib/chain.h b/libraries/eosiolib/chain.h index 0647814ab6..73c111e313 100644 --- a/libraries/eosiolib/chain.h +++ b/libraries/eosiolib/chain.h @@ -33,6 +33,7 @@ extern "C" { * @endcode */ __attribute__((eosio_wasm_import)) + [[deprecated("dep uint32_t get_active_producers( capi_name* producers, uint32_t datalen ); } diff --git a/tools/include/compiler_options.hpp.in b/tools/include/compiler_options.hpp.in index 1c2ed83b0b..030cfdb4c3 100644 --- a/tools/include/compiler_options.hpp.in +++ b/tools/include/compiler_options.hpp.in @@ -831,11 +831,8 @@ static Options CreateOptions(bool add_defaults=true) { if (fuse_main_opt) ldopts.emplace_back("-fuse-main"); #endif -<<<<<<< HEAD -======= #ifndef ONLY_LD ->>>>>>> a153ef9c... Set default output filename return {output_fn, inputs, link, abigen, pp_dir, abigen_output, abigen_contract, copts, ldopts, agopts, agresources, debug, fnative_opt}; #else return {output_fn, {}, link, abigen, pp_dir, abigen_output, abigen_contract, copts, ldopts, agopts, agresources, debug, fnative_opt}; From bd71437f27efad116b815029ca2d1baabb92a0e1 Mon Sep 17 00:00:00 2001 From: Bucky Kittinger Date: Fri, 27 Sep 2019 17:44:00 -0400 Subject: [PATCH 7/8] perfection --- libraries/eosiolib/chain.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/eosiolib/chain.h b/libraries/eosiolib/chain.h index 73c111e313..0647814ab6 100644 --- a/libraries/eosiolib/chain.h +++ b/libraries/eosiolib/chain.h @@ -33,7 +33,6 @@ extern "C" { * @endcode */ __attribute__((eosio_wasm_import)) - [[deprecated("dep uint32_t get_active_producers( capi_name* producers, uint32_t datalen ); } From 7968a44340aa1ac36d3ca2e5638387a1a914c985 Mon Sep 17 00:00:00 2001 From: Vadim Date: Fri, 26 Jul 2019 14:57:57 +0300 Subject: [PATCH 8/8] put buffer_size as a second argument to get_active_producers --- libraries/eosiolib/eosiolib.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libraries/eosiolib/eosiolib.cpp b/libraries/eosiolib/eosiolib.cpp index b92bb10130..f97f67237a 100644 --- a/libraries/eosiolib/eosiolib.cpp +++ b/libraries/eosiolib/eosiolib.cpp @@ -55,10 +55,11 @@ namespace eosio { } std::vector get_active_producers() { - auto prod_cnt = get_active_producers(nullptr, 0)/8; - std::vector active_prods(prod_cnt); - get_active_producers((uint64_t*)active_prods.data(), active_prods.size()); - return active_prods; + const auto buffer_size = get_active_producers(nullptr, 0); + const auto prod_cnt = buffer_size / sizeof(name); + std::vector active_prods(prod_cnt); + get_active_producers((uint64_t*)active_prods.data(), buffer_size); + return active_prods; } // powers.hpp