This is an automated email from the ASF dual-hosted git repository.

mgreber pushed a commit to branch branch-1.18.x
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/branch-1.18.x by this push:
     new 38ec08c3c [thirdparty] fix building LLVM+IWYU on ARM (one more patch)
38ec08c3c is described below

commit 38ec08c3c0ede8f5fb64871616f4085b779efda9
Author: Alexey Serbin <[email protected]>
AuthorDate: Mon Feb 24 16:56:30 2025 -0800

    [thirdparty] fix building LLVM+IWYU on ARM (one more patch)
    
    This is one more patch to fix building IWYU in-tree with LLVM on ARM:
    this is a patch [1] from IWYU's upstream repo, with paths modified to
    accommodate for the LLVM in-tree layout of the source files.
    Without this patch, building Kudu's 3rd-party on ARM after [2]
    produced an error like below:
    
      
thirdparty/src/llvm-11.0.0.src/tools/clang/tools/include-what-you-use/iwyu.cc:4142:3:
 error: ‘LLVMInitializeX86TargetInfo’ was not declared in this scope
         LLVMInitializeX86TargetInfo();
    
    This is a follow-up to [2] and [3].
    
    [1] 
https://github.com/include-what-you-use/include-what-you-use/commit/0de60d8a2
    [2] https://github.com/apache/kudu/commit/6962aa8fb
    [3] https://github.com/apache/kudu/commit/de9a0370e
    
    Change-Id: I4628f31c8238f4863b7eb31b888f6dfa595cad17
    Reviewed-on: http://gerrit.cloudera.org:8080/22537
    Tested-by: Alexey Serbin <[email protected]>
    Reviewed-by: Abhishek Chennaka <[email protected]>
    (cherry picked from commit 40db16aac4c4028283c9be3bbda655dda0b73dce)
    Reviewed-on: http://gerrit.cloudera.org:8080/22540
    Reviewed-by: Marton Greber <[email protected]>
---
 thirdparty/download-thirdparty.sh            |  3 +-
 thirdparty/patches/llvm-iwyu-0de60d8a2.patch | 49 ++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/thirdparty/download-thirdparty.sh 
b/thirdparty/download-thirdparty.sh
index 4528f47b9..9f5b09c86 100755
--- a/thirdparty/download-thirdparty.sh
+++ b/thirdparty/download-thirdparty.sh
@@ -332,13 +332,14 @@ fetch_and_patch \
  $PYTHON_SOURCE \
  $PYTHON_PATCHLEVEL
 
-LLVM_PATCHLEVEL=7
+LLVM_PATCHLEVEL=8
 fetch_and_patch \
  llvm-${LLVM_VERSION}-iwyu-${IWYU_VERSION}.src.tar.gz \
  $LLVM_SOURCE \
  $LLVM_PATCHLEVEL \
  "patch -p1 < $TP_DIR/patches/llvm-add-iwyu.patch" \
  "patch -p1 < $TP_DIR/patches/llvm-iwyu-718e69875.patch" \
+ "patch -p1 < $TP_DIR/patches/llvm-iwyu-0de60d8a2.patch" \
  "patch -d projects -p1 < 
$TP_DIR/patches/llvm-remove-cyclades-inclusion-in-sanitizer.patch" \
  "patch -p2 < $TP_DIR/patches/llvm-fix-missing-include.patch" \
  "patch -d projects -p1 < 
$TP_DIR/patches/llvm-Sanitizer-built-against-glibc-2_34-doesnt-work.patch" \
diff --git a/thirdparty/patches/llvm-iwyu-0de60d8a2.patch 
b/thirdparty/patches/llvm-iwyu-0de60d8a2.patch
new file mode 100644
index 000000000..8ce129082
--- /dev/null
+++ b/thirdparty/patches/llvm-iwyu-0de60d8a2.patch
@@ -0,0 +1,49 @@
+commit 0de60d8a276fa4cfff885cc332e41bf690517e51
+Author: Kim Gräsman <[email protected]>
+Date:   Wed Jul 14 12:30:10 2021 +0200
+
+    Initialize all LLVM targets on startup
+    
+    It used to be the case that the MS inline assembly parser in Clang crashed 
if an
+    X86 target was not registered and initialized.
+    
+    The error handling there has been improved, so now Clang complains and 
says it
+    needs X86 target support to continue, and raises an error.
+    
+    That's good news for IWYU, as the majority of code we analyze has no MS 
inline
+    assembly (fingers crossed!). So instead of requiring an X86 target to be
+    included, initialize _all_ registered LLVM targets and assume that X86 is
+    available in any configuration intended for use with MS inline assembly.
+    
+    This makes it possible to build a fully non-X86 toolchain including IWYU.
+
+diff --git a/tools/clang/tools/include-what-you-use/iwyu.cc 
b/tools/clang/tools/include-what-you-use/iwyu.cc
+index bbf532f..df1a439 100644
+--- a/tools/clang/tools/include-what-you-use/iwyu.cc
++++ b/tools/clang/tools/include-what-you-use/iwyu.cc
+@@ -4171,7 +4171,6 @@ class IwyuAction : public ASTFrontendAction {
+ 
+ #include "iwyu_driver.h"
+ #include "clang/Frontend/FrontendAction.h"
+-#include "llvm/Support/ManagedStatic.h"
+ #include "llvm/Support/TargetSelect.h"
+ 
+ using include_what_you_use::OptionsParser;
+@@ -4179,12 +4178,11 @@ using include_what_you_use::IwyuAction;
+ using include_what_you_use::CreateCompilerInstance;
+ 
+ int main(int argc, char **argv) {
+-  // Must initialize X86 target to be able to parse Microsoft inline
+-  // assembly. We do this unconditionally, because it allows an IWYU
+-  // built for non-X86 targets to parse MS inline asm without choking.
+-  LLVMInitializeX86TargetInfo();
+-  LLVMInitializeX86TargetMC();
+-  LLVMInitializeX86AsmParser();
++  // X86 target is required to parse Microsoft inline assembly, so we hope 
it's
++  // part of all targets. Clang parser will complain otherwise.
++  llvm::InitializeAllTargetInfos();
++  llvm::InitializeAllTargetMCs();
++  llvm::InitializeAllAsmParsers();
+ 
+   // The command line should look like
+   //   path/to/iwyu -Xiwyu --verbose=4 [-Xiwyu --other_iwyu_flag]... 
CLANG_FLAGS... foo.cc

Reply via email to