diff options
author | Alan Modra <amodra@gmail.com> | 2023-09-19 09:39:31 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2023-09-20 08:23:47 +0930 |
commit | a1d1634d0012ddeecc59bb0e6012d4455edae6e8 (patch) | |
tree | ba213a2d27da84a2ec41bc2a1e7fc6ac23730131 /gas/config/tc-riscv.c | |
parent | a56e5dce69bfad45ee6977a916ccea283e087e8b (diff) | |
download | binutils-a1d1634d0012ddeecc59bb0e6012d4455edae6e8.zip binutils-a1d1634d0012ddeecc59bb0e6012d4455edae6e8.tar.gz binutils-a1d1634d0012ddeecc59bb0e6012d4455edae6e8.tar.bz2 |
elf-attrs.c memory allocation fail
Report errors rather than segfaulting.
bfd/
* elf-attrs.c (elf_new_obj_attr): Return NULL on bfd_alloc fail.
(bfd_elf_add_obj_attr_int): Handle NULL return from the above,
and propagate return to callers.
(elf_add_obj_attr_string, elf_add_obj_attr_int_string): Likewise.
(bfd_elf_add_obj_attr_string): Similarly.
(_bfd_elf_copy_obj_attributes): Report error on alloc fails.
(_bfd_elf_parse_attributes): Likewise.
* elf-bfd.h (bfd_elf_add_obj_attr_int): Update prototype.
(bfd_elf_add_obj_attr_string): Likewise.
(bfd_elf_add_obj_attr_int_string): Likewise.
gas/
* config/obj-elf.c (obj_elf_vendor_attribute): Report fatal
error on out of memory from bfd attribute functions.
* config/tc-arc.c (arc_set_attribute_int): Likewise.
(arc_set_attribute_string, arc_set_public_attributes): Likewise.
* config/tc-arm.c (aeabi_set_attribute_int): Likewise.
(aeabi_set_attribute_string): Likewise.
* config/tc-mips.c (mips_md_finish): Likewise.
* config/tc-msp430.c (msp430_md_finish): Likewise.
* config/tc-riscv.c (riscv_write_out_attrs): Likewise.
* config/tc-sparc.c (sparc_md_finish): Likewise.
* config/tc-tic6x.c (tic6x_set_attribute_int): Likewise.
* config/tc-csky.c (md_begin): Likewise.
(set_csky_attribute): Return ok status.
Diffstat (limited to 'gas/config/tc-riscv.c')
-rw-r--r-- | gas/config/tc-riscv.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c index 3b520ad..0b8ecf9 100644 --- a/gas/config/tc-riscv.c +++ b/gas/config/tc-riscv.c @@ -4902,7 +4902,9 @@ riscv_write_out_attrs (void) /* Re-write architecture elf attribute. */ arch_str = riscv_rps_as.subset_list->arch_str; - bfd_elf_add_proc_attr_string (stdoutput, Tag_RISCV_arch, arch_str); + if (!bfd_elf_add_proc_attr_string (stdoutput, Tag_RISCV_arch, arch_str)) + as_fatal (_("error adding attribute: %s"), + bfd_errmsg (bfd_get_error ())); /* For the file without any instruction, we don't set the default_priv_spec according to the privileged elf attributes since the md_assemble isn't @@ -4937,9 +4939,14 @@ riscv_write_out_attrs (void) versions[i] = number; /* Re-write privileged elf attributes. */ - bfd_elf_add_proc_attr_int (stdoutput, Tag_RISCV_priv_spec, versions[0]); - bfd_elf_add_proc_attr_int (stdoutput, Tag_RISCV_priv_spec_minor, versions[1]); - bfd_elf_add_proc_attr_int (stdoutput, Tag_RISCV_priv_spec_revision, versions[2]); + if (!bfd_elf_add_proc_attr_int (stdoutput, Tag_RISCV_priv_spec, + versions[0]) + || !bfd_elf_add_proc_attr_int (stdoutput, Tag_RISCV_priv_spec_minor, + versions[1]) + || !bfd_elf_add_proc_attr_int (stdoutput, Tag_RISCV_priv_spec_revision, + versions[2])) + as_fatal (_("error adding attribute: %s"), + bfd_errmsg (bfd_get_error ())); } /* Add the default contents for the .riscv.attributes section. */ |