[PATCH] D135903: [wasm-ld] Add support for calling constructors in reactors.

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 13 12:26:18 PDT 2022


sbc100 added a subscriber: tlively.
sbc100 added a comment.

Aren't reactors supposed to define an `_initialize` function that takes care of this?

Perhaps the idea is to make the reactor model work even for users that don't link against `crt1_reactor.o`?

In that case could we instead create a default `_initialize` function here and avoid the wrappers completely?

e.g.

  if (!isDefined("_initialize")) {
    create_default_initialize();
  }

Obviously this would mean that if a user supplies their own initialize function that they need to take care of calling `__wasm_call_ctors`, but that seems like a pretty reasonable expectation.



================
Comment at: lld/test/wasm/init-fini-no-gc.ll:54
 ; CHECK-NEXT:        Locals:          []
-; CHECK-NEXT:        Body:            100010010B
+; CHECK-NEXT:        Body:            024023010D001000410124010B10010B
 
----------------
These days we can use `llvm-object -d` to disassembly the code here, making the test more readable.  See `lld/test/wasm/tls.s` for example.



================
Comment at: lld/test/wasm/reactor-exports.s:86-89
+# CHECK-NEXT:        Body:            024023010D001000410124010B2000200110010B
 # CHECK-NEXT:      - Index:           9
 # CHECK-NEXT:        Locals:          []
+# CHECK-NEXT:        Body:            024023010D001000410124010B2000200110020B
----------------
Ditto, we can use disassembly here now.


================
Comment at: lld/wasm/Symbols.h:539
+  // Symbol whose value is non-zero if the global ctors have been called.
+  static GlobalSymbol *ctorsDone;
+
----------------
This could be tricky because wasm globals are non-shared and therefore thread local.  

@tlively solved this problem for data segment initialization by using a word of memory instead.  Search for `initMemoryFlag` to see how it was done in that case.


================
Comment at: lld/wasm/Writer.cpp:1055
+        needCtorsDone = true;
+	break;
+      }
----------------
Odd indentation here?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135903/new/

https://reviews.llvm.org/D135903



More information about the llvm-commits mailing list