Skip to content

Commit 624c208

Browse files
keith-packardrlubos
authored andcommitted
[nrf fromtree] 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 <[email protected]> (cherry picked from commit 424590f)
1 parent bb6a7db commit 624c208

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,9 @@ if(CONFIG_USERSPACE)
469469
endif()
470470

471471
get_property(TOPT GLOBAL PROPERTY TOPT)
472-
set_ifndef( TOPT -Wl,-T) # clang doesn't pick -T for some reason and complains,
473-
# while -Wl,-T works for both, gcc and clang
472+
get_property(COMPILER_TOPT TARGET compiler PROPERTY linker_script)
473+
set_ifndef( TOPT "${COMPILER_TOPT}")
474+
set_ifndef( TOPT -Wl,-T) # Use this if the compiler driver doesn't set a value
474475

475476
if(CONFIG_HAVE_CUSTOM_LINKER_SCRIPT)
476477
set(LINKER_SCRIPT ${APPLICATION_SOURCE_DIR}/${CONFIG_CUSTOM_LINKER_SCRIPT})

cmake/compiler/clang/compiler_flags.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ set_compiler_property(PROPERTY diagnostic -fcolor-diagnostics)
2323
# clang flag to save temporary object files
2424
set_compiler_property(PROPERTY save_temps -save-temps)
2525

26+
# clang doesn't handle the -T flag
27+
set_compiler_property(PROPERTY linker_script -Wl,-T)
28+
2629
#######################################################
2730
# This section covers flags related to warning levels #
2831
#######################################################

cmake/compiler/compiler_flags_template.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ set_compiler_property(PROPERTY debug)
106106
# Flags to save temporary object files
107107
set_compiler_property(PROPERTY save_temps)
108108

109+
# Flag to specify linker script
110+
set_compiler_property(PROPERTY linker_script)
111+
109112
set_compiler_property(PROPERTY no_common)
110113

111114
# Flags for imacros. The specific header must be appended by user.

cmake/compiler/gcc/compiler_flags.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ set_compiler_property(PROPERTY debug -g)
182182
# Flags to save temporary object files
183183
set_compiler_property(PROPERTY save_temps -save-temps=obj)
184184

185+
# Flag to specify linker script
186+
set_compiler_property(PROPERTY linker_script -T)
187+
185188
# GCC 11 by default emits DWARF version 5 which cannot be parsed by
186189
# pyelftools. Can be removed once pyelftools supports v5.
187190
check_set_compiler_property(APPEND PROPERTY debug -gdwarf-4)

0 commit comments

Comments
 (0)