summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorAntonello Dettori <dettori.an@gmail.com>2016-06-16 13:40:24 +0200
committerAaron Durbin <adurbin@chromium.org>2016-06-17 20:04:27 +0200
commit3bded7db7e925e177570d95dfc7b5cb08118b101 (patch)
treeb112d8e702a207ba8c71821386c99964c558dbbd /util
parentd72cc4111b81497356b0cb5d4c305ae9e460a9b5 (diff)
downloadcoreboot-3bded7db7e925e177570d95dfc7b5cb08118b101.tar.xz
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@dettori.io> Reviewed-on: https://review.coreboot.org/15215 Reviewed-by: Aaron Durbin <adurbin@chromium.org> Tested-by: build bot (Jenkins) Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Diffstat (limited to 'util')
-rw-r--r--util/cbfstool/elfheaders.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/util/cbfstool/elfheaders.c b/util/cbfstool/elfheaders.c
index e068d38144..8942eea03c 100644
--- a/util/cbfstool/elfheaders.c
+++ b/util/cbfstool/elfheaders.c
@@ -958,6 +958,7 @@ static void write_phdrs(struct elf_writer *ew, struct buffer *phdrs)
Elf64_Half i;
Elf64_Phdr phdr;
size_t num_written = 0;
+ size_t num_needs_write = 0;
for (i = 0; i < ew->num_secs; i++) {
struct elf_writer_section *sec = &ew->sections[i];
@@ -967,7 +968,7 @@ static void write_phdrs(struct elf_writer *ew, struct buffer *phdrs)
if (!section_consecutive(ew, i)) {
/* Write out previously set phdr. */
- if (num_written != 0) {
+ if (num_needs_write != num_written) {
phdr_write(ew, phdrs, &phdr);
num_written++;
}
@@ -983,6 +984,8 @@ 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;
+ num_needs_write++;
+
} else {
/* Accumulate file size and memsize. The assumption
* is that each section is either NOBITS or full
@@ -998,8 +1001,11 @@ static void write_phdrs(struct elf_writer *ew, struct buffer *phdrs)
}
/* Write out the last phdr. */
- if (num_written != ew->ehdr.e_phnum)
+ if (num_needs_write != num_written) {
phdr_write(ew, phdrs, &phdr);
+ num_written++;
+ }
+ assert(num_written == ew->ehdr.e_phnum);
}
static void fixup_symbol_table(struct elf_writer *ew)