Replace SYMBOLIC_BIND with SYMBOL_REFERENCES_LOCAL
authorH.J. Lu <hjl.tools@gmail.com>
Sat, 11 Apr 2015 14:34:49 +0000 (07:34 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Sat, 11 Apr 2015 14:56:48 +0000 (07:56 -0700)
When checking R_386_GOTOFF/R_X86_64_GOTOFF64 for building shared library,
we should check SYMBOL_REFERENCES_LOCAL instead of SYMBOLIC_BIND to cover
more cases.

bfd/

* elf32-i386.c (elf_i386_relocate_section): Replace SYMBOLIC_BIND
with SYMBOL_REFERENCES_LOCAL when checking R_386_GOTOFF against
protected data symbol when building shared library.
* elf64-x86-64.c (elf_x86_64_relocate_section): Check
R_X86_64_GOTOFF64 against undefined symbol and replace
SYMBOLIC_BIND with SYMBOL_REFERENCES_LOCAL when checking
R_X86_64_GOTOFF64 against protected data symbol when building
shared library.

ld/testsuite/

* ld-i386/i386.exp: Run protected6a.
* ld-i386/protected6.d: Renamed to ...
* ld-i386/protected6a.d: This.
* ld-x86-64/hidden4.d: New file.
* ld-x86-64/hidden4.s: Likewise.
* ld-x86-64/hidden5.d: Likewise.
* ld-x86-64/hidden5.s: Likewise.
* ld-x86-64/protected6.d: Renamed to ...
* ld-x86-64/protected6a.d: This.
* ld-x86-64/x86-64.exp: Run hidden4, hidden5, protected6a,
protected7a and protected7b.

14 files changed:
bfd/ChangeLog
bfd/elf32-i386.c
bfd/elf64-x86-64.c
ld/testsuite/ChangeLog
ld/testsuite/ld-i386/i386.exp
ld/testsuite/ld-i386/protected6.d [deleted file]
ld/testsuite/ld-i386/protected6a.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/hidden4.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/hidden4.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/hidden5.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/hidden5.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/protected6.d [deleted file]
ld/testsuite/ld-x86-64/protected6a.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/x86-64.exp

index ea3543552ad23aa02d7722a94a2e984efd806163..207884a1cd705cb9e21ef1e414e1b47d814e6ed5 100644 (file)
@@ -1,3 +1,14 @@
+2015-04-11  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * elf32-i386.c (elf_i386_relocate_section): Replace SYMBOLIC_BIND
+       with SYMBOL_REFERENCES_LOCAL when checking R_386_GOTOFF against
+       protected data symbol when building shared library.
+       * elf64-x86-64.c (elf_x86_64_relocate_section): Check
+       R_X86_64_GOTOFF64 against undefined symbol and replace
+       SYMBOLIC_BIND with SYMBOL_REFERENCES_LOCAL when checking
+       R_X86_64_GOTOFF64 against protected data symbol when building
+       shared library.
+
 2015-04-10  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/pr17709
index af16da357dd057f0b092cc7fc854939435c37e96..f71bce122438a7331825eea8235638f69576c8ea 100644 (file)
@@ -3717,7 +3717,7 @@ elf_i386_relocate_section (bfd *output_bfd,
          /* Check to make sure it isn't a protected function or data
             symbol for shared library since it may not be local when
             used as function address or with copy relocation.  We also
-            need to make sure that a symbol is defined locally.  */
+            need to make sure that a symbol is referenced locally.  */
          if (info->shared && h)
            {
              if (!h->def_regular)
@@ -3747,7 +3747,7 @@ elf_i386_relocate_section (bfd *output_bfd,
                  return FALSE;
                }
              else if (!info->executable
-                      && !SYMBOLIC_BIND (info, h)
+                      && !SYMBOL_REFERENCES_LOCAL (info, h)
                       && (h->type == STT_FUNC
                           || h->type == STT_OBJECT)
                       && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
index 2b37c270f8f7064191b0c71b24f86cf4c57b46a9..a3604c7eba5c44be944c68411671d1df1864cdb2 100644 (file)
@@ -3957,22 +3957,50 @@ elf_x86_64_relocate_section (bfd *output_bfd,
 
          /* Check to make sure it isn't a protected function or data
             symbol for shared library since it may not be local when
-            used as function address or with copy relocation.  */
-         if (!info->executable
-             && h
-             && !SYMBOLIC_BIND (info, h)
-             && h->def_regular
-             && (h->type == STT_FUNC
-                 || h->type == STT_OBJECT)
-             && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
+            used as function address or with copy relocation.  We also
+            need to make sure that a symbol is referenced locally.  */
+         if (info->shared && h)
            {
-             (*_bfd_error_handler)
-               (_("%B: relocation R_X86_64_GOTOFF64 against protected %s `%s' can not be used when making a shared object"),
-                input_bfd,
-                h->type == STT_FUNC ? "function" : "data",
-                h->root.root.string);
-             bfd_set_error (bfd_error_bad_value);
+             if (!h->def_regular)
+               {
+                 const char *v;
+
+                 switch (ELF_ST_VISIBILITY (h->other))
+                   {
+                   case STV_HIDDEN:
+                     v = _("hidden symbol");
+                     break;
+                   case STV_INTERNAL:
+                     v = _("internal symbol");
+                     break;
+                   case STV_PROTECTED:
+                     v = _("protected symbol");
+                     break;
+                   default:
+                     v = _("symbol");
+                     break;
+                   }
+
+                 (*_bfd_error_handler)
+                   (_("%B: relocation R_X86_64_GOTOFF64 against undefined %s `%s' can not be used when making a shared object"),
+                    input_bfd, v, h->root.root.string);
+                 bfd_set_error (bfd_error_bad_value);
+                 return FALSE;
+               }
+             else if (!info->executable
+                      && !SYMBOL_REFERENCES_LOCAL (info, h)
+                      && (h->type == STT_FUNC
+                          || h->type == STT_OBJECT)
+                      && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
+               {
+                 (*_bfd_error_handler)
+                   (_("%B: relocation R_X86_64_GOTOFF64 against protected %s `%s' can not be used when making a shared object"),
+                    input_bfd,
+                    h->type == STT_FUNC ? "function" : "data",
+                    h->root.root.string);
+                 bfd_set_error (bfd_error_bad_value);
              return FALSE;
+               }
            }
 
          /* Note that sgot is not involved in this
index c4bc387a5635141e3a73ad6fbd1f03ae608c2de2..8b45279b0e87d1076f8be4b524398c717f5cae46 100644 (file)
@@ -1,3 +1,17 @@
+2015-04-11  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * ld-i386/i386.exp: Run protected6a.
+       * ld-i386/protected6.d: Renamed to ...
+       * ld-i386/protected6a.d: This.
+       * ld-x86-64/hidden4.d: New file.
+       * ld-x86-64/hidden4.s: Likewise.
+       * ld-x86-64/hidden5.d: Likewise.
+       * ld-x86-64/hidden5.s: Likewise.
+       * ld-x86-64/protected6.d: Renamed to ...
+       * ld-x86-64/protected6a.d: This.
+       * ld-x86-64/x86-64.exp: Run hidden4, hidden5, protected6a,
+       protected7a and protected7b.
+
 2015-04-10  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/pr17709
index 3dd113913967ea157fd12ca2516b5c297195baa0..0c0fd96b5f79d6059d04674e907753a3f4f2afb6 100644 (file)
@@ -236,7 +236,7 @@ run_dump_test "protected2"
 run_dump_test "protected3"
 run_dump_test "protected4"
 run_dump_test "protected5"
-run_dump_test "protected6"
+run_dump_test "protected6a"
 run_dump_test "tlspie1"
 run_dump_test "tlspie2"
 run_dump_test "nogot1"
diff --git a/ld/testsuite/ld-i386/protected6.d b/ld/testsuite/ld-i386/protected6.d
deleted file mode 100644 (file)
index 37d5132..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#as: --32
-#ld: -shared -melf_i386
-#error: .*relocation R_386_GOTOFF against protected data `foo' can not be used when making a shared object
diff --git a/ld/testsuite/ld-i386/protected6a.d b/ld/testsuite/ld-i386/protected6a.d
new file mode 100644 (file)
index 0000000..7dc3504
--- /dev/null
@@ -0,0 +1,4 @@
+#source: protected6.s
+#as: --32
+#ld: -shared -melf_i386
+#error: .*relocation R_386_GOTOFF against protected data `foo' can not be used when making a shared object
diff --git a/ld/testsuite/ld-x86-64/hidden4.d b/ld/testsuite/ld-x86-64/hidden4.d
new file mode 100644 (file)
index 0000000..2f36d00
--- /dev/null
@@ -0,0 +1,3 @@
+#as: --64
+#ld: -shared -melf_x86_64
+#error: .*relocation R_X86_64_GOTOFF64 against undefined hidden symbol `foo' can not be used when making a shared object
diff --git a/ld/testsuite/ld-x86-64/hidden4.s b/ld/testsuite/ld-x86-64/hidden4.s
new file mode 100644 (file)
index 0000000..3e6a2a1
--- /dev/null
@@ -0,0 +1,8 @@
+       .text
+.globl bar
+       .type   bar, @function
+bar:
+       movabsq $foo@GOTOFF, %rax
+       .size   bar, .-bar
+       .weak   foo
+       .hidden foo
diff --git a/ld/testsuite/ld-x86-64/hidden5.d b/ld/testsuite/ld-x86-64/hidden5.d
new file mode 100644 (file)
index 0000000..2f36d00
--- /dev/null
@@ -0,0 +1,3 @@
+#as: --64
+#ld: -shared -melf_x86_64
+#error: .*relocation R_X86_64_GOTOFF64 against undefined hidden symbol `foo' can not be used when making a shared object
diff --git a/ld/testsuite/ld-x86-64/hidden5.s b/ld/testsuite/ld-x86-64/hidden5.s
new file mode 100644 (file)
index 0000000..f356076
--- /dev/null
@@ -0,0 +1,7 @@
+       .text
+.globl bar
+       .type   bar, @function
+bar:
+       movabsq $foo@GOTOFF, %rax
+       .size   bar, .-bar
+       .hidden foo
diff --git a/ld/testsuite/ld-x86-64/protected6.d b/ld/testsuite/ld-x86-64/protected6.d
deleted file mode 100644 (file)
index 872a9f6..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#as: --64
-#ld: -shared -melf_x86_64
-#error: .*relocation R_X86_64_GOTOFF64 against protected data `foo' can not be used when making a shared object
diff --git a/ld/testsuite/ld-x86-64/protected6a.d b/ld/testsuite/ld-x86-64/protected6a.d
new file mode 100644 (file)
index 0000000..3a7963f
--- /dev/null
@@ -0,0 +1,4 @@
+#source: protected6.s
+#as: --64
+#ld: -shared -melf_x86_64
+#error: .*relocation R_X86_64_GOTOFF64 against protected data `foo' can not be used when making a shared object
index 63754efdca599188dfadb8d3e1d8482fc05556b4..213a4c03bab3d4953aa8c875a7af3bd033780037 100644 (file)
@@ -211,6 +211,8 @@ run_dump_test "tlsie3"
 run_dump_test "hidden1"
 run_dump_test "hidden2"
 run_dump_test "hidden3"
+run_dump_test "hidden4"
+run_dump_test "hidden5"
 run_dump_test "protected1"
 run_dump_test "protected2"
 run_dump_test "protected2-l1om"
@@ -218,7 +220,7 @@ run_dump_test "protected3"
 run_dump_test "protected3-l1om"
 run_dump_test "protected4"
 run_dump_test "protected5"
-run_dump_test "protected6"
+run_dump_test "protected6a"
 run_dump_test "protected7a"
 run_dump_test "protected7b"
 run_dump_test "tlsle1"
This page took 0.041915 seconds and 4 git commands to generate.