mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-22 11:00:01 +08:00
(do_relocs_for): Don't allocate storage or process relocs if there aren't any
relocs to process. Avoids malloc/free bug on SCO too.
This commit is contained in:
@ -364,6 +364,10 @@ DEFUN (do_relocs_for, (abfd, h, file_cursor),
|
|||||||
fixS *fix_ptr = segment_info[idx].fix_root;
|
fixS *fix_ptr = segment_info[idx].fix_root;
|
||||||
nrelocs = count_entries_in_chain (idx);
|
nrelocs = count_entries_in_chain (idx);
|
||||||
|
|
||||||
|
if (nrelocs)
|
||||||
|
/* Bypass this stuff if no relocs. This also incidentally
|
||||||
|
avoids a SCO bug, where free(malloc(0)) tends to crash. */
|
||||||
|
{
|
||||||
external_reloc_size = nrelocs * RELSZ;
|
external_reloc_size = nrelocs * RELSZ;
|
||||||
external_reloc_vec =
|
external_reloc_vec =
|
||||||
(struct external_reloc *) malloc (external_reloc_size);
|
(struct external_reloc *) malloc (external_reloc_size);
|
||||||
@ -448,11 +452,20 @@ DEFUN (do_relocs_for, (abfd, h, file_cursor),
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Write out the reloc table */
|
/* Write out the reloc table */
|
||||||
segment_info[idx].scnhdr.s_relptr = nrelocs ? *file_cursor : 0;
|
bfd_write ((PTR) external_reloc_vec, 1, external_reloc_size,
|
||||||
segment_info[idx].scnhdr.s_nreloc = nrelocs;
|
abfd);
|
||||||
bfd_write ((PTR) external_reloc_vec, 1, external_reloc_size, abfd);
|
|
||||||
*file_cursor += external_reloc_size;
|
|
||||||
free (external_reloc_vec);
|
free (external_reloc_vec);
|
||||||
|
|
||||||
|
/* Fill in section header info. */
|
||||||
|
segment_info[idx].scnhdr.s_relptr = *file_cursor;
|
||||||
|
*file_cursor += external_reloc_size;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* No relocs */
|
||||||
|
segment_info[idx].scnhdr.s_relptr = 0;
|
||||||
|
}
|
||||||
|
segment_info[idx].scnhdr.s_nreloc = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Set relocation_size field in file headers */
|
/* Set relocation_size field in file headers */
|
||||||
|
Reference in New Issue
Block a user