-
-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Problem when linking to clang and getting the Homebrew libc++ #96915
Comments
I'm not sure what to make of this problem, but I'm pretty sure your problem isn't due to mixed
My guess is that you've run into a different LLVM bug. |
Yes, my hypothesis here is that the Mac OS X libc++ happens to be compatible with the one from llvm@11 for the versions used here.
Did you try the reproducer? I think the
Yes and some things appeared to work in our project. I boiled down to a reproducer above a pattern that was not working. Edit -- it might also matter if static or dynamic linking with clang/llvm libraries is used.
Note that the clang from llvm@13 is not involved in compiling my example at all. |
If this hypothesis were true, then I would expect to see
Yes, I agree with you that the
I'm still not convinced.
Sure, but I don't think this is relevant here. At the very least, this isn't relevant to any claims I've previously made. |
Well, feel free to investigate further. I've already spent about a week on this and the workaround I show here is the best I could come up with. |
Does the behaviour change if the clang from llvm@13 is used? |
Not for me, anyway
|
Do you mind reporting this upstream (i.e. LLVM)? I think this is an upstream bug. Linking If your hypothesis is correct, then it is impossible to link against |
@carlocab - the reason that I have posted it here and not upstream is that I was unable to reproduce the issue when not doing a Homebrew build. (I.e. if I build and install LLVM somewhere myself, manually, outside of homebrew, everything works OK). AFAIK that is due to the Additionally I wanted to ask if it was clear to you why building with headers from one version of a library and then linking with a different version of the same library is a problem, in general. I could explain that more / find a reference to link here, if not. We could certainly ask upstream if they expect that to work for libc++ specifically - but I'm not so sure they can even answer the question of whether it is expected to work between Apple's libc++ and the open source one. I think we would have to involve somebody from Apple to answer that. Apple's libc++ could have any number of changes that break compatibility with the open source version.
Right, that is one way to fix it. Including that, I can think of several ways that Homebrew could fix it:
Relevant to the last option: Why does the LLVM formula install libc++ at all? Does it need to continue to do that?
Do you already know the answer? Why does homebrew install libc++ with LLVM by default? |
I am almost certainly confused |
Which version of LLVM did you build? How did you configure it?
I'm aware that, in general, this is a recipe for ABI breakage. It just seems unlikely that this is what's happening here. We know that this doesn't occur with LLVM 11 but does with LLVM 13, and you've suggested that Apple We also know that this problem does not go away with Homebrew LLVM 13 We can also try the reverse exercise: use Homebrew LLVM 13
If there was indeed ABI breakage in
At this stage, all of these solutions are show-stoppers because they're not the right solutions. They are predicated on a diagnosis that doesn't seem to be correct.
A few reasons:
Those are just the one off the top of my head. There's likely more.
Yes, unless we have compelling reasons to do otherwise. I don't think we have any so far. |
I built LLVM 12 with the Homebrew patches applied. I tried to make it as similar as possible to the Homebrew build but was having problems with the lldb build so disabled that. Here is the cmake command I used to configure it:
I don't know that any version of Apple's
Do you know how to query the library version? The one reported by
Is this the same version number you are talking about?
That is interesting. However I don't think it necessarily rules out header vs library version differences. In particular, the reproducer uses some of clang in a library (and links statically with it). That library is compiled as part of the Homebrew package and so it does not use the Homebrew libc++ today. So, in other words, to do that experiment properly, you would need a version of the Homebrew LLVM 13 clang libraries was compiled with the Homebrew LLVM 13 libc++ at include-time. I bet that will make the reproducer no longer show a problem. Is that an experiment you are able to try? |
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as resolved.
This comment was marked as resolved.
This seems to backpedal from your earlier claim that
It could, but this is still predicated on one of Apple or upstream LLVM breaking the ABI (both unlikely). In any case, any minor problems, if they exist, appear to be orthogonal to the issue here. They haven't been exposed previously, and are not exposed by your reproducer in LLVM 11.
What is important is the compatibility version, which is the same.
You would bet wrong.
This is built from LLVM 13.0.1 (llvm/llvm-project@75e33f7). I invoked CMake using Details
The object file was compiled with
and linked with
We can check that this links with the
It also loads our just-built
This does still load Apple We can also check that
So, even if we compile To be sure, I did check that I could reproduce the same results as your initial example when using Homebrew LLVM (i.e. not one that I just built locally) and linking with Homebrew |
To try to remove any doubt about mixing
This should guarantee that I am using my just-installed Here's what I get:
|
OK, at this point you have more information than I do that would be useful to LLVM developers in an upstream bug report. In particular, the bug report to give them is ideally one that does not use Homebrew at all. Wait, no, the cmake you did uses the Homebrew clang in order to get it to build with that libc++. So it is still not a demonstrator independent of Homebrew. |
This comment was marked as off-topic.
This comment was marked as off-topic.
I've been able to create some scripts to reproduce that we can use as a bug report to LLVM. These scripts don't use Homebrew at all. (I haven't tried it on a system without Homebrew installed at all but I didn't have any llvm package installed). runtest.sh
cmake1.sh
build1.sh
cmake2.sh
build2.sh
repro.sh
repro.cpp
|
I have created this llvm project issue: llvm/llvm-project#54438 |
NB:
Mixing libc++ versions is unsupported upstream. |
@kencu As I mentioned in the discussion above, I don't think this is a consequence of mixing libc++ versions. You will get the erroneous behaviour if you build libc++ first and then link libLLVM against your just-built libc++. |
If you see what I did with install_name_tool, you can make the error come and go at will just by by forcing mixing or not mixing of libc++ versions… |
Of course, it’s possible some other factor could be involved too…toolchains are like that! |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Thanks for keeping this alive, @Bo98! |
I am exploring solutions to this at #106925. |
I experimented with removing the A few notes:
|
although those projects/runtimes (libcxx/libcxxabi) need to be enabled for the build, there are toggles to allow you to install the libraries or not: you probably already knew this, of course. |
Yes, I vaguely recalled some However: if we don't want to link with different versions of |
we at the unnamed always install and use the latest headers that match the compiler version, but (usually) don’t install libcxx/libcxxabi. It has worked generally well for us; you might find the same. MacOS is designed to deploy on older targets, so the newer headers have guards in them for the capabilities of the libcxx you are deploying to. this install technique was originally set up by one of the Apple compiler engineers who previously was involved way back when — I just continued that along. At one point I installed a newer version of libcxx/libcxxabi as well that can be specifically optionally used during builds on older systems, but there are conflicts sometimes as you have found too… best of luck! you’re doing great work here! |
I just wanted to point out some ways that the Chapel package might be unique:
|
@carlocab: Following up on Michael's hypothesis, could you share the list of 20+ formulae you're referring to above? I'm curious whether (through inspection or reasoning or inquiries) we could confirm or deny the guess. |
Here's a list:
A number of these also link with
I notice that Why would using |
Another odd thing about Chapel is that we have some relatively strange workarounds for this issue...
We are statically linking with clang and LLVM libraries on Mac OS X because of bugs in The static linking is a workaround. From a PR message talking about it ( chapel-lang/chapel#19272 ) :
It's my understanding that projects using |
Not sure if doing away with static linking will help, but you can definitely do that with
In particular, you should no longer see the issue reported at llvm/llvm-project#39599 using a recent enough LLVM packaged with Homebrew. |
I think a good next step would be to see if the reproducer in this issues original post still has the problem if it is changed to dynamically link. |
I've reproduced the problem in the OP with static linking and the current LLVM 14 Homebrew package on my system:
(it is supposed to print out "is 1"). However, I'm still seeing the problem with dynamic linking:
The workaround (adding So, unfortunately, it does not seem that switching Chapel to dynamic linking will help with this problem. Nonetheless, I'd like to look at doing that anyway, to make it less unique in this regard, and to better match what we do on linux. |
Chapel should no longer be linking with LLVM
Compare this with the bottle built at #110783:
Incidentally, this may be what distinguishes Chapel from the other formulae that use LLVM Incidentally, something weird I noticed, in the ARM bottles:
There is no linkage with Not sure if this is an issue. |
@carlocab - that's great, thanks. I see that #106925 went in but I'm not understanding what happened to fix the problem. Could you summarize? Thanks. Also I am understanding that we should be able to remove the workaround now from Chapel, so please speak up if I'm misunderstanding. Regarding the |
I can confirm that the reproducer in this issue is no longer misbehaving for me with the updated LLVM 14 or 15 Homebrew packages.
|
That's this one: d3999fc (plus a little extra here, since I am bad at atomic commits)
I think so; if by workaround you mean what you have in place to try to avoid linkage with both LLVM libc++ and Apple libc++.
Yea, maybe, but all our builds of libLLVM (14, 15, ARM, Intel) link with See, for example, the output of |
OK, so the LLVM libc++ is being installed into a different directory from the LLVM install (e.g. |
Remove workaround for Homebrew libc++ issue This PR removes a workaround for issue #19217 (which is the same issue as Homebrew/homebrew-core#96915 and llvm/llvm-project#54438 ). The problem is solved in the current Homebrew LLVM 14 and LLVM 15 formulae now that libc++ is installed into a different directory than the LLVM libraries. (This problem would still be present for the LLVM 12 and 13 formulae). Since the workaround is removed, this PR adjusts printchplenv to raise an error if using Mac OS X with system LLVM 11, 12, or 13. Such LLVMs will not be selected as a quickstart configuration. Also, it updates prereqs.rst to indicate that LLVM 14 or newer is required on Mac OS X. Reviewed by @daviditen - thanks! - [x] testing on Mac OS X 10.15 "Catalina" - [x] testing on Mac OS X 11 "Big Sur" - [x] testing on Mac OS X 12 "Monterey" (x86) - [x] testing on Mac OS X 12 "Monterey" (M1)
brew gist-logs <formula>
link ORbrew config
ANDbrew doctor
outputVerification
brew update
and am still able to reproduce my issue.brew doctor
and that did not fix my problem.What were you trying to do (and why)?
I'm one of the developers for the upstream Chapel project. Chapel was working with
llvm@11
but we were running into strange problems withllvm@12
andllvm@13
(see chapel-lang/chapel#19217 ).It took me a long time but I eventually figured out that the problem was due to mixing libc++ versions. The Chapel compiler,
chpl
was linking with the libc++ included in the Homebrew LLVM package; but the LLVM and Clang libraries were linking with a libc++ provided by the system. This will occur with any program that is linking with llvm or clang libraries using the usual commands to add a-L
path for/usr/local/Cellar/llvm/13.0.1_1/lib
, including using the output of/usr/local/opt/llvm@13/bin/llvm-config --ldflags
.I have included a small reproducer example in the step-by-step section below.
What happened (include all command output)?
With the test program provided below, I get this output
What did you expect to happen?
I expected this output from the test program provided below (without the workaround):
Step-by-step reproduction instructions (by running
brew
commands)Then, I have saved the following to
pretend-in-llvm.cpp
and within it are the commands to reproduce this problem.The text was updated successfully, but these errors were encountered: