1# SPDX-License-Identifier: Apache-2.0 2 3# See root CMakeLists.txt for description and expectations of these macros 4 5macro(toolchain_ld_baremetal) 6 7 # LINKERFLAGPREFIX comes from linker/lld/target.cmake 8 zephyr_ld_options( 9 -nostdlib 10 -static 11 ${LINKERFLAGPREFIX},-X 12 ${LINKERFLAGPREFIX},-N 13 ) 14 15 # Force LLVM to use built-in lld linker 16 if(NOT CONFIG_LLVM_USE_LD) 17 zephyr_ld_options( 18 -fuse-ld=lld 19 ) 20 endif() 21 22 # Funny thing is if this is set to =error, some architectures will 23 # skip this flag even though the compiler flag check passes 24 # (e.g. ARC and Xtensa). So warning should be the default for now. 25 # 26 # Skip this for native application as Zephyr only provides 27 # additions to the host toolchain linker script. The relocation 28 # sections (.rel*) requires us to override those provided 29 # by host toolchain. As we can't account for all possible 30 # combination of compiler and linker on all machines used 31 # for development, it is better to turn this off. 32 # 33 # CONFIG_LINKER_ORPHAN_SECTION_PLACE is to place the orphan sections 34 # without any warnings or errors, which is the default behavior. 35 # So there is no need to explicitly set a linker flag. 36 if(CONFIG_LINKER_ORPHAN_SECTION_WARN) 37 zephyr_ld_options( 38 ${LINKERFLAGPREFIX},--orphan-handling=warn 39 ) 40 elseif(CONFIG_LINKER_ORPHAN_SECTION_ERROR) 41 zephyr_ld_options( 42 ${LINKERFLAGPREFIX},--orphan-handling=error 43 ) 44 endif() 45 46endmacro() 47