From e828702b6ae405e78a523c1ee13e89e8b0d13965 Mon Sep 17 00:00:00 2001 From: Eugeniy Paltsev Date: Wed, 24 Mar 2021 13:31:08 +0300 Subject: [PATCH] linker-defs: Fix sorting order of objects by priority Commit 0a7b65e tweaked the CREATE_OBJ_LEVEL macro in such a way that it would break the expected sorting order. For example if you had 2, 19, 20, 30 as the level, we'd end up sort these to be 19, 2, 20, 30. Fix this by adding aditional "_" symbol after the init level counter. That allows to keep correct sort order (for both GNU and MWDT toolchains) and distinguish init level counter from section suffix (for MWDT toolchain). Fixes zephyrproject-rtos#33464 Signed-off-by: Eugeniy Paltsev --- include/device.h | 2 +- include/init.h | 2 +- include/linker/linker-defs.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/device.h b/include/device.h index 1df010d7a55..3b81213e72c 100644 --- a/include/device.h +++ b/include/device.h @@ -1040,7 +1040,7 @@ BUILD_ASSERT(sizeof(device_handle_t) == 2, "fix the linker scripts"); COND_CODE_1(DT_NODE_EXISTS(node_id), (), (static)) \ const Z_DECL_ALIGN(struct device) \ DEVICE_NAME_GET(dev_name) __used \ - __attribute__((__section__(".device_" #level STRINGIFY(prio)))) = { \ + __attribute__((__section__(".device_" #level STRINGIFY(prio)"_"))) = { \ .name = drv_name, \ .config = (cfg_ptr), \ .api = (api_ptr), \ diff --git a/include/init.h b/include/init.h index 6fe49730e84..403885f5c1c 100644 --- a/include/init.h +++ b/include/init.h @@ -85,7 +85,7 @@ void z_sys_init_run_level(int32_t _level); #define Z_INIT_ENTRY_DEFINE(_entry_name, _init_fn, _device, _level, _prio) \ static const Z_DECL_ALIGN(struct init_entry) \ _CONCAT(__init_, _entry_name) __used \ - __attribute__((__section__(".init_" #_level STRINGIFY(_prio)))) = { \ + __attribute__((__section__(".init_" #_level STRINGIFY(_prio)"_"))) = { \ .init = (_init_fn), \ .dev = (_device), \ } diff --git a/include/linker/linker-defs.h b/include/linker/linker-defs.h index 2fb73bfd787..9a64d71a3c9 100644 --- a/include/linker/linker-defs.h +++ b/include/linker/linker-defs.h @@ -116,8 +116,8 @@ */ #define CREATE_OBJ_LEVEL(object, level) \ __##object##_##level##_start = .; \ - KEEP(*(SORT(.object##_##level[0-9]*))); \ - KEEP(*(SORT(.object##_##level[1-9][0-9]*))); + KEEP(*(SORT(.object##_##level[0-9]_*))); \ + KEEP(*(SORT(.object##_##level[1-9][0-9]_*))); /* * link in shell initialization objects for all modules that use shell and