• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revisionf5deb4103e0cec3912c304d7c08277aadab09e5c (tree)
Time2020-01-15 12:10:41
AuthorAlan Modra <amodra@gmai...>
CommiterAlan Modra

Log Message

PR25384, PowerPC64 ELFv1 copy relocs against function symbols

Function symbols of course don't normally want .dynbss copies but
with some old versions of gcc they are needed to copy the function
descriptor. This patch restricts the cases where they are useful to
compilers using dot-symbols, and enables the warning regardless of
whether a PLT entry is emitted in the executable. PLTs in shared
libraries are affected by a .dynbss copy in the executable.

bfd/
PR 25384
* elf64-ppc.c (ELIMINATE_COPY_RELOCS): Update comment.
(ppc64_elf_adjust_dynamic_symbol): Don't allow .dynbss copies
of function symbols unless dot symbols are present. Do warn
whenever one is created, regardles of whether a PLT entry is
also emitted for the function symbol.
ld/
* testsuite/ld-powerpc/ambiguousv1b.d: Adjust expected output.
* testsuite/ld-powerpc/funref.s: Align func_tab.
* testsuite/ld-powerpc/funref2.s: Likewise.
* testsuite/ld-powerpc/funv1.s: Add dot symbols.

(cherry picked from commit e1c6cf618cbeebbafd34afc5ee921fcbf7061bfa)

Change Summary

Incremental Difference

--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,12 @@
1+2020-01-15 Alan Modra <amodra@gmail.com>
2+
3+ PR 25384
4+ * elf64-ppc.c (ELIMINATE_COPY_RELOCS): Update comment.
5+ (ppc64_elf_adjust_dynamic_symbol): Don't allow .dynbss copies
6+ of function symbols unless dot symbols are present. Do warn
7+ whenever one is created, regardles of whether a PLT entry is
8+ also emitted for the function symbol.
9+
110 2019-08-28 Tamar Christina <tamar.christina@arm.com>
211
312 Backported from mainline.
--- a/bfd/elf64-ppc.c
+++ b/bfd/elf64-ppc.c
@@ -2574,20 +2574,20 @@ must_be_dyn_reloc (struct bfd_link_info *info,
25742574 }
25752575
25762576 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2577- copying dynamic variables from a shared lib into an app's dynbss
2577+ copying dynamic variables from a shared lib into an app's .dynbss
25782578 section, and instead use a dynamic relocation to point into the
2579- shared lib. With code that gcc generates, it's vital that this be
2580- enabled; In the PowerPC64 ABI, the address of a function is actually
2581- the address of a function descriptor, which resides in the .opd
2582- section. gcc uses the descriptor directly rather than going via the
2583- GOT as some other ABI's do, which means that initialized function
2584- pointers must reference the descriptor. Thus, a function pointer
2585- initialized to the address of a function in a shared library will
2586- either require a copy reloc, or a dynamic reloc. Using a copy reloc
2587- redefines the function descriptor symbol to point to the copy. This
2588- presents a problem as a plt entry for that function is also
2589- initialized from the function descriptor symbol and the copy reloc
2590- may not be initialized first. */
2579+ shared lib. With code that gcc generates it is vital that this be
2580+ enabled; In the PowerPC64 ELFv1 ABI the address of a function is
2581+ actually the address of a function descriptor which resides in the
2582+ .opd section. gcc uses the descriptor directly rather than going
2583+ via the GOT as some other ABIs do, which means that initialized
2584+ function pointers reference the descriptor. Thus, a function
2585+ pointer initialized to the address of a function in a shared
2586+ library will either require a .dynbss copy and a copy reloc, or a
2587+ dynamic reloc. Using a .dynbss copy redefines the function
2588+ descriptor symbol to point to the copy. This presents a problem as
2589+ a PLT entry for that function is also initialized from the function
2590+ descriptor symbol and the copy may not be initialized first. */
25912591 #define ELIMINATE_COPY_RELOCS 1
25922592
25932593 /* Section name for stubs is the associated section name plus this
@@ -6134,13 +6134,23 @@ ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
61346134 || h->protected_def)
61356135 return TRUE;
61366136
6137- if (h->plt.plist != NULL)
6138- {
6139- /* We should never get here, but unfortunately there are versions
6140- of gcc out there that improperly (for this ABI) put initialized
6141- function pointers, vtable refs and suchlike in read-only
6142- sections. Allow them to proceed, but warn that this might
6143- break at runtime. */
6137+ if (h->type == STT_FUNC
6138+ || h->type == STT_GNU_IFUNC)
6139+ {
6140+ /* .dynbss copies of function symbols only work if we have
6141+ ELFv1 dot-symbols. ELFv1 compilers since 2004 default to not
6142+ use dot-symbols and set the function symbol size to the text
6143+ size of the function rather than the size of the descriptor.
6144+ That's wrong for copying a descriptor. */
6145+ if (((struct ppc_link_hash_entry *) h)->oh == NULL
6146+ || !(h->size == 24 || h->size == 16))
6147+ return TRUE;
6148+
6149+ /* We should never get here, but unfortunately there are old
6150+ versions of gcc (circa gcc-3.2) that improperly for the
6151+ ELFv1 ABI put initialized function pointers, vtable refs and
6152+ suchlike in read-only sections. Allow them to proceed, but
6153+ warn that this might break at runtime. */
61446154 info->callbacks->einfo
61456155 (_("%P: copy reloc against `%pT' requires lazy plt linking; "
61466156 "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,10 @@
1+2020-01-15 Alan Modra <amodra@gmail.com>
2+
3+ * testsuite/ld-powerpc/ambiguousv1b.d: Adjust expected output.
4+ * testsuite/ld-powerpc/funref.s: Align func_tab.
5+ * testsuite/ld-powerpc/funref2.s: Likewise.
6+ * testsuite/ld-powerpc/funv1.s: Add dot symbols.
7+
18 2019-09-05 Eric Botcazou <ebotcazou@adacore.com>
29
310 PR ld/24574
--- a/ld/testsuite/ld-powerpc/ambiguousv1b.d
+++ b/ld/testsuite/ld-powerpc/ambiguousv1b.d
@@ -3,6 +3,7 @@
33 #as: -a64
44 #ld: -melf64ppc --emit-stub-syms
55 #ld_after_inputfiles: tmpdir/funv1.so
6+#warning: .*requires lazy plt linking.*
67 #readelf: -rs --wide
78 # Check that we do the right thing with funref2.s that doesn't have
89 # anything to mark it as ELFv1 or ELFv2. Since my_func address is
@@ -15,9 +16,9 @@ Relocation section .* contains 1 entry:
1516
1617 Symbol table '\.dynsym' contains 2 entries:
1718 #...
18-.*: 0*[1-9a-f][0-9a-f]* 4 FUNC GLOBAL DEFAULT 1[23] my_func
19+.*: 0*[1-9a-f][0-9a-f]* +24 FUNC +GLOBAL DEFAULT +1[23] my_func
1920 #...
2021 Symbol table '\.symtab' contains .* entries:
2122 #...
22-.*: 0*[1-9a-f][0-9a-f]* 4 FUNC GLOBAL DEFAULT 1[23] my_func
23+.*: 0*[1-9a-f][0-9a-f]* +24 FUNC +GLOBAL DEFAULT +1[23] my_func
2324 #pass
--- a/ld/testsuite/ld-powerpc/funref.s
+++ b/ld/testsuite/ld-powerpc/funref.s
@@ -1,4 +1,5 @@
11 .data
22 .globl func_tab
3+ .p2align 3
34 func_tab:
45 .dc.a my_func
--- a/ld/testsuite/ld-powerpc/funref2.s
+++ b/ld/testsuite/ld-powerpc/funref2.s
@@ -1,4 +1,5 @@
11 .section .rodata,"a",@progbits
22 .globl func_tab
3+ .p2align 3
34 func_tab:
45 .dc.a my_func
--- a/ld/testsuite/ld-powerpc/funv1.s
+++ b/ld/testsuite/ld-powerpc/funv1.s
@@ -1,10 +1,12 @@
1- .globl my_func
2- .type my_func,@function
3- .section .opd,"aw",@progbits
1+# old style ELFv1, with dot-symbols
2+ .globl my_func, .my_func
3+ .type .my_func, @function
4+ .section .opd, "aw", @progbits
45 my_func:
5- .quad .Lmy_func, .TOC.@tocbase
6+ .quad .my_func, .TOC.@tocbase, 0
7+ .size my_func, . - my_func
68
79 .text
8-.Lmy_func:
10+.my_func:
911 blr
10- .size my_func,.-.Lmy_func
12+ .size .my_func, . - .my_func