aboutsummaryrefslogtreecommitdiff
path: root/ld/emultempl
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2009-09-23 13:54:29 +0000
committerAlan Modra <amodra@gmail.com>2009-09-23 13:54:29 +0000
commit7ee314faa48ba637641861e0288736cb4666f940 (patch)
tree20e03cb7130dc65e3ad2e741cffd98153f2adb71 /ld/emultempl
parent8a00d39205398a858642a2c727bd2a54d8e49b46 (diff)
downloadgdb-7ee314faa48ba637641861e0288736cb4666f940.zip
gdb-7ee314faa48ba637641861e0288736cb4666f940.tar.gz
gdb-7ee314faa48ba637641861e0288736cb4666f940.tar.bz2
bfd/
* bfd-in.h (bfd_elf_size_dynamic_sections): Add audit and depaudit arguments. * elflink.c (bfd_elf_size_dynamic_sections): Generate DT_AUDIT, DT_DEPAUDIT from audit/depaudit arguments. (elf_finalize_dynstr): Finalize DT_AUDIT and DT_DEPAUDIT strtab entries. (elf_link_add_object_symbols): Set dt_audit target data when finding a DT_AUDIT. * bfd-in2.h: Regenerate. * bfd-elf.h: Add dt_audit to elf_obj_tdata, and elf_dt_audit macro. ld/ * emultempl/elf32.em (gld${EMULATION_NAME}_add_options): Add --audit, --depaudit, and -P options. (gld${EULATION_NAME}_handle_options): Ditto. (gld${EULATION_NAME}_list_options): Ditto. (gld${EMULATION_NAME}_append_to_separated_string): New function for handling rpath-like colon separated strings. (gld${EMULATION_NAME}_before_allocation): Pass the audit and depaudit libs to bfd. Propagate DT_AUDIT from needed libs to depaudit. * ld.texinfo: Document new options. ld/testsuite/ * ld-elf/audit.exp: New. * ld-elf/audit.rd: New. * ld-elf/depaudit.rd: New. * ld-elf/depaudit2.rd: New.
Diffstat (limited to 'ld/emultempl')
-rw-r--r--ld/emultempl/elf32.em93
1 files changed, 91 insertions, 2 deletions
diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index 9518714..f7b70ac 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -157,6 +157,10 @@ static lang_input_statement_type *global_found;
static struct bfd_link_needed_list *global_vercheck_needed;
static bfd_boolean global_vercheck_failed;
+/* These variables are used to implement target options */
+
+static char *audit; /* colon (typically) separated list of libs */
+static char *depaudit; /* colon (typically) separated list of libs */
/* On Linux, it's possible to have different versions of the same
shared library linked against different versions of libc. The
@@ -1396,6 +1400,46 @@ if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation;
fi
fragment <<EOF
+/* used by before_allocation and handle_option. */
+static void
+gld${EMULATION_NAME}_append_to_separated_string (char **to, char *optarg)
+{
+ if (*to == NULL)
+ *to = xstrdup (optarg);
+ else
+ {
+ size_t to_len = strlen (*to);
+ size_t optarg_len = strlen (optarg);
+ char *buf;
+ char *cp = *to;
+
+ /* First see whether OPTARG is already in the path. */
+ do
+ {
+ if (strncmp (optarg, cp, optarg_len) == 0
+ && (cp[optarg_len] == 0
+ || cp[optarg_len] == config.rpath_separator))
+ /* We found it. */
+ break;
+
+ /* Not yet found. */
+ cp = strchr (cp, config.rpath_separator);
+ if (cp != NULL)
+ ++cp;
+ }
+ while (cp != NULL);
+
+ if (cp == NULL)
+ {
+ buf = xmalloc (to_len + optarg_len + 2);
+ sprintf (buf, "%s%c%s", *to,
+ config.rpath_separator, optarg);
+ free (*to);
+ *to = buf;
+ }
+ }
+}
+
/* This is called after the sections have been attached to output
sections, but before any sizes or addresses have been set. */
@@ -1404,6 +1448,7 @@ gld${EMULATION_NAME}_before_allocation (void)
{
const char *rpath;
asection *sinterp;
+ bfd *abfd;
if (link_info.hash->type == bfd_link_elf_hash_table)
_bfd_elf_tls_setup (link_info.output_bfd, &link_info);
@@ -1418,9 +1463,39 @@ gld${EMULATION_NAME}_before_allocation (void)
rpath = command_line.rpath;
if (rpath == NULL)
rpath = (const char *) getenv ("LD_RUN_PATH");
+
+ for (abfd = link_info.input_bfds; abfd; abfd = abfd->link_next)
+ {
+ const char *audit_libs = elf_dt_audit (abfd);
+
+ /* If the input bfd contains an audit entry, we need to add it as
+ a dep audit entry. */
+ if (audit_libs && *audit_libs != '\0')
+ {
+ char *cp = xstrdup (audit_libs);
+ do
+ {
+ int more = 0;
+ char *cp2 = strchr (cp, config.rpath_separator);
+
+ if (cp2)
+ {
+ *cp2 = '\0';
+ more = 1;
+ }
+
+ if (cp != NULL && *cp != '\0')
+ gld${EMULATION_NAME}_append_to_separated_string (&depaudit, cp);
+
+ cp = more ? ++cp2 : NULL;
+ }
+ while (cp != NULL);
+ }
+ }
+
if (! (bfd_elf_size_dynamic_sections
(link_info.output_bfd, command_line.soname, rpath,
- command_line.filter_shlib,
+ command_line.filter_shlib, audit, depaudit,
(const char * const *) command_line.auxiliary_filters,
&link_info, &sinterp, lang_elf_version_info)))
einfo ("%P%F: failed to set dynamic section sizes: %E\n");
@@ -2007,15 +2082,18 @@ fragment <<EOF
#define OPTION_EXCLUDE_LIBS (OPTION_EH_FRAME_HDR + 1)
#define OPTION_HASH_STYLE (OPTION_EXCLUDE_LIBS + 1)
#define OPTION_BUILD_ID (OPTION_HASH_STYLE + 1)
+#define OPTION_AUDIT (OPTION_BUILD_ID + 1)
static void
gld${EMULATION_NAME}_add_options
(int ns, char **shortopts, int nl, struct option **longopts,
int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
{
- static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:";
+ static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:P:";
static const struct option xtra_long[] = {
{"build-id", optional_argument, NULL, OPTION_BUILD_ID},
+ {"audit", required_argument, NULL, OPTION_AUDIT},
+ {"depaudit", required_argument, NULL, 'P'},
EOF
if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
@@ -2067,6 +2145,12 @@ gld${EMULATION_NAME}_handle_option (int optc)
if (strcmp (optarg, "none"))
link_info.emit_note_gnu_build_id = xstrdup (optarg);
break;
+ case OPTION_AUDIT:
+ gld${EMULATION_NAME}_append_to_separated_string (&audit, optarg);
+ break;
+ case 'P':
+ gld${EMULATION_NAME}_append_to_separated_string (&depaudit, optarg);
+ break;
EOF
@@ -2218,6 +2302,11 @@ gld${EMULATION_NAME}_list_options (FILE * file)
{
fprintf (file, _("\
--build-id[=STYLE] Generate build ID note\n"));
+ fprintf (file, _("\
+ --audit=AUDITLIB Specify a library to use for auditing\n"));
+ fprintf (file, _("\
+ -P AUDITLIB, --depaudit=AUDITLIB\n" "\
+ Specify a library to use for auditing dependencies\n"));
EOF
if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then