[lld] f97adea - ELF: Simplify isRelRoDataSection and rename the text file

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 23 09:34:12 PDT 2025


Author: Fangrui Song
Date: 2025-07-23T09:34:07-07:00
New Revision: f97adea477069e57422a2446162fe41feb4e1277

URL: https://github.com/llvm/llvm-project/commit/f97adea477069e57422a2446162fe41feb4e1277
DIFF: https://github.com/llvm/llvm-project/commit/f97adea477069e57422a2446162fe41feb4e1277.diff

LOG: ELF: Simplify isRelRoDataSection and rename the text file

PR #148920 was merged before I could share my comments.

* Fix the text filename. There are other minor suggestions, but can be
  done in #148985
* Make `isRelRoDataSection` concise, to be consistent with the majority of
  helper functions.

Added: 
    lld/test/ELF/keep-data-section-prefix.s

Modified: 
    lld/ELF/Writer.cpp

Removed: 
    lld/test/ELF/keep-text-section-prefix.s


################################################################################
diff  --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index e7cebab7974cd..c3c057812a685 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -553,24 +553,16 @@ template <class ELFT> void Writer<ELFT>::addSectionSymbols() {
   }
 }
 
-// Returns true if the section is a data section that's read only and
-// relocatable per its section name.
+// Returns true if this is a variant of .data.rel.ro.
 static bool isRelRoDataSection(Ctx &ctx, StringRef secName) {
-  // The section name should start with ".data.rel.ro".
   if (!secName.consume_front(".data.rel.ro"))
     return false;
-
-  // If the section name is .data.rel.ro, it is a relocatable read-only data
-  // section.
   if (secName.empty())
     return true;
-  //  If  -z keep-data-section-prefix is given, '.data.rel.ro.hot' and
-  //  '.data.rel.ro.unlikely' are considered a split of '.data.rel.ro' based on
-  //  hotness.
-  if (ctx.arg.zKeepDataSectionPrefix) {
+  // If -z keep-data-section-prefix is specified, additionally allow
+  // '.data.rel.ro.hot' and '.data.rel.ro.unlikely'.
+  if (ctx.arg.zKeepDataSectionPrefix)
     return secName == ".hot" || secName == ".unlikely";
-  }
-
   return false;
 }
 

diff  --git a/lld/test/ELF/keep-text-section-prefix.s b/lld/test/ELF/keep-data-section-prefix.s
similarity index 97%
rename from lld/test/ELF/keep-text-section-prefix.s
rename to lld/test/ELF/keep-data-section-prefix.s
index 7b6cc17c423c7..4b08f53620ea4 100644
--- a/lld/test/ELF/keep-text-section-prefix.s
+++ b/lld/test/ELF/keep-data-section-prefix.s
@@ -32,7 +32,7 @@
 ##   .data.rel.ro.split -> .data.rel.ro
 ##   .data.rel.ro -> .data.rel.ro
 ##   .data.rel.ro.hot -> .data.rel.ro.hot
-##   .data.rel.ro.unlikely -> .data.rel.ro.unlikely 
+##   .data.rel.ro.unlikely -> .data.rel.ro.unlikely
 # LS:      .text
 # LS-NEXT: .data.rel.ro.hot .data.rel.ro .data.rel.ro.unlikely .relro_padding
 # LS-NEXT: .data .bss
@@ -61,7 +61,7 @@
 SECTIONS {
   .data.rel.ro.hot : { *(.data.rel.ro.hot) }
   .data.rel.ro : { .data.rel.ro }
-  .data.rel.ro.unlikely : { *(.data.rel.ro.unlikely) } 
+  .data.rel.ro.unlikely : { *(.data.rel.ro.unlikely) }
 } INSERT AFTER .text
 
 


        


More information about the llvm-commits mailing list