Skip to content

Commit

Permalink
linker: Re-implement {APP,KERNEL}_INPUT_SECTION
Browse files Browse the repository at this point in the history
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 <sebastian.boe@nordicsemi.no>
  • Loading branch information
SebastianBoe authored and nashif committed Aug 17, 2018
1 parent 964f6dc commit cbe7b4f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 30 deletions.
13 changes: 6 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 16 additions & 23 deletions include/linker/linker-defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]*)))

Expand Down

0 comments on commit cbe7b4f

Please sign in to comment.