Skip to content

Commit 9e63416

Browse files
authored
10540: Modify linker scripts to include the relavant Linker Fragments (zephyrproject-rtos#19)
linker: Updated Linker script with linker script fragments Modified linker script to use linker script fragments and added MACROs for section definitions Signed-off-by: Adhil Xavier <adhil.xavier@ignitarium.com>
1 parent b62dbcc commit 9e63416

File tree

11 files changed

+204
-47
lines changed

11 files changed

+204
-47
lines changed

cmake/compiler/xcdsc/generic.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set(CMAKE_SYSTEM_PROCESSOR ${ARCH})
33
# Find and validate the xc-dsc-gcc compiler binary
44
find_program(CMAKE_C_COMPILER xc-dsc-gcc PATHS ${XCDSC_TOOLCHAIN_PATH}/bin/ NO_DEFAULT_PATH REQUIRED )
55
add_definitions(-D__XC_DSC__)
6+
add_definitions(-DQUICK_FIX_XCDSC_LINKER_EMPTY_OUTPUT_SECTION)
67
# Get compiler version
78
execute_process(
89
COMMAND ${CMAKE_C_COMPILER} --version

cmake/linker/xcdsc/target.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ macro(configure_linker_script linker_script_gen linker_pass_define)
1919
${extra_dependencies}
2020
${linker_script_dep}
2121
COMMAND ${CMAKE_C_COMPILER} -x assembler-with-cpp -MD -MF ${linker_script_gen}.dep -MT ${linker_script_gen}
22+
-D_LINKER
23+
-D_ASM_LANGUAGE
2224
-D__XCDSC_LINKER_CMD__
25+
-DQUICK_FIX_XCDSC_LINKER_EMPTY_OUTPUT_SECTION
2326
-imacros ${AUTOCONF_H}
2427
-I${ZEPHYR_BASE}/include
2528
-imacros${ZEPHYR_BASE}/include/zephyr/linker/sections.h

include/zephyr/arch/dspic/linker.ld

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1+
/*
2+
* Copyright (c) 2025, Microchip Technology Inc.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
16
/*
27
* Generic Zephyr Linker Script
3-
*.
4-
* Note: For some of the input sections such as init levels and
5-
* data sections and kernel objects needs to be added via
6-
* linker script fragment files, At this point, only have added those
7-
* input sections required and kept minimal because when adding
8-
* linker script linker fragment files, it affects the syntax of
9-
* XC-DSC Linker.
108
*/
119

1210
#include <zephyr/linker/sections.h>
@@ -27,11 +25,10 @@
2725
#define ROMABLE_REGION program
2826
#define RAMABLE_REGION data
2927

30-
OUTPUT_ARCH("33AK128MC106")
28+
3129
CRT0_STARTUP(reset0.S.obj)
3230
CRT1_STARTUP(reset1.S.obj)
3331
CRT_STARTMODE(crt_start_mode_normal)
34-
3532
MEMORY
3633
{
3734
/* Memory map from the original target-specific script */
@@ -40,7 +37,6 @@ MEMORY
4037
/* Used by and documented in include/linker/intlist.ld */
4138
IDT_LIST (wx) : ORIGIN = 0xFFFFFFFF, LENGTH = 0
4239
}
43-
4440
SECTIONS
4541
{
4642
/* Start of the ROM-based sections */
@@ -55,7 +51,6 @@ SECTIONS
5551
* table and debug information.
5652
*/
5753
#include <snippets-rom-start.ld>
58-
5954
} GROUP_LINK_IN(ROMABLE_REGION)
6055

6156
/*
@@ -67,25 +62,41 @@ SECTIONS
6762
SECTION_PROLOGUE(._TEXT_SECTION_NAME,,)
6863
{
6964
__text_region_start = .;
65+
#include <zephyr/linker/kobject-text.ld>
7066
*(.init);
7167
*(.text);
7268
*(.text*);
7369
*(.user_init);
7470
KEEP (*(.handle));
7571
KEEP (*(.isr*));
7672
*(.lib*);
77-
___rodata_region_start = .;
78-
*(.rodata) *(.rodata.*)
79-
___rodata_region_end = .;
80-
*(.rodata) /* Read-Only Data */
81-
___static_thread_data_list_start = .;
82-
KEEP(*(SORT(.static_thread_data*)))
83-
___static_thread_data_list_end = .;
73+
__text_region_end = .;
8474
. = ALIGN(4);
8575
} GROUP_LINK_IN(ROMABLE_REGION)
86-
__text_region_end = .;
87-
ITERABLE_SECTION_ROM_NUMERIC(service, Z_LINK_ITERABLE_SUBALIGN)
76+
77+
___rodata_region_start = .;
78+
#include <zephyr/linker/common-rom.ld>
79+
80+
/* Located in generated directory. This file is populated by calling
81+
* zephyr_linker_sources(ROM_SECTIONS ...). Useful for grouping iterable RO structs.
82+
*/
83+
#include <snippets-rom-sections.ld>
84+
#include <zephyr/linker/thread-local-storage.ld>
85+
86+
SECTION_PROLOGUE(.rodata,,)
87+
{
88+
*(.rodata)
89+
*(.rodata.*)
90+
/* Located in generated directory. This file is populated by the
91+
* zephyr_linker_sources() Cmake function.
92+
*/
93+
#include <snippets-rodata.ld>
94+
#include <zephyr/linker/kobject-rom.ld>
95+
} GROUP_LINK_IN(ROMABLE_REGION)
96+
8897
. = ALIGN(4);
98+
___rodata_region_end = .;
99+
#include <zephyr/linker/cplusplus-rom.ld>
89100
GROUP_END(ROMABLE_REGION)
90101

91102
/* Start of the RAM-based sections */
@@ -108,27 +119,32 @@ SECTIONS
108119
__data_region_start = .;
109120
*(.data)
110121
*(".data.*")
111-
__device_list_start = .;
112-
KEEP(*(SORT(.z_device*)))
113-
__device_list_end = .;
114-
/* Initialization levels: Early -> Application */
115-
___init_EARLY_start = .;
116-
KEEP(*(SORT(.init_EARLY*)))
117-
___init_PRE_KERNEL_1_start = .;
118-
KEEP(*(SORT(.init_PRE_KERNEL_1*)))
119-
___init_PRE_KERNEL_2_start = .;
120-
KEEP(*(SORT(.init_PRE_KERNEL_2*)))
121-
___init_POST_KERNEL_start = .;
122-
KEEP(*(SORT(.init_POST_KERNEL*)))
123-
___init_APPLICATION_start = .;
124-
KEEP(*(SORT(.init_APPLICATION*)))
125-
___init_SMP_start = .;
126-
KEEP(*(SORT(.init_SMP*)))
127-
___init_end = .;
128-
__data_region_start = .;
122+
*(".kernel.*")
129123

124+
/* Located in generated directory. This file is populated by the
125+
* zephyr_linker_sources() Cmake function.
126+
*/
127+
#include <snippets-rwdata.ld>
128+
__data_region_end = .;
130129
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
131130

131+
#include <zephyr/linker/common-ram.ld>
132+
133+
#include <zephyr/linker/kobject-data.ld>
134+
135+
#include <zephyr/linker/cplusplus-ram.ld>
136+
137+
/* Located in generated directory. This file is populated by the
138+
* zephyr_linker_sources() Cmake function.
139+
*/
140+
#include <snippets-data-sections.ld>
141+
142+
/* Located in generated directory. This file is populated by the
143+
* zephyr_linker_sources() Cmake function.
144+
*/
145+
#include <snippets-sections.ld>
146+
147+
#include <zephyr/linker/debug-sections.ld>
132148

133149
/*
134150
* This section handles uninitialized data (BSS). It occupies space
@@ -145,7 +161,9 @@ SECTIONS
145161
___bss_end = .;
146162
} GROUP_LINK_IN(RAMABLE_REGION)
147163

164+
148165
GROUP_END(RAMABLE_REGION)
166+
149167
}
150168

151169
/*

include/zephyr/linker/common-ram.ld

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ ITERABLE_SECTION_RAM(scmi_protocol, Z_LINK_ITERABLE_SUBALIGN)
4141

4242
SECTION_DATA_PROLOGUE(device_states,,)
4343
{
44+
#ifdef QUICK_FIX_XCDSC_LINKER_EMPTY_OUTPUT_SECTION
45+
. = . + 4;
46+
#endif
4447
. = ALIGN(CONFIG_ARCH_DEVICE_STATE_ALIGN);
4548
/* Device states used by the device objects. */
4649
PLACE_SYMBOL_HERE(__device_states_start);
@@ -61,7 +64,11 @@ ITERABLE_SECTION_RAM(scmi_protocol, Z_LINK_ITERABLE_SUBALIGN)
6164
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
6265
#endif /* CONFIG_DEVICE_DEPS_DYNAMIC */
6366

67+
#ifdef QUICK_FIX_XCDSC_LINKER_EMPTY_OUTPUT_SECTION
68+
#ifdef CONFIG_LOG_MODE_DEFERRED
6469
ITERABLE_SECTION_RAM_GC_ALLOWED(log_mpsc_pbuf, Z_LINK_ITERABLE_SUBALIGN)
70+
#endif
71+
#endif
6572
ITERABLE_SECTION_RAM(log_msg_ptr, Z_LINK_ITERABLE_SUBALIGN)
6673
ITERABLE_SECTION_RAM(log_dynamic, Z_LINK_ITERABLE_SUBALIGN)
6774

@@ -90,8 +97,15 @@ ITERABLE_SECTION_RAM(scmi_protocol, Z_LINK_ITERABLE_SUBALIGN)
9097
ITERABLE_SECTION_RAM_GC_ALLOWED(k_fifo, Z_LINK_ITERABLE_SUBALIGN)
9198
ITERABLE_SECTION_RAM_GC_ALLOWED(k_lifo, Z_LINK_ITERABLE_SUBALIGN)
9299
ITERABLE_SECTION_RAM_GC_ALLOWED(k_condvar, Z_LINK_ITERABLE_SUBALIGN)
100+
/* For placing kernel objects section and "sys_mem_blocks_ptr" section using
101+
* same MACRO. Dummy instances were created for all kernel objects in application
102+
* but not for the below section.
103+
*/
104+
#ifdef QUICK_FIX_XCDSC_LINKER_EMPTY_OUTPUT_SECTION
105+
#ifdef CONFIG_OBJ_CORE_SYS_MEM_BLOCKS
93106
ITERABLE_SECTION_RAM_GC_ALLOWED(sys_mem_blocks_ptr, Z_LINK_ITERABLE_SUBALIGN)
94-
107+
#endif
108+
#endif
95109
ITERABLE_SECTION_RAM(net_buf_pool, Z_LINK_ITERABLE_SUBALIGN)
96110

97111
#if defined(CONFIG_NETWORKING)

include/zephyr/linker/common-rom/common-rom-init.ld

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#if defined(CONFIG_TOOLCHAIN_SUPPORTS_STATIC_INIT_GNU) || defined(CONFIG_NATIVE_APPLICATION)
44
SECTION_PROLOGUE(init_array,,)
55
{
6+
#ifdef QUICK_FIX_XCDSC_LINKER_EMPTY_OUTPUT_SECTION
7+
. = . + 4;
8+
#endif
69
/*
710
* Add all of the GNU-style constructors in priority order. Note
811
* that this doesn't build the ctors in the "usual" fashion with

include/zephyr/linker/common-rom/common-rom-kernel-devices.ld

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,16 @@
8282

8383
SECTION_DATA_PROLOGUE(app_shmem_regions,,)
8484
{
85+
86+
#ifdef QUICK_FIX_XCDSC_LINKER_EMPTY_OUTPUT_SECTION
87+
. = . + 4;
88+
#endif
8589
PLACE_SYMBOL_HERE(__app_shmem_regions_start);
8690
KEEP(*(SORT(.app_regions.*)));
8791
PLACE_SYMBOL_HERE(__app_shmem_regions_end);
8892
} GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
8993

9094
ITERABLE_SECTION_ROM(k_p4wq_initparam, Z_LINK_ITERABLE_SUBALIGN)
91-
9295
ITERABLE_SECTION_ROM(_static_thread_data, Z_LINK_ITERABLE_SUBALIGN)
9396

9497
#if defined(CONFIG_PCIE)
@@ -98,8 +101,10 @@
98101
#if !defined(CONFIG_DEVICE_DEPS_DYNAMIC)
99102
SECTION_DATA_PROLOGUE(device_deps,,)
100103
{
104+
#ifdef QUICK_FIX_XCDSC_LINKER_EMPTY_OUTPUT_SECTION
105+
. = . + 4;
106+
#endif
101107
#include <zephyr/linker/device-deps.ld>
102108
} GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
103109
#endif /* !CONFIG_DEVICE_DEPS_DYNAMIC */
104-
105110
#include <device-api-sections.ld>

include/zephyr/linker/common-rom/common-rom-misc.ld

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646

4747
SECTION_DATA_PROLOGUE(symbol_to_keep,,)
4848
{
49+
#ifdef QUICK_FIX_XCDSC_LINKER_EMPTY_OUTPUT_SECTION
50+
. = . + 4;
51+
#endif
4952
PLACE_SYMBOL_HERE(__symbol_to_keep_start);
5053
KEEP(*(SORT(.symbol_to_keep*)));
5154
PLACE_SYMBOL_HERE(__symbol_to_keep_end);

include/zephyr/linker/iterable_sections.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,27 @@
1313
*/
1414

1515
/* clang-format off */
16+
17+
/* Microchip's XCDSC linker doesn't generate empty sections
18+
* unlike the other toolchains. So adding a dummy byte to empty
19+
* sections to create it otherwise will get an assertion fail
20+
* error at build time. This workaround will be removed later
21+
*/
22+
#ifdef QUICK_FIX_XCDSC_LINKER_EMPTY_OUTPUT_SECTION
23+
#define Z_LINK_ITERABLE_PREFIX . = . + 4;
24+
#else
25+
#define Z_LINK_ITERABLE_PREFIX
26+
#endif
27+
1628
#define Z_LINK_ITERABLE(struct_type) \
29+
Z_LINK_ITERABLE_PREFIX \
1730
PLACE_SYMBOL_HERE(_CONCAT(_##struct_type, _list_start)); \
1831
KEEP(*(SORT_BY_NAME(._##struct_type.static.*))); \
1932
PLACE_SYMBOL_HERE(_CONCAT(_##struct_type, _list_end));
2033

2134

2235
#define Z_LINK_ITERABLE_NUMERIC(struct_type) \
36+
Z_LINK_ITERABLE_PREFIX \
2337
PLACE_SYMBOL_HERE(_CONCAT(_##struct_type, _list_start)); \
2438
KEEP(*(SORT(._##struct_type.static.*_?_*))); \
2539
KEEP(*(SORT(._##struct_type.static.*_??_*))); \
@@ -36,6 +50,7 @@
3650
PLACE_SYMBOL_HERE(_CONCAT(_##struct_type, _list_start)); \
3751
*(SORT_BY_NAME(._##struct_type.static.*)); \
3852
PLACE_SYMBOL_HERE(_CONCAT(_##struct_type, _list_end));
53+
3954
/* clang-format on */
4055

4156
#define Z_LINK_ITERABLE_SUBALIGN CONFIG_LINKER_ITERABLE_SUBALIGN

0 commit comments

Comments
 (0)