X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=ao-tools%2Flib%2Fao-elf.c;h=cc127b62a8a7e73515313dc4cce7d425c4d3a259;hp=99b37210781e553094f2e9aa52407392b7da2486;hb=f036b35a6fe1e187b2faea5c4ddf72359b33a44f;hpb=14204e3d147ad99cc249ad8de254809180fe5c38 diff --git a/ao-tools/lib/ao-elf.c b/ao-tools/lib/ao-elf.c index 99b37210..cc127b62 100644 --- a/ao-tools/lib/ao-elf.c +++ b/ao-tools/lib/ao-elf.c @@ -3,7 +3,8 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -185,6 +186,7 @@ load_write(struct ao_hex_image *from, uint32_t address, uint32_t length, void *d return new; } +#define DBG 0 /* * Construct a large in-memory block for all * of the loaded sections of the program @@ -201,12 +203,12 @@ get_load(Elf *e) GElf_Phdr phdr; GElf_Addr sh_paddr; struct ao_hex_image *load = NULL; -#if 0 +#if DBG char *section_name; #endif size_t nshdr; size_t s; - + if (elf_getshdrstrndx(e, &shstrndx) < 0) return 0; @@ -230,7 +232,7 @@ get_load(Elf *e) /* Get the associated file section */ -#if 0 +#if DBG fprintf (stderr, "offset %08x vaddr %08x paddr %08x filesz %08x memsz %08x\n", (uint32_t) phdr.p_offset, (uint32_t) phdr.p_vaddr, @@ -238,7 +240,7 @@ get_load(Elf *e) (uint32_t) phdr.p_filesz, (uint32_t) phdr.p_memsz); #endif - + for (s = 0; s < nshdr; s++) { scn = elf_getscn(e, s); @@ -251,18 +253,16 @@ get_load(Elf *e) abort(); } -#if 0 +#if DBG 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; -#if 0 +#if DBG fprintf (stderr, "\tsize %08x rom %08x exec %08x %s\n", (uint32_t) shdr.sh_size, (uint32_t) sh_paddr,