Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

DAWN-486 ⁃ WASM doesn't call constructor for globally initialized objects #518

Closed
brianjohnson5972 opened this issue Sep 28, 2017 · 5 comments

Comments

@brianjohnson5972
Copy link
Contributor

brianjohnson5972 commented Sep 28, 2017

If the following code is included in wasm and run, it passes, since it appears that objects allocated in global space are just initialized to 0 and doesn't run the ctor.

Found emscripten-core/emscripten#5391, so we may need to get a more recent emscripten.

class test_init
{
public:
   test_init()
   : _0(0)
   , _1(1)
   {
      _2 = 2;
   }

   bool operator==(const test_init& rhs)
   {
      return _0 == rhs._0 && _1 == rhs._1 && _2 == rhs._2;
   }

   int _0;
   int _1;
   int _2;
} init0;

void test_init()
{
   test_init init1;
   test_init init2;
   assert ( init1 == init2, "init1 should equal init2");
   assert ( init1._0 == 0, "expected _0 to be 0");
   assert ( init1._1 == 1, "expected _1 to be 1");
   assert ( init1._2 == 2, "expected _2 to be 2");
   assert ( init0._0 == 0, "expected _0 to be 0");
   assert ( init0._1 == 0, "expected _1 to be 1, but it is 0");
   assert ( init0._2 == 0, "expected _2 to be 2, but it is 0");
   assert ( !(init1 == init0), "init1 should equal init0, but it doesn't");
}
@brianjohnson5972 brianjohnson5972 changed the title Global initialization in WASM WASM doesn't call constructor for globally initialized objects Sep 28, 2017
@blockone-syncclient blockone-syncclient changed the title WASM doesn't call constructor for globally initialized objects DAWN-486 ⁃ WASM doesn't call constructor for globally initialized objects Jan 16, 2018
@blockone-syncclient
Copy link

➤ Corey Lederer commented:

From Bart's comment on old ticket:

FWIW, this is not the job of the Virtual Machine in the c++ spec. It is the job of the compiler tool-chain/runtime library. In compilers compatible with the GNU libc(++) runtimes the linker will produce __CTOR_LIST__ and __DTOR_LIST__ symbols and the runtime entry point (which isn't actually "main") will call those and then call "main".

The runtime dependency in implementing this that way is a working "atexit" function to call the __DTOR_LIST__

We don't actually use EMSCRIPTEN to compile our wasm. That is the glue between WASM and a browser, that provides all of these runtime features. We would need to emulate what they did to support some of these things.

@andriantolie
Copy link
Contributor

@brianjohnson5972 is this issue still relevant?

@brianjohnson5972
Copy link
Contributor Author

@spoonincode What is the state of this issue with our current supported libraries?

@spoonincode
Copy link
Contributor

This should be working with eosio.cdt afaik

@larryk85

@larryk85
Copy link
Contributor

eosio.cdt fixes these issues.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants