Skip to contentSkip to conversation

Treat constant sections as string sections

PATCH Superseded Frediano Ziglio 3 participants 4 messages Sep 18, 2025 – Oct 7, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Treat constant sections as string sections

Newer compiler can put some constant strings inside constant sections (.rodata.cstXX) instead of string sections (.rodata.str1.XX). This causes the produced live patch to not apply when such strings are produced.
So treat the constant sections as string ones.

---
 create-diff-object.c | 6 ++++++
 1 file changed, 6 insertions(+)
create-diff-object.c +6 -0
index 7e6138b..7acaf88 100644
@@ -1446,11 +1446,16 @@ static bool is_rodata_str_section(const char *name)
 {
 #define GCC_5_SECTION_NAME ".rodata.str1."
 #define GCC_6_SECTION_NAME ".str1."
+#define GCC_CSTR ".rodata.cst"
 	const char *s;
 
 	if (strncmp(name, ".rodata.", 8))
 		return false;
 
+	/* Check if name matches ".rodata.cst[0-9]+" */
+	if (!strncmp(name, GCC_CSTR, strlen(GCC_CSTR)))
+		return is_number(name + strlen(GCC_CSTR));
+
 	/* Check if name matches ".rodata.str1.[0-9]+" */
 	if (!strncmp(name, GCC_5_SECTION_NAME, strlen(GCC_5_SECTION_NAME)))
 		return is_number(name + strlen(GCC_5_SECTION_NAME));
@@ -1462,6 +1467,7 @@ static bool is_rodata_str_section(const char *name)
 	return is_number(s + strlen(GCC_6_SECTION_NAME));
 #undef GCC_5_SECTION_NAME
 #undef GCC_6_SECTION_NAME
+#undef GCC_CSTR
 }
 
 static void kpatch_include_standard_elements(struct kpatch_elf *kelf)
Signature · 1 line
2.51.0
#2 lore raw
In reply to Frediano Ziglio

<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; From:&nbsp;Frediano Ziglio&nbsp;</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; Sent:&nbsp;Thursday, September 18, 2025 10:51 AM</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; To:&nbsp;[email protected]&nbsp;</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; Cc:&nbsp;Frediano Ziglio ; Ross Lagerwall ; Konrad Rzeszutek Wilk ; Andrew Cooper ; Roger Pau Monne&nbsp;</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; Subject:&nbsp;[PATCH livepatch-build-tools] Treat constant sections as string sections</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; &nbsp;</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; Newer compiler can put some constant strings inside constant</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; sections (.rodata.cstXX) instead of string sections (.rodata.str1.XX).</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; This causes the produced live patch to not apply when such</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; strings are produced.</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; So treat the constant sections as string ones.</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><br></div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">Are you sure it was a string and not something else? As far as I can</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">tell GCC chooses the section in categorize_decl_for_section() which</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">doesn't appear to ever put constant strings in .rodata.cst.</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><br></div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">In any case if we have a reference to a constant in .rodata.cst then the</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">section _does_ need to be included in its entirety, though it makes me</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">wonder if is_rodata_str_section is the best place for this check.</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><br></div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt;&nbsp;</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; Signed-off-by: Frediano Ziglio&nbsp;</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; ---</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; &nbsp;create-diff-object.c | 6 ++++++</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; &nbsp;1 file changed, 6 insertions(+)</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt;&nbsp;</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; diff --git a/create-diff-object.c b/create-diff-object.c</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; index 7e6138b..7acaf88 100644</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; --- a/create-diff-object.c</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; +++ b/create-diff-object.c</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; @@ -1446,11 +1446,16 @@ static bool is_rodata_str_section(const char *name)</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><br></div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">Can you update the comment at the top of this function?</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><br></div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; &nbsp;{</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; &nbsp;#define GCC_5_SECTION_NAME ".rodata.str1."</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; &nbsp;#define GCC_6_SECTION_NAME ".str1."</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">&gt; +#define GCC_CSTR ".rodata.cst"</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><br></div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">What does CSTR stand for? May call it GCC_CONSTANT_SECTION_NAME instead?</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><br></div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">Ross</div>

#3 lore raw
Quoted 13 lines
Quoted 11 lines

From: Frediano Ziglio
Sent: Thursday, September 18, 2025 10:51 AM
To: xen-devel@xxxxxxxxxxxxxxxxxxxx
Cc: Frediano Ziglio ; Ross Lagerwall ; Konrad Rzeszutek Wilk ; Andrew Cooper ; Roger Pau Monne
Subject: [PATCH livepatch-build-tools] Treat constant sections as string sections

Newer compiler can put some constant strings inside constant sections (.rodata.cstXX) instead of string sections (.rodata.str1.XX). This causes the produced live patch to not apply when such strings are produced.
So treat the constant sections as string ones.

Quoted 4 lines

Are you sure it was a string and not something else? As far as I can tell GCC chooses the section in categorize_decl_for_section() which doesn't appear to ever put constant strings in .rodata.cst.

In the specific case it was a "h" string (used for continuation).

Quoted 12 lines

In any case if we have a reference to a constant in .rodata.cst then the section _does_ need to be included in its entirety, though it makes me wonder if is_rodata_str_section is the best place for this check.

Quoted 6 lines
Signed-off-by Frediano Ziglio
---
 create-diff-object.c | 6 ++++++
 1 file changed, 6 insertions(+)
Quoted 9 lines

create-diff-object.c static bool is_rodata_str_section(const char *name)

Quoted 5 lines
create-diff-object.c +0 -0
index 7e6138b..7acaf88 100644
@@ -1446,11 +1446,16 @@ static bool is_rodata_str_section(const char *name)

Can you update the comment at the top of this function?

I'll do it.

Quoted 9 lines

create-diff-object.c static bool is_rodata_str_section(const char *name) · line 1449

Quoted 5 lines
create-diff-object.c +1 -0
 {
 #define GCC_5_SECTION_NAME ".rodata.str1."
 #define GCC_6_SECTION_NAME ".str1."
+#define GCC_CSTR ".rodata.cst"

What does CSTR stand for? May call it GCC_CONSTANT_SECTION_NAME instead?

It makes sense, I'll change it.

Quoted 2 lines

Ross

Frediano