This is an archive of the discontinued LLVM Phabricator instance.

[Driver] Select newest GCC installation on Solaris
ClosedPublic

Authored by ro on Aug 7 2023, 5:18 AM.

Details

Summary

As described in Issue #53709, since 28d58d8fe2094af6902dee7b4d68ec30a3e9d737 clang doesn't find the latest of several parallel GCC installations on Solaris, but only the first in directory order, which is pretty random.

Since this breaks basic functionality of the Solaris port, this patch restores scanning all prefixes for GCC installations.

Tested on sparcv9-sun-solaris2.11, amd64-pc-solaris2.11, and x86_64-pc-linux-gnu.

Diff Detail

Event Timeline

ro created this revision.Aug 7 2023, 5:18 AM
ro requested review of this revision.Aug 7 2023, 5:18 AM
MaskRay added inline comments.Aug 7 2023, 7:57 PM
clang/lib/Driver/ToolChains/Gnu.cpp
2193

Adding a Solaris special case here seems strange.

Do you know what the typical Prefixes values are on Solaris? Is it possible to remove some elements as a special case for Solaris instead?

ro added inline comments.Aug 8 2023, 3:59 AM
clang/lib/Driver/ToolChains/Gnu.cpp
2193

Agreed. This patch in its current form is just meant as a stop-gap measure to unbreak basic Solaris functionality while avoiding to affect other targets.

I've described the value of Prefixes on Solaris in the Issue: its an array of /usr/gcc/<N> for each installed version of GCC, however in directory order and thus random. The exact set is variable since every version can be installed or uninstalled at any time, old versions get deprecated and removed, and new ones added over time.

My fundamental problem here is that I haven't yet been able to reproduce the failure your original patch is meant to fix, so I don't really know what to guard against.

ro updated this revision to Diff 549925.Aug 14 2023, 7:34 AM

Updated based on discussions in Issue #53709:

  • Sort Solaris GCC prefixes in reverse version order so the latest version is picked.
  • Update testcase to match.

Tested on amd64-pc-solaris2.11 and x86_64-pc-linux-gnu.

I'm seeing weird testsuite failures in 2-stage builds on Solaris/amd64 with gcc 12, but not with clang 16, which I don't yet understand.

Thanks for the update. Regarding testing, it seems that unittests will be more convenience than creating so many placeholder files in Inputs/. clang/unittests/Driver/ToolChainTest.cpp TEST(ToolChainTest, VFSGCCInstallation) has an example for Linux. You can add another for Solaris.

clang/lib/Driver/ToolChains/Gnu.cpp
2258

It's better to use https://en.wikipedia.org/wiki/Schwartzian_transform here to avoid calling llvm::sys::path::filename and Generic_GCC::GCCVersion::Parse in the comparator. Then the comparator is just A < B and can just be removed.

ro marked an inline comment as done.Aug 15 2023, 2:46 AM

Thanks for the update. Regarding testing, it seems that unittests will be more convenience than creating so many placeholder files in Inputs/. clang/unittests/Driver/ToolChainTest.cpp TEST(ToolChainTest, VFSGCCInstallation) has an example for Linux. You can add another for Solaris.

TBH, I'm quite sceptical about the unittest framework here: we already have 2300+ empty files in clang/test/Driver, so adding 12 more shouldn't be such a big deal. With a real in-filesystem tree, I can quickly test various scenarious with clang -v --sysroot, while this isn't possible with the unittest framework (which I find way harder to read). I'm adding the unittest nonetheless, but would prefer to keep the lit-based test instead.

clang/lib/Driver/ToolChains/Gnu.cpp
2258

This is way shorter and efficient indeed. Patch updated.

ro updated this revision to Diff 550226.Aug 15 2023, 2:48 AM
ro marked an inline comment as done.
  • Simplify SolarisPrefixes sorting.
  • Switch to unitest`.
MaskRay accepted this revision.Aug 15 2023, 9:08 AM

Thanks!

clang/lib/Driver/ToolChains/Gnu.cpp
2258

Use emplace_back

This revision is now accepted and ready to land.Aug 15 2023, 9:08 AM
This revision was landed with ongoing or failed builds.Aug 16 2023, 12:58 AM
This revision was automatically updated to reflect the committed changes.