• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

修訂a83ef4d139c377e0e87d105977d85c6ef9fbb162 (tree)
時間2017-11-28 20:48:44
作者H.J. Lu <hjl.tools@gmai...>
CommiterH.J. Lu

Log Message

ld: Set non_ir_ref_regular on symbols referenced in regular objects

If linker plugin is enabled, set non_ir_ref_regular on symbols referenced
in regular objects so that linker plugin will get the correct symbol
resolution.

bfd/

PR ld/22502
* elflink.c (_bfd_elf_merge_symbol): Also skip definition from
an IR object.
(elf_link_add_object_symbols): If linker plugin is enabled, set
non_ir_ref_regular on symbols referenced in regular objects so
that linker plugin will get the correct symbol resolution.

ld/

PR ld/22502
* testsuite/ld-plugin/lto.exp: Run PR ld/22502 test.
* testsuite/ld-plugin/pr22502a.c: New file.
* testsuite/ld-plugin/pr22502b.c: Likewise.

Change Summary

差異

--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,12 @@
1+2017-11-28 H.J. Lu <hongjiu.lu@intel.com>
2+
3+ PR ld/22502
4+ * elflink.c (_bfd_elf_merge_symbol): Also skip definition from
5+ an IR object.
6+ (elf_link_add_object_symbols): If linker plugin is enabled, set
7+ non_ir_ref_regular on symbols referenced in regular objects so
8+ that linker plugin will get the correct symbol resolution.
9+
110 2017-11-27 Szabolcs Nagy <szabolcs.nagy@arm.com>
211
312 PR ld/22263
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -1555,10 +1555,13 @@ _bfd_elf_merge_symbol (bfd *abfd,
15551555 sec = *psec;
15561556 }
15571557
1558- /* There are multiple definitions of a normal symbol.
1559- Skip the default symbol as well. */
1558+ /* There are multiple definitions of a normal symbol. Skip the
1559+ default symbol as well as definition from an IR object. */
15601560 if (olddef && !olddyn && !oldweak && newdef && !newdyn && !newweak
1561- && !default_sym && h->def_regular)
1561+ && !default_sym && h->def_regular
1562+ && !(oldbfd != NULL
1563+ && (oldbfd->flags & BFD_PLUGIN) != 0
1564+ && (abfd->flags & BFD_PLUGIN) == 0))
15621565 {
15631566 /* Handle a multiple definition. */
15641567 (*info->callbacks->multiple_definition) (info, &h->root,
@@ -4931,6 +4934,65 @@ error_free_dyn:
49314934 }
49324935 }
49334936
4937+ if (info->lto_plugin_active
4938+ && !bfd_link_relocatable (info)
4939+ && (abfd->flags & BFD_PLUGIN) == 0
4940+ && !just_syms
4941+ && extsymcount)
4942+ {
4943+ int r_sym_shift;
4944+
4945+ if (bed->s->arch_size == 32)
4946+ r_sym_shift = 8;
4947+ else
4948+ r_sym_shift = 32;
4949+
4950+ /* If linker plugin is enabled, set non_ir_ref_regular on symbols
4951+ referenced in regular objects so that linker plugin will get
4952+ the correct symbol resolution. */
4953+
4954+ sym_hash = elf_sym_hashes (abfd);
4955+ for (s = abfd->sections; s != NULL; s = s->next)
4956+ {
4957+ Elf_Internal_Rela *internal_relocs;
4958+ Elf_Internal_Rela *rel, *relend;
4959+
4960+ /* Don't check relocations in excluded sections. */
4961+ if ((s->flags & SEC_RELOC) == 0
4962+ || s->reloc_count == 0
4963+ || (s->flags & SEC_EXCLUDE) != 0
4964+ || ((info->strip == strip_all
4965+ || info->strip == strip_debugger)
4966+ && (s->flags & SEC_DEBUGGING) != 0))
4967+ continue;
4968+
4969+ internal_relocs = _bfd_elf_link_read_relocs (abfd, s, NULL,
4970+ NULL,
4971+ info->keep_memory);
4972+ if (internal_relocs == NULL)
4973+ goto error_free_vers;
4974+
4975+ rel = internal_relocs;
4976+ relend = rel + s->reloc_count;
4977+ for ( ; rel < relend; rel++)
4978+ {
4979+ unsigned long r_symndx = rel->r_info >> r_sym_shift;
4980+ struct elf_link_hash_entry *h;
4981+
4982+ /* Skip local symbols. */
4983+ if (r_symndx < extsymoff)
4984+ continue;
4985+
4986+ h = sym_hash[r_symndx - extsymoff];
4987+ if (h != NULL)
4988+ h->root.non_ir_ref_regular = 1;
4989+ }
4990+
4991+ if (elf_section_data (s)->relocs != internal_relocs)
4992+ free (internal_relocs);
4993+ }
4994+ }
4995+
49344996 if (extversym != NULL)
49354997 {
49364998 free (extversym);
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,10 @@
1+2017-11-28 H.J. Lu <hongjiu.lu@intel.com>
2+
3+ PR ld/22502
4+ * testsuite/ld-plugin/lto.exp: Run PR ld/22502 test.
5+ * testsuite/ld-plugin/pr22502a.c: New file.
6+ * testsuite/ld-plugin/pr22502b.c: Likewise.
7+
18 2017-11-24 H.J. Lu <hongjiu.lu@intel.com>
29
310 * testsuite/ld-elf/pr21562c.t: Also provide ___start_scnfoo and
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -208,6 +208,12 @@ set lto_link_tests [list \
208208 "-flto -Wl,-plugin,$plug_so" "-flto" \
209209 {pr20321.c} {{warning ".*: duplicated plugin"}} \
210210 "pr20321" "c"] \
211+ [list "Build pr22502a.o" \
212+ "" "" \
213+ {pr22502a.c}] \
214+ [list "Build pr22502b.o" \
215+ "$plug_opt" "-flto $lto_no_fat" \
216+ {pr22502b.c}] \
211217 ]
212218
213219 if { [at_least_gcc_version 4 7] } {
@@ -391,6 +397,9 @@ set lto_run_tests [list \
391397 [list "Run pr20267b" \
392398 "-O2 -flto tmpdir/pr20267a.o tmpdir/libpr20267b.a" "" \
393399 {dummy.c} "pr20267b" "pass.out" "-flto -O2" "c"] \
400+ [list "Run pr22502" \
401+ "-O2 -flto tmpdir/pr22502a.o tmpdir/pr22502b.o" "" \
402+ {dummy.c} "pr20267" "pass.out" "-flto -O2" "c"] \
394403 ]
395404
396405 if { [at_least_gcc_version 4 7] } {
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr22502a.c
@@ -0,0 +1,16 @@
1+#include <stdio.h>
2+
3+volatile int x;
4+extern void abort ();
5+
6+__attribute__((weak))
7+void foobar (void) { x++; }
8+
9+int main (void)
10+{
11+ foobar ();
12+ if (x != -1)
13+ abort ();
14+ printf ("PASS\n");
15+ return 0;
16+}
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr22502b.c
@@ -0,0 +1,3 @@
1+extern volatile int x;
2+
3+void foobar (void) { x--; }