Blob Blame History Raw
From 3112397f3b7b59f8e9089143965d889165c16d13 Mon Sep 17 00:00:00 2001
From: Josh Poimboeuf <jpoimboe@redhat.com>
Date: Mon, 6 Jun 2022 17:05:41 -0700
Subject: [PATCH] create-diff-object: Create missing section symbol

Recent toolchains only create a section symbol if it's needed, i.e. if
there's a reference to it.  If there's a missing section symbol in
kpatch_create_intermediate_sections(), create one instead of erroring
out.

Fixes #1272.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 kpatch-build/create-diff-object.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 319ed68d..420d55d8 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -3397,12 +3397,23 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
 
 			/* add rela to fill in krelas[index].dest field */
 			ALLOC_LINK(rela2, &krela_sec->rela->relas);
-			if (sec->base->secsym)
-				rela2->sym = sec->base->secsym;
-			else
-				ERROR("can't create dynrela for section %s (symbol %s): no bundled or section symbol",
-				      sec->name, rela->sym->name);
+			if (!sec->base->secsym) {
+				struct symbol *sym;
 
+				/*
+				 * Newer toolchains are stingy with their
+				 * section symbols, create one if it doesn't
+				 * exist already.
+				 */
+				ALLOC_LINK(sym, &kelf->symbols);
+				sym->sec = sec->base;
+				sym->sym.st_info = GELF_ST_INFO(STB_LOCAL, STT_SECTION);
+				sym->type = STT_SECTION;
+				sym->bind = STB_LOCAL;
+				sym->name = sec->base->name;
+				sec->base->secsym = sym;
+			}
+			rela2->sym = sec->base->secsym;
 			rela2->type = absolute_rela_type(kelf);
 			rela2->addend = rela->offset;
 			rela2->offset = (unsigned int)(index * sizeof(*krelas) + \