Skip to content

Commit

Permalink
Support WiFi as default network interface
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ccli8 committed Oct 25, 2024
1 parent 5b5e7b0 commit aab8e20
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,20 @@ WiFiInterface *WiFiInterface::get_default_instance()
return &esp;
}

/*
* With e.g. GCC linker option "--undefined=<LINK_FOO>", 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
* <LINK_FOO> symbol correctly.
*/
extern "C"
void LINK_ESP8266INTERFACE_CPP(void)
{
}

#endif

void ESP8266Interface::refresh_conn_state_cb()
Expand Down
12 changes: 12 additions & 0 deletions connectivity/drivers/wifi/COMPONENT_WHD/whd_mac/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,17 @@ WhdSoftAPInterface *WhdSoftAPInterface::get_default_instance()
static WhdSoftAPInterface softap;
return &softap;
}

/*
* With e.g. GCC linker option "--undefined=<LINK_FOO>", 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
* <LINK_FOO> symbol correctly.
*/
extern "C"
void LINK_WHD_INTERFACE_CPP(void)
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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=<LINK_FOO>", 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
* <LINK_FOO> symbol correctly.
*/
extern "C"
void LINK_EMW3080BINTERFACE_CPP(void)
{
}
#endif
14 changes: 13 additions & 1 deletion connectivity/drivers/wifi/TARGET_WICED/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,16 @@ target_sources(mbed-wiced
wiced_interface/default_wifi_interface.cpp
)

target_link_libraries(mbed-wifi PUBLIC mbed-wiced)
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()
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,18 @@ WiFiInterface *WiFiInterface::get_target_default_instance()
return &wifi;
}

/*
* With e.g. GCC linker option "--undefined=<LINK_FOO>", 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
* <LINK_FOO> symbol correctly.
*/
extern "C"
void LINK_DEFAULT_WIFI_INTERFACE_CPP(void)
{
}

#endif

0 comments on commit aab8e20

Please sign in to comment.