1<html lang="en"> 2<head> 3<title>Input Section Wildcards - 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="prev" href="Input-Section-Basics.html#Input-Section-Basics" title="Input Section Basics"> 10<link rel="next" href="Input-Section-Common.html#Input-Section-Common" title="Input Section Common"> 11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 12<!-- 13This file documents the GNU linker LD 14(Sourcery CodeBench Lite 2011.09-69) 15version 2.21.53. 16 17Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 182001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. 19 20Permission is granted to copy, distribute and/or modify this document 21under the terms of the GNU Free Documentation License, Version 1.3 22or any later version published by the Free Software Foundation; 23with no Invariant Sections, with no Front-Cover Texts, and with no 24Back-Cover Texts. A copy of the license is included in the 25section entitled ``GNU Free Documentation License''.--> 26<meta http-equiv="Content-Style-Type" content="text/css"> 27<style type="text/css"><!-- 28 pre.display { font-family:inherit } 29 pre.format { font-family:inherit } 30 pre.smalldisplay { font-family:inherit; font-size:smaller } 31 pre.smallformat { font-family:inherit; font-size:smaller } 32 pre.smallexample { font-size:smaller } 33 pre.smalllisp { font-size:smaller } 34 span.sc { font-variant:small-caps } 35 span.roman { font-family:serif; font-weight:normal; } 36 span.sansserif { font-family:sans-serif; font-weight:normal; } 37--></style> 38<link rel="stylesheet" type="text/css" href="../cs.css"> 39</head> 40<body> 41<div class="node"> 42<a name="Input-Section-Wildcards"></a> 43<p> 44Next: <a rel="next" accesskey="n" href="Input-Section-Common.html#Input-Section-Common">Input Section Common</a>, 45Previous: <a rel="previous" accesskey="p" href="Input-Section-Basics.html#Input-Section-Basics">Input Section Basics</a>, 46Up: <a rel="up" accesskey="u" href="Input-Section.html#Input-Section">Input Section</a> 47<hr> 48</div> 49 50<h5 class="subsubsection">3.6.4.2 Input Section Wildcard Patterns</h5> 51 52<p><a name="index-input-section-wildcards-408"></a><a name="index-wildcard-file-name-patterns-409"></a><a name="index-file-name-wildcard-patterns-410"></a><a name="index-section-name-wildcard-patterns-411"></a>In an input section description, either the file name or the section 53name or both may be wildcard patterns. 54 55 <p>The file name of ‘<samp><span class="samp">*</span></samp>’ seen in many examples is a simple wildcard 56pattern for the file name. 57 58 <p>The wildcard patterns are like those used by the Unix shell. 59 60 <dl> 61<dt>‘<samp><span class="samp">*</span></samp>’<dd>matches any number of characters 62<br><dt>‘<samp><span class="samp">?</span></samp>’<dd>matches any single character 63<br><dt>‘<samp><span class="samp">[</span><var>chars</var><span class="samp">]</span></samp>’<dd>matches a single instance of any of the <var>chars</var>; the ‘<samp><span class="samp">-</span></samp>’ 64character may be used to specify a range of characters, as in 65‘<samp><span class="samp">[a-z]</span></samp>’ to match any lower case letter 66<br><dt>‘<samp><span class="samp">\</span></samp>’<dd>quotes the following character 67</dl> 68 69 <p>When a file name is matched with a wildcard, the wildcard characters 70will not match a ‘<samp><span class="samp">/</span></samp>’ character (used to separate directory names on 71Unix). A pattern consisting of a single ‘<samp><span class="samp">*</span></samp>’ character is an 72exception; it will always match any file name, whether it contains a 73‘<samp><span class="samp">/</span></samp>’ or not. In a section name, the wildcard characters will match 74a ‘<samp><span class="samp">/</span></samp>’ character. 75 76 <p>File name wildcard patterns only match files which are explicitly 77specified on the command line or in an <code>INPUT</code> command. The linker 78does not search directories to expand wildcards. 79 80 <p>If a file name matches more than one wildcard pattern, or if a file name 81appears explicitly and is also matched by a wildcard pattern, the linker 82will use the first match in the linker script. For example, this 83sequence of input section descriptions is probably in error, because the 84<samp><span class="file">data.o</span></samp> rule will not be used: 85<pre class="smallexample"> .data : { *(.data) } 86 .data1 : { data.o(.data) } 87</pre> 88 <p><a name="index-SORT_005fBY_005fNAME-412"></a>Normally, the linker will place files and sections matched by wildcards 89in the order in which they are seen during the link. You can change 90this by using the <code>SORT_BY_NAME</code> keyword, which appears before a wildcard 91pattern in parentheses (e.g., <code>SORT_BY_NAME(.text*)</code>). When the 92<code>SORT_BY_NAME</code> keyword is used, the linker will sort the files or sections 93into ascending order by name before placing them in the output file. 94 95 <p><a name="index-SORT_005fBY_005fALIGNMENT-413"></a><code>SORT_BY_ALIGNMENT</code> is very similar to <code>SORT_BY_NAME</code>. The 96difference is <code>SORT_BY_ALIGNMENT</code> will sort sections into 97ascending order by alignment before placing them in the output file. 98 99 <p><a name="index-SORT_005fBY_005fINIT_005fPRIORITY-414"></a><code>SORT_BY_INIT_PRIORITY</code> is very similar to <code>SORT_BY_NAME</code>. The 100difference is <code>SORT_BY_INIT_PRIORITY</code> will sort sections into 101ascending order by numerical value of the GCC init_priority attribute 102encoded in the section name before placing them in the output file. 103 104 <p><a name="index-SORT-415"></a><code>SORT</code> is an alias for <code>SORT_BY_NAME</code>. 105 106 <p>When there are nested section sorting commands in linker script, there 107can be at most 1 level of nesting for section sorting commands. 108 109 <ol type=1 start=1> 110<li><code>SORT_BY_NAME</code> (<code>SORT_BY_ALIGNMENT</code> (wildcard section pattern)). 111It will sort the input sections by name first, then by alignment if 2 112sections have the same name. 113<li><code>SORT_BY_ALIGNMENT</code> (<code>SORT_BY_NAME</code> (wildcard section pattern)). 114It will sort the input sections by alignment first, then by name if 2 115sections have the same alignment. 116<li><code>SORT_BY_NAME</code> (<code>SORT_BY_NAME</code> (wildcard section pattern)) is 117treated the same as <code>SORT_BY_NAME</code> (wildcard section pattern). 118<li><code>SORT_BY_ALIGNMENT</code> (<code>SORT_BY_ALIGNMENT</code> (wildcard section pattern)) 119is treated the same as <code>SORT_BY_ALIGNMENT</code> (wildcard section pattern). 120<li>All other nested section sorting commands are invalid. 121 </ol> 122 123 <p>When both command line section sorting option and linker script 124section sorting command are used, section sorting command always 125takes precedence over the command line option. 126 127 <p>If the section sorting command in linker script isn't nested, the 128command line option will make the section sorting command to be 129treated as nested sorting command. 130 131 <ol type=1 start=1> 132<li><code>SORT_BY_NAME</code> (wildcard section pattern ) with 133<samp><span class="option">--sort-sections alignment</span></samp> is equivalent to 134<code>SORT_BY_NAME</code> (<code>SORT_BY_ALIGNMENT</code> (wildcard section pattern)). 135<li><code>SORT_BY_ALIGNMENT</code> (wildcard section pattern) with 136<samp><span class="option">--sort-section name</span></samp> is equivalent to 137<code>SORT_BY_ALIGNMENT</code> (<code>SORT_BY_NAME</code> (wildcard section pattern)). 138 </ol> 139 140 <p>If the section sorting command in linker script is nested, the 141command line option will be ignored. 142 143 <p>If you ever get confused about where input sections are going, use the 144‘<samp><span class="samp">-M</span></samp>’ linker option to generate a map file. The map file shows 145precisely how input sections are mapped to output sections. 146 147 <p>This example shows how wildcard patterns might be used to partition 148files. This linker script directs the linker to place all ‘<samp><span class="samp">.text</span></samp>’ 149sections in ‘<samp><span class="samp">.text</span></samp>’ and all ‘<samp><span class="samp">.bss</span></samp>’ sections in ‘<samp><span class="samp">.bss</span></samp>’. 150The linker will place the ‘<samp><span class="samp">.data</span></samp>’ section from all files beginning 151with an upper case character in ‘<samp><span class="samp">.DATA</span></samp>’; for all other files, the 152linker will place the ‘<samp><span class="samp">.data</span></samp>’ section in ‘<samp><span class="samp">.data</span></samp>’. 153<pre class="smallexample"> SECTIONS { 154 .text : { *(.text) } 155 .DATA : { [A-Z]*(.data) } 156 .data : { *(.data) } 157 .bss : { *(.bss) } 158 } 159</pre> 160 </body></html> 161 162