diff --git a/cmake/linker_script/common/common-rom.cmake b/cmake/linker_script/common/common-rom.cmake index a902a24f3c0..2fd4fcedb47 100644 --- a/cmake/linker_script/common/common-rom.cmake +++ b/cmake/linker_script/common/common-rom.cmake @@ -188,6 +188,11 @@ zephyr_iterable_section(NAME tracing_backend KVMA RAM_REGION GROUP RODATA_REGION zephyr_linker_section(NAME zephyr_dbg_info KVMA RAM_REGION GROUP RODATA_REGION NOINPUT ${XIP_ALIGN_WITH_INPUT}) zephyr_linker_section_configure(SECTION zephyr_dbg_info INPUT ".zephyr_dbg_info" KEEP) +if(CONFIG_SYMTAB) + zephyr_linker_section(NAME symtab KVMA FLASH GROUP RODATA_REGION SUBALIGN 4 NOINPUT) + zephyr_linker_section_configure(SECTION symtab INPUT ".gnu.linkonce.symtab*") +endif() + if (CONFIG_DEVICE_DEPS) zephyr_linker_section(NAME device_deps KVMA RAM_REGION GROUP RODATA_REGION NOINPUT ${XIP_ALIGN_WITH_INPUT} ENDALIGN 16) zephyr_linker_section_configure(SECTION device_deps INPUT .__device_deps_pass1* KEEP SORT NAME PASS LINKER_DEVICE_DEPS_PASS1) diff --git a/include/zephyr/linker/common-rom/common-rom-debug.ld b/include/zephyr/linker/common-rom/common-rom-debug.ld index 07d89ca6069..c5b32833a09 100644 --- a/include/zephyr/linker/common-rom/common-rom-debug.ld +++ b/include/zephyr/linker/common-rom/common-rom-debug.ld @@ -8,3 +8,10 @@ { KEEP(*(".dbg_thread_info")); } GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) + +#ifdef CONFIG_SYMTAB + SECTION_PROLOGUE(symtab,,) + { + KEEP(*(_SYMTAB_SECTION_SYMS)) + } GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) +#endif /* CONFIG_SYMTAB */ diff --git a/include/zephyr/linker/section_tags.h b/include/zephyr/linker/section_tags.h index 5678a07325b..6c7c1bdd675 100644 --- a/include/zephyr/linker/section_tags.h +++ b/include/zephyr/linker/section_tags.h @@ -103,6 +103,12 @@ #define __isr #endif +/* Symbol table section */ +#if defined(CONFIG_SYMTAB) +#define __symtab_info Z_GENERIC_SECTION(_SYMTAB_INFO_SECTION_NAME) +#define __symtab_entry Z_GENERIC_SECTION(_SYMTAB_ENTRY_SECTION_NAME) +#endif /* CONFIG_SYMTAB */ + #endif /* !_ASMLANGUAGE */ #endif /* ZEPHYR_INCLUDE_LINKER_SECTION_TAGS_H_ */ diff --git a/include/zephyr/linker/sections.h b/include/zephyr/linker/sections.h index 2f1049d09f3..14aa4c29894 100644 --- a/include/zephyr/linker/sections.h +++ b/include/zephyr/linker/sections.h @@ -77,6 +77,13 @@ #define _NOCACHE_SECTION_NAME nocache #endif +/* Symbol table section */ +#if defined(CONFIG_SYMTAB) +#define _SYMTAB_INFO_SECTION_NAME .gnu.linkonce.symtab.info +#define _SYMTAB_ENTRY_SECTION_NAME .gnu.linkonce.symtab.entry +#define _SYMTAB_SECTION_SYMS .gnu.linkonce.symtab* +#endif /* CONFIG_SYMTAB */ + #if defined(CONFIG_LINKER_USE_BOOT_SECTION) #define BOOT_TEXT_SECTION_NAME boot_text #define BOOT_BSS_SECTION_NAME boot_bss diff --git a/scripts/build/gen_symtab.py b/scripts/build/gen_symtab.py index 1d933443384..ac20506a645 100644 --- a/scripts/build/gen_symtab.py +++ b/scripts/build/gen_symtab.py @@ -125,10 +125,11 @@ def main(): with open(args.output, 'w') as wf: print("/* AUTO-GENERATED by gen_symtab.py, do not edit! */", file=wf) print("", file=wf) + print("#include ", file=wf) print("#include ", file=wf) print("", file=wf) print( - f"const struct z_symtab_entry z_symtab_entries[{len(symtab_list) + 1}] = {{", file=wf) + f"const struct z_symtab_entry __symtab_entry z_symtab_entries[{len(symtab_list) + 1}] = {{", file=wf) for i, entry in enumerate(symtab_list): print( f"\t/* ADDR: {hex(entry.addr)} SIZE: {hex(entry.size)} */", file=wf) @@ -145,7 +146,7 @@ def main(): f"\t[{len(symtab_list)}] = {{.offset = {dummy_offset}, .name = \"?\"}},", file=wf) print(f"}};\n", file=wf) - print(f"const struct symtab_info z_symtab = {{", file=wf) + print(f"const struct symtab_info __symtab_info z_symtab = {{", file=wf) print(f"\t.first_addr = {hex(first_addr)},", file=wf) print(f"\t.length = {len(symtab_list)},", file=wf) print(f"\t.entries = z_symtab_entries,", file=wf) diff --git a/subsys/debug/symtab/CMakeLists.txt b/subsys/debug/symtab/CMakeLists.txt index 5e128c8bc3a..37cfce45ece 100644 --- a/subsys/debug/symtab/CMakeLists.txt +++ b/subsys/debug/symtab/CMakeLists.txt @@ -1,7 +1,13 @@ +# Copyright (c) 2024 Meta Platforms # SPDX-License-Identifier: Apache-2.0 -add_library(symtab +zephyr_library() + +zephyr_library_sources( symtab.c +) + +add_library(symtab symtab_stub.c ) diff --git a/subsys/debug/symtab/symtab_stub.c b/subsys/debug/symtab/symtab_stub.c index a99b85e7aa5..710505017d2 100644 --- a/subsys/debug/symtab/symtab_stub.c +++ b/subsys/debug/symtab/symtab_stub.c @@ -4,11 +4,12 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include #include /** * These are placeholder variables. They will be replaced by the real ones * generated by `gen_symtab.py`. */ -const struct z_symtab_entry *z_symtab_entries; -const struct symtab_info z_symtab; +const struct z_symtab_entry __symtab_entry * z_symtab_entries; +const struct symtab_info __symtab_info z_symtab;