From 5b5e7b05557e3140fe7cb0c197cbac1b73116c03 Mon Sep 17 00:00:00 2001 From: Chun-Chieh Li Date: Wed, 9 Oct 2024 13:36:29 +0800 Subject: [PATCH 1/2] Fix WiFi link error for as default network interface This fixes WiFi doesn't get linked in when configued as default network interface. --- connectivity/netsocket/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/connectivity/netsocket/CMakeLists.txt b/connectivity/netsocket/CMakeLists.txt index 271b0f7854e..51f199d1e63 100644 --- a/connectivity/netsocket/CMakeLists.txt +++ b/connectivity/netsocket/CMakeLists.txt @@ -74,6 +74,12 @@ if("MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE=MESH" IN_LIST MBED_CONFIG_DE target_link_libraries(mbed-netsocket-api PUBLIC mbed-nanostack-mbed_mesh_api) endif() +# Similarly if wifi networking is used bring in that library +if("MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE=WIFI" IN_LIST MBED_CONFIG_DEFINITIONS) + if(TARGET mbed-wifi) + target_link_libraries(mbed-netsocket-api PUBLIC mbed-wifi) + endif() +endif() if("DEVICE_EMAC=1" IN_LIST MBED_TARGET_DEFINITIONS) target_link_libraries(mbed-netsocket-api From aab8e207ae71df8fe2548a1420d6d4fe95bade70 Mon Sep 17 00:00:00 2001 From: Chun-Chieh Li Date: Thu, 24 Oct 2024 10:57:47 +0800 Subject: [PATCH 2/2] Support WiFi as default network interface This requires support for weak symbol override. Object files arcived in static library don't always participate in linking, dependent on linker and link order. The steps below pull in the override object file anyway even though it comes from static library: 1. Add e.g. GCC linker option "--undefined=" 2. Add function with 'extern "C"' in override source file See: https://stackoverflow.com/questions/42588983/what-does-the-gnu-ld-undefined-option-do --- .../COMPONENT_ESPRESSIF_ESP8266/CMakeLists.txt | 12 ++++++++++++ .../ESP8266Interface.cpp | 14 ++++++++++++++ .../wifi/COMPONENT_WHD/whd_mac/CMakeLists.txt | 12 ++++++++++++ .../whd_mac/interface/whd_interface.cpp | 14 ++++++++++++++ .../TARGET_STM/COMPONENT_EMW3080B/CMakeLists.txt | 12 ++++++++++++ .../COMPONENT_EMW3080B/EMW3080BInterface.cpp | 16 ++++++++++++++++ .../drivers/wifi/TARGET_WICED/CMakeLists.txt | 14 +++++++++++++- .../wiced_interface/default_wifi_interface.cpp | 14 ++++++++++++++ 8 files changed, 107 insertions(+), 1 deletion(-) diff --git a/connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/CMakeLists.txt b/connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/CMakeLists.txt index 682139f0e84..235a30e4005 100644 --- a/connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/CMakeLists.txt +++ b/connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/CMakeLists.txt @@ -12,3 +12,15 @@ target_include_directories(mbed-wifi . ./ESP8266 ) + +# Link override object file coming from static library anyway +# +# NOTE: This linker option is to pretend undefined symbol and won't cause +# undefined symbol error even though the override object file actually +# doesn't provide such symbol definition. +if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM") + target_link_options(mbed-wifi + INTERFACE + LINKER:--undefined=LINK_ESP8266INTERFACE_CPP + ) +endif() diff --git a/connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/ESP8266Interface.cpp b/connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/ESP8266Interface.cpp index ed040325cea..f8eb93f9b5e 100644 --- a/connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/ESP8266Interface.cpp +++ b/connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/ESP8266Interface.cpp @@ -1149,6 +1149,20 @@ WiFiInterface *WiFiInterface::get_default_instance() return &esp; } +/* + * With e.g. GCC linker option "--undefined=", pull in this + * object file anyway for being able to override weak symbol successfully + * even though from static library. See: + * https://stackoverflow.com/questions/42588983/what-does-the-gnu-ld-undefined-option-do + * + * NOTE: For C++ name mangling, 'extern "C"' is necessary to match the + * symbol correctly. + */ +extern "C" +void LINK_ESP8266INTERFACE_CPP(void) +{ +} + #endif void ESP8266Interface::refresh_conn_state_cb() diff --git a/connectivity/drivers/wifi/COMPONENT_WHD/whd_mac/CMakeLists.txt b/connectivity/drivers/wifi/COMPONENT_WHD/whd_mac/CMakeLists.txt index 44536a7d49d..2d6069b80d3 100644 --- a/connectivity/drivers/wifi/COMPONENT_WHD/whd_mac/CMakeLists.txt +++ b/connectivity/drivers/wifi/COMPONENT_WHD/whd_mac/CMakeLists.txt @@ -21,3 +21,15 @@ target_sources(mbed-wifi utils/cydhcp_server_debug.cpp utils/cynetwork_utils.c ) + +# Link override object file coming from static library anyway +# +# NOTE: This linker option is to pretend undefined symbol and won't cause +# undefined symbol error even though the override object file actually +# doesn't provide such symbol definition. +if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM") + target_link_options(mbed-wifi + INTERFACE + LINKER:--undefined=LINK_WHD_INTERFACE_CPP + ) +endif() diff --git a/connectivity/drivers/wifi/COMPONENT_WHD/whd_mac/interface/whd_interface.cpp b/connectivity/drivers/wifi/COMPONENT_WHD/whd_mac/interface/whd_interface.cpp index 6798817727a..068eba037a4 100644 --- a/connectivity/drivers/wifi/COMPONENT_WHD/whd_mac/interface/whd_interface.cpp +++ b/connectivity/drivers/wifi/COMPONENT_WHD/whd_mac/interface/whd_interface.cpp @@ -32,3 +32,17 @@ WhdSoftAPInterface *WhdSoftAPInterface::get_default_instance() static WhdSoftAPInterface softap; return &softap; } + +/* + * With e.g. GCC linker option "--undefined=", pull in this + * object file anyway for being able to override weak symbol successfully + * even though from static library. See: + * https://stackoverflow.com/questions/42588983/what-does-the-gnu-ld-undefined-option-do + * + * NOTE: For C++ name mangling, 'extern "C"' is necessary to match the + * symbol correctly. + */ +extern "C" +void LINK_WHD_INTERFACE_CPP(void) +{ +} diff --git a/connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/CMakeLists.txt b/connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/CMakeLists.txt index a91dc52b119..b26af364e43 100644 --- a/connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/CMakeLists.txt +++ b/connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/CMakeLists.txt @@ -21,3 +21,15 @@ target_sources(mbed-wifi mx_wifi/core/mx_wifi_ipc.c mx_wifi/core/mx_wifi_slip.c ) + +# Link override object file coming from static library anyway +# +# NOTE: This linker option is to pretend undefined symbol and won't cause +# undefined symbol error even though the override object file actually +# doesn't provide such symbol definition. +if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM") + target_link_options(mbed-wifi + INTERFACE + LINKER:--undefined=LINK_EMW3080BINTERFACE_CPP + ) +endif() diff --git a/connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/EMW3080BInterface.cpp b/connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/EMW3080BInterface.cpp index c59407d7ffc..bca8ccb3235 100644 --- a/connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/EMW3080BInterface.cpp +++ b/connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/EMW3080BInterface.cpp @@ -365,3 +365,19 @@ WiFiInterface *WiFiInterface::get_target_default_instance() return &wifi; } #endif /* MBED_CONF_NSAPI_PRESENT */ + +#if MBED_CONF_EMW3080B_PROVIDE_DEFAULT || defined(MBED_CONF_NSAPI_PRESENT) +/* + * With e.g. GCC linker option "--undefined=", pull in this + * object file anyway for being able to override weak symbol successfully + * even though from static library. See: + * https://stackoverflow.com/questions/42588983/what-does-the-gnu-ld-undefined-option-do + * + * NOTE: For C++ name mangling, 'extern "C"' is necessary to match the + * symbol correctly. + */ +extern "C" +void LINK_EMW3080BINTERFACE_CPP(void) +{ +} +#endif diff --git a/connectivity/drivers/wifi/TARGET_WICED/CMakeLists.txt b/connectivity/drivers/wifi/TARGET_WICED/CMakeLists.txt index eeafb531385..44a3e35cebd 100644 --- a/connectivity/drivers/wifi/TARGET_WICED/CMakeLists.txt +++ b/connectivity/drivers/wifi/TARGET_WICED/CMakeLists.txt @@ -23,4 +23,16 @@ target_sources(mbed-wiced wiced_interface/default_wifi_interface.cpp ) -target_link_libraries(mbed-wifi PUBLIC mbed-wiced) \ No newline at end of file +target_link_libraries(mbed-wifi PUBLIC mbed-wiced) + +# Link override object file coming from static library anyway +# +# NOTE: This linker option is to pretend undefined symbol and won't cause +# undefined symbol error even though the override object file actually +# doesn't provide such symbol definition. +if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM") + target_link_options(mbed-wifi + INTERFACE + LINKER:--undefined=LINK_DEFAULT_WIFI_INTERFACE_CPP + ) +endif() diff --git a/connectivity/drivers/wifi/TARGET_WICED/wiced_interface/default_wifi_interface.cpp b/connectivity/drivers/wifi/TARGET_WICED/wiced_interface/default_wifi_interface.cpp index 190b3ad5917..9222e31b81f 100644 --- a/connectivity/drivers/wifi/TARGET_WICED/wiced_interface/default_wifi_interface.cpp +++ b/connectivity/drivers/wifi/TARGET_WICED/wiced_interface/default_wifi_interface.cpp @@ -25,4 +25,18 @@ WiFiInterface *WiFiInterface::get_target_default_instance() return &wifi; } +/* + * With e.g. GCC linker option "--undefined=", pull in this + * object file anyway for being able to override weak symbol successfully + * even though from static library. See: + * https://stackoverflow.com/questions/42588983/what-does-the-gnu-ld-undefined-option-do + * + * NOTE: For C++ name mangling, 'extern "C"' is necessary to match the + * symbol correctly. + */ +extern "C" +void LINK_DEFAULT_WIFI_INTERFACE_CPP(void) +{ +} + #endif