Defining the contents of a sections segment includes specifying the source file of each section. The standard method is merely listing the files, as The following listing shows.
SECTIONS { .example_section : { main.obj (.text) file2.obj (.text) file3.obj (.text) # and so forth
The object file and its path should be part of linker command line option if the file is not part of project. For a large project, however, such a list can be very long. To shorten it, you can use the asterisk ( * ) wild-card character, which represents the names of every file in your project. The line
* (.text)
in a section definition tells the system to include the .text section from each file.
Furthermore the * wildcard does not duplicate sections already specified; you need not replace existing lines of the code. In the following listing, replacing the # and so forth comment line with
* (.text)
would add the .text sections from all other project files, without duplicating the .text sections from files main.c, file2.c, or file3.c.
Once * is used any other use of file (.text) will be ignored because the linker makes a single pass thru the .lcf.
For precise control over function placement within a section, use the OBJECT keyword. For example, to place functions beta and alpha before anything else in a section, your definition could be like the following listing.
SECTIONS { .program_section : { OBJECT (beta, main.c) # Function beta is 1st section item OBJECT (alpha, main.c) # Function alpha is 2nd section_item * (.text) # Remaining_items are .text sections from all files } > ROOT
If you use the OBJECT keyword to specify a function, subsequently using * wild-card character does not specify that function a second time.
For more information about specifying files and functions, see the topics OBJECT and SECTIONS of this manual.