* ldemul.c (ldemul_new_vers_pattern): New function.
authorAlan Modra <amodra@gmail.com>
Wed, 22 May 2002 09:04:48 +0000 (09:04 +0000)
committerAlan Modra <amodra@gmail.com>
Wed, 22 May 2002 09:04:48 +0000 (09:04 +0000)
* ldemul.h (ldemul_new_vers_pattern): Declare.
(struct ld_emulation_xfer_struct): Add new_vers_pattern.
* ldlang.c (lang_new_vers_pattern): Call ldemul_new_vers_pattern.
* emultempl/ppc64elf.em (dotsyms): New static var.
(gld${EMULATION_NAME}_new_vers_pattern): New function.
(LDEMUL_NEW_VERS_PATTERN): Define.
(PARSE_AND_LIST_PROLOGUE): Add OPTION_DOTSYMS, OPTION_NO_DOTSYMS.
(PARSE_AND_LIST_LONGOPTS): Likewise.
(PARSE_AND_LIST_ARGS_CASES): Handle them.
* emultempl/aix.em (ld_${EMULATION_NAME}_emulation): Update
initialiser.
* emultempl/armcoff.em: Likewise.
* emultempl/armelf_oabi.em: Likewise.
* emultempl/beos.em: Likewise.
* emultempl/elf32.em: Likewise.
* emultempl/generic.em: Likewise.
* emultempl/gld960.em: Likewise.
* emultempl/gld960c.em: Likewise.
* emultempl/linux.em: Likewise.
* emultempl/lnk960.em: Likewise.
* emultempl/m68kcoff.em: Likewise.
* emultempl/mipsecoff.em: Likewise.
* emultempl/pe.em: Likewise.
* emultempl/sunos.em: Likewise.
* emultempl/ticoff.em: Likewise.
* emultempl/vanilla.em: Likewise.

21 files changed:
ld/ChangeLog
ld/emultempl/aix.em
ld/emultempl/armcoff.em
ld/emultempl/armelf_oabi.em
ld/emultempl/beos.em
ld/emultempl/elf32.em
ld/emultempl/generic.em
ld/emultempl/gld960.em
ld/emultempl/gld960c.em
ld/emultempl/linux.em
ld/emultempl/lnk960.em
ld/emultempl/m68kcoff.em
ld/emultempl/mipsecoff.em
ld/emultempl/pe.em
ld/emultempl/ppc64elf.em
ld/emultempl/sunos.em
ld/emultempl/ticoff.em
ld/emultempl/vanilla.em
ld/ldemul.c
ld/ldemul.h
ld/ldlang.c

index 57ef8c9f4a742d639e1a690fdb0dacb4f085f76e..c6dc6fe076a5db4fcd7e954dec94548a31aac3ca 100644 (file)
@@ -1,3 +1,33 @@
+2002-05-22  Alan Modra  <amodra@bigpond.net.au>
+
+       * ldemul.c (ldemul_new_vers_pattern): New function.
+       * ldemul.h (ldemul_new_vers_pattern): Declare.
+       (struct ld_emulation_xfer_struct): Add new_vers_pattern.
+       * ldlang.c (lang_new_vers_pattern): Call ldemul_new_vers_pattern.
+       * emultempl/ppc64elf.em (dotsyms): New static var.
+       (gld${EMULATION_NAME}_new_vers_pattern): New function.
+       (LDEMUL_NEW_VERS_PATTERN): Define.
+       (PARSE_AND_LIST_PROLOGUE): Add OPTION_DOTSYMS, OPTION_NO_DOTSYMS.
+       (PARSE_AND_LIST_LONGOPTS): Likewise.
+       (PARSE_AND_LIST_ARGS_CASES): Handle them.
+       * emultempl/aix.em (ld_${EMULATION_NAME}_emulation): Update
+       initialiser.
+       * emultempl/armcoff.em: Likewise.
+       * emultempl/armelf_oabi.em: Likewise.
+       * emultempl/beos.em: Likewise.
+       * emultempl/elf32.em: Likewise.
+       * emultempl/generic.em: Likewise.
+       * emultempl/gld960.em: Likewise.
+       * emultempl/gld960c.em: Likewise.
+       * emultempl/linux.em: Likewise.
+       * emultempl/lnk960.em: Likewise.
+       * emultempl/m68kcoff.em: Likewise.
+       * emultempl/mipsecoff.em: Likewise.
+       * emultempl/pe.em: Likewise.
+       * emultempl/sunos.em: Likewise.
+       * emultempl/ticoff.em: Likewise.
+       * emultempl/vanilla.em: Likewise.
+
 2002-05-22  Alan Modra  <amodra@bigpond.net.au>
 
        * genscripts.sh (LIB_PATH): For native targets, concatenate $libdir
index 50bfe64a25b54b15c9aec1f58ddb61650c5cf192..3caa0187266c27c393504cf648d27a140fdd7c25 100644 (file)
@@ -1375,5 +1375,6 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = {
   NULL,                                /* list_options */
   NULL,                                /* recognized_file */
   NULL,                                /* find potential_libraries */
+  NULL                         /* new_vers_pattern */
 };
 EOF
index 783efa9245eb126c02e7a5a003519950158df7a1..c6a9895c3011339d57a14d77c6d5e55fec65c9a5 100644 (file)
@@ -289,6 +289,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
   NULL,        /* unrecognised file */
   gld${EMULATION_NAME}_list_options,
   NULL,        /* recognized file */
-  NULL         /* find_potential_libraries */
+  NULL,        /* find_potential_libraries */
+  NULL /* new_vers_pattern */
 };
 EOF
index b0c56698f9619f26bdcd2c7014c925c1a004982f..aae7ea9f060e9f9fdf4ce25979f5ccd6bc7e29d0 100644 (file)
@@ -174,6 +174,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
   NULL,        /* unrecognized file */
   NULL,        /* list options */
   NULL,        /* recognized file */
-  NULL         /* find_potential_libraries */
+  NULL,        /* find_potential_libraries */
+  NULL /* new_vers_pattern */
 };
 EOF
index e6e6b58cfbcf7c3b2cd875d3f7738cd2ee21d8a3..256c55d3005099d3fe3c7cc3daff04e3616f9d5f 100644 (file)
@@ -874,6 +874,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
   NULL,        /* unrecognized file */
   NULL,        /* list options */
   NULL,        /* recognized file */
-  NULL /* find_potential_libraries */
+  NULL,        /* find_potential_libraries */
+  NULL /* new_vers_pattern */
 };
 EOF
index 5f12e69f072bcd152d74628b01ba43d60c89e988..a85d97d76892de54fe8e95f6c190973b233240a5 100644 (file)
@@ -1659,5 +1659,6 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
   ${LDEMUL_LIST_OPTIONS-gld${EMULATION_NAME}_list_options},
   ${LDEMUL_RECOGNIZED_FILE-NULL},
   ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL},
+  ${LDEMUL_NEW_VERS_PATTERN-NULL}
 };
 EOF
index 382150f6c371430b09bf6ae2b6e58e1aabac455c..397422ce67060234da99dd70cf7819bba434eda7 100644 (file)
@@ -144,6 +144,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
   ${LDEMUL_UNRECOGNIZED_FILE-NULL},
   ${LDEMUL_LIST_OPTIONS-NULL},
   ${LDEMUL_RECOGNIZED_FILE-NULL},
-  ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL}
+  ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL},
+  ${LDEMUL_NEW_VERS_PATTERN-NULL}
 };
 EOF
index 88cfbcc77e888b67f4064fa0407ea38305f8ddca..c37f4b399724c935569a1d0024a936e716eb4e52 100644 (file)
@@ -189,6 +189,7 @@ struct ld_emulation_xfer_struct ld_gld960_emulation =
   NULL,        /* unrecognized file */
   NULL,        /* list options */
   NULL,        /* recognized file */
-  NULL         /* find_potential_libraries */
+  NULL,        /* find_potential_libraries */
+  NULL /* new_vers_pattern */
 };
 EOF
index 0772bcad6034304a733f05addc6d2d6d6f3f7692..261a3f8cf36d0f5af94a7bfad840f04d206fd265 100644 (file)
@@ -204,6 +204,7 @@ struct ld_emulation_xfer_struct ld_gld960coff_emulation =
   NULL,        /* unrecognized file */
   NULL,        /* list options */
   NULL,        /* recognized file */
-  NULL         /* find_potential_libraries */
+  NULL,        /* find_potential_libraries */
+  NULL /* new_vers_pattern */
 };
 EOF
index 85ed138d74673cefcee3722947be17e77ace7050..fda490b5da8bdf795d721b204f0e7be6bf2fe8d3 100644 (file)
@@ -221,6 +221,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
   NULL,        /* unrecognized file */
   NULL,        /* list options */
   NULL,        /* recognized file */
-  NULL         /* find_potential_libraries */
+  NULL,        /* find_potential_libraries */
+  NULL /* new_vers_pattern */
 };
 EOF
index f5741b4c4ed2a394e1561c3460efca67e3c8e674..f23f2bc85d79a5f075823beef87b4fb3e72f4e63 100644 (file)
@@ -345,6 +345,7 @@ struct ld_emulation_xfer_struct ld_lnk960_emulation =
   NULL,        /* unrecognized file */
   NULL,        /* list options */
   NULL,        /* recognized file */
-  NULL         /* find_potential_libraries */
+  NULL,        /* find_potential_libraries */
+  NULL /* new_vers_pattern */
 };
 EOF
index 078324fcc582b3380aca7bd48c66569a8f49743e..8ac4e616a7e187691824562e5ffd7e1a244026bd 100644 (file)
@@ -240,6 +240,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
   NULL,        /* unrecognized file */
   NULL,        /* list options */
   NULL,        /* recognized file */
-  NULL         /* find_potential_libraries */
+  NULL,        /* find_potential_libraries */
+  NULL /* new_vers_pattern */
 };
 EOF
index 7fc392cae5bfe4c8b6e626470f59a8db48be31d8..9521e016a056d2b328a66de3af356888bc40c847 100644 (file)
@@ -255,6 +255,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
   NULL,        /* unrecognized file */
   NULL,        /* list options */
   NULL,        /* recognized file */
-  NULL         /* find_potential_libraries */
+  NULL,        /* find_potential_libraries */
+  NULL /* new_vers_pattern */
 };
 EOF
index ad4c6ba91c5e0be485e3974764e26e7a1c1f92d9..d9db9ae7c062e609c2aa89e91b44b8bedc56448c 100644 (file)
@@ -1937,6 +1937,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
   gld_${EMULATION_NAME}_unrecognized_file,
   gld_${EMULATION_NAME}_list_options,
   gld_${EMULATION_NAME}_recognized_file,
-  gld_${EMULATION_NAME}_find_potential_libraries
+  gld_${EMULATION_NAME}_find_potential_libraries,
+  NULL /* new_vers_pattern */
 };
 EOF
index a280804403f46fe7c432df4797f7b7f741443f5a..3c1eb8e88cbd0eaeddc338bc3714d24938dfb5d6 100644 (file)
@@ -38,11 +38,16 @@ static int need_laying_out = 0;
    should use a suitable default size.  */
 static bfd_signed_vma group_size = 1;
 
+/* Whether to add ".foo" entries for each "foo" in a version script.  */
+static int dotsyms = 1;
+
 static void ppc_create_output_section_statements PARAMS ((void));
 static asection *ppc_add_stub_section PARAMS ((const char *, asection *));
 static void ppc_layout_sections_again PARAMS ((void));
 static void gld${EMULATION_NAME}_after_allocation PARAMS ((void));
 static void build_section_lists PARAMS ((lang_statement_union_type *));
+static struct bfd_elf_version_expr *gld${EMULATION_NAME}_new_vers_pattern
+  PARAMS ((struct bfd_elf_version_expr *));
 
 /* This is called before the input files are opened.  We create a new
    fake input file to hold the stub sections.  */
@@ -242,6 +247,7 @@ build_section_lists (statement)
     }
 }
 
+
 /* Final emulation specific call.  */
 
 static void
@@ -301,6 +307,77 @@ gld${EMULATION_NAME}_finish ()
 }
 
 
+/* Add a pattern matching ".foo" for every "foo" in a version script.
+
+   The reason for doing this is that many shared library version
+   scripts export a selected set of functions or data symbols, forcing
+   others local.  eg.
+
+   . VERS_1 {
+   .       global:
+   .               this; that; some; thing;
+   .       local:
+   .               *;
+   .   };
+
+   To make the above work for PowerPC64, we need to export ".this",
+   ".that" and so on, otherwise only the function descriptor syms are
+   exported.  Lack of an exported function code sym may cause a
+   definition to be pulled in from a static library.  */
+
+struct bfd_elf_version_expr *
+gld${EMULATION_NAME}_new_vers_pattern (entry)
+     struct bfd_elf_version_expr *entry;
+{
+  struct bfd_elf_version_expr *dot_entry;
+  struct bfd_elf_version_expr *next;
+  unsigned int len;
+  char *dot_pat;
+
+  if (!dotsyms || entry->pattern[0] == '*')
+    return entry;
+
+  /* Is the script adding ".foo" explicitly?  */
+  if (entry->pattern[0] == '.')
+    {
+      /* We may have added this pattern automatically.  Don't add it
+        again.  Quadratic behaviour here is acceptable as the list
+        may be traversed for each input bfd symbol.  */
+      for (next = entry->next; next != NULL; next = next->next)
+       {
+         if (strcmp (next->pattern, entry->pattern) == 0
+             && next->match == entry->match)
+           {
+             next = entry->next;
+             free (entry->pattern);
+             free (entry);
+             return next;
+           }
+       }
+      return entry;
+    }
+
+  /* Don't add ".foo" if the script has already done so.  */
+  for (next = entry->next; next != NULL; next = next->next)
+    {
+      if (next->pattern[0] == '.'
+         && strcmp (next->pattern + 1, entry->pattern) == 0
+         && next->match == entry->match)
+       return entry;
+    }
+
+  dot_entry = (struct bfd_elf_version_expr *) xmalloc (sizeof *dot_entry);
+  dot_entry->next = entry;
+  len = strlen (entry->pattern) + 2;
+  dot_pat = xmalloc (len);
+  dot_pat[0] = '.';
+  memcpy (dot_pat + 1, entry->pattern, len - 1);
+  dot_entry->pattern = dot_pat;
+  dot_entry->match = entry->match;
+  return dot_entry;
+}
+
+
 /* Avoid processing the fake stub_file in vercheck, stat_needed and
    check_needed routines.  */
 
@@ -335,6 +412,8 @@ EOF
 #
 PARSE_AND_LIST_PROLOGUE='
 #define OPTION_STUBGROUP_SIZE          301
+#define OPTION_DOTSYMS                 (OPTION_STUBGROUP_SIZE + 1)
+#define OPTION_NO_DOTSYMS              (OPTION_DOTSYMS + 1)
 '
 
 # The options are repeated below so that no abbreviations are allowed.
@@ -342,6 +421,10 @@ PARSE_AND_LIST_PROLOGUE='
 PARSE_AND_LIST_LONGOPTS='
   { "stub-group-size", required_argument, NULL, OPTION_STUBGROUP_SIZE },
   { "stub-group-size", required_argument, NULL, OPTION_STUBGROUP_SIZE },
+  { "dotsyms", no_argument, NULL, OPTION_DOTSYMS },
+  { "dotsyms", no_argument, NULL, OPTION_DOTSYMS },
+  { "no-dotsyms", no_argument, NULL, OPTION_NO_DOTSYMS },
+  { "no-dotsyms", no_argument, NULL, OPTION_NO_DOTSYMS },
 '
 
 PARSE_AND_LIST_OPTIONS='
@@ -354,6 +437,15 @@ PARSE_AND_LIST_OPTIONS='
                           after each stub section.  Values of +/-1 indicate\n\
                           the linker should choose suitable defaults.\n"
                   ));
+  fprintf (file, _("\
+  --dotsyms             For every version pattern \"foo\" in a version script,\n\
+                          add \".foo\" so that function code symbols are\n\
+                          treated the same as function descriptor symbols.\n\
+                          Defaults to on.\n"
+                  ));
+  fprintf (file, _("\
+  --no-dotsyms          Don'\''t do anything special in version scripts.\n"
+                  ));
 '
 
 PARSE_AND_LIST_ARGS_CASES='
@@ -365,6 +457,18 @@ PARSE_AND_LIST_ARGS_CASES='
          einfo (_("%P%F: invalid number `%s'\''\n"), optarg);
       }
       break;
+
+    case OPTION_DOTSYMS:
+      {
+       dotsyms = 1;
+      }
+      break;
+
+    case OPTION_NO_DOTSYMS:
+      {
+       dotsyms = 0;
+      }
+      break;
 '
 
 # Put these extra ppc64elf routines in ld_${EMULATION_NAME}_emulation
@@ -372,3 +476,4 @@ PARSE_AND_LIST_ARGS_CASES='
 LDEMUL_AFTER_ALLOCATION=gld${EMULATION_NAME}_after_allocation
 LDEMUL_FINISH=gld${EMULATION_NAME}_finish
 LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=ppc_create_output_section_statements
+LDEMUL_NEW_VERS_PATTERN=gld${EMULATION_NAME}_new_vers_pattern
index 17cd40787ce5f9fb3e7233957bfb6c648e895997..64e5ea5dd458dea098aeb3dffe2fe2865efa00b6 100644 (file)
@@ -1050,6 +1050,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
   NULL,        /* unrecognized file */
   NULL,        /* list options */
   NULL,        /* recognized file */
-  NULL         /* find_potential_libraries */
+  NULL,        /* find_potential_libraries */
+  NULL /* new_vers_pattern */
 };
 EOF
index a2ab4dbfbc22707ba6e824bcaa9f540c42480667..eb103177f1d54a051f247eaff056a0afc0eddfe1 100644 (file)
@@ -197,6 +197,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
   NULL, /* unrecognized_file */
   gld_${EMULATION_NAME}_list_options,
   NULL, /* recognized file */
-  NULL         /* find_potential_libraries */
+  NULL,        /* find_potential_libraries */
+  NULL /* new_vers_pattern */
 };
 EOF
index 96ee34c8aef76214af1c2d48f5d7a56709534e17..4c38207a51cf91fdadfe2b8ee11ff52afeef6eaf 100644 (file)
@@ -82,6 +82,7 @@ struct ld_emulation_xfer_struct ld_vanilla_emulation =
   NULL,        /* unrecognized file */
   NULL,        /* list options */
   NULL,        /* recognized file */
-  NULL         /* find_potential_libraries */
+  NULL,        /* find_potential_libraries */
+  NULL /* new_vers_pattern */
 };
 EOF
index 6b96204183e372b1ef714bae13c072d6c95b5189..abf3419f99fe8aef0f5701fde816c6228bd5d6ed 100644 (file)
@@ -308,3 +308,12 @@ ldemul_find_potential_libraries (name, entry)
 
   return 0;
 }
+
+struct bfd_elf_version_expr *
+ldemul_new_vers_pattern (entry)
+     struct bfd_elf_version_expr *entry;
+{
+  if (ld_emulation->new_vers_pattern)
+    entry = (*ld_emulation->new_vers_pattern) (entry);
+  return entry;
+}
index c49961c15cfd071e38d6fe97dddff5743df75617..3e275002ac50bc22461d3a32dbc650ebc0724275 100644 (file)
@@ -53,6 +53,8 @@ extern void syslib_default PARAMS ((char*));
 extern void hll_default PARAMS ((char*));
 extern int  ldemul_find_potential_libraries
   PARAMS ((char *, struct lang_input_statement_struct *));
+extern struct bfd_elf_version_expr *ldemul_new_vers_pattern
+  PARAMS ((struct bfd_elf_version_expr *));
 
 typedef struct ld_emulation_xfer_struct {
   /* Run before parsing the command line and script file.
@@ -139,6 +141,11 @@ typedef struct ld_emulation_xfer_struct {
   int (* find_potential_libraries)
     PARAMS ((char *, struct lang_input_statement_struct *));
 
+  /* Called when adding a new version pattern.  PowerPC64-ELF uses
+     this hook to add a pattern matching ".foo" for every "foo".  */
+  struct bfd_elf_version_expr * (*new_vers_pattern)
+    PARAMS ((struct bfd_elf_version_expr *));
+
 } ld_emulation_xfer_type;
 
 typedef enum {
index 885f74c3b02990d70a9558bdb762ed486f4dd3b3..796f889dab5e82b6f735702f1be30cff56f6bfd6 100644 (file)
@@ -5083,7 +5083,7 @@ lang_new_vers_pattern (orig, new, lang)
       ret->match = lang_vers_match_lang_c;
     }
 
-  return ret;
+  return ldemul_new_vers_pattern (ret);
 }
 
 /* This is called for each set of variable names and match