Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for LLVM 15 #677

Merged
merged 5 commits into from
Oct 5, 2022
Merged

Add support for LLVM 15 #677

merged 5 commits into from
Oct 5, 2022

Conversation

thedataking
Copy link
Contributor

@thedataking thedataking commented Sep 23, 2022

clang::StringLiteral::StringKind::Ascii was renamed to clang::StringLiteral::StringKind::Ordinary. Add release keys and update build_translator.py. Closes #676.

@thedataking thedataking marked this pull request as draft September 23, 2022 09:43
@chrysn chrysn mentioned this pull request Sep 26, 2022
@chrysn
Copy link
Contributor

chrysn commented Sep 28, 2022

Unrelated trouble with earlier Debian versions that's not this PR's fault

Testers on not-perfectly-recent Debian beware that the change to LLVM 15 that requires this (the StringLiteral::StringKind renaming) came in quite late in the LLVM release process. Users of Debian experimental will find that the new version will not build on some versions of llvm-15-dev, but that the current master does work. This is no fault of this PR, but of the Debian package claiming something to be -15 when it doesn't have all of -15's changes (but to be fair, it is an experimental pre-release, and needs to be opted in to).

With the very latest experimental release (llvm-15 1:15.0.1-1~exp2 from Debian, including mlir-15-tools, and a bunch of packages the build process will conveniently ask for), this passes compilation, but fails at link time:

  = note: /usr/bin/ld: /usr/lib/llvm-15/lib/libclangSema.a(SemaRISCVVectorLookup.cpp.o): in function `clang::CreateRISCVIntrinsicManager(clang::Sema&)':
          (.text._ZN5clang27CreateRISCVIntrinsicManagerERNS_4SemaE+0x1b8): undefined reference to `clang::RISCV::RVVIntrinsic::computeBuiltinTypes(llvm::ArrayRef<clang::RISCV::PrototypeDescriptor>, bool, bool, bool, unsigned int)'
          /usr/bin/ld: (.text._ZN5clang27CreateRISCVIntrinsicManagerERNS_4SemaE+0x1f9): undefined reference to `clang::RISCV::RVVIntrinsic::computeBuiltinTypes(llvm::ArrayRef<clang::RISCV::PrototypeDescriptor>, bool, bool, bool, unsigned int)'

I think this would be resolved by not only linking in libclangSema.a but also libclangSupport.a, but I don't know where that's stated (yet?).

@chrysn
Copy link
Contributor

chrysn commented Sep 28, 2022

... and I have a patch:

diff --git a/c2rust-ast-exporter/build.rs b/c2rust-ast-exporter/build.rs
index 4dd17e88..22581b66 100644
--- a/c2rust-ast-exporter/build.rs
+++ b/c2rust-ast-exporter/build.rs
@@ -172,6 +172,7 @@ fn build_native(llvm_info: &LLVMInfo) {
             "clangParse",
             "clangSerialization",
             "clangSema",
+            "clangSupport",
             "clangEdit",
             "clangAnalysis",
             "clangDriver",

(Can't test whether that needs version sensing to decide whether or not to add that, as I don't want to shuffle around all my local packages once more -- I trust CI would give clear indications here)

[edit: With that patch, this branch not only builds but passes all my application tests so far, except where there are other open PRs]

@thedataking
Copy link
Contributor Author

Thanks @chrysn, I've incorporated your suggestion. Let me know if you hit any other issues.

@thedataking thedataking force-pushed the feature/llvm-15.0.0 branch 2 times, most recently from 5b7ac17 to 95b62c3 Compare October 3, 2022 23:26
clang::StringLiteral::StringKind::Ascii was renamed to
clang::StringLiteral::StringKind::Ordinary. Add release keys and
update build_translator.py. Closes #676.
The static libraries for the homebrew version of clang/LLVM 15 are
build with a feature (opaque pointers) not understood by earlier
versions of clang/LLVM. Switching to dynamic linking on MacOS
sidesteps the issue. We still link against static libraries if this
is requested via the `llvm-static` feature flag.
Disable support for iOS in compiler-rt. Don't pass --wildcard to
tar since the version shipping with MacOS doesn't support it.
@thedataking thedataking marked this pull request as ready for review October 4, 2022 06:14
@thedataking thedataking merged commit 8014cd4 into master Oct 5, 2022
Comment on lines +112 to +114
def llvm_major_ver_ge(test_ver) -> bool:
(major, _, _) = self.LLVM_VER.split(".")
return int(major) >= test_ver
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think llvm_major_ver() -> int would be better, and do the >= at call site. It's much easier to read and more flexible, and test_ver isn't otherwise used in llvm_major_ver_ge.

Comment on lines +193 to +197
if llvm_info.llvm_major_version >= 15 {
// insert after clangSema
let sema_pos = clang_libs.iter().position(|&r| r == "clangSema").unwrap();
clang_libs.insert(sema_pos + 1, "clangSupport");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put this inline as something like if llvm_info.llvm_major_version >= 15 { "clangSupport" } else { "" } and then filter out "". It's much cleaner, easier to understand the order of libraries, and more extensible if we need to add conditional libraries where order matters.

if cfg!(feature = "llvm-static") {
false
} else {
true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not need to do a similar libclang_path.exists() check for macOS like we do for linux?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

c2rust fails to build with LLVM 15
3 participants