-
Notifications
You must be signed in to change notification settings - Fork 569
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PoCL: Bundle parts of the sysroot to make Clang work. (#9656)
- Loading branch information
Showing
2 changed files
with
154 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
From 4663081155ce0af4ebacd5a3429eba9449f35b0f Mon Sep 17 00:00:00 2001 | ||
From: Tim Besard <tim.besard@gmail.com> | ||
Date: Mon, 21 Oct 2024 09:40:13 +0200 | ||
Subject: [PATCH] Replace POCL_PATH_LD by a more generic POCL_ARGS_CLANG. | ||
|
||
--- | ||
doc/sphinx/source/using.rst | 12 +++++++++++- | ||
lib/CL/pocl_llvm_build.cc | 12 ++++++++---- | ||
lib/CL/pocl_runtime_config.c | 28 ++++++++++++++++++++++++++++ | ||
lib/CL/pocl_runtime_config.h | 3 +++ | ||
4 files changed, 50 insertions(+), 5 deletions(-) | ||
|
||
diff --git a/doc/sphinx/source/using.rst b/doc/sphinx/source/using.rst | ||
index cdf9b5172..b366e611b 100644 | ||
--- a/doc/sphinx/source/using.rst | ||
+++ b/doc/sphinx/source/using.rst | ||
@@ -311,13 +311,23 @@ pocl. | ||
The following variables are available: | ||
|
||
* **POCL_PATH_CLANG** -- Path to the clang executable. | ||
- * **POCL_PATH_LD** -- Path to the ld executable used by clang. | ||
* **POCL_PATH_LLVM_LINK** -- Path to the llvm-link executable. | ||
* **POCL_PATH_LLVM_OPT** -- Path to the llvm-opt executable. | ||
* **POCL_PATH_LLVM_LLC** -- Path to the llc executable. | ||
* **POCL_PATH_LLVM_SPIRV** -- Path to the llvm-spirv executable. | ||
* **POCL_PATH_SPIRV_LINK** -- Path to the spirv-link executable. | ||
|
||
+- **POCL_ARGS_XXX** | ||
+ | ||
+ String. These variables can be used to pass additional arguments to executables | ||
+ that pocl invokes during compilation, linking, etc. Multiple arguments can be | ||
+ passed by separating them with a semicolon. | ||
+ | ||
+ The following variables are available: | ||
+ | ||
+ * **POCL_ARGS_CLANG** -- Additional arguments to pass to clang. | ||
+ | ||
+ | ||
- **POCL_SIGFPE_HANDLER** | ||
|
||
Defaults to 1. If set to 0, pocl will not install the SIGFPE handler. | ||
diff --git a/lib/CL/pocl_llvm_build.cc b/lib/CL/pocl_llvm_build.cc | ||
index b425d5edc..1892ab13d 100644 | ||
--- a/lib/CL/pocl_llvm_build.cc | ||
+++ b/lib/CL/pocl_llvm_build.cc | ||
@@ -1047,15 +1047,19 @@ int pocl_invoke_clang(cl_device_id Device, const char** Args) { | ||
while (*ArgsEnd++ != nullptr) {} | ||
llvm::SmallVector<const char*, 0> ArgsArray(Args, ArgsEnd); | ||
|
||
- std::string LDPath; | ||
- if (const char* LDOverride = pocl_get_path("LD", nullptr)) { | ||
- LDPath = "--ld-path=" + std::string(LDOverride); | ||
- ArgsArray.push_back(LDPath.c_str()); | ||
+ int NumExtraArgs; | ||
+ const char *ExtraArgs = pocl_get_args("CLANG", &NumExtraArgs); | ||
+ const char *ExtraArg = ExtraArgs; | ||
+ for (int i = 0; i < NumExtraArgs; ++i) { | ||
+ ArgsArray.push_back(ExtraArg); | ||
+ ExtraArg += strlen(ExtraArg) + 1; | ||
} | ||
|
||
std::unique_ptr<clang::driver::Compilation> C( | ||
TheDriver.BuildCompilation(ArgsArray)); | ||
|
||
+ free((void *)ExtraArgs); | ||
+ | ||
if (C && !C->containsError()) { | ||
SmallVector<std::pair<int, const clang::driver::Command *>, 4> FailingCommands; | ||
return TheDriver.ExecuteCompilation(*C, FailingCommands); | ||
diff --git a/lib/CL/pocl_runtime_config.c b/lib/CL/pocl_runtime_config.c | ||
index 3f596549e..4a7e38b54 100644 | ||
--- a/lib/CL/pocl_runtime_config.c | ||
+++ b/lib/CL/pocl_runtime_config.c | ||
@@ -67,3 +67,31 @@ pocl_get_path (const char *name, const char *default_value) | ||
snprintf (key, sizeof (key), "POCL_PATH_%s", name); | ||
return pocl_get_string_option (key, default_value); | ||
} | ||
+ | ||
+/* Returns `n` null-terminated strings representing arguments | ||
+ for an invocation. Can be set using the POCL_ARGS env vars. | ||
+ If the env var is not set, returns NULL and sets `n` to zero. */ | ||
+char * | ||
+pocl_get_args (const char *name, int *n) | ||
+{ | ||
+ char key[256]; | ||
+ snprintf (key, sizeof (key), "POCL_ARGS_%s", name); | ||
+ const char *val = getenv (key); | ||
+ if (val == NULL) | ||
+ { | ||
+ *n = 0; | ||
+ return NULL; | ||
+ } | ||
+ | ||
+ char *args = strdup (val); | ||
+ *n = 1; | ||
+ for (char *p = args; *p; ++p) | ||
+ { | ||
+ if (*p == ';') | ||
+ { | ||
+ *p = 0; | ||
+ ++(*n); | ||
+ } | ||
+ } | ||
+ return args; | ||
+} | ||
diff --git a/lib/CL/pocl_runtime_config.h b/lib/CL/pocl_runtime_config.h | ||
index 3d58a7b9e..6dafd5340 100644 | ||
--- a/lib/CL/pocl_runtime_config.h | ||
+++ b/lib/CL/pocl_runtime_config.h | ||
@@ -43,6 +43,9 @@ const char* pocl_get_string_option(const char *key, const char *default_value); | ||
POCL_EXPORT | ||
const char *pocl_get_path (const char *name, const char *default_value); | ||
|
||
+POCL_EXPORT | ||
+char *pocl_get_args (const char *name, int *n); | ||
+ | ||
#ifdef __cplusplus | ||
} | ||
#endif |