Static ctors in wasm

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Fri Feb 16 05:43:08 UTC 2024


On 16/02/2024 6:02 PM, Richard (Rikki) Andrew Cattermole wrote:
> Great!
> 
> Unfortunately I don't know how the lists created by the linker work.
> 
> But I do know that they are linker specific.

I did some searching.

``__start_section`` and ``__stop_section`` are generated by the linker 
automatically for a given section.

https://stackoverflow.com/a/48550485

I have been able to replicate what it should be doing using run.dlang.io.

```d
import std;
import core.attribute;

void main()
{
     writeln([var1, var2, var3], __start_sect_test, __stop_sect_test);
}

__gshared extern(C) extern {
     immutable int* __start_sect_test;
     immutable int* __stop_sect_test;
}

__gshared {
     @(ldc.attributes.section("sect_test"))
     int var1 = 72;
     @(ldc.attributes.section("sect_test"))
     int var2 = 43;
     @(ldc.attributes.section("sect_test"))
     int var3 = 59;
}
```

Now you'll have something to compare the ``__minfo`` symbols to.

One thing to check is that your triple is for the binary wasm otherwise 
it might not be using sections.

https://github.com/ldc-developers/ldc/blob/6ede9a4fdfd04724fc28a60e6460993d8344136f/gen/modules.cpp#L105


More information about the Digitalmars-d mailing list