public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* obcopy vs. files with silly section alignment
@ 2021-10-29  7:35 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2021-10-29  7:35 UTC (permalink / raw)
  To: binutils

We already ignore stupid segment alignment when rewriting headers,
ignore section alignment too.

	* elf.c (rewrite_elf_program_header): Ignore section alignment
	power greater than 62.

diff --git a/bfd/elf.c b/bfd/elf.c
index cd8280e5551..4df144b04f0 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -6953,9 +6953,14 @@ rewrite_elf_program_header (bfd *ibfd, bfd *obfd, bfd_vma maxpagesize)
    && !(SEGMENT_AFTER_SEGMENT (seg1, seg2, p_paddr)			\
 	|| SEGMENT_AFTER_SEGMENT (seg2, seg1, p_paddr)))
 
-  /* Initialise the segment mark field.  */
+  /* Initialise the segment mark field, and discard stupid alignment.  */
   for (section = ibfd->sections; section != NULL; section = section->next)
-    section->segment_mark = false;
+    {
+      asection *o = section->output_section;
+      if (o != NULL && o->alignment_power >= (sizeof (bfd_vma) * 8) - 1)
+	o->alignment_power = 0;
+      section->segment_mark = false;
+    }
 
   /* The Solaris linker creates program headers in which all the
      p_paddr fields are zero.  When we try to objcopy or strip such a

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-10-29  7:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-29  7:35 obcopy vs. files with silly section alignment Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).