From cbe7b4fb744eb6b658b960ead03b1ef63d58173c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B8e?= Date: Fri, 3 Aug 2018 16:15:05 +0200 Subject: [PATCH] linker: Re-implement {APP,KERNEL}_INPUT_SECTION MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This rewrites the implementation of the APP_INPUT_SECTION and KERNEL_INPUT_SECTION macros such that an unbounded amount of kernelspace libraries can be used. This resolves #7703 The new implementation has a caveat/limitation; the linker script developer must invoke APP_INPUT_SECTION before KERNEL_INPUT_SECTION. All in-tree linker scripts happened to already be doing this so no in-tree porting was necessary. Signed-off-by: Sebastian Bøe --- CMakeLists.txt | 13 ++++++------ include/linker/linker-defs.h | 39 +++++++++++++++--------------------- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ac86b2409c..42cbfc88fec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -618,15 +618,14 @@ if(CONFIG_APPLICATION_MEMORY) list(APPEND ks ${fixed_path}) endforeach() - # We are done constructing kernel_object_file_list, now we inject this - # information into the linker script through -D's - list(LENGTH kernel_object_file_list NUM_KERNEL_OBJECT_FILES) - list(APPEND LINKER_SCRIPT_DEFINES -DNUM_KERNEL_OBJECT_FILES=${NUM_KERNEL_OBJECT_FILES}) - set(i 0) + # We are done constructing kernel_object_file_list, now we inject + # this list into the linker script through the define + # KERNELSPACE_OBJECT_FILES + set(def -DKERNELSPACE_OBJECT_FILES=) foreach(f ${ks}) - list(APPEND LINKER_SCRIPT_DEFINES -DKERNEL_OBJECT_FILE_${i}=${f}) - math(EXPR i "${i}+1") + set(def "${def} ${f}") endforeach() + list(APPEND LINKER_SCRIPT_DEFINES ${def}) endif() # CONFIG_APPLICATION_MEMORY # Declare MPU userspace dependencies before the linker scripts to make diff --git a/include/linker/linker-defs.h b/include/linker/linker-defs.h index c5042aeadab..87857bcf7c1 100644 --- a/include/linker/linker-defs.h +++ b/include/linker/linker-defs.h @@ -112,34 +112,27 @@ * their shell commands are automatically initialized by the kernel. */ +#ifdef CONFIG_APPLICATION_MEMORY +/* + * KERNELSPACE_OBJECT_FILES is a space-separated list of object files + * and libraries that belong in kernelspace. + */ +#define MAYBE_EXCLUDE_SOME_FILES EXCLUDE_FILE (KERNELSPACE_OBJECT_FILES) +#else +#define MAYBE_EXCLUDE_SOME_FILES +#endif /* CONFIG_APPLICATION_MEMORY */ + /* * APP_INPUT_SECTION should be invoked on sections that should be in * 'app' space. KERNEL_INPUT_SECTION should be invoked on sections * that should be in 'kernel' space. + * + * NB: APP_INPUT_SECTION must be invoked before + * KERNEL_INPUT_SECTION. If it is not all sections will end up in + * kernelspace. */ -#ifdef CONFIG_APPLICATION_MEMORY - -#ifndef NUM_KERNEL_OBJECT_FILES -#error "Expected NUM_KERNEL_OBJECT_FILES to be defined" -#elif NUM_KERNEL_OBJECT_FILES > 32 -#error "Max supported kernel objects is 32." -/* TODO: Using the preprocessor to do this was a mistake. Rewrite to - scale better. e.g. by aggregating the kernel objects into two - archives like KBuild did.*/ -#endif - -#define X(i, j) KERNEL_OBJECT_FILE_##i (j) -#define Y(i, j) KERNEL_OBJECT_FILE_##i - -#define KERNEL_INPUT_SECTION(sect) \ - UTIL_LISTIFY(NUM_KERNEL_OBJECT_FILES, X, sect) -#define APP_INPUT_SECTION(sect) \ - *(EXCLUDE_FILE (UTIL_LISTIFY(NUM_KERNEL_OBJECT_FILES, Y, ~)) sect) - -#else -#define KERNEL_INPUT_SECTION(sect) *(sect) -#define APP_INPUT_SECTION(sect) *(sect) -#endif /* CONFIG_APPLICATION_MEMORY */ +#define APP_INPUT_SECTION(sect) *(MAYBE_EXCLUDE_SOME_FILES sect) +#define KERNEL_INPUT_SECTION(sect) *(sect) #define APP_SMEM_SECTION() KEEP(*(SORT(data_smem_[_a-zA-Z0-9]*)))