bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug gold/21452] New: Enable safe ICF for shared object


From: hjl.tools at gmail dot com
Subject: [Bug gold/21452] New: Enable safe ICF for shared object
Date: Tue, 02 May 2017 16:57:27 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=21452

            Bug ID: 21452
           Summary: Enable safe ICF for shared object
           Product: binutils
           Version: 2.29 (HEAD)
            Status: NEW
          Severity: normal
          Priority: P2
         Component: gold
          Assignee: ccoutant at gmail dot com
          Reporter: hjl.tools at gmail dot com
                CC: ian at airs dot com, rahulchaudhry at chromium dot org,
                    tmsriram at google dot com
  Target Milestone: ---
            Target: x86-64

x86-64.cc has

template<int size>
inline bool
Target_x86_64<size>::Scan::local_reloc_may_be_function_pointer(
  Symbol_table* ,
  Layout* ,
  Target_x86_64<size>* ,
  Sized_relobj_file<size, false>* src_obj,
  unsigned int src_indx,
  Output_section* ,
  const elfcpp::Rela<size, false>& reloc,
  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);
}

// For safe ICF, scan a relocation for a global symbol to check if it
// corresponds to a function pointer being taken.  In that case mark
// the function whose pointer was taken as not foldable.

template<int size>
inline bool
Target_x86_64<size>::Scan::global_reloc_may_be_function_pointer(
  Symbol_table*,
  Layout* ,
  Target_x86_64<size>* ,
  Sized_relobj_file<size, false>* src_obj,
  unsigned int src_indx,
  Output_section* ,
  const elfcpp::Rela<size, false>& reloc,
  unsigned int r_type,
  Symbol* gsym
{
  // 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);
}

With

commit 4aebb6312eb5dcd12f2f8420028547584b708907
Author: Rahul Chaudhry <address@hidden>
Date:   Wed Feb 15 00:37:10 2017 -0800

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

    gold/
            * x86_64.cc (Target_x86_64::do_can_check_for_function_pointers):
            Return true even when building pie binaries.
            (Target_x86_64::possible_function_pointer_reloc): Check opcode
            for R_X86_64_PC32 relocations.
            (Target_x86_64::local_reloc_may_be_function_pointer): Pass
            extra arguments to local_reloc_may_be_function_pointer.
            (Target_x86_64::global_reloc_may_be_function_pointer): Likewise.
            * gc.h (gc_process_relocs): Add check for STT_FUNC.
            * testsuite/Makefile.am (icf_safe_pie_test): New test case.
            * testsuite/Makefile.in: Regenerate.
            * testsuite/icf_safe_pie_test.sh: New shell script.


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

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]