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

llvm: general cleanup and corrections #52352

Closed
wants to merge 6 commits into from
Closed

Conversation

Bo98
Copy link
Member

@Bo98 Bo98 commented Mar 30, 2020

  • Have you followed the guidelines for contributing?
  • Have you checked that there aren't other open pull requests for the same formula update/change?
  • Have you built your formula locally with brew install --build-from-source <formula>, where <formula> is the name of the formula you're submitting?
  • Is your test running fine brew test <formula>, where <formula> is the name of the formula you're submitting?
  • Does your build pass brew audit --strict <formula> (after doing brew install <formula>)?

Some of this could likely be applied to llvm@9 and earlier. The formula was a collection of a years of additions - some of which no longer applies.

I will want to verify the bottle's contents before merging this. Done.

@Bo98 Bo98 marked this pull request as ready for review March 31, 2020 01:57
Copy link
Member

@SMillerDev SMillerDev left a comment

Choose a reason for hiding this comment

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

Should this also be applied to older versions?

Formula/llvm.rb Outdated
# Use system libcxxabi.
rm_r "libcxxabi" if build.head?

py_ver = "2.7"
Copy link
Member

Choose a reason for hiding this comment

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

3 isn't an option?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it is - Linuxbrew uses it. I limited making any actual functional changes (besides fixing polly linking) but I can go ahead and migrate to 3.8 unless there is a particular reason anyone knows not to.

Copy link
Member

Choose a reason for hiding this comment

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

If we can use python 3.8, I would prefer that too. Just had no time to migrate it until now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Apart from Python, is there anything else here you would prefer done here that would be useful for Linux?

Copy link
Member

Choose a reason for hiding this comment

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

@iMichka I linked the monster patch for linux in a slack PM to Bo

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I'll need to better understand the original problem and why it is Linux specific.

Looking at the patch alone, it doesn't seem obvious at first if there's a better way. You can do things like supplying sysroots but I think that is not what is wanted.

@Bo98
Copy link
Member Author

Bo98 commented Mar 31, 2020

Should this also be applied to older versions?

Perhaps in part - I need to be careful.

@Bo98
Copy link
Member Author

Bo98 commented Mar 31, 2020

Actually this doesn't need depends_on "python@3.8" at runtime really. I could just install it to the correct place so that those who have python@3.8 installed can use it and make Python a build time dependency. Thoughts?

@SMillerDev
Copy link
Member

Sounds good

(lib/"python#{py_ver}/site-packages").install llvmpath/"bindings/python/llvm"

# Install Emacs modes
elisp.install Dir[llvmpath/"utils/emacs/*.el"] + Dir[share/"clang/*.el"]
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

You're sure this preserves all of the previously-included elisp files?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I downloaded the bottle from Jenkins to verify:

$ ls ./llvm/10.0.0/share/emacs/site-lisp/llvm
clang-format.el         clang-rename.el  llvm-mode.el
clang-include-fixer.el  emacs.el         tablegen-mode.el

@josephg
Copy link

josephg commented Apr 2, 2020

I'm still running into polly linking issues using the formula in this PR. I'm trying to build zig from source:

$  brew install https://raw.githubusercontent.com/Bo98/homebrew-core/llvm-cleanup/Formula/llvm.rb
(4 hours later)
zig/build$ cmake .. -DCMAKE_PREFIX_PATH=/usr/local/opt/llvm  -DCMAKE_CXX_COMPILER=/usr/local/opt/llvm/bin/clang++

Configuring zig version 0.5.0+f6d384450
...
-- Build files have been written to: /Users/josephg/3rdparty/zig/build
$ make
...
Undefined symbols for architecture x86_64:
  "getPollyPluginInfo()", referenced from:
      (anonymous namespace)::EmitAssemblyHelper::EmitAssemblyWithNewPassManager(clang::BackendAction, std::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_delete<llvm::raw_pwrite_stream> >) in libclangCodeGen.a(BackendUtil.cpp.o)
ld: symbol(s) not found for architecture x86_64
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [zig0] Error 1
make[1]: *** [CMakeFiles/zig0.dir/all] Error 2
make: *** [all] Error 2

Mangled symbols for getPollyPluginInfo show up in libclang-cpp.dylib and LLVMPolly.so:

$ nm -gU  /usr/local/opt/llvm/lib/libclang-cpp.dylib | grep getPolly                                    
0000000001d294f6 T __Z18getPollyPluginInfov

@Bo98
Copy link
Member Author

Bo98 commented Apr 2, 2020

I thought the issue you describe was specific to standalone clang builds. The third commit of this pull request changes the type of build LLVM performs to avoid standalone builds entirely. If it doesn’t work on these two quite different setups, I don’t really know what can be done without upstream fixing it on their side.

@Bo98 Bo98 mentioned this pull request Apr 2, 2020
3 tasks
@Bo98
Copy link
Member Author

Bo98 commented Apr 2, 2020

If someone can link to me a specific LLVM bug or patch about the issue that is not specific to Clang standalone then let me know. It seems to me that it's not a misconfiguration on Homebrew's side given apt.llvm.org has the same issue and there is a current open bug at Debian about it.

@jedisct1
Copy link
Contributor

jedisct1 commented Apr 2, 2020

At least, this PR totally solved LLVM 10 installation for me.

@Bo98 Bo98 changed the title llvm: fix polly linking, correct tests, fix HEAD, cleanup unneeded installs llvm: general cleanup and corrections Apr 2, 2020
@Bo98
Copy link
Member Author

Bo98 commented Apr 2, 2020

I see a lot of discussion pointing here from various issues so I'll summarise what's been done:

  • This is now built using the "monorepo" layout. This is generally the layout that is the most tested upstream, and as such may well fix things on its own from changing to this. This also allows --HEAD builds to "work" again (beside from upstream bugs that may prevent compile).
  • Fixed a compile issue if Lua was installed.
  • Prevented opportunistic linkage to LZMA.
  • Greatly simplified the formula to remove installs already handled by CMake and to reduce duplicated files and unneeded wrappers. swig is no longer a dependency. No functionality has been lost as far as I know.
  • The binaries are now linked to the shared libraries rather than static. This decreases the size of the bottle and the install by over 75% (4.2GB disk -> 1GB; 1.25GB bottle -> ~300MB). No functionality has been lost, but let me know if there are any significant performance regressions (I doubt it since most other package managers ship it this way).
  • libLLVM-C is now included.
  • Python bindings are now supplied for Python 3.8 rather than 2.7.
  • The tests have been improved to properly test both Xcode and CLT SDKs.
  • Some old, broken Polly-related CMake variables were corrected. Probably no actual benefit here though since I suspect they were enabled by default anyway.

As for zig, I do not believe this is Homebrew specific at all. I've seen the same issue on at least 4 package managers so it seems to clear to me that it is an upstream LLVM change. I recommend you speak with them - but feel free to let me know if you hear anything.

I do suspect however that you can avoid the issue altogether by stopping linking against Clang's static libraries and start linking against the shared library clang-cpp. I know Fedora for one have made an effort to move everything they manage to use clang-cpp. I've not tried it in the context of zig however - this would require modifying the zig CMake scripts.

As some general guidance: LLVM does provide some CMake targets for you in the CMake files they ship at lib/cmake. This is the recommended approach to linking LLVM & Clang in CMake. llvm-config doesn't cover clang-cpp as far as I know and has known bugs on macOS so I strongly discourage using it within CMake as much as possible. Based on some of the logs I've seen over the past couple days, those bugs are clearly still present.

@Bo98 Bo98 closed this in 78baeec Apr 2, 2020
@Bo98 Bo98 deleted the llvm-cleanup branch April 2, 2020 23:03
@moreindirection
Copy link
Contributor

moreindirection commented Apr 3, 2020

Thanks for fixing - llvm installs cleanly for me now.

@timotheecour
Copy link
Contributor

@Bo98 that commit 78baeec only does a small subset of the changes in this PR, what about the other changes?

according to ziglang/zig#4897 (comment)

@robinsoncol Homebrew’s LLVM is misconfigured: #52352

@Bo98
Copy link
Member Author

Bo98 commented Apr 16, 2020

@timotheecour See discussion on ziglang/zig#4799.

I'm aware of some issues on zig 0.6.0 but they don't appear to be the same issues as the one you linked.

@timotheecour
Copy link
Contributor

timotheecour commented Apr 16, 2020

@Bo98 i followed that thread but the "fix" suggested -DZIG_PREFER_CLANG_CPP_DYLIB=ON doesn't really work: it makes zig build but the zig is useless, see ziglang/zig#5055 (comment) ; where i show that:

  • with gcc + manually built llvm+friends + a patch to zig, zig works with or without DZIG_STATIC=ON
  • with clang + homebrew built llvm+friends (or manually built), -DZIG_PREFER_CLANG_CPP_DYLIB=ON is needed to avoid the famous getPollyPluginInfo link error, but then zig is useless (with or without with or without -DZIG_STATIC=ON)

@alebcay alebcay mentioned this pull request Apr 30, 2020
5 tasks
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.

8 participants