[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: https://github.com/llvm/llvm-project/pull/83093
This commit is contained in:
Fangrui Song 2024-08-19 18:20:02 -07:00 committed by GitHub
parent b5f3e28eca
commit d3864d946a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 12 additions and 54 deletions

View File

@ -604,9 +604,6 @@ def warn_drv_unsupported_gpopt : Warning<
"ignoring '-mgpopt' option as it cannot be used with %select{|the implicit"
" usage of }0-mabicalls">,
InGroup<UnsupportedGPOpt>;
def warn_drv_unsupported_sdata : Warning<
"ignoring '-msmall-data-limit=' with -mcmodel=large for -fpic or RV64">,
InGroup<OptionIgnored>;
def warn_drv_unsupported_longcalls : Warning<
"ignoring '-mlong-calls' option as it is not currently supported with "
"%select{|the implicit usage of }0-mabicalls">,

View File

@ -2126,42 +2126,6 @@ void Clang::AddPPCTargetArgs(const ArgList &Args,
}
}
static void SetRISCVSmallDataLimit(const ToolChain &TC, const ArgList &Args,
ArgStringList &CmdArgs) {
const Driver &D = TC.getDriver();
const llvm::Triple &Triple = TC.getTriple();
// Default small data limitation is eight.
const char *SmallDataLimit = "8";
// Get small data limitation.
if (Args.getLastArg(options::OPT_shared, options::OPT_fpic,
options::OPT_fPIC)) {
// Not support linker relaxation for PIC.
SmallDataLimit = "0";
if (Args.hasArg(options::OPT_G)) {
D.Diag(diag::warn_drv_unsupported_sdata);
}
} else if (Args.getLastArgValue(options::OPT_mcmodel_EQ)
.equals_insensitive("large") &&
(Triple.getArch() == llvm::Triple::riscv64)) {
// Not support linker relaxation for RV64 with large code model.
SmallDataLimit = "0";
if (Args.hasArg(options::OPT_G)) {
D.Diag(diag::warn_drv_unsupported_sdata);
}
} else if (Triple.isAndroid()) {
// GP relaxation is not supported on Android.
SmallDataLimit = "0";
if (Args.hasArg(options::OPT_G)) {
D.Diag(diag::warn_drv_unsupported_sdata);
}
} else if (Arg *A = Args.getLastArg(options::OPT_G)) {
SmallDataLimit = A->getValue();
}
// Forward the -msmall-data-limit= option.
CmdArgs.push_back("-msmall-data-limit");
CmdArgs.push_back(SmallDataLimit);
}
void Clang::AddRISCVTargetArgs(const ArgList &Args,
ArgStringList &CmdArgs) const {
const llvm::Triple &Triple = getToolChain().getTriple();
@ -2170,7 +2134,10 @@ void Clang::AddRISCVTargetArgs(const ArgList &Args,
CmdArgs.push_back("-target-abi");
CmdArgs.push_back(ABIName.data());
SetRISCVSmallDataLimit(getToolChain(), Args, CmdArgs);
if (Arg *A = Args.getLastArg(options::OPT_G)) {
CmdArgs.push_back("-msmall-data-limit");
CmdArgs.push_back(A->getValue());
}
if (!Args.hasFlag(options::OPT_mimplicit_float,
options::OPT_mno_implicit_float, true))

View File

@ -21,23 +21,19 @@
// RUN: | FileCheck %s -check-prefix=RV64-S2G4
// RUN: %clang --target=riscv64-unknown-elf %s -S -emit-llvm -msmall-data-threshold=16 -o - \
// RUN: | FileCheck %s -check-prefix=RV64-T16
// RUN: %clang --target=riscv64-linux-android %s -S -emit-llvm -o - \
// RUN: | FileCheck %s -check-prefix=RV64-ANDROID
// RUN: %clang --target=riscv64-linux-android %s -S -emit-llvm -msmall-data-limit=8 -o - \
// RUN: | FileCheck %s -check-prefix=RV64-ANDROID
// RUN: %clang --target=riscv64-unknown-elf %s -S -emit-llvm -fpic -o - \
// RUN: | FileCheck %s -check-prefix=RV64-PIC
void test(void) {}
// RV32-DEFAULT: !{i32 8, !"SmallDataLimit", i32 8}
// RV32-DEFAULT: !{i32 8, !"SmallDataLimit", i32 0}
// RV32-G4: !{i32 8, !"SmallDataLimit", i32 4}
// RV32-S0: !{i32 8, !"SmallDataLimit", i32 0}
// RV32-S2G4: !{i32 8, !"SmallDataLimit", i32 4}
// RV32-T16: !{i32 8, !"SmallDataLimit", i32 16}
// RV32-PIC: !{i32 8, !"SmallDataLimit", i32 0}
// RV64-DEFAULT: !{i32 8, !"SmallDataLimit", i32 8}
// RV64-DEFAULT: !{i32 8, !"SmallDataLimit", i32 0}
// RV64-G4: !{i32 8, !"SmallDataLimit", i32 4}
// RV64-S0: !{i32 8, !"SmallDataLimit", i32 0}
// RV64-S2G4: !{i32 8, !"SmallDataLimit", i32 4}
@ -48,6 +44,3 @@ void test(void) {}
// The value will be passed by module flag instead of target feature.
// RV32-S0-NOT: +small-data-limit=
// RV64-S0-NOT: +small-data-limit=
// RV64-ANDROID-NOT: small-data-limit
// RV64-ANDROID: !{i32 8, !"SmallDataLimit", i32 0}

View File

@ -1,4 +0,0 @@
// REQUIRES: riscv-registered-target
// RUN: %clang -S --target=riscv32-unknown-elf -fpic -msmall-data-limit=8 %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-PIC-SDATA %s
// CHECK-PIC-SDATA: warning: ignoring '-msmall-data-limit=' with -mcmodel=large for -fpic or RV64

View File

@ -0,0 +1,5 @@
// RUN: %clang -### -S --target=riscv64 %s 2>&1 | FileCheck %s
// RUN: %clang -### -S --target=riscv64 -msmall-data-limit=8 %s 2>&1 | FileCheck %s --check-prefix=EIGHT
// CHECK-NOT: "-msmall-data-limit"
// EIGHT: "-msmall-data-limit" "8"

View File

@ -22,7 +22,7 @@ class RISCVELFTargetObjectFile : public TargetLoweringObjectFileELF {
MCSection *SmallROData16Section;
MCSection *SmallROData32Section;
MCSection *SmallBSSSection;
unsigned SSThreshold = 8;
unsigned SSThreshold = 0;
public:
unsigned getTextSectionAlignment() const override;