Skip to content

Commit 0678f5c

Browse files
committed
linker: use wildcards in rel-sections.ld
Update rel-sections.ld to use wildcards instead of spelling out those sections one by one. Also, for POSIX, don't include this and turns off the warnings. With different host toolchain across different OS, it would be maintanence nightmare to account for all those combinations. So this reverts the POSIX linker script to before the first orphan section changes. Fixes #10493 Signed-off-by: Daniel Leung <[email protected]>
1 parent 1a1df58 commit 0678f5c

File tree

3 files changed

+23
-151
lines changed

3 files changed

+23
-151
lines changed

CMakeLists.txt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,21 @@ 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-
)
290+
if(NOT CONFIG_NATIVE_APPLICATION)
291+
# Funny thing is if this is set to =error, some architectures will
292+
# skip this flag even though the compiler flag check passes
293+
# (e.g. ARC and Xtensa). So keep it at =warn, for now.
294+
#
295+
# Skip this for native application as Zephyr only provides
296+
# additions to the host toolchain linker script. The relocation
297+
# sections (.rel*) requires us to override those provided
298+
# by host toolchain. As we can't account for all possible
299+
# combination of compiler and linker on all machines used
300+
# for development, it is better to turn this off.
301+
zephyr_ld_options(
302+
${LINKERFLAGPREFIX},--orphan-handling=warn
303+
)
304+
endif()
296305

297306
if(CONFIG_HAVE_CUSTOM_LINKER_SCRIPT)
298307
set(LINKER_SCRIPT ${APPLICATION_SOURCE_DIR}/${CONFIG_CUSTOM_LINKER_SCRIPT})

include/arch/posix/linker.ld

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,43 +21,16 @@
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;
3224

3325
SECTIONS
3426
{
3527

36-
#include <linker/rel-sections.ld>
37-
3828
#include <linker/common-rom.ld>
3929

4030
#include <linker/common-ram.ld>
4131

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-
5332
#include <arch/posix/native_tasks.ld>
5433

55-
/* Related to transactional memory */
56-
SECTION_PROLOGUE(.tm_clone_table,,)
57-
{
58-
*(.tm_clone_table)
59-
}
60-
6134
__data_ram_end = .;
6235

6336
} INSERT AFTER .data;

include/linker/rel-sections.ld

Lines changed: 8 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -2,142 +2,32 @@
22
* .rel.* are for relocation.
33
* These are being produced by compiler/linker.
44
* Specify these here so they are not considered orphan sections.
5-
*
6-
* Obtained via
7-
* '$(ARCH)-zephyr-elf-ld --verbose'
85
*/
96

10-
#if !defined(CONFIG_RISCV32) && !defined(CONFIG_XTENSA)
11-
SECTION_PROLOGUE(.rel.dyn,,)
7+
SECTION_PROLOGUE(.rel.plt,,)
128
{
13-
*(.rel.init)
14-
*(.rel.text .rel.text.* .rel.text_start.* .rel.gnu.linkonce.t.*)
15-
*(.rel.fini)
16-
*(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)
17-
*(.rel.data.rel.ro .rel.data.rel.ro.* .rel.gnu.linkonce.d.rel.ro.*)
18-
*(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)
19-
*(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)
20-
*(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)
21-
22-
#if defined(CONFIG_ARCH_POSIX)
23-
*(.rel.preinit_array)
24-
*(.rel.init_array)
25-
*(.rel.fini_array)
26-
#endif
27-
28-
*(.rel.ctors)
29-
*(.rel.dtors)
30-
*(.rel.got)
31-
*(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)
9+
*(.rel.plt)
3210

33-
#if defined(CONFIG_ARM) || defined(CONFIG_NIOS2)
3411
PROVIDE_HIDDEN (__rel_iplt_start = .);
3512
*(.rel.iplt)
3613
PROVIDE_HIDDEN (__rel_iplt_end = .);
37-
#endif
38-
39-
/* These are related to sections defined by Zephyr */
40-
*(.rel.kernel .rel.kernel.*)
41-
*(.rel.init_PRE_KERNEL*)
42-
*(.rel.init_POST_KERNEL*)
43-
*(.rel.init_APPLICATION*)
44-
45-
#if defined(CONFIG_ARCH_POSIX)
46-
*(.rel.native_PRE_BOOT*)
47-
*(.rel.native_FIRST_SLEEP*)
48-
*(.rel.native_ON_EXIT*)
49-
#endif
50-
51-
*(.rel.devconfig.*)
52-
53-
*(.rel._k_*)
54-
55-
*(.rel._bt_settings.*)
56-
57-
*(.rel.log_*)
58-
59-
*(.rel._net_buf_pool.*)
60-
*(.rel.net_*)
61-
62-
*(.rel._static_thread_data.*)
63-
64-
*(.rel.usb.*)
65-
66-
#if defined(CONFIG_X86)
67-
*(.rel.ifunc)
68-
*(.rel.mmulist)
69-
*(.rel.tss)
70-
#endif
7114
}
72-
#endif /* !defined(CONFIG_RISCV32) */
7315

74-
#if defined(CONFIG_ARM) || defined(CONFIG_NIOS2) || defined(CONFIG_RISCV32)
75-
SECTION_PROLOGUE(.rela.dyn,,)
16+
SECTION_PROLOGUE(.rela.plt,,)
7617
{
77-
*(.rela.init)
78-
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
79-
*(.rela.fini)
80-
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
81-
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
82-
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
83-
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
84-
*(.rela.ctors)
85-
*(.rela.dtors)
86-
*(.rela.got)
87-
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
18+
*(.rela.plt)
8819

89-
#if defined(CONFIG_ARM) || defined(CONFIG_NIOS2)
9020
PROVIDE_HIDDEN (__rela_iplt_start = .);
9121
*(.rela.iplt)
9222
PROVIDE_HIDDEN (__rela_iplt_end = .);
93-
#endif
94-
95-
/* These are related to sections defined by Zephyr */
96-
*(.rela.kernel .rel.kernel.*)
97-
*(.rela.init_PRE_KERNEL*)
98-
*(.rela.init_POST_KERNEL*)
99-
*(.rela.init_APPLICATION*)
100-
101-
*(.rela.devconfig.*)
102-
103-
*(.rela._k_*)
104-
105-
*(.rela._bt_settings.*)
106-
107-
*(.rela.log_*)
108-
109-
*(.rela._net_buf_pool.*)
110-
*(.rela.net_*)
111-
112-
*(.rela._static_thread_data.*)
113-
114-
*(.rela.usb.*)
115-
116-
#if defined(CONFIG_RISCV32)
117-
*(.rela.exception.*)
118-
*(.rela.gnu.linkonce.sw_isr_table)
119-
*(.rela.sdata.*)
120-
#endif
121-
12223
}
123-
#endif
12424

125-
#if !defined(CONFIG_RISCV32) && !defined(CONFIG_XTENSA)
126-
SECTION_PROLOGUE(.rel.plt,,)
25+
SECTION_PROLOGUE(.rel.dyn,,)
12726
{
128-
*(.rel.plt)
129-
130-
#if defined(CONFIG_X86)
131-
PROVIDE_HIDDEN (__rel_iplt_start = .);
132-
*(.rel.iplt)
133-
PROVIDE_HIDDEN (__rel_iplt_end = .);
134-
#endif
27+
*(.rel.*)
13528
}
136-
#endif /* !defined(CONFIG_RISCV32) */
13729

138-
#if defined(CONFIG_ARM) || defined(CONFIG_NIOS2) || defined(CONFIG_RISCV32)
139-
SECTION_PROLOGUE(.rela.plt,,)
30+
SECTION_PROLOGUE(.rela.dyn,,)
14031
{
141-
*(.rela.plt)
32+
*(.rela.*)
14233
}
143-
#endif

0 commit comments

Comments
 (0)