Contents|Index|Previous|Next

Section Placement

In a section definition, you can specify the contents of an output section by listing particular input files, by listing particular input-file sections, or by a combination of the two. You can also place arbitrary data in the section, and define symbols relative to the beginning of the section. The contents of a section definition may include any of the following kinds of statement. You can include as many of these as you like in a single section definition, separated from one another by whitespace.

filename
You may simply name a particular input file to be placed in the current output section; all sections from that file are placed in the current section definition. If the file name has already been mentioned in another section definition, with an explicit section name list, then only those sections which have not yet been allocated are used. To specify a list of particular files by name, use the following example.

.data : { afile.o bfile.o cfile.o }

The example also illustrates that multiple statements can be included in the contents of a section definition, since each file name is a separate statement.

filename( section)
filename( section, section, ...)
filename( section section ...)
You can name one or more sections from your input files, for insertion in the current output section.

If you wish to specify a list of input-file sections inside the parentheses, you may separate the section names by either commas or whitespace.

*(section)
*(section, section, ...)
*(section section ...)
Instead of explicitly naming particular input files in a link control script, you can refer to all files from the ld command line: use ‘*’ instead of a particular file name before the parenthesized input-file section list.

If you have already explicitly included some files by name, ‘*’ refers to all remaining files—those whose places in the output file have not yet been defined. For instance, to copy sections 1 through 4 from an Oasys file into the .text section of an a.out file, and sections 13 and 14 into the .data section, use input like the following example.

SECTIONS {
.text :{
*("1" "2" "3" "4")
}
.data :{
*("13" "14")
}
}

‘[ section ...]’ used to be accepted as an alternate way to specify named sections from all unallocated input files.

Because some operating systems (VMS) allow brackets in file names, that notation is no longer supported.

filename( COMMON )
*( COMMON )
Specify where in your output file to place uninitialized data with this notation. *(COMMON) by itself refers to all uninitialized data from all input files (so far as it is not yet allocated); filename(COMMON) refers to uninitialized data from a particular file.

Both are special cases of the general mechanisms for specifying where to place input-file sections.

ld permits you to refer to uninitialized data as if it were in an input-file section named COMMON, regardless of the input file’s format.

For example, the following command script arranges the output file into three consecutive sections, named .text, .data, and .bss, taking the input for each from the correspondingly named sections of all the input files.

SECTIONS {
.text : { *(.text) }
.data : { *(.data) }
.bss : { *(.bss) *(COMMON) }
}

The following example reads all of the sections from file all.o and places them at the start of output section outputa which starts at location 0x10000. All of section .input1 from file foo.o follows immediately, in the same output section. All of section .input2 from foo.o goes into output section outputb, followed by section .input1 from foo1.o. All of the remaining .input1 and .input2 sections from any files are written to output section outputc.

SECTIONS {
outputa 0x10000 :
{
all.o
foo.o (.input1)
}
outputb :
{
foo.o (.input2)
foo1.o (.input1)
}
outputc :
{
*(.input1)
*(.input2)
}
}