This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] PR gold/21452: Enable safe ICF for shared object on x86-64


With

commit 4aebb6312eb5dcd12f2f8420028547584b708907
Author: Rahul Chaudhry <rahulchaudhry@google.com>
Date:   Wed Feb 15 00:37:10 2017 -0800

    Improved support for --icf=safe when used with -pie.

we now check opcode with R_X86_64_PC32 relocation, which tell branches
from other instructions.  We can enable safe ICF for shared object on
x86-64.  Also, global symbols with non-default visibility should be
folded like local symbols.

OK for master?

H.J.
---
	PR gold/21452
	* x86_64.cc (Scan::local_reloc_may_be_function_pointer): Remove
	check for shared library.
	(Scan::global_reloc_may_be_function_pointer): Remove check for
	shared library and symbol visibility.
	* testsuite/icf_safe_so_test.cc (bar_static): New function.
	(main): Take function address of bar_static and use it.
	* testsuite/icf_safe_so_test.sh (arch_specific_safe_fold): Also
	check fold on x86-64.  Check bar_static isn't folded.
---
 gold/testsuite/icf_safe_so_test.cc |  8 ++++++++
 gold/testsuite/icf_safe_so_test.sh |  3 ++-
 gold/x86_64.cc                     | 16 +---------------
 3 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/gold/testsuite/icf_safe_so_test.cc b/gold/testsuite/icf_safe_so_test.cc
index 21aedef..409b72a 100644
--- a/gold/testsuite/icf_safe_so_test.cc
+++ b/gold/testsuite/icf_safe_so_test.cc
@@ -61,10 +61,18 @@ int bar_glob()
   return 2;
 }
 
+static int
+bar_static()
+{
+  return 2;
+}
+
 int main()
 {
   int (*p)() = foo_glob;
   (void)p;
+  p = bar_static;
+  (void)p;
   foo_static();
   foo_prot();
   foo_hidden();
diff --git a/gold/testsuite/icf_safe_so_test.sh b/gold/testsuite/icf_safe_so_test.sh
index bf13d38..ae25219 100755
--- a/gold/testsuite/icf_safe_so_test.sh
+++ b/gold/testsuite/icf_safe_so_test.sh
@@ -88,7 +88,7 @@ END {
 
 arch_specific_safe_fold()
 {
-    if grep -q -e "Intel 80386" -e "ARM" -e "PowerPC" $1;
+    if grep -q -e "Advanced Micro Devices X86-64" -e "Intel 80386" -e "ARM" -e "PowerPC" $1;
     then
       check_fold $2 $4 $5 $3
     else
@@ -103,3 +103,4 @@ arch_specific_safe_fold icf_safe_so_test_2.stdout icf_safe_so_test_1.stdout icf_
 arch_specific_safe_fold icf_safe_so_test_2.stdout icf_safe_so_test_1.stdout icf_safe_so_test.map "foo_hidden" "foo_static"
 arch_specific_safe_fold icf_safe_so_test_2.stdout icf_safe_so_test_1.stdout icf_safe_so_test.map "foo_internal" "foo_static"
 check_nofold icf_safe_so_test_1.stdout "foo_glob" "bar_glob"
+check_nofold icf_safe_so_test_1.stdout "bar_static" "bar_glob"
diff --git a/gold/x86_64.cc b/gold/x86_64.cc
index 7f1742d..c15208c 100644
--- a/gold/x86_64.cc
+++ b/gold/x86_64.cc
@@ -3362,12 +3362,6 @@ Target_x86_64<size>::Scan::local_reloc_may_be_function_pointer(
   unsigned int r_type,
   const elfcpp::Sym<size, false>&)
 {
-  // When building a shared library, do not fold any local symbols as it is
-  // not possible to distinguish pointer taken versus a call by looking at
-  // the relocation types.
-  if (parameters->options().shared())
-    return true;
-
   return possible_function_pointer_reloc(src_obj, src_indx,
                                          reloc.get_r_offset(), r_type);
 }
@@ -3387,16 +3381,8 @@ Target_x86_64<size>::Scan::global_reloc_may_be_function_pointer(
   Output_section* ,
   const elfcpp::Rela<size, false>& reloc,
   unsigned int r_type,
-  Symbol* gsym)
+  Symbol*)
 {
-  // When building a shared library, do not fold symbols whose visibility
-  // is hidden, internal or protected.
-  if (parameters->options().shared()
-      && (gsym->visibility() == elfcpp::STV_INTERNAL
-	  || gsym->visibility() == elfcpp::STV_PROTECTED
-	  || gsym->visibility() == elfcpp::STV_HIDDEN))
-    return true;
-
   return possible_function_pointer_reloc(src_obj, src_indx,
                                          reloc.get_r_offset(), r_type);
 }
-- 
2.9.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]