From 1c2de10c064eb0c4dd1c9359b7100f809a54421f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B8e?= Date: Tue, 2 Jan 2018 15:54:16 +0100 Subject: [PATCH] cmake: ninja: Change how CMake names the kernelspace archives MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The linker script places kernelspace and userspace archives in different sections. But the linker script itself does not determine what archives are in what space, that is done by CMake. CMake passes the list of kernelspace archives to the linker script through defines, like this: -DNUM_KERNEL_OBJECT_FILES=3 -DKERNEL_OBJECT_FILE_0=path/to/archive_a.a -DKERNEL_OBJECT_FILE_1=path/to/archive_b.a -DKERNEL_OBJECT_FILE_2=path/to/archive_c.a These paths are relative, and since Ninja and Make invoke the linker with different "working directories"[0], the relative paths need to be different. This patch rectifies the relative path when using Ninja. This fixes #5343 [0] https://gitlab.kitware.com/cmake/cmake/issues/17448 Signed-off-by: Sebastian Bøe --- CMakeLists.txt | 12 +++++++++++- include/linker/linker-defs.h | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 04d4753d1c..4c9e931730 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -475,7 +475,17 @@ if(CONFIG_APPLICATION_MEMORY) string(SUBSTRING ${fixed_path} 1 -1 fixed_path) endif() - list(APPEND ks "${fixed_path}lib${target_name}.a") + set(fixed_path "${fixed_path}lib${target_name}.a") + + if(CMAKE_GENERATOR STREQUAL "Ninja") + # Ninja invokes the linker from the root of the build directory + # (APPLICATION_BINARY_DIR) instead of from the build/zephyr + # directory (PROJECT_BINARY_DIR). So for linker-defs.h to get + # the correct path we need to prefix with zephyr/. + set(fixed_path "zephyr/${fixed_path}") + endif() + + list(APPEND ks ${fixed_path}) endforeach() # We are done constructing kernel_object_file_list, now we inject this diff --git a/include/linker/linker-defs.h b/include/linker/linker-defs.h index 486f1cd0d0..3d9de4c12f 100644 --- a/include/linker/linker-defs.h +++ b/include/linker/linker-defs.h @@ -115,8 +115,8 @@ archives like KBuild did.*/ #endif -#define X(i, j) KERNEL_OBJECT_FILE_##i (j) -#define Y(i, j) *KERNEL_OBJECT_FILE_##i +#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)