* input-file.c (input_file_open): Rearrange to avoid warning.
[deliverable/binutils-gdb.git] / gas / subsegs.c
index 0fe11e757ffcd0912ccef22ae51a49e1bba9f317..88a4ba05229bb6ac521505c9d11171bd546270ef 100644 (file)
@@ -1,6 +1,6 @@
 /* subsegs.c - subsegments -
    Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2002
+   1999, 2000, 2002, 2004, 2005
    Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
@@ -70,14 +70,14 @@ static segment_info_type *und_seg_info;
 
 #endif /* BFD_ASSEMBLER */
 
-static void subseg_set_rest PARAMS ((segT, subsegT));
+static void subseg_set_rest (segT, subsegT);
 
 static fragS dummy_frag;
 
 static frchainS absolute_frchain;
 \f
 void
-subsegs_begin ()
+subsegs_begin (void)
 {
   /* Check table(s) seg_name[], seg_N_TYPE[] is in correct order */
 #if !defined (MANY_SEGMENTS) && !defined (BFD_ASSEMBLER)
@@ -146,9 +146,7 @@ subsegs_begin ()
  * segment context correct.
  */
 void
-subseg_change (seg, subseg)
-     register segT seg;
-     register int subseg;
+subseg_change (register segT seg, register int subseg)
 {
   now_seg = seg;
   now_subseg = subseg;
@@ -203,9 +201,7 @@ subseg_change (seg, subseg)
 }
 \f
 static void
-subseg_set_rest (seg, subseg)
-     segT seg;
-     subsegT subseg;
+subseg_set_rest (segT seg, subsegT subseg)
 {
   register frchainS *frcP;     /* crawl frchain chain */
   register frchainS **lastPP;  /* address of last pointer */
@@ -401,9 +397,7 @@ subseg_set (seg, subseg)    /* begin assembly for a new sub-segment */
 #else /* BFD_ASSEMBLER */
 
 segT
-subseg_get (segname, force_new)
-     const char *segname;
-     int force_new;
+subseg_get (const char *segname, int force_new)
 {
   segT secptr;
   segment_info_type *seginfo;
@@ -453,9 +447,7 @@ subseg_get (segname, force_new)
 }
 
 segT
-subseg_new (segname, subseg)
-     const char *segname;
-     subsegT subseg;
+subseg_new (const char *segname, subsegT subseg)
 {
   segT secptr;
   segment_info_type *seginfo;
@@ -471,9 +463,7 @@ subseg_new (segname, subseg)
 /* Like subseg_new, except a new section is always created, even if
    a section with that name already exists.  */
 segT
-subseg_force_new (segname, subseg)
-     const char *segname;
-     subsegT subseg;
+subseg_force_new (const char *segname, subsegT subseg)
 {
   segT secptr;
   segment_info_type *seginfo;
@@ -487,9 +477,7 @@ subseg_force_new (segname, subseg)
 }
 
 void
-subseg_set (secptr, subseg)
-     segT secptr;
-     subsegT subseg;
+subseg_set (segT secptr, subsegT subseg)
 {
   if (! (secptr == now_seg && subseg == now_subseg))
     subseg_set_rest (secptr, subseg);
@@ -503,8 +491,7 @@ subseg_set (secptr, subseg)
 /* Get the gas information we are storing for a section.  */
 
 segment_info_type *
-seg_info (sec)
-     segT sec;
+seg_info (segT sec)
 {
   if (sec == bfd_abs_section_ptr)
     return abs_seg_info;
@@ -515,8 +502,7 @@ seg_info (sec)
 }
 
 symbolS *
-section_symbol (sec)
-     segT sec;
+section_symbol (segT sec)
 {
   segment_info_type *seginfo = seg_info (sec);
   symbolS *s;
@@ -537,16 +523,18 @@ section_symbol (sec)
     }
   else
     {
+      segT seg;
       s = symbol_find_base (sec->symbol->name, 0);
-      if (s == NULL)
+      /* We have to make sure it is the right symbol when we
+        have multiple sections with the same section name.  */
+      if (s == NULL
+         || ((seg = S_GET_SEGMENT (s)) != sec
+             && seg != undefined_section))
        s = symbol_new (sec->symbol->name, sec, 0, &zero_address_frag);
-      else
+      else if (seg == undefined_section)
        {
-         if (S_GET_SEGMENT (s) == undefined_section)
-           {
-             S_SET_SEGMENT (s, sec);
-             symbol_set_frag (s, &zero_address_frag);
-           }
+         S_SET_SEGMENT (s, sec);
+         symbol_set_frag (s, &zero_address_frag);
        }
     }
 
@@ -581,8 +569,7 @@ const char * const nontext_section_names[] = {
 #endif /* ! BFD_ASSEMBLER */
 
 int
-subseg_text_p (sec)
-     segT sec;
+subseg_text_p (segT sec)
 {
 #ifdef BFD_ASSEMBLER
   return (bfd_get_section_flags (stdoutput, sec) & SEC_CODE) != 0;
@@ -608,9 +595,36 @@ subseg_text_p (sec)
 #endif /* ! BFD_ASSEMBLER */
 }
 
+/* Return non zero if SEC has at least one byte of data.  It is
+   possible that we'll return zero even on a non-empty section because
+   we don't know all the fragment types, and it is possible that an
+   fr_fix == 0 one still contributes data.  Think of this as
+   seg_definitely_not_empty_p.  */
+
+int
+seg_not_empty_p (segT sec ATTRIBUTE_UNUSED)
+{
+  segment_info_type *seginfo = seg_info (sec);
+  frchainS *chain;
+  fragS *frag;
+
+  if (!seginfo)
+    return 0;
+  
+  for (chain = seginfo->frchainP; chain; chain = chain->frch_next)
+    {
+      for (frag = chain->frch_root; frag; frag = frag->fr_next)
+       if (frag->fr_fix)
+         return 1;
+      if (obstack_next_free (&chain->frch_obstack)
+         != chain->frch_last->fr_literal)
+       return 1;
+    }
+  return 0;
+}
+
 void
-subsegs_print_statistics (file)
-     FILE *file;
+subsegs_print_statistics (FILE *file)
 {
   frchainS *frchp;
   fprintf (file, "frag chains:\n");
@@ -630,27 +644,6 @@ subsegs_print_statistics (file)
 
       for (fragp = frchp->frch_root; fragp; fragp = fragp->fr_next)
        {
-#if 0
-         switch (fragp->fr_type)
-           {
-           case rs_fill:
-             fprintf (file, "f"); break;
-           case rs_align:
-             fprintf (file, "a"); break;
-           case rs_align_code:
-             fprintf (file, "c"); break;
-           case rs_org:
-             fprintf (file, "o"); break;
-           case rs_machine_dependent:
-             fprintf (file, "m"); break;
-           case rs_space:
-             fprintf (file, "s"); break;
-           case 0:
-             fprintf (file, "0"); break;
-           default:
-             fprintf (file, "?"); break;
-           }
-#endif
          count++;
        }
       fprintf (file, "\n");
This page took 0.025133 seconds and 4 git commands to generate.