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 shows.
SECTIONS { .example_section : { main.c (.text) file2.c (.text) file3.c (.text) # and so forth
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 name 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 Listing: Standard Source-File Specification, 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 explanations OBJECT and SECTIONS.