Skip to content

Commit e8c2952

Browse files
authored
Fix arm64 issues on mac (#3688)
Make wamrc normalize "arm64" to "aarch64v8". Previously the only way to make the "arm64" target was to not specify a target on 64 bit arm-based mac builds. Now arm64 and aarch64v8 are treated as the same. Make aot_loader accept "aarch64v8" on arm-based apple (as well as accepting legacy "arm64" based aot targets). This also removes __APPLE__ and __MACH__ from the block that defaults size_level to 1 since it doesn't seem to be supported for aarch64: `LLVM ERROR: Only small, tiny and large code models are allowed on AArch64`
1 parent b00904b commit e8c2952

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

core/iwasm/aot/aot_loader.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,10 @@ load_target_info_section(const uint8 *buf, const uint8 *buf_end,
579579
return false;
580580
}
581581

582+
/* for backwards compatibility with previous wamrc aot files */
583+
if (!strcmp(target_info.arch, "arm64"))
584+
bh_strcpy_s(target_info.arch, sizeof(target_info.arch), "aarch64v8");
585+
582586
/* Check machine info */
583587
if (!check_machine_info(&target_info, error_buf, error_buf_size)) {
584588
return false;

core/iwasm/aot/arch/aot_reloc_aarch64.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ get_target_symbol_map(uint32 *sym_num)
5353
return target_sym_map;
5454
}
5555

56-
#if (defined(__APPLE__) || defined(__MACH__)) && defined(__arm64__)
57-
#define BUILD_TARGET_AARCH64_DEFAULT "arm64"
58-
#else
59-
#define BUILD_TARGET_AARCH64_DEFAULT "aarch64v8"
60-
#endif
61-
6256
void
6357
get_current_target(char *target_buf, uint32 target_buf_size)
6458
{
@@ -68,8 +62,8 @@ get_current_target(char *target_buf, uint32 target_buf_size)
6862

6963
/* Set to "aarch64v8" by default if sub version isn't specified */
7064
if (strcmp(s, "AARCH64") == 0) {
71-
s = BUILD_TARGET_AARCH64_DEFAULT;
72-
s_size = sizeof(BUILD_TARGET_AARCH64_DEFAULT);
65+
s = "aarch64v8";
66+
s_size = 9; /* strlen("aarch64v8"); */
7367
}
7468
if (target_buf_size < s_size) {
7569
s_size = target_buf_size;
@@ -83,7 +77,6 @@ get_current_target(char *target_buf, uint32 target_buf_size)
8377
/* Ensure the string is null byte ('\0') terminated */
8478
*d = '\0';
8579
}
86-
#undef BUILD_TARGET_AARCH64_DEFAULT
8780

8881
static uint32
8982
get_plt_item_size()

core/iwasm/compilation/aot_llvm.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2790,6 +2790,15 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option)
27902790
bh_assert(vendor_sys);
27912791
bh_memcpy_s(default_arch, sizeof(default_arch), default_triple,
27922792
(uint32)(vendor_sys - default_triple));
2793+
/**
2794+
* On Mac M[1-9]+ LLVM will report arm64 as the
2795+
* architecture, for the purposes of wamr this is the
2796+
* same as aarch64v8 so we'll normalize it here.
2797+
*/
2798+
if (!strcmp(default_arch, "arm64")) {
2799+
bh_strcpy_s(default_arch, sizeof(default_arch),
2800+
"aarch64v8");
2801+
}
27932802
arch1 = default_arch;
27942803

27952804
LLVMDisposeMessage(default_triple);

wamr-compiler/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,8 @@ main(int argc, char *argv[])
601601
LOG_VERBOSE("Set size level to 1 for Windows AOT file");
602602
option.size_level = 1;
603603
}
604-
#if defined(_WIN32) || defined(_WIN32_) || defined(__APPLE__) \
605-
|| defined(__MACH__)
604+
#if defined(_WIN32) || defined(_WIN32_) \
605+
|| ((defined(__APPLE__) || defined(__MACH__)) && !defined(__arm64__))
606606
if (!option.target_arch && !option.target_abi) {
607607
LOG_VERBOSE("Set size level to 1 for Windows or MacOS AOT file");
608608
option.size_level = 1;

0 commit comments

Comments
 (0)