aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjcmdln <jcmdln@gmail.com>2023-10-11 21:06:42 -0400
committerjcmdln <jcmdln@gmail.com>2023-10-11 21:06:42 -0400
commitbd86cb22e065c500108c06ce3dfde7201cb34f12 (patch)
treea5182761f66b63425dee76ef6cf80a9bf69aec02
parent0c10b951a931d28614c381e7fc26bdafa1e2b9fe (diff)
Support LLVM >=17.0.1 on Darwin and Linux
-rwxr-xr-xbuild_odin.sh6
-rw-r--r--src/llvm_backend.cpp26
-rw-r--r--src/llvm_backend.hpp4
-rw-r--r--src/main.cpp4
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<String>(heap_allocator(), 0, 1);
if (build_context.metrics.os == TargetOs_windows) {
+ auto paths = array_make<String>(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 <llvm-c/Object.h>
#include <llvm-c/BitWriter.h>
#include <llvm-c/DebugInfo.h>
+#if LLVM_VERSION_MAJOR >= 17 && (LLVM_VERSION_MINOR > 0 || (LLVM_VERSION_MINOR == 0 && LLVM_VERSION_PATCH > 0))
+#include <llvm-c/Transforms/PassBuilder.h>
+#else
#include <llvm-c/Transforms/AggressiveInstCombine.h>
#include <llvm-c/Transforms/InstCombine.h>
#include <llvm-c/Transforms/IPO.h>
@@ -23,6 +26,7 @@
#include <llvm-c/Transforms/Utils.h>
#include <llvm-c/Transforms/Vectorize.h>
#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