* [committed] MIPS/BFD: Respect the ELF gABI dynamic symbol table sort requirement
@ 2017-02-02 23:05 Maciej W. Rozycki
2017-02-13 14:45 ` Maciej W. Rozycki
0 siblings, 1 reply; 2+ messages in thread
From: Maciej W. Rozycki @ 2017-02-02 23:05 UTC (permalink / raw)
To: binutils; +Cc: James Cowgill
Ensure all local symbols precede external symbols in the dynamic symbol
table.
No local symbols are expected to make it to the dynamic symbol table
except for section symbols already taken care of, so this is really a
safeguard only against a potential BFD bug otherwise not so harmful,
which may become a grave one due to a symbol table sorting requirement
violation (see PR ld/20828 for an example). This means however that no
test suite coverage is possible for this change as code introduced here
is not normally expected to trigger.
Logically split then the part of the dynamic symbol table which is not
global offset table mapped, into a local area at the beginning and an
external area following. By the time `mips_elf_sort_hash_table' is
called we have the number of local dynamic symbol table entries (section
and non-section) already counted in `local_dynsymcount', so use it to
offset the external area from the beginning.
bfd/
* elfxx-mips.c (mips_elf_hash_sort_data): Add
`max_local_dynindx'.
(mips_elf_sort_hash_table): Handle it.
(mips_elf_sort_hash_table_f) <GGA_NONE>: For forced local
symbols bump up `max_local_dynindx' rather than
`max_non_got_dynindx'.
---
binutils-mips-bfd-dynsym-sort.diff
Index: binutils/bfd/elfxx-mips.c
===================================================================
--- binutils.orig/bfd/elfxx-mips.c 2017-02-02 00:56:37.742249694 +0000
+++ binutils/bfd/elfxx-mips.c 2017-02-02 00:56:42.271630635 +0000
@@ -315,7 +315,10 @@ struct mips_elf_hash_sort_data
with a GOT entry that is not referenced (e.g., a dynamic symbol
with dynamic relocations pointing to it from non-primary GOTs). */
bfd_size_type max_unref_got_dynindx;
- /* The greatest dynamic symbol table index not corresponding to a
+ /* The greatest dynamic symbol table index corresponding to a local
+ symbol. */
+ bfd_size_type max_local_dynindx;
+ /* The greatest dynamic symbol table index corresponding to an external
symbol without a GOT entry. */
bfd_size_type max_non_got_dynindx;
};
@@ -3846,11 +3849,15 @@ mips_elf_sort_hash_table (bfd *abfd, str
hsd.max_unref_got_dynindx
= hsd.min_got_dynindx
= (htab->root.dynsymcount - g->reloc_only_gotno);
- hsd.max_non_got_dynindx = count_section_dynsyms (abfd, info) + 1;
+ /* Add 1 to local symbol indices to account for the mandatory NULL entry
+ at the head of the table; see `_bfd_elf_link_renumber_dynsyms'. */
+ hsd.max_local_dynindx = count_section_dynsyms (abfd, info) + 1;
+ hsd.max_non_got_dynindx = htab->root.local_dynsymcount + 1;
mips_elf_link_hash_traverse (htab, mips_elf_sort_hash_table_f, &hsd);
/* There should have been enough room in the symbol table to
accommodate both the GOT and non-GOT symbols. */
+ BFD_ASSERT (hsd.max_local_dynindx <= htab->root.local_dynsymcount + 1);
BFD_ASSERT (hsd.max_non_got_dynindx <= hsd.min_got_dynindx);
BFD_ASSERT (hsd.max_unref_got_dynindx == htab->root.dynsymcount);
BFD_ASSERT (htab->root.dynsymcount - hsd.min_got_dynindx == g->global_gotno);
@@ -3879,7 +3886,10 @@ mips_elf_sort_hash_table_f (struct mips_
switch (h->global_got_area)
{
case GGA_NONE:
- h->root.dynindx = hsd->max_non_got_dynindx++;
+ if (h->root.forced_local)
+ h->root.dynindx = hsd->max_local_dynindx++;
+ else
+ h->root.dynindx = hsd->max_non_got_dynindx++;
break;
case GGA_NORMAL:
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [committed] MIPS/BFD: Respect the ELF gABI dynamic symbol table sort requirement
2017-02-02 23:05 [committed] MIPS/BFD: Respect the ELF gABI dynamic symbol table sort requirement Maciej W. Rozycki
@ 2017-02-13 14:45 ` Maciej W. Rozycki
0 siblings, 0 replies; 2+ messages in thread
From: Maciej W. Rozycki @ 2017-02-13 14:45 UTC (permalink / raw)
To: binutils; +Cc: Tristan Gingold, James Cowgill
On Thu, 2 Feb 2017, Maciej W. Rozycki wrote:
> Ensure all local symbols precede external symbols in the dynamic symbol
> table.
>
> No local symbols are expected to make it to the dynamic symbol table
> except for section symbols already taken care of, so this is really a
> safeguard only against a potential BFD bug otherwise not so harmful,
> which may become a grave one due to a symbol table sorting requirement
> violation (see PR ld/20828 for an example). This means however that no
> test suite coverage is possible for this change as code introduced here
> is not normally expected to trigger.
>
> Logically split then the part of the dynamic symbol table which is not
> global offset table mapped, into a local area at the beginning and an
> external area following. By the time `mips_elf_sort_hash_table' is
> called we have the number of local dynamic symbol table entries (section
> and non-section) already counted in `local_dynsymcount', so use it to
> offset the external area from the beginning.
>
> bfd/
> * elfxx-mips.c (mips_elf_hash_sort_data): Add
> `max_local_dynindx'.
> (mips_elf_sort_hash_table): Handle it.
> (mips_elf_sort_hash_table_f) <GGA_NONE>: For forced local
> symbols bump up `max_local_dynindx' rather than
> `max_non_got_dynindx'.
> ---
I have been told the issue outstanding with PR ld/20828 and version
symbols causes non-working executables to be produced such as in the case
of Firefox.
I have therefore decided to backport this change (and its 3 preparatory
cleanups) to 2.28 to make people's life easier, as it makes executables
work while not making them otherwise any worse than now -- the binding of
any version symbols remains local, which is incorrect, or at least
inconsistent, however very unlikely to cause any problem.
Maciej
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-02-13 14:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-02 23:05 [committed] MIPS/BFD: Respect the ELF gABI dynamic symbol table sort requirement Maciej W. Rozycki
2017-02-13 14:45 ` Maciej W. Rozycki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).