cc: remove unneeded linker flag when building with GCC on Linux#10606
cc: remove unneeded linker flag when building with GCC on Linux#10606iMichka merged 1 commit intoHomebrew:masterfrom
Conversation
|
Review period will end on 2021-02-15 at 07:38:15 UTC. |
|
If not, this code needs more logic to work for any version of gcc, not gcc@10 only. Because if someone updates gcc to gcc@11 in homebrew-core, this will break this part of the code. |
MikeMcQuaid
left a comment
There was a problem hiding this comment.
The other solution that was mentioned was to remove
$HOMEBREW_PREFIX/libfrom the list of library paths added bydetermine_library_paths, but I don't know what kind of breakage this could create, so this solution is safer. However feedback on this decision would be great as there may be other opinions about how best to handle this.
Another option still is to ensure there's no GCC files in that directory at all. I really dislike the idea of hardcoding a GCC version in the shims here.
|
I agree with both of you that we should not hardcode the GCC version here. The easiest way to avoid that would be to programmatically determine the GCC version and then replace "10" with the value of the variable containing the version. Regarding GCC specs, I think the way those specs are currently used is that they are passed in as Regarding the removal of the GCC files in I think we could circumvent that by moving the symlinks for the GCC files to a subdirectory like I think if I can get the linker flags into the GCC spec files, that would be the "cleanest" solution. If it's okay I'd like to leave this open since it's a WIP, but I'll definitely close it if I am successful with the other two solutions. |
|
Review period ended. |
a943145 to
8a0820e
Compare
|
@iMichka @sjackman I was digging around the specs for As you can see, I believe the reason we are getting these linker errors is because we are adding To test this, I tried three different scenarios:
The solution here is very simple - we just remove I've renamed the issue since the change for this PR is different now, but I think this is a much simpler solution than what I've tried before. |
|
Makes sense to me. The spec files are currently only installed on Linux (we still need to backport that code to homebrew-core but it's coming soon). It's a good way to handle this, as each formula provides their linker flags and it avoids conflicts. Can you maybe just check one final thing: what happens with mixed dependency trees? (I mean with for example gcc@6 and gcc@7 being dependencies of a formula). Are both paths added, and in which order? Also, are the lib flags for system gcc5 still added? Or does it also use the spec file from system gcc? |
I appreciate this means that in the short-term we can't just unlink this formula but long-term it feels like relying on
If we're going to move them anyway (in a way that doesn't break existing binary packages which I'm not sure is possible): I'd suggest using the existing optlink path.
Yes, most probably.
Stupid question: what's the "specs file" reference here?
Would there be any value/benefit in doing it here before we ship this PR? |
Library/Homebrew/shims/super/cc
Outdated
There was a problem hiding this comment.
A comment explaining why this isn't needed for clang would be good. Have you tested compiling with Clang on Linux and ensured this doesn't break things?
There was a problem hiding this comment.
@iMichka Do we currently have a way to use the clang superenv on Linux? I'm not even sure if we officially support building with clang on Linux right now. I'll update this with a comment to explain my understanding of why it is not needed, and I will also test clang if possible. I think we should leave $HOMEBREW_PREFIX/lib in the ldflags because clang doesn't have an equivalent to the specs file that tells it to look there for libraries.
|
@MikeMcQuaid see https://github.com/Homebrew/linuxbrew-core/blob/master/Formula/gcc.rb#L224-L270 for the specs file. This code is in the post-install step of each gcc formula provided by linuxbrew-core. It allows to defined the different include and lib paths for each gcc version. |
That looks pretty heavy for formulae code. Is it just use in a single GCC or multiple? Why does it have to be in post-install rather than install? Would be good to get something (tested, too!) into Homebrew/brew if it's used on more than a single formula. |
|
There are some steps to keep a backup of the original specs file, but we might just drop that. And it's in the post install step as the content depends on the version of glibc that is installed (though I do not know the details here). I agree that we could move that code to Homebrew/brew as it is used by each gcc formula in the same ways. |
Sounds good in that case, yeh. |
Using the |
I should clarify that when I look at the build logs for a formula using a newer version of GCC, I don't actually see any of those linker flags in the GCC call. I think the arguments from the specs file are "invisibly" added to the GCC call after all the arguments provided to it on the command line. When you say mixed dependency do you mean a situation with If you're talking about the latter case, I think the arguments from the specs are added based on whichever version of Where we'd run into problems is if we had the opposite situation - the formula uses gcc-6 but depends on a formula which has a runtime dependency gcc-7. The I think the only solution there is to forbid formulae on Linux from using a version of gcc that is older than the newest version used by anything in the formula's dependency tree. The easiest way to achieve this is by just using the latest version of GCC (currently gcc-10) whenever the CI host gcc (currently gcc-5) is too old. However we could add an of audit to check for this automatically in PRs. Sorry for such a long answer, but this is a rather complex problem! I'll try to find some test cases to verify what I've said here. |
I think the lib flags from the system GCC spec are only used when we actually call the system GCC. We use the system GCC in CI or whenever the host GCC is version 5 or greater. The first argument in the specs is |
8a0820e to
c7f3371
Compare
brew stylewith your changes locally?brew typecheckwith your changes locally?brew testswith your changes locally?brew manlocally and committed any changes?This pull request should fix a bug on Linux when attempting to use a newer
gccwhen the brewedgcc@5is installed and is linked into$HOMEBREW_PREFIX/lib. Thedetermine_library_pathsmethod inextend/ENV/super.rbadds$HOMEBREW_PREFIX/libto the list of the library paths, which results in-L$HOMEBREW_PREFIX/libbeing add as a linker flag to the superenv. This creates a problem when using newer of versions ofgcc, because this flag causes the linker to use$HOMEBREW_PREFIX/lib/libstdc++.so.6and the other run time libraries fromgcc-5instead of the versions of those libraries that come with newer version ofgccwhich we are trying to use.This solution resolves this by inserting an additional linker flag for the directory which contains the runtime libraries for the newer
gccbefore$HOMEBREW_PREFIX/lib, so that the linker will always find the newergccruntime libraries before finding the older copies of those libraries in$HOMEBREW_PREFIX/lib.This fix should not be merged until
gccon Linux points togcc@10. Once that is completed, we will migrate all formulae which need a newergccfrom whatever version they are currently using todepends_on gcc. In the unlikely event that we have formulae which need agccversion between 5 and 10, we'd have to make equivalent changes for those versions ofgccas well. This is because the directory with the run time libraries includes thegccversion, and therefore differs for each version.The other solution that was mentioned was to remove
$HOMEBREW_PREFIX/libfrom the list of library paths added bydetermine_library_paths, but I don't know what kind of breakage this could create, so this solution is safer. However feedback on this decision would be great as there may be other opinions about how best to handle this.