Prevent the linker from overestimating the alignment requirement of common symbols...
authorTuckker <tuckkern+sourceware@gmail.com>
Fri, 28 Aug 2020 12:27:16 +0000 (13:27 +0100)
committerNick Clifton <nickc@redhat.com>
Fri, 28 Aug 2020 12:27:16 +0000 (13:27 +0100)
PR 26543
* linker.c (bfd_generic_define_common_symbol): Force the alignment
to 1 if the section has now alignment requirement.

bfd/ChangeLog
bfd/linker.c

index 6fa6ee0f316b9f83b09bd3c12184fd18377b0e40..bf082fc4cb63f885063f9b948cb291d2600f5580 100644 (file)
@@ -1,3 +1,9 @@
+2020-08-28  Tuckker  <tuckkern+sourceware@gmail.com>
+
+       PR 26543
+       * linker.c (bfd_generic_define_common_symbol): Force the alignment
+       to 1 if the section has now alignment requirement.
+
 2020-08-28  Cooper Qu  <cooper.qu@linux.alibaba.com>
 
        * elf32-csky.c (csky_archs): Fix arch names.
index d4057461a3f4a358f138f3d1b74694160e3c553a..1357168456867148ac8b8ef47fe64f90f13a0c21 100644 (file)
@@ -3095,8 +3095,13 @@ bfd_generic_define_common_symbol (bfd *output_bfd,
   section = h->u.c.p->section;
 
   /* Increase the size of the section to align the common symbol.
-     The alignment must be a power of two.  */
-  alignment = bfd_octets_per_byte (output_bfd, section) << power_of_two;
+     The alignment must be a power of two.  But if the section does
+     not have any alignment requirement then do not increase the
+     alignment unnecessarily.  */
+  if (power_of_two)
+    alignment = bfd_octets_per_byte (output_bfd, section) << power_of_two;
+  else
+    alignment = 1;
   BFD_ASSERT (alignment != 0 && (alignment & -alignment) == alignment);
   section->size += alignment - 1;
   section->size &= -alignment;