This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch] ld: check for address space overflow


On Fri, Mar 10, 2017 at 6:29 AM, Tristan Gingold <gingold@adacore.com> wrote:
> Hello,
>
> currently the linker allows to put a section which starts near the end of the address space and which ends past the end (so wrap around).  I think this should be flagged as an error.
>
> No regression on powerpc-elf
>
> Ok for master ?
>
> Tristan.
>
> commit 09718888d36a07cc9c71aa301a39a4299dbf8c34
> Author: Tristan Gingold <gingold@adacore.com>
> Date:   Fri Mar 10 15:16:19 2017 +0100
>
>     ld: add an error in case of address space overflow.
>
>     ld/
>         * ldlang.c (lang_check_section_addresses): Check for address space
>         overflow.
>         * testsuite/ld-checks/checks.exp (overflow_check): New procedure
>         * testsuite/ld-checks/over.s: New test source.
>         * testsuite/ld-checks/over.d: New test.
>         * testsuite/ld-checks/over2.s: New test source.
>         * testsuite/ld-checks/over2.d: New test.
>
> diff --git a/ld/ChangeLog b/ld/ChangeLog
> index 3883bcb..5387210 100644
> --- a/ld/ChangeLog
> +++ b/ld/ChangeLog
> @@ -1,3 +1,13 @@
> +2017-03-10  Tristan Gingold  <gingold@adacore.com>
> +
> +       * ldlang.c (lang_check_section_addresses): Check for address space
> +       overflow.
> +       * testsuite/ld-checks/checks.exp (overflow_check): New procedure
> +       * testsuite/ld-checks/over.s: New test source.
> +       * testsuite/ld-checks/over.d: New test.
> +       * testsuite/ld-checks/over2.s: New test source.
> +       * testsuite/ld-checks/over2.d: New test.
> +
>  2017-03-07  Alan Modra  <amodra@gmail.com>
>
>         * ldlang.c (open_input_bfds): Check that lang_assignment_statement
> diff --git a/ld/ldlang.c b/ld/ldlang.c
> index ff6ef39..36b6884 100644
> --- a/ld/ldlang.c
> +++ b/ld/ldlang.c
> @@ -4768,6 +4768,7 @@ lang_check_section_addresses (void)
>    asection *s, *p;
>    struct check_sec *sections;
>    size_t i, count;
> +  bfd_vma addr_mask;
>    bfd_vma s_start;
>    bfd_vma s_end;
>    bfd_vma p_start = 0;
> @@ -4775,6 +4776,25 @@ lang_check_section_addresses (void)
>    lang_memory_region_type *m;
>    bfd_boolean overlays;
>
> +  /* Detect address space overflow.  */
> +  addr_mask = ((bfd_vma) 1 <<
> +              (bfd_arch_bits_per_address (link_info.output_bfd) - 1)) - 1;

This isn't correct.  See is32bit () in bfd.c.  And it doesn't work
for -0x80000000 with 64-bit VMA for 32-bit targets.

> +  addr_mask = (addr_mask << 1) + 1;
> +  for (s = link_info.output_bfd->sections; s != NULL; s = s->next)
> +    {
> +      s_end = (s->vma + s->size) & addr_mask;
> +      if (s_end != 0 && s_end < s->vma)
> +       einfo (_("%X%P: section %s VMA wraps around address space\n"),
> +              s->name);
> +      else
> +       {
> +         s_end = (s->lma + s->size) & addr_mask;
> +         if (s_end != 0 && s_end < s->lma)
> +           einfo (_("%X%P: section %s LMA wraps around address space\n"),
> +                  s->name);
> +       }
> +    }
> +
>    if (bfd_count_sections (link_info.output_bfd) <= 1)
>      return;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]