[PATCH livepatch-build-tools] Treat constant sections as string sections

Frediano Ziglio posted 1 patch 2 weeks, 2 days ago
Failed in applying to current master (apply log)
create-diff-object.c | 6 ++++++
1 file changed, 6 insertions(+)
[PATCH livepatch-build-tools] Treat constant sections as string sections
Posted by Frediano Ziglio 2 weeks, 2 days ago
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 <frediano.ziglio@citrix.com>
---
 create-diff-object.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/create-diff-object.c b/create-diff-object.c
index 7e6138b..7acaf88 100644
--- a/create-diff-object.c
+++ b/create-diff-object.c
@@ -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)
-- 
2.51.0
Re: [PATCH livepatch-build-tools] Treat constant sections as string sections
Posted by Roger Pau Monné 1 day, 10 hours ago
On Thu, Sep 18, 2025 at 10:51:58AM +0100, Frediano Ziglio wrote:
> 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 <frediano.ziglio@citrix.com>

Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>

Thanks, Roger.