Skip to content

Commit 8ce758a

Browse files
dcpleungnashif
authored andcommitted
linker: warn about orphan sections
This adds a linker flag and necessary changes to linker scripts so that linker will warn about orphan sections. Relates to #5534. Signed-off-by: Daniel Leung <[email protected]>
1 parent 08c165f commit 8ce758a

File tree

25 files changed

+397
-0
lines changed

25 files changed

+397
-0
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,13 @@ zephyr_ld_options(
287287
${LINKERFLAGPREFIX},--build-id=none
288288
)
289289

290+
# Funny thing is if this is set to =error, some architectures will
291+
# skip this flag even though the compiler flag check passes
292+
# (e.g. ARC and Xtensa). So keep it at =warn, for now.
293+
zephyr_ld_options(
294+
${LINKERFLAGPREFIX},--orphan-handling=warn
295+
)
296+
290297
if(CONFIG_HAVE_CUSTOM_LINKER_SCRIPT)
291298
set(LINKER_SCRIPT ${APPLICATION_SOURCE_DIR}/${CONFIG_CUSTOM_LINKER_SCRIPT})
292299
if(NOT EXISTS ${LINKER_SCRIPT})

include/arch/arc/v2/linker.ld

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ MEMORY {
7373
}
7474

7575
SECTIONS {
76+
77+
#include <linker/rel-sections.ld>
78+
7679
GROUP_START(ROMABLE_REGION)
7780

7881
SECTION_PROLOGUE(_TEXT_SECTION_NAME,,ALIGN(1024)) {
@@ -283,4 +286,7 @@ SECTIONS {
283286
#ifdef CONFIG_GEN_ISR_TABLES
284287
#include <linker/intlist.ld>
285288
#endif
289+
290+
#include <linker/debug-sections.ld>
291+
286292
}

include/arch/arm/cortex_m/scripts/linker.ld

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,23 @@ ENTRY(CONFIG_KERNEL_ENTRY)
8787

8888
SECTIONS
8989
{
90+
91+
#include <linker/rel-sections.ld>
92+
93+
/*
94+
* .plt and .iplt are here according to 'arm-zephyr-elf-ld --verbose',
95+
* before text section.
96+
*/
97+
SECTION_PROLOGUE(.plt,,)
98+
{
99+
*(.plt)
100+
}
101+
102+
SECTION_PROLOGUE(.iplt,,)
103+
{
104+
*(.iplt)
105+
}
106+
90107
GROUP_START(ROMABLE_REGION)
91108

92109
_image_rom_start = ROM_ADDR;
@@ -133,6 +150,12 @@ SECTIONS
133150
*(".text.*")
134151
*(.gnu.linkonce.t.*)
135152

153+
/*
154+
* These are here according to 'arm-zephyr-elf-ld --verbose',
155+
* after .gnu.linkonce.t.*
156+
*/
157+
*(.glue_7t) *(.glue_7) *(.vfp11_veneer) *(.v4_bx)
158+
136159
#include <linker/priv_stacks-text.ld>
137160
#include <linker/kobject-text.ld>
138161

@@ -219,6 +242,18 @@ SECTIONS
219242
} > FLASH_CCFG
220243
#endif
221244

245+
/*
246+
* These are here according to 'arm-zephyr-elf-ld --verbose',
247+
* before data section.
248+
*/
249+
SECTION_PROLOGUE(.got,,)
250+
{
251+
*(.got.plt)
252+
*(.igot.plt)
253+
*(.got)
254+
*(.igot)
255+
}
256+
222257
GROUP_START(RAMABLE_REGION)
223258

224259

@@ -319,6 +354,8 @@ SECTIONS
319354
KERNEL_INPUT_SECTION(COMMON)
320355
*(".kernel_bss.*")
321356

357+
#include <linker/priv_stacks-noinit.ld>
358+
322359
/*
323360
* As memory is cleared in words only, it is simpler to ensure the BSS
324361
* section ends on a 4 byte boundary. This wastes a maximum of 3 bytes.
@@ -427,4 +464,12 @@ SECTIONS
427464
#include <linker/intlist.ld>
428465
#endif
429466

467+
#include <linker/debug-sections.ld>
468+
469+
SECTION_PROLOGUE(.ARM.attributes, 0,)
470+
{
471+
KEEP(*(.ARM.attributes))
472+
KEEP(*(.gnu.attributes))
473+
}
474+
430475
}

include/arch/nios2/linker.ld

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,23 @@ ENTRY(CONFIG_KERNEL_ENTRY)
8282

8383
SECTIONS
8484
{
85+
86+
#include <linker/rel-sections.ld>
87+
88+
/*
89+
* .plt and .iplt are here according to
90+
* 'nios2-zephyr-elf-ld --verbose', before text section.
91+
*/
92+
SECTION_PROLOGUE(.plt,,)
93+
{
94+
*(.plt)
95+
}
96+
97+
SECTION_PROLOGUE(.iplt,,)
98+
{
99+
*(.iplt)
100+
}
101+
85102
GROUP_START(ROMABLE_REGION)
86103
_image_rom_start = _ROM_ADDR;
87104

@@ -261,5 +278,7 @@ SECTIONS
261278
#include <linker/intlist.ld>
262279
#endif
263280

281+
#include <linker/debug-sections.ld>
282+
264283
}
265284

include/arch/posix/linker.ld

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,43 @@
2121
#include <linker/linker-defs.h>
2222
#include <linker/linker-tool.h>
2323

24+
SECTIONS
25+
{
26+
SECTION_PROLOGUE(.note.ABI-tag,,)
27+
{
28+
*(.note.ABI-tag)
29+
}
30+
31+
} INSERT AFTER .interp;
2432

2533
SECTIONS
2634
{
2735

36+
#include <linker/rel-sections.ld>
37+
2838
#include <linker/common-rom.ld>
2939

3040
#include <linker/common-ram.ld>
3141

42+
SECTION_PROLOGUE(_NOINIT_SECTION_NAME, (NOLOAD OPTIONAL),)
43+
{
44+
/*
45+
* This section is used for non-initialized objects that
46+
* will not be cleared during the boot process.
47+
*/
48+
KERNEL_INPUT_SECTION(.noinit)
49+
KERNEL_INPUT_SECTION(".noinit.*")
50+
*(".kernel_noinit.*")
51+
}
52+
3253
#include <arch/posix/native_tasks.ld>
3354

55+
/* Related to transactional memory */
56+
SECTION_PROLOGUE(.tm_clone_table,,)
57+
{
58+
*(.tm_clone_table)
59+
}
60+
3461
__data_ram_end = .;
3562

3663
} INSERT AFTER .data;

include/arch/riscv32/common/linker.ld

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ ENTRY(CONFIG_KERNEL_ENTRY)
4646
SECTIONS
4747
{
4848

49+
#include <linker/rel-sections.ld>
50+
51+
/*
52+
* The .plt and .iplt are here according to
53+
* 'riscv32-zephyr-elf-ld --verbose', before text section.
54+
*/
55+
SECTION_PROLOGUE(.plt,,)
56+
{
57+
*(.plt)
58+
}
59+
60+
SECTION_PROLOGUE(.iplt,,)
61+
{
62+
*(.iplt)
63+
}
64+
4965
GROUP_START(ROM)
5066
_image_rom_start = .;
5167

@@ -175,4 +191,7 @@ SECTIONS
175191
#endif
176192

177193
GROUP_END(RAMABLE_REGION)
194+
195+
#include <linker/debug-sections.ld>
196+
178197
}

include/arch/riscv32/pulpino/linker.ld

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,23 @@ ENTRY(CONFIG_KERNEL_ENTRY)
4141

4242
SECTIONS
4343
{
44+
45+
#include <linker/rel-sections.ld>
46+
47+
/*
48+
* .plt and .iplt are here according to
49+
* 'riscv32-zephyr-elf-ld --verbose', before text section.
50+
*/
51+
SECTION_PROLOGUE(.plt,,)
52+
{
53+
*(.plt)
54+
}
55+
56+
SECTION_PROLOGUE(.iplt,,)
57+
{
58+
*(.iplt)
59+
}
60+
4461
GROUP_START(INSTRRAM)
4562

4663
SECTION_PROLOGUE(_VECTOR_SECTION_NAME,,)
@@ -71,6 +88,7 @@ SECTIONS
7188
*(.text)
7289
*(".text.*")
7390
*(.gnu.linkonce.t.*)
91+
*(.eh_frame)
7492
} GROUP_LINK_IN(INSTRRAM)
7593

7694
_image_text_end = .;
@@ -160,4 +178,7 @@ SECTIONS
160178
#endif
161179

162180
GROUP_END(RAMABLE_REGION)
181+
182+
#include <linker/debug-sections.ld>
183+
163184
}

include/arch/x86/linker.ld

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ ENTRY(CONFIG_KERNEL_ENTRY)
6666
/* SECTIONS definitions */
6767
SECTIONS
6868
{
69+
70+
#include <linker/rel-sections.ld>
71+
6972
GROUP_START(ROMABLE_REGION)
7073
#ifdef CONFIG_REALMODE
7174
/* 16-bit sections */
@@ -378,6 +381,8 @@ SECTIONS
378381
#include <custom-sections.ld>
379382
#endif
380383

384+
#include <linker/debug-sections.ld>
385+
381386
}
382387

383388
#ifdef CONFIG_XIP

include/linker/debug-sections.ld

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* following sections are obtained via 'ld --verbose' */
2+
3+
/* Stabs debugging sections. */
4+
SECTION_PROLOGUE(.stab, 0,) { *(.stab) }
5+
SECTION_PROLOGUE(.stabstr, 0,) { *(.stabstr) }
6+
SECTION_PROLOGUE(.stab.excl, 0,) { *(.stab.excl) }
7+
SECTION_PROLOGUE(.stab.exclstr, 0,) { *(.stab.exclstr) }
8+
SECTION_PROLOGUE(.stab.index, 0,) { *(.stab.index) }
9+
SECTION_PROLOGUE(.stab.indexstr, 0,) { *(.stab.indexstr) }
10+
SECTION_PROLOGUE(.comment, 0,) { *(.comment) }
11+
/* DWARF debug sections.
12+
Symbols in the DWARF debugging sections are relative to the beginning
13+
of the section so we begin them at 0. */
14+
/* DWARF 1 */
15+
SECTION_PROLOGUE(.debug, 0,) { *(.debug) }
16+
SECTION_PROLOGUE(.line, 0,) { *(.line) }
17+
/* GNU DWARF 1 extensions */
18+
SECTION_PROLOGUE(.debug_srcinfo, 0,) { *(.debug_srcinfo) }
19+
SECTION_PROLOGUE(.debug_sfnames, 0,) { *(.debug_sfnames) }
20+
/* DWARF 1.1 and DWARF 2 */
21+
SECTION_PROLOGUE(.debug_aranges, 0,) { *(.debug_aranges) }
22+
SECTION_PROLOGUE(.debug_pubnames, 0,) { *(.debug_pubnames) }
23+
/* DWARF 2 */
24+
SECTION_PROLOGUE(.debug_info, 0,) { *(.debug_info .gnu.linkonce.wi.*) }
25+
SECTION_PROLOGUE(.debug_abbrev, 0,) { *(.debug_abbrev) }
26+
SECTION_PROLOGUE(.debug_line, 0,) { *(.debug_line .debug_line.* .debug_line_end ) }
27+
SECTION_PROLOGUE(.debug_frame, 0,) { *(.debug_frame) }
28+
SECTION_PROLOGUE(.debug_str, 0,) { *(.debug_str) }
29+
SECTION_PROLOGUE(.debug_loc, 0,) { *(.debug_loc) }
30+
SECTION_PROLOGUE(.debug_macinfo, 0,) { *(.debug_macinfo) }
31+
/* SGI/MIPS DWARF 2 extensions */
32+
SECTION_PROLOGUE(.debug_weaknames, 0,) { *(.debug_weaknames) }
33+
SECTION_PROLOGUE(.debug_funcnames, 0,) { *(.debug_funcnames) }
34+
SECTION_PROLOGUE(.debug_typenames, 0,) { *(.debug_typenames) }
35+
SECTION_PROLOGUE(.debug_varnames, 0,) { *(.debug_varnames) }
36+
/* DWARF 3 */
37+
SECTION_PROLOGUE(.debug_pubtypes, 0,) { *(.debug_pubtypes) }
38+
SECTION_PROLOGUE(.debug_ranges, 0,) { *(.debug_ranges) }
39+
/* DWARF Extension. */
40+
SECTION_PROLOGUE(.debug_macro, 0,) { *(.debug_macro) }

include/linker/priv_stacks-noinit.ld

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright (c) 2017 Linaro Limited.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
*(".priv_stacks.noinit")

0 commit comments

Comments
 (0)