Skip to content

Commit f97adea

Browse files
committed
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.
1 parent 90944b8 commit f97adea

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

lld/ELF/Writer.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -553,24 +553,16 @@ template <class ELFT> void Writer<ELFT>::addSectionSymbols() {
553553
}
554554
}
555555

556-
// Returns true if the section is a data section that's read only and
557-
// relocatable per its section name.
556+
// Returns true if this is a variant of .data.rel.ro.
558557
static bool isRelRoDataSection(Ctx &ctx, StringRef secName) {
559-
// The section name should start with ".data.rel.ro".
560558
if (!secName.consume_front(".data.rel.ro"))
561559
return false;
562-
563-
// If the section name is .data.rel.ro, it is a relocatable read-only data
564-
// section.
565560
if (secName.empty())
566561
return true;
567-
// If -z keep-data-section-prefix is given, '.data.rel.ro.hot' and
568-
// '.data.rel.ro.unlikely' are considered a split of '.data.rel.ro' based on
569-
// hotness.
570-
if (ctx.arg.zKeepDataSectionPrefix) {
562+
// If -z keep-data-section-prefix is specified, additionally allow
563+
// '.data.rel.ro.hot' and '.data.rel.ro.unlikely'.
564+
if (ctx.arg.zKeepDataSectionPrefix)
571565
return secName == ".hot" || secName == ".unlikely";
572-
}
573-
574566
return false;
575567
}
576568

lld/test/ELF/keep-text-section-prefix.s renamed to lld/test/ELF/keep-data-section-prefix.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
## .data.rel.ro.split -> .data.rel.ro
3333
## .data.rel.ro -> .data.rel.ro
3434
## .data.rel.ro.hot -> .data.rel.ro.hot
35-
## .data.rel.ro.unlikely -> .data.rel.ro.unlikely
35+
## .data.rel.ro.unlikely -> .data.rel.ro.unlikely
3636
# LS: .text
3737
# LS-NEXT: .data.rel.ro.hot .data.rel.ro .data.rel.ro.unlikely .relro_padding
3838
# LS-NEXT: .data .bss
@@ -61,7 +61,7 @@
6161
SECTIONS {
6262
.data.rel.ro.hot : { *(.data.rel.ro.hot) }
6363
.data.rel.ro : { .data.rel.ro }
64-
.data.rel.ro.unlikely : { *(.data.rel.ro.unlikely) }
64+
.data.rel.ro.unlikely : { *(.data.rel.ro.unlikely) }
6565
} INSERT AFTER .text
6666

6767

0 commit comments

Comments
 (0)