X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=elf2flt.c;h=1cc6c03d26402a046d35dc5efaa2cbf5ee0ae6b1;hb=3b0f01b9267cf12cee0bb48e3918d088f54e6e9e;hp=09bf89663533c0899423ee30ee96090f2040d5ce;hpb=cf57f51fa9fdf263a22014040dd990a3eecae51f;p=uclinux-h8%2Felf2flt.git diff --git a/elf2flt.c b/elf2flt.c index 09bf896..1cc6c03 100644 --- a/elf2flt.c +++ b/elf2flt.c @@ -236,6 +236,10 @@ get_symbols (bfd *abfd, long *num) return NULL; symbol_table = (asymbol **) malloc (storage_needed); + if (symbol_table == NULL) { + perror("malloc"); + exit(1); + } number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table); @@ -425,7 +429,7 @@ dump_symbols(symbols, number_of_symbols); * Also note that both the relocatable and absolute versions have this * terminator even though the relocatable one doesn't have the GOT! */ - if (pic_with_got) { + if (pic_with_got && !use_resolved) { unsigned long *lp = (unsigned long *)data; /* Should call ntohl(*lp) here but is isn't going to matter */ while (*lp != 0xffffffff) lp++; @@ -492,7 +496,12 @@ dump_symbols(symbols, number_of_symbols); } symb = get_symbols(rel_bfd, &nsymb); - relpp = (arelent **) xmalloc(relsize); + relpp = (arelent **) malloc(relsize); + if (relpp == NULL) { + perror("malloc"); + exit(1); + } + relcount = bfd_canonicalize_reloc(rel_bfd, r, relpp, symb); if (relcount <= 0) { if (verbose) @@ -674,7 +683,7 @@ dump_symbols(symbols, number_of_symbols); + lo; } } else - goto bad_v850_reloc_err; + goto bad_resolved_reloc; break; case R_V850_LO16: @@ -688,28 +697,36 @@ dump_symbols(symbols, number_of_symbols); && (p[-1]->addend == p[0]->addend)) break; /* not an error */ else - goto bad_v850_reloc_err; + goto bad_resolved_reloc; case R_V850_HI16: - bad_v850_reloc_err: - printf("ERROR: reloc type %s unsupported in this context\n", - q->howto->name); - bad_relocs++; - break; -#endif /* TARGET_V850 */ - -#if defined(TARGET_arm) + goto bad_resolved_reloc; + default: + goto good_32bit_resolved_reloc; +#elif defined(TARGET_arm) case R_ARM_ABS32: relocation_needed = 1; break; + case R_ARM_REL32: + case R_ARM_THM_PC11: case R_ARM_THM_PC22: relocation_needed = 0; break; default: - printf("ERROR: reloc type %s unsupported in this context\n", - q->howto->name); - bad_relocs++; - break; + goto bad_resolved_reloc; +#elif defined(TARGET_m68k) + case R_68K_32: + goto good_32bit_resolved_reloc; + case R_68K_PC32: + case R_68K_PC16: + /* The linker has already resolved + PC relocs for us. In PIC links, + the symbol must be in the data + segment. */ + case R_68K_NONE: + continue; + default: + goto bad_resolved_reloc; #else default: /* The default is to assume that the @@ -719,6 +736,9 @@ dump_symbols(symbols, number_of_symbols); give an error by default, and require `safe' relocations to be enumberated explicitly?). */ + goto good_32bit_resolve_reloc; +#endif + good_32bit_resolved_reloc: if (bfd_big_endian (abs_bfd)) sym_addr = (r_mem[0] << 24) @@ -732,7 +752,13 @@ dump_symbols(symbols, number_of_symbols); + (r_mem[2] << 16) + (r_mem[3] << 24); relocation_needed = 1; -#endif + break; + + bad_resolved_reloc: + printf("ERROR: reloc type %s unsupported in this context\n", + q->howto->name); + bad_relocs++; + break; } } else { /* Calculate the sym address ourselves. */ @@ -1758,7 +1784,7 @@ static void write_zeroes (unsigned long num, FILE *stream) if (num > 0) { /* It'd be nice if we could just use fseek, but that doesn't seem to work for stdio output files. */ - bzero(zeroes, 1024); + memset(zeroes, 0x00, 1024); while (num > sizeof(zeroes)) { fwrite(zeroes, sizeof(zeroes), 1, stream); num -= sizeof(zeroes); @@ -1851,7 +1877,10 @@ int main(int argc, char *argv[]) use_resolved = 1; break; case 's': - stack = atoi(optarg); + if (sscanf(optarg, "%i", &stack) != 1) { + fprintf(stderr, "%s invalid stack size %s\n", argv[0], optarg); + usage(); + } break; case 'R': rel_file = optarg; @@ -1958,6 +1987,10 @@ int main(int argc, char *argv[]) } text = malloc(text_len); + if (text == NULL) { + perror("malloc"); + exit(1); + } if (verbose) printf("TEXT -> vma=0x%x len=0x%x\n", text_vma, text_len); @@ -1978,6 +2011,10 @@ int main(int argc, char *argv[]) exit (2); } data = malloc(data_len); + if (data == NULL) { + perror("malloc"); + exit(1); + } if (verbose) printf("DATA -> vma=0x%x len=0x%x\n", data_vma, data_len); @@ -2048,7 +2085,7 @@ int main(int argc, char *argv[]) | (compress ? (compress == 2 ? FLAT_FLAG_GZDATA : FLAT_FLAG_GZIP) : 0) ); hdr.build_date = htonl((unsigned long)time(NULL)); - bzero(hdr.filler, sizeof(hdr.filler)); + memset(hdr.filler, 0x00, sizeof(hdr.filler)); for (i=0; i