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

Improve LLVM configuration on Mac OS X #18727

Merged
merged 3 commits into from
Nov 16, 2021

Conversation

mppf
Copy link
Member

@mppf mppf commented Nov 15, 2021

Follow-up to PR #18606

  • Add isysroot argument even for system llvm

    • This appears to be necessary on Mac OS X 11.6.1 with Homebrew llvm
      version 11.1.0.
  • Link clang statically for Mac OS X with system LLVM

  • Add -I and -L paths according to sysroot

    • The -L path at least seems to be necessary on Mac OS 11.6 and
      newer. See https://developer.apple.com/forums/thread/666700 for some
      background in this area. Even though the -isysroot path covers it,
      the linking call does not seem to use it.
  • homebrew system LLVM 11.1 functions on Big Sur
  • homebrew system LLVM 11.1 functions on Catalina
  • homebrew system LLVM functions on Mojave
  • bundled LLVM functions on Big Sur and Catalina
  • full local testing

Reviewed by @ronawho - thanks!

This appears to be necessary on Mac OS X 11.6.1 with
Homebrew llvm version 11.1.0.

---
Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
---
Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
This seems to be necessary on Mac OS 11.6 and newer.
See https://developer.apple.com/forums/thread/666700
for some background in this area.

---
Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
@bradcray
Copy link
Member

I verified that this resolves https://github.com/Cray/chapel-private/issues/2702 in my setup (Mojave, CHPL_LLVM=system, homebrew llvm).

@mppf mppf requested a review from ronawho November 16, 2021 18:25
@@ -324,7 +324,8 @@ def get_sysroot_resource_dir_args():
args = [ ]
target_platform = chpl_platform.get('target')
llvm_val = get()
if target_platform == "darwin" and llvm_val == "bundled":
if (target_platform == "darwin" and
(llvm_val == "bundled" or llvm_val == "system")):
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's worth changing, but just checking for my sake -- is this the same as llvm_val != 'none'?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not quite, because we also can have 'unset' as the CHPL_LLVM value.

@mppf mppf merged commit d36815f into chapel-lang:main Nov 16, 2021
@mppf mppf deleted the mac-os-x-link-clang-static branch November 16, 2021 19:48
mppf added a commit to mppf/chapel that referenced this pull request Nov 22, 2021
* Don't add sysroot args for system LLVM on Mac OS X
* Don't add -I and -L equivalents to sysroot argument.

I think these are both not necessary. I think that these were workarounds
for a problem local to my system (because things started to behave better
when I reinstalled CommandLineTools).

---
Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
mppf added a commit that referenced this pull request Nov 29, 2021
Address command quoting issue in printchplenv

For #18741

This PR adjusts chpl_compiler.get_compiler_command and
chpl_llvm.get_llvm_clang to return a Python list so that it is easier to
construct the correctly quoted command to run when using these.

It also adjusts get_compiler_version to accept flag of host or target.

While there, avoid adding a gcc prefix argument for clang when the prefix
is just the normal /usr.

It removes two workarounds I added in PR #18727 because reinstalling
CommandLineTools fixed the problem for me and these workarounds weren't
sufficient to get the third-party code compiling.

Future Work:
 * figure out how to resolve linker errors like `object file ... was
   built for newer macOS version (11.6) than being linked (11.0)` with
   CHPL_LLVM=bundled when linking `chpl` itself. So far these appear to
   be harmless.
 * Look into problems with Mojave with CHPL_LLVM=bundled (wasn't working
   for @e-kayrakli but so far we are not sure if that is a local issue)

Verified that `make check` passes on
- [x] Big Sur with CHPL_LLVM=system with Homebrew LLVM 11.1
- [x] Big Sur with CHPL_LLVM=bundled
- [x] Mojave with CHPL_LLVM=system with Homebrew LLVM 10.1
- [x] Catalina with CHPL_LLVM=system with Homebrew LLVM 10.1
- [x] Ubuntu builds with CHPL_LLVM=bundled, CHPL_TARGET_COMPILER=clang,
  custom GCC, and no clang in path
- [x] Ubuntu builds with CHPL_LLVM=system

And
- [x] full local testing

Reviewed by @e-kayrakli - thanks!
mppf added a commit that referenced this pull request Feb 22, 2022
Fix problem with static link order with static clang and llvm

This resolves a problem on CentOS 7 which has an error like this:

```
: CommandLine Error: Option 'enable-vfe' registered more than once!
LLVM ERROR: inconsistency in registered CommandLine options
```

We have some evidence that this error was caused by statically linking
LLVM libraries but dynamically linking clang-cpp. For one thing, on that
system, changing to statically linking both solved this issue.

This PR changes chpl_llvm.py to ask `llvm-config` if it has shared
libraries available (with `llvm-config --shared-mode`) and if not it will
use the static linking approach for both the LLVM and clang dependencies.

Additionally, when using static linking for LLVM and clang, on CentOS 7,
the linker was picky about the order. Since the link line should have the
things depended upon later, this PR puts the `-l` flags for clang
libraries before the `-l` flags for LLVM libraries. On Mac OS X with
Homebrew LLVM, we were using the same (arguably incorrect) `-l` ordering
but for some reason the linker there did not complain.

Note that we statically link both LLVM and clang on Mac OS X (since PR
#18727). This PR leaves it this way. Historically, there have been
problems with upstream LLVM and Homebrew in building a dynamic library
that works with `llvm-config` (in particular the versioned file, like
`libLLVM-11.dylib`, is missing). See [this LLVM bug
report](llvm/llvm-project#39599). I expect that
we will be able to allow dynamic linking on Mac OS X once we are able to
establish that the issue is resolved.

We are statically linking with CHPL_LLVM=bundled and this PR does not
change that.

Reviewed by @Maxrimus - thanks!

- [x] 'hello' builds and runs with system LLVM on Ubuntu 21
- [x] 'hello' builds and runs with system LLVM on SLES 12
- [x] 'hello' builds and runs with system LLVM on Mac OS X with Homebrew
- [x] 'hello' builds and runs with bundled LLVM on Ubuntu 21
- [x] full local testing
@mppf mppf mentioned this pull request Mar 11, 2022
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.

3 participants