GNU Binutils with patches for OS216
Revisão | 5376d47f66d0e4e07b3d42cb62ad07327cad4292 (tree) |
---|---|
Hora | 2020-06-24 19:56:16 |
Autor | H.J. Lu <hjl.tools@gmai...> |
Commiter | H.J. Lu |
ld: Set non_ir_ref_regular on source for assignment
We need to set non_ir_ref_regular on the source for assignment to get
the correct LTO resolution:
190 a27be7f4ad90c5ce PREVAILING_DEF real_g
instead of
190 30c3b2d8f967f5ea PREVAILING_DEF_IRONLY real_g
PR ld/26163
* ldexp.c (exp_fold_tree_1): Set non_ir_ref_regular on the source
for assignment.
* testsuite/ld-plugin/lto.exp: Run ld/26163 test.
* testsuite/ld-plugin/pr26163a.c: New file.
* testsuite/ld-plugin/pr26163b.c: Likewise.
@@ -1,3 +1,12 @@ | ||
1 | +2020-06-24 H.J. Lu <hongjiu.lu@intel.com> | |
2 | + | |
3 | + PR ld/26163 | |
4 | + * ldexp.c (exp_fold_tree_1): Set non_ir_ref_regular on the source | |
5 | + for assignment. | |
6 | + * testsuite/ld-plugin/lto.exp: Run ld/26163 test. | |
7 | + * testsuite/ld-plugin/pr26163a.c: New file. | |
8 | + * testsuite/ld-plugin/pr26163b.c: Likewise. | |
9 | + | |
1 | 10 | 2020-06-24 Alan Modra <amodra@gmail.com> |
2 | 11 | |
3 | 12 | * lexsup.c (elf_shlib_list_options): Properly format help message. |
@@ -1217,15 +1217,19 @@ exp_fold_tree_1 (etree_type *tree) | ||
1217 | 1217 | bfd_link_hide_symbol (link_info.output_bfd, |
1218 | 1218 | &link_info, h); |
1219 | 1219 | |
1220 | - /* Copy the symbol type if this is an expression only | |
1220 | + /* Copy the symbol type and set non_ir_ref_regular | |
1221 | + on the source if this is an expression only | |
1221 | 1222 | referencing a single symbol. (If the expression |
1222 | 1223 | contains ternary conditions, ignoring symbols on |
1223 | 1224 | false branches.) */ |
1224 | 1225 | if (expld.assign_src != NULL |
1225 | 1226 | && (expld.assign_src |
1226 | 1227 | != (struct bfd_link_hash_entry *) -1)) |
1227 | - bfd_copy_link_hash_symbol_type (link_info.output_bfd, | |
1228 | - h, expld.assign_src); | |
1228 | + { | |
1229 | + bfd_copy_link_hash_symbol_type (link_info.output_bfd, | |
1230 | + h, expld.assign_src); | |
1231 | + expld.assign_src->non_ir_ref_regular = TRUE; | |
1232 | + } | |
1229 | 1233 | } |
1230 | 1234 | } |
1231 | 1235 | } |
@@ -207,6 +207,9 @@ set lto_link_tests [list \ | ||
207 | 207 | [list "Build pr24406-2b.o" \ |
208 | 208 | "" "-O2 -fno-lto" \ |
209 | 209 | {pr24406-2b.c}] \ |
210 | + [list "Build pr26163a.o" \ | |
211 | + "" "-O2 -fno-lto" \ | |
212 | + {pr26163a.c}] \ | |
210 | 213 | ] |
211 | 214 | |
212 | 215 | if { [at_least_gcc_version 10 0] } { |
@@ -502,6 +505,11 @@ set lto_run_tests [list \ | ||
502 | 505 | {pr24406-2a.c} "pr24406-2" "pass.out" \ |
503 | 506 | "-flto -O2" "c" "" \ |
504 | 507 | "tmpdir/pr24406-2b.o -Wl,--wrap=cook"] \ |
508 | + [list "Run pr26163" \ | |
509 | + "-O2 -flto" "" \ | |
510 | + {pr26163b.c} "pr24406-2" "pass.out" \ | |
511 | + "-flto -O2" "c" "" \ | |
512 | + "tmpdir/pr26163a.o -Wl,--defsym,g=real_g"] \ | |
505 | 513 | ] |
506 | 514 | |
507 | 515 | if { [at_least_gcc_version 4 7] } { |
@@ -0,0 +1,9 @@ | ||
1 | +extern int counter; | |
2 | + | |
3 | +extern void g(void); | |
4 | + | |
5 | +void f(void) | |
6 | +{ | |
7 | + g(); | |
8 | + counter++; | |
9 | +} |
@@ -0,0 +1,19 @@ | ||
1 | +#include <stdio.h> | |
2 | + | |
3 | +int counter; | |
4 | +extern void f(void); | |
5 | + | |
6 | +void | |
7 | +real_g(void) | |
8 | +{ | |
9 | + counter++; | |
10 | +} | |
11 | + | |
12 | +int main() | |
13 | +{ | |
14 | + real_g(); | |
15 | + f(); | |
16 | + if (counter == 3) | |
17 | + printf ("PASS\n"); | |
18 | + return 0; | |
19 | +} |