]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix possible failure in the AVR linker tests.
authorSenthil Kumar Selvaraj <senthil_kumar.selvaraj@atmel.com>
Fri, 18 Mar 2016 09:51:47 +0000 (09:51 +0000)
committerNick Clifton <nickc@redhat.com>
Fri, 18 Mar 2016 09:51:47 +0000 (09:51 +0000)
* ld-avr/gc-section-debugline.d: Relax regex check for CU.

ld/ChangeLog
ld/emultempl/pe.em
ld/ldlang.c
ld/pe-dll.c
ld/testsuite/ld-avr/gc-section-debugline.d
ld/testsuite/ld-pe/pe.exp
ld/testsuite/ld-pe/pr19803.d [new file with mode: 0644]
ld/testsuite/ld-pe/pr19803.e [new file with mode: 0644]
ld/testsuite/ld-pe/pr19803.s [new file with mode: 0644]

index 04b484cc4eda5bb37b0f3371a4965708009ffc2e..401226bc54b11e306213159c6fd814654f2f3837 100644 (file)
@@ -1,3 +1,7 @@
+2016-03-18  Senthil Kumar Selvaraj  <senthil_kumar.selvaraj@atmel.com>
+
+       * ld-avr/gc-section-debugline.d: Relax regex check for CU.
+
 2016-03-15  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/19827
index 2b78536df8996bc387c34c55c948b74224e7d8c9..bf146f69a9c20aaad4e6737527c97e0f95b58724 100644 (file)
@@ -563,7 +563,6 @@ set_entry_point (void)
     }
   else
     {
-
       for (i = 0; v[i].entry; i++)
         if (v[i].value == pe_subsystem)
           break;
index 7b74e2483f61489759e8142544010634faf21497..e6cc4244da8e0f1f3eda4efe7e352bcbbf2e4b9e 100644 (file)
@@ -6477,7 +6477,6 @@ static void
 lang_gc_sections (void)
 {
   /* Keep all sections so marked in the link script.  */
-
   lang_gc_sections_1 (statement_list.head);
 
   /* SEC_EXCLUDE is ignored when doing a relocatable link, except in
@@ -6783,9 +6782,30 @@ lang_process (void)
 #endif /* ENABLE_PLUGINS */
 
   link_info.gc_sym_list = &entry_symbol;
+
   if (entry_symbol.name == NULL)
-    link_info.gc_sym_list = ldlang_undef_chain_list_head;
-  if (link_info.init_function != NULL)
+    {
+      link_info.gc_sym_list = ldlang_undef_chain_list_head;
+
+      /* entry_symbol is normally initialied by a ENTRY definition in the
+        linker script or the -e command line option.  But if neither of
+        these have been used, the target specific backend may still have
+        provided an entry symbol via a call to lang_default_entry()o.
+        Unfortunately this value will not be processed until lang_end()
+        is called, long after this function has finished.  So detect this
+        case here and add the target's entry symbol to the list of starting
+        points for garbage collection resolution.  */
+      if (entry_symbol_default != NULL)
+       {
+         struct bfd_sym_chain *sym
+           = (struct bfd_sym_chain *) stat_alloc (sizeof (*sym));
+         sym->next = link_info.gc_sym_list;
+         sym->name = entry_symbol_default;
+         link_info.gc_sym_list = sym;
+       }
+    }
+
+ if (link_info.init_function != NULL)
     {
       struct bfd_sym_chain *sym
        = (struct bfd_sym_chain *) stat_alloc (sizeof (*sym));
index 14f963b27456e94ddf9e7da8a5284f1420971c1d..ccdbed0d23a8c550a7ad0a95897739ec463e2c25 100644 (file)
@@ -895,6 +895,7 @@ process_def_file_and_drectve (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *
   for (i = 0; i < NE; i++)
     {
       char *name;
+
       name = xmalloc (strlen (pe_def_file->exports[i].internal_name) + 2);
       if (pe_details->underscored
          && (*pe_def_file->exports[i].internal_name != '@'))
@@ -2790,7 +2791,44 @@ pe_dll_generate_implib (def_file *def, const char *impfilename, struct bfd_link_
       /* Don't add PRIVATE entries to import lib.  */
       if (pe_def_file->exports[i].flag_private)
        continue;
+
       def->exports[i].internal_name = def->exports[i].name;
+
+      /* PR 19803: If a symbol has been discard due to garbage
+        collection then do not create any exports for it.  */
+      {
+       struct coff_link_hash_entry *h;
+
+       h = coff_link_hash_lookup (coff_hash_table (info), internal,
+                                  FALSE, FALSE, FALSE);
+       if (h != NULL
+           /* If the symbol is hidden and undefined then it
+              has been swept up by garbage collection.  */
+           && h->symbol_class == C_HIDDEN
+           && h->root.u.def.section == bfd_und_section_ptr)
+         continue;
+
+       /* If necessary, check with an underscore prefix as well.  */
+       if (pe_details->underscored && internal[0] != '@')
+         {
+           char *name;
+
+           name = xmalloc (strlen (internal) + 2);
+           sprintf (name, "_%s", internal);
+
+           h = coff_link_hash_lookup (coff_hash_table (info), name,
+                                      FALSE, FALSE, FALSE);
+           free (name);
+
+           if (h != NULL
+               /* If the symbol is hidden and undefined then it
+                  has been swept up by garbage collection.  */
+               && h->symbol_class == C_HIDDEN
+               && h->root.u.def.section == bfd_und_section_ptr)
+             continue;
+         }
+      }
+
       n = make_one (def->exports + i, outarch,
                    ! (def->exports + i)->flag_data);
       n->archive_next = head;
index e98ff6c0cfac9896c67f477559d88f681c5f1cec..f8c07de6a4aa39e940055176f97b2865c1de12a8 100644 (file)
@@ -9,7 +9,7 @@
 
 Decoded dump of debug contents of section .debug_line:
 
-CU: .*:
+.*:
 File name                            Line number    Starting address
 per-function-debugline.s                      39                   0
 
index 622caed2dabb8c811906565ac3a44cdff95cc46b..a31f6e7fd74e1e622d019a33b3e5f82000cc212d 100644 (file)
@@ -76,6 +76,20 @@ run_dump_test "longsecn-5"
 run_dump_test "orphan"
 run_dump_test "orphan_nu"
 
+run_dump_test "pr19803"
+set pr19803_dll {
+    {   "PR 19803: not exporting swept symbols"
+       "-shared --out-implib dx.dll --gc-sections"
+       "" "" {pr19803.s}
+       {{objdump "--syms dx.dll" pr19803.e}}
+       "a.exe"}
+}
+# This test is *supposed* to fail.  If the symbol defined in pr19803.e is
+# found then it was not stripped from the export dll, despite the fact that
+# it (should have been) garbage collected from the executable.
+setup_xfail *-*-*
+run_ld_link_tests $pr19803_dll
+
 if {[istarget x86_64-*-mingw*] } {
        run_dump_test "cfi"
 } elseif {[istarget i*86-*-cygwin*] || [istarget i*86-*-mingw*] } {
diff --git a/ld/testsuite/ld-pe/pr19803.d b/ld/testsuite/ld-pe/pr19803.d
new file mode 100644 (file)
index 0000000..1fc6daf
--- /dev/null
@@ -0,0 +1,17 @@
+#ld: -shared --out-implib dx.dll.a --gc-sections
+#objdump: --syms
+#notarget: mcore-* arm-epoc-pe
+#
+# Check that the target specific entry symbol _DllMainCRTStartup is still
+# a defined (sec > 0), public (scl == 2) symbol, even after garbage
+# collection.
+#
+# Check that the symbol _testval is undefined (sec == 0) and hidden
+# (scl == 106) in the output.  It should have been changed to this state when
+# garbage collection was performed.
+
+#...
+.*\(sec  0\)\(fl 0x00\)\(ty   0\)\(scl 106\) \(nx 0\) 0x0+000 _testval
+#...
+.*\(sec  1\)\(fl 0x00\)\(ty   0\)\(scl   2\) \(nx 0\) 0x0+000 .*Startup.*
+#pass
diff --git a/ld/testsuite/ld-pe/pr19803.e b/ld/testsuite/ld-pe/pr19803.e
new file mode 100644 (file)
index 0000000..a2f8162
--- /dev/null
@@ -0,0 +1,3 @@
+#...
+.*__imp__testval
+#pass
diff --git a/ld/testsuite/ld-pe/pr19803.s b/ld/testsuite/ld-pe/pr19803.s
new file mode 100644 (file)
index 0000000..290a698
--- /dev/null
@@ -0,0 +1,14 @@
+       .text
+        .globl  "_DllMainCRTStartup@12"
+"_DllMainCRTStartup@12":
+        .globl  _DllMainCRTStartup
+_DllMainCRTStartup:
+        .globl  DllMainCRTStartup
+DllMainCRTStartup:
+       nop
+
+       .section .rdata,"dr"
+        .globl  _testval
+_testval:
+        .long   1
+        .long   2