From bd86cb22e065c500108c06ce3dfde7201cb34f12 Mon Sep 17 00:00:00 2001 From: jcmdln Date: Wed, 11 Oct 2023 21:06:42 -0400 Subject: [PATCH] Support LLVM >=17.0.1 on Darwin and Linux --- build_odin.sh | 6 ++++-- src/llvm_backend.cpp | 26 +++++++++++++++++++++++--- src/llvm_backend.hpp | 4 ++++ src/main.cpp | 4 ++-- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/build_odin.sh b/build_odin.sh index cbda51bfc..ddfbe967c 100755 --- a/build_odin.sh +++ b/build_odin.sh @@ -52,7 +52,7 @@ config_darwin() { fi fi - MAX_LLVM_VERSION=("14.999.999") + MAX_LLVM_VERSION=("17.999.999") if [ $(version $($LLVM_CONFIG --version)) -gt $(version $MAX_LLVM_VERSION) ]; then echo "Tried to use " $(which $LLVM_CONFIG) "version" $($LLVM_CONFIG --version) panic "Requirement: llvm-config must be base version smaller than 15" @@ -102,6 +102,8 @@ config_linux() { LLVM_CONFIG=llvm-config-11-64 elif [ -x "$(command -v llvm-config-14)" ]; then LLVM_CONFIG=llvm-config-14 + elif [ -x "$(command -v llvm-config-17)" ]; then + LLVM_CONFIG=llvm-config-17 else panic "Unable to find LLVM-config" fi @@ -113,7 +115,7 @@ config_linux() { panic "Requirement: llvm-config must be base version greater than 11" fi - MAX_LLVM_VERSION=("14.999.999") + MAX_LLVM_VERSION=("17.999.999") if [ $(version $($LLVM_CONFIG --version)) -gt $(version $MAX_LLVM_VERSION) ]; then echo "Tried to use " $(which $LLVM_CONFIG) "version" $($LLVM_CONFIG --version) panic "Requirement: llvm-config must be base version smaller than 15" diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index ceb4dc1de..00c62f0f1 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -2602,17 +2602,37 @@ gb_internal bool lb_generate_code(lbGenerator *gen) { if (build_context.sanitizer_flags & SanitizerFlag_Address) { - auto paths = array_make(heap_allocator(), 0, 1); if (build_context.metrics.os == TargetOs_windows) { + auto paths = array_make(heap_allocator(), 0, 1); String path = concatenate_strings(permanent_allocator(), build_context.ODIN_ROOT, str_lit("\\bin\\llvm\\windows\\clang_rt.asan-x86_64.lib")); array_add(&paths, path); + Entity *lib = alloc_entity_library_name(nullptr, make_token_ident("asan_lib"), nullptr, slice_from_array(paths), str_lit("asan_lib")); + array_add(&gen->foreign_libraries, lib); + } else if (build_context.metrics.os == TargetOs_darwin || build_context.metrics.os == TargetOs_linux) { + if (!build_context.extra_linker_flags.text) { + build_context.extra_linker_flags = str_lit("-fsanitize=address"); + } else { + build_context.extra_linker_flags = concatenate_strings(permanent_allocator(), build_context.extra_linker_flags, str_lit(" -fsanitize=address")); + } } - Entity *lib = alloc_entity_library_name(nullptr, make_token_ident("asan_lib"), nullptr, slice_from_array(paths), str_lit("asan_lib")); - array_add(&gen->foreign_libraries, lib); } if (build_context.sanitizer_flags & SanitizerFlag_Memory) { + if (build_context.metrics.os == TargetOs_darwin || build_context.metrics.os == TargetOs_linux) { + if (!build_context.extra_linker_flags.text) { + build_context.extra_linker_flags = str_lit("-fsanitize=memory"); + } else { + build_context.extra_linker_flags = concatenate_strings(permanent_allocator(), build_context.extra_linker_flags, str_lit(" -fsanitize=memory")); + } + } } if (build_context.sanitizer_flags & SanitizerFlag_Thread) { + if (build_context.metrics.os == TargetOs_darwin || build_context.metrics.os == TargetOs_linux) { + if (!build_context.extra_linker_flags.text) { + build_context.extra_linker_flags = str_lit("-fsanitize=thread"); + } else { + build_context.extra_linker_flags = concatenate_strings(permanent_allocator(), build_context.extra_linker_flags, str_lit(" -fsanitize=thread")); + } + } } gb_sort_array(gen->foreign_libraries.data, gen->foreign_libraries.count, foreign_library_cmp); diff --git a/src/llvm_backend.hpp b/src/llvm_backend.hpp index abdeea4ba..fb0d67c21 100644 --- a/src/llvm_backend.hpp +++ b/src/llvm_backend.hpp @@ -15,6 +15,9 @@ #include #include #include +#if LLVM_VERSION_MAJOR >= 17 && (LLVM_VERSION_MINOR > 0 || (LLVM_VERSION_MINOR == 0 && LLVM_VERSION_PATCH > 0)) +#include +#else #include #include #include @@ -23,6 +26,7 @@ #include #include #endif +#endif #if LLVM_VERSION_MAJOR < 11 #error "LLVM Version 11 is the minimum required" diff --git a/src/main.cpp b/src/main.cpp index e9c988d95..79c2b3561 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -89,8 +89,8 @@ gb_global Timings global_timings = {0}; #if LLVM_VERSION_MAJOR < 11 #error LLVM Version 11+ is required => "brew install llvm@11" #endif - #if LLVM_VERSION_MAJOR > 14 - #error LLVM Version 11..=14 is required => "brew install llvm@14" + #if (LLVM_VERSION_MAJOR > 14 && LLVM_VERSION_MAJOR < 17) || LLVM_VERSION_MAJOR > 17 + #error LLVM Version 11..=14 or =17 is required => "brew install llvm@14" #endif #endif