From: David McCullough Date: Thu, 7 May 2009 06:15:31 +0000 (+0000) Subject: The FLAT structure is all built on 32bit types, so make sure the elf2flt X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=223a4dab0fefcddfe1b5b2d28c4a6710fc149e4d;p=elf2flt.git The FLAT structure is all built on 32bit types, so make sure the elf2flt code uses 32bit types rather than long's. This way we get correct behavior when the host sizeof(long) is not 32bit as is on all 64bit systems nowadays. Signed-off-by: Bernd Schmidt Signed-off-by: Mike Frysinger --- diff --git a/elf2flt.c b/elf2flt.c index 289d542..a950ff7 100644 --- a/elf2flt.c +++ b/elf2flt.c @@ -225,7 +225,7 @@ einfo (int type, const char *format, ...) { asymbol** get_symbols (bfd *abfd, long *num) { - long storage_needed; + int32_t storage_needed; asymbol **symbol_table; long number_of_symbols; @@ -294,11 +294,11 @@ get_gp_value(asymbol **symbol_table, long number_of_symbols) -long -add_com_to_bss(asymbol **symbol_table, long number_of_symbols, long bss_len) +int32_t +add_com_to_bss(asymbol **symbol_table, int32_t number_of_symbols, int32_t bss_len) { - long i, comsize; - long offset; + int32_t i, comsize; + int32_t offset; comsize = 0; for (i=0; i GOT_LIMIT) { fprintf(stderr, "GOT too large: %d bytes (limit = %d bytes)\n", @@ -795,7 +795,7 @@ dump_symbols(symbols, number_of_symbols); sym_vma, (*(q->sym_ptr_ptr))->value, q->address, sym_addr, (*p)->howto->rightshift, - *(unsigned long *)r_mem); + *(uint32_t *)r_mem); sym_vma = bfd_section_vma(abs_bfd, sym_section); sym_addr += sym_vma + q->addend; break; @@ -812,7 +812,7 @@ dump_symbols(symbols, number_of_symbols); sym_vma, (*(q->sym_ptr_ptr))->value, q->address, sym_addr, (*p)->howto->rightshift, - *(unsigned long *)r_mem); + *(uint32_t *)r_mem); case R_ARM_PC24: sym_vma = 0; sym_addr = (sym_addr-q->address)>>(*p)->howto->rightshift; @@ -903,7 +903,7 @@ dump_symbols(symbols, number_of_symbols); the relocation symbol. */ { unsigned char *p = r_mem; - unsigned long offset; + uint32_t offset; pflags=0x80000000; /* work out the relocation */ @@ -1152,7 +1152,7 @@ NIOS2_RELOC_ERR: sym_addr = (((*(q->sym_ptr_ptr))->value- q->address) >> 2) & 0x3fffffff; sym_addr |= ( - ntohl(*(unsigned long *)r_mem) + ntohl(*(uint32_t *)r_mem) & 0xc0000000 ); break; @@ -1162,7 +1162,7 @@ NIOS2_RELOC_ERR: sym_vma = bfd_section_vma(abs_bfd, sym_section); sym_addr += sym_vma + q->addend; sym_addr |= ( - htonl(*(unsigned long *)r_mem) + htonl(*(uint32_t *)r_mem) & 0xffc00000 ); break; @@ -1173,7 +1173,7 @@ NIOS2_RELOC_ERR: sym_addr += sym_vma + q->addend; sym_addr &= 0x000003ff; sym_addr |= ( - htonl(*(unsigned long *)r_mem) + htonl(*(uint32_t *)r_mem) & 0xfffffc00 ); break; @@ -1493,9 +1493,9 @@ DIS29_RELOCATION: #if defined(TARGET_arm) union { unsigned char c[4]; - unsigned long l; + uint32_t l; } tmp; - long hl; + int32_t hl; int i0, i1, i2, i3; /* @@ -1513,7 +1513,7 @@ DIS29_RELOCATION: i3 = 0; } - tmp.l = *(unsigned long *)r_mem; + tmp.l = *(uint32_t *)r_mem; hl = tmp.c[i0] | (tmp.c[i1] << 8) | (tmp.c[i2] << 16); if (use_resolved || (((*p)->howto->type != R_ARM_PC24) && @@ -1531,9 +1531,9 @@ DIS29_RELOCATION: ((*p)->howto->type != R_ARM_PLT32))) tmp.c[i3] = (hl >> 24) & 0xff; if ((*p)->howto->type == R_ARM_ABS32) - *(unsigned long *)r_mem = htonl(hl); + *(uint32_t *)r_mem = htonl(hl); else - *(unsigned long *)r_mem = tmp.l; + *(uint32_t *)r_mem = tmp.l; #elif defined(TARGET_bfin) if ((*p)->howto->type == R_pcrel24 @@ -1801,16 +1801,16 @@ int main(int argc, char *argv[]) asymbol **symbol_table; long number_of_symbols; - unsigned long data_len = 0; - unsigned long bss_len = 0; - unsigned long text_len = 0; - unsigned long reloc_len; + uint32_t data_len = 0; + uint32_t bss_len = 0; + uint32_t text_len = 0; + uint32_t reloc_len; - unsigned long data_vma = ~0; - unsigned long bss_vma = ~0; - unsigned long text_vma = ~0; + uint32_t data_vma = ~0; + uint32_t bss_vma = ~0; + uint32_t text_vma = ~0; - unsigned long text_offs; + uint32_t text_offs; void *text; void *data; @@ -1941,7 +1941,7 @@ int main(int argc, char *argv[]) /* Group output sections into text, data, and bss, and calc their sizes. */ for (s = abs_bfd->sections; s != NULL; s = s->next) { - unsigned long *vma, *len; + uint32_t *vma, *len; bfd_size_type sec_size; bfd_vma sec_vma; @@ -2043,9 +2043,9 @@ int main(int argc, char *argv[]) data_len = bss_vma - data_vma; } - reloc = output_relocs(abs_bfd, symbol_table, number_of_symbols, &reloc_len, - text, text_len, text_vma, data, data_len, data_vma, - rel_bfd); + reloc = (uint32_t *) + output_relocs(abs_bfd, symbol_table, number_of_symbols, &reloc_len, + text, text_len, text_vma, data, data_len, data_vma, rel_bfd); if (reloc == NULL) printf("No relocations in code!\n"); @@ -2068,7 +2068,7 @@ int main(int argc, char *argv[]) | (pic_with_got ? FLAT_FLAG_GOTPIC : 0) | (docompress ? (docompress == 2 ? FLAT_FLAG_GZDATA : FLAT_FLAG_GZIP) : 0) ); - hdr.build_date = htonl((unsigned long)time(NULL)); + hdr.build_date = htonl((uint32_t)time(NULL)); memset(hdr.filler, 0x00, sizeof(hdr.filler)); for (i=0; i