summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
86d5119)
Skip sections with size 0, or which are of type SHT_NOBITS or which
don't have the SHF_ALLOC flag set.
This avoids crashing on sections which don't have any data to copy.
Signed-off-by: Keith Packard <keithp@keithp.com>
#include <getopt.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <stdlib.h>
#include <string.h>
#include "ao-hex.h"
#include "ao-elf.h"
#include "ao-verbose.h"
#include "ao-hex.h"
#include "ao-elf.h"
#include "ao-verbose.h"
/*
* Construct a large in-memory block for all
* of the loaded sections of the program
/*
* Construct a large in-memory block for all
* of the loaded sections of the program
GElf_Phdr phdr;
GElf_Addr sh_paddr;
struct ao_hex_image *load = NULL;
GElf_Phdr phdr;
GElf_Addr sh_paddr;
struct ao_hex_image *load = NULL;
char *section_name;
#endif
size_t nshdr;
char *section_name;
#endif
size_t nshdr;
/* Get the associated file section */
/* Get the associated file section */
fprintf (stderr, "offset %08x vaddr %08x paddr %08x filesz %08x memsz %08x\n",
(uint32_t) phdr.p_offset,
(uint32_t) phdr.p_vaddr,
fprintf (stderr, "offset %08x vaddr %08x paddr %08x filesz %08x memsz %08x\n",
(uint32_t) phdr.p_offset,
(uint32_t) phdr.p_vaddr,
section_name = elf_strptr(e, shstrndx, shdr.sh_name);
#endif
section_name = elf_strptr(e, shstrndx, shdr.sh_name);
#endif
- if (phdr.p_offset <= shdr.sh_offset && shdr.sh_offset < phdr.p_offset + phdr.p_filesz) {
-
- if (shdr.sh_size == 0)
- continue;
-
+ if (shdr.sh_size != 0 && shdr.sh_type != SHT_NOBITS && (shdr.sh_flags & SHF_ALLOC) &&
+ phdr.p_offset <= shdr.sh_offset && shdr.sh_offset < phdr.p_offset + phdr.p_filesz)
+ {
sh_paddr = phdr.p_paddr + shdr.sh_offset - phdr.p_offset;
sh_paddr = phdr.p_paddr + shdr.sh_offset - phdr.p_offset;
fprintf (stderr, "\tsize %08x rom %08x exec %08x %s\n",
(uint32_t) shdr.sh_size,
(uint32_t) sh_paddr,
fprintf (stderr, "\tsize %08x rom %08x exec %08x %s\n",
(uint32_t) shdr.sh_size,
(uint32_t) sh_paddr,