thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-dump-Write-ELF-section-headers-right-after-ELF-heade.patch

bf143f
From 987ede93fa4e3d058acddc19874e467faa116ede Mon Sep 17 00:00:00 2001
bf143f
From: Janosch Frank <frankja@linux.ibm.com>
bf143f
Date: Mon, 17 Oct 2022 08:38:14 +0000
bf143f
Subject: [PATCH 33/42] dump: Write ELF section headers right after ELF header
bf143f
MIME-Version: 1.0
bf143f
Content-Type: text/plain; charset=UTF-8
bf143f
Content-Transfer-Encoding: 8bit
bf143f
bf143f
RH-Author: Cédric Le Goater <clg@redhat.com>
bf143f
RH-MergeRequest: 226: s390: Enhanced Interpretation for PCI Functions and Secure Execution guest dump
bf143f
RH-Bugzilla: 1664378 2043909
bf143f
RH-Acked-by: Thomas Huth <thuth@redhat.com>
bf143f
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
bf143f
RH-Acked-by: Jon Maloy <jmaloy@redhat.com>
bf143f
RH-Commit: [33/41] e956040753533ac376e9763145192de1e216027d
bf143f
bf143f
Let's start bundling the writes of the headers and of the data so we
bf143f
have a clear ordering between them. Since the ELF header uses offsets
bf143f
to the headers we can freely order them.
bf143f
bf143f
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
bf143f
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
bf143f
Message-Id: <20221017083822.43118-3-frankja@linux.ibm.com>
bf143f
(cherry picked from commit cb415fd61e48d52f81dcf38956e3f913651cff1c)
bf143f
Signed-off-by: Cédric Le Goater <clg@redhat.com>
bf143f
---
bf143f
 dump/dump.c | 31 ++++++++++++++-----------------
bf143f
 1 file changed, 14 insertions(+), 17 deletions(-)
bf143f
bf143f
diff --git a/dump/dump.c b/dump/dump.c
bf143f
index 4142b4cc0c..d17537d4e9 100644
bf143f
--- a/dump/dump.c
bf143f
+++ b/dump/dump.c
bf143f
@@ -584,6 +584,8 @@ static void dump_begin(DumpState *s, Error **errp)
bf143f
      *   --------------
bf143f
      *   |  elf header |
bf143f
      *   --------------
bf143f
+     *   |  sctn_hdr   |
bf143f
+     *   --------------
bf143f
      *   |  PT_NOTE    |
bf143f
      *   --------------
bf143f
      *   |  PT_LOAD    |
bf143f
@@ -592,8 +594,6 @@ static void dump_begin(DumpState *s, Error **errp)
bf143f
      *   --------------
bf143f
      *   |  PT_LOAD    |
bf143f
      *   --------------
bf143f
-     *   |  sec_hdr    |
bf143f
-     *   --------------
bf143f
      *   |  elf note   |
bf143f
      *   --------------
bf143f
      *   |  memory     |
bf143f
@@ -609,20 +609,20 @@ static void dump_begin(DumpState *s, Error **errp)
bf143f
         return;
bf143f
     }
bf143f
 
bf143f
-    /* write PT_NOTE to vmcore */
bf143f
-    write_elf_phdr_note(s, errp);
bf143f
+    /* write section headers to vmcore */
bf143f
+    write_elf_section_headers(s, errp);
bf143f
     if (*errp) {
bf143f
         return;
bf143f
     }
bf143f
 
bf143f
-    /* write all PT_LOADs to vmcore */
bf143f
-    write_elf_phdr_loads(s, errp);
bf143f
+    /* write PT_NOTE to vmcore */
bf143f
+    write_elf_phdr_note(s, errp);
bf143f
     if (*errp) {
bf143f
         return;
bf143f
     }
bf143f
 
bf143f
-    /* write section headers to vmcore */
bf143f
-    write_elf_section_headers(s, errp);
bf143f
+    /* write all PT_LOADs to vmcore */
bf143f
+    write_elf_phdr_loads(s, errp);
bf143f
     if (*errp) {
bf143f
         return;
bf143f
     }
bf143f
@@ -1877,16 +1877,13 @@ static void dump_init(DumpState *s, int fd, bool has_format,
bf143f
     }
bf143f
 
bf143f
     if (dump_is_64bit(s)) {
bf143f
-        s->phdr_offset = sizeof(Elf64_Ehdr);
bf143f
-        s->shdr_offset = s->phdr_offset + sizeof(Elf64_Phdr) * s->phdr_num;
bf143f
-        s->note_offset = s->shdr_offset + sizeof(Elf64_Shdr) * s->shdr_num;
bf143f
-        s->memory_offset = s->note_offset + s->note_size;
bf143f
+        s->shdr_offset = sizeof(Elf64_Ehdr);
bf143f
+        s->phdr_offset = s->shdr_offset + sizeof(Elf64_Shdr) * s->shdr_num;
bf143f
+        s->note_offset = s->phdr_offset + sizeof(Elf64_Phdr) * s->phdr_num;
bf143f
     } else {
bf143f
-
bf143f
-        s->phdr_offset = sizeof(Elf32_Ehdr);
bf143f
-        s->shdr_offset = s->phdr_offset + sizeof(Elf32_Phdr) * s->phdr_num;
bf143f
-        s->note_offset = s->shdr_offset + sizeof(Elf32_Shdr) * s->shdr_num;
bf143f
-        s->memory_offset = s->note_offset + s->note_size;
bf143f
+        s->shdr_offset = sizeof(Elf32_Ehdr);
bf143f
+        s->phdr_offset = s->shdr_offset + sizeof(Elf32_Shdr) * s->shdr_num;
bf143f
+        s->note_offset = s->phdr_offset + sizeof(Elf32_Phdr) * s->phdr_num;
bf143f
     }
bf143f
 
bf143f
     return;
bf143f
-- 
bf143f
2.37.3
bf143f