This file is indexed.

/usr/share/doc/llvm-3.7-doc/html/SegmentedStacks.html is in llvm-3.7-doc 1:3.7.1-5ubuntu3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Segmented Stacks in LLVM &#8212; LLVM 3.7 documentation</title>
    
    <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '3.7',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true,
        SOURCELINK_SUFFIX: '.txt'
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="TableGen Fundamentals" href="TableGenFundamentals.html" />
    <link rel="prev" title="LLVM Link Time Optimization: Design and Implementation" href="LinkTimeOptimization.html" />
<style type="text/css">
  table.right { float: right; margin-left: 20px; }
  table.right td { border: 1px solid #ccc; }
</style>

  </head>
  <body role="document">
<div class="logo">
  <a href="index.html">
    <img src="_static/logo.png"
         alt="LLVM Logo" width="250" height="88"/></a>
</div>

    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="TableGenFundamentals.html" title="TableGen Fundamentals"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="LinkTimeOptimization.html" title="LLVM Link Time Optimization: Design and Implementation"
             accesskey="P">previous</a> |</li>
  <li><a href="http://llvm.org/">LLVM Home</a>&nbsp;|&nbsp;</li>
  <li><a href="index.html">Documentation</a>&raquo;</li>
 
      </ul>
    </div>


    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <div class="section" id="segmented-stacks-in-llvm">
<h1>Segmented Stacks in LLVM<a class="headerlink" href="#segmented-stacks-in-llvm" title="Permalink to this headline"></a></h1>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#introduction" id="id2">Introduction</a></li>
<li><a class="reference internal" href="#implementation-details" id="id3">Implementation Details</a><ul>
<li><a class="reference internal" href="#allocating-stacklets" id="id4">Allocating Stacklets</a></li>
<li><a class="reference internal" href="#variable-sized-allocas" id="id5">Variable Sized Allocas</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="introduction">
<h2><a class="toc-backref" href="#id2">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline"></a></h2>
<p>Segmented stack allows stack space to be allocated incrementally than as a
monolithic chunk (of some worst case size) at thread initialization. This is
done by allocating stack blocks (henceforth called <em>stacklets</em>) and linking them
into a doubly linked list. The function prologue is responsible for checking if
the current stacklet has enough space for the function to execute; and if not,
call into the libgcc runtime to allocate more stack space. Segmented stacks are
enabled with the <code class="docutils literal"><span class="pre">&quot;split-stack&quot;</span></code> attribute on LLVM functions.</p>
<p>The runtime functionality is <a class="reference external" href="http://gcc.gnu.org/wiki/SplitStacks">already there in libgcc</a>.</p>
</div>
<div class="section" id="implementation-details">
<h2><a class="toc-backref" href="#id3">Implementation Details</a><a class="headerlink" href="#implementation-details" title="Permalink to this headline"></a></h2>
<div class="section" id="allocating-stacklets">
<span id="id1"></span><h3><a class="toc-backref" href="#id4">Allocating Stacklets</a><a class="headerlink" href="#allocating-stacklets" title="Permalink to this headline"></a></h3>
<p>As mentioned above, the function prologue checks if the current stacklet has
enough space. The current approach is to use a slot in the TCB to store the
current stack limit (minus the amount of space needed to allocate a new block) -
this slot&#8217;s offset is again dictated by <code class="docutils literal"><span class="pre">libgcc</span></code>. The generated
assembly looks like this on x86-64:</p>
<div class="highlight-nasm"><div class="highlight"><pre><span></span>  leaq     -8(%rsp), %r10
  cmpq     %fs:112,  %r10
  jg       .LBB0_2

  # More stack space needs to be allocated
  movabsq  $8, %r10   # The amount of space needed
  movabsq  $0, %r11   # The total size of arguments passed on stack
  callq    __morestack
  ret                 # The reason for this extra return is explained below
.LBB0_2:
  # Usual prologue continues here
</pre></div>
</div>
<p>The size of function arguments on the stack needs to be passed to
<code class="docutils literal"><span class="pre">__morestack</span></code> (this function is implemented in <code class="docutils literal"><span class="pre">libgcc</span></code>) since that number
of bytes has to be copied from the previous stacklet to the current one. This is
so that SP (and FP) relative addressing of function arguments work as expected.</p>
<p>The unusual <code class="docutils literal"><span class="pre">ret</span></code> is needed to have the function which made a call to
<code class="docutils literal"><span class="pre">__morestack</span></code> return correctly. <code class="docutils literal"><span class="pre">__morestack</span></code>, instead of returning, calls
into <code class="docutils literal"><span class="pre">.LBB0_2</span></code>. This is possible since both, the size of the <code class="docutils literal"><span class="pre">ret</span></code>
instruction and the PC of call to <code class="docutils literal"><span class="pre">__morestack</span></code> are known. When the function
body returns, control is transferred back to <code class="docutils literal"><span class="pre">__morestack</span></code>. <code class="docutils literal"><span class="pre">__morestack</span></code>
then de-allocates the new stacklet, restores the correct SP value, and does a
second return, which returns control to the correct caller.</p>
</div>
<div class="section" id="variable-sized-allocas">
<h3><a class="toc-backref" href="#id5">Variable Sized Allocas</a><a class="headerlink" href="#variable-sized-allocas" title="Permalink to this headline"></a></h3>
<p>The section on <a class="reference internal" href="#allocating-stacklets">allocating stacklets</a> automatically assumes that every stack
frame will be of fixed size. However, LLVM allows the use of the <code class="docutils literal"><span class="pre">llvm.alloca</span></code>
intrinsic to allocate dynamically sized blocks of memory on the stack. When
faced with such a variable-sized alloca, code is generated to:</p>
<ul class="simple">
<li>Check if the current stacklet has enough space. If yes, just bump the SP, like
in the normal case.</li>
<li>If not, generate a call to <code class="docutils literal"><span class="pre">libgcc</span></code>, which allocates the memory from the
heap.</li>
</ul>
<p>The memory allocated from the heap is linked into a list in the current
stacklet, and freed along with the same. This prevents a memory leak.</p>
</div>
</div>
</div>


          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="TableGenFundamentals.html" title="TableGen Fundamentals"
             >next</a> |</li>
        <li class="right" >
          <a href="LinkTimeOptimization.html" title="LLVM Link Time Optimization: Design and Implementation"
             >previous</a> |</li>
  <li><a href="http://llvm.org/">LLVM Home</a>&nbsp;|&nbsp;</li>
  <li><a href="index.html">Documentation</a>&raquo;</li>
 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2003-2017, LLVM Project.
      Last updated on 2017-09-14.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.6.
    </div>
  </body>
</html>