# Linker scripts Use linker scripts to provide detailed specifications of how files are to be linked. The scripts offer greater control over linking than is available using just the linker command options ([Options](https://docs.qualcomm.com/doc/80-VB419-102/topic/use_the_linker.html#sec-use-the-linker-options)). Linker scripts control the following properties: - ELF program header - Program entry point - Input and output files and searching paths - Section memory placement and runtime properties - Section removal - Symbol definition Note Linker scripts are optional. In most cases, the default behavior of the linker is sufficient: input sections are merged according to their section names, and segments are ordered by sections that share similar permissions ## Use a linker script A linker script consists of a sequence of commands stored in a text file. Specify the script file on the command line either with -T or by indicating the file as an input file. The linker distinguishes between script files and object files and handles each accordingly. To generate a map file that shows how a linker script controlled linking, use the -M option. Note Linker scripts are optional. In most cases, the default behavior of the linker is sufficient. ## Example script file This linker script demonstrates the scripting features. Note The syntax used in linker scripts is similar to the scripts used with the GNU linker. However, only the features and syntax described in this document are supported. ENTRY (main) SEARCH_DIR("./") PHDRS { CODE PT_LOAD ; DATA PT_LOAD ; } SECTIONS { .text.qcldfn (0x2000) : { *(.text.qcldfn*) } : CODE . = ALIGN(0x1000); PROVIDE( etext = .); text_start = . + 0x1000 - 0x1000; .text : { EXCLUDE_FILE(*notused.o*) *(.text.*) } : CODE .data : { *(.data.*) } : DATA .init : { KEEP (*(.init)) } . = SEGMENT_START(".bss", 0x80000); .bss : { *(.bss.*) } bss_start = .; bss_end } = .; Copy to clipboard The following commands specify the link properties: - The PHDRS command defines two loadable ELF segments. - The SECTIONS command specifies how input sections are mapped to output sections, and where output sections are located in memory. - Wildcard characters in the SECTIONS command indicate that multiple input sections are mapped to a single output section. A period indicates the current location counter and is assigned several different values in the SECTIONS command. Following are descriptions of the sections in the example script. - **.text.qcldfn** - All input sections whose names begin with .text.qcldfn are mapped to an output section named .text.qcldfn. This output section is first in the CODE segment. The merged output section is located at virtual memory address 0x2000. The location counter then advances to the next 0x1000 address boundary past the end of the .text.qcldfn output section using the ALIGN directive. - **etext** - Symbol that is defined with the location counter value of any unresolved symbol references for the symbol using the PROVIDE command. - **text\_start** - Symbol that is assigned the current location counter value plus any following arithmetic expression. - **.text** - All input sections whose names begin with .text are mapped to the .text output section. This output section is put into the CODE segment. The merged output section is located at the current location counter. The .text.qcldfn section is not affected by this statement even though it matches the .text.\* section name wildcard because it is already merged in the previous link script statement. - **.data** - Current location counter is assigned the base address of the .data output section with the SEGMENT\_START directive. If undefined, a default value of 0x50000 is used. All input sections whose names begin with .data are mapped to the .data output section. This section is put into the DATA segment. The merged output section is located at the current location counter as specified by the preceding statement in the script. - **.init** - All input sections whose names with .init are mapped to the .init output section. Because no segment is defined, available previous segments are used instead and the output is put into the DATA segment. The merged output section is located at the current location counter as specified by the preceding statement in the script. - **.bss** - The current location counter is assigned the base address of the .bss output section with the SEGMENT\_START directive. If undefined, a default value of 0x80000 is used. All input sections whose names begin with .bss are mapped to the .bss output section. The merged output section is located at the current location counter as specified by the preceding statement in the script. If garbage collection is enabled (with the KEEP directive), none of the input sections are removed from memory. The bss\_start and bss\_end symbols are assigned the current location counter value. ## Basic script syntax ### Symbols Symbol names must begin with a letter, underscore, or period. They can include letters, numbers, underscores, hyphens, or periods. ### Comments Comments can appear in linker scripts: > > > `/* comment */` ### Strings Character strings can be specified as parameters with or without delimiter characters. ### Expressions Expressions are similar to C and support all C arithmetic operators. They are evaluated as type long or unsigned long. For more information, see [Expressions](https://docs.qualcomm.com/doc/80-VB419-102/topic/linker_scripts.html#expressions-1). ### Location counter A period is used as a symbol to indicate the current location counter. It is used in the SECTIONS command only, where it designates locations in the output section: . = ALIGN(0x1000); . = . + 0x1000; Copy to clipboard Assigning a value to the location counter symbol changes the location counter to the specified value. The location counter can be moved forward by arbitrary amounts to create gaps in an output section. It cannot, however, be moved backwards. ### Symbol assignment Symbols, including the location counter, can be assigned constants or expressions: text_start = . + 0x1000; Copy to clipboard Assignment statements are similar to C, and support all C assignment operators. Terminate assignment statements with semicolons. ## Script commands The SECTIONS command must be specified in a linker script. All other script commands are optional. For an example linker script (which demonstrates the use of several commands), see [Example script file](https://docs.qualcomm.com/doc/80-VB419-102/topic/linker_scripts.html#example-script-file). Expressions can be used in several linker script commands. For more information, see [Expressions](https://docs.qualcomm.com/doc/80-VB419-102/topic/linker_scripts.html#expressions-1). ### PHDRS The PHDRS script command sets information in the program header of an ELF output file. PHDRS { [FILEHDR][PHDRS][AT (
)][FLAGS ()] } Copy to clipboard #### Syntax *<name>* Specifies the program header in the SECTIONS command (see [SECTIONS](https://docs.qualcomm.com/doc/80-VB419-102/topic/linker_scripts.html#sections)). *<type>* Specifies the program header type. - PT\_LOAD - Loadable segment - PT\_NULL - Linker does not include section in a segment. No loadable section should be set to PT\_NULL. - PT\_DYNAMIC - Segment where dynamic linking information is stored - PT\_INTERP - Segment where the name of the dynamic linker is stored - PT\_NOTE - Segment where note information is stored - PT\_SHLIB - Reserved program header type - PT\_PHDR - Segment where program headers are stored - **FILEHDR PHDRS** | **AT (<address>)** - Not supported. These options are parsed but have no effect on linking. - **FLAGS (<flags>)** - Specifies the p\_flags field in the ELF header. The value of *p\_flags* must be an integer. The FLAGS argument takes a numeric value as input. You can determine the values by checking the Linux definitions. The loader of the executable knows about those values. The following example is from the Elf header file (*/usr/include/elf.h*): #define PF_X (1 << 0) /* Segment is executable */ #define PF_W (1 << 1) /* Segment is writable */ #define PF_R (1 << 2) /* Segment is readable */ #define PF_MASKOS 0x0ff00000 /* OS-specific */ #define PF_MASKPROC 0xf0000000 /* Processor-specific */ Copy to clipboard Thus, to set `PF_R|PF_W = (1 << 1) | (1 << 2) = 0x6 and PF_R=0x4`: > > > PHDRS { > tim0 PT_LOAD FLAGS (0x4); //read only tim1 PT_LOAD FLAGS > (0x6); //read|write > } > > SECTIONS { > .text : { *(.text*) } :A > } > Copy to clipboard Note If the sections in an output file have different flag settings than PHDRS, the linker chooses the least-restrictive settings for the output file. #### PHDRS example More than one program header specification can be assigned to a given section. The following linker script generates a linker error indicating that the same section cannot be included in two different segments: PHDRS { phdr1 PT_LOAD; phdr2 PT_LOAD; } .text : { *(*.text*) } : phdr1 :phdr2 Copy to clipboard The PHDRS command overrides the linker’s default program header settings. For multiple program headers, only the first can have an LMA or VMA definition. For an example linker script that demonstrates the use of the PHDRS, see [Example script file](https://docs.qualcomm.com/doc/80-VB419-102/topic/linker_scripts.html#example-script-file). ### SECTIONS The SECTIONS script command specifies how input sections are mapped to output sections, and where output sections are located in memory. This command must be specified once, and only once, in a linker script. For an example linker script that demonstrates the use of the SECTIONS, see [Example script file](https://docs.qualcomm.com/doc/80-VB419-102/topic/linker_scripts.html#example-script-file) SECTIONS { ... } Copy to clipboard #### Section statements A SECTIONS command contains one or more section statements, where each statement can be one of the following: - An ENTRY command ([ENTRY](https://docs.qualcomm.com/doc/80-VB419-102/topic/linker_scripts.html#entry)). - A *symbol assignment statement* to set the location counter ([Symbol assignment](https://docs.qualcomm.com/doc/80-VB419-102/topic/linker_scripts.html#symbol-assignment-1)). The location counter specifies the default address in subsequent section-mapping statements that do not explicitly specify an address. - An *output section description* to specify one or more input sections in one or more library files, and to map those sections to an output section. The virtual memory address of the output section can be specified using attribute keywords. #### Output section description A SECTIONS command can contain one or more output section descriptions. [][()] : [AT()] [ALIGN()] [SUBALIGN()] [] { ... }[>][AT>][:...][ =] Copy to clipboard ##### Syntax - *<section-name>* - Specifies the name of the output section. - *<virtual\_addr>* - Specifies the virtual address of the output section (optional). The address value can be an expression (see [Expressions](https://docs.qualcomm.com/doc/80-VB419-102/topic/linker_scripts.html#expressions-1)). - *<type>* - Specifies the section load property (optional). - NOLOAD - Marks a section as not loadable. - DSECT - Parsed only; has no effect on linking. - COPY - Parsed only; has no effect on linking. - INFO - Parsed only; has no effect on linking. - OVERLAY - Parsed only; has no effect on linking. - *<load\_addr>* - Specifies the load address of the output section (optional). The address value can be specified as an expression (see [Expressions](https://docs.qualcomm.com/doc/80-VB419-102/topic/linker_scripts.html#expressions-1)). - *<section\_align>* - Specifies the section alignment of the output section (optional). The alignment value can be an expression (see [Expressions](https://docs.qualcomm.com/doc/80-VB419-102/topic/linker_scripts.html#expressions-1)). - *<subsection\_align>* - Specifies the subsection alignment of the output section (optional). The alignment value can be an expression (see [Expressions](https://docs.qualcomm.com/doc/80-VB419-102/topic/linker_scripts.html#expressions-1)). - *<constraint>* - Specifies the access type of the input sections (optional). - NOLOAD - All input sections are read-only. - DSECT - All input sections are read/write (default). - *<output-section-command>* - Specifies an output section command (see [Output section commands](https://docs.qualcomm.com/doc/80-VB419-102/topic/linker_scripts.html#output-section-commands)). An output section description contains one or more output section commands. - *<region>* - Specifies the region of the output section (optional). The region is expressed as a string. This option is parsed but has no effect on linking. - *<lma-region>* - Specifies the load memory address (LMA) region of the output section (optional). The value can be an expression. This option is parsed, but it has no effect on linking. - *<fillexp>* - Specifies the fill value of the output section (optional). The value can be an expression. This option is parsed, but it has no effect on linking. - *<phdr>* - Specifies a program segment for the output section (optional). To assign multiple program segments to an output section, this option can appear more than once in an output section description. Note Setting phdr in an output section description will affect subsequent output sections. This behavior differs from the GNU linker. #### Output section commands An output section description contains one or more output section commands. An output section command consists of one or more statements separated by semicolons. The statements can be any of the following: - Output section data - Output section keyword - *Symbol assignment statement* to set the location counter (see [Symbol assignment](https://docs.qualcomm.com/doc/80-VB419-102/topic/linker_scripts.html#symbol-assignment-1)). The location counter specifies the default address in subsequent section-mapping statements that do not explicitly specify an address. - *Input section description* to specify one or more input sections in one or more library files (see [Input section description](https://docs.qualcomm.com/doc/80-VB419-102/topic/linker_scripts.html#input-section-description)). #### Output section data The OUTPUT\_SECTION\_DATA operator can be used to include specific bytes of data from an expression value ([Expressions](https://docs.qualcomm.com/doc/80-VB419-102/topic/linker_scripts.html#expressions-1)). OUTPUT_SECTION_DATA_() Copy to clipboard Where *<keyword>* can have literal values: BYTE, SHORT, LONG, QUAD, or SQUAD. Note Currently, output section data is not supported by the linker. The keyword is parsed but the data value generated is undefined and the linker does not generate a warning message. Replace all output section data references with fill expressions ([Output section description](https://docs.qualcomm.com/doc/80-VB419-102/topic/linker_scripts.html#output-section-description)). #### Output section keywords For compatibility with the GNU linker, the CREATE\_OBJECT\_SYMBOLS, CONSTRUCTORS, and SORT\_BY\_NAME(CONSTRUCTORS) keywords are parsed, but they have no effect on linking. #### Input section description An output section command may contain one or more input section descriptions. An input section description specifies the sections to be linked and the files they are contained in. An input section description has the following basic syntax for specifying a section in an object file: () Copy to clipboard A single input section description can specify multiple files or sections: [:]... ([[...) Copy to clipboard Separate multiple file names with colons, and separate multiple section names with spaces. The \* and ? wildcard characters can be used in file names and section names. For example, the following input file description specifies all input sections named .text\* contained in all linker input files: *(.text*) Copy to clipboard Use the EXCLUDE\_FILE operator to reduce the number of items matched by a wildcard expression. Excluded items can be files, archives, or archive members. For example: *(EXCLUDE_FILE(*crtend.o) .text .data) Copy to clipboard This example specifies all the linker input files except for any files named \*crtend.o. Note If an exclusion is used in a list of section names, it applies only to the immediately following section name in the list (.text in the example above). For examples of using exclusions, see [Linker script examples](https://docs.qualcomm.com/doc/80-VB419-102/topic/linker_scripts.html#linker-script-examples). Use the KEEP operator to prevent the linker performing garbage collection on unused sections when the -gc-sections linker option is used. For example: KEEP(*(.init)) Copy to clipboard This example says that the input section.init will be retained by the linker even if it is not referenced in the program being linked. Note For compatibility with the GNU linker, the following sort operators are all parsed, but they have no effect on linking: SORT\_NONE, SORT\_BY\_NAME, SORT\_BY\_ALIGNMENT, and SORT\_BY\_INIT\_PRIORITY. #### Orphan section placement Orphan sections are sections that are present in the input files but not explicitly placed into the output file by the linker script. The linker will still copy these sections into the output file but without attempting to place them anywhere. The linker uses a simple heuristic and attempts to place orphan sections with the following steps: 1. The linker checks the properties of the section that it is to automatically place. It looks for these properties in the text, data, and bss sections or any predefined section in the linker. If a match is found, the linker places the orphan section at the predefined location. 2. If the orphan section does not match any predefined sections, the linker places the orphan section after nonorphan sections of the same attribute or permissions. A special category of orphan sections have an attribute that the compiler tells the linker to place. The compiler communicates this by using an attribute that specifies an address. You can use attribute ((at(*XXX*))) to specify the address. The linker uses this information to place the section at the specified address. If there is not enough room, it produces an error. ### ENTRY The ENTRY script command specifies the program execution entry point. The entry point is the first instruction that is executed after a program is loaded. ENTRY () Copy to clipboard This command is equivalent to the linker command-line option, -e. ### OUTPUT\_FORMAT The OUTPUT\_FORMAT script command specifies the output file properties. For compatibility with the GNU linker, this command is parsed but has no effect on linking. OUTPUT_FORMAT () Copy to clipboard ### OUTPUT\_ARCH The OUTPUT\_ARCH script command specifies the target processor architecture. For compatibility with the GNU linker, this command is parsed but has no effect on linking. OUTPUT_ARCH ("aarch64") Copy to clipboard ### SEARCH\_DIR The SEARCH\_DIR script command specifies which adds the specified path to the list of paths that the linker uses to search for libraries. SEARCH_DIR () Copy to clipboard This command is equivalent to the linker command-line option, -L. ### INCLUDE The INCLUDE script command specifies the contents of the text file at the current location in the linker script. The specified file is searched for in the current directory and any directory that the linker uses to search for libraries. Note Include files can be nested. INCLUDE () Copy to clipboard ### OUTPUT The OUTPUT script command defines the location and file where the linker will write output data. Only one output is allowed per linking. OUTPUT () Copy to clipboard ### GROUP The GROUP script command includes a list of achieved file names. The achieved names defined in the list are searched repeatedly until all defined references are resolved. GROUP (, , ...) Copy to clipboard ### ASSERT The ASSERT script command adds an assertion to the linker script. ASSERT(, ) Copy to clipboard ### NOCROSSREFS The NOCROSSREFS command takes a list of space-separated output section names as its arguments. Any cross-references among these output sections will result in link editor failure. The list can also contain an orphan section that is not specified in the linker script. NOCROSSREFS(
...) Copy to clipboard A linker script can contain multiple NOCROSSREFS commands. Each command is treated as an independent set of output sections that are checked for cross-references. ## Expressions Expressions in linker scripts are identical to C expressions. They are evaluated in 32-bit for Arm architecture and 64-bit for AArch64 architecture. In addition to the SECTION command operators ([SECTIONS](https://docs.qualcomm.com/doc/80-VB419-102/topic/linker_scripts.html#sections)), the linker defines the following functions that can be used in linker script expressions. - **.** - Return the location counter value representing the current virtual address. - **ABSOLUTE (<expression>)** - Return the absolute value of the expression. - **ADDR (<string>)** - Return the virtual address of the symbol or section. A period character (.) is supported. - **ALIGN (<expression>)** - Return the value when the current location counter is aligned to the next expression boundary. The value of the current location counter is not changed. - **ALIGN (<expression1>, <expression2>)** - Return the value when the value of *expression1* is aligned to the next *expression2* boundary. - **ALIGNOF (<string>)** - Return the align information of the symbol or section. - **ASSERT (<expression>, <string>)** - Throw an assertion if the expression result is zero. - **BLOCK (<expression>)** - Synonym for ALIGN (*expression*). - **CONSTANT (COMMONPAGESIZE)** - Return the defined common page size. - **CONSTANT (MAXPAGESIZE)** - Return the defined default page size required by the ABI. - **DATA\_SEGMENT\_ALIGN(<maxpagesize>, <commonpagesize>)** - Equivalent to: `(ALIGN(maxpagesize)+(.&(maxpagesize ? 1)))` Or `ALIGN(maxpagesize)+(.&(maxpagesize -commonpagesize)))` The linker computes both of these values and returns the larger one. - **DATA\_SEGMENT\_END (<expression>)** - Not used; return the value of the expression. - **DATA\_SEGMENT\_RELRO\_END(<expression>)** - Not used; return the value of the expression. - **DEFINED (<symbol>)** - Return 1 if the symbol is defined in the global symbol table of the linker. Otherwise, return 0. - **LOADADDR (<string>)** - Synonym for ADDR (*string*). - **MAX (<expression>, <expression>)** - Return the maximum value of two expressions. - **MIN (<expression1>, <expression2>)** - Return the minimum value of two expressions. - **SEGMENT\_START (<string>,<expression>)** - If a string matches a known segment, return the start address of that segment. If nothing is found, return the value of the expression. - **SIZEOF (<string>)** - Return the size of the symbol, section, or segment. - **SIZEOF\_HEADERS** - Return the section start file offset. ## Symbol assignment Any symbol defined in a linker script becomes a global symbol. The following C assignment operators are supported to assign a value to a symbol: symbol = expression; symbol += expression; symbol -= expression; symbol *= expression; symbol /= expression; symbol &= expression; symbol |= expression; symbol <<= expression; symbol >>= expression; Copy to clipboard The first statement defines a symbol and assigns it the value of the expression. In the other statements, the symbol must already be defined. All the statements must be terminated with semicolons. A common way to create an empty space in memory is to use the .+=space\_size expression. For example, the following statement generates a section named BSS1 with size 0x2000: > > > `BSS1 { . += 0x2000 }` The linker script supports the following symbol assignment functions. > > > `HIDDEN ()` Hide the defined symbol so it is not exported. > > > `FILL ()` Specify the fill value for the current section. The fill length can be 1, 2, 4, or 8. The linker determines the length by selecting the minimum fit length. In the following example, the fill length is 8: > > > `FILL( 0xdeadc0de )` A FILL statement covers memory locations from the point at which it occurs to the end of the current section. Multiple FILL statements can be used in an output section definition to fill different parts of the section with different patterns. > > > `ASSERT (, )` When the specified expression is zero, the linker throws an assertion with the specified message string. > > > `PROVIDE ()` Similar to symbol assignment, but does not perform checking for an unresolved reference. > > > `PROVIDE_HIDDEN ()` Similar to PROVIDE, but hides the defined symbol so it will not be exported. > > > `PRINT ()` Instruct the linker to print symbol name and expression value to standard output during parsing. ## Linker script examples The following example linker scripts show how to specify input files for linking. The examples use the EXCLUDE\_FILE operator, which is defined in the input section descriptions ([Input section description](https://docs.qualcomm.com/doc/80-VB419-102/topic/linker_scripts.html#input-section-description)). ### Exclude file in archive To exclude a file in an archive from linking, specify the archive as part of the input expression, and specify the file to be excluded as the parameter of the following the EXCLUDE\_FILE operator. The following example uses four relocatable files: a1.o, a2.o, a3.o, and a4.o. Each file contains functions named foo\_N and bar\_N, where N indicates the digit in the file name. The linker script excludes foo\_2 but not bar\_2 from .text1 because EXCLUDE\_FILE applies only to the immediately following section name. script.t : SECTIONS { .text1 : { *lib23.a:(EXCLUDE_FILE(a2.o) .text.foo* .text.bar*) } .text2 : { *(*) } } clang -ffunction-sections -c a1.c a2.c a3.c a4.c arm-ar cr lib23.a a2.o a3.o arm-ar cr lib4.a a4.o arm-link -T script.t -o mcld.out a1.o --whole-archive lib23.a lib4.a --no- whole-archive Copy to clipboard Section headers starting at offset 0x22a0 are printed as follows: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text1 PROGBITS 00000000 001000 00002c 00 AX 0 0 16 [ 2] .text2 PROGBITS 00000030 002030 00009c 00 WAX 0 0 16 Copy to clipboard The symbol table is printed as follows: Num: Value Size Type Bind Vis Ndx Name Num: Value Size Type Bind Vis Ndx Name 8: 00000040 12 FUNC GLOBAL DEFAULT 2 bar_1 9: 00000000 12 FUNC GLOBAL DEFAULT 1 bar_2 10: 00000020 12 FUNC GLOBAL DEFAULT 1 bar_3 11: 000000c0 12 FUNC GLOBAL DEFAULT 2 bar_4 12: 00000030 12 FUNC GLOBAL DEFAULT 2 foo_1 13: 000000a0 12 FUNC GLOBAL DEFAULT 2 foo_2 14: 00000010 12 FUNC GLOBAL DEFAULT 1 foo_3 15: 000000b0 12 FUNC GLOBAL DEFAULT 2 foo_4 Copy to clipboard ### Exclude all files in archive To exclude all files in an archive from linking, specify the archive to be excluded as the parameter of the EXCLUDE\_FILE operator. The following example uses four relocatable files: a1.o, a2.o, a3.o, and a4.o. Each file contains functions named foo\_N and bar\_N, where N indicates the digit in the file name. The linker script excludes foo\_2/3 but not bar\_2/3 from .text1 because EXCLUDE\_FILE applies only to the immediately following section name. script.t : SECTIONS { .text1 : { *lib*:(EXCLUDE_FILE(*lib23.a) .text.foo* .text.bar*) } .text2 : { *(*) } } clang -ffunction-sections -c a1.c a2.c a3.c a4.c arm-ar cr lib23.a a2.o a3.o arm-ar cr lib4.a a4.o arm-link -T script.t -o mcld.out a1.o --whole-archive lib23.a lib4.a --no- whole-archive Copy to clipboard Section headers starting at offset 0x22a0 are printed as follows: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text1 PROGBITS 00000000 001000 00003c 00 AX 0 0 16 [ 2] .text2 PROGBITS 00000040 002040 00008c 00 WAX 0 0 16 Copy to clipboard The symbol table is printed as follows: Num: Value Size Type Bind Vis Ndx Name 8: 00000050 12 FUNC GLOBAL DEFAULT 2 bar_1 9: 00000000 12 FUNC GLOBAL DEFAULT 1 bar_2 10: 00000010 12 FUNC GLOBAL DEFAULT 1 bar_3 11: 00000030 12 FUNC GLOBAL DEFAULT 1 bar_4 12: 00000040 12 FUNC GLOBAL DEFAULT 2 foo_1 13: 000000b0 12 FUNC GLOBAL DEFAULT 2 foo_2 14: 000000c0 12 FUNC GLOBAL DEFAULT 2 foo_3 15: 00000020 12 FUNC GLOBAL DEFAULT 1 foo_4 Copy to clipboard ### Exclude multiple files To exclude multiple files from linking, specify the files as parameters of the EXCLUDE\_FILE operator. EXCLUDE\_FILE accepts multiple file name parameters. The following example uses four relocatable files: a1.o, a2.o, a3.o, and a4.o. Each file contains functions named foo\_N and bar\_N, where N indicates the digit in the file name. The linker script excludes foo\_2/3 but not bar\_2/3 from .text1 because EXCLUDE\_FILE applies only to the immediately following section name. script.t : SECTIONS { .text1 : { *lib*:(EXCLUDE_FILE(a2.0 a3.0) .text.foo* .text.bar*) } .text2 : { *(*) } } clang -ffunction-sections -c a1.c a2.c a3.c a4.c arm-ar cr lib23.a a2.o a3.o arm-ar cr lib4.a a4.o arm-link -T script.t -o mcld.out a1.o --whole-archive lib23.a lib4.a --no- whole-archive Copy to clipboard Section headers starting at offset 0x2260 are printed as follows: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text1 PROGBITS 00000000 001000 00003c 00 AX 0 0 16 [ 2] .text2 PROGBITS 00000040 002040 000040 00 WAX 0 0 16 Copy to clipboard The symbol table is printed as follows: Num: Value Size Type Bind Vis Ndx Name 8: 00000050 12 FUNC GLOBAL DEFAULT 2 bar_1 9: 00000000 12 FUNC GLOBAL DEFAULT 1 bar_2 10: 00000010 12 FUNC GLOBAL DEFAULT 1 bar_3 11: 00000030 12 FUNC GLOBAL DEFAULT 1 bar_4 12: 00000040 12 FUNC GLOBAL DEFAULT 2 foo_1 13: 00000060 12 FUNC GLOBAL DEFAULT 2 foo_2 14: 00000070 12 FUNC GLOBAL DEFAULT 2 foo_3 15: 00000020 12 FUNC GLOBAL DEFAULT 1 foo_4 Copy to clipboard ### Exclude archive and non-archive files To exclude archive and non-archive files from linking, specify the files as parameters of the EXCLUDE\_FILE operator. EXCLUDE\_FILE searches inside and outside archives for files to exclude. The following example uses four relocatable files: a1.o, a2.o, a3.o, and a4.o. Each file contains functions named foo\_N and bar\_N, where N indicates the digit in the file name. The linker script excludes foo\_1/2 but not bar\_1/2 from .text1 because EXCLUDE\_FILE applies only to the immediately following section name. script.t : SECTIONS { .text1 : { *:(EXCLUDE_FILE(a[12].o) .text.foo* .text.bar*) } .text2 : { *(*) } } clang -ffunction-sections -c a1.c a2.c a3.c a4.c arm-ar cr lib23.a a2.o a3.o arm-ar cr lib4.a a4.o arm-link -T script.t -o mcld.out a1.o --whole-archive lib23.a lib4.a --no- whole-archive Copy to clipboard Section headers starting at offset 0x2260 are printed as follows: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text1 PROGBITS 00000000 001000 00004c 00 AX 0 0 16 [ 2] .text2 PROGBITS 00000050 002050 000030 00 WAX 0 0 16 Copy to clipboard The symbol table is printed as follows: Num: Value Size Type Bind Vis Ndx Name 8: 00000060 12 FUNC GLOBAL DEFAULT 2 bar_1 9: 00000000 12 FUNC GLOBAL DEFAULT 1 bar_2 10: 00000020 12 FUNC GLOBAL DEFAULT 1 bar_3 11: 00000040 12 FUNC GLOBAL DEFAULT 1 bar_4 12: 00000050 12 FUNC GLOBAL DEFAULT 2 foo_1 13: 00000070 12 FUNC GLOBAL DEFAULT 2 foo_2 14: 00000010 12 FUNC GLOBAL DEFAULT 1 foo_3 15: 00000030 12 FUNC GLOBAL DEFAULT 1 foo_4 Copy to clipboard ### Conflicting wildcards To exclude archive and nonarchive files from linking, specify the files as parameters of the EXCLUDE\_FILE operator. EXCLUDE\_FILE earches inside and outside archives for files to exclude. The following example uses four relocatable files: a1.o, a2.o, a3.o, and a4.o. Each file contains functions named foo\_N and bar\_N, where N indicates the digit in the file name. The linker script excludes foo\_1/2 but not bar\_1/2 from .text1 because EXCLUDE\_FILE applies only to the immediately following section name. script.t : SECTIONS { .text1 : { *:(EXCLUDE_FILE(a[12].o) .text.foo* .text.bar*) } .text2 : { *(*) } } clang -ffunction-vb419sections -c a1.c a2.c a3.c a4.c arm-ar cr lib23.a a2.o a3.o arm-ar cr lib4.a a4.o arm-link -T script.t -o mcld.out a1.o --whole-archive lib23.a lib4.a --no- whole-archive Copy to clipboard Section headers starting at offset 0x2260 are printed as follows: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text1 PROGBITS 00000000 001000 00004c 00 AX 0 0 16 [ 2] .text2 PROGBITS 00000050 002050 000030 00 WAX 0 0 16 Copy to clipboard The symbol table is printed as follows: Num: Value Size Type Bind Vis Ndx Name 8: 00000060 12 FUNC GLOBAL DEFAULT 2 bar_1 9: 00000000 12 FUNC GLOBAL DEFAULT 1 bar_2 10: 00000020 12 FUNC GLOBAL DEFAULT 1 bar_3 11: 00000040 12 FUNC GLOBAL DEFAULT 1 bar_4 12: 00000050 12 FUNC GLOBAL DEFAULT 2 foo_1 13: 00000070 12 FUNC GLOBAL DEFAULT 2 foo_2 14: 00000010 12 FUNC GLOBAL DEFAULT 1 foo_3 15: 00000030 12 FUNC GLOBAL DEFAULT 1 foo_4 Copy to clipboard ### GNU linker options This section lists all GNU linker options (arranged by linker support and no linker support). The slashes (/) in certain options indicate aliases for those options. #### [Options supported by the linker](https://docs.qualcomm.com/doc/80-VB419-102/topic/linker_scripts.html#id11) @FILE | --allow-multiple-definition --allow-shlib-undefined | --no-allow-shlib-undefined --as-needed | --no-as-needed -Bdynamic / -dy / -call_shared | -Bgroup -Bstatic / -dn / -non_shared / -static -Bsymbolic | -Bsymbolic-functions --build-id[=