[PATCH] D152279: [Driver] Default -msmall-data-limit= to 0

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 6 08:35:25 PDT 2023


MaskRay created this revision.
MaskRay added reviewers: apazos, asb, craig.topper, hiraditya, jrtc27, shiva0217.
Herald added subscribers: luke, frasercrmck, luismarques, sameer.abuasal, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, niosHD, sabuasal, simoncook, johnrusso, rbar.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead.
Herald added a project: clang.

D57497 <https://reviews.llvm.org/D57497> added -msmall-data-limit= as an alias for -G and defaulted it to 8 for
-fno-pic/-fpie.

GCC documents this option as "Put global and static data smaller than <number> bytes into a special section (on some targets)."
The targets are not documented, but it seems to not use the value for -fpie.

I think the different behavior for -fno-pic/-fpie/-fpic is not a good
idea and defaulting to -msmall-data-limit=0 makes more sense.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152279

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/RISCV/riscv-sdata-module-flag.c


Index: clang/test/CodeGen/RISCV/riscv-sdata-module-flag.c
===================================================================
--- clang/test/CodeGen/RISCV/riscv-sdata-module-flag.c
+++ clang/test/CodeGen/RISCV/riscv-sdata-module-flag.c
@@ -28,14 +28,14 @@
 
 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}
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2079,12 +2079,11 @@
   const Driver &D = TC.getDriver();
   const llvm::Triple &Triple = TC.getTriple();
   // Default small data limitation is eight.
-  const char *SmallDataLimit = "8";
+  const char *SmallDataLimit = "0";
   // 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);
     }
@@ -2092,7 +2091,6 @@
                  .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);
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152279.528884.patch
Type: text/x-patch
Size: 1982 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230606/add82d0b/attachment.bin>


More information about the cfe-commits mailing list