Skip to content

Commit d968e47

Browse files
Arm backend: Add function to help linker force include backend (#16177)
### Summary Add a function that serves as a linker force-include mechanism to ensure the EthosU backend module gets properly linked into the final executable, even when it might otherwise be optimized out by the linker. This is needed when you use linker options that remove unused code or data then this function can be called from your runner to force the inclusion of the EthosU backend module. This might be the case when build Executorch in other projects like in ZephyrOS when you have an other set of compilers and linker flags. ### Test plan Tested by invoking the project from ZephyrOS and check if the backend get installed or not. cc @freddan80 @per @oscarandersson8218 @digantdesai Signed-off-by: Zingo Andersen <[email protected]> Co-authored-by: Johan Alfven <[email protected]>
1 parent b6935ad commit d968e47

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

backends/arm/runtime/EthosUBackend.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,33 @@ class EthosUBackend final : public ::executorch::runtime::BackendInterface {
540540
};
541541

542542
namespace {
543-
auto backend = EthosUBackend();
544-
Backend backend_id{"EthosUBackend", &backend};
545-
static auto registered = register_backend(backend_id);
543+
auto EthosUBackend_backend = EthosUBackend();
544+
Backend EthosUBackend_id{"EthosUBackend", &EthosUBackend_backend};
545+
static executorch::runtime::Error EthosUBackend_registered =
546+
register_backend(EthosUBackend_id);
547+
548+
#ifdef __ZEPHYR__
549+
/**
550+
* This function serves as a linker force-include mechanism to ensure the
551+
* EthosU backend module gets properly linked into the final executable,
552+
* even when it might otherwise be optimized out by the linker due to
553+
* linker options that remove unused code or data for example
554+
* if you link with --gc-sections
555+
* This function can be called from your runner to force the inclusion of
556+
* the EthosU backend module. As a bonus it will return the status of the
557+
* backend registration, so you can also check if the registration was
558+
* successful.
559+
*/
560+
561+
// Warning: This should not be considered to be an API and might get removed
562+
// without notice in a future release if a better way to solve this is
563+
// implemented.
564+
extern "C" executorch::runtime::Error
565+
executorch_delegate_EthosUBackend_registered() {
566+
return EthosUBackend_registered;
567+
}
568+
#endif
569+
546570
} // namespace
547571

548572
} // namespace arm

0 commit comments

Comments
 (0)