[PATCH] D97902: [Driver] Clarify --gcc-toolchain

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 3 18:05:17 PST 2021


MaskRay created this revision.
MaskRay added reviewers: nathanchance, nickdesaulniers.
Herald added subscribers: jansvoboda11, dang.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

And add tests: when both --prefix(-B) and --gcc-toolchain are specified, the GCC
installation with the largest version wins. This just documents the
current behavior.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97902

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Driver/Options.td
  clang/test/Driver/gcc-toolchain.cpp


Index: clang/test/Driver/gcc-toolchain.cpp
===================================================================
--- clang/test/Driver/gcc-toolchain.cpp
+++ clang/test/Driver/gcc-toolchain.cpp
@@ -29,3 +29,23 @@
 // CHECK: "{{[^"]*}}/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5{{/|\\\\}}crtbegin.o"
 // CHECK: "-L[[TOOLCHAIN]]/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5"
 // CHECK: "-L[[TOOLCHAIN]]/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5/../../../.."
+//
+// RUN: %clangxx -no-canonical-prefixes %s -### -o %t 2>&1 \
+// RUN:     --target=x86_64-linux-gnu -stdlib=libstdc++ \
+// RUN:     --gcc-toolchain=%S/Inputs/ubuntu_13.04_multiarch_tree/usr \
+// RUN:     --sysroot= | FileCheck %s --check-prefix=UBUNTU13
+
+/// If both --prefix and --gcc-toolchain are specified, the GCC installation with a larger version wins.
+// RUN: %clangxx -no-canonical-prefixes %s -### -o %t 2>&1 \
+// RUN:     --target=i386-unknown-linux -stdlib=libstdc++ \
+// RUN:     --prefix=%S/Inputs/ubuntu_13.04_multiarch_tree/usr \
+// RUN:     --gcc-toolchain=%S/Inputs/ubuntu_11.04_multiarch_tree/usr \
+// RUN:     --sysroot= | FileCheck %s --check-prefix=UBUNTU13
+
+// RUN: %clangxx -no-canonical-prefixes %s -### -o %t 2>&1 \
+// RUN:     --target=i386-unknown-linux -stdlib=libstdc++ \
+// RUN:     --prefix=%S/Inputs/ubuntu_11.04_multiarch_tree/usr \
+// RUN:     --gcc-toolchain=%S/Inputs/ubuntu_13.04_multiarch_tree/usr \
+// RUN:     --sysroot= | FileCheck %s --check-prefix=UBUNTU13
+
+// UBUNTU13: {{.*}}/ubuntu_13.04_multiarch_tree/usr/lib/gcc/x86_64-linux-gnu/4.7
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -599,8 +599,12 @@
 def _DASH_DASH : Option<["--"], "", KIND_REMAINING_ARGS>,
     Flags<[NoXarchOption, CoreOption]>;
 def A : JoinedOrSeparate<["-"], "A">, Flags<[RenderJoined]>, Group<gfortran_Group>;
-def B : JoinedOrSeparate<["-"], "B">, MetaVarName<"<dir>">,
-    HelpText<"Add <dir> to search path for binaries and object files used implicitly">;
+def B : JoinedOrSeparate<["-"], "B">, MetaVarName<"<prefix>">,
+    HelpText<"Search $prefix/$triple-$file and $prefix$file for executables, libraries, includes and data files used by the compiler. "
+    "If $prefix is a directory, the directory is used to search for GCC installation on targets which commonly use GCC. "
+    "The directory usually contains 'include' and 'lib'. "
+    "If $prefix is not a directory, the GCC installation detection is skipped but $prefix can still be used to "
+    "find executables, typically for -nostdinc -nostdlib compiles">;
 def CC : Flag<["-"], "CC">, Flags<[CC1Option]>, Group<Preprocessor_Group>,
     HelpText<"Include comments from within macros in preprocessed output">,
     MarshallingInfoFlag<PreprocessorOutputOpts<"ShowMacroComments">>;
@@ -3667,7 +3671,9 @@
 def mcpu_EQ_QUESTION : Flag<["-"], "mcpu=?">, Alias<print_supported_cpus>;
 def mtune_EQ_QUESTION : Flag<["-"], "mtune=?">, Alias<print_supported_cpus>;
 def gcc_toolchain : Joined<["--"], "gcc-toolchain=">, Flags<[NoXarchOption]>,
-  HelpText<"Use the gcc toolchain at the given directory">;
+  HelpText<"Search for GCC installation in the specified directory, similar to -B<dir>."
+  "The directory usually contains 'lib' and 'include'."
+  "If specified, sysroot is not skipped for GCC detection">;
 def time : Flag<["-"], "time">,
   HelpText<"Time individual commands">;
 def traditional_cpp : Flag<["-", "--"], "traditional-cpp">, Flags<[CC1Option]>,
Index: clang/docs/ClangCommandLineReference.rst
===================================================================
--- clang/docs/ClangCommandLineReference.rst
+++ clang/docs/ClangCommandLineReference.rst
@@ -18,9 +18,9 @@
 
 
 .. program:: clang
-.. option:: -B<dir>, --prefix <arg>, --prefix=<arg>
+.. option:: -B<prefix>, --prefix <arg>, --prefix=<arg>
 
-Add <dir> to search path for binaries and object files used implicitly
+Search $prefix/$triple-$file and $prefix$file for executables, libraries, includes and data files used by the compiler. If $prefix is a directory, the directory is used to search for GCC installation on targets which commonly use GCC. The directory usually contains 'include' and 'lib'. If $prefix is not a directory, the GCC installation detection is skipped but $prefix can still be used to find executables, typically for -nostdinc -nostdlib compiles
 
 .. option:: -F<arg>
 
@@ -256,7 +256,7 @@
 
 .. option:: --gcc-toolchain=<arg>, -gcc-toolchain <arg>
 
-Use the gcc toolchain at the given directory
+Search for GCC installation in the specified directory, similar to -B<dir>.The directory usually contains 'lib' and 'include'.If specified, sysroot is not skipped for GCC detection
 
 .. option:: -gcodeview
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97902.327982.patch
Type: text/x-patch
Size: 4839 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210304/c2afe15e/attachment.bin>


More information about the cfe-commits mailing list