<div dir="ltr">The start function is not meant for general use, but rather for toolchains to initialize the state of the runtime where they can guarantee that no imports will be required.<div><br></div><div>For getting rid of unused globals and generally optimizing your wasm modules, I highly recommend using Binaryen's wasm-opt tool. <a href="https://github.com/webassembly/binaryen">https://github.com/webassembly/binaryen</a>.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 15, 2019 at 6:11 PM Petr Penzin via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">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 bgcolor="#FFFFFF">
<p>There is a good amount of expertise on this in Emscripten
community: <a href="https://github.com/emscripten-core/emscripten" target="_blank">https://github.com/emscripten-core/emscripten</a></p>
<p>You can also try to ask in one of the WebAssembly repos:
<a href="https://github.com/WebAssembly" target="_blank">https://github.com/WebAssembly</a><br>
</p>
<p>I think Luke Imhoff has done some work accessing the start
function, I am not sure if he is on this list. I personally don't
know of a way write to start function. There is a bit on it in
tool conventions:</p>
<p><a href="https://github.com/WebAssembly/tool-conventions/blob/master/Linking.md#start-section" target="_blank">https://github.com/WebAssembly/tool-conventions/blob/master/Linking.md#start-section</a><br>
</p>
<p>The __heap_base symbol is there because Wasm does not have the
memory layout C family languages expect. At higher opt level Clang
is usually pretty good at removing its use.</p>
<p>Best,</p>
<p>Petr<br>
</p>
<div>On 10/15/19 4:50 PM, Bill Ticehurst via
llvm-dev wrote:<br>
</div>
<blockquote type="cite">
<div>
<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>
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</p>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<br>
<fieldset></fieldset>
<pre>_______________________________________________
LLVM Developers mailing list
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
</blockquote>
</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>