Skip to content

Commit 197e043

Browse files
authored
Fix wifi cannot configure as default network interface (#377)
* Fix WiFi link error for as default network interface This fixes WiFi doesn't get linked in when configued as default network interface. * 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 af80d11 commit 197e043

File tree

9 files changed

+113
-1
lines changed

9 files changed

+113
-1
lines changed

connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,15 @@ target_include_directories(mbed-wifi
1212
.
1313
./ESP8266
1414
)
15+
16+
# Link override object file coming from static library anyway
17+
#
18+
# NOTE: This linker option is to pretend undefined symbol and won't cause
19+
# undefined symbol error even though the override object file actually
20+
# doesn't provide such symbol definition.
21+
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
22+
target_link_options(mbed-wifi
23+
INTERFACE
24+
LINKER:--undefined=LINK_ESP8266INTERFACE_CPP
25+
)
26+
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/COMPONENT_WHD/whd_mac/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,15 @@ target_sources(mbed-wifi
2121
utils/cydhcp_server_debug.cpp
2222
utils/cynetwork_utils.c
2323
)
24+
25+
# Link override object file coming from static library anyway
26+
#
27+
# NOTE: This linker option is to pretend undefined symbol and won't cause
28+
# undefined symbol error even though the override object file actually
29+
# doesn't provide such symbol definition.
30+
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
31+
target_link_options(mbed-wifi
32+
INTERFACE
33+
LINKER:--undefined=LINK_WHD_INTERFACE_CPP
34+
)
35+
endif()

connectivity/drivers/wifi/COMPONENT_WHD/whd_mac/interface/whd_interface.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,17 @@ WhdSoftAPInterface *WhdSoftAPInterface::get_default_instance()
3232
static WhdSoftAPInterface softap;
3333
return &softap;
3434
}
35+
36+
/*
37+
* With e.g. GCC linker option "--undefined=<LINK_FOO>", pull in this
38+
* object file anyway for being able to override weak symbol successfully
39+
* even though from static library. See:
40+
* https://stackoverflow.com/questions/42588983/what-does-the-gnu-ld-undefined-option-do
41+
*
42+
* NOTE: For C++ name mangling, 'extern "C"' is necessary to match the
43+
* <LINK_FOO> symbol correctly.
44+
*/
45+
extern "C"
46+
void LINK_WHD_INTERFACE_CPP(void)
47+
{
48+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,15 @@ 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 coming from static library anyway
26+
#
27+
# NOTE: This linker option is to pretend undefined symbol and won't cause
28+
# undefined symbol error even though the override object file actually
29+
# doesn't provide such symbol definition.
30+
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
31+
target_link_options(mbed-wifi
32+
INTERFACE
33+
LINKER:--undefined=LINK_EMW3080BINTERFACE_CPP
34+
)
35+
endif()

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,19 @@ WiFiInterface *WiFiInterface::get_target_default_instance()
365365
return &wifi;
366366
}
367367
#endif /* MBED_CONF_NSAPI_PRESENT */
368+
369+
#if MBED_CONF_EMW3080B_PROVIDE_DEFAULT || defined(MBED_CONF_NSAPI_PRESENT)
370+
/*
371+
* With e.g. GCC linker option "--undefined=<LINK_FOO>", pull in this
372+
* object file anyway for being able to override weak symbol successfully
373+
* even though from static library. See:
374+
* https://stackoverflow.com/questions/42588983/what-does-the-gnu-ld-undefined-option-do
375+
*
376+
* NOTE: For C++ name mangling, 'extern "C"' is necessary to match the
377+
* <LINK_FOO> symbol correctly.
378+
*/
379+
extern "C"
380+
void LINK_EMW3080BINTERFACE_CPP(void)
381+
{
382+
}
383+
#endif

connectivity/drivers/wifi/TARGET_WICED/CMakeLists.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,16 @@ target_sources(mbed-wiced
2323
wiced_interface/default_wifi_interface.cpp
2424
)
2525

26-
target_link_libraries(mbed-wifi PUBLIC mbed-wiced)
26+
target_link_libraries(mbed-wifi PUBLIC mbed-wiced)
27+
28+
# Link override object file coming from static library anyway
29+
#
30+
# NOTE: This linker option is to pretend undefined symbol and won't cause
31+
# undefined symbol error even though the override object file actually
32+
# doesn't provide such symbol definition.
33+
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
34+
target_link_options(mbed-wifi
35+
INTERFACE
36+
LINKER:--undefined=LINK_DEFAULT_WIFI_INTERFACE_CPP
37+
)
38+
endif()

connectivity/drivers/wifi/TARGET_WICED/wiced_interface/default_wifi_interface.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,18 @@ WiFiInterface *WiFiInterface::get_target_default_instance()
2525
return &wifi;
2626
}
2727

28+
/*
29+
* With e.g. GCC linker option "--undefined=<LINK_FOO>", pull in this
30+
* object file anyway for being able to override weak symbol successfully
31+
* even though from static library. See:
32+
* https://stackoverflow.com/questions/42588983/what-does-the-gnu-ld-undefined-option-do
33+
*
34+
* NOTE: For C++ name mangling, 'extern "C"' is necessary to match the
35+
* <LINK_FOO> symbol correctly.
36+
*/
37+
extern "C"
38+
void LINK_DEFAULT_WIFI_INTERFACE_CPP(void)
39+
{
40+
}
41+
2842
#endif

connectivity/netsocket/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ if("MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE=MESH" IN_LIST MBED_CONFIG_DE
7474
target_link_libraries(mbed-netsocket-api PUBLIC mbed-nanostack-mbed_mesh_api)
7575
endif()
7676

77+
# Similarly if wifi networking is used bring in that library
78+
if("MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE=WIFI" IN_LIST MBED_CONFIG_DEFINITIONS)
79+
if(TARGET mbed-wifi)
80+
target_link_libraries(mbed-netsocket-api PUBLIC mbed-wifi)
81+
endif()
82+
endif()
7783

7884
if("DEVICE_EMAC=1" IN_LIST MBED_TARGET_DEFINITIONS)
7985
target_link_libraries(mbed-netsocket-api

0 commit comments

Comments
 (0)