]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Account for .tbss alignment when adjusting start of relro
authorAlan Modra <amodra@gmail.com>
Thu, 19 Nov 2015 04:30:13 +0000 (15:00 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 19 Nov 2015 05:52:25 +0000 (16:22 +1030)
Another option might be to not bump "dot" for .tbss alignment in the
main section sizing loop, but that could leak some of the following
section into the TLS segment.  Leakage shouldn't matter since it will
be to bytes past the end of .tdata, but for now this is a safer
option.

PR ld/19264
* ldlang.c (lang_size_sections): Don't ignore .tbss when
adjusting start of relro region.

ld/ChangeLog
ld/ldlang.c

index d4324ec6d50532af07cc1c857dfdb943aa6889de..d6bf9ab7bf850f476c46d1f4c5b658b13e09aa3c 100644 (file)
@@ -1,3 +1,9 @@
+2015-11-19  Alan Modra  <amodra@gmail.com>
+
+       PR ld/19264
+       * ldlang.c (lang_size_sections): Don't ignore .tbss when
+       adjusting start of relro region.
+
 2015-11-16  Nick Clifton  <nickc@redhat.com>
 
        PR ld/19106
index 3841afc75f8400912cbe5d05b1894d4abcf25d93..c45b9128f43543f77f91b6ffc4bad56d760dbc00 100644 (file)
@@ -5457,18 +5457,23 @@ lang_size_sections (bfd_boolean *relax, bfd_boolean check_regions)
 
       /* For sections in the relro segment..  */
       for (sec = link_info.output_bfd->section_last; sec; sec = sec->prev)
-       if (!IGNORE_SECTION (sec)
+       if ((sec->flags & SEC_ALLOC) != 0
            && sec->vma >= expld.dataseg.base
            && sec->vma < expld.dataseg.relro_end - expld.dataseg.relro_offset)
          {
            /* Where do we want to put this section so that it ends as
               desired?  */
-           bfd_vma start = sec->vma;
-           bfd_vma end = start + sec->size;
-           bfd_vma bump = desired_end - end;
+           bfd_vma start, end, bump;
+
+           end = start = sec->vma;
+           if ((sec->flags & SEC_HAS_CONTENTS) != 0
+               || (sec->flags & SEC_THREAD_LOCAL) == 0)
+             end += sec->size;
+           bump = desired_end - end;
            /* We'd like to increase START by BUMP, but we must heed
               alignment so the increase might be less than optimum.  */
-           start += bump & ~(((bfd_vma) 1 << sec->alignment_power) - 1);
+           start += bump;
+           start &= ~(((bfd_vma) 1 << sec->alignment_power) - 1);
            /* This is now the desired end for the previous section.  */
            desired_end = start;
          }