diff --git a/CMakeLists.txt b/CMakeLists.txt index ccff722a319..a282b51163b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -165,8 +165,6 @@ endif() if(NOT CONFIG_NATIVE_APPLICATION) zephyr_ld_options( - -nostartfiles - -nodefaultlibs -nostdlib -static -no-pie @@ -748,7 +746,7 @@ function(construct_add_custom_command_for_linker_pass linker_output_name output_ COMMAND ${CMAKE_C_COMPILER} -x assembler-with-cpp ${NOSTDINC_F} - -undef + ${NOSYSDEF_CFLAG} -MD -MF ${linker_cmd_file_name}.dep -MT ${BASE_NAME}/${linker_cmd_file_name} ${ZEPHYR_INCLUDES} ${LINKER_SCRIPT_DEFINES} diff --git a/cmake/compiler/gcc.cmake b/cmake/compiler/gcc.cmake index a8b58088873..79f7a7b7ce0 100644 --- a/cmake/compiler/gcc.cmake +++ b/cmake/compiler/gcc.cmake @@ -53,6 +53,12 @@ find_program(CMAKE_CXX_COMPILER ${cplusplus_compiler} PATH ${TOOLCHAIN_HOME} NO_ set(NOSTDINC "") +# Note that NOSYSDEF_CFLAG may be an empty string, and +# set_ifndef() does not work with empty string. +if(NOT DEFINED NOSYSDEF_CFLAG) + set(NOSYSDEF_CFLAG -undef) +endif() + foreach(file_name include include-fixed) execute_process( COMMAND ${CMAKE_C_COMPILER} --print-file-name=${file_name} diff --git a/cmake/compiler/llvm.cmake b/cmake/compiler/llvm.cmake index 5548353f9bc..d43dbdfa1b7 100644 --- a/cmake/compiler/llvm.cmake +++ b/cmake/compiler/llvm.cmake @@ -3,6 +3,12 @@ set(NOSTDINC "") +# Note that NOSYSDEF_CFLAG may be an empty string, and +# set_ifndef() does not work with empty string. +if(NOT DEFINED NOSYSDEF_CFLAG) + set(NOSYSDEF_CFLAG -undef) +endif() + foreach(file_name include include-fixed) execute_process( COMMAND ${CMAKE_C_COMPILER} --print-file-name=${file_name} @@ -19,4 +25,3 @@ endforeach() set(CMAKE_REQUIRED_FLAGS -nostartfiles -nostdlib ${isystem_include_flags} -Wl,--unresolved-symbols=ignore-in-object-files) string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") - diff --git a/cmake/dts.cmake b/cmake/dts.cmake index 2ae55dfe59a..429ea91377a 100644 --- a/cmake/dts.cmake +++ b/cmake/dts.cmake @@ -92,7 +92,8 @@ if(CONFIG_HAS_DTS) -include ${AUTOCONF_H} ${DTC_INCLUDE_FLAG_FOR_DTS} # include the DTS source and overlays -I${ZEPHYR_BASE}/dts/common - -undef -D__DTS__ + ${NOSYSDEF_CFLAG} + -D__DTS__ -P -E ${ZEPHYR_BASE}/misc/empty_file.c -o ${BOARD}.dts.pre.tmp