[PATCH] Fix some bugs for Score

ligang@sunnorth.com.cn ligang@sunnorth.com.cn
Mon Oct 16 19:53:00 GMT 2006


Hello Nick,

I have fixed some bugs.  See the changelog and patch below please.


1. Fix internal error: fixup not contained within frag.

   gas/config/
   * tc-score.c (build_relax_frag): Compute correct tc_frag_data.fixp. 
 
2. Change .rel.dyn section type from PROGBITS to REL to make readelf print 
.rel.dyn
   section content.

   bfd/
   * elf32-score.c (score_elf_rel_dyn_section): Replace bfd_make_section
   with bfd_make_section_with_flags.
   (_bfd_score_elf_create_dynamic_sections): Ditto.
   (score_elf_create_got_section): Ditto.
 
3. Redefine section type value because of conflict.

   include/elf/
   * score.h (EF_SCORE_PIC): Redefine EF_SCORE_PIC as 0x80000000.
   (EF_SCORE_FIXDEP): Redefine EF_SCORE_FIXDEP as 0x40000000.
   (EF_SCORE_HASENTRY): Delete.
 
   bfd/
   * elf32-score.c (score_elf_final_link_relocate): Delete referrence to
   EF_SCORE_HASENTRY.
 

Index: elf32-score.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-score.c,v
retrieving revision 1.3
diff -p -u -r1.3 elf32-score.c
--- elf32-score.c       28 Sep 2006 13:27:32 -0000      1.3
+++ elf32-score.c       13 Oct 2006 10:03:43 -0000
@@ -1141,17 +1141,17 @@ score_elf_rel_dyn_section (bfd *dynobj, 
   sreloc = bfd_get_section_by_name (dynobj, dname);
   if (sreloc == NULL && create_p)
     {
-      sreloc = bfd_make_section (dynobj, dname);
+      sreloc = bfd_make_section_with_flags (dynobj, dname,
+                                            (SEC_ALLOC
+                                             | SEC_LOAD
+                                             | SEC_HAS_CONTENTS
+                                             | SEC_IN_MEMORY
+                                             | SEC_LINKER_CREATED
+                                             | SEC_READONLY));
       if (sreloc == NULL
-         || ! bfd_set_section_flags (dynobj, sreloc,
-                                     (SEC_ALLOC
-                                      | SEC_LOAD
-                                      | SEC_HAS_CONTENTS
-                                      | SEC_IN_MEMORY
-                                      | SEC_LINKER_CREATED
-                                      | SEC_READONLY))
-         || ! bfd_set_section_alignment (dynobj, sreloc, 
SCORE_ELF_LOG_FILE_ALIGN (dynobj)))
-       return NULL;
+          || ! bfd_set_section_alignment (dynobj, sreloc,
+                                          SCORE_ELF_LOG_FILE_ALIGN 
(dynobj)))
+        return NULL;
     }
 
   return sreloc;
@@ -1350,9 +1350,8 @@ score_elf_create_got_section (bfd *abfd,
 
   /* We have to use an alignment of 2**4 here because this is hardcoded
      in the function stub generation and in the linker script.  */
-  s = bfd_make_section (abfd, ".got");
+  s = bfd_make_section_with_flags (abfd, ".got", flags);
   if (s == NULL
-      || ! bfd_set_section_flags (abfd, s, flags)
       || ! bfd_set_section_alignment (abfd, s, 4))
     return FALSE;
 
@@ -1929,15 +1928,6 @@ score_elf_final_link_relocate (reloc_how
   r_type = ELF32_R_TYPE (rel->r_info);
   rel_addr = (input_section->output_section->vma + 
input_section->output_offset + rel->r_offset);
 
-  /* If the start address has been set, then set the EF_SCORE_HASENTRY
-     flag.  Setting this more than once is redundant, but the cost is
-     not too high, and it keeps the code simple.
-     The test is done  here, rather than somewhere else, because the
-     start address is only set just before the final link commences.
-     Note - if the user deliberately sets a start address of 0, the flag 
will not be set.  */
-  if (bfd_get_start_address (output_bfd) != 0)
-    elf_elfheader (output_bfd)->e_flags |= EF_SCORE_HASENTRY;
-
   if (r_type == R_SCORE_GOT15)
     {
       const Elf_Internal_Rela *relend;
@@ -3173,9 +3163,9 @@ _bfd_score_elf_create_dynamic_sections (
   /* Create .stub section.  */
   if (bfd_get_section_by_name (abfd, SCORE_ELF_STUB_SECTION_NAME) == 
NULL)
     {
-      s = bfd_make_section (abfd, SCORE_ELF_STUB_SECTION_NAME);
+      s = bfd_make_section_with_flags (abfd, SCORE_ELF_STUB_SECTION_NAME,
+                                       flags | SEC_CODE);
       if (s == NULL
-          || !bfd_set_section_flags (abfd, s, flags | SEC_CODE)
           || !bfd_set_section_alignment (abfd, s, 2))
 
         return FALSE;

Index: tc-score.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-score.c,v
retrieving revision 1.2
diff -p -u -r1.2 tc-score.c
--- tc-score.c  13 Oct 2006 06:55:50 -0000      1.2
+++ tc-score.c  13 Oct 2006 10:04:15 -0000
@@ -3602,7 +3602,7 @@ build_relax_frag (struct score_it fix_in
   int i;
   char *p;
   fixS *fixp = NULL;
-  fixS *head_fixp = NULL;
+  fixS *cur_fixp = NULL;
   long where;
   struct score_it inst_main;
 
@@ -3643,14 +3643,12 @@ build_relax_frag (struct score_it fix_in
                             &inst_main.reloc.exp, inst_main.reloc.pc_rel, 
inst_main.reloc.type);
     }
 
-  head_fixp = xmalloc (sizeof (fixS *));
-  frag_now->tc_frag_data.fixp = head_fixp;
-
   if (fixp)
-    {
-      head_fixp->fx_next = fixp;
-      head_fixp = head_fixp->fx_next;
-    }
+    frag_now->tc_frag_data.fixp = fixp;
+  else
+    frag_now->tc_frag_data.fixp = NULL;
+
+  cur_fixp = frag_now->tc_frag_data.fixp;
 
 #ifdef OBJ_ELF
   dwarf2_emit_insn (inst_main.size);
@@ -3669,16 +3667,20 @@ build_relax_frag (struct score_it fix_in
                                 var_insts[i].reloc.type);
           if (fixp)
             {
-              head_fixp->fx_next = fixp;
-              head_fixp = head_fixp->fx_next;
+              if (cur_fixp)
+                {
+                  cur_fixp->fx_next = fixp;
+                  cur_fixp = cur_fixp->fx_next;
+                }
+              else
+                {
+                  frag_now->tc_frag_data.fixp = fixp;
+                  cur_fixp = frag_now->tc_frag_data.fixp;
+                }
            }
         }
     }
 
-  head_fixp = frag_now->tc_frag_data.fixp;
-  frag_now->tc_frag_data.fixp = head_fixp->fx_next;
-  free (head_fixp);
-
   p = frag_var (rs_machine_dependent, inst_main.relax_size + 
RELAX_PAD_BYTE, 0,
                 RELAX_ENCODE (inst_main.size, inst_main.relax_size, 
inst_main.type,
                 0, inst_main.size, 0), add_symbol, 0, NULL);


Index: score.h
===================================================================
RCS file: /cvs/src/src/include/elf/score.h,v
retrieving revision 1.1
diff -p -u -r1.1 score.h
--- score.h     16 Sep 2006 23:51:50 -0000      1.1
+++ score.h     13 Oct 2006 10:04:45 -0000
@@ -32,16 +32,15 @@
 #define OPC_32                  0xc0000000      /* denotes 32b 
instruction, (default) */
 #define OPC_16                  0x00000000      /* denotes 16b 
instruction  */
 #define OPC_PE                  0x8000          /* denotes 
parallel-execution instructions  */
-#define EF_SCORE_HASENTRY       0x02
 #define GP_DISP_LABEL           "_gp_disp"
 
 /* Processor specific flags for the ELF header e_flags field.  */
 
-/* Fix data dependency.  */
-#define EF_SCORE_FIXDEP         0x00000001
-
 /* File contains position independent code.  */
-#define EF_SCORE_PIC           0x00000002
+#define EF_SCORE_PIC           0x80000000
+
+/* Fix data dependency.  */
+#define EF_SCORE_FIXDEP         0x40000000
 
 /* Defined and allocated common symbol.  Value is virtual address.  If
    relocated, alignment must be preserved.  */



Best regards
                     Ligang



More information about the Binutils mailing list