From b96ecd621a269a100805474709ea0c359f3a4e58 Mon Sep 17 00:00:00 2001 From: Chun-Chieh Li Date: Thu, 24 Oct 2024 10:57:47 +0800 Subject: [PATCH] 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 | 10 ++++++++++ .../ESP8266Interface.cpp | 14 ++++++++++++++ .../TARGET_STM/COMPONENT_EMW3080B/CMakeLists.txt | 10 ++++++++++ .../COMPONENT_EMW3080B/EMW3080BInterface.cpp | 14 ++++++++++++++ 4 files changed, 48 insertions(+) diff --git a/connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/CMakeLists.txt b/connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/CMakeLists.txt index 682139f0e84..b0d5e9fbd52 100644 --- a/connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/CMakeLists.txt +++ b/connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/CMakeLists.txt @@ -12,3 +12,13 @@ target_include_directories(mbed-wifi . ./ESP8266 ) + +# Link override object file from static library +if("MBED_CONF_ESP8266_PROVIDE_DEFAULT=1" IN_LIST MBED_CONFIG_DEFINITIONS) + if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM") + target_link_options(mbed-wifi + INTERFACE + LINKER:--undefined=LINK_ESP8266INTERFACE_CPP + ) + endif() +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/TARGET_STM/COMPONENT_EMW3080B/CMakeLists.txt b/connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/CMakeLists.txt index a91dc52b119..8dda87839c6 100644 --- a/connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/CMakeLists.txt +++ b/connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/CMakeLists.txt @@ -21,3 +21,13 @@ target_sources(mbed-wifi mx_wifi/core/mx_wifi_ipc.c mx_wifi/core/mx_wifi_slip.c ) + +# Link override object file from static library +if("MBED_CONF_EMW3080B_PROVIDE_DEFAULT=1" IN_LIST MBED_CONFIG_DEFINITIONS) + if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM") + target_link_options(mbed-wifi + INTERFACE + LINKER:--undefined=LINK_EMW3080BINTERFACE_CPP + ) + endif() +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..1773b9282e5 100644 --- a/connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/EMW3080BInterface.cpp +++ b/connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/EMW3080BInterface.cpp @@ -352,6 +352,20 @@ WiFiInterface *WiFiInterface::get_default_instance() static EMW3080BInterface emw; return &emw; } + +/* + * 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 /* MBED_CONF_EMW3080B_PROVIDE_DEFAULT */