This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
version script trickery for powerpc64-linux
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: binutils at sources dot redhat dot com
- Cc: Olaf Hering <olh at suse dot de>, Peter Bergner <peter at bergner dot org>, Steve Munroe <sjmunroe at us dot ibm dot com>
- Date: Wed, 22 May 2002 18:28:22 +0930
- Subject: version script trickery for powerpc64-linux
This allows powerpc64-linux to use standard version scripts when
building shared libs. See the comment starting with
"/* Add a pattern matching ".
ld/ChangeLog
* 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.
Index: ld/ldemul.c
===================================================================
RCS file: /cvs/src/src/ld/ldemul.c,v
retrieving revision 1.8
diff -u -p -r1.8 ldemul.c
--- ld/ldemul.c 3 Dec 2001 23:15:26 -0000 1.8
+++ ld/ldemul.c 22 May 2002 07:56:21 -0000
@@ -308,3 +308,12 @@ ldemul_find_potential_libraries (name, e
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: ld/ldemul.h
===================================================================
RCS file: /cvs/src/src/ld/ldemul.h,v
retrieving revision 1.7
diff -u -p -r1.7 ldemul.h
--- ld/ldemul.h 3 Dec 2001 23:15:26 -0000 1.7
+++ ld/ldemul.h 22 May 2002 07:56:21 -0000
@@ -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.
@@ -138,6 +140,11 @@ typedef struct ld_emulation_xfer_struct
(For VMS files matching ":lib*.a" have also been scanned). */
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;
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.84
diff -u -p -r1.84 ldlang.c
--- ld/ldlang.c 15 May 2002 00:19:23 -0000 1.84
+++ ld/ldlang.c 22 May 2002 07:56:26 -0000
@@ -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
Index: ld/emultempl/aix.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/aix.em,v
retrieving revision 1.24
diff -u -p -r1.24 aix.em
--- ld/emultempl/aix.em 18 May 2002 16:56:27 -0000 1.24
+++ ld/emultempl/aix.em 22 May 2002 07:56:27 -0000
@@ -1375,5 +1375,6 @@ struct ld_emulation_xfer_struct ld_${EMU
NULL, /* list_options */
NULL, /* recognized_file */
NULL, /* find potential_libraries */
+ NULL /* new_vers_pattern */
};
EOF
Index: ld/emultempl/armcoff.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/armcoff.em,v
retrieving revision 1.11
diff -u -p -r1.11 armcoff.em
--- ld/emultempl/armcoff.em 3 Sep 2001 06:43:36 -0000 1.11
+++ ld/emultempl/armcoff.em 22 May 2002 07:56:28 -0000
@@ -289,6 +289,7 @@ struct ld_emulation_xfer_struct ld_${EMU
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: ld/emultempl/armelf_oabi.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/armelf_oabi.em,v
retrieving revision 1.8
diff -u -p -r1.8 armelf_oabi.em
--- ld/emultempl/armelf_oabi.em 3 Sep 2001 06:43:36 -0000 1.8
+++ ld/emultempl/armelf_oabi.em 22 May 2002 07:56:28 -0000
@@ -174,6 +174,7 @@ struct ld_emulation_xfer_struct ld_${EMU
NULL, /* unrecognized file */
NULL, /* list options */
NULL, /* recognized file */
- NULL /* find_potential_libraries */
+ NULL, /* find_potential_libraries */
+ NULL /* new_vers_pattern */
};
EOF
Index: ld/emultempl/beos.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/beos.em,v
retrieving revision 1.17
diff -u -p -r1.17 beos.em
--- ld/emultempl/beos.em 15 Feb 2002 02:11:05 -0000 1.17
+++ ld/emultempl/beos.em 22 May 2002 07:56:28 -0000
@@ -874,6 +874,7 @@ struct ld_emulation_xfer_struct ld_${EMU
NULL, /* unrecognized file */
NULL, /* list options */
NULL, /* recognized file */
- NULL /* find_potential_libraries */
+ NULL, /* find_potential_libraries */
+ NULL /* new_vers_pattern */
};
EOF
Index: ld/emultempl/elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.74
diff -u -p -r1.74 elf32.em
--- ld/emultempl/elf32.em 22 May 2002 05:08:31 -0000 1.74
+++ ld/emultempl/elf32.em 22 May 2002 07:56:29 -0000
@@ -1659,5 +1659,6 @@ struct ld_emulation_xfer_struct ld_${EMU
${LDEMUL_LIST_OPTIONS-gld${EMULATION_NAME}_list_options},
${LDEMUL_RECOGNIZED_FILE-NULL},
${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL},
+ ${LDEMUL_NEW_VERS_PATTERN-NULL}
};
EOF
Index: ld/emultempl/generic.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/generic.em,v
retrieving revision 1.8
diff -u -p -r1.8 generic.em
--- ld/emultempl/generic.em 13 Aug 2001 07:31:29 -0000 1.8
+++ ld/emultempl/generic.em 22 May 2002 07:56:29 -0000
@@ -144,6 +144,7 @@ struct ld_emulation_xfer_struct ld_${EMU
${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: ld/emultempl/gld960.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/gld960.em,v
retrieving revision 1.8
diff -u -p -r1.8 gld960.em
--- ld/emultempl/gld960.em 3 Dec 2001 23:15:27 -0000 1.8
+++ ld/emultempl/gld960.em 22 May 2002 07:56:29 -0000
@@ -189,6 +189,7 @@ struct ld_emulation_xfer_struct ld_gld96
NULL, /* unrecognized file */
NULL, /* list options */
NULL, /* recognized file */
- NULL /* find_potential_libraries */
+ NULL, /* find_potential_libraries */
+ NULL /* new_vers_pattern */
};
EOF
Index: ld/emultempl/gld960c.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/gld960c.em,v
retrieving revision 1.9
diff -u -p -r1.9 gld960c.em
--- ld/emultempl/gld960c.em 3 Dec 2001 23:15:27 -0000 1.9
+++ ld/emultempl/gld960c.em 22 May 2002 07:56:30 -0000
@@ -204,6 +204,7 @@ struct ld_emulation_xfer_struct ld_gld96
NULL, /* unrecognized file */
NULL, /* list options */
NULL, /* recognized file */
- NULL /* find_potential_libraries */
+ NULL, /* find_potential_libraries */
+ NULL /* new_vers_pattern */
};
EOF
Index: ld/emultempl/linux.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/linux.em,v
retrieving revision 1.8
diff -u -p -r1.8 linux.em
--- ld/emultempl/linux.em 25 May 2001 05:39:22 -0000 1.8
+++ ld/emultempl/linux.em 22 May 2002 07:56:30 -0000
@@ -221,6 +221,7 @@ struct ld_emulation_xfer_struct ld_${EMU
NULL, /* unrecognized file */
NULL, /* list options */
NULL, /* recognized file */
- NULL /* find_potential_libraries */
+ NULL, /* find_potential_libraries */
+ NULL /* new_vers_pattern */
};
EOF
Index: ld/emultempl/lnk960.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/lnk960.em,v
retrieving revision 1.8
diff -u -p -r1.8 lnk960.em
--- ld/emultempl/lnk960.em 10 Feb 2002 19:12:13 -0000 1.8
+++ ld/emultempl/lnk960.em 22 May 2002 07:56:30 -0000
@@ -345,6 +345,7 @@ struct ld_emulation_xfer_struct ld_lnk96
NULL, /* unrecognized file */
NULL, /* list options */
NULL, /* recognized file */
- NULL /* find_potential_libraries */
+ NULL, /* find_potential_libraries */
+ NULL /* new_vers_pattern */
};
EOF
Index: ld/emultempl/m68kcoff.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/m68kcoff.em,v
retrieving revision 1.3
diff -u -p -r1.3 m68kcoff.em
--- ld/emultempl/m68kcoff.em 13 Mar 2001 06:14:27 -0000 1.3
+++ ld/emultempl/m68kcoff.em 22 May 2002 07:56:31 -0000
@@ -240,6 +240,7 @@ struct ld_emulation_xfer_struct ld_${EMU
NULL, /* unrecognized file */
NULL, /* list options */
NULL, /* recognized file */
- NULL /* find_potential_libraries */
+ NULL, /* find_potential_libraries */
+ NULL /* new_vers_pattern */
};
EOF
Index: ld/emultempl/mipsecoff.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/mipsecoff.em,v
retrieving revision 1.8
diff -u -p -r1.8 mipsecoff.em
--- ld/emultempl/mipsecoff.em 25 May 2001 05:39:22 -0000 1.8
+++ ld/emultempl/mipsecoff.em 22 May 2002 07:56:31 -0000
@@ -255,6 +255,7 @@ struct ld_emulation_xfer_struct ld_${EMU
NULL, /* unrecognized file */
NULL, /* list options */
NULL, /* recognized file */
- NULL /* find_potential_libraries */
+ NULL, /* find_potential_libraries */
+ NULL /* new_vers_pattern */
};
EOF
Index: ld/emultempl/pe.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/pe.em,v
retrieving revision 1.59
diff -u -p -r1.59 pe.em
--- ld/emultempl/pe.em 15 Feb 2002 02:11:05 -0000 1.59
+++ ld/emultempl/pe.em 22 May 2002 07:56:32 -0000
@@ -1937,6 +1937,7 @@ struct ld_emulation_xfer_struct ld_${EMU
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: ld/emultempl/ppc64elf.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/ppc64elf.em,v
retrieving revision 1.6
diff -u -p -r1.6 ppc64elf.em
--- ld/emultempl/ppc64elf.em 2 May 2002 09:48:15 -0000 1.6
+++ ld/emultempl/ppc64elf.em 22 May 2002 07:56:32 -0000
@@ -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: ld/emultempl/sunos.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/sunos.em,v
retrieving revision 1.9
diff -u -p -r1.9 sunos.em
--- ld/emultempl/sunos.em 19 Sep 2001 05:33:35 -0000 1.9
+++ ld/emultempl/sunos.em 22 May 2002 07:56:32 -0000
@@ -1050,6 +1050,7 @@ struct ld_emulation_xfer_struct ld_${EMU
NULL, /* unrecognized file */
NULL, /* list options */
NULL, /* recognized file */
- NULL /* find_potential_libraries */
+ NULL, /* find_potential_libraries */
+ NULL /* new_vers_pattern */
};
EOF
Index: ld/emultempl/ticoff.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/ticoff.em,v
retrieving revision 1.3
diff -u -p -r1.3 ticoff.em
--- ld/emultempl/ticoff.em 6 Sep 2000 00:13:34 -0000 1.3
+++ ld/emultempl/ticoff.em 22 May 2002 07:56:32 -0000
@@ -197,6 +197,7 @@ struct ld_emulation_xfer_struct ld_${EMU
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: ld/emultempl/vanilla.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/vanilla.em,v
retrieving revision 1.6
diff -u -p -r1.6 vanilla.em
--- ld/emultempl/vanilla.em 3 Sep 2001 06:43:36 -0000 1.6
+++ ld/emultempl/vanilla.em 22 May 2002 07:56:32 -0000
@@ -82,6 +82,7 @@ struct ld_emulation_xfer_struct ld_vanil
NULL, /* unrecognized file */
NULL, /* list options */
NULL, /* recognized file */
- NULL /* find_potential_libraries */
+ NULL, /* find_potential_libraries */
+ NULL /* new_vers_pattern */
};
EOF
--
Alan Modra
IBM OzLabs - Linux Technology Centre