184 lines
8.4 KiB
HTML
184 lines
8.4 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
|
||
|
(Linaro_Binutils-2017.02)
|
||
|
version 2.27.0.
|
||
|
|
||
|
Copyright (C) 1991-2016 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 5.2, http://www.gnu.org/software/texinfo/ -->
|
||
|
<head>
|
||
|
<title>LD: Input Section Basics</title>
|
||
|
|
||
|
<meta name="description" content="LD: Input Section Basics">
|
||
|
<meta name="keywords" content="LD: Input Section Basics">
|
||
|
<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="Input-Section.html#Input-Section" rel="up" title="Input Section">
|
||
|
<link href="Input-Section-Wildcards.html#Input-Section-Wildcards" rel="next" title="Input Section Wildcards">
|
||
|
<link href="Input-Section.html#Input-Section" rel="prev" title="Input Section">
|
||
|
<style type="text/css">
|
||
|
<!--
|
||
|
a.summary-letter {text-decoration: none}
|
||
|
blockquote.smallquotation {font-size: smaller}
|
||
|
div.display {margin-left: 3.2em}
|
||
|
div.example {margin-left: 3.2em}
|
||
|
div.indentedblock {margin-left: 3.2em}
|
||
|
div.lisp {margin-left: 3.2em}
|
||
|
div.smalldisplay {margin-left: 3.2em}
|
||
|
div.smallexample {margin-left: 3.2em}
|
||
|
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
|
||
|
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.nocodebreak {white-space:nowrap}
|
||
|
span.nolinebreak {white-space:nowrap}
|
||
|
span.roman {font-family:serif; font-weight:normal}
|
||
|
span.sansserif {font-family:sans-serif; font-weight:normal}
|
||
|
ul.no-bullet {list-style: none}
|
||
|
-->
|
||
|
</style>
|
||
|
|
||
|
|
||
|
</head>
|
||
|
|
||
|
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
|
||
|
<a name="Input-Section-Basics"></a>
|
||
|
<div class="header">
|
||
|
<p>
|
||
|
Next: <a href="Input-Section-Wildcards.html#Input-Section-Wildcards" accesskey="n" rel="next">Input Section Wildcards</a>, Up: <a href="Input-Section.html#Input-Section" accesskey="u" rel="up">Input Section</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="Input-Section-Basics-1"></a>
|
||
|
<h4 class="subsubsection">3.6.4.1 Input Section Basics</h4>
|
||
|
<a name="index-input-section-basics"></a>
|
||
|
<p>An input section description consists of a file name optionally followed
|
||
|
by a list of section names in parentheses.
|
||
|
</p>
|
||
|
<p>The file name and the section name may be wildcard patterns, which we
|
||
|
describe further below (see <a href="Input-Section-Wildcards.html#Input-Section-Wildcards">Input Section Wildcards</a>).
|
||
|
</p>
|
||
|
<p>The most common input section description is to include all input
|
||
|
sections with a particular name in the output section. For example, to
|
||
|
include all input ‘<samp>.text</samp>’ sections, you would write:
|
||
|
</p><div class="smallexample">
|
||
|
<pre class="smallexample">*(.text)
|
||
|
</pre></div>
|
||
|
<p>Here the ‘<samp>*</samp>’ is a wildcard which matches any file name. To exclude a list
|
||
|
of files from matching the file name wildcard, EXCLUDE_FILE may be used to
|
||
|
match all files except the ones specified in the EXCLUDE_FILE list. For
|
||
|
example:
|
||
|
</p><div class="smallexample">
|
||
|
<pre class="smallexample">*(EXCLUDE_FILE (*crtend.o *otherfile.o) .ctors)
|
||
|
</pre></div>
|
||
|
<p>will cause all .ctors sections from all files except <samp>crtend.o</samp> and
|
||
|
<samp>otherfile.o</samp> to be included.
|
||
|
</p>
|
||
|
<p>There are two ways to include more than one section:
|
||
|
</p><div class="smallexample">
|
||
|
<pre class="smallexample">*(.text .rdata)
|
||
|
*(.text) *(.rdata)
|
||
|
</pre></div>
|
||
|
<p>The difference between these is the order in which the ‘<samp>.text</samp>’ and
|
||
|
‘<samp>.rdata</samp>’ input sections will appear in the output section. In the
|
||
|
first example, they will be intermingled, appearing in the same order as
|
||
|
they are found in the linker input. In the second example, all
|
||
|
‘<samp>.text</samp>’ input sections will appear first, followed by all
|
||
|
‘<samp>.rdata</samp>’ input sections.
|
||
|
</p>
|
||
|
<p>You can specify a file name to include sections from a particular file.
|
||
|
You would do this if one or more of your files contain special data that
|
||
|
needs to be at a particular location in memory. For example:
|
||
|
</p><div class="smallexample">
|
||
|
<pre class="smallexample">data.o(.data)
|
||
|
</pre></div>
|
||
|
|
||
|
<p>To refine the sections that are included based on the section flags
|
||
|
of an input section, INPUT_SECTION_FLAGS may be used.
|
||
|
</p>
|
||
|
<p>Here is a simple example for using Section header flags for ELF sections:
|
||
|
</p>
|
||
|
<div class="smallexample">
|
||
|
<pre class="smallexample">SECTIONS {
|
||
|
.text : { INPUT_SECTION_FLAGS (SHF_MERGE & SHF_STRINGS) *(.text) }
|
||
|
.text2 : { INPUT_SECTION_FLAGS (!SHF_WRITE) *(.text) }
|
||
|
}
|
||
|
</pre></div>
|
||
|
|
||
|
<p>In this example, the output section ‘<samp>.text</samp>’ will be comprised of any
|
||
|
input section matching the name *(.text) whose section header flags
|
||
|
<code>SHF_MERGE</code> and <code>SHF_STRINGS</code> are set. The output section
|
||
|
‘<samp>.text2</samp>’ will be comprised of any input section matching the name *(.text)
|
||
|
whose section header flag <code>SHF_WRITE</code> is clear.
|
||
|
</p>
|
||
|
<p>You can also specify files within archives by writing a pattern
|
||
|
matching the archive, a colon, then the pattern matching the file,
|
||
|
with no whitespace around the colon.
|
||
|
</p>
|
||
|
<dl compact="compact">
|
||
|
<dt>‘<samp>archive:file</samp>’</dt>
|
||
|
<dd><p>matches file within archive
|
||
|
</p></dd>
|
||
|
<dt>‘<samp>archive:</samp>’</dt>
|
||
|
<dd><p>matches the whole archive
|
||
|
</p></dd>
|
||
|
<dt>‘<samp>:file</samp>’</dt>
|
||
|
<dd><p>matches file but not one in an archive
|
||
|
</p></dd>
|
||
|
</dl>
|
||
|
|
||
|
<p>Either one or both of ‘<samp>archive</samp>’ and ‘<samp>file</samp>’ can contain shell
|
||
|
wildcards. On DOS based file systems, the linker will assume that a
|
||
|
single letter followed by a colon is a drive specifier, so
|
||
|
‘<samp>c:myfile.o</samp>’ is a simple file specification, not ‘<samp>myfile.o</samp>’
|
||
|
within an archive called ‘<samp>c</samp>’. ‘<samp>archive:file</samp>’ filespecs may
|
||
|
also be used within an <code>EXCLUDE_FILE</code> list, but may not appear in
|
||
|
other linker script contexts. For instance, you cannot extract a file
|
||
|
from an archive by using ‘<samp>archive:file</samp>’ in an <code>INPUT</code>
|
||
|
command.
|
||
|
</p>
|
||
|
<p>If you use a file name without a list of sections, then all sections in
|
||
|
the input file will be included in the output section. This is not
|
||
|
commonly done, but it may by useful on occasion. For example:
|
||
|
</p><div class="smallexample">
|
||
|
<pre class="smallexample">data.o
|
||
|
</pre></div>
|
||
|
|
||
|
<p>When you use a file name which is not an ‘<samp>archive:file</samp>’ specifier
|
||
|
and does not contain any wild card
|
||
|
characters, the linker will first see if you also specified the file
|
||
|
name on the linker command line or in an <code>INPUT</code> command. If you
|
||
|
did not, the linker will attempt to open the file as an input file, as
|
||
|
though it appeared on the command line. Note that this differs from an
|
||
|
<code>INPUT</code> command, because the linker will not search for the file in
|
||
|
the archive search path.
|
||
|
</p>
|
||
|
<hr>
|
||
|
<div class="header">
|
||
|
<p>
|
||
|
Next: <a href="Input-Section-Wildcards.html#Input-Section-Wildcards" accesskey="n" rel="next">Input Section Wildcards</a>, Up: <a href="Input-Section.html#Input-Section" accesskey="u" rel="up">Input Section</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>
|