Blame SOURCES/v0.9.2-backport-MR-1200-Make-sure-section-symbols-ex.patch

cbf2d8
From c1a07a5329c0b7db0ec54eea093e5d2d77735c06 Mon Sep 17 00:00:00 2001
cbf2d8
From: Joe Lawrence <joe.lawrence@redhat.com>
cbf2d8
Date: Fri, 9 Dec 2022 15:37:49 -0500
cbf2d8
Subject: [PATCH] v0.9.2 backport: MR!1200 ("Make sure section symbols exist")
cbf2d8
Content-type: text/plain
cbf2d8
cbf2d8
commit 5622e3cc3d393fd77866b9838d16cd064de6fba5
cbf2d8
Author: Artem Savkov <asavkov@redhat.com>
cbf2d8
Date:   Fri Jun 18 10:59:26 2021 +0200
cbf2d8
cbf2d8
    Make sure section symbols exist
cbf2d8
cbf2d8
    Binutils recently became much more aggressive about removing unused
cbf2d8
    section symbols. Since we can not rely on those being available anymore
cbf2d8
    add additional checks before using them.
cbf2d8
cbf2d8
    Fixes: #1193
cbf2d8
cbf2d8
    Signed-off-by: Artem Savkov <asavkov@redhat.com>
cbf2d8
cbf2d8
Fixes: KLP-216 ("Backport kpatch-build section symbol check")
cbf2d8
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
cbf2d8
---
cbf2d8
 kpatch-build/create-diff-object.c | 15 ++++++++++-----
cbf2d8
 1 file changed, 10 insertions(+), 5 deletions(-)
cbf2d8
cbf2d8
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
cbf2d8
index c9afe33bbdae..94879b5fce6a 100644
cbf2d8
--- a/kpatch-build/create-diff-object.c
cbf2d8
+++ b/kpatch-build/create-diff-object.c
cbf2d8
@@ -1241,7 +1241,8 @@ static void kpatch_correlate_static_local_variables(struct kpatch_elf *base,
cbf2d8
 		if (bundled && sym->sec->twin) {
cbf2d8
 			UNCORRELATE_ELEMENT(sym->sec);
cbf2d8
 
cbf2d8
-			UNCORRELATE_ELEMENT(sym->sec->secsym);
cbf2d8
+			if (sym->sec->secsym)
cbf2d8
+				UNCORRELATE_ELEMENT(sym->sec->secsym);
cbf2d8
 
cbf2d8
 			if (sym->sec->rela)
cbf2d8
 				UNCORRELATE_ELEMENT(sym->sec->rela);
cbf2d8
@@ -1744,7 +1745,7 @@ static int kpatch_include_callback_elements(struct kpatch_elf *kelf)
cbf2d8
 			sym = rela->sym;
cbf2d8
 			log_normal("found callback: %s\n",sym->name);
cbf2d8
 			kpatch_include_symbol(sym);
cbf2d8
-		} else {
cbf2d8
+		} else if (sec->secsym) {
cbf2d8
 			sec->secsym->include = 1;
cbf2d8
 		}
cbf2d8
 	}
cbf2d8
@@ -1772,7 +1773,8 @@ static void kpatch_include_force_elements(struct kpatch_elf *kelf)
cbf2d8
 			sec->include = 1;
cbf2d8
 			if (!is_rela_section(sec)) {
cbf2d8
 				/* .kpatch.force */
cbf2d8
-				sec->secsym->include = 1;
cbf2d8
+				if (sec->secsym)
cbf2d8
+					sec->secsym->include = 1;
cbf2d8
 				continue;
cbf2d8
 			}
cbf2d8
 			/* .rela.kpatch.force */
cbf2d8
@@ -2381,7 +2383,8 @@ static void kpatch_regenerate_special_section(struct kpatch_elf *kelf,
cbf2d8
 	sec->include = 1;
cbf2d8
 	sec->base->include = 1;
cbf2d8
 	/* include secsym so .kpatch.arch relas can point to section symbols */
cbf2d8
-	sec->base->secsym->include = 1;
cbf2d8
+	if (sec->base->secsym)
cbf2d8
+		sec->base->secsym->include = 1;
cbf2d8
 
cbf2d8
 	/*
cbf2d8
 	 * Update text section data buf and size.
cbf2d8
@@ -2564,7 +2567,9 @@ static void kpatch_mark_ignored_sections(struct kpatch_elf *kelf)
cbf2d8
 		 * from the section data comparison, but this is a simpler way.
cbf2d8
 		 */
cbf2d8
 		strsec->include = 1;
cbf2d8
-		strsec->secsym->include = 1;
cbf2d8
+		if (strsec->secsym)
cbf2d8
+			strsec->secsym->include = 1;
cbf2d8
+
cbf2d8
 		name = strsec->data->d_buf + rela->addend;
cbf2d8
 		ignoresec = find_section_by_name(&kelf->sections, name);
cbf2d8
 		if (!ignoresec)
cbf2d8
-- 
cbf2d8
2.38.1
cbf2d8