From 424590f7d84df361e03b62128dd3c7032aa71656 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 5 Jul 2023 10:13:08 -0700 Subject: [PATCH] cmake/compiler: Add linker_script compiler property This property specifies the flag used to pass the linker script filename through the compiler front end tot he linker. For clang, we use the general purpose linker-pass through -Wl flag with -T: -Wl,-T as clang doesn't support -T. For gcc, we use -T directly as this keeps the picolibc specs file from inserting the picolibc linker script as well. If the compiler doesn't specify a value, we continue to use -Wl,-T as before. Signed-off-by: Keith Packard --- CMakeLists.txt | 5 +++-- cmake/compiler/clang/compiler_flags.cmake | 3 +++ cmake/compiler/compiler_flags_template.cmake | 3 +++ cmake/compiler/gcc/compiler_flags.cmake | 3 +++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b5ffba54fbc..0f03c70eb24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -485,8 +485,9 @@ if(CONFIG_USERSPACE) endif() get_property(TOPT GLOBAL PROPERTY TOPT) -set_ifndef( TOPT -Wl,-T) # clang doesn't pick -T for some reason and complains, - # while -Wl,-T works for both, gcc and clang +get_property(COMPILER_TOPT TARGET compiler PROPERTY linker_script) +set_ifndef( TOPT "${COMPILER_TOPT}") +set_ifndef( TOPT -Wl,-T) # Use this if the compiler driver doesn't set a value if(CONFIG_HAVE_CUSTOM_LINKER_SCRIPT) set(LINKER_SCRIPT ${APPLICATION_SOURCE_DIR}/${CONFIG_CUSTOM_LINKER_SCRIPT}) diff --git a/cmake/compiler/clang/compiler_flags.cmake b/cmake/compiler/clang/compiler_flags.cmake index 7a3fbdc1c3a..12868539d2f 100644 --- a/cmake/compiler/clang/compiler_flags.cmake +++ b/cmake/compiler/clang/compiler_flags.cmake @@ -23,6 +23,9 @@ set_compiler_property(PROPERTY diagnostic -fcolor-diagnostics) # clang flag to save temporary object files set_compiler_property(PROPERTY save_temps -save-temps) +# clang doesn't handle the -T flag +set_compiler_property(PROPERTY linker_script -Wl,-T) + ####################################################### # This section covers flags related to warning levels # ####################################################### diff --git a/cmake/compiler/compiler_flags_template.cmake b/cmake/compiler/compiler_flags_template.cmake index 4614866b2ce..5f15d1b8007 100644 --- a/cmake/compiler/compiler_flags_template.cmake +++ b/cmake/compiler/compiler_flags_template.cmake @@ -106,6 +106,9 @@ set_compiler_property(PROPERTY debug) # Flags to save temporary object files set_compiler_property(PROPERTY save_temps) +# Flag to specify linker script +set_compiler_property(PROPERTY linker_script) + set_compiler_property(PROPERTY no_common) # Flags for imacros. The specific header must be appended by user. diff --git a/cmake/compiler/gcc/compiler_flags.cmake b/cmake/compiler/gcc/compiler_flags.cmake index 75c54577cdc..3283c0d86a6 100644 --- a/cmake/compiler/gcc/compiler_flags.cmake +++ b/cmake/compiler/gcc/compiler_flags.cmake @@ -182,6 +182,9 @@ set_compiler_property(PROPERTY debug -g) # Flags to save temporary object files set_compiler_property(PROPERTY save_temps -save-temps=obj) +# Flag to specify linker script +set_compiler_property(PROPERTY linker_script -T) + # Flags to not track macro expansion set_compiler_property(PROPERTY no_track_macro_expansion -ftrack-macro-expansion=0)