1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3<!-- This file documents the GNU linker LD 4(GNU Toolchain for the A-profile Architecture 10.3-2021.07 (arm-10.29)) 5version 2.36.1. 6 7Copyright (C) 1991-2021 Free Software Foundation, Inc. 8 9Permission is granted to copy, distribute and/or modify this document 10under the terms of the GNU Free Documentation License, Version 1.3 11or any later version published by the Free Software Foundation; 12with no Invariant Sections, with no Front-Cover Texts, and with no 13Back-Cover Texts. A copy of the license is included in the 14section entitled "GNU Free Documentation License". --> 15<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ --> 16<head> 17<title>LD: Input Section Wildcards</title> 18 19<meta name="description" content="LD: Input Section Wildcards"> 20<meta name="keywords" content="LD: Input Section Wildcards"> 21<meta name="resource-type" content="document"> 22<meta name="distribution" content="global"> 23<meta name="Generator" content="makeinfo"> 24<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 25<link href="index.html#Top" rel="start" title="Top"> 26<link href="LD-Index.html#LD-Index" rel="index" title="LD Index"> 27<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> 28<link href="Input-Section.html#Input-Section" rel="up" title="Input Section"> 29<link href="Input-Section-Common.html#Input-Section-Common" rel="next" title="Input Section Common"> 30<link href="Input-Section-Basics.html#Input-Section-Basics" rel="previous" title="Input Section Basics"> 31<style type="text/css"> 32<!-- 33a.summary-letter {text-decoration: none} 34blockquote.smallquotation {font-size: smaller} 35div.display {margin-left: 3.2em} 36div.example {margin-left: 3.2em} 37div.indentedblock {margin-left: 3.2em} 38div.lisp {margin-left: 3.2em} 39div.smalldisplay {margin-left: 3.2em} 40div.smallexample {margin-left: 3.2em} 41div.smallindentedblock {margin-left: 3.2em; font-size: smaller} 42div.smalllisp {margin-left: 3.2em} 43kbd {font-style:oblique} 44pre.display {font-family: inherit} 45pre.format {font-family: inherit} 46pre.menu-comment {font-family: serif} 47pre.menu-preformatted {font-family: serif} 48pre.smalldisplay {font-family: inherit; font-size: smaller} 49pre.smallexample {font-size: smaller} 50pre.smallformat {font-family: inherit; font-size: smaller} 51pre.smalllisp {font-size: smaller} 52span.nocodebreak {white-space:nowrap} 53span.nolinebreak {white-space:nowrap} 54span.roman {font-family:serif; font-weight:normal} 55span.sansserif {font-family:sans-serif; font-weight:normal} 56ul.no-bullet {list-style: none} 57--> 58</style> 59 60 61</head> 62 63<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> 64<a name="Input-Section-Wildcards"></a> 65<div class="header"> 66<p> 67Next: <a href="Input-Section-Common.html#Input-Section-Common" accesskey="n" rel="next">Input Section Common</a>, Previous: <a href="Input-Section-Basics.html#Input-Section-Basics" accesskey="p" rel="previous">Input Section Basics</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> 68</div> 69<hr> 70<a name="Input-Section-Wildcard-Patterns"></a> 71<h4 class="subsubsection">3.6.4.2 Input Section Wildcard Patterns</h4> 72<a name="index-input-section-wildcards"></a> 73<a name="index-wildcard-file-name-patterns"></a> 74<a name="index-file-name-wildcard-patterns"></a> 75<a name="index-section-name-wildcard-patterns"></a> 76<p>In an input section description, either the file name or the section 77name or both may be wildcard patterns. 78</p> 79<p>The file name of ‘<samp>*</samp>’ seen in many examples is a simple wildcard 80pattern for the file name. 81</p> 82<p>The wildcard patterns are like those used by the Unix shell. 83</p> 84<dl compact="compact"> 85<dt>‘<samp>*</samp>’</dt> 86<dd><p>matches any number of characters 87</p></dd> 88<dt>‘<samp>?</samp>’</dt> 89<dd><p>matches any single character 90</p></dd> 91<dt>‘<samp>[<var>chars</var>]</samp>’</dt> 92<dd><p>matches a single instance of any of the <var>chars</var>; the ‘<samp>-</samp>’ 93character may be used to specify a range of characters, as in 94‘<samp>[a-z]</samp>’ to match any lower case letter 95</p></dd> 96<dt>‘<samp>\</samp>’</dt> 97<dd><p>quotes the following character 98</p></dd> 99</dl> 100 101<p>When a file name is matched with a wildcard, the wildcard characters 102will not match a ‘<samp>/</samp>’ character (used to separate directory names on 103Unix). A pattern consisting of a single ‘<samp>*</samp>’ character is an 104exception; it will always match any file name, whether it contains a 105‘<samp>/</samp>’ or not. In a section name, the wildcard characters will match 106a ‘<samp>/</samp>’ character. 107</p> 108<p>File name wildcard patterns only match files which are explicitly 109specified on the command line or in an <code>INPUT</code> command. The linker 110does not search directories to expand wildcards. 111</p> 112<p>If a file name matches more than one wildcard pattern, or if a file name 113appears explicitly and is also matched by a wildcard pattern, the linker 114will use the first match in the linker script. For example, this 115sequence of input section descriptions is probably in error, because the 116<samp>data.o</samp> rule will not be used: 117</p><div class="smallexample"> 118<pre class="smallexample">.data : { *(.data) } 119.data1 : { data.o(.data) } 120</pre></div> 121 122<a name="index-SORT_005fBY_005fNAME"></a> 123<p>Normally, the linker will place files and sections matched by wildcards 124in the order in which they are seen during the link. You can change 125this by using the <code>SORT_BY_NAME</code> keyword, which appears before a wildcard 126pattern in parentheses (e.g., <code>SORT_BY_NAME(.text*)</code>). When the 127<code>SORT_BY_NAME</code> keyword is used, the linker will sort the files or sections 128into ascending order by name before placing them in the output file. 129</p> 130<a name="index-SORT_005fBY_005fALIGNMENT"></a> 131<p><code>SORT_BY_ALIGNMENT</code> is similar to <code>SORT_BY_NAME</code>. 132<code>SORT_BY_ALIGNMENT</code> will sort sections into descending order of 133alignment before placing them in the output file. Placing larger 134alignments before smaller alignments can reduce the amount of padding 135needed. 136</p> 137<a name="index-SORT_005fBY_005fINIT_005fPRIORITY"></a> 138<p><code>SORT_BY_INIT_PRIORITY</code> is also similar to <code>SORT_BY_NAME</code>. 139<code>SORT_BY_INIT_PRIORITY</code> will sort sections into ascending 140numerical order of the GCC init_priority attribute encoded in the 141section name before placing them in the output file. In 142<code>.init_array.NNNNN</code> and <code>.fini_array.NNNNN</code>, <code>NNNNN</code> is 143the init_priority. In <code>.ctors.NNNNN</code> and <code>.dtors.NNNNN</code>, 144<code>NNNNN</code> is 65535 minus the init_priority. 145</p> 146<a name="index-SORT"></a> 147<p><code>SORT</code> is an alias for <code>SORT_BY_NAME</code>. 148</p> 149<p>When there are nested section sorting commands in linker script, there 150can be at most 1 level of nesting for section sorting commands. 151</p> 152<ol> 153<li> <code>SORT_BY_NAME</code> (<code>SORT_BY_ALIGNMENT</code> (wildcard section pattern)). 154It will sort the input sections by name first, then by alignment if two 155sections have the same name. 156</li><li> <code>SORT_BY_ALIGNMENT</code> (<code>SORT_BY_NAME</code> (wildcard section pattern)). 157It will sort the input sections by alignment first, then by name if two 158sections have the same alignment. 159</li><li> <code>SORT_BY_NAME</code> (<code>SORT_BY_NAME</code> (wildcard section pattern)) is 160treated the same as <code>SORT_BY_NAME</code> (wildcard section pattern). 161</li><li> <code>SORT_BY_ALIGNMENT</code> (<code>SORT_BY_ALIGNMENT</code> (wildcard section pattern)) 162is treated the same as <code>SORT_BY_ALIGNMENT</code> (wildcard section pattern). 163</li><li> All other nested section sorting commands are invalid. 164</li></ol> 165 166<p>When both command-line section sorting option and linker script 167section sorting command are used, section sorting command always 168takes precedence over the command-line option. 169</p> 170<p>If the section sorting command in linker script isn’t nested, the 171command-line option will make the section sorting command to be 172treated as nested sorting command. 173</p> 174<ol> 175<li> <code>SORT_BY_NAME</code> (wildcard section pattern ) with 176<samp>--sort-sections alignment</samp> is equivalent to 177<code>SORT_BY_NAME</code> (<code>SORT_BY_ALIGNMENT</code> (wildcard section pattern)). 178</li><li> <code>SORT_BY_ALIGNMENT</code> (wildcard section pattern) with 179<samp>--sort-section name</samp> is equivalent to 180<code>SORT_BY_ALIGNMENT</code> (<code>SORT_BY_NAME</code> (wildcard section pattern)). 181</li></ol> 182 183<p>If the section sorting command in linker script is nested, the 184command-line option will be ignored. 185</p> 186<a name="index-SORT_005fNONE"></a> 187<p><code>SORT_NONE</code> disables section sorting by ignoring the command-line 188section sorting option. 189</p> 190<p>If you ever get confused about where input sections are going, use the 191‘<samp>-M</samp>’ linker option to generate a map file. The map file shows 192precisely how input sections are mapped to output sections. 193</p> 194<p>This example shows how wildcard patterns might be used to partition 195files. This linker script directs the linker to place all ‘<samp>.text</samp>’ 196sections in ‘<samp>.text</samp>’ and all ‘<samp>.bss</samp>’ sections in ‘<samp>.bss</samp>’. 197The linker will place the ‘<samp>.data</samp>’ section from all files beginning 198with an upper case character in ‘<samp>.DATA</samp>’; for all other files, the 199linker will place the ‘<samp>.data</samp>’ section in ‘<samp>.data</samp>’. 200</p><div class="smallexample"> 201<pre class="smallexample">SECTIONS { 202 .text : { *(.text) } 203 .DATA : { [A-Z]*(.data) } 204 .data : { *(.data) } 205 .bss : { *(.bss) } 206} 207</pre></div> 208 209<hr> 210<div class="header"> 211<p> 212Next: <a href="Input-Section-Common.html#Input-Section-Common" accesskey="n" rel="next">Input Section Common</a>, Previous: <a href="Input-Section-Basics.html#Input-Section-Basics" accesskey="p" rel="previous">Input Section Basics</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> 213</div> 214 215 216 217</body> 218</html> 219