digitalmars.D.ldc - WebAssembly _start or crt_constructor not get called.
- learnfirst1 (18/18) Aug 10 2018 extern(C) {
- learnfirst1 (2/20) Aug 10 2018 I write wrong, it return 1 not 0 on browser.
- kinke (5/5) Aug 10 2018 I don't know about _start(), but please don't expect
- learnfirst1 (6/11) Aug 10 2018 please take a look at this:
- kinke (5/10) Aug 10 2018 Thx for the link, but I don't see a corresponding file for global
extern(C) { __gshared int counter = 1; pragma(crt_constructor) void ginit(){ counter++; } int getCounter(){ return counter; } void _start() { counter++; } } ---------------------- build with ldc2 -mtriple=wasm32-unknown-unknown-wasm -betterC test.d -link-internally I expect the getCounter return 3, but it return 0, is this a bug ?
Aug 10 2018
On Friday, 10 August 2018 at 08:45:07 UTC, learnfirst1 wrote:extern(C) { __gshared int counter = 1; pragma(crt_constructor) void ginit(){ counter++; } int getCounter(){ return counter; } void _start() { counter++; } } ---------------------- build with ldc2 -mtriple=wasm32-unknown-unknown-wasm -betterC test.d -link-internally I expect the getCounter return 3, but it return 0, is this a bug ?I write wrong, it return 1 not 0 on browser.
Aug 10 2018
I don't know about _start(), but please don't expect `pragma(crt_constructor)` to work. As the name says, these 'C runtime constructors' are normally invoked by the C runtime entry point, before calling the C main, all of which doesn't apply to WebAssembly or any other bare metal target.
Aug 10 2018
On Friday, 10 August 2018 at 10:43:09 UTC, kinke wrote:I don't know about _start(), but please don't expect `pragma(crt_constructor)` to work. As the name says, these 'C runtime constructors' are normally invoked by the C runtime entry point, before calling the C main, all of which doesn't apply to WebAssembly or any other bare metal target.please take a look at this: http://llvm.org/doxygen/WebAssemblyLowerGlobalDtors_8cpp_source.html Since LLVM can support WebAssembly GlobalCtors, LDC also append crt_constructor into llvm::GlobalCtors, why not make ldc with WebAssembly work same way.
Aug 10 2018
On Friday, 10 August 2018 at 11:22:39 UTC, learnfirst1 wrote:please take a look at this: http://llvm.org/doxygen/WebAssemblyLowerGlobalDtors_8cpp_source.html Since LLVM can support WebAssembly GlobalCtors, LDC also append crt_constructor into llvm::GlobalCtors, why not make ldc with WebAssembly work same way.Thx for the link, but I don't see a corresponding file for global *con*structors. LDC emits them into `llvm.global_{ctor,dtor}s` (see https://run.dlang.io/is/q8TIBU and hit the `IR` button), so I guess the lowering already works for `pragma(crt_destructor)`.
Aug 10 2018