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 24, 2024
1 parent dfa5925 commit b96ecd6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,20 @@ WiFiInterface *WiFiInterface::get_default_instance()
static EMW3080BInterface emw;
return &emw;
}

/*
* 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 /* MBED_CONF_EMW3080B_PROVIDE_DEFAULT */


Expand Down

0 comments on commit b96ecd6

Please sign in to comment.