This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PR ld/17973: Don't generate the fake FILE symbol when plugin is used


On Sat, Feb 14, 2015 at 5:15 AM, Alan Modra <amodra@gmail.com> wrote:
> LTO output objects have an STT_FILE symbol using the name of the file,
> a temporary file.  This results in executables that can't be exactly
> reproduced, so the file name needs to be dropped.  We don't want to
> lose all file symbols when linking a mix of lto and non-lto objects as
> a file symbol can be used to figure which source file generated a
> given local symbol.  So lto output objects need to be marked.
>
> I chose to mark lto output objects with a new bfd flag.  This flag is
> also used to fix a bug in the link-once handling;  An object being
> loaded after "loading_lto_outputs" is set might be one extracted from
> an archive to satisfy new references from lto objects, not an lto
> object itself.
>
> The new flag is copied from archive to elements, and the same done
> for no_export.  This fixes a bug in that --exclude-libs doesn't work
> with thin archives.  I'm not completely happy with this part of the
> patch and may revist this to avoid the hack in
> _bfd_look_for_bfd_in_cache.
>
>         PR ld/17973
> include/
>         * bfdlink.h (struct bfd_link_info): Delete loading_lto_outputs.
> bfd/
>         * bfd.c (struct bfd): Add lto_output.
>         * linker.c (_bfd_handle_already_linked): Explicitly test for
>         objects added by the lto plugin.
>         * opncls.c (_bfd_new_bfd_contained_in): Copy lto_output and
>         no_export flags from archive.
>         * archive.c (open_nested_file): New function, setting lto_output
>         and no_export, extracted from..
>         (find_nested_archive): ..here.  Flip params.  Rename from
>         _bfd_find_nested_archive.
>         (_bfd_get_elt_at_filepos): Correct var typo.  Use open_nested_file.
>         (_bfd_look_for_bfd_in_cache): Copy no_export.
>         * elflink.c (elf_link_add_object_symbols): Remove now unnecessary
>         my_archive->no_export test.
>         (elf_link_input_bfd): Drop existing lto_output STT_FILE syms.
>         Don't use the file name when adding lto_output STT_FILE sym.
>         * bfd-in2.h: Regenerate.
> ld/
>         * ldlang.h (struct lang_input_statement_flags): Add lto_output.
>         * ldlang.c (lang_process): Don't set loading_lto_outputs.
>         * ldfile.c (ldfile_try_open_bfd): Transfer entry flags.lto_output
>         to bfd.
>         * plugin.c (add_input_file, add_input_library): Set flags.lto_output.
>

I checked in this testcase.

H.J.
---
>From f58926a652e71cc4809758c693ff005d9fdc46e1 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Sat, 14 Feb 2015 05:45:08 -0800
Subject: [PATCH] Add a testcase for PR ld/17973

ld/

PR ld/17973
* testplug2.c (allsymbolsread_silent): New.
(set_register_hook): Handle allsymbolsreadsilent.
(onall_symbols_read): Skip a message if allsymbolsread_silent is
TRUE.

ld/testsuite/

PR ld/17973
* ld-plugin/plugin.exp (regassilent): New.
Compile tmpdir/dummy.s and ld-plugin/pr17973.s.
(plugin_tests): Add a test for PR ld/17973.
* ld-plugin/pr17973.d: New file.
* ld-plugin/pr17973.s: Likewise.
---
 ld/ChangeLog                      | 8 ++++++++
 ld/testplug2.c                    | 9 ++++++++-
 ld/testsuite/ChangeLog            | 9 +++++++++
 ld/testsuite/ld-plugin/plugin.exp | 8 +++++++-
 ld/testsuite/ld-plugin/pr17973.d  | 4 ++++
 ld/testsuite/ld-plugin/pr17973.s  | 3 +++
 6 files changed, 39 insertions(+), 2 deletions(-)
 create mode 100644 ld/testsuite/ld-plugin/pr17973.d
 create mode 100644 ld/testsuite/ld-plugin/pr17973.s

diff --git a/ld/ChangeLog b/ld/ChangeLog
index 4803ec3..43cf4e8 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,11 @@
+2015-02-14  H.J. Lu  <hongjiu.lu@intel.com>
+
+ PR ld/17973
+ * testplug2.c (allsymbolsread_silent): New.
+ (set_register_hook): Handle allsymbolsreadsilent.
+ (onall_symbols_read): Skip a message if allsymbolsread_silent is
+ TRUE.
+
 2015-02-14  Alan Modra  <amodra@gmail.com>

  PR ld/17973
diff --git a/ld/testplug2.c b/ld/testplug2.c
index 10f0efb..9b93dd8 100644
--- a/ld/testplug2.c
+++ b/ld/testplug2.c
@@ -125,6 +125,7 @@ static bfd_boolean register_claimfile_hook = TRUE;
 static bfd_boolean register_allsymbolsread_hook = FALSE;
 static bfd_boolean register_cleanup_hook = FALSE;
 static bfd_boolean dumpresolutions = FALSE;
+static bfd_boolean allsymbolsread_silent = FALSE;

 /* The master list of all claimable/claimed files.  */
 static claim_file_t *claimfiles_list = NULL;
@@ -307,6 +308,11 @@ set_register_hook (const char *whichhook,
bfd_boolean yesno)
     register_claimfile_hook = yesno;
   else if (!strcmp ("allsymbolsread", whichhook))
     register_allsymbolsread_hook = yesno;
+  else if (!strcmp ("allsymbolsreadsilent", whichhook))
+    {
+      register_allsymbolsread_hook = yesno;
+      allsymbolsread_silent = TRUE;
+    }
   else if (!strcmp ("cleanup", whichhook))
     register_cleanup_hook = yesno;
   else
@@ -573,7 +579,8 @@ onall_symbols_read (void)
   char buffer[30];
   int fd;
   char *filename;
-  TV_MESSAGE (LDPL_INFO, "hook called: all symbols read.");
+  if (! allsymbolsread_silent)
+    TV_MESSAGE (LDPL_INFO, "hook called: all symbols read.");
   for ( ; claimfile; claimfile = claimfile->next)
     {
       enum ld_plugin_status rv;
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index af5b544..42ed492 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,12 @@
+2015-02-14  H.J. Lu  <hongjiu.lu@intel.com>
+
+ PR ld/17973
+ * ld-plugin/plugin.exp (regassilent): New.
+ Compile tmpdir/dummy.s and ld-plugin/pr17973.s.
+ (plugin_tests): Add a test for PR ld/17973.
+ * ld-plugin/pr17973.d: New file.
+ * ld-plugin/pr17973.s: Likewise.
+
 2015-02-12  H.J. Lu  <hongjiu.lu@intel.com>

  * ld-i386/i386.exp: Replace elf_i386 with elf_i386_nacl for nacl.
diff --git a/ld/testsuite/ld-plugin/plugin.exp
b/ld/testsuite/ld-plugin/plugin.exp
index 35b7bbe..b6007eb 100644
--- a/ld/testsuite/ld-plugin/plugin.exp
+++ b/ld/testsuite/ld-plugin/plugin.exp
@@ -66,6 +66,7 @@ verbose "Full plugin3 path $plugin3_path" 2

 set regclm "-plugin-opt registerclaimfile"
 set regas "-plugin-opt registerallsymbolsread"
+set regassilent "-plugin-opt registerallsymbolsreadsilent"
 set regcln "-plugin-opt registercleanup"

 if { [istarget m681*-*-*] || [istarget m68hc1*-*-*] || [istarget
m9s12x*-*-*] } {
@@ -85,7 +86,9 @@ set plugin_nm_output ""
 if { $can_compile && \
  (![ld_compile "$CC $CFLAGS" $srcdir/$subdir/main.c tmpdir/main.o] \
  || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/func.c tmpdir/func.o] \
- || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/text.c tmpdir/text.o]) } {
+ || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/text.c tmpdir/text.o] \
+ || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/dummy.s tmpdir/dummy.o] \
+ || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/pr17973.s tmpdir/pr17973.o]) } {
     # Defer fail until we have list of tests set.
     set failed_compile 1
 }
@@ -174,6 +177,9 @@ set plugin_tests [list \
     $testobjfiles $libs" "" "" "" {{ld plugin-28.d}} "main.x" ] \
     [list "plugin warning" "-plugin $plugin2_path -plugin-opt warning \
     $testobjfiles $libs" "" "" "" {{ld plugin-29.d}} "main.x" ] \
+    [list "PR ld/17973" "-plugin $plugin2_path -shared $regassilent \
+ -plugin-opt add:tmpdir/pr17973.o \
+    tmpdir/dummy.o" "" "" "" {{readelf -sW pr17973.d}} "main.x" ] \
 ]

 set plugin_lib_tests [list \
diff --git a/ld/testsuite/ld-plugin/pr17973.d b/ld/testsuite/ld-plugin/pr17973.d
new file mode 100644
index 0000000..85c849a
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr17973.d
@@ -0,0 +1,4 @@
+#failif
+#...
+.*0+ +FILE +LOCAL +DEFAULT +ABS tmpdir/pr17973.o
+#...
diff --git a/ld/testsuite/ld-plugin/pr17973.s b/ld/testsuite/ld-plugin/pr17973.s
new file mode 100644
index 0000000..77c5c8a
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr17973.s
@@ -0,0 +1,3 @@
+ .data
+foo:
+ .dc.a bar
-- 
2.1.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]