/* ${ELFSIZE} bit ELF emulation code for ${EMULATION_NAME}
Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
- 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+ 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+ Free Software Foundation, Inc.
Written by Steve Chamberlain <sac@cygnus.com>
ELF support by Ian Lance Taylor <ian@cygnus.com>
#include <ldgram.h>
#include "elf/common.h"
#include "elf-bfd.h"
+#include "filenames.h"
/* Declare functions used by various EXTRA_EM_FILEs. */
static void gld${EMULATION_NAME}_before_parse (void);
if test x"$LDEMUL_RECOGNIZED_FILE" != xgld"${EMULATION_NAME}"_load_symbols; then
fragment <<EOF
-/* Handle as_needed DT_NEEDED. */
+/* Handle the generation of DT_NEEDED tags. */
static bfd_boolean
gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *entry)
{
- int class = 0;
+ int link_class = 0;
/* Tell the ELF linker that we don't want the output file to have a
DT_NEEDED entry for this file, unless it is used to resolve
references in a regular object. */
- if (entry->as_needed)
- class = DYN_AS_NEEDED;
+ if (entry->add_DT_NEEDED_for_regular)
+ link_class = DYN_AS_NEEDED;
/* Tell the ELF linker that we don't want the output file to have a
DT_NEEDED entry for any dynamic library in DT_NEEDED tags from
this file at all. */
- if (!entry->add_needed)
- class |= DYN_NO_ADD_NEEDED;
+ if (!entry->add_DT_NEEDED_for_dynamic)
+ link_class |= DYN_NO_ADD_NEEDED;
if (entry->just_syms_flag
&& (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) != 0)
einfo (_("%P%F: --just-symbols may not be used on DSO: %B\n"),
entry->the_bfd);
- if (!class
+ if (link_class == 0
|| (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) == 0)
return FALSE;
- bfd_elf_set_dyn_lib_class (entry->the_bfd, class);
+ bfd_elf_set_dyn_lib_class (entry->the_bfd,
+ (enum dynamic_lib_link_class) link_class);
/* Continue on with normal load_symbols processing. */
return FALSE;
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
bfd *abfd;
const char *name = needed->name;
const char *soname;
- int class;
+ int link_class;
abfd = bfd_openr (name, bfd_get_target (link_info.output_bfd));
if (abfd == NULL)
if (! force)
{
- struct bfd_link_needed_list *needed;
+ struct bfd_link_needed_list *needs;
- if (! bfd_elf_get_bfd_needed_list (abfd, &needed))
+ if (! bfd_elf_get_bfd_needed_list (abfd, &needs))
einfo ("%F%P:%B: bfd_elf_get_bfd_needed_list failed: %E\n", abfd);
- if (needed != NULL)
+ if (needs != NULL)
{
- global_vercheck_needed = needed;
+ global_vercheck_needed = needs;
global_vercheck_failed = FALSE;
lang_for_each_input_file (gld${EMULATION_NAME}_vercheck);
if (global_vercheck_failed)
{
struct bfd_link_needed_list *l;
- for (l = needed; l != NULL; l = l->next)
+ for (l = needs; l != NULL; l = l->next)
if (CONST_STRNEQ (l->name, "libc.so"))
break;
if (l == NULL)
/* Tell the ELF linker that we don't want the output file to have a
DT_NEEDED entry for this file, unless it is used to resolve
references in a regular object. */
- class = DYN_DT_NEEDED;
+ link_class = DYN_DT_NEEDED;
/* Tell the ELF linker that we don't want the output file to have a
DT_NEEDED entry for this file at all if the entry is from a file
with DYN_NO_ADD_NEEDED. */
if (needed->by != NULL
&& (bfd_elf_get_dyn_lib_class (needed->by) & DYN_NO_ADD_NEEDED) != 0)
- class |= DYN_NO_NEEDED | DYN_NO_ADD_NEEDED;
+ link_class |= DYN_NO_NEEDED | DYN_NO_ADD_NEEDED;
- bfd_elf_set_dyn_lib_class (abfd, class);
+ bfd_elf_set_dyn_lib_class (abfd, (enum dynamic_lib_link_class) link_class);
/* Add this file into the symbol table. */
if (! bfd_link_add_symbols (abfd, &link_info))
if (s == NULL)
s = path + strlen (path);
+#if HAVE_DOS_BASED_FILE_SYSTEM
+ /* Assume a match on the second char is part of drive specifier. */
+ else if (config.rpath_separator == ':'
+ && s == path + 1
+ && ISALPHA (*path))
+ {
+ s = strchr (s + 1, config.rpath_separator);
+ if (s == NULL)
+ s = path + strlen (path);
+ }
+#endif
filename = (char *) xmalloc (s - path + len + 2);
if (s == path)
sset = filename;
static bfd_size_type
gld${EMULATION_NAME}_id_note_section_size (bfd *abfd,
- struct bfd_link_info *link_info)
+ struct bfd_link_info *linfo)
{
- const char *style = link_info->emit_note_gnu_build_id;
+ const char *style = linfo->emit_note_gnu_build_id;
bfd_size_type size;
abfd = abfd;
gld${EMULATION_NAME}_write_build_id_section (bfd *abfd)
{
const struct elf_backend_data *bed = get_elf_backend_data (abfd);
- struct build_id_info *info =
+ struct build_id_info *info = (struct build_id_info *)
elf_tdata (abfd)->after_write_object_contents_info;
asection *asec;
Elf_Internal_Shdr *i_shdr;
if (i_shdr->contents == NULL)
{
if (asec->contents == NULL)
- asec->contents = xmalloc (asec->size);
+ asec->contents = (unsigned char *) xmalloc (asec->size);
contents = asec->contents;
}
else
contents = i_shdr->contents + asec->output_offset;
- e_note = (void *) contents;
+ e_note = (Elf_External_Note *) contents;
size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
size = (size + 3) & -(bfd_size_type) 4;
id_bits = contents + size;
abfd = link_info.input_bfds;
- size = gld${EMULATION_NAME}_id_note_section_size (abfd, &link_info);
- if (size == 0)
+ if (abfd == NULL)
{
- einfo ("%P: warning: unrecognized --build-id style ignored.\n");
+ /* PR 10555: If there are no input files do not
+ try to create a .note.gnu-build-id section. */
free (link_info.emit_note_gnu_build_id);
link_info.emit_note_gnu_build_id = NULL;
}
else
{
- s = bfd_make_section_with_flags (abfd, ".note.gnu.build-id",
- SEC_ALLOC | SEC_LOAD
- | SEC_IN_MEMORY | SEC_LINKER_CREATED
- | SEC_READONLY | SEC_DATA);
- if (s != NULL && bfd_set_section_alignment (abfd, s, 2))
+ size = gld${EMULATION_NAME}_id_note_section_size (abfd, &link_info);
+ if (size == 0)
{
- struct elf_obj_tdata *t = elf_tdata (link_info.output_bfd);
- struct build_id_info *b = xmalloc (sizeof *b);
- b->style = link_info.emit_note_gnu_build_id;
- b->sec = s;
- elf_section_type (s) = SHT_NOTE;
- s->size = size;
- t->after_write_object_contents
- = &gld${EMULATION_NAME}_write_build_id_section;
- t->after_write_object_contents_info = b;
+ einfo ("%P: warning: unrecognized --build-id style ignored.\n");
+ free (link_info.emit_note_gnu_build_id);
+ link_info.emit_note_gnu_build_id = NULL;
}
else
{
- einfo ("%P: warning: Cannot create .note.gnu.build-id section,"
- " --build-id ignored.\n");
- free (link_info.emit_note_gnu_build_id);
- link_info.emit_note_gnu_build_id = NULL;
+ s = bfd_make_section_with_flags (abfd, ".note.gnu.build-id",
+ SEC_ALLOC | SEC_LOAD
+ | SEC_IN_MEMORY | SEC_LINKER_CREATED
+ | SEC_READONLY | SEC_DATA);
+ if (s != NULL && bfd_set_section_alignment (abfd, s, 2))
+ {
+ struct elf_obj_tdata *t = elf_tdata (link_info.output_bfd);
+ struct build_id_info *b =
+ (struct build_id_info *) xmalloc (sizeof *b);
+
+ b->style = link_info.emit_note_gnu_build_id;
+ b->sec = s;
+ elf_section_type (s) = SHT_NOTE;
+ s->size = size;
+ t->after_write_object_contents
+ = &gld${EMULATION_NAME}_write_build_id_section;
+ t->after_write_object_contents_info = b;
+ }
+ else
+ {
+ einfo ("%P: warning: Cannot create .note.gnu.build-id section,"
+ " --build-id ignored.\n");
+ free (link_info.emit_note_gnu_build_id);
+ link_info.emit_note_gnu_build_id = NULL;
+ }
}
}
}
fi
fragment <<EOF
+/* used by before_allocation and handle_option. */
+static void
+gld${EMULATION_NAME}_append_to_separated_string (char **to, char *op_arg)
+{
+ if (*to == NULL)
+ *to = xstrdup (op_arg);
+ else
+ {
+ size_t to_len = strlen (*to);
+ size_t op_arg_len = strlen (op_arg);
+ char *buf;
+ char *cp = *to;
+
+ /* First see whether OPTARG is already in the path. */
+ do
+ {
+ if (strncmp (op_arg, cp, op_arg_len) == 0
+ && (cp[op_arg_len] == 0
+ || cp[op_arg_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 + op_arg_len + 2);
+ sprintf (buf, "%s%c%s", *to,
+ config.rpath_separator, op_arg);
+ 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. */
{
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);
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");
continue;
sz = s->size;
- msg = xmalloc ((size_t) (sz + 1));
+ msg = (char *) xmalloc ((size_t) (sz + 1));
if (! bfd_get_section_contents (is->the_bfd, s, msg,
(file_ptr) 0, sz))
einfo ("%F%B: Can't read contents of section .gnu.warning: %E\n",
#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
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
if (*end || (config.maxpagesize & (config.maxpagesize - 1)) != 0)
einfo (_("%P%F: invalid maxium page size \`%s'\n"),
optarg + 14);
- ASSERT (default_target != NULL);
- bfd_emul_set_maxpagesize (default_target, config.maxpagesize);
}
else if (CONST_STRNEQ (optarg, "common-page-size="))
{
|| (config.commonpagesize & (config.commonpagesize - 1)) != 0)
einfo (_("%P%F: invalid common page size \`%s'\n"),
optarg + 17);
- ASSERT (default_target != NULL);
- bfd_emul_set_commonpagesize (default_target,
- config.commonpagesize);
}
/* What about the other Solaris -z options? FIXME. */
break;
{
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