Fix windows link error and clear windows warnings (#2463)

- Fix windows wamrc link error: aot_generate_tempfile_name undefined.
- Clear windows compile warnings.
- And rename folder `samples/bh_atomic` and `samples/mem_allocator` to
  `samples/bh-atomic` and `samples/mem-allocator`.
This commit is contained in:
Wenyong Huang 2023-08-14 19:04:49 +08:00 committed by GitHub
parent e360b7a919
commit 923e8d6471
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 46 additions and 18 deletions

View File

@ -2735,6 +2735,33 @@ aot_generate_tempfile_name(const char *prefix, const char *extension,
snprintf(buffer + name_len, len - name_len, ".%s", extension); snprintf(buffer + name_len, len - name_len, ".%s", extension);
return buffer; return buffer;
} }
#else
errno_t
_mktemp_s(char *nameTemplate, size_t sizeInChars);
char *
aot_generate_tempfile_name(const char *prefix, const char *extension,
char *buffer, uint32 len)
{
int name_len;
name_len = snprintf(buffer, len, "%s-XXXXXX", prefix);
if (_mktemp_s(buffer, name_len + 1) != 0) {
return NULL;
}
/* Check if buffer length is enough */
/* name_len + '.' + extension + '\0' */
if (name_len + 1 + strlen(extension) + 1 > len) {
aot_set_last_error("temp file name too long.");
return NULL;
}
snprintf(buffer + name_len, len - name_len, ".%s", extension);
return buffer;
}
#endif /* end of !(defined(_WIN32) || defined(_WIN32_)) */ #endif /* end of !(defined(_WIN32) || defined(_WIN32_)) */
bool bool

View File

@ -2403,7 +2403,7 @@ aot_resolve_object_data_sections(AOTObjectData *obj_data)
&& !strcmp(name, "__llvm_prf_cnts")) { && !strcmp(name, "__llvm_prf_cnts")) {
snprintf(buf, sizeof(buf), "%s%u", name, snprintf(buf, sizeof(buf), "%s%u", name,
llvm_prf_cnts_idx++); llvm_prf_cnts_idx++);
size = strlen(buf) + 1; size = (uint32)(strlen(buf) + 1);
if (!(data_section->name = wasm_runtime_malloc(size))) { if (!(data_section->name = wasm_runtime_malloc(size))) {
aot_set_last_error( aot_set_last_error(
"allocate memory for data section name failed."); "allocate memory for data section name failed.");
@ -2416,7 +2416,7 @@ aot_resolve_object_data_sections(AOTObjectData *obj_data)
&& !strcmp(name, "__llvm_prf_data")) { && !strcmp(name, "__llvm_prf_data")) {
snprintf(buf, sizeof(buf), "%s%u", name, snprintf(buf, sizeof(buf), "%s%u", name,
llvm_prf_data_idx++); llvm_prf_data_idx++);
size = strlen(buf) + 1; size = (uint32)(strlen(buf) + 1);
if (!(data_section->name = wasm_runtime_malloc(size))) { if (!(data_section->name = wasm_runtime_malloc(size))) {
aot_set_last_error( aot_set_last_error(
"allocate memory for data section name failed."); "allocate memory for data section name failed.");
@ -2520,15 +2520,15 @@ read_stack_usage_file(const AOTCompContext *comp_ctx, const char *filename,
} }
if (prefix == aot_func_prefix) { if (prefix == aot_func_prefix) {
if (sz < precheck_stack_size_min) { if (sz < precheck_stack_size_min) {
precheck_stack_size_min = sz; precheck_stack_size_min = (uint32)sz;
} }
if (sz > precheck_stack_size_max) { if (sz > precheck_stack_size_max) {
precheck_stack_size_max = sz; precheck_stack_size_max = (uint32)sz;
} }
precheck_found++; precheck_found++;
continue; continue;
} }
sizes[func_idx] = sz; sizes[func_idx] = (uint32)sz;
found++; found++;
} }
fclose(fp); fclose(fp);
@ -2651,7 +2651,7 @@ aot_resolve_stack_sizes(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
* aot_emit_object_data_section_info will emit this copy. * aot_emit_object_data_section_info will emit this copy.
*/ */
obj_data->stack_sizes_section_name = sec_name; obj_data->stack_sizes_section_name = sec_name;
obj_data->stack_sizes_offset = addr; obj_data->stack_sizes_offset = (uint32)addr;
obj_data->stack_sizes = wasm_runtime_malloc( obj_data->stack_sizes = wasm_runtime_malloc(
obj_data->func_count * sizeof(*obj_data->stack_sizes)); obj_data->func_count * sizeof(*obj_data->stack_sizes));
if (obj_data->stack_sizes == NULL) { if (obj_data->stack_sizes == NULL) {
@ -2975,7 +2975,7 @@ aot_resolve_object_relocation_group(AOTObjectData *obj_data,
|| !strcmp(group->section_name, ".rel.text")) { || !strcmp(group->section_name, ".rel.text")) {
snprintf(buf, sizeof(buf), "%s%u", relocation->symbol_name, snprintf(buf, sizeof(buf), "%s%u", relocation->symbol_name,
prof_section_idx); prof_section_idx);
size = strlen(buf) + 1; size = (uint32)(strlen(buf) + 1);
if (!(relocation->symbol_name = wasm_runtime_malloc(size))) { if (!(relocation->symbol_name = wasm_runtime_malloc(size))) {
aot_set_last_error( aot_set_last_error(
"allocate memory for relocation symbol name failed."); "allocate memory for relocation symbol name failed.");
@ -2990,7 +2990,7 @@ aot_resolve_object_relocation_group(AOTObjectData *obj_data,
19)) { 19)) {
snprintf(buf, sizeof(buf), "%s%u", relocation->symbol_name, snprintf(buf, sizeof(buf), "%s%u", relocation->symbol_name,
prof_section_idx); prof_section_idx);
size = strlen(buf) + 1; size = (uint32)(strlen(buf) + 1);
if (!(relocation->symbol_name = wasm_runtime_malloc(size))) { if (!(relocation->symbol_name = wasm_runtime_malloc(size))) {
aot_set_last_error( aot_set_last_error(
"allocate memory for relocation symbol name failed."); "allocate memory for relocation symbol name failed.");
@ -3156,7 +3156,7 @@ aot_resolve_object_relocation_groups(AOTObjectData *obj_data)
|| !strcmp(name, ".rel__llvm_prf_data"))) { || !strcmp(name, ".rel__llvm_prf_data"))) {
char buf[32]; char buf[32];
snprintf(buf, sizeof(buf), "%s%u", name, llvm_prf_data_idx); snprintf(buf, sizeof(buf), "%s%u", name, llvm_prf_data_idx);
size = strlen(buf) + 1; size = (uint32)(strlen(buf) + 1);
if (!(relocation_group->section_name = if (!(relocation_group->section_name =
wasm_runtime_malloc(size))) { wasm_runtime_malloc(size))) {
aot_set_last_error( aot_set_last_error(

View File

@ -237,9 +237,10 @@ get_inst_extra_offset(AOTCompContext *comp_ctx)
const AOTCompData *comp_data = comp_ctx->comp_data; const AOTCompData *comp_data = comp_ctx->comp_data;
uint32 table_count = comp_data->import_table_count + comp_data->table_count; uint32 table_count = comp_data->import_table_count + comp_data->table_count;
uint64 offset = get_tbl_inst_offset(comp_ctx, NULL, table_count); uint64 offset = get_tbl_inst_offset(comp_ctx, NULL, table_count);
bh_assert(offset <= UINT_MAX); uint32 offset_32 = (uint32)offset;
offset = align_uint(offset, 8); bh_assert(offset <= UINT32_MAX);
return offset; offset_32 = align_uint((uint32)offset_32, 8);
return offset_32;
} }
/* /*
@ -309,8 +310,8 @@ aot_add_precheck_function(AOTCompContext *comp_ctx, LLVMModuleRef module,
goto fail; goto fail;
} }
unsigned int param_count = LLVMCountParams(precheck_func); uint32 param_count = LLVMCountParams(precheck_func);
uint64 sz = param_count * sizeof(LLVMValueRef); uint32 sz = param_count * (uint32)sizeof(LLVMValueRef);
params = wasm_runtime_malloc(sz); params = wasm_runtime_malloc(sz);
if (params == NULL) { if (params == NULL) {
goto fail; goto fail;
@ -626,8 +627,8 @@ aot_add_llvm_func(AOTCompContext *comp_ctx, LLVMModuleRef module,
if (comp_ctx->is_indirect_mode) { if (comp_ctx->is_indirect_mode) {
/* avoid LUT relocations ("switch-table") */ /* avoid LUT relocations ("switch-table") */
LLVMAttributeRef attr_no_jump_tables = LLVMCreateStringAttribute( LLVMAttributeRef attr_no_jump_tables = LLVMCreateStringAttribute(
comp_ctx->context, "no-jump-tables", strlen("no-jump-tables"), comp_ctx->context, "no-jump-tables",
"true", strlen("true")); (uint32)strlen("no-jump-tables"), "true", (uint32)strlen("true"));
LLVMAddAttributeAtIndex(func, LLVMAttributeFunctionIndex, LLVMAddAttributeAtIndex(func, LLVMAttributeFunctionIndex,
attr_no_jump_tables); attr_no_jump_tables);
} }
@ -2081,7 +2082,7 @@ jit_stack_size_callback(void *user_data, const char *name, size_t namelen,
return; return;
} }
/* ensure NUL termination */ /* ensure NUL termination */
bh_memcpy_s(buf, sizeof(buf), name, namelen); bh_memcpy_s(buf, (uint32)sizeof(buf), name, (uint32)namelen);
buf[namelen] = 0; buf[namelen] = 0;
ret = sscanf(buf, AOT_FUNC_INTERNAL_PREFIX "%" SCNu32, &func_idx); ret = sscanf(buf, AOT_FUNC_INTERNAL_PREFIX "%" SCNu32, &func_idx);
@ -2102,7 +2103,7 @@ jit_stack_size_callback(void *user_data, const char *name, size_t namelen,
/* Note: -1 == AOT_NEG_ONE from aot_create_stack_sizes */ /* Note: -1 == AOT_NEG_ONE from aot_create_stack_sizes */
bh_assert(comp_ctx->jit_stack_sizes[func_idx] == (uint32)-1); bh_assert(comp_ctx->jit_stack_sizes[func_idx] == (uint32)-1);
comp_ctx->jit_stack_sizes[func_idx] = stack_size + call_size; comp_ctx->jit_stack_sizes[func_idx] = (uint32)stack_size + call_size;
} }
static bool static bool