[PATCH] Use ELF_SECTION_IN_SEGMENT to map segments
Tue May 22 14:15:00 GMT 2018
On 05/22/2018 12:00 PM, Alan Hayward wrote:
> The macro ELF_SECTION_IN_SEGMENT should be used when calculating if
> a section maps to a segment.
> The binutils patch "[PATCH] Use offsets instead of addresses in
> ELF_SECTION_IN_SEGMENT" makes further improvements to the macro.
> When the two patches are combined, this will allow GDB to be used
> to debug Arm baremetal binaries produced by the Arm Compiler. See
> the binutils patch for further details.
> Regardless of Arm debugging, this patch reduces code/logic duplication
> in gdb.
> --- a/gdb/elfread.c
> +++ b/gdb/elfread.c
> @@ -120,17 +120,13 @@ elf_symfile_segments (bfd *abfd)
> for (i = 0, sect = abfd->sections; sect != NULL; i++, sect = sect->next)
> int j;
> - CORE_ADDR vma;
> + Elf_Internal_Shdr *this_hdr = &(elf_section_data (sect)->this_hdr);
Drop unnecessary parens.
You could defer this call until after the SEC_ALLOC check.
> if ((bfd_get_section_flags (abfd, sect) & SEC_ALLOC) == 0)
> - vma = bfd_get_section_vma (abfd, sect);
> for (j = 0; j < num_segments; j++)
> - if (segments[j]->p_memsz > 0
> - && vma >= segments[j]->p_vaddr
> - && (vma - segments[j]->p_vaddr) < segments[j]->p_memsz)
> + if ELF_SECTION_IN_SEGMENT (this_hdr, segments[j])
That is some odd-looking C/C++ code, for assuming the macro's
internals are wrapped in parens. Please write the more usual:
if (ELF_SECTION_IN_SEGMENT (this_hdr, segments[j]))
OK with those fixed.
More information about the Gdb-patches