Hi, we are trying the emscripten/incoming branch. the wasm-ctor-eval always
returns us "ctor_evaller: not successful". It fails even with the simple
test prog (attachment) using this command:
"emcc -Oz source.cpp -std=c++14 -stdlib=libc++ -s EMTERPRETIFY=1 -s
EMTERPRETIFY_ASYNC=1 --proxy-to-worker --bind -s NO_EXIT_RUNTIME=1 -s
TOTAL_MEMORY=369098752 -s DISABLE_EXCEPTION_CATCHING=0 -s INLINING_LIMIT=1
-s WASM=1 -s DETERMINISTIC=1 -s BINARYEN_TRAP_MODE='js'
the debug output looks like below:
*DEBUG:root:ctor_evaller: 3 ctors, from |__ATINIT__.push({ func: function()
{ __GLOBAL__I_000101() } }, { func: function() {
__GLOBAL__sub_I_source_cpp() } }, { func: function() {
__GLOBAL__sub_I_iostream_cpp() } });*
*DEBUG:root:ctor_evaller (wasm): trying to eval 3 global constructors*
*DEBUG:root:wasm ctor cmd:
['D:/Emscripten/binaryen/master_vs2015_64bit_binaryen\\bin\\wasm-ctor-eval',
'a.out.wasm', '-o', 'a.out.wasm',
'--ctors=__GLOBAL__I_000101,__GLOBAL__sub_I_source_cpp,__GLOBAL__sub_I_iostream_cpp']*
*DEBUG:root:trying to eval __GLOBAL__I_000101*
* ...stopping since could not eval: tried to access a dangerous
(import-initialized) global: global$3*
*DEBUG:root:ctor_evaller: not successful*
is this an unknown issue? or did we miss anything?
Thanks in advance
--
You received this message because you are subscribed to the Google Groups
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
#include <iostream>
#include <memory>
#include <assert.h>
#include <vector>
template <typename _T, typename = typename std::enable_if<std::is_integral<_T>::value>::type>
static inline constexpr _T Max(_T a, _T b)
{
return (a <= b) ? b : a;
}
constexpr size_t _DEFAULT_ALIGNMENT_ = alignof(std::max_align_t);
static inline constexpr bool isPOT(size_t N)
{
return (N != 0) && ((N&~(N - 1)) == N);
}
inline bool is_aligned(void* p, size_t N)
{
assert(isPOT(N));
return ((size_t)p & ~(N - 1)) == (size_t)p;
}
template <size_t _align = alignof(std::max_align_t)>
struct alignment_proxy
{
alignas(_align) char _Buf[1];
};
using alignment_proxy_t = alignment_proxy<>;
inline alignment_proxy_t* safe_alloc(size_t InSize)
{
return (alignment_proxy_t*)malloc(InSize);
}
template <typename _Ty, typename = typename std::enable_if<std::is_pointer<_Ty>::value>::type>
inline auto align_cast(void* src) -> _Ty
{
constexpr auto Align = alignof(std::remove_pointer_t<_Ty>);
return (_Ty)(((size_t)src + Align - 1) & ~(Align - 1));
}
template <typename _Ty, size_t _align, _Ty... args>
struct alignas(_align) aligned_array
{
using const_iterator = const _Ty*;
using value_type = _Ty;
_Ty val[sizeof...(args)] = { args... };
inline constexpr size_t size() const { return sizeof...(args); }
const _Ty& operator[] (int index) const { return val[index];}
inline const_iterator begin() const { return &val[0]; }
inline const_iterator end() const { return &val[size()]; }
};
template <typename _Ty, _Ty... args>
auto make() -> aligned_array<_Ty, alignof(_Ty), args...>
{
return aligned_array<_Ty, alignof(_Ty), args...>();
}
template <typename _It, typename _Ty, typename _Pr,
typename = typename std::enable_if< std::is_same<typename std::iterator_traits<_It>::iterator_category, std::random_access_iterator_tag>::value>::type>
auto binarySearch(_It beg, _It end, const _Ty& val, const _Pr& pred) -> _It
{
while (beg != end)
{
auto dist = std::distance(beg, end);
_It cur = beg + (dist >> 1);
if (pred(*cur, val))
{
beg = ++cur;
}
else
{
end = cur;
}
}
return beg;
}
template <typename _It, typename _Ty>
static inline _It binarySearch(_It beg, _It end, const _Ty& val)
{
return binarySearch(beg, end, val, std::less<_Ty>());
}
template <typename _Array>
static inline auto binarySearch(const _Array& arr, const typename _Array::value_type& val)
-> decltype(std::cbegin(arr))
{
return binarySearch(std::cbegin(arr), std::cend(arr), val);
}
template <typename _Array>
static void print(const _Array& arr)
{
for (const auto& v : arr)
std::cout << (int)v << "\t";
std::cout << std::endl;
}
std::vector<int> gIntArray = { 1,2,3,4,5 };
auto gAlignedArray0 = make<char, 1>();
auto gAlignedArray1 = make<unsigned char,1, 2>();
auto gAlignedArray2 = make<short, 1, 2, 3>();
auto gAlignedArray3 = make<unsigned short, 1, 2, 3,4>();
auto gAlignedArray4 = make<int, 1, 2, 3, 4, 5>();
auto gAlignedArray5 = make<unsigned int, 1, 2, 3, 4, 5, 6>();
auto gAlignedArray6 = make<long, 1, 2, 3, 4, 5, 6, 7>();
auto gAlignedArray7 = make<unsigned long, 1, 2, 3, 4, 5, 6, 7, 8>();
auto gAlignedArray8 = make<long long, 1, 2, 3, 4, 5, 6, 7, 8, 9>();
auto gAlignedArray9 = make<unsigned long long, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10>();
int main(int argc, char** argv)
{
{
const auto p = make<short, 1, 2, 3>();
std::cout << p[0] << std::endl << p.size() << std::endl;
}
{
auto p = binarySearch(gIntArray, 5);
if (*p == 5) {
std::cout << *p << std::endl;
}
}
print(gAlignedArray0);
print(gAlignedArray1);
print(gAlignedArray2);
print(gAlignedArray3);
print(gAlignedArray4);
print(gAlignedArray5);
print(gAlignedArray6);
print(gAlignedArray7);
print(gAlignedArray8);
print(gAlignedArray9);
return EXIT_SUCCESS;
}