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]

[PATCH] add user_phdrs flag to bfd_link_info


My target's hooks fiddle the layout and PHDRS normally.
But they shouldn't do that when the linker script gave explicit PHDRS.
There didn't seem to be any way for them to know whether the segment map
had come from an explicit PHDRS or from the implicit logic.  The simplest
fix seemed to be to add the flag to struct bfd_link_info.

Ok for trunk?


Thanks,
Roland


bfd/
2012-04-06  Roland McGrath  <mcgrathr@google.com>

	* elf.c (_bfd_elf_map_sections_to_segments): Set INFO->user_phdrs.
	* elf-nacl.c (nacl_modify_segment_map): Do nothing if INFO->user_phdrs.
	(nacl_modify_program_headers): Likewise.

include/
2012-04-06  Roland McGrath  <mcgrathr@google.com>

	* bfdlink.h (struct bfd_link_info): Add new member user_phdrs.

diff --git a/bfd/elf-nacl.c b/bfd/elf-nacl.c
index 3ba7f55..842e367 100644
--- a/bfd/elf-nacl.c
+++ b/bfd/elf-nacl.c
@@ -62,13 +62,18 @@ segment_nonexecutable_and_has_contents (struct elf_segment_map *seg)
    The first non-executable PT_LOAD segment appears first in the file
    and contains the ELF file header and phdrs.  */
 bfd_boolean
-nacl_modify_segment_map (bfd *abfd, struct bfd_link_info *info ATTRIBUTE_UNUSED)
+nacl_modify_segment_map (bfd *abfd, struct bfd_link_info *info)
 {
   struct elf_segment_map **m = &elf_tdata (abfd)->segment_map;
   struct elf_segment_map **first_load = NULL;
   struct elf_segment_map **last_load = NULL;
   bfd_boolean moved_headers = FALSE;
 
+  if (info != NULL && info->user_phdrs)
+    /* The linker script used PHDRS explicitly, so don't change what the
+       user asked for.  */
+    return TRUE;
+
   while (*m != NULL)
     {
       struct elf_segment_map *seg = *m;
@@ -141,6 +146,11 @@ nacl_modify_program_headers (bfd *abfd,
   Elf_Internal_Phdr *phdr = elf_tdata (abfd)->phdr;
   Elf_Internal_Phdr *p = phdr;
 
+  if (info != NULL && info->user_phdrs)
+    /* The linker script used PHDRS explicitly, so don't change what the
+       user asked for.  */
+    return TRUE;
+
   /* Find the PT_LOAD that contains the headers (should be the first).  */
   while (*m != NULL)
     {
diff --git a/bfd/elf.c b/bfd/elf.c
index df43a6a..7faa8f6 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -3744,6 +3744,10 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info)
   bfd_boolean no_user_phdrs;
 
   no_user_phdrs = elf_tdata (abfd)->segment_map == NULL;
+
+  if (info != NULL)
+    info->user_phdrs = !no_user_phdrs;
+
   if (no_user_phdrs && bfd_count_sections (abfd) != 0)
     {
       asection *s;
diff --git a/include/bfdlink.h b/include/bfdlink.h
index c79d8f0..d900b47 100644
--- a/include/bfdlink.h
+++ b/include/bfdlink.h
@@ -405,6 +405,9 @@ struct bfd_link_info
   /* TRUE if we should warn alternate ELF machine code.  */
   unsigned int warn_alternate_em: 1;
 
+  /* TRUE if the linker script contained an explicit PHDRS command.  */
+  unsigned int user_phdrs: 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.  */


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