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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>How to build Windows Itanium applications. — LLVM 13 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script 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="How to Cross Compile Compiler-rt Builtins For Arm" href="HowToCrossCompileBuiltinsOnArm.html" />
<link rel="prev" title="How To Build Clang and LLVM with Profile-Guided Optimizations" href="HowToBuildWithPGO.html" />
<style type="text/css">
table.right { float: right; margin-left: 20px; }
table.right td { border: 1px solid #ccc; }
</style>
</head><body>
<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="HowToCrossCompileBuiltinsOnArm.html" title="How to Cross Compile Compiler-rt Builtins For Arm"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="HowToBuildWithPGO.html" title="How To Build Clang and LLVM with Profile-Guided Optimizations"
accesskey="P">previous</a> |</li>
<li><a href="https://llvm.org/">LLVM Home</a> | </li>
<li><a href="index.html">Documentation</a>»</li>
<li class="nav-item nav-item-1"><a href="UserGuides.html" accesskey="U">User Guides</a> »</li>
<li class="nav-item nav-item-this"><a href="">How to build Windows Itanium applications.</a></li>
</ul>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3>Documentation</h3>
<ul class="want-points">
<li><a href="https://llvm.org/docs/GettingStartedTutorials.html">Getting Started/Tutorials</a></li>
<li><a href="https://llvm.org/docs/UserGuides.html">User Guides</a></li>
<li><a href="https://llvm.org/docs/Reference.html">Reference</a></li>
</ul>
<h3>Getting Involved</h3>
<ul class="want-points">
<li><a href="https://llvm.org/docs/Contributing.html">Contributing to LLVM</a></li>
<li><a href="https://llvm.org/docs/HowToSubmitABug.html">Submitting Bug Reports</a></li>
<li><a href="https://llvm.org/docs/GettingInvolved.html#mailing-lists">Mailing Lists</a></li>
<li><a href="https://llvm.org/docs/GettingInvolved.html#irc">IRC</a></li>
<li><a href="https://llvm.org/docs/GettingInvolved.html#meetups-and-social-events">Meetups and Social Events</a></li>
</ul>
<h3>Additional Links</h3>
<ul class="want-points">
<li><a href="https://llvm.org/docs/FAQ.html">FAQ</a></li>
<li><a href="https://llvm.org/docs/Lexicon.html">Glossary</a></li>
<li><a href="https://llvm.org/pubs">Publications</a></li>
<li><a href="https://github.com/llvm/llvm-project//">Github Repository</a></li>
</ul>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/HowToBuildWindowsItaniumPrograms.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="how-to-build-windows-itanium-applications">
<h1>How to build Windows Itanium applications.<a class="headerlink" href="#how-to-build-windows-itanium-applications" title="Permalink to this headline">¶</a></h1>
<div class="section" id="introduction">
<h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
<p>This document contains information describing how to create a Windows Itanium toolchain.</p>
<p>Windows Itanium allows you to deploy Itanium C++ ABI applications on top of the MS VS CRT.
This environment can use the Windows SDK headers directly and does not required additional
headers or additional runtime machinery (such as is used by mingw).</p>
<p>Windows Itanium Stack:</p>
<ul class="simple">
<li><p>Uses the Itanium C++ abi.</p></li>
<li><p>libc++.</p></li>
<li><p>libc++-abi.</p></li>
<li><p>libunwind.</p></li>
<li><p>The MS VS CRT.</p></li>
<li><p>Is compatible with MS Windows SDK include headers.</p></li>
<li><p>COFF/PE file format.</p></li>
<li><p>LLD</p></li>
</ul>
<p>Note: compiler-rt is not used. This functionality is supplied by the MS VCRT.</p>
</div>
<div class="section" id="prerequisites">
<h2>Prerequisites<a class="headerlink" href="#prerequisites" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li><p>The MS SDK is installed as part of MS Visual Studio.</p></li>
<li><p>Clang with support for the windows-itanium triple.</p></li>
<li><p>COFF LLD with support for the -autoimport switch.</p></li>
</ul>
</div>
<div class="section" id="known-issues">
<h2>Known issues:<a class="headerlink" href="#known-issues" title="Permalink to this headline">¶</a></h2>
<p>SJLJ exceptions, “-fsjlj-exceptions”, are the only currently supported model.</p>
<p>link.exe (the MS linker) is unsuitable as it doesn’t support auto-importing which
is currently required to link correctly. However, if that limitation is removed
then there are no other known issues with using link.exe.</p>
<p>Currently, there is a lack of a usable Windows compiler driver for Windows Itanium.
A reasonable work-around is to build clang with a windows-msvc default target and
then override the triple with e.g. “-Xclang -triple -Xclang x86_64-unknown-windows-itanium”.
The linker can be specified with: “-fuse-ld=lld”.</p>
<p>In the Itanium C++ ABI the first member of an object is a pointer to the vtable
for its class. The vtable is often emitted into the object file with the key function
and must be imported for classes marked dllimport. The pointers must be globally
unique. Unfortunately, the COFF/PE file format does not provide a mechanism to
store a runtime address from another DLL into this pointer (although runtime
addresses are patched into the IAT). Therefore, the compiler must emit some code,
that runs after IAT patching but before anything that might use the vtable pointers,
and sets the vtable pointer to the address from the IAT. For the special case of
the references to vtables for __cxxabiv1::__class_type_info from typeinto objects
there is no declaration available to the compiler so this can’t be done. To allow
programs to link we currently rely on the -auto-import switch in LLD to auto-import
references to __cxxabiv1::__class_type_info pointers (see: <a class="reference external" href="https://reviews.llvm.org/D43184">https://reviews.llvm.org/D43184</a>
for a related discussion). This allows for linking; but, code that actually uses
such fields will not work as they these will not be fixed up at runtime. See
_pei386_runtime_relocator which handles the runtime component of the autoimporting
scheme used for mingw and comments in <a class="reference external" href="https://reviews.llvm.org/D43184">https://reviews.llvm.org/D43184</a> and
<a class="reference external" href="https://reviews.llvm.org/D89518">https://reviews.llvm.org/D89518</a> for more.</p>
</div>
<div class="section" id="assembling-a-toolchain">
<h2>Assembling a Toolchain:<a class="headerlink" href="#assembling-a-toolchain" title="Permalink to this headline">¶</a></h2>
<p>The procedure is:</p>
<p># Build an LLVM toolchain with support for Windows Itanium.
# Use the toolchain from step 1. to build libc++, libc++abi, and libunwind.</p>
<p>It is also possible to cross-compile from Linux.</p>
<p>One method of building the libraries in step 2. is to build them “stand-alone”.
A stand-alone build doesn’t involve the rest of the LLVM tree. The steps are:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">cd</span> <span class="pre">build-dir</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">cmake</span> <span class="pre">-DLLVM_PATH=<path</span> <span class="pre">to</span> <span class="pre">llvm</span> <span class="pre">checkout</span> <span class="pre">e.g.</span> <span class="pre">/llvm-project/></span> <span class="pre">-DCMAKE_INSTALL_PREFIX=<install</span> <span class="pre">path></span> <span class="pre"><other</span> <span class="pre">options></span> <span class="pre"><path</span> <span class="pre">to</span> <span class="pre">project</span> <span class="pre">e.g.</span> <span class="pre">/llvm-project/libcxxabi></span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre"><make</span> <span class="pre">program</span> <span class="pre">e.g.</span> <span class="pre">ninja></span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre"><make</span> <span class="pre">program></span> <span class="pre">install</span></code></p></li>
</ul>
<p>More information on standalone builds can be found in the build documentation for
the respective libraries. The next section discuss the salient options and modifications
required for building and installing the libraries using standalone builds. This assumes
that we are building libunwind and ibc++ as DLLs and statically linking libc++abi into
libc++. Other build configurations are possible, but they are not discussed here.</p>
<div class="section" id="common-cmake-configuration-options">
<h3>Common CMake configuration options:<a class="headerlink" href="#common-cmake-configuration-options" title="Permalink to this headline">¶</a></h3>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">-D_LIBCPP_ABI_FORCE_ITANIUM'</span></code></p></li>
</ul>
<p>Tell the libc++ headers that the Itanium C++ ABI is being used.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">-DCMAKE_C_FLAGS="-lmsvcrt</span> <span class="pre">-llegacy_stdio_definitions</span> <span class="pre">-D_NO_CRT_STDIO_INLINE"</span></code></p></li>
</ul>
<p>Supply CRT definitions including stdio definitions that have been removed from the MS VS CRT.
We don’t want the stdio functions declared inline as they will cause multiple definition
errors when the same symbols are pulled in from legacy_stdio_definitions.ib.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">-DCMAKE_INSTALL_PREFIX=<install</span> <span class="pre">path></span></code></p></li>
</ul>
<p>Where to install the library and headers.</p>
</div>
<div class="section" id="building-libunwind">
<h3>Building libunwind:<a class="headerlink" href="#building-libunwind" title="Permalink to this headline">¶</a></h3>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">-DLIBUNWIND_ENABLE_SHARED=ON</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">-DLIBUNWIND_ENABLE_STATIC=OFF</span></code></p></li>
</ul>
<p>libunwind can be built as a DLL. It is not dependent on other projects.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">-DLIBUNWIND_USE_COMPILER_RT=OFF</span></code></p></li>
</ul>
<p>We use the MS runtime.</p>
<p>The CMake files will need to be edited to prevent them adding GNU specific libraries to the link line.</p>
</div>
<div class="section" id="building-libc-abi">
<h3>Building libc++abi:<a class="headerlink" href="#building-libc-abi" title="Permalink to this headline">¶</a></h3>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">-DLIBCXXABI_ENABLE_SHARED=OFF</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">-DLIBCXXABI_ENABLE_STATIC=ON</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">-DLIBCXX_ENABLE_SHARED=ON'</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON</span></code></p></li>
</ul>
<p>To break the symbol dependency between libc++abi and libc++ we
build libc++abi as a static library and then statically link it
into the libc++ DLL. This necessitates setting the CMake file
to ensure that the visibility macros (which expand to dllexport/import)
are expanded as they will be needed when creating the final libc++
DLL later, see: <a class="reference external" href="https://reviews.llvm.org/D90021">https://reviews.llvm.org/D90021</a>.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">-DLIBCXXABI_LIBCXX_INCLUDES=<path</span> <span class="pre">to</span> <span class="pre">libcxx>/include</span></code></p></li>
</ul>
<p>Where to find the libc++ headers</p>
</div>
<div class="section" id="building-libc">
<h3>Building libc++:<a class="headerlink" href="#building-libc" title="Permalink to this headline">¶</a></h3>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">-DLIBCXX_ENABLE_SHARED=ON</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">-DLIBCXX_ENABLE_STATIC=OFF</span></code></p></li>
</ul>
<p>We build libc++ as a DLL and statically link libc++abi into it.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">-DLIBCXX_INSTALL_HEADERS=ON</span></code></p></li>
</ul>
<p>Install the headers.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">-DLIBCXX_USE_COMPILER_RT=OFF</span></code></p></li>
</ul>
<p>We use the MS runtime.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">-DLIBCXX_HAS_WIN32_THREAD_API=ON</span></code></p></li>
</ul>
<p>Windows Itanium does not offer a POSIX-like layer over WIN32.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">-DLIBCXX_CXX_ABI=libcxxabi</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">-DLIBCXX_CXX_ABI_INCLUDE_PATHS=<libcxxabi</span> <span class="pre">src</span> <span class="pre">path>/include</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">-DLIBCXX_CXX_ABI_LIBRARY_PATH=<libcxxabi</span> <span class="pre">build</span> <span class="pre">path>/lib</span></code></p></li>
</ul>
<p>Use the static libc++abi library built earlier.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">-DLIBCXX_NO_VCRUNTIME=ON</span></code></p></li>
</ul>
<p>Remove any dependency on the VC runtime - we need libc++abi to supply the C++ runtime.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">-DCMAKE_C_FLAGS=<path</span> <span class="pre">to</span> <span class="pre">installed</span> <span class="pre">unwind.lib></span></code></p></li>
</ul>
<p>As we are statically linking against libcxxabi we need to link
against the unwind import library to resolve unwind references
from the libcxxabi objects.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">-DCMAKE_C_FLAGS+='</span> <span class="pre">-UCLOCK_REALTIME'</span></code></p></li>
</ul>
<p>Prevent the inclusion of sys/time that MS doesn’t provide.</p>
</div>
<div class="section" id="notes">
<h3>Notes:<a class="headerlink" href="#notes" title="Permalink to this headline">¶</a></h3>
<p>An example build recipe is available here: <a class="reference external" href="https://reviews.llvm.org/D88124">https://reviews.llvm.org/D88124</a></p>
</div>
</div>
</div>
<div class="clearer"></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="HowToCrossCompileBuiltinsOnArm.html" title="How to Cross Compile Compiler-rt Builtins For Arm"
>next</a> |</li>
<li class="right" >
<a href="HowToBuildWithPGO.html" title="How To Build Clang and LLVM with Profile-Guided Optimizations"
>previous</a> |</li>
<li><a href="https://llvm.org/">LLVM Home</a> | </li>
<li><a href="index.html">Documentation</a>»</li>
<li class="nav-item nav-item-1"><a href="UserGuides.html" >User Guides</a> »</li>
<li class="nav-item nav-item-this"><a href="">How to build Windows Itanium applications.</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2003-2021, LLVM Project.
Last updated on 2021-09-18.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.5.4.
</div>
</body>
</html>
|