This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] LTO: Change resolution to LDPR_PREVAILING_DEF for wrapper symbol
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: binutils at sourceware dot org
- Date: Tue, 2 Apr 2019 15:11:47 -0700
- Subject: [PATCH] LTO: Change resolution to LDPR_PREVAILING_DEF for wrapper symbol
Change resolution from PREVAILING_DEF_IRONLY to LDPR_PREVAILING_DEF
for wrapper symbol.
PR ld/24406
* ld.texi: Remove LTO warning from --wrap.
* plugin.c (get_symbols): Change resolution to LDPR_PREVAILING_DEF
for wrapper symbol.
* testsuite/ld-plugin/lto.exp: Run ld/24406 test.
* testsuite/ld-plugin/pr24406.c: New file.
---
ld/ld.texi | 3 ---
ld/plugin.c | 15 +++++++++++----
ld/testsuite/ld-plugin/lto.exp | 4 ++++
ld/testsuite/ld-plugin/pr24406.c | 17 +++++++++++++++++
4 files changed, 32 insertions(+), 7 deletions(-)
create mode 100644 ld/testsuite/ld-plugin/pr24406.c
diff --git a/ld/ld.texi b/ld/ld.texi
index 0bcbec463f..f652740c04 100644
--- a/ld/ld.texi
+++ b/ld/ld.texi
@@ -2415,9 +2415,6 @@ g (void)
@}
@end smallexample
-Please keep in mind that with link-time optimization (LTO) enabled, your whole
-program may be a translation unit.
-
@kindex --eh-frame-hdr
@kindex --no-eh-frame-hdr
@item --eh-frame-hdr
diff --git a/ld/plugin.c b/ld/plugin.c
index a76e44c79f..e2abc84375 100644
--- a/ld/plugin.c
+++ b/ld/plugin.c
@@ -744,10 +744,17 @@ get_symbols (const void *handle, int nsyms, struct ld_plugin_symbol *syms,
struct bfd_link_hash_entry *blhe;
asection *owner_sec;
int res;
+ struct bfd_link_hash_entry *unwrap = NULL;
if (syms[n].def != LDPK_UNDEF)
- blhe = bfd_link_hash_lookup (link_info.hash, syms[n].name,
- FALSE, FALSE, TRUE);
+ {
+ blhe = bfd_link_hash_lookup (link_info.hash, syms[n].name,
+ FALSE, FALSE, TRUE);
+ /* Check if a symbol is a wrapped symbol. */
+ if (blhe && syms[n].def != LDPK_WEAKUNDEF)
+ unwrap = unwrap_hash_lookup (&link_info, (bfd *) abfd,
+ blhe);
+ }
else
blhe = bfd_wrapped_link_hash_lookup (link_info.output_bfd, &link_info,
syms[n].name, FALSE, FALSE, TRUE);
@@ -836,8 +843,8 @@ get_symbols (const void *handle, int nsyms, struct ld_plugin_symbol *syms,
/* We need to know if the sym is referenced from non-IR files. Or
even potentially-referenced, perhaps in a future final link if
this is a partial one, perhaps dynamically at load-time if the
- symbol is externally visible. */
- if (blhe->non_ir_ref_regular)
+ symbol is externally visible. Also check for wrapper symbol. */
+ if (blhe->non_ir_ref_regular || (unwrap && unwrap != blhe))
res = LDPR_PREVAILING_DEF;
else if (is_visible_from_outside (&syms[n], blhe))
res = def_ironly_exp;
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index ce57705f46..30ab2cb3fe 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -461,6 +461,10 @@ set lto_run_tests [list \
"-O2 -flto" "" \
{dummy.c} "pr22751" "pass.out" "-flto -O2" "c" "" \
"-Wl,--whole-archive tmpdir/pr22751.a -Wl,--no-whole-archive"] \
+ [list "Run pr24406" \
+ "-O2 -flto" "" \
+ {pr24406.c} "pr24406" "pass.out" "-flto -O2" "c" "" \
+ "-Wl,--wrap=read"] \
]
if { [at_least_gcc_version 4 7] } {
diff --git a/ld/testsuite/ld-plugin/pr24406.c b/ld/testsuite/ld-plugin/pr24406.c
new file mode 100644
index 0000000000..43995bdb07
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr24406.c
@@ -0,0 +1,17 @@
+#include <stdio.h>
+#include <unistd.h>
+
+ssize_t
+__wrap_read (int fd, void *buffer, size_t count)
+{
+ puts ("PASS");
+ return fd + count + sizeof (buffer);
+}
+
+
+int
+main ()
+{
+ int i = read (1, "abc", 5);
+ return i == 0;
+}
--
2.20.1