Skip to content

Commit b96ecd6

Browse files
committed
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=<LINK_FOO>" 2. Add <LINK_FOO> function with 'extern "C"' in override source file See: https://stackoverflow.com/questions/42588983/what-does-the-gnu-ld-undefined-option-do
1 parent dfa5925 commit b96ecd6

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,13 @@ target_include_directories(mbed-wifi
1212
.
1313
./ESP8266
1414
)
15+
16+
# Link override object file from static library
17+
if("MBED_CONF_ESP8266_PROVIDE_DEFAULT=1" IN_LIST MBED_CONFIG_DEFINITIONS)
18+
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
19+
target_link_options(mbed-wifi
20+
INTERFACE
21+
LINKER:--undefined=LINK_ESP8266INTERFACE_CPP
22+
)
23+
endif()
24+
endif()

connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/ESP8266Interface.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,20 @@ WiFiInterface *WiFiInterface::get_default_instance()
11491149
return &esp;
11501150
}
11511151

1152+
/*
1153+
* With e.g. GCC linker option "--undefined=<LINK_FOO>", pull in this
1154+
* object file anyway for being able to override weak symbol successfully
1155+
* even though from static library. See:
1156+
* https://stackoverflow.com/questions/42588983/what-does-the-gnu-ld-undefined-option-do
1157+
*
1158+
* NOTE: For C++ name mangling, 'extern "C"' is necessary to match the
1159+
* <LINK_FOO> symbol correctly.
1160+
*/
1161+
extern "C"
1162+
void LINK_ESP8266INTERFACE_CPP(void)
1163+
{
1164+
}
1165+
11521166
#endif
11531167

11541168
void ESP8266Interface::refresh_conn_state_cb()

connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,13 @@ target_sources(mbed-wifi
2121
mx_wifi/core/mx_wifi_ipc.c
2222
mx_wifi/core/mx_wifi_slip.c
2323
)
24+
25+
# Link override object file from static library
26+
if("MBED_CONF_EMW3080B_PROVIDE_DEFAULT=1" IN_LIST MBED_CONFIG_DEFINITIONS)
27+
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
28+
target_link_options(mbed-wifi
29+
INTERFACE
30+
LINKER:--undefined=LINK_EMW3080BINTERFACE_CPP
31+
)
32+
endif()
33+
endif()

connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/EMW3080BInterface.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,20 @@ WiFiInterface *WiFiInterface::get_default_instance()
352352
static EMW3080BInterface emw;
353353
return &emw;
354354
}
355+
356+
/*
357+
* With e.g. GCC linker option "--undefined=<LINK_FOO>", pull in this
358+
* object file anyway for being able to override weak symbol successfully
359+
* even though from static library. See:
360+
* https://stackoverflow.com/questions/42588983/what-does-the-gnu-ld-undefined-option-do
361+
*
362+
* NOTE: For C++ name mangling, 'extern "C"' is necessary to match the
363+
* <LINK_FOO> symbol correctly.
364+
*/
365+
extern "C"
366+
void LINK_EMW3080BINTERFACE_CPP(void)
367+
{
368+
}
355369
#endif /* MBED_CONF_EMW3080B_PROVIDE_DEFAULT */
356370

357371

0 commit comments

Comments
 (0)