include/elf/
[deliverable/binutils-gdb.git] / gas / config / obj-elf.c
index b826803f9ff0146955394cc69f1a73eeb2a5fa12..0f0c7d30406db2f3f8b4167410b2d94cc1c3131d 100644 (file)
@@ -1,12 +1,13 @@
 /* ELF object file format
    Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+   2001, 2002, 2003, 2004, 2005, 2006, 2007
+   Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
 
    GAS is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2,
+   published by the Free Software Foundation; either version 3,
    or (at your option) any later version.
 
    GAS is distributed in the hope that it will be useful, but
@@ -781,31 +782,7 @@ obj_elf_parse_section_letters (char *str, size_t len)
 }
 
 static int
-obj_elf_section_word (char *str, size_t len)
-{
-  if (len == 5 && strncmp (str, "write", 5) == 0)
-    return SHF_WRITE;
-  if (len == 5 && strncmp (str, "alloc", 5) == 0)
-    return SHF_ALLOC;
-  if (len == 9 && strncmp (str, "execinstr", 9) == 0)
-    return SHF_EXECINSTR;
-  if (len == 3 && strncmp (str, "tls", 3) == 0)
-    return SHF_TLS;
-
-#ifdef md_elf_section_word
-  {
-    int md_attr = md_elf_section_word (str, len);
-    if (md_attr >= 0)
-      return md_attr;
-  }
-#endif
-
-  as_warn (_("unrecognized section attribute"));
-  return 0;
-}
-
-static int
-obj_elf_section_type (char *str, size_t len)
+obj_elf_section_type (char *str, size_t len, bfd_boolean warn)
 {
   if (len == 8 && strncmp (str, "progbits", 8) == 0)
     return SHT_PROGBITS;
@@ -828,7 +805,39 @@ obj_elf_section_type (char *str, size_t len)
   }
 #endif
 
-  as_warn (_("unrecognized section type"));
+  if (warn)
+    as_warn (_("unrecognized section type"));
+  return 0;
+}
+
+static int
+obj_elf_section_word (char *str, size_t len, int *type)
+{
+  int ret;
+
+  if (len == 5 && strncmp (str, "write", 5) == 0)
+    return SHF_WRITE;
+  if (len == 5 && strncmp (str, "alloc", 5) == 0)
+    return SHF_ALLOC;
+  if (len == 9 && strncmp (str, "execinstr", 9) == 0)
+    return SHF_EXECINSTR;
+  if (len == 3 && strncmp (str, "tls", 3) == 0)
+    return SHF_TLS;
+
+#ifdef md_elf_section_word
+  {
+    int md_attr = md_elf_section_word (str, len);
+    if (md_attr >= 0)
+      return md_attr;
+  }
+#endif
+
+  ret = obj_elf_section_type (str, len, FALSE);
+  if (ret != 0)
+    *type = ret;
+  else
+    as_warn (_("unrecognized section attribute"));
+
   return 0;
 }
 
@@ -882,6 +891,7 @@ obj_elf_section (int push)
   int type, attr, dummy;
   int entsize;
   int linkonce;
+  subsegT new_subsection = -1;
 
 #ifndef TC_I370
   if (flag_mri)
@@ -920,6 +930,22 @@ obj_elf_section (int push)
       ++input_line_pointer;
       SKIP_WHITESPACE ();
 
+      if (push && ISDIGIT (*input_line_pointer))
+       {
+         /* .pushsection has an optional subsection.  */
+         new_subsection = (subsegT) get_absolute_expression ();
+
+         SKIP_WHITESPACE ();
+
+         /* Stop if we don't see a comma.  */
+         if (*input_line_pointer != ',')
+           goto done;
+
+         /* Skip the comma.  */
+         ++input_line_pointer;
+         SKIP_WHITESPACE ();
+       }
+
       if (*input_line_pointer == '"')
        {
          beg = demand_copy_C_string (&dummy);
@@ -947,14 +973,14 @@ obj_elf_section (int push)
                      ignore_rest_of_line ();
                      return;
                    }
-                 type = obj_elf_section_type (beg, strlen (beg));
+                 type = obj_elf_section_type (beg, strlen (beg), TRUE);
                }
              else if (c == '@' || c == '%')
                {
                  beg = ++input_line_pointer;
                  c = get_symbol_end ();
                  *input_line_pointer = c;
-                 type = obj_elf_section_type (beg, input_line_pointer - beg);
+                 type = obj_elf_section_type (beg, input_line_pointer - beg, TRUE);
                }
              else
                input_line_pointer = save;
@@ -1017,7 +1043,7 @@ obj_elf_section (int push)
              c = get_symbol_end ();
              *input_line_pointer = c;
 
-             attr |= obj_elf_section_word (beg, input_line_pointer - beg);
+             attr |= obj_elf_section_word (beg, input_line_pointer - beg, & type);
 
              SKIP_WHITESPACE ();
            }
@@ -1026,9 +1052,13 @@ obj_elf_section (int push)
        }
     }
 
+done:
   demand_empty_rest_of_line ();
 
   obj_elf_change_section (name, type, attr, entsize, group_name, linkonce, push);
+
+  if (push && new_subsection != -1)
+    subseg_set (now_seg, new_subsection);
 }
 
 /* Change to the .data section.  */
@@ -1088,7 +1118,7 @@ obj_elf_struct (int i)
 static void
 obj_elf_subsection (int ignore ATTRIBUTE_UNUSED)
 {
-  register int temp;
+  int temp;
 
 #ifdef md_flush_pending_output
   md_flush_pending_output ();
@@ -1274,7 +1304,7 @@ obj_elf_vtable_inherit (int ignore ATTRIBUTE_UNUSED)
 
   if (csym == NULL || symbol_get_frag (csym) == NULL)
     {
-      as_bad ("expected `%s' to have already been set for .vtable_inherit",
+      as_bad (_("expected `%s' to have already been set for .vtable_inherit"),
              cname);
       bad = 1;
     }
@@ -1284,7 +1314,7 @@ obj_elf_vtable_inherit (int ignore ATTRIBUTE_UNUSED)
   SKIP_WHITESPACE ();
   if (*input_line_pointer != ',')
     {
-      as_bad ("expected comma after name in .vtable_inherit");
+      as_bad (_("expected comma after name in .vtable_inherit"));
       ignore_rest_of_line ();
       return NULL;
     }
@@ -1344,7 +1374,7 @@ obj_elf_vtable_entry (int ignore ATTRIBUTE_UNUSED)
   SKIP_WHITESPACE ();
   if (*input_line_pointer != ',')
     {
-      as_bad ("expected comma after name in .vtable_entry");
+      as_bad (_("expected comma after name in .vtable_entry"));
       ignore_rest_of_line ();
       return NULL;
     }
@@ -1521,7 +1551,7 @@ obj_elf_size (int ignore ATTRIBUTE_UNUSED)
 }
 
 /* Handle the ELF .type pseudo-op.  This sets the type of a symbol.
-   There are five syntaxes:
+   There are six syntaxes:
 
    The first (used on Solaris) is
        .type SYM,#function
@@ -1533,8 +1563,32 @@ obj_elf_size (int ignore ATTRIBUTE_UNUSED)
        .type SYM,%function
    The fifth (used on SVR4/860) is
        .type SYM,"function"
+   The sixth (emitted by recent SunPRO under Solaris) is
+       .type SYM,[0-9]
+   where the integer is the STT_* value.
    */
 
+static char *
+obj_elf_type_name (char *cp)
+{
+  char *p;
+
+  p = input_line_pointer;
+  if (*input_line_pointer >= '0'
+      && *input_line_pointer <= '9')
+    {
+      while (*input_line_pointer >= '0'
+            && *input_line_pointer <= '9')
+       ++input_line_pointer;
+      *cp = *input_line_pointer;
+      *input_line_pointer = '\0';
+    }
+  else
+    *cp = get_symbol_end ();
+
+  return p;
+}
+
 static void
 obj_elf_type (int ignore ATTRIBUTE_UNUSED)
 {
@@ -1562,22 +1616,67 @@ obj_elf_type (int ignore ATTRIBUTE_UNUSED)
       || *input_line_pointer == '%')
     ++input_line_pointer;
 
-  typename = input_line_pointer;
-  c = get_symbol_end ();
+  typename = obj_elf_type_name (& c);
 
   type = 0;
   if (strcmp (typename, "function") == 0
+      || strcmp (typename, "2") == 0
       || strcmp (typename, "STT_FUNC") == 0)
     type = BSF_FUNCTION;
   else if (strcmp (typename, "object") == 0
+          || strcmp (typename, "1") == 0
           || strcmp (typename, "STT_OBJECT") == 0)
     type = BSF_OBJECT;
   else if (strcmp (typename, "tls_object") == 0
+          || strcmp (typename, "6") == 0
           || strcmp (typename, "STT_TLS") == 0)
     type = BSF_OBJECT | BSF_THREAD_LOCAL;
   else if (strcmp (typename, "notype") == 0
+          || strcmp (typename, "0") == 0
           || strcmp (typename, "STT_NOTYPE") == 0)
     ;
+  else if (strcmp (typename, "common") == 0
+          || strcmp (typename, "5") == 0
+          || strcmp (typename, "STT_COMMON") == 0)
+    {
+      type = BSF_OBJECT;
+
+      if (! S_IS_COMMON (sym))
+       {
+         if (S_IS_VOLATILE (sym))
+           {
+             sym = symbol_clone (sym, 1);
+             S_SET_SEGMENT (sym, bfd_com_section_ptr);
+             S_SET_VALUE (sym, 0);
+             S_SET_EXTERNAL (sym);
+             symbol_set_frag (sym, &zero_address_frag);
+             S_CLEAR_VOLATILE (sym);
+           }
+         else if (S_IS_DEFINED (sym) || symbol_equated_p (sym))
+           as_bad (_("symbol '%s' is already defined"), S_GET_NAME (sym));
+         else
+           {
+             /* FIXME: Is it safe to just change the section ?  */
+             S_SET_SEGMENT (sym, bfd_com_section_ptr);
+             S_SET_VALUE (sym, 0);
+             S_SET_EXTERNAL (sym);
+           }
+       }
+    }
+  else if (strcmp (typename, "indirect_function") == 0
+      || strcmp (typename, "10") == 0
+      || strcmp (typename, "STT_IFUNC") == 0)
+    {
+      const struct elf_backend_data *bed;
+
+      bed = get_elf_backend_data (stdoutput);
+      if (!(bed->elf_osabi == ELFOSABI_LINUX
+           /* GNU/Linux is still using the default value 0.  */
+           || bed->elf_osabi == ELFOSABI_NONE))
+       as_bad (_("symbol type \"%s\" is supported only by GNU targets"),
+               typename);
+      type = BSF_FUNCTION | BSF_INDIRECT_FUNCTION;
+    }
 #ifdef md_elf_symbol_type
   else if ((type = md_elf_symbol_type (typename, sym, elfsym)) != -1)
     ;
@@ -1617,7 +1716,7 @@ obj_elf_ident (int ignore ATTRIBUTE_UNUSED)
     }
   else
     subseg_set (comment_section, 0);
-  stringer (1);
+  stringer (8 + 1);
   subseg_set (old_section, old_subsection);
 }
 
@@ -1693,6 +1792,9 @@ adjust_stab_sections (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED)
    this at the moment, so we do it ourselves.  We save the information
    in the symbol.  */
 
+#ifdef OBJ_MAYBE_ELF
+static
+#endif
 void
 elf_ecoff_set_ext (symbolS *sym, struct ecoff_extr *ext)
 {
This page took 0.02783 seconds and 4 git commands to generate.