[PATCH, nds32] Add one more argument to control contents cache.

"Kuan-Lin Chen (陳冠霖)" kuanlinchentw@gmail.com
Mon Feb 2 06:07:00 GMT 2015


The hook bfd_elf32_bfd_get_relocated_section_contents frees contents in
gdb, and it make contents pointer mismatched.
---
  bfd/ChangeLog     |    5 ++++
  bfd/elf32-nds32.c |   67 
+++++++++++++++++++++++++++++++++-------------------
  2 files changed, 47 insertions(+), 25 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 464400f..5942e1c 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,8 @@
+2015-02-02  Kuan-Lin Chen  <kuanlinchentw@gmail.com>
+
+	* elf32-nds32.c (nds32_get_section_contents): Add one more argument.
+	(nds32_elf_relocate_section): Do not relocate R_NDS32_LONGJUMP7.
+
  2015-01-29  Alan Modra  <amodra@gmail.com>

  	* elf64-ppc.c (ppc64_elf_relocate_section): Correct GOT_TLSLD
diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c
index e5fc2a6..081b997 100644
--- a/bfd/elf32-nds32.c
+++ b/bfd/elf32-nds32.c
@@ -108,10 +108,11 @@ static Elf_Internal_Rela *find_relocs_at_address
    (Elf_Internal_Rela *, Elf_Internal_Rela *,
     Elf_Internal_Rela *, enum elf_nds32_reloc_type);
  static bfd_vma calculate_memory_address
-  (bfd *, Elf_Internal_Rela *, Elf_Internal_Sym *, Elf_Internal_Shdr *);
-static int nds32_get_section_contents (bfd *, asection *, bfd_byte **);
+(bfd *, Elf_Internal_Rela *, Elf_Internal_Sym *, Elf_Internal_Shdr *);
+static int nds32_get_section_contents (bfd *, asection *,
+				       bfd_byte **, bfd_boolean);
  static bfd_boolean nds32_elf_ex9_build_hash_table
-  (bfd *, asection *, struct bfd_link_info *);
+(bfd *, asection *, struct bfd_link_info *);
  static bfd_boolean nds32_elf_ex9_itb_base (struct bfd_link_info *);
  static void nds32_elf_ex9_import_table (struct bfd_link_info *);
  static void nds32_elf_ex9_finish (struct bfd_link_info *);
@@ -4512,6 +4513,17 @@ nds32_elf_relocate_section (bfd * 
   output_bfd ATTRIBUTE_UNUSED,
  	return FALSE;
      }

+  if (is_ITB_BASE_set == 0)
+    {
+      /* Set the _ITB_BASE_.  */
+      if (!nds32_elf_ex9_itb_base (info))
+	{
+	  (*_bfd_error_handler) (_("%B: error: Cannot set _ITB_BASE_"),
+				 output_bfd);
+	  bfd_set_error (bfd_error_bad_value);
+	}
+    }
+
    if (table->target_optimize & NDS32_RELAX_JUMP_IFC_ON)
      if (!nds32_elf_ifc_reloc ())
        (*_bfd_error_handler) (_("error: IFC relocation error."));
@@ -4562,10 +4574,11 @@ nds32_elf_relocate_section (bfd * 
    output_bfd ATTRIBUTE_UNUSED,
  	  || (r_type >= R_NDS32_INSN16 && r_type <= R_NDS32_25_FIXED_RELA)
  	  || r_type == R_NDS32_DATA
  	  || r_type == R_NDS32_TRAN
-	  || (r_type >= R_NDS32_LONGCALL4 && r_type <= R_NDS32_LONGJUMP6))
+	  || (r_type >= R_NDS32_LONGCALL4 && r_type <= R_NDS32_LONGJUMP7))
  	continue;

-      /* If we enter the fp-as-gp region.  Resolve the address of best 
fp-base.  */
+      /* If we enter the fp-as-gp region.  Resolve the address
+	 of best fp-base.  */
        if (ELF32_R_TYPE (rel->r_info) == R_NDS32_RELAX_REGION_BEGIN
  	  && (rel->r_addend & R_NDS32_RELAX_REGION_OMIT_FP_FLAG))
  	{
@@ -5946,7 +5959,7 @@ nds32_check_vec_size (bfd *ibfd)
        /* Get vec_size in file.  */
        unsigned int flag_t;

-      nds32_get_section_contents (ibfd, sec_t, &contents);
+      nds32_get_section_contents (ibfd, sec_t, &contents, TRUE);
        flag_t = bfd_get_32 (ibfd, contents);

        /* The value could only be 4 or 16.  */
@@ -8140,7 +8153,7 @@ is_convert_32_to_16 (bfd *abfd, asection *sec,

    offset = reloc->r_offset;

-  if (!nds32_get_section_contents (abfd, sec, &contents))
+  if (!nds32_get_section_contents (abfd, sec, &contents, TRUE))
      return FALSE;
    insn = bfd_getb32 (contents + offset);

@@ -8653,7 +8666,7 @@ nds32_elf_relax_delete_blanks (bfd *abfd, asection 
*sec,
        if (!(sect->flags & SEC_RELOC))
  	continue;

-      nds32_get_section_contents (abfd, sect, &contents);
+      nds32_get_section_contents (abfd, sect, &contents, TRUE);

        for (irel = internal_relocs; irel < irelend; irel++)
  	{
@@ -8901,7 +8914,8 @@ done_adjust_diff:
  /* Get the contents of a section.  */

  static int
-nds32_get_section_contents (bfd *abfd, asection *sec, bfd_byte 
**contents_p)
+nds32_get_section_contents (bfd *abfd, asection *sec,
+			    bfd_byte **contents_p, bfd_boolean cache)
  {
    /* Get the section contents.  */
    if (elf_section_data (sec)->this_hdr.contents != NULL)
@@ -8910,7 +8924,8 @@ nds32_get_section_contents (bfd *abfd, asection 
*sec, bfd_byte **contents_p)
      {
        if (!bfd_malloc_and_get_section (abfd, sec, contents_p))
  	return FALSE;
-      elf_section_data (sec)->this_hdr.contents = *contents_p;
+      if (cache)
+	elf_section_data (sec)->this_hdr.contents = *contents_p;
      }

    return TRUE;
@@ -12057,7 +12072,7 @@ nds32_elf_relax_section (bfd *abfd, asection *sec,
    load_store_relax = table->load_store_relax;

    /* Get symbol table and section content.  */
-  if (!nds32_get_section_contents (abfd, sec, &contents)
+  if (!nds32_get_section_contents (abfd, sec, &contents, TRUE)
        || !nds32_get_local_syms (abfd, sec, &isymbuf))
      goto error_return;

@@ -12743,7 +12758,7 @@ nds32_relax_fp_as_gp (struct bfd_link_info 
*link_info,

    symtab_hdr = &elf_tdata (abfd)->symtab_hdr;

-  if (!nds32_get_section_contents (abfd, sec, &contents)
+  if (!nds32_get_section_contents (abfd, sec, &contents, TRUE)
        || !nds32_get_local_syms (abfd, sec, &isymbuf))
      return FALSE;

@@ -12880,7 +12895,7 @@ nds32_fag_remove_unused_fpbase (bfd *abfd, 
asection *sec,
    */

    symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
-  nds32_get_section_contents (abfd, sec, &contents);
+  nds32_get_section_contents (abfd, sec, &contents, TRUE);

    for (irel = internal_relocs; irel < irelend; irel++)
      {
@@ -12982,7 +12997,7 @@ nds32_elf_get_relocated_section_contents (bfd *abfd,
      return NULL;

    /* Read in the section.  */
-  if (!nds32_get_section_contents (input_bfd, input_section, &data))
+  if (!nds32_get_section_contents (input_bfd, input_section, &data, FALSE))
      return NULL;

    if (reloc_size == 0)
@@ -13233,7 +13248,7 @@ nds32_elf_ifc_calc (struct bfd_link_info *info,
  	  && !(irel->r_addend & R_NDS32_RELAX_ENTRY_IFC_FLAG)))
      return TRUE;

-  if (!nds32_get_section_contents (abfd, sec, &contents))
+  if (!nds32_get_section_contents (abfd, sec, &contents, TRUE))
      return FALSE;

    table = nds32_elf_hash_table (info);
@@ -13475,7 +13490,7 @@ nds32_elf_ifc_replace (struct bfd_link_info *info)
  	      irelend = internal_relocs + ptr->sec->reloc_count;

  	      if (!nds32_get_section_contents (ptr->sec->owner, ptr->sec,
-					       &contents))
+					       &contents, TRUE))
  		return FALSE;

  	      while (irel_ptr)
@@ -13532,8 +13547,9 @@ nds32_elf_ifc_replace (struct bfd_link_info *info)
  			(irel_ptr->sec->owner, irel_ptr->sec, NULL, NULL,
  			 TRUE /* keep_memory */);
  		      irelend = internal_relocs + irel_ptr->sec->reloc_count;
-		      if (!nds32_get_section_contents
-			     (irel_ptr->sec->owner, irel_ptr->sec, &contents))
+		      if (!nds32_get_section_contents (irel_ptr->sec->owner,
+						       irel_ptr->sec, &contents,
+						       TRUE))
  			return FALSE;

  		      irel = irel_ptr->irel;
@@ -13619,7 +13635,8 @@ nds32_elf_ifc_reloc (void)
  	  if (ptr->h == NULL)
  	    {
  	      /* Local symbol.  */
-	      if (!nds32_get_section_contents (ptr->sec->owner, ptr->sec, 
&contents))
+	      if (!nds32_get_section_contents (ptr->sec->owner, ptr->sec,
+					       &contents, TRUE))
  		return FALSE;

  	      while (irel_ptr)
@@ -13717,7 +13734,7 @@ nds32_elf_ifc_reloc (void)
  			    return FALSE;
  			}
  		      if (!nds32_get_section_contents
-			  (irel_ptr->sec->owner, irel_ptr->sec, &contents))
+			  (irel_ptr->sec->owner, irel_ptr->sec, &contents, TRUE))
  			return FALSE;
  		      insn16 = INSN_IFCALL9 | (relocation >> 1);
  		      bfd_putb16 (insn16, contents + irel_ptr->irel->r_offset);
@@ -14172,7 +14189,7 @@ nds32_elf_ex9_build_itable (struct bfd_link_info 
*link_info)
        table_sec = bfd_get_section_by_name (it_abfd, ".ex9.itable");
        if (table_sec != NULL)
  	{
-	  if (!nds32_get_section_contents (it_abfd, table_sec, &contents))
+	  if (!nds32_get_section_contents (it_abfd, table_sec, &contents, TRUE))
  	    return;

  	  for (ptr = ex9_insn_head; ptr !=NULL ; ptr = ptr->next)
@@ -14518,7 +14535,7 @@ nds32_elf_ex9_replace_instruction (struct 
bfd_link_info *info, bfd *abfd, asecti


    /* Load section instructions, relocations, and symbol table.  */
-  if (!nds32_get_section_contents (abfd, sec, &contents)
+  if (!nds32_get_section_contents (abfd, sec, &contents, TRUE)
        || !nds32_get_local_syms (abfd, sec, &isym))
      return FALSE;
    internal_relocs =
@@ -15110,7 +15127,7 @@ nds32_elf_ex9_reloc_jmp (struct bfd_link_info 
*link_info)
  	  if (table_sec->size == 0)
  	    return;

-	  if (!nds32_get_section_contents (it_abfd, table_sec, &contents))
+	  if (!nds32_get_section_contents (it_abfd, table_sec, &contents, TRUE))
  	    return;
  	}
      }
@@ -15249,7 +15266,7 @@ nds32_elf_ex9_reloc_jmp (struct bfd_link_info 
*link_info)
  				{
  				  if (!nds32_get_section_contents
  					 (fix_ptr->sec->owner, fix_ptr->sec,
-					  &source_contents))
+					  &source_contents, TRUE))
  				    (*_bfd_error_handler)
  				      (_("Linker: error cannot fixed ex9 relocation \n"));
  				  if (temp_ptr->order < 32)
@@ -15331,7 +15348,7 @@ nds32_elf_ex9_build_hash_table (bfd *abfd, 
asection *sec,

    sym_hashes = elf_sym_hashes (abfd);
    /* Load section instructions, relocations, and symbol table.  */
-  if (!nds32_get_section_contents (abfd, sec, &contents))
+  if (!nds32_get_section_contents (abfd, sec, &contents, TRUE))
      return FALSE;

    internal_relocs = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL,

-- 
Best regards,
Kuan-Lin Chen.
kuanlinchentw@gmail.com



More information about the Binutils mailing list