<div dir="ltr">> Is the Binaryen or Emscripten or Wabt repo the best place to ask even Clang/LLVM questions when it comes to Wasm? <div><br></div><div>The Emscripten repo is a nice catch-all for asking cross-cutting questions, including wasm-specific Clang/LLVM questions. This list is of course fine for LLVM questions as well.<div><br></div><div>> However if my global is a type with a non-trivial constructor, the “data” entry for it is just zeroed out, and there is no startup function set to run any initialization.</div><div><br></div><div>It sounds like you're looking for __wasm_call_ctors. I was going to link to its documentation, but it turns out there is none. I'll fix that here: <a href="https://github.com/WebAssembly/tool-conventions/blob/master/Linking.md">https://github.com/WebAssembly/tool-conventions/blob/master/Linking.md</a>. Anyway, just add that function to the list of functions lld should export and make sure to call it in your runtime. You're not seeing your constructor functions now because they're being garbage collected by lld.</div><div><br></div><div>> Does Binaryen preserve the “names” section? Clang/LLVM is populating that quite nicely, and some of the stuff I’m experimenting with (e.g. profiling) depends on its presence.<br></div><div><br></div><div>Yes, Binaryen can preserve the names section if you pass it -g.</div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 17, 2019 at 12:58 PM Bill Ticehurst via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="EN-US">
<div class="gmail-m_-8188907412763761679WordSection1">
<p class="MsoNormal">[sending this as a new email, as I didn’t get responses to my prior posting via email – I just saw them on the archive]</p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Thomas Lively wrote via llvm-dev on Wed Oct 16 17:33:54 PDT 2019</p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">> The start function is not meant for general use, but rather for toolchains</p>
<p class="MsoNormal">> to initialize the state of the runtime where they can guarantee that no</p>
<p class="MsoNormal">> imports will be required.</p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">But I am trying to write a simple toolchain, hence trying to use it to initialize my globals (or at least the one global I use for my memory allocator).
</p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Interestingly, if I have a global of a type with a simple constructor (e.g. just setting members to integral values), I can see it doesn’t call the constructor, but just inlines the resulting memory values. For example, if setting the first
 member to 0xCCCC I see “(data (;0;) (i32.const 1024) "\cc\cc\00\00\etc..” in the WAT. However if my global is a type with a non-trivial constructor, the “data” entry for it is just zeroed out, and there is no startup function set to run any initialization.
 (Which seems like a bug – or at least a compiler warning should indicate globals will not be initialized as expected).</p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">If this is something that SHOULD be added, happy to take a crack at it if someone more experience in this area can provide a little guidance when needed.</p>
<p class="MsoNormal"></p>
<p class="MsoNormal">> For getting rid of unused globals and generally optimizing your wasm</p>
<p class="MsoNormal">> modules, I highly recommend using Binaryen's wasm-opt tool.</p>
<p class="MsoNormal">> <a href="https://github.com/webassembly/binaryen" target="_blank">https://github.com/webassembly/binaryen</a>.</p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Yeah, just trying minimize the toolchain right now. Does Binaryen preserve the “names” section? Clang/LLVM is populating that quite nicely, and some of the stuff I’m experimenting with (e.g. profiling) depends on its presence.</p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Is the Binaryen or Emscripten or Wabt repo the best place to ask even Clang/LLVM questions when it comes to Wasm? Seems most of the contributors are active on those projects. (As the GitHub UX is better than this mailing list).</p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Thanks,</p>
<p class="MsoNormal"><u></u> <u></u></p>
<ul style="margin-top:0in" type="disc">
<li class="gmail-m_-8188907412763761679MsoListParagraph">
Bill</li></ul>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Sent from <a href="https://go.microsoft.com/fwlink/?LinkId=550986" target="_blank">
Mail</a> for Windows 10</p>
<p class="MsoNormal"><u></u> <u></u></p>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 0in 0in">
<p class="MsoNormal" style="border:none;padding:0in"><b>From: </b><a href="mailto:billti@hotmail.com" target="_blank">Bill Ticehurst</a><br>
<b>Sent: </b>Tuesday, October 15, 2019 4:50 PM<br>
<b>To: </b><a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<b>Subject: </b>Wasm, start function, and default globals</p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Apologies if there is a better forum for these questions. Please redirect me if so.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I’ve been using the clang/wasm-ld tools to experiment with some basic examples, and there’s a couple things I’m wrestling with.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">1) How to denote a function as the “start” function (<a href="https://webassembly.github.io/spec/core/binary/modules.html#start-section" target="_blank">https://webassembly.github.io/spec/core/binary/modules.html#start-section</a>)<u></u><u></u></p>
<p class="MsoNormal">2) How to avoid the defaulted __heap_base global.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I’ve dug around on the samples, mailing lists, and in the wasm-ld code for an attribute or flag to specify the start function, but don’t see anything. Is this just not implemented (or tracked) yet?<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">For 2), I always see the below global in the compiled output even with the most trivial code that makes no reference to it (e.g. compiling just a simple function that only references values on the implicit operand stack).<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">(global (;0;) (mut i32) (i32.const 66560))<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Per <a href="https://dassur.ma/things/c-to-webassembly/" target="_blank">https://dassur.ma/things/c-to-webassembly/</a>, looks like this is the __heap_base value implicitly provided for modeling the stack/heap as are usually present in most C/C++ environments,
 even though unused in my compiled output. Is this something that could/should be optimized away, but again just isn’t implemented yet? Any way to suppress this building with the current clang/wasm-ld toolchain?<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Thanks,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<ul style="margin-top:0in" type="disc">
<li class="gmail-m_-8188907412763761679MsoListParagraph">
Bill<u></u><u></u></li></ul>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Sent from <a href="https://go.microsoft.com/fwlink/?LinkId=550986" target="_blank">
Mail</a> for Windows 10<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>

_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>