1<html lang="en"> 2<head> 3<title>Input Section Basics - Untitled</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Untitled"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="Input-Section.html#Input-Section" title="Input Section"> 9<link rel="next" href="Input-Section-Wildcards.html#Input-Section-Wildcards" title="Input Section Wildcards"> 10<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 11<!-- 12This file documents the GNU linker LD 13(Sourcery CodeBench Lite 2011.09-69) 14version 2.21.53. 15 16Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 172001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. 18 19Permission is granted to copy, distribute and/or modify this document 20under the terms of the GNU Free Documentation License, Version 1.3 21or any later version published by the Free Software Foundation; 22with no Invariant Sections, with no Front-Cover Texts, and with no 23Back-Cover Texts. A copy of the license is included in the 24section entitled ``GNU Free Documentation License''.--> 25<meta http-equiv="Content-Style-Type" content="text/css"> 26<style type="text/css"><!-- 27 pre.display { font-family:inherit } 28 pre.format { font-family:inherit } 29 pre.smalldisplay { font-family:inherit; font-size:smaller } 30 pre.smallformat { font-family:inherit; font-size:smaller } 31 pre.smallexample { font-size:smaller } 32 pre.smalllisp { font-size:smaller } 33 span.sc { font-variant:small-caps } 34 span.roman { font-family:serif; font-weight:normal; } 35 span.sansserif { font-family:sans-serif; font-weight:normal; } 36--></style> 37<link rel="stylesheet" type="text/css" href="../cs.css"> 38</head> 39<body> 40<div class="node"> 41<a name="Input-Section-Basics"></a> 42<p> 43Next: <a rel="next" accesskey="n" href="Input-Section-Wildcards.html#Input-Section-Wildcards">Input Section Wildcards</a>, 44Up: <a rel="up" accesskey="u" href="Input-Section.html#Input-Section">Input Section</a> 45<hr> 46</div> 47 48<h5 class="subsubsection">3.6.4.1 Input Section Basics</h5> 49 50<p><a name="index-input-section-basics-407"></a>An input section description consists of a file name optionally followed 51by a list of section names in parentheses. 52 53 <p>The file name and the section name may be wildcard patterns, which we 54describe further below (see <a href="Input-Section-Wildcards.html#Input-Section-Wildcards">Input Section Wildcards</a>). 55 56 <p>The most common input section description is to include all input 57sections with a particular name in the output section. For example, to 58include all input ‘<samp><span class="samp">.text</span></samp>’ sections, you would write: 59<pre class="smallexample"> *(.text) 60</pre> 61 <p class="noindent">Here the ‘<samp><span class="samp">*</span></samp>’ is a wildcard which matches any file name. To exclude a list 62of files from matching the file name wildcard, EXCLUDE_FILE may be used to 63match all files except the ones specified in the EXCLUDE_FILE list. For 64example: 65<pre class="smallexample"> *(EXCLUDE_FILE (*crtend.o *otherfile.o) .ctors) 66</pre> 67 <p>will cause all .ctors sections from all files except <samp><span class="file">crtend.o</span></samp> and 68<samp><span class="file">otherfile.o</span></samp> to be included. 69 70 <p>There are two ways to include more than one section: 71<pre class="smallexample"> *(.text .rdata) 72 *(.text) *(.rdata) 73</pre> 74 <p class="noindent">The difference between these is the order in which the ‘<samp><span class="samp">.text</span></samp>’ and 75‘<samp><span class="samp">.rdata</span></samp>’ input sections will appear in the output section. In the 76first example, they will be intermingled, appearing in the same order as 77they are found in the linker input. In the second example, all 78‘<samp><span class="samp">.text</span></samp>’ input sections will appear first, followed by all 79‘<samp><span class="samp">.rdata</span></samp>’ input sections. 80 81 <p>You can specify a file name to include sections from a particular file. 82You would do this if one or more of your files contain special data that 83needs to be at a particular location in memory. For example: 84<pre class="smallexample"> data.o(.data) 85</pre> 86 <p>To refine the sections that are included based on the section flags 87of an input section, INPUT_SECTION_FLAGS may be used. 88 89 <p>Here is a simple example for using Section header flags for ELF sections: 90 91<pre class="smallexample"> SECTIONS { 92 .text : { INPUT_SECTION_FLAGS (SHF_MERGE & SHF_STRINGS) *(.text) } 93 .text2 : { INPUT_SECTION_FLAGS (!SHF_WRITE) *(.text) } 94 } 95</pre> 96 <p>In this example, the output section ‘<samp><span class="samp">.text</span></samp>’ will be comprised of any 97input section matching the name *(.text) whose section header flags 98<code>SHF_MERGE</code> and <code>SHF_STRINGS</code> are set. The output section 99‘<samp><span class="samp">.text2</span></samp>’ will be comprised of any input section matching the name *(.text) 100whose section header flag <code>SHF_WRITE</code> is clear. 101 102 <p>You can also specify files within archives by writing a pattern 103matching the archive, a colon, then the pattern matching the file, 104with no whitespace around the colon. 105 106 <dl> 107<dt>‘<samp><span class="samp">archive:file</span></samp>’<dd>matches file within archive 108<br><dt>‘<samp><span class="samp">archive:</span></samp>’<dd>matches the whole archive 109<br><dt>‘<samp><span class="samp">:file</span></samp>’<dd>matches file but not one in an archive 110</dl> 111 112 <p>Either one or both of ‘<samp><span class="samp">archive</span></samp>’ and ‘<samp><span class="samp">file</span></samp>’ can contain shell 113wildcards. On DOS based file systems, the linker will assume that a 114single letter followed by a colon is a drive specifier, so 115‘<samp><span class="samp">c:myfile.o</span></samp>’ is a simple file specification, not ‘<samp><span class="samp">myfile.o</span></samp>’ 116within an archive called ‘<samp><span class="samp">c</span></samp>’. ‘<samp><span class="samp">archive:file</span></samp>’ filespecs may 117also be used within an <code>EXCLUDE_FILE</code> list, but may not appear in 118other linker script contexts. For instance, you cannot extract a file 119from an archive by using ‘<samp><span class="samp">archive:file</span></samp>’ in an <code>INPUT</code> 120command. 121 122 <p>If you use a file name without a list of sections, then all sections in 123the input file will be included in the output section. This is not 124commonly done, but it may by useful on occasion. For example: 125<pre class="smallexample"> data.o 126</pre> 127 <p>When you use a file name which is not an ‘<samp><span class="samp">archive:file</span></samp>’ specifier 128and does not contain any wild card 129characters, the linker will first see if you also specified the file 130name on the linker command line or in an <code>INPUT</code> command. If you 131did not, the linker will attempt to open the file as an input file, as 132though it appeared on the command line. Note that this differs from an 133<code>INPUT</code> command, because the linker will not search for the file in 134the archive search path. 135 136 </body></html> 137 138