Pull request 934 in include-what-you-use: Initialize all LLVM targets on startup

0 views
Skip to first unread message

notifi...@include-what-you-use.org

unread,
Jul 14, 2021, 6:36:49 AM7/14/21
to include-wh...@googlegroups.com
New pull request 934 by kimgr: Initialize all LLVM targets on startup
https://github.com/include-what-you-use/include-what-you-use/pull/934

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.

notifi...@include-what-you-use.org

unread,
Jul 14, 2021, 6:39:35 AM7/14/21
to include-wh...@googlegroups.com
Comment #0 on pull request 934 by kimgr: Initialize all LLVM targets on startup
https://github.com/include-what-you-use/include-what-you-use/pull/934

@Romain-Geissler-1A I finally got around to thinking about this issue you reported in https://github.com/include-what-you-use/include-what-you-use/pull/854.

I resorted to just initializing all targets, hoping that X86 is available in environments where MS inline assembly is a thing. Error handling in LLVM/Clang has also been improved to no longer crash, but report an actionable error message (that no target information is available).

notifi...@include-what-you-use.org

unread,
Jul 14, 2021, 6:39:50 AM7/14/21
to include-wh...@googlegroups.com
Comment #2 on pull request 934 by kimgr: Initialize all LLVM targets on startup
https://github.com/include-what-you-use/include-what-you-use/pull/934

Replaces #854

notifi...@include-what-you-use.org

unread,
Jul 14, 2021, 7:55:31 AM7/14/21
to include-wh...@googlegroups.com
Comment #3 on pull request 934 by Romain-Geissler-1A: Initialize all LLVM targets on startup
https://github.com/include-what-you-use/include-what-you-use/pull/934

Cool, thank you !

notifi...@include-what-you-use.org

unread,
Jul 21, 2021, 4:28:27 AM7/21/21
to include-wh...@googlegroups.com
Comment #3 on pull request 934 by vmiklos: Initialize all LLVM targets on startup
https://github.com/include-what-you-use/include-what-you-use/pull/934

@kimgr Hmm, this breaks my build, I wonder why. Do you use -DBUILD_SHARED_LIBS=ON when building llvm? Or do you restrict the list of llvm targets in your config? In both cases, I don't specify anything explicitly, i.e. use the defaults.

The output I get is:

```
[ 92%] Built target clang-resource-headers
[ 93%] Linking CXX executable bin/include-what-you-use
ld: CMakeFiles/include-what-you-use.dir/iwyu.cc.o: in function `main':
iwyu.cc:(.text.main+0xc): undefined reference to `LLVMInitializeAArch64TargetInfo'
ld: iwyu.cc:(.text.main+0x11): undefined reference to `LLVMInitializeAMDGPUTargetInfo'
ld: iwyu.cc:(.text.main+0x16): undefined reference to `LLVMInitializeARMTargetInfo'
ld: iwyu.cc:(.text.main+0x1b): undefined reference to `LLVMInitializeAVRTargetInfo'
...
```

Everything is OK again if I revert this single commit locally. Thanks.

notifi...@include-what-you-use.org

unread,
Jul 21, 2021, 6:09:49 AM7/21/21
to include-wh...@googlegroups.com
Comment #5 on pull request 934 by kimgr: Initialize all LLVM targets on startup
https://github.com/include-what-you-use/include-what-you-use/pull/934

@vmiklos Oh no, thanks for the report!

I never use `BUILD_SHARED_LIBS`, as it's marketed as an unsupported llvm dev convenience. But I use the LLVM Debian packages, and I think they ship LLVM and Clang dylibs by default (based off a more supported configuration, not sure what).

Hmm. I wonder if there's a nice way to query what targets are available on startup -- i'd like to do something like:
```
if 'X86' in supported_targets:
LLVMInitializeX86TargetInfo()
...
```

Reply all
Reply to author
Forward
0 new messages