|
|
elf_hash_table (info)->eh_info.hdr_sec = s; | elf_hash_table (info)->eh_info.hdr_sec = s; |
} | } |
| |
|
if ( info->direct && !info->executable ) |
|
{ |
|
s = bfd_make_section (abfd, ".direct"); |
|
if (s == NULL |
|
|| ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) |
|
|| ! bfd_set_section_alignment (abfd, s, 2)) |
|
return FALSE; |
|
elf_hash_table (info)->direct_sec = s; |
|
} |
|
|
/* Create sections to hold version informations. These are removed | /* Create sections to hold version informations. These are removed |
if they are not needed. */ | if they are not needed. */ |
s = bfd_make_section_with_flags (abfd, ".gnu.version_d", | s = bfd_make_section_with_flags (abfd, ".gnu.version_d", |
|
|
| |
if (!_bfd_elf_add_dynamic_entry (info, DT_NEEDED, strindex)) | if (!_bfd_elf_add_dynamic_entry (info, DT_NEEDED, strindex)) |
return -1; | return -1; |
|
elf_dt_needed_idx (abfd) = ++(info->dt_needed_index); |
|
/* fprintf (stderr, "Set soname '%s' as index %d\n", |
|
soname, info->dt_needed_index); */ |
} | } |
else | else |
/* We were just checking for existence of the tag. */ | /* We were just checking for existence of the tag. */ |
|
|
bfd_boolean add_needed; | bfd_boolean add_needed; |
struct elf_link_hash_table * hash_table; | struct elf_link_hash_table * hash_table; |
bfd_size_type amt; | bfd_size_type amt; |
|
asection *direct_sec; |
|
unsigned char *direct_data; |
| |
hash_table = elf_hash_table (info); | hash_table = elf_hash_table (info); |
| |
|
|
add_symbol_hook = bed->elf_add_symbol_hook; | add_symbol_hook = bed->elf_add_symbol_hook; |
collect = bed->collect; | collect = bed->collect; |
| |
|
direct_sec = NULL; |
|
direct_data = NULL; |
|
|
if ((abfd->flags & DYNAMIC) == 0) | if ((abfd->flags & DYNAMIC) == 0) |
dynamic = FALSE; | dynamic = FALSE; |
else | else |
|
|
bfd_set_error (bfd_error_wrong_format); | bfd_set_error (bfd_error_wrong_format); |
goto error_return; | goto error_return; |
} | } |
|
if (info->direct && |
|
(direct_sec = bfd_get_section_by_name (abfd, ".direct"))) |
|
{ |
|
direct_data = bfd_alloc (abfd, direct_sec->size); |
|
if (direct_data == NULL || |
|
! bfd_get_section_contents (abfd, direct_sec, direct_data, 0, direct_sec->size)) |
|
goto error_return; |
|
} |
} | } |
| |
/* As a GNU extension, any input sections which are named | /* As a GNU extension, any input sections which are named |
|
|
&& vernum > 1 | && vernum > 1 |
&& definition) | && definition) |
h->verinfo.verdef = &elf_tdata (abfd)->verdef[vernum - 1]; | h->verinfo.verdef = &elf_tdata (abfd)->verdef[vernum - 1]; |
|
|
|
if (direct_sec) |
|
{ |
|
unsigned long d_idx = isym - isymbuf; |
|
/* FIXME: does bfd_elf_get_elf_syms read dynsym or the symbol |
|
table ? */ |
|
d_idx += extsymoff; |
|
d_idx *= 2; |
|
if (d_idx > bfd_get_section_size (direct_sec)) |
|
fprintf (stderr, "Warning - strange error on '%s': 0x%x 0x%x\n", |
|
h->root.root.string, (int)d_idx, |
|
(int)bfd_get_section_size (direct_sec)); |
|
else |
|
{ |
|
unsigned int direct_entry; |
|
direct_entry = bfd_get_16 (abfd, direct_data + d_idx); |
|
if ((direct_entry & DT_DIRECT_VAGUE)) |
|
h->vague_ref = 1; |
|
if (!h->vague_ref && |
|
(direct_entry & DT_DIRECT_MASK) != DT_DIRECT_UNKNOWN) |
|
h->concrete_ref = 1; |
|
#if 0 |
|
fprintf (stderr, "symbol '%s': %s direct entry 0x%x (index %d) section '%s' : '%s'\n", |
|
h->root.root.string, |
|
h->vague_ref ? "vague " : h->concrete_ref ? "concrete" : "unknown", |
|
direct_entry, (int)d_idx/2, |
|
new_sec ? new_sec->name : "<nosec>", |
|
new_sec && new_sec->owner ? new_sec->owner->filename : "<noownername>"); |
|
#endif |
|
} |
|
} |
} | } |
| |
if (! (_bfd_generic_link_add_one_symbol | if (! (_bfd_generic_link_add_one_symbol |
|
|
h = (struct elf_link_hash_entry *) h->root.u.i.link; | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
*sym_hash = h; | *sym_hash = h; |
| |
|
/* FIXME: move direct bits here ? - seem fine where they are ... */ |
|
|
new_weakdef = FALSE; | new_weakdef = FALSE; |
if (dynamic | if (dynamic |
&& definition | && definition |
|
|
if (isymbuf != NULL) | if (isymbuf != NULL) |
free (isymbuf); | free (isymbuf); |
error_return: | error_return: |
|
if (direct_data != NULL) |
|
free (direct_data); |
return FALSE; | return FALSE; |
} | } |
| |
|
|
return FALSE; | return FALSE; |
} | } |
| |
|
/* Create the direct bindings section - 1 entry per dynsym */ |
|
s = bfd_get_section_by_name (dynobj, ".direct"); |
|
if (s) |
|
{ |
|
if (dynsymcount == 0) |
|
_bfd_strip_section_from_output (info, s); |
|
else |
|
{ |
|
s->size = dynsymcount * sizeof (Elf_External_Direct); |
|
s->contents = bfd_zalloc (output_bfd, s->size); |
|
if (s->contents == NULL) |
|
return FALSE; |
|
memset (s->contents, 0xff, s->size); |
|
if (!_bfd_elf_add_dynamic_entry (info, DT_DIRECT, 0)) |
|
return FALSE; |
|
} |
|
} |
|
|
/* Set the size of the .dynsym and .hash sections. We counted | /* Set the size of the .dynsym and .hash sections. We counted |
the number of dynamic symbols in elf_link_add_object_symbols. | the number of dynamic symbols in elf_link_add_object_symbols. |
We will build the contents of .dynsym and .hash when we build | We will build the contents of .dynsym and .hash when we build |
|
|
asection *hash_sec; | asection *hash_sec; |
/* symbol version section (.gnu.version). */ | /* symbol version section (.gnu.version). */ |
asection *symver_sec; | asection *symver_sec; |
|
/* .direct linkage section */ |
|
asection *direct_sec; |
/* Buffer large enough to hold contents of any section. */ | /* Buffer large enough to hold contents of any section. */ |
bfd_byte *contents; | bfd_byte *contents; |
/* Buffer large enough to hold external relocs of any section. */ | /* Buffer large enough to hold external relocs of any section. */ |
|
|
eversym += h->dynindx; | eversym += h->dynindx; |
_bfd_elf_swap_versym_out (finfo->output_bfd, &iversym, eversym); | _bfd_elf_swap_versym_out (finfo->output_bfd, &iversym, eversym); |
} | } |
|
|
|
if (finfo->direct_sec) |
|
{ |
|
bfd_vma offset = 2 * h->dynindx; |
|
if (offset > finfo->direct_sec->size) |
|
fprintf (stderr, "Out of bounds direct section index %d\n", |
|
(int) offset); |
|
else |
|
{ |
|
int dt_index = DT_DIRECT_UNKNOWN; |
|
|
|
#if 0 |
|
fprintf (stderr, "Symbol '%s' type %d\n", |
|
h->root.root.string, h->root.type); |
|
#endif |
|
if ((h->root.type == bfd_link_hash_defined |
|
|| h->root.type == bfd_link_hash_defweak) && |
|
h->root.u.def.section != NULL && |
|
h->root.u.def.section->owner != NULL) |
|
|
|
{ |
|
asection *sec = h->root.u.def.section; |
|
|
|
dt_index = elf_dt_needed_idx (sec->owner); |
|
|
|
if (!(sec->owner->flags & DYNAMIC)) |
|
{ |
|
if (!sec->name || |
|
!strncmp (sec->name, ".gnu.linkonce", sizeof ".gnu.linkonce" - 1)) |
|
dt_index |= DT_DIRECT_VAGUE; |
|
|
|
/* app -> library data references get turned into copy |
|
relocs, so objects can migrate unpredictably into the |
|
application itself. */ |
|
else if (h->type == STT_OBJECT) |
|
dt_index |= DT_DIRECT_VAGUE; |
|
} |
|
else if (h->vague_ref) |
|
dt_index |= DT_DIRECT_VAGUE; |
|
|
|
else if (!h->concrete_ref) |
|
dt_index = DT_DIRECT_UNKNOWN; |
|
|
|
#if 0 |
|
fprintf (stderr, "Sym '%s' (type %d) [type %d] section %s [%s] owner '%s' [%d] offset %d resolves '%s'\n", |
|
h->root.root.string, h->root.type, h->type, |
|
sec->name ? sec->name : "<null>", |
|
sec->owner->flags & DYNAMIC ? "dynamic" : "static", |
|
sec->owner ? sec->owner->filename : "<noowner?>", |
|
dt_index, (int) offset, |
|
dt_index & DT_DIRECT_VAGUE ? "<vague>" : "concrete"); |
|
#endif |
|
} |
|
bfd_put_16 (finfo->output_bfd, |
|
dt_index, |
|
finfo->direct_sec->contents + offset); |
|
} |
|
} |
} | } |
| |
/* If we're stripping it, then it was just a dynamic symbol, and | /* If we're stripping it, then it was just a dynamic symbol, and |
|
|
finfo.dynsym_sec = NULL; | finfo.dynsym_sec = NULL; |
finfo.hash_sec = NULL; | finfo.hash_sec = NULL; |
finfo.symver_sec = NULL; | finfo.symver_sec = NULL; |
|
finfo.direct_sec = NULL; |
} | } |
else | else |
{ | { |
|
|
BFD_ASSERT (finfo.dynsym_sec != NULL && finfo.hash_sec != NULL); | BFD_ASSERT (finfo.dynsym_sec != NULL && finfo.hash_sec != NULL); |
finfo.symver_sec = bfd_get_section_by_name (dynobj, ".gnu.version"); | finfo.symver_sec = bfd_get_section_by_name (dynobj, ".gnu.version"); |
/* Note that it is OK if symver_sec is NULL. */ | /* Note that it is OK if symver_sec is NULL. */ |
|
finfo.direct_sec = bfd_get_section_by_name (dynobj, ".direct"); |
} | } |
| |
finfo.contents = NULL; | finfo.contents = NULL; |
|
|
case DT_VERNEED: | case DT_VERNEED: |
name = ".gnu.version_r"; | name = ".gnu.version_r"; |
goto get_vma; | goto get_vma; |
|
case DT_DIRECT: |
|
name = ".direct"; |
|
goto get_vma; |
case DT_VERSYM: | case DT_VERSYM: |
name = ".gnu.version"; | name = ".gnu.version"; |
get_vma: | get_vma: |