[RFC PATCH] avoid intermingling executable and nonexecutable sections in a segment

Roland McGrath mcgrathr@google.com
Wed Nov 21 00:15:00 GMT 2012


Assuming HJ meant what I thought he meant, here is that version of the
change.  It does seem cleaner than a separate global.  It still doesn't
seem like a clean place to set the flag, but I don't know where else would
be better.


Thanks,
Roland


include/
	* bfdlink.h (struct bfd_link_info): New flag member `separate_code'.

ld/
	* ldlang.c (ldlang_override_segment_assignment):
	If INFO->separate_code is set, then always return TRUE when
	SEC_CODE differs between the sections.
	* emultempl/elf32.em
	(gld${EMULATION_NAME}_after_open) [$SEPARATE_CODE = yes]:
	Set link_info.separate_code.

--- a/include/bfdlink.h
+++ b/include/bfdlink.h
@@ -1,6 +1,6 @@
 /* bfdlink.h -- header file for BFD link routines
    Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-   2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+   2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
    Written by Steve Chamberlain and Ian Lance Taylor, Cygnus Support.

@@ -408,6 +408,9 @@ struct bfd_link_info
   /* TRUE if the linker script contained an explicit PHDRS command.  */
   unsigned int user_phdrs: 1;

+  /* TRUE if code and non-code sections should never be in one segment.  */
+  unsigned int separate_code: 1;
+
   /* Char that may appear as the first char of a symbol, but should be
      skipped (like symbol_leading_char) when looking up symbols in
      wrap_hash.  Used by PowerPC Linux for 'dot' symbols.  */
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -1061,6 +1061,14 @@ gld${EMULATION_NAME}_after_open (void)
   struct elf_link_hash_table *htab;

   after_open_default ();
+EOF
+if [ "x${SEPARATE_CODE}" = xyes ] ; then
+fragment <<EOF
+
+  link_info.separate_code = TRUE;
+EOF
+fi
+fragment <<EOF

   htab = elf_hash_table (&link_info);
   if (!is_elf_hash_table (htab))
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -5343,7 +5343,7 @@ lang_size_sections_1
    segments.  We are allowed an opportunity to override this decision.  */

 bfd_boolean
-ldlang_override_segment_assignment (struct bfd_link_info * info
ATTRIBUTE_UNUSED,
+ldlang_override_segment_assignment (struct bfd_link_info *info,
 				    bfd * abfd ATTRIBUTE_UNUSED,
 				    asection * current_section,
 				    asection * previous_section,
@@ -5361,6 +5361,12 @@ ldlang_override_segment_assignment (struct
bfd_link_info * info ATTRIBUTE_UNUSED
   if (current_section == NULL || previous_section == NULL)
     return new_segment;

+  /* If this flag is set, the target never wants code and non-code
+     sections comingled in the same segment.  */
+  if (info->separate_code
+      && ((current_section->flags ^ previous_section->flags) & SEC_CODE))
+    return TRUE;
+
   /* Find the memory regions associated with the two sections.
      We call lang_output_section_find() here rather than scanning the list
      of output sections looking for a matching section pointer because if



More information about the Binutils mailing list