Skip to content

Commit 0f744f3

Browse files
committed
Add an option to correct driver's fallback position
1 parent e42895a commit 0f744f3

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5541,6 +5541,12 @@ def fno_rtlib_defaultlib : Flag<["-"], "fno-rtlib-defaultlib">,
55415541
Visibility<[ClangOption, CLOption]>,
55425542
Group<f_Group>,
55435543
HelpText<"On Windows, do not emit /defaultlib: directives to link compiler-rt libraries">;
5544+
def frtlib_per_target :
5545+
Flag<["-"], "frtlib-per-target">, Visibility<[ClangOption, CLOption]>, Group<f_Group>,
5546+
HelpText<"Compiler-rt libraries are in per-target directories">;
5547+
def fno_rtlib_per_target :
5548+
Flag<["-"], "fno-rtlib-per-target">, Visibility<[ClangOption, CLOption]>, Group<f_Group>,
5549+
HelpText<"Compiler-rt libraries are in one directory and have target-specific names">;
55445550
def offload_add_rpath: Flag<["--"], "offload-add-rpath">,
55455551
Flags<[NoArgumentUnused]>,
55465552
Alias<frtlib_add_rpath>;

clang/lib/Driver/ToolChain.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,10 @@ std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component,
685685
Path = P;
686686
}
687687
// Some targets default to the old layout.
688-
if (getTriple().isOSAIX() || getTriple().isPS() ||
689-
getTriple().isWindowsMSVCEnvironment())
688+
bool UseOldLayout =
689+
getTriple().isOSAIX() || getTriple().isPS() || getTriple().isOSWindows();
690+
if (!Args.hasFlag(options::OPT_frtlib_per_target,
691+
options::OPT_fno_rtlib_per_target, !UseOldLayout))
690692
Path.clear();
691693

692694
// Check the filename for the old layout if the new one does not exist.

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6225,6 +6225,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
62256225
}
62266226
}
62276227

6228+
// Don't warn about compiler-rt layout options.
6229+
Args.ClaimAllArgs(options::OPT_frtlib_per_target);
6230+
Args.ClaimAllArgs(options::OPT_fno_rtlib_per_target);
6231+
62286232
// Warn about ignored options to clang.
62296233
for (const Arg *A :
62306234
Args.filtered(options::OPT_clang_ignored_gcc_optimization_f_Group)) {

clang/test/Driver/sanitizer-ld.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,21 @@
798798
// CHECK-CFI-STATS-WIN64: "--dependent-lib=clang_rt.stats{{(-x86_64)?}}.lib"
799799
// CHECK-CFI-STATS-WIN64: "--linker-option=/include:__sanitizer_stats_register"
800800

801+
// RUN: not %clang -fsanitize=cfi -fsanitize-stats -### %s 2>&1 \
802+
// RUN: --target=x86_64-pc-windows \
803+
// RUN: -resource-dir=%S/Inputs/resource_dir \
804+
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
805+
// RUN: -frtlib-per-target \
806+
// RUN: | FileCheck --check-prefix=CHECK-CFI-STATS-RTLIB %s -DSUFFIX=
807+
// RUN: not %clang -fsanitize=cfi -fsanitize-stats -### %s 2>&1 \
808+
// RUN: --target=x86_64-pc-windows \
809+
// RUN: -resource-dir=%S/Inputs/resource_dir \
810+
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
811+
// RUN: -fno-rtlib-per-target \
812+
// RUN: | FileCheck --check-prefix=CHECK-CFI-STATS-RTLIB %s -DSUFFIX=-x86_64
813+
// CHECK-CFI-STATS-RTLIB: "--dependent-lib=clang_rt.stats_client[[SUFFIX]].lib"
814+
// CHECK-CFI-STATS-RTLIB: "--dependent-lib=clang_rt.stats[[SUFFIX]].lib"
815+
801816
// RUN: not %clang -fsanitize=cfi -fsanitize-stats -### %s 2>&1 \
802817
// RUN: --target=i686-pc-windows \
803818
// RUN: --sysroot=%S/Inputs/basic_linux_tree \

0 commit comments

Comments
 (0)