From a1bfa0de3cbffef96c2398dbe0db1cb3879fded3 Mon Sep 17 00:00:00 2001 From: Jeeyong Um Date: Mon, 2 Sep 2019 08:29:56 +0000 Subject: [PATCH 1/8] Handle `-x` compile option --- tools/include/compiler_options.hpp.in | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/include/compiler_options.hpp.in b/tools/include/compiler_options.hpp.in index a5e17cc157..46741b91fe 100644 --- a/tools/include/compiler_options.hpp.in +++ b/tools/include/compiler_options.hpp.in @@ -642,6 +642,10 @@ static Options CreateOptions(bool add_defaults=true) { } if(g_opt) copts.emplace_back("-g"); + if (!x_opt.empty()) { + // x_opt should precede input files + copts.insert(copts.begin(), "-x"+x_opt); + } if (color_diag_opt) { copts.emplace_back("-fcolor-diagnostics"); } From a4bf636e89c7736afdaa83011abfd71900a3c34a Mon Sep 17 00:00:00 2001 From: Jeeyong Um Date: Mon, 2 Sep 2019 08:31:07 +0000 Subject: [PATCH 2/8] Enforce cxx build when compiling c with eosio-cpp --- tools/cc/eosio-cpp.cpp.in | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/cc/eosio-cpp.cpp.in b/tools/cc/eosio-cpp.cpp.in index e66be14fcf..5028f4b2e5 100644 --- a/tools/cc/eosio-cpp.cpp.in +++ b/tools/cc/eosio-cpp.cpp.in @@ -113,6 +113,8 @@ void generate(const std::vector& base_options, std::string input, s options.push_back(input); // don't remove oddity of CommonOptionsParser? options.push_back(input); options.push_back("--"); + if (llvm::sys::path::extension(input).equals(".c")) + options.push_back("-xc++"); for (size_t i=1; i < base_options.size(); i++) { options.push_back(base_options[i]); } @@ -219,6 +221,9 @@ int main(int argc, const char **argv) { new_opts.insert(new_opts.begin(), "-o "+output); outputs.push_back(output); + if (llvm::sys::path::extension(input).equals(".c")) + new_opts.insert(new_opts.begin(), "-xc++"); + if (!eosio::cdt::environment::exec_subprogram("clang-7", new_opts)) { llvm::sys::fs::remove(tmp_file); return -1; From 4a4afd0343da6717ce0d11e3308bb098efebd18d Mon Sep 17 00:00:00 2001 From: Jeeyong Um Date: Sun, 25 Aug 2019 07:35:51 +0000 Subject: [PATCH 3/8] Fix build fail when struct inherits from std types `add_struct` enforces parsing its base as struct, and it causes segfault when inheriting from the std types. This patch mitigates this issue by allowing add_struct to call add_type for its base, but generated ABI is still not usable, because chain::abi_serializer requires struct base to be struct type. There is a workaround fix making it work by trick, but ultimately it needs consensus upgrade. https://github.com/EOSIO/eosio.cdt/issues/541 --- 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 761ade8033..c1fe733c3b 100644 --- a/tools/include/eosio/abigen.hpp +++ b/tools/include/eosio/abigen.hpp @@ -159,7 +159,7 @@ namespace eosio { namespace cdt { abi_struct ret; if ( decl->getNumBases() == 1 ) { ret.base = get_type(decl->bases_begin()->getType()); - add_struct(decl->bases_begin()->getType().getTypePtr()->getAsCXXRecordDecl()); + add_type(decl->bases_begin()->getType()); } std::string sub_name = ""; for ( auto field : decl->fields() ) { From eabd01af0e7ae8209475a72cee60503593ce85e0 Mon Sep 17 00:00:00 2001 From: Jeeyong Um Date: Sun, 25 Aug 2019 07:58:54 +0000 Subject: [PATCH 4/8] Remove unused variable --- tools/include/eosio/abigen.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/include/eosio/abigen.hpp b/tools/include/eosio/abigen.hpp index c1fe733c3b..b9033630f9 100644 --- a/tools/include/eosio/abigen.hpp +++ b/tools/include/eosio/abigen.hpp @@ -161,7 +161,6 @@ namespace eosio { namespace cdt { ret.base = get_type(decl->bases_begin()->getType()); add_type(decl->bases_begin()->getType()); } - std::string sub_name = ""; for ( auto field : decl->fields() ) { if ( field->getName() == "transaction_extensions") { abi_struct ext; @@ -173,7 +172,6 @@ namespace eosio { namespace cdt { } else { ret.fields.push_back({field->getName().str(), get_type(field->getType())}); - sub_name += "_" + get_type(field->getType()); add_type(field->getType()); } } From 98f549ca54d2fae8167cbfc8431ccab950267428 Mon Sep 17 00:00:00 2001 From: Jeeyong Um Date: Sun, 25 Aug 2019 09:55:43 +0000 Subject: [PATCH 5/8] cherry-pick merge conflicts fix --- tools/include/eosio/abigen.hpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/include/eosio/abigen.hpp b/tools/include/eosio/abigen.hpp index b9033630f9..1cd33e636b 100644 --- a/tools/include/eosio/abigen.hpp +++ b/tools/include/eosio/abigen.hpp @@ -387,6 +387,14 @@ namespace eosio { namespace cdt { set_of_tables.insert(t); } + std::function get_root_name; + get_root_name = [&] (const std::string& name) { + for (auto td : _abi.typedefs) + if (remove_suffix(name) == td.new_type_name) + return get_root_name(td.type); + return name; + }; + auto validate_struct = [&]( abi_struct as ) { if ( is_builtin_type(_translate_type(as.name)) ) return false; @@ -401,7 +409,7 @@ namespace eosio { namespace cdt { return true; } } - if (s.base == as.name) + if (get_root_name(s.base) == as.name) return true; } for ( auto a : _abi.actions ) { @@ -421,10 +429,14 @@ namespace eosio { namespace cdt { auto validate_types = [&]( abi_typedef td ) { for ( auto as : _abi.structs ) - if (validate_struct(as)) + if (validate_struct(as)) { for ( auto f : as.fields ) if ( remove_suffix(f.type) == td.new_type_name ) return true; + 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 ) From c750e54b3fff16406113e1330ea1950e32a7aa18 Mon Sep 17 00:00:00 2001 From: Jeeyong Um Date: Thu, 8 Aug 2019 02:26:40 +0000 Subject: [PATCH 6/8] cherry-pick merge conflict fixes --- tools/include/compiler_options.hpp.in | 57 ++------------------------- 1 file changed, 4 insertions(+), 53 deletions(-) diff --git a/tools/include/compiler_options.hpp.in b/tools/include/compiler_options.hpp.in index 46741b91fe..fa10b93802 100644 --- a/tools/include/compiler_options.hpp.in +++ b/tools/include/compiler_options.hpp.in @@ -555,54 +555,6 @@ static Options CreateOptions(bool add_defaults=true) { #endif #endif #ifndef ONLY_LD - copts.emplace_back("-I./"); - if (!sysroot_opt.empty()) { - copts.emplace_back("--sysroot="+sysroot_opt); - copts.emplace_back("-I"+sysroot_opt+"/include/libcxx"); - copts.emplace_back("-I"+sysroot_opt+"/include/libc"); - - // only allow capi for native builds and for eosio-cc - if (fnative_opt) { - copts.emplace_back("-I"+sysroot_opt+"/include/eosiolib/capi"); - copts.emplace_back("-I"+sysroot_opt+"/include/eosiolib/native"); - } -#ifndef CPP_COMP - copts.emplace_back("-I"+sysroot_opt+"/include/eosiolib/capi"); -#endif - copts.emplace_back("-I"+sysroot_opt+"/include/eosiolib/core"); - copts.emplace_back("-I"+sysroot_opt+"/include/eosiolib/contracts"); - - ldopts.emplace_back("-L"+sysroot_opt+"/lib"); -#ifndef __APPLE__ - ldopts.emplace_back("-L"+sysroot_opt+"/lib64"); -#endif - } - else { - copts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include/libcxx"); - copts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include/libc"); - copts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include"); - copts.emplace_back("--sysroot="+eosio::cdt::whereami::where()+"/../"); - agopts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include/libcxx"); - agopts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include/libc"); - agopts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include"); - agopts.emplace_back("--sysroot="+eosio::cdt::whereami::where()+"/../"); - ldopts.emplace_back("-L"+eosio::cdt::whereami::where()+"/../lib"); - - if (fnative_opt) { - copts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include/eosiolib/capi"); - copts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include/eosiolib/native"); - } -#ifndef CPP_COMP - copts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include/eosiolib/capi"); -#endif - copts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include/eosiolib/core"); - copts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include/eosiolib/contracts"); - -#ifndef __APPLE__ - ldopts.emplace_back("-L"+eosio::cdt::whereami::where()+"/../lib64"); -#endif - } - if (!isystem_opt.empty()) { copts.emplace_back("-isystem="+isystem_opt); } @@ -801,12 +753,11 @@ static Options CreateOptions(bool add_defaults=true) { #ifndef ONLY_LD #ifdef CPP_COMP if (! std_opt.empty()) { - copts.emplace_back("--std="+std_opt); - agopts.emplace_back("--std="+std_opt); + copts.emplace_back("-std="+std_opt); + agopts.emplace_back("-std="+std_opt); } else { - copts.emplace_back("--std=c++17"); - agopts.emplace_back("--std=c++17"); - + copts.emplace_back("-std=c++17"); + agopts.emplace_back("-std=c++17"); } if (faligned_allocation_opt) { From cb0cebe5135e2c5a6a0686e96226d84bfcb819a1 Mon Sep 17 00:00:00 2001 From: Jeeyong Um Date: Thu, 8 Aug 2019 02:28:16 +0000 Subject: [PATCH 7/8] more fixes to build --- libraries/libc++/CMakeLists.txt | 8 ++--- tools/cc/eosio-cpp.cpp.in | 19 +---------- tools/include/compiler_options.hpp.in | 46 +++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 22 deletions(-) diff --git a/libraries/libc++/CMakeLists.txt b/libraries/libc++/CMakeLists.txt index a68aacbdd6..b5b74e98cb 100644 --- a/libraries/libc++/CMakeLists.txt +++ b/libraries/libc++/CMakeLists.txt @@ -18,19 +18,19 @@ add_native_library(native_c++ target_include_directories(c++ PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/libcxx/include ${CMAKE_SOURCE_DIR}/libc/musl/include ${CMAKE_SOURCE_DIR}/libc/musl/src/internal ${CMAKE_SOURCE_DIR}/libc/musl/src/crypt - ${CMAKE_SOURCE_DIR}/libc/musl/arch/eos - ${CMAKE_CURRENT_SOURCE_DIR}/libcxx/include) + ${CMAKE_SOURCE_DIR}/libc/musl/arch/eos) target_include_directories(native_c++ PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/libcxx/include ${CMAKE_SOURCE_DIR}/libc/musl/include ${CMAKE_SOURCE_DIR}/libc/musl/src/internal ${CMAKE_SOURCE_DIR}/libc/musl/src/crypt - ${CMAKE_SOURCE_DIR}/libc/musl/arch/eos - ${CMAKE_CURRENT_SOURCE_DIR}/libcxx/include) + ${CMAKE_SOURCE_DIR}/libc/musl/arch/eos) target_link_libraries(c++ c) target_link_libraries(native_c++ native_c) diff --git a/tools/cc/eosio-cpp.cpp.in b/tools/cc/eosio-cpp.cpp.in index 5028f4b2e5..90ed8151d3 100644 --- a/tools/cc/eosio-cpp.cpp.in +++ b/tools/cc/eosio-cpp.cpp.in @@ -115,27 +115,10 @@ void generate(const std::vector& base_options, std::string input, s options.push_back("--"); if (llvm::sys::path::extension(input).equals(".c")) options.push_back("-xc++"); - for (size_t i=1; i < base_options.size(); i++) { + for (size_t i=0; i < base_options.size(); i++) { options.push_back(base_options[i]); } - options.push_back("--target=wasm32"); - options.push_back("-nostdlib"); - options.push_back("-ffreestanding"); - options.push_back("-fno-builtin"); - options.push_back("-fno-rtti"); - options.push_back("-fno-exceptions"); - options.push_back("-I${Boost_INCLUDE_DIRS}"); - options.push_back("-DBOOST_DISABLE_ASSERTS"); - options.push_back("-DBOOST_EXCEPTION_DISABLE"); options.push_back("-Wno-everything"); - options.push_back("-std=c++17"); - options.push_back(std::string("-I")+eosio::cdt::whereami::where()+"/../include/libcxx"); - options.push_back(std::string("-I")+eosio::cdt::whereami::where()+"/../include/libc"); - options.push_back(std::string("-I")+eosio::cdt::whereami::where()+"/../include"); - options.push_back(std::string("-I")+eosio::cdt::whereami::where()+"/../../../../../libraries/libc++/libcxx/include"); - options.push_back(std::string("-I")+eosio::cdt::whereami::where()+"/../../../../../libraries/libc/musl/include"); - options.push_back(std::string("-I")+eosio::cdt::whereami::where()+"/../../../../../libraries"); - options.push_back(std::string("-I")+eosio::cdt::whereami::where()+"/../../../../../libraries/boost/include"); int size = options.size(); const char** new_argv = new const char*[size]; diff --git a/tools/include/compiler_options.hpp.in b/tools/include/compiler_options.hpp.in index fa10b93802..2792ee4248 100644 --- a/tools/include/compiler_options.hpp.in +++ b/tools/include/compiler_options.hpp.in @@ -645,6 +645,52 @@ static Options CreateOptions(bool add_defaults=true) { copts.emplace_back("-I"+inc_dir); agopts.emplace_back("-I"+inc_dir); } + if (!sysroot_opt.empty()) { + copts.emplace_back("--sysroot="+sysroot_opt); + copts.emplace_back("-I"+sysroot_opt+"/include/libcxx"); + copts.emplace_back("-I"+sysroot_opt+"/include/libc"); + + // only allow capi for native builds and for eosio-cc + if (fnative_opt) { + copts.emplace_back("-I"+sysroot_opt+"/include/eosiolib/capi"); + copts.emplace_back("-I"+sysroot_opt+"/include/eosiolib/native"); + } +#ifndef CPP_COMP + copts.emplace_back("-I"+sysroot_opt+"/include/eosiolib/capi"); +#endif + copts.emplace_back("-I"+sysroot_opt+"/include/eosiolib/core"); + copts.emplace_back("-I"+sysroot_opt+"/include/eosiolib/contracts"); + + ldopts.emplace_back("-L"+sysroot_opt+"/lib"); +#ifndef __APPLE__ + ldopts.emplace_back("-L"+sysroot_opt+"/lib64"); +#endif + } + else { + copts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include/libcxx"); + copts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include/libc"); + copts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include"); + copts.emplace_back("--sysroot="+eosio::cdt::whereami::where()+"/../"); + agopts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include/libcxx"); + agopts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include/libc"); + agopts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include"); + agopts.emplace_back("--sysroot="+eosio::cdt::whereami::where()+"/../"); + ldopts.emplace_back("-L"+eosio::cdt::whereami::where()+"/../lib"); + + if (fnative_opt) { + copts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include/eosiolib/capi"); + copts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include/eosiolib/native"); + } +#ifndef CPP_COMP + copts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include/eosiolib/capi"); +#endif + copts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include/eosiolib/core"); + copts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include/eosiolib/contracts"); + +#ifndef __APPLE__ + ldopts.emplace_back("-L"+eosio::cdt::whereami::where()+"/../lib64"); +#endif + } if (O_opt.empty() && !g_opt) { copts.emplace_back("-O3"); } From f78eb472782b63ed309153e1198753ddb21b2ab9 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