diff options
author | Mihailo Stojanovic <mihailo.stojanovic@rt-rk.com> | 2019-08-09 11:06:37 +0100 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2019-08-09 11:06:37 +0100 |
commit | f16a9783c5f085443d806646074e9c06fdee9a88 (patch) | |
tree | 98daf0fca4cd2a572ee12f1d6b895739b235b008 /bfd/elflink.c | |
parent | 1ba7cdcd931ddf672e4a8a6483593f9b94e55965 (diff) | |
download | gdb-f16a9783c5f085443d806646074e9c06fdee9a88.zip gdb-f16a9783c5f085443d806646074e9c06fdee9a88.tar.gz gdb-f16a9783c5f085443d806646074e9c06fdee9a88.tar.bz2 |
Add support for a MIPS specific .MIPS.xhash section.
This patch is a reimplementation of [1] which was submitted in 2015 by
Neil Schellenberger. Copyright issue was sorted out [2] last year.
It proposed a new section (.gnu.xhash) and related dynamic tag
(DT_GNU_XHASH). The new section would be virtually identical to the
existing .gnu.hash except for the translation table (xlat) which would
contain correct MIPS .dynsym indexes corresponding to the hashvals in
chains. This is because MIPS ABI imposes a different ordering on the
dynsyms than the one expected by the .gnu.hash section. Another addition
would be a leading word (ngnusyms) which would contain the number of
entries in the translation table.
In this patch, the new section name and dynamic tag are changed to
reflect the fact that the section should be treated as MIPS-specific
(.MIPS.xhash and DT_MIPS_XHASH).
This patch addresses the alignment issue as reported in [3], which is
caused by the leading word added to the .MIPS.xhash section. Leading word
is removed in this patch, and the number of entries in the translation
table is now calculated using DT_MIPS_SYMTABNO dynamic tag (this is
addressed by the corresponding glibc patch).
Suggestions on coding style in [4] were taken into account. Existing
GNU hash testcase was covered, and another one was added in the MIPS
part of the testsuite.
The other major change is reserving MIPS ABI version 5 for .MIPS.xhash,
marking the need of support for .MIPS.xhash in the dynamic linker (again,
addressed in the corresponding glibc patch). This is something which I
am not sure of, especially after reading [5]. I am confused on whether
this ABI version is reserved for IFUNC, or it can be used for this
purpose.
Already mentioned glibc patch is submitted at:
https://sourceware.org/ml/libc-alpha/2019-06/msg00456.html
[1] https://sourceware.org/ml/binutils/2015-10/msg00057.html
[2] https://sourceware.org/ml/binutils/2018-03/msg00025.html
[3] https://sourceware.org/ml/binutils/2016-01/msg00006.html
[4] https://sourceware.org/ml/binutils/2016-02/msg00097.html
[5] https://sourceware.org/ml/libc-alpha/2016-12/msg00853.html
ld * emulparams/elf32bmip.sh: Add .MIPS.xhash section.
* emulparams/elf32bmipn32-defs.sh: Add .MIPS.xhash section.
* emulparams/elf64bmip-defs.sh: Add .MIPS.xhash section.
* emultempl/mipself.em: Remove mips_after_parse function.
* testsuite/ld-elf/hash.d: Update comment.
* testsuite/ld-mips-elf/hash1.d: New test.
* testsuite/ld-mips-elf/hash1.s: Ditto.
* testsuite/ld-mips-elf/hash1a.d: Remove.
* testsuite/ld-mips-elf/hash1b.d: Ditto.
* testsuite/ld-mips-elf/hash1c.d: Ditto
* testsuite/ld-mips-elf/hash2.d: New test.
* testsuite/ld-mips-elf/mips-elf.exp: New tests.
* testsuite/ld-mips-elf/start.s: New test.
bfd * elf-bfd.h (struct elf_backend_data): New members.
* elflink.c (_bfd_elf_link_create_dynamic_sections): Create
.gnu.hash section if necessary.
(struct collect_gnu_hash_codes): New member.
(elf_gnu_hash_process_symidx): New function name.
(elf_renumber_gnu_hash_syms): Ignore local and undefined
symbols. Record xlat location for every symbol which should have
a .MIPS.xhash entry.
(bfd_elf_size_dynamic_sections): Add DT_GNU_HASH dynamic tag to
dynamic section if necessary.
(GNU_HASH_SECTION_NAME): New define.
(bfd_elf_size_dynsym_hash_dynstr): Get .MIPS.xhash section.
Update the section size info.
* elfxx-mips.c (struct mips_elf_hash_sort_data): New members.
(struct mips_elf_link_hash_entry): New member.
(mips_elf_link_hash_newfunc): Initialize .MIPS.xhash translation
table location.
(mips_elf_sort_hash_table): Initialize the pointer to the
.MIPS.xhash section.
(mips_elf_sort_hash_table_f): Populate the .MIPS.xhash
translation table entry with the symbol dynindx.
(_bfd_mips_elf_section_from_shdr): Add SHT_MIPS_XHASH.
(_bfd_mips_elf_fake_sections): Initialize .MIPS.xhash section
info.
(_bfd_mips_elf_create_dynamic_sections): Create .MIPS.xhash
section.
(_bfd_mips_elf_size_dynamic_sections): Add DT_MIPS_XHASH tag to
dynamic section.
(_bfd_mips_elf_finish_synamic_sections): Add DT_MIPS_XHASH.
(_bfd_mips_elf_final_write_processing): Set .MIPS.xhash section
sh_link info.
(_bfd_mips_elf_get_target_dtag): Get DT_MIPS_XHASH tag.
(MIPS_LIBC_ABI_XHASH): New ABI version enum value.
(_bfd_mips_post_process_headers): Mark the ABI version as
MIPS_LIBC_ABI_XHASH if there exists a .MIPS.xhash section,
but not a .hash section.
(_bfd_mips_elf_record_xhash_symbol): New function. Record a
position in the translation table, associated with the hash
entry.
* elfxx-mips.h (literal_reloc_p): Define
elf_backend_record_xhash_symbol backend hook.
* elfxx-target.h: Initialize elf_backend_record_xhash_symbol
backend hook.
include * elf/mips.h (SHT_GNU_XHASH): New define.
(DT_GNU_XHASH): New define.
binutils * readelf.c (get_mips_dynamic_type): Return MIPS_XHASH dynamic type.
(get_mips_section_type_name): Return MI{S_XHASH name string.
(dynamic_section_mips_val): Initialize the .MIPS.xhash dynamic
info.
(process_symbol_table): Initialize the .MIPS.xhash section
pointer. Adjust the readelf output to support the new section.
(process_object): Set the .MIPS.xhash dynamic info to zero.
Diffstat (limited to 'bfd/elflink.c')
-rw-r--r-- | bfd/elflink.c | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/bfd/elflink.c b/bfd/elflink.c index 5971845..c7440d1 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -339,7 +339,7 @@ _bfd_elf_link_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) elf_section_data (s)->this_hdr.sh_entsize = bed->s->sizeof_hash_entry; } - if (info->emit_gnu_hash) + if (info->emit_gnu_hash && bed->record_xhash_symbol == NULL) { s = bfd_make_section_anyway_with_flags (abfd, ".gnu.hash", flags | SEC_READONLY); @@ -5853,6 +5853,7 @@ struct collect_gnu_hash_codes unsigned long int *counts; bfd_vma *bitmask; bfd_byte *contents; + bfd_size_type xlat; long int min_dynindx; unsigned long int bucketcount; unsigned long int symindx; @@ -5917,10 +5918,12 @@ elf_collect_gnu_hash_codes (struct elf_link_hash_entry *h, void *data) } /* This function will be called though elf_link_hash_traverse to do - final dynaminc symbol renumbering. */ + final dynamic symbol renumbering in case of .gnu.hash. + If using .MIPS.xhash, invoke record_xhash_symbol to add symbol index + to the translation table. */ static bfd_boolean -elf_renumber_gnu_hash_syms (struct elf_link_hash_entry *h, void *data) +elf_gnu_hash_process_symidx (struct elf_link_hash_entry *h, void *data) { struct collect_gnu_hash_codes *s = (struct collect_gnu_hash_codes *) data; unsigned long int bucket; @@ -5934,7 +5937,15 @@ elf_renumber_gnu_hash_syms (struct elf_link_hash_entry *h, void *data) if (! (*s->bed->elf_hash_symbol) (h)) { if (h->dynindx >= s->min_dynindx) - h->dynindx = s->local_indx++; + { + if (s->bed->record_xhash_symbol != NULL) + { + (*s->bed->record_xhash_symbol) (h, 0); + s->local_indx++; + } + else + h->dynindx = s->local_indx++; + } return TRUE; } @@ -5951,7 +5962,14 @@ elf_renumber_gnu_hash_syms (struct elf_link_hash_entry *h, void *data) bfd_put_32 (s->output_bfd, val, s->contents + (s->indx[bucket] - s->symindx) * 4); --s->counts[bucket]; - h->dynindx = s->indx[bucket]++; + if (s->bed->record_xhash_symbol != NULL) + { + bfd_vma xlat_loc = s->xlat + (s->indx[bucket]++ - s->symindx) * 4; + + (*s->bed->record_xhash_symbol) (h, xlat_loc); + } + else + h->dynindx = s->indx[bucket]++; return TRUE; } @@ -6980,7 +6998,8 @@ bfd_elf_size_dynamic_sections (bfd *output_bfd, if ((info->emit_hash && !_bfd_elf_add_dynamic_entry (info, DT_HASH, 0)) || (info->emit_gnu_hash - && !_bfd_elf_add_dynamic_entry (info, DT_GNU_HASH, 0)) + && (bed->record_xhash_symbol == NULL + && !_bfd_elf_add_dynamic_entry (info, DT_GNU_HASH, 0))) || !_bfd_elf_add_dynamic_entry (info, DT_STRTAB, 0) || !_bfd_elf_add_dynamic_entry (info, DT_SYMTAB, 0) || !_bfd_elf_add_dynamic_entry (info, DT_STRSZ, strsize) @@ -7105,6 +7124,9 @@ _bfd_elf_init_2_index_sections (bfd *output_bfd, struct bfd_link_info *info) elf_hash_table (info)->text_index_section = found; } +#define GNU_HASH_SECTION_NAME(bed) \ + (bed)->record_xhash_symbol != NULL ? ".MIPS.xhash" : ".gnu.hash" + bfd_boolean bfd_elf_size_dynsym_hash_dynstr (bfd *output_bfd, struct bfd_link_info *info) { @@ -7271,12 +7293,12 @@ bfd_elf_size_dynsym_hash_dynstr (bfd *output_bfd, struct bfd_link_info *info) return FALSE; } - s = bfd_get_linker_section (dynobj, ".gnu.hash"); + s = bfd_get_linker_section (dynobj, GNU_HASH_SECTION_NAME (bed)); BFD_ASSERT (s != NULL); if (cinfo.nsyms == 0) { - /* Empty .gnu.hash section is special. */ + /* Empty .gnu.hash or .MIPS.xhash section is special. */ BFD_ASSERT (cinfo.min_dynindx == -1); free (cinfo.hashcodes); s->size = 5 * 4 + bed->s->arch_size / 8; @@ -7356,6 +7378,8 @@ bfd_elf_size_dynsym_hash_dynstr (bfd *output_bfd, struct bfd_link_info *info) s->size = (4 + bucketcount + cinfo.nsyms) * 4; s->size += cinfo.maskbits / 8; + if (bed->record_xhash_symbol != NULL) + s->size += cinfo.nsyms * 4; contents = (unsigned char *) bfd_zalloc (output_bfd, s->size); if (contents == NULL) { @@ -7382,9 +7406,11 @@ bfd_elf_size_dynsym_hash_dynstr (bfd *output_bfd, struct bfd_link_info *info) cinfo.contents = contents; - /* Renumber dynamic symbols, populate .gnu.hash section. */ + cinfo.xlat = contents + cinfo.nsyms * 4 - s->contents; + /* Renumber dynamic symbols, if populating .gnu.hash section. + If using .MIPS.xhash, populate the translation table. */ elf_link_hash_traverse (elf_hash_table (info), - elf_renumber_gnu_hash_syms, &cinfo); + elf_gnu_hash_process_symidx, &cinfo); contents = s->contents + 16; for (i = 0; i < maskwords; ++i) |