This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] ld: Add PR ld/25593 tests
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Alan Modra <amodra at gmail dot com>
- Cc: Binutils <binutils at sourceware dot org>
- Date: Tue, 25 Feb 2020 18:27:24 -0800
- Subject: [PATCH] ld: Add PR ld/25593 tests
- References: <20200226000524.GB5750@bubble.grove.modra.org>
On Tue, Feb 25, 2020 at 4:05 PM Alan Modra <amodra@gmail.com> wrote:
>
> This patch delays setting up DT_NEEDED dynamic tags until all object
> files and libraries have been opened and their symbols processed,
> rather than adding the tags while processing symbols. Tags are
> ordered according to the position of the associated library on the
> command line and linker scripts. It is still possible with
> --as-needed libs that are mentioned more than once for tags to be
> ordered according to which mention was needed. For example with
> "--as-needed a.so b.so c.so b.so" when b.so is not needed by a.so or
> any other prior object file but is needed by c.so, the order of tags
> will be "A C B".
>
> bfd/
> PR 25593
> * elf-bfd.h (struct elf_link_hash_table): Rename "loaded" to
> "dyn_loaded".
> (bfd_elf_add_dt_needed_tag): Declare.
> * elf-strtab.c (_bfd_elf_strtab_restore): Handle NULL buf.
> * elflink.c (bfd_elf_add_dt_needed_tag): Make global and rename
> from elf_add_dt_needed_tag. Remove soname and doit param.
> (elf_link_add_object_symbols): Don't use elf_add_dt_needed_tag
> to see whether as-needed lib is already loaded, use dyn_loaded
> list instead. When saving and restoring around as-needed lib
> handle possibility that dynstr has not been initialised. Don't
> add DT_NEEDED tags here. Limit dyn_loaded list to dynamic libs.
> Mark libs loaded via DT_NEEDED entries of other libs with
> DYN_NO_NEEDED if they should not be mentioned in DT_NEEDED of
> the output.
> (elf_link_check_versioned_symbol): Remove now unneccesary
> DYNAMIC check when traversing dyn_loaded list.
> ld/
> PR 25593
> * ldelf.c (ldelf_try_needed): Add DT_NEEDED lib to input_bfds.
> (ldelf_after_open): Save state of input_bfds list before loading
> DT_NEEDED libs. Traverse input_bfds list adding DT_NEEDED tags.
> Restore input_bfds list.
> * testsuite/ld-cris/gotplt1.d: Adjust for changed .dynstr order.
>
Here is a patch to add some tests. OK for master branch.
--
H.J.
From 13a22f48ee85f6bc78f7d3d614754be55451ccf3 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Tue, 25 Feb 2020 04:22:37 -0800
Subject: [PATCH] ld: Add PR ld/25593 tests
PR ld/25593
* testsuite/ld-plugin/lto.exp: Run ld/25593 tests.
* testsuite/ld-plugin/pr25593.d: New file.
* testsuite/ld-plugin/pr25593a-1.c: Likewise.
* testsuite/ld-plugin/pr25593a-2.c: Likewise.
* testsuite/ld-plugin/pr25593b.c: Likewise.
* testsuite/ld-plugin/pr25593c.c: Likewise.
* testsuite/ld-plugin/pr25593d.c: Likewise.
* testsuite/ld-plugin/pr25593e.c: Likewise.
---
ld/testsuite/ld-plugin/lto.exp | 26 ++++++++++++++++++++++++++
ld/testsuite/ld-plugin/pr25593.d | 5 +++++
ld/testsuite/ld-plugin/pr25593a-1.c | 12 ++++++++++++
ld/testsuite/ld-plugin/pr25593a-2.c | 1 +
ld/testsuite/ld-plugin/pr25593b.c | 7 +++++++
ld/testsuite/ld-plugin/pr25593c.c | 4 ++++
ld/testsuite/ld-plugin/pr25593d.c | 4 ++++
ld/testsuite/ld-plugin/pr25593e.c | 4 ++++
8 files changed, 63 insertions(+)
create mode 100644 ld/testsuite/ld-plugin/pr25593.d
create mode 100644 ld/testsuite/ld-plugin/pr25593a-1.c
create mode 100644 ld/testsuite/ld-plugin/pr25593a-2.c
create mode 100644 ld/testsuite/ld-plugin/pr25593b.c
create mode 100644 ld/testsuite/ld-plugin/pr25593c.c
create mode 100644 ld/testsuite/ld-plugin/pr25593d.c
create mode 100644 ld/testsuite/ld-plugin/pr25593e.c
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index 1b44b0da3fd..0243f093288 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -342,6 +342,32 @@ set lto_link_elf_tests [list \
[list "PR ld/24486" \
"-O2 -flto tmpdir/pr24486a.o tmpdir/pr24486c.so -Wl,--as-needed tmpdir/pr24486b.so" "" \
{dummy.c} {} "pr24486.exe"] \
+ [list "Build pr25593a-1.o" \
+ "$plug_opt" "-flto -O2" \
+ {pr25593a-1.c} {} "" "c"] \
+ [list "Build pr25593a-2.o" \
+ "" "-O2" \
+ {pr25593a-2.c} {} "" "c"] \
+ [list "Build pr25593b.o" \
+ "" "-O2" \
+ {pr25593b.c} {} "" "c"] \
+ [list "Build pr25593c.so" \
+ "-shared" "-O2 -fpic" \
+ {pr25593c.c} {} "pr25593c.so" "c"] \
+ [list "Build pr25593d.so" \
+ "-shared" "-O2 -fpic" \
+ {pr25593d.c} {} "pr25593d.so" "c"] \
+ [list "Build pr25593e.so" \
+ "-shared" "-O2 -fpic" \
+ {pr25593e.c} {} "pr25593e.so" "c"] \
+ [list "PR ld/r25593 (LTO)" \
+ "-O2 -flto -Wl,--as-needed tmpdir/pr25593a-1.o tmpdir/pr25593b.o \
+ tmpdir/pr25593c.so tmpdir/pr25593d.so tmpdir/pr25593e.so" "" \
+ {dummy.c} {{readelf {-d --wide} pr25593.d}} "pr25593a.exe"] \
+ [list "PR ld/r25593" \
+ "-O2 -flto -Wl,--as-needed tmpdir/pr25593a-2.o tmpdir/pr25593b.o \
+ tmpdir/pr25593c.so tmpdir/pr25593d.so tmpdir/pr25593e.so" "" \
+ {dummy.c} {{readelf {-d --wide} pr25593.d}} "pr25593b.exe"] \
]
# PR 14918 checks that libgcc is not spuriously included in a shared link of
diff --git a/ld/testsuite/ld-plugin/pr25593.d b/ld/testsuite/ld-plugin/pr25593.d
new file mode 100644
index 00000000000..77877674e4e
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr25593.d
@@ -0,0 +1,5 @@
+#...
+ 0x0+1 \(NEEDED\) +Shared library: \[tmpdir/pr25593c\.so\]
+ 0x0+1 \(NEEDED\) +Shared library: \[tmpdir/pr25593d\.so\]
+ 0x0+1 \(NEEDED\) +Shared library: \[tmpdir/pr25593e\.so\]
+#pass
diff --git a/ld/testsuite/ld-plugin/pr25593a-1.c b/ld/testsuite/ld-plugin/pr25593a-1.c
new file mode 100644
index 00000000000..13d53950c3f
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr25593a-1.c
@@ -0,0 +1,12 @@
+extern void foo (void);
+extern void bar (void);
+extern void xxx (void);
+
+int
+main (void)
+{
+ xxx ();
+ foo ();
+ bar ();
+ return 0;
+}
diff --git a/ld/testsuite/ld-plugin/pr25593a-2.c b/ld/testsuite/ld-plugin/pr25593a-2.c
new file mode 100644
index 00000000000..bdc30dda6f1
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr25593a-2.c
@@ -0,0 +1 @@
+#include "pr25593a-1.c"
diff --git a/ld/testsuite/ld-plugin/pr25593b.c b/ld/testsuite/ld-plugin/pr25593b.c
new file mode 100644
index 00000000000..75b24193c7a
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr25593b.c
@@ -0,0 +1,7 @@
+extern void xyz ();
+
+void
+xxx (void)
+{
+ xyz ();
+}
diff --git a/ld/testsuite/ld-plugin/pr25593c.c b/ld/testsuite/ld-plugin/pr25593c.c
new file mode 100644
index 00000000000..cd0130cacdf
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr25593c.c
@@ -0,0 +1,4 @@
+void
+foo (void)
+{
+}
diff --git a/ld/testsuite/ld-plugin/pr25593d.c b/ld/testsuite/ld-plugin/pr25593d.c
new file mode 100644
index 00000000000..7de81b31a47
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr25593d.c
@@ -0,0 +1,4 @@
+void
+bar (void)
+{
+}
diff --git a/ld/testsuite/ld-plugin/pr25593e.c b/ld/testsuite/ld-plugin/pr25593e.c
new file mode 100644
index 00000000000..831b10522b4
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr25593e.c
@@ -0,0 +1,4 @@
+void
+xyz (void)
+{
+}
--
2.24.1