This is an archive of the discontinued LLVM Phabricator instance.

[Driver] Add --gcc-install-dir=
ClosedPublic

Authored by MaskRay on Sep 5 2022, 4:02 PM.

Details

Summary

This option specifies a GCC installation directory such as
/usr/lib/gcc/x86_64-linux-gnu/12, /usr/lib/gcc/x86_64-gentoo-linux-musl/11.2.0 .

It is intended to replace --gcc-toolchain=, which specifies a directory where
lib/gcc{,-cross} can be found. When --gcc-toolchain= is specified, the
selected lib/gcc/$triple/$version installation uses complex logic and the
largest GCC version is picked. There is no way to specify another version in the
presence of multiple GCC versions.

D25661 added gcc-config detection for Gentoo: ScanGentooConfigs.
The implementation may be simplified by using --gcc-install-dir=.

Diff Detail

Event Timeline

MaskRay created this revision.Sep 5 2022, 4:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 5 2022, 4:02 PM
MaskRay requested review of this revision.Sep 5 2022, 4:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 5 2022, 4:02 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
MaskRay updated this revision to Diff 458065.Sep 5 2022, 4:14 PM

improve test

MaskRay edited the summary of this revision. (Show Details)Sep 5 2022, 4:17 PM

At a first glance, it works. I'm now building GCC:11 here to test it against two real installations.

mgorny accepted this revision.Sep 18 2022, 1:29 AM

Ok, this works fine for me (though I haven't run the tests yet). If D109621 and this one lands, I think the old Gentoo logic can be removed. We'll still have to update gcc-config to keep updating the config files but I'm pretty sure we can do that in time for 16.0.0.

This revision is now accepted and ready to land.Sep 18 2022, 1:29 AM
mgorny requested changes to this revision.Sep 18 2022, 3:19 AM

Unfortunately, we have some test failures after this change, e.g.:

FAIL: Clang :: CodeGenHLSL/basic_types.hlsl (6525 of 15795)
******************** TEST 'Clang :: CodeGenHLSL/basic_types.hlsl' FAILED ********************
Script:
--
: 'RUN: at line 1';   /var/tmp/portage/sys-devel/clang-16.0.0_pre20220915/work/x/y/clang-abi_x86_32.x86/bin/clang --driver-mode=dxc  -Tlib_6_7 -fcgl -Fo - /var/tmp/portage/sys-devel/clang-16.0.0_pre20220915/work/clang/test/CodeGenHLSL/basic_types.hlsl | /usr/lib/llvm/16/bin/FileCheck /var/tmp/portage/sys-devel/clang-16.0.0_pre20220915/work/clang/test/CodeGenHLSL/basic_types.hlsl
--
Exit Code: 2

Command Output (stderr):
--
+ : 'RUN: at line 1'
+ /usr/lib/llvm/16/bin/FileCheck /var/tmp/portage/sys-devel/clang-16.0.0_pre20220915/work/clang/test/CodeGenHLSL/basic_types.hlsl
+ /var/tmp/portage/sys-devel/clang-16.0.0_pre20220915/work/x/y/clang-abi_x86_32.x86/bin/clang --driver-mode=dxc -Tlib_6_7 -fcgl -Fo - /var/tmp/portage/sys-devel/clang-16.0.0_pre20220915/work/clang/test/CodeGenHLSL/basic_types.hlsl
clang-16: error: unknown argument: '--gcc-install-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/12.2.1'
FileCheck error: '<stdin>' is empty.
FileCheck command line:  /usr/lib/llvm/16/bin/FileCheck /var/tmp/portage/sys-devel/clang-16.0.0_pre20220915/work/clang/test/CodeGenHLSL/basic_types.hlsl

--

********************

Unfortunately, within the current config framework, it's impossible to set options per --driver-mode=... (and i'm not convinced we really want to pursue keeping a bunch of config files to figure out which driver modes use GCC and which do not). Would it be feasible to add this option (and other similar options — e.g. -rtlib, -unwindlib, -stdlib) to all drivers, and make them emit argument unused warnings like -fuse-ld?

This revision now requires changes to proceed.Sep 18 2022, 3:19 AM

Hmm, apparently this could be achieved by making it a "CoreOption".

MaskRay added a comment.EditedSep 18 2022, 10:59 AM

Hmm, apparently this could be achieved by making it a "CoreOption".

I don't think it is appropriate to have CoreOption. The Windows dxc support appears to have nothing to do with gcc installation unless I am mistaken.
It's for configuration file support to figure out how to work with --driver-mode, not this patch which causes no test failure if you don't place --driver-mode in a default config file (which isn't a supported case).

In general I am not sure we can reasonably support placing arbitrary options into a default config and expect all test suite to pass.
For --rtlib= --unwindlib= --stdlib= etc, yeah, we currently add the option to fix many parameters, but it is infeasible if this expands to more configurable defaults.

I think you misunderstood me. The aforementioned tests fail if I put --gcc-install-dir= in the config file. There is no way to put it in the config file that wouldn't affect these tests right now.

I think you misunderstood me. The aforementioned tests fail if I put --gcc-install-dir= in the config file. There is no way to put it in the config file that wouldn't affect these tests right now.

This is unsupported. It's like if you put -W in a default config file it may change a lot of things. We cannot reasonably support such tests without introducing a lot of complexity to a lot of driver tests.

mgorny accepted this revision.Sep 21 2022, 1:31 PM

Let's tackle the config changes independently and not block this on them.

This revision is now accepted and ready to land.Sep 21 2022, 1:31 PM
This revision was automatically updated to reflect the committed changes.