@@ -48,87 +48,86 @@ PROVIDE(SysTick = DefaultHandler);
48
48
/* # Interrupt vectors */
49
49
EXTERN(__INTERRUPTS); /* `static` variable similar to `__EXCEPTIONS` */
50
50
51
- /* # User overridable symbols I */
52
- /* Lets the user place the stack in a different RAM region */
53
- PROVIDE(_stack_start = ORIGIN(RAM) + LENGTH(RAM));
54
-
55
51
/* # Sections */
56
52
SECTIONS
57
53
{
54
+ PROVIDE(_stack_start = ORIGIN(RAM) + LENGTH(RAM));
55
+
58
56
/* ## Sections in FLASH */
59
57
/* ### Vector table */
60
- .vector_table ORIGIN(FLASH) : ALIGN(4)
58
+ .vector_table ORIGIN(FLASH) :
61
59
{
62
60
/* Initial Stack Pointer (SP) value */
63
- __STACK_START = .; /* Just to get a nicer name in the disassembly */
64
61
LONG(_stack_start);
65
62
66
63
/* Reset vector */
67
- KEEP(*(.vector_table.reset_vector)); /* this is `__RESET_VECTOR` symbol */
68
- __reset_vector = ABSOLUTE(.) ;
64
+ KEEP(*(.vector_table.reset_vector)); /* this is the `__RESET_VECTOR` symbol */
65
+ __reset_vector = . ;
69
66
70
67
/* Exceptions */
71
- KEEP(*(.vector_table.exceptions)); /* this is `__EXCEPTIONS` symbol */
72
- __eexceptions = ABSOLUTE(.) ;
68
+ KEEP(*(.vector_table.exceptions)); /* this is the `__EXCEPTIONS` symbol */
69
+ __eexceptions = . ;
73
70
74
71
/* Device specific interrupts */
75
- KEEP(*(.vector_table.interrupts)); /* this is `__INTERRUPTS` symbol */
76
- __einterrupts = ABSOLUTE(.);
72
+ KEEP(*(.vector_table.interrupts)); /* this is the `__INTERRUPTS` symbol */
77
73
} > FLASH
78
74
75
+ PROVIDE(_stext = ADDR(.vector_table) + SIZEOF(.vector_table));
76
+
79
77
/* ### .text */
80
78
.text _stext :
81
79
{
82
80
*(.text .text.*);
83
- __etext = ABSOLUTE(.);
84
81
} > FLASH
85
82
86
83
/* ### .rodata */
87
84
.rodata :
88
85
{
89
- . = ALIGN(4); /* 4-byte align the start (VMA) of this section */
90
- /* __srodata = ABSOLUTE(.); */
91
-
92
86
*(.rodata .rodata.*);
93
87
94
- . = ALIGN(4); /* 4-byte align the end (VMA) of this section */
95
- __erodata = ABSOLUTE(.);
88
+ /* 4-byte align the end (VMA) of this section */
89
+ /* WHY? To my knowledge there's no way to indicate the alignment of *LMA* so we align *this*
90
+ section with the goal of using its end address as the LMA of .data */
91
+ . = ALIGN(4);
96
92
} > FLASH
97
93
98
94
/* ## Sections in RAM */
99
95
/* ### .data */
100
- .data : AT(__erodata ) /* LMA */
96
+ .data : AT(ADDR(.rodata) + SIZEOF(.rodata) ) /* LMA */
101
97
{
102
- . = ALIGN(4); /* 4-byte align the start (VMA) of this section */
103
- __sdata = ABSOLUTE(.);
104
-
105
98
*(.data .data.*);
106
99
107
100
. = ALIGN(4); /* 4-byte align the end (VMA) of this section */
108
- __edata = ABSOLUTE(.);
109
101
} > RAM
110
102
103
+ /* VMA of .data */
104
+ __sdata = ADDR(.data);
105
+ __edata = ADDR(.data) + SIZEOF(.data);
106
+
107
+ /* LMA of .data */
108
+ __sidata = LOADADDR(.data);
109
+
111
110
/* ### .bss */
112
111
.bss :
113
112
{
114
- . = ALIGN(4); /* 4-byte align the start (VMA) of this section */
115
- __sbss = ABSOLUTE(.);
116
-
117
113
*(.bss .bss.*);
118
114
119
115
. = ALIGN(4); /* 4-byte align the end (VMA) of this section */
120
- __ebss = ABSOLUTE(.);
121
116
} > RAM
122
117
123
- /* ## Fake output .got section */
118
+ __sbss = ADDR(.bss);
119
+ __ebss = ADDR(.bss) + SIZEOF(.bss);
120
+
121
+ /* Place the heap right after `.bss` */
122
+ __sheap = ADDR(.bss) + SIZEOF(.bss);
123
+
124
+ /* ## .got */
124
125
/* Dynamic relocations are unsupported. This section is only used to detect relocatable code in
125
126
the input files and raise an error if relocatable code is found */
126
- .got :
127
+ .got (NOLOAD) :
127
128
{
128
- __sgot = ABSOLUTE(.);
129
129
KEEP(*(.got .got.*));
130
- __egot = ABSOLUTE(.);
131
- } > FLASH
130
+ }
132
131
133
132
/* ## Discarded sections */
134
133
/DISCARD/ :
@@ -138,67 +137,56 @@ SECTIONS
138
137
}
139
138
}
140
139
141
- /* # User overridable symbols II */
142
- /* (The user overridable symbols are split in two parts because LLD demands that the RHS of PROVIDE
143
- to be defined before the PROVIDE invocation) */
144
- /* Lets the user override this to place .text a bit further than the vector table. Required by
145
- microcontrollers that store their configuration right after the vector table. */
146
- PROVIDE(_stext = __einterrupts);
140
+ /* Do not exceed this mark in the error messages below | */
141
+ /* # Alignment checks */
142
+ ASSERT(ORIGIN(FLASH) % 4 == 0, "
143
+ ERROR(cortex-m-rt): the start of the FLASH region must be 4-byte aligned");
147
144
148
- /* # Hardcoded symbols */
149
- /* Place `.bss` at the start of the RAM region */
150
- __sidata = LOADADDR(.data);
151
- /* Place the heap right after `.bss` and `.data` */
152
- __sheap = __ebss;
145
+ ASSERT(ORIGIN(RAM) % 4 == 0, "
146
+ ERROR(cortex-m-rt): the start of the RAM region must be 4-byte aligned");
153
147
154
- /* # Sanity checks */
148
+ ASSERT(__sdata % 4 == 0 && __edata % 4 == 0, "
149
+ BUG(cortex-m-rt): .data is not 4-byte aligned");
155
150
156
- /* Do not exceed this mark in the error messages below | */
157
- ASSERT(__reset_vector == ORIGIN(FLASH) + 0x8, "
158
- cortex-m-rt: The reset vector is missing. This is a bug in cortex-m-rt. Please file a bug
159
- report at: https://github.com/japaric/cortex-m-rt/issues");
160
-
161
- ASSERT(__eexceptions - ORIGIN(FLASH) == 0x40, "
162
- cortex-m-rt: The exception vectors are missing. This is a bug in cortex-m-rt. Please file
163
- a bug report at: https://github.com/japaric/cortex-m-rt/issues");
164
-
165
- ASSERT(__sheap >= __ebss, "
166
- cortex-m-rt: The heap overlaps with the .bss section. This is a bug in cortex-m-rt. Please
167
- file a bug report at: https://github.com/japaric/cortex-m-rt/issues");
168
-
169
- ASSERT(__sheap >= __edata, "
170
- cortex-m-rt: The heap overlaps with the .data section. This is a bug in cortex-m-rt.
171
- Please file a bug report at: https://github.com/japaric/cortex-m-rt/issues");
172
-
173
- ASSERT(__einterrupts - __eexceptions > 0, "
174
- cortex-m-rt: The interrupt vectors are missing. Possible solutions, from most likely to
175
- less likely:
176
- - Link to a device crate
177
- - Disable the 'device' feature of cortex-m-rt to build a generic application (a dependency
178
- may be enabling it)
179
- - Supply the interrupt handlers yourself. Check the documentation for details.");
151
+ ASSERT(__sidata % 4 == 0, "
152
+ BUG(cortex-m-rt): the LMA of .data is not 4-byte aligned");
153
+
154
+ ASSERT(__sbss % 4 == 0 && __ebss % 4 == 0, "
155
+ BUG(cortex-m-rt): .bss is not 4-byte aligned");
180
156
181
- ASSERT(__einterrupts <= _stext, "
182
- cortex-m-rt: The '.text' section can't be placed inside the '.vector_table' section. Set
183
- '_stext' to an address greater than '__einterrupts' (cf. `nm` output)");
157
+ ASSERT(__sheap % 4 == 0, "
158
+ BUG(cortex-m-rt): start of .heap is not 4-byte aligned");
184
159
185
- ASSERT(_stext < ORIGIN(FLASH) + LENGTH(FLASH), "
186
- cortex-m-rt The '.text' section must be placed inside the FLASH memory. Set '_stext' to an
187
- address smaller than 'ORIGIN(FLASH) + LENGTH(FLASH)");
160
+ /* # Position checks */
188
161
189
- /* This has been temporarily omitted because it's not supported by LLD */
190
- /* ASSERT(__sbss % 4 == 0 && __ebss % 4 == 0 , " */
191
- /* .bss is not 4-byte aligned at its boundaries. This is a cortex-m-rt bug. "); */
162
+ /* ## .vector_table */
163
+ ASSERT(__reset_vector == ADDR(.vector_table) + 0x8 , "
164
+ BUG(cortex-m-rt): the reset vector is missing ");
192
165
193
- /* ASSERT(__sdata % 4 == 0 && __edata % 4 == 0 , " */
194
- /* .data is not 4-byte aligned at its boundaries. This is a cortex-m-rt bug. "); */
166
+ ASSERT(__eexceptions == ADDR(.vector_table) + 0x40 , "
167
+ BUG( cortex-m-rt): the exception vectors are missing ");
195
168
196
- /* ASSERT(__sidata % 4 == 0, " */
197
- /* __sidata is not 4-byte aligned. This is a cortex-m-rt bug."); */
169
+ ASSERT(SIZEOF(.vector_table) > 0x40, "
170
+ ERROR(cortex-m-rt): The interrupt vectors are missing.
171
+ Possible solutions, from most likely to less likely:
172
+ - Link to a svd2rust generated device crate
173
+ - Disable the 'device' feature of cortex-m-rt to build a generic application (a dependency
174
+ may be enabling it)
175
+ - Supply the interrupt handlers yourself. Check the documentation for details.");
198
176
199
- ASSERT(__sgot == __egot, "
200
- .got section detected in the input object files. Dynamic relocations are not supported.
201
- If you are linking to C code compiled using the `cc` crate then modify your build script
202
- to compile the C code _without_ the -fPIC flag. See the documentation of the
203
- `cc::Build.pic` method for details.");
177
+ /* ## .text */
178
+ ASSERT(ADDR(.vector_table) + SIZEOF(.vector_table) <= _stext, "
179
+ ERROR(cortex-m-rt): The .text section can't be placed inside the .vector_table section
180
+ Set _stext to an address greater than the end of .vector_table (See output of `nm`)");
181
+
182
+ ASSERT(_stext + SIZEOF(.text) < ORIGIN(FLASH) + LENGTH(FLASH), "
183
+ ERROR(cortex-m-rt): The .text section must be placed inside the FLASH memory.
184
+ Set _stext to an address smaller than 'ORIGIN(FLASH) + LENGTH(FLASH)'");
185
+
186
+ /* # Other checks */
187
+ ASSERT(SIZEOF(.got) == 0, "
188
+ ERROR(cortex-m-rt): .got section detected in the input object files
189
+ Dynamic relocations are not supported. If you are linking to C code compiled using
190
+ the 'cc' crate then modify your build script to compile the C code _without_
191
+ the -fPIC flag. See the documentation of the `cc::Build.pic` method for details.");
204
192
/* Do not exceed this mark in the error messages above | */
0 commit comments