diff --git a/src/codegen.cpp b/src/codegen.cpp index 015680b5d..8de3e8119 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -7989,15 +7989,9 @@ static void detect_dynamic_linker(CodeGen *g) { #if defined(ZIG_OS_LINUX) { Error err; - static const char *dyn_tests[] = { -#if defined(ZIG_ARCH_X86_64) - "ld-linux-x86-64.so.2", - "ld-musl-x86_64.so.1", -#endif - }; Buf *result = buf_alloc(); - for (size_t i = 0; i < array_length(dyn_tests); i += 1) { - const char *lib_name = dyn_tests[i]; + for (size_t i = 0; possible_ld_names[i] != NULL; i += 1) { + const char *lib_name = possible_ld_names[i]; if ((err = zig_libc_cc_print_file_name(lib_name, result, false, true))) { if (err != ErrorCCompilerCannotFindFile) { fprintf(stderr, "Unable to detect native dynamic linker: %s\n", err_str(err)); diff --git a/src/compiler.cpp b/src/compiler.cpp index 7ec1485fa..af62173db 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -26,11 +26,12 @@ Buf *get_stage1_cache_path(void) { } static void detect_dynamic_linker(Buf *lib_path) { -#if defined(ZIG_OS_LINUX) && defined(ZIG_ARCH_X86_64) - if (buf_ends_with_str(lib_path, "ld-linux-x86-64.so.2")) { - buf_init_from_buf(&saved_dynamic_linker_path, lib_path); - } else if (buf_ends_with_str(lib_path, "ld-musl-x86-64.so.1")) { - buf_init_from_buf(&saved_dynamic_linker_path, lib_path); +#if defined(ZIG_OS_LINUX) + for (size_t i = 0; possible_ld_names[i] != NULL; i += 1) { + if (buf_ends_with_str(lib_path, possible_ld_names[i])) { + buf_init_from_buf(&saved_dynamic_linker_path, lib_path); + break; + } } #endif } diff --git a/src/os.cpp b/src/os.cpp index 4f7ca74f2..1dd22b718 100644 --- a/src/os.cpp +++ b/src/os.cpp @@ -2076,3 +2076,21 @@ void os_file_close(OsFile file) { close(file); #endif } + +#ifdef ZIG_OS_LINUX +const char *possible_ld_names[] = { +#if defined(ZIG_ARCH_X86_64) + "ld-linux-x86-64.so.2", + "ld-musl-x86_64.so.1", +#elif defined(ZIG_ARCH_ARM64) + "ld-linux-aarch64.so.1", + "ld-musl-aarch64.so.1", +#elif defined(ZIG_ARCH_ARM) + "ld-linux-armhf.so.3", + "ld-musl-armhf.so.1", + "ld-linux.so.3", + "ld-musl-arm.so.1", +#endif + NULL, +}; +#endif diff --git a/src/os.hpp b/src/os.hpp index 36d3c327a..5064a6444 100644 --- a/src/os.hpp +++ b/src/os.hpp @@ -33,10 +33,18 @@ #if defined(__x86_64__) #define ZIG_ARCH_X86_64 +#elif defined(__aarch64__) +#define ZIG_ARCH_ARM64 +#elif defined(__ARM_EABI__) +#define ZIG_ARCH_ARM #else #define ZIG_ARCH_UNKNOWN #endif +#ifdef ZIG_OS_LINUX +extern const char *possible_ld_names[]; +#endif + #if defined(ZIG_OS_WINDOWS) #define ZIG_PRI_usize "I64u" #define ZIG_PRI_u64 "I64u" diff --git a/std/special/bootstrap.zig b/std/special/bootstrap.zig index 04b29d670..064d8bac6 100644 --- a/std/special/bootstrap.zig +++ b/std/special/bootstrap.zig @@ -171,6 +171,13 @@ fn linuxSetThreadArea(addr: usize) void { // acrh_prctl is documented to never fail assert(rc == 0); }, + builtin.Arch.aarch64 => { + asm volatile ( + \\ msr tpidr_el0,x0 + \\ mov w0,#0 + \\ ret + ); + }, else => @compileError("Unsupported architecture"), } }