You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
163 lines
7.8 KiB
HTML
163 lines
7.8 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<!-- This file documents the GNU linker LD
|
|
(SiFive Binutils 2.32.0-2020.04.1)
|
|
version 2.32.
|
|
|
|
Copyright (C) 1991-2019 Free Software Foundation, Inc.
|
|
|
|
Permission is granted to copy, distribute and/or modify this document
|
|
under the terms of the GNU Free Documentation License, Version 1.3
|
|
or any later version published by the Free Software Foundation;
|
|
with no Invariant Sections, with no Front-Cover Texts, and with no
|
|
Back-Cover Texts. A copy of the license is included in the
|
|
section entitled "GNU Free Documentation License". -->
|
|
<!-- Created by GNU Texinfo 6.4, http://www.gnu.org/software/texinfo/ -->
|
|
<head>
|
|
<title>Output Section Keywords (LD)</title>
|
|
|
|
<meta name="description" content="Output Section Keywords (LD)">
|
|
<meta name="keywords" content="Output Section Keywords (LD)">
|
|
<meta name="resource-type" content="document">
|
|
<meta name="distribution" content="global">
|
|
<meta name="Generator" content="makeinfo">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<link href="index.html#Top" rel="start" title="Top">
|
|
<link href="LD-Index.html#LD-Index" rel="index" title="LD Index">
|
|
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
|
|
<link href="SECTIONS.html#SECTIONS" rel="up" title="SECTIONS">
|
|
<link href="Output-Section-Discarding.html#Output-Section-Discarding" rel="next" title="Output Section Discarding">
|
|
<link href="Output-Section-Data.html#Output-Section-Data" rel="prev" title="Output Section Data">
|
|
<style type="text/css">
|
|
<!--
|
|
a.summary-letter {text-decoration: none}
|
|
blockquote.indentedblock {margin-right: 0em}
|
|
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
|
|
blockquote.smallquotation {font-size: smaller}
|
|
div.display {margin-left: 3.2em}
|
|
div.example {margin-left: 3.2em}
|
|
div.lisp {margin-left: 3.2em}
|
|
div.smalldisplay {margin-left: 3.2em}
|
|
div.smallexample {margin-left: 3.2em}
|
|
div.smalllisp {margin-left: 3.2em}
|
|
kbd {font-style: oblique}
|
|
pre.display {font-family: inherit}
|
|
pre.format {font-family: inherit}
|
|
pre.menu-comment {font-family: serif}
|
|
pre.menu-preformatted {font-family: serif}
|
|
pre.smalldisplay {font-family: inherit; font-size: smaller}
|
|
pre.smallexample {font-size: smaller}
|
|
pre.smallformat {font-family: inherit; font-size: smaller}
|
|
pre.smalllisp {font-size: smaller}
|
|
span.nolinebreak {white-space: nowrap}
|
|
span.roman {font-family: initial; font-weight: normal}
|
|
span.sansserif {font-family: sans-serif; font-weight: normal}
|
|
ul.no-bullet {list-style: none}
|
|
-->
|
|
</style>
|
|
|
|
|
|
</head>
|
|
|
|
<body lang="en">
|
|
<a name="Output-Section-Keywords"></a>
|
|
<div class="header">
|
|
<p>
|
|
Next: <a href="Output-Section-Discarding.html#Output-Section-Discarding" accesskey="n" rel="next">Output Section Discarding</a>, Previous: <a href="Output-Section-Data.html#Output-Section-Data" accesskey="p" rel="prev">Output Section Data</a>, Up: <a href="SECTIONS.html#SECTIONS" accesskey="u" rel="up">SECTIONS</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="LD-Index.html#LD-Index" title="Index" rel="index">Index</a>]</p>
|
|
</div>
|
|
<hr>
|
|
<a name="Output-Section-Keywords-1"></a>
|
|
<h4 class="subsection">3.6.6 Output Section Keywords</h4>
|
|
<p>There are a couple of keywords which can appear as output section
|
|
commands.
|
|
</p>
|
|
<dl compact="compact">
|
|
<dd><a name="index-CREATE_005fOBJECT_005fSYMBOLS"></a>
|
|
<a name="index-input-filename-symbols"></a>
|
|
<a name="index-filename-symbols"></a>
|
|
</dd>
|
|
<dt><code>CREATE_OBJECT_SYMBOLS</code></dt>
|
|
<dd><p>The command tells the linker to create a symbol for each input file.
|
|
The name of each symbol will be the name of the corresponding input
|
|
file. The section of each symbol will be the output section in which
|
|
the <code>CREATE_OBJECT_SYMBOLS</code> command appears.
|
|
</p>
|
|
<p>This is conventional for the a.out object file format. It is not
|
|
normally used for any other object file format.
|
|
</p>
|
|
<a name="index-CONSTRUCTORS"></a>
|
|
<a name="index-C_002b_002b-constructors_002c-arranging-in-link"></a>
|
|
<a name="index-constructors_002c-arranging-in-link"></a>
|
|
</dd>
|
|
<dt><code>CONSTRUCTORS</code></dt>
|
|
<dd><p>When linking using the a.out object file format, the linker uses an
|
|
unusual set construct to support C++ global constructors and
|
|
destructors. When linking object file formats which do not support
|
|
arbitrary sections, such as ECOFF and XCOFF, the linker will
|
|
automatically recognize C++ global constructors and destructors by name.
|
|
For these object file formats, the <code>CONSTRUCTORS</code> command tells the
|
|
linker to place constructor information in the output section where the
|
|
<code>CONSTRUCTORS</code> command appears. The <code>CONSTRUCTORS</code> command is
|
|
ignored for other object file formats.
|
|
</p>
|
|
<p>The symbol <code><span class="nolinebreak">__CTOR_LIST__</span></code><!-- /@w --> marks the start of the global
|
|
constructors, and the symbol <code><span class="nolinebreak">__CTOR_END__</span></code><!-- /@w --> marks the end.
|
|
Similarly, <code><span class="nolinebreak">__DTOR_LIST__</span></code><!-- /@w --> and <code><span class="nolinebreak">__DTOR_END__</span></code><!-- /@w --> mark
|
|
the start and end of the global destructors. The
|
|
first word in the list is the number of entries, followed by the address
|
|
of each constructor or destructor, followed by a zero word. The
|
|
compiler must arrange to actually run the code. For these object file
|
|
formats <small>GNU</small> C++ normally calls constructors from a subroutine
|
|
<code>__main</code>; a call to <code>__main</code> is automatically inserted into
|
|
the startup code for <code>main</code>. <small>GNU</small> C++ normally runs
|
|
destructors either by using <code>atexit</code>, or directly from the function
|
|
<code>exit</code>.
|
|
</p>
|
|
<p>For object file formats such as <code>COFF</code> or <code>ELF</code> which support
|
|
arbitrary section names, <small>GNU</small> C++ will normally arrange to put the
|
|
addresses of global constructors and destructors into the <code>.ctors</code>
|
|
and <code>.dtors</code> sections. Placing the following sequence into your
|
|
linker script will build the sort of table which the <small>GNU</small> C++
|
|
runtime code expects to see.
|
|
</p>
|
|
<div class="smallexample">
|
|
<pre class="smallexample"> __CTOR_LIST__ = .;
|
|
LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
|
|
*(.ctors)
|
|
LONG(0)
|
|
__CTOR_END__ = .;
|
|
__DTOR_LIST__ = .;
|
|
LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
|
|
*(.dtors)
|
|
LONG(0)
|
|
__DTOR_END__ = .;
|
|
</pre></div>
|
|
|
|
<p>If you are using the <small>GNU</small> C++ support for initialization priority,
|
|
which provides some control over the order in which global constructors
|
|
are run, you must sort the constructors at link time to ensure that they
|
|
are executed in the correct order. When using the <code>CONSTRUCTORS</code>
|
|
command, use ‘<samp>SORT_BY_NAME(CONSTRUCTORS)</samp>’ instead. When using the
|
|
<code>.ctors</code> and <code>.dtors</code> sections, use ‘<samp>*(SORT_BY_NAME(.ctors))</samp>’ and
|
|
‘<samp>*(SORT_BY_NAME(.dtors))</samp>’ instead of just ‘<samp>*(.ctors)</samp>’ and
|
|
‘<samp>*(.dtors)</samp>’.
|
|
</p>
|
|
<p>Normally the compiler and linker will handle these issues automatically,
|
|
and you will not need to concern yourself with them. However, you may
|
|
need to consider this if you are using C++ and writing your own linker
|
|
scripts.
|
|
</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
<hr>
|
|
<div class="header">
|
|
<p>
|
|
Next: <a href="Output-Section-Discarding.html#Output-Section-Discarding" accesskey="n" rel="next">Output Section Discarding</a>, Previous: <a href="Output-Section-Data.html#Output-Section-Data" accesskey="p" rel="prev">Output Section Data</a>, Up: <a href="SECTIONS.html#SECTIONS" accesskey="u" rel="up">SECTIONS</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="LD-Index.html#LD-Index" title="Index" rel="index">Index</a>]</p>
|
|
</div>
|
|
|
|
|
|
|
|
</body>
|
|
</html>
|