[lld] [lld][ELF] Allow `.data.rel.ro.unlikely` to be RELRO (PR #148920)

Mingming Liu via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 21 09:04:08 PDT 2025


================
@@ -629,9 +629,9 @@ static bool isRelroSection(Ctx &ctx, const OutputSection *sec) {
   // magic section names.
   StringRef s = sec->name;
 
-  bool abiAgnostic = s == ".data.rel.ro" || s == ".bss.rel.ro" ||
-                     s == ".ctors" || s == ".dtors" || s == ".jcr" ||
----------------
mingmingl-llvm wrote:

Thanks for the summary! They capture the different use cases pretty well.

> These same 3 usecases should apply equivalently for .rodata and .data (and suffixed versions of those), which can use the same flag you've added here. Maybe that work is in a separate patch?
> It's not entirely clear to me in the code how to achieve this, but I'm surprised that your handling of the option is in this function rather than in LinkerScript::getOutputSectionName, like we do for .text - but I also understand that .data.rel.ro needs a bit more processing than .text for assigning into segments.

It's correct that `LinkerScript::getOutputSectionName` should be the place to implement section mapping if linker script is not adopted (e.g., for use case 2).

To clarify a little bit, this change aims to support placing `.data.rel.ro.unlikely` after `.data.rel.ro` section but doesn't implement the data section mapping. Before this change, lld will fail with error  `section: .relro_padding is not contiguous with other relro sections` when `.data.rel.ro.unlikely` is placed after `.data.rel.ro` section, and lld/test/ELF/keep-text-section-prefix.s L19-20 has a test case.

I revived a commit as https://github.com/llvm/llvm-project/pull/148985 to implement the section mapping, and I plan to send it out as a separate change after adding a regression test.

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


More information about the llvm-commits mailing list