blob: 41d6357fe13b07d3b666d527aef658a44d434bda [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
38 .text : AT (_payload_begin_offset) {
39 /* 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 = . ;
64 . = ALIGN(4);
65
Aaron Durbinad935522012-12-24 14:28:37 -060066 *(.rodata);
67 *(.rodata.*);
68 . = ALIGN(4);
69 }
70
71 .module_params : AT (LOADADDR(.text) + SIZEOF(.text)) {
72 /* The parameters section can be used to pass parameters
73 * to a module, however there has to be an prior agreement
74 * on how to interpret the parameters. */
75 _module_params_begin = .;
76 *(.module_parameters);
77 _module_params_end = .;
78 . = ALIGN(4);
79 }
80
81 .data : AT (LOADADDR(.module_params) + SIZEOF(.module_params)) {
82 _sdata = .;
83 *(.data);
84 . = ALIGN(4);
85 _edata = .;
86 }
87
88 /* _payload_end marks the end of the module's code and data. */
89 _payload_end_offset = LOADADDR(.data) + SIZEOF(.data);
90
91 .bss (NOLOAD) : {
Aaron Durbinf7c6d482013-02-06 15:47:31 -060092 /* C uninitialized data of the module. */
93 _bss = .;
Aaron Durbinad935522012-12-24 14:28:37 -060094 *(.bss);
95 *(.sbss);
96 *(COMMON);
97 . = ALIGN(8);
Aaron Durbinf7c6d482013-02-06 15:47:31 -060098 _ebss = .;
Aaron Durbinad935522012-12-24 14:28:37 -060099
Aaron Durbinad935522012-12-24 14:28:37 -0600100 /*
101 * Place the heap after BSS. The heap size is passed in by
102 * by way of ld --defsym=__heap_size=<>
103 */
104 _heap = .;
105 . = . + __heap_size;
106 _eheap = .;
107 }
108
109 /* _module_program_size is the total memory used by the program. */
110 _module_program_size = _eheap - _module_link_start_addr;
111
Aaron Durbinf7c6d482013-02-06 15:47:31 -0600112 /* coreboot's ramstage uses the _ram_seg and _eram_seg symbols
113 * for determining its load location. Provide those to help it out.
114 * It's a nop for any non-ramstage rmodule. */
115 _ram_seg = _module_link_start_addr;
116 _eram_seg = _module_link_start_addr + _module_program_size;
117
Aaron Durbinad935522012-12-24 14:28:37 -0600118 /* The relocation information is linked on top of the BSS section
119 * because the BSS section takes no space on disk. The relocation data
120 * resides directly after the data section in the flat binary. */
121 .relocations ADDR(.bss) : AT (_payload_end_offset) {
122 *(.rel.*);
123 }
124 _relocations_begin_offset = LOADADDR(.relocations);
125 _relocations_end_offset = _relocations_begin_offset +
126 SIZEOF(.relocations);
127
128 /DISCARD/ : {
129 /* Drop unnecessary sections. Since these modules are linked
130 * as shared objects there are dynamic sections. These sections
131 * aren't needed so drop them. */
132 *(.comment);
133 *(.note);
134 *(.note.*);
135 *(.dynamic);
136 *(.dynsym);
137 *(.dynstr);
138 *(.gnu.hash);
139 *(.eh_frame);
140 }
141}