[llvm] [RISCV] Let -data-sections also work on sbss/sdata sections (PR #87040)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 22 00:22:38 PDT 2024


================
@@ -104,10 +104,34 @@ bool RISCVELFTargetObjectFile::isGlobalInSmallSection(
 MCSection *RISCVELFTargetObjectFile::SelectSectionForGlobal(
     const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
   // Handle Small Section classification here.
-  if (Kind.isBSS() && isGlobalInSmallSection(GO, TM))
-    return SmallBSSSection;
-  if (Kind.isData() && isGlobalInSmallSection(GO, TM))
-    return SmallDataSection;
+  if (isGlobalInSmallSection(GO, TM)) {
+    // Emit to an unique sdata/sbss section when -fdata-section is set.
+    // However, if a symbol has an explicit sdata/sbss section, place it in that
+    // section.
+    bool EmitUniquedSection = TM.getDataSections() && !GO->hasSection();
----------------
KaiYG wrote:

I think `isGlobalInSmallSection` always return `false` unless the explicit section is a `.sdata` or `.sbss`, so I meant to let symbols with `__attribute__((section(".sdata")))`/`__attribute__((section(".sbss")))` neglect -fdata-sections and directly use `SmallDataSection`/`SmallBSSSection`.
Please correct me if I misunderstand, thanks.


https://github.com/llvm/llvm-project/pull/87040


More information about the llvm-commits mailing list