diff --git a/cmake/compiler/gcc/target_xtensa.cmake b/cmake/compiler/gcc/target_xtensa.cmake index 177830427dbdda2..5321204c2df5e74 100644 --- a/cmake/compiler/gcc/target_xtensa.cmake +++ b/cmake/compiler/gcc/target_xtensa.cmake @@ -17,5 +17,4 @@ set(LLEXT_APPEND_FLAGS -fPIC -nostdlib -nodefaultlibs - -shared ) diff --git a/cmake/modules/extensions.cmake b/cmake/modules/extensions.cmake index 594d8104a3b544d..8a47db809f6a9ce 100644 --- a/cmake/modules/extensions.cmake +++ b/cmake/modules/extensions.cmake @@ -4869,24 +4869,48 @@ function(add_llext_target target_name) "$" ) - # Compile the source file to an object file using current Zephyr settings - # but a different set of flags - add_library(${target_name}_lib OBJECT ${source_file}) - target_compile_definitions(${target_name}_lib PRIVATE + # Compile the source file using current Zephyr settings but a + # different set of flags + + set(link_target ${target_name}_lib) + if(CONFIG_ARM) + + # Create an object library to compile the source file + add_library(${link_target} OBJECT ${source_file}) + set(linked_file $) + + elseif(CONFIG_XTENSA) + + # Ensure shared library support is enabled + set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS true) + + # Create a shared library + add_library(${link_target} SHARED ${source_file}) + set(linked_file $) + + # Add the llext flags to the linking step as well + # (the linker will ignore the compilation-related ones) + target_link_options(${link_target} PRIVATE + ${LLEXT_APPEND_FLAGS} + ) + + endif() + + target_compile_definitions(${link_target} PRIVATE $ ) - target_compile_options(${target_name}_lib PRIVATE + target_compile_options(${link_target} PRIVATE ${zephyr_filtered_flags} ${LLEXT_APPEND_FLAGS} ${LLEXT_C_FLAGS} ) - target_include_directories(${target_name}_lib PRIVATE + target_include_directories(${link_target} PRIVATE $ ) - target_include_directories(${target_name}_lib SYSTEM PUBLIC + target_include_directories(${link_target} SYSTEM PUBLIC $ ) - add_dependencies(${target_name}_lib + add_dependencies(${link_target} zephyr_interface zephyr_generated_headers ) @@ -4897,31 +4921,22 @@ function(add_llext_target target_name) # No conversion required, simply copy the object file add_custom_command( OUTPUT ${output_file} - COMMAND ${CMAKE_COMMAND} -E copy $ ${output_file} - DEPENDS ${target_name}_lib $ + COMMAND ${CMAKE_COMMAND} -E copy ${linked_file} ${output_file} + DEPENDS ${link_target} ${linked_file} ) elseif(CONFIG_XTENSA) - # Generate an intermediate file name - get_filename_component(output_dir ${output_file} DIRECTORY) - get_filename_component(output_name_we ${output_file} NAME_WE) - set(pre_output_file ${output_dir}/${output_name_we}.pre.llext) - - # Need to convert the object file to a shared library, then strip some sections + # Need to strip the shared library of some sections add_custom_command( OUTPUT ${output_file} - BYPRODUCTS ${pre_output_file} - COMMAND ${CMAKE_C_COMPILER} ${LLEXT_APPEND_FLAGS} - -o ${pre_output_file} - $ COMMAND $ $ $.xt.* - $${pre_output_file} + $${linked_file} $${output_file} $ - DEPENDS ${target_name}_lib $ + DEPENDS ${link_target} ${linked_file} ) else()