* config/tc-mips.c (md_pseudo_table): If OBJ_ELF, handle .section.
[deliverable/binutils-gdb.git] / gas / subsegs.c
index 0566d0aa3cf90ae0ebaa5d2d059bea153556778a..5ce2e9e33dba800edf130043527344d3df18b116 100644 (file)
@@ -1,5 +1,6 @@
 /* subsegs.c - subsegments -
-   Copyright (C) 1987, 1990, 1991, 1992 Free Software Foundation, Inc.
+   Copyright (C) 1987, 1990, 1991, 1992, 1993, 1994
+   Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
 
@@ -56,6 +57,13 @@ char *const seg_name[] =
   "register",
   "",
 };                             /* Used by error reporters, dumpers etc. */
+#else /* BFD_ASSEMBLER */
+
+/* Gas segment information for bfd_abs_section_ptr and
+   bfd_und_section_ptr.  */
+static segment_info_type *abs_seg_info;
+static segment_info_type *und_seg_info;
+
 #endif /* BFD_ASSEMBLER */
 
 static void subseg_set_rest PARAMS ((segT, subsegT));
@@ -85,7 +93,7 @@ subsegs_begin ()
   /* Fake up 1st frag.  It won't be used=> is ok if obstack...
      pads the end of it for alignment. */
   frag_now = (fragS *) obstack_alloc (&frags, SIZEOF_STRUCT_FRAG);
-  memset (frag_now, SIZEOF_STRUCT_FRAG, 0);
+  memset (frag_now, 0, SIZEOF_STRUCT_FRAG);
 
 #ifndef BFD_ASSEMBLER
   /* This 1st frag will not be in any frchain.
@@ -137,13 +145,17 @@ subseg_change (seg, subseg)
     if (! seginfo)
       {
        seginfo = (segment_info_type *) xmalloc (sizeof (*seginfo));
-       if (! seginfo)
-         abort ();
-       seginfo->fix_root = 0;
-       seginfo->fix_tail = 0;
+       memset ((PTR) seginfo, 0, sizeof (*seginfo));
+       seginfo->fix_root = NULL;
+       seginfo->fix_tail = NULL;
        seginfo->bfd_section = seg;
        seginfo->sym = 0;
-       bfd_set_section_userdata (stdoutput, seg, (char *) seginfo);
+       if (seg == bfd_abs_section_ptr)
+         abs_seg_info = seginfo;
+       else if (seg == bfd_und_section_ptr)
+         und_seg_info = seginfo;
+       else
+         bfd_set_section_userdata (stdoutput, seg, (PTR) seginfo);
       }
   }
 #else
@@ -211,10 +223,10 @@ subseg_set_rest (seg, subseg)
    * position of chain rooted in frchain_root.
    */
   for (frcP = *(lastPP = &frchain_root);
-       frcP && (int) (frcP->frch_seg) <= (int) seg;
+       frcP && frcP->frch_seg <= seg;
        frcP = *(lastPP = &frcP->frch_next))
     {
-      if ((int) (frcP->frch_seg) == (int) seg
+      if (frcP->frch_seg == seg
          && frcP->frch_subseg >= subseg)
        {
          break;
@@ -242,14 +254,14 @@ subseg_set_rest (seg, subseg)
    *
    */
   if (!frcP
-      || ((int) (frcP->frch_seg) > (int) seg
+      || (frcP->frch_seg > seg
          || frcP->frch_subseg > subseg))       /* Kinky logic only works with 2 segments. */
     {
       /*
        * This should be the only code that creates a frchainS.
        */
       newP = (frchainS *) obstack_alloc (&frags, sizeof (frchainS));
-      memset (newP, sizeof (frchainS), 0);
+      memset (newP, 0, sizeof (frchainS));
       /* This begines on a good boundary because a obstack_done()
         preceeded it.  It implies an obstack_done(), so we expect
         the next object allocated to begin on a correct boundary. */
@@ -258,6 +270,10 @@ subseg_set_rest (seg, subseg)
       (frcP = newP)->frch_subseg = subseg;
       newP->frch_seg = seg;
       newP->frch_last = NULL;
+#ifdef BFD_ASSEMBLER
+      newP->fix_root = NULL;
+      newP->fix_tail = NULL;
+#endif
     }
   /*
    * Here with frcP ->ing to the frchainS for subseg.
@@ -398,19 +414,25 @@ subseg_get (segname, force_new)
   seginfo = seg_info (secptr);
   if (! seginfo)
     {
-      secptr->output_section = secptr;
+      /* Check whether output_section is set first because secptr may
+         be bfd_abs_section_ptr.  */
+      if (secptr->output_section != secptr)
+       secptr->output_section = secptr;
       seginfo = (segment_info_type *) xmalloc (sizeof (*seginfo));
-      seginfo->fix_root = 0;
-      seginfo->fix_tail = 0;
+      memset ((PTR) seginfo, 0, sizeof (*seginfo));
+      seginfo->fix_root = NULL;
+      seginfo->fix_tail = NULL;
       seginfo->bfd_section = secptr;
-      bfd_set_section_userdata (stdoutput, secptr, (char *) seginfo);
-      seginfo->frchainP = 0;
-      seginfo->lineno_list_head = seginfo->lineno_list_tail = 0;
-      seginfo->sym = 0;
-      seginfo->dot = 0;
-      seginfo->hadone = 0;
-      seginfo->user_stuff = 0;
-      seginfo->stabu.stab_string_size = 0;
+      if (secptr == bfd_abs_section_ptr)
+       abs_seg_info = seginfo;
+      else if (secptr == bfd_und_section_ptr)
+       und_seg_info = seginfo;
+      else
+       bfd_set_section_userdata (stdoutput, secptr, (PTR) seginfo);
+      seginfo->frchainP = NULL;
+      seginfo->lineno_list_head = seginfo->lineno_list_tail = NULL;
+      seginfo->sym = NULL;
+      seginfo->dot = NULL;
     }
   return secptr;
 }
@@ -458,23 +480,58 @@ subseg_set (secptr, subseg)
     subseg_set_rest (secptr, subseg);
 }
 
+#ifndef obj_sec_sym_ok_for_reloc
+#define obj_sec_sym_ok_for_reloc(SEC)  0
+#endif
+
+/* Get the gas information we are storing for a section.  */
+
+segment_info_type *
+seg_info (sec)
+     segT sec;
+{
+  if (sec == bfd_abs_section_ptr)
+    return abs_seg_info;
+  else if (sec == bfd_und_section_ptr)
+    return und_seg_info;
+  else
+    return (segment_info_type *) bfd_get_section_userdata (stdoutput, sec);
+}
+
 symbolS *
 section_symbol (sec)
      segT sec;
 {
   segment_info_type *seginfo = seg_info (sec);
+  symbolS *s;
 
   if (seginfo == 0)
     abort ();
   if (seginfo->sym)
     return seginfo->sym;
-  seginfo->sym = symbol_find (sec->name);
-  if (!seginfo->sym)
+  s = symbol_find (sec->name);
+  if (!s)
     {
-      seginfo->sym = symbol_make (sec->name);
-      seginfo->sym->bsym = sec->symbol;
+#ifndef EMIT_SECTION_SYMBOLS
+#define EMIT_SECTION_SYMBOLS 1
+#endif
+
+      if (EMIT_SECTION_SYMBOLS
+#ifdef BFD_ASSEMBLER
+         && symbol_table_frozen
+#endif
+         )
+       s = symbol_new (sec->name, sec, 0, &zero_address_frag);
+      else
+       s = symbol_create (sec->name, sec, 0, &zero_address_frag);
+      S_CLEAR_EXTERNAL (s);
+
+      /* Use the BFD section symbol, if possible.  */
+      if (obj_sec_sym_ok_for_reloc (sec))
+       s->bsym = sec->symbol;
     }
-  return seginfo->sym;
+  seginfo->sym = s;
+  return s;
 }
 
 #endif /* BFD_ASSEMBLER */
This page took 0.02494 seconds and 4 git commands to generate.