Skip to content

Commit 1418b15

Browse files
larryliu0820facebook-github-bot
authored andcommitted
Use a preprocessor flag to optionally depend on dynamic linking header
Summary: we need to install libdl in order to ``` #include <dlfcn.h> ``` I'm turning this feature on based on host os. If user wants to enable it, they need to make sure `dlfcn.h` header is available which it should for most UNIX-like host OSes. Added comments for that. Reviewed By: digantdesai, dbort Differential Revision: D47886884 fbshipit-source-id: fdf4db841bd066dcf47f16ea622e56e35f48e660
1 parent 0c330f8 commit 1418b15

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

runtime/platform/system.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
*/
1515
#pragma once
1616

17-
#if defined(__linux__) || defined(__APPLE__)
17+
/**
18+
* To enable dynamic linking debugging capability on UNIX-like OS. If enabled
19+
* and see an error like: `undefined symbol: dladdr`, install `libdl` to fix.
20+
*/
21+
#if defined(ET_USE_LIBDL)
1822
#include <dlfcn.h>
1923
#endif
2024

@@ -30,7 +34,7 @@ extern "C" {
3034
* @retval The path to the shared library containing the symbol.
3135
*/
3236
inline const char* et_pal_get_shared_library_name(const void* addr) {
33-
#if defined(__linux__) || defined(__APPLE__)
37+
#if defined(ET_USE_LIBDL)
3438
Dl_info info;
3539
if (dladdr(addr, &info) && info.dli_fname) {
3640
return info.dli_fname;

runtime/platform/targets.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ def define_common_targets():
9292
exported_deps = [
9393
":compiler",
9494
],
95+
exported_preprocessor_flags = select(
96+
{
97+
"DEFAULT": [],
98+
"ovr_config//os:linux": ["-DET_USE_LIBDL"],
99+
"ovr_config//os:macos": ["-DET_USE_LIBDL"],
100+
},
101+
),
95102
visibility = [
96103
"//executorch/...",
97104
"@EXECUTORCH_CLIENTS",

0 commit comments

Comments
 (0)