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]

Re: [PATCH] PR ld/15365: Restrict __ehdr_start's export class (was: RE: [COMMITTED PATCH] Use __ehdr_start, if available, as fallback for AT_PHDR.)


On Wed, Apr 24, 2013 at 10:48:53PM +0100, Maciej W. Rozycki wrote:
> @@ -1488,6 +1488,29 @@ gld${EMULATION_NAME}_before_allocation (
>       referred to by dynamic objects.  */
>    lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);
>  
> +  /* The magic __ehdr_start symbol needs to have its export class restricted
> +     at least to hidden.  Force it now rather than when the symbol is defined
> +     in assign_file_positions_for_non_load_sections, because it is too late
> +     there and by then backends may have already arranged for the symbol to
> +     have a global scope as with the default export class.  */
> +  if (!link_info.relocatable)
> +    {
> +      struct elf_link_hash_entry *h;
> +
> +      h = elf_link_hash_lookup (elf_hash_table (&link_info), "__ehdr_start",
> +				FALSE, FALSE, TRUE);
> +
> +      /* Only adjust the export class if the symbol was referenced and not
> +         defined, otherwise leave it alone.  */
> +      if (h != NULL
> +	  && (h->root.type == bfd_link_hash_new
> +	      || h->root.type == bfd_link_hash_undefined
> +	      || h->root.type == bfd_link_hash_undefweak
> +	      || h->root.type == bfd_link_hash_common)
> +	  && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL)
> +	h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN;
> +    }
> +

You need to check link_info.hash->type == bfd_link_elf_hash_table
here.  If fact I think you could use bfd_elf_record_link_assignment
to make __ehdr_start hidden, as follows.  If this passes testing then
please commit.  Oh, and a bonus point if you fix
bfd_elf_record_link_assignment to not turn STV_INTERNAL into
STV_HIDDEN.

Index: ld/emultempl/elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.242
diff -u -p -r1.242 elf32.em
--- ld/emultempl/elf32.em	4 Apr 2013 14:38:47 -0000	1.242
+++ ld/emultempl/elf32.em	25 Apr 2013 00:30:13 -0000
@@ -1481,12 +1484,21 @@ gld${EMULATION_NAME}_before_allocation (
   bfd *abfd;
 
   if (link_info.hash->type == bfd_link_elf_hash_table)
-    _bfd_elf_tls_setup (link_info.output_bfd, &link_info);
+    {
+      _bfd_elf_tls_setup (link_info.output_bfd, &link_info);
 
-  /* If we are going to make any variable assignments, we need to let
-     the ELF backend know about them in case the variables are
-     referred to by dynamic objects.  */
-  lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);
+      /* Make __ehdr_start hidden if it has been referenced, to
+	 prevent the symbol from being dynamic.  */
+      if (!bfd_elf_record_link_assignment (link_info.output_bfd, &link_info,
+					   "__ehdr_start", TRUE, TRUE))
+	einfo ("%P%F: failed to record assignment to %s: %E\n",
+	       "__ehdr_start");
+
+      /* If we are going to make any variable assignments, we need to
+	 let the ELF backend know about them in case the variables are
+	 referred to by dynamic objects.  */
+      lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);
+    }
 
   /* Let the ELF backend work out the sizes of any sections required
      by dynamic linking.  */

-- 
Alan Modra
Australia Development Lab, IBM


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