aboutsummaryrefslogtreecommitdiff
path: root/binutils
diff options
context:
space:
mode:
Diffstat (limited to 'binutils')
-rw-r--r--binutils/MAINTAINERS1
-rw-r--r--binutils/doc/binutils.texi8
-rw-r--r--binutils/dwarf.c14
-rw-r--r--binutils/resbin.c363
-rw-r--r--binutils/rescoff.c88
5 files changed, 274 insertions, 200 deletions
diff --git a/binutils/MAINTAINERS b/binutils/MAINTAINERS
index 2aaadc8..7b50393 100644
--- a/binutils/MAINTAINERS
+++ b/binutils/MAINTAINERS
@@ -118,6 +118,7 @@ responsibility among the other maintainers.
OR1K Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
OR1K Stafford Horne <shorne@gmail.com>
PPC Peter Bergner <bergner@linux.ibm.com>
+ PPC Surya Kumari Jangala <jskumari@linux.ibm.com>
PPC vector ext Aldy Hernandez <aldyh@redhat.com>
RISC-V Palmer Dabbelt <palmer@dabbelt.com>
RISC-V Andrew Waterman <andrew@sifive.com>
diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index b291670..c74526e 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -2701,6 +2701,14 @@ but the result again may not be as you expect.
For RISC-V, the following options are supported:
@table @code
+@item max
+Disassemble without checking architecture string. This is a best effort mode, so
+for overlapping ISA extensions the first match (possibly incorrect in a given
+context) will be used to decode the instruction. It's useful, if the ELF file
+doesn't expose ISA string, preventing automatic ISA subset deduction, and the
+default fallback ISA string (@code{rv64gc}) doesn't cover all instructions in
+the binary.
+
@item numeric
Print numeric register names, rather than ABI names (e.g., print @code{x2}
instead of @code{sp}).
diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index 08bb623..fb09b86 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -7324,7 +7324,7 @@ display_debug_loc (struct dwarf_section *section, void *file)
unsigned int *array = NULL;
const char *suffix = strrchr (section->name, '.');
bool is_dwo = false;
- int is_loclists = strstr (section->name, "debug_loclists") != NULL;
+ bool is_loclists = strstr (section->name, "debug_loclists") != NULL;
uint64_t next_header_offset = 0;
if (suffix && strcmp (suffix, ".dwo") == 0)
@@ -7450,6 +7450,16 @@ display_debug_loc (struct dwarf_section *section, void *file)
debug_info *debug_info_p = debug_information + i;
uint32_t offset_count;
+ /* .debug_loclists section is loaded into debug_information as
+ DWARF-5 debug info and .debug_loc section is loaded into
+ debug_information as pre-DWARF-5 debug info. When dumping
+ .debug_loc section, we should only process pre-DWARF-5 debug
+ info in debug_information. When dumping .debug_loclists
+ section, we should only process DWARF-5 info in
+ debug_information. */
+ if ((debug_info_p->dwarf_version >= 5) != is_loclists)
+ continue;
+
if (!locs_sorted)
{
for (k = 0; k < debug_info_p->num_loc_offsets; k++)
@@ -7462,7 +7472,7 @@ display_debug_loc (struct dwarf_section *section, void *file)
/* .debug_loclists has a per-unit header.
Update start if we are detecting it. */
- if (debug_info_p->dwarf_version == 5)
+ if (debug_info_p->dwarf_version >= 5)
{
j = locs_sorted ? 0 : array [0];
diff --git a/binutils/resbin.c b/binutils/resbin.c
index 1698e14..98dd68b 100644
--- a/binutils/resbin.c
+++ b/binutils/resbin.c
@@ -141,7 +141,7 @@ get_unicode (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length,
++c;
}
- ret = (unichar *) res_alloc ((c + 1) * sizeof (unichar));
+ ret = res_alloc ((c + 1) * sizeof (unichar));
for (i = 0; i < c; i++)
ret[i] = windres_get_16 (wrbfd, data + i * 2, 2);
@@ -198,7 +198,7 @@ bin_to_res_generic (windres_bfd *wrbfd ATTRIBUTE_UNUSED, enum rc_res_type type,
{
rc_res_resource *r;
- r = (rc_res_resource *) res_alloc (sizeof (rc_res_resource));
+ r = res_alloc (sizeof (rc_res_resource));
r->type = type;
r->u.data.data = data;
r->u.data.length = length;
@@ -220,13 +220,13 @@ bin_to_res_cursor (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
return NULL;
}
- c = (rc_cursor *) res_alloc (sizeof (rc_cursor));
+ c = res_alloc (sizeof (rc_cursor));
c->xhotspot = windres_get_16 (wrbfd, data, 2);
c->yhotspot = windres_get_16 (wrbfd, data + 2, 2);
c->length = length - 4;
c->data = data + 4;
- r = (rc_res_resource *) res_alloc (sizeof *r);
+ r = res_alloc (sizeof *r);
r->type = RES_TYPE_CURSOR;
r->u.cursor = c;
@@ -242,10 +242,10 @@ bin_to_res_menu (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length)
rc_menu *m;
rc_uint_type version, got;
- r = (rc_res_resource *) res_alloc (sizeof *r);
+ r = res_alloc (sizeof *r);
r->type = RES_TYPE_MENU;
- m = (rc_menu *) res_alloc (sizeof (rc_menu));
+ m = res_alloc (sizeof (rc_menu));
r->u.menu = m;
if (length < 2)
@@ -301,8 +301,8 @@ bin_to_res_menu (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length)
/* Convert menu items from binary. */
static rc_menuitem *
-bin_to_res_menuitems (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length,
- rc_uint_type *got)
+bin_to_res_menuitems (windres_bfd *wrbfd, const bfd_byte *data,
+ rc_uint_type length, rc_uint_type *got)
{
rc_menuitem *first, **pp;
@@ -323,7 +323,7 @@ bin_to_res_menuitems (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type len
return NULL;
}
- mi = (rc_menuitem *) res_alloc (sizeof *mi);
+ mi = res_alloc (sizeof *mi);
mi->state = 0;
mi->help = 0;
@@ -365,8 +365,8 @@ bin_to_res_menuitems (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type len
rc_uint_type subread;
mi->id = 0;
- mi->popup = bin_to_res_menuitems (wrbfd, data + itemlen, length - itemlen,
- &subread);
+ mi->popup = bin_to_res_menuitems (wrbfd, data + itemlen,
+ length - itemlen, &subread);
if (mi->popup == NULL)
return NULL;
itemlen += subread;
@@ -390,8 +390,8 @@ bin_to_res_menuitems (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type len
/* Convert menuex items from binary. */
static rc_menuitem *
-bin_to_res_menuexitems (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length,
- rc_uint_type *got)
+bin_to_res_menuexitems (windres_bfd *wrbfd, const bfd_byte *data,
+ rc_uint_type length, rc_uint_type *got)
{
rc_menuitem *first, **pp;
@@ -412,7 +412,7 @@ bin_to_res_menuexitems (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type l
return NULL;
}
- mi = (rc_menuitem *) res_alloc (sizeof (rc_menuitem));
+ mi = res_alloc (sizeof (rc_menuitem));
mi->type = windres_get_32 (wrbfd, data, 4);
mi->state = windres_get_32 (wrbfd, data + 4, 4);
mi->id = windres_get_32 (wrbfd, data + 8, 4);
@@ -492,7 +492,7 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
return NULL;
}
- d = (rc_dialog *) res_alloc (sizeof (rc_dialog));
+ d = res_alloc (sizeof (rc_dialog));
signature = windres_get_16 (wrbfd, data + 2, 2);
if (signature != 0xffff)
@@ -513,7 +513,7 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
return NULL;
}
- d->ex = (rc_dialog_ex *) res_alloc (sizeof (rc_dialog_ex));
+ d->ex = res_alloc (sizeof (rc_dialog_ex));
d->ex->help = windres_get_32 (wrbfd, data + 4, 4);
d->exstyle = windres_get_32 (wrbfd, data + 8, 4);
d->style = windres_get_32 (wrbfd, data + 12, 4);
@@ -602,7 +602,7 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
off = (off + 3) &~ 3;
- dc = (rc_dialog_control *) res_alloc (sizeof (rc_dialog_control));
+ dc = res_alloc (sizeof (rc_dialog_control));
if (d->ex == NULL)
{
@@ -677,8 +677,7 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
return NULL;
}
- dc->data = ((rc_rcdata_item *)
- res_alloc (sizeof (rc_rcdata_item)));
+ dc->data = res_alloc (sizeof (rc_rcdata_item));
dc->data->next = NULL;
dc->data->type = RCDATA_BUFFER;
dc->data->u.buffer.length = datalen;
@@ -692,7 +691,7 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
pp = &dc->next;
}
- r = (rc_res_resource *) res_alloc (sizeof *r);
+ r = res_alloc (sizeof *r);
r->type = RES_TYPE_DIALOG;
r->u.dialog = d;
@@ -708,7 +707,7 @@ bin_to_res_string (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
int i;
rc_res_resource *r;
- st = (rc_stringtable *) res_alloc (sizeof (rc_stringtable));
+ st = res_alloc (sizeof (rc_stringtable));
for (i = 0; i < 16; i++)
{
@@ -733,7 +732,7 @@ bin_to_res_string (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
return NULL;
}
- s = (unichar *) res_alloc (slen * sizeof (unichar));
+ s = res_alloc (slen * sizeof (unichar));
st->strings[i].string = s;
for (j = 0; j < slen; j++)
@@ -744,7 +743,7 @@ bin_to_res_string (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
length -= 2 + 2 * slen;
}
- r = (rc_res_resource *) res_alloc (sizeof *r);
+ r = res_alloc (sizeof *r);
r->type = RES_TYPE_STRINGTABLE;
r->u.stringtable = st;
@@ -754,7 +753,8 @@ bin_to_res_string (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
/* Convert a fontdir resource from binary. */
static rc_res_resource *
-bin_to_res_fontdir (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length)
+bin_to_res_fontdir (windres_bfd *wrbfd, const bfd_byte *data,
+ rc_uint_type length)
{
rc_uint_type c, i;
rc_fontdir *first, **pp;
@@ -784,7 +784,7 @@ bin_to_res_fontdir (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
}
bfi = (const struct bin_fontdir_item *) data;
- fd = (rc_fontdir *) res_alloc (sizeof *fd);
+ fd = res_alloc (sizeof *fd);
fd->index = windres_get_16 (wrbfd, bfi->index, 2);
/* To work out the length of the fontdir data, we must get the
@@ -827,7 +827,7 @@ bin_to_res_fontdir (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
length -= off;
}
- r = (rc_res_resource *) res_alloc (sizeof *r);
+ r = res_alloc (sizeof *r);
r->type = RES_TYPE_FONTDIR;
r->u.fontdir = first;
@@ -837,7 +837,8 @@ bin_to_res_fontdir (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
/* Convert an accelerators resource from binary. */
static rc_res_resource *
-bin_to_res_accelerators (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length)
+bin_to_res_accelerators (windres_bfd *wrbfd, const bfd_byte *data,
+ rc_uint_type length)
{
rc_accelerator *first, **pp;
rc_res_resource *r;
@@ -855,7 +856,7 @@ bin_to_res_accelerators (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type
return NULL;
}
- a = (rc_accelerator *) res_alloc (sizeof (rc_accelerator));
+ a = res_alloc (sizeof (rc_accelerator));
a->flags = windres_get_16 (wrbfd, data, 2);
a->key = windres_get_16 (wrbfd, data + 2, 2);
@@ -872,7 +873,7 @@ bin_to_res_accelerators (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type
length -= 8;
}
- r = (rc_res_resource *) res_alloc (sizeof (rc_res_resource));
+ r = res_alloc (sizeof (rc_res_resource));
r->type = RES_TYPE_ACCELERATOR;
r->u.acc = first;
@@ -888,14 +889,14 @@ bin_to_res_rcdata (windres_bfd *wrbfd ATTRIBUTE_UNUSED, const bfd_byte *data,
rc_rcdata_item *ri;
rc_res_resource *r;
- ri = (rc_rcdata_item *) res_alloc (sizeof (rc_rcdata_item));
+ ri = res_alloc (sizeof (rc_rcdata_item));
ri->next = NULL;
ri->type = RCDATA_BUFFER;
ri->u.buffer.length = length;
ri->u.buffer.data = data;
- r = (rc_res_resource *) res_alloc (sizeof *r);
+ r = res_alloc (sizeof *r);
r->type = rctyp;
r->u.rcdata = ri;
@@ -905,7 +906,8 @@ bin_to_res_rcdata (windres_bfd *wrbfd ATTRIBUTE_UNUSED, const bfd_byte *data,
/* Convert a group cursor resource from binary. */
static rc_res_resource *
-bin_to_res_group_cursor (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length)
+bin_to_res_group_cursor (windres_bfd *wrbfd, const bfd_byte *data,
+ rc_uint_type length)
{
int type, c, i;
rc_group_cursor *first, **pp;
@@ -942,7 +944,7 @@ bin_to_res_group_cursor (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type
return NULL;
}
- gc = (rc_group_cursor *) res_alloc (sizeof *gc);
+ gc = res_alloc (sizeof *gc);
gc->width = windres_get_16 (wrbfd, data, 2);
gc->height = windres_get_16 (wrbfd, data + 2, 2);
@@ -959,7 +961,7 @@ bin_to_res_group_cursor (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type
length -= 14;
}
- r = (rc_res_resource *) res_alloc (sizeof (rc_res_resource));
+ r = res_alloc (sizeof (rc_res_resource));
r->type = RES_TYPE_GROUP_CURSOR;
r->u.group_cursor = first;
@@ -969,7 +971,8 @@ bin_to_res_group_cursor (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type
/* Convert a group icon resource from binary. */
static rc_res_resource *
-bin_to_res_group_icon (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length)
+bin_to_res_group_icon (windres_bfd *wrbfd, const bfd_byte *data,
+ rc_uint_type length)
{
int type, c, i;
rc_group_icon *first, **pp;
@@ -1006,7 +1009,7 @@ bin_to_res_group_icon (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type le
return NULL;
}
- gi = (rc_group_icon *) res_alloc (sizeof (rc_group_icon));
+ gi = res_alloc (sizeof (rc_group_icon));
gi->width = windres_get_8 (wrbfd, data, 1);
gi->height = windres_get_8 (wrbfd, data + 1, 1);
@@ -1024,7 +1027,7 @@ bin_to_res_group_icon (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type le
length -= 14;
}
- r = (rc_res_resource *) res_alloc (sizeof *r);
+ r = res_alloc (sizeof *r);
r->type = RES_TYPE_GROUP_ICON;
r->u.group_icon = first;
@@ -1037,8 +1040,8 @@ bin_to_res_group_icon (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type le
to the type, and *OFF to the offset to the children. */
static bool
-get_version_header (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length,
- const char *key, unichar **pkey,
+get_version_header (windres_bfd *wrbfd, const bfd_byte *data,
+ rc_uint_type length, const char *key, unichar **pkey,
rc_uint_type *len, rc_uint_type *vallen, rc_uint_type *type,
rc_uint_type *off)
{
@@ -1099,7 +1102,8 @@ get_version_header (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
/* Convert a version resource from binary. */
static rc_res_resource *
-bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length)
+bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data,
+ rc_uint_type length)
{
rc_uint_type verlen, vallen, type, off;
rc_fixed_versioninfo *fi;
@@ -1125,7 +1129,8 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
return NULL;
}
- /* PR 27686: Ignore any padding bytes after the end of the version structure. */
+ /* PR 27686: Ignore any padding bytes after the end of the version
+ structure. */
length = verlen;
data += off;
@@ -1164,7 +1169,7 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
return NULL;
}
- fi = (rc_fixed_versioninfo *) res_alloc (sizeof (rc_fixed_versioninfo));
+ fi = res_alloc (sizeof (rc_fixed_versioninfo));
fi->file_version_ms = windres_get_32 (wrbfd, data + 8, 4);
fi->file_version_ls = windres_get_32 (wrbfd, data + 12, 4);
@@ -1196,7 +1201,7 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
return NULL;
}
- vi = (rc_ver_info *) res_alloc (sizeof (rc_ver_info));
+ vi = res_alloc (sizeof (rc_ver_info));
ch = windres_get_16 (wrbfd, data + 6, 2);
@@ -1238,7 +1243,7 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
return NULL;
}
- vst = (rc_ver_stringtable *) res_alloc (sizeof (rc_ver_stringtable));
+ vst = res_alloc (sizeof (rc_ver_stringtable));
if (!get_version_header (wrbfd, data, length, (const char *) NULL,
&vst->language, &stverlen, &vallen,
@@ -1256,64 +1261,65 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
length -= off;
verlen -= off;
- stverlen -= off;
+ stverlen -= off;
- vst->strings = NULL;
- ppvs = &vst->strings;
+ vst->strings = NULL;
+ ppvs = &vst->strings;
- while (stverlen > 0)
- {
- rc_ver_stringinfo *vs;
- rc_uint_type sverlen, vslen, valoff;
-
- if (length < 8)
+ while (stverlen > 0)
{
- toosmall (_("version string"));
- return NULL;
- }
-
- vs = (rc_ver_stringinfo *) res_alloc (sizeof (rc_ver_stringinfo));
-
- if (!get_version_header (wrbfd, data, length, (const char *) NULL,
- &vs->key, &sverlen, &vallen, &type, &off))
- return NULL;
-
- data += off;
- length -= off;
-
- vs->value = get_unicode (wrbfd, data, length, &vslen);
- if (vs->value == NULL)
- return NULL;
- valoff = vslen * 2 + 2;
- valoff = (valoff + 3) & ~3;
-
- if (off + valoff != sverlen)
- {
- non_fatal (_("unexpected version string length %ld != %ld + %ld"),
- (long) sverlen, (long) off, (long) valoff);
- return NULL;
+ rc_ver_stringinfo *vs;
+ rc_uint_type sverlen, vslen, valoff;
+
+ if (length < 8)
+ {
+ toosmall (_("version string"));
+ return NULL;
+ }
+
+ vs = res_alloc (sizeof (rc_ver_stringinfo));
+
+ if (!get_version_header (wrbfd, data, length,
+ (const char *) NULL, &vs->key,
+ &sverlen, &vallen, &type, &off))
+ return NULL;
+
+ data += off;
+ length -= off;
+
+ vs->value = get_unicode (wrbfd, data, length, &vslen);
+ if (vs->value == NULL)
+ return NULL;
+ valoff = vslen * 2 + 2;
+ valoff = (valoff + 3) & ~3;
+
+ if (off + valoff != sverlen)
+ {
+ non_fatal (_("unexpected version string length %ld != %ld + %ld"),
+ (long) sverlen, (long) off, (long) valoff);
+ return NULL;
+ }
+
+ data += valoff;
+ length -= valoff;
+
+ if (stverlen < sverlen)
+ {
+ non_fatal (_("unexpected version string length %ld < %ld"),
+ (long) verlen, (long) sverlen);
+ return NULL;
+ }
+ stverlen -= sverlen;
+ verlen -= sverlen;
+
+ vs->next = NULL;
+ *ppvs = vs;
+ ppvs = &vs->next;
}
- data += valoff;
- length -= valoff;
-
- if (stverlen < sverlen)
- {
- non_fatal (_("unexpected version string length %ld < %ld"),
- (long) verlen, (long) sverlen);
- return NULL;
- }
- stverlen -= sverlen;
- verlen -= sverlen;
-
- vs->next = NULL;
- *ppvs = vs;
- ppvs = &vs->next;
- }
-
- vst->next = NULL;
- *ppvst = vst;
- ppvst = &vst->next;
+ vst->next = NULL;
+ *ppvst = vst;
+ ppvst = &vst->next;
}
}
else if (ch == 'V')
@@ -1358,7 +1364,7 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
return NULL;
}
- vv = (rc_ver_varinfo *) res_alloc (sizeof (rc_ver_varinfo));
+ vv = res_alloc (sizeof (rc_ver_varinfo));
vv->language = windres_get_16 (wrbfd, data, 2);
vv->charset = windres_get_16 (wrbfd, data + 2, 2);
@@ -1399,11 +1405,11 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
pp = &vi->next;
}
- v = (rc_versioninfo *) res_alloc (sizeof (rc_versioninfo));
+ v = res_alloc (sizeof (rc_versioninfo));
v->fixed = fi;
v->var = first;
- r = (rc_res_resource *) res_alloc (sizeof *r);
+ r = res_alloc (sizeof *r);
r->type = RES_TYPE_VERSIONINFO;
r->u.versioninfo = v;
@@ -1419,14 +1425,14 @@ bin_to_res_userdata (windres_bfd *wrbfd ATTRIBUTE_UNUSED, const bfd_byte *data,
rc_rcdata_item *ri;
rc_res_resource *r;
- ri = (rc_rcdata_item *) res_alloc (sizeof (rc_rcdata_item));
+ ri = res_alloc (sizeof (rc_rcdata_item));
ri->next = NULL;
ri->type = RCDATA_BUFFER;
ri->u.buffer.length = length;
ri->u.buffer.data = data;
- r = (rc_res_resource *) res_alloc (sizeof *r);
+ r = res_alloc (sizeof *r);
r->type = RES_TYPE_USERDATA;
r->u.rcdata = ri;
@@ -1446,7 +1452,7 @@ bin_to_res_toolbar (windres_bfd *wrbfd, const bfd_byte *data,
toosmall (_("toolbar"));
return NULL;
}
- ri = (rc_toolbar *) res_alloc (sizeof (rc_toolbar));
+ ri = res_alloc (sizeof (rc_toolbar));
ri->button_width = windres_get_32 (wrbfd, data, 4);
ri->button_height = windres_get_32 (wrbfd, data + 4, 4);
ri->nitems = windres_get_32 (wrbfd, data + 8, 4);
@@ -1455,27 +1461,30 @@ bin_to_res_toolbar (windres_bfd *wrbfd, const bfd_byte *data,
data += 12;
length -= 12;
for (i = 0; i < ri->nitems; i++)
- {
- rc_toolbar_item *it;
- it = (rc_toolbar_item *) res_alloc (sizeof (rc_toolbar_item));
- it->id.named = 0;
- if (length < 4)
- toosmall (_("toolbar item"));
- it->id.u.id = (int) windres_get_32 (wrbfd, data, 4);
- it->prev = it->next = NULL;
- data += 4;
- length -= 4;
- if(ri->items) {
- rc_toolbar_item *ii = ri->items;
- while (ii->next != NULL)
- ii = ii->next;
- it->prev = ii;
- ii->next = it;
- }
- else
- ri->items = it;
- }
- r = (rc_res_resource *) res_alloc (sizeof *r);
+ {
+ rc_toolbar_item *it;
+ it = res_alloc (sizeof (rc_toolbar_item));
+ it->id.named = 0;
+ if (length < 4)
+ {
+ toosmall (_("toolbar item"));
+ return NULL;
+ }
+ it->id.u.id = (int) windres_get_32 (wrbfd, data, 4);
+ it->prev = it->next = NULL;
+ data += 4;
+ length -= 4;
+ if(ri->items) {
+ rc_toolbar_item *ii = ri->items;
+ while (ii->next != NULL)
+ ii = ii->next;
+ it->prev = ii;
+ ii->next = it;
+ }
+ else
+ ri->items = it;
+ }
+ r = res_alloc (sizeof *r);
r->type = RES_TYPE_TOOLBAR;
r->u.toolbar = ri;
return r;
@@ -1514,7 +1523,8 @@ res_to_bin (windres_bfd *wrbfd, rc_uint_type off, const rc_res_resource *res)
case RES_TYPE_FONT:
case RES_TYPE_ICON:
case RES_TYPE_MESSAGETABLE:
- return res_to_bin_generic (wrbfd, off, res->u.data.length, res->u.data.data);
+ return res_to_bin_generic (wrbfd, off, res->u.data.length,
+ res->u.data.data);
case RES_TYPE_ACCELERATOR:
return res_to_bin_accelerator (wrbfd, off, res->u.acc);
case RES_TYPE_CURSOR:
@@ -1565,13 +1575,13 @@ resid_to_bin (windres_bfd *wrbfd, rc_uint_type off, rc_res_id id)
rc_uint_type len = (id.u.n.name ? unichar_len (id.u.n.name) : 0);
if (wrbfd)
{
- bfd_byte *d = (bfd_byte *) reswr_alloc ((len + 1) * sizeof (unichar));
+ bfd_byte *d = reswr_alloc ((len + 1) * sizeof (unichar));
rc_uint_type i;
for (i = 0; i < len; i++)
windres_put_16 (wrbfd, d + (i * sizeof (unichar)), id.u.n.name[i]);
windres_put_16 (wrbfd, d + (len * sizeof (unichar)), 0);
set_windres_bfd_content (wrbfd, d, off, (len + 1) * sizeof (unichar));
- }
+ }
off += (rc_uint_type) ((len + 1) * sizeof (unichar));
}
return off;
@@ -1592,7 +1602,7 @@ unicode_to_bin (windres_bfd *wrbfd, rc_uint_type off, const unichar *str)
{
bfd_byte *d;
rc_uint_type i;
- d = (bfd_byte *) reswr_alloc ( (len + 1) * sizeof (unichar));
+ d = reswr_alloc ((len + 1) * sizeof (unichar));
for (i = 0; i < len; i++)
windres_put_16 (wrbfd, d + (i * sizeof (unichar)), str[i]);
windres_put_16 (wrbfd, d + (len * sizeof (unichar)), 0);
@@ -1617,12 +1627,13 @@ res_to_bin_accelerator (windres_bfd *wrbfd, rc_uint_type off,
{
struct bin_accelerator ba;
- windres_put_16 (wrbfd, ba.flags, a->flags | (a->next != NULL ? 0 : ACC_LAST));
+ windres_put_16 (wrbfd, ba.flags,
+ a->flags | (a->next != NULL ? 0 : ACC_LAST));
windres_put_16 (wrbfd, ba.key, a->key);
windres_put_16 (wrbfd, ba.id, a->id);
windres_put_16 (wrbfd, ba.pad, 0);
set_windres_bfd_content (wrbfd, &ba, off, BIN_ACCELERATOR_SIZE);
- }
+ }
off += BIN_ACCELERATOR_SIZE;
}
return off;
@@ -1641,7 +1652,8 @@ res_to_bin_cursor (windres_bfd *wrbfd, rc_uint_type off, const rc_cursor *c)
windres_put_16 (wrbfd, bc.yhotspot, c->yhotspot);
set_windres_bfd_content (wrbfd, &bc, off, BIN_CURSOR_SIZE);
if (c->length)
- set_windres_bfd_content (wrbfd, c->data, off + BIN_CURSOR_SIZE, c->length);
+ set_windres_bfd_content (wrbfd, c->data, off + BIN_CURSOR_SIZE,
+ c->length);
}
off = (off + BIN_CURSOR_SIZE + (rc_uint_type) c->length);
return off;
@@ -1671,8 +1683,9 @@ res_to_bin_group_cursor (windres_bfd *wrbfd, rc_uint_type off,
windres_put_16 (wrbfd, bgci.bits, gc->bits);
windres_put_32 (wrbfd, bgci.bytes, gc->bytes);
windres_put_16 (wrbfd, bgci.index, gc->index);
- set_windres_bfd_content (wrbfd, &bgci, off, BIN_GROUP_CURSOR_ITEM_SIZE);
- }
+ set_windres_bfd_content (wrbfd, &bgci, off,
+ BIN_GROUP_CURSOR_ITEM_SIZE);
+ }
off += BIN_GROUP_CURSOR_ITEM_SIZE;
}
@@ -1705,17 +1718,17 @@ res_to_bin_dialog (windres_bfd *wrbfd, rc_uint_type off, const rc_dialog *dialog
if (wrbfd)
{
- if (! dialogex)
- {
+ if (! dialogex)
+ {
windres_put_32 (wrbfd, bd.style, dialog->style);
windres_put_32 (wrbfd, bd.exstyle, dialog->exstyle);
windres_put_16 (wrbfd, bd.x, dialog->x);
windres_put_16 (wrbfd, bd.y, dialog->y);
windres_put_16 (wrbfd, bd.width, dialog->width);
windres_put_16 (wrbfd, bd.height, dialog->height);
- }
- else
- {
+ }
+ else
+ {
windres_put_16 (wrbfd, bdx.sig1, 1);
windres_put_16 (wrbfd, bdx.sig2, 0xffff);
windres_put_32 (wrbfd, bdx.help, (dialog->ex ? dialog->ex->help : 0));
@@ -1748,9 +1761,12 @@ res_to_bin_dialog (windres_bfd *wrbfd, rc_uint_type off, const rc_dialog *dialog
{
struct bin_dialogexfont bdxf;
windres_put_16 (wrbfd, bdxf.pointsize, dialog->pointsize);
- windres_put_16 (wrbfd, bdxf.weight, (dialog->ex == NULL ? 0 : dialog->ex->weight));
- windres_put_8 (wrbfd, bdxf.italic, (dialog->ex == NULL ? 0 : dialog->ex->italic));
- windres_put_8 (wrbfd, bdxf.charset, (dialog->ex == NULL ? 1 : dialog->ex->charset));
+ windres_put_16 (wrbfd, bdxf.weight,
+ dialog->ex == NULL ? 0 : dialog->ex->weight);
+ windres_put_8 (wrbfd, bdxf.italic,
+ dialog->ex == NULL ? 0 : dialog->ex->italic);
+ windres_put_8 (wrbfd, bdxf.charset,
+ dialog->ex == NULL ? 1 : dialog->ex->charset);
set_windres_bfd_content (wrbfd, &bdxf, off, BIN_DIALOGEXFONT_SIZE);
}
}
@@ -1764,8 +1780,8 @@ res_to_bin_dialog (windres_bfd *wrbfd, rc_uint_type off, const rc_dialog *dialog
off += (4 - ((off - off_delta) & 3)) & 3;
if (wrbfd)
{
- if (! dialogex)
- {
+ if (! dialogex)
+ {
struct bin_dialog_control bdc;
windres_put_32 (wrbfd, bdc.style, dc->style);
@@ -1775,10 +1791,11 @@ res_to_bin_dialog (windres_bfd *wrbfd, rc_uint_type off, const rc_dialog *dialog
windres_put_16 (wrbfd, bdc.width, dc->width);
windres_put_16 (wrbfd, bdc.height, dc->height);
windres_put_16 (wrbfd, bdc.id, dc->id);
- set_windres_bfd_content (wrbfd, &bdc, off, BIN_DIALOG_CONTROL_SIZE);
- }
- else
- {
+ set_windres_bfd_content (wrbfd, &bdc, off,
+ BIN_DIALOG_CONTROL_SIZE);
+ }
+ else
+ {
struct bin_dialogex_control bdc;
windres_put_32 (wrbfd, bdc.help, dc->help);
@@ -1789,11 +1806,11 @@ res_to_bin_dialog (windres_bfd *wrbfd, rc_uint_type off, const rc_dialog *dialog
windres_put_16 (wrbfd, bdc.width, dc->width);
windres_put_16 (wrbfd, bdc.height, dc->height);
windres_put_32 (wrbfd, bdc.id, dc->id);
- set_windres_bfd_content (wrbfd, &bdc, off, BIN_DIALOGEX_CONTROL_SIZE);
+ set_windres_bfd_content (wrbfd, &bdc, off,
+ BIN_DIALOGEX_CONTROL_SIZE);
}
}
- off += (dialogex != 0 ? BIN_DIALOGEX_CONTROL_SIZE : BIN_DIALOG_CONTROL_SIZE);
-
+ off += dialogex != 0 ? BIN_DIALOGEX_CONTROL_SIZE : BIN_DIALOG_CONTROL_SIZE;
off = resid_to_bin (wrbfd, off, dc->class);
off = resid_to_bin (wrbfd, off, dc->text);
@@ -1835,7 +1852,8 @@ res_to_bin_dialog (windres_bfd *wrbfd, rc_uint_type off, const rc_dialog *dialog
/* Convert a fontdir resource to binary. */
static rc_uint_type
-res_to_bin_fontdir (windres_bfd *wrbfd, rc_uint_type off, const rc_fontdir *fontdirs)
+res_to_bin_fontdir (windres_bfd *wrbfd, rc_uint_type off,
+ const rc_fontdir *fontdirs)
{
rc_uint_type start;
int c;
@@ -1869,7 +1887,8 @@ res_to_bin_fontdir (windres_bfd *wrbfd, rc_uint_type off, const rc_fontdir *font
/* Convert a group icon resource to binary. */
static rc_uint_type
-res_to_bin_group_icon (windres_bfd *wrbfd, rc_uint_type off, const rc_group_icon *group_icons)
+res_to_bin_group_icon (windres_bfd *wrbfd, rc_uint_type off,
+ const rc_group_icon *group_icons)
{
rc_uint_type start;
struct bin_group_icon bgi;
@@ -1919,21 +1938,21 @@ res_to_bin_menu (windres_bfd *wrbfd, rc_uint_type off, const rc_menu *menu)
if (wrbfd)
{
- if (! menuex)
- {
+ if (! menuex)
+ {
struct bin_menu bm;
windres_put_16 (wrbfd, bm.sig1, 0);
windres_put_16 (wrbfd, bm.sig2, 0);
set_windres_bfd_content (wrbfd, &bm, off, BIN_MENU_SIZE);
- }
- else
- {
+ }
+ else
+ {
struct bin_menuex bm;
windres_put_16 (wrbfd, bm.sig1, 1);
windres_put_16 (wrbfd, bm.sig2, 4);
windres_put_32 (wrbfd, bm.help, menu->help);
set_windres_bfd_content (wrbfd, &bm, off, BIN_MENUEX_SIZE);
- }
+ }
}
off += (menuex != 0 ? BIN_MENUEX_SIZE : BIN_MENU_SIZE);
if (! menuex)
@@ -1950,7 +1969,8 @@ res_to_bin_menu (windres_bfd *wrbfd, rc_uint_type off, const rc_menu *menu)
/* Convert menu items to binary. */
static rc_uint_type
-res_to_bin_menuitems (windres_bfd *wrbfd, rc_uint_type off, const rc_menuitem *items)
+res_to_bin_menuitems (windres_bfd *wrbfd, rc_uint_type off,
+ const rc_menuitem *items)
{
const rc_menuitem *mi;
@@ -1990,7 +2010,8 @@ res_to_bin_menuitems (windres_bfd *wrbfd, rc_uint_type off, const rc_menuitem *i
/* Convert menuex items to binary. */
static rc_uint_type
-res_to_bin_menuexitems (windres_bfd *wrbfd, rc_uint_type off, const rc_menuitem *items)
+res_to_bin_menuexitems (windres_bfd *wrbfd, rc_uint_type off,
+ const rc_menuitem *items)
{
rc_uint_type off_delta = off;
const rc_menuitem *mi;
@@ -2043,7 +2064,8 @@ res_to_bin_menuexitems (windres_bfd *wrbfd, rc_uint_type off, const rc_menuitem
to binary. */
static rc_uint_type
-res_to_bin_rcdata (windres_bfd *wrbfd, rc_uint_type off, const rc_rcdata_item *items)
+res_to_bin_rcdata (windres_bfd *wrbfd, rc_uint_type off,
+ const rc_rcdata_item *items)
{
const rc_rcdata_item *ri;
@@ -2089,9 +2111,10 @@ res_to_bin_rcdata (windres_bfd *wrbfd, rc_uint_type off, const rc_rcdata_item *i
{
rc_uint_type i;
- hp = (bfd_byte *) reswr_alloc (len);
+ hp = reswr_alloc (len);
for (i = 0; i < ri->u.wstring.length; i++)
- windres_put_16 (wrbfd, hp + i * sizeof (unichar), ri->u.wstring.w[i]);
+ windres_put_16 (wrbfd, hp + i * sizeof (unichar),
+ ri->u.wstring.w[i]);
}
break;
case RCDATA_BUFFER:
@@ -2128,7 +2151,7 @@ res_to_bin_stringtable (windres_bfd *wrbfd, rc_uint_type off,
bfd_byte *hp;
rc_uint_type j;
- hp = (bfd_byte *) reswr_alloc (length);
+ hp = reswr_alloc (length);
windres_put_16 (wrbfd, hp, slen);
for (j = 0; j < slen; j++)
@@ -2155,7 +2178,7 @@ string_to_unicode_bin (windres_bfd *wrbfd, rc_uint_type off, const char *s)
rc_uint_type i;
bfd_byte *hp;
- hp = (bfd_byte *) reswr_alloc ((len + 1) * sizeof (unichar));
+ hp = reswr_alloc ((len + 1) * sizeof (unichar));
for (i = 0; i < len; i++)
windres_put_16 (wrbfd, hp + i * 2, s[i]);
@@ -2182,7 +2205,7 @@ res_to_bin_toolbar (windres_bfd *wrbfd, rc_uint_type off, rc_toolbar *tb)
bfd_byte *ids;
rc_uint_type i = 0;
- ids = (bfd_byte *) reswr_alloc (tb->nitems * 4);
+ ids = reswr_alloc (tb->nitems * 4);
it=tb->items;
while(it != NULL)
{
@@ -2221,7 +2244,7 @@ res_to_bin_versioninfo (windres_bfd *wrbfd, rc_uint_type off,
struct bin_fixed_versioninfo bfv;
const rc_fixed_versioninfo *fi;
- fi = versioninfo->fixed;
+ fi = versioninfo->fixed;
windres_put_32 (wrbfd, bfv.sig1, 0xfeef04bd);
windres_put_32 (wrbfd, bfv.sig2, 0x10000);
windres_put_32 (wrbfd, bfv.file_version, fi->file_version_ms);
@@ -2348,13 +2371,13 @@ res_to_bin_versioninfo (windres_bfd *wrbfd, rc_uint_type off,
off += 4;
}
if (wrbfd)
- {
+ {
windres_put_16 (wrbfd, bvvd.size, off - vvd_off);
windres_put_16 (wrbfd, bvvd.sig1, off - vvvd_off);
windres_put_16 (wrbfd, bvvd.sig2, 0);
set_windres_bfd_content (wrbfd, &bvvd, vvd_off,
BIN_VER_INFO_SIZE);
- }
+ }
break;
}
@@ -2375,7 +2398,7 @@ res_to_bin_versioninfo (windres_bfd *wrbfd, rc_uint_type off,
windres_put_16 (wrbfd, bvi.size, off - start);
windres_put_16 (wrbfd, bvi.fixed_size,
versioninfo->fixed == NULL ? 0
- : BIN_FIXED_VERSIONINFO_SIZE);
+ : BIN_FIXED_VERSIONINFO_SIZE);
windres_put_16 (wrbfd, bvi.sig2, 0);
set_windres_bfd_content (wrbfd, &bvi, start, BIN_VER_INFO_SIZE);
}
diff --git a/binutils/rescoff.c b/binutils/rescoff.c
index 98e5eb0..6031602 100644
--- a/binutils/rescoff.c
+++ b/binutils/rescoff.c
@@ -138,12 +138,14 @@ read_coff_rsrc (const char *filename, const char *target)
if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
list_matching_formats (matching);
free (matching);
+ bfd_close (abfd);
return NULL;
}
if (bfd_get_flavour (abfd) != bfd_target_coff_flavour
|| !obj_pe (abfd))
{
non_fatal (_("%s: not a PE file"), filename);
+ bfd_close (abfd);
return NULL;
}
@@ -151,6 +153,7 @@ read_coff_rsrc (const char *filename, const char *target)
if (sec == NULL)
{
non_fatal (_("%s: no resource section"), filename);
+ bfd_close (abfd);
return NULL;
}
@@ -163,6 +166,7 @@ read_coff_rsrc (const char *filename, const char *target)
if (size > (bfd_size_type) get_file_size (filename))
{
non_fatal (_("%s: .rsrc section is bigger than the file!"), filename);
+ bfd_close (abfd);
return NULL;
}
@@ -218,7 +222,8 @@ read_coff_res_dir (windres_bfd *wrbfd, const bfd_byte *data,
return NULL;
}
- if ((size_t) (flaginfo->data_end - data) < sizeof (struct extern_res_directory))
+ size_t data_len = flaginfo->data_end - data;
+ if (data_len < sizeof (struct extern_res_directory))
{
overrun (flaginfo, _("directory"));
return NULL;
@@ -249,7 +254,8 @@ read_coff_res_dir (windres_bfd *wrbfd, const bfd_byte *data,
const bfd_byte *ers;
int length, j;
- if ((const bfd_byte *) ere >= flaginfo->data_end)
+ if ((const bfd_byte *) ere > flaginfo->data_end
+ || flaginfo->data_end - (const bfd_byte *) ere < 8)
{
overrun (flaginfo, _("named directory entry"));
return NULL;
@@ -261,31 +267,32 @@ read_coff_res_dir (windres_bfd *wrbfd, const bfd_byte *data,
/* For some reason the high bit in NAME is set. */
name &=~ 0x80000000;
- if (name > (rc_uint_type) (flaginfo->data_end - flaginfo->data))
+ if (name > data_len)
{
overrun (flaginfo, _("directory entry name"));
return NULL;
}
ers = flaginfo->data + name;
-
+ if (flaginfo->data_end - ers < 2)
+ {
+ overrun (flaginfo, _("resource name"));
+ return NULL;
+ }
+ length = windres_get_16 (wrbfd, ers, 2);
+ /* PR 17512: file: 05dc4a16. */
+ if (length * 2 + 4 > flaginfo->data_end - ers)
+ {
+ overrun (flaginfo, _("resource name"));
+ return NULL;
+ }
re = (rc_res_entry *) res_alloc (sizeof *re);
re->next = NULL;
re->id.named = 1;
- length = windres_get_16 (wrbfd, ers, 2);
re->id.u.n.length = length;
re->id.u.n.name = (unichar *) res_alloc (length * sizeof (unichar));
for (j = 0; j < length; j++)
- {
- /* PR 17512: file: 05dc4a16. */
- if (length < 0 || ers >= flaginfo->data_end
- || ers + j * 2 + 4 >= flaginfo->data_end)
- {
- overrun (flaginfo, _("resource name"));
- return NULL;
- }
- re->id.u.n.name[j] = windres_get_16 (wrbfd, ers + j * 2 + 2, 2);
- }
+ re->id.u.n.name[j] = windres_get_16 (wrbfd, ers + j * 2 + 2, 2);
if (level == 0)
type = &re->id;
@@ -293,24 +300,25 @@ read_coff_res_dir (windres_bfd *wrbfd, const bfd_byte *data,
if ((rva & 0x80000000) != 0)
{
rva &=~ 0x80000000;
- if (rva >= (rc_uint_type) (flaginfo->data_end - flaginfo->data))
+ if (rva >= data_len)
{
overrun (flaginfo, _("named subdirectory"));
return NULL;
}
re->subdir = 1;
- re->u.dir = read_coff_res_dir (wrbfd, flaginfo->data + rva, flaginfo, type,
- level + 1);
+ re->u.dir = read_coff_res_dir (wrbfd, flaginfo->data + rva, flaginfo,
+ type, level + 1);
}
else
{
- if (rva >= (rc_uint_type) (flaginfo->data_end - flaginfo->data))
+ if (rva >= data_len)
{
overrun (flaginfo, _("named resource"));
return NULL;
}
re->subdir = 0;
- re->u.res = read_coff_data_entry (wrbfd, flaginfo->data + rva, flaginfo, type);
+ re->u.res = read_coff_data_entry (wrbfd, flaginfo->data + rva,
+ flaginfo, type);
}
*pp = re;
@@ -322,7 +330,8 @@ read_coff_res_dir (windres_bfd *wrbfd, const bfd_byte *data,
unsigned long name, rva;
rc_res_entry *re;
- if ((const bfd_byte *) ere >= flaginfo->data_end)
+ if ((const bfd_byte *) ere > flaginfo->data_end
+ || flaginfo->data_end - (const bfd_byte *) ere < 8)
{
overrun (flaginfo, _("ID directory entry"));
return NULL;
@@ -342,24 +351,25 @@ read_coff_res_dir (windres_bfd *wrbfd, const bfd_byte *data,
if ((rva & 0x80000000) != 0)
{
rva &=~ 0x80000000;
- if (rva >= (rc_uint_type) (flaginfo->data_end - flaginfo->data))
+ if (rva >= data_len)
{
overrun (flaginfo, _("ID subdirectory"));
return NULL;
}
re->subdir = 1;
- re->u.dir = read_coff_res_dir (wrbfd, flaginfo->data + rva, flaginfo, type,
- level + 1);
+ re->u.dir = read_coff_res_dir (wrbfd, flaginfo->data + rva, flaginfo,
+ type, level + 1);
}
else
{
- if (rva >= (rc_uint_type) (flaginfo->data_end - flaginfo->data))
+ if (rva >= data_len)
{
overrun (flaginfo, _("ID resource"));
return NULL;
}
re->subdir = 0;
- re->u.res = read_coff_data_entry (wrbfd, flaginfo->data + rva, flaginfo, type);
+ re->u.res = read_coff_data_entry (wrbfd, flaginfo->data + rva,
+ flaginfo, type);
}
*pp = re;
@@ -522,6 +532,7 @@ write_coff_file (const char *filename, const char *target,
if (! bfd_set_format (abfd, bfd_object))
{
bfd_nonfatal ("bfd_set_format");
+ bfd_close_all_done (abfd);
return false;
}
@@ -529,24 +540,28 @@ write_coff_file (const char *filename, const char *target,
if (! bfd_set_arch_mach (abfd, bfd_arch_sh, 0))
{
bfd_nonfatal ("bfd_set_arch_mach(sh)");
+ bfd_close_all_done (abfd);
return false;
}
#elif defined DLLTOOL_MIPS
if (! bfd_set_arch_mach (abfd, bfd_arch_mips, 0))
{
bfd_nonfatal ("bfd_set_arch_mach(mips)");
+ bfd_close_all_done (abfd);
return false;
}
#elif defined DLLTOOL_ARM
if (! bfd_set_arch_mach (abfd, bfd_arch_arm, 0))
{
bfd_nonfatal ("bfd_set_arch_mach(arm)");
+ bfd_close_all_done (abfd);
return false;
}
#elif defined DLLTOOL_AARCH64
if (! bfd_set_arch_mach (abfd, bfd_arch_aarch64, 0))
{
bfd_nonfatal ("bfd_set_arch_mach(aarch64)");
+ bfd_close_all_done (abfd);
return false;
}
#else
@@ -554,6 +569,7 @@ write_coff_file (const char *filename, const char *target,
if (! bfd_set_arch_mach (abfd, bfd_arch_i386, 0))
{
bfd_nonfatal ("bfd_set_arch_mach(i386)");
+ bfd_close_all_done (abfd);
return false;
}
#endif
@@ -561,6 +577,7 @@ write_coff_file (const char *filename, const char *target,
if (! bfd_set_file_flags (abfd, HAS_SYMS | HAS_RELOC))
{
bfd_nonfatal ("bfd_set_file_flags");
+ bfd_close_all_done (abfd);
return false;
}
@@ -570,12 +587,14 @@ write_coff_file (const char *filename, const char *target,
if (sec == NULL)
{
bfd_nonfatal ("bfd_make_section");
+ bfd_close_all_done (abfd);
return false;
}
if (! bfd_set_symtab (abfd, &sec->symbol, 1))
{
bfd_nonfatal ("bfd_set_symtab");
+ bfd_close_all_done (abfd);
return false;
}
@@ -622,7 +641,11 @@ write_coff_file (const char *filename, const char *target,
/* Actually convert the resources to binary. */
if (!coff_to_bin (resources, &cwi))
- return false;
+ {
+ bfd_close_all_done (abfd);
+ free (cwi.relocs);
+ return false;
+ }
/* Add another few bytes to the directory strings if needed for
alignment. */
@@ -649,6 +672,8 @@ write_coff_file (const char *filename, const char *target,
if (!bfd_set_section_size (sec, length))
{
bfd_nonfatal ("bfd_set_section_size");
+ bfd_close_all_done (abfd);
+ free (cwi.relocs);
return false;
}
@@ -660,6 +685,8 @@ write_coff_file (const char *filename, const char *target,
if (! bfd_set_section_contents (abfd, sec, d->data, offset, d->length))
{
bfd_nonfatal ("bfd_set_section_contents");
+ bfd_close_all_done (abfd);
+ free (cwi.relocs);
return false;
}
offset += d->length;
@@ -678,7 +705,11 @@ write_coff_file (const char *filename, const char *target,
{
if (res_to_bin (cwi.wrbfd, (rc_uint_type) offset, rd->res)
== (rc_uint_type) -1)
- return false;
+ {
+ bfd_close_all_done (abfd);
+ free (cwi.relocs);
+ return false;
+ }
offset += rd->length;
}
@@ -687,6 +718,7 @@ write_coff_file (const char *filename, const char *target,
if (! bfd_close (abfd))
{
bfd_nonfatal ("bfd_close");
+ free (cwi.relocs);
return false;
}