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]

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


GCC LTO plugin generates linker input files with random files, which
have no relations with input source files.  In order to avoid random
build id with LTO build, GCC won't generate the .file directive with
the names of random files.  See GCC PR lto/65015:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65015

for details.  When plugin is used, linker shouldn't use the names of
of random files for the fake FILE symbol either.  OK for master?

Thanks.


H.J.
--
bfd/

	PR ld/17973
	* elflink.c (elf_link_input_bfd): Don't generate the fake FILE
	symbol when plugin is used.

ld/testsuite/

	PR ld/17973
	* ld-plugin/plugin.exp: Compile ld-plugin/pr17973.s.
	(plugin_tests): Add a test for PR ld/17973.
	* ld-plugin/pr17973.d: New file.
	* ld-plugin/pr17973.s: Likewise.
---
 bfd/ChangeLog                     |  6 +++++
 bfd/elflink.c                     | 52 +++++++++++++++++++++++----------------
 ld/testsuite/ChangeLog            |  8 ++++++
 ld/testsuite/ld-plugin/plugin.exp |  5 +++-
 ld/testsuite/ld-plugin/pr17973.d  |  4 +++
 ld/testsuite/ld-plugin/pr17973.s  |  3 +++
 6 files changed, 56 insertions(+), 22 deletions(-)
 create mode 100644 ld/testsuite/ld-plugin/pr17973.d
 create mode 100644 ld/testsuite/ld-plugin/pr17973.s

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index cb08b77..b63cb17 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2015-02-13  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/17973
+	* elflink.c (elf_link_input_bfd): Don't generate the fake FILE
+	symbol when plugin is used.
+
 2015-02-13  Alan Modra  <amodra@gmail.com>
 
 	PR binutils/17512
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 16d9f20..c7cd365 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -9518,27 +9518,37 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
 	      && bfd_is_local_label_name (input_bfd, name)))
 	continue;
 
-      if (ELF_ST_TYPE (isym->st_info) == STT_FILE)
-	{
-	  have_file_sym = TRUE;
-	  flinfo->filesym_count += 1;
-	}
-      if (!have_file_sym)
-	{
-	  /* In the absence of debug info, bfd_find_nearest_line uses
-	     FILE symbols to determine the source file for local
-	     function symbols.  Provide a FILE symbol here if input
-	     files lack such, so that their symbols won't be
-	     associated with a previous input file.  It's not the
-	     source file, but the best we can do.  */
-	  have_file_sym = TRUE;
-	  flinfo->filesym_count += 1;
-	  memset (&osym, 0, sizeof (osym));
-	  osym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FILE);
-	  osym.st_shndx = SHN_ABS;
-	  if (!elf_link_output_sym (flinfo, input_bfd->filename, &osym,
-				    bfd_abs_section_ptr, NULL))
-	    return FALSE;
+      /* Don't generate the fake FILE symbol when plugin is used.  See
+	 GCC PR lto/65015:
+
+	 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65015
+
+	 for details.  */
+      if (!flinfo->info->lto_plugin_active)
+	{
+	  if (ELF_ST_TYPE (isym->st_info) == STT_FILE)
+	    {
+	      have_file_sym = TRUE;
+	      flinfo->filesym_count += 1;
+	    }
+	  if (!have_file_sym)
+	    {
+	      /* In the absence of debug info, bfd_find_nearest_line uses
+		 FILE symbols to determine the source file for local
+		 function symbols.  Provide a FILE symbol here if input
+		 files lack such, so that their symbols won't be
+		 associated with a previous input file.  It's not the
+		 source file, but the best we can do.  */
+	      have_file_sym = TRUE;
+	      flinfo->filesym_count += 1;
+	      memset (&osym, 0, sizeof (osym));
+	      osym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FILE);
+	      osym.st_shndx = SHN_ABS;
+	      if (!elf_link_output_sym (flinfo, input_bfd->filename,
+					&osym, bfd_abs_section_ptr,
+					NULL))
+		return FALSE;
+	    }
 	}
 
       osym = *isym;
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index af5b544..eb84e44 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2015-02-13  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/17973
+	* ld-plugin/plugin.exp: Compile 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..3f03fdb 100644
--- a/ld/testsuite/ld-plugin/plugin.exp
+++ b/ld/testsuite/ld-plugin/plugin.exp
@@ -85,7 +85,8 @@ 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/pr17973.s tmpdir/pr17973.o]) } {
     # Defer fail until we have list of tests set.
     set failed_compile 1
 }
@@ -174,6 +175,8 @@ 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 \
+    tmpdir/pr17973.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
-- 
1.9.3


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