blob: 93b4c06ae2856637d2cbf0778c66193698df255d [file] [log] [blame] [edit]
<!DOCTYPE HTML>
<html lang="en" class="light sidebar-visible" dir="ltr">
<head>
<!-- Book generated using mdBook -->
<meta charset="UTF-8">
<title>GCC codegen backend - Rust Compiler Development Guide</title>
<!-- Custom HTML head -->
<meta name="description" content="A guide to developing the Rust compiler (rustc)">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#ffffff">
<link rel="icon" href="../../favicon.svg">
<link rel="shortcut icon" href="../../favicon.png">
<link rel="stylesheet" href="../../css/variables.css">
<link rel="stylesheet" href="../../css/general.css">
<link rel="stylesheet" href="../../css/chrome.css">
<link rel="stylesheet" href="../../css/print.css" media="print">
<!-- Fonts -->
<link rel="stylesheet" href="../../FontAwesome/css/font-awesome.css">
<link rel="stylesheet" href="../../fonts/fonts.css">
<!-- Highlight.js Stylesheets -->
<link rel="stylesheet" id="highlight-css" href="../../highlight.css">
<link rel="stylesheet" id="tomorrow-night-css" href="../../tomorrow-night.css">
<link rel="stylesheet" id="ayu-highlight-css" href="../../ayu-highlight.css">
<!-- Custom theme stylesheets -->
<link rel="stylesheet" href="../../pagetoc.css">
<!-- Provide site root and default themes to javascript -->
<script>
const path_to_root = "../../";
const default_light_theme = "light";
const default_dark_theme = "navy";
window.path_to_searchindex_js = "../../searchindex.js";
</script>
<!-- Start loading toc.js asap -->
<script src="../../toc.js"></script>
</head>
<body>
<div id="mdbook-help-container">
<div id="mdbook-help-popup">
<h2 class="mdbook-help-title">Keyboard shortcuts</h2>
<div>
<p>Press <kbd></kbd> or <kbd></kbd> to navigate between chapters</p>
<p>Press <kbd>S</kbd> or <kbd>/</kbd> to search in the book</p>
<p>Press <kbd>?</kbd> to show this help</p>
<p>Press <kbd>Esc</kbd> to hide this help</p>
</div>
</div>
</div>
<div id="body-container">
<!-- Work around some values being stored in localStorage wrapped in quotes -->
<script>
try {
let theme = localStorage.getItem('mdbook-theme');
let sidebar = localStorage.getItem('mdbook-sidebar');
if (theme.startsWith('"') && theme.endsWith('"')) {
localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
}
if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
}
} catch (e) { }
</script>
<!-- Set the theme before any content is loaded, prevents flash -->
<script>
const default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? default_dark_theme : default_light_theme;
let theme;
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
if (theme === null || theme === undefined) { theme = default_theme; }
const html = document.documentElement;
html.classList.remove('light')
html.classList.add(theme);
html.classList.add("js");
</script>
<input type="checkbox" id="sidebar-toggle-anchor" class="hidden">
<!-- Hide / unhide sidebar before it is displayed -->
<script>
let sidebar = null;
const sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
if (document.body.clientWidth >= 1080) {
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
sidebar = sidebar || 'visible';
} else {
sidebar = 'hidden';
sidebar_toggle.checked = false;
}
if (sidebar === 'visible') {
sidebar_toggle.checked = true;
} else {
html.classList.remove('sidebar-visible');
}
</script>
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
<!-- populated by js -->
<mdbook-sidebar-scrollbox class="sidebar-scrollbox"></mdbook-sidebar-scrollbox>
<noscript>
<iframe class="sidebar-iframe-outer" src="../../toc.html"></iframe>
</noscript>
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
<div class="sidebar-resize-indicator"></div>
</div>
</nav>
<div id="page-wrapper" class="page-wrapper">
<div class="page">
<div id="menu-bar-hover-placeholder"></div>
<div id="menu-bar" class="menu-bar sticky">
<div class="left-buttons">
<label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
<i class="fa fa-bars"></i>
</label>
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
<i class="fa fa-paint-brush"></i>
</button>
<ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
<li role="none"><button role="menuitem" class="theme" id="default_theme">Auto</button></li>
<li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
<li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
<li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
<li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
<li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
</ul>
<button id="search-toggle" class="icon-button" type="button" title="Search (`/`)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="/ s" aria-controls="searchbar">
<i class="fa fa-search"></i>
</button>
</div>
<h1 class="menu-title">Rust Compiler Development Guide</h1>
<div class="right-buttons">
<a href="../../print.html" title="Print this book" aria-label="Print this book">
<i id="print-button" class="fa fa-print"></i>
</a>
<a href="https://github.com/rust-lang/rustc-dev-guide" title="Git repository" aria-label="Git repository">
<i id="git-repository-button" class="fa fa-github"></i>
</a>
<a href="https://github.com/rust-lang/rustc-dev-guide/edit/main/src/tests/codegen-backend-tests/cg_gcc.md" title="Suggest an edit" aria-label="Suggest an edit" rel="edit">
<i id="git-edit-button" class="fa fa-edit"></i>
</a>
</div>
</div>
<div id="search-wrapper" class="hidden">
<form id="searchbar-outer" class="searchbar-outer">
<div class="search-wrapper">
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
<div class="spinner-wrapper">
<i class="fa fa-spinner fa-spin"></i>
</div>
</div>
</form>
<div id="searchresults-outer" class="searchresults-outer hidden">
<div id="searchresults-header" class="searchresults-header"></div>
<ul id="searchresults">
</ul>
</div>
</div>
<!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
<script>
document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
});
</script>
<div id="content" class="content">
<main>
<h1 id="gcc-codegen-backend"><a class="header" href="#gcc-codegen-backend">GCC codegen backend</a></h1>
<p>We run a subset of the compiler test suite with the GCC codegen backend on our CI, to help find changes that could break the integration of this backend with the compiler.</p>
<p>If you encounter any bugs or problems with the GCC codegen backend in general, don't hesitate to open issues on the
<a href="https://github.com/rust-lang/rustc_codegen_gcc"><code>rustc_codegen_gcc</code> repository</a>.</p>
<p>Note that the backend currently only supports the <code>x86_64-unknown-linux-gnu</code> target.</p>
<h2 id="running-into-gcc-backend-ci-errors"><a class="header" href="#running-into-gcc-backend-ci-errors">Running into GCC backend CI errors</a></h2>
<p>If you ran into an error related to tests executed with the GCC codegen backend on CI in the <code>x86_64-gnu-gcc</code> job,
you can use the following command to run UI tests locally using the GCC backend, which reproduces what happens on CI:</p>
<pre><code class="language-bash">./x test tests/ui \
--set 'rust.codegen-backends = ["llvm", "gcc"]' \
--set 'rust.debug-assertions = false' \
--test-codegen-backend gcc
</code></pre>
<p>If a different test suite has failed on CI, you will have to modify the <code>tests/ui</code> part.</p>
<p>To reproduce the whole CI job locally, you can run <code>cargo run --manifest-path src/ci/citool/Cargo.toml run-local x86_64-gnu-gcc</code>.
See <a href="../docker.html">Testing with Docker</a> for more information.</p>
<h3 id="what-to-do-in-case-of-a-gcc-job-failure"><a class="header" href="#what-to-do-in-case-of-a-gcc-job-failure">What to do in case of a GCC job failure?</a></h3>
<p>If the GCC job test fails and it seems like the failure could be caused by the GCC backend, you can ping the <a href="https://github.com/orgs/rust-lang/teams/wg-gcc-backend">cg-gcc working group</a> using <code>@rust-lang/wg-gcc-backend</code></p>
<p>If fixing a compiler test that fails with the GCC backend is non-trivial, you can ignore that test when executed with <code>cg_gcc</code> using the <code>//@ ignore-backends: gcc</code> <a href="../directives.html">compiletest directive</a>.</p>
<h2 id="choosing-which-codegen-backends-are-built"><a class="header" href="#choosing-which-codegen-backends-are-built">Choosing which codegen backends are built</a></h2>
<p>The <code>rust.codegen-backends = [...]</code> bootstrap option affects which codegen backends will be built and
included in the sysroot of the produced <code>rustc</code>.
To use the GCC codegen backend, <code>"gcc"</code> has to be included in this array in <code>bootstrap.toml</code>:</p>
<pre><code class="language-toml">rust.codegen-backends = ["llvm", "gcc"]
</code></pre>
<p>If you don't want to change your <code>bootstrap.toml</code> file, you can alternatively run your <code>x</code>
commands with <code>--set 'rust.codegen-backends=["llvm", "gcc"]'</code>.
For example:</p>
<pre><code class="language-bash">./x build --set 'rust.codegen-backends=["llvm", "gcc"]'
</code></pre>
<p>The first backend in the <code>codegen-backends</code> array will determine which backend will be used as the
<em>default backend</em> of the built <code>rustc</code>.
This also determines which backend will be used to compile the
stage 1 standard library (or anything built in stage 2+).
To produce <code>rustc</code> that uses the GCC backend
by default, you can thus put <code>"gcc"</code> as the first element of this array:</p>
<pre><code class="language-bash">./x build --set 'rust.codegen-backends=["gcc"]' library
</code></pre>
<h2 id="choosing-the-codegen-backend-used-in-tests"><a class="header" href="#choosing-the-codegen-backend-used-in-tests">Choosing the codegen backend used in tests</a></h2>
<p>To run compiler tests with the GCC codegen backend being used to build the test Rust programs, you can use the
<code>--test-codegen-backend</code> flag:</p>
<pre><code class="language-bash">./x test tests/ui --test-codegen-backend gcc
</code></pre>
<p>Note that in order for this to work, the tested compiler must have the GCC codegen backend <a href="#choosing-which-codegen-backends-are-built">available</a> in its sysroot directory.</p>
<h2 id="downloading-gcc-from-ci"><a class="header" href="#downloading-gcc-from-ci">Downloading GCC from CI</a></h2>
<p>The <code>gcc.download-ci-gcc</code> bootstrap option controls if GCC (which is a dependency of the GCC codegen backend)
will be downloaded from CI or built locally.
The default value is <code>true</code>, which will download GCC from CI
if there are no local changes to the GCC sources and the given host target is available on CI.</p>
<h2 id="running-tests-of-the-backend-itself"><a class="header" href="#running-tests-of-the-backend-itself">Running tests of the backend itself</a></h2>
<p>In addition to running the compiler's test suites using the GCC codegen backend, you can also run the test suite of the backend itself.</p>
<p>Now you do that using the following command:</p>
<pre><code class="language-text">./x test rustc_codegen_gcc
</code></pre>
<p>The backend needs to be <a href="#choosing-which-codegen-backends-are-built">enabled</a> for this to work.</p>
</main>
<nav class="nav-wrapper" aria-label="Page navigation">
<!-- Mobile navigation buttons -->
<a rel="prev" href="../../tests/codegen-backend-tests/cg_clif.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
<i class="fa fa-angle-left"></i>
</a>
<a rel="next prefetch" href="../../tests/perf.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
<i class="fa fa-angle-right"></i>
</a>
<div style="clear: both"></div>
</nav>
</div>
</div>
<nav class="nav-wide-wrapper" aria-label="Page navigation">
<a rel="prev" href="../../tests/codegen-backend-tests/cg_clif.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
<i class="fa fa-angle-left"></i>
</a>
<a rel="next prefetch" href="../../tests/perf.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
<i class="fa fa-angle-right"></i>
</a>
</nav>
</div>
<script>
window.playground_copyable = true;
</script>
<script src="../../elasticlunr.min.js"></script>
<script src="../../mark.min.js"></script>
<script src="../../searcher.js"></script>
<script src="../../clipboard.min.js"></script>
<script src="../../highlight.js"></script>
<script src="../../book.js"></script>
<!-- Custom JS scripts -->
<script src="../../mermaid.min.js"></script>
<script src="../../mermaid-init.js"></script>
<script src="../../pagetoc.js"></script>
</div>
</body>
</html>