Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linker: Re-implement {APP,KERNEL}_INPUT_SECTION #9280

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
43 changes: 20 additions & 23 deletions include/linker/linker-defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,31 +113,28 @@
*/

#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)
#define APP_SMEM_SECTION() KEEP(*(SORT(data_smem_[_a-zA-Z0-9]*)))

/*
* 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 KERNEL_INPUT_SECTION(sect) *(sect)
#define APP_INPUT_SECTION(sect) *(sect)
#define APP_SMEM_SECTION() KEEP(*(SORT(data_smem_[_a-zA-Z0-9]*)))
#endif
#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.
*/
#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]*)))

#ifdef CONFIG_X86 /* LINKER FILES: defines used by linker script */
/* Should be moved to linker-common-defs.h */
Expand Down