<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:285507027;
        mso-list-type:hybrid;
        mso-list-template-ids:-1275453428 -1 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l0:level1
        {mso-level-start-at:2;
        mso-level-number-format:bullet;
        mso-level-text:-;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:20.65pt;
        text-indent:-.25in;
        font-family:"Calibri",sans-serif;
        mso-fareast-font-family:"Times New Roman";}
@list l0:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:56.65pt;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l0:level3
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:92.65pt;
        text-indent:-.25in;
        font-family:Wingdings;}
@list l0:level4
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:128.65pt;
        text-indent:-.25in;
        font-family:Symbol;}
@list l0:level5
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:164.65pt;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l0:level6
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:200.65pt;
        text-indent:-.25in;
        font-family:Wingdings;}
@list l0:level7
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:236.65pt;
        text-indent:-.25in;
        font-family:Symbol;}
@list l0:level8
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:272.65pt;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l0:level9
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:308.65pt;
        text-indent:-.25in;
        font-family:Wingdings;}
@list l1
        {mso-list-id:1148284151;
        mso-list-type:hybrid;
        mso-list-template-ids:481740550 -1 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l1:level1
        {mso-level-start-at:0;
        mso-level-number-format:bullet;
        mso-level-text:-;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:20.65pt;
        text-indent:-.25in;
        font-family:"Calibri",sans-serif;
        mso-fareast-font-family:"Times New Roman";}
@list l1:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:56.65pt;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l1:level3
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:92.65pt;
        text-indent:-.25in;
        font-family:Wingdings;}
@list l1:level4
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:128.65pt;
        text-indent:-.25in;
        font-family:Symbol;}
@list l1:level5
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:164.65pt;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l1:level6
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:200.65pt;
        text-indent:-.25in;
        font-family:Wingdings;}
@list l1:level7
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:236.65pt;
        text-indent:-.25in;
        font-family:Symbol;}
@list l1:level8
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:272.65pt;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l1:level9
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:308.65pt;
        text-indent:-.25in;
        font-family:Wingdings;}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
--></style>
</head>
<body lang="EN-US" link="blue" vlink="#954F72">
<div class="WordSection1">
<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"><o:p> </o:p></p>
<p class="MsoNormal">Thomas Lively wrote via llvm-dev on Wed Oct 16 17:33:54 PDT 2019</p>
<p class="MsoNormal"><o:p> </o:p></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"><o:p> </o:p></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"><o:p> </o:p></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"><o:p> </o:p></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">https://github.com/webassembly/binaryen</a>.</p>
<p class="MsoNormal"><o:p> </o:p></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"><o:p> </o:p></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"><o:p> </o:p></p>
<p class="MsoNormal">Thanks,</p>
<p class="MsoNormal"><o:p> </o:p></p>
<ul style="margin-top:0in" type="disc">
<li class="MsoListParagraph" style="margin-left:-15.35pt;mso-list:l1 level1 lfo2">
Bill</li></ul>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Sent from <a href="https://go.microsoft.com/fwlink/?LinkId=550986">
Mail</a> for Windows 10</p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="mso-element:para-border-div;border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="border:none;padding:0in"><b>From: </b><a href="mailto:billti@hotmail.com">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">llvm-dev@lists.llvm.org</a><br>
<b>Subject: </b>Wasm, start function, and default globals</p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Apologies if there is a better forum for these questions. Please redirect me if so.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></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.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></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">https://webassembly.github.io/spec/core/binary/modules.html#start-section</a>)<o:p></o:p></p>
<p class="MsoNormal">2) How to avoid the defaulted __heap_base global.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></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?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></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).<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">(global (;0;) (mut i32) (i32.const 66560))<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Per <a href="https://dassur.ma/things/c-to-webassembly/">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?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<ul style="margin-top:0in" type="disc">
<li class="MsoListParagraph" style="margin-left:-15.35pt;mso-list:l0 level1 lfo1">
Bill<o:p></o:p></li></ul>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Sent from <a href="https://go.microsoft.com/fwlink/?LinkId=550986">
Mail</a> for Windows 10<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>