Skip to content

Commit d3864d9

Browse files
authored
[Driver] Default -msmall-data-limit= to 0 and clean up code
D57497 added -msmall-data-limit= as an alias for -G and defaulted it to 8 for -fno-pic/-fpie. The behavior is already different from GCC in a few ways: * GCC doesn't accept -G. * GCC -fpie doesn't seem to use -msmall-data-limit=. * GCC emits .srodata.cst* that we don't use (#82214). Writable contents caused confusion (https://bugs.chromium.org/p/llvm/issues/detail?id=61) In addition, * claiming `-shared` means we don't get a desired `-Wunused-command-line-argument` for `clang --target=riscv64-linux-gnu -fpic -c -shared a.c`. * -mcmodel=large doesn't work for RISC-V yet, so the special case is strange. * It's quite unusual to emit a warning when an option (unrelated to relocation model) is used with -fpic. * We don't want future configurations (Android) to continue adding customization to `SetRISCVSmallDataLimit`. I believe the extra code just doesn't pull its weight and should be cleaned up. This patch also changes the default to 0. GP relaxation users are encouraged to specify these customization options explicitly. Pull Request: #83093
1 parent b5f3e28 commit d3864d9

File tree

6 files changed

+12
-54
lines changed

6 files changed

+12
-54
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,9 +604,6 @@ def warn_drv_unsupported_gpopt : Warning<
604604
"ignoring '-mgpopt' option as it cannot be used with %select{|the implicit"
605605
" usage of }0-mabicalls">,
606606
InGroup<UnsupportedGPOpt>;
607-
def warn_drv_unsupported_sdata : Warning<
608-
"ignoring '-msmall-data-limit=' with -mcmodel=large for -fpic or RV64">,
609-
InGroup<OptionIgnored>;
610607
def warn_drv_unsupported_longcalls : Warning<
611608
"ignoring '-mlong-calls' option as it is not currently supported with "
612609
"%select{|the implicit usage of }0-mabicalls">,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,42 +2126,6 @@ void Clang::AddPPCTargetArgs(const ArgList &Args,
21262126
}
21272127
}
21282128

2129-
static void SetRISCVSmallDataLimit(const ToolChain &TC, const ArgList &Args,
2130-
ArgStringList &CmdArgs) {
2131-
const Driver &D = TC.getDriver();
2132-
const llvm::Triple &Triple = TC.getTriple();
2133-
// Default small data limitation is eight.
2134-
const char *SmallDataLimit = "8";
2135-
// Get small data limitation.
2136-
if (Args.getLastArg(options::OPT_shared, options::OPT_fpic,
2137-
options::OPT_fPIC)) {
2138-
// Not support linker relaxation for PIC.
2139-
SmallDataLimit = "0";
2140-
if (Args.hasArg(options::OPT_G)) {
2141-
D.Diag(diag::warn_drv_unsupported_sdata);
2142-
}
2143-
} else if (Args.getLastArgValue(options::OPT_mcmodel_EQ)
2144-
.equals_insensitive("large") &&
2145-
(Triple.getArch() == llvm::Triple::riscv64)) {
2146-
// Not support linker relaxation for RV64 with large code model.
2147-
SmallDataLimit = "0";
2148-
if (Args.hasArg(options::OPT_G)) {
2149-
D.Diag(diag::warn_drv_unsupported_sdata);
2150-
}
2151-
} else if (Triple.isAndroid()) {
2152-
// GP relaxation is not supported on Android.
2153-
SmallDataLimit = "0";
2154-
if (Args.hasArg(options::OPT_G)) {
2155-
D.Diag(diag::warn_drv_unsupported_sdata);
2156-
}
2157-
} else if (Arg *A = Args.getLastArg(options::OPT_G)) {
2158-
SmallDataLimit = A->getValue();
2159-
}
2160-
// Forward the -msmall-data-limit= option.
2161-
CmdArgs.push_back("-msmall-data-limit");
2162-
CmdArgs.push_back(SmallDataLimit);
2163-
}
2164-
21652129
void Clang::AddRISCVTargetArgs(const ArgList &Args,
21662130
ArgStringList &CmdArgs) const {
21672131
const llvm::Triple &Triple = getToolChain().getTriple();
@@ -2170,7 +2134,10 @@ void Clang::AddRISCVTargetArgs(const ArgList &Args,
21702134
CmdArgs.push_back("-target-abi");
21712135
CmdArgs.push_back(ABIName.data());
21722136

2173-
SetRISCVSmallDataLimit(getToolChain(), Args, CmdArgs);
2137+
if (Arg *A = Args.getLastArg(options::OPT_G)) {
2138+
CmdArgs.push_back("-msmall-data-limit");
2139+
CmdArgs.push_back(A->getValue());
2140+
}
21742141

21752142
if (!Args.hasFlag(options::OPT_mimplicit_float,
21762143
options::OPT_mno_implicit_float, true))

clang/test/CodeGen/RISCV/riscv-sdata-module-flag.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,19 @@
2121
// RUN: | FileCheck %s -check-prefix=RV64-S2G4
2222
// RUN: %clang --target=riscv64-unknown-elf %s -S -emit-llvm -msmall-data-threshold=16 -o - \
2323
// RUN: | FileCheck %s -check-prefix=RV64-T16
24-
// RUN: %clang --target=riscv64-linux-android %s -S -emit-llvm -o - \
25-
// RUN: | FileCheck %s -check-prefix=RV64-ANDROID
26-
// RUN: %clang --target=riscv64-linux-android %s -S -emit-llvm -msmall-data-limit=8 -o - \
27-
// RUN: | FileCheck %s -check-prefix=RV64-ANDROID
2824
// RUN: %clang --target=riscv64-unknown-elf %s -S -emit-llvm -fpic -o - \
2925
// RUN: | FileCheck %s -check-prefix=RV64-PIC
3026

3127
void test(void) {}
3228

33-
// RV32-DEFAULT: !{i32 8, !"SmallDataLimit", i32 8}
29+
// RV32-DEFAULT: !{i32 8, !"SmallDataLimit", i32 0}
3430
// RV32-G4: !{i32 8, !"SmallDataLimit", i32 4}
3531
// RV32-S0: !{i32 8, !"SmallDataLimit", i32 0}
3632
// RV32-S2G4: !{i32 8, !"SmallDataLimit", i32 4}
3733
// RV32-T16: !{i32 8, !"SmallDataLimit", i32 16}
3834
// RV32-PIC: !{i32 8, !"SmallDataLimit", i32 0}
3935

40-
// RV64-DEFAULT: !{i32 8, !"SmallDataLimit", i32 8}
36+
// RV64-DEFAULT: !{i32 8, !"SmallDataLimit", i32 0}
4137
// RV64-G4: !{i32 8, !"SmallDataLimit", i32 4}
4238
// RV64-S0: !{i32 8, !"SmallDataLimit", i32 0}
4339
// RV64-S2G4: !{i32 8, !"SmallDataLimit", i32 4}
@@ -48,6 +44,3 @@ void test(void) {}
4844
// The value will be passed by module flag instead of target feature.
4945
// RV32-S0-NOT: +small-data-limit=
5046
// RV64-S0-NOT: +small-data-limit=
51-
52-
// RV64-ANDROID-NOT: small-data-limit
53-
// RV64-ANDROID: !{i32 8, !"SmallDataLimit", i32 0}

clang/test/Driver/riscv-sdata-warning.c

Lines changed: 0 additions & 4 deletions
This file was deleted.

clang/test/Driver/riscv-sdata.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %clang -### -S --target=riscv64 %s 2>&1 | FileCheck %s
2+
// RUN: %clang -### -S --target=riscv64 -msmall-data-limit=8 %s 2>&1 | FileCheck %s --check-prefix=EIGHT
3+
4+
// CHECK-NOT: "-msmall-data-limit"
5+
// EIGHT: "-msmall-data-limit" "8"

llvm/lib/Target/RISCV/RISCVTargetObjectFile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class RISCVELFTargetObjectFile : public TargetLoweringObjectFileELF {
2222
MCSection *SmallROData16Section;
2323
MCSection *SmallROData32Section;
2424
MCSection *SmallBSSSection;
25-
unsigned SSThreshold = 8;
25+
unsigned SSThreshold = 0;
2626

2727
public:
2828
unsigned getTextSectionAlignment() const override;

0 commit comments

Comments
 (0)