[coreboot-gerrit] New patch to review for coreboot: elfwriter: Fix multi-phdrs ELFs parsing

Antonello Dettori (dev@dettori.io) gerrit at coreboot.org
Thu Jun 16 13:50:24 CEST 2016


Antonello Dettori (dev at dettori.io) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/15215

-gerrit

commit 7d7169ba959cc9b042f1be0ce9e884a0e33ad99f
Author: Antonello Dettori <dettori.an at gmail.com>
Date:   Thu Jun 16 13:40:24 2016 +0200

    elfwriter: Fix multi-phdrs ELFs parsing
    
    Allow to write multiple phdrs, one for each non-consecutive section
    of the ELF.
    Previously it only worked for ELFs contaning a single
    program header.
    
    Change-Id: If6f95e999373a0cab4414b811e8ced4c93c67c30
    Signed-off-by: Antonello Dettori <dev at dettori.io>
---
 util/cbfstool/elfheaders.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/util/cbfstool/elfheaders.c b/util/cbfstool/elfheaders.c
index e068d38..8dd4bde 100644
--- a/util/cbfstool/elfheaders.c
+++ b/util/cbfstool/elfheaders.c
@@ -969,7 +969,6 @@ static void write_phdrs(struct elf_writer *ew, struct buffer *phdrs)
 			/* Write out previously set phdr. */
 			if (num_written != 0) {
 				phdr_write(ew, phdrs, &phdr);
-				num_written++;
 			}
 			phdr.p_type = PT_LOAD;
 			phdr.p_offset = sec->shdr.sh_offset;
@@ -983,6 +982,13 @@ static void write_phdrs(struct elf_writer *ew, struct buffer *phdrs)
 			if (sec->shdr.sh_flags & SHF_WRITE)
 				phdr.p_flags |= PF_W;
 			phdr.p_align = sec->shdr.sh_addralign;
+
+			/* Avoid incrementing num_written during the
+			 * last iteration and therefore skip the last
+			 * phdr_write because e_phnum == num_written. */
+			if (num_written+1 < ew->ehdr.e_phnum)
+				num_written++;
+
 		} else {
 			/* Accumulate file size and memsize. The assumption
 			 * is that each section is either NOBITS or full



More information about the coreboot-gerrit mailing list