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

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

diff --git a/create-diff-object.c b/create-diff-object.c
index 7e6138b..8104017 100644
--- a/create-diff-object.c
+++ b/create-diff-object.c
@@ -1441,16 +1441,24 @@ static bool is_number(const char *s)
  * or .rodata.str1.[0-9]+ (older versions of GCC)
  * For the new format we only include the needed strings sections.
  * For the old format all string sections are always included.
+ * We also treat constant sections .rodata.cst[0-9]+ as string
+ * sections as newer compilers put some strings on them.
  */
 static bool is_rodata_str_section(const char *name)
 {
 #define GCC_5_SECTION_NAME ".rodata.str1."
 #define GCC_6_SECTION_NAME ".str1."
+#define GCC_CONSTANT_SECTION_NAME ".rodata.cst"
 	const char *s;
 
 	if (strncmp(name, ".rodata.", 8))
 		return false;
 
+	/* Check if name matches ".rodata.cst[0-9]+" */
+	if (!strncmp(name, GCC_CONSTANT_SECTION_NAME,
+		     strlen(GCC_CONSTANT_SECTION_NAME)))
+		return is_number(name + strlen(GCC_CONSTANT_SECTION_NAME));
+
 	/* 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 +1470,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_CONSTANT_SECTION_NAME
 }
 
 static void kpatch_include_standard_elements(struct kpatch_elf *kelf)
-- 
2.51.0
Re: [PATCH livepatch-build-tools v2] Treat constant sections as string sections
Posted by Ross Lagerwall 3 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>

Reviewed-by: Ross Lagerwall <ross.lagerwall@citrix.com>

Thanks,
Ross