Skip to content

Commit dfe52ab

Browse files
authored
Fix compile warnings on windows platform: dll linkage and others (#604)
1 parent 77c3ddf commit dfe52ab

File tree

9 files changed

+66
-53
lines changed

9 files changed

+66
-53
lines changed

core/iwasm/aot/arch/aot_reloc_x86_64.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
#define R_X86_64_32 10 /* Direct 32 bit zero extended */
1313
#define R_X86_64_32S 11 /* Direct 32 bit sign extended */
1414
#else
15+
#ifndef IMAGE_REL_AMD64_ADDR64
1516
#define IMAGE_REL_AMD64_ADDR64 1 /* The 64-bit VA of the relocation target */
1617
#define IMAGE_REL_AMD64_ADDR32 2 /* The 32-bit VA of the relocation target */
1718
#define IMAGE_REL_AMD64_REL32 4 /* The 32-bit relative address from
1819
the byte following the relocation*/
1920
#endif
21+
#endif
2022

2123
#if defined(BH_PLATFORM_WINDOWS)
2224
#pragma function (floor)

core/iwasm/common/wasm_runtime_common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2325,7 +2325,7 @@ resolve_function(const WASMModuleInstanceCommon *module_inst,
23252325
char *orig_name = NULL;
23262326
char *sub_module_name = NULL;
23272327
char *function_name = NULL;
2328-
uint32 length = strlen(name) + 1;
2328+
uint32 length = (uint32)(strlen(name) + 1);
23292329

23302330
orig_name = runtime_malloc(sizeof(char) * length, NULL, NULL, 0);
23312331
if (!orig_name) {
@@ -3387,7 +3387,7 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
33873387
#endif
33883388

33893389
#if defined(_WIN32) || defined(_WIN32_)
3390-
typedef union __declspec(intrin_type) __declspec(align(1)) v128 {
3390+
typedef union __declspec(intrin_type) __declspec(align(8)) v128 {
33913391
__int8 m128i_i8[16];
33923392
__int16 m128i_i16[8];
33933393
__int32 m128i_i32[4];

core/iwasm/common/wasm_runtime_common.h

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -337,34 +337,34 @@ typedef package_type_t PackageType;
337337
typedef wasm_section_t WASMSection, AOTSection;
338338

339339
/* See wasm_export.h for description */
340-
bool
340+
WASM_RUNTIME_API_EXTERN bool
341341
wasm_runtime_init(void);
342342

343343
/* See wasm_export.h for description */
344-
bool
344+
WASM_RUNTIME_API_EXTERN bool
345345
wasm_runtime_full_init(RuntimeInitArgs *init_args);
346346

347347
/* See wasm_export.h for description */
348-
void
348+
WASM_RUNTIME_API_EXTERN void
349349
wasm_runtime_destroy(void);
350350

351351
/* See wasm_export.h for description */
352-
PackageType
352+
WASM_RUNTIME_API_EXTERN PackageType
353353
get_package_type(const uint8 *buf, uint32 size);
354354

355355

356356
/* See wasm_export.h for description */
357-
WASMModuleCommon *
357+
WASM_RUNTIME_API_EXTERN WASMModuleCommon *
358358
wasm_runtime_load(const uint8 *buf, uint32 size,
359359
char *error_buf, uint32 error_buf_size);
360360

361361
/* See wasm_export.h for description */
362-
WASMModuleCommon *
362+
WASM_RUNTIME_API_EXTERN WASMModuleCommon *
363363
wasm_runtime_load_from_sections(WASMSection *section_list, bool is_aot,
364364
char *error_buf, uint32 error_buf_size);
365365

366366
/* See wasm_export.h for description */
367-
void
367+
WASM_RUNTIME_API_EXTERN void
368368
wasm_runtime_unload(WASMModuleCommon *module);
369369

370370
/* Internal API */
@@ -379,58 +379,58 @@ wasm_runtime_deinstantiate_internal(WASMModuleInstanceCommon *module_inst,
379379
bool is_sub_inst);
380380

381381
/* See wasm_export.h for description */
382-
WASMModuleInstanceCommon *
382+
WASM_RUNTIME_API_EXTERN WASMModuleInstanceCommon *
383383
wasm_runtime_instantiate(WASMModuleCommon *module,
384384
uint32 stack_size, uint32 heap_size,
385385
char *error_buf, uint32 error_buf_size);
386386

387387
/* See wasm_export.h for description */
388-
void
388+
WASM_RUNTIME_API_EXTERN void
389389
wasm_runtime_deinstantiate(WASMModuleInstanceCommon *module_inst);
390390

391391
/* See wasm_export.h for description */
392-
WASMFunctionInstanceCommon *
392+
WASM_RUNTIME_API_EXTERN WASMFunctionInstanceCommon *
393393
wasm_runtime_lookup_function(WASMModuleInstanceCommon * const module_inst,
394394
const char *name, const char *signature);
395395

396396
/* See wasm_export.h for description */
397-
WASMExecEnv *
397+
WASM_RUNTIME_API_EXTERN WASMExecEnv *
398398
wasm_runtime_create_exec_env(WASMModuleInstanceCommon *module_inst,
399399
uint32 stack_size);
400400

401401
/* See wasm_export.h for description */
402-
void
402+
WASM_RUNTIME_API_EXTERN void
403403
wasm_runtime_destroy_exec_env(WASMExecEnv *exec_env);
404404

405405
/* See wasm_export.h for description */
406-
WASMModuleInstanceCommon *
406+
WASM_RUNTIME_API_EXTERN WASMModuleInstanceCommon *
407407
wasm_runtime_get_module_inst(WASMExecEnv *exec_env);
408408

409409
/* See wasm_export.h for description */
410-
void *
410+
WASM_RUNTIME_API_EXTERN void *
411411
wasm_runtime_get_function_attachment(WASMExecEnv *exec_env);
412412

413413
/* See wasm_export.h for description */
414-
void
414+
WASM_RUNTIME_API_EXTERN void
415415
wasm_runtime_set_user_data(WASMExecEnv *exec_env, void *user_data);
416416

417417
/* See wasm_export.h for description */
418-
void *
418+
WASM_RUNTIME_API_EXTERN void *
419419
wasm_runtime_get_user_data(WASMExecEnv *exec_env);
420420

421421
/* See wasm_export.h for description */
422-
bool
422+
WASM_RUNTIME_API_EXTERN bool
423423
wasm_runtime_call_wasm(WASMExecEnv *exec_env,
424424
WASMFunctionInstanceCommon *function,
425425
uint32 argc, uint32 argv[]);
426426

427-
bool
427+
WASM_RUNTIME_API_EXTERN bool
428428
wasm_runtime_call_wasm_a(WASMExecEnv *exec_env,
429429
WASMFunctionInstanceCommon *function,
430430
uint32 num_results, wasm_val_t *results,
431431
uint32 num_args, wasm_val_t *args);
432432

433-
bool
433+
WASM_RUNTIME_API_EXTERN bool
434434
wasm_runtime_call_wasm_v(WASMExecEnv *exec_env,
435435
WASMFunctionInstanceCommon *function,
436436
uint32 num_results, wasm_val_t *results,
@@ -464,85 +464,85 @@ wasm_runtime_create_exec_env_and_call_wasm(WASMModuleInstanceCommon *module_inst
464464
uint32 argc, uint32 argv[]);
465465

466466
/* See wasm_export.h for description */
467-
bool
467+
WASM_RUNTIME_API_EXTERN bool
468468
wasm_application_execute_main(WASMModuleInstanceCommon *module_inst,
469469
int32 argc, char *argv[]);
470470

471471
/* See wasm_export.h for description */
472-
bool
472+
WASM_RUNTIME_API_EXTERN bool
473473
wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
474474
const char *name, int32 argc, char *argv[]);
475475

476476
/* See wasm_export.h for description */
477-
void
477+
WASM_RUNTIME_API_EXTERN void
478478
wasm_runtime_set_exception(WASMModuleInstanceCommon *module,
479479
const char *exception);
480480

481481
/* See wasm_export.h for description */
482-
const char *
482+
WASM_RUNTIME_API_EXTERN const char *
483483
wasm_runtime_get_exception(WASMModuleInstanceCommon *module);
484484

485485
/* See wasm_export.h for description */
486-
void
486+
WASM_RUNTIME_API_EXTERN void
487487
wasm_runtime_clear_exception(WASMModuleInstanceCommon *module_inst);
488488

489489
/* See wasm_export.h for description */
490-
void
490+
WASM_RUNTIME_API_EXTERN void
491491
wasm_runtime_set_custom_data(WASMModuleInstanceCommon *module_inst,
492492
void *custom_data);
493493

494494
/* See wasm_export.h for description */
495-
void *
495+
WASM_RUNTIME_API_EXTERN void *
496496
wasm_runtime_get_custom_data(WASMModuleInstanceCommon *module_inst);
497497

498498
/* See wasm_export.h for description */
499-
uint32
499+
WASM_RUNTIME_API_EXTERN uint32
500500
wasm_runtime_module_malloc(WASMModuleInstanceCommon *module_inst, uint32 size,
501501
void **p_native_addr);
502502

503503
/* See wasm_export.h for description */
504-
void
504+
WASM_RUNTIME_API_EXTERN void
505505
wasm_runtime_module_free(WASMModuleInstanceCommon *module_inst, uint32 ptr);
506506

507507
/* See wasm_export.h for description */
508-
uint32
508+
WASM_RUNTIME_API_EXTERN uint32
509509
wasm_runtime_module_dup_data(WASMModuleInstanceCommon *module_inst,
510510
const char *src, uint32 size);
511511

512512
/* See wasm_export.h for description */
513-
bool
513+
WASM_RUNTIME_API_EXTERN bool
514514
wasm_runtime_validate_app_addr(WASMModuleInstanceCommon *module_inst,
515515
uint32 app_offset, uint32 size);
516516

517517
/* See wasm_export.h for description */
518-
bool
518+
WASM_RUNTIME_API_EXTERN bool
519519
wasm_runtime_validate_app_str_addr(WASMModuleInstanceCommon *module_inst,
520520
uint32 app_str_offset);
521521

522522
/* See wasm_export.h for description */
523-
bool
523+
WASM_RUNTIME_API_EXTERN bool
524524
wasm_runtime_validate_native_addr(WASMModuleInstanceCommon *module_inst,
525525
void *native_ptr, uint32 size);
526526

527527
/* See wasm_export.h for description */
528-
void *
528+
WASM_RUNTIME_API_EXTERN void *
529529
wasm_runtime_addr_app_to_native(WASMModuleInstanceCommon *module_inst,
530530
uint32 app_offset);
531531

532532
/* See wasm_export.h for description */
533-
uint32
533+
WASM_RUNTIME_API_EXTERN uint32
534534
wasm_runtime_addr_native_to_app(WASMModuleInstanceCommon *module_inst,
535535
void *native_ptr);
536536

537537
/* See wasm_export.h for description */
538-
bool
538+
WASM_RUNTIME_API_EXTERN bool
539539
wasm_runtime_get_app_addr_range(WASMModuleInstanceCommon *module_inst,
540540
uint32 app_offset,
541541
uint32 *p_app_start_offset,
542542
uint32 *p_app_end_offset);
543543

544544
/* See wasm_export.h for description */
545-
bool
545+
WASM_RUNTIME_API_EXTERN bool
546546
wasm_runtime_get_native_addr_range(WASMModuleInstanceCommon *module_inst,
547547
uint8 *native_ptr,
548548
uint8 **p_native_start_addr,
@@ -563,7 +563,7 @@ wasm_runtime_set_llvm_stack(WASMModuleInstanceCommon *module_inst,
563563
uint32 llvm_stack);
564564

565565
#if WASM_ENABLE_MULTI_MODULE != 0
566-
void
566+
WASM_RUNTIME_API_EXTERN void
567567
wasm_runtime_set_module_reader(const module_reader reader,
568568
const module_destroyer destroyer);
569569

@@ -616,19 +616,19 @@ wasm_exec_env_set_aux_stack(WASMExecEnv *exec_env,
616616

617617
#if WASM_ENABLE_LIBC_WASI != 0
618618
/* See wasm_export.h for description */
619-
void
619+
WASM_RUNTIME_API_EXTERN void
620620
wasm_runtime_set_wasi_args(WASMModuleCommon *module,
621621
const char *dir_list[], uint32 dir_count,
622622
const char *map_dir_list[], uint32 map_dir_count,
623623
const char *env_list[], uint32 env_count,
624624
char *argv[], int argc);
625625

626626
/* See wasm_export.h for description */
627-
bool
627+
WASM_RUNTIME_API_EXTERN bool
628628
wasm_runtime_is_wasi_mode(WASMModuleInstanceCommon *module_inst);
629629

630630
/* See wasm_export.h for description */
631-
WASMFunctionInstanceCommon *
631+
WASM_RUNTIME_API_EXTERN WASMFunctionInstanceCommon *
632632
wasm_runtime_lookup_wasi_start_function(WASMModuleInstanceCommon *module_inst);
633633

634634
bool
@@ -666,13 +666,13 @@ bool
666666
wasm_runtime_enlarge_memory(WASMModuleInstanceCommon *module, uint32 inc_page_count);
667667

668668
/* See wasm_export.h for description */
669-
bool
669+
WASM_RUNTIME_API_EXTERN bool
670670
wasm_runtime_register_natives(const char *module_name,
671671
NativeSymbol *native_symbols,
672672
uint32 n_native_symbols);
673673

674674
/* See wasm_export.h for description */
675-
bool
675+
WASM_RUNTIME_API_EXTERN bool
676676
wasm_runtime_register_natives_raw(const char *module_name,
677677
NativeSymbol *native_symbols,
678678
uint32 n_native_symbols);

core/iwasm/include/wasm_c_api.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
#include <assert.h>
1111

1212
#ifndef WASM_API_EXTERN
13-
#ifdef _WIN32
14-
#define WASM_API_EXTERN __declspec(dllimport)
13+
#if defined(_MSC_BUILD)
14+
#if defined(COMPILING_WASM_RUNTIME_API)
15+
#define WASM_API_EXTERN __declspec(dllexport)
16+
#else
17+
#define WASM_API_EXTERN __declspec(dllimport)
18+
#endif
1519
#else
1620
#define WASM_API_EXTERN
1721
#endif

core/iwasm/include/wasm_export.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
#ifndef WASM_RUNTIME_API_EXTERN
15-
#if defined(MSVC)
15+
#if defined(_MSC_BUILD )
1616
#if defined(COMPILING_WASM_RUNTIME_API)
1717
#define WASM_RUNTIME_API_EXTERN __declspec(dllexport)
1818
#else

core/shared/platform/include/platform_common.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@ extern "C" {
3333
#define BH_FREE os_free
3434
#endif
3535

36-
#if defined(MSVC)
37-
__declspec(dllimport) void *BH_MALLOC(unsigned int size);
38-
__declspec(dllimport) void BH_FREE(void *ptr);
36+
#if defined(_MSC_BUILD)
37+
#if defined(COMPILING_WASM_RUNTIME_API)
38+
__declspec(dllexport) void *BH_MALLOC(unsigned int size);
39+
__declspec(dllexport) void BH_FREE(void *ptr);
40+
#else
41+
__declspec(dllimport) void* BH_MALLOC(unsigned int size);
42+
__declspec(dllimport) void BH_FREE(void* ptr);
43+
#endif
3944
#else
4045
void *BH_MALLOC(unsigned int size);
4146
void BH_FREE(void *ptr);

product-mini/platforms/windows/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
1515

1616
set (CMAKE_C_STANDARD 99)
1717

18+
add_definitions(-DCOMPILING_WASM_RUNTIME_API=1)
19+
1820
# Set WAMR_BUILD_TARGET, currently values supported:
1921
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]", "MIPS", "XTENSA"
2022
if (NOT DEFINED WAMR_BUILD_TARGET)
@@ -126,4 +128,3 @@ set_target_properties (libiwasm PROPERTIES OUTPUT_NAME iwasm)
126128

127129
target_link_libraries (libiwasm ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS})
128130

129-
target_compile_definitions(libiwasm PRIVATE COMPILING_WASM_RUNTIME_API=1)

product-mini/platforms/windows/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ module_reader_callback(const char *module_name, uint8 **p_buffer,
185185
uint32 *p_size)
186186
{
187187
const char *format = "%s/%s.wasm";
188-
int sz = strlen(module_search_path) + strlen("/") + strlen(module_name) +
189-
strlen(".wasm") + 1;
188+
uint32 sz = (uint32)(strlen(module_search_path) + strlen("/")
189+
+ strlen(module_name) + strlen(".wasm") + 1);
190190
char *wasm_file_name = BH_MALLOC(sz);
191191
if (!wasm_file_name) {
192192
return false;

wamr-compiler/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ if (NOT WAMR_BUILD_PLATFORM STREQUAL "windows")
1010
else()
1111
project (aot-compiler C ASM CXX)
1212
enable_language (ASM_MASM)
13+
add_definitions(-DCOMPILING_WASM_RUNTIME_API=1)
1314
endif()
1415

1516
set (CMAKE_CXX_STANDARD 14)

0 commit comments

Comments
 (0)