This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [RFC PATCH] avoid intermingling executable and nonexecutable sections in a segment
On Tue, Nov 20, 2012 at 3:01 PM, Alan Modra <amodra@gmail.com> wrote:
> Seems like you could do this much easier with a change to
> ldlang_override_segment_assignment controlled by a new global set from
> $SEPARATE_CODE.
OK, that's arguably much less kludgey. I'm not clear on where a less
kludgey place to set that global might be. How's this?
Thanks,
Roland
ld/
2012-11-20 Roland McGrath <mcgrathr@google.com>
* ldlang.c (lang_segments_separate_code): New global variable.
(ldlang_override_segment_assignment): If that's true, then
always return TRUE when SEC_CODE differs between the sections.
* ldlang.h (lang_segments_separate_code): Declare it.
* emultempl/elf32.em
(gld${EMULATION_NAME}_after_open) [$SEPARATE_CODE = yes]: Set it.
--- 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
+
+ lang_segments_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
@@ -113,6 +113,8 @@ struct lang_nocrossrefs *nocrossref_list;
DEFINED() need to increment this. */
int lang_statement_iteration = 0;
+bfd_boolean lang_segments_separate_code = FALSE;
+
etree_type *base; /* Relocation base - or null */
/* Return TRUE if the PATTERN argument is a wildcard pattern.
@@ -5361,6 +5363,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 (lang_segments_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
--- a/ld/ldlang.h
+++ b/ld/ldlang.h
@@ -487,6 +487,8 @@ extern lang_statement_list_type input_file_chain;
extern int lang_statement_iteration;
+extern bfd_boolean lang_segments_separate_code;
+
extern void lang_init
(void);
extern void lang_finish