Skip to content

Commit 40db16a

Browse files
committed
[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] include-what-you-use/include-what-you-use@0de60d8a2 [2] 6962aa8fb [3] de9a0370e Change-Id: I4628f31c8238f4863b7eb31b888f6dfa595cad17 Reviewed-on: http://gerrit.cloudera.org:8080/22537 Tested-by: Alexey Serbin <[email protected]> Reviewed-by: Abhishek Chennaka <[email protected]>
1 parent 6962aa8 commit 40db16a

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

thirdparty/download-thirdparty.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,14 @@ fetch_and_patch \
332332
$PYTHON_SOURCE \
333333
$PYTHON_PATCHLEVEL
334334

335-
LLVM_PATCHLEVEL=7
335+
LLVM_PATCHLEVEL=8
336336
fetch_and_patch \
337337
llvm-${LLVM_VERSION}-iwyu-${IWYU_VERSION}.src.tar.gz \
338338
$LLVM_SOURCE \
339339
$LLVM_PATCHLEVEL \
340340
"patch -p1 < $TP_DIR/patches/llvm-add-iwyu.patch" \
341341
"patch -p1 < $TP_DIR/patches/llvm-iwyu-718e69875.patch" \
342+
"patch -p1 < $TP_DIR/patches/llvm-iwyu-0de60d8a2.patch" \
342343
"patch -d projects -p1 < $TP_DIR/patches/llvm-remove-cyclades-inclusion-in-sanitizer.patch" \
343344
"patch -p2 < $TP_DIR/patches/llvm-fix-missing-include.patch" \
344345
"patch -d projects -p1 < $TP_DIR/patches/llvm-Sanitizer-built-against-glibc-2_34-doesnt-work.patch" \
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
commit 0de60d8a276fa4cfff885cc332e41bf690517e51
2+
Author: Kim Gräsman <[email protected]>
3+
Date: Wed Jul 14 12:30:10 2021 +0200
4+
5+
Initialize all LLVM targets on startup
6+
7+
It used to be the case that the MS inline assembly parser in Clang crashed if an
8+
X86 target was not registered and initialized.
9+
10+
The error handling there has been improved, so now Clang complains and says it
11+
needs X86 target support to continue, and raises an error.
12+
13+
That's good news for IWYU, as the majority of code we analyze has no MS inline
14+
assembly (fingers crossed!). So instead of requiring an X86 target to be
15+
included, initialize _all_ registered LLVM targets and assume that X86 is
16+
available in any configuration intended for use with MS inline assembly.
17+
18+
This makes it possible to build a fully non-X86 toolchain including IWYU.
19+
20+
diff --git a/tools/clang/tools/include-what-you-use/iwyu.cc b/tools/clang/tools/include-what-you-use/iwyu.cc
21+
index bbf532f..df1a439 100644
22+
--- a/tools/clang/tools/include-what-you-use/iwyu.cc
23+
+++ b/tools/clang/tools/include-what-you-use/iwyu.cc
24+
@@ -4171,7 +4171,6 @@ class IwyuAction : public ASTFrontendAction {
25+
26+
#include "iwyu_driver.h"
27+
#include "clang/Frontend/FrontendAction.h"
28+
-#include "llvm/Support/ManagedStatic.h"
29+
#include "llvm/Support/TargetSelect.h"
30+
31+
using include_what_you_use::OptionsParser;
32+
@@ -4179,12 +4178,11 @@ using include_what_you_use::IwyuAction;
33+
using include_what_you_use::CreateCompilerInstance;
34+
35+
int main(int argc, char **argv) {
36+
- // Must initialize X86 target to be able to parse Microsoft inline
37+
- // assembly. We do this unconditionally, because it allows an IWYU
38+
- // built for non-X86 targets to parse MS inline asm without choking.
39+
- LLVMInitializeX86TargetInfo();
40+
- LLVMInitializeX86TargetMC();
41+
- LLVMInitializeX86AsmParser();
42+
+ // X86 target is required to parse Microsoft inline assembly, so we hope it's
43+
+ // part of all targets. Clang parser will complain otherwise.
44+
+ llvm::InitializeAllTargetInfos();
45+
+ llvm::InitializeAllTargetMCs();
46+
+ llvm::InitializeAllAsmParsers();
47+
48+
// The command line should look like
49+
// path/to/iwyu -Xiwyu --verbose=4 [-Xiwyu --other_iwyu_flag]... CLANG_FLAGS... foo.cc

0 commit comments

Comments
 (0)