https://sourceware.org/bugzilla/show_bug.cgi?id=34468

Jaeger Hofer <antiq.hofer at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |antiq.hofer at gmail dot com

--- Comment #3 from Jaeger Hofer <antiq.hofer at gmail dot com> ---
I believe we could have a workaround / temporary fix like this >

what I tested out: imho we could indeed use the mmap writer here, because the
read/write one corrupts the bytes before an edited section, as Brandon pointed
out.

but additionally in the second change we can elf_flagshdr the section 0 dirty
in a separate call since the loop's iterator skips it; and then in the third
take we can elf_flagshdr every section header as dirty in the loop so the moved
header table is written onto it in full. I did this in order to make the mmap
writer copy every header to the new e_shoff so that no slot in the relocated
table is left with leftover file contents.


--- a/tools/debugedit.c
+++ b/tools/debugedit.c
@@ -3580,7 +3580,7 @@
   if (dest_dir == NULL && (!do_build_id || no_recompute_build_id))
     elf = elf_begin (fd, ELF_C_READ, NULL);
   else
-    elf = elf_begin (fd, ELF_C_RDWR, NULL);
+    elf = elf_begin (fd, ELF_C_RDWR_MMAP, NULL);
   if (elf == NULL)
     {
       error (0, 0, "cannot open ELF file: %s", elf_errmsg (-1));
@@ -4079,6 +4079,11 @@
        }

       /* Now adjust any sizes and offsets for the unallocated sections. */
+      {
+       Elf_Scn *zscn = elf_getscn (elf, 0);
+       if (zscn != NULL)
+         elf_flagshdr (zscn, ELF_C_SET, ELF_F_DIRTY);
+      }
       scn = NULL;
       while ((scn = elf_nextscn (elf, scn)) != NULL)
        {
@@ -4087,6 +4092,8 @@
          if (shdr == NULL)
            error (1, 0, "Couldn't get shdr: %s", elf_errmsg (-1));

+         elf_flagshdr (scn, ELF_C_SET, ELF_F_DIRTY);
+
          /* A bug in elfutils before 0.169 means we have to write out
             all section data, even when nothing changed.
             https://sourceware.org/bugzilla/show_bug.cgi?id=21199 */



all 58 tests turn out ok now, for the moment I have not seen any negative
effects; I know it doesn't cover libelf issue entirely, but at least there's
nothing else breaking hopefully and treats the header table relocation issue.
also no longer any truncation of files on gentoo either. ( apologies for short
dyslexia )

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Reply via email to