* as.h (rs_align_test): New.
authorRichard Henderson <rth@redhat.com>
Thu, 28 Dec 2000 10:07:56 +0000 (10:07 +0000)
committerRichard Henderson <rth@redhat.com>
Thu, 28 Dec 2000 10:07:56 +0000 (10:07 +0000)
* frags.c (NOP_OPCODE): Move default from read.c.
(MAX_MEM_FOR_RS_ALIGN_CODE): New default.
(frag_align_code): New.
* frags.h (frag_align_code): Declare.
* read.c (NOP_OPCODE): Remove.
(do_align): Use frag_align_code.
* write.c (NOP_OPCODE): Remove.
(get_recorded_alignment): New.
(cvt_frag_to_fill): Handle rs_align_test.
(relax_segment): Likewise.
(subsegs_finish): Align last subseg in section to the
section alignment.  Use frag_align_code.
* write.h (get_recorded_alignment): Declare.
* config/obj-coff.c (size_section): Handle rs_align_test.
(fill_section, fixup_mdeps): Likewise.
(write_object_file): Use frag_align_code.

* config/tc-alpha.c (alpha_align): Use frag_align_code.
(alpha_handle_align): New.
* config/tc-alpha.h (HANDLE_ALIGN): New.
(MAX_MEM_FOR_RS_ALIGN_CODE): New.

* config/tc-i386.h (md_do_align): Use frag_align_code.
(MAX_MEM_FOR_RS_ALIGN_CODE): New.

* config/tc-ia64.c (ia64_md_do_align): Don't do code alignment.
(ia64_handle_align): New.
* config/tc-ia64.h (HANDLE_ALIGN): New.
(MAX_MEM_FOR_RS_ALIGN_CODE): New.

* config/tc-m32r.c (m32r_do_align): Remove.
(m32r_handle_align): New.
(fill_insn): Use frag_align_code.
* config/tc-m32r.h (md_do_align): Remove.
(HANDLE_ALIGN, MAX_MEM_FOR_RS_ALIGN_CODE): New.
* config/tc-m88k.c, config/tc-m88k.h: Similarly.
* config/tc-mips.c, config/tc-mips.h: Similarly.

* config/tc-sh.c (sh_cons_align): Use rs_align_test.
(sh_handle_align): Likewise.  Handle rs_align_code.
(sh_do_align): Remove.
* config/tc-sh.h (md_do_align): Remove.
(MAX_MEM_FOR_RS_ALIGN_CODE): New.

* config/tc-sparc.c (sparc_cons_align): Use rs_align_test.
(sparc_handle_align): Likewise.  Handle rs_align_code.
* config/tc-sparc.h (md_do_align): Remove.
(MAX_MEM_FOR_RS_ALIGN_CODE): New.

23 files changed:
gas/ChangeLog
gas/as.h
gas/config/obj-coff.c
gas/config/tc-alpha.c
gas/config/tc-alpha.h
gas/config/tc-i386.h
gas/config/tc-ia64.c
gas/config/tc-ia64.h
gas/config/tc-m32r.c
gas/config/tc-m32r.h
gas/config/tc-m88k.c
gas/config/tc-m88k.h
gas/config/tc-mips.c
gas/config/tc-mips.h
gas/config/tc-sh.c
gas/config/tc-sh.h
gas/config/tc-sparc.c
gas/config/tc-sparc.h
gas/frags.c
gas/frags.h
gas/read.c
gas/write.c
gas/write.h

index 424bba336ddc8023eda915280d110764d1b13544..e6bd7376966d0328167b0d3e36bd483ab695e968 100644 (file)
@@ -1,3 +1,55 @@
+2000-12-28  Richard Henderson  <rth@redhat.com>
+
+       * as.h (rs_align_test): New.
+       * frags.c (NOP_OPCODE): Move default from read.c.
+       (MAX_MEM_FOR_RS_ALIGN_CODE): New default.
+       (frag_align_code): New.
+       * frags.h (frag_align_code): Declare.
+       * read.c (NOP_OPCODE): Remove.
+       (do_align): Use frag_align_code.
+       * write.c (NOP_OPCODE): Remove.
+       (get_recorded_alignment): New.
+       (cvt_frag_to_fill): Handle rs_align_test.
+       (relax_segment): Likewise.
+       (subsegs_finish): Align last subseg in section to the
+       section alignment.  Use frag_align_code.
+       * write.h (get_recorded_alignment): Declare.
+       * config/obj-coff.c (size_section): Handle rs_align_test.
+       (fill_section, fixup_mdeps): Likewise.
+       (write_object_file): Use frag_align_code.
+
+       * config/tc-alpha.c (alpha_align): Use frag_align_code.
+       (alpha_handle_align): New.
+       * config/tc-alpha.h (HANDLE_ALIGN): New.
+       (MAX_MEM_FOR_RS_ALIGN_CODE): New.
+
+       * config/tc-i386.h (md_do_align): Use frag_align_code.
+       (MAX_MEM_FOR_RS_ALIGN_CODE): New.
+
+       * config/tc-ia64.c (ia64_md_do_align): Don't do code alignment.
+       (ia64_handle_align): New.
+       * config/tc-ia64.h (HANDLE_ALIGN): New.
+       (MAX_MEM_FOR_RS_ALIGN_CODE): New.
+
+       * config/tc-m32r.c (m32r_do_align): Remove.
+       (m32r_handle_align): New.
+       (fill_insn): Use frag_align_code.
+       * config/tc-m32r.h (md_do_align): Remove.
+       (HANDLE_ALIGN, MAX_MEM_FOR_RS_ALIGN_CODE): New.
+       * config/tc-m88k.c, config/tc-m88k.h: Similarly.
+       * config/tc-mips.c, config/tc-mips.h: Similarly.
+
+       * config/tc-sh.c (sh_cons_align): Use rs_align_test.
+       (sh_handle_align): Likewise.  Handle rs_align_code.
+       (sh_do_align): Remove.
+       * config/tc-sh.h (md_do_align): Remove.
+       (MAX_MEM_FOR_RS_ALIGN_CODE): New.
+
+       * config/tc-sparc.c (sparc_cons_align): Use rs_align_test.
+       (sparc_handle_align): Likewise.  Handle rs_align_code.
+       * config/tc-sparc.h (md_do_align): Remove.
+       (MAX_MEM_FOR_RS_ALIGN_CODE): New.
+
 2000-12-22  DJ Delorie  <dj@redhat.com>
 
        * config/tc-d10v.c (md_assemble): set prev_seg and prev_subseg
index 3df7be3bd2cb6212d5a6d94720b29fb131784763..fe649888bd631725bcafc256d979f4dbbcced900 100644 (file)
--- a/gas/as.h
+++ b/gas/as.h
@@ -364,6 +364,10 @@ enum _relax_state {
      bytes to skip when aligning, or 0 if there is no maximum.  */
   rs_align_code,
 
+  /* Test for alignment.  Like rs_align, but used by several targets
+     to warn if data is not properly aligned.  */
+  rs_align_test,
+
   /* Org: Fr_offset, fr_symbol: address. 1 variable char: fill
      character.  */
   rs_org,
index 67e607557afdcdf9ad4fc20d94c9f4ad26638d63..e16e5df651dbafd15437d36a40c00eedbd1dacc1 100644 (file)
@@ -1826,6 +1826,7 @@ size_section (abfd, idx)
          break;
        case rs_align:
        case rs_align_code:
+       case rs_align_test:
          {
            addressT off;
 
@@ -2135,6 +2136,7 @@ fill_section (abfd, h, file_cursor)
                case rs_fill:
                case rs_align:
                case rs_align_code:
+               case rs_align_test:
                case rs_org:
                  if (frag->fr_fix)
                    {
@@ -3443,12 +3445,15 @@ write_object_file ()
       md_do_align (SUB_SEGMENT_ALIGN (now_seg), (char *) NULL, 0, 0,
                   alignment_done);
 #endif
-      frag_align (SUB_SEGMENT_ALIGN (now_seg),
-                 subseg_text_p (now_seg) ? NOP_OPCODE : 0,
-                 0);
+      if (subseg_text_p (now_seg))
+       frag_align_code (SUB_SEGMENT_ALIGN (now_seg), 0);
+      else
+       frag_align (SUB_SEGMENT_ALIGN (now_seg), 0, 0);
+
 #ifdef md_do_align
     alignment_done:
 #endif
+
       frag_wane (frag_now);
       frag_now->fr_fix = 0;
       know (frag_now->fr_next == NULL);
@@ -4092,6 +4097,7 @@ fixup_mdeps (frags, h, this_segment)
        {
        case rs_align:
        case rs_align_code:
+       case rs_align_test:
        case rs_org:
 #ifdef HANDLE_ALIGN
          HANDLE_ALIGN (frags);
index 6a7116e6c7650dbacaa6433083cc6df45112d8d7..01e9bbd5d54ff5c7a6e1078c601ec80007e01075 100644 (file)
@@ -5673,27 +5673,8 @@ alpha_align (n, pfill, label, force)
 
   if (pfill == NULL)
     {
-      if (n > 2
-         && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
-       {
-         static char const unop[4] = { 0x00, 0x00, 0xe0, 0x2f };
-         static char const nopunop[8] = {
-               0x1f, 0x04, 0xff, 0x47,
-               0x00, 0x00, 0xe0, 0x2f
-         };
-
-         /* First, make sure we're on a four-byte boundary, in case
-            someone has been putting .byte values into the text
-            section.  The DEC assembler silently fills with unaligned
-            no-op instructions.  This will zero-fill, then nop-fill
-            with proper alignment.  */
-         if (alpha_current_align < 2)
-           frag_align (2, 0, 0);
-         if (alpha_current_align < 3)
-           frag_align_pattern (3, unop, sizeof unop, 0);
-         if (n > 3)
-           frag_align_pattern (n, nopunop, sizeof nopunop, 0);
-       }
+      if (subseg_text_p (now_seg))
+       frag_align_code (n, 0);
       else
        frag_align (n, 0, 0);
     }
@@ -5710,10 +5691,55 @@ alpha_align (n, pfill, label, force)
 
   record_alignment (now_seg, n);
 
-  /* ??? if alpha_flag_relax && force && elf, record the requested alignment
+  /* ??? If alpha_flag_relax && force && elf, record the requested alignment
      in a reloc for the linker to see.  */
 }
 
+/* This is called from HANDLE_ALIGN in write.c.  Fill in the contents
+   of an rs_align_code fragment.  */
+
+void 
+alpha_handle_align (fragp)
+     fragS *fragp;
+{
+  static char const unop[4] = { 0x00, 0x00, 0xe0, 0x2f };
+  static char const nopunop[8] = {
+       0x1f, 0x04, 0xff, 0x47,
+       0x00, 0x00, 0xe0, 0x2f
+  };
+
+  int bytes, fix;
+  char *p;
+
+  if (fragp->fr_type != rs_align_code)
+    return;
+
+  bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
+  p = fragp->fr_literal + fragp->fr_fix;
+  fix = 0;
+
+  if (bytes & 3)
+    {
+      fix = bytes & 3;
+      memset (p, 0, fix);
+      p += fix;
+      bytes -= fix;
+    }
+
+  if (bytes & 4)
+    {
+      memcpy (p, unop, 4);
+      p += 4;
+      bytes -= 4;
+      fix += 4;
+    }
+
+  memcpy (p, nopunop, 8);
+
+  fragp->fr_fix += fix;
+  fragp->fr_var = 8;
+}
+
 /* The Alpha has support for some VAX floating point types, as well as for
    IEEE floating point.  We consider IEEE to be the primary floating point
    format, and sneak in the VAX floating point support here.  */
index b4335e305455495fa4700c435384d00d71e5219c..7edc412aff8334e32c86710153a491cbbb4b4e08 100644 (file)
@@ -90,6 +90,11 @@ extern void alpha_define_label PARAMS ((symbolS *));
 #define md_cons_align(nbytes) alpha_cons_align (nbytes)
 extern void alpha_cons_align PARAMS ((int));
 
+#define HANDLE_ALIGN(fragp) alpha_handle_align (fragp)
+extern void alpha_handle_align PARAMS ((struct frag *));
+
+#define MAX_MEM_FOR_RS_ALIGN_CODE  (3 + 4 + 8)
+
 #ifdef OBJ_ECOFF
 #define tc_frob_file_before_adjust() alpha_frob_file_before_adjust ()
 extern void alpha_frob_file_before_adjust PARAMS ((void));
index 3c2efbf10d1f78cc42a020ba9b9324464604c685..964820138c01a9fbee97be0967385fb2142e0f74 100644 (file)
@@ -505,13 +505,12 @@ if ((n) && !need_pass_2                                                   \
     && (!(fill) || ((char)*(fill) == (char)0x90 && (len) == 1))                \
     && subseg_text_p (now_seg))                                                \
   {                                                                    \
-    char *p;                                                           \
-    p = frag_var (rs_align_code, 15, 1, (relax_substateT) max,         \
-                 (symbolS *) 0, (offsetT) (n), (char *) 0);            \
-    *p = 0x90;                                                         \
+    frag_align_code ((n), (max));                                      \
     goto around;                                                       \
   }
 
+#define MAX_MEM_FOR_RS_ALIGN_CODE  15
+
 extern void i386_align_code PARAMS ((fragS *, int));
 
 #define HANDLE_ALIGN(fragP)                                            \
index 9bf22a80a81295a70692939fc352b14cfafc9f30..b0ff7ed4fc4618a3a60ae6abce7b004853763724 100644 (file)
@@ -9768,42 +9768,52 @@ md_section_align (seg, size)
 
 /* Handle ia64 specific semantics of the align directive.  */
 
-int
+void
 ia64_md_do_align (n, fill, len, max)
      int n;
      const char *fill;
      int len ATTRIBUTE_UNUSED;
      int max;
 {
-  /* Fill any pending bundle with nops.  */
-  if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
+  if (subseg_text_p (now_seg))
     ia64_flush_insns ();
+}
 
-  /* When we align code in a text section, emit a bundle of 3 nops instead of
-     zero bytes.  We can only do this if a multiple of 16 bytes was requested.
-     N is log base 2 of the requested alignment.  */
-  if (fill == NULL
-      && bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE
-      && n > 4)
-    {
-      /* Use mfi bundle of nops with no stop bits.  */
-      static const unsigned char be_nop[]
-       = { 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
-           0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c};
-      static const unsigned char le_nop[]
-       = { 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
-           0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00};
-
-      /* Make sure we are on a 16-byte boundary, in case someone has been
-        putting data into a text section.  */
-      frag_align (4, 0, 0);
+/* This is called from HANDLE_ALIGN in write.c.  Fill in the contents
+   of an rs_align_code fragment.  */
 
-      if (target_big_endian)
-       frag_align_pattern (n, be_nop, 16, max);
-      else
-       frag_align_pattern (n, le_nop, 16, max);
-      return 1;
+void
+ia64_handle_align (fragp)
+     fragS *fragp;
+{
+  /* Use mfi bundle of nops with no stop bits.  */
+  static const unsigned char be_nop[]
+    = { 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
+       0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c};
+  static const unsigned char le_nop[]
+    = { 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+       0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00};
+
+  int bytes;
+  char *p;
+
+  if (fragp->fr_type != rs_align_code)
+    return;
+
+  bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
+  p = fragp->fr_literal + fragp->fr_fix;
+
+  /* Make sure we are on a 16-byte boundary, in case someone has been
+     putting data into a text section.  */
+  if (bytes & 15)
+    {
+      int fix = bytes & 15;
+      memset (p, 0, fix);
+      p += fix;
+      bytes -= fix;
+      fragp->fr_fix += fix;
     }
 
-  return 0;
+  memcpy (p, (target_big_endian ? be_nop : le_nop), 16);
+  fragp->fr_var = 16;
 }
index 73add6669e363d6b5e5fe6a06248b5ed59b6a4c8..fd802de8331a660a8bbbcf9f76c3b3147e2f206d 100644 (file)
@@ -83,7 +83,8 @@ extern void ia64_validate_fix PARAMS ((struct fix *fix));
 extern char * ia64_canonicalize_symbol_name PARAMS ((char *));
 extern flagword ia64_elf_section_flags PARAMS ((flagword, int, int));
 extern long ia64_pcrel_from_section PARAMS ((struct fix *fix, segT sec));
-extern int ia64_md_do_align PARAMS ((int, const char *, int, int));
+extern void ia64_md_do_align PARAMS ((int, const char *, int, int));
+extern void ia64_handle_align PARAMS ((fragS *f));
 
 #define md_end()                               ia64_end_of_source ()
 #define md_start_line_hook()           ia64_start_line ()
@@ -108,7 +109,10 @@ extern int ia64_md_do_align PARAMS ((int, const char *, int, int));
 #define TC_CONS_FIX_NEW(f,o,l,e)       ia64_cons_fix_new (f, o, l, e)
 #define TC_VALIDATE_FIX(fix,seg,skip)  ia64_validate_fix (fix)
 #define MD_PCREL_FROM_SECTION(fix,sec) ia64_pcrel_from_section (fix, sec)
-#define md_do_align(n,f,l,m,j)         if (ia64_md_do_align (n,f,l,m)) goto j
+#define md_do_align(n,f,l,m,j)         ia64_md_do_align (n,f,l,m)
+#define HANDLE_ALIGN(f)                        ia64_handle_align (f)
+
+#define MAX_MEM_FOR_RS_ALIGN_CODE  (15 + 16)
 
 /* Call md_apply_fix3 with segment instead of md_apply_fix.  */
 #define MD_APPLY_FIX3
index 4bf21da659a13a8e432ffb298234bc6df3c9c5a8..d31dd8d59f77d3461f5e8f60dbfd12449e63170e 100644 (file)
@@ -327,54 +327,44 @@ const pseudo_typeS md_pseudo_table[] =
 #define NOP_INSN 0x7000
 #define PAR_NOP_INSN 0xf000 /* Can only be used in 2nd slot.  */
 
-/* When we align the .text section, insert the correct NOP pattern.
-   N is the power of 2 alignment.  LEN is the length of pattern FILL.
-   MAX is the maximum number of characters to skip when doing the alignment,
-   or 0 if there is no maximum.  */
+/* This is called from HANDLE_ALIGN in write.c.  Fill in the contents
+   of an rs_align_code fragment.  */
 
-int
-m32r_do_align (n, fill, len, max)
-     int n;
-     const char *fill;
-     int len;
-     int max;
+void
+m32r_handle_align (fragp)
 {
-  /* Only do this if the fill pattern wasn't specified.  */
-  if (fill == NULL
-      && subseg_text_p (now_seg)
-      /* Only do this special handling if aligning to at least a
-        4 byte boundary.  */
-      && n > 1
-     /* Only do this special handling if we're allowed to emit at
-        least two bytes.  */
-      && (max == 0 || max > 1))
-    {
-      static const unsigned char nop_pattern[] = { 0xf0, 0x00 };
+  static const unsigned char nop_pattern[] = { 0xf0, 0x00 };
+  static const unsigned char multi_nop_pattern[] = { 0x70, 0x00, 0xf0, 0x00 };
 
-#if 0
-      /* First align to a 2 byte boundary, in case there is an odd .byte.  */
-      /* FIXME: How much memory will cause gas to use when assembling a big
-        program?  Perhaps we can avoid the frag_align call?  */
-      frag_align (1, 0, 0);
-#endif
-      /* Next align to a 4 byte boundary (we know n >= 2) using a parallel
-        nop.  */
-      frag_align_pattern (2, nop_pattern, sizeof nop_pattern, 0);
-      /* If doing larger alignments use a repeating sequence of appropriate
-        nops.  */
-      if (n > 2)
-       {
-         static const unsigned char multi_nop_pattern[] =
-         { 0x70, 0x00, 0xf0, 0x00 };
-         frag_align_pattern (n, multi_nop_pattern, sizeof multi_nop_pattern,
-                             max ? max - 2 : 0);
-       }
+  int bytes, fix;
+  char *p;
 
-      prev_insn.insn = NULL;
-      return 1;
+  if (fragp->fr_type != rs_align_code)
+    return;
+
+  bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
+  p = fragp->fr_literal + fragp->fr_fix;
+  fix = 0;
+
+  if (bytes & 1)
+    {
+      fix = 1;
+      *p++ = 0;
+      bytes--;
     }
 
-  return 0;
+  if (bytes & 2)
+    {
+      memcpy (p, nop_pattern, 2);
+      p += 2;
+      bytes -= 2;
+      fix += 2;
+    }
+
+  memcpy (p, multi_nop_pattern, 4);
+
+  fragp->fr_fix += fix;
+  fragp->fr_var = 4;
 }
 
 /* If the last instruction was the first of 2 16 bit insns,
@@ -390,7 +380,7 @@ static void
 fill_insn (ignore)
      int ignore;
 {
-  (void) m32r_do_align (2, NULL, 0, 0);
+  frag_align_code (2, 0);
   prev_insn.insn = NULL;
   seen_relaxable_p = 0;
 }
index 2191947ea67d11e12da66a2c6a9e0f68005c3fe4..9e04c19158ce68670670203f8285301f86b35f60 100644 (file)
@@ -61,11 +61,11 @@ m32r_relax_frag (fragP, stretch)
 /* Account for nop if 32 bit insn falls on odd halfword boundary.  */
 #define TC_CGEN_MAX_RELAX(insn, len) (6)
 
-/* Alignments are used to ensure 32 bit insns live on 32 bit boundaries, so
-   we use a special alignment function to insert the correct nop pattern.  */
-extern int m32r_do_align PARAMS ((int, const char *, int, int));
-#define md_do_align(n, fill, len, max, l) \
-if (m32r_do_align (n, fill, len, max)) goto l
+/* Fill in rs_align_code fragments.  */
+extern void m32r_handle_align PARAMS ((fragS *));
+#define HANDLE_ALIGN(f)  m32r_handle_align (f)
+
+#define MAX_MEM_FOR_RS_ALIGN_CODE  (1 + 2 + 4)
 
 #define MD_APPLY_FIX3
 #define md_apply_fix3 gas_cgen_md_apply_fix3
index 86496cfd78b9199f525b8e1872637651d6aaca49..af243b2e4c71c7dff17b87aeda101bd52e4f229a 100644 (file)
@@ -1427,23 +1427,34 @@ md_pcrel_from (fixp)
   /*NOTREACHED*/
 }
 
-/* When we align the .init section, insert the correct NOP pattern.  */
+/* Fill in rs_align_code fragments.  */
 
-int
-m88k_do_align (n, fill, max, len)
-     int n;
-     const char *fill;
-     int len;
-     int max;
+void
+m88k_handle_align (fragp)
+     fragS *fragp;
 {
-  if (fill == NULL
-      && strcmp (obj_segment_name (now_seg), ".init") == 0)
+  static const unsigned char nop_pattern[] = { 0xf4, 0x00, 0x58, 0x00 };
+
+  int bytes;
+  char *p;
+
+  if (fragp->fr_type != rs_align_code)
+    return;
+
+  bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
+  p = fragp->fr_literal + fragp->fr_fix;
+
+  if (bytes & 3)
     {
-      static const unsigned char nop_pattern[] = { 0xf4, 0x00, 0x58, 0x00 };
-      frag_align_pattern (n, nop_pattern, sizeof (nop_pattern), max);
-      return 1;
+      int fix = bytes & 3;
+      memset (p, 0, fix);
+      p += fix;
+      bytes -= fix;
+      fragp->fr_fix += fix;
     }
-  return 0;
+
+  memcpy (p, nop_pattern, 4);
+  fragp->fr_var = 4;
 }
 
 #endif /* M88KCOFF */
index cbd69c84dd64534ba8c22fa315c32164b5182b38..6e28820f0e7574836a64875b3a89d1eb0bbf0596 100644 (file)
@@ -100,9 +100,10 @@ struct reloc_info_m88k
 #endif
 #define SUB_SEGMENT_ALIGN(SEG) max (section_alignment[(int) (SEG)], 4)
 
-/* We use a special alignment function to insert the correct nop
-   pattern in .init.  */
-extern int m88k_do_align PARAMS ((int, const char *, int, int));
-#define md_do_align(n,fill,len,max,l) if (m88k_do_align(n,fill,max,len)) goto l
+/* Fill in rs_align_code fragments.  */
+extern void m88k_handle_align PARAMS ((fragS *));
+#define HANDLE_ALIGN(frag)  m88k_handle_align (frag)
+
+#define MAX_MEM_FOR_RS_ALIGN_CODE  (3 + 4)
 
 #endif /* M88KCOFF */
index 02abcc5291d76f04253bde30edadc51cb7dcfaaf..a04058524ac759bbc7b46bf539be0db9456a1982 100644 (file)
@@ -11550,34 +11550,37 @@ static procS cur_proc;
 static procS *cur_proc_ptr;
 static int numprocs;
 
-/* When we align code in the .text section of mips16, use the correct two
-   byte nop pattern of 0x6500 (move $0,$0) */
+/* Fill in an rs_align_code fragment.  */
 
-int
-mips_do_align (n, fill, len, max)
-     int n;
-     const char *fill;
-     int len ATTRIBUTE_UNUSED;
-     int max;
+void
+mips_handle_align (fragp)
+     fragS *fragp;
 {
-  if (fill == NULL
-      && subseg_text_p (now_seg)
-      && n > 1
-      && mips_opts.mips16)
+  if (fragp->fr_type != rs_align_code)
+    return;
+
+  if (mips_opts.mips16)
     {
       static const unsigned char be_nop[] = { 0x65, 0x00 };
       static const unsigned char le_nop[] = { 0x00, 0x65 };
 
-      frag_align (1, 0, 0);
+      int bytes;
+      char *p;
 
-      if (target_big_endian)
-       frag_align_pattern (n, be_nop, 2, max);
-      else
-       frag_align_pattern (n, le_nop, 2, max);
-      return 1;
+      bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
+      p = fragp->fr_literal + fragp->fr_fix;
+
+      if (bytes & 1)
+       {
+         *p++ = 0;
+         fragp->fr_fix += 1;
+       }
+
+      memcpy (p, (target_big_endian ? be_nop : le_nop), 2);
+      fragp->fr_var = 2;
     }
 
-  return 0;
+  /* For mips32, a nop is a zero, which we trivially get by doing nothing.  */
 }
 
 static void
index 14ac44f63aa53ed3a1cd77047dde4747f7ee3b14..561d5d7f0d557d7a38f1eee6ae8b91260cf61b60 100644 (file)
@@ -55,8 +55,10 @@ extern int mips_relax_frag PARAMS ((struct frag *, long));
 #define md_undefined_symbol(name)      (0)
 #define md_operand(x)
 
-extern int mips_do_align PARAMS ((int, const char *, int, int));
-#define md_do_align(n,fill,len,max,l) if (mips_do_align (n,fill,len,max)) goto l
+extern void mips_handle_align PARAMS ((struct frag *));
+#define HANDLE_ALIGN(fragp)  mips_handle_align (fragp)
+
+#define MAX_MEM_FOR_RS_ALIGN_CODE  (1 + 2)
 
 /* We permit PC relative difference expressions when generating
    embedded PIC code.  */
index ee4058456e83dbaa59855081444a57976a4eb012..275415aeb90812551b9def18d53f16a82d447e7e 100644 (file)
@@ -2582,7 +2582,7 @@ sh_cons_align (nbytes)
       return;
     }
 
-  p = frag_var (rs_align_code, 1, 1, (relax_substateT) 0,
+  p = frag_var (rs_align_test, 1, 1, (relax_substateT) 0,
                (symbolS *) NULL, (offsetT) nalign, (char *) NULL);
 
   record_alignment (now_seg, nalign);
@@ -2596,17 +2596,47 @@ void
 sh_handle_align (frag)
      fragS *frag;
 {
+  int bytes = frag->fr_next->fr_address - frag->fr_address - frag->fr_fix;
+
+  if (frag->fr_type == rs_align_code)
+    {
+      static const unsigned char big_nop_pattern[] = { 0x00, 0x09 };
+      static const unsigned char little_nop_pattern[] = { 0x09, 0x00 };
+
+      char *p = frag->fr_literal + frag->fr_fix;
+
+      if (bytes & 1)
+       {
+         *p++ = 0;
+         bytes--;
+         frag->fr_fix += 1;
+       }
+
+      if (target_big_endian)
+       {
+         memcpy (p, big_nop_pattern, sizeof big_nop_pattern);
+         frag->fr_var = sizeof big_nop_pattern;
+       }
+      else
+       {
+         memcpy (p, little_nop_pattern, sizeof little_nop_pattern);
+         frag->fr_var = sizeof little_nop_pattern;
+       }
+    }
+  else if (frag->fr_type == rs_align_test)
+    {
+      if (bytes != 0)
+       as_warn_where (frag->fr_file, frag->fr_line, _("misaligned data"));
+    }
+
   if (sh_relax
-      && frag->fr_type == rs_align
+      && (frag->fr_type == rs_align
+         || frag->fr_type == rs_align_code)
       && frag->fr_address + frag->fr_fix > 0
       && frag->fr_offset > 1
       && now_seg != bss_section)
     fix_new (frag, frag->fr_fix, 2, &abs_symbol, frag->fr_offset, 0,
             BFD_RELOC_SH_ALIGN);
-
-  if (frag->fr_type == rs_align_code
-      && frag->fr_next->fr_address - frag->fr_address - frag->fr_fix != 0)
-    as_warn_where (frag->fr_file, frag->fr_line, _("misaligned data"));
 }
 
 /* This macro decides whether a particular reloc is an entry in a
@@ -3082,36 +3112,6 @@ tc_coff_sizemachdep (frag)
 
 #endif /* OBJ_COFF */
 
-/* When we align the .text section, insert the correct NOP pattern.  */
-
-int
-sh_do_align (n, fill, len, max)
-     int n;
-     const char *fill;
-     int len ATTRIBUTE_UNUSED;
-     int max;
-{
-  if (fill == NULL
-      && subseg_text_p (now_seg)
-      && n > 1)
-    {
-      static const unsigned char big_nop_pattern[] = { 0x00, 0x09 };
-      static const unsigned char little_nop_pattern[] = { 0x09, 0x00 };
-
-      /* First align to a 2 byte boundary, in case there is an odd
-         .byte.  */
-      frag_align (1, 0, 0);
-      if (target_big_endian)
-       frag_align_pattern (n, big_nop_pattern, sizeof big_nop_pattern, max);
-      else
-       frag_align_pattern (n, little_nop_pattern, sizeof little_nop_pattern,
-                           max);
-      return 1;
-    }
-
-  return 0;
-}
-
 #ifndef BFD_ASSEMBLER
 #ifdef OBJ_COFF
 
index ed17a47ff83c89f26c90b423251c444375e23f18..eebc21a238e850743cbce9f1a185e1ae04eedb8d 100644 (file)
@@ -53,6 +53,8 @@ extern void sh_cons_align PARAMS ((int));
 #define HANDLE_ALIGN(frag) sh_handle_align (frag)
 extern void sh_handle_align PARAMS ((fragS *));
 
+#define MAX_MEM_FOR_RS_ALIGN_CODE (1 + 2)
+
 /* We need to force out some relocations when relaxing.  */
 #define TC_FORCE_RELOCATION(fix) sh_force_relocation (fix)
 extern int sh_force_relocation ();
@@ -76,11 +78,6 @@ extern boolean sh_fix_adjustable PARAMS ((struct fix *));
 extern const struct relax_type md_relax_table[];
 #define TC_GENERIC_RELAX_TABLE md_relax_table
 
-/* We use a special alignment function to insert the correct nop
-   pattern.  */
-extern int sh_do_align PARAMS ((int, const char *, int, int));
-#define md_do_align(n,fill,len,max,l) if (sh_do_align (n,fill,len,max)) goto l
-
 /* We record, for each section, whether we have most recently output a
    CODE reloc or a DATA reloc.  */
 struct sh_segment_info_type
index 850e606f1d98b14a419c6176b69bee275542f0b4..d60626782692fc7b19797b00e97bcfe7e205e77f 100644 (file)
@@ -4085,53 +4085,65 @@ sparc_cons_align (nbytes)
       return;
     }
 
-  p = frag_var (rs_align_code, 1, 1, (relax_substateT) 0,
+  p = frag_var (rs_align_test, 1, 1, (relax_substateT) 0,
                (symbolS *) NULL, (offsetT) nalign, (char *) NULL);
 
   record_alignment (now_seg, nalign);
 }
 
-/* This is where we do the unexpected alignment check.
-   This is called from HANDLE_ALIGN in tc-sparc.h.  */
+/* This is called from HANDLE_ALIGN in tc-sparc.h.  */
 
 void
 sparc_handle_align (fragp)
      fragS *fragp;
 {
-  if (fragp->fr_type == rs_align_code && !fragp->fr_subtype
-      && fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix != 0)
-    as_bad_where (fragp->fr_file, fragp->fr_line, _("misaligned data"));
-  if (fragp->fr_type == rs_align_code && fragp->fr_subtype == 1024)
+  int count, fix;
+  char *p;
+
+  count = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
+  
+  switch (fragp->fr_type)
     {
-      int count =
-       fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
+    case rs_align_test:
+      if (count != 0)
+       as_bad_where (fragp->fr_file, fragp->fr_line, _("misaligned data"));
+      break;
 
-      if (count >= 4
-         && !(count & 3)
-         && count <= 1024
-         && !((long) (fragp->fr_literal + fragp->fr_fix) & 3))
-       {
-         unsigned *p = (unsigned *) (fragp->fr_literal + fragp->fr_fix);
-         int i;
+    case rs_align_code:
+      p = fragp->fr_literal + fragp->fr_fix;
+      fix = 0;
 
-         for (i = 0; i < count; i += 4, p++)
-           if (INSN_BIG_ENDIAN)
-             /* Emit nops.  */
-             number_to_chars_bigendian ((char *) p, 0x01000000, 4);
-           else
-             number_to_chars_littleendian ((char *) p, 0x10000000, 4);
+      if (count & 3)
+       {
+         fix = count & 3;
+         memset (p, 0, fix);
+         p += fix;
+         count -= fix;
+       }
 
-         if (SPARC_OPCODE_ARCH_V9_P (max_architecture) && count > 8)
-           {
-             char *waddr = &fragp->fr_literal[fragp->fr_fix];
-             unsigned wval = (0x30680000 | count >> 2); /* ba,a,pt %xcc, 1f  */
-             if (INSN_BIG_ENDIAN)
-               number_to_chars_bigendian (waddr, wval, 4);
-             else
-               number_to_chars_littleendian (waddr, wval, 4);
-           }
-         fragp->fr_var = count;
+      if (SPARC_OPCODE_ARCH_V9_P (max_architecture) && count > 8)
+       {
+         unsigned wval = (0x30680000 | count >> 2); /* ba,a,pt %xcc, 1f  */
+         if (INSN_BIG_ENDIAN)
+           number_to_chars_bigendian (p, wval, 4);
+         else
+           number_to_chars_littleendian (p, wval, 4);
+         p += 4;
+         count -= 4;
+         fix += 4;
        }
+
+      if (INSN_BIG_ENDIAN)
+       number_to_chars_bigendian (p, 0x01000000, 4);
+      else
+       number_to_chars_littleendian (p, 0x01000000, 4);
+
+      fragp->fr_fix += fix;
+      fragp->fr_var = 4;
+      break;
+
+    default:
+      break;
     }
 }
 
index 9a477abd62d6ca27ebc98683bab79be754458c08..17bef83f300cb02d216df005bc4b856dcb539e43 100644 (file)
@@ -50,31 +50,24 @@ extern const char *sparc_target_format PARAMS ((void));
 
 #define WORKING_DOT_WORD
 
-#define md_convert_frag(b,s,f)         {as_fatal (_("sparc convert_frag\n"));}
+#define md_convert_frag(b,s,f) \
+  as_fatal (_("sparc convert_frag\n"))
 #define md_estimate_size_before_relax(f,s) \
-                       (as_fatal(_("estimate_size_before_relax called")),1)
+  (as_fatal(_("estimate_size_before_relax called")), 1)
 
 #define LISTING_HEADER "SPARC GAS "
 
 extern int sparc_pic_code;
 
-#define md_do_align(n, fill, len, max, around)                         \
-if ((n) && (n) <= 10 && !need_pass_2 && !(fill)                                \
-    && subseg_text_p (now_seg))                                                \
-  {                                                                    \
-    char *p;                                                           \
-    p = frag_var (rs_align_code, 1 << n, 1, (relax_substateT) 1024,    \
-                  (symbolS *) 0, (offsetT) (n), (char *) 0);           \
-    *p = 0x00;                                                         \
-    goto around;                                                       \
-  }
-
 /* We require .word, et. al., to be aligned correctly.  */
 #define md_cons_align(nbytes) sparc_cons_align (nbytes)
 extern void sparc_cons_align PARAMS ((int));
+
 #define HANDLE_ALIGN(fragp) sparc_handle_align (fragp)
 extern void sparc_handle_align PARAMS ((struct frag *));
 
+#define MAX_MEM_FOR_RS_ALIGN_CODE  (3 + 4 + 4)
+
 #if defined (OBJ_ELF) || defined (OBJ_AOUT)
 
 /* This expression evaluates to false if the relocation is for a local
index f5a9d9e5e59889c5a83e219a7afcfda882010c3c..f2f8cfefff53d4b365b08c65af841fed434aa428 100644 (file)
@@ -322,6 +322,39 @@ frag_align_pattern (alignment, fill_pattern, n_fill, max)
   memcpy (p, fill_pattern, n_fill);
 }
 
+/* The NOP_OPCODE is for the alignment fill value.  Fill it with a nop
+   instruction so that the disassembler does not choke on it.  */
+#ifndef NOP_OPCODE
+#define NOP_OPCODE 0x00
+#endif
+
+/* Use this to restrict the amount of memory allocated for representing
+   the alignment code.  Needs to be large enough to hold any fixed sized
+   prologue plus the replicating portion.  */
+#ifndef MAX_MEM_FOR_RS_ALIGN_CODE
+  /* Assume that if HANDLE_ALIGN is not defined then no special action
+     is required to code fill, which means that we get just repeat the
+     one NOP_OPCODE byte.  */
+# ifndef HANDLE_ALIGN
+#  define MAX_MEM_FOR_RS_ALIGN_CODE  1
+# else
+#  define MAX_MEM_FOR_RS_ALIGN_CODE  ((1 << alignment) - 1)
+# endif
+#endif
+
+void
+frag_align_code (alignment, max)
+     int alignment;
+     int max;
+{
+  char *p;
+
+  p = frag_var (rs_align_code, MAX_MEM_FOR_RS_ALIGN_CODE, 1,
+               (relax_substateT) max, (symbolS *) 0,
+               (offsetT) alignment, (char *) 0);
+  *p = NOP_OPCODE;
+}
+
 addressT
 frag_now_fix_octets ()
 {
index 877074b8dab79ac4710aa363703d7116da67706b..c1c652bd89a4d9ff12597b2f4cebb56c789122d0 100644 (file)
@@ -132,6 +132,7 @@ void frag_align_pattern PARAMS ((int alignment,
                                 const char *fill_pattern,
                                 int n_fill,
                                 int max));
+void frag_align_code PARAMS ((int alignment, int max));
 void frag_new PARAMS ((int old_frags_var_max_size));
 void frag_wane PARAMS ((fragS * fragP));
 
index 0db8697fdbbd9b950991d9b1b867d05d45b618a5..1086bf022d48539d81bf6055d80250b4beaa7134 100644 (file)
@@ -67,13 +67,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
   while (0)
 #endif
 
-/* The NOP_OPCODE is for the alignment fill value.
-   Fill it a nop instruction so that the disassembler does not choke
-   on it.  */
-#ifndef NOP_OPCODE
-#define NOP_OPCODE 0x00
-#endif
-
 char *input_line_pointer;      /*->next char of source file to parse.  */
 
 #if BITS_PER_CHAR != 8
@@ -1172,26 +1165,21 @@ do_align (n, fill, len, max)
      int len;
      int max;
 {
-  char default_fill;
-
 #ifdef md_do_align
   md_do_align (n, fill, len, max, just_record_alignment);
 #endif
 
-  if (fill == NULL)
-    {
-      if (subseg_text_p (now_seg))
-       default_fill = NOP_OPCODE;
-      else
-       default_fill = 0;
-      fill = &default_fill;
-      len = 1;
-    }
-
   /* Only make a frag if we HAVE to...  */
   if (n != 0 && !need_pass_2)
     {
-      if (len <= 1)
+      if (fill == NULL)
+       {
+         if (subseg_text_p (now_seg))
+           frag_align_code (n, max);
+         else
+           frag_align (n, 0, max);
+       }
+      else if (len <= 1)
        frag_align (n, *fill, max);
       else
        frag_align_pattern (n, fill, len, max);
index 459933828a795a7a5d0338a8fd0a32118cf63085..897e70707379d4d73578b87e1df8eb105e5a72bc 100644 (file)
 #undef  BFD_FAST_SECTION_FILL
 #define BFD_FAST_SECTION_FILL
 
-/* The NOP_OPCODE is for the alignment fill value.  Fill it with a nop
-   instruction so that the disassembler does not choke on it.  */
-#ifndef NOP_OPCODE
-#define NOP_OPCODE 0x00
-#endif
-
 #ifndef TC_ADJUST_RELOC_COUNT
 #define TC_ADJUST_RELOC_COUNT(FIXP,COUNT)
 #endif
@@ -383,6 +377,19 @@ record_alignment (seg, align)
 #endif
 }
 
+int
+get_recorded_alignment (seg)
+     segT seg;
+{
+  if (seg == absolute_section)
+    return 0;
+#ifdef BFD_ASSEMBLER
+  return bfd_get_section_alignment (stdoutput, seg);
+#else
+  return section_alignment[(int) seg];
+#endif
+}
+
 #ifdef BFD_ASSEMBLER
 
 /* Reset the section indices after removing the gas created sections.  */
@@ -494,6 +501,7 @@ cvt_frag_to_fill (headersP, sec, fragP)
     {
     case rs_align:
     case rs_align_code:
+    case rs_align_test:
     case rs_org:
     case rs_space:
 #ifdef HANDLE_ALIGN
@@ -1390,14 +1398,28 @@ subsegs_finish ()
 
   for (frchainP = frchain_root; frchainP; frchainP = frchainP->frch_next)
     {
+      int alignment;
+
       subseg_set (frchainP->frch_seg, frchainP->frch_subseg);
 
       /* This now gets called even if we had errors.  In that case,
          any alignment is meaningless, and, moreover, will look weird
          if we are generating a listing.  */
-      frag_align (had_errors () ? 0 : SUB_SEGMENT_ALIGN (now_seg),
-                 subseg_text_p (now_seg) ? NOP_OPCODE : 0,
-                 0);
+      alignment = had_errors () ? 0 : SUB_SEGMENT_ALIGN (now_seg);
+
+      /* The last subsegment gets an aligment corresponding to the
+        alignment of the section.  This allows proper nop-filling
+        at the end of code-bearing sections.  */
+      if (!frchainP->frch_next || frchainP->frch_next->frch_seg != now_seg)
+       alignment = get_recorded_alignment (now_seg);
+
+      if (alignment > 0)
+       {
+         if (subseg_text_p (now_seg))
+           frag_align_code (alignment, 0);
+         else
+           frag_align (alignment, 0, 0);
+       }
 
       /* frag_align will have left a new frag.
         Use this last frag for an empty ".fill".
@@ -2156,6 +2178,7 @@ relax_segment (segment_frag_root, segment)
 
        case rs_align:
        case rs_align_code:
+       case rs_align_test:
          {
            addressT offset = relax_align (address, (int) fragP->fr_offset);
 
@@ -2305,6 +2328,7 @@ relax_segment (segment_frag_root, segment)
 #endif
              case rs_align:
              case rs_align_code:
+             case rs_align_test:
                {
                  addressT oldoff, newoff;
 
index 9a917db594c4693098902b64a7688560d02ff8d0..9872e9d82b435540d9b9e96a0792c7b78d38211c 100644 (file)
@@ -178,6 +178,7 @@ extern bit_fixS *bit_fix_new
           long max, long add));
 extern void append PARAMS ((char **charPP, char *fromP, unsigned long length));
 extern void record_alignment PARAMS ((segT seg, int align));
+extern int get_recorded_alignment PARAMS ((segT seg));
 extern void subsegs_finish PARAMS ((void));
 extern void write_object_file PARAMS ((void));
 extern long relax_frag PARAMS ((fragS *, long));
This page took 0.068467 seconds and 4 git commands to generate.