]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Set non_ir_ref_dynamic if a symbol is made dynamic
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 20 Mar 2018 10:51:26 +0000 (03:51 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 20 Mar 2018 11:18:53 +0000 (04:18 -0700)
If a symbol is made dynamic by --dynamic-list, it has non-IR reference.

bfd/

PR ld/22983
* elflink.c (bfd_elf_link_mark_dynamic_symbol): Set
non_ir_ref_dynamic if a symbol is made dynamic by --dynamic-list.

ld/

PR ld/22983
* testsuite/ld-plugin/lto.exp: Run PR ld/22983 test.
* testsuite/ld-plugin/pr22983.d: New file.
* testsuite/ld-plugin/pr22983.t: Likewise.
* testsuite/ld-plugin/pr22983a.c: Likewise.
* testsuite/ld-plugin/pr22983b.c: Likewise.

(cherry picked from commit 416c34d683f2a17aefe19afb466af4316c7c603b)

bfd/ChangeLog
bfd/elflink.c
ld/ChangeLog
ld/testsuite/ld-plugin/lto.exp
ld/testsuite/ld-plugin/pr22983.d [new file with mode: 0644]
ld/testsuite/ld-plugin/pr22983.t [new file with mode: 0644]
ld/testsuite/ld-plugin/pr22983a.c [new file with mode: 0644]
ld/testsuite/ld-plugin/pr22983b.c [new file with mode: 0644]

index 13ccbc5eb0bc7714a911e384d18641bc8a098a80..74d76dce05b58a6dd7a72cd5a581a2fe8afdd089 100644 (file)
@@ -1,3 +1,12 @@
+2018-03-20  H.J. Lu  <hongjiu.lu@intel.com>
+
+       Backport from master branch
+       2018-03-20  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/22983
+       * elflink.c (bfd_elf_link_mark_dynamic_symbol): Set
+       non_ir_ref_dynamic if a symbol is made dynamic by --dynamic-list.
+
 2018-03-19  H.J. Lu  <hongjiu.lu@intel.com>
 
        Backport from master branch
index 69cb5abbac3eb0174c51fb10248c9215064b08e4..6bb4e98ae67ffed7660fd1fd78b960948c889d5b 100644 (file)
@@ -586,7 +586,12 @@ bfd_elf_link_mark_dynamic_symbol (struct bfd_link_info *info,
       || (d != NULL
          && h->non_elf
          && (*d->match) (&d->head, NULL, h->root.root.string)))
-    h->dynamic = 1;
+    {
+      h->dynamic = 1;
+      /* NB: If a symbol is made dynamic by --dynamic-list, it has
+        non-IR reference.  */
+      h->root.non_ir_ref_dynamic = 1;
+    }
 }
 
 /* Record an assignment to a symbol made by a linker script.  We need
index 6cea82b6adbe3155b8f4a46afc144bb1305eaa55..b266e2433fe3e9a5df2b721156c7a5c50b34b08d 100644 (file)
@@ -1,3 +1,15 @@
+2018-03-20  H.J. Lu  <hongjiu.lu@intel.com>
+
+       Backport from master branch
+       2018-03-20  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/22983
+       * testsuite/ld-plugin/lto.exp: Run PR ld/22983 test.
+       * testsuite/ld-plugin/pr22983.d: New file.
+       * testsuite/ld-plugin/pr22983.t: Likewise.
+       * testsuite/ld-plugin/pr22983a.c: Likewise.
+       * testsuite/ld-plugin/pr22983b.c: Likewise.
+
 2018-03-19  H.J. Lu  <hongjiu.lu@intel.com>
 
        Backport from master branch
index 896f453def1d7787cb9a171a8b452002f8f12cf8..4bd2ada0ea7c96f5538d84e48b5148edc2c5a8d5 100644 (file)
@@ -564,6 +564,16 @@ run_ld_link_exec_tests $lto_run_tests
 
 if { [is_elf_format] } {
     run_ld_link_exec_tests $lto_run_elf_tests
+    run_cc_link_tests [list \
+       [list \
+           "Build pr22983" \
+           "-Wl,--dynamic-list,pr22983.t" \
+           "-flto" \
+           {pr22983a.c pr22983b.c} \
+           {{readelf {--dyn-syms --wide} pr22983.d}} \
+           "pr22983" \
+       ] \
+    ]
 }
 
 if { [is_elf_format] && [check_lto_shared_available] } {
diff --git a/ld/testsuite/ld-plugin/pr22983.d b/ld/testsuite/ld-plugin/pr22983.d
new file mode 100644 (file)
index 0000000..af1d710
--- /dev/null
@@ -0,0 +1,9 @@
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +[0-9a-f]+ +[0-9a-f]+ +OBJECT +GLOBAL +DEFAULT +[0-9]+ +var_attr_used_enabled
+ +[0-9]+: +[0-9a-f]+ +[0-9a-f]+ +OBJECT +GLOBAL +DEFAULT +[0-9]+ +var_attr_used_disabled
+#...
+ +[0-9]+: +[0-9a-f]+ +[0-9a-f]+ +FUNC +GLOBAL +DEFAULT +[0-9]+ +func_attr_used_enabled
+ +[0-9]+: +[0-9a-f]+ +[0-9a-f]+ +FUNC +GLOBAL +DEFAULT +[0-9]+ +func_attr_used_disabled
+#...
diff --git a/ld/testsuite/ld-plugin/pr22983.t b/ld/testsuite/ld-plugin/pr22983.t
new file mode 100644 (file)
index 0000000..ca31f10
--- /dev/null
@@ -0,0 +1,6 @@
+{
+var_attr_used_disabled;
+var_attr_used_enabled;
+func_attr_used_disabled;
+func_attr_used_enabled;
+};
diff --git a/ld/testsuite/ld-plugin/pr22983a.c b/ld/testsuite/ld-plugin/pr22983a.c
new file mode 100644 (file)
index 0000000..283f263
--- /dev/null
@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+int func_attr_used_disabled(int val);
+int func_attr_used_enabled(int val);
+extern int var_attr_used_enabled;
+extern int var_attr_used_disabled;
+
+int main(int argc, const char **argv){
+       printf("%d\n", var_attr_used_disabled);
+       printf("%d\n", var_attr_used_enabled);
+       printf("%d\n", func_attr_used_disabled(1));
+       printf("%d\n", func_attr_used_enabled(1));
+       return 0;
+}
diff --git a/ld/testsuite/ld-plugin/pr22983b.c b/ld/testsuite/ld-plugin/pr22983b.c
new file mode 100644 (file)
index 0000000..1b66ed8
--- /dev/null
@@ -0,0 +1,10 @@
+int func_attr_used_disabled(int val){
+       return val + 1;
+}
+__attribute__((used))
+int func_attr_used_enabled(int val){
+       return val + 1;
+}
+__attribute__((used))
+int var_attr_used_enabled = 0b0101010101;
+int var_attr_used_disabled = 0b0101010101;