Skip to content

Commit af55745

Browse files
committed
changed all linkerscripts to use macros
1 parent c4668b5 commit af55745

18 files changed

Lines changed: 113 additions & 827 deletions

File tree

targets/arm/linkerscript/linkerscript.ld

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/* helpers to combine strings with a parameter */
2+
#define COMBINE_STRX(a,b) a##b
3+
#define COMBINE_STR2(a,b) COMBINE_STRX(a,b)
4+
#define COMBINE_STR3(a,b,c) COMBINE_STR2(COMBINE_STR2(a,b),c)
5+
16
/* macro to define the vectors section. Should be pointed to the correct memory region */
27
#define VECTORS() \
38
.vectors (READONLY) : \
@@ -7,3 +12,24 @@
712
KEEP(*(.vectors .vectors.*)); \
813
. = ALIGN(4); \
914
}
15+
16+
/* macro to define the rodata section */
17+
#define RODATA() \
18+
.rodata (READONLY) : \
19+
{ \
20+
. = ALIGN(4); \
21+
/* Constands, strings, etc */ \
22+
*(.rodata .rodata.* .gnu.linkonce.r.*); \
23+
. = ALIGN(4); \
24+
}
25+
26+
/* macro to define a init array. Array name is passed as an argument */
27+
#define INIT_ARRAY(name) \
28+
.name : \
29+
{ \
30+
. = ALIGN(4); \
31+
PROVIDE(COMBINE_STR3(__,name,_start) = .); \
32+
KEEP(*(SORT(.name.*))) \
33+
KEEP(*(SORT(.name))) \
34+
PROVIDE(COMBINE_STR3(__,name,_end) = .); \
35+
}

targets/chip/atsam3x8e/linkerscript.ld

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,7 @@ SECTIONS
3333
{
3434
/* Vector table. Has the initial stack pointer and the initial
3535
structure for the arm interrupts */
36-
.vectors :
37-
{
38-
. = ALIGN(4);
39-
/* vector table */
40-
KEEP(*(.vectors .vectors.*));
41-
. = ALIGN(4);
42-
} > rom
36+
VECTORS() > rom
4337

4438
/* Text segment, stores all user code */
4539
.text :
@@ -66,50 +60,13 @@ SECTIONS
6660
} > rom
6761

6862
/* Read only data */
69-
.rodata :
70-
{
71-
. = ALIGN(4);
72-
73-
/* Constands, strings, etc */
74-
*(.rodata .rodata.* .gnu.linkonce.r.*);
75-
76-
. = ALIGN(4);
77-
} > rom
63+
RODATA() > rom
7864

7965
/* Support C constructors, and C destructors in both user code
8066
and the C library. This also provides support for C++ code. */
81-
.preinit_array :
82-
{
83-
. = ALIGN(4);
84-
PROVIDE(__preinit_array_start = .);
85-
86-
KEEP(*(SORT(.preinit_array.*)))
87-
KEEP(*(SORT(.preinit_array)))
88-
89-
PROVIDE(__preinit_array_end = .);
90-
} > rom
91-
92-
.init_array :
93-
{
94-
. = ALIGN(4);
95-
PROVIDE(__init_array_start = .);
96-
97-
KEEP(*(SORT(.init_array.*)))
98-
KEEP(*(SORT(.init_array)))
99-
100-
PROVIDE(__init_array_end = .);
101-
} > rom
102-
103-
.fini_array :
104-
{
105-
. = ALIGN(4);
106-
PROVIDE(__fini_array_start = .);
107-
108-
KEEP(*(SORT(.fini_array.*)))
109-
KEEP(*(SORT(.fini_array)))
110-
111-
PROVIDE(__fini_array_end = .);
112-
} > rom
67+
INIT_ARRAY(preinit_array) > rom
68+
INIT_ARRAY(init_array) > rom
69+
INIT_ARRAY(fini_array) > rom
11370

11471
/* Stack segment */
11572
.stack (NOLOAD) :

targets/chip/atsam4s2b/linkerscript.ld

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,7 @@ SECTIONS
3333
{
3434
/* Vector table. Has the initial stack pointer and the initial
3535
structure for the arm interrupts */
36-
.vectors :
37-
{
38-
. = ALIGN(4);
39-
/* vector table */
40-
KEEP(*(.vectors .vectors.*));
41-
. = ALIGN(4);
42-
} > rom
36+
VECTORS() > rom
4337

4438
/* Text segment, stores all user code */
4539
.text :
@@ -66,51 +60,13 @@ SECTIONS
6660
} > rom
6761

6862
/* Read only data */
69-
.rodata :
70-
{
71-
. = ALIGN(4);
72-
73-
/* Constands, strings, etc */
74-
*(.rodata .rodata.* .gnu.linkonce.r.*);
75-
76-
. = ALIGN(4);
77-
} > rom
63+
RODATA() > rom
7864

7965
/* Support C constructors, and C destructors in both user code
8066
and the C library. This also provides support for C++ code. */
81-
.preinit_array :
82-
{
83-
. = ALIGN(4);
84-
PROVIDE(__preinit_array_start = .);
85-
86-
KEEP(*(SORT(.preinit_array.*)))
87-
KEEP(*(SORT(.preinit_array)))
88-
89-
PROVIDE(__preinit_array_end = .);
90-
} > rom
91-
92-
.init_array :
93-
{
94-
. = ALIGN(4);
95-
PROVIDE(__init_array_start = .);
96-
97-
KEEP(*(SORT(.init_array.*)))
98-
KEEP(*(SORT(.init_array)))
99-
100-
PROVIDE(__init_array_end = .);
101-
} > rom
102-
103-
.fini_array :
104-
{
105-
. = ALIGN(4);
106-
PROVIDE(__fini_array_start = .);
107-
108-
KEEP(*(SORT(.fini_array.*)))
109-
KEEP(*(SORT(.fini_array)))
110-
111-
PROVIDE(__fini_array_end = .);
112-
} > rom
113-
67+
INIT_ARRAY(preinit_array) > rom
68+
INIT_ARRAY(init_array) > rom
69+
INIT_ARRAY(fini_array) > rom
11470
/* Stack segment */
11571
.stack (NOLOAD) :
11672
{

targets/chip/lpc1752/linkerscript.ld

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,7 @@ SECTIONS
3333
{
3434
/* Vector table. Has the initial stack pointer and the initial
3535
structure for the arm interrupts */
36-
.vectors :
37-
{
38-
. = ALIGN(4);
39-
/* vector table */
40-
KEEP(*(.vectors .vectors.*));
41-
. = ALIGN(4);
42-
} > rom
36+
VECTORS() > rom
4337

4438
.crp 0x000002fc :
4539
{
@@ -81,51 +75,13 @@ SECTIONS
8175
} > rom
8276

8377
/* Read only data */
84-
.rodata :
85-
{
86-
. = ALIGN(4);
87-
88-
/* Constands, strings, etc */
89-
*(.rodata .rodata.* .gnu.linkonce.r.*);
90-
91-
. = ALIGN(4);
92-
} > rom
78+
RODATA() > rom
9379

9480
/* Support C constructors, and C destructors in both user code
9581
and the C library. This also provides support for C++ code. */
96-
.preinit_array :
97-
{
98-
. = ALIGN(4);
99-
PROVIDE(__preinit_array_start = .);
100-
101-
KEEP(*(SORT(.preinit_array.*)))
102-
KEEP(*(SORT(.preinit_array)))
103-
104-
PROVIDE(__preinit_array_end = .);
105-
} > rom
106-
107-
.init_array :
108-
{
109-
. = ALIGN(4);
110-
PROVIDE(__init_array_start = .);
111-
112-
KEEP(*(SORT(.init_array.*)))
113-
KEEP(*(SORT(.init_array)))
114-
115-
PROVIDE(__init_array_end = .);
116-
} > rom
117-
118-
.fini_array :
119-
{
120-
. = ALIGN(4);
121-
PROVIDE(__fini_array_start = .);
122-
123-
KEEP(*(SORT(.fini_array.*)))
124-
KEEP(*(SORT(.fini_array)))
125-
126-
PROVIDE(__fini_array_end = .);
127-
} > rom
128-
82+
INIT_ARRAY(preinit_array) > rom
83+
INIT_ARRAY(init_array) > rom
84+
INIT_ARRAY(fini_array) > rom
12985
/* Stack segment */
13086
.stack (NOLOAD) :
13187
{

targets/chip/lpc1754/linkerscript.ld

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,7 @@ SECTIONS
3434
{
3535
/* Vector table. Has the initial stack pointer and the initial
3636
structure for the arm interrupts */
37-
.vectors :
38-
{
39-
. = ALIGN(4);
40-
/* vector table */
41-
KEEP(*(.vectors .vectors.*));
42-
. = ALIGN(4);
43-
} > rom
37+
VECTORS() > rom
4438

4539
.crp 0x000002fc :
4640
{
@@ -82,51 +76,13 @@ SECTIONS
8276
} > rom
8377

8478
/* Read only data */
85-
.rodata :
86-
{
87-
. = ALIGN(4);
88-
89-
/* Constands, strings, etc */
90-
*(.rodata .rodata.* .gnu.linkonce.r.*);
91-
92-
. = ALIGN(4);
93-
} > rom
79+
RODATA() > rom
9480

9581
/* Support C constructors, and C destructors in both user code
9682
and the C library. This also provides support for C++ code. */
97-
.preinit_array :
98-
{
99-
. = ALIGN(4);
100-
PROVIDE(__preinit_array_start = .);
101-
102-
KEEP(*(SORT(.preinit_array.*)))
103-
KEEP(*(SORT(.preinit_array)))
104-
105-
PROVIDE(__preinit_array_end = .);
106-
} > rom
107-
108-
.init_array :
109-
{
110-
. = ALIGN(4);
111-
PROVIDE(__init_array_start = .);
112-
113-
KEEP(*(SORT(.init_array.*)))
114-
KEEP(*(SORT(.init_array)))
115-
116-
PROVIDE(__init_array_end = .);
117-
} > rom
118-
119-
.fini_array :
120-
{
121-
. = ALIGN(4);
122-
PROVIDE(__fini_array_start = .);
123-
124-
KEEP(*(SORT(.fini_array.*)))
125-
KEEP(*(SORT(.fini_array)))
126-
127-
PROVIDE(__fini_array_end = .);
128-
} > rom
129-
83+
INIT_ARRAY(preinit_array) > rom
84+
INIT_ARRAY(init_array) > rom
85+
INIT_ARRAY(fini_array) > rom
13086
/* Stack segment */
13187
.stack (NOLOAD) :
13288
{

targets/chip/lpc1756/linkerscript.ld

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,7 @@ SECTIONS
3434
{
3535
/* Vector table. Has the initial stack pointer and the initial
3636
structure for the arm interrupts */
37-
.vectors :
38-
{
39-
. = ALIGN(4);
40-
/* vector table */
41-
KEEP(*(.vectors .vectors.*));
42-
. = ALIGN(4);
43-
} > rom
37+
VECTORS() > rom
4438

4539
.crp 0x000002fc :
4640
{
@@ -82,51 +76,13 @@ SECTIONS
8276
} > rom
8377

8478
/* Read only data */
85-
.rodata :
86-
{
87-
. = ALIGN(4);
88-
89-
/* Constands, strings, etc */
90-
*(.rodata .rodata.* .gnu.linkonce.r.*);
91-
92-
. = ALIGN(4);
93-
} > rom
79+
RODATA() > rom
9480

9581
/* Support C constructors, and C destructors in both user code
9682
and the C library. This also provides support for C++ code. */
97-
.preinit_array :
98-
{
99-
. = ALIGN(4);
100-
PROVIDE(__preinit_array_start = .);
101-
102-
KEEP(*(SORT(.preinit_array.*)))
103-
KEEP(*(SORT(.preinit_array)))
104-
105-
PROVIDE(__preinit_array_end = .);
106-
} > rom
107-
108-
.init_array :
109-
{
110-
. = ALIGN(4);
111-
PROVIDE(__init_array_start = .);
112-
113-
KEEP(*(SORT(.init_array.*)))
114-
KEEP(*(SORT(.init_array)))
115-
116-
PROVIDE(__init_array_end = .);
117-
} > rom
118-
119-
.fini_array :
120-
{
121-
. = ALIGN(4);
122-
PROVIDE(__fini_array_start = .);
123-
124-
KEEP(*(SORT(.fini_array.*)))
125-
KEEP(*(SORT(.fini_array)))
126-
127-
PROVIDE(__fini_array_end = .);
128-
} > rom
129-
83+
INIT_ARRAY(preinit_array) > rom
84+
INIT_ARRAY(init_array) > rom
85+
INIT_ARRAY(fini_array) > rom
13086
/* Stack segment */
13187
.stack (NOLOAD) :
13288
{

0 commit comments

Comments
 (0)