diff options
author | Alan Modra <amodra@gmail.com> | 2021-09-02 09:04:52 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2021-09-02 13:48:21 +0930 |
commit | 36f61bf2ad936edfb76eda706eb3b081a61d5a5a (patch) | |
tree | e8eac96abd2209a4b3e23dae781487f53352f056 /bfd/elf-eh-frame.c | |
parent | 76aa354424729aafdabdf4929aa9751c6fdee081 (diff) | |
download | binutils-36f61bf2ad936edfb76eda706eb3b081a61d5a5a.zip binutils-36f61bf2ad936edfb76eda706eb3b081a61d5a5a.tar.gz binutils-36f61bf2ad936edfb76eda706eb3b081a61d5a5a.tar.bz2 |
PTR_ADD and NPTR_ADD for bfd.h
This defines a couple of macros used to avoid ubsan complaints about
calculations involving NULL pointers. PTR_ADD should be used in the
case where it is known that the offset is always zero with a NULL
pointer, and you'd like to know if a non-zero offset is ever used.
NPTR_ADD should be rarely used, but is defined for cases where a
non-zero offset is expected and should be ignored if the pointer is
NULL.
bfd/
* bfd-in.h (PTR_ADD, NPTR_ADD): Define.
* bfd-in2.h: Regenerate.
* elf-eh-frame.c (adjust_eh_frame_local_symbols): Avoid NULL
pointer calculations.
* elflink.c (_bfd_elf_strip_zero_sized_dynamic_sections): Likewise.
(bfd_elf_add_dt_needed_tag, elf_finalize_dynstr): Likewise.
(elf_link_add_object_symbols, elf_link_input_bfd): Likewise.
(bfd_elf_final_link, bfd_elf_gc_record_vtinherit): Likewise.
binutils/
* objdump.c (disassemble_section): Use PTR_ADD for rel_ppend.
Diffstat (limited to 'bfd/elf-eh-frame.c')
-rw-r--r-- | bfd/elf-eh-frame.c | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/bfd/elf-eh-frame.c b/bfd/elf-eh-frame.c index 6ce6d22..b5ec814 100644 --- a/bfd/elf-eh-frame.c +++ b/bfd/elf-eh-frame.c @@ -1440,25 +1440,27 @@ static int adjust_eh_frame_local_symbols (const asection *sec, struct elf_reloc_cookie *cookie) { - unsigned int shndx; - Elf_Internal_Sym *sym; - Elf_Internal_Sym *end_sym; int adjusted = 0; - shndx = elf_section_data (sec)->this_idx; - end_sym = cookie->locsyms + cookie->locsymcount; - for (sym = cookie->locsyms + 1; sym < end_sym; ++sym) - if (sym->st_info <= ELF_ST_INFO (STB_LOCAL, STT_OBJECT) - && sym->st_shndx == shndx) - { - bfd_signed_vma delta = offset_adjust (sym->st_value, sec); + if (cookie->locsymcount > 1) + { + unsigned int shndx = elf_section_data (sec)->this_idx; + Elf_Internal_Sym *end_sym = cookie->locsyms + cookie->locsymcount; + Elf_Internal_Sym *sym; - if (delta != 0) + for (sym = cookie->locsyms + 1; sym < end_sym; ++sym) + if (sym->st_info <= ELF_ST_INFO (STB_LOCAL, STT_OBJECT) + && sym->st_shndx == shndx) { - adjusted = 1; - sym->st_value += delta; + bfd_signed_vma delta = offset_adjust (sym->st_value, sec); + + if (delta != 0) + { + adjusted = 1; + sym->st_value += delta; + } } - } + } return adjusted; } |