blob: 0cdbb2fa2597a196994eabb97b223f764607e803 [file] [log] [blame]
Aaron Durbinad935522012-12-24 14:28:37 -06001OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
2OUTPUT_ARCH(i386)
3
4/*
5 * This linker script is used to link rmodules (relocatable modules). It
6 * links at zero so that relocation fixups are easy when placing the binaries
7 * anywhere in the address space.
8 *
9 * NOTE: The program's loadable sections (text, module_params, and data) are
10 * packed into the flat blob using the AT directive. The rmodule loader assumes
11 * the entire program resides in one contiguous address space. Therefore,
12 * alignment for a given section (if required) needs to be done at the end of
13 * the preceeding section. e.g. if the data section should be aligned to an 8
14 * byte address the text section should have ALIGN(8) at the end of its section.
15 * Otherwise there won't be a consistent mapping between the flat blob and the
16 * loaded program.
17 */
18
19BASE_ADDRESS = 0x00000;
20
21SECTIONS
22{
23 . = BASE_ADDRESS;
24
25 .header : AT (0) {
26 *(.module_header);
27 . = ALIGN(8);
28 }
29
30 /* Align the start of the module program to a large enough alignment
31 * so that any data in the program with an alignement property is met.
32 * Essentially, this alignment is the maximum possible data alignment
33 * property a program can have. */
34 . = ALIGN(4096);
35 _module_link_start_addr = .;
36 _payload_begin_offset = LOADADDR(.header) + SIZEOF(.header);
37
Aaron Durbine1be5ae2013-04-29 13:53:41 -050038 .payload : AT (_payload_begin_offset) {
Aaron Durbinad935522012-12-24 14:28:37 -060039 /* C code of the module. */
Aaron Durbind23e292e2013-03-22 19:55:35 -050040 *(.textfirst);
Aaron Durbinad935522012-12-24 14:28:37 -060041 *(.text);
42 *(.text.*);
43 /* C read-only data. */
44 . = ALIGN(16);
Aaron Durbinf7c6d482013-02-06 15:47:31 -060045
Aaron Durbind23e292e2013-03-22 19:55:35 -050046 __CTOR_LIST__ = .;
47 *(.ctors);
48 LONG(0);
49 __CTOR_END__ = .;
50
Aaron Durbinf7c6d482013-02-06 15:47:31 -060051 /* The driver sections are to allow linking coreboot's
52 * ramstage with the rmodule linker. Any changes made in
53 * coreboot_ram.ld should be made here as well. */
54 console_drivers = .;
55 *(.rodata.console_drivers)
56 econsole_drivers = . ;
57 . = ALIGN(4);
58 pci_drivers = . ;
59 *(.rodata.pci_driver)
60 epci_drivers = . ;
61 cpu_drivers = . ;
62 *(.rodata.cpu_driver)
63 ecpu_drivers = . ;
Aaron Durbina4feddf2013-04-24 16:12:52 -050064 _bs_init_begin = .;
65 *(.bs_init)
66 _bs_init_end = .;
67
Aaron Durbinf7c6d482013-02-06 15:47:31 -060068 . = ALIGN(4);
69
Aaron Durbinad935522012-12-24 14:28:37 -060070 *(.rodata);
71 *(.rodata.*);
72 . = ALIGN(4);
Aaron Durbinad935522012-12-24 14:28:37 -060073
Aaron Durbinad935522012-12-24 14:28:37 -060074 /* The parameters section can be used to pass parameters
75 * to a module, however there has to be an prior agreement
76 * on how to interpret the parameters. */
77 _module_params_begin = .;
78 *(.module_parameters);
79 _module_params_end = .;
Aaron Durbine1be5ae2013-04-29 13:53:41 -050080 . = ALIGN(8);
Aaron Durbinad935522012-12-24 14:28:37 -060081
Aaron Durbine1be5ae2013-04-29 13:53:41 -050082 /* Data section. */
Aaron Durbinad935522012-12-24 14:28:37 -060083 _sdata = .;
84 *(.data);
85 . = ALIGN(4);
86 _edata = .;
Aaron Durbine1be5ae2013-04-29 13:53:41 -050087
88 . = ALIGN(8);
Aaron Durbinad935522012-12-24 14:28:37 -060089 }
90
91 /* _payload_end marks the end of the module's code and data. */
Aaron Durbine1be5ae2013-04-29 13:53:41 -050092 _payload_end_offset = LOADADDR(.payload) + SIZEOF(.payload);
Aaron Durbinad935522012-12-24 14:28:37 -060093
94 .bss (NOLOAD) : {
Aaron Durbinf7c6d482013-02-06 15:47:31 -060095 /* C uninitialized data of the module. */
96 _bss = .;
Aaron Durbinad935522012-12-24 14:28:37 -060097 *(.bss);
98 *(.sbss);
99 *(COMMON);
100 . = ALIGN(8);
Aaron Durbinf7c6d482013-02-06 15:47:31 -0600101 _ebss = .;
Aaron Durbinad935522012-12-24 14:28:37 -0600102
Aaron Durbinad935522012-12-24 14:28:37 -0600103 /*
104 * Place the heap after BSS. The heap size is passed in by
105 * by way of ld --defsym=__heap_size=<>
106 */
107 _heap = .;
108 . = . + __heap_size;
109 _eheap = .;
110 }
111
112 /* _module_program_size is the total memory used by the program. */
113 _module_program_size = _eheap - _module_link_start_addr;
114
Aaron Durbinf7c6d482013-02-06 15:47:31 -0600115 /* coreboot's ramstage uses the _ram_seg and _eram_seg symbols
116 * for determining its load location. Provide those to help it out.
117 * It's a nop for any non-ramstage rmodule. */
118 _ram_seg = _module_link_start_addr;
119 _eram_seg = _module_link_start_addr + _module_program_size;
120
Aaron Durbinad935522012-12-24 14:28:37 -0600121 /* The relocation information is linked on top of the BSS section
122 * because the BSS section takes no space on disk. The relocation data
123 * resides directly after the data section in the flat binary. */
124 .relocations ADDR(.bss) : AT (_payload_end_offset) {
125 *(.rel.*);
126 }
127 _relocations_begin_offset = LOADADDR(.relocations);
128 _relocations_end_offset = _relocations_begin_offset +
129 SIZEOF(.relocations);
130
131 /DISCARD/ : {
132 /* Drop unnecessary sections. Since these modules are linked
133 * as shared objects there are dynamic sections. These sections
134 * aren't needed so drop them. */
135 *(.comment);
136 *(.note);
137 *(.note.*);
138 *(.dynamic);
139 *(.dynsym);
140 *(.dynstr);
141 *(.gnu.hash);
142 *(.eh_frame);
143 }
144}