Skip to content

Commit d9d0777

Browse files
authored
Move dlfcn.h availability check to platform_common.h (bytecodealliance#1134)
1 parent 814a76e commit d9d0777

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

core/shared/platform/include/platform_common.h

+8
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ BH_VPRINTF(const char *format, va_list ap);
6565
#define NULL (void *)0
6666
#endif
6767

68+
#if !defined(BH_HAS_DLFCN)
69+
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE)
70+
#define BH_HAS_DLFCN 1
71+
#else
72+
#define BH_HAS_DLFCN 0
73+
#endif
74+
#endif
75+
6876
#ifndef __cplusplus
6977

7078
#ifndef true

core/shared/platform/nuttx/platform_internal.h

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ typedef pthread_t korp_thread;
4141
#define os_printf printf
4242
#define os_vprintf vprintf
4343

44+
#if defined(CONFIG_LIBC_DLFCN)
45+
#define BH_HAS_DLFCN 1
46+
#else
47+
#define BH_HAS_DLFCN 0
48+
#endif
49+
4450
/* On NuttX, time_t is uint32_t */
4551
#define BH_TIME_T_MAX 0xffffffff
4652

product-mini/platforms/posix/main.c

+11-10
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
#endif
99
#include <stdlib.h>
1010
#include <string.h>
11-
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE)
12-
#include <dlfcn.h>
13-
#endif
1411

1512
#include "bh_platform.h"
1613
#include "bh_read_file.h"
1714
#include "wasm_export.h"
1815

16+
#if BH_HAS_DLFCN
17+
#include <dlfcn.h>
18+
#endif
19+
1920
static int app_argc;
2021
static char **app_argv;
2122

@@ -47,7 +48,7 @@ print_help()
4748
printf(" for example:\n");
4849
printf(" --addr-pool=1.2.3.4/15,2.3.4.5/16\n");
4950
#endif
50-
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE)
51+
#if BH_HAS_DLFCN
5152
printf(" --native-lib=<lib> Register native libraries to the WASM module, which\n");
5253
printf(" are shared object (.so) files, for example:\n");
5354
printf(" --native-lib=test1.so --native-lib=test2.so\n");
@@ -182,7 +183,7 @@ validate_env_str(char *env)
182183
}
183184
#endif
184185

185-
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE)
186+
#if BH_HAS_DLFCN
186187
typedef uint32 (*get_native_lib_func)(char **p_module_name,
187188
NativeSymbol **p_native_symbols);
188189

@@ -232,7 +233,7 @@ load_and_register_native_libs(const char **native_lib_list,
232233

233234
return native_handle_count;
234235
}
235-
#endif /* end of defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) */
236+
#endif /* BH_HAS_DLFCN */
236237

237238
#if WASM_ENABLE_MULTI_MODULE != 0
238239
static char *
@@ -309,7 +310,7 @@ main(int argc, char *argv[])
309310
const char *addr_pool[8] = { NULL };
310311
uint32 addr_pool_size = 0;
311312
#endif
312-
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE)
313+
#if BH_HAS_DLFCN
313314
const char *native_lib_list[8] = { NULL };
314315
uint32 native_lib_count = 0;
315316
void *native_handle_list[8] = { NULL };
@@ -403,7 +404,7 @@ main(int argc, char *argv[])
403404
}
404405
}
405406
#endif /* WASM_ENABLE_LIBC_WASI */
406-
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE)
407+
#if BH_HAS_DLFCN
407408
else if (!strncmp(argv[0], "--native-lib=", 13)) {
408409
if (argv[0][13] == '\0')
409410
return print_help();
@@ -485,7 +486,7 @@ main(int argc, char *argv[])
485486
bh_log_set_verbose_level(log_verbose_level);
486487
#endif
487488

488-
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE)
489+
#if BH_HAS_DLFCN
489490
native_handle_count = load_and_register_native_libs(
490491
native_lib_list, native_lib_count, native_handle_list);
491492
#endif
@@ -564,7 +565,7 @@ main(int argc, char *argv[])
564565
os_munmap(wasm_file_buf, wasm_file_size);
565566

566567
fail1:
567-
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE)
568+
#if BH_HAS_DLFCN
568569
/* unload the native libraries */
569570
for (native_handle_idx = 0; native_handle_idx < native_handle_count;
570571
native_handle_idx++)

0 commit comments

Comments
 (0)