This is the mail archive of the binutils@sources.redhat.com 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: Support ps common sections


On Fri, Jun 17, 2005 at 02:05:52PM -0700, H. J. Lu wrote:
> On Fri, Jun 17, 2005 at 03:09:49PM +0200, Jan Hubicka wrote:
> > > On Fri, Jun 17, 2005 at 11:08:52AM +0200, Jan Hubicka wrote:
> > > > 
> > > > 1) I am unsure how to get page alignment only when .lrosegment is
> > > > non-zero.  I tried to play around with SIZEOF operator but I am not sure
> > > > if I can apply SIZEOF to the alignment before .lrodata that might (in
> > > > theory) change size of .lrodata due to alignments.
> > > > 
> > > 
> > > I have implemented the similar thing for another project. I will take a
> > > look after I fix the SHN issue.
> > > 
> > > > 2) I am completely such with the SHN issue.  I've dicussed this with
> > > 
> > > I am working on it now. I will add a few functions to ELF backend to
> > > deal with it. I hope to have something very soon.
> > 
> > Thanks a lot! (I will try to cleanup the GCC part of changes in meantime.)
> 
> Here is the infrastructure patch for SHN_XXX_COMMON.
> 

Here is the updated patch. elf_fake_sections shouldn't clear sh_flags
since assembler may set additional bits.


H.J.
---
2005-06-17  H.J. Lu  <hongjiu.lu@intel.com>

	* elf-bfd.h (elf_backend_data): Add special_section,
	common_definition, common_section_index, common_section,
	and merge_symbol.
	(_bfd_elf_common_definition): New.
	(_bfd_elf_common_section_index): New.
	(_bfd_elf_common_section): New.

	* elf.c (elf_fake_sections): Don't clear sh_flags.

	* elflink.c (_bfd_elf_merge_symbol): Call backend merge_symbol
	if it is available.
	(is_global_data_symbol_definition): Call backend
	common_definition instead of checking SHN_COMMON.
	(elf_link_add_object_symbols): Likewise.
	(elf_link_output_extsym): Call backend common_section_index
	for common section index.
	(elf_link_input_bfd): Call backend special_section for unknown
	special section indices.
	(_bfd_elf_common_definition): New.
	(_bfd_elf_common_section_index): New.
	(_bfd_elf_common_section): New.

	* elfxx-target.h (elf_backend_common_definition): New.
	(elf_backend_common_section_index): New.
	(elf_backend_common_section): New.
	(elf_backend_special_section): New.
	(elf_backend_merge_symbol): New.
	(elfNN_bed): Initialize special_section, common_definition,
	common_section_index, common_section, and merge_symbol.

	* section.c (BFD_FAKE_SECTION): New.
	(STD_SECTION): Use it.
	* bfd-in2.h: Regenerated.

--- bfd/elf-bfd.h.common	2005-06-17 18:10:04.000000000 -0700
+++ bfd/elf-bfd.h	2005-06-17 18:10:04.000000000 -0700
@@ -970,6 +970,22 @@ struct elf_backend_data
      see elf.c.  */
   bfd_vma (*plt_sym_val) (bfd_vma, const asection *, const arelent *);
 
+  /* Return the special section where symbol is defined.  */
+  asection *(*special_section) (Elf_Internal_Sym *);
+
+  /* Is symbol defined in common section?  */
+  bfd_boolean (*common_definition) (Elf_Internal_Sym *);
+
+  /* Return a common section index for section.  */
+  unsigned int (*common_section_index) (asection *);
+
+  /* Return a common section for section.  */
+  asection *(*common_section) (asection *);
+
+  /* Return TRUE if we can merge 2 definitions.  */
+  bfd_boolean (*merge_symbol) (struct elf_link_hash_entry *,
+			       bfd *, asection *, bfd *, asection *);
+
   /* Used to handle bad SHF_LINK_ORDER input.  */
   bfd_error_handler_type link_order_error_handler;
 
@@ -1741,6 +1757,15 @@ extern int bfd_elf_link_record_local_dyn
 extern bfd_boolean _bfd_elf_close_and_cleanup
   (bfd *);
 
+extern bfd_boolean _bfd_elf_common_definition
+  (Elf_Internal_Sym *);
+
+extern unsigned int _bfd_elf_common_section_index
+  (asection *);
+
+extern asection *_bfd_elf_common_section
+  (asection *);
+
 extern void _bfd_dwarf2_cleanup_debug_info
   (bfd *);
 
--- bfd/elf.c.common	2005-06-17 15:26:44.000000000 -0700
+++ bfd/elf.c	2005-06-17 18:10:04.000000000 -0700
@@ -2626,7 +2626,7 @@ elf_fake_sections (bfd *abfd, asection *
       return;
     }
 
-  this_hdr->sh_flags = 0;
+  /* Don't clear sh_flags. Assembler may set additional bits.  */
 
   if ((asect->flags & SEC_ALLOC) != 0
       || asect->user_set_vma)
--- bfd/elflink.c.common	2005-06-17 18:10:04.000000000 -0700
+++ bfd/elflink.c	2005-06-17 18:10:04.000000000 -0700
@@ -783,6 +783,7 @@ _bfd_elf_merge_symbol (bfd *abfd,
   bfd *oldbfd;
   bfd_boolean newdyn, olddyn, olddef, newdef, newdyncommon, olddyncommon;
   bfd_boolean newweak, oldweak;
+  const struct elf_backend_data *bed;
 
   *skip = FALSE;
   *override = FALSE;
@@ -960,6 +961,11 @@ _bfd_elf_merge_symbol (bfd *abfd,
       return FALSE;
     }
 
+  bed = get_elf_backend_data (abfd);
+  if (bed->merge_symbol
+      && !bed->merge_symbol (h, abfd, sec, oldbfd, oldsec))
+    return FALSE;
+
   /* We need to remember if a symbol has a definition in a dynamic
      object or is weak in all dynamic objects. Internal and hidden
      visibility will make it unavailable to dynamic objects.  */
@@ -1200,7 +1206,7 @@ _bfd_elf_merge_symbol (bfd *abfd,
       newdef = FALSE;
       newdyncommon = FALSE;
       *pvalue = sym->st_size;
-      *psec = sec = bfd_com_section_ptr;
+      *psec = sec = bed->common_section (sec);
       *size_change_ok = TRUE;
     }
 
@@ -2664,6 +2670,8 @@ static bfd_boolean
 is_global_data_symbol_definition (bfd *abfd ATTRIBUTE_UNUSED,
 				  Elf_Internal_Sym *sym)
 {
+  const struct elf_backend_data *bed;
+
   /* Local symbols do not count, but target specific ones might.  */
   if (ELF_ST_BIND (sym->st_info) != STB_GLOBAL
       && ELF_ST_BIND (sym->st_info) < STB_LOOS)
@@ -2679,7 +2687,8 @@ is_global_data_symbol_definition (bfd *a
 
   /* If the symbol is defined in the common section, then
      it is a common definition and so does not count.  */
-  if (sym->st_shndx == SHN_COMMON)
+  bed = get_elf_backend_data (abfd);
+  if (bed->common_definition (sym))
     return FALSE;
 
   /* If the symbol is in a target specific section then we
@@ -3593,7 +3602,7 @@ elf_link_add_object_symbols (bfd *abfd, 
       else if (bind == STB_GLOBAL)
 	{
 	  if (isym->st_shndx != SHN_UNDEF
-	      && isym->st_shndx != SHN_COMMON)
+	      && !bed->common_definition (isym))
 	    flags = BSF_GLOBAL;
 	}
       else if (bind == STB_WEAK)
@@ -3883,7 +3892,7 @@ elf_link_add_object_symbols (bfd *abfd, 
 	}
 
       /* Set the alignment of a common symbol.  */
-      if ((isym->st_shndx == SHN_COMMON
+      if ((bed->common_definition (isym)
 	   || bfd_is_com_section (sec))
 	  && h->root.type == bfd_link_hash_common)
 	{
@@ -3915,7 +3924,8 @@ elf_link_add_object_symbols (bfd *abfd, 
 	     definition or a common symbol is ignored due to the old
 	     normal definition. We need to make sure the maximum
 	     alignment is maintained.  */
-	  if ((old_alignment || isym->st_shndx == SHN_COMMON)
+	  if ((old_alignment
+	       || bed->common_definition (isym))
 	      && h->root.type != bfd_link_hash_common)
 	    {
 	      unsigned int common_align;
@@ -6528,7 +6538,7 @@ elf_link_output_extsym (struct elf_link_
 
     case bfd_link_hash_common:
       input_sec = h->root.u.c.p->section;
-      sym.st_shndx = SHN_COMMON;
+      sym.st_shndx = bed->common_section_index (input_sec);
       sym.st_value = 1 << h->root.u.c.p->alignment_power;
       break;
 
@@ -6882,6 +6892,8 @@ elf_link_input_bfd (struct elf_final_lin
 	isec = bfd_abs_section_ptr;
       else if (isym->st_shndx == SHN_COMMON)
 	isec = bfd_com_section_ptr;
+      else if (bed->special_section)
+	isec = bed->special_section (isym);
       else
 	{
 	  /* Who knows?  */
@@ -9906,3 +9918,21 @@ _bfd_elf_provide_section_bound_symbols (
   if (do_end)
     bfd_elf_set_symbol (he, end_val);
 }
+
+bfd_boolean
+_bfd_elf_common_definition (Elf_Internal_Sym *sym)
+{
+  return sym->st_shndx == SHN_COMMON;
+}
+
+unsigned int
+_bfd_elf_common_section_index (asection *sec ATTRIBUTE_UNUSED)
+{
+  return SHN_COMMON;
+}
+
+asection *
+_bfd_elf_common_section (asection *sec ATTRIBUTE_UNUSED)
+{
+  return bfd_com_section_ptr;
+}
--- bfd/elfxx-target.h.common	2005-05-25 06:51:27.000000000 -0700
+++ bfd/elfxx-target.h	2005-06-17 18:10:04.000000000 -0700
@@ -518,6 +518,26 @@
 #define elf_backend_link_order_error_handler _bfd_default_error_handler
 #endif
 
+#ifndef elf_backend_common_definition
+#define elf_backend_common_definition _bfd_elf_common_definition
+#endif
+
+#ifndef elf_backend_common_section_index
+#define elf_backend_common_section_index _bfd_elf_common_section_index
+#endif
+
+#ifndef elf_backend_common_section
+#define elf_backend_common_section _bfd_elf_common_section
+#endif
+
+#ifndef elf_backend_special_section
+#define elf_backend_special_section NULL
+#endif
+
+#ifndef elf_backend_merge_symbol
+#define elf_backend_merge_symbol NULL
+#endif
+
 extern const struct elf_size_info _bfd_elfNN_size_info;
 
 #ifndef INCLUDED_TARGET_FILE
@@ -586,6 +606,11 @@ static const struct elf_backend_data elf
   elf_backend_ecoff_debug_swap,
   elf_backend_bfd_from_remote_memory,
   elf_backend_plt_sym_val,
+  elf_backend_special_section,
+  elf_backend_common_definition,
+  elf_backend_common_section_index,
+  elf_backend_common_section,
+  elf_backend_merge_symbol,
   elf_backend_link_order_error_handler,
   elf_backend_relplt_name,
   ELF_MACHINE_ALT1,
--- bfd/section.c.common	2005-05-18 10:37:28.000000000 -0700
+++ bfd/section.c	2005-06-17 18:10:04.000000000 -0700
@@ -634,6 +634,47 @@ CODE_FRAGMENT
 .#define bfd_section_removed_from_list(ABFD, S) \
 .  ((S)->next == NULL ? (ABFD)->section_last != (S) : (S)->next->prev != (S))
 .
+.#define BFD_FAKE_SECTION(SEC, FLAGS, SYM, SYM_PTR, NAME, IDX)		\
+.  {* name, id,  index, next, prev, flags, user_set_vma,            *}	\
+.  { NAME,  IDX, 0,     NULL, NULL, FLAGS, 0,				\
+.									\
+.  {* linker_mark, linker_has_input, gc_mark, segment_mark,         *}	\
+.     0,           0,                1,       0,			\
+.									\
+.  {* sec_info_type, use_rela_p, has_tls_reloc, has_gp_reloc,       *}	\
+.     0,	      0,	  0,		 0,			\
+.									\
+.  {* need_finalize_relax, reloc_done,                              *}	\
+.     0,		    0,						\
+.									\
+.  {* vma, lma, size, rawsize                                       *}	\
+.     0,   0,   0,    0,						\
+.									\
+.  {* output_offset, output_section,              alignment_power,  *}	\
+.     0,             (struct bfd_section *) &SEC, 0,			\
+.									\
+.  {* relocation, orelocation, reloc_count, filepos, rel_filepos,   *}	\
+.     NULL,       NULL,        0,           0,       0,			\
+.									\
+.  {* line_filepos, userdata, contents, lineno, lineno_count,       *}	\
+.     0,            NULL,     NULL,     NULL,   0,			\
+.									\
+.  {* entsize, kept_section, moving_line_filepos,		     *}	\
+.     0,       NULL,	      0,					\
+.									\
+.  {* target_index, used_by_bfd, constructor_chain, owner,          *}	\
+.     0,            NULL,        NULL,              NULL,		\
+.									\
+.  {* symbol,                                                       *}	\
+.     (struct bfd_symbol *) SYM,					\
+.									\
+.  {* symbol_ptr_ptr,                                               *}	\
+.     (struct bfd_symbol **) SYM_PTR,					\
+.									\
+.  {* map_head, map_tail                                            *}	\
+.     { NULL }, { NULL }						\
+.    }
+.
 */
 
 /* We use a macro to initialize the static asymbol structures because
@@ -661,46 +702,8 @@ static const asymbol global_syms[] =
 
 #define STD_SECTION(SEC, FLAGS, SYM, NAME, IDX)				\
   const asymbol * const SYM = (asymbol *) &global_syms[IDX]; 		\
-  asection SEC = 							\
-    /* name, id,  index, next, prev, flags, user_set_vma,            */	\
-    { NAME,  IDX, 0,     NULL, NULL, FLAGS, 0,				\
-									\
-    /* linker_mark, linker_has_input, gc_mark, segment_mark,         */	\
-       0,           0,                1,       0,			\
-									\
-    /* sec_info_type, use_rela_p, has_tls_reloc, has_gp_reloc,       */ \
-       0,	      0,	  0,		 0,			\
-									\
-    /* need_finalize_relax, reloc_done,                              */ \
-       0,		    0,						\
-									\
-    /* vma, lma, size, rawsize                                       */	\
-       0,   0,   0,    0,						\
-									\
-    /* output_offset, output_section,              alignment_power,  */	\
-       0,             (struct bfd_section *) &SEC, 0,			\
-									\
-    /* relocation, orelocation, reloc_count, filepos, rel_filepos,   */	\
-       NULL,       NULL,        0,           0,       0,		\
-									\
-    /* line_filepos, userdata, contents, lineno, lineno_count,       */	\
-       0,            NULL,     NULL,     NULL,   0,			\
-									\
-    /* entsize, kept_section, moving_line_filepos,	           */	\
-       0,       NULL,	      0,					\
-									\
-    /* target_index, used_by_bfd, constructor_chain, owner,          */	\
-       0,            NULL,        NULL,              NULL,		\
-									\
-    /* symbol,                                                       */	\
-       (struct bfd_symbol *) &global_syms[IDX],				\
-									\
-    /* symbol_ptr_ptr,                                               */	\
-       (struct bfd_symbol **) &SYM,					\
-									\
-    /* map_head, map_tail                                            */	\
-       { NULL }, { NULL }						\
-    }
+  asection SEC = BFD_FAKE_SECTION(SEC, FLAGS, &global_syms[IDX], &SYM,	\
+				  NAME, IDX)
 
 STD_SECTION (bfd_com_section, SEC_IS_COMMON, bfd_com_symbol,
 	     BFD_COM_SECTION_NAME, 0);


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