Treat constant sections as string sections
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
@@ -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
Quoted 7 lines · Frediano Ziglio
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.Signed-off-by Frediano Ziglio <[email protected]>
Thanks, Roger.
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">> From: Frediano Ziglio </div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">> Sent: 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);">> To: [email protected] </div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">> Cc: Frediano Ziglio ; Ross Lagerwall ; Konrad Rzeszutek Wilk ; Andrew Cooper ; Roger Pau Monne </div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">> Subject: [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);">> </div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">> 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);">> 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);">> 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);">> 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);">> 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);">> </div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">> Signed-off-by: Frediano Ziglio </div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">> ---</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">> 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);">> 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);">> </div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">> 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);">> 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);">> --- 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);">> +++ 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);">> @@ -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);">> {</div><div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">> #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);">> #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);">> +#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>
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 sectionsNewer 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_sectionis 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@@ -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_NAMEinstead?
It makes sense, I'll change it.
Quoted 2 lines
Ross
Frediano