ld: Input Section Wildcards
1
1 3.6.4.2 Input Section Wildcard Patterns
1 .......................................
1
1 In an input section description, either the file name or the section
1 name or both may be wildcard patterns.
1
1 The file name of '*' seen in many examples is a simple wildcard
1 pattern for the file name.
1
1 The wildcard patterns are like those used by the Unix shell.
1
1 '*'
1 matches any number of characters
1 '?'
1 matches any single character
1 '[CHARS]'
1 matches a single instance of any of the CHARS; the '-' character
1 may be used to specify a range of characters, as in '[a-z]' to
1 match any lower case letter
1 '\'
1 quotes the following character
1
1 When a file name is matched with a wildcard, the wildcard characters
1 will not match a '/' character (used to separate directory names on
1 Unix). A pattern consisting of a single '*' character is an exception;
1 it will always match any file name, whether it contains a '/' or not.
1 In a section name, the wildcard characters will match a '/' character.
1
1 File name wildcard patterns only match files which are explicitly
1 specified on the command line or in an 'INPUT' command. The linker does
1 not search directories to expand wildcards.
1
1 If a file name matches more than one wildcard pattern, or if a file
1 name appears explicitly and is also matched by a wildcard pattern, the
1 linker will use the first match in the linker script. For example, this
1 sequence of input section descriptions is probably in error, because the
1 'data.o' rule will not be used:
1 .data : { *(.data) }
1 .data1 : { data.o(.data) }
1
1 Normally, the linker will place files and sections matched by
1 wildcards in the order in which they are seen during the link. You can
1 change this by using the 'SORT_BY_NAME' keyword, which appears before a
1 wildcard pattern in parentheses (e.g., 'SORT_BY_NAME(.text*)'). When
1 the 'SORT_BY_NAME' keyword is used, the linker will sort the files or
1 sections into ascending order by name before placing them in the output
1 file.
1
1 'SORT_BY_ALIGNMENT' is very similar to 'SORT_BY_NAME'. The
1 difference is 'SORT_BY_ALIGNMENT' will sort sections into descending
1 order by alignment before placing them in the output file. Larger
1 alignments are placed before smaller alignments in order to reduce the
1 amount of padding necessary.
1
1 'SORT_BY_INIT_PRIORITY' is very similar to 'SORT_BY_NAME'. The
1 difference is 'SORT_BY_INIT_PRIORITY' will sort sections into ascending
1 order by numerical value of the GCC init_priority attribute encoded in
1 the section name before placing them in the output file.
1
1 'SORT' is an alias for 'SORT_BY_NAME'.
1
1 When there are nested section sorting commands in linker script,
1 there can be at most 1 level of nesting for section sorting commands.
1
1 1. 'SORT_BY_NAME' ('SORT_BY_ALIGNMENT' (wildcard section pattern)).
1 It will sort the input sections by name first, then by alignment if
1 two sections have the same name.
1 2. 'SORT_BY_ALIGNMENT' ('SORT_BY_NAME' (wildcard section pattern)).
1 It will sort the input sections by alignment first, then by name if
1 two sections have the same alignment.
1 3. 'SORT_BY_NAME' ('SORT_BY_NAME' (wildcard section pattern)) is
1 treated the same as 'SORT_BY_NAME' (wildcard section pattern).
1 4. 'SORT_BY_ALIGNMENT' ('SORT_BY_ALIGNMENT' (wildcard section
1 pattern)) is treated the same as 'SORT_BY_ALIGNMENT' (wildcard
1 section pattern).
1 5. All other nested section sorting commands are invalid.
1
1 When both command line section sorting option and linker script
1 section sorting command are used, section sorting command always takes
1 precedence over the command line option.
1
1 If the section sorting command in linker script isn't nested, the
1 command line option will make the section sorting command to be treated
1 as nested sorting command.
1
1 1. 'SORT_BY_NAME' (wildcard section pattern ) with '--sort-sections
1 alignment' is equivalent to 'SORT_BY_NAME' ('SORT_BY_ALIGNMENT'
1 (wildcard section pattern)).
1 2. 'SORT_BY_ALIGNMENT' (wildcard section pattern) with '--sort-section
1 name' is equivalent to 'SORT_BY_ALIGNMENT' ('SORT_BY_NAME'
1 (wildcard section pattern)).
1
1 If the section sorting command in linker script is nested, the
1 command line option will be ignored.
1
1 'SORT_NONE' disables section sorting by ignoring the command line
1 section sorting option.
1
1 If you ever get confused about where input sections are going, use
1 the '-M' linker option to generate a map file. The map file shows
1 precisely how input sections are mapped to output sections.
1
1 This example shows how wildcard patterns might be used to partition
1 files. This linker script directs the linker to place all '.text'
1 sections in '.text' and all '.bss' sections in '.bss'. The linker will
1 place the '.data' section from all files beginning with an upper case
1 character in '.DATA'; for all other files, the linker will place the
1 '.data' section in '.data'.
1 SECTIONS {
1 .text : { *(.text) }
1 .DATA : { [A-Z]*(.data) }
1 .data : { *(.data) }
1 .bss : { *(.bss) }
1 }
1