gdb: fix building on Darwin 9
[deliverable/binutils-gdb.git] / ld / deffilep.y
index c1c95d2872ecca1f3baa33d4fac4f9764c80ff7f..3afb3ce3ce859ffcd370f53c99afbeadb3136c2e 100644 (file)
@@ -113,6 +113,7 @@ static const char *lex_parse_string_end = 0;
 
 %union {
   char *id;
+  const char *id_const;
   int number;
   char *digits;
 };
@@ -127,8 +128,9 @@ static const char *lex_parse_string_end = 0;
 %type  <digits> opt_digits
 %type  <number> opt_base opt_ordinal
 %type  <number> attr attr_list opt_number exp_opt_list exp_opt
-%type  <id> opt_name opt_equal_name dot_name anylang_id opt_id
+%type  <id> opt_name opt_name2 opt_equal_name anylang_id opt_id
 %type  <id> opt_equalequal_name
+%type  <id_const> keyword_as_name
 
 %%
 
@@ -164,7 +166,7 @@ expline:
                /* The opt_comma is necessary to support both the usual
                  DEF file syntax as well as .drectve syntax which
                  mandates <expsym>,<expoptlist>.  */
-               dot_name opt_equal_name opt_ordinal opt_comma exp_opt_list opt_comma opt_equalequal_name
+               opt_name2 opt_equal_name opt_ordinal opt_comma exp_opt_list opt_comma opt_equalequal_name
                        { def_exports ($1, $2, $3, $5, $7); }
        ;
 exp_opt_list:
@@ -234,19 +236,65 @@ attr:
        |       SHARED  { $$=8;}
        ;
 
-opt_name: ID           { $$ = $1; }
-       | '.' ID
+
+keyword_as_name: BASE { $$ = "BASE"; }
+        | CODE { $$ = "CODE"; }
+        | CONSTANTU { $$ = "CONSTANT"; }
+        | CONSTANTL { $$ = "constant"; }
+        | DATAU { $$ = "DATA"; }
+        | DATAL { $$ = "data"; }
+        | DESCRIPTION { $$ = "DESCRIPTION"; }
+        | DIRECTIVE { $$ = "DIRECTIVE"; }
+        | EXECUTE { $$ = "EXECUTE"; }
+        | EXPORTS { $$ = "EXPORTS"; }
+        | HEAPSIZE { $$ = "HEAPSIZE"; }
+        | IMPORTS { $$ = "IMPORTS"; }
+/* Disable LIBRARY keyword as valid symbol-name.  This is necessary
+   for libtool, which places this command after EXPORTS command.
+   This behavior is illegal by specification, but sadly required by
+   by compatibility reasons.
+   See PR binutils/13710
+        | LIBRARY { $$ = "LIBRARY"; } */
+        | NAME { $$ = "NAME"; }
+        | NONAMEU { $$ = "NONAME"; }
+        | NONAMEL { $$ = "noname"; }
+        | PRIVATEU { $$ = "PRIVATE"; }
+        | PRIVATEL { $$ = "private"; }
+        | READ { $$ = "READ"; }
+        | SHARED  { $$ = "SHARED"; }
+        | STACKSIZE_K { $$ = "STACKSIZE"; }
+        | VERSIONK { $$ = "VERSION"; }
+        | WRITE { $$ = "WRITE"; }
+        ;
+
+opt_name2: ID { $$ = $1; }
+       | '.' keyword_as_name
          {
+           char *name = xmalloc (strlen ($2) + 2);
+           sprintf (name, ".%s", $2);
+           $$ = name;
+         }
+       | '.' opt_name2
+         { 
            char *name = def_pool_alloc (strlen ($2) + 2);
            sprintf (name, ".%s", $2);
            $$ = name;
          }
-       | ID '.' ID     
+       | keyword_as_name '.' opt_name2
+         { 
+           char *name = def_pool_alloc (strlen ($1) + 1 + strlen ($3) + 1);
+           sprintf (name, "%s.%s", $1, $3);
+           $$ = name;
+         }
+       | ID '.' opt_name2
          { 
            char *name = def_pool_alloc (strlen ($1) + 1 + strlen ($3) + 1);
            sprintf (name, "%s.%s", $1, $3);
            $$ = name;
          }
+       ;
+
+opt_name: opt_name2 { $$ = $1; }
        |               { $$ = ""; }
        ;
 
@@ -260,7 +308,7 @@ opt_ordinal:
        ;
 
 opt_equal_name:
-          '=' dot_name { $$ = $2; }
+          '=' opt_name2        { $$ = $2; }
         |              { $$ =  0; }                     
        ;
 
@@ -268,21 +316,6 @@ opt_base: BASE     '=' NUMBER      { $$ = $3;}
        |       { $$ = -1;}
        ;
 
-dot_name: ID           { $$ = $1; }
-       | '.' ID
-         {
-           char *name = def_pool_alloc (strlen ($2) + 2);
-           sprintf (name, ".%s", $2);
-           $$ = name;
-         }
-       | dot_name '.' ID       
-         { 
-           char *name = def_pool_alloc (strlen ($1) + 1 + strlen ($3) + 1);
-           sprintf (name, "%s.%s", $1, $3);
-           $$ = name;
-         }
-       ;
-
 anylang_id: ID         { $$ = $1; }
        | '.' ID
          {
@@ -594,13 +627,21 @@ find_export_in_list (def_file_export *b, int max,
   if (!max)
     return 0;
   if ((e = cmp_export_elem (b, ex_name, in_name, its_name, ord)) <= 0)
-    return 0;
+    {
+      if (!e)
+        *is_ident = 1;
+      return 0;
+    }
   if (max == 1)
     return 1;
   if ((e = cmp_export_elem (b + (max - 1), ex_name, in_name, its_name, ord)) > 0)
     return max;
   else if (!e || max == 2)
-    return max - 1;
+    {
+      if (!e)
+       *is_ident = 1;
+      return max - 1;
+    }
   l = 0; r = max - 1;
   while (l < r)
     {
@@ -705,13 +746,15 @@ cmp_import_elem (const def_file_import *e, const char *ex_name,
 {
   int r;
 
+  if ((r = are_names_equal (module, (e->module ? e->module->name : NULL))))
+    return r;
   if ((r = are_names_equal (ex_name, e->name)) != 0)
     return r;
   if ((r = are_names_equal (in_name, e->internal_name)) != 0)
     return r;
   if (ord != e->ordinal)
     return (ord < e->ordinal ? -1 : 1);
-  return are_names_equal (module, (e->module ? e->module->name : NULL));
+  return 0;
 }
 
 /* Search the position of the identical element, or returns the position
@@ -729,13 +772,21 @@ find_import_in_list (def_file_import *b, int max,
   if (!max)
     return 0;
   if ((e = cmp_import_elem (b, ex_name, in_name, module, ord)) <= 0)
-    return 0;
+    {
+      if (!e)
+        *is_ident = 1;
+      return 0;
+    }
   if (max == 1)
     return 1;
   if ((e = cmp_import_elem (b + (max - 1), ex_name, in_name, module, ord)) > 0)
     return max;
   else if (!e || max == 2)
-    return max - 1;
+    {
+      if (!e)
+        *is_ident = 1;
+      return max - 1;
+    }
   l = 0; r = max - 1;
   while (l < r)
     {
@@ -1095,13 +1146,39 @@ def_directive (char *str)
 static void
 def_aligncomm (char *str, int align)
 {
-  def_file_aligncomm *c = xmalloc (sizeof (def_file_aligncomm));
+  def_file_aligncomm *c, *p;
+  
+  p = NULL;
+  c = def->aligncomms;
+  while (c != NULL)
+    {
+      int e = strcmp (c->symbol_name, str);
+      if (!e)
+       {
+         /* Not sure if we want to allow here duplicates with
+            different alignments, but for now we keep them.  */
+         e = (int) c->alignment - align;
+         if (!e)
+           return;
+       }
+      if (e > 0)
+        break;
+      c = (p = c)->next;
+    }
 
+  c = xmalloc (sizeof (def_file_aligncomm));
   c->symbol_name = xstrdup (str);
   c->alignment = (unsigned int) align;
-
-  c->next = def->aligncomms;
-  def->aligncomms = c;
+  if (!p)
+    {
+      c->next = def->aligncomms;
+      def->aligncomms = c;
+    }
+  else
+    {
+      c->next = p->next;
+      p->next = c;
+    }
 }
 
 static int
This page took 0.026861 seconds and 4 git commands to generate.