Fix the plugin as-needed patch. (#1889763)

This commit is contained in:
Nick Clifton 2020-10-29 15:08:07 +00:00
parent 7a51afe32a
commit 7b51276e4a
2 changed files with 70 additions and 77 deletions

View File

@ -1,83 +1,73 @@
diff -rup binutils.orig/ld/testsuite/ld-plugin/lto.exp binutils-2.35.1/ld/testsuite/ld-plugin/lto.exp
--- binutils.orig/ld/testsuite/ld-plugin/lto.exp 2020-10-09 11:46:13.571665439 +0100
+++ binutils-2.35.1/ld/testsuite/ld-plugin/lto.exp 2020-10-09 11:47:59.113302758 +0100
@@ -319,27 +319,6 @@ set lto_link_elf_tests [list \
[list "PR ld/13244" \
"-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib" "-O2 -fno-early-inlining -flto" \
{pr13244.c} {{"readelf" {-s --wide} "pr13244.d"}} "pr13244.so" "c"] \
- [list "Build libpr15146a.a" \
- "$plug_opt" "-flto -O2" \
- {pr15146a.c} {} "lib15146a.a"] \
- [list "Build pr15146b.so" \
- "-shared" "-O2 -fpic" \
- {pr15146b.c} {} "pr15146b.so" "c"] \
- [list "Build pr15146c.so" \
- "-shared -Wl,--no-as-needed tmpdir/pr15146b.so" "-O2 -fpic" \
- {pr15146c.c} {} "pr15146c.so" "c"] \
- [list "PR ld/15146 (1)" \
- "-O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146a.o tmpdir/pr15146c.so" "" \
- {dummy.c} {{"readelf" {-d} "pr15146.d"}} "pr15146a.exe"] \
- [list "Build libpr15146d.a" \
- "$plug_opt" "-flto -O2" \
- {pr15146d.c} {} "lib15146d.a"] \
- [list "Build libpr16746a.a" \
- "" "" \
- {pr16746a.c pr16746b.c} {} "lib15146a.a"] \
- [list "Build libpr16746b.a" \
- "$plug_opt" "-O2 -flto" \
- {pr16746c.c pr16746d.c} {} "lib15146b.a"] \
[list "PR ld/16746 (1)" \
"-O2 -flto -fuse-linker-plugin tmpdir/pr16746a.o tmpdir/pr16746c.o" "-O2 -flto" \
{dummy.c} {} "pr16746a.exe"] \
@@ -602,13 +581,6 @@ run_cc_link_tests $lto_compile_elf_tests
# Restrict these to ELF targets that support shared libs and PIC.
if { [is_elf_format] && [check_lto_shared_available] } {
run_cc_link_tests $lto_link_elf_tests
- set testname "PR ld/15146 (2)"
- set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146d.o tmpdir/pr15146c.so"]
- if { [ regexp "undefined reference to symbol '\\.?xxx'" $exec_output ] } {
- pass $testname
- } {
- fail $testname
- }
set testname "PR ld/16746 (3)"
set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746b.o tmpdir/pr16746d.o"]
if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
diff -rup binutils.orig/bfd/elflink.c binutils-2.35.1/bfd/elflink.c
--- binutils.orig/bfd/elflink.c 2020-10-09 11:46:14.151663446 +0100
+++ binutils-2.35.1/bfd/elflink.c 2020-10-09 11:46:27.222618528 +0100
@@ -4970,11 +4970,7 @@ elf_link_add_object_symbols (bfd *abfd,
object and a shared object. */
bfd_boolean dynsym = FALSE;
--- binutils.orig/bfd/elflink.c 2020-10-29 12:46:32.228618844 +0000
+++ binutils-2.35.1/bfd/elflink.c 2020-10-29 13:07:58.786847312 +0000
@@ -5340,7 +5340,7 @@ elf_link_add_object_symbols (bfd *abfd,
struct elf_link_hash_entry *h;
bfd_size_type size;
unsigned int alignment_power;
- unsigned int non_ir_ref_dynamic;
+ struct elf_link_hash_entry preserved_h;
- /* Plugin symbols aren't normal. Don't set def_regular or
- ref_regular for them, or make them dynamic. */
- if ((abfd->flags & BFD_PLUGIN) != 0)
- ;
- else if (! dynamic)
+ if (! dynamic)
for (p = htab->root.table.table[i]; p != NULL; p = p->next)
{
if (! definition)
{
@@ -5155,10 +5151,6 @@ elf_link_add_object_symbols (bfd *abfd,
&& !bfd_link_relocatable (info))
dynsym = FALSE;
- /* Nor should we make plugin symbols dynamic. */
- if ((abfd->flags & BFD_PLUGIN) != 0)
- dynsym = FALSE;
-
if (definition)
{
h->target_internal = isym->st_target_internal;
@@ -5185,7 +5177,7 @@ elf_link_add_object_symbols (bfd *abfd,
@@ -5365,7 +5365,8 @@ elf_link_add_object_symbols (bfd *abfd,
/* Preserve non_ir_ref_dynamic so that this symbol
will be exported when the dynamic lib becomes needed
in the second pass. */
- non_ir_ref_dynamic = h->root.non_ir_ref_dynamic;
+ preserved_h = *h;
+
memcpy (p, old_ent, htab->root.table.entsize);
old_ent = (char *) old_ent + htab->root.table.entsize;
h = (struct elf_link_hash_entry *) p;
@@ -5382,7 +5383,10 @@ elf_link_add_object_symbols (bfd *abfd,
if (alignment_power > h->root.u.c.p->alignment_power)
h->root.u.c.p->alignment_power = alignment_power;
}
- h->root.non_ir_ref_dynamic = non_ir_ref_dynamic;
+
+ h->root.non_ir_ref_dynamic
+ = preserved_h.root.non_ir_ref_dynamic;
+ h->root.as_needed_def_dynamic |= preserved_h.dynamic_def;
}
}
- if (dynsym && h->dynindx == -1)
+ if (dynsym && (abfd->flags & BFD_PLUGIN) == 0 && h->dynindx == -1)
@@ -5819,6 +5823,11 @@ elf_link_add_archive_symbols (bfd *abfd,
if (h == NULL)
continue;
+ /* Don't load the archive element after seeing a definition
+ in a DT_NEEDED shared object. */
+ if (h->root.as_needed_def_dynamic)
+ continue;
+
if (h->root.type == bfd_link_hash_undefined)
{
if (! bfd_elf_link_record_dynamic_symbol (info, h))
goto error_free_vers;
/* If the archive element has already been loaded then one
Only in binutils.orig/: binutils-2.35.1
diff -rup binutils.orig/include/bfdlink.h binutils-2.35.1/include/bfdlink.h
--- binutils.orig/include/bfdlink.h 2020-10-29 12:46:31.611621137 +0000
+++ binutils-2.35.1/include/bfdlink.h 2020-10-29 13:07:36.833927443 +0000
@@ -114,6 +114,9 @@ struct bfd_link_hash_entry
as distinct from a LTO IR object file. */
unsigned int non_ir_ref_dynamic : 1;
+ /* Symbol is defined in a DT_NEEDED dynamic object file. */
+ unsigned int as_needed_def_dynamic : 1;
+
/* Symbol is a built-in define. These will be overridden by PROVIDE
in a linker script. */
unsigned int linker_def : 1;
diff -rup binutils.orig/ld/plugin.c binutils-2.35.1/ld/plugin.c
--- binutils.orig/ld/plugin.c 2020-10-29 12:46:31.878620145 +0000
+++ binutils-2.35.1/ld/plugin.c 2020-10-29 13:07:19.951989072 +0000
@@ -794,7 +794,8 @@ get_symbols (const void *handle, int nsy
if (blhe->type == bfd_link_hash_undefined
|| blhe->type == bfd_link_hash_undefweak)
{
- res = LDPR_UNDEF;
+ res = (blhe->as_needed_def_dynamic
+ ? LDPR_RESOLVED_DYN : LDPR_UNDEF);
goto report_symbol;
}
if (blhe->type != bfd_link_hash_defined

View File

@ -2,7 +2,7 @@
Summary: A GNU collection of binary utilities
Name: %{?cross}binutils%{?_with_debug:-debug}
Version: 2.35.1
Release: 8%{?dist}
Release: 9%{?dist}
License: GPLv3+
URL: https://sourceware.org/binutils
@ -832,6 +832,9 @@ exit 0
#----------------------------------------------------------------------------
%changelog
* Thu Oct 29 2020 Nick Clifton <nickc@redhat.com> - 2.35.1-9
- Fix the plugin as-needed patch. (#1889763)
* Tue Oct 27 2020 Nick Clifton <nickc@redhat.com> - 2.35.1-8
- Really fix erroneous decoding of LEB128 values. (#1891171)