diff --git a/.gitlab/CODEOWNERS b/.gitlab/CODEOWNERS index 0a860d3fad..bfe7cf3a1c 100644 --- a/.gitlab/CODEOWNERS +++ b/.gitlab/CODEOWNERS @@ -113,6 +113,7 @@ /components/idf_test/ @esp-idf-codeowners/ci /components/ieee802154/ @esp-idf-codeowners/ieee802154 /components/json/ @esp-idf-codeowners/app-utilities +/components/linux/ @esp-idf-codeowners/system /components/log/ @esp-idf-codeowners/system /components/lwip/ @esp-idf-codeowners/lwip /components/mbedtls/ @esp-idf-codeowners/app-utilities @esp-idf-codeowners/security diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b86ac6027..ec4e2bcc66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -196,6 +196,12 @@ endif() list(APPEND link_options "-fno-lto") +if(CONFIG_IDF_TARGET_LINUX AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") + list(APPEND link_options "-Wl,-dead_strip") +else() + list(APPEND link_options "-Wl,--gc-sections") +endif() + # Placing jump tables in flash would cause issues with code that required # to be placed in IRAM list(APPEND compile_options "-fno-jump-tables") diff --git a/Kconfig b/Kconfig index 9a18909c8b..17ca73813b 100644 --- a/Kconfig +++ b/Kconfig @@ -37,6 +37,10 @@ mainmenu "Espressif IoT Development Framework Configuration" string default "$IDF_TARGET" + config IDF_TARGET_LINUX + bool + default "y" if IDF_TARGET="linux" + config IDF_TARGET_ESP32 bool default "y" if IDF_TARGET="esp32" @@ -163,6 +167,7 @@ mainmenu "Espressif IoT Development Framework Configuration" config APP_BUILD_TYPE_APP_2NDBOOT bool prompt "Default (binary application + 2nd stage bootloader)" + depends on !IDF_TARGET_LINUX select APP_BUILD_GENERATE_BINARIES select APP_BUILD_BOOTLOADER select APP_BUILD_USE_FLASH_SECTIONS diff --git a/components/esp_common/include/esp_attr.h b/components/esp_common/include/esp_attr.h index 84de204618..acd895c7be 100644 --- a/components/esp_common/include/esp_attr.h +++ b/components/esp_common/include/esp_attr.h @@ -147,9 +147,14 @@ FORCE_INLINE_ATTR TYPE& operator<<=(TYPE& a, int b) { a = a << b; return a; } // // Using unique sections also means --gc-sections can remove unused // data with a custom section type set +#ifndef CONFIG_IDF_TARGET_LINUX #define _SECTION_ATTR_IMPL(SECTION, COUNTER) __attribute__((section(SECTION "." _COUNTER_STRINGIFY(COUNTER)))) - #define _COUNTER_STRINGIFY(COUNTER) #COUNTER +#else +// Custom section attributes are generally not used in the port files for Linux target, but may be found +// in the common header files. Don't declare custom sections in that case. +#define _SECTION_ATTR_IMPL(SECTION, COUNTER) +#endif /* Use IDF_DEPRECATED attribute to mark anything deprecated from use in ESP-IDF's own source code, but not deprecated for external users. diff --git a/components/esp_rom/CMakeLists.txt b/components/esp_rom/CMakeLists.txt index 251f60edfb..ad48f71bd1 100644 --- a/components/esp_rom/CMakeLists.txt +++ b/components/esp_rom/CMakeLists.txt @@ -48,8 +48,11 @@ endfunction() if(target STREQUAL "linux") # We need to disable some warnings due to the ROM code's printf implementation - if(${CMAKE_CXX_COMPILER_VERSION} GREATER "7.0.0") # TODO: clang compatibility - target_compile_options(${COMPONENT_LIB} PUBLIC -Wimplicit-fallthrough=0 -Wno-shift-count-overflow) + if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND ${CMAKE_CXX_COMPILER_VERSION} GREATER "7.0.0") + target_compile_options(${COMPONENT_LIB} PRIVATE -Wimplicit-fallthrough=0 -Wno-shift-count-overflow) + endif() + if(CMAKE_C_COMPILER_ID MATCHES "Clang") # Clang or AppleClang + target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-integer-overflow -Wno-shift-count-overflow) endif() else() target_linker_script(${COMPONENT_LIB} INTERFACE "${target}/${ld_folder}/${target}.rom.ld") diff --git a/components/linux/include/sys/lock.h b/components/linux/include/sys/lock.h new file mode 100644 index 0000000000..71d2f7654a --- /dev/null +++ b/components/linux/include/sys/lock.h @@ -0,0 +1,47 @@ +/* + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef __SYS_LOCK_H__ +#define __SYS_LOCK_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* newlib locks implementation for CONFIG_IDF_TARGET_LINUX, single threaded. + * Note, currently this doesn't implement the functions required + * when _RETARGETABLE_LOCKING is defined. They should be added. + */ + + +/* Compatibility definitions for legacy newlib locking functions */ +typedef int _lock_t; + +static inline void _lock_init(_lock_t *plock) {} +static inline void _lock_init_recursive(_lock_t *plock) {} +static inline void _lock_close(_lock_t *plock) {} +static inline void _lock_close_recursive(_lock_t *plock) {} +static inline void _lock_acquire(_lock_t *plock) {} +static inline void _lock_acquire_recursive(_lock_t *plock) {} +static inline int _lock_try_acquire(_lock_t *plock) +{ + return 1; +} +static inline int _lock_try_acquire_recursive(_lock_t *plock) +{ + return 1; +} +static inline void _lock_release(_lock_t *plock) {} +static inline void _lock_release_recursive(_lock_t *plock) {} + + +#ifdef __cplusplus +} +#endif + +#endif /* __SYS_LOCK_H__ */ diff --git a/components/linux/include/sys/queue.h b/components/linux/include/sys/queue.h index 9787d9d5f8..34f5a6caa4 100644 --- a/components/linux/include/sys/queue.h +++ b/components/linux/include/sys/queue.h @@ -1 +1,7 @@ -#include "bsd/sys/queue.h" +#if __has_include() +/* On Linux, try using sys/queue.h provided by libbsd-dev */ +#include +#else +/* Fall back to sys/queue.h which may exist e.g. on macOS */ +#include_next +#endif diff --git a/components/partition_table/CMakeLists.txt b/components/partition_table/CMakeLists.txt index 385d2a5d96..f3b607d685 100644 --- a/components/partition_table/CMakeLists.txt +++ b/components/partition_table/CMakeLists.txt @@ -1,4 +1,10 @@ -idf_component_register(PRIV_REQUIRES esptool_py) +idf_build_get_property(target IDF_TARGET) +set(priv_req) +if(NOT ${target} STREQUAL "linux") + list(APPEND priv_req esptool_py) +endif() + +idf_component_register(PRIV_REQUIRES ${priv_req}) if(BOOTLOADER_BUILD) return() diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index 273f751e6e..dfcd74d312 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -111,13 +111,10 @@ function(__build_set_default_build_specifications) list(APPEND cxx_compile_options "-std=gnu++11") - list(APPEND link_options "-Wl,--gc-sections") - idf_build_set_property(COMPILE_DEFINITIONS "${compile_definitions}" APPEND) idf_build_set_property(COMPILE_OPTIONS "${compile_options}" APPEND) idf_build_set_property(C_COMPILE_OPTIONS "${c_compile_options}" APPEND) idf_build_set_property(CXX_COMPILE_OPTIONS "${cxx_compile_options}" APPEND) - idf_build_set_property(LINK_OPTIONS "${link_options}" APPEND) endfunction() #