GNU Binutils with patches for OS216
修訂 | a83ef4d139c377e0e87d105977d85c6ef9fbb162 (tree) |
---|---|
時間 | 2017-11-28 20:48:44 |
作者 | H.J. Lu <hjl.tools@gmai...> |
Commiter | H.J. Lu |
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.
@@ -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 | + | |
1 | 10 | 2017-11-27 Szabolcs Nagy <szabolcs.nagy@arm.com> |
2 | 11 | |
3 | 12 | PR ld/22263 |
@@ -1555,10 +1555,13 @@ _bfd_elf_merge_symbol (bfd *abfd, | ||
1555 | 1555 | sec = *psec; |
1556 | 1556 | } |
1557 | 1557 | |
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. */ | |
1560 | 1560 | 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)) | |
1562 | 1565 | { |
1563 | 1566 | /* Handle a multiple definition. */ |
1564 | 1567 | (*info->callbacks->multiple_definition) (info, &h->root, |
@@ -4931,6 +4934,65 @@ error_free_dyn: | ||
4931 | 4934 | } |
4932 | 4935 | } |
4933 | 4936 | |
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 | + | |
4934 | 4996 | if (extversym != NULL) |
4935 | 4997 | { |
4936 | 4998 | free (extversym); |
@@ -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 | + | |
1 | 8 | 2017-11-24 H.J. Lu <hongjiu.lu@intel.com> |
2 | 9 | |
3 | 10 | * testsuite/ld-elf/pr21562c.t: Also provide ___start_scnfoo and |
@@ -208,6 +208,12 @@ set lto_link_tests [list \ | ||
208 | 208 | "-flto -Wl,-plugin,$plug_so" "-flto" \ |
209 | 209 | {pr20321.c} {{warning ".*: duplicated plugin"}} \ |
210 | 210 | "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}] \ | |
211 | 217 | ] |
212 | 218 | |
213 | 219 | if { [at_least_gcc_version 4 7] } { |
@@ -391,6 +397,9 @@ set lto_run_tests [list \ | ||
391 | 397 | [list "Run pr20267b" \ |
392 | 398 | "-O2 -flto tmpdir/pr20267a.o tmpdir/libpr20267b.a" "" \ |
393 | 399 | {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"] \ | |
394 | 403 | ] |
395 | 404 | |
396 | 405 | if { [at_least_gcc_version 4 7] } { |
@@ -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 | +} |
@@ -0,0 +1,3 @@ | ||
1 | +extern volatile int x; | |
2 | + | |
3 | +void foobar (void) { x--; } |