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]

[1/6][PATCH] Fix PE-COFF bug in orphan section alignment handling.


    Hi list,

  Fixes a problem with orphan section alignment in the PE-COFF linker, this
was causing "ld -r" of objects containing LTO sections to break.

ld/ChangeLog:

2011-02-20  Dave Korn  <...

	* emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Preserve
	alignment of input sections when creating orphan output sections
	during relocatable link.
	* emultempl/pep.em (gld_${EMULATION_NAME}_place_orphan): Likewise.

  I could just approve and commit this myself, but since it came up as part of
developing the series I'll post it for comment anyway, in case there's perhaps
a better way to do what I want.

    cheers,
      DaveK

>From 1aefb61e70c166a04e79afba432082247bd69e77 Mon Sep 17 00:00:00 2001
From: Dave Korn <dave.korn.cygwin@gmail.com>
Date: Sat, 19 Feb 2011 23:18:55 +0000
Subject: [PATCH] Fix PE-COFF bug in orphan section alignment handling.

ld/ChangeLog:

2011-02-20  Dave Korn  <...

	* emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Preserve
	alignment of input sections when creating orphan output sections
	during relocatable link.
	* emultempl/pep.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
---
 ld/emultempl/pe.em  |    7 ++++++-
 ld/emultempl/pep.em |    7 ++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
index a3e4cdd..55041f3 100644
--- a/ld/emultempl/pe.em
+++ b/ld/emultempl/pe.em
@@ -2007,10 +2007,15 @@ gld_${EMULATION_NAME}_place_orphan (asection *s,
 		     ->output_section_statement);
 	}
 
-      /* All sections in an executable must be aligned to a page boundary.  */
+      /* All sections in an executable must be aligned to a page boundary.
+	 In a relocatable link, just preserve the incoming alignment; the
+	 address is discarded by lang_insert_orphan in that case, anyway.  */
       address = exp_unop (ALIGN_K, exp_nameop (NAME, "__section_alignment__"));
       os = lang_insert_orphan (s, secname, constraint, after, place, address,
 			       &add_child);
+      if (link_info.relocatable)
+	os->bfd_section->alignment_power = os->section_alignment
+					 = s->alignment_power;
     }
 
   /* If the section name has a '\$', sort it with the other '\$'
diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em
index a307c14..51dffff 100644
--- a/ld/emultempl/pep.em
+++ b/ld/emultempl/pep.em
@@ -1746,10 +1746,15 @@ gld_${EMULATION_NAME}_place_orphan (asection *s,
 		     ->output_section_statement);
 	}
 
-      /* All sections in an executable must be aligned to a page boundary.  */
+      /* All sections in an executable must be aligned to a page boundary.
+	 In a relocatable link, just preserve the incoming alignment; the
+	 address is discarded by lang_insert_orphan in that case, anyway.  */
       address = exp_unop (ALIGN_K, exp_nameop (NAME, "__section_alignment__"));
       os = lang_insert_orphan (s, secname, constraint, after, place, address,
 			       &add_child);
+      if (link_info.relocatable)
+	os->bfd_section->alignment_power = os->section_alignment
+					 = s->alignment_power;
     }
 
   /* If the section name has a '\$', sort it with the other '\$'

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