Fix some issues on MacOS platform (#937)

Fix some issues on MacOS platform
- Enable libc-wasi by default
- Set target abi to "gnu" if it is not set for wamrc to avoid generating
  object file of unsupported Mach-O format
- Set `<vendor>-<sys>` info according to target abi for wamrc to support
  generating AOT file for other OSs but not current host
- Set cpu name if arch/abi/cpu are not set to avoid checking SIMD
  capability failed
- Set size level to 1 for MacOS/Windows platform to avoid relocation type
  unsupported warning
- Clear posix_memmap.c compiling warning
- Fix spec case test script issues, enable test spec cases on MacOS

Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
This commit is contained in:
Wenyong Huang
2022-01-07 09:53:48 +08:00
committed by GitHub
parent 308d31c621
commit cb51dbb513
6 changed files with 106 additions and 10 deletions

View File

@ -1610,7 +1610,74 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
abi = "ilp32d";
}
if (arch) {
#if defined(__APPLE__) || defined(__MACH__)
if (!abi) {
/* On MacOS platform, set abi to "gnu" to avoid generating
object file of Mach-O binary format which is unsupported */
abi = "gnu";
if (!arch && !cpu && !features) {
/* Get CPU name of the host machine to avoid checking
SIMD capability failed */
if (!(cpu = cpu_new = LLVMGetHostCPUName())) {
aot_set_last_error("llvm get host cpu name failed.");
goto fail;
}
}
}
#endif
if (abi) {
/* Construct target triple: <arch>-<vendor>-<sys>-<abi> */
const char *vendor_sys;
char *arch1 = arch, default_arch[32] = { 0 };
if (!arch1) {
char *default_triple = LLVMGetDefaultTargetTriple();
if (!default_triple) {
aot_set_last_error(
"llvm get default target triple failed.");
goto fail;
}
vendor_sys = strstr(default_triple, "-");
bh_assert(vendor_sys);
bh_memcpy_s(default_arch, sizeof(default_arch), default_triple,
vendor_sys - default_triple);
arch1 = default_arch;
LLVMDisposeMessage(default_triple);
}
/**
* Set <vendor>-<sys> according to abi to generate the object file
* with the correct file format which might be different from the
* default object file format of the host, e.g., generating AOT file
* for Windows/MacOS under Linux host, or generating AOT file for
* Linux/MacOS under Windows host.
*/
if (!strcmp(abi, "msvc")) {
if (!strcmp(arch1, "i386"))
vendor_sys = "-pc-win32-";
else
vendor_sys = "-pc-windows-";
}
else {
vendor_sys = "-pc-linux-";
}
bh_assert(strlen(arch1) + strlen(vendor_sys) + strlen(abi)
< sizeof(triple_buf));
bh_memcpy_s(triple_buf, sizeof(triple_buf), arch1, strlen(arch1));
bh_memcpy_s(triple_buf + strlen(arch1),
sizeof(triple_buf) - strlen(arch1), vendor_sys,
strlen(vendor_sys));
bh_memcpy_s(triple_buf + strlen(arch1) + strlen(vendor_sys),
sizeof(triple_buf) - strlen(arch1) - strlen(vendor_sys),
abi, strlen(abi));
triple = triple_buf;
}
else if (arch) {
/* Construct target triple: <arch>-<vendor>-<sys>-<abi> */
const char *vendor_sys;
char *default_triple = LLVMGetDefaultTargetTriple();
@ -1640,10 +1707,13 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
bh_assert(strlen(arch) + strlen(vendor_sys) + strlen(abi)
< sizeof(triple_buf));
memcpy(triple_buf, arch, strlen(arch));
memcpy(triple_buf + strlen(arch), vendor_sys, strlen(vendor_sys));
memcpy(triple_buf + strlen(arch) + strlen(vendor_sys), abi,
strlen(abi));
bh_memcpy_s(triple_buf, sizeof(triple_buf), arch, strlen(arch));
bh_memcpy_s(triple_buf + strlen(arch),
sizeof(triple_buf) - strlen(arch), vendor_sys,
strlen(vendor_sys));
bh_memcpy_s(triple_buf + strlen(arch) + strlen(vendor_sys),
sizeof(triple_buf) - strlen(arch) - strlen(vendor_sys),
abi, strlen(abi));
triple = triple_buf;
}

View File

@ -16,6 +16,7 @@ static size_t total_size_munmapped = 0;
#define HUGE_PAGE_SIZE (2 * 1024 * 1024)
#if !defined(__APPLE__) && !defined(__NuttX__)
static inline uintptr_t
round_up(uintptr_t v, uintptr_t b)
{
@ -29,6 +30,7 @@ round_down(uintptr_t v, uintptr_t b)
uintptr_t m = b - 1;
return v & ~m;
}
#endif
void *
os_mmap(void *hint, size_t size, int prot, int flags)